| export const formatGridForDisplay = (grid) => { | |
| if (!grid || !Array.isArray(grid)) return []; | |
| return grid.map(row => | |
| row.map(cell => cell === '.' ? '.' : cell.toUpperCase()) | |
| ); | |
| }; | |
| export const validateUserInput = (input) => { | |
| return /^[A-Za-z]?$/.test(input); | |
| }; | |
| export const checkPuzzleCompletion = (grid, userAnswers) => { | |
| if (!grid || !userAnswers) return false; | |
| for (let row = 0; row < grid.length; row++) { | |
| for (let col = 0; col < grid[row].length; col++) { | |
| if (grid[row][col] !== '.') { | |
| const key = `${row}-${col}`; | |
| if (!userAnswers[key] || userAnswers[key] !== grid[row][col]) { | |
| return false; | |
| } | |
| } | |
| } | |
| } | |
| return true; | |
| }; | |
| export const getWordPositions = (grid, clues) => { | |
| const positions = {}; | |
| clues.forEach(clue => { | |
| positions[`${clue.number}-${clue.direction}`] = { | |
| start: clue.position, | |
| length: clue.word.length, | |
| direction: clue.direction | |
| }; | |
| }); | |
| return positions; | |
| }; | |
| export const highlightWord = (wordPositions, selectedClue) => { | |
| if (!selectedClue || !wordPositions[selectedClue]) return []; | |
| const { start, length, direction } = wordPositions[selectedClue]; | |
| const cells = []; | |
| for (let i = 0; i < length; i++) { | |
| if (direction === 'across') { | |
| cells.push(`${start.row}-${start.col + i}`); | |
| } else { | |
| cells.push(`${start.row + i}-${start.col}`); | |
| } | |
| } | |
| return cells; | |
| }; |