Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
aa152147
五子棋
提交
5407e651
五
五子棋
项目概览
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看板
提交
5407e651
编写于
9月 18, 2025
作者:
U
u014301111
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Thu Sep 18 17:36:00 CST 2025 inscode
上级
96f98cfa
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
13 addition
and
10 deletion
+13
-10
src/utils/index.js
src/utils/index.js
+13
-10
未找到文件。
src/utils/index.js
浏览文件 @
5407e651
...
...
@@ -4,6 +4,7 @@ export const is_empty = 'e';
*/
export
const
is_white
=
'
w
'
;
export
const
is_black
=
'
b
'
;
export
const
is_same
=
'
same
'
/**
* [y, x] === [row, col] === [行,列]
*/
...
...
@@ -134,13 +135,13 @@ export function robotPlay(board, win_size) {
}
},
{})
}
// 空位 对每个空位进行评分
// 空位 对每个空位进行评分
,
const
scores
=
board
.
map
((
item
,
row
)
=>
{
return
item
.
flatMap
((
_item
,
col
)
=>
{
if
(
_item
===
is_empty
)
{
if
(
aroundIsEmpty
(
pan_info
,
row
,
col
))
return
[]
// 评估每个空位置的价值,从八个方向去计算
const
score
=
directions
.
reduce
((
r
,
[
y
,
x
])
=>
{
const
_
score
=
directions
.
reduce
((
r
,
[
y
,
x
])
=>
{
r
[
is_black
]
+=
getDirectionScore
(
pan_info
,
row
,
col
,
[
y
,
x
],
win_size
,
is_black
)
r
[
is_white
]
+=
getDirectionScore
(
pan_info
,
row
,
col
,
[
y
,
x
],
win_size
,
is_white
)
return
r
...
...
@@ -148,17 +149,17 @@ export function robotPlay(board, win_size) {
[
is_black
]:
0
,
[
is_white
]:
0
})
const
_b_score
=
score
[
is_black
]
const
_w_score
=
score
[
is_white
]
const
_b_score
=
_
score
[
is_black
]
const
_w_score
=
_
score
[
is_white
]
const
key
=
`
${
row
}
_
${
col
}
_
${
_b_score
===
_w_score
?
is_same
:
_w_score
>
_b_score
?
is_white
:
is_black
}
`
return
[{
[
`
${
row
}
_
${
col
}
`
]:
Math
.
max
(
_b_score
,
_w_score
)
[
key
]:
Math
.
max
(
_b_score
,
_w_score
)
}]
}
return
[]
})
}).
flat
(
1
)
console
.
log
(
scores
)
console
.
log
(
scores
);
// 按分数分组
const
scores_group_obj
=
scores
.
reduce
((
r
,
item
)
=>
{
const
key
=
Object
.
values
(
item
)[
0
]
...
...
@@ -183,7 +184,8 @@ export function robotPlay(board, win_size) {
res_key
=
Object
.
keys
(
max_scores_arr
[
random_index
])[
0
]
}
return
res_key
.
split
(
'
_
'
).
map
(
item
=>
parseInt
(
item
,
10
));
const
[
_row
,
_col
,
type
]
=
res_key
.
split
(
'
_
'
)
return
[
parseInt
(
_row
,
10
),
parseInt
(
_col
,
10
),
type
];
}
/**
...
...
@@ -225,7 +227,6 @@ function getDirectionsInfo({ ROW, COL, OBJ }, row, col, [y, x], player) {
const
_inChessboard
=
inChessboard
(
ROW
,
COL
)
while
(
_inChessboard
(
_row
,
_col
))
{
const
item
=
OBJ
[
`
${
_row
}
_
${
_col
}
`
]
console
.
log
(
_row
,
_col
);
if
(
item
===
villain
)
{
break
;
...
...
@@ -244,7 +245,6 @@ function getDirectionsInfo({ ROW, COL, OBJ }, row, col, [y, x], player) {
obstacle_num
+=
1
}
debugger
return
[
empty_num
,
...
...
@@ -277,6 +277,9 @@ function getDirectionScore(pan_info, row, col, [y, x], win_size, player) {
*
* 随机下棋
* 如果一个判定回合,棋盘积分中最高的积分有多个,则随机选择一个位置,避免有规律 =====
*
* 进攻性
* 如果一个位置,两方都可以下,优先我方落子
*/
const
SIZE
=
r_piece_num
+
l_piece_num
// 没有棋子
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录