@@ -14,7 +14,7 @@ Game run(const PvPState &state) {
1414
1515 game.logr () << " TURN " << state.get_turn_no () << " LOGS:" ;
1616
17- // Get all the attackers and defenders in the game and store it
17+ // Get all the attackers and opponent in the game and store it
1818 const std::vector<Attacker> &attackers = state.get_attackers ();
1919 const std::vector<Attacker> &opponent_attackers = state.get_opponent_attackers ();
2020
@@ -31,55 +31,60 @@ Game run(const PvPState &state) {
3131 // static variable in c++
3232
3333 static int last_spawned = 0 ;
34- for (size_t type_id = 1 ; type_id <= Constants::NO_OF_ATTACKER_TYPES;
35- type_id++) {
36- // Spawn the attacker of type_id at position
37- // all_valid_spawn_positions[last_spawned]
38-
39- // There are two cases when you might be panalized
40- // - Spawning at invalid position
41- // - Spawning at position where you have already spawned one attacker
42- // in the same turn
43- //
44- // We have provided helpers to check just that
45-
46- // game class will keep track of all your spawned positions for you and
47- // provides a helper method called already_spawned_at_position(Position)
48- // to check if you already spawned in the position
49-
50- // Mostly a good practice to check with these two helpers before spawning,
51- // to save up on accidental penalties
52- if (is_valid_spawn_position (all_valid_spawn_positions[last_spawned]) &&
53- !game.already_spawned_at_position (
54- all_valid_spawn_positions[last_spawned])) {
55- // If lets say you had run out of coins left, the game will just ignore
56- // the spawn
57- game.spawn_attacker (type_id, all_valid_spawn_positions[last_spawned]);
58-
59- // This has the starting attributes for the attacker we are about to
60- // spawn
61- // For full information about the Attributes class refer the
62- // documentation
63- // This can be used for strategizing
64- Attributes attackers_attributes =
65- Constants::ATTACKER_TYPE_ATTRIBUTES.at (type_id);
66-
67- // You can use the logger we provide to show log messages in the
68- // rendered game
69- game.logr () << " To to be spawned at Position("
70- << all_valid_spawn_positions[last_spawned].get_x () << " ,"
71- << all_valid_spawn_positions[last_spawned].get_y () << " )"
72- << ' \n ' ;
73- (last_spawned += 1 ) %= all_valid_spawn_positions.size ();
74- }
34+ for (size_t type_id = 1 ; type_id <= Constants::NO_OF_ATTACKER_TYPES;
35+ type_id++) {
36+ // Spawn the attacker of type_id at position
37+ // all_valid_spawn_positions[last_spawned]
38+
39+ // There are two cases when you might be panalized
40+ // - Spawning at invalid position
41+ // - Spawning at position where you have already spawned one attacker
42+ // in the same turn
43+ //
44+ // We have provided helpers to check just that
45+
46+ // game class will keep track of all your spawned positions for you and
47+ // provides a helper method called already_spawned_at_position(Position)
48+ // to check if you already spawned in the position
49+
50+ // Mostly a good practice to check with these two helpers before spawning,
51+ // to save up on accidental penalties
52+ if (is_valid_spawn_position (all_valid_spawn_positions[last_spawned]) &&
53+ !game.already_spawned_at_position (
54+ all_valid_spawn_positions[last_spawned])) {
55+ // If lets say you had run out of coins left, the game will just ignore
56+ // the spawn
57+ game.spawn_attacker (type_id, all_valid_spawn_positions[last_spawned]);
58+
59+ // This has the starting attributes for the attacker we are about to
60+ // spawn
61+ // For full information about the Attributes class refer the
62+ // documentation
63+ // This can be used for strategizing
64+ Attributes attackers_attributes =
65+ Constants::ATTACKER_TYPE_ATTRIBUTES.at (type_id);
66+
67+ // You can use the logger we provide to show log messages in the
68+ // rendered game
69+ game.logr () << " To to be spawned at Position("
70+ << all_valid_spawn_positions[last_spawned].get_x () << " ,"
71+ << all_valid_spawn_positions[last_spawned].get_y () << " )"
72+ << ' \n ' ;
73+ (last_spawned += 1 ) %= all_valid_spawn_positions.size ();
7574 }
75+ }
7676
7777 // Now lets say you always want to set the target for the attackers[0] to
7878 // defenders[0]
7979 // To do that you do
8080 if (!attackers.empty () && !opponent_attackers.empty ()) {
8181 // check if they are empty beforehand to be safe from unexpected errors
8282 game.set_target (attackers.front (), opponent_attackers.front ());
83+ // lets say i want to activate the ability of the first attacker
84+ // check if ability wasnt activated before to avoid getting penalized
85+ if (!Game::already_activated_attacker_ids.contains (attackers.front ().get_id ())){
86+ game.activate_ability (attackers.front ().get_id ());
87+ }
8388 }
8489
8590 // Lets log all the spawned positions for this turn
0 commit comments