-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_state.h
243 lines (204 loc) · 6.24 KB
/
game_state.h
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
#ifndef BISTROMATHICS_GAME_STATE_H
#define BISTROMATHICS_GAME_STATE_H 1
#include <utility>
#include <list>
#include <vector>
using namespace std;
#define EMPTY '.'
#define LADDER 'H'
#define BRICK '='
#define GOLD '*'
#define REMOVED_BRICK '-'
#define FILLED_BRICK '+'
enum ChaseState{
//UNKNOWN is if we lose track and can't figure out what the enemy is doing
//if it's dead, use PATROL
CHASE_RED,CHASE_BLUE,RETURN_TO_PATROL,PATROL,UNKNOWN
};
static const char* chaseStateNames[] = {
"CHASE_RED",
"CHASE_BLUE",
"RETURN_TO_PATROL",
"PATROL",
"UNKNOWN"
};
//find a better place for these...
enum Player{
NOONE = -1,RED=0,BLUE=1
};
enum Action{
NONE=0,LEFT,RIGHT,DIG_LEFT,DIG_RIGHT,TOP,BOTTOM
};
struct ChaseInfo{
int pathLength;
Action startDir;
Action attackDir;
};
struct EnemyInfo{
pair<int,int> loc;
pair<int,int> spawn;
int spawnDelay;//same comment as for enemySpawnDelay
vector<Action> program;
Player master;
bool isTrapped;
Action lastMove;
int distSq;
int distSqToOpponent;
ChaseState chaseState;
ChaseInfo chaseInfo;
list<Action> chaseStack;
int patrolIndex;
inline bool isAlive(){
return loc.first!=-1;
}
bool isFalling();
};
//things that don't change
class StaticWorldData{
public:
int nrounds;
int nenemies;
pair<int,int> enemySpawn;
pair<int,int> ourSpawn;
};
extern StaticWorldData fixedData;
//these things change every turn
class World{
public:
int currTurn;
int missedTurns;
char map[16][26];
char timeout[16][26];//Indicates how long for bricks and gold to respaun. 0= there now.
pair<int,int> currLoc;
int currScore;
int brickDelay;
pair<int,int> enemyLoc;
int enemyScore;
int enemySpawnDelay;
int enemyBrickDelay;
EnemyInfo enemies[16*25];
inline char checkMapSafe(int r,int c){
if(r>=0 && r<16 && c>=0 && c<25)
return map[r][c];
return '\0';
}
inline char checkMapSafe(const pair<int,int>& loc){
return checkMapSafe(loc.first,loc.second);
}
bool canDoActionRaw(Action act, const pair<int,int>& loc);
bool canDoActionPlayer(Action act){ return canDoActionPlayer(act,currLoc); }
bool canDoActionPlayer(Action act, const pair<int,int>&loc){ return canDoActionPlayer(act,loc,brickDelay); }
bool canDoActionPlayer(Action act, const pair<int,int>& loc, int curBrickDelay);
bool canDoActionOpponent(Action act, const pair<int,int>& loc);
bool canDoActionOpponent(Action act){ return canDoActionOpponent(act,enemyLoc); }
bool canDoActionEnemy(Action act, const pair<int,int>& loc);
bool isAlive(){
return currLoc.first!=-1;
};
};
extern World game;
//extern the global state
//the actually declarations for all of these are in game_state.cpp
static int& nrounds = fixedData.nrounds;
static int& nenemies = fixedData.nenemies;
static int& currTurn = game.currTurn;
static int& missedTurns = game.missedTurns;
static char (&map)[16][26] = game.map;
extern char originalMap[16][26];
extern int component[16][26];
extern vector<Action> actions;
extern vector<int > rlocs;
extern vector<int> clocs;
extern int gold_comp[600];
extern int max_gold_comp;
extern int totalGoldOnMap;
extern bool reachable[16][26][16][26];
extern int depth[16][26];
extern pair<int,int> earliest_parent[16][26];
static pair<int,int>& currLoc = game.currLoc;
static pair<int,int>& ourSpawn = fixedData.ourSpawn;
static int& currScore = game.currScore;
static int& brickDelay = game.brickDelay;
static pair<int,int>& enemyLoc = game.enemyLoc;
static pair<int,int>& enemySpawn = fixedData.enemySpawn;
static int& enemyScore = game.enemyScore;
//if we lose some turns this could be an estimate,
//if it's 0, then the enemy is alive
static int& enemySpawnDelay = game.enemySpawnDelay;
static int& enemyBrickDelay = game.enemyBrickDelay;
static EnemyInfo (&enemies)[16*25] = game.enemies;
//returns '\0' if it's off the map
static inline char checkMapSafe(int r, int c){
return game.checkMapSafe(r,c);
}
static inline char checkMapSafe(const pair<int,int>& loc){
return game.checkMapSafe(loc.first,loc.second);
}
//bunch of tiny utility functions
static inline bool isImpassable(char c){
return c==BRICK || c==FILLED_BRICK || c=='\0';
}
static inline bool isSolid(char c){
return c==BRICK || c==LADDER || c==FILLED_BRICK || c=='\0';
}
static inline bool isBrick(const pair<int,int>& loc){
return map[loc.first][loc.second] == BRICK;
}
static inline bool isSupported(const pair<int,int>& loc = currLoc){
return isSolid(checkMapSafe(loc.first+1,loc.second)) || map[loc.first][loc.second]==LADDER;
}
static inline bool isSupportedEnemy(const pair<int,int>& loc){
return checkMapSafe(loc.first+1,loc.second)==REMOVED_BRICK || isSupported(loc);
}
static inline bool isAlive(){
return game.isAlive();
}
static inline int distSq(const pair<int,int>& a, const pair<int,int>& b){
return (b.first-a.first)*(b.first-a.first)+(b.second-a.second)*(b.second-a.second);
}
inline bool EnemyInfo::isFalling(){
return this->isAlive() && !isSupported(loc) && !isTrapped;
}
static inline Action reverseAction(Action a){
switch(a){
case NONE:
return NONE;
case LEFT:
return RIGHT;
case RIGHT:
return LEFT;
case DIG_LEFT:
return DIG_RIGHT;
case DIG_RIGHT:
return DIG_LEFT;
case TOP:
return BOTTOM;
case BOTTOM:
return TOP;
}
}
static const char *actionNames[7] = {
"NONE",
"LEFT",
"RIGHT",
"DIG_LEFT",
"DIG_RIGHT",
"TOP",
"BOTTOM"
};
static inline bool canDoActionPlayer(Action act, const pair<int,int>& loc = currLoc){
return game.canDoActionPlayer(act,loc);
}
static inline bool canDoActionOpponent(Action act, const pair<int,int>& loc = enemyLoc){
return game.canDoActionOpponent(act,loc);
}
static inline bool canDoActionEnemy(Action act, const pair<int,int>& loc){
return game.canDoActionEnemy(act,loc);
}
//dont use this one if possible, it will be removed soon.
static inline bool canDoAction(Action act,const pair<int,int>& loc = currLoc){
return canDoActionPlayer(act,loc);
}
bool canDoAction2(Action act,const pair<int,int>& loc = currLoc);
pair<int,int> simulateAction(Action act,const pair<int,int>& loc);
#endif