diff --git a/src/utils/index.js b/src/utils/index.js index 5a1d48a52127d868faf1441fb0775e8f6a892253..8e2a44c0d700abba483f72f1ef14717d4099ca17 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -83,7 +83,7 @@ export function robotPlay(board, robot, win_size) { // 评估每个空位置的价值,从八个方向去计算 score = directions.reduce((r, [y, x]) => { - const square = getDirectionScore(board, row, col, [y, x], win_size, is_black) + getDirectionScore(board, row, col, [y * -1, x * -1], win_size, is_black) + const square = getDirectionScore(board, row, col, [y, x], win_size) + getDirectionScore(board, row, col, [y * -1, x * -1], win_size) return r + (10 ** square) }, 0) @@ -135,14 +135,14 @@ function getBoundary(size, num) { * @param {*} piece_type * @returns */ -function getDirectionScore(board, row, col, [y, x], win_size, piece_type) { +function getDirectionScore(board, row, col, [y, x], win_size) { const ROW = board.length const COL = board[0].length let res = 0 let _row = row + y let _col = col + x while (true) { - if (_row < 0 || _col < 0 || !board[_row] || board[_row][_col] !== piece_type) { + if (_row < 0 || _col < 0 || !board[_row] || board[_row][_col] !== is_black) { break; } res += 1