File size: 1,437 Bytes
d9a16d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
};