net.sf.freecol.server.ai
Class AIPlayer

java.lang.Object
  extended by net.sf.freecol.server.ai.AIObject
      extended by net.sf.freecol.server.ai.AIPlayer

public class AIPlayer
extends AIObject

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
static java.lang.String COPYRIGHT
           
static java.lang.String LICENSE
           
static java.lang.String REVISION
           
static int STRATEGY_CONQUEST
           
static int STRATEGY_COOPERATION
           
static int STRATEGY_IMMIGRATION
           
static int STRATEGY_NONE
           
static int STRATEGY_TRADE
           
 
Fields inherited from class net.sf.freecol.server.ai.AIObject
id, uninitialized
 
Constructor Summary
AIPlayer(AIMain aiMain, org.w3c.dom.Element element)
          Creates a new AIPlayer and reads the information from the given Element.
AIPlayer(AIMain aiMain, ServerPlayer player)
          Creates a new AIPlayer.
AIPlayer(AIMain aiMain, javax.xml.stream.XMLStreamReader in)
          Creates a new AIPlayer.
 
Method Summary
 boolean acceptIndianDemand(Unit unit, Colony colony, Goods goods, int gold)
          Decides whether to accept an Indian demand, or not.
 boolean acceptTax(int tax)
          Decides whether to accept the monarch's tax raise or not.
 java.util.Iterator<AIColony> getAIColonyIterator()
          Returns an iterator over all the AIColonys owned by this player.
 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.
 int getStrategy()
          Returns the strategy of this AIPlayer.
 java.util.Iterator<TileImprovement> getTileImprovementIterator()
          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.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Reads information for this object from an XML stream.
 int selectFoundingFather(int[] foundingFathers)
          Selects the most useful founding father offered.
 void setDebuggingConnection(Connection debuggingConnection)
          Sets the Connection to be used while communicating with the server.
 void startWorking()
          Tells this AIPlayer to make decisions.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          Writes this object to an XML stream.
 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.AIObject
dispose, getAIMain, getGame, getRandom, isUninitialized, readFromXML, readFromXMLElement, toXML, toXMLElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

LICENSE

public static final java.lang.String LICENSE
See Also:
Constant Field Values

REVISION

public static final java.lang.String REVISION
See Also:
Constant Field Values

STRATEGY_NONE

public static final int STRATEGY_NONE
See Also:
Constant Field Values

STRATEGY_TRADE

public static final int STRATEGY_TRADE
See Also:
Constant Field Values

STRATEGY_IMMIGRATION

public static final int STRATEGY_IMMIGRATION
See Also:
Constant Field Values

STRATEGY_COOPERATION

public static final int STRATEGY_COOPERATION
See Also:
Constant Field Values

STRATEGY_CONQUEST

public static final int STRATEGY_CONQUEST
See Also:
Constant Field Values
Constructor Detail

AIPlayer

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

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

AIPlayer

public AIPlayer(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.

AIPlayer

public AIPlayer(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.


getTileImprovementIterator

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

Returns:
The Iterator.
See Also:
TileImprovement

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 wether a colony should be built or not has been implemented.

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.

Returns:
The Iterator.
See Also:
Wish

selectFoundingFather

public int selectFoundingFather(int[] foundingFathers)
Selects the most useful founding father offered.

Parameters:
foundingFathers - The founding fathers on offer.
Returns:
The founding father selected.

tradeProposition

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

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.

acceptTax

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

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.

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.

getAIUnitIterator

public java.util.Iterator<AIUnit> getAIUnitIterator()
Returns an iterator over all the AIUnits owned by this player.

Returns:
The Iterator.

getAIColonyIterator

public java.util.Iterator<AIColony> getAIColonyIterator()
Returns an iterator over all the AIColonys owned by this player.

Returns:
The Iterator.

getPlayer

public Player getPlayer()
Returns the Player this AIPlayer is controlling.

Returns:
The Player.

getStrategy

public int getStrategy()
Returns the strategy of this AIPlayer.

Returns:
the strategy of this AIPlayer.

getConnection

public Connection getConnection()
Gets the connection to the server.

Returns:
The connection that can be used when communication with the server.

setDebuggingConnection

public void setDebuggingConnection(Connection debuggingConnection)
Sets the Connection to be used while communicating with the server. This method is only used for debugging.

Parameters:
debuggingConnection - The connection to be used for debugging.

getID

public java.lang.String getID()
Returns the ID for this AIPlayer. This is the same as the ID for the Player this AIPlayer controls.

Specified by:
getID in class AIObject
Returns:
The ID.

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
Writes this object to an XML stream.

Specified by:
toXMLImpl in class AIObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Reads information for this object from an XML stream.

Specified by:
readFromXMLImpl in class AIObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems reading from the stream.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Returns the tag name of the root element representing this object.

Returns:
the tag name.