Agent

Agent class representing an agent in the game. This class encapsulates the agent's beliefs, desires, intentions, and pathfinding logic. It interacts with the game server through a client and manages its own state, including movement, exploration, and collision handling.

Constructor

new Agent(client, me, parcels, mapStore, agentStore, serverConfig)

The Agent class is responsible for managing the agent's actions and interactions within the game. It maintains the agent's beliefs, desires, and intentions, and uses pathfinding algorithms to navigate the game map. The agent can perform actions such as picking up parcels, depositing them at bases, and exploring the map. It also handles agent collisions and camping behavior based on the game state. The agent's actions are logged for debugging and analysis purposes.
Parameters:
NameTypeDescription
clientDeliverooClientThe client to communicate with the server.
meMeThe agent's own data, including its position and state.
parcelsParcelsStoreThe parcels store to manage parcels in the game.
mapStoreMapStoreThe map store to manage the game map.
agentStoreAgentStoreThe agent store to manage other agents in the game.
serverConfigServerConfigThe server configuration containing game settings.

Classes

Agent

Methods

(async) achieveDeposit(isEqualToLastIntention)

This method is called when the agent intends to deposit parcels. It checks if the agent is already at the nearest base and emits a putdown event if so. If the agent is not at the base, it calculates a new path towards the base and checks for collisions with other agents. If the agent reaches the base's coordinates, it emits a putdown event to deposit the carried parcels.
Parameters:
NameTypeDescription
isEqualToLastIntentionbooleanIndicates if the current intention is the same as the last one.

(async) achieveExplore(isEqualToLastIntention)

This method is called when the agent intends to explore the map. It checks if the agent is camping on a spawn tile and updates the camping state based on the elapsed time. If the agent is not camping, it calculates a new path towards a random spawn tile and checks for collisions with other agents. If the agent reaches the spawn tile, it will either continue exploring or camp based on the spawn's sparsity. If the agent is camping, it will perform random movements until the camping conditions are no longer met.
Parameters:
NameTypeDescription
isEqualToLastIntentionbooleanIndicates if the current intention is the same as the last one.

(async) achievePickup(p, isEqualToLastIntention, isFromDropped)

This method is called when the agent intends to pick up a parcel. It checks if the agent is already at the parcel's location and emits a pickup event if so. If the agent is not at the parcel's location, it calculates a new path towards the parcel and checks for collisions with other agents. If the agent reaches the parcel's coordinates, it emits a pickup event to the server.
Parameters:
NameTypeDescription
pObjectThe parcel to be picked up, containing its coordinates and ID.
isEqualToLastIntentionbooleanIndicates if the current intention is the same as the last one.
isFromDroppedbooleanIndicates if the pickup is from a dropped parcel.

(async) act()

This method is called in each game loop to execute the agent's intentions based on the current game state. It ensures that the agent acts on its most pressing intentions while considering the environment and other agents.

filterIntentions()

This method is typically called after generating desires to prioritize the most desirable actions for the agent. It ensures that the agent acts on the most valuable intentions first, based on their calculated scores.

generateDesires()

This method is called to determine the agent's desires, which are then used to form intentions. It evaluates the agent's current state, including carried parcels and their rewards, and generates a list of desires with associated scores. It also considers the agent's position on the map and the distance to available parcels. If the agent is carrying parcels, it will also consider depositing them at the nearest base. Finally, it adds an intention to explore if no other intentions are more desirable.

getBasePath(target)

This method attempts to find a path to the nearest base tile. If the agent is already at the target base, it returns immediately. If the agent is not at the target base, it checks if the path to the base is clear. If the path is not clear, it removes the current base from the map and waits for a specified time before restoring it. It then finds a new target base and recalculates the path to it. This process continues until a valid path is found or the maximum number of tries is reached.
Parameters:
NameTypeDescription
targetObjectThe target coordinates of the nearest base to which the agent should find a path.
Example
agent.getBasePath({ x: 10, y: 15 });

getNewPath(target)

This method calculates a path from the agent's current position to the specified target using the A* algorithm. It initializes the path index to 0 and temporarily removes visible agents from the map to avoid collisions. The path is then calculated and stored in the agent's path property. After the path is calculated, the removed agents are restored to their original tile types. This allows the agent to find a path without being blocked by other agents while still considering their presence in the game.
Parameters:
NameTypeDescription
targetObjectThe target coordinates to which the agent should find a path.
Example
agent.getNewPath({ x: 5, y: 10 });

getPath(target)

This method calculates a path from the agent's current position to the specified target using the A* algorithm. It initializes the path index to 0 and stores the calculated path in the agent's path property. The path is used to determine the agent's movement towards the target tile.
Parameters:
NameTypeDescription
targetObjectThe target coordinates to which the agent should find a path.
Example
agent.getPath({ x: 5, y: 10 });

log(logLevel, …args) → {void}

This method checks if the provided log level is included in the agent's log levels. If it is, it calls the `log` function with the log levels, log level, and arguments. This allows for flexible logging of messages based on the agent's current log configuration.
Parameters:
NameTypeAttributesDescription
logLevelstringThe log level to filter messages (e.g., LOG_LEVELS.MASTER, LOG_LEVELS.ACTION)
args*<repeatable>
The arguments to log, can be any type (string, object, etc.)
Returns:
Type: 
void
Examples
agent.log(LOG_LEVELS.MASTER, "This is a master log message");
agent.log(LOG_LEVELS.ACTION, "This is an action log message", { somjeData: 123 });

(async) oneStep()

This method is called in each game loop to move the agent towards its next destination. It calculates the direction to the next tile in the path and performs the movement action. If the agent has reached the end of its path, it resets the last intention to indicate that no further action is needed.

(async) oneStepCheckAgents(newPathTile)

This method is called in each game loop to handle agent movement and collision detection. It ensures that the agent can navigate the map while avoiding collisions with other agents. If a collision is detected, it will wait for a specified time before attempting to get a new path. If no collisions are detected, it will proceed with the next step in the agent's path.
Parameters:
NameTypeDescription
newPathTileObjectThe tile to which the agent should move if a collision is detected.

updateBeliefs() → {void}

This method is typically called in each game loop to keep the agent's beliefs up-to-date with the current game state.
Returns:
Type: 
void