Tue Jul 25 03:03:00 CST 2023 inscode

上级 6dccd644
...@@ -4,7 +4,7 @@ import { is_empty, checkWin, is_black, is_white, robotPlay } from "./utils" ...@@ -4,7 +4,7 @@ import { is_empty, checkWin, is_black, is_white, robotPlay } from "./utils"
import RandomTree from "./components/RandomTree.vue"; import RandomTree from "./components/RandomTree.vue";
// import { robotPlay } from './utils/api' // import { robotPlay } from './utils/api'
// 配置 // 配置
const size = ref(30) const size = ref(20)
const win_size = ref(5) const win_size = ref(5)
// 棋盘 // 棋盘
const lattices = ref([]) const lattices = ref([])
......
...@@ -168,19 +168,22 @@ export function robotPlay(board, win_size) { ...@@ -168,19 +168,22 @@ export function robotPlay(board, win_size) {
*/ */
/** /**
* 获取这一边方向的信息,连珠颗数,延伸出去的空位数 * 获取这一边方向的信息,连珠颗数,延伸出去的空位数。
* 只需要 [空格,空格,棋子,棋子,空格,空格] 这样的数据
* @param {(is_empty|is_white|is_black)[][]} board 棋盘 * @param {(is_empty|is_white|is_black)[][]} board 棋盘
* @param {number} row 行 * @param {number} row 行
* @param {number} col 列 * @param {number} col 列
* @return {{num: number, empty_num: number}} 说明:num: 棋子个数;empty_num: 空格数量 * @return {{num: number, first_empty_num: number, last_empty_num: number}} 说明:num: 棋子个数;empty_num: 空格数量
*/ */
function getJoinInfo(board, row, col, [y, x], player) { function getDirectionsInfo(board, row, col, [y, x], player) {
const ROW = board.length const ROW = board.length
const COL = board[0].length const COL = board[0].length
// 连续棋子数 // 连续棋子数
let num = 0 let num = 0
// 一侧到边缘的空位 // 棋子前面的空格数
let empty_num = 0 let first_empty_num = 0
// 棋子后面的空格数
let last_empty_num = 0
// 不包括当前位置 // 不包括当前位置
let _row = row + y let _row = row + y
let _col = col + x let _col = col + x
...@@ -193,20 +196,22 @@ function getJoinInfo(board, row, col, [y, x], player) { ...@@ -193,20 +196,22 @@ function getJoinInfo(board, row, col, [y, x], player) {
break; break;
} }
// 连珠计数 // 连珠计数
if (!empty_num && item === player) { if (!first_empty_num && item === player) {
num += 1 num += 1
} }
// 计算空位 // 计算棋子前面的空格
if (item === is_empty) { if (item === is_empty) {
empty_num += 1 first_empty_num += 1
} }
// 计算棋子后面的空格数
_row += y _row += y
_col += x _col += x
} }
return { return {
num, num,
empty_num first_empty_num,
last_empty_num
} }
} }
/** /**
...@@ -219,8 +224,8 @@ function getJoinInfo(board, row, col, [y, x], player) { ...@@ -219,8 +224,8 @@ function getJoinInfo(board, row, col, [y, x], player) {
* @returns * @returns
*/ */
function getDirectionScore(board, row, col, [y, x], win_size, player) { function getDirectionScore(board, row, col, [y, x], win_size, player) {
const { num: r_num, empty_num: r_empty_num } = getJoinInfo(board, row, col, [y, x], player) const { num: r_num, first_empty_num: r_empty_num } = getDirectionsInfo(board, row, col, [y, x], player)
const { num: l_num, empty_num: l_empty_num } = getJoinInfo(board, row, col, [y * -1, x * -1], player) const { num: l_num, first_empty_num: l_empty_num } = getDirectionsInfo(board, row, col, [y * -1, x * -1], player)
const SIZE = r_num + l_num const SIZE = r_num + l_num
// 没有棋子 // 没有棋子
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册