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.
PropertiesName | Type | Description |
---|---|---|
map | Map | A Map to store agents, where the key is the agent's ID and the value is an OpponentAgent instance. |
- Source
Classes
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:
Name | Type | Description |
---|---|---|
a | * | Agent object containing id, x, y, teamName, etc. |
timestamp | number | Timestamp of the agent's state |
- Source
findDirection(old, curr) → {string}
This method determines the direction in which an agent has moved based on its previous and current positions.
Parameters:
Name | Type | Description |
---|---|---|
old | OpponentAgent | The previous state of the agent |
curr | OpponentAgent | The current state of the agent |
- Source
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:
Name | Type | Description |
---|---|---|
a | * | Agent object containing id |
- Source
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:
Name | Type | Description |
---|---|---|
a | * | Agent object containing id, x, y, etc. |
timestamp | number | Timestamp of the agent's state |
- Source
visible(me, config) → {Array}
This method returns an array of all agents currently stored in the AgentStore.
Parameters:
Name | Type | Description |
---|---|---|
me | Me | The current player's agent |
config | ServerConfig | The server configuration containing game settings |
- Source
Returns:
- Array of all agents in the store
- Type:
- Array