From 73056fb8d2d39ce54b377fa41c6e39e2b11ecdee Mon Sep 17 00:00:00 2001 From: 63db3122f0950a2aef64df95 <63db3122f0950a2aef64df95@devide> Date: Mon, 3 Jul 2023 07:19:00 +0000 Subject: [PATCH] Mon Jul 3 07:19:00 UTC 2023 inscode --- src/utils/index.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index a224a2e..a1b0998 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -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; } -- GitLab