Think(owner)

Class for representing the brain of a game entity.

new Think(owner)

Constructs a new Think object.

Parameters:
Name Type Default Description
owner GameEntity null

The owner of this instance.

Author:

Extends

Members

evaluators :Array.<GoalEvaluator>

A list of goal evaluators.

nullable owner :GameEntity

The owner of this goal.

Overrides:
Default Value:
  • null

status :Status

The status of this goal.

Overrides:
Default Value:
  • INACTIVE

subgoals :Array.<Goal>

A list of subgoals.

Overrides:

Methods

activate()

Executed when this goal is activated.

Overrides:

activateIfInactive() → {Goal}

Ensures the goal is activated if it is inactive.

Returns:
Goal -

A reference to this goal.

Overrides:

active() → {Boolean}

Returns true if the status of this goal is ACTIVE.

Returns:
Boolean -

Whether the goal is active or not.

Overrides:

addEvaluator(evaluator) → {Think}

Adds the given goal evaluator to this instance.

Parameters:
Name Type Description
evaluator GoalEvaluator

The goal evaluator to add.

Returns:
Think -

A reference to this instance.

addSubgoal(goal) → {Goal}

Adds a goal as a subgoal to this instance.

Parameters:
Name Type Description
goal Goal

The subgoal to add.

Returns:
Goal -

A reference to this goal.

Overrides:

arbitrate() → {Think}

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.

Returns:
Think -

A reference to this instance.

clearSubgoals() → {Goal}

Removes all subgoals and ensures Goal#terminate is called for each subgoal.

Returns:
Goal -

A reference to this goal.

Overrides:

completed() → {Boolean}

Returns true if the status of this goal is COMPLETED.

Returns:
Boolean -

Whether the goal is completed or not.

Overrides:

currentSubgoal() → {Goal}

Returns the current subgoal. If no subgoals are defined, null is returned.

Returns:
Goal -

The current subgoal.

Overrides:

execute()

Executed in each simulation step.

Overrides:

executeSubgoals() → {Status}

Executes the current subgoal of this composite goal.

Returns:
Status -

The status of this composite subgoal.

Overrides:

failed() → {Boolean}

Returns true if the status of this goal is FAILED.

Returns:
Boolean -

Whether the goal is failed or not.

Overrides:

fromJSON(json) → {Think}

Restores this instance from the given JSON object.

Parameters:
Name Type Description
json Object

The JSON object.

Returns:
Think -

A reference to this instance.

Overrides:

handleMessage() → {Boolean}

Returns true if the given message was processed by the current subgoal.

Returns:
Boolean -

Whether the message was processed or not.

Overrides:

hasSubgoals() → {Boolean}

Returns true if this composite goal has subgoals.

Returns:
Boolean -

Whether the composite goal has subgoals or not.

Overrides:

inactive() → {Boolean}

Returns true if the status of this goal is INACTIVE.

Returns:
Boolean -

Whether the goal is inactive or not.

Overrides:

registerType(type, constructor) → {Think}

Registers a custom type for deserialization. When calling Think#fromJSON this instance is able to pick the correct constructor in order to create custom goals or goal evaluators.

Parameters:
Name Type Description
type String

The name of the goal or goal evaluator.

constructor function

The constructor function.

Returns:
Think -

A reference to this instance.

removeEvaluator(evaluator) → {Think}

Removes the given goal evaluator from this instance.

Parameters:
Name Type Description
evaluator GoalEvaluator

The goal evaluator to remove.

Returns:
Think -

A reference to this instance.

removeSubgoal(goal) → {Goal}

Removes a subgoal from this instance.

Parameters:
Name Type Description
goal Goal

The subgoal to remove.

Returns:
Goal -

A reference to this goal.

Overrides:

replanIfFailed() → {Goal}

Ensures the goal is replanned if it has failed.

Returns:
Goal -

A reference to this goal.

Overrides:

resolveReferences(entities) → {CompositeGoal}

Restores UUIDs with references to GameEntity objects.

Parameters:
Name Type Description
entities Map.<String, GameEntity>

Maps game entities to UUIDs.

Returns:
CompositeGoal -

A reference to this composite goal.

Overrides:

terminate()

Executed when this goal is satisfied.

Overrides:

toJSON() → {Object}

Transforms this instance into a JSON object.

Returns:
Object -

The JSON object.

Overrides: