Skip to content

Class group4::SecondWorld

ClassList > group4 > SecondWorld

More...

  • #include <SecondWorld.hpp>

Inherits the following classes: WorldBase

Public Functions

Type Name
bool CheckPosition (cse491::AgentBase & agent, cse491::GridPosition & pos)
int DoAction (cse491::AgentBase & agent, size_t action_id) override
void DropItem (cse491::AgentBase & agent, cse491::GridPosition & pos)
bool IsTraversable (const AgentBase & agent, cse491::GridPosition pos) override const
void LoadFromFile (const std::string & input_filename)
void PrintEntities ()
virtual void Run () override
void SaveToFile ()
SecondWorld ()
SecondWorld (std::string grid_filename, std::string agent_filename)
~SecondWorld () = default

Protected Types

Type Name
enum ActionType

Protected Attributes

Type Name
std::map< size_t, std::unique_ptr< cse491::ItemBase > > inventory
Vector of the items in this world.
worldlang::ProgramExecutor pe
Script executor object.

Protected Functions

Type Name
void ConfigAgent (cse491::AgentBase & agent) override
Provide the agent with movement actions.

Detailed Description

Creates a world with agents and a win flag

Public Functions Documentation

function CheckPosition

inline bool group4::SecondWorld::CheckPosition (
    cse491::AgentBase & agent,
    cse491::GridPosition & pos
) 

Checks to see if there is a flag or item at the agent's current position

Parameters:

  • agent The agent
  • pos The position

Returns:

true if agent should update position on return

function DoAction

inline int group4::SecondWorld::DoAction (
    cse491::AgentBase & agent,
    size_t action_id
) override

Allows agents to perform an action and sets each agent's new position

Parameters:

  • agent The agent performing the action
  • action_id The id that represents the move

Returns:

An int that declares if the move is legal or illegal (true / false)

function DropItem

inline void group4::SecondWorld::DropItem (
    cse491::AgentBase & agent,
    cse491::GridPosition & pos
) 

Drops the item in the agent's inventory

Parameters:

  • agent This agent's item we're dropping
  • pos The position where the item will be dropped

function IsTraversable

inline bool group4::SecondWorld::IsTraversable (
    const AgentBase & agent,
    cse491::GridPosition pos
) override const

Can walk on all tiles except for walls and water (unless agent has property set)

function LoadFromFile

inline void group4::SecondWorld::LoadFromFile (
    const std::string & input_filename
) 

Loads data from a JSON file and adds agents with specified properties into the world.

Parameters:

  • input_filename Relative path to input.json file

function PrintEntities

inline void group4::SecondWorld::PrintEntities () 

Prints the entities in item_set (testing)

function Run

inline virtual void group4::SecondWorld::Run () override

This function gives us an output.json file

function SaveToFile

inline void group4::SecondWorld::SaveToFile () 

This function gives us an output.json file using nlohmann::json library

function SecondWorld [1/2]

inline group4::SecondWorld::SecondWorld () 

Constructor with no arguments

function SecondWorld [2/2]

inline group4::SecondWorld::SecondWorld (
    std::string grid_filename,
    std::string agent_filename
) 

Constructor with grid and agent file names

Parameters:

  • grid_filename Relative path to grid file
  • agent_filename Relative path to agent input.json file

function ~SecondWorld

group4::SecondWorld::~SecondWorld () = default

Destructor

Protected Types Documentation

enum ActionType

enum group4::SecondWorld::ActionType {
    REMAIN_STILL = 0,
    MOVE_UP,
    MOVE_DOWN,
    MOVE_LEFT,
    MOVE_RIGHT,
    DROP_ITEM
};

Protected Attributes Documentation

variable inventory

std::map<size_t, std::unique_ptr<cse491::ItemBase> > inventory;

variable pe

worldlang::ProgramExecutor pe;

Protected Functions Documentation

function ConfigAgent

inline void group4::SecondWorld::ConfigAgent (
    cse491::AgentBase & agent
) override

The documentation for this class was generated from the following file source/Worlds/SecondWorld.hpp