Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
aa152147
五子棋
提交
9539c8d2
五
五子棋
项目概览
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看板
提交
9539c8d2
编写于
6月 26, 2023
作者:
6
63db3122f0950a2aef64df95
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Mon Jun 26 09:59:00 UTC 2023 inscode
上级
c7bfabea
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
63 addition
and
6 deletion
+63
-6
src/App.vue
src/App.vue
+4
-2
src/utils/api.js
src/utils/api.js
+50
-0
src/utils/index.js
src/utils/index.js
+3
-3
vite.config.js
vite.config.js
+6
-1
未找到文件。
src/App.vue
浏览文件 @
9539c8d2
<
script
setup
>
import
{
onMounted
,
ref
}
from
"
vue
"
import
{
is_empty
,
checkWin
,
robotPlay
,
is_black
,
is_white
}
from
"
./utils
"
import
{
is_empty
,
checkWin
,
is_black
,
is_white
}
from
"
./utils
"
import
{
robotPlay
}
from
'
./utils/api
'
// 配置
const
size
=
ref
(
20
)
const
win_size
=
ref
(
5
)
...
...
@@ -18,13 +19,14 @@ function confirm() {
}
// 玩家下棋
function
playChess
(
item
,
row
,
col
)
{
if
(
isWin
.
length
||
item
)
return
if
(
isWin
.
length
||
item
!==
is_empty
)
return
lattices
.
value
[
row
][
col
]
=
nextPlay
const
test
=
checkWin
({
row
,
col
,
board
:
lattices
.
value
,
player
:
nextPlay
,
win_size
:
win_size
.
value
})
if
(
test
)
{
isWin
=
test
return
}
else
{
console
.
log
(
'
------------
'
)
robotPlay
(
lattices
.
value
,
is_black
,
win_size
.
value
)
}
}
...
...
src/utils/api.js
0 → 100644
浏览文件 @
9539c8d2
export
const
apiKey
=
process
.
env
.
INSCODE_API_KEY
;
export
const
apiUrl
=
'
https://inscode-api.csdn.net/api/v1/gpt/
'
;
const
regex
=
/"content":"
([^
"
]
*
)
"/
;
/**
* 机器人回合下棋
* @param {(null|isWhite|isBlack)[][]} board 棋盘
* @param {isWhite|isBlack} player 当前下棋类型
* @param {number} win_size 多少颗棋子能赢
*
* @return {[number, number]} 返回机器人回合要落子的坐标
*/
export
function
robotPlay
(
board
,
player
,
win_size
)
{
console
.
log
(
'
============
'
)
/**
* 发送请求,InsCode 已经集成了 GPT 能力
* 在 vite.config.js 中已通过环境变量写入了 apiKey(该 key 是动态写入使用者的,在 IDE 中是作者,发布到社区是运行该作品的用户)
* 发布到社区后,将消耗运行者的额度
* 注意:如果部署应用,任何人通过部署后的域名访问应用时,都将消耗部署者的额度
*/
const
body
=
{
messages
:
[
{
role
:
'
user
'
,
content
:
"
你好
"
}
],
apikey
:
apiKey
}
const
source
=
fetch
(
apiUrl
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
(
body
),
}).
then
(
res
=>
{
console
.
log
(
res
)
return
res
.
text
()
}).
then
(
res
=>
{
console
.
log
(
res
.
split
(
'
\n
'
))
console
.
log
(
'
++++++++
'
)
const
match
=
res
.
match
(
regex
);
if
(
match
&&
match
.
length
==
2
)
{
console
.
log
(
match
[
1
]);
}
}).
catch
(
err
=>
{
console
.
log
(
err
)
})
}
src/utils/index.js
浏览文件 @
9539c8d2
export
const
is_empty
=
null
;
export
const
is_empty
=
'
isEmpty
'
;
export
const
is_white
=
'
isWhite
'
;
export
const
is_black
=
'
isBlack
'
;
export
const
directions
=
[
...
...
@@ -13,7 +13,7 @@ export const directions = [
* @param {object} param
* @param {number} param.row 行
* @param {number} param.col 列
* @param {(
null
|is_white|is_black)[]} param.board 棋盘
* @param {(
isEmpty
|is_white|is_black)[]} param.board 棋盘
* @param {is_white|is_black} [param.player] 当前棋子类型
* @param {number} param.win_size 需要几个棋子才赢
* @param {[]} [param.direction] 方向
...
...
@@ -96,7 +96,7 @@ export function robotPlay(board, player, win_size) {
}
}
_board
[
i
][
j
]
=
null
;
// 恢复棋盘状态
_board
[
i
][
j
]
=
isEmpty
;
// 恢复棋盘状态
// 选取分数最高的空位
if
(
score
>
maxScore
)
{
...
...
vite.config.js
浏览文件 @
9539c8d2
...
...
@@ -6,5 +6,10 @@ export default defineConfig({
server
:
{
host
:
true
},
plugins
:
[
vue
()]
plugins
:
[
vue
()],
define
:
{
'
process.env
'
:
{
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录