Mon Jul 3 07:19:00 UTC 2023 inscode

上级 7d6e1a07
......@@ -4,11 +4,14 @@ export const is_empty = 'isEmpty';
*/
export const is_white = 'isWhite';
export const is_black = 'isBlack';
/**
* [y, x] === [row, col] === [行,列]
*/
export const directions = [
[1, 0], // 水平方向
[0, 1], // 垂直方向
[1, 1], // 右下方向
[1, -1] // 左下方向
[1, 0], // 垂直方向
[0, 1], // 水平方向
[1, 1], // \ 方向
[1, -1] // / 方向
]
/**
......@@ -30,21 +33,21 @@ export function checkWin({ row, col, board, player, win_size }) {
for (let i = 0; i < directions.length; i++) {
res = [[row, col]];
const [dx, dy] = directions[i];
let x = row + dx;
let y = col + dy;
const [dy, dx] = directions[i];
let x = col + dx;
let y = row + dy;
// 向正反两个方向扩展,检查是否有连续的五个相同棋子
while (x >= 0 && x < ROW && y >= 0 && y < COL && board[x][y] === TYPE) {
res.push([x, y])
while (x >= 0 && x < COL && y >= 0 && y < ROW && board[x][y] === TYPE) {
res.push([y, x])
x += dx;
y += dy;
}
x = row - dx;
y = col - dy;
while (x >= 0 && x < ROW && y >= 0 && y < COL && board[x][y] === TYPE) {
res.push([x, y])
x = col - dx;
y = row - dy;
while (x >= 0 && x < COL && y >= 0 && y < ROW && board[x][y] === TYPE) {
res.push([y, x])
x -= dx;
y -= dy;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册