{memoryPhase ? "Remember all the mines!" : "Mark all the mines!"}
{minefield.map((line, y) => (
{line.map((cell, x) => {
if (memoryPhase) {
if (minefield[y][x]) return [?] ;
return [ ] ;
} else {
if (x == pos[0] && y == pos[1]) return [X] ;
if (answer[y][x]) return [.] ;
if (hasAugment && minefield[y][x]) return [?] ;
return [ ] ;
}
})}
))}
>
);
}
function fieldEquals(a: boolean[][], b: boolean[][]): boolean {
function count(field: boolean[][]): number {
return field.flat().reduce((a, b) => a + (b ? 1 : 0), 0);
}
return count(a) === count(b);
}
function generateEmptyField(difficulty: Difficulty): boolean[][] {
const field = [];
for (let i = 0; i < difficulty.height; i++) {
field.push(new Array(Math.round(difficulty.width)).fill(false));
}
return field;
}
function generateMinefield(difficulty: Difficulty): boolean[][] {
const field = generateEmptyField(difficulty);
for (let i = 0; i < difficulty.mines; i++) {
const x = Math.floor(Math.random() * field.length);
const y = Math.floor(Math.random() * field[0].length);
if (field[x][y]) {
i--;
continue;
}
field[x][y] = true;
}
return field;
}