Viewing readonly version: 63View latest version
Script
999
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
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import ReactDOM from "https://esm.sh/react-dom@18.2.0";
import React, { useState } from "https://esm.sh/react@18.2.0";
const GridGame = () => {
const initialGrid = Array(10).fill().map((_, rowIndex) =>
Array(10).fill().map((_, colIndex) => rowIndex === 4 && colIndex === 4 ? true : false)
);
const [grid, setGrid] = useState(initialGrid);
const [error, setError] = useState(null);
const isValidCell = (row, col) => {
return row >= 0 && row < 10 && col >= 0 && col < 10;
};
const hasAdjacentGreen = (row, col) => {
const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];
return directions.some(([dx, dy]) => {
const newRow = row + dx;
const newCol = col + dy;
return isValidCell(newRow, newCol) && grid[newRow][newCol];
});
};
const getEdgeBorders = (row, col) => {
if (!grid[row][col]) return "";
const borders = [];
const directions = [
["top", -1, 0],
["right", 0, 1],
["bottom", 1, 0],
["left", 0, -1],
];
H
game