ANTWAR C++ SDK
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Simulator Class Reference

An integrated module for simulation with simple interfaces for your convenience. Built from the game state of a Controller instance, a Simulator object allows you to simulate the whole game and "predict" the future for decision making. More...

#include <simulate.hpp>

Collaboration diagram for Simulator:
Collaboration graph
[legend]

Public Member Functions

 Simulator (const GameInfo &info)
 Construct a new Simulator object from a GameInfo instance. Current game state will be copied.
 
const GameInfoget_info ()
 Get information about current game state.
 
const std::vector< Operation > & get_operations_of_player (int player_id) const
 Get added operations of a player.
 
bool add_operation_of_player (int player_id, Operation op)
 Try adding an operation to "operations[player_id]". The operation has been constructed elsewhere. This function will check validness of the operation and add it to "operations[player_id]" if valid.

 
void apply_operations_of_player (int player_id)
 Apply all operations in "operations[player_id]" to current state.
 
GameState next_round ()
 Update game state at the end of current round. This function is called after both players have applied their operations.
 

Private Member Functions

void attack_ants ()
 Lightning storms snd towers try attacking ants.
 
GameState move_ants ()
 Make alive ants move according to pheromone, without modifying pheromone.
 
void generate_ants ()
 Bases try generating new ants.
 
void get_basic_income (int player_id)
 Get the basic income for a player and add it to corresponding coins.
 
GameState judge_winner () const
 Judge winner at MAX_ROUND.
 

Private Attributes

GameInfo info
 Game state.
 
std::vector< Operationoperations [2]
 Players' operations which are about to be applied to current game state.
 

Detailed Description

An integrated module for simulation with simple interfaces for your convenience. Built from the game state of a Controller instance, a Simulator object allows you to simulate the whole game and "predict" the future for decision making.

Constructor & Destructor Documentation

◆ Simulator()

Simulator::Simulator ( const GameInfo info)
inline

Construct a new Simulator object from a GameInfo instance. Current game state will be copied.

Parameters
infoThe GaemInfo instance as data source.

Member Function Documentation

◆ add_operation_of_player()

bool Simulator::add_operation_of_player ( int  player_id,
Operation  op 
)
inline

Try adding an operation to "operations[player_id]". The operation has been constructed elsewhere. This function will check validness of the operation and add it to "operations[player_id]" if valid.

Parameters
player_idThe player.
opThe operation to be added.
Returns
Whether the operation is added successfully.

◆ apply_operations_of_player()

void Simulator::apply_operations_of_player ( int  player_id)
inline

Apply all operations in "operations[player_id]" to current state.

Parameters
player_idThe player.

◆ attack_ants()

void Simulator::attack_ants ( )
inlineprivate

Lightning storms snd towers try attacking ants.

Note
A tower may not attack if it has not cooled down (i.e. CD > 0) or if no target is available. Even if it is able to attack, a tower may not cause any damage due to item effects.
The state of an ant may be changed. Set AntState::Fail if an ant has negative health points(hp). Set AntState::Frozen if an ant is attacked by a tower of type TowerType::Ice.
See also
AntState for more information on the life cycle of an ant.

◆ generate_ants()

void Simulator::generate_ants ( )
inlineprivate

Bases try generating new ants.

Note
Generation may not happen if it is not the right time (i.e. round % cycle == 0).

◆ get_basic_income()

void Simulator::get_basic_income ( int  player_id)
inlineprivate

Get the basic income for a player and add it to corresponding coins.

Parameters
player_idThe player's ID.

◆ get_info()

const GameInfo & Simulator::get_info ( )
inline

Get information about current game state.

Returns
A read-only (constant) reference to the current GameInfo object.

◆ get_operations_of_player()

const std::vector< Operation > & Simulator::get_operations_of_player ( int  player_id) const
inline

Get added operations of a player.

Parameters
player_idThe player.
Returns
A read-only (constant) reference to "operations[player_id]".

◆ judge_winner()

GameState Simulator::judge_winner ( ) const
inlineprivate

Judge winner at MAX_ROUND.

Returns
Game result.
Note
The function returns GameState::Undecided when both players have the same hp.

◆ move_ants()

GameState Simulator::move_ants ( )
inlineprivate

Make alive ants move according to pheromone, without modifying pheromone.

Note
The state of an ant may be changed. Set AntState::TooOld if an ant reaches age limit. Set AntState::Success if an ant has reached opponent's base, then update the base's health points (hp).
Returns
Current game state (running / ended for one side's hp <= 0).
See also
AntState for more information on the life cycle of an ant.

◆ next_round()

GameState Simulator::next_round ( )
inline

Update game state at the end of current round. This function is called after both players have applied their operations.

Returns
Current game state (running / ended with some reasons).

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