Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

25 Commits

Repository files navigation

DouZero_API

API 交互斗地主 AI

Logo

本项目基于DouZero

调用API

程序默认运行于24813端口 目前只支持post方法调用,请求头 Content-Type: application/json

{
"action": string,"data": object
}
参数名说明
action上报类型,可选"init"/"play",对应 初始化游戏/游戏进程上报
data上报数据,见下方

上报数据:

初始化游戏

{
"pid": string / int,"three_landlord_cards": string,"ai_amount": int,"player_data":[
{
"model": string,"hand_cards": string,"position_code": int
},
{
"model": string,"hand_cards": string,"position_code": int
}
]
}
参数名说明示例
pid对局唯一标识,若为int类型会自动转为string10001
three_landlord_cards三张地主牌"444"
ai_amountAI玩家数量,为1或22
player_dataAI玩家数据,AI玩家数为1时只会读取数组中的第一个元素,内容元素见下方\
modelAI玩家使用的模型"WP"
hand_cardsAI玩家的手牌"333444456789TJQKA2XD"
position_codeAI玩家的位号 0-地主上家,1-地主,2-地主下家1
完整示例
{
"action": "init",
"data": {
"three_landlord_cards": "444",
"pid": 10001,
"ai_amount": 2,
"player_data": [
{
"model": "WP",
"hand_cards": "333444456789TJQKA2XD",
"position_code": 1
},
{
"model": "WP",
"hand_cards": "3555666777888999T",
"position_code": 2
}
]
}
}

游戏进程上报

也就是上报玩家出牌

{
"pid": string / int,"player": int,"cards": string
}
参数名说明示例
pid对局唯一标识,若为int类型会自动转为string10001
player出牌玩家位号0
cards玩家出的牌,为空字符串则表示不要"TJQKA"

程序并不会检测玩家所出的牌是否遵循规则,请保证上报数据准确

完整示例
{
"action": "play",
"data": {
"pid": 10001,
"player": 0,
"cards": "TJQKA"
}
}

API响应

{
"type": string,"action": string,"status": string,"msg": string,"data": object
}
参数名说明
type响应类型,与上报数据的action相对应,上报"play"时为"step"
action响应AI操作,尚未轮到AI出牌时为"receive",AI出牌时为"play"
status响应状态,为"ok"/"fail"
msg错误信息,响应状态为"fail"时不为空
data响应数据,见下方

响应数据:

{
"pid": pid,"game_over": boolen,"play": [
{
"cards": array,"confidence": string
},
{
"cards": array,"confidence": string
}
]
}
参数名说明
pid对应对局标识
game_over对局是否结束,结束则为true
playAI出牌数据,action为"receive"时无此元素,元素内容见下方
cardsAI出的牌,为数组类型
confidenceAI的胜率估计

预设模型简介

  • WP

DouZero-WP (baselines/douzero_WP/): 以胜率(Winning Percentage, WP)为目标训练的Douzero智能体

  • ADP

DouZero-ADP (baselines/douzero_ADP/): 以平均分数差异(Average Difference Points, ADP)为目标训练的Douzero智能体

大概更倾向于出炸弹刷分

自定义运行端口

程序默认运行于0.0.0.0:24813,通过-H参数修改host,-p参数修改端口,如:

DouZero_API.exe -H 127.0.0.1 -p 24814
python start.py -H 127.0.0.1 -p 24814

超时检测

程序每5分钟将检查一次进程列表,超过半个小时未响应的游戏进程将被删除。

使用自己的模型

baselines/文件夹下新建文件夹,将自己训练的landlord.ckptlandlord_up.ckptlandlord_down.ckpt扔进去,文件夹名即为游戏初始化时需要填入的"model"参数

鸣谢

About

基于DouZero实现API交互斗地主AI

Resources

Stars

39 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages