AgentStore

AgentStore class to store agents in the game

Constructor

new AgentStore()

This class is responsible for managing the agents in the game. It allows adding, removing, and updating agents, as well as finding visible agents based on the player's position and the game configuration. It uses a Map to store agents, where the key is the agent's ID and the value is an instance of OpponentAgent.
Properties
NameTypeDescription
mapMapA Map to store agents, where the key is the agent's ID and the value is an OpponentAgent instance.

Classes

AgentStore

Methods

addAgent(a, timestamp)

This method adds an agent to the AgentStore. If the agent is already present, it updates its state. If the agent is new, it creates a new OpponentAgent instance and adds it to the map.
Parameters:
NameTypeDescription
a*Agent object containing id, x, y, teamName, etc.
timestampnumberTimestamp of the agent's state

findDirection(old, curr) → {string}

This method determines the direction in which an agent has moved based on its previous and current positions.
Parameters:
NameTypeDescription
oldOpponentAgentThe previous state of the agent
currOpponentAgentThe current state of the agent
Returns:
- The direction of movement (UP, DOWN, LEFT, RIGHT, NONE)
Type: 
string

removeAgent(a)

This method removes an agent from the AgentStore based on its ID.
Parameters:
NameTypeDescription
a*Agent object containing id

updateAgent(a, timestamp)

This method updates the state of an existing agent in the AgentStore. It updates the agent's position, direction, and timestamp.
Parameters:
NameTypeDescription
a*Agent object containing id, x, y, etc.
timestampnumberTimestamp of the agent's state

visible(me, config) → {Array}

This method returns an array of all agents currently stored in the AgentStore.
Parameters:
NameTypeDescription
meMeThe current player's agent
configServerConfigThe server configuration containing game settings
Returns:
- Array of all agents in the store
Type: 
Array