11#include " player_code.h"
22
3- void init_constants () {
3+ std::ostringstream all_logs;
44
5- std::cin >> Constants::NO_OF_TURNS >> Constants::MAX_NO_OF_COINS;
5+ // make global object for holding all ids of attackers whose abilities activated
66
7+ void init_constants () {
78 // All the attacker types
89 std::cin >> Constants::NO_OF_ATTACKER_TYPES;
910
1011 std::unordered_map<size_t , Attributes> attacker_type_to_attributes;
1112 for (size_t i = 1 ; i <= Constants::NO_OF_ATTACKER_TYPES; i++) {
12- unsigned hp, range, attack_power, speed, price, is_aerial;
13- std::cin >> hp >> range >> attack_power >> speed >> price >> is_aerial;
13+ unsigned hp, range, attack_power, speed, price, is_aerial , weight, num_ability_turns, ability_activation_cost ;
14+ std::cin >> hp >> range >> attack_power >> speed >> price >> is_aerial >> weight >> num_ability_turns >> ability_activation_cost ;
1415 attacker_type_to_attributes.insert (
15- std::make_pair (i, Attributes (hp, range, attack_power, speed, price, is_aerial)));
16+ std::make_pair (i, Attributes (hp, range, attack_power, speed, price, is_aerial,weight, num_ability_turns,ability_activation_cost )));
1617 }
1718 Constants::ATTACKER_TYPE_ATTRIBUTES = attacker_type_to_attributes;
1819
@@ -24,7 +25,7 @@ void init_constants() {
2425 unsigned hp, range, attack_power, speed, price, is_aerial;
2526 std::cin >> hp >> range >> attack_power >> speed >> price >> is_aerial;
2627 defender_type_to_attributes.insert (
27- std::make_pair (i, Attributes (hp, range, attack_power, speed, price, is_aerial)));
28+ std::make_pair (i, Attributes (hp, range, attack_power, speed, price, is_aerial, 0 , 0 , 0 )));
2829 }
2930 Constants::DEFENDER_TYPE_ATTRIBUTES = defender_type_to_attributes;
3031}
@@ -36,19 +37,19 @@ Map get_initial_map() {
3637 return map;
3738}
3839
39- void output (State &state, Game &game) {
40-
41- // Player logs are logged to cerr, so that driver will collect it
40+ void output (size_t turn_no, Game &game) {
4241 game.logr ().flush ();
42+
4343 if (!game.logr ().view ().empty ()) {
44- std::cerr << " TURN " << state. get_turn_no () << ' \n ' ;
45- std::cerr << game.logr ().view () << ' \n ' ;
46- std::cerr << " ENDLOG" << std::endl;
44+ all_logs << " TURN " << turn_no << std::endl ;
45+ all_logs << game.logr ().view () << std::endl ;
46+ all_logs << " ENDLOG" << std::endl;
4747 }
4848
4949 // Game details logged
5050 const auto &spawn_positions = game.get_spawn_positions ();
5151 const auto &player_set_targets = game.get_player_set_targets ();
52+ const auto &ability_activations = game.get_ability_activations ();
5253
5354 std::cout << spawn_positions.size () << std::endl;
5455 for (const auto &entry : spawn_positions) {
@@ -60,20 +61,27 @@ void output(State &state, Game &game) {
6061 for (const auto &entry : player_set_targets) {
6162 std::cout << entry.first << " " << entry.second << std::endl;
6263 }
64+
65+ std::cout << ability_activations.size () << std::endl;
66+ for (const auto &attacker_id : ability_activations) {
67+ std::cout << attacker_id << std::endl;
68+ }
6369}
6470
6571void dump_logs (State &state, Game &game) {}
6672
73+ void dump_logs (PvPState& state, Game &game) {}
74+
6775State next_state (size_t cur_turn_no) {
6876 size_t no_of_active_defenders;
6977 size_t no_of_active_attackers;
7078
7179 std::cin >> no_of_active_attackers;
7280 std::vector<Attacker> attackers;
7381 for (size_t i = 0 ; i < no_of_active_attackers; i++) {
74- size_t id, hp, x, y, type;
75- std::cin >> id >> x >> y >> type >> hp;
76- attackers.push_back (Attacker (id, hp, type, Position (x, y)));
82+ size_t id, hp, x, y, type, is_ability_active ;
83+ std::cin >> id >> x >> y >> type >> hp >> is_ability_active ;
84+ attackers.push_back (Attacker (id, hp, type, Position (x, y), is_ability_active ));
7785 }
7886
7987 std::cin >> no_of_active_defenders;
@@ -90,19 +98,87 @@ State next_state(size_t cur_turn_no) {
9098 return {move (attackers), move (defenders), coins_left, cur_turn_no + 1 };
9199}
92100
93- int main ( ) {
94- init_constants () ;
95- Map initial_map = get_initial_map () ;
101+ PvPState pvp_next_state ( size_t cur_turn_no ) {
102+ size_t no_of_active_attackers ;
103+ size_t no_of_opponent_attackers ;
96104
97- State state ({}, initial_map.spawn_defenders (), Constants::MAX_NO_OF_COINS, 0 );
105+ std::cin >> no_of_active_attackers;
106+ std::vector<Attacker> attackers;
107+ for (size_t i = 0 ; i < no_of_active_attackers; i++) {
108+ size_t id, hp, x, y, type, is_ability_active;
109+ std::cin >> id >> x >> y >> type >> hp >> is_ability_active;
110+ attackers.push_back (Attacker (id, hp, type, Position (x, y), is_ability_active));
111+ }
112+
113+ std::cin >> no_of_opponent_attackers;
114+ std::vector<Attacker> opponent_attackers;
115+ for (size_t i = 0 ; i < no_of_opponent_attackers; i++) {
116+ size_t id, hp, x, y, type, is_ability_active;
117+ std::cin >> id >> x >> y >> type >> hp >> is_ability_active;
118+ opponent_attackers.push_back (Attacker (id, hp, type, Position (x, y), is_ability_active));
119+ }
120+
121+ return {move (attackers), move (opponent_attackers), Constants::PVP_FIXED_COINS, cur_turn_no + 1 };
122+ }
123+
124+ enum class GameType {
125+ NORMAL,
126+ PVP
127+ };
98128
99- auto game = run (state);
129+ GameType string_to_game_type (std::string type) {
130+ if (type == std::string (" normal" )) {
131+ return GameType::NORMAL;
132+ } else {
133+ return GameType::PVP;
134+ }
135+ }
100136
101- output (state, game);
137+ int main (int argc, char ** argv) {
138+
139+ if (argc < 2 ) {
140+ std::cerr << " Usage: " << argv[0 ] << " [game-type]\n " ;
141+ exit (1 );
142+ }
102143
103- for (size_t i = 0 ; i < Constants::NO_OF_TURNS; i++) {
104- state = next_state (state.get_turn_no ());
105- game = run (state);
106- output (state, game);
144+ auto gameType = string_to_game_type (std::string (argv[1 ]));
145+
146+ switch (gameType) {
147+ case GameType::NORMAL: {
148+ std::cin >> Constants::NO_OF_TURNS >> Constants::MAX_NO_OF_COINS;
149+ init_constants ();
150+ Map initial_map = get_initial_map ();
151+ State state ({}, initial_map.spawn_defenders (), Constants::MAX_NO_OF_COINS, 0 );
152+
153+ auto game = run (state);
154+ output (state.get_turn_no (), game);
155+
156+ for (size_t i = 0 ; i < Constants::NO_OF_TURNS; i++) {
157+ state = next_state (state.get_turn_no ());
158+ game = run (state);
159+ output (state.get_turn_no (), game);
160+ }
161+
162+ break ;
163+ }
164+
165+ case GameType::PVP: {
166+ std::cin >> Constants::NO_OF_TURNS >> Constants::PVP_FIXED_COINS;
167+ init_constants ();
168+ PvPState state ({},{},Constants::PVP_FIXED_COINS, 0 );
169+
170+ auto game = run (state);
171+ output (state.get_turn_no (), game);
172+
173+ for (size_t i = 0 ; i < Constants::NO_OF_TURNS; i++) {
174+ state = pvp_next_state (state.get_turn_no ());
175+ game = run (state);
176+ output (state.get_turn_no (), game);
177+ }
178+
179+ break ;
180+ }
107181 }
182+
183+ std::cerr << all_logs.str () << std::endl;
108184}
0 commit comments