C++ Reference
-
class Agent
Subclassed by SGA::ActionAbstractionMCTSAgent, SGA::BeamSearchAgent, SGA::BFSAgent, SGA::CombatAgent, SGA::DFSAgent, SGA::DoNothingAgent, SGA::KTKCombatAgent, SGA::MCTSAgent, SGA::OSLAAgent, SGA::PusherAgent, SGA::RandomAgent, SGA::RHEAAgent, SGA::ScriptedAgent, SGA::UnitMCTSAgent
Public Functions
-
virtual void init(GameState initialState, const ForwardModel &forwardModel, Timer timer)
Function for initializing the agent. Override this function to receive a call just before starts.
- Parameters
initialState – Copy of the initial state of the game.
forwardModel – Forward Model of the game.
timeBudgetMs – Number of milliseconds to return an action
-
virtual ActionAssignment computeAction(GameState state, const ForwardModel &forwardModel, Timer timer) = 0
Function for deciding the next action to execute. Must be overriden for an agent to work. Returns an ActionAssignment which specifies what actions will be executed in the game.
- Parameters
state – Copy of the current state of the game
forwardModel – Forward model of the game.
timeBudgetMs – Time in milliseconds to return an action
- Returns
-
virtual int getPlayerID()
Returns this player’s ID.
- Returns
This player’s ID
-
virtual void setPlayerID(int playerID)
Sets the ID of this plater
- Parameters
playerID – Player ID to set.
-
virtual void setSeed(boost::mt19937::result_type seed = 0)
Sets the seed for the random number generator of this agent.
- Parameters
seed – Seed for the generator
-
inline virtual const std::string &getName() const
Returns the name of this agent.
-
virtual void init(GameState initialState, const ForwardModel &forwardModel, Timer timer)
-
struct GameDescription
Public Functions
-
inline const std::unordered_map<ActionCategory, std::vector<int>> &getActionCategories() const
Returns the action categories of this game.
-
inline const std::unordered_map<EntityCategory, std::vector<int>> &getEntityCategories() const
Returns the entity categories of this game.
-
std::vector<int> getActionTypesIDs(ActionCategory category) const
Returns all the actiontypes IDs of the selected action category.
- Parameters
category – The category group to be searched.
- Returns
List of action type IDs.
-
std::vector<int> getEntityTypesIDs(EntityCategory category) const
Returns all the entity type IDs of the selected entity category.
- Parameters
category – The category group to be searched.
- Returns
List of entity type IDs.
-
std::vector<ActionType> getActionTypes(ActionCategory category, const GameInfo &gameInfo) const
Returns all the actiontypes IDs of the selected action category.
- Parameters
category – The category group to be searched.
gameInfo – The gameInfo object wich contains all the type of actions.
- Returns
List of action types
-
std::vector<EntityType> getEntityTypes(EntityCategory category, const GameInfo &gameInfo) const
Returns all the entity type IDs of the selected entity category.
- Parameters
category – The category group to be searched.
gameInfo – The gameInfo object wich contains all the type of actions.
- Returns
List of entity types
-
bool isFromCategory(EntityCategory category, int entityTypeId) const
Checks if a given entity type ID belongs to a given category
- Parameters
category – The category group to be cheked.
entityTypeId – ID Type of the entity that is to be checekd if it’s part of the category.
- Returns
True if entityTypeId is a subset of the category given
-
inline const std::unordered_map<ActionCategory, std::vector<int>> &getActionCategories() const
-
struct GameInfo
Contains all the type information used by the game. It have different methods to get the different types: parameter, entity, action… The agent can access to the yaml path where the game configuration is defined.
Public Functions
-
const EntityType &getEntityType(int entityTypeID) const
Returns the entity type.
- Parameters
entityTypeID – The ID of the entity type.
- Returns
The entity type.
-
const BuffType &getBuffType(int buffTypeID) const
Returns the buff type.
- Parameters
buffTypeID – The ID of the buff type.
- Returns
The buff type.
-
const TileType &getTileType(int tileTypeID) const
Returns the tile type.
- Parameters
tileTypeID – The ID of the tile type
- Returns
The TileType.
-
int getParameterGlobalID(std::string parameterName)
Returns the ID of the parameter.
- Parameters
parameterName – The parameter name.
- Returns
The parameter ID.
-
const Parameter &getParameterType(int entityTypeID, int globalParameterID) const
Returns the parameter type from a entityType.
- Parameters
entityTypeID – The entityType ID.
globalParameterID – The parameter ID.
- Returns
The parameter.
-
bool checkEntityHaveParameter(int entityTypeID, const std::string ¶meterName) const
Returns true if the entity type has the searched parameter
- Parameters
entityTypeID – The entity type.
parameterName – The parameter name.
- Returns
True if it has the parameter
-
const SGA::Parameter &getPlayerParameter(ParameterID id) const
Returns the parameter of the player.
- Parameters
ParameterID – The ID of the parameter
- Returns
The parameter.
-
const SGA::Parameter &getPlayerParameter(const std::string &name) const
Returns the parameter of the player.
- Parameters
ParameterID – The ID of the parameter
- Returns
The parameter.
-
const SGA::Parameter &getPlayerParameterByIndex(int index) const
Returns the parameter of the player by index.
- Parameters
ParameterID – The index of the parameter
- Returns
The parameter.
-
const SGA::Parameter &getStateParameter(ParameterID id) const
Returns the parameter of the state.
- Parameters
ParameterID – The ID of the parameter
- Returns
The parameter.
-
const SGA::Parameter &getStateParameter(std::string &name) const
Returns the parameter of the state.
- Parameters
ParameterID – The ID of the parameter
- Returns
The parameter.
-
const SGA::Parameter &getStateParameterByIndex(int index) const
Returns the parameter of the state by index.
- Parameters
ParameterID – The index of the parameter
- Returns
The parameter.
-
const ActionType &getActionTypeConst(int actionTypeID)
Returns the action type.
- Parameters
actionTypeID – The ID of the action type
- Returns
The action type.
-
const ActionType &getActionType(int typeID) const
Returns the action type.
- Parameters
typeID – The ID of the action type
- Returns
The action type.
-
int getActionTypeID(std::string actionName)
Returns the action type ID.
- Parameters
actionName – The name of the action type
- Returns
The action type ID.
-
std::unordered_map<int, int> getTechnologyCounts() const
Returns a map of tuples with the tree ID and how many technologies each has.
- Returns
A map with trees and technology counts
-
const TechnologyTreeNode &getTechnology(int technologyID) const
Returns a technology node with an ID corresponding to the one passed by parameter. The node could come from any of the trees of the tree collection.
- Parameters
technologyID – ID of the technology to search for.
- Returns
The tree node searched for, an exception if it doesn’t exist.
-
int getTechnologyTypeID(const std::string &technologyName) const
Returns the ID of a technology that matches the requested name, in any of the trees of the tree collection.
- Parameters
technologyName – Name of the technology to search for.
- Returns
ID of the technology searched for, or a runtime error if it doesn’t exist.
-
std::vector<TechnologyTreeNode> getTreeNodes(int techTreeID) const
Returns a list with all technologies of a given tree, specified by its ID
- Parameters
techTreeID – ID of the tech tree to look for
- Returns
A list with all technologies of a given research tree
-
std::vector<int> getTechTreesIDs() const
Returns the IDs of the tech trees of this game.
- Returns
Returns the IDs of the tech trees of this game.
-
const EntityType &getEntityType(int entityTypeID) const
-
struct GameState
Contains the game data without any logic, offering access to the current board, a list of player and their units. If the agent want access to the definition of entity types, actions or game config yaml it should access to SGA::GameInfo
Public Functions
-
bool canExecuteAction(const Entity &entity, const ActionType &actionType) const
Checks if a SGA::Entity can execute a given actionType
- Parameters
entity – The entity that will be analyzed
- Returns
A boolean indicating if the player can execute the action type
-
bool canExecuteAction(const Player &player, const ActionType &actionType) const
Checks if a player can execute a given actionType
- Parameters
player – The player that will be analyzed
- Returns
A boolean indicating if the entity can execute the action type
-
std::vector<ActionType> getPlayerActionTypes(int playerID) const
Returns a list with all the action types that a player can execute
- Parameters
playerID – ID of the player we get the action types from.
- Returns
Vector with action types this player can execute in this game
-
bool isResearched(int playerID, int technologyID) const
Checks if given technology has been researched by a player.
- Parameters
playerID – ID of the player to check
technologyID – ID of the technology to check
- Returns
A boolean indicating if the player has researched the given technology
-
bool canResearch(int playerID, int technologyID) const
Checks if given technology can been researched by a player.
- Parameters
playerID – ID of the player to check
technologyID – ID of the technology to check
- Returns
A boolean indicating if the player can research the given technology
-
void researchTechnology(int playerID, int technologyID)
Process the research of a given technology for a player. This method does not check if the technology is research or if it can be researched.
- Parameters
playerID – ID of the player who has to research a tech
technologyID – ID of the technology to research
-
void initResearchTechs()
Initializes the research technologies to all players, to none.
-
bool isWalkable(const Vector2i &position)
Checks if tile is occupied or the tile is walkable
- Parameters
position – The position of the tile map
- Returns
A boolean indicating if the tile in the given position is walkable
-
bool isInBounds(const Vector2i &pos) const
Checks if position is inside of the tile map
- Parameters
pos – The position to be checked
- Returns
A boolean indicating if tile map contains the position
-
bool isInBounds(const Vector2f &pos) const
Checks if position is inside of the tile map
- Parameters
pos – The position to be checked
- Returns
A boolean indicating if tile map contains the position
-
inline int getBoardWidth() const
Returns the width of the board.
- Returns
The width of the board.
-
inline int getBoardHeight() const
Returns the height of the board.
- Returns
The height of the board.
-
const Tile &getTileAtConst(const Vector2i &pos) const
Returns the tile at the position indicated in the parameter. Can throw an exception if out of bounds.
- Parameters
pos – Position of the tile to retrieve
- Returns
The tile at ‘pos’
-
const Tile &getTileAtConst(int x, int y) const
Returns the tile at the position (x,y) indicated in the parameter. Can throw an exception if out of bounds.
- Parameters
x – X Position of the tile to retrieve
y – Y Position of the tile to retrieve
- Returns
The tile at position (x,y)
-
Tile &getTileAt(const Vector2i &pos)
Returns the tile at the position indicated in the parameter. Can throw an exception if out of bounds.
- Parameters
pos – Position of the tile to retrieve
- Returns
The tile at ‘pos’
-
Tile &getTileAt(int x, int y)
Returns the tile at the position (x,y) indicated in the parameter. Can throw an exception if out of bounds.
- Parameters
x – X Position of the tile to retrieve
y – Y Position of the tile to retrieve
- Returns
The tile at position (x,y)
-
void initBoard(int boardWidth, std::vector<Tile> &tiles)
Initializes the board with the tiles passed by parameter.
- Parameters
tiles – Tiles to fill the board with.
boardWidth – Width of the board to initialize.
-
Entity *getEntityAround(Vector2f pos, float maxDistance = 0.0)
Returns an entity at board position ‘pos’. It’ll return a nullptr if no entities at this position.
- Parameters
pos – Position in the board to look for an entity.
maxDistance – If provided, considers units at a distance less or equal this value to the position provided.
- Returns
A pointer to the entity in this location.
-
Entity *getEntity(int entityID)
Returns an entity by its ID. It’ll return nullptr if no entity exists associated to the given ID. It searchs also the objects from the entities
- Parameters
entityID – ID of the entity to retrieve.
- Returns
A pointer to the entity.
-
Entity *getOnlyEntities(int entityID)
Returns an entity by its ID. It’ll return nullptr if no entity exists associated to the given ID. It only search the entities in the gamestate without the objects of the inventories
- Parameters
entityID – ID of the entity to retrieve.
- Returns
A pointer to the entity.
-
Entity *getObject(int entityID)
Returns an object/entity by its ID. It’ll return nullptr if no entity exists associated to the given ID.
- Parameters
entityID – ID of the object/entity to retrieve.
- Returns
A pointer to the entity.
-
Entity *getSlotObject(int entityID)
Returns an object/entity by its ID. It’ll return nullptr if no entity exists associated to the given ID.
- Parameters
entityID – ID of the object/entity to retrieve.
- Returns
A pointer to the entity.
-
int addEntity(const EntityType &type, int playerID, const Vector2f &position)
Adds a new entity of a given type to the game, in a given position, belonging to a specific player.
- Parameters
type – Type of the player, as defined <here cref=”SGA::EntityType”>
playerID – ID of the player this new entity will belong to.
position – Position where the entity will be added.
- Returns
Returns the unique ID of the entity created.
-
int addEntity(Entity entity, int playerID, const Vector2f &position)
Adds a entity of a given type to the game, in a given position, belonging to a specific player.
- Parameters
type – Type of the player, as defined <here cref=”SGA::EntityType”>
playerID – ID of the player this new entity will belong to.
position – Position where the entity will be added.
- Returns
Returns the unique ID of the entity created.
-
inline std::vector<Entity> &getEntities()
Gets the list of all entities.
- Returns
A vector with all entities in the game.
-
std::vector<Entity> getPlayerEntities(int playerID, EntityCategory entityCategory = EntityCategory::Null) const
Gets the list of entities of the specified player.
- Parameters
playerID – ID of the player whose entities are retrieved.
entityCategory – Entites retrieved will belong to this indicated category. If not suplied, this method returns all entities.
- Returns
The list of entities of the given player. Returns an empty list if player ID doesn’t exist or it has not entities.
-
std::vector<Entity> getNonPlayerEntities(int playerID, EntityCategory entityCategory = EntityCategory::Null) const
Gets the list of entities that do not belong to the specified player.
- Parameters
playerID – ID of the player whose entities are NOT to be retrieved.
entityCategory – Entites retrieved will belong to this indicated category. If not suplied, this method returns all entities.
- Returns
The list of entities not own by the given player.
-
const Player *getPlayer(int playerID) const
Gets a player given its ID.
- Parameters
playerID – ID of the player to retrieve
- Returns
Player seeked for, or nullptr if it doesn’t exist.
-
std::vector<int> whoCanPlay() const
Returns a list with the ID of players that can play in this game state.
- Returns
A list with all IDs of player that can play now.
-
bool canPlay(int playerID) const
Indicates if the player with the provided ID can play in this game state.
- Parameters
playerID – ID to check
- Returns
true if the player with ID playerID can play now.
-
inline const std::vector<Player> &getPlayers() const
Returns all players of this game.
- Returns
Players of the game.
-
inline int getNumPlayers() const
Gets the number of players in this game state.
- Returns
Number of players in this game
-
int addPlayer(Player &p)
Adds a player to the game state.
- Parameters
p – The player to add.
- Returns
Returns the ID of the player added to the game, equal to the number of players -1.
-
double getPlayerParameter(int playerID, const std::string ¶mName) const
Gets the value of a player parameter. Be sure to check first is the parameter you are asking for exist using <here cref=”SGA::GameState::hasPlayerParameter()”>
- Parameters
playerID – ID of the player to get the parameter from
paramName – Name of the parameter which value is requested
- Returns
Returns the value of the parameter indicated for the player whose ID is given.
-
bool hasPlayerParameter(const std::string ¶mName) const
Indicates if the player has a specific parameter
///
- Parameters
paramName – Name of the parameter which want to be checked
- Returns
A bool indicating if player has that parameter
-
std::vector<std::string> getPlayerParameterNames(int playerID) const
Returns a list will all the parameter names of the player of which ID is given
- Parameters
playerID – ID of the player to get the parameter from. For the moment, all players have the same parameter names (hence playerID is not used).
- Returns
A vector with all the parameter names of the requested player.
-
std::unordered_map<std::string, double> getPlayerParameters(int playerID) const
Gets a map with all pairs <parameter,value>
- Parameters
playerID – ID of the player to get the parameter from.
- Returns
Returns a map with all the parameters of this player.
-
int getPlayerScore(int playerID) const
Returns the score of the player whose ID is passed.
- Parameters
playerID – ID of the player to pass.
- Returns
The current score of the given player.
-
void printStateInfo() const
Print all the entities of the current state
-
void printBoard(int playerID) const
Print view of the map of the current state applying fog
- param playerID
The ID of the player to print information of.
-
void printEntityInfo(int entityID) const
Print information of a specific entity
- param playerID
ID of the entity to print information of.
-
inline void incNextContinuousActionID()
Increments the ID for the next continuous action.
-
inline int getNextContinuousActionID()
Returns the ID for the next continuous action.
- Returns
The ID of the next continuous action.
-
void applyFogOfWar(int playerID)
Removes entities and hide tiles that are not visible from the point of view of the given player.
- Parameters
playerID – The playerID of the player from which the fow will be applied
-
inline int getFogOfWarTileId() const
Returns the ID of the tile that represents the fog of war.
- Returns
ID of the tile that represents the fog of war
-
inline int getCurrentTBSPlayer() const
Returns the ID of the player that moves in this state for Turn Based Games. For non-TBS, this value is -1.
-
inline void setCurrentTBSPlayer(int playerID)
Sets the current TBS player. For non-TBS, this should receive -1.
-
inline bool isGameOver() const
Returns true if the game is over.
- Returns
Whether the game is over (true) or not (false).
-
inline void setGameOver(bool over)
Sets if the game is over
- Parameters
over – Indicates if the game is over
-
inline int getWinnerID() const
Returns the player ID of the winner. If game is not over, this returns -1.
- Returns
ID of the winner player.
-
inline void setWinnerID(int winnerID)
Sets the winner of the game.
- Parameters
winnerID – Player ID of the winner
-
inline int getCurrentTick() const
Returns the current tick of the game.
-
inline void incTick()
Increments the current tick in the game by 1.
-
inline int getTickLimit() const
Returns the current game tick limit.
-
inline void setTickLimit(int tickL)
Sets the time limit of the game, measured in ticks.
- Parameters
tickL –
-
inline std::shared_ptr<GameInfo> getGameInfo() const
Returns a pointer to the struct with static information about the game.
Sets the pointer to the game information struct.
-
inline const GameType &getGameType() const
Returns the type of the game, of GameType
-
inline void setGameType(GameType gt)
Sets the type of game (enum type GameType)
Returns a pointer to the Navigation object used by the RTS engine for pathfinding.
Sets the pointer to the Navigation object used by the RTS engine for pathfinding.
-
inline std::mt19937 &getRndEngine()
Returns the game’s random number generator.
- Returns
-
inline const std::vector<double> &getParameters() const
Returns the list of parameters, can’t be modified.
-
inline std::vector<double> &getParameters()
Returns the list of parameters of this player (can be modified)
-
inline double &getRawParameterAt(int paramIdx)
Returns a reference to a parameter value of this player.
-
inline const double &getRawParameterAt(int paramIdx) const
yer to a certain value
Returns a const value of a parameter of this player.
-
inline double getParameterAt(int paramIdx)
Gets a specific parameters value, by index
- Returns
The parameter value.
-
inline double getMaxParameterAt(int paramIdx)
Gets a specific max parameters value, by index
- Returns
The max parameter value.
-
inline double getMinParameterAt(int paramIdx)
Gets a specific min parameters value, by index
- Returns
The min parameter value.
-
inline void setParameter(int paramIdx, double val)
Sets the parameter of this play
- param paramIdx
Parameter index of this param.
- param val
Value to be set for the parameter.
-
inline void setMaxParameter(int paramIdx, double val)
Sets the parameter of this play
- param paramIdx
Parameter index of this param.
- param val
Value to be set for the parameter.
-
inline void setMinParameter(int paramIdx, double val)
Sets the parameter of this play
- param paramIdx
Parameter index of this param.
- param val
Value to be set for the parameter.
-
inline void resizeParameters(int cap)
Sets a size for the vector of parameters of this player.
-
inline const ActionQueue &getActionQueuesConst() const
***** ACTION QUEUE FUNCTIONS *****/
-
bool canExecuteAction(const Entity &entity, const ActionType &actionType) const
-
struct Entity
Is an object that interacts with the game and responds to player input or other entities. This entity can be assigned to a player performing a set of actions per tick/turn. It has a list of parameters that store real values. If the player wants to check the SGA::EntityType it can search it using the assigned typeID.
Public Functions
-
inline Entity()
Creates an instance of an entity.
-
void init(const EntityType *type, int entityID)
- Parameters
entityID – (Unique) ID of this entity in the game.
-
inline const EntityType &getEntityType() const
Return entity type
-
int getEntityTypeID() const
Return entity type ID
-
bool isNeutral() const
Indicates if this unit is neutral (i.e. does not belong to any playing faction).
- Returns
True if this entity is neutral.
-
const ActionInfo &getActionInfo(int actionTypeID) const
Returns a SGA::ActionInfo object linked to action type, used to check when was the last time the action type was executed by this entity
- Parameters
actionTypeID – The ID of the action type we’re looking for.
- Returns
The action info object, if it exists. Throws a runtime error if it doesn’t.
-
inline const std::vector<ActionInfo> &getAttachedActions() const
Returns the actions attached to this entity.
- Returns
The list of SGA::ActionInfo attached to this entity.
-
std::vector<ActionType> getActionTypes(const GameInfo &gameInfo) const
Retrieves the list of action types this entity can execute.
- Parameters
gameInfo – Reference to the game information object (from GameState)
- Returns
Vector with all action types this entity can execute
-
void setActionTicks(int actionTypeID, int tick)
Sets the last executed game ticks to the tick passed by parameter for the action corresponding to the type received.
- Parameters
actionTypeID – The ID of the action type we’re looking for.
tick – The value of the tick to set in the action information
-
inline bool flagged()
Checks if this entity should be removed by the game engine.
- Returns
True if this entity is marked to be removed.
-
inline std::unordered_map<int, double> &getParamValues()
Gets the list of parameters values. Modifiable.
- Returns
The list of parameters values.
-
inline const std::unordered_map<int, double> &getParamValues() const
Gets the list of parameters values.
- Returns
The list of parameters values.
-
std::vector<std::string> getEntityParameterNames() const
Gets the list of parameters names.
- Returns
The list of parameters names of this entity.
-
std::unordered_map<std::string, double> getEntityParameters() const
Gets a map with all pairs <parameter,value>
- Returns
Returns a map with all the parameters.
-
double getParameter(const std::string ¶mName) const
Gets the value of a specific parameter with buffs applied, by name
- Returns
The parameter value.
-
double &getRawParameter(const std::string ¶mName)
Gets the reference value of a specific parameter raw, by name
- Returns
The parameter reference value.
-
inline double &getRawParameterAt(int paramIdx)
Gets a specific parameters raw, by index
- Returns
The parameter reference value.
-
inline double &getParameterAt(int paramIdx)
Gets a specific parameters value, by index
- Returns
The parameter value.
-
inline double getMaxParameterAt(int paramIdx)
Gets a specific max parameters value, by index
- Returns
The max parameter value.
-
inline double getMinParameterAt(int paramIdx)
Gets a specific min parameters value, by index
- Returns
The min parameter value.
-
inline std::vector<Action> &getContinuousActions()
Gets the list of continuous actions attached to this entity. Modifiable.
- Returns
The list of continuous actions attached to this entity.
-
inline const std::vector<Action> &getContinuousActions() const
Gets the list of continuous actions attached to this entity.
- Returns
The list of continuous actions attached to this entity.
-
inline std::vector<Buff> &getBuffs()
Gets the list of buffs attached to this entity. Modifiable.
- Returns
The list of buffs attached to this entity.
-
inline const std::vector<Buff> &getBuffs() const
Gets the list of buffs attached to this entity.
- Returns
The list of buffs attached to this entity.
-
inline double getMovementSpeed() const
Returns the movement speed of this entity.
-
inline double getCollisionRadius() const
Returns the collision radius of this entity.
-
inline int getID() const
Returns theID of this entity.
-
inline int getOwnerID() const
Returns the owner ID (i.e. player ID) who controls this entity.
-
inline void setOwnerID(int oID)
Sets the owner ID (player ID) in control of this entity..
-
inline double getLineOfSightRange() const
Returns the line of sight of this entity.
-
inline double x() const
Returns x position of this entity.
-
inline double y() const
Returns y position of this entity.
-
inline const Vector2f &getPosition() const
Returns position of this entity.
-
inline void setPosition(Vector2f v)
Sets the position of this entity in the board. Does not modify the board.
-
inline void incPathIndex()
Increments the current index of the path that this entity is following (RTS games only)
-
void recomputeStats()
Recompute all the parameteres with the applied buffs
-
inline void removeBuffsOfType(const BuffType &newType)
Remove all the buffs of the same type
-
inline void removeAllBuffs()
Recompute all the buffs
-
inline bool hasBuff(int typeID) const
Check if player has a buff type applied
-
int getInventorySize() const
Return the inventory size
-
int getInventoryUse() const
Return the iventory slots used
-
int isInventoryFull() const
Check if inventory is full.
-
inline void removeObject(int entityID)
Remove new object from the inventory
-
inline void removeSlotObject(int entityID)
Remove slot object from the slots
-
inline std::vector<std::pair<Entity, std::vector<int>>> getSlots() const
Return the slots of this entity
-
void equipObject(int entityID)
Equip object from the inventory
-
inline void unEquipObject(int entityID)
UnEquip object from the slot
-
inline const Entity *getSlotObjectBySlotId(int slotId) const
Get the object from the slot with a specific ID
-
bool checkSlotsAreNotInUse(const Entity &object) const
Checks if slots that a object needs are not in use
-
inline bool hasObject(int entityID) const
Return if the entity has a object with a specific Id
-
inline bool hasSlotObject(int entityID) const
Return if the entity has a object with a specific Id
-
inline const Entity *getObjectConst(int entityID) const
Return the object of this entity with a given entityID
-
inline Entity()
-
struct EntityType
Contains the definition of the entity type. This information includes a list of parameters definitions, the actions that can execute, required technologies to spawn a entity, a list of spawnable entity types and a list of cost assigned to this entity type.
Public Functions
-
const Parameter &getParameter(ParameterID id) const
Returns a SGA::Parameter reference that contains the parameter defintion
-
const Parameter &getParameterByIndex(int index) const
Returns a SGA::Parameter reference that contains the parameter defintion
-
const Parameter &getParameterByName(const std::string &name) const
Returns a SGA::Parameter reference that contains the parameter defintion
-
bool canExecuteAction(int actionTypeID) const
Checks if this entity type is allowed to execute an action type
-
double getParamMax(std::string paramName) const
Returns the maximum value of a given parameter
-
double getParamMin(std::string paramName) const
Returns the minimum value of a given parameter
-
inline std::vector<int> getSlotsUsedIds(Entity &object) const
Get the slots Ids used by a specific ID
-
inline int getSlotId(std::string slotName) const
Get the slots Id by name
-
inline std::vector<int> getSlotsUsedIds() const
Get the slotsIDs that are used
-
const Parameter &getParameter(ParameterID id) const
-
struct Entity
Is an object that interacts with the game and responds to player input or other entities. This entity can be assigned to a player performing a set of actions per tick/turn. It has a list of parameters that store real values. If the player wants to check the SGA::EntityType it can search it using the assigned typeID.
Public Functions
-
inline Entity()
Creates an instance of an entity.
-
void init(const EntityType *type, int entityID)
- Parameters
entityID – (Unique) ID of this entity in the game.
-
inline const EntityType &getEntityType() const
Return entity type
-
int getEntityTypeID() const
Return entity type ID
-
bool isNeutral() const
Indicates if this unit is neutral (i.e. does not belong to any playing faction).
- Returns
True if this entity is neutral.
-
const ActionInfo &getActionInfo(int actionTypeID) const
Returns a SGA::ActionInfo object linked to action type, used to check when was the last time the action type was executed by this entity
- Parameters
actionTypeID – The ID of the action type we’re looking for.
- Returns
The action info object, if it exists. Throws a runtime error if it doesn’t.
-
inline const std::vector<ActionInfo> &getAttachedActions() const
Returns the actions attached to this entity.
- Returns
The list of SGA::ActionInfo attached to this entity.
-
std::vector<ActionType> getActionTypes(const GameInfo &gameInfo) const
Retrieves the list of action types this entity can execute.
- Parameters
gameInfo – Reference to the game information object (from GameState)
- Returns
Vector with all action types this entity can execute
-
void setActionTicks(int actionTypeID, int tick)
Sets the last executed game ticks to the tick passed by parameter for the action corresponding to the type received.
- Parameters
actionTypeID – The ID of the action type we’re looking for.
tick – The value of the tick to set in the action information
-
inline bool flagged()
Checks if this entity should be removed by the game engine.
- Returns
True if this entity is marked to be removed.
-
inline std::unordered_map<int, double> &getParamValues()
Gets the list of parameters values. Modifiable.
- Returns
The list of parameters values.
-
inline const std::unordered_map<int, double> &getParamValues() const
Gets the list of parameters values.
- Returns
The list of parameters values.
-
std::vector<std::string> getEntityParameterNames() const
Gets the list of parameters names.
- Returns
The list of parameters names of this entity.
-
std::unordered_map<std::string, double> getEntityParameters() const
Gets a map with all pairs <parameter,value>
- Returns
Returns a map with all the parameters.
-
double getParameter(const std::string ¶mName) const
Gets the value of a specific parameter with buffs applied, by name
- Returns
The parameter value.
-
double &getRawParameter(const std::string ¶mName)
Gets the reference value of a specific parameter raw, by name
- Returns
The parameter reference value.
-
inline double &getRawParameterAt(int paramIdx)
Gets a specific parameters raw, by index
- Returns
The parameter reference value.
-
inline double &getParameterAt(int paramIdx)
Gets a specific parameters value, by index
- Returns
The parameter value.
-
inline double getMaxParameterAt(int paramIdx)
Gets a specific max parameters value, by index
- Returns
The max parameter value.
-
inline double getMinParameterAt(int paramIdx)
Gets a specific min parameters value, by index
- Returns
The min parameter value.
-
inline std::vector<Action> &getContinuousActions()
Gets the list of continuous actions attached to this entity. Modifiable.
- Returns
The list of continuous actions attached to this entity.
-
inline const std::vector<Action> &getContinuousActions() const
Gets the list of continuous actions attached to this entity.
- Returns
The list of continuous actions attached to this entity.
-
inline std::vector<Buff> &getBuffs()
Gets the list of buffs attached to this entity. Modifiable.
- Returns
The list of buffs attached to this entity.
-
inline const std::vector<Buff> &getBuffs() const
Gets the list of buffs attached to this entity.
- Returns
The list of buffs attached to this entity.
-
inline double getMovementSpeed() const
Returns the movement speed of this entity.
-
inline double getCollisionRadius() const
Returns the collision radius of this entity.
-
inline int getID() const
Returns theID of this entity.
-
inline int getOwnerID() const
Returns the owner ID (i.e. player ID) who controls this entity.
-
inline void setOwnerID(int oID)
Sets the owner ID (player ID) in control of this entity..
-
inline double getLineOfSightRange() const
Returns the line of sight of this entity.
-
inline double x() const
Returns x position of this entity.
-
inline double y() const
Returns y position of this entity.
-
inline const Vector2f &getPosition() const
Returns position of this entity.
-
inline void setPosition(Vector2f v)
Sets the position of this entity in the board. Does not modify the board.
-
inline const Path &getPath() const
Returns the path that this entity is following (RTS games only)
-
inline void incPathIndex()
Increments the current index of the path that this entity is following (RTS games only)
-
inline void setPath(Path p)
Sets the path this entity is following (RTS games only)
-
inline void addBuff(Buff b)
Add buff to the player
-
void recomputeStats()
Recompute all the parameteres with the applied buffs
-
inline void removeBuffsOfType(const BuffType &newType)
Remove all the buffs of the same type
-
inline void removeAllBuffs()
Recompute all the buffs
-
inline bool hasBuff(int typeID) const
Check if player has a buff type applied
-
int getInventorySize() const
Return the inventory size
-
int getInventoryUse() const
Return the iventory slots used
-
int isInventoryFull() const
Check if inventory is full.
-
inline void addObject(Entity newObject)
Add a new object to the inventory
-
inline void removeObject(int entityID)
Remove new object from the inventory
-
inline void removeSlotObject(int entityID)
Remove slot object from the slots
-
inline const std::vector<Entity> &getInventory() const
Return the inventory of this entity
-
inline std::vector<std::pair<Entity, std::vector<int>>> getSlots() const
Return the slots of this entity
-
void equipObject(int entityID)
Equip object from the inventory
-
inline void unEquipObject(int entityID)
UnEquip object from the slot
-
inline const Entity *getSlotObjectBySlotId(int slotId) const
Get the object from the slot with a specific ID
-
bool checkSlotsAreNotInUse(const Entity &object) const
Checks if slots that a object needs are not in use
-
inline bool hasObject(int entityID) const
Return if the entity has a object with a specific Id
-
inline bool hasSlotObject(int entityID) const
Return if the entity has a object with a specific Id
-
inline const Entity *getObjectConst(int entityID) const
Return the object of this entity with a given entityID
-
inline Entity *getObject(int entityID)
Return the object of this entity with a given entityID
-
inline const Entity *getSlotObjectConst(int entityID) const
Return the object of this entity with a given entityID
-
Entity *getSlotObject(int entityID)
Return the object of this entity with a given entityID
-
inline Entity()
-
struct Tile
Public Functions
-
int getTileTypeID() const
Returns the tile type ID of this tile
- Returns
type ID of this tile
-
inline const TileType &getTileType() const
Returns the tile type of this tile
- Returns
type of this tile
-
const std::string name() const
Returns the name of this tile type
- Returns
Name ot the tile type of this type.
-
inline std::unordered_map<int, double> &getParamValues()
Gets the list of parameters values. Modifiable.
- Returns
The list of parameters values.
-
inline const std::unordered_map<int, double> &getParamValues() const
Gets the list of parameters values.
- Returns
The list of parameters values.
-
std::vector<std::string> getTileParameterNames() const
Gets the list of parameters names.
- Returns
The list of parameters names of this tile.
-
std::unordered_map<std::string, double> getTileParameters() const
Gets a map with all pairs <parameter,value>
- Returns
Returns a map with all the parameters.
-
double getParameter(const std::string ¶mName) const
Gets the value of a specific parameter with buffs applied, by name
- Returns
The parameter value.
-
double &getRawParameter(const std::string ¶mName)
Gets the reference value of a specific parameter raw, by name
- Returns
The parameter reference value.
-
inline double &getRawParameterAt(int paramIdx)
Gets a specific parameters raw, by index
- Returns
The parameter reference value.
-
inline double &getParameterAt(int paramIdx)
Gets a specific parameters value, by index
- Returns
The parameter value.
-
inline double getMaxParameterAt(int paramIdx)
Gets a specific max parameters value, by index
- Returns
The max parameter value.
-
inline double getMinParameterAt(int paramIdx)
Gets a specific min parameters value, by index
- Returns
The min parameter value.
-
int getTileTypeID() const
-
struct TileType
Public Functions
-
inline Tile toTile(int x, int y) const
Creates an instantiation of this tile given a position
- Parameters
x – X position of the tile
y – Y position of the tile
- Returns
A Tile object of this type in the position <x,y>
-
const Parameter &getParameter(ParameterID id) const
Returns a SGA::Parameter reference that contains the parameter defintion
-
const Parameter &getParameterByIndex(int index) const
Returns a SGA::Parameter reference that contains the parameter defintion
-
const Parameter &getParameterByName(std::string &name) const
Returns a SGA::Parameter reference that contains the parameter defintion
-
double getParamMax(std::string paramName) const
Returns the maximum value of a given parameter
-
double getParamMin(std::string paramName) const
Returns the minimum value of a given parameter
-
inline Tile toTile(int x, int y) const
-
class ActionSpace
Test
-
class ForwardModel
Is the driving component of Stratega, with a provided gamestate it can generate a new set of available actions thanks to the SGA::ActionSpace. The returned actions store the action type and a list of sources and targets the action will be applied to. Each SGA::RTSForwardModel and SGA::TBSForwardModel by default contains the definition of how to advance the game and other utility methods used in each specific game type. When a player provides the forward model an action and a gamestate, it first checks the type of action and after it updates the action info before executing the action. The forward models can be extended by implementing forward model abstractions, can be useful for reducing the games complexity and ease the training and decision-making process of AI agents.
Subclassed by SGA::RTSForwardModel, SGA::TBSForwardModel
Public Functions
-
virtual void advanceGameState(GameState &state, const Action &action) const = 0
Advances the game state passed by parameter with a given action.
- Parameters
state – State to be advanced. The actual object is modified by this call.
action – Action to execute in the game state
-
virtual void advanceGameState(GameState &state, const ActionAssignment &action) const = 0
Advances the game state passed by parameter with a given action
- Parameters
state – Game state to advance. The actual object is modified by this call.
action – ActionAssignment to execute in the game state.
-
std::vector<Action> generateActions(const GameState &state, int playerID) const
Returns a list of available actions in the given gamestate by the received player
- Parameters
state – Game state for which actions are generated.
playerID – ID of the players to generate available actions for.
- Returns
The list of available actions for player with ID ‘playerID’ in game state ‘state’.
-
virtual void generateActions(const GameState &state, int playerID, std::vector<Action> &actionBucket) const
Generates actions in the given gamestate by the received player and fills the action vector passed by parameter.
- Parameters
state – State of the game to generate actions for.
playerID – ID of the player for which actions are generated.
actionBucket – List of actions to populate by this method.
-
virtual std::unique_ptr<ForwardModel> clone() const = 0
Clones the current forward model.
- Returns
A copy of this forward model.
-
virtual GameType getGameType() const = 0
Indicates the game type this forward model is for. GameType is an enum defined in GameState.h
- Returns
The game type of this forward model.
-
bool checkPlayerLost(const GameState &state, int playerID) const
Checks if a player has lost the game due to the game’s lose conditions.
- Parameters
state – State of the game to check whether the player has lost or not.
playerID – ID of the player to check their lose condition
- Returns
True of the player lost.
-
bool checkPlayerWon(const GameState &state, int playerID) const
Returns if a player won the game by attending to the winning conditions defined in the rules.
- Parameters
state – State of the game to check whether the player won or not
playerID – ID of the player to be checked.
- Returns
True if the player won
-
void spawnEntity(GameState &state, const EntityType &entityType, int playerID, const Vector2f &position) const
Spawns an entity in the game with the default spawn entity method. A list of On Spawn effects are executed just after spawning the entity
- Parameters
state – State to spawn the entity in.
entityType – Type of entity to spawn.
playerID – ID of the player that will own the entity.
position – Position where the entity will be spawned.
-
inline std::shared_ptr<ActionSpace> getActionSpace() const
Returns the action space of this forward model
- Returns
Action space of this forward model.
Adds a list of conditions for the game to be won for a player.
- Parameters
conditions – List of conditions that, once fullfiled, cause a player to WIN.
Adds a list of conditions for the game to be lost for a player.
- Parameters
conditions – List of conditions that, once fullfiled, cause a player to LOSE.
-
inline const std::vector<std::vector<std::shared_ptr<Condition>>> &getWinConditions() const
Returns a list of sub-lists with all WIN conditions. Each sub-list contains a group of conditions that must be fulfilled for the game to be over for a player. The game will be WON by a player if all conditions in a sub-list are fullfiled, for at least one of the sub-lists returned.
- Returns
A list of sub-lists with all WIN conditions
-
inline const std::vector<std::vector<std::shared_ptr<Condition>>> &getLoseConditions() const
Returns a list of sub-lists with all LOSE conditions. Each sub-list contains a group of conditions that must be fulfilled for the game to be over for a player. The game will be LOST by a player if all conditions in a sub-list are fullfiled, for at least one of the sub-lists returned.
- Returns
A list of sub-lists with all LOSE conditions
-
void addOnTickEffect(OnTickEffect &ote)
Adds an OnTickEffect to the forward mode, which will be executed every game tick.
- Parameters
ote – Effect to add.
-
void addOnAdvanceEffect(OnTickEffect &ote)
Adds an OnAdvanceEffect to the forward mode, which will be executed every game tick.
- Parameters
ote – Effect to add.
-
void addOnStartEffect(OnTickEffect &ote)
Adds an OnGameStateEffect to the forward mode, which will be executed at the beginning of the game.
- Parameters
ote – Effect to add.
-
void addOnEntitySpawnEffect(OnEntitySpawnEffect &ose)
Adds an OnEntitySpawnEffect to the forward mode, which will be executed every time an entity is spawned.
- Parameters
ote – Effect to add.
-
inline const std::vector<OnTickEffect> &getOnTickEffects() const
Returns all effects that are exxecuted on every tick of the game.
-
inline const std::vector<OnTickEffect> &getOnAdvanceEffects() const
Returns all effects that are executed on advance game.
-
inline const std::vector<OnTickEffect> &getOnStartEffects() const
Returns all effects that are exxecuted at game start.
-
inline const std::vector<OnEntitySpawnEffect> &getOnEntitySpawnEffects() const
Returns all effects that are exxecuted every time an entity is spawned in the game.
-
inline void modifyEntityByParameterByName(Entity &entity, const std::string ¶meterName, double newValue) const
Returns all effects that are exxecuted every time an entity is spawned in the game.
-
inline void modifyEntityParameterByID(Entity &entity, int parameterID, double newValue) const
Modify entity parameter by ID
- Parameters
entity – Entity to search parameter from
parameterID – Index of the parameter
newValue – New value of the parameter
-
void modifyEntityParameterByIndex(Entity &entity, int parameterIndex, double newValue) const
Modify entity parameter by index
- Parameters
entity – Entity to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyTileByParameterByName(Tile &tile, std::string ¶meterName, double newValue) const
Modify Tile parameter by name
-
inline void modifyTileParameterByID(Tile &tile, int parameterID, double newValue) const
Modify Tile parameter by ID
- Parameters
entity – Entity to search parameter from
parameterID – Index of the parameter
newValue – New value of the parameter
-
void modifyTileParameterByIndex(Tile &tile, int parameterIndex, double newValue) const
Modify Tile parameter by index
- Parameters
entity – Entity to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyPlayerByParameterByName(Player &player, const std::string ¶meterName, double newValue, GameInfo &gameInfo) const
Modify player parameter by name
- Parameters
entity – Entity to search parameter from
parameterName – Name of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyPlayerParameterByID(Player &player, int parameterID, double newValue, const GameInfo &gameInfo) const
Modify player parameter by ID
- Parameters
player – Player to search parameter from
parameterID – ID of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
void modifyPlayerParameterByIndex(Player &player, int parameterIndex, double newValue) const
Modify a player parameter by index
- Parameters
player – Player to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
-
inline void modifyStateByParameterByName(GameState &state, std::string ¶meterName, double newValue, GameInfo &gameInfo) const
Modify state parameter by name
- Parameters
state – State to search parameter from
parameterName – Name of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyStateParameterByID(GameState &state, int parameterID, double newValue, const GameInfo &gameInfo) const
Modify state parameter by ID
- Parameters
state – State to search parameter from
parameterID – ID of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
virtual void advanceGameState(GameState &state, const Action &action) const = 0
-
class RTSForwardModel : public SGA::ForwardModel
Is the default SGA::yForwardModel for RTS games, it contains specific methods. Each SGA::RTSForwardModel::advanceGameState() call move all the entities and resolve the collisions before executing all the received actions. After executing the actions it updates the entities that should be removed before checking if the game is over. The SGA::RTSForwardModel::advanceGameState() accepts a list of actions or one single action.
Subclassed by SGA::PortfolioRTSForwardModel
Public Functions
-
virtual void advanceGameState(GameState &state, const Action &action) const override
Moves all the entities and resolves collisions before and after executing an action in a given SGA::GameState After executing the actions it updates the entities that should be removed before checking if the game is over.
-
virtual void advanceGameState(GameState &state, const ActionAssignment &action) const override
Moves all the entities and resolves collisions before and after executing a list of actions in a given SGA::GameState After executing the actions it updates the entities that should be removed before checking if the game is over.
-
virtual std::unique_ptr<ForwardModel> clone() const override
Clones the current forward model.
- Returns
A copy of this forward model.
-
inline virtual GameType getGameType() const override
Indicates the game type this forward model is for. GameType is an enum defined in GameState.h
- Returns
The game type of this forward model.
-
void moveEntities(GameState &state) const
Moves all the entities that have a current path and they did not reach their destination. If the entity has a path it moves the entity through all the path points one after the other until reaching the last one.
-
void resolveEntityCollisions(GameState &state) const
Resolves collisions between entities in a basic way computing the penetration depth and pushing them way in the opposite direction.
-
void resolveEnvironmentCollisions(GameState &state) const
Resolves collisions between entities and the tiles that are not walkable in a basic way computing the penetration depth and pushing them way in the opposite direction.
Generate a complete new Navmesh using Recast framework. Is a heavy computation task depending the size of the tilemap.
-
Path findPath(const GameState &state, Vector2f startPos, Vector2f endPos) const
Returns a SGA::Path inside the Navmesh between the start and end positons.
-
bool checkGameIsFinished(GameState &state) const
Checks if the game is finished by current limit or because a player has won.
-
std::vector<Action> generateActions(const GameState &state, int playerID) const
Returns a list of available actions in the given gamestate by the received player
- Parameters
state – Game state for which actions are generated.
playerID – ID of the players to generate available actions for.
- Returns
The list of available actions for player with ID ‘playerID’ in game state ‘state’.
-
virtual void generateActions(const GameState &state, int playerID, std::vector<Action> &actionBucket) const
Generates actions in the given gamestate by the received player and fills the action vector passed by parameter.
- Parameters
state – State of the game to generate actions for.
playerID – ID of the player for which actions are generated.
actionBucket – List of actions to populate by this method.
-
bool checkPlayerLost(const GameState &state, int playerID) const
Checks if a player has lost the game due to the game’s lose conditions.
- Parameters
state – State of the game to check whether the player has lost or not.
playerID – ID of the player to check their lose condition
- Returns
True of the player lost.
-
bool checkPlayerWon(const GameState &state, int playerID) const
Returns if a player won the game by attending to the winning conditions defined in the rules.
- Parameters
state – State of the game to check whether the player won or not
playerID – ID of the player to be checked.
- Returns
True if the player won
-
void spawnEntity(GameState &state, const EntityType &entityType, int playerID, const Vector2f &position) const
Spawns an entity in the game with the default spawn entity method. A list of On Spawn effects are executed just after spawning the entity
- Parameters
state – State to spawn the entity in.
entityType – Type of entity to spawn.
playerID – ID of the player that will own the entity.
position – Position where the entity will be spawned.
-
inline std::shared_ptr<ActionSpace> getActionSpace() const
Returns the action space of this forward model
- Returns
Action space of this forward model.
Adds a list of conditions for the game to be won for a player.
- Parameters
conditions – List of conditions that, once fullfiled, cause a player to WIN.
Adds a list of conditions for the game to be lost for a player.
- Parameters
conditions – List of conditions that, once fullfiled, cause a player to LOSE.
-
inline const std::vector<std::vector<std::shared_ptr<Condition>>> &getWinConditions() const
Returns a list of sub-lists with all WIN conditions. Each sub-list contains a group of conditions that must be fulfilled for the game to be over for a player. The game will be WON by a player if all conditions in a sub-list are fullfiled, for at least one of the sub-lists returned.
- Returns
A list of sub-lists with all WIN conditions
-
inline const std::vector<std::vector<std::shared_ptr<Condition>>> &getLoseConditions() const
Returns a list of sub-lists with all LOSE conditions. Each sub-list contains a group of conditions that must be fulfilled for the game to be over for a player. The game will be LOST by a player if all conditions in a sub-list are fullfiled, for at least one of the sub-lists returned.
- Returns
A list of sub-lists with all LOSE conditions
-
void addOnTickEffect(OnTickEffect &ote)
Adds an OnTickEffect to the forward mode, which will be executed every game tick.
- Parameters
ote – Effect to add.
-
void addOnAdvanceEffect(OnTickEffect &ote)
Adds an OnAdvanceEffect to the forward mode, which will be executed every game tick.
- Parameters
ote – Effect to add.
-
void addOnStartEffect(OnTickEffect &ote)
Adds an OnGameStateEffect to the forward mode, which will be executed at the beginning of the game.
- Parameters
ote – Effect to add.
-
void addOnEntitySpawnEffect(OnEntitySpawnEffect &ose)
Adds an OnEntitySpawnEffect to the forward mode, which will be executed every time an entity is spawned.
- Parameters
ote – Effect to add.
-
inline const std::vector<OnTickEffect> &getOnTickEffects() const
Returns all effects that are exxecuted on every tick of the game.
-
inline const std::vector<OnTickEffect> &getOnAdvanceEffects() const
Returns all effects that are executed on advance game.
-
inline const std::vector<OnTickEffect> &getOnStartEffects() const
Returns all effects that are exxecuted at game start.
-
inline const std::vector<OnEntitySpawnEffect> &getOnEntitySpawnEffects() const
Returns all effects that are exxecuted every time an entity is spawned in the game.
-
inline void modifyEntityByParameterByName(Entity &entity, const std::string ¶meterName, double newValue) const
Returns all effects that are exxecuted every time an entity is spawned in the game.
-
inline void modifyEntityParameterByID(Entity &entity, int parameterID, double newValue) const
Modify entity parameter by ID
- Parameters
entity – Entity to search parameter from
parameterID – Index of the parameter
newValue – New value of the parameter
-
void modifyEntityParameterByIndex(Entity &entity, int parameterIndex, double newValue) const
Modify entity parameter by index
- Parameters
entity – Entity to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyTileByParameterByName(Tile &tile, std::string ¶meterName, double newValue) const
Modify Tile parameter by name
-
inline void modifyTileParameterByID(Tile &tile, int parameterID, double newValue) const
Modify Tile parameter by ID
- Parameters
entity – Entity to search parameter from
parameterID – Index of the parameter
newValue – New value of the parameter
-
void modifyTileParameterByIndex(Tile &tile, int parameterIndex, double newValue) const
Modify Tile parameter by index
- Parameters
entity – Entity to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyPlayerByParameterByName(Player &player, const std::string ¶meterName, double newValue, GameInfo &gameInfo) const
Modify player parameter by name
- Parameters
entity – Entity to search parameter from
parameterName – Name of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyPlayerParameterByID(Player &player, int parameterID, double newValue, const GameInfo &gameInfo) const
Modify player parameter by ID
- Parameters
player – Player to search parameter from
parameterID – ID of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
void modifyPlayerParameterByIndex(Player &player, int parameterIndex, double newValue) const
Modify a player parameter by index
- Parameters
player – Player to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
-
inline void modifyStateByParameterByName(GameState &state, std::string ¶meterName, double newValue, GameInfo &gameInfo) const
Modify state parameter by name
- Parameters
state – State to search parameter from
parameterName – Name of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyStateParameterByID(GameState &state, int parameterID, double newValue, const GameInfo &gameInfo) const
Modify state parameter by ID
- Parameters
state – State to search parameter from
parameterID – ID of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
virtual void advanceGameState(GameState &state, const Action &action) const override
-
class TBSForwardModel : public SGA::ForwardModel
Is the default SGA::ForwardModel for TBS games, it contains specific methods. Each SGA::TBSForwardModel::advanceGameState() call execute the received action and updates the entities that should be removed before checking if the game is over. The SGA::TBSForwardModel::advanceGameState() accepts a list of actions or one single action.
Subclassed by SGA::PortfolioTBSForwardModel
Public Functions
-
virtual void advanceGameState(GameState &state, const Action &action) const override
Executes an action in a given SGA::GameState before updating the entities of the gamestate that should be removed and checking if the game is over.
-
virtual void advanceGameState(GameState &state, const ActionAssignment &action) const override
Executes a list of actions.
-
virtual std::unique_ptr<ForwardModel> clone() const override
Clones the current forward model.
- Returns
A copy of this forward model.
-
inline virtual GameType getGameType() const override
Indicates the game type this forward model is for. GameType is an enum defined in GameState.h
- Returns
The game type of this forward model.
-
void endTurn(GameState &state) const
End the turn of the current player and if all the player has played it ends the current game turn.
-
bool checkGameIsFinished(GameState &state) const
Checks if the game is finished by current limit or because a player has won.
-
std::vector<Action> generateActions(const GameState &state, int playerID) const
Returns a list of available actions in the given gamestate by the received player
- Parameters
state – Game state for which actions are generated.
playerID – ID of the players to generate available actions for.
- Returns
The list of available actions for player with ID ‘playerID’ in game state ‘state’.
-
virtual void generateActions(const GameState &state, int playerID, std::vector<Action> &actionBucket) const
Generates actions in the given gamestate by the received player and fills the action vector passed by parameter.
- Parameters
state – State of the game to generate actions for.
playerID – ID of the player for which actions are generated.
actionBucket – List of actions to populate by this method.
-
bool checkPlayerLost(const GameState &state, int playerID) const
Checks if a player has lost the game due to the game’s lose conditions.
- Parameters
state – State of the game to check whether the player has lost or not.
playerID – ID of the player to check their lose condition
- Returns
True of the player lost.
-
bool checkPlayerWon(const GameState &state, int playerID) const
Returns if a player won the game by attending to the winning conditions defined in the rules.
- Parameters
state – State of the game to check whether the player won or not
playerID – ID of the player to be checked.
- Returns
True if the player won
-
void spawnEntity(GameState &state, const EntityType &entityType, int playerID, const Vector2f &position) const
Spawns an entity in the game with the default spawn entity method. A list of On Spawn effects are executed just after spawning the entity
- Parameters
state – State to spawn the entity in.
entityType – Type of entity to spawn.
playerID – ID of the player that will own the entity.
position – Position where the entity will be spawned.
-
inline std::shared_ptr<ActionSpace> getActionSpace() const
Returns the action space of this forward model
- Returns
Action space of this forward model.
Adds a list of conditions for the game to be won for a player.
- Parameters
conditions – List of conditions that, once fullfiled, cause a player to WIN.
Adds a list of conditions for the game to be lost for a player.
- Parameters
conditions – List of conditions that, once fullfiled, cause a player to LOSE.
-
inline const std::vector<std::vector<std::shared_ptr<Condition>>> &getWinConditions() const
Returns a list of sub-lists with all WIN conditions. Each sub-list contains a group of conditions that must be fulfilled for the game to be over for a player. The game will be WON by a player if all conditions in a sub-list are fullfiled, for at least one of the sub-lists returned.
- Returns
A list of sub-lists with all WIN conditions
-
inline const std::vector<std::vector<std::shared_ptr<Condition>>> &getLoseConditions() const
Returns a list of sub-lists with all LOSE conditions. Each sub-list contains a group of conditions that must be fulfilled for the game to be over for a player. The game will be LOST by a player if all conditions in a sub-list are fullfiled, for at least one of the sub-lists returned.
- Returns
A list of sub-lists with all LOSE conditions
-
void addOnTickEffect(OnTickEffect &ote)
Adds an OnTickEffect to the forward mode, which will be executed every game tick.
- Parameters
ote – Effect to add.
-
void addOnAdvanceEffect(OnTickEffect &ote)
Adds an OnAdvanceEffect to the forward mode, which will be executed every game tick.
- Parameters
ote – Effect to add.
-
void addOnStartEffect(OnTickEffect &ote)
Adds an OnGameStateEffect to the forward mode, which will be executed at the beginning of the game.
- Parameters
ote – Effect to add.
-
void addOnEntitySpawnEffect(OnEntitySpawnEffect &ose)
Adds an OnEntitySpawnEffect to the forward mode, which will be executed every time an entity is spawned.
- Parameters
ote – Effect to add.
-
inline const std::vector<OnTickEffect> &getOnTickEffects() const
Returns all effects that are exxecuted on every tick of the game.
-
inline const std::vector<OnTickEffect> &getOnAdvanceEffects() const
Returns all effects that are executed on advance game.
-
inline const std::vector<OnTickEffect> &getOnStartEffects() const
Returns all effects that are exxecuted at game start.
-
inline const std::vector<OnEntitySpawnEffect> &getOnEntitySpawnEffects() const
Returns all effects that are exxecuted every time an entity is spawned in the game.
-
inline void modifyEntityByParameterByName(Entity &entity, const std::string ¶meterName, double newValue) const
Returns all effects that are exxecuted every time an entity is spawned in the game.
-
inline void modifyEntityParameterByID(Entity &entity, int parameterID, double newValue) const
Modify entity parameter by ID
- Parameters
entity – Entity to search parameter from
parameterID – Index of the parameter
newValue – New value of the parameter
-
void modifyEntityParameterByIndex(Entity &entity, int parameterIndex, double newValue) const
Modify entity parameter by index
- Parameters
entity – Entity to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyTileByParameterByName(Tile &tile, std::string ¶meterName, double newValue) const
Modify Tile parameter by name
-
inline void modifyTileParameterByID(Tile &tile, int parameterID, double newValue) const
Modify Tile parameter by ID
- Parameters
entity – Entity to search parameter from
parameterID – Index of the parameter
newValue – New value of the parameter
-
void modifyTileParameterByIndex(Tile &tile, int parameterIndex, double newValue) const
Modify Tile parameter by index
- Parameters
entity – Entity to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyPlayerByParameterByName(Player &player, const std::string ¶meterName, double newValue, GameInfo &gameInfo) const
Modify player parameter by name
- Parameters
entity – Entity to search parameter from
parameterName – Name of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyPlayerParameterByID(Player &player, int parameterID, double newValue, const GameInfo &gameInfo) const
Modify player parameter by ID
- Parameters
player – Player to search parameter from
parameterID – ID of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
void modifyPlayerParameterByIndex(Player &player, int parameterIndex, double newValue) const
Modify a player parameter by index
- Parameters
player – Player to search parameter from
parameterIndex – Index of the parameter
newValue – New value of the parameter
-
inline void modifyStateByParameterByName(GameState &state, std::string ¶meterName, double newValue, GameInfo &gameInfo) const
Modify state parameter by name
- Parameters
state – State to search parameter from
parameterName – Name of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
inline void modifyStateParameterByID(GameState &state, int parameterID, double newValue, const GameInfo &gameInfo) const
Modify state parameter by ID
- Parameters
state – State to search parameter from
parameterID – ID of the parameter
newValue – New value of the parameter
gameInfo – Game info object with the information of the current game
-
virtual void advanceGameState(GameState &state, const Action &action) const override
-
class Path
Contains all the points of the path and the current point index. Used by the default SGA::RTSForwardModel for moving entities.
-
struct Action
Contains the main information of an action as the action type id that is linked to an SGA::ActionType which defines the conditions and effects that should be executed or validated. The owner and a list of source/targets SGA::ActionTarget of the action. The action has an actionFlag to check if is an end tick action, continuous action or a normal action.
Public Functions
-
void execute(GameState &state, const ForwardModel &fm) const
Execute the effects defined in the SGA::ActionType linked to this action.
- Parameters
state – Game state in which this action is executed
fm – Forward model used to execute the aciton.
-
bool validate(GameState &state) const
Checks if this action can be executed. It verifies if the conditions defined in the SGA::ActionType linked to this action are passed. This method also checks if the last time of the action execution is higher than the cooldown, and if all the preconditions and target conditions are fullfilled. It also checks that all the actions targets are valid.
- Parameters
state – Game state in which this action could be executed
- Returns
True if this action can be run in the game state passed by parameter
-
bool isEntityAction() const
Checks if this action is to be executed over an entity.
- Returns
True if this action has an entity as target
-
bool isPlayerAction() const
Checks if this action is to be executed over a player.
- Returns
True if this action has a player as target
-
int getSourceID() const
Gets the player or entity ID of the target of this action
- Returns
The player or entity ID of the target of this action
-
int getActionTypeID() const
Returns the action type ID of this action
- Returns
Returns the action type ID of this action
-
std::string getActionName() const
Returns the name of this action
- Returns
Returns the name of this action
-
inline const ActionType &getActionType() const
Checks if this action is to be executed over an entity.
- Returns
True if this action has an entity as target
-
ActionSourceType getActionSourceType() const
Returns the action source type
- Returns
Action source type
Public Static Functions
-
static inline Action createEndAction(int playerID, const ActionType *newActionType = nullptr)
Generates an Action used by the game to end the tick/turn.
- Parameters
playerID – ID of the player for which the End action is created
- Returns
Action that ends the current turn for the plater ID supplied
-
static inline Action createAbortEntityAction(int playerID, int entityID, int continuousActionID)
Generates an Action which the owner is a entity, used by the game to abort a continuous action.
- Parameters
playerID – Player ID for which this action is created.
entityID – Entity that owns this action to abort a continuous action.
continuousActionID – ID of the continuous action to abort
- Returns
-
static inline Action createAbortPlayerAction(int playerID, int continuousActionID)
Generates an Action which the owner is a player, used by the game to abort a continuous action.
- Parameters
playerID – Player ID for which this action is created.
continuousActionID – ID of the continuous action to abort
- Returns
-
void execute(GameState &state, const ForwardModel &fm) const
-
struct ActionInfo
Contains the last tick this action was executed and the action type ID. Used by forward models to check if the SGA::Entity or player can execute the action again after the cooldown.
-
struct ActionType
Contains the definition of an action. Which type is the source SGA::ActionSourceType , a set effects, preconditions and a list of action targets linked to their target conditions. If the action is continuous it will have a set of effects as events: OnStart, OnTick, OnComplete, OnAbort and the list of conditions that triggers the completed action.
Public Functions
-
class ActionTarget
Used by SGA::Action to reference any possible type of target available in Stratega. It contains a union of different types of data.
-
enum SGA::ActionSourceType
Used to know who is the source of an action, it can be a entity or a player.
Values:
-
enumerator Entity
-
enumerator Player
-
enumerator Entity
-
enum SGA::ActionFlag
Used to define how the SGA::ForwardModel::executeAction() will execute this action.
Values:
-
enumerator None
-
enumerator EndTickAction
-
enumerator ContinuousAction
-
enumerator AbortContinuousAction
-
enumerator None
-
class Condition
Subclassed by SGA::CanAfford, SGA::CanEquipObject, SGA::CanResearch, SGA::CanSpawnCondition, SGA::DifferentPlayer, SGA::HasBuff, SGA::HasElapsedTime, SGA::HasEntity, SGA::HasInventoryFull, SGA::HasNoBuff, SGA::HasNoEntities, SGA::HasNoEntity, SGA::HasNotInventoryFull, SGA::InRange, SGA::IsNeutral, SGA::IsNotNeutral, SGA::IsNotOccupied, SGA::IsNotOccupiedGrid, SGA::IsNotTick, SGA::IsOccupied, SGA::IsOccupiedGrid, SGA::IsPlayerEntity, SGA::IsPlayerID, SGA::IsResearched, SGA::IsTick, SGA::IsTickMultipleOf, SGA::IsTile, SGA::IsWalkable, SGA::OutRange, SGA::ResourceGreaterEqual, SGA::ResourceLowerEqual, SGA::SamePlayer
-
class Effect
Subclassed by SGA::ApplyBuff, SGA::Attack, SGA::AttackAroundWithArmor, SGA::AttackProbability, SGA::AttackWithArmorUnderCover, SGA::ChangeOwnerEffect, SGA::ChangeResource, SGA::DropObject, SGA::Empty, SGA::EnqueueAction, SGA::EquipObject, SGA::ModifyResource, SGA::Move, SGA::PayCostEffect, SGA::PickUp, SGA::Push, SGA::PushAndHit, SGA::PushAroundPositionAndHit, SGA::RemoveAllBuffs, SGA::RemoveBuff, SGA::RemoveEntityEffect, SGA::RemoveObject, SGA::ResearchTechnology, SGA::SetToMaximum, SGA::SpawnEntity, SGA::SpawnEntityGrid, SGA::SpawnEntityRandom, SGA::SpawnEntityRandomLocation, SGA::TransferEffect, SGA::UnEquipObject, SGA::UseObject, SGA::UseSlotObject
-
struct SamplingMethod
Subclassed by SGA::Dijkstra, SGA::Neighbours
-
struct Buff
Public Functions
-
inline const BuffType &getType() const
Return the buff type
- Returns
Buff type
-
inline int getElapsedTicks() const
Return the number of ticks elapsed of this buff
- Returns
Elapsed ticks
-
inline void setElapsedTicks(int newElapsedTicks)
Apply the new amount of elapsed ticks this buff has
- Parameters
newElapsedTicks – New amount of elapsed ticks
-
inline int getDurationTicks() const
Return the number of duration ticks of this buff
- Returns
Duration ticks
-
inline void setDurationTicks(int newDurartionTicks)
Apply the new amount of duration ticks this buff has
- Parameters
newElapsedTicks – New amount of duration ticks
-
inline void incrementElapseTicks()
Increment the elpased tick by one
Public Static Functions
-
inline const BuffType &getType() const
-
struct Buff
Public Functions
-
inline const BuffType &getType() const
Return the buff type
- Returns
Buff type
-
inline int getElapsedTicks() const
Return the number of ticks elapsed of this buff
- Returns
Elapsed ticks
-
inline void setElapsedTicks(int newElapsedTicks)
Apply the new amount of elapsed ticks this buff has
- Parameters
newElapsedTicks – New amount of elapsed ticks
-
inline int getDurationTicks() const
Return the number of duration ticks of this buff
- Returns
Duration ticks
-
inline void setDurationTicks(int newDurartionTicks)
Apply the new amount of duration ticks this buff has
- Parameters
newElapsedTicks – New amount of duration ticks
-
inline void incrementElapseTicks()
Increment the elpased tick by one
Public Static Functions
-
inline const BuffType &getType() const
-
struct TechnologyTreeNode
Public Functions
Public Members
-
std::string name
Name of this technology as given in YAML
-
int id = -1
Unique ID of this technology.
-
std::vector<int> parentIDs
IDs of the technologies that are required for this one to be researchable.
-
std::unordered_map<ParameterID, double> cost
List of pairs (param,cost) that can be spend to research this technology.
-
double continuousActionTime = 0
How many ticks/turns takes to research this technology.
-
std::string name
-
class TechnologyTreeType
Public Functions
-
const TechnologyTreeNode &getTechnologyNode(int technologyID) const
Returns a tech tree node from this tree with a corresponding technology ID.
- Parameters
technologyID – ID of the technology we are looking for
- Returns
Technology node to retrieve from this tree.
-
bool existsTechnologyTreeNode(int technologyID) const
Checks if a given technology ID exists in this tree.
- Parameters
technologyID – Tech ID to check
- Returns
True if there’s a technology in this tree with the ID received.
-
int getTechnologyNodeID(const std::string &technologyName) const
Returns the ID of a technology that matches the requested name.
- Parameters
technologyName – Name to match of a technology in the tree.
- Returns
The ID of the technology with the same name as the one passed.
-
bool existsTechnologyNode(const std::string &technologyName) const
Checks if a technology with a given name exists in this tree.
- Parameters
technologyName – Name of the technology to check
- Returns
True if it exists.
Public Members
-
std::string technologyTreeName
Name of this technology tree
-
std::unordered_map<int, TechnologyTreeNode> technologies
Data of this tech tree, each entry contains and ID as key and a technology node as a value
-
const TechnologyTreeNode &getTechnologyNode(int technologyID) const
-
class TechnologyTreeCollection
Public Functions
-
const TechnologyTreeNode &getTechnology(int technologyID) const
Returns a technology node with an ID corresponding to the one passed by parameter. The node could come from any of the trees of this collection.
- Parameters
technologyID – ID of the technology to search for.
- Returns
The tree node searched for, an exception if it doesn’t exist.
-
int getTechnologyTypeID(const std::string &technologyName) const
Returns the ID of a technology that matches the requested name, in any of the trees of this collection.
- Parameters
technologyName – Name of the technology to search for.
- Returns
ID of the technology searched for, or a runtime error if it doesn’t exist.
Public Members
-
std::unordered_map<int, TechnologyTreeType> technologyTreeTypes
List of technology trees, indexed by a unique ID.
-
const TechnologyTreeNode &getTechnology(int technologyID) const