Methods

astarSearch(start, goal, mapStore)

This function implements the A* search algorithm to find the shortest path from start to goal. It uses a heuristic based on the Manhattan distance to prioritize nodes in the search. The function returns an array of coordinates representing the path from start to goal. If no path is found, it returns an empty array.
Parameters:
NameTypeDescription
startObjectStarting coordinates
goalObjectGoal coordinates
mapStoreMapStoreThe MapStore instance containing the grid and obstacles

buildExecutor(onMove, onPickup, onDeposit) → {PddlExecutor}

Builds a PddlExecutor instance with action handlers for MOVE, PICKUP, and DEPOSIT.
Parameters:
NameTypeDescription
onMovefunctionFunction to call when MOVE action is executed.
onPickupfunctionFunction to call when PICKUP action is executed.
onDepositfunctionFunction to call when DEPOSIT action is executed.
Returns:
- Configured PddlExecutor instance.
Type: 
PddlExecutor

checkIfIamAtBase(me, mapStore) → {boolean}

This function checks if the current player's coordinates match any of the base locations in the map store. It uses the coord2Key function to convert the player's coordinates into a key that can be checked against the map store's bases.
Parameters:
NameTypeDescription
meMeThe current player instance.
mapStoreMapStoreThe MapStore instance containing the current map state.
Throws:
- Throws an error if the map store is not initialized or if the player's coordinates are invalid.
Type
Error
Returns:
- Returns true if the player is at a base, false otherwise.
Type: 
boolean

direction(from, to) → {string|null}

Determine the direction from one coordinate to another.
Parameters:
NameTypeDescription
fromObjectStarting coordinates
toObjectTarget coordinates
Returns:
- Returns 'right', 'left', 'up', 'down' or null if coordinates are the same
Type: 
string | null

easyExplore(client, me, mapStore) → {Promise.<boolean>}

This function finds a random spawn tile on the map and uses the A* search algorithm to calculate the path to that tile. It then moves the agent in the direction of each step in the path. If a valid path is found, it moves the agent step by step. If no spawn tile is found or no valid path exists, it logs an error message and returns false.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
mapStoreMapStoreThe MapStore instance containing the current map state.
Returns:
- Returns true if successfully moved to a spawn tile, false otherwise.
Type: 
Promise.<boolean>

executePlan(rawPlan, onMove, onPickup, onDeposit) → {Promise.<void>}

Executes a PDDL plan using the provided action handlers.
Parameters:
NameTypeDescription
rawPlanArrayThe raw plan generated by the PDDL solver.
onMovefunctionFunction to call when MOVE action is executed.
onPickupfunctionFunction to call when PICKUP action is executed.
onDepositfunctionFunction to call when DEPOSIT action is executed.
Throws:
- Throws an error if the plan execution fails.
Type
Error
Returns:
- A promise that resolves when the plan execution is complete.
Type: 
Promise.<void>

generateDeliverooDomain()

Returns a static PDDL domain definition (deliveroo-domain.pddl).

generateDeliverooProblem()

Predicates that I have in the domain-file: - (at ?a - agent ?t - tile) -(parcel-at ?p - parcel ?t - tile) - (carrying ?a - agent ?p - parcel) - (base-at ?b - base ?t - tile) - (delivered ?p - parcel) -(adjacent ?t1 - tile ?t2 - tile) So I need to use these predicates to build the problem The PDDL problem definition has the following structure: define (problem PROBLEM_NAME) (:domain DOMAIN_NAME) (:objects OBJ1 OBJ2 ... OBJ_N) (:init ATOM1 ATOM2 ... ATOM_N) (:goal CONDITION_FORMULA) )

getNearTiles(mapStore, me, mate, myPos) → {Array.<string>}

Gets the possible near tiles for movement based on the current position of the agent and its mate.
Parameters:
NameTypeDescription
mapStoreMapStoreThe MapStore instance containing the current map state.
meMeThe current player instance.
mateMeThe mate player instance.
myPosObjectThe current position of the agent.
Returns:
- An array of possible movement directions (e.g., ['UP', 'DOWN']).
Type: 
Array.<string>

getPlan(mapStore, parcelsStore, me, serverConfig) → {Promise.<Array>}

Generates a PDDL plan for the Deliveroo problem using the online solver.
Parameters:
NameTypeDescription
mapStoreMapStoreThe MapStore instance containing the current map state.
parcelsStoreParcelsStoreThe ParcelsStore instance containing the current parcels state.
meMeThe current player instance.
serverConfigServerConfigThe server configuration instance.
Throws:
- Throws an error if the solver fails to generate a plan.
Type
Error
Returns:
- A promise that resolves to the raw plan generated by the solver.
Type: 
Promise.<Array>

goAway(client, me, mate, mapStore) → {Promise.<void>}

This function iterates a specified number of times, each time selecting a random direction from the possible near tiles around the agent's current position. It moves the agent in that random direction and updates the agent's position for the next iteration. This is useful for simulating random movement away from the current position, which can be useful in various game scenarios.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
mateMeThe mate player instance.
mapStoreMapStoreThe MapStore instance containing the current map state.
Returns:
- A promise that resolves when the movement is complete.
Type: 
Promise.<void>

(async) initApp() → {Promise.<Object>}

This function initializes the main components of the application: - DeliverooClient: The client to interact with the Deliveroo API. - Me: Represents the current player. - ParcelsStore: Manages the parcels in the game. - MapStore: Manages the game map - AgentStore: Manages the agents in the game. - ServerConfig: Holds the server configuration.
Throws:
- Throws an error if initialization fails.
Type
Error
Returns:
- An object containing initialized instances.
Type: 
Promise.<Object>

(async) main()

Main function to initialize the Deliveroo client, models, and agent. It sets up event listeners for client events and runs the agent's decision-making loop. The agent updates its beliefs, generates desires, filters intentions, and acts based on the current state of the game. The loop continues until the game is terminated, allowing the agent to continuously adapt to the game environment.

(async) mainMulti()

Main function to initialize the Deliveroo client, models, and agents. It sets up event listeners for client events and runs the agents' decision-making loop. The agents update their beliefs, generate desires, filter intentions, and act based on the current state of the game. The loop continues until the game is terminated, allowing the agents to continuously adapt to the game environment.

(async) mainSinglePDDL() → {Promise.<void>}

This function initializes the application by creating instances of necessary classes, registers event handlers, waits for the application to be ready, and then starts the main planning loop. It serves as the entry point for the application, ensuring that all components are set up correctly before starting the main logic.
Throws:
- Throws an error if the application initialization or planning loop fails.
Type
Error
Returns:
- A promise that resolves when the application is fully initialized and the planning loop is running.
Type: 
Promise.<void>

makeOnDeposit(client, parcels, me) → {function}

This function returns a handler that can be used to emit a putdown action. It uses the client to emit a putdown event with the current parcels and the player's ID. This will trigger the server to handle the deposit logic for the parcels.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
parcelsParcelsStoreThe parcels store instance.
meMeThe current player instance.
Returns:
- A function that emits a putdown action with the current parcels when called.
Type: 
function

makeOnMove(client, me) → {function}

This function returns a handler that can be used to move the agent to a specified target position. It calculates the direction from the current position to the target position and uses the client to emit a move action. It also waits for the move to complete and checks if the agent has reached the target position. If the move fails or the agent does not reach the target position, it logs an error and rejects the promise.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
Throws:
- Throws an error if the direction cannot be determined or if the move fails.
Type
Error
Returns:
- A function that takes target coordinates and moves the agent.
Type: 
function

makeOnPickup(client, me) → {function}

This function returns a handler that can be used to emit a pickup action. It uses the client to emit a pickup event, which will trigger the server to handle the pickup logic.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
Returns:
- A function that emits a pickup action when called.
Type: 
function

moveAndWait(client, me, dir) → {Promise.<void>}

This function emits a move command to the Deliveroo client and waits for the player's state to update with the new position. It listens for the 'onYou' event to confirm that the move has been processed and the player's position has been updated.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
dirstringThe direction to move in (e.g., 'UP', 'DOWN', 'LEFT', 'RIGHT').
Returns:
- A promise that resolves when the move is complete.
Type: 
Promise.<void>

moveToNearestBase(client, me, mapStore) → {Promise.<boolean>}

This function finds the nearest base on the map and uses the A* search algorithm to calculate the path to that base. It then moves the agent in the direction of the first step in the path. If a valid path is found, it moves the agent and returns true. If no base is found or no valid path exists, it logs an error message and returns false.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
mapStoreMapStoreThe MapStore instance containing the current map state.
Returns:
- Returns true if successfully moved to a new base, false otherwise.
Type: 
Promise.<boolean>

(async) planWithDynamicAgents(mapStore, agentStore, me, parcels, serverConfig) → {Promise.<Array>}

This function generates a plan for the current player based on the current map state, visible agents, and parcels. It temporarily removes agents from the map to avoid interference during planning. After generating the plan, it restores the agents back to their original state on the map. If an error occurs during planning, it logs the error and returns an empty plan.
Parameters:
NameTypeDescription
mapStoreMapStoreThe MapStore instance containing the current map state.
agentStoreAgentStoreThe AgentStore instance containing the current agents state.
meMeThe current player instance.
parcelsParcelsStoreThe list of parcels to be processed.
serverConfigServerConfigThe server configuration instance.
Throws:
- Throws an error if the planning process fails.
Type
Error
Returns:
- A promise that resolves to the raw plan generated by the planner.
Type: 
Promise.<Array>

randomMoveAndBack(client, me, mapStore) → {Promise.<void>}

This function checks the surrounding tiles for walkable paths and randomly selects one to move in. After moving in the random direction, it immediately moves back to the original position. This is useful for testing movement logic or simulating random behavior in the game.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
mapStoreMapStoreThe MapStore instance containing the current map state.
Returns:
- A promise that resolves when the random move and return are complete.
Type: 
Promise.<void>

registerEventHandlers(context)

This function sets up event listeners for various events emitted by the Deliveroo client. It updates the player state, map tiles, configuration, parcels sensing, and agents sensing. It ensures that the application reacts to changes in the game state and updates the relevant models accordingly.
Parameters:
NameTypeDescription
contextObjectThe context containing initialized instances.
Properties
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
parcelsParcelsStoreThe parcels store instance.
mapStoreMapStoreThe map store instance.
agentStoreAgentStoreThe agent store instance.
serverConfigServerConfigThe server configuration instance.
Throws:
- Throws an error if the client fails to register event handlers.
Type
Error

(async) runPlanningLoop(context) → {Promise.<void>}

This function runs the main planning loop for the application. It continuously checks the game state, computes a plan using dynamic agents, and executes the plan. If no plan is found, it attempts to move towards the nearest base. It handles errors during planning and execution, ensuring that the application remains responsive and can recover from failures.
Parameters:
NameTypeDescription
contextObjectThe context containing initialized instances.
Properties
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
parcelsParcelsStoreThe parcels store instance.
mapStoreMapStoreThe map store instance.
agentStoreAgentStoreThe agent store instance.
serverConfigServerConfigThe server configuration instance.
Throws:
- Throws an error if the planning or execution fails.
Type
Error
Returns:
- A promise that resolves when the planning loop is complete.
Type: 
Promise.<void>

sanitizePddlName(raw) → {string}

This function is useful for ensuring that names used in PDDL (Planning Domain Definition Language) are valid and follow the naming conventions required by PDDL, such as using lowercase letters, numbers, and underscores, while avoiding spaces and special characters.
Parameters:
NameTypeDescription
rawstringThe raw name to sanitize.
Returns:
- The sanitized PDDL name.
Type: 
string
Example
sanitizePddlName("  My Name!  "); // returns "my_name"
sanitizePddlName("Invalid@Name#123"); // returns "invalid_name_123"
sanitizePddlName("  __Extra__Underscores__  "); // returns "extra_underscores"
sanitizePddlName("1234"); // returns "1234"
sanitizePddlName("!@#$%^&*()"); // returns ""

smartMove(client, me, target, mapStore) → {Promise.<void>}

This function calculates the path from the current position to the target position using the A* search algorithm. It then iterates through each step in the path, determines the direction to move in, and calls the `moveAndWait` function to move the agent step by step.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
targetObjectThe target position to move towards.
mapStoreMapStoreThe MapStore instance containing the current map state.
Returns:
- A promise that resolves when the movement is complete.
Type: 
Promise.<void>

smartMoveToNearestBase(client, me, mapStore) → {Promise.<void>}

This function finds the nearest base on the map and moves the agent towards it using the `smartMove` function. If a base is found, it will navigate to that base efficiently, taking into account the current map state and obstacles.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
mapStoreMapStoreThe MapStore instance containing the current map state.
Returns:
- A promise that resolves when the movement is complete.
Type: 
Promise.<void>

smartMoveToNearestBaseAndPutDown(client, me, mapStore, parcels) → {Promise.<void>}

This function finds the nearest base on the map and moves the agent towards it using the `smartMove` function. Once the agent reaches the base, it emits a put down command for all carried parcels. This is useful for efficiently delivering parcels to the nearest base, ensuring that the agent can quickly return to the delivery process.
Parameters:
NameTypeDescription
clientDeliverooClientThe Deliveroo client instance.
meMeThe current player instance.
mapStoreMapStoreThe MapStore instance containing the current map state.
parcelsParcelsStoreThe list of parcels to be put down.
Returns:
- A promise that resolves when the movement and put down action are complete.
Type: 
Promise.<void>

(async) waitForAppReady(context) → {Promise.<void>}

This function continuously checks if the player ID is set and the map size is greater than zero. It uses a polling mechanism to wait until these conditions are met before resolving the promise. This is useful to ensure that the application has all necessary data before proceeding with the main logic.
Parameters:
NameTypeDescription
contextObjectThe context containing initialized instances.
Properties
NameTypeDescription
meMeThe current player instance.
mapStoreMapStoreThe map store instance.
Throws:
- Throws an error if the application is not ready within a reasonable time.
Type
Error
Returns:
- A promise that resolves when the application is ready.
Type: 
Promise.<void>