17#include "optional.hpp"
40static constexpr int EDGE = 10;
63 {-1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1},
64 {-1, -1, -1, -1, -1, -1, 0, 0, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, -1},
65 {-1, -1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, -1, -1, -1, -1},
66 {-1, -1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, -1, -1},
67 {0, 0, 2, 2, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 2, 2, 0, 0},
68 {0, 0, 0, 2, 0, 0, 2, 2, 0, 2, 0, 2, 2, 0, 0, 2, 0, 0, 0},
69 {0, 2, 2, 0, 2, 0, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 2, 2, 0},
70 {0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0},
71 {0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0},
72 {0, 1, 3, 0, 3, 1, 0, 1, 0, 1, 0, 1, 0, 1, 3, 0, 3, 1, 0},
73 {0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0},
74 {0, 3, 3, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 3, 3, 0},
75 {0, 3, 0, 0, 0, 0, 3, 3, 0, 3, 0, 3, 3, 0, 0, 0, 0, 3, 0},
76 {0, 0, 3, 3, 0, 0, 0, 3, 0, 3, 0, 3, 0, 0, 0, 3, 3, 0, 0},
77 {-1, 0, 0, 3, 0, 1, 1, 0, 0, 3, 0, 0, 1, 1, 0, 3, 0, 0, -1},
78 {-1, -1, -1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, -1, -1, -1},
79 {-1, -1, -1, -1, -1, 0, 0, 1, 1, 0, 1, 1, 0, 0, -1, -1, -1, -1, -1},
80 {-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1},
81 {-1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
103static constexpr int OFFSET[2][6][2] = {{{0, 1}, {-1, 0}, {0, -1}, {1, -1}, {1, 0}, {1, 1}},
104 {{-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, 0}, {0, 1}}};
116 int dy = abs(y0 - y1);
118 if (abs(y0 - y1) % 2)
121 dx =
std::max(0, abs(x0 - x1) - abs(y0 - y1) / 2 - (y0 % 2));
123 dx =
std::max(0, abs(x0 - x1) - abs(y0 - y1) / 2 - (1 - (y0 % 2)));
126 dx =
std::max(0, abs(x0 - x1) - abs(y0 - y1) / 2);
182 for (
int i = 0; i < 6; ++i)
184 if (
OFFSET[y0 % 2][i][0] == dx &&
OFFSET[y0 % 2][i][1] == dy)
192static constexpr int COIN_INIT = 50,
194static constexpr int TOWER_BUILD_PRICE_BASE = 15,
195 TOWER_BUILD_PRICE_RATIO = 2;
196static constexpr int LEVEL2_TOWER_UPGRADE_PRICE = 60,
197 LEVEL3_TOWER_UPGRADE_PRICE = 200;
198static constexpr double TOWER_DOWNGRADE_REFUND_RATIO = 0.8;
199static constexpr int LEVEL2_BASE_UPGRADE_PRICE = 200,
200 LEVEL3_BASE_UPGRADE_PRICE = 250;
204static constexpr double PHEROMONE_INIT = 10,
206 PHEROMONE_ATTENUATING_RATIO = 0.97;
240 static constexpr int AGE_LIMIT = 32;
241 static constexpr int MAX_HP_INFO[] = {10, 25, 50};
242 static constexpr int REWARD_INFO[] = {3, 5, 7};
247 Ant(
int id,
int player,
int x,
int y,
int hp,
int level,
int age,
AntState state)
248 : id(id), player(player), x(x), y(y), hp(hp), level(level), age(age), state(state), evasion(0), deflector(false) {}
257 x +=
OFFSET[y % 2][direction][0];
258 y +=
OFFSET[y % 2][direction][1];
266 return MAX_HP_INFO[level];
274 return REWARD_INFO[level];
283 return state == AntState::Alive || state == AntState::Frozen;
295 return distance(this->x, this->y, x, y) <= range;
311constexpr int Ant::MAX_HP_INFO[];
312constexpr int Ant::REWARD_INFO[];
357 {}, {}, {}, {}, {}, {}, {},
361 {}, {}, {}, {}, {}, {}, {},
365 {}, {}, {}, {}, {}, {}, {},
389 : id(id), player(player), x(x), y(y), type(type),
cd(
cd)
412 int target_num = type == Double ? 2 : 1;
418 for (
int idx: attackable_idxs)
420 attacked_idxs.
insert(attacked_idxs.
end(), attackable_idxs.
begin(), attackable_idxs.
end());
426 if (!attacked_idxs.
empty())
429 return attacked_idxs;
446 auto bound = target_num <= idxs.
size() ? (idxs.
begin() + target_num) : idxs.
end();
448 int dist1 = distance(ants[i].x, ants[i].y, x, y),
449 dist2 = distance(ants[j].x, ants[j].y, x, y);
451 return dist1 < dist2;
456 if (idxs.
size() > target_num)
472 for (
int idx: target_idxs)
494 return attackable_idxs;
505 else if (ant.deflector && damage < ant.
max_hp() / 2)
511 ant.state = AntState::Frozen;
513 ant.state = AntState::Fail;
528 for (
int i = 0; i < ants.
size(); ++i)
529 if (ants[i].is_attackable_from(player, x, y, range))
571 if (type < TowerType::Basic || type > TowerType::Missile)
575 case TowerType::Basic:
576 return type == TowerType::Heavy || type == TowerType::Quick || type == TowerType::Mortar;
577 case TowerType::Heavy:
578 return type == TowerType::HeavyPlus || type == TowerType::Ice || type == TowerType::Cannon;
579 case TowerType::Quick:
580 return type == TowerType::QuickPlus || type == TowerType::Double || type == TowerType::Sniper;
581 case TowerType::Mortar:
582 return type == TowerType::MortarPlus || type == TowerType::Pulse || type == TowerType::Missile;
592 type =
static_cast<TowerType>(type / 10);
605 return type != TowerType::Basic;
615 const int player, x, y;
620 static constexpr int MAX_HP = 50;
625 : player(player), x(
POSITION[player][0]), y(
POSITION[player][1]), hp(MAX_HP),
674 EmergencyEvasion = 4,
712 return distance(x, y, this->x, this->y) <= range;
754 : type(type), arg0(arg0), arg1(arg1) {}
760 out <<
' ' << op.arg0;
762 out <<
' ' << op.arg1;
777 unsigned long long get()
779 seed = (25214903917 *
seed) & ((1ll << 48) - 1);
static constexpr int EDGE
Length of one edge.
Definition: common.hpp:40
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
PointType
Tag indicating property of points.
Definition: common.hpp:51
@ Path
Ants can pass through here.
Definition: common.hpp:53
@ Void
Out of the map.
Definition: common.hpp:52
@ Barrier
No passing or building here.
Definition: common.hpp:54
@ Player1Highland
Player1 can have buildings here.
Definition: common.hpp:56
@ Player0Highland
Player0 can have buildings here.
Definition: common.hpp:55
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
int get_direction(int x0, int y0, int x1, int y1)
Get the direction of two adjacent points, starting from the first and pointing to the second.
Definition: common.hpp:178
constexpr TowerInfo TOWER_INFO[]
Static information of all types of tower.
Definition: common.hpp:352
static constexpr int MAP_PROPERTY[MAP_SIZE][MAP_SIZE]
Point types of the map.
Definition: common.hpp:62
static constexpr int MAX_ROUND
Max number of rounds.
Definition: common.hpp:22
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
OperationType
Tag for the type of an operation. The integer values of these enumeration items are also their indexe...
Definition: common.hpp:723
@ 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
AntState
State of an ant, indicating its life cycle stages.
Definition: common.hpp:218
@ Frozen
Frozen, cannot move.
Definition: common.hpp:223
@ Fail
Non-positive health points (HP)
Definition: common.hpp:221
@ TooOld
Reach age limit.
Definition: common.hpp:222
@ Alive
Normal case.
Definition: common.hpp:219
@ Success
Reach the opponent's camp.
Definition: common.hpp:220
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
BuildingType
A tag indicating the type of a building on the map.
Definition: common.hpp:30
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 partial_sort(T... args)
Basic attacking unit.
Definition: common.hpp:230
int reward() const
Reward for killing this ant.
Definition: common.hpp:272
bool is_alive() const
Check if the ant is alive, including states AntState::Alive and AntState::Frozen.
Definition: common.hpp:281
bool is_in_range(int x, int y, int range) const
Check if the ant stays in a circle with given point as the center.
Definition: common.hpp:293
Ant(int id, int player, int x, int y, int hp, int level, int age, AntState state)
Construct a new ant with given information.
Definition: common.hpp:247
void move(int direction)
Move the ant in a specified direction.
Definition: common.hpp:254
bool is_attackable_from(int player, int x, int y, int range) const
Check if the ant is attackable by a player from given position and range.
Definition: common.hpp:305
int max_hp() const
HP limit of this ant.
Definition: common.hpp:264
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
optional< Ant > generate_ant(int id, int round)
Try to generate a new ant.
Definition: common.hpp:634
int ant_level
Level of produced ants.
Definition: common.hpp:618
static constexpr int GENERATION_CYCLE_INFO[]
Ants will be generated when round index can be divided by this value.
Definition: common.hpp:622
Player's operations. It is able to be applied to the map.
Definition: common.hpp:742
Operation(OperationType type, int arg0=INVALID_ARG, int arg1=INVALID_ARG)
Construct a new Operation object with specified type and arguments.
Definition: common.hpp:753
static constexpr int INVALID_ARG
Placeholder for the second argument.
Definition: common.hpp:745
Random noise generator.
Definition: common.hpp:772
unsigned long long seed
Seed for pheromone random initialization.
Definition: common.hpp:773
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
Structure of static information of a type of towers.
Definition: common.hpp:343
double speed
Number of rounds required for an attack.
Definition: common.hpp:345
int range
Radius of searching range.
Definition: common.hpp:346
Defense unit. Only choice to get yourself armed to the teeth.
Definition: common.hpp:375
void upgrade(TowerType new_type)
Upgrade tower to new type and reset CD, without checking validness.
Definition: common.hpp:555
bool is_downgrade_valid() const
Check if the tower can be downgraded.
Definition: common.hpp:603
std::vector< int > find_attackable(const std::vector< Ant > &ants, const std::vector< int > &target_idxs) const
Find all ants affected by this attack based on given targets.
Definition: common.hpp:469
std::vector< int > get_attackable_ants(const std::vector< Ant > &ants, int x, int y, int range) const
Find all attackable ants based on given position and range.
Definition: common.hpp:525
void reset_cd()
Reset CD value.
Definition: common.hpp:546
std::vector< int > find_targets(const std::vector< Ant > &ants, int target_num) const
Find certain amount of targets and return its reference by index in order.
Definition: common.hpp:441
std::vector< int > attack(std::vector< Ant > &ants)
Try to attack ants around, and update CD time.
Definition: common.hpp:402
Tower(int id, int player, int x, int y, TowerType type=TowerType::Basic, int cd=-1)
Construct a new tower with given information.
Definition: common.hpp:388
bool is_upgrade_type_valid(int type) const
Check if the tower can be upgraded to a certain type.
Definition: common.hpp:569
int cd
Time remaining until next attack (Possibly negative)
Definition: common.hpp:380
bool is_ready() const
Check if the tower is ready to attack.
Definition: common.hpp:538
void action(Ant &ant) const
Cause real damage and other effects on the target.
Definition: common.hpp:501
void downgrade()
Downgrade tower to new type and reset CD, without checking validness.
Definition: common.hpp:590
double speed
Number of rounds required for an attack.
Definition: common.hpp:381