Fri Jun 30 10:56:00 UTC 2023 inscode

上级 73674f09
......@@ -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)
......
......@@ -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)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册