Summary
Backend provides the bots integration, so that anyone can host their bot to play the game.
TODOs
Flow
When the room owner invoke add ai
Server will check how many bots are available, random choose 1 to join the room
The chosen bot service will get the request includes bot_id, player_id
When the bot's turn, the bot will be asked to play the game with current board info
When been kicked, the bot service will get the request includes bot_id, player_id
When the game is over, the bot service will get the latest board info
Requirement
- The bot service should response the request through webhook_url until been kicked or game over.
- The bot maintainer can choose the bot's max concurrent_number.
How to manage bots
- Get the JWT
POST /api/v1/users
Content-Type: application/json
{
"name": "your account name",
"password": "p@$$w0rd"
}
- Register bot
POST /api/v1/bots
Content-Type: application/json
Authentication: Bearer $token
{
"name": "used as nickname in game",
"webhook_url": "the bot service endpoint",
"concurrent_number": 1
}
- Look up bots has registered
GET /api/v1/bots
Content-Type: application/json
Authentication: Bearer $token
- Update bot
PUT /api/v1/bots/{bot_id}
Content-Type: application/json
Authentication: Bearer $token
{
"name": "used as nickname in game",
"webhook_url": "the bot service endpoint",
"concurrent_number": 1
}
- Remove bot
DELETE /api/v1/bots/{bot_id}
Content-Type: application/json
Authentication: Bearer $token
What actions the bot should implement
- expect response: 204 or 200 with any body
the game server send requests to bot's webhook_url, with following payload
event_name: pick, kick, to_place, to_split, game_over
POST "$webhook_url"
Content-Type: application/json
{
"event_name": "event_name",
"bot_id": 1,
"game_id": 1,
"player_id": 1,
"game_config": {}
"game_data": {}
}
- pick: the room owner pick bot to join game, the request body includes:
- bot_id: int (check from
GET /api/v1/bots)
- player_id: int (allow bot can join multiple rooms or same room at the same time)
- expect response: 204 or 200 with any body
- kick: the room owner kick the bot, the request body includes:
- bot_id
- player_id
- expect response: 204 or 200 with any body
- to_place: given the board, ask the bot to place
- bot_id
- player_id
- game_id: int
- game_config: provide the player order
- game_data: provide the board information
- expect response: 200 with coordinate to place
- to_split: given the board, ask the bot to split
- bot_id
- player_id
- game_id: int
- game_config: provide the player order
- game_data: provide the board information
- expect response: 200 with the origin coord. and target coord. (and amount)
{
"origin_x": 1,
"origin_y": 1,
"target_x": 2,
"target_y": 2,
"target_amount": 1
}
- game_over: notify the game is over
- bot_id
- player_id
- game_id: int
- game_config
- game_data: provide the board information in the end
- expect response: 204 or 200 with any body
Summary
Backend provides the bots integration, so that anyone can host their bot to play the game.
TODOs
Flow
When the room owner invoke
add aiServer will check how many bots are available, random choose 1 to join the room
The chosen bot service will get the request includes
bot_id,player_idWhen the bot's turn, the bot will be asked to play the game with current board info
When been kicked, the bot service will get the request includes
bot_id,player_idWhen the game is over, the bot service will get the latest board info
Requirement
How to manage bots
What actions the bot should implement
GET /api/v1/bots){ "x": 1, "y": 1 }{ "origin_x": 1, "origin_y": 1, "target_x": 2, "target_y": 2, "target_amount": 1 }