diff --git a/src/App.vue b/src/App.vue index a8c3d8b0a9d2b8c17d411f90745b2331888ef524..106a6e218c4300007ee8e231c2387e05f0aa153c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,7 +3,7 @@ import { onMounted, ref } from "vue" import { is_empty, checkWin, is_black, is_white, robotPlay } from "./utils" // import { robotPlay } from './utils/api' // 配置 -const size = ref(3) +const size = ref(20) const win_size = ref(5) const lattices = ref([]) const is_load = ref(false) diff --git a/src/utils/index.js b/src/utils/index.js index 5fc802aacce373c1f0ff18d5bca60e93c67f58e5..5afa4fcdfbb3e57dd61cc30d3c74f325a5b451ea 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -23,7 +23,6 @@ export const directions = [ * @returns */ export function checkWin({ row, col, board, player, win_size, direction }) { - console.log(win_size) const _row = board.length; const _col = board[0].length const pieceType = player ?? board[row][col] @@ -99,7 +98,7 @@ export function robotPlay(board, robot, win_size) { } // 选取分数最高的空位 - if (score > maxScore) { + if (score >= maxScore) { maxScorePos = [row, col]; maxScore = score; } @@ -123,10 +122,10 @@ const direction_8 = [ function getDirectionScore(board, row, col, direction) { let res = 0 const [x, y] = direction - let _row = row - let _col = col + let _row = row + x + let _col = col + y while (true) { - if (board[_row][_col] !== is_black) { + if (_row < 0 || _col < 0 || !board[_row] || board[_row][_col] !== is_black) { return res } res += 1 @@ -145,11 +144,13 @@ function getDirectionScore(board, row, col, direction) { * @return {number} */ function estimateScore({ board, row, col }) { - return direction_8.map((_direction) => { + const arr = direction_8.map((_direction) => { const square = getDirectionScore(board, row, col, _direction) if (square === 0) return square return 10 ** (square - 1) - }).reduce((r, item) => { + }) + + return arr.reduce((r, item) => { return r + item }, 0) }