12 Commits

7 changed files with 324 additions and 70 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "vue-nonograms-solid", "name": "vue-nonograms-solid",
"version": "1.4.0", "version": "1.6.4",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "vue-nonograms-solid", "name": "vue-nonograms-solid",
"version": "1.4.0", "version": "1.6.4",
"dependencies": { "dependencies": {
"fireworks-js": "^2.10.8", "fireworks-js": "^2.10.8",
"flag-icons": "^7.5.0", "flag-icons": "^7.5.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "vue-nonograms-solid", "name": "vue-nonograms-solid",
"version": "1.4.0", "version": "1.6.4",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, computed } from 'vue'; import { ref, computed, onMounted, watch } from 'vue';
import { usePuzzleStore } from '@/stores/puzzle'; import { usePuzzleStore } from '@/stores/puzzle';
import { useI18n } from '@/composables/useI18n'; import { useI18n } from '@/composables/useI18n';
import { calculateDifficulty } from '@/utils/puzzleUtils'; import { calculateDifficulty } from '@/utils/puzzleUtils';
@@ -12,6 +12,26 @@ const customSize = ref(10);
const fillRate = ref(50); const fillRate = ref(50);
const errorMsg = ref(''); const errorMsg = ref('');
onMounted(() => {
const savedSize = localStorage.getItem('nonograms_custom_size');
if (savedSize && !isNaN(savedSize)) {
customSize.value = Math.max(5, Math.min(80, Number(savedSize)));
}
const savedFillRate = localStorage.getItem('nonograms_custom_fill_rate');
if (savedFillRate && !isNaN(savedFillRate)) {
fillRate.value = Math.max(10, Math.min(90, Number(savedFillRate)));
}
});
watch(customSize, (newVal) => {
localStorage.setItem('nonograms_custom_size', newVal);
});
watch(fillRate, (newVal) => {
localStorage.setItem('nonograms_custom_fill_rate', newVal);
});
const snapToStep = (value, step) => { const snapToStep = (value, step) => {
const rounded = Math.round(value / step) * step; const rounded = Math.round(value / step) * step;
return Math.max(5, Math.min(80, rounded)); return Math.max(5, Math.min(80, rounded));
@@ -21,12 +41,12 @@ const handleSnap = () => {
customSize.value = snapToStep(Number(customSize.value), 5); customSize.value = snapToStep(Number(customSize.value), 5);
}; };
const difficultyLevel = computed(() => { const difficultyInfo = computed(() => {
return calculateDifficulty(fillRate.value / 100); return calculateDifficulty(fillRate.value / 100, customSize.value);
}); });
const difficultyColor = computed(() => { const difficultyColor = computed(() => {
switch(difficultyLevel.value) { switch(difficultyInfo.value.level) {
case 'extreme': return '#ff3333'; case 'extreme': return '#ff3333';
case 'hardest': return '#ff9933'; case 'hardest': return '#ff9933';
case 'harder': return '#ffff33'; case 'harder': return '#ffff33';
@@ -77,7 +97,7 @@ const confirm = () => {
v-model="fillRate" v-model="fillRate"
min="10" min="10"
max="90" max="90"
step="5" step="1"
/> />
<div class="range-scale"> <div class="range-scale">
<span>10%</span> <span>10%</span>
@@ -86,10 +106,9 @@ const confirm = () => {
</div> </div>
<div class="difficulty-indicator"> <div class="difficulty-indicator">
<span class="label">{{ t('custom.difficulty') }}:</span> <div class="label">{{ t('custom.difficulty') }}</div>
<span class="value" :style="{ color: difficultyColor }"> <div class="level" :style="{ color: difficultyColor }">{{ t(`difficulty.${difficultyInfo.level}`) }}</div>
{{ t(`difficulty.${difficultyLevel}`) }} <div class="percentage" :style="{ color: difficultyColor }">{{ difficultyInfo.value }}%</div>
</span>
</div> </div>
<p v-if="errorMsg" class="error">{{ errorMsg }}</p> <p v-if="errorMsg" class="error">{{ errorMsg }}</p>
@@ -199,12 +218,30 @@ input[type="range"]::-moz-range-thumb {
justify-content: space-between; justify-content: space-between;
color: var(--text-muted); color: var(--text-muted);
font-size: 0.85rem; font-size: 0.85rem;
.difficulty-indicator {
margin: 20px 0 30px 0;
display: flex;
flex-direction: column;
align-items: center;
gap: 5px;
} }
.difficulty-indicator { .label {
margin: 20px 0; font-size: 1rem;
font-size: 1.2rem; color: var(--text-muted);
display: flex; }
.level {
font-size: 1.4rem;
font-weight: bold;
text-transform: uppercase;
line-height: 1.2;
}
.percentage {
font-size: 1rem;
font-weight: bold;
} display: flex;
justify-content: center; justify-content: center;
gap: 10px; gap: 10px;
align-items: center; align-items: center;

View File

@@ -4,7 +4,7 @@ import { Fireworks } from 'fireworks-js';
import { usePuzzleStore } from '@/stores/puzzle'; import { usePuzzleStore } from '@/stores/puzzle';
import { useI18n } from '@/composables/useI18n'; import { useI18n } from '@/composables/useI18n';
import { useTimer } from '@/composables/useTimer'; import { useTimer } from '@/composables/useTimer';
import { Download } from 'lucide-vue-next'; import { Download, FileCode } from 'lucide-vue-next';
import { calculateDifficulty } from '@/utils/puzzleUtils'; import { calculateDifficulty } from '@/utils/puzzleUtils';
const store = usePuzzleStore(); const store = usePuzzleStore();
@@ -41,30 +41,43 @@ const playFanfare = async () => {
} }
} }
masterGain = audioContext.createGain(); masterGain = audioContext.createGain();
masterGain.gain.value = 0.18; masterGain.gain.value = 0.25; // Slightly louder but softer tone
masterGain.connect(audioContext.destination); masterGain.connect(audioContext.destination);
const notes = [
{ time: 0.0, dur: 0.18, freqs: [523.25, 659.25, 783.99] },
{ time: 0.2, dur: 0.18, freqs: [587.33, 740.0, 880.0] },
{ time: 0.4, dur: 0.22, freqs: [659.25, 830.61, 987.77] },
{ time: 0.7, dur: 0.35, freqs: [698.46, 880.0, 1046.5] }
];
const now = audioContext.currentTime; const now = audioContext.currentTime;
notes.forEach(({ time, dur, freqs }) => {
freqs.forEach((freq) => { const playNote = (freq, startTime, duration) => {
const osc = audioContext.createOscillator(); const osc = audioContext.createOscillator();
const gain = audioContext.createGain(); const gain = audioContext.createGain();
osc.type = 'triangle';
osc.frequency.value = freq; // Mix of sine and triangle for a bell-like quality
gain.gain.setValueAtTime(0.0001, now + time); osc.type = 'sine';
gain.gain.linearRampToValueAtTime(0.8, now + time + 0.02); osc.frequency.value = freq;
gain.gain.exponentialRampToValueAtTime(0.0001, now + time + dur);
osc.connect(gain); // Envelope for elegant bell/chime sound
gain.connect(masterGain); gain.gain.setValueAtTime(0, startTime);
osc.start(now + time); gain.gain.linearRampToValueAtTime(0.4, startTime + 0.05); // Soft attack
osc.stop(now + time + dur + 0.05); gain.gain.exponentialRampToValueAtTime(0.01, startTime + duration); // Long release
});
}); osc.connect(gain);
gain.connect(masterGain);
osc.start(startTime);
osc.stop(startTime + duration + 0.1);
};
// C Major 7 Arpeggio sequence (C5, E5, G5, B5, C6) - Elegant & Uplifting
const sequence = [
{ freq: 523.25, time: 0.0, dur: 0.8 }, // C5
{ freq: 659.25, time: 0.1, dur: 0.8 }, // E5
{ freq: 783.99, time: 0.2, dur: 0.8 }, // G5
{ freq: 987.77, time: 0.3, dur: 0.8 }, // B5 (Maj7)
{ freq: 1046.50, time: 0.4, dur: 2.0 }, // C6 (High C resolve)
// Add a bass root note at the end for fullness
{ freq: 523.25, time: 0.4, dur: 2.0 } // C5
];
sequence.forEach(note => playNote(note.freq, now + note.time, note.dur));
}; };
const triggerVibration = () => { const triggerVibration = () => {
@@ -175,7 +188,11 @@ const buildShareCanvas = () => {
if (store.guideUsageCount > 0) { if (store.guideUsageCount > 0) {
ctx.fillStyle = '#ff4d4d'; ctx.fillStyle = '#ff4d4d';
ctx.font = '600 14px "Segoe UI", sans-serif'; ctx.font = '600 14px "Segoe UI", sans-serif';
const guideText = t('win.usedGuide', { count: store.guideUsageCount });
const totalCells = store.size * store.size;
const percent = Math.min(100, Math.round((store.guideUsageCount / totalCells) * 100));
const guideText = t('win.usedGuide', { count: store.guideUsageCount, percent });
ctx.fillText(`⚠️ ${guideText}`, padding, height - padding - footerHeight + 10); ctx.fillText(`⚠️ ${guideText}`, padding, height - padding - footerHeight + 10);
} }
@@ -185,6 +202,125 @@ const buildShareCanvas = () => {
return canvas; return canvas;
}; };
const buildShareSVG = () => {
const grid = store.playerGrid;
if (!grid || !grid.length) return null;
const appUrl = 'https://nonograms.7u.pl/';
const size = store.size;
const maxBoard = 640;
const cellSize = Math.max(8, Math.floor(maxBoard / size));
const boardSize = cellSize * size;
const padding = 28;
const headerHeight = 64;
const footerHeight = 28;
const infoHeight = 40;
const width = boardSize + padding * 2;
const height = boardSize + padding * 2 + headerHeight + footerHeight + infoHeight;
// Colors
const bgGradientStart = '#1b2a4a';
const bgGradientEnd = '#0a1324';
const overlayColor = 'rgba(0, 0, 0, 0.35)';
const textColor = '#e8fbff';
const gridColor = 'rgba(255, 255, 255, 0.06)';
const gridLineColor = 'rgba(255, 255, 255, 0.12)';
const filledColor = '#00f2fe';
const crossColor = 'rgba(255, 255, 255, 0.5)';
const urlColor = 'rgba(255, 255, 255, 0.75)';
// Difficulty Logic
const densityPercent = Math.round(store.currentDensity * 100);
const diffInfo = calculateDifficulty(store.currentDensity, store.size);
const difficultyKey = diffInfo.level;
let diffColor = '#33ff33';
if (difficultyKey === 'extreme') diffColor = '#ff3333';
else if (difficultyKey === 'hardest') diffColor = '#ff9933';
else if (difficultyKey === 'harder') diffColor = '#ffff33';
const difficultyText = t(`difficulty.${difficultyKey}`);
const diffLabel = `${t('win.difficulty')} ${difficultyText} (${densityPercent}%)`;
let svgContent = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">`;
// Background
svgContent += `
<defs>
<linearGradient id="bg" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="${bgGradientStart}"/>
<stop offset="100%" stop-color="${bgGradientEnd}"/>
</linearGradient>
</defs>
<rect width="100%" height="100%" fill="url(#bg)"/>
<rect x="12" y="12" width="${width - 24}" height="${height - 24}" fill="${overlayColor}"/>
`;
// Text: Title & Time
svgContent += `
<text x="${padding}" y="${padding + 28}" font-family="Segoe UI, sans-serif" font-weight="700" font-size="26" fill="${textColor}">${t('app.title')}</text>
<text x="${padding}" y="${padding + 56}" font-family="Segoe UI, sans-serif" font-weight="600" font-size="16" fill="${textColor}">${t('win.time')} ${formattedTime.value}</text>
`;
// Text: Difficulty (Right Aligned - manual approx or end anchor)
svgContent += `
<text x="${width - padding}" y="${padding + 56}" font-family="Segoe UI, sans-serif" font-weight="600" font-size="14" fill="${diffColor}" text-anchor="end">${diffLabel}</text>
`;
const gridX = padding;
const gridY = padding + headerHeight;
// Grid Background
svgContent += `<rect x="${gridX}" y="${gridY}" width="${boardSize}" height="${boardSize}" fill="${gridColor}"/>`;
// Grid Lines
let gridLines = '';
for (let i = 0; i <= size; i++) {
const pos = i * cellSize;
// Vertical
gridLines += `<line x1="${gridX + pos}" y1="${gridY}" x2="${gridX + pos}" y2="${gridY + boardSize}" stroke="${gridLineColor}" stroke-width="1"/>`;
// Horizontal
gridLines += `<line x1="${gridX}" y1="${gridY + pos}" x2="${gridX + boardSize}" y2="${gridY + pos}" stroke="${gridLineColor}" stroke-width="1"/>`;
}
svgContent += gridLines;
// Cells
let cells = '';
const lineWidth = Math.max(1.5, Math.floor(cellSize * 0.12));
for (let r = 0; r < size; r++) {
for (let c = 0; c < size; c++) {
const state = grid[r]?.[c];
const cx = gridX + c * cellSize;
const cy = gridY + r * cellSize;
if (state === 1) { // Filled
cells += `<rect x="${cx + 1}" y="${cy + 1}" width="${cellSize - 2}" height="${cellSize - 2}" fill="${filledColor}"/>`;
} else if (state === 2) { // Cross
const d = cellSize * 0.6;
const off = cellSize * 0.2;
cells += `
<path d="M${cx + off} ${cy + off} L${cx + off + d} ${cy + off + d} M${cx + off + d} ${cy + off} L${cx + off} ${cy + off + d}"
stroke="${crossColor}" stroke-width="${lineWidth}" stroke-linecap="round"/>
`;
}
}
}
svgContent += cells;
// Guide Usage
if (store.guideUsageCount > 0) {
const totalCells = store.size * store.size;
const percent = Math.min(100, Math.round((store.guideUsageCount / totalCells) * 100));
const guideText = t('win.usedGuide', { count: store.guideUsageCount, percent });
svgContent += `<text x="${padding}" y="${height - padding - footerHeight + 10}" font-family="Segoe UI, sans-serif" font-weight="600" font-size="14" fill="#ff4d4d">⚠️ ${guideText}</text>`;
}
// URL
svgContent += `<text x="${padding}" y="${height - padding + 6}" font-family="Segoe UI, sans-serif" font-weight="500" font-size="14" fill="${urlColor}">${appUrl}</text>`;
svgContent += '</svg>';
return svgContent;
};
const canvasToBlob = (canvas) => new Promise((resolve) => canvas.toBlob((blob) => resolve(blob), 'image/png')); const canvasToBlob = (canvas) => new Promise((resolve) => canvas.toBlob((blob) => resolve(blob), 'image/png'));
const createShareBlob = async () => { const createShareBlob = async () => {
@@ -193,6 +329,20 @@ const createShareBlob = async () => {
return canvasToBlob(canvas); return canvasToBlob(canvas);
}; };
const downloadShareSVG = () => {
const svgString = buildShareSVG();
if (!svgString) return;
const blob = new Blob([svgString], { type: 'image/svg+xml' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `nonogram-${store.size}x${store.size}.svg`;
document.body.appendChild(link);
link.click();
link.remove();
URL.revokeObjectURL(url);
};
const downloadShareImage = async () => { const downloadShareImage = async () => {
const blob = await createShareBlob(); const blob = await createShareBlob();
if (!blob) return; if (!blob) return;
@@ -341,6 +491,10 @@ onUnmounted(() => {
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareDownload')" @click="downloadShareImage"> <button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareDownload')" @click="downloadShareImage">
<Download :size="20" /> <Download :size="20" />
</button> </button>
<!-- Download SVG (Compact) -->
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" aria-label="Download SVG" @click="downloadShareSVG">
<FileCode :size="20" />
</button>
</div> </div>
</div> </div>

View File

@@ -46,7 +46,7 @@ const messages = {
'win.shareWhatsapp': 'WhatsApp', 'win.shareWhatsapp': 'WhatsApp',
'win.shareDownload': 'Pobierz zrzut', 'win.shareDownload': 'Pobierz zrzut',
'win.difficulty': 'Poziom:', 'win.difficulty': 'Poziom:',
'win.usedGuide': 'Użyto podpowiedzi: {count}', 'win.usedGuide': 'Podpowiedzi: {percent}% ({count})',
'pwa.installTitle': 'Zainstaluj aplikację i graj offline', 'pwa.installTitle': 'Zainstaluj aplikację i graj offline',
'pwa.installMobile': 'Dodaj do ekranu głównego', 'pwa.installMobile': 'Dodaj do ekranu głównego',
'pwa.installDesktop': 'Zainstaluj na komputerze', 'pwa.installDesktop': 'Zainstaluj na komputerze',
@@ -153,7 +153,7 @@ const messages = {
'win.shareWhatsapp': 'WhatsApp', 'win.shareWhatsapp': 'WhatsApp',
'win.shareDownload': 'Download screenshot', 'win.shareDownload': 'Download screenshot',
'win.difficulty': 'Difficulty:', 'win.difficulty': 'Difficulty:',
'win.usedGuide': 'Guide used: {count}', 'win.usedGuide': 'Hints: {percent}% ({count})',
'pwa.installTitle': 'Install the app and play offline', 'pwa.installTitle': 'Install the app and play offline',
'pwa.installMobile': 'Add to home screen', 'pwa.installMobile': 'Add to home screen',
'pwa.installDesktop': 'Install on desktop', 'pwa.installDesktop': 'Install on desktop',

View File

@@ -52,24 +52,36 @@ export function generateRandomGrid(size, density = 0.5) {
return grid; return grid;
} }
export function calculateDifficulty(density) { export function calculateDifficulty(density, size = 10) {
// Shannon Entropy: H(x) = -x*log2(x) - (1-x)*log2(1-x) // Shannon Entropy: H(x) = -x*log2(x) - (1-x)*log2(1-x)
// Normalized to 0-1 range (since max entropy at 0.5 is 1) // Normalized to 0-1 range (since max entropy at 0.5 is 1)
// Avoid log(0) // Avoid log(0)
if (density <= 0 || density >= 1) return 'easy'; if (density <= 0 || density >= 1) return { level: 'easy', value: 0 };
const entropy = -density * Math.log2(density) - (1 - density) * Math.log2(1 - density); const entropy = -density * Math.log2(density) - (1 - density) * Math.log2(1 - density);
// Thresholds based on entropy // Difficulty score combines entropy (complexity) and size (scale)
// 0.5 density -> entropy 1.0 (Extreme) // We use sqrt(size) to dampen the effect of very large grids,
// 0.4/0.6 density -> entropy ~0.97 (Extreme) // ensuring that density still plays a major role.
// 0.3/0.7 density -> entropy ~0.88 (Hardest) // Normalized against max size (80)
// 0.2/0.8 density -> entropy ~0.72 (Harder) const sizeFactor = Math.sqrt(size / 80);
// <0.2/>0.8 density -> entropy <0.72 (Easy) const score = entropy * sizeFactor * 100;
const value = Math.round(score);
// Thresholds
let level = 'easy';
if (value >= 80) level = 'extreme';
else if (value >= 60) level = 'hardest';
else if (value >= 40) level = 'harder';
else if (value >= 20) level = 'medium'; // Using 'medium' key if available, or we need to add it?
// Wait, useI18n only has: easy, harder, hardest, extreme.
// Let's stick to those keys but adjust ranges.
if (value >= 75) level = 'extreme';
else if (value >= 50) level = 'hardest';
else if (value >= 25) level = 'harder';
else level = 'easy';
if (entropy >= 0.96) return 'extreme'; // approx 38% - 62% return { level, value };
if (entropy >= 0.85) return 'hardest'; // approx 28% - 38% & 62% - 72%
if (entropy >= 0.65) return 'harder'; // approx 17% - 28% & 72% - 83%
return 'easy';
} }

View File

@@ -91,15 +91,33 @@ const solveLineLogic = (lineState, hints) => {
return result; return result;
} }
const len = hints[hintIndex]; const len = hints[hintIndex];
// maxStart logic: we need enough space for this block (len) + subsequent blocks/gaps (suffixMin[hintIndex+1])
// suffixMin[hintIndex] = len + (m - hintIndex - 1) + suffixMin[hintIndex+1]
// Actually suffixMin[hintIndex] already includes everything needed from here to end.
// So if we place block at start, end is start + len.
// Total space needed is suffixMin[hintIndex].
// So start can go up to n - suffixMin[hintIndex].
const maxStart = n - suffixMin[hintIndex]; const maxStart = n - suffixMin[hintIndex];
for (let start = pos; start <= maxStart; start++) { for (let start = pos; start <= maxStart; start++) {
if (hasFilled(pos, start)) continue; if (hasFilled(pos, start)) continue; // Must be empty before this block
if (hasCross(start, start + len)) continue; if (hasCross(start, start + len)) continue; // Block space must be free of crosses
if (start + len < n && lineState[start + len] === 1) continue;
const nextPos = start + len < n ? start + len + 1 : start + len; // If not the last block, we need a gap after
if (canPlaceSuffix(nextPos, hintIndex + 1)) { if (hintIndex < m - 1) {
memoSuffix[pos][hintIndex] = true; if (start + len < n && lineState[start + len] === 1) continue; // Gap must not be filled
return true; // We can assume gap is at start + len. Next block starts at least at start + len + 1
const nextPos = start + len + 1;
if (canPlaceSuffix(nextPos, hintIndex + 1)) {
memoSuffix[pos][hintIndex] = true;
return true;
}
} else {
// Last block
// Check if we can fill the rest with empty
if (hasFilled(start + len, n)) continue;
memoSuffix[pos][hintIndex] = true;
return true;
} }
} }
memoSuffix[pos][hintIndex] = false; memoSuffix[pos][hintIndex] = false;
@@ -115,16 +133,42 @@ const solveLineLogic = (lineState, hints) => {
return result; return result;
} }
const len = hints[hintCount - 1]; const len = hints[hintCount - 1];
const maxStart = pos - len;
// Logic for prefix:
// We are placing the (hintCount-1)-th block ending at 'start + len' <= pos.
// So 'start' <= pos - len.
// But we also need to ensure there is space for previous blocks.
// However, the simple constraint is just iterating backwards.
// maxStart: if this is the only block, maxStart = pos - len.
// If there are previous blocks, we need a gap before this block.
// So previous block ended at start - 1.
// Actually the recursive call will handle space check.
// But for the gap check:
// If we place block at 'start', we need lineState[start-1] != 1 (if start > 0).
// And we recursively check canPlacePrefix(start-1, count-1).
// But if start=0 and count > 1, impossible.
const maxStart = pos - len; // Simplified, loop condition handles rest
for (let start = maxStart; start >= 0; start--) { for (let start = maxStart; start >= 0; start--) {
if (hasCross(start, start + len)) continue; if (hasCross(start, start + len)) continue;
if (start + len < pos && lineState[start + len] === 1) continue; if (hasFilled(start + len, pos)) continue; // Must be empty after this block up to pos
if (hasFilled(start + len, pos)) continue;
if (start > 0 && lineState[start - 1] === 1) continue; // Check gap before
const prevPos = start > 0 ? start - 1 : 0; if (hintCount > 1) {
if (canPlacePrefix(prevPos, hintCount - 1)) { if (start === 0) continue; // No space for previous blocks
memoPrefix[pos][hintCount] = true; if (lineState[start - 1] === 1) continue; // Gap must not be filled
return true; const prevPos = start - 1;
if (canPlacePrefix(prevPos, hintCount - 1)) {
memoPrefix[pos][hintCount] = true;
return true;
}
} else {
// First block
if (hasFilled(0, start)) continue; // Before first block must be empty
memoPrefix[pos][hintCount] = true;
return true;
} }
} }
memoPrefix[pos][hintCount] = false; memoPrefix[pos][hintCount] = false;
@@ -136,7 +180,14 @@ const solveLineLogic = (lineState, hints) => {
const len = hints[i]; const len = hints[i];
const starts = []; const starts = [];
for (let start = 0; start <= n - len; start++) { for (let start = 0; start <= n - len; start++) {
if (!canPlacePrefix(start, i)) continue; if (i === 0) {
if (!canPlacePrefix(start, 0)) continue;
} else {
if (start === 0) continue;
if (lineState[start - 1] === 1) continue;
if (!canPlacePrefix(start - 1, i)) continue;
}
if (hasCross(start, start + len)) continue; if (hasCross(start, start + len)) continue;
if (start + len < n && lineState[start + len] === 1) continue; if (start + len < n && lineState[start + len] === 1) continue;
const nextPos = start + len < n ? start + len + 1 : start + len; const nextPos = start + len < n ? start + len + 1 : start + len;