You need to sign in or sign up before continuing.
提交 50a3b7d5 编写于 作者: U u014301111

Sat Aug 12 19:03:00 CST 2023 inscode

上级 54166b14
......@@ -10,6 +10,7 @@ const win_size = ref(5)
const lattices = ref([])
// 下起记录
const records = ref([])
// 赢棋的下标
let isWin = []
const time = ref(Date.now())
......@@ -79,9 +80,12 @@ async function playChess(item, row, col) {
console.timeEnd('playChess')
}
onMounted(async () => {
return;
const autoPlay = async () => {
await sleep()
confirm()
setPiece([(size.value / 2) | 0, (size.value / 2) | 0], is_black)
while (true) {
console.log(1)
if (records.value.length == size.value * size.value) {
break;
}
......@@ -89,9 +93,9 @@ onMounted(async () => {
// 机器人下棋
const [y, x] = robotPlay(lattices.value, win_size.value)
setPiece([y, x], is_black)
setPiece([y, x], is_white)
const test_black = checkWin({ row: y, col: x, board: lattices.value, player: is_black, win_size: win_size.value })
const test_black = checkWin({ row: y, col: x, board: lattices.value, player: is_white, win_size: win_size.value })
if (test_black) {
isWin = test_black
break;
......@@ -101,9 +105,9 @@ onMounted(async () => {
// 机器人下棋
const [row, col] = robotPlay(lattices.value, win_size.value)
setPiece([row, col], is_white)
setPiece([row, col], is_black)
const test_white = checkWin({ row, col, board: lattices.value, player: is_white, win_size: win_size.value })
const test_white = checkWin({ row, col, board: lattices.value, player: is_black, win_size: win_size.value })
if (test_white) {
isWin = test_white
break;
......@@ -111,7 +115,7 @@ onMounted(async () => {
await sleep()
}
})
}
</script>
<template>
......@@ -125,6 +129,7 @@ onMounted(async () => {
<input v-model="win_size" id="win_size" type="number" min="3" max="8">
</p>
<button @click="confirm" whitespace-nowrap mr-6px px-6px>重新开始</button>
<button @click="autoPlay" whitespace-nowrap mr-6px px-6px>自动下棋</button>
<button @click="back" whitespace-nowrap px-6px>返回上一步</button>
</div>
<div p-6px box-border flex flex-col items-center border="t t-solid #999">
......
......@@ -14,7 +14,7 @@ export const directions = [
[1, -1] // / 方向
]
export const sleep = (tim = 200) => {
export const sleep = (tim = 500) => {
return new Promise(res => {
setTimeout(res, tim);
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册