Thu Jul 6 07:28:00 UTC 2023 inscode

上级 33673ada
......@@ -113,7 +113,7 @@ export function robotPlay(board, win_size) {
// 评估每个空位置的价值,从八个方向去计算
score = directions.reduce((r, [y, x]) => {
const square = getDirectionScore(board, row, col, [y, x], win_size)
return r + (10 ** square)
return r + square
}, 0)
// 选取分数最高的空位
......@@ -182,16 +182,13 @@ function getJoinInfo(board, row, col, [y, x]) {
let _row = row + y
let _col = col + x
while (true) {
if (!inRange(_row, ROW) || !inRange(_col, COL)) {
break;
}
while (inRange(_row, ROW) && inRange(_col, COL)) {
const item = board[_row][_col]
if (item === is_white) {
break;
}
// 连珠计数
if (item === is_black) {
if (!empty_num && item === is_black) {
num += 1
}
// 计算空位数
......@@ -209,7 +206,7 @@ function getJoinInfo(board, row, col, [y, x]) {
}
/**
* 获取一个方向上的棋子数,八个方向
* 根据棋子位置信息,计算分数
* @param {(is_empty|is_white|is_black)[]} board 棋盘
* @param {number} row 行 y
* @param {number} col 列 x
......@@ -218,9 +215,20 @@ function getJoinInfo(board, row, col, [y, x]) {
* @returns
*/
function getDirectionScore(board, row, col, [y, x], win_size) {
let res = 0
const { num: r_num, empty_num: r_empty_num } = getJoinInfo(board, row, col, [y, x])
const { num: l_num, empty_num: l_empty_num } = getJoinInfo(board, row, col, [y * -1, x * -1])
return r_num + l_num
res = r_num + l_num
// 如果是中间断掉的
if (l_empty_num !== 0 && r_empty_num !== 0 && (r_num + l_num) < win_size - 1) {
// 两边都有障碍物
if (r_empty_num === 0 && l_empty_num === 0) {
res = 0
}
}
// 如果位置不够 win_size,要加上当前位置
return 10 ** res
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册