Constructor
new Parcel(parcel, mapStore, frame, parcelStore)
This class is used to represent a parcel in the game. It contains properties such as id, carriedBy, x, y, reward, baseDistance, lastSeen, existingProb, nearestBase, potentialPickUpReward, and potentialPickUpRewardSlave
Parameters:
PropertiesName | Type | Description |
---|---|---|
parcel | Object | The parcel object containing id, carriedBy, x, y, reward |
mapStore | MapStore | The MapStore instance containing the bases |
frame | number | The current frame number |
parcelStore | ParcelsStore | The ParcelStore instance managing parcels |
Name | Type | Description |
---|---|---|
id | string | The unique identifier of the parcel. |
carriedBy | string | | The ID of the agent currently carrying the parcel, or null if not carried. |
x | number | The x-coordinate of the parcel's position. |
y | number | The y-coordinate of the parcel's position. |
reward | number | The reward value of the parcel. |
baseDistance | number | The distance to the nearest base for this parcel. |
lastSeen | number | The frame number when the parcel was last seen. |
existingProb | number | The survival probability of the parcel based on the last seen frame and agent count. |
nearestBase | Object | | The coordinates of the nearest base to the parcel, or null if not applicable. |
potentialPickUpReward | number | The potential reward for picking up the parcel (for master instance). |
potentialPickUpRewardSlave | number | The potential reward for picking up the parcel (for slave instance). |
- Source
Classes
Methods
calculateNearestBase(mapStore) → {void}
This method calculates the nearest base to the parcel and updates the baseDistance and nearestBase properties. It uses the nearestBase method from the MapStore to find the closest base and its distance. If no base is found, the baseDistance remains Infinity and nearestBase is null.
Parameters:
Name | Type | Description |
---|---|---|
mapStore | MapStore | The MapStore instance containing the bases |
- Source
Returns:
- Type:
- void
calculatePotentialPickUpReward(agentPos, isMaster, carriedValue, carriedCount, mapStore, clockPenalty, config)
This method calculates the potential pickup reward for a parcel based on its position, carried value, and other parameters. It updates the potentialPickUpReward or potentialPickUpRewardSlave property based on whether it is called from the master or slave instance.
Parameters:
Name | Type | Description |
---|---|---|
agentPos | Object | The position of the agent attempting to pick up the parcel |
isMaster | boolean | Whether the current instance is the master instance |
carriedValue | number | The total value of parcels currently carried by the agent |
carriedCount | number | The number of parcels currently carried by the agent |
mapStore | MapStore | The MapStore instance containing the game map |
clockPenalty | number | The clock penalty applied to the reward calculation |
config | ServerConfig | The server configuration settings |
- Source
calculateSurvivalProbability(currentFrame, agentCount)
This method calculates the survival probability of the parcel based on the time since it was last seen and the number of agents. The probability decreases exponentially with time and increases with the number of agents.
Parameters:
Name | Type | Description |
---|---|---|
currentFrame | number | The current frame number |
agentCount | number | The number of agents in the game |
- Source
Example
// Example usage:
const parcel = new Parcel(parcelData, mapStore, currentFrame, parcelStore);
parcel.calculateSurvivalProbability(currentFrame, agentCount);