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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
use std::collections::{ HashMap };
use std::rc::Rc;
use super::{
Color,
PowerSource,
TerrainInfo,
Unit,
Upgrade,
Point2,
Point3,
Score,
UnitType,
UnitTypeData,
Effect,
Ability,
AbilityData,
UpgradeData,
Buff,
BuffData,
Visibility,
ActionTarget,
ImageData
};
/// target for debugging text
#[derive(Debug, Copy, Clone)]
pub enum DebugTextTarget {
/// screen coordinates for debug text
Screen(Point2),
/// world coordinates for debug text
World(Point3)
}
/// a command to issue to the game instance
#[derive(Debug, Clone)]
pub enum Command {
/// command a set of units
Action {
/// units to command
units: Vec<Rc<Unit>>,
/// ability to trigger
ability: Ability,
/// ability target
target: Option<ActionTarget>
},
// ToggleAutocast {
// units: Vec<Rc<Unit>>,
// ability: Ability
// },
}
/// a debug command for the game
#[derive(Debug, Clone)]
pub enum DebugCommand {
/// shows debug text in the game instance
DebugText {
/// text to display
text: String,
/// target in screen or world space
///
/// if the target is None, then text appears at top-left of screen.
target: Option<DebugTextTarget>,
/// color of the text
color: Color,
},
/// shows a debug line in the game from p1 to p2
DebugLine {
/// starting point of the line
p1: Point3,
/// ending point of the line
p2: Point3,
/// color of the line
color: Color,
},
/// shows a debug box in the game defined by corners min and max
DebugBox {
/// minimum corner of the box
min: Point3,
/// maximum corner of the box
max: Point3,
/// color of the box
color: Color,
},
/// shows a debug sphere in the game
DebugSphere {
/// center of the sphere
center: Point3,
/// radius of the sphere
radius: f32,
/// color of the sphere
color: Color,
}
}
/// an event from the game
#[derive(Debug, Clone)]
pub enum GameEvent {
/// a unit was destroyed
UnitDestroyed(Rc<Unit>),
/// a unit was created
UnitCreated(Rc<Unit>),
/// a unit does not have any orders
UnitIdle(Rc<Unit>),
/// a unit was detected
UnitDetected(Rc<Unit>),
/// an upgrade completed
UpgradeCompleted(Upgrade),
/// a unit finished constructing a building
BuildingCompleted(Rc<Unit>),
/// number of nydus worms detected
NydusWormsDetected(u32),
/// number of nukes launched
NukesDetected(u32),
}
/// game data (may vary depending on version and DLC)
#[derive(Debug, Clone)]
pub struct GameData {
/// data associated with abilities
pub ability_data: HashMap<Ability, AbilityData>,
/// data associated with unit types
pub unit_type_data: HashMap<UnitType, UnitTypeData>,
/// data associated with upgrades
pub upgrade_data: HashMap<Upgrade, UpgradeData>,
/// data associated buffs
pub buff_data: HashMap<Buff, BuffData>,
/// playable area info
pub terrain_info: TerrainInfo,
}
/// current state of the map
#[derive(Debug, Clone)]
pub struct MapState {
/// creep image (sample pixels to find tiles with creep)
pub creep: ImageData,
/// visibility image (sample pixels to find visible tiles)
pub visibility: ImageData,
}
/// state of the game (changes every frame)
#[derive(Debug, Clone)]
pub struct GameState {
/// the player id associated with the participant
pub player_id: u32,
/// the previous game step
pub previous_step: u32,
/// the current game step
pub current_step: u32,
/// position of the center of the camera
pub camera_pos: Point2,
/// a list of all known units at the moment
pub units: Vec<Rc<Unit>>,
/// all power sources associated with the current player
pub power_sources: Vec<PowerSource>,
/// all active effects in vision of the current player
pub effects: Vec<Effect>,
/// all upgrades
pub upgrades: Vec<Upgrade>,
/// current mineral count
pub minerals: u32,
/// current vespene count
pub vespene: u32,
/// the total supply cap given the players max supply
pub food_cap: u32,
/// the total supply used by the player
pub food_used: u32,
/// the total supply consumed by army units alone
pub food_army: u32,
/// the total supply consumed by workers alone
pub food_workers: u32,
/// the number of workers that currently have no orders
pub idle_worker_count: u32,
/// the number of army units
pub army_count: u32,
/// the number of warp gates owned by the player
pub warp_gate_count: u32,
/// the number of larva owned by the player
pub larva_count: u32,
/// detailed current set of scores
pub score: Score
}
impl GameState {
/// filter all units based on a custom condition
pub fn filter_units<F>(&self, filter: F) -> Vec<Rc<Unit>>
where F: Fn(&Unit) -> bool
{
let mut units = vec![ ];
for unit in &self.units {
if filter(&unit) {
units.push(Rc::clone(&unit));
}
}
units
}
/// check if the given point contains creep
pub fn has_creep(&self, _: Point2) -> bool {
unimplemented!("has creep")
}
/// get the visibility of the given point for the current player
pub fn get_visibility(&self, _: Point2) -> Visibility {
unimplemented!("get visibility")
}
/// whether the given point on the terrain is pathable
///
/// this does not include pathing blockers like structures, for more
/// accurate pathing results, use query interface
pub fn is_pathable(&self, _: Point2) -> bool {
unimplemented!("is pathable")
}
/// whether the given point on the terrain is buildable
///
/// this does not include blockers like other structures. for more
/// accurate building placement results, use query interface
pub fn is_placable(&self, _: Point2) -> bool {
unimplemented!("is placable")
}
/// returns the terrain height of the given point
pub fn get_terrain_height(&self, _: Point2) -> f32 {
unimplemented!("get terrain height")
}
}
/// all game data passed to agents and observers
#[derive(Debug, Clone)]
pub struct FrameData {
/// state that updates every frame
pub state: GameState,
/// data that can change on a per game basis
pub data: Rc<GameData>,
/// events that have happened since the last update
pub events: Vec<GameEvent>,
/// current map state
pub map: Rc<MapState>
}