-
Notifications
You must be signed in to change notification settings - Fork 0
/
hive_api_v0.1.0_doc.js
164 lines (159 loc) · 5.31 KB
/
hive_api_v0.1.0_doc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// HIVE API VERSION 0.1.0
/*
"Greetings" request
this request type is used to establish the identity of a remote AI module
and also to inform the module about the semantic version string of the system.
*/
// example request structure sent from the game core to an AI module
{
request_type: "Greetings",
request_id: "n6Vvi",
system_version: "0.1.0"
}
// example response structure sent back to the requestor
// Note: this is the same format as the package.json files bundled with the AI in this, the main Hive project.
{
response_type: "Greetings",
response_id: "n6Vvi",
name: "rando", // short name / code-name internally used to identify in records involving this module
active: true, // whether this AI is considered to be in a usable state by its owner
version: "0.0.1", // version of the AI code
long_name: "Rando[m]", // display name
module: "hive-ai-rando", // [optional] currently only used to locate local AI modules
description: "The random monkey AI", // short description; displayed to user
author: "Trylobot", // [optional] author(s) of the AI module code
project_url: "https://github.com/Trylobot/hive/tree/master/ai/rando", // [optional] url to a project page
language: "Javascript" // [optional] primary language used to write the AI module
}
// ----------------------------------------------------------------------------
/*
"Choose Turn" request
this request type is used to request turns from remote AI modules.
the possible turns are enumerated in advance, and the AI is expected to choose one.
the board state and the contents of each players' hand is also given.
there is no explicit limit on think-time.
*/
// example request structure sent from the game core to an AI module
{
request_type: "Choose Turn",
request_id: "7pNQ4",
game_id: "KqwSQ", // used to identify game among multiple simultaneous ongoing games
request_timestamp: 1405582952293, // a reference point for the receiver
response_deadline: 1405583012293, // response not received by this time? game is thrown in favor of opponent (+/- 5 seconds)
game_state: { // intended for direct deserialization (see core/domain/game.js load_game)
board: { // (see core/domain/board.js)
pieces: { // map<string,array<piece>>: keys are occupied positions, values are piece-stacks
"0,0": [ // position at 0,0 contains one piece
{ // (see core/domain/piece.js)
color: "White", // (see core/domain/piece.js colors_enum)
type: "Queen Bee" // (see core/domain/piece.js types_enum)
}
],
"1,1": [ // position at 1,1 contains a stack two pieces high
{ // ... with the black queen bee on bottom
color: "Black",
type: "Queen Bee"
},
{ // ... covered by a black beetle
color: "Black",
type: "Beetle"
}
]
}
},
hands: { // hands for both players; keys are piece-type names (see core/domain/piece.js)
"White": {
"Soldier Ant": 2, // white has two soldier ants
"Grasshopper": 1
},
"Black": {} // omitted keys can be thought of as zero pieces of that type available
},
player_turn: "White",
turn_number: 2,
game_over: false,
winner: null,
is_draw: false,
creation_parameters: {
use_mosquito: false,
use_ladybug: false,
use_pillbug: false
},
turn_history: [
{ // (see core/domain/turn.js)
turn_type: "Placement",
piece_type: "Beetle",
destination: "0,0"
},
{
turn_type: "Placement",
piece_type: "Queen Bee",
destination: "1,-1"
},
{
turn_type: "Movement",
source: "1,-1",
destination: "-1,-1"
}
],
possible_turns: {
"Placement": { // all data in here is related to placement of new pieces
piece_types: [ // list of piece types valid to place this turn
"Soldier Ant"
],
positions: [ // list of valid placement positions for any of the above piece types
"-2,0",
"-1,-1",
"1,-1"
]
},
"Movement": { // all data in here is related to normal movement of existing pieces
"0,0": [ // this lists the valid movement destinations for the piece at this position
"2,0",
"-1,1"
]
},
"Special Ability": { // all data in here is related to special abilities (currently pillbug)
"0,0": { // pillbug's (or mosquito mimicking pillbug)'s location
"1,1": [ // list of valid destinations for the piece at this position, moved by the above pillbug
"2,0"
]
}
}
}
}
}
// example response structure sent back to the requestor
{
response_type: "Choose Turn",
request_id: "7pNQ4",
game_id: "KqwSQ",
turn_type: "Placement",
piece_type: "Soldier Ant",
destination: "-1,-1"
}
// another example
{
response_type: "Choose Turn",
request_id: "7pNQ4",
game_id: "KqwSQ",
turn_type: "Movement",
source: "0,0",
destination: "2,0"
}
// special ability usage
{
response_type: "Choose Turn",
request_id: "7pNQ4",
game_id: "KqwSQ",
turn_type: "Special Ability",
ability_user: "0,0",
source: "1,1",
destination: "2,0"
}
// forfeit turn
{
response_type: "Choose Turn",
request_id: "7pNQ4",
game_id: "KqwSQ",
turn_type: "Forfeit"
}