This module provides utility functions for calculating scores related to parcel pickup in a grid-based game. It includes a function to compute the score for picking up parcels based on various parameters such as starting position, goal position, carried value, carried count, reward, pickup count, base distance, clock penalty, and map store. The score is calculated by considering the total reward, distance to the parcel, and the number of parcels involved. The function is useful for determining the optimal strategy for parcel pickup in the game.
- Source
Example
// Example usage:
import { getPickupScore } from './misc';
const startPos = { x: 1, y: 2 };
const goalPos = { x: 3, y: 4 };
const carriedValue = 100;
const carriedCount = 2;
const reward = 50;
const pickupCount = 3;
const baseDistance = 5;
const clockPenalty = 0.1;
const mapStore = new MapStore();
const configuration = new ServerConfig();
const score = getPickupScore(startPos, goalPos, carriedValue, carriedCount, reward, pickupCount, baseDistance, clockPenalty, mapStore, configuration);
console.log(score); // Outputs the calculated score for picking up parcels
Methods
(static) getPickupScore(startPos, goalPos, carriedValue, carriedCount, reward, pickupCount, baseDistance, clockPenalty, mapStore, configuration) → {number}
This function computes the score for picking up parcels by considering the total reward from carried parcels and the parcel being picked up, the distance to the parcel, and the number of parcels involved. The score is adjusted by a clock penalty based on the total distance traveled. If the base distance is not provided, it defaults to 0. The function uses the MapStore instance to calculate the distance between the start and goal positions. The score is calculated as follows: 1. Calculate the distance to the parcel using the MapStore's distance method. 2. Compute the total reward as the sum of carried value and the reward for the parcel being picked up. 3. Calculate the total distance as the sum of the distance to the parcel and the base distance. 4. Determine the total number of parcels as the sum of carried count and pickup count. 5. Finally, calculate the score as the total reward minus the product of total distance, total parcels, and clock penalty divided by the decaying interval.
Parameters:
Name | Type | Description |
---|---|---|
startPos | Object | The starting position of the player, with x and y properties. |
goalPos | Object | The goal position of the parcel, with x and y properties. |
carriedValue | number | The total value of parcels currently being carried by the player. |
carriedCount | number | The number of parcels currently being carried by the player. |
reward | number | The reward value of the parcel being picked up. |
pickupCount | number | The number of parcels to be picked up. |
baseDistance | number | The base distance to consider for the pickup. |
clockPenalty | number | The penalty applied to the score based on time. |
mapStore | MapStore | An instance of MapStore to calculate distances. |
configuration | ServerConfig | An instance of ServerConfig containing game configuration settings. |
- Source
Returns:
- The calculated score for picking up parcels.
- Type:
- number