From 28bba002fc8f99df9f201d2f0eae5e230485ed60 Mon Sep 17 00:00:00 2001 From: 63db3122f0950a2aef64df95 <63db3122f0950a2aef64df95@devide> Date: Fri, 30 Jun 2023 10:56:00 +0000 Subject: [PATCH] Fri Jun 30 10:56:00 UTC 2023 inscode --- src/App.vue | 2 +- src/utils/index.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/App.vue b/src/App.vue index a8c3d8b..106a6e2 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 5fc802a..5afa4fc 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) } -- GitLab