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

An integrated module of IO and game state management with simple interfaces for your convenience. Focus on the information of current game state (e.g. get the probability of an ant's movement) and make your decisions, without caring much about tedious details of IO. More...

#include <control.hpp>

Collaboration diagram for Controller:
Collaboration graph
[legend]

Public Member Functions

 Controller ()
 Construct a new Controller object. Read initializing information from judger and initialize.
 
const GameInfoget_info () const
 Get information about current game state.
 
const std::vector< Operation > & get_self_operations () const
 Get added operations.
 
const std::vector< Operation > & get_opponent_operations () const
 Get saved opponent's operations.
 
void read_round_info ()
 Read round information from judger and update current game state.
 
void read_opponent_operations ()
 Read opponent's operations from judger and overwrites "opponent_operations".
 
void apply_opponent_operations ()
 Apply all the operations in "opponent_operations" to current game state.
 
bool append_self_operation (OperationType type, int arg0=-1, int arg1=-1)
 Try adding an operation to "self_operations". The operation will be constructed with the given type and arguments. This function will check validness of the operation and add it to "self_operations" if valid.

 
bool append_self_operation (Operation op)
 Try adding an operation to "self_operations". The operation has been constructed elsewhere. This function will check validness of the operation and add it to "self_operations" if valid.

 
void apply_self_operations ()
 Apply all the operations in "self_operations" to current game state.
 
void send_self_operations () const
 Send all the operations in "self_operations" (i.e. print to stdout)
 

Public Attributes

const int self_player_id
 Your player ID.
 

Private Member Functions

void update_towers (std::vector< Tower > &new_towers)
 Update "info.towers" with vector "new_towers" and reset "info.next_tower_id".
 
void update_ants (const std::vector< Ant > &new_ants)
 Update "info.ants" with vector "new_ants" and reset "info.next_ant_id".
 
void update_ant (const Ant &a)
 Update "info.ants" with ant "a".
 
void update_coins (int coin0, int coin1)
 Update "info.coins".
 
void update_bases_hp (int hp0, int hp1)
 Update health points (HP) of "info.base[0]" and "info.base[1]".
 
 Controller (InitInfo init_info)
 Construct a new Controller object with given init info.
 

Private Attributes

GameInfo info
 Current game information.
 
std::vector< Operationself_operations
 Self operations which are about to be sent.
 
std::vector< Operationopponent_operations
 Opponent's operations received from judger.
 

Detailed Description

An integrated module of IO and game state management with simple interfaces for your convenience. Focus on the information of current game state (e.g. get the probability of an ant's movement) and make your decisions, without caring much about tedious details of IO.

Member Function Documentation

◆ append_self_operation() [1/2]

bool Controller::append_self_operation ( Operation  op)
inline

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

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

◆ append_self_operation() [2/2]

bool Controller::append_self_operation ( OperationType  type,
int  arg0 = -1,
int  arg1 = -1 
)
inline

Try adding an operation to "self_operations". The operation will be constructed with the given type and arguments. This function will check validness of the operation and add it to "self_operations" if valid.

Parameters
typeThe type of the operation (see OperationType).
arg0The first argument of the operation.
arg1(optional) The second argument of the operation.
Returns
Whether the operation is added successfully.

◆ get_info()

const GameInfo & Controller::get_info ( ) const
inline

Get information about current game state.

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

◆ get_opponent_operations()

const std::vector< Operation > & Controller::get_opponent_operations ( ) const
inline

Get saved opponent's operations.

Returns
A read-only (constant) reference to opponent operations.

◆ get_self_operations()

const std::vector< Operation > & Controller::get_self_operations ( ) const
inline

Get added operations.

Returns
A read-only (constant) reference to self operations.

◆ update_ant()

void Controller::update_ant ( const Ant a)
inlineprivate

Update "info.ants" with ant "a".

Parameters
aThe given ant for updating.

Given ant "a", find in vector "ants" if there is an ant "b" having the same ID as "a". If found "b" (which means "a" is not newly generated), then update "b" with "a". If not found "b" (which means "a" is newly generated), then emplace "a" at the back of vector "info.ants".

◆ update_ants()

void Controller::update_ants ( const std::vector< Ant > &  new_ants)
inlineprivate

Update "info.ants" with vector "new_ants" and reset "info.next_ant_id".

Parameters
new_antsThe vector of ants (read from Judger) for updating.

◆ update_bases_hp()

void Controller::update_bases_hp ( int  hp0,
int  hp1 
)
inlineprivate

Update health points (HP) of "info.base[0]" and "info.base[1]".

Parameters
hp0The hp of player0's base (read from Judger).
hp1The hp of player1's base (read from Judger).
See also
GameInfo::set_base_hp for details.

◆ update_coins()

void Controller::update_coins ( int  coin0,
int  coin1 
)
inlineprivate

Update "info.coins".

Parameters
coin0The number of coins of player0 (read from Judger).
coin1The number of coins of player1 (read from Judger).
See also
GameInfo::set_coin for details.

◆ update_towers()

void Controller::update_towers ( std::vector< Tower > &  new_towers)
inlineprivate

Update "info.towers" with vector "new_towers" and reset "info.next_tower_id".

Parameters
new_towersThe vector of towers (read from Judger) for updating.

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