Viewing readonly version: 101View latest version
HTTP
99
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
let grid = Array(10).fill().map((_, rowIndex) =>
Array(10).fill().map((_, colIndex) => rowIndex === 4 && colIndex === 4 ? true : false)
);
const online: Map<string, number> = new Map();
const getOnline = (id: string) => {
if (!online.has(id)) {
for (const [key, value] of online) {
if (value + 60 * 1000 < Date.now()) {
online.delete(key);
}
}
online.set(id, Date.now());
}
return online.size;
};
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
if (req.method == "POST" && url.pathname == "/api/board") {
const { clickedCell }: { grid: boolean[][]; clickedCell: { row: number; col: number } } = await req
.json();
const { row, col } = clickedCell;
const isValidCell = (row: number, col: number) => {
return row >= 0 && row < 10 && col >= 0 && col < 10;
};
const countGreenSquares = () => {
return grid.reduce((sum, row) => sum + row.reduce((rowSum, cell) => rowSum + (cell ? 1 : 0), 0), 0);
};
const hasAdjacentGreen = (row: number, col: number) => {
const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];
return directions.some(([dx, dy]) => {
H
game