diff --git a/src/App.vue b/src/App.vue index 9006c2a0e99b6ddcb3a9eca057634004bf22e2dc..67461338cdc396531be5d338352e7bd057c4d34c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -27,9 +27,8 @@ async function playChess(item, row, col) { isWin = test return } - return // 机器人下棋 - const [x, y] = robotPlay(lattices.value, is_white, win_size.value) + const [y, x] = robotPlay(lattices.value, is_white, win_size.value) lattices.value[x][y] = is_white const testRobo = checkWin({ row: x, col: y, board: lattices.value, player: is_white, win_size: win_size.value }) if (testRobo) { diff --git a/src/utils/index.js b/src/utils/index.js index 255f5ff7286c99c5aa38e403385ac57cba7a5f35..f4a91f40c3eb26abc887b1a714121aac41a60529 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -36,7 +36,7 @@ export function checkWin({ row, col, board, player, win_size }) { let y = row + dy; // 向正反两个方向扩展,检查是否有连续的五个相同棋子 - while (x >= 0 && x < COL && y >= 0 && y < ROW && board[x][y] === player) { + while (x >= 0 && x < COL && y >= 0 && y < ROW && board[y][x] === player) { res.push([y, x]) x += dx; y += dy; @@ -44,7 +44,7 @@ export function checkWin({ row, col, board, player, win_size }) { x = col - dx; y = row - dy; - while (x >= 0 && x < COL && y >= 0 && y < ROW && board[x][y] === player) { + while (x >= 0 && x < COL && y >= 0 && y < ROW && board[y][x] === player) { res.push([y, x]) x -= dx; y -= dy; @@ -188,7 +188,7 @@ function getDirectionScore(board, row, col, [x, y], piece_type) { */ function estimateScore({ board, row, col, win_size }) { return direction_4.reduce((r, [p1, p2]) => { - const square = getDirectionScore(board, row, col, p1, win_size, is_white) + getDirectionScore(board, row, col, p2, win_size, is_white) + const square = getDirectionScore(board, row, col, p1, win_size, is_black) + getDirectionScore(board, row, col, p2, win_size, is_black) return r + 10 ** square }, 0) }