Parcel

Parcel class to represent a parcel in the game

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:
NameTypeDescription
parcelObjectThe parcel object containing id, carriedBy, x, y, reward
mapStoreMapStoreThe MapStore instance containing the bases
framenumberThe current frame number
parcelStoreParcelsStoreThe ParcelStore instance managing parcels
Properties
NameTypeDescription
idstringThe unique identifier of the parcel.
carriedBystring | nullThe ID of the agent currently carrying the parcel, or null if not carried.
xnumberThe x-coordinate of the parcel's position.
ynumberThe y-coordinate of the parcel's position.
rewardnumberThe reward value of the parcel.
baseDistancenumberThe distance to the nearest base for this parcel.
lastSeennumberThe frame number when the parcel was last seen.
existingProbnumberThe survival probability of the parcel based on the last seen frame and agent count.
nearestBaseObject | nullThe coordinates of the nearest base to the parcel, or null if not applicable.
potentialPickUpRewardnumberThe potential reward for picking up the parcel (for master instance).
potentialPickUpRewardSlavenumberThe potential reward for picking up the parcel (for slave instance).

Classes

Parcel

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:
NameTypeDescription
mapStoreMapStoreThe MapStore instance containing the bases
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:
NameTypeDescription
agentPosObjectThe position of the agent attempting to pick up the parcel
isMasterbooleanWhether the current instance is the master instance
carriedValuenumberThe total value of parcels currently carried by the agent
carriedCountnumberThe number of parcels currently carried by the agent
mapStoreMapStoreThe MapStore instance containing the game map
clockPenaltynumberThe clock penalty applied to the reward calculation
configServerConfigThe server configuration settings

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:
NameTypeDescription
currentFramenumberThe current frame number
agentCountnumberThe number of agents in the game
Example
// Example usage:
const parcel = new Parcel(parcelData, mapStore, currentFrame, parcelStore);
parcel.calculateSurvivalProbability(currentFrame, agentCount);