-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.h
More file actions
187 lines (138 loc) · 3.96 KB
/
game.h
File metadata and controls
187 lines (138 loc) · 3.96 KB
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
#ifndef GAME_H
#define GAME_H
// This game code is a port of Darwin's node code. I can optimize this a lot but
// probably don't have time to. Do not take any of this as best practice in C++
// Player ids
#define NO_PLAYER -1
#define BOTH_PLAYER 2
#define PLAYER1 0
#define PLAYER2 1
#define APOCALYPSE -1
// Cardinal directions
#define NODIR -1 // no direction
#define WEST 0
#define NORTH 1
#define EAST 2
#define SOUTH 3
// Orientations
#define HORIZONTAL 0
#define VERTICAL 1
#define ORIGIN 2
// Things that can be in a SPace
#define SP_OUT 0
#define SP_HARDBLOCK 1
#define SP_SOFTBLOCK 2
#define SP_BOMB 3
#define SP_PLAYER1 4
#define SP_PLAYER2 5
#define SP_AIR 6
// Portal Colors
#define PC_ORANGE 0
#define PC_BLUE 1
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <sstream>
#include <vector>
#include <stdexcept>
#include "json.h"
using json = nlohmann::json;
class Player;
class Coord {
public:
Coord();
Coord(int x, int y);
Coord(int x, int y, int dir);
Coord(const Coord& other);
std::string toString();
int x, y; // position
int dir; // direction
};
class Portal {
public:
Portal();
Portal(Player* owner, int color, Coord& location);
Portal(Portal* other, Player* newOwner);
Coord location;
Player* owner;
int color;
};
class Trail {
public:
Trail(int owner, int tick, int type);
Trail(Trail* other);
void set(int owner, int tick, int type);
void apocalify();
int p1Tick, p1Type;
bool p1Exist;
int p2Tick, p2Type;
bool p2Exist;
bool apocalypse;
};
class Bomb {
public:
Bomb(Player* owner, Coord& location);
Bomb(Bomb* other, Player* newOwner);
Coord location;
Player* owner;
int tick;
};
class Player {
public:
Player(int playerNum);
Player(Player* other);
void kill();
bool alive;
int playerNum; // is this player1 or player2?
int coins, bombCount, bombPierce, bombRange;
Coord location;
Portal *orangePortal, *bluePortal;
std::string lastMove;
};
class Game {
// The actual game. I just converted Darwin's node code to c++
// because node is garbage
public:
Game();
Game(Game* other);
virtual ~Game();
void advanceApocalypseIterator();
void loadFromJSON(const json& j);
std::string hash();
int whoWon();
bool isOutOfBounds(const Coord& loc);
Coord getNextSquare(int x, int y, int direction);
Coord simulateMovement(int x, int y, int direction);
int getBlockValue(int x, int y);
int querySpace(int x, int y);
void trailResolveSquare(int x, int y);
void placeTrail(Player* owner, int x, int y, int type);
void recursiveDetonate(Player* owner, int x, int y, int direction, int range, int pierce, bool pierceMode);
void detonate(int x, int y);
void deletePortal(int x, int y, int direction);
void shootPortal(Player* owner, int direction, int portalColor);
std::string submit(Player* currentPlayer, const std::string& move);
std::vector<std::string> filterPointlessMoves();
std::vector<Game*> getChildren();
void render();
static bool isAMoveMove(std::string move);
static std::string getCounterMove(std::string move);
static int getDirectionOf(std::string clm);
static std::vector<std::string> allMoves;
// Maybe should use getters but meh
int boardSize;
bool running, p1First; // Whether player1 goes first this turn
int moveNumber;
int winner, mePlayer, lastPlayer; // 0 for player1, 1 for player2;
std::string lastMove; // Here we have the move that was last made. Or something.
Player *player1, *player2; // Player class also has person id
Coord apocalypseIterator1, apocalypseIterator2;
Player *currentPlayer;
std::map<int, Bomb*> bombMap;
std::vector<int> hardBlockBoard, softBlockBoard;
int currentTurn; // 0 for first in order, 1 for second
std::map<int, Trail*> trailMap;
std::map<int, std::map<int, Portal*> > portalMap;
};
#endif