Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
aa152147
五子棋
提交
483e543d
五
五子棋
项目概览
aa152147
/
五子棋
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
43
Fork
23
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
五
五子棋
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
483e543d
编写于
7月 03, 2023
作者:
6
63db3122f0950a2aef64df95
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Mon Jul 3 23:02:00 UTC 2023 inscode
上级
f2ad4e03
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
33 deletion
+47
-33
src/App.vue
src/App.vue
+30
-14
src/assets/base.css
src/assets/base.css
+10
-0
src/assets/main.css
src/assets/main.css
+2
-2
src/utils/index.js
src/utils/index.js
+5
-17
未找到文件。
src/App.vue
浏览文件 @
483e543d
<
script
setup
>
<
script
setup
>
import
{
onMounted
,
ref
}
from
"
vue
"
import
{
onMounted
,
ref
,
computed
}
from
"
vue
"
import
{
is_empty
,
checkWin
,
is_black
,
is_white
,
robotPlay
}
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
)
// 棋盘
const
lattices
=
ref
([])
const
lattices
=
ref
([])
const
is_load
=
ref
(
false
)
// 下起记录
const
records
=
ref
([])
// 5 连珠的下标
// 5 连珠的下标
let
isWin
=
[]
let
isWin
=
[]
const
records_obj
=
computed
(()
=>
{
return
records
.
value
.
reduce
((
r
,
{
location
,
type
})
=>
{
const
[
y
,
x
]
=
location
||
[]
const
_win
=
isWin
.
map
(([
r
,
c
])
=>
`
${
r
}
_
${
c
}
`
).
includes
(
`
${
y
}
_
${
x
}
`
)
return
{
...
r
,
[
`
${
y
}
_
${
x
}
`
]:
_win
?
'
isWin
'
:
type
}
},
{})
})
onMounted
(
confirm
)
onMounted
(
confirm
)
...
@@ -16,12 +28,22 @@ function confirm() {
...
@@ -16,12 +28,22 @@ function confirm() {
isWin
=
[]
isWin
=
[]
lattices
.
value
=
Array
(
size
.
value
).
fill
([]).
map
(()
=>
Array
(
size
.
value
).
fill
(
is_empty
))
lattices
.
value
=
Array
(
size
.
value
).
fill
([]).
map
(()
=>
Array
(
size
.
value
).
fill
(
is_empty
))
}
}
function
back
(){
Array
(
2
)
}
function
setPiece
([
y
,
x
],
type
){
records
.
value
.
push
({
location
:
[
y
,
x
],
type
:
type
})
lattices
.
value
[
y
][
x
]
=
type
}
async
function
playChess
(
item
,
row
,
col
)
{
async
function
playChess
(
item
,
row
,
col
)
{
if
(
is_load
.
value
)
return
if
(
isWin
.
length
||
item
!==
is_empty
)
return
if
(
isWin
.
length
||
item
!==
is_empty
)
return
// 玩家下棋
// 玩家下棋
lattices
.
value
[
row
][
col
]
=
is_black
setPiece
([
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
})
if
(
test
)
{
if
(
test
)
{
isWin
=
test
isWin
=
test
...
@@ -29,20 +51,13 @@ async function playChess(item, row, col) {
...
@@ -29,20 +51,13 @@ async function playChess(item, row, col) {
}
}
// 机器人下棋
// 机器人下棋
const
[
y
,
x
]
=
robotPlay
(
lattices
.
value
,
is_white
,
win_size
.
value
)
const
[
y
,
x
]
=
robotPlay
(
lattices
.
value
,
is_white
,
win_size
.
value
)
lattices
.
value
[
y
][
x
]
=
is_white
setPiece
([
y
,
x
],
is_white
)
const
testRobo
=
checkWin
({
row
:
y
,
col
:
x
,
board
:
lattices
.
value
,
player
:
is_white
,
win_size
:
win_size
.
value
})
const
testRobo
=
checkWin
({
row
:
y
,
col
:
x
,
board
:
lattices
.
value
,
player
:
is_white
,
win_size
:
win_size
.
value
})
if
(
testRobo
)
{
if
(
testRobo
)
{
isWin
=
testRobo
isWin
=
testRobo
}
}
}
}
function
getStyle
(
item
,
row
,
col
)
{
if
(
isWin
.
length
)
{
return
isWin
.
map
(([
r
,
c
])
=>
`
${
r
}
_
${
c
}
`
).
includes
(
`
${
row
}
_
${
col
}
`
)
?
'
isWin
'
:
item
}
return
item
}
</
script
>
</
script
>
<
template
>
<
template
>
...
@@ -56,10 +71,11 @@ function getStyle(item, row, col) {
...
@@ -56,10 +71,11 @@ function getStyle(item, row, col) {
<input
v-model=
"win_size"
id=
"win_size"
type=
"number"
min=
"3"
max=
"8"
>
<input
v-model=
"win_size"
id=
"win_size"
type=
"number"
min=
"3"
max=
"8"
>
</p>
</p>
<button
@
click=
"confirm"
class=
"space-nowrap"
>
重新开始
</button>
<button
@
click=
"confirm"
class=
"space-nowrap"
>
重新开始
</button>
<button
@
click=
"back"
class=
"space-nowrap"
>
返回上一步
</button>
</div>
</div>
<div
class=
"content border-top content-lattice"
>
<div
class=
"content border-top content-lattice"
>
<p
class=
"row"
v-for=
"(lattice, r_i) in lattices"
:key=
"r_i"
>
<p
class=
"row"
v-for=
"(lattice, r_i) in lattices"
:key=
"r_i"
>
<p
class=
"col"
:class=
"
getStyle(item, r_i, c_i)
"
v-for=
"(item, c_i) in lattice"
:key=
"`$
{r_i}-${c_i}`"
<p
class=
"col"
:class=
"
records_obj[`$
{r_i}_${c_i}`]
" v-for="(item, c_i) in lattice" :key="`${r_i}-${c_i}`"
@click="playChess(item, r_i, c_i)">
@click="playChess(item, r_i, c_i)">
</p>
</p>
</p>
</p>
...
...
src/assets/base.css
浏览文件 @
483e543d
...
@@ -4,6 +4,10 @@
...
@@ -4,6 +4,10 @@
--vt-c-white-soft
:
#f8f8f8
;
--vt-c-white-soft
:
#f8f8f8
;
--vt-c-white-mute
:
#f2f2f2
;
--vt-c-white-mute
:
#f2f2f2
;
--vt-c-red
:
#ff0000
;
--vt-c-red-soft
:
#f80808
;
--vt-c-red-mute
:
#f20202
;
--vt-c-black
:
#181818
;
--vt-c-black
:
#181818
;
--vt-c-black-soft
:
#222222
;
--vt-c-black-soft
:
#222222
;
--vt-c-black-mute
:
#282828
;
--vt-c-black-mute
:
#282828
;
...
@@ -36,6 +40,9 @@
...
@@ -36,6 +40,9 @@
--color-text
:
var
(
--vt-c-text-light-1
);
--color-text
:
var
(
--vt-c-text-light-1
);
--section-gap
:
160px
;
--section-gap
:
160px
;
--p-border-color
:
var
(
--vt-c-black
);
--p-win-border-color
:
var
(
--vt-c-red
);
}
}
@media
(
prefers-color-scheme
:
dark
)
{
@media
(
prefers-color-scheme
:
dark
)
{
...
@@ -49,6 +56,9 @@
...
@@ -49,6 +56,9 @@
--color-heading
:
var
(
--vt-c-text-dark-1
);
--color-heading
:
var
(
--vt-c-text-dark-1
);
--color-text
:
var
(
--vt-c-text-dark-2
);
--color-text
:
var
(
--vt-c-text-dark-2
);
--p-border-color
:
var
(
--vt-c-white
);
--p-win-border-color
:
var
(
--vt-c-white
);
}
}
}
}
...
...
src/assets/main.css
浏览文件 @
483e543d
...
@@ -113,12 +113,12 @@ input {
...
@@ -113,12 +113,12 @@ input {
.isBlack
::after
{
.isBlack
::after
{
background-color
:
black
;
background-color
:
black
;
border-color
:
black
;
border-color
:
var
(
--p-border-color
)
;
}
}
.isWin
::after
{
.isWin
::after
{
background-color
:
red
;
background-color
:
red
;
border-color
:
red
;
border-color
:
var
(
--p-win-border-color
)
;
}
}
.space-nowrap
{
.space-nowrap
{
...
...
src/utils/index.js
浏览文件 @
483e543d
...
@@ -81,8 +81,11 @@ export function robotPlay(board, robot, win_size) {
...
@@ -81,8 +81,11 @@ export function robotPlay(board, robot, win_size) {
let
score
=
0
;
let
score
=
0
;
const
[
row
,
col
]
=
point
;
const
[
row
,
col
]
=
point
;
// 这里要应该是要返回这个位置的分数
// 评估每个空位置的价值,从八个方向去计算
score
=
estimateScore
({
row
,
col
,
board
,
win_size
})
score
=
directions
.
reduce
((
r
,
[
y
,
x
])
=>
{
const
square
=
getDirectionScore
(
board
,
row
,
col
,
[
y
,
x
],
win_size
,
is_black
)
+
getDirectionScore
(
board
,
row
,
col
,
[
y
*
-
1
,
x
*
-
1
],
win_size
,
is_black
)
return
r
+
(
10
**
square
)
},
0
)
// 选取分数最高的空位
// 选取分数最高的空位
if
(
score
>=
maxScore
)
{
if
(
score
>=
maxScore
)
{
...
@@ -150,18 +153,3 @@ function getDirectionScore(board, row, col, [y, x], win_size, piece_type) {
...
@@ -150,18 +153,3 @@ function getDirectionScore(board, row, col, [y, x], win_size, piece_type) {
return
res
return
res
}
}
/**
* 评估每个空位置的价值,从八个方向去计算,
* 计分规则 1,10,100,1000,10000,100000 根据棋子数量计分,每多一颗棋子,分数乘以10
* @param {object} Estimate
* @param {object} Estimate.board
* @param {number} Estimate.row
* @param {number} Estimate.col
* @return {number}
*/
function
estimateScore
({
board
,
row
,
col
,
win_size
})
{
return
directions
.
reduce
((
r
,
[
y
,
x
])
=>
{
const
square
=
getDirectionScore
(
board
,
row
,
col
,
[
y
,
x
],
win_size
,
is_black
)
+
getDirectionScore
(
board
,
row
,
col
,
[
y
*
-
1
,
x
*
-
1
],
win_size
,
is_black
)
return
r
+
(
10
**
square
)
},
0
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录