ANTWAR C++ SDK
Loading...
Searching...
No Matches
game_info.hpp
Go to the documentation of this file.
1
11#pragma once
12
13#include <vector>
14#include <utility>
15#include <cmath>
16#include <cassert>
17#include <algorithm>
18#include <fstream>
19#include <iomanip>
20#include "common.hpp"
21#include "optional.hpp"
22
28{
29 int round;
33 int coins[2];
36 int super_weapon_cd[2][SuperWeaponCount];
37
40
41 GameInfo(unsigned long long seed)
42 : round(0), bases{Base(0), Base(1)}, coins{COIN_INIT, COIN_INIT},
44 {
45 // Initialize pheromone
46 Random random(seed);
47 for(int i = 0; i < 2; i++)
48 for(int j = 0; j < MAP_SIZE; j++)
49 for(int k = 0; k < MAP_SIZE; k++)
50 pheromone[i][j][k] = random.get() * std::pow(2, -46) + 8;
51 }
52
53 /* Getters */
54
61 template<typename T, typename Pred>
62 optional<T> find_one(const std::vector<T>& v, Pred pred) const
63 {
64 auto it = std::find_if(v.begin(), v.end(), pred);
65 if (it != v.end())
66 return make_optional<T>(*it);
67 else
68 return nullopt;
69 }
70
77 template<typename T, typename Pred>
78 std::vector<T> find_all(const std::vector<T>& v, Pred pred) const
79 {
80 std::vector<T> fit_elems;
81 for (const T& e: v)
82 if (pred(e))
83 fit_elems.emplace_back(e);
84 return fit_elems;
85 }
86
87 // Ant
88
94 {
95 return ants;
96 }
97
104 std::vector<Ant> ant_at(int x, int y) const
105 {
106 return find_all(ants, [x, y](const Ant &a){ return a.x == x && a.y == y; });
107 }
108
115 optional<Ant> ant_of_id(int id) const
116 {
117 return find_one(ants, [id](const Ant &a) { return a.id == id; });
118 }
119
125 int ant_of_id_by_index(int id) const
126 {
127 auto it = std::find_if(ants.begin(), ants.end(), [&](const Ant &a)
128 { return a.id == id; });
129 if (it != ants.end())
130 return it - ants.begin();
131 else
132 return -1;
133 }
134
135 // Tower
136
142 {
143 return towers;
144 }
145
153 optional<Tower> tower_at(int x, int y) const
154 {
155 return find_one(
156 towers, [x, y](const Tower &t) { return t.x == x && t.y == y; });
157 }
158
165 optional<Tower> tower_of_id(int id) const
166 {
167 return find_one(
168 towers, [id](const Tower &t) { return t.id == id; });
169 }
170
171 /* Setters */
172
181 void build_tower(int id, int player, int x, int y, TowerType type = TowerType::Basic)
182 {
183 towers.emplace_back(id, player, x, y, type);
184 }
185
191 void upgrade_tower(int id, TowerType type)
192 {
193 auto it = std::find_if(towers.begin(), towers.end(), [&](const Tower &t)
194 { return t.id == id; });
195 if (it != towers.end())
196 {
197 it->upgrade(type);
198 }
199 }
200
207 {
208 auto it = std::find_if(towers.begin(), towers.end(), [&](const Tower &t)
209 { return t.id == id; });
210 if (it != towers.end())
211 {
212 if (it->is_downgrade_valid()) // Downgrade
213 it->downgrade();
214 else // Destroy
215 towers.erase(it);
216 }
217 }
218
219 void upgrade_generation_speed(int player_id)
220 {
221 bases[player_id].upgrade_generation_speed();
222 }
223
224 void upgrade_generated_ant(int player_id)
225 {
226 bases[player_id].upgrade_generated_ant();
227 }
228
232 void set_coin(int player_id, int value)
233 {
234 coins[player_id] = value;
235 }
236
240 void update_coin(int player_id, int change)
241 {
242 coins[player_id] += change;
243 }
244
248 void set_base_hp(int player_id, int value)
249 {
250 bases[player_id].hp = value;
251 }
252
256 void update_base_hp(int player_id, int change)
257 {
258 bases[player_id].hp += change;
259 }
260
261 /* Ants and pheromone updaters. */
262
267 {
268 for (auto it = ants.begin(); it != ants.end();)
269 {
270 if (it->state == AntState::Success || it->state == AntState::Fail || it->state == AntState::TooOld)
271 it = ants.erase(it);
272 else
273 ++it;
274 }
275 }
276
281 {
282 for (const Ant& ant : ants)
283 update_pheromone(ant);
284 }
285
290 void update_pheromone(const Ant &ant)
291 {
292 // Parameters for the algorithm
293 static constexpr double TAU[] = {0.0, 10.0, -5, -3};
294
295 // Do nothing if the ant is alive or frozen
296 if (ant.state == AntState::Alive || ant.state == AntState::Frozen)
297 return;
298
299 // Update pheromone from start to end
300 int tau = TAU[ant.state];
301 int player = ant.player;
302 int x = Base::POSITION[player][0], y = Base::POSITION[player][1];
303 bool visited[MAP_SIZE][MAP_SIZE] = {};
304
305 for (int move: ant.path)
306 {
307 // If not visited yet
308 if (!visited[x][y])
309 {
310 visited[x][y] = true; // Mark on the map
311 pheromone[player][x][y] += tau; // Update pheromone
312 if (pheromone[player][x][y] < PHEROMONE_MIN) // No underflow
313 pheromone[player][x][y] = PHEROMONE_MIN;
314 }
315 // Move to next position
316 x += OFFSET[y % 2][move][0];
317 y += OFFSET[y % 2][move][1];
318 }
319
320 // Should have reached the end now
321 assert(x == ant.x && y == ant.y);
322 if (!visited[x][y]) // Update at the current position if not visited yet
323 {
324 pheromone[player][x][y] += tau;
325 if (pheromone[player][x][y] < PHEROMONE_MIN)
326 pheromone[player][x][y] = PHEROMONE_MIN;
327 }
328 }
329
334 {
335 for (int i = 0; i < 2; ++i)
336 for (int j = 0; j < MAP_SIZE; ++j)
337 for (int k = 0; k < MAP_SIZE; ++k)
338 pheromone[i][j][k] =
339 PHEROMONE_ATTENUATING_RATIO * pheromone[i][j][k]
340 + (1 - PHEROMONE_ATTENUATING_RATIO) * PHEROMONE_INIT;
341 }
342
343 /* Operation checkers and appliers */
344
350 int tower_num_of_player(int player_id) const
351 {
352 return std::count_if(
353 towers.begin(),
354 towers.end(),
355 [player_id](const Tower& tower) {
356 return tower.player == player_id;
357 }
358 );
359 }
360
369 bool is_operation_valid(int player_id, const Operation& op) const
370 {
371 switch (op.type)
372 {
373 case BuildTower:
374 return is_highland(player_id, op.arg0, op.arg1)
375 && !tower_at(op.arg0, op.arg1)
376 && !is_shielded_by_emp(player_id, op.arg0, op.arg1);
377 case UpgradeTower:
378 {
379 auto t = tower_of_id(op.arg0);
380 return t && t.value().player == player_id
381 && t.value().is_upgrade_type_valid(op.arg1)
382 && !is_shielded_by_emp(t.value());
383 }
384 case DowngradeTower:
385 {
386 auto t = tower_of_id(op.arg0);
387 return t && t.value().player == player_id
388 && !is_shielded_by_emp(t.value());
389 }
391 case UseEmpBlaster:
392 case UseDeflector:
394 return is_valid_pos(op.arg0, op.arg1)
395 && super_weapon_cd[player_id][op.type % 10] <= 0;
397 return bases[player_id].gen_speed_level < 2;
399 return bases[player_id].ant_level < 2;
400 default:
401 return false;
402 }
403 }
404
412 bool is_operation_valid(int player_id, const std::vector<Operation>& ops, const Operation& new_op) const
413 {
414 // Check if there are multiple operations of the same type
415 bool collide = false;
416 switch (new_op.type)
417 {
418 // At specified position only one tower can be built
419 case OperationType::BuildTower:
420 collide = std::any_of(ops.begin(), ops.end(), [&](const Operation& op) {
421 return op.type == BuildTower && op.arg0 == new_op.arg0 && op.arg1 == new_op.arg1;
422 });
423 break;
424 // A tower can only be upgraded/downgraded once
425 case OperationType::UpgradeTower:
426 case OperationType::DowngradeTower:
427 collide = std::any_of(ops.begin(), ops.end(), [&](const Operation& op) {
428 return (op.type == UpgradeTower || op.type == DowngradeTower) && op.arg0 == new_op.arg0;
429 });
430 break;
431 // Base can only be upgraded once
432 case OperationType::UpgradeGeneratedAnt:
433 case OperationType::UpgradeGenerationSpeed:
434 collide = std::any_of(ops.begin(), ops.end(), [&](const Operation& op) {
435 return op.type == UpgradeGeneratedAnt || op.type == UpgradeGenerationSpeed;
436 });
437 break;
438 // Super weapon of specified type can only be used once
439 case OperationType::UseLightningStorm:
440 case OperationType::UseEmpBlaster:
441 case OperationType::UseDeflector:
442 case OperationType::UseEmergencyEvasion:
443 collide = std::any_of(ops.begin(), ops.end(), [&](const Operation& op) {
444 return op.type == new_op.type;
445 });
446 break;
447 // Illegal operation type
448 default:
449 return false;
450 }
451 if (collide)
452 return false;
453
454 // Check operation validness
455 if (!is_operation_valid(player_id, new_op))
456 return false;
457
458 // Check if the player has enough coins
459 std::vector<Operation> new_ops(ops);
460 new_ops.push_back(new_op);
461 if (!check_affordable(player_id, new_ops))
462 return false;
463
464 // Pass all checks. The operation has been added successfully.
465 return true;
466 }
467
475 int get_operation_income(int player_id, const Operation& op) const
476 {
477 switch (op.type)
478 {
479 case BuildTower:
480 return -build_tower_cost(tower_num_of_player(player_id));
481 case UpgradeTower:
482 return -upgrade_tower_cost(op.arg1);
483 case DowngradeTower:
484 {
485 auto t = tower_of_id(op.arg0);
486 if (t.value().type == TowerType::Basic) // To be destroyed
487 return destroy_tower_income(tower_num_of_player(player_id));
488 else // To be downgraded
489 return downgrade_tower_income(t.value().type);
490 }
492 case UseEmpBlaster:
493 case UseDeflector:
495 return -use_super_weapon_cost(op.type % 10);
497 return -upgrade_base_cost(bases[player_id].gen_speed_level);
499 return -upgrade_base_cost(bases[player_id].ant_level);
500 default:
501 return 0;
502 }
503 }
504
511 bool check_affordable(int player_id, const std::vector<Operation>& ops) const
512 {
513 int income = 0, tower_num = tower_num_of_player(player_id);
514 for (const Operation& op : ops)
515 {
516 // Special handling for BuildTower and DowngradeTower, for the cost of
517 // BuildTower and DowngradeTower depends on the number of towers of the player.
518 switch (op.type)
519 {
520 case OperationType::BuildTower:
521 income -= build_tower_cost(tower_num++);
522 break;
523 case OperationType::DowngradeTower:
524 {
525 auto t = tower_of_id(op.arg0);
526 if (t.value().type == TowerType::Basic) // To be destroyed
527 income += destroy_tower_income(tower_num--);
528 else // To be downgraded
529 income += downgrade_tower_income(t.value().type);
530 break;
531 }
532 default:
533 income += get_operation_income(player_id, op);
534 break;
535 }
536 }
537 return income + coins[player_id] >= 0;
538 }
539
545 void apply_operation(int player_id, const Operation& op)
546 {
547 update_coin(player_id, get_operation_income(player_id, op));
548 switch (op.type)
549 {
550 case BuildTower:
551 build_tower(next_tower_id++, player_id, op.arg0, op.arg1);
552 break;
553 case UpgradeTower:
554 upgrade_tower(op.arg0, static_cast<TowerType>(op.arg1));
555 break;
556 case DowngradeTower:
558 break;
560 case UseEmpBlaster:
561 case UseDeflector:
563 use_super_weapon(static_cast<SuperWeaponType>(op.type % 10), player_id, op.arg0, op.arg1);
564 break;
566 upgrade_generation_speed(player_id);
567 break;
569 upgrade_generated_ant(player_id);
570 break;
571 }
572 }
573
574 /* ACO predictors */
575
581 int next_move(const Ant& ant) const
582 {
583 // Constants
584 static constexpr double ETA[] = {1.25, 1.00, 0.75};
585 static constexpr int ETA_OFFSET = 1;
586
587 // Data
588 int target_x = Base::POSITION[!ant.player][0],
589 target_y = Base::POSITION[!ant.player][1];
590 int cur_dist = distance(ant.x, ant.y, target_x, target_y);
591
592 // Store weighted and original pheromone
593 double phero[6][2] = {};
594 static constexpr int WEIGHTED = 0, ORIGINAL = 1;
595 std::fill(&phero[0][0], &phero[0][0] + sizeof(phero) / sizeof(double), -1.0); // Init
596
597 // Compute weighted and original pheromone
598 for (int i = 0; i < 6; ++i)
599 {
600 // Neighbor coordinates
601 int x = ant.x + OFFSET[ant.y % 2][i][0],
602 y = ant.y + OFFSET[ant.y % 2][i][1];
603 // Valid: not blocked and not going back
604 if ((!ant.path.empty() && ant.path.back() == (i + 3) % 6) || !is_path(x, y))
605 continue;
606 // Weight (Atrract)
607 int next_dist = distance(x, y, target_x, target_y);
608 double weight = ETA[next_dist - cur_dist + ETA_OFFSET];
609 // Update
610 phero[i][WEIGHTED] = weight * pheromone[ant.player][x][y];
611 phero[i][ORIGINAL] = pheromone[ant.player][x][y];
612 }
613
614 // Get max
615 auto p = std::max_element(phero, std::end(phero),
616 [phero] (const double ph1[], const double ph2[]) {
617 // Check weighted pheromone
618 if (ph1[WEIGHTED] != ph2[WEIGHTED])
619 return ph1[WEIGHTED] < ph2[WEIGHTED];
620 // Then check original pheromone
621 if (ph1[ORIGINAL] != ph2[ORIGINAL])
622 return ph1[ORIGINAL] < ph2[ORIGINAL];
623 // If all equals, take one with smaller index as the bigger
624 return std::distance(&phero[0][0], ph1) > std::distance(&phero[0][0], ph2);
625 });
626
627 // Return direction
628 return std::distance(phero, p);
629 }
630
631 /* Caculators for economy */
632
638 static int destroy_tower_income(int tower_num)
639 {
640 return build_tower_cost(tower_num - 1) * TOWER_DOWNGRADE_REFUND_RATIO;
641 }
642
648 static int downgrade_tower_income(int type)
649 {
650 return upgrade_tower_cost(type) * TOWER_DOWNGRADE_REFUND_RATIO;
651 }
652
658 static int build_tower_cost(int tower_num)
659 {
660 return TOWER_BUILD_PRICE_BASE * std::pow(TOWER_BUILD_PRICE_RATIO, tower_num);
661 }
662
668 static int upgrade_tower_cost(int type)
669 {
670 switch (type)
671 {
672 // Level 2
673 case TowerType::Heavy:
674 case TowerType::Quick:
675 case TowerType::Mortar:
676 return LEVEL2_TOWER_UPGRADE_PRICE;
677 // Level 3
678 case TowerType::HeavyPlus:
679 case TowerType::Ice:
680 case TowerType::Cannon:
681 case TowerType::QuickPlus:
682 case TowerType::Double:
683 case TowerType::Sniper:
684 case TowerType::MortarPlus:
685 case TowerType::Pulse:
686 case TowerType::Missile:
687 return LEVEL3_TOWER_UPGRADE_PRICE;
688 }
689 return -1;
690 }
691
697 static int upgrade_base_cost(int level)
698 {
699 switch (level)
700 {
701 case 0: return LEVEL2_BASE_UPGRADE_PRICE;
702 case 1: return LEVEL3_BASE_UPGRADE_PRICE;
703 }
704 return -1;
705 }
706
712 static int use_super_weapon_cost(int type)
713 {
714 return SUPER_WEAPON_INFO[type][3];
715 }
716
717 /* Super weapons */
718
722 void use_super_weapon(SuperWeaponType type, int player, int x, int y)
723 {
724 // Construct a super weapon
725 SuperWeapon sw(type, player, x, y);
726 // Apply EmergercyEvasion directly
727 if (sw.type == EmergencyEvasion)
728 {
729 for (Ant &ant : ants)
730 {
731 if (sw.is_in_range(ant.x, ant.y) && ant.player == sw.player)
732 ant.evasion = 2;
733 }
734 }
735 // Add to super weapon list for other super weapons
736 else
738 // Reset cd
739 super_weapon_cd[player][type] = SUPER_WEAPON_INFO[type][2];
740 }
741
746 bool is_shielded_by_emp(int player_id, int x, int y) const
747 {
748 return std::any_of(super_weapons.begin(), super_weapons.end(), [player_id, x, y](const SuperWeapon& weapon){
749 return weapon.type == EmpBlaster && weapon.player != player_id && weapon.is_in_range(x, y);
750 });
751 }
752
757 bool is_shielded_by_emp(const Tower& tower) const
758 {
759 return is_shielded_by_emp(tower.player, tower.x, tower.y);
760 }
761
766 bool is_shielded_by_deflector(const Ant& a) const
767 {
768 return std::any_of(super_weapons.begin(), super_weapons.end(), [a](const SuperWeapon& weapon){
769 return weapon.type == Deflector && weapon.player == a.player && weapon.is_in_range(a.x, a.y);
770 });
771 }
772
777 {
778 for (auto it = super_weapons.begin(); it != super_weapons.end(); )
779 {
780 if (it->player != player_id)
781 {
782 ++it;
783 continue;
784 }
785 // Count down
786 it->left_time--;
787 // Clear if timeout
788 if (it->left_time <= 0)
789 it = super_weapons.erase(it);
790 else
791 ++it;
792 }
793 }
794
799 {
800 for (int i = 0; i < 2; ++i)
801 for (int j = 1; j < 5; ++j)
802 super_weapon_cd[i][j] = std::max(super_weapon_cd[i][j] - 1, 0);
803 }
804
805 /* For debug */
806
810 void show() const
811 {
812 std::ofstream fout("info.out");
813 fout << "Rounds:" << round << std::endl;
814 // Towers
815 fout << "Towers:" << std::endl;
816 fout << "id\tplayer\tx\ty\ttype\tcd" << std::endl;
817 for (auto& tower : towers)
818 fout << tower.id << '\t' << tower.player << "\t\t" << tower.x << '\t' << tower.y << '\t' << tower.type <<'\t' << tower.cd << std::endl;
819 // Ants
820 fout << "Ants:" << std::endl;
821 fout << "id\tplayer\tx\ty\thp\tage\tstate" << std::endl;
822 for (auto& ant : ants)
823 fout << ant.id << '\t' << ant.player << "\t\t" << ant.x << '\t' << ant.y << '\t' << ant.hp << '\t' << ant.age << '\t' << ant.state << std::endl;
824 // Coins
825 fout << "coin0:" << coins[0] << std::endl;
826 fout << "coin1:" << coins[1] << std::endl;
827 // Bases
828 fout << "base0:" << bases[0].hp << std::endl;
829 fout << "base1:" << bases[1].hp << std::endl;
830
831 fout.close();
832 }
833
837 void dump(std::ofstream& fout) const
838 {
839 // Round
840 fout << round << std::endl;
841 // Towers
842 fout << towers.size() << std::endl;
843 for (auto& tower : towers)
844 fout << tower.id << ' '
845 << tower.player << ' '
846 << tower.x << ' '
847 << tower.y << ' '
848 << tower.type << ' '
849 << tower.cd << std::endl;
850 // Ants
851 fout << ants.size() << std::endl;
852 for (auto& ant : ants)
853 fout << ant.id << ' '
854 << ant.player << ' '
855 << ant.x << ' '
856 << ant.y << ' '
857 << ant.hp << ' '
858 << ant.level << ' '
859 << ant.age << ' '
860 << ant.state << std::endl;
861 // Coins
862 fout << coins[0] << ' ' << coins[1] << std::endl;
863 // Hp
864 fout << bases[0].hp << ' ' << bases[1].hp << std::endl;
865 // Pheromone
866 for (int player = 0; player < 2; ++player)
867 {
868 for (int i = 0; i < MAP_SIZE; ++i)
869 {
870 for (int j = 0; j < MAP_SIZE; ++j)
871 {
872 fout << std::fixed << std::setprecision(4) << pheromone[player][i][j] << ' ';
873 }
874 fout << std::endl;
875 }
876 }
877 }
878
882 void dump(const char filename[]) const
883 {
884 std::ofstream fout(filename, std::ios::app);
885 dump(fout);
886 fout.close();
887 }
888};
T any_of(T... args)
T back(T... args)
T begin(T... args)
T close(T... args)
Models and constants.
bool is_highland(int player, int x, int y)
Check if a player can build towers at given position.
Definition: common.hpp:163
SuperWeaponType
Tag for the type of a super weapon. The integer values of these enumeration items are also their inde...
Definition: common.hpp:670
static constexpr int SUPER_WEAPON_INFO[5][4]
Static information of all types of super weapons.
Definition: common.hpp:682
TowerType
Tag for the type of a tower. The integer values of these enumeration items are also their indexes.
Definition: common.hpp:319
static constexpr int MAP_SIZE
Size of the map.
Definition: common.hpp:46
static constexpr int OFFSET[2][6][2]
The offsets between the coordinates of the current point and its surrounding 6 points.
Definition: common.hpp:103
@ UpgradeTower
Upgrade a tower.
Definition: common.hpp:726
@ UseEmpBlaster
Use an EMP blaster.
Definition: common.hpp:730
@ UpgradeGenerationSpeed
Increase ant producing speed.
Definition: common.hpp:734
@ UpgradeGeneratedAnt
Increase HP of newly generated ants.
Definition: common.hpp:735
@ UseDeflector
Use a deflector.
Definition: common.hpp:731
@ UseEmergencyEvasion
Use an emergency evasion.
Definition: common.hpp:732
@ BuildTower
Build a tower.
Definition: common.hpp:725
@ DowngradeTower
Downgrade/Destroy a tower.
Definition: common.hpp:727
@ UseLightningStorm
Use a lightning storm.
Definition: common.hpp:729
int distance(int x0, int y0, int x1, int y1)
Get the distance between two points on the map (NOT Euclidean distance).
Definition: common.hpp:114
bool is_path(int x, int y)
Check if the given position is reachable for ants.
Definition: common.hpp:150
bool is_valid_pos(int x, int y)
Check if the given coordinates refers to a valid point on the map.
Definition: common.hpp:137
T count_if(T... args)
T distance(T... args)
T emplace_back(T... args)
T empty(T... args)
T end(T... args)
T endl(T... args)
T erase(T... args)
T fill(T... args)
T find_if(T... args)
T fixed(T... args)
T max_element(T... args)
T max(T... args)
T move(T... args)
T pow(T... args)
T push_back(T... args)
T setprecision(T... args)
T size(T... args)
Basic attacking unit.
Definition: common.hpp:230
Target to protect or to destroy.
Definition: common.hpp:613
void upgrade_generated_ant()
Upgrade ant generation speed.
Definition: common.hpp:656
int gen_speed_level
Level of production speed.
Definition: common.hpp:617
void upgrade_generation_speed()
Upgrade ant generation speed.
Definition: common.hpp:648
static constexpr int POSITION[2][2]
Positions for both players.
Definition: common.hpp:621
int ant_level
Level of produced ants.
Definition: common.hpp:618
A module used for game state management, providing interfaces for accessing and modifying various typ...
Definition: game_info.hpp:28
int round
Current round number.
Definition: game_info.hpp:29
bool is_shielded_by_emp(int player_id, int x, int y) const
Check whether a point is shielded by EmpBluster for a player.
Definition: game_info.hpp:746
bool is_shielded_by_deflector(const Ant &a) const
Check whether an ant is shielded by Deflector for a player.
Definition: game_info.hpp:766
optional< Ant > ant_of_id(int id) const
Find the ant of a specific ID.
Definition: game_info.hpp:115
std::vector< Tower > all_towers() const
Get all towers on the map.
Definition: game_info.hpp:141
void update_pheromone(const Ant &ant)
Update pheromone based on the state of an ant.
Definition: game_info.hpp:290
void update_base_hp(int player_id, int change)
Update the hp of base for a player.
Definition: game_info.hpp:256
void dump(std::ofstream &fout) const
Dump current information with ofstream.
Definition: game_info.hpp:837
void dump(const char filename[]) const
Dump current information to file.
Definition: game_info.hpp:882
void count_down_super_weapons_cd()
Count down cd of all types of super weapons.
Definition: game_info.hpp:798
std::vector< Ant > ants
All ants on the map.
Definition: game_info.hpp:31
int next_ant_id
ID of the next generated ant.
Definition: game_info.hpp:38
bool is_shielded_by_emp(const Tower &tower) const
Check whether a tower is shielded by EmpBluster.
Definition: game_info.hpp:757
void update_pheromone_for_ants()
Update pheromone for each ant.
Definition: game_info.hpp:280
void clear_dead_and_succeeded_ants()
Clear ants of state "Success", "Fail" or "TooOld".
Definition: game_info.hpp:266
std::vector< SuperWeapon > super_weapons
Super weapons being used.
Definition: game_info.hpp:35
int get_operation_income(int player_id, const Operation &op) const
Get the income of an operation BEFORE applied. The income could be negative, which means the operatio...
Definition: game_info.hpp:475
void global_pheromone_attenuation()
Global pheromone attenuation.
Definition: game_info.hpp:333
optional< T > find_one(const std::vector< T > &v, Pred pred) const
Find no more than one element in the given vector for which a predicate is true.
Definition: game_info.hpp:62
static int build_tower_cost(int tower_num)
Calculate the cost of building a tower for a player.
Definition: game_info.hpp:658
void update_coin(int player_id, int change)
Update the number of coins for a player.
Definition: game_info.hpp:240
void build_tower(int id, int player, int x, int y, TowerType type=TowerType::Basic)
Emplace a new tower at the back of vector "towers".
Definition: game_info.hpp:181
void downgrade_or_destroy_tower(int id)
Find the tower of a specific ID and downgrade it if possible. Otherwise, erase it from vector "towers...
Definition: game_info.hpp:206
double pheromone[2][MAP_SIZE][MAP_SIZE]
Pheromone of each point on the map: "pheromone[player_id][x][y]".
Definition: game_info.hpp:34
bool is_operation_valid(int player_id, const std::vector< Operation > &ops, const Operation &new_op) const
Check whether the newly added operation is valid, considering not only the operation itself,...
Definition: game_info.hpp:412
std::vector< Ant > all_ants() const
Get all ants on the map.
Definition: game_info.hpp:93
static int destroy_tower_income(int tower_num)
Calculate the income of detroying a tower for a player.
Definition: game_info.hpp:638
bool is_operation_valid(int player_id, const Operation &op) const
Check operation validness.
Definition: game_info.hpp:369
static int use_super_weapon_cost(int type)
Calculate the cost of using a super weapon.
Definition: game_info.hpp:712
int ant_of_id_by_index(int id) const
Find the ant of a specific ID and get its index in vector "ants".
Definition: game_info.hpp:125
int super_weapon_cd[2][SuperWeaponCount]
Super weapon cooldown of both sides: "super_weapon_cd[player_id]".
Definition: game_info.hpp:36
int next_tower_id
ID of the next built tower.
Definition: game_info.hpp:39
std::vector< Tower > towers
All towers on the map.
Definition: game_info.hpp:30
void apply_operation(int player_id, const Operation &op)
Change buildings, targets and coin values based on the given operation.
Definition: game_info.hpp:545
int tower_num_of_player(int player_id) const
Count the number of towers of a player.
Definition: game_info.hpp:350
optional< Tower > tower_of_id(int id) const
Find the tower of a specific ID.
Definition: game_info.hpp:165
bool check_affordable(int player_id, const std::vector< Operation > &ops) const
Check whether a player can afford a set of operations.
Definition: game_info.hpp:511
std::vector< Ant > ant_at(int x, int y) const
Find all ants at a specific point.
Definition: game_info.hpp:104
void use_super_weapon(SuperWeaponType type, int player, int x, int y)
Handle the operation of using a super weapon.
Definition: game_info.hpp:722
int next_move(const Ant &ant) const
Get next moving direction for an ant based on the probability, randomly.
Definition: game_info.hpp:581
int coins[2]
Coins of both sides: "coins[player_id]".
Definition: game_info.hpp:33
std::vector< T > find_all(const std::vector< T > &v, Pred pred) const
Find all elements in the given vector for which a predicate is true.
Definition: game_info.hpp:78
void upgrade_tower(int id, TowerType type)
Find the tower of a specific ID, then upgrade it.
Definition: game_info.hpp:191
void count_down_super_weapons_left_time(int player_id)
Count down left_time of super weapons for a player. Clear it if timeout.
Definition: game_info.hpp:776
void set_coin(int player_id, int value)
Set the number of coins for a player.
Definition: game_info.hpp:232
static int downgrade_tower_income(int type)
Calculate the income of downgrading a tower for a player.
Definition: game_info.hpp:648
static int upgrade_base_cost(int level)
Calculate the cost of upgrading a base's generation speed or level of generated ants.
Definition: game_info.hpp:697
static int upgrade_tower_cost(int type)
Calculate the cost of upgrading a tower.
Definition: game_info.hpp:668
Base bases[2]
Bases of both sides: "bases[player_id]".
Definition: game_info.hpp:32
void show() const
Print current information to file "info.out".
Definition: game_info.hpp:810
void set_base_hp(int player_id, int value)
Set the hp of base for a player.
Definition: game_info.hpp:248
optional< Tower > tower_at(int x, int y) const
Find the tower at a specific point.
Definition: game_info.hpp:153
Player's operations. It is able to be applied to the map.
Definition: common.hpp:742
Random noise generator.
Definition: common.hpp:772
Great choice to knockout your opponent.
Definition: common.hpp:694
bool is_in_range(int x, int y) const
Check whether given position is in the range of effect.
Definition: common.hpp:710
Defense unit. Only choice to get yourself armed to the teeth.
Definition: common.hpp:375