|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.server.ai.AIObject
net.sf.freecol.server.ai.goal.Goal
public abstract class Goal
A Goal is used to encapsulate a specific part of the decision-making process of an AI.
Using a top-down approach, every AIPlayer
has a set of Goals which,
in turn, may have further subgoals. In combination, this tree of goals
and subgoals reflects the current strategy of the AIPlayer.
Units (each one wrapped in an AIUnit
object) will be moved between
existing Goal objects.
TODO: Turn AIUnit
into a simple wrapper for individual units.
Specific AI goals are created by extending this class; some of these could also be used to assist the human player (i.e. GoTo, Scouting, Trade, Piracy).
Field Summary |
---|
Fields inherited from class net.sf.freecol.common.model.FreeColObject |
---|
ID_ATTRIBUTE_TAG |
Fields inherited from interface net.sf.freecol.server.ai.goal.GoalConstants |
---|
MAX_SEARCH_RADIUS |
Constructor Summary | |
---|---|
Goal(AIPlayer p,
Goal g,
float w)
Standard constructor |
|
Goal(AIPlayer p,
Goal g,
float w,
AIUnit u)
Alternate constructor - directly add a unit to this Goal. |
Method Summary | |
---|---|
void |
addUnit(AIUnit u)
Adds a unit to this goal. |
java.util.List<AIUnit> |
cancelGoal()
Cancels a goal and all of its subgoals. |
boolean |
canYieldUnit(UnitType ut,
AIObject o)
Used by a parent goal to check whether this goal, including subgoals, can yield a specific unit. |
void |
doPlanning()
Recursively calls doPlanning() in subgoals that needsPlanning() ,
then calls its own planning method. |
float |
getAbsoluteWeight()
Returns the absolute weight of this goal. |
java.lang.String |
getDebugDescription()
Build and return a string describing this goal including its parent goal. |
java.lang.String |
getGoalDescription()
Returns a string describing just this goal. |
float |
getParentWeight()
Gets the weight of the parent goal, or 1 if there is no parent goal. |
float |
getWeight()
Returns the relativeWeight this goal has been weighted with by its parent. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
float |
getYieldedUnitWeight(UnitType ut,
AIObject o)
Returns the absolute weight of the unit which would be yielded by yieldUnit(UnitType,AIObject) . |
boolean |
isFinished()
Determines whether this goal is finished. |
boolean |
needsPlanning()
Determines whether this or a subgoal needsPlanning . |
void |
normalizeSubGoalWeights()
Calling this ensures that the relative weights given to subgoals add up to 1. |
void |
setNeedsPlanningRecursive(boolean p)
Sets the needsPlanning status of this Goal and all its subgoals. |
void |
setWeight(float w)
Sets a relative weight for this goal. |
AIUnit |
yieldUnit(UnitType ut,
AIObject o)
Removes a unit from the goal, potentially from a subgoal, and yields it to the caller. |
Methods inherited from class net.sf.freecol.server.ai.AIObject |
---|
dispose, getAIMain, getGame, isUninitialized, readFromXML |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Goal(AIPlayer p, Goal g, float w)
p
- The AIPlayer
this goal belongs tog
- The parent goal; may be null if we're a direct goal of the AIPlayerw
- The relativeWeight of this goalpublic Goal(AIPlayer p, Goal g, float w, AIUnit u)
p
- The AIPlayer
this goal belongs tog
- The parent goal; may be null if we're a direct goal of the AIPlayerw
- The relativeWeight of this goalu
- An initial AIUnit
given to this goalMethod Detail |
---|
public boolean isFinished()
public java.util.List<AIUnit> cancelGoal()
NOTE: Preferably, only the direct parent should call this.
AIUnit
being freed up by this actionpublic void doPlanning()
doPlanning()
in subgoals that needsPlanning()
,
then calls its own planning method.
public boolean needsPlanning()
needsPlanning
.
public void setNeedsPlanningRecursive(boolean p)
needsPlanning
status of this Goal and all its subgoals.
Should be called by the AIPlayer
once for each of its subgoals
at the start of a turn. The Goal will handle all other instances of this
flag needing to be reset internally.
p
- Boolean determining whether to set needsPlanning =true or =falsepublic float getWeight()
NOTE: In many cases, you will want to use getAbsoluteWeight()
instead.
relativeWeight
of this goalpublic float getParentWeight()
public float getAbsoluteWeight()
The absolute weight is the weight of this goal in relation to the AIPlayer
.
This is used when making requests, to allow the AIPlayer to find the
"most important" request.
public void setWeight(float w)
w
- A relative weight, should be in range [0;1]public void normalizeSubGoalWeights()
NOTE: This allows for a small margin of error (+/- 0.05), to avoid recalculating too often.
public void addUnit(AIUnit u)
AIPlayer
fulfilling a unit request,
by the parent goal, or by a subgoal that no longer needs the unit.
Possible TODO: If the unit we're requesting is a high-interest one,
such as a Galleon, AIUnit#setLoaningGoal()
may be used to
signal that this unit may _only_ be moved to subgoals, or back to
AIPlayer
, but not further up the hierarchy or to any other requesting Goal.
u
- The AIUnit
being added to this goalpublic boolean canYieldUnit(UnitType ut, AIObject o)
This recursively checks its subgoals, if there's no match among the own units.
Possible TODO: Check whether AIUnit#isOnLoan()
- in which case, we mustn't
yield a unit unless it's the AIPlayer
that requests.
ut
- The UnitType
wanted by the parento
- The AIObject
(should be AIPlayer or another Goal) calling this
UnitType
, false otherwisepublic float getYieldedUnitWeight(UnitType ut, AIObject o)
yieldUnit(UnitType,AIObject)
.
This is the same as getAbsoluteWeight()
of the yielding goal.
ut
- The UnitType
wanted by the parento
- The AIObject
(should be AIPlayer or another Goal) calling this
canYieldUnit(UnitType,AIObject)
first,
or is responsible to sanitize this result itself before trying
to yieldUnit(UnitType,AIObject)
based on it.public AIUnit yieldUnit(UnitType ut, AIObject o)
Returned unit should be the one with minimum absolute weight,
see getYieldedUnitWeight(UnitType,AIObject)
.
ut
- The UnitType
wanted by the parento
- The AIObject
(should be AIPlayer or another Goal) calling this
AIUnit
with minimal absolute weight.
Note that this may be null if no matching unit is found!public java.lang.String getGoalDescription()
getDebugDescription
.
public java.lang.String getDebugDescription()
public static java.lang.String getXMLElementTagName()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |