-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_code.h
160 lines (129 loc) · 4.26 KB
/
player_code.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
#pragma once
#include <compare>
#include <iostream>
#include <set>
#include <sstream>
#include <unordered_map>
#include <vector>
struct Attributes {
const unsigned hp;
const unsigned range;
const unsigned attack_power;
const unsigned speed;
const unsigned price;
const unsigned is_aerial;
const unsigned weight;
const unsigned num_ability_turns;
const unsigned ability_activation_cost;
Attributes(unsigned hp, unsigned range, unsigned attack_power, unsigned speed,
unsigned price, unsigned is_aerial, unsigned weight, unsigned num_ability_turns, unsigned ability_activation_cost);
};
struct Constants {
static inline size_t MAP_NO_OF_ROWS = 64;
static inline size_t MAP_NO_OF_COLS = 64;
static inline size_t NO_OF_DEFENDER_TYPES;
static inline size_t NO_OF_ATTACKER_TYPES;
static inline size_t NO_OF_TURNS;
static inline size_t MAX_NO_OF_COINS;
static inline size_t PVP_FIXED_COINS = 100;
static inline std::unordered_map<size_t, Attributes> ATTACKER_TYPE_ATTRIBUTES;
static inline std::unordered_map<size_t, Attributes> DEFENDER_TYPE_ATTRIBUTES;
};
class Position {
private:
int _x;
int _y;
public:
Position(int x, int y);
[[nodiscard]] int get_x() const;
[[nodiscard]] int get_y() const;
double distance_to(Position other) const;
auto operator<=>(const Position &other) const = default;
};
bool is_valid_spawn_position(int x, int y);
bool is_valid_spawn_position(Position pos);
std::vector<Position> get_all_valid_spawn_positions();
class Actor {
private:
size_t _id;
size_t _hp;
size_t _type;
Position _position;
public:
Actor(size_t id, size_t hp, size_t type, Position pos);
size_t get_id() const;
size_t get_hp() const;
size_t get_type() const;
Position get_position() const;
};
class Attacker : public Actor {
public:
Attacker(size_t id, size_t hp, size_t type, Position pos, size_t is_ability_active);
size_t is_ability_active;
};
class Defender : public Actor {
public:
Defender(size_t id, size_t hp, size_t type, Position pos);
};
class State {
public:
State(std::vector<Attacker> attackers, std::vector<Defender> defenders,
size_t no_of_coins_left, size_t turn_no);
const std::vector<Attacker> &get_attackers() const;
const std::vector<Defender> &get_defenders() const;
size_t get_turn_no() const;
size_t get_coins_left() const;
private:
size_t _turn_no;
size_t _no_of_coins_left;
std::vector<Attacker> _attackers;
std::vector<Defender> _defenders;
};
class PvPState {
public:
PvPState(std::vector<Attacker> attackers,std::vector<Attacker> opponent_attackers, size_t no_of_coins_left, size_t turn_no);
const std::vector<Attacker> &get_attackers() const;
const std::vector<Attacker> &get_opponent_attackers() const;
size_t get_turn_no() const;
size_t get_coins_left() const;
private:
size_t _turn_no;
size_t _no_of_coins_left;
std::vector<Attacker> _attackers;
std::vector<Attacker> _opponent_attackers;
};
class Game {
public:
Game();
void spawn_attacker(size_t id, Position pos);
bool already_spawned_at_position(Position pos);
void set_target(size_t attacker_id, size_t defender_id);
void set_target(const Attacker &attacker, const Defender &defender);
void set_target(const Attacker &attacker, const Attacker &opponent);
void activate_ability(size_t attacker_id);
std::ostringstream &logr();
const std::unordered_map<size_t, size_t> &get_player_set_targets() const;
const std::vector<std::pair<size_t, Position>> &get_spawn_positions() const;
const std::set<Position> &get_already_spawned_positions() const;
const std::vector<size_t> &get_ability_activations() const;
static inline std::set<size_t> already_activated_attacker_ids;
private:
std::unordered_map<size_t, size_t> _player_set_targets;
std::vector<std::pair<size_t, Position>> _spawn_postions;
std::set<Position> _already_spawned_positions;
std::vector<size_t> _ability_activations;
std::ostringstream _logr;
};
class Map {
public:
Map(std::vector<std::vector<int>> map_as_grid);
static Map get(std::istream &stream);
[[nodiscard]] std::vector<Defender> spawn_defenders() const;
static inline size_t no_of_rows = 64;
static inline size_t no_of_cols = 64;
private:
std::vector<std::vector<int>> _grid;
};
Game run(const State &state);
Game run(const PvPState &state);
#define logger game.logr()