Mon Jul 3 10:43:00 UTC 2023 inscode

上级 419eaf90
...@@ -81,21 +81,8 @@ export function robotPlay(board, robot, win_size) { ...@@ -81,21 +81,8 @@ export function robotPlay(board, robot, win_size) {
let score = 0; let score = 0;
const [row, col] = point; const [row, col] = point;
// 判断在此空位上落子后是否获胜 // 这里要应该是要返回这个位置的分数
const win = checkWin({ row, col, board, player: robot, win_size }); score = estimateScore({ row, col, board, win_size })
if (win) {
return [row, col]
} else {
// 判断对手是否能在这一个空位上获胜
const oppWin = checkWin({ row, col, board, player: is_black, win_size });
if (oppWin) {
return [row, col]
} else {
// 这里要应该是要返回这个位置的分数
score = estimateScore({ row, col, board, win_size })
console.log(score)
}
}
// 选取分数最高的空位 // 选取分数最高的空位
if (score >= maxScore) { if (score >= maxScore) {
...@@ -173,7 +160,6 @@ function getDirectionScore(board, row, col, [y, x], win_size, piece_type) { ...@@ -173,7 +160,6 @@ function getDirectionScore(board, row, col, [y, x], win_size, piece_type) {
* @return {number} * @return {number}
*/ */
function estimateScore({ board, row, col, win_size }) { function estimateScore({ board, row, col, win_size }) {
console.log(JSON.stringify(board))
return directions.reduce((r, [y, x]) => { return directions.reduce((r, [y, x]) => {
const square = getDirectionScore(board, row, col, [y, x], win_size, is_black) + getDirectionScore(board, row, col, [y * -1, x * -1], win_size, is_black) const square = getDirectionScore(board, row, col, [y, x], win_size, is_black) + getDirectionScore(board, row, col, [y * -1, x * -1], win_size, is_black)
return r + (10 ** square) return r + (10 ** square)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册