Skip to content

Commit b5897d0

Browse files
authored
Update README.md
1 parent 678e438 commit b5897d0

1 file changed

Lines changed: 177 additions & 0 deletions

File tree

README.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,183 @@
66

77
> 本项目基于[DouZero](https://github.com/kwai/DouZero)
88
9+
## 调用API
10+
11+
> 程序默认运行于`24813`端口
12+
> 目前只支持post方法调用,请求头 `Content-Type: application/json`
13+
14+
```json
15+
{
16+
"action": string,
17+
"data": object
18+
}
19+
```
20+
21+
| 参数名 | 说明 |
22+
|-----|---------|
23+
| action | 上报类型,可选"init"/"play",对应 初始化游戏/游戏进程上报 |
24+
| data | 上报数据,见下方 |
25+
26+
上报数据:
27+
28+
### 初始化游戏
29+
30+
```json
31+
{
32+
"pid": string / int,
33+
"three_landlord_cards": string,
34+
"ai_amount": int,
35+
"player_data":[
36+
{
37+
"model": string,
38+
"hand_cards": string,
39+
"position_code": int
40+
},
41+
{
42+
"model": string,
43+
"hand_cards": string,
44+
"position_code": int
45+
}
46+
]
47+
}
48+
```
49+
50+
| 参数名 | 说明 | 示例 |
51+
|-----|---------|--------|
52+
| pid | 对局唯一标识,若为int类型会自动转为string | 10001 |
53+
| three_landlord_cards | 三张地主牌 | "444" |
54+
| ai_amount | AI玩家数量,为1或2 | 2 |
55+
| player_data | AI玩家数据,AI玩家数为1时只会读取数组中的第一个元素,内容元素见下方 | \ |
56+
| model | AI玩家使用的模型 | "WP" |
57+
| hand_cards | AI玩家的手牌 | "333444456789TJQKA2XD" |
58+
| position_code | AI玩家的位号 **0-地主上家,1-地主,2-地主下家** | 1 |
59+
60+
<details>
61+
<summary>完整示例</summary>
62+
63+
```json
64+
{
65+
"action": "init",
66+
"data": {
67+
"three_landlord_cards": "444",
68+
"pid": 10001,
69+
"ai_amount": 2,
70+
"player_data": [
71+
{
72+
"model": "WP",
73+
"hand_cards": "333444456789TJQKA2XD",
74+
"position_code": 1
75+
},
76+
{
77+
"model": "WP",
78+
"hand_cards": "3555666777888999T",
79+
"position_code": 2
80+
}
81+
]
82+
}
83+
}
84+
```
85+
86+
</details>
87+
88+
### 游戏进程上报
89+
90+
也就是上报玩家出牌
91+
92+
```json
93+
{
94+
"pid": string / int,
95+
"player": int,
96+
"cards": string
97+
}
98+
```
99+
100+
| 参数名 | 说明 | 示例 |
101+
|-----|---------|--------|
102+
| pid | 对局唯一标识,若为int类型会自动转为string | 10001 |
103+
| player | 出牌玩家位号 | 0 |
104+
| cards | 玩家出的牌,为空字符串则表示不要 | "TJQKA" |
105+
106+
> 程序并不会检测玩家所出的牌是否遵循规则,请保证上报数据准确
107+
108+
<details>
109+
<summary>完整示例</summary>
110+
111+
```json
112+
{
113+
"action": "play",
114+
"data": {
115+
"pid": 10001,
116+
"player": 0,
117+
"cards": "TJQKA"
118+
}
119+
}
120+
```
121+
122+
</details>
123+
124+
## API响应
125+
126+
```json
127+
{
128+
"type": string,
129+
"action": string,
130+
"status": string,
131+
"msg": string,
132+
"data": object
133+
}
134+
```
135+
| 参数名 | 说明 |
136+
|-----|---------|
137+
| type | 响应类型,与上报数据的`action`相对应,上报"play"时为"step" |
138+
| action | 响应AI操作,尚未轮到AI出牌时为"receive",AI出牌时为"play" |
139+
| status | 响应状态,为"ok"/"fail" |
140+
| msg | 错误信息,响应状态为"fail"时不为空 |
141+
| data | 响应数据,见下方 |
142+
143+
响应数据:
144+
145+
```json
146+
{
147+
"pid": pid,
148+
"game_over": boolen,
149+
"play": [
150+
{
151+
"cards": array,
152+
"confidence": string
153+
},
154+
{
155+
"cards": array,
156+
"confidence": string
157+
}
158+
]
159+
}
160+
```
161+
162+
| 参数名 | 说明 |
163+
|-----|---------|
164+
| pid | 对应对局标识 |
165+
| game_over | 对局是否结束,结束则为`true` |
166+
| play | AI出牌数据,action为"receive"时无此元素,元素内容见下方 |
167+
| cards | AI出的牌,为数组类型 |
168+
| confidence | AI的胜率估计 |
169+
170+
## 预设模型简介
171+
172+
- WP
173+
174+
DouZero-WP (baselines/douzero_WP/): 以胜率(Winning Percentage, WP)为目标训练的Douzero智能体
175+
176+
- ADP
177+
178+
DouZero-ADP (baselines/douzero_ADP/): 以平均分数差异(Average Difference Points, ADP)为目标训练的Douzero智能体
179+
180+
> 大概更倾向于出炸弹刷分
181+
182+
## 使用自己的模型
183+
184+
`baselines/`文件夹下新建文件夹,将自己训练的`landlord.ckpt``landlord_up.ckpt``landlord_down.ckpt`扔进去,文件夹名即为游戏初始化时需要填入的"model"参数
185+
9186
## 鸣谢
10187
* 本项目基于[DouZero](https://github.com/kwai/DouZero)
11188
* 借鉴了[DouZero_For_HappyDouDiZhu](https://github.com/tianqiraf/DouZero_For_HappyDouDiZhu)项目的部分代码与写法

0 commit comments

Comments
 (0)