arbitrate method

Think arbitrate()

This method represents the top level decision process of an agent. It iterates through each goal evaluator and selects the one that has the highest score as the current goal.

Implementation

Think arbitrate() {
	final evaluators = this.evaluators;

	double bestDesirability = - 1;
	GoalEvaluator? bestEvaluator;

	// try to find the best top-level goal/strategy for the entity
	for ( int i = 0, l = evaluators.length; i < l; i ++ ) {
		final evaluator = evaluators[ i ];

		double desirability = evaluator.calculateDesirability( owner! );
		desirability *= evaluator.characterBias;

		if ( desirability >= bestDesirability ) {
			bestDesirability = desirability;
			bestEvaluator = evaluator;
		}
	}

	// use the evaluator to set the respective goal
	if ( bestEvaluator != null ) {
		bestEvaluator.setGoal( owner! );
	}
    else {
		yukaConsole.error( 'YUKA.Think: Unable to determine goal evaluator for game entity: $owner');
	}

	return this;
}