Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
aa152147
五子棋
提交
d815ac5e
五
五子棋
项目概览
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看板
提交
d815ac5e
编写于
6月 27, 2023
作者:
6
63db3122f0950a2aef64df95
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tue Jun 27 01:59:00 UTC 2023 inscode
上级
9539c8d2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
21 deletion
+22
-21
src/App.vue
src/App.vue
+5
-7
src/utils/api.js
src/utils/api.js
+17
-14
未找到文件。
src/App.vue
浏览文件 @
d815ac5e
...
@@ -6,7 +6,6 @@ import { robotPlay } from './utils/api'
...
@@ -6,7 +6,6 @@ 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
([])
let
nextPlay
=
is_black
// is_white
// 5 连珠的下标
// 5 连珠的下标
let
isWin
=
[]
let
isWin
=
[]
...
@@ -14,20 +13,19 @@ onMounted(confirm)
...
@@ -14,20 +13,19 @@ onMounted(confirm)
function
confirm
()
{
function
confirm
()
{
isWin
=
[]
isWin
=
[]
nextPlay
=
is_black
;
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
playChess
(
item
,
row
,
col
)
{
async
function
playChess
(
item
,
row
,
col
)
{
if
(
isWin
.
length
||
item
!==
is_empty
)
return
if
(
isWin
.
length
||
item
!==
is_empty
)
return
lattices
.
value
[
row
][
col
]
=
nextPlay
lattices
.
value
[
row
][
col
]
=
is_black
const
test
=
checkWin
({
row
,
col
,
board
:
lattices
.
value
,
player
:
nextPlay
,
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
return
return
}
else
{
}
else
{
cons
ole
.
log
(
'
------------
'
)
cons
t
[
x
,
y
]
=
await
robotPlay
(
lattices
.
value
,
is_white
,
win_size
.
value
)
robotPlay
(
lattices
.
value
,
is_black
,
win_size
.
value
)
lattices
.
value
[
x
][
y
]
=
is_white
}
}
}
}
...
...
src/utils/api.js
浏览文件 @
d815ac5e
export
const
apiKey
=
process
.
env
.
INSCODE_API_KEY
;
export
const
apiKey
=
process
.
env
.
INSCODE_API_KEY
;
export
const
apiUrl
=
'
https://inscode-api.csdn.net/api/v1/gpt/
'
;
export
const
apiUrl
=
'
https://inscode-api.csdn.net/api/v1/gpt/
'
;
const
regex
=
/"content":"
([^
"
]
*
)
"/
;
import
{
is_empty
,
checkWin
,
is_black
,
is_white
}
from
"
./index
"
/**
/**
* 机器人回合下棋
* 机器人回合下棋
* @param {(null|isWhite|isBlack)[][]} board 棋盘
* @param {(null|isWhite|isBlack)[][]} board 棋盘
...
@@ -10,41 +10,44 @@ const regex = /"content":"([^"]*)"/;
...
@@ -10,41 +10,44 @@ const regex = /"content":"([^"]*)"/;
*
*
* @return {[number, number]} 返回机器人回合要落子的坐标
* @return {[number, number]} 返回机器人回合要落子的坐标
*/
*/
export
function
robotPlay
(
board
,
player
,
win_size
)
{
export
async
function
robotPlay
(
board
,
player
,
win_size
)
{
console
.
log
(
'
============
'
)
/**
/**
* 发送请求,InsCode 已经集成了 GPT 能力
* 发送请求,InsCode 已经集成了 GPT 能力
* 在 vite.config.js 中已通过环境变量写入了 apiKey(该 key 是动态写入使用者的,在 IDE 中是作者,发布到社区是运行该作品的用户)
* 在 vite.config.js 中已通过环境变量写入了 apiKey(该 key 是动态写入使用者的,在 IDE 中是作者,发布到社区是运行该作品的用户)
* 发布到社区后,将消耗运行者的额度
* 发布到社区后,将消耗运行者的额度
* 注意:如果部署应用,任何人通过部署后的域名访问应用时,都将消耗部署者的额度
* 注意:如果部署应用,任何人通过部署后的域名访问应用时,都将消耗部署者的额度
*/
*/
const
content
=
`这是一个五子棋游戏,
${
JSON
.
stringify
(
board
)}
,下一步"
${
player
}
"要下到哪,请不要返回多余的文字,只返回数组,比如["x", "y"]。`
const
body
=
{
const
body
=
{
messages
:
[
messages
:
[
{
{
role
:
'
user
'
,
role
:
'
user
'
,
content
:
"
你好
"
content
}
}
],
],
apikey
:
apiKey
apikey
:
apiKey
}
}
const
source
=
fetch
(
apiUrl
,
{
return
await
fetch
(
apiUrl
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
headers
:
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
'
Content-Type
'
:
'
application/json
'
},
},
body
:
JSON
.
stringify
(
body
),
body
:
JSON
.
stringify
(
body
),
}).
then
(
res
=>
{
}).
then
(
res
=>
{
console
.
log
(
res
)
return
res
.
text
()
return
res
.
text
()
}).
then
(
res
=>
{
}).
then
(
async
(
res
)
=>
{
console
.
log
(
res
.
split
(
'
\n
'
))
const
arr
=
res
.
split
(
'
\n
'
).
filter
(
item
=>
!!
item
&&
!
item
.
includes
(
"
DONE
"
)).
map
(
item
=>
JSON
.
parse
(
item
.
replace
(
'
data:
'
,
''
))).
flatMap
(
item
=>
{
console
.
log
(
'
++++++++
'
)
const
content
=
item
.
choices
[
0
].
delta
?.
content
const
match
=
res
.
match
(
regex
);
return
content
?
[
content
]
:
[]
if
(
match
&&
match
.
length
==
2
)
{
}).
join
(
''
)
console
.
log
(
match
[
1
]);
console
.
log
(
arr
)
let
_res
=
[]
try
{
_res
=
JSON
.
parse
(
arr
)
}
catch
(
err
)
{
_res
=
await
robotPlay
(
board
,
player
,
win_size
)
}
}
}).
catch
(
err
=>
{
return
_res
console
.
log
(
err
)
})
})
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录