net.sf.freecol.server.ai
Class StandardAIPlayer

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.server.ai.AIObject
          extended by net.sf.freecol.server.ai.AIPlayer
              extended by net.sf.freecol.server.ai.StandardAIPlayer

public class StandardAIPlayer
extends 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
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
StandardAIPlayer(AIMain aiMain, org.w3c.dom.Element element)
          Creates a new AIPlayer and reads the information from the given Element.
StandardAIPlayer(AIMain aiMain, ServerPlayer player)
          Creates a new AIPlayer.
StandardAIPlayer(AIMain aiMain, javax.xml.stream.XMLStreamReader in)
          Creates a new AIPlayer.
 
Method Summary
 boolean acceptDiplomaticTrade(DiplomaticTrade agreement)
           
 boolean acceptIndianDemand(Unit unit, Colony colony, Goods goods, int gold)
          Decides whether to accept an Indian demand, or not.
 boolean acceptMercenaryOffer()
          Decides whether to accept a mercenary offer, or not.
 boolean acceptTax(int tax)
          Decides whether to accept the monarch's tax raise or not.
 int buyProposition(Unit unit, Goods goods, int gold)
          Called when another Player proposes a trade.
 java.util.Iterator<TileImprovementPlan> getTileImprovementPlanIterator()
          Returns an Iterator over all the TileImprovements needed by all of this player's colonies.
 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.
 boolean hasFewColonies()
          This is a temporary method which are used for forcing the computer players into building more colonies.
 void registerSellGoods(Goods goods)
          Called after another Player sends a trade message
 void removeTileImprovementPlan(TileImprovementPlan plan)
          Remove a TileImprovementPlan from the list
 FoundingFather selectFoundingFather(java.util.List<FoundingFather> foundingFathers)
          Selects the most useful founding father offered.
 void startWorking()
          Tells this AIPlayer to make decisions.
 int tradeProposition(Unit unit, Settlement settlement, Goods goods, int gold)
          Called when another Player proposes a trade.
 
Methods inherited from class net.sf.freecol.server.ai.AIPlayer
getConnection, getId, getPlayer, recruitAIUnitInEurope, setDebuggingConnection, trainAIUnitInEurope
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
dispose, getAIMain, getGame, isUninitialized, readFromXML
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardAIPlayer

public StandardAIPlayer(AIMain aiMain,
                        ServerPlayer player)
Creates a new AIPlayer.

Parameters:
aiMain - The main AI-class.
player - The player that should be associated with this AIPlayer.

StandardAIPlayer

public StandardAIPlayer(AIMain aiMain,
                        org.w3c.dom.Element element)
Creates a new AIPlayer and reads the information from the given Element.

Parameters:
aiMain - The main AI-class.
element - The XML-element containing information.

StandardAIPlayer

public StandardAIPlayer(AIMain aiMain,
                        javax.xml.stream.XMLStreamReader in)
                 throws javax.xml.stream.XMLStreamException
Creates a new AIPlayer.

Parameters:
aiMain - The main AI-object.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
Method Detail

startWorking

public void startWorking()
Tells this AIPlayer to make decisions. The AIPlayer is done doing work this turn when this method returns.

Specified by:
startWorking in class AIPlayer

getTileImprovementPlanIterator

public java.util.Iterator<TileImprovementPlan> getTileImprovementPlanIterator()
Returns an Iterator over all the TileImprovements needed by all of this player's colonies.

Specified by:
getTileImprovementPlanIterator in class AIPlayer
Returns:
The Iterator.
See Also:
TileImprovement

removeTileImprovementPlan

public void removeTileImprovementPlan(TileImprovementPlan plan)
Remove a TileImprovementPlan from the list

Specified by:
removeTileImprovementPlan in class AIPlayer

hasFewColonies

public boolean hasFewColonies()
This is a temporary method which are used for forcing the computer players into building more colonies. The method will be removed after the proper code for deciding whether a colony should be built or not has been implemented.

Specified by:
hasFewColonies in class AIPlayer
Returns:
true if the AI should build more colonies.

getWishIterator

public java.util.Iterator<Wish> getWishIterator()
Returns an Iterator for all the wishes. The items are sorted by the value, with the item having the highest value appearing first in the Iterator.

Specified by:
getWishIterator in class AIPlayer
Returns:
The Iterator.
See Also:
Wish

selectFoundingFather

public FoundingFather selectFoundingFather(java.util.List<FoundingFather> foundingFathers)
Selects the most useful founding father offered.

Specified by:
selectFoundingFather in class AIPlayer
Parameters:
foundingFathers - The founding fathers on offer.
Returns:
The founding father selected.

acceptTax

public boolean acceptTax(int tax)
Decides whether to accept the monarch's tax raise or not.

Specified by:
acceptTax in class AIPlayer
Parameters:
tax - The new tax rate to be considered.
Returns:
true if the tax raise should be accepted.

acceptIndianDemand

public boolean acceptIndianDemand(Unit unit,
                                  Colony colony,
                                  Goods goods,
                                  int gold)
Decides whether to accept an Indian demand, or not.

Specified by:
acceptIndianDemand in class AIPlayer
Parameters:
unit - The unit making demands.
colony - The colony where demands are being made.
goods - The goods demanded.
gold - The amount of gold demanded.
Returns:
true if this AIPlayer accepts the indian demand and false otherwise.

acceptMercenaryOffer

public boolean acceptMercenaryOffer()
Decides whether to accept a mercenary offer, or not.

Specified by:
acceptMercenaryOffer in class AIPlayer
Returns:
true if this AIPlayer accepts the offer and false otherwise.

acceptDiplomaticTrade

public boolean acceptDiplomaticTrade(DiplomaticTrade agreement)
Specified by:
acceptDiplomaticTrade in class AIPlayer

registerSellGoods

public void registerSellGoods(Goods goods)
Called after another Player sends a trade message

Specified by:
registerSellGoods in class AIPlayer
Parameters:
goods - The goods which we are going to offer

buyProposition

public int buyProposition(Unit unit,
                          Goods goods,
                          int gold)
Called when another Player proposes a trade.

Specified by:
buyProposition in class AIPlayer
Parameters:
unit - The foreign Unit trying to trade.
goods - The goods the given Unit is trying to sell.
gold - The suggested price.
Returns:
The price this AIPlayer suggests or NetworkConstants.NO_TRADE.

tradeProposition

public int tradeProposition(Unit unit,
                            Settlement settlement,
                            Goods goods,
                            int gold)
Called when another Player proposes a trade.

Specified by:
tradeProposition in class AIPlayer
Parameters:
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.
Returns:
The price this AIPlayer suggests or NetworkConstants.NO_TRADE.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Returns the tag name of the root element representing this object. ATTN: For compatibility, this has the same tag name as its super class, the previous implementation of all AIPlayers. Eventually change this at some point.

Returns:
the tag name.