Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9ae630fe5 | |||
| 132c4ebced | |||
| 0b8dcacd18 | |||
| 4ef4f2b251 | |||
| 17d8cbfedd | |||
| a41e337c43 | |||
| 1f1de61044 | |||
| 7f22aa9198 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.6.0",
|
||||
"version": "1.6.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.6.0",
|
||||
"version": "1.6.4",
|
||||
"dependencies": {
|
||||
"fireworks-js": "^2.10.8",
|
||||
"flag-icons": "^7.5.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.6.0",
|
||||
"version": "1.6.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { ref, computed, onMounted, watch } from 'vue';
|
||||
import { usePuzzleStore } from '@/stores/puzzle';
|
||||
import { useI18n } from '@/composables/useI18n';
|
||||
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
||||
@@ -12,6 +12,26 @@ const customSize = ref(10);
|
||||
const fillRate = ref(50);
|
||||
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 rounded = Math.round(value / step) * step;
|
||||
return Math.max(5, Math.min(80, rounded));
|
||||
@@ -21,12 +41,12 @@ const handleSnap = () => {
|
||||
customSize.value = snapToStep(Number(customSize.value), 5);
|
||||
};
|
||||
|
||||
const difficultyLevel = computed(() => {
|
||||
return calculateDifficulty(fillRate.value / 100);
|
||||
const difficultyInfo = computed(() => {
|
||||
return calculateDifficulty(fillRate.value / 100, customSize.value);
|
||||
});
|
||||
|
||||
const difficultyColor = computed(() => {
|
||||
switch(difficultyLevel.value) {
|
||||
switch(difficultyInfo.value.level) {
|
||||
case 'extreme': return '#ff3333';
|
||||
case 'hardest': return '#ff9933';
|
||||
case 'harder': return '#ffff33';
|
||||
@@ -77,7 +97,7 @@ const confirm = () => {
|
||||
v-model="fillRate"
|
||||
min="10"
|
||||
max="90"
|
||||
step="5"
|
||||
step="1"
|
||||
/>
|
||||
<div class="range-scale">
|
||||
<span>10%</span>
|
||||
@@ -86,10 +106,9 @@ const confirm = () => {
|
||||
</div>
|
||||
|
||||
<div class="difficulty-indicator">
|
||||
<span class="label">{{ t('custom.difficulty') }}:</span>
|
||||
<span class="value" :style="{ color: difficultyColor }">
|
||||
{{ t(`difficulty.${difficultyLevel}`) }}
|
||||
</span>
|
||||
<div class="label">{{ t('custom.difficulty') }}</div>
|
||||
<div class="level" :style="{ color: difficultyColor }">{{ t(`difficulty.${difficultyInfo.level}`) }}</div>
|
||||
<div class="percentage" :style="{ color: difficultyColor }">{{ difficultyInfo.value }}%</div>
|
||||
</div>
|
||||
|
||||
<p v-if="errorMsg" class="error">{{ errorMsg }}</p>
|
||||
@@ -199,12 +218,30 @@ input[type="range"]::-moz-range-thumb {
|
||||
justify-content: space-between;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.85rem;
|
||||
.difficulty-indicator {
|
||||
margin: 20px 0 30px 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.difficulty-indicator {
|
||||
margin: 20px 0;
|
||||
font-size: 1.2rem;
|
||||
display: flex;
|
||||
.label {
|
||||
font-size: 1rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.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;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
|
||||
@@ -231,7 +231,8 @@ const buildShareSVG = () => {
|
||||
|
||||
// Difficulty Logic
|
||||
const densityPercent = Math.round(store.currentDensity * 100);
|
||||
const difficultyKey = calculateDifficulty(store.currentDensity);
|
||||
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';
|
||||
|
||||
@@ -52,24 +52,36 @@ export function generateRandomGrid(size, density = 0.5) {
|
||||
return grid;
|
||||
}
|
||||
|
||||
export function calculateDifficulty(density) {
|
||||
export function calculateDifficulty(density, size = 10) {
|
||||
// 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)
|
||||
|
||||
// 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);
|
||||
|
||||
// Thresholds based on entropy
|
||||
// 0.5 density -> entropy 1.0 (Extreme)
|
||||
// 0.4/0.6 density -> entropy ~0.97 (Extreme)
|
||||
// 0.3/0.7 density -> entropy ~0.88 (Hardest)
|
||||
// 0.2/0.8 density -> entropy ~0.72 (Harder)
|
||||
// <0.2/>0.8 density -> entropy <0.72 (Easy)
|
||||
// Difficulty score combines entropy (complexity) and size (scale)
|
||||
// We use sqrt(size) to dampen the effect of very large grids,
|
||||
// ensuring that density still plays a major role.
|
||||
// Normalized against max size (80)
|
||||
const sizeFactor = Math.sqrt(size / 80);
|
||||
const score = entropy * sizeFactor * 100;
|
||||
const value = Math.round(score);
|
||||
|
||||
if (entropy >= 0.96) return 'extreme'; // approx 38% - 62%
|
||||
if (entropy >= 0.85) return 'hardest'; // approx 28% - 38% & 62% - 72%
|
||||
if (entropy >= 0.65) return 'harder'; // approx 17% - 28% & 72% - 83%
|
||||
return 'easy';
|
||||
// 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';
|
||||
|
||||
return { level, value };
|
||||
}
|
||||
|
||||
@@ -91,15 +91,33 @@ const solveLineLogic = (lineState, hints) => {
|
||||
return result;
|
||||
}
|
||||
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];
|
||||
|
||||
for (let start = pos; start <= maxStart; start++) {
|
||||
if (hasFilled(pos, start)) continue;
|
||||
if (hasCross(start, start + len)) continue;
|
||||
if (start + len < n && lineState[start + len] === 1) continue;
|
||||
const nextPos = start + len < n ? start + len + 1 : start + len;
|
||||
if (canPlaceSuffix(nextPos, hintIndex + 1)) {
|
||||
memoSuffix[pos][hintIndex] = true;
|
||||
return true;
|
||||
if (hasFilled(pos, start)) continue; // Must be empty before this block
|
||||
if (hasCross(start, start + len)) continue; // Block space must be free of crosses
|
||||
|
||||
// If not the last block, we need a gap after
|
||||
if (hintIndex < m - 1) {
|
||||
if (start + len < n && lineState[start + len] === 1) continue; // Gap must not be filled
|
||||
// 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;
|
||||
@@ -115,16 +133,42 @@ const solveLineLogic = (lineState, hints) => {
|
||||
return result;
|
||||
}
|
||||
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--) {
|
||||
if (hasCross(start, start + len)) continue;
|
||||
if (start + len < pos && lineState[start + len] === 1) continue;
|
||||
if (hasFilled(start + len, pos)) continue;
|
||||
if (start > 0 && lineState[start - 1] === 1) continue;
|
||||
const prevPos = start > 0 ? start - 1 : 0;
|
||||
if (canPlacePrefix(prevPos, hintCount - 1)) {
|
||||
memoPrefix[pos][hintCount] = true;
|
||||
return true;
|
||||
if (hasFilled(start + len, pos)) continue; // Must be empty after this block up to pos
|
||||
|
||||
// Check gap before
|
||||
if (hintCount > 1) {
|
||||
if (start === 0) continue; // No space for previous blocks
|
||||
if (lineState[start - 1] === 1) continue; // Gap must not be filled
|
||||
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;
|
||||
@@ -136,7 +180,14 @@ const solveLineLogic = (lineState, hints) => {
|
||||
const len = hints[i];
|
||||
const starts = [];
|
||||
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 (start + len < n && lineState[start + len] === 1) continue;
|
||||
const nextPos = start + len < n ? start + len + 1 : start + len;
|
||||
|
||||
Reference in New Issue
Block a user