Mon Jul 3 08:49:00 UTC 2023 inscode

上级 fa3f6429
......@@ -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) {
......
......@@ -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)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册