Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
aa152147
五子棋
提交
4f2815f7
五
五子棋
项目概览
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看板
提交
4f2815f7
编写于
7月 08, 2023
作者:
6
63db3122f0950a2aef64df95
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto Commit
上级
573e4e72
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
48 deletion
+37
-48
src/App.vue
src/App.vue
+1
-1
src/utils/index.js
src/utils/index.js
+35
-43
vite.config.js
vite.config.js
+1
-4
未找到文件。
src/App.vue
浏览文件 @
4f2815f7
...
@@ -35,7 +35,7 @@ function back() {
...
@@ -35,7 +35,7 @@ function back() {
const
{
location
:
[
y
,
x
],
type
}
=
records
.
value
.
pop
()
const
{
location
:
[
y
,
x
],
type
}
=
records
.
value
.
pop
()
lattices
.
value
[
y
][
x
]
=
is_empty
lattices
.
value
[
y
][
x
]
=
is_empty
// 如果是玩家赢了,只需要退回一步就行
// 如果是玩家赢了,只需要退回一步就行
if
(
type
===
is_black
)
{
if
(
type
===
is_black
)
{
break
;
break
;
}
}
}
}
...
...
src/utils/index.js
浏览文件 @
4f2815f7
...
@@ -14,6 +14,18 @@ export const directions = [
...
@@ -14,6 +14,18 @@ export const directions = [
[
1
,
-
1
]
// / 方向
[
1
,
-
1
]
// / 方向
]
]
Array
.
prototype
.
group
=
function
(
fn
)
{
return
this
.
reduce
((
r
,
item
,
index
,
arr
)
=>
{
const
key
=
fn
(
item
,
index
,
arr
)
if
(
r
[
key
]?.
length
)
{
r
[
key
].
push
(
item
)
}
else
{
r
[
key
]
=
[
item
]
}
return
r
},
{})
}
/**
/**
* 检查 n 是否在 start 与 end 之间,但不包括 end。
* 检查 n 是否在 start 与 end 之间,但不包括 end。
* 如果 end 没有指定,那么 start 设置为0。
* 如果 end 没有指定,那么 start 设置为0。
...
@@ -31,25 +43,6 @@ function inRange(n, start = 0, end) {
...
@@ -31,25 +43,6 @@ function inRange(n, start = 0, end) {
}
}
return
n
>=
start
&&
n
<
end
return
n
>=
start
&&
n
<
end
}
}
/**
* 产生一个包括 lower 与 upper 之间的数。
* 如果只提供一个参数返回一个0到提供数之间的数。
* @param {number} lower
* @param {number} upper
*/
function
random
(
lower
=
0
,
upper
=
1
)
{
// 交换 lower 和 upper 的值(如果 lower 大于 upper)
if
(
lower
>
upper
)
{
[
lower
,
upper
]
=
[
upper
,
lower
];
}
// 计算范围内的整数数量
const
range
=
upper
-
lower
+
1
;
// 生成随机整数
const
randomInteger
=
Math
.
floor
(
Math
.
random
()
*
range
)
+
lower
;
return
randomInteger
;
}
/**
/**
* 检查四个方向连续的棋子数
* 检查四个方向连续的棋子数
...
@@ -92,6 +85,7 @@ export function checkWin({ row, col, board, player, win_size }) {
...
@@ -92,6 +85,7 @@ export function checkWin({ row, col, board, player, win_size }) {
return
res
;
return
res
;
}
}
}
}
console
.
log
(
res
)
// 当前空位,可以结成多少颗连珠
// 当前空位,可以结成多少颗连珠
return
false
;
return
false
;
}
}
...
@@ -116,26 +110,35 @@ export function robotPlay(board, win_size) {
...
@@ -116,26 +110,35 @@ export function robotPlay(board, win_size) {
[
is_black
]:
0
,
[
is_black
]:
0
,
[
is_white
]:
0
[
is_white
]:
0
})
})
if
(
score
[
is_black
]
==
0
&&
score
[
is_white
]
==
0
)
return
[]
const
_b_score
=
score
[
is_black
]
const
_w_score
=
score
[
is_white
]
if
(
_b_score
==
0
&&
_w_score
==
0
)
return
[]
return
[{
return
[{
[
`
${
row
}
_
${
col
}
`
]:
score
[
`
${
row
}
_
${
col
}
`
]:
Math
.
max
(
_b_score
,
_w_score
)
}]
}]
}
else
{
}
else
{
return
[]
return
[]
}
}
})
})
}).
flat
(
1
)
}).
flat
(
1
)
const
_scores
=
scores
.
sort
((
black_score
,
white_score
)
=>
{
// 按分数分组
const
[
b_s1
,
b_w1
]
=
Object
.
values
(
Object
.
values
(
black_score
)[
0
])
const
scores_group_obj
=
scores
.
group
((
item
)
=>
{
const
[
w_s1
,
w_w1
]
=
Object
.
values
(
Object
.
values
(
white_score
)[
0
])
return
Object
.
values
(
item
)[
0
]
const
score1
=
Math
.
max
(
b_s1
,
b_w1
)
const
score2
=
Math
.
max
(
w_s1
,
w_w1
)
return
score2
-
score1
})
})
console
.
log
(
_scores
)
// 找到最高分数
const
max_key
=
Math
.
max
(...
Object
.
keys
(
scores_group_obj
))
const
max_scores_arr
=
scores_group_obj
[
max_key
]
let
res_key
=
''
if
(
max_scores_arr
.
length
===
1
)
{
res_key
=
Object
.
keys
(
max_scores_arr
[
0
])[
0
]
}
else
if
(
max_scores_arr
.
length
>
1
)
{
const
random_index
=
Math
.
floor
(
Math
.
random
()
*
max_scores_arr
.
length
)
res_key
=
Object
.
keys
(
max_scores_arr
[
random_index
])[
0
]
return
Object
.
keys
(
_scores
[
0
])[
0
].
split
(
'
_
'
);
}
return
res_key
.
split
(
'
_
'
).
map
(
item
=>
parseInt
(
item
,
10
));
}
}
/**
/**
...
@@ -166,16 +169,6 @@ export function robotPlay(board, win_size) {
...
@@ -166,16 +169,6 @@ export function robotPlay(board, win_size) {
*
*
*/
*/
/**
* 获取获取边界距离
* @param {number} size
* @param {number} num
*/
function
getBoundary
(
size
,
num
)
{
const
HALF
=
Math
.
floor
(
size
/
2
)
// 先下取整
return
(
num
>
HALF
?
size
-
num
:
num
)
+
1
// 当前位置算进去
}
/**
/**
* 获取这一边方向的信息,连珠颗数,延伸出去的空位数
* 获取这一边方向的信息,连珠颗数,延伸出去的空位数
* @param {(is_empty|is_white|is_black)[][]} board 棋盘
* @param {(is_empty|is_white|is_black)[][]} board 棋盘
...
@@ -194,9 +187,11 @@ function getJoinInfo(board, row, col, [y, x], player) {
...
@@ -194,9 +187,11 @@ function getJoinInfo(board, row, col, [y, x], player) {
let
_row
=
row
+
y
let
_row
=
row
+
y
let
_col
=
col
+
x
let
_col
=
col
+
x
const
villain
=
player
===
is_black
?
is_white
:
is_black
;
while
(
inRange
(
_row
,
ROW
)
&&
inRange
(
_col
,
COL
))
{
while
(
inRange
(
_row
,
ROW
)
&&
inRange
(
_col
,
COL
))
{
const
item
=
board
[
_row
][
_col
]
const
item
=
board
[
_row
][
_col
]
if
(
item
===
is_white
)
{
if
(
item
===
villain
)
{
break
;
break
;
}
}
// 连珠计数
// 连珠计数
...
@@ -216,9 +211,6 @@ function getJoinInfo(board, row, col, [y, x], player) {
...
@@ -216,9 +211,6 @@ function getJoinInfo(board, row, col, [y, x], player) {
empty_num
empty_num
}
}
}
}
function
pow
(
num
=
0
)
{
return
10
**
num
}
/**
/**
* 根据棋子位置信息,计算分数
* 根据棋子位置信息,计算分数
* @param {(is_empty|is_white|is_black)[]} board 棋盘
* @param {(is_empty|is_white|is_black)[]} board 棋盘
...
...
vite.config.js
浏览文件 @
4f2815f7
...
@@ -4,12 +4,9 @@ import vue from '@vitejs/plugin-vue'
...
@@ -4,12 +4,9 @@ import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
// https://vitejs.dev/config/
export
default
defineConfig
({
export
default
defineConfig
({
plugins
:
[
vue
()],
plugins
:
[
vue
()],
server
:
{
host
:
true
,
},
define
:
{
define
:
{
'
process.env
'
:
{
'
process.env
'
:
{
INSCODE_API_KEY
:
process
.
env
.
INSCODE_API_KEY
INSCODE_API_KEY
:
process
.
env
.
INSCODE_API_KEY
}
}
}
}
,
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录