ANTWAR C++ SDK
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
common.hpp File Reference

Models and constants. More...

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include "optional.hpp"

Go to the source code of this file.

Classes

struct  Ant
 Basic attacking unit. More...
 
struct  TowerInfo
 Structure of static information of a type of towers. More...
 
struct  Tower
 Defense unit. Only choice to get yourself armed to the teeth. More...
 
struct  Base
 Target to protect or to destroy. More...
 
struct  SuperWeapon
 Great choice to knockout your opponent. More...
 
struct  Operation
 Player's operations. It is able to be applied to the map. More...
 
struct  Random
 Random noise generator. More...
 

Enumerations

enum class  BuildingType { Empty , Tower , Base }
 A tag indicating the type of a building on the map.
 
enum  PointType {
  Void = -1 , Path = 0 , Barrier = 1 , Player0Highland = 2 ,
  Player1Highland = 3
}
 Tag indicating property of points. More...
 
enum  AntState {
  Alive = 0 , Success = 1 , Fail = 2 , TooOld = 3 ,
  Frozen = 4
}
 State of an ant, indicating its life cycle stages. More...
 
enum  TowerType {
  Basic = 0 , Heavy = 1 , HeavyPlus = 11 , Ice = 12 ,
  Cannon = 13 , Quick = 2 , QuickPlus = 21 , Double = 22 ,
  Sniper = 23 , Mortar = 3 , MortarPlus = 31 , Pulse = 32 ,
  Missile = 33
}
 Tag for the type of a tower. The integer values of these enumeration items are also their indexes.
 
enum  SuperWeaponType {
  LightningStorm = 1 , EmpBlaster = 2 , Deflector = 3 , EmergencyEvasion = 4 ,
  SuperWeaponCount
}
 Tag for the type of a super weapon. The integer values of these enumeration items are also their indexes.
 
enum  OperationType {
  BuildTower = 11 , UpgradeTower = 12 , DowngradeTower = 13 , UseLightningStorm = 21 ,
  UseEmpBlaster = 22 , UseDeflector = 23 , UseEmergencyEvasion = 24 , UpgradeGenerationSpeed = 31 ,
  UpgradeGeneratedAnt = 32
}
 Tag for the type of an operation. The integer values of these enumeration items are also their indexes. More...
 

Functions

int distance (int x0, int y0, int x1, int y1)
 Get the distance between two points on the map (NOT Euclidean distance).
 
bool is_valid_pos (int x, int y)
 Check if the given coordinates refers to a valid point on the map.
 
bool is_path (int x, int y)
 Check if the given position is reachable for ants.
 
bool is_highland (int player, int x, int y)
 Check if a player can build towers at given position.
 
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.
 

Variables

static constexpr int MAX_ROUND = 512
 Max number of rounds.
 
static constexpr int EDGE = 10
 Length of one edge.
 
static constexpr int MAP_SIZE = 2 * EDGE - 1
 Size of the map.
 
static constexpr int MAP_PROPERTY [MAP_SIZE][MAP_SIZE]
 Point types of the map.
 
static constexpr int OFFSET [2][6][2]
 The offsets between the coordinates of the current point and its surrounding 6 points.
 
static constexpr int COIN_INIT = 50
 
static constexpr int BASIC_INCOME = 1
 
static constexpr int TOWER_BUILD_PRICE_BASE = 15
 
static constexpr int TOWER_BUILD_PRICE_RATIO = 2
 
static constexpr int LEVEL2_TOWER_UPGRADE_PRICE = 60
 
static constexpr int LEVEL3_TOWER_UPGRADE_PRICE = 200
 
static constexpr double TOWER_DOWNGRADE_REFUND_RATIO = 0.8
 
static constexpr int LEVEL2_BASE_UPGRADE_PRICE = 200
 
static constexpr int LEVEL3_BASE_UPGRADE_PRICE = 250
 
static constexpr double PHEROMONE_INIT = 10
 
static constexpr double PHEROMONE_MIN = 0
 
static constexpr double PHEROMONE_ATTENUATING_RATIO = 0.97
 
constexpr TowerInfo TOWER_INFO []
 Static information of all types of tower.
 
static constexpr int SUPER_WEAPON_INFO [5][4]
 Static information of all types of super weapons.
 

Detailed Description

Models and constants.

Author
Yufei Li, Jingxuan Liu
Date
2023-04-01

Enumeration Type Documentation

◆ AntState

enum AntState

State of an ant, indicating its life cycle stages.

Note
Terminology: An ant is called "alive" iff it has positive health points (HP) and hasn't reached the opponent's base. Therefore "alive" ants have state AntState::Alive or AntState::Frozen, while "dead" ants have other states. It's irreversible to change from "alive" states to "dead" states.
Enumerator
Alive 

Normal case.

Success 

Reach the opponent's camp.

Fail 

Non-positive health points (HP)

TooOld 

Reach age limit.

Frozen 

Frozen, cannot move.

◆ OperationType

Tag for the type of an operation. The integer values of these enumeration items are also their indexes.

Enumerator
BuildTower 

Build a tower.

UpgradeTower 

Upgrade a tower.

DowngradeTower 

Downgrade/Destroy a tower.

UseLightningStorm 

Use a lightning storm.

UseEmpBlaster 

Use an EMP blaster.

UseDeflector 

Use a deflector.

UseEmergencyEvasion 

Use an emergency evasion.

UpgradeGenerationSpeed 

Increase ant producing speed.

UpgradeGeneratedAnt 

Increase HP of newly generated ants.

◆ PointType

enum PointType

Tag indicating property of points.

Enumerator
Void 

Out of the map.

Path 

Ants can pass through here.

Barrier 

No passing or building here.

Player0Highland 

Player0 can have buildings here.

Player1Highland 

Player1 can have buildings here.

Function Documentation

◆ distance()

int distance ( int  x0,
int  y0,
int  x1,
int  y1 
)
inline

Get the distance between two points on the map (NOT Euclidean distance).

Parameters
x0The x-coordinate of the first point.
y0The y-coordinate of the first point.
x1The x-coordinate of the second point.
y1The y-coordinate of the second point.
Returns
The distance between the given points.

◆ get_direction()

int get_direction ( int  x0,
int  y0,
int  x1,
int  y1 
)
inline

Get the direction of two adjacent points, starting from the first and pointing to the second.

Parameters
x0The x-coordinate of the first point.
y0The y-coordinate of the first point.
x1The x-coordinate of the second point.
y1The y-coordinate of the second point.
Returns
The index of the direction if given adjacent points, or -1 in other cases.

◆ is_highland()

bool is_highland ( int  player,
int  x,
int  y 
)
inline

Check if a player can build towers at given position.

Parameters
xThe x-coordinate of the point.
yThe y-coordinate of the point.
Returns
Whether building is allowed.

◆ is_path()

bool is_path ( int  x,
int  y 
)
inline

Check if the given position is reachable for ants.

Parameters
xThe x-coordinate of the point.
yThe y-coordinate of the point.
Returns
Whether it is reachable.

◆ is_valid_pos()

bool is_valid_pos ( int  x,
int  y 
)
inline

Check if the given coordinates refers to a valid point on the map.

Parameters
xThe x-coordinate of the point.
yThe y-coordinate of the point.
Returns
Whether the given coordinates refers to a valid point on the map.

Variable Documentation

◆ EDGE

constexpr int EDGE = 10
staticconstexpr

Length of one edge.

Note
EDGE must be even.

◆ MAP_PROPERTY

constexpr int MAP_PROPERTY[MAP_SIZE][MAP_SIZE]
staticconstexpr
Initial value:
= {
{-1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, 0, 0, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, -1, -1, -1, -1},
{-1, -1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, -1, -1},
{0, 0, 2, 2, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 2, 2, 0, 0},
{0, 0, 0, 2, 0, 0, 2, 2, 0, 2, 0, 2, 2, 0, 0, 2, 0, 0, 0},
{0, 2, 2, 0, 2, 0, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 2, 2, 0},
{0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0},
{0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0},
{0, 1, 3, 0, 3, 1, 0, 1, 0, 1, 0, 1, 0, 1, 3, 0, 3, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0},
{0, 3, 3, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 3, 3, 0},
{0, 3, 0, 0, 0, 0, 3, 3, 0, 3, 0, 3, 3, 0, 0, 0, 0, 3, 0},
{0, 0, 3, 3, 0, 0, 0, 3, 0, 3, 0, 3, 0, 0, 0, 3, 3, 0, 0},
{-1, 0, 0, 3, 0, 1, 1, 0, 0, 3, 0, 0, 1, 1, 0, 3, 0, 0, -1},
{-1, -1, -1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, -1, -1, -1},
{-1, -1, -1, -1, -1, 0, 0, 1, 1, 0, 1, 1, 0, 0, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
}

Point types of the map.

◆ MAP_SIZE

constexpr int MAP_SIZE = 2 * EDGE - 1
staticconstexpr

Size of the map.

Note
Point (x, y) with x < MAP_SIZE and y < MAP_SIZE may not be a valid position on the map.

◆ OFFSET

constexpr int OFFSET[2][6][2]
staticconstexpr
Initial value:
= {{{0, 1}, {-1, 0}, {0, -1}, {1, -1}, {1, 0}, {1, 1}},
{{-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, 0}, {0, 1}}}

The offsets between the coordinates of the current point and its surrounding 6 points.

When y is even:
                         {x - 1, y}
     {x, y - 1}                          {x, y + 1}
                         {x, y} 
     {x + 1, y - 1}                      {x + 1, y + 1}
                         {x + 1, y}

When y is odd:           
                         {x - 1, y}
     {x - 1, y - 1}                          {x - 1, y + 1}
                         {x, y} 
     {x, y - 1}                              {x, y + 1}
                         {x + 1, y}

◆ SUPER_WEAPON_INFO

constexpr int SUPER_WEAPON_INFO[5][4]
staticconstexpr
Initial value:
= {
{},
{20, 3, 100, 150},
{20, 3, 100, 150},
{10, 3, 50, 100},
{1, 3, 50, 100}
}

Static information of all types of super weapons.

Note
[type]{duration, range, cd, price}

◆ TOWER_INFO

constexpr TowerInfo TOWER_INFO[]
constexpr
Initial value:
= {
{5, 2, 2},
{20, 2, 2},
{6, 1, 3},
{16, 4, 3},
{}, {}, {}, {}, {}, {}, {},
{35, 2, 3},
{15, 2, 2},
{50, 3, 3},
{}, {}, {}, {}, {}, {}, {},
{8, 0.5, 3},
{7, 1, 4},
{15, 2, 6},
{}, {}, {}, {}, {}, {}, {},
{35, 4, 4},
{30, 3, 2},
{45, 6, 5}
}

Static information of all types of tower.