Sun Jun 25 08:36:00 UTC 2023 inscode

上级 79930569
......@@ -22,22 +22,22 @@ function confirm() {
function playChess(item, r_i, c_i) {
if (isWin.length || item) return
lattices.value[r_i][c_i] = 'isBlack'
const test = checkWin(r_i, 'isBlack')
const test = checkWin(r_i, c_i, lattices.value)
if (test) {
console.log(test)
isWin = test
} else {
robotMove()
}
}
function robotMove() {
const [bestRow, bestCol] = findBestMove(lattices.value, "isWhite");
lattices.value[bestRow][bestCol] = "isWhite";
console.log(bestRow, bestCol)
// lattices.value[bestRow][bestCol] = "isWhite";
const testRobot = checkWin(lattices.value, "isWhite")
/* const testRobot = checkWin(lattices.value)
if (testRobot) {
isWin = testRobot
}
} */
}
......
export function checkWin(row, col, pieceType, board) {
const boardSize = board.length;
export function checkWin(row, col, board) {
const _row = board.length;
const _col = board[0].length
const pieceType = board[row][col]
const directions = [
[1, 0], // 水平方向
......@@ -16,7 +18,7 @@ export function checkWin(row, col, pieceType, board) {
let y = col + dy;
// 向正反两个方向扩展,检查是否有连续的五个相同棋子
while (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] === pieceType) {
while (x >= 0 && x < _row && y >= 0 && y < _col && board[x][y] === pieceType) {
count++;
x += dx;
y += dy;
......@@ -24,7 +26,7 @@ export function checkWin(row, col, pieceType, board) {
x = row - dx;
y = col - dy;
while (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] === pieceType) {
while (x >= 0 && x < _row && y >= 0 && y < _col && board[x][y] === pieceType) {
count++;
x -= dx;
y -= dy;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册