Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 874e35bba3 | |||
| 69b04d3336 | |||
| c5b212234a | |||
| 8e0ddf3a72 | |||
| bfb24cfb03 | |||
| 8d3bde8d38 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-nonograms-solid",
|
"name": "vue-nonograms-solid",
|
||||||
"version": "1.0.7",
|
"version": "1.2.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "vue-nonograms-solid",
|
"name": "vue-nonograms-solid",
|
||||||
"version": "1.0.7",
|
"version": "1.2.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fireworks-js": "^2.10.8",
|
"fireworks-js": "^2.10.8",
|
||||||
"flag-icons": "^7.5.0",
|
"flag-icons": "^7.5.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-nonograms-solid",
|
"name": "vue-nonograms-solid",
|
||||||
"version": "1.0.7",
|
"version": "1.2.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { ref, computed } from 'vue';
|
import { ref, computed } 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';
|
||||||
|
|
||||||
const emit = defineEmits(['close']);
|
const emit = defineEmits(['close']);
|
||||||
const store = usePuzzleStore();
|
const store = usePuzzleStore();
|
||||||
@@ -21,13 +22,7 @@ const handleSnap = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const difficultyLevel = computed(() => {
|
const difficultyLevel = computed(() => {
|
||||||
const rate = fillRate.value;
|
return calculateDifficulty(fillRate.value / 100);
|
||||||
const dist = Math.abs(rate - 50);
|
|
||||||
|
|
||||||
if (dist <= 5) return 'extreme';
|
|
||||||
if (dist <= 15) return 'hardest';
|
|
||||||
if (dist <= 25) return 'harder';
|
|
||||||
return 'easy';
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const difficultyColor = computed(() => {
|
const difficultyColor = computed(() => {
|
||||||
@@ -213,6 +208,8 @@ input[type="range"]::-moz-range-thumb {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
height: 1.5em; /* Reserve space for one line of text */
|
||||||
}
|
}
|
||||||
|
|
||||||
.difficulty-indicator .label {
|
.difficulty-indicator .label {
|
||||||
@@ -224,6 +221,9 @@ input[type="range"]::-moz-range-thumb {
|
|||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
text-shadow: 0 0 10px currentColor;
|
text-shadow: 0 0 10px currentColor;
|
||||||
transition: color 0.3s ease;
|
transition: color 0.3s ease;
|
||||||
|
display: inline-block;
|
||||||
|
min-width: 120px; /* Reserve space for longest text */
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.error {
|
.error {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useTimer } from '@/composables/useTimer';
|
|||||||
import xIcon from '@/assets/brands/x.svg';
|
import xIcon from '@/assets/brands/x.svg';
|
||||||
import facebookIcon from '@/assets/brands/facebook.svg';
|
import facebookIcon from '@/assets/brands/facebook.svg';
|
||||||
import whatsappIcon from '@/assets/brands/whatsapp.svg';
|
import whatsappIcon from '@/assets/brands/whatsapp.svg';
|
||||||
|
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
||||||
|
|
||||||
const store = usePuzzleStore();
|
const store = usePuzzleStore();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
@@ -88,8 +89,9 @@ const buildShareCanvas = () => {
|
|||||||
const padding = 28;
|
const padding = 28;
|
||||||
const headerHeight = 64;
|
const headerHeight = 64;
|
||||||
const footerHeight = 28;
|
const footerHeight = 28;
|
||||||
|
const infoHeight = 40; // New space for difficulty/guide info
|
||||||
const width = boardSize + padding * 2;
|
const width = boardSize + padding * 2;
|
||||||
const height = boardSize + padding * 2 + headerHeight + footerHeight;
|
const height = boardSize + padding * 2 + headerHeight + footerHeight + infoHeight;
|
||||||
const scale = window.devicePixelRatio || 1;
|
const scale = window.devicePixelRatio || 1;
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = width * scale;
|
canvas.width = width * scale;
|
||||||
@@ -109,6 +111,24 @@ const buildShareCanvas = () => {
|
|||||||
ctx.fillText(t('app.title'), padding, padding + 10);
|
ctx.fillText(t('app.title'), padding, padding + 10);
|
||||||
ctx.font = '600 16px "Segoe UI", sans-serif';
|
ctx.font = '600 16px "Segoe UI", sans-serif';
|
||||||
ctx.fillText(`${t('win.time')} ${formattedTime.value}`, padding, padding + 34);
|
ctx.fillText(`${t('win.time')} ${formattedTime.value}`, padding, padding + 34);
|
||||||
|
|
||||||
|
// Difficulty & Density Info
|
||||||
|
const densityPercent = Math.round(store.currentDensity * 100);
|
||||||
|
const difficultyKey = calculateDifficulty(store.currentDensity);
|
||||||
|
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}`);
|
||||||
|
ctx.font = '600 14px "Segoe UI", sans-serif';
|
||||||
|
|
||||||
|
// Right aligned difficulty info
|
||||||
|
const diffLabel = `${t('win.difficulty')} ${difficultyText} (${densityPercent}%)`;
|
||||||
|
const diffWidth = ctx.measureText(diffLabel).width;
|
||||||
|
ctx.fillStyle = diffColor;
|
||||||
|
ctx.fillText(diffLabel, width - padding - diffWidth, padding + 34);
|
||||||
|
|
||||||
const gridX = padding;
|
const gridX = padding;
|
||||||
const gridY = padding + headerHeight;
|
const gridY = padding + headerHeight;
|
||||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.06)';
|
ctx.fillStyle = 'rgba(255, 255, 255, 0.06)';
|
||||||
@@ -152,6 +172,15 @@ const buildShareCanvas = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Guide Usage Info (Dirty Flag)
|
||||||
|
if (store.guideUsageCount > 0) {
|
||||||
|
ctx.fillStyle = '#ff4d4d';
|
||||||
|
ctx.font = '600 14px "Segoe UI", sans-serif';
|
||||||
|
const guideText = t('win.usedGuide', { count: store.guideUsageCount });
|
||||||
|
ctx.fillText(`⚠️ ${guideText}`, padding, height - padding - footerHeight + 10);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.75)';
|
ctx.fillStyle = 'rgba(255, 255, 255, 0.75)';
|
||||||
ctx.font = '500 14px "Segoe UI", sans-serif';
|
ctx.font = '500 14px "Segoe UI", sans-serif';
|
||||||
ctx.fillText(appUrl, padding, height - padding + 6);
|
ctx.fillText(appUrl, padding, height - padding + 6);
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ const messages = {
|
|||||||
'win.shareFacebook': 'Facebook',
|
'win.shareFacebook': 'Facebook',
|
||||||
'win.shareWhatsapp': 'WhatsApp',
|
'win.shareWhatsapp': 'WhatsApp',
|
||||||
'win.shareDownload': 'Pobierz zrzut',
|
'win.shareDownload': 'Pobierz zrzut',
|
||||||
|
'win.difficulty': 'Poziom:',
|
||||||
|
'win.usedGuide': 'Użyto podpowiedzi: {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',
|
||||||
@@ -150,6 +152,8 @@ const messages = {
|
|||||||
'win.shareFacebook': 'Facebook',
|
'win.shareFacebook': 'Facebook',
|
||||||
'win.shareWhatsapp': 'WhatsApp',
|
'win.shareWhatsapp': 'WhatsApp',
|
||||||
'win.shareDownload': 'Download screenshot',
|
'win.shareDownload': 'Download screenshot',
|
||||||
|
'win.difficulty': 'Difficulty:',
|
||||||
|
'win.usedGuide': 'Guide used: {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',
|
||||||
@@ -291,9 +295,17 @@ const messages = {
|
|||||||
'custom.cancel': '取消',
|
'custom.cancel': '取消',
|
||||||
'custom.start': '开始',
|
'custom.start': '开始',
|
||||||
'custom.sizeError': '尺寸必须在 5 到 80 之间!',
|
'custom.sizeError': '尺寸必须在 5 到 80 之间!',
|
||||||
|
'custom.fillRate': '填充率',
|
||||||
|
'custom.difficulty': '难度',
|
||||||
|
'difficulty.easy': '简单',
|
||||||
|
'difficulty.harder': '较难',
|
||||||
|
'difficulty.hardest': '最难',
|
||||||
|
'difficulty.extreme': '极限',
|
||||||
'win.title': '恭喜!',
|
'win.title': '恭喜!',
|
||||||
'win.message': '你解开了谜题!',
|
'win.message': '你解开了谜题!',
|
||||||
'win.time': '时间:',
|
'win.time': '时间:',
|
||||||
|
'win.difficulty': '难度:',
|
||||||
|
'win.usedGuide': '使用指南: {count}',
|
||||||
'win.playAgain': '再玩一次',
|
'win.playAgain': '再玩一次',
|
||||||
'win.shareTitle': '分享你的结果',
|
'win.shareTitle': '分享你的结果',
|
||||||
'win.shareText': '我在 {time} 内解开了 {size}x{size} 的数织!',
|
'win.shareText': '我在 {time} 内解开了 {size}x{size} 的数织!',
|
||||||
@@ -491,9 +503,17 @@ const messages = {
|
|||||||
'custom.cancel': 'Cancelar',
|
'custom.cancel': 'Cancelar',
|
||||||
'custom.start': 'Empezar',
|
'custom.start': 'Empezar',
|
||||||
'custom.sizeError': '¡El tamaño debe estar entre 5 y 80!',
|
'custom.sizeError': '¡El tamaño debe estar entre 5 y 80!',
|
||||||
|
'custom.fillRate': 'Relleno',
|
||||||
|
'custom.difficulty': 'Dificultad',
|
||||||
|
'difficulty.easy': 'Fácil',
|
||||||
|
'difficulty.harder': 'Más difícil',
|
||||||
|
'difficulty.hardest': 'El más difícil',
|
||||||
|
'difficulty.extreme': 'Extremo',
|
||||||
'win.title': '¡FELICIDADES!',
|
'win.title': '¡FELICIDADES!',
|
||||||
'win.message': '¡Has resuelto el rompecabezas!',
|
'win.message': '¡Has resuelto el rompecabezas!',
|
||||||
'win.time': 'Tiempo:',
|
'win.time': 'Tiempo:',
|
||||||
|
'win.difficulty': 'Dificultad:',
|
||||||
|
'win.usedGuide': 'Guía usada: {count}',
|
||||||
'win.playAgain': 'Jugar de nuevo',
|
'win.playAgain': 'Jugar de nuevo',
|
||||||
'win.shareTitle': 'Comparte tu resultado',
|
'win.shareTitle': 'Comparte tu resultado',
|
||||||
'win.shareText': '¡Resolví un nonograma de {size}x{size} en {time}!',
|
'win.shareText': '¡Resolví un nonograma de {size}x{size} en {time}!',
|
||||||
@@ -557,9 +577,17 @@ const messages = {
|
|||||||
'custom.cancel': 'Annuler',
|
'custom.cancel': 'Annuler',
|
||||||
'custom.start': 'Démarrer',
|
'custom.start': 'Démarrer',
|
||||||
'custom.sizeError': 'La taille doit être entre 5 et 80 !',
|
'custom.sizeError': 'La taille doit être entre 5 et 80 !',
|
||||||
|
'custom.fillRate': 'Remplissage',
|
||||||
|
'custom.difficulty': 'Difficulté',
|
||||||
|
'difficulty.easy': 'Facile',
|
||||||
|
'difficulty.harder': 'Plus difficile',
|
||||||
|
'difficulty.hardest': 'Le plus difficile',
|
||||||
|
'difficulty.extreme': 'Extrême',
|
||||||
'win.title': 'FÉLICITATIONS !',
|
'win.title': 'FÉLICITATIONS !',
|
||||||
'win.message': 'Vous avez résolu le puzzle !',
|
'win.message': 'Vous avez résolu le puzzle !',
|
||||||
'win.time': 'Temps:',
|
'win.time': 'Temps:',
|
||||||
|
'win.difficulty': 'Difficulté :',
|
||||||
|
'win.usedGuide': 'Guide utilisé : {count}',
|
||||||
'win.playAgain': 'Rejouer',
|
'win.playAgain': 'Rejouer',
|
||||||
'win.shareTitle': 'Partagez votre résultat',
|
'win.shareTitle': 'Partagez votre résultat',
|
||||||
'win.shareText': 'J’ai résolu un nonogramme {size}x{size} en {time} !',
|
'win.shareText': 'J’ai résolu un nonogramme {size}x{size} en {time} !',
|
||||||
@@ -623,9 +651,17 @@ const messages = {
|
|||||||
'custom.cancel': 'إلغاء',
|
'custom.cancel': 'إلغاء',
|
||||||
'custom.start': 'ابدأ',
|
'custom.start': 'ابدأ',
|
||||||
'custom.sizeError': 'يجب أن يكون الحجم بين 5 و80!',
|
'custom.sizeError': 'يجب أن يكون الحجم بين 5 و80!',
|
||||||
|
'custom.fillRate': 'معدل الملء',
|
||||||
|
'custom.difficulty': 'الصعوبة',
|
||||||
|
'difficulty.easy': 'سهل',
|
||||||
|
'difficulty.harder': 'أصعب',
|
||||||
|
'difficulty.hardest': 'الأصعب',
|
||||||
|
'difficulty.extreme': 'أقصى',
|
||||||
'win.title': 'تهانينا!',
|
'win.title': 'تهانينا!',
|
||||||
'win.message': 'لقد حللت اللغز!',
|
'win.message': 'لقد حللت اللغز!',
|
||||||
'win.time': 'الوقت:',
|
'win.time': 'الوقت:',
|
||||||
|
'win.difficulty': 'الصعوبة:',
|
||||||
|
'win.usedGuide': 'تم استخدام الدليل: {count}',
|
||||||
'win.playAgain': 'العب مرة أخرى',
|
'win.playAgain': 'العب مرة أخرى',
|
||||||
'win.shareTitle': 'شارك نتيجتك',
|
'win.shareTitle': 'شارك نتيجتك',
|
||||||
'win.shareText': 'حللت نونوغرام {size}x{size} في {time}!',
|
'win.shareText': 'حللت نونوغرام {size}x{size} في {time}!',
|
||||||
@@ -755,9 +791,17 @@ const messages = {
|
|||||||
'custom.cancel': 'Отмена',
|
'custom.cancel': 'Отмена',
|
||||||
'custom.start': 'Старт',
|
'custom.start': 'Старт',
|
||||||
'custom.sizeError': 'Размер должен быть от 5 до 80!',
|
'custom.sizeError': 'Размер должен быть от 5 до 80!',
|
||||||
|
'custom.fillRate': 'Заполнение',
|
||||||
|
'custom.difficulty': 'Сложность',
|
||||||
|
'difficulty.easy': 'Легкий',
|
||||||
|
'difficulty.harder': 'Сложный',
|
||||||
|
'difficulty.hardest': 'Очень сложный',
|
||||||
|
'difficulty.extreme': 'Экстремальный',
|
||||||
'win.title': 'ПОЗДРАВЛЯЕМ!',
|
'win.title': 'ПОЗДРАВЛЯЕМ!',
|
||||||
'win.message': 'Вы решили головоломку!',
|
'win.message': 'Вы решили головоломку!',
|
||||||
'win.time': 'Время:',
|
'win.time': 'Время:',
|
||||||
|
'win.difficulty': 'Сложность:',
|
||||||
|
'win.usedGuide': 'Подсказок использовано: {count}',
|
||||||
'win.playAgain': 'Сыграть снова',
|
'win.playAgain': 'Сыграть снова',
|
||||||
'win.shareTitle': 'Поделитесь результатом',
|
'win.shareTitle': 'Поделитесь результатом',
|
||||||
'win.shareText': 'Я решил(а) нонограмму {size}x{size} за {time}!',
|
'win.shareText': 'Я решил(а) нонограмму {size}x{size} за {time}!',
|
||||||
@@ -954,9 +998,17 @@ const messages = {
|
|||||||
'custom.cancel': 'Abbrechen',
|
'custom.cancel': 'Abbrechen',
|
||||||
'custom.start': 'Start',
|
'custom.start': 'Start',
|
||||||
'custom.sizeError': 'Die Größe muss zwischen 5 und 80 liegen!',
|
'custom.sizeError': 'Die Größe muss zwischen 5 und 80 liegen!',
|
||||||
|
'custom.fillRate': 'Füllrate',
|
||||||
|
'custom.difficulty': 'Schwierigkeit',
|
||||||
|
'difficulty.easy': 'Einfach',
|
||||||
|
'difficulty.harder': 'Schwerer',
|
||||||
|
'difficulty.hardest': 'Am schwersten',
|
||||||
|
'difficulty.extreme': 'Extrem',
|
||||||
'win.title': 'HERZLICHEN GLÜCKWUNSCH!',
|
'win.title': 'HERZLICHEN GLÜCKWUNSCH!',
|
||||||
'win.message': 'Sie haben das Rätsel gelöst!',
|
'win.message': 'Sie haben das Rätsel gelöst!',
|
||||||
'win.time': 'Zeit:',
|
'win.time': 'Zeit:',
|
||||||
|
'win.difficulty': 'Schwierigkeit:',
|
||||||
|
'win.usedGuide': 'Hilfe benutzt: {count}',
|
||||||
'win.playAgain': 'Erneut spielen',
|
'win.playAgain': 'Erneut spielen',
|
||||||
'win.shareTitle': 'Teilen Sie Ihr Ergebnis',
|
'win.shareTitle': 'Teilen Sie Ihr Ergebnis',
|
||||||
'win.shareText': 'Ich habe ein {size}x{size} Nonogramm in {time} gelöst!',
|
'win.shareText': 'Ich habe ein {size}x{size} Nonogramm in {time} gelöst!',
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ export function useSolver() {
|
|||||||
} else if (type === 'done') {
|
} else if (type === 'done') {
|
||||||
isProcessing.value = false;
|
isProcessing.value = false;
|
||||||
pause();
|
pause();
|
||||||
|
} else if (type === 'stuck') {
|
||||||
|
isProcessing.value = false;
|
||||||
|
pause();
|
||||||
} else {
|
} else {
|
||||||
isProcessing.value = false;
|
isProcessing.value = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
const playerGrid = ref([]); // 0: empty, 1: filled, 2: cross
|
const playerGrid = ref([]); // 0: empty, 1: filled, 2: cross
|
||||||
const isGameWon = ref(false);
|
const isGameWon = ref(false);
|
||||||
const hasUsedGuide = ref(false);
|
const hasUsedGuide = ref(false);
|
||||||
|
const guideUsageCount = ref(0);
|
||||||
|
const currentDifficulty = ref(null); // 'easy', 'medium', 'hard', 'custom' or object { density: 0.5 }
|
||||||
|
const currentDensity = ref(0);
|
||||||
const size = ref(5);
|
const size = ref(5);
|
||||||
const startTime = ref(null);
|
const startTime = ref(null);
|
||||||
const elapsedTime = ref(0);
|
const elapsedTime = ref(0);
|
||||||
@@ -118,6 +121,8 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
resetGrid();
|
resetGrid();
|
||||||
isGameWon.value = false;
|
isGameWon.value = false;
|
||||||
hasUsedGuide.value = false;
|
hasUsedGuide.value = false;
|
||||||
|
guideUsageCount.value = 0;
|
||||||
|
currentDensity.value = totalCellsToFill.value / (size.value * size.value);
|
||||||
elapsedTime.value = 0;
|
elapsedTime.value = 0;
|
||||||
startTimer();
|
startTimer();
|
||||||
saveState();
|
saveState();
|
||||||
@@ -134,8 +139,11 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
resetGrid();
|
resetGrid();
|
||||||
isGameWon.value = false;
|
isGameWon.value = false;
|
||||||
hasUsedGuide.value = false;
|
hasUsedGuide.value = false;
|
||||||
|
guideUsageCount.value = 0;
|
||||||
|
currentDensity.value = density;
|
||||||
elapsedTime.value = 0;
|
elapsedTime.value = 0;
|
||||||
startTimer();
|
startTimer();
|
||||||
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetGrid() {
|
function resetGrid() {
|
||||||
@@ -243,6 +251,8 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
playerGrid: playerGrid.value,
|
playerGrid: playerGrid.value,
|
||||||
isGameWon: isGameWon.value,
|
isGameWon: isGameWon.value,
|
||||||
hasUsedGuide: hasUsedGuide.value,
|
hasUsedGuide: hasUsedGuide.value,
|
||||||
|
guideUsageCount: guideUsageCount.value,
|
||||||
|
currentDensity: currentDensity.value,
|
||||||
elapsedTime: elapsedTime.value,
|
elapsedTime: elapsedTime.value,
|
||||||
moves: moves.value,
|
moves: moves.value,
|
||||||
history: history.value
|
history: history.value
|
||||||
@@ -260,6 +270,9 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
solution.value = parsed.solution;
|
solution.value = parsed.solution;
|
||||||
playerGrid.value = parsed.playerGrid;
|
playerGrid.value = parsed.playerGrid;
|
||||||
isGameWon.value = parsed.isGameWon;
|
isGameWon.value = parsed.isGameWon;
|
||||||
|
hasUsedGuide.value = parsed.hasUsedGuide || false;
|
||||||
|
guideUsageCount.value = parsed.guideUsageCount || 0;
|
||||||
|
currentDensity.value = parsed.currentDensity || 0;
|
||||||
elapsedTime.value = parsed.elapsedTime || 0;
|
elapsedTime.value = parsed.elapsedTime || 0;
|
||||||
moves.value = parsed.moves || 0;
|
moves.value = parsed.moves || 0;
|
||||||
history.value = parsed.history || [];
|
history.value = parsed.history || [];
|
||||||
@@ -287,6 +300,7 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
resetGrid();
|
resetGrid();
|
||||||
isGameWon.value = false;
|
isGameWon.value = false;
|
||||||
hasUsedGuide.value = false;
|
hasUsedGuide.value = false;
|
||||||
|
guideUsageCount.value = 0;
|
||||||
elapsedTime.value = 0;
|
elapsedTime.value = 0;
|
||||||
startTimer();
|
startTimer();
|
||||||
saveState();
|
saveState();
|
||||||
@@ -298,6 +312,7 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
function markGuideUsed() {
|
function markGuideUsed() {
|
||||||
if (isGameWon.value) return;
|
if (isGameWon.value) return;
|
||||||
hasUsedGuide.value = true;
|
hasUsedGuide.value = true;
|
||||||
|
guideUsageCount.value++;
|
||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,6 +341,8 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
undo,
|
undo,
|
||||||
closeWinModal,
|
closeWinModal,
|
||||||
hasUsedGuide,
|
hasUsedGuide,
|
||||||
|
guideUsageCount,
|
||||||
|
currentDensity,
|
||||||
markGuideUsed
|
markGuideUsed
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -51,3 +51,25 @@ export function generateRandomGrid(size, density = 0.5) {
|
|||||||
}
|
}
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function calculateDifficulty(density) {
|
||||||
|
// 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';
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const messages = {
|
|||||||
'worker.solved': 'Rozwiązane!',
|
'worker.solved': 'Rozwiązane!',
|
||||||
'worker.logicRow': 'Logika: Wiersz {row}, Kolumna {col} -> {state}',
|
'worker.logicRow': 'Logika: Wiersz {row}, Kolumna {col} -> {state}',
|
||||||
'worker.logicCol': 'Logika: Kolumna {col}, Wiersz {row} -> {state}',
|
'worker.logicCol': 'Logika: Kolumna {col}, Wiersz {row} -> {state}',
|
||||||
'worker.guess': 'Zgadywanie: Wiersz {row}, Kolumna {col}',
|
'worker.stuck': 'Brak logicznego ruchu. Spróbuj zgadnąć lub cofnąć.',
|
||||||
'worker.done': 'Koniec!',
|
'worker.done': 'Koniec!',
|
||||||
'worker.state.filled': 'Pełne',
|
'worker.state.filled': 'Pełne',
|
||||||
'worker.state.empty': 'Puste'
|
'worker.state.empty': 'Puste'
|
||||||
@@ -14,7 +14,7 @@ const messages = {
|
|||||||
'worker.solved': 'Solved!',
|
'worker.solved': 'Solved!',
|
||||||
'worker.logicRow': 'Logic: Row {row}, Column {col} -> {state}',
|
'worker.logicRow': 'Logic: Row {row}, Column {col} -> {state}',
|
||||||
'worker.logicCol': 'Logic: Column {col}, Row {row} -> {state}',
|
'worker.logicCol': 'Logic: Column {col}, Row {row} -> {state}',
|
||||||
'worker.guess': 'Guessing: Row {row}, Column {col}',
|
'worker.stuck': 'No logical move found. Try guessing or undoing.',
|
||||||
'worker.done': 'Done!',
|
'worker.done': 'Done!',
|
||||||
'worker.state.filled': 'Filled',
|
'worker.state.filled': 'Filled',
|
||||||
'worker.state.empty': 'Empty'
|
'worker.state.empty': 'Empty'
|
||||||
@@ -236,29 +236,9 @@ const handleStep = (playerGrid, solution, locale) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let r = 0; r < size; r++) {
|
// Check for guess logic - we want to avoid this unless strictly necessary
|
||||||
for (let c = 0; c < size; c++) {
|
// If no logic move found, return 'stuck' instead of cheating
|
||||||
const current = playerGrid[r][c];
|
return { type: 'stuck', statusText: t(locale, 'worker.stuck') };
|
||||||
const target = solution[r][c];
|
|
||||||
let isCorrect = false;
|
|
||||||
if (target === 1 && current === 1) isCorrect = true;
|
|
||||||
if (target === 0 && current === 2) isCorrect = true;
|
|
||||||
if (target === 0 && current === 0) isCorrect = false;
|
|
||||||
if (target === 1 && current === 0) isCorrect = false;
|
|
||||||
if (!isCorrect) {
|
|
||||||
const newState = target === 1 ? 1 : 2;
|
|
||||||
return {
|
|
||||||
type: 'move',
|
|
||||||
r,
|
|
||||||
c,
|
|
||||||
state: newState,
|
|
||||||
statusText: t(locale, 'worker.guess', { row: r + 1, col: c + 1 })
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { type: 'done', statusText: t(locale, 'worker.done') };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.onmessage = (event) => {
|
self.onmessage = (event) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user