net.sf.freecol.server.ai
Class AIPlayer

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
Direct Known Subclasses:
ColonialAIPlayer, StandardAIPlayer

public abstract 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
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
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.
 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.
 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.
 void setDebuggingConnection(Connection debuggingConnection)
          Sets the Connection to be used while communicating with the server.
abstract  void startWorking()
          Tells this AIPlayer to make decisions.
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, 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

AIPlayer

public AIPlayer(AIMain aiMain,
                java.lang.String id)
Method Detail

getPlayer

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

Returns:
The Player.

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.

Overrides:
getId in class FreeColObject
Returns:
The ID.

trainAIUnitInEurope

public AIUnit trainAIUnitInEurope(UnitType unitType)
Helper function for server communication - Ask the server to train a unit in Europe on behalf of the AIPlayer. TODO: Move this to a specialized Handler class (AIEurope?) TODO: Give protected access?

Returns:
the new AIUnit created by this action. May be null.

recruitAIUnitInEurope

public AIUnit recruitAIUnitInEurope(int slot)
Helper function for server communication - Ask the server to recruit a unit in Europe on behalf of the AIPlayer. TODO: Move this to a specialized Handler class (AIEurope?) TODO: Give protected access?

Returns:
the new AIUnit created by this action. May be null.

startWorking

public abstract void startWorking()
Tells this 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.


getTileImprovementPlanIterator

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

Returns:
The Iterator.
See Also:
TileImprovement

removeTileImprovementPlan

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


hasFewColonies

public abstract 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.

Returns:
true if the AI should build more colonies.

getWishIterator

public abstract 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 abstract FoundingFather selectFoundingFather(java.util.List<FoundingFather> foundingFathers)
Selects the most useful founding father offered.

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

acceptTax

public abstract 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 abstract 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.

acceptMercenaryOffer

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

Returns:
true if this AIPlayer accepts the offer and false otherwise.

acceptDiplomaticTrade

public abstract boolean acceptDiplomaticTrade(DiplomaticTrade agreement)

registerSellGoods

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

Parameters:
goods - The goods which we are going to offer

buyProposition

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

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 abstract 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.

getXMLElementTagName

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

Returns:
the tag name.