Tue Jun 27 09:39:00 UTC 2023 inscode

上级 80380c1f
<script setup> <script setup>
import { onMounted, ref } from "vue" import { onMounted, ref } from "vue"
import { is_empty, checkWin, is_black, is_white } from "./utils" import { is_empty, checkWin, is_black, is_white, robotPlay } from "./utils"
import { robotPlay } from './utils/api' // import { robotPlay } from './utils/api'
// 配置 // 配置
const size = ref(20) const size = ref(20)
const win_size = ref(5) const win_size = ref(5)
...@@ -22,6 +22,7 @@ async function playChess(item, row, col) { ...@@ -22,6 +22,7 @@ async function playChess(item, row, col) {
if (isWin.length || item !== is_empty) return if (isWin.length || item !== is_empty) return
lattices.value[row][col] = is_black lattices.value[row][col] = is_black
const test = checkWin({ row, col, board: lattices.value, player: is_black, win_size: win_size.value }) const test = checkWin({ row, col, board: lattices.value, player: is_black, win_size: win_size.value })
console.log(test)
if (test) { if (test) {
isWin = test isWin = test
return return
......
...@@ -53,7 +53,7 @@ export function checkWin({ row, col, board, player, win_size, direction }) { ...@@ -53,7 +53,7 @@ export function checkWin({ row, col, board, player, win_size, direction }) {
} }
} }
return false; // 未出现五连珠 return res; // 未出现五连珠
} }
// TODO: 机器人下棋 // TODO: 机器人下棋
...@@ -67,7 +67,6 @@ export function robotPlay(board, player, win_size) { ...@@ -67,7 +67,6 @@ export function robotPlay(board, player, win_size) {
const empty_points = _board.map((item, row) => { const empty_points = _board.map((item, row) => {
return item.flatMap((_item, col) => _item === is_empty ? [[row, col]] : []) return item.flatMap((_item, col) => _item === is_empty ? [[row, col]] : [])
}).flat(1) }).flat(1)
console.log(empty_points)
// 对每个空位进行评分 // 对每个空位进行评分
empty_points.forEach((point) => { empty_points.forEach((point) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册