Mon Jul 3 07:19:00 UTC 2023 inscode

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