refactor: optimize solver to use pure logic without guessing

This commit is contained in:
2026-02-10 23:13:14 +01:00
parent bfb24cfb03
commit 8e0ddf3a72
5 changed files with 37 additions and 37 deletions

View File

@@ -2,6 +2,7 @@
import { ref, computed } from 'vue';
import { usePuzzleStore } from '@/stores/puzzle';
import { useI18n } from '@/composables/useI18n';
import { calculateDifficulty } from '@/utils/puzzleUtils';
const emit = defineEmits(['close']);
const store = usePuzzleStore();
@@ -21,13 +22,7 @@ const handleSnap = () => {
};
const difficultyLevel = computed(() => {
const rate = fillRate.value;
const dist = Math.abs(rate - 50);
if (dist <= 5) return 'extreme';
if (dist <= 15) return 'hardest';
if (dist <= 25) return 'harder';
return 'easy';
return calculateDifficulty(fillRate.value / 100);
});
const difficultyColor = computed(() => {

View File

@@ -7,6 +7,7 @@ import { useTimer } from '@/composables/useTimer';
import xIcon from '@/assets/brands/x.svg';
import facebookIcon from '@/assets/brands/facebook.svg';
import whatsappIcon from '@/assets/brands/whatsapp.svg';
import { calculateDifficulty } from '@/utils/puzzleUtils';
const store = usePuzzleStore();
const { t } = useI18n();
@@ -113,12 +114,11 @@ const buildShareCanvas = () => {
// Difficulty & Density Info
const densityPercent = Math.round(store.currentDensity * 100);
const dist = Math.abs(densityPercent - 50);
let difficultyKey = 'easy';
const difficultyKey = calculateDifficulty(store.currentDensity);
let diffColor = '#33ff33';
if (dist <= 5) { difficultyKey = 'extreme'; diffColor = '#ff3333'; }
else if (dist <= 15) { difficultyKey = 'hardest'; diffColor = '#ff9933'; }
else if (dist <= 25) { difficultyKey = 'harder'; diffColor = '#ffff33'; }
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';