提交 eea4f3d7 编写于 作者: U u014301111

Sat Jul 29 04:55:00 CST 2023 inscode

上级 29e5eed7
...@@ -57,7 +57,6 @@ function aroundIsEmpty({ ROW, COL, OBJ }, y, x) { ...@@ -57,7 +57,6 @@ function aroundIsEmpty({ ROW, COL, OBJ }, y, x) {
} }
} }
} }
return res_arr === 0 return res_arr === 0
} }
...@@ -78,36 +77,25 @@ export function checkWin({ row, col, board, player, win_size }) { ...@@ -78,36 +77,25 @@ export function checkWin({ row, col, board, player, win_size }) {
for (let i = 0; i < directions.length; i++) { for (let i = 0; i < directions.length; i++) {
res = [[row, col]]; res = [[row, col]];
const [dy, dx] = directions[i]; for (let j = -1; j < 3; j += 2) {
let x = col + dx;
let y = row + dy;
// 向正反两个方向扩展,检查是否有连续的五个相同棋子
while (inRange(x, COL) && inRange(y, ROW) && board[y][x] === player) {
res.push([y, x])
x += dx;
y += dy;
}
// 出现五连珠,返回胜利 const [dy, dx] = directions[i];
if (res.length >= win_size) { let x = col + dx * j;
return res; let y = row + dy * j;
}
x = col - dx; // 向正反两个方向扩展,检查是否有连续的五个相同棋子
y = row - dy; while (inRange(x, COL) && inRange(y, ROW) && board[y][x] === player) {
while (inRange(x, COL) && inRange(y, ROW) && board[y][x] === player) { res.push([y, x])
res.push([y, x]) x += dx * j;
x -= dx; y += dy * j;
y -= dy; }
}
// 出现五连珠,返回胜利 // 出现五连珠,返回胜利
if (res.length >= win_size) { if (res.length >= win_size) {
return res; return res;
}
} }
} }
// 当前空位,可以结成多少颗连珠
return false; return false;
} }
...@@ -176,6 +164,7 @@ export function robotPlay(board, win_size) { ...@@ -176,6 +164,7 @@ export function robotPlay(board, win_size) {
if (max_scores_arr.length === 1) { if (max_scores_arr.length === 1) {
res_key = Object.keys(max_scores_arr[0])[0] res_key = Object.keys(max_scores_arr[0])[0]
} else if (max_scores_arr.length > 1) { } else if (max_scores_arr.length > 1) {
// 多个相同的分数的,随机选择一个
const random_index = Math.floor(Math.random() * max_scores_arr.length) const random_index = Math.floor(Math.random() * max_scores_arr.length)
res_key = Object.keys(max_scores_arr[random_index])[0] res_key = Object.keys(max_scores_arr[random_index])[0]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册