|
|||||||||
| 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.AIPlayer
public abstract class AIPlayer
Objects of this class contains AI-information for a single Player and
is used for controlling this player.
The method startWorking() gets called by the
AIInGameInputHandler when it is this player's turn.
| Field Summary | |
|---|---|
private java.util.ArrayList<AIUnit> |
aiUnits
Temporary variable, used to hold all AIUnit objects belonging to this AI. |
private Connection |
debuggingConnection
Temporary variable, used for debugging purposes only. |
private static java.util.logging.Logger |
logger
|
private ServerPlayer |
player
The FreeColGameObject this AIObject contains AI-information for. |
| Fields inherited from class net.sf.freecol.server.ai.AIObject |
|---|
uninitialized |
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE |
| Constructor Summary | |
|---|---|
AIPlayer(AIMain aiMain,
java.lang.String id)
|
|
| Method Summary | |
|---|---|
abstract boolean |
acceptDiplomaticTrade(DiplomaticTrade agreement)
|
abstract boolean |
acceptIndianDemand(Unit unit,
Colony colony,
Goods goods,
int gold)
Decides whether to accept an Indian demand, or not. |
abstract boolean |
acceptMercenaryOffer()
Decides whether to accept a mercenary offer, or not. |
abstract boolean |
acceptTax(int tax)
Decides whether to accept the monarch's tax raise or not. |
abstract int |
buyProposition(Unit unit,
Goods goods,
int gold)
Called when another Player proposes a trade. |
protected boolean |
checkForREFDefeat()
For REF-players: Checks if we have lost the war of independence. |
protected void |
clearAIUnits()
Helper method to let implementing subclasses clear aiUnits. |
protected java.util.Iterator<AIColony> |
getAIColonyIterator()
Returns an iterator over all the AIColonys owned by this
player. |
protected java.util.Iterator<AIUnit> |
getAIUnitIterator()
Returns an iterator over all the AIUnits owned by this
player. |
Connection |
getConnection()
Gets the connection to the server. |
java.lang.String |
getId()
Returns the ID for this AIPlayer. |
Player |
getPlayer()
Returns the Player this AIPlayer is
controlling. |
abstract java.util.Iterator<TileImprovementPlan> |
getTileImprovementPlanIterator()
Returns an Iterator over all the
TileImprovements needed by all of this player's colonies. |
abstract java.util.Iterator<Wish> |
getWishIterator()
Returns an Iterator for all the wishes. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
abstract boolean |
hasFewColonies()
This is a temporary method which are used for forcing the computer players into building more colonies. |
protected abstract void |
readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
Reads information for this object from an XML stream. |
AIUnit |
recruitAIUnitInEurope(int slot)
Helper function for server communication - Ask the server to recruit a unit in Europe on behalf of the AIPlayer. |
abstract void |
registerSellGoods(Goods goods)
Called after another Player sends a trade message |
abstract void |
removeTileImprovementPlan(TileImprovementPlan plan)
Remove a TileImprovementPlan from the list |
abstract FoundingFather |
selectFoundingFather(java.util.List<FoundingFather> foundingFathers)
Selects the most useful founding father offered. |
protected void |
sendAndWaitSafely(org.w3c.dom.Element element)
Send an element and ignore IO exceptions. |
protected void |
sendUpdatedTilesToAll(java.util.ArrayList<Tile> tiles)
Send some tiles to update to all players which can see them |
void |
setDebuggingConnection(Connection debuggingConnection)
Sets the Connection to be used while communicating with
the server. |
protected void |
setPlayer(ServerPlayer p)
Sets the ServerPlayer this AIPlayer is controlling. |
abstract void |
startWorking()
Tells this AIPlayer to make decisions. |
protected abstract void |
toXMLImpl(javax.xml.stream.XMLStreamWriter out)
Writes this object to an XML stream. |
abstract int |
tradeProposition(Unit unit,
Settlement settlement,
Goods goods,
int gold)
Called when another Player proposes a trade. |
AIUnit |
trainAIUnitInEurope(UnitType unitType)
Helper function for server communication - Ask the server to train a unit in Europe on behalf of the AIPlayer. |
| Methods inherited from class net.sf.freecol.server.ai.AIObject |
|---|
dispose, getAIMain, getAIRandom, getGame, isUninitialized, readFromXML |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
private ServerPlayer player
private Connection debuggingConnection
private java.util.ArrayList<AIUnit> aiUnits
| Constructor Detail |
|---|
public AIPlayer(AIMain aiMain,
java.lang.String id)
| Method Detail |
|---|
public Player getPlayer()
Player this AIPlayer is
controlling.
Player.protected void setPlayer(ServerPlayer p)
protected void clearAIUnits()
protected java.util.Iterator<AIUnit> getAIUnitIterator()
AIUnits owned by this
player.
Iterator.protected java.util.Iterator<AIColony> getAIColonyIterator()
AIColonys owned by this
player.
Iterator.public Connection getConnection()
public void setDebuggingConnection(Connection debuggingConnection)
Connection to be used while communicating with
the server.
This method is only used for debugging.
debuggingConnection - The connection to be used for debugging.protected void sendAndWaitSafely(org.w3c.dom.Element element)
element - The element.protected void sendUpdatedTilesToAll(java.util.ArrayList<Tile> tiles)
tiles - The tiles to update.public java.lang.String getId()
AIPlayer. This is the same as the
ID for the Player this AIPlayer controls.
getId in class FreeColObjectpublic AIUnit trainAIUnitInEurope(UnitType unitType)
public AIUnit recruitAIUnitInEurope(int slot)
protected boolean checkForREFDefeat()
public abstract void startWorking()
AIPlayer to make decisions. The
AIPlayer is done doing work this turn when this method
returns.
NOTE: For the moment, any implementation of this _must_ make sure
to call checkForREFDefeat() at the start of a turn,
if the player this AI works for isREF(). See TODO at that method.
public abstract java.util.Iterator<TileImprovementPlan> getTileImprovementPlanIterator()
Iterator over all the
TileImprovements needed by all of this player's colonies.
Iterator.TileImprovementpublic abstract void removeTileImprovementPlan(TileImprovementPlan plan)
TileImprovementPlan from the list
public abstract boolean hasFewColonies()
true if the AI should build more colonies.public abstract java.util.Iterator<Wish> getWishIterator()
Iterator for all the wishes. The items are
sorted by the value, with the item having the
highest value appearing first in the Iterator.
Iterator.Wishpublic abstract FoundingFather selectFoundingFather(java.util.List<FoundingFather> foundingFathers)
foundingFathers - The founding fathers on offer.
public abstract boolean acceptTax(int tax)
tax - The new tax rate to be considered.
true if the tax raise should be accepted.
public abstract boolean acceptIndianDemand(Unit unit,
Colony colony,
Goods goods,
int gold)
unit - The unit making demands.colony - The colony where demands are being made.goods - The goods demanded.gold - The amount of gold demanded.
true if this AIPlayer accepts the
indian demand and false otherwise.public abstract boolean acceptMercenaryOffer()
true if this AIPlayer accepts the
offer and false otherwise.public abstract boolean acceptDiplomaticTrade(DiplomaticTrade agreement)
public abstract void registerSellGoods(Goods goods)
Player sends a trade message
goods - The goods which we are going to offer
public abstract int buyProposition(Unit unit,
Goods goods,
int gold)
Player proposes a trade.
unit - The foreign Unit trying to trade.goods - The goods the given Unit is trying to sell.gold - The suggested price.
AIPlayer suggests or
NetworkConstants.NO_TRADE.
public abstract int tradeProposition(Unit unit,
Settlement settlement,
Goods goods,
int gold)
Player proposes a trade.
unit - The foreign Unit trying to trade.settlement - The Settlement this player owns and
which the given Unit if trying to sell goods.goods - The goods the given Unit is trying to sell.gold - The suggested price.
AIPlayer suggests or
NetworkConstants.NO_TRADE.
protected abstract void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
throws javax.xml.stream.XMLStreamException
toXMLImpl in class FreeColObjectout - The target stream.
javax.xml.stream.XMLStreamException - if there are any problems writing to the
stream.
protected abstract void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readFromXMLImpl in class FreeColObjectin - The input stream with the XML.
javax.xml.stream.XMLStreamException - if there are any problems reading from the
stream.public static java.lang.String getXMLElementTagName()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||