- 1 :
/**
- 2 :
* Base class for representing a goal evaluator in context of Goal-driven agent design.
- 3 :
*
- 4 :
* @author {@link https://github.com/Mugen87|Mugen87}
- 5 :
*/
- 6 :
class GoalEvaluator {
- 7 :
- 8 :
/**
- 9 :
* Constructs a new goal evaluator.
- 10 :
*
- 11 :
* @param {Number} characterBias - Can be used to adjust the preferences of agents.
- 12 :
*/
- 13 :
constructor( characterBias = 1 ) {
- 14 :
- 15 :
/**
- 16 :
* Can be used to adjust the preferences of agents. When the desirability score
- 17 :
* for a goal has been evaluated, it is multiplied by this value.
- 18 :
* @type {Number}
- 19 :
* @default 1
- 20 :
*/
- 21 :
this.characterBias = characterBias;
- 22 :
- 23 :
}
- 24 :
- 25 :
/**
- 26 :
* Calculates the desirability. It's a score between 0 and 1 representing the desirability
- 27 :
* of a goal. This goal is considered as a top level strategy of the agent like *Explore* or
- 28 :
* *AttackTarget*. Must be implemented by all concrete goal evaluators.
- 29 :
*
- 30 :
* @param {GameEntity} owner - The owner of this goal evaluator.
- 31 :
* @return {Number} The desirability.
- 32 :
*/
- 33 :
calculateDesirability( /* owner */ ) {
- 34 :
- 35 :
return 0;
- 36 :
- 37 :
}
- 38 :
- 39 :
/**
- 40 :
* Executed if this goal evaluator produces the highest desirability. Must be implemented
- 41 :
* by all concrete goal evaluators.
- 42 :
*
- 43 :
* @param {GameEntity} owner - The owner of this goal evaluator.
- 44 :
*/
- 45 :
setGoal( /* owner */ ) {}
- 46 :
- 47 :
/**
- 48 :
* Transforms this instance into a JSON object.
- 49 :
*
- 50 :
* @return {Object} The JSON object.
- 51 :
*/
- 52 :
toJSON() {
- 53 :
- 54 :
return {
- 55 :
type: this.constructor.name,
- 56 :
characterBias: this.characterBias
- 57 :
};
- 58 :
- 59 :
}
- 60 :
- 61 :
/**
- 62 :
* Restores this instance from the given JSON object.
- 63 :
*
- 64 :
* @param {Object} json - The JSON object.
- 65 :
* @return {GoalEvaluator} A reference to this goal evaluator.
- 66 :
*/
- 67 :
fromJSON( json ) {
- 68 :
- 69 :
this.characterBias = json.characterBias;
- 70 :
- 71 :
return this;
- 72 :
- 73 :
}
- 74 :
- 75 :
}
- 76 :
- 77 :
- 78 :
- 79 :
export { GoalEvaluator };