Class cse491::AgentBase
ClassList > cse491 > AgentBase
Inherits the following classes: cse491::Entity
Inherited by the following classes: cse491::InterfaceBase
Public Functions
Type | Name |
---|---|
virtual AgentBase & | AddAction (const std::string & action_name, size_t action_id) Provide a new action that this agent can take. |
AgentBase (size_t id, const std::string & name) Default value upon initialization. |
|
virtual void | Deserialize_impl (std::istream & is) override Deserialize item-specific values and call Entity 's Deserialize_impl. |
size_t | GetActionID (const std::string & action_name) const Return an action ID if that action exists, otherwise return zero. |
int | GetActionResult () const Retrieve the result of the most recent action. |
State | GetAgentState () Get the current state of the Agent. |
virtual GridPosition | GetNextPosition () Allow derived agents to provide an arbitrary next position for the world to move the agent to. |
virtual std::string | GetTypeName_impl () override const Override to allow access the derived name for this type. |
bool | HasAction (const std::string & action_name) const Test if agent already has a specified action. |
virtual bool | Initialize () Run AFTER the world configures the agent, for additional tests or setup. |
virtual bool | IsAgent () override const Is Entity an autonomous agent? |
virtual void | Notify (const std::string &, const std::string &="none") Send a notification to this agent, typically from the world. |
virtual size_t | SelectAction (const WorldGrid & grid, const type_options_t & type_options, const item_map_t & item_map, const agent_map_t & agent_map) Decide the next action for this agent to perform; should be overridden! |
virtual void | Serialize_impl (std::ostream & os) override const Serialize item-specific values and call Entity 's Serialize_impl. |
void | SetActionResult (int result) Update the result from the most recent action. |
void | TakeDamage (cse491::AgentBase & agent) If the agent is in State::Taking_Damage, decrease the health by the damage factor once per timestep. |
void | UpdateAgentState (cse491::AgentBase & agent) Updates an Agent's state depending on health. |
void | storeActionMap (std::string name) |
~AgentBase () = default |
Public Functions inherited from cse491::Entity
See cse491::Entity
Type | Name |
---|---|
Entity & | AddItem (size_t id) |
Entity & | AddItem (Entity & item) |
virtual void | Deserialize_impl (std::istream & is) override Serialize entity-specific values. |
Entity (size_t id, const std::string & name) |
|
Entity (const Entity &) = delete |
|
Entity (Entity &&) = default |
|
size_t | GetGridID () const |
size_t | GetID () const |
std::vector< size_t > | GetInventory () const |
const std::string & | GetName () const |
size_t | GetNumProperties () const How many properties does this entity have? |
GridPosition | GetPosition () const |
const T & | GetProperty (const std::string & name) const Return the current value of the specified property. |
property_map_t & | GetPropertyMap () return the property map for the entity |
PropertyType | GetPropertyType (const std::string & name) const |
WorldBase & | GetWorld () const |
bool | HasItem (size_t id) const Inventory Management. |
bool | HasProperty (const std::string & name) const Does this agent have a property with the specified name? |
bool | HasWorld () const |
virtual bool | IsAgent () const Is Entity an autonomous agent? |
virtual bool | IsInterface () const Is Entity an interface for a human? |
virtual bool | IsItem () const Is Entity an item? |
bool | IsOnGrid (size_t in_grid_id) const |
Entity & | RemoveItem (size_t id) |
Entity & | RemoveItem (Entity & item) |
Entity & | RemoveProperty (const std::string & name) Completely remove a property from an Entity . |
virtual void | Serialize_impl (std::ostream & os) override const Serialize entity-specific values. |
Entity & | SetName (const std::string in_name) |
Entity & | SetPosition (GridPosition in_pos, size_t grid_id=0) |
Entity & | SetPosition (double x, double y) |
Entity & | SetProperties () Allow for setting multiple properties at once. |
Entity & | SetProperties (const std::string & name, VALUE_T && value, EXTRA_Ts &&... extras) |
Entity & | SetProperty (const std::string & name, const T & value) Change the value of the specified property (will create if needed) |
virtual Entity & | SetWorld (WorldBase & in_world) |
Entity & | operator= (const Entity &) = delete |
Entity & | operator= (Entity &&) = delete |
virtual | ~Entity () = default |
Public Functions inherited from cse491::CoreObject
Type | Name |
---|---|
void | Deserialize (std::istream & is) Restore the state of this object, extracting it from the provided stream. |
bool | Deserialize (std::string filename) A version of Deserialize that accepts a filename to read this object from. |
std::string | GetTypeName () const Access the derived name for this type. |
void | Serialize (std::ostream & os) const Store the current state of this object for later extraction. |
bool | Serialize (std::string filename) const A version of Serialize that accepts a filename for saving just this object. |
auto | operator<=> (const CoreObject &) const |
virtual | ~CoreObject () |
Protected Types inherited from cse491::Entity
See cse491::Entity
Type | Name |
---|---|
typedef std::unordered_map< std::string, std::unique_ptr< PropertyBase > > | property_map_t Every entity can have a simple set of properties (with values) associated with it. |
Protected Attributes
Type | Name |
---|---|
int | action Action that agent is currently performing. |
std::unordered_map< std::string, size_t > | action_map Map of names to action ids. |
int | action_result = = 0 Usually a one (success) or zero (failure). |
State | agent_state = = Healthy |
Protected Attributes inherited from cse491::Entity
See cse491::Entity
Type | Name |
---|---|
size_t | grid_id = = 0 Which grid is this entity on? |
size_t | id = = 0 Unique ID for this entity (0 is used for "no ID") |
std::vector< size_t > | inventory What entity ids are held by this entity? |
std::string | name = = "" Name for this entity (E.g., "Player 1" or "+2 Sword") |
GridPosition | position Where on the grid is this entity? |
property_map_t | property_map |
Protected Functions inherited from cse491::Entity
See cse491::Entity
Type | Name |
---|---|
Property< T > & | AsProperty (const std::string & name) const |
Protected Functions inherited from cse491::CoreObject
Type | Name |
---|---|
virtual void | Deserialize_impl (std::istream &) = 0 Override to restore the state of this object from the provided stream. |
bool | EndDeserialize (std::istream & is) Set up end of the deserialization for this class (does type checking) |
void | EndSerialize (std::ostream & os) const Set up end of the serialization for this class (allows checking later) |
virtual std::string | GetTypeName_impl () const = 0 Override to allow access the derived name for this type. |
virtual void | Serialize_impl (std::ostream &) const = 0 Override to store the current state of this object for later extraction. |
bool | StartDeserialize (std::istream & is) Set up beginning of the deserialization for this class (does type checking) |
void | StartSerialize (std::ostream & os) const Set up beginning of the serialization for this class (allows checking later) |
Public Functions Documentation
function AddAction
inline virtual AgentBase & cse491::AgentBase::AddAction (
const std::string & action_name,
size_t action_id
)
function AgentBase
inline cse491::AgentBase::AgentBase (
size_t id,
const std::string & name
)
function Deserialize_impl
Deserialize item-specific values and call Entity 's Deserialize_impl.
inline virtual void cse491::AgentBase::Deserialize_impl (
std::istream & is
) override
Parameters:
is
istream to read contents from.
Implements cse491::CoreObject::Deserialize_impl
function GetActionID
inline size_t cse491::AgentBase::GetActionID (
const std::string & action_name
) const
function GetActionResult
inline int cse491::AgentBase::GetActionResult () const
function GetAgentState
Get the current state of the Agent.
inline State cse491::AgentBase::GetAgentState ()
Returns:
State enum of agent_state
function GetNextPosition
inline virtual GridPosition cse491::AgentBase::GetNextPosition ()
function GetTypeName_impl
Override to allow access the derived name for this type.
inline virtual std::string cse491::AgentBase::GetTypeName_impl () override const
Returns:
A unique typename, ideally the exact name for this class (with scope) This member function will be helpful for serialization and debugging. It should return a fully scoped typename, such as "cse491::WorldGrid".
Implements cse491::CoreObject::GetTypeName_impl
function HasAction
inline bool cse491::AgentBase::HasAction (
const std::string & action_name
) const
function Initialize
Run AFTER the world configures the agent, for additional tests or setup.
inline virtual bool cse491::AgentBase::Initialize ()
Returns:
Was the initialization successful?
function IsAgent
inline virtual bool cse491::AgentBase::IsAgent () override const
Implements cse491::Entity::IsAgent
function Notify
Send a notification to this agent, typically from the world.
inline virtual void cse491::AgentBase::Notify (
const std::string &,
const std::string &="none"
)
Parameters:
message
Contents of the notificationmsg_type
Category of message, such as "item_alert", "damage", or "enemy" This function is useful to notify users of events in the world, such as them taking damage, finding an item, etc. The message type can potentially also provide information to an autonomous agent assuming we come up with a standard list of types.
function SelectAction
Decide the next action for this agent to perform; should be overridden!
inline virtual size_t cse491::AgentBase::SelectAction (
const WorldGrid & grid,
const type_options_t & type_options,
const item_map_t & item_map,
const agent_map_t & agent_map
)
Parameters:
grid
The agent is provided with the current WorldGrid
Returns:
ID associated with the action to perform; (zero is always "no action")
function Serialize_impl
Serialize item-specific values and call Entity 's Serialize_impl.
inline virtual void cse491::AgentBase::Serialize_impl (
std::ostream & os
) override const
Parameters:
os
ostream to write contents to.
Implements cse491::CoreObject::Serialize_impl
function SetActionResult
inline void cse491::AgentBase::SetActionResult (
int result
)
function TakeDamage
inline void cse491::AgentBase::TakeDamage (
cse491::AgentBase & agent
)
function UpdateAgentState
Updates an Agent's state depending on health.
inline void cse491::AgentBase::UpdateAgentState (
cse491::AgentBase & agent
)
Parameters:
agent
The agent whose state to update If the agent's health is between Max_health and 3 -> Healthy If the agent's health is between 0 and 3 -> Dying If the agent is Taking_Damage -> Taking_Damage If the agent is at 0 or below -> Dead
See also: TakeDamage
Returns:
None
function storeActionMap
inline void cse491::AgentBase::storeActionMap (
std::string name
)
function ~AgentBase
cse491::AgentBase::~AgentBase () = default
Protected Attributes Documentation
variable action
int action;
variable action_map
std::unordered_map<std::string, size_t> action_map;
variable action_result
int action_result;
variable agent_state
State agent_state;
The documentation for this class was generated from the following file source/core/AgentBase.hpp