Constructor
new DeliverooClient(isMaster)
This class is used to send and receive events related to the game. It allows the agent to move, pick up parcels, drop off parcels, and receive updates about the game state. It is typically used at the start of the game to set up the client with the agent's ID and to listen for events from the server.
Parameters:
Name | Type | Description |
---|---|---|
isMaster | boolean | Indicates whether this client is the master or slave. |
Example
const client = new DeliverooClient(true);
Methods
emitMove()
This method is used to move the agent in the specified direction. It emits a move event to the server, which updates the agent's position on the map.
emitPickup()
This method is used to emit a pickup event for the agent. It is typically called when the agent is on a tile with a parcel and wants to pick it up. The server will then update the agent's state to reflect that it is carrying the parcel.
(async) emitPutdown(parcelStore, id) → {Promise.<void>}
This method is used to put down parcels at the agent's current location. It emits a putdown event to the server and removes all parcels carried by the agent from the parcel store. It is typically called when the agent reaches a base tile and needs to drop off parcels.
Parameters:
Name | Type | Description |
---|---|---|
parcelStore | ParcelsStore | The store containing parcels. |
id | string | The ID of the parcel to put down. |
Returns:
- A promise that resolves when the putdown event is emitted.
- Type:
- Promise.<void>
onAgentsSensing()
This method is used to listen for updates on agents in the game. It allows the agent to receive updates about the state of other agents, including their positions and actions.
onConfig()
This method is used to listen for configuration updates from the server. It allows the agent to receive updates about the game configuration, such as the map size and other settings.
onMap()
This method is used to listen for map updates from the server. It allows the agent to receive updates about the game map, including the positions of parcels and bases.
onParcelsSensing()
This method is used to listen for updates on parcels in the game. It allows the agent to receive updates about the state of parcels, including their positions and whether they have been picked up or delivered.
onTile()
This method is used to emit a drop event for the agent. It is typically called when the agent is on a tile with a base and wants to drop off parcels. The server will then update the agent's state to reflect that it has dropped off the parcels.
onYou(callback)
This method is used to set up the client with the agent's ID. It is typically called at the start of the game to ensure the client is ready to send and receive events.
Parameters:
Name | Type | Description |
---|---|---|
callback | * | The callback function to be called when the agent's ID is received. |