ANTWAR C++ SDK
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
GameInfo Struct Reference

A module used for game state management, providing interfaces for accessing and modifying various types of information such as Entity, Economy, Pheromone, SuperWeapon and Operation. More...

#include <game_info.hpp>

Collaboration diagram for GameInfo:
Collaboration graph
[legend]

Public Member Functions

 GameInfo (unsigned long long seed)
 
template<typename T , typename Pred >
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.
 
template<typename T , typename Pred >
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.
 
std::vector< Antall_ants () const
 Get all ants on the map.
 
std::vector< Antant_at (int x, int y) const
 Find all ants at a specific point.
 
optional< Antant_of_id (int id) const
 Find the ant of a specific ID.
 
int ant_of_id_by_index (int id) const
 Find the ant of a specific ID and get its index in vector "ants".
 
std::vector< Towerall_towers () const
 Get all towers on the map.
 
optional< Towertower_at (int x, int y) const
 Find the tower at a specific point.
 
optional< Towertower_of_id (int id) const
 Find the tower of a specific ID.
 
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".
 
void upgrade_tower (int id, TowerType type)
 Find the tower of a specific ID, then upgrade it.
 
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".
 
void upgrade_generation_speed (int player_id)
 
void upgrade_generated_ant (int player_id)
 
void set_coin (int player_id, int value)
 Set the number of coins for a player.
 
void update_coin (int player_id, int change)
 Update the number of coins for a player.
 
void set_base_hp (int player_id, int value)
 Set the hp of base for a player.
 
void update_base_hp (int player_id, int change)
 Update the hp of base for a player.
 
void clear_dead_and_succeeded_ants ()
 Clear ants of state "Success", "Fail" or "TooOld".
 
void update_pheromone_for_ants ()
 Update pheromone for each ant.
 
void update_pheromone (const Ant &ant)
 Update pheromone based on the state of an ant.
 
void global_pheromone_attenuation ()
 Global pheromone attenuation.
 
int tower_num_of_player (int player_id) const
 Count the number of towers of a player.
 
bool is_operation_valid (int player_id, const Operation &op) const
 Check operation validness.
 
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, but also the operations added before and the player's coins.
 
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 operation costs money.
 
bool check_affordable (int player_id, const std::vector< Operation > &ops) const
 Check whether a player can afford a set of operations.
 
void apply_operation (int player_id, const Operation &op)
 Change buildings, targets and coin values based on the given operation.
 
int next_move (const Ant &ant) const
 Get next moving direction for an ant based on the probability, randomly.
 
void use_super_weapon (SuperWeaponType type, int player, int x, int y)
 Handle the operation of using a super weapon.
 
bool is_shielded_by_emp (int player_id, int x, int y) const
 Check whether a point is shielded by EmpBluster for a player.
 
bool is_shielded_by_emp (const Tower &tower) const
 Check whether a tower is shielded by EmpBluster.
 
bool is_shielded_by_deflector (const Ant &a) const
 Check whether an ant is shielded by Deflector for a player.
 
void count_down_super_weapons_left_time (int player_id)
 Count down left_time of super weapons for a player. Clear it if timeout.
 
void count_down_super_weapons_cd ()
 Count down cd of all types of super weapons.
 
void show () const
 Print current information to file "info.out".
 
void dump (std::ofstream &fout) const
 Dump current information with ofstream.
 
void dump (const char filename[]) const
 Dump current information to file.
 

Static Public Member Functions

static int destroy_tower_income (int tower_num)
 Calculate the income of detroying a tower for a player.
 
static int downgrade_tower_income (int type)
 Calculate the income of downgrading a tower for a player.
 
static int build_tower_cost (int tower_num)
 Calculate the cost of building a tower for a player.
 
static int upgrade_tower_cost (int type)
 Calculate the cost of upgrading a tower.
 
static int upgrade_base_cost (int level)
 Calculate the cost of upgrading a base's generation speed or level of generated ants.
 
static int use_super_weapon_cost (int type)
 Calculate the cost of using a super weapon.
 

Public Attributes

int round
 Current round number.
 
std::vector< Towertowers
 All towers on the map.
 
std::vector< Antants
 All ants on the map.
 
Base bases [2]
 Bases of both sides: "bases[player_id]".
 
int coins [2]
 Coins of both sides: "coins[player_id]".
 
double pheromone [2][MAP_SIZE][MAP_SIZE]
 Pheromone of each point on the map: "pheromone[player_id][x][y]".
 
std::vector< SuperWeaponsuper_weapons
 Super weapons being used.
 
int super_weapon_cd [2][SuperWeaponCount]
 Super weapon cooldown of both sides: "super_weapon_cd[player_id]".
 
int next_ant_id
 ID of the next generated ant.
 
int next_tower_id
 ID of the next built tower.
 

Detailed Description

A module used for game state management, providing interfaces for accessing and modifying various types of information such as Entity, Economy, Pheromone, SuperWeapon and Operation.

Member Function Documentation

◆ all_ants()

std::vector< Ant > GameInfo::all_ants ( ) const
inline

Get all ants on the map.

Returns
A vector of copies of all ants on the map.

◆ all_towers()

std::vector< Tower > GameInfo::all_towers ( ) const
inline

Get all towers on the map.

Returns
A vector of copies of all towers on the map.

◆ ant_at()

std::vector< Ant > GameInfo::ant_at ( int  x,
int  y 
) const
inline

Find all ants at a specific point.

Parameters
xThe x-coordinate of the point.
yThe y-coordinate of the point.
Returns
A vector of copies of all ants at the given point.

◆ ant_of_id()

optional< Ant > GameInfo::ant_of_id ( int  id) const
inline

Find the ant of a specific ID.

Parameters
idThe ID of the target ant.
Returns
An optional object whose value is the ant of the given ID or nullopt if not found.

◆ ant_of_id_by_index()

int GameInfo::ant_of_id_by_index ( int  id) const
inline

Find the ant of a specific ID and get its index in vector "ants".

Parameters
idThe ID of the target ant.
Returns
The index of the ant in vector "ants" or -1 if not found.

◆ apply_operation()

void GameInfo::apply_operation ( int  player_id,
const Operation op 
)
inline

Change buildings, targets and coin values based on the given operation.

Parameters
player_idWhose operation.
opThe operation to be applied.

◆ build_tower()

void GameInfo::build_tower ( int  id,
int  player,
int  x,
int  y,
TowerType  type = TowerType::Basic 
)
inline

Emplace a new tower at the back of vector "towers".

Parameters
idThe ID of the new tower.
playerThe player id of the new tower.
xThe x-coordinate of the new tower.
yThe y-coordinate of the new tower.
typeThe type of the new tower (default type = TowerType::Basic).

◆ build_tower_cost()

static int GameInfo::build_tower_cost ( int  tower_num)
inlinestatic

Calculate the cost of building a tower for a player.

Parameters
tower_numThe number of towers (before building) of the player.
Returns
Cost of building.

◆ check_affordable()

bool GameInfo::check_affordable ( int  player_id,
const std::vector< Operation > &  ops 
) const
inline

Check whether a player can afford a set of operations.

Parameters
player_idThe player.
opsThe operation set.
Returns
Whether the player can afford these operations.

◆ destroy_tower_income()

static int GameInfo::destroy_tower_income ( int  tower_num)
inlinestatic

Calculate the income of detroying a tower for a player.

Parameters
tower_numThe number of barracks (before destroying) of the player.
Returns
Income of destroying.

◆ downgrade_or_destroy_tower()

void GameInfo::downgrade_or_destroy_tower ( int  id)
inline

Find the tower of a specific ID and downgrade it if possible. Otherwise, erase it from vector "towers".

Parameters
idThe ID of the tower about to be destroyed.

◆ downgrade_tower_income()

static int GameInfo::downgrade_tower_income ( int  type)
inlinestatic

Calculate the income of downgrading a tower for a player.

Parameters
typeThe type of the tower before downgraded.
Returns
Income of downgrading.

◆ find_all()

template<typename T , typename Pred >
std::vector< T > GameInfo::find_all ( const std::vector< T > &  v,
Pred  pred 
) const
inline

Find all elements in the given vector for which a predicate is true.

Parameters
vA vector.
predA predicate.
Returns
A vector of copies of all elements for which "pred" is true.

◆ find_one()

template<typename T , typename Pred >
optional< T > GameInfo::find_one ( const std::vector< T > &  v,
Pred  pred 
) const
inline

Find no more than one element in the given vector for which a predicate is true.

Parameters
vA vector.
predA predicate.
Returns
An optional object whose value satisfies "pred" or nullopt if not found.

◆ get_operation_income()

int GameInfo::get_operation_income ( int  player_id,
const Operation op 
) const
inline

Get the income of an operation BEFORE applied. The income could be negative, which means the operation costs money.

Parameters
player_idThe player.
opThe operation.
Returns
How much the player will get when applying the operation.

◆ is_operation_valid() [1/2]

bool GameInfo::is_operation_valid ( int  player_id,
const Operation op 
) const
inline

Check operation validness.

Parameters
player_idThe player.
opThe operation.
Returns
Whether the operation is valid (i.e. can be applied).
Note
This function does not check whether the player has enough coins, or there are multiple operations of the same type. See another overload for those checks.

◆ is_operation_valid() [2/2]

bool GameInfo::is_operation_valid ( int  player_id,
const std::vector< Operation > &  ops,
const Operation new_op 
) const
inline

Check whether the newly added operation is valid, considering not only the operation itself, but also the operations added before and the player's coins.

Parameters
player_idThe player.
opsOperations already added, with the newly added one at the end.
Returns
Whether the operation is valid.

◆ is_shielded_by_deflector()

bool GameInfo::is_shielded_by_deflector ( const Ant a) const
inline

Check whether an ant is shielded by Deflector for a player.

Returns
Whether the ant is shielded.

◆ is_shielded_by_emp() [1/2]

bool GameInfo::is_shielded_by_emp ( const Tower tower) const
inline

Check whether a tower is shielded by EmpBluster.

Returns
Whether the tower is shielded.

◆ is_shielded_by_emp() [2/2]

bool GameInfo::is_shielded_by_emp ( int  player_id,
int  x,
int  y 
) const
inline

Check whether a point is shielded by EmpBluster for a player.

Returns
Whether the point is shielded.

◆ next_move()

int GameInfo::next_move ( const Ant ant) const
inline

Get next moving direction for an ant based on the probability, randomly.

Parameters
aThe ant.
Returns
Next moving direction.

◆ tower_at()

optional< Tower > GameInfo::tower_at ( int  x,
int  y 
) const
inline

Find the tower at a specific point.

Parameters
xThe x-coordinate of the point.
yThe y-coordinate of the point.
Returns
An optional object whose value is the tower at the given point or nullopt if not found.

◆ tower_num_of_player()

int GameInfo::tower_num_of_player ( int  player_id) const
inline

Count the number of towers of a player.

Parameters
player_idThe player.
Returns
The number of towers of the player.

◆ tower_of_id()

optional< Tower > GameInfo::tower_of_id ( int  id) const
inline

Find the tower of a specific ID.

Parameters
idThe ID of the target tower.
Returns
An optional object whose value is the tower of the given ID or nullopt if not found.

◆ update_pheromone()

void GameInfo::update_pheromone ( const Ant ant)
inline

Update pheromone based on the state of an ant.

Parameters
antThe given ant for updating.

◆ upgrade_base_cost()

static int GameInfo::upgrade_base_cost ( int  level)
inlinestatic

Calculate the cost of upgrading a base's generation speed or level of generated ants.

Parameters
levelLevel of the base before upgrading.
Returns
Cost of upgrading.

◆ upgrade_tower()

void GameInfo::upgrade_tower ( int  id,
TowerType  type 
)
inline

Find the tower of a specific ID, then upgrade it.

Parameters
idThe ID of the tower about to be upgraded.
typeThe target type of upgrading.

◆ upgrade_tower_cost()

static int GameInfo::upgrade_tower_cost ( int  type)
inlinestatic

Calculate the cost of upgrading a tower.

Parameters
typeThe target type of upgrading.
Returns
Cost of upgrading.

◆ use_super_weapon_cost()

static int GameInfo::use_super_weapon_cost ( int  type)
inlinestatic

Calculate the cost of using a super weapon.

Parameters
typeThe type of super weapon.
Returns
Cost of using.

The documentation for this struct was generated from the following file: