games.strategy.triplea.baseAI
Class AbstractAI

java.lang.Object
  extended by games.strategy.triplea.baseAI.AbstractAI
All Implemented Interfaces:
IRemote, ITripleaPlayer
Direct Known Subclasses:
StrongAI, WeakAI

public abstract class AbstractAI
extends java.lang.Object
implements ITripleaPlayer

Base class for ais.

Control pausing with the AI pause menu option AI's should note that any data that is stored in the ai instance, will be lost when the game is restarted. We cannot save data with an AI, since the player may choose to restart the game with a different ai, or with a human player.

If an ai finds itself starting in the middle of a move phase, or the middle of a purchase phase, (as would happen if a player saved the game during the middle of an AI's move phase) it is acceptable for the ai to play badly for a turn, but the ai should recover, and play correctly when the next phase of the game starts.

Author:
sgb

Constructor Summary
AbstractAI(java.lang.String name)
           
 
Method Summary
protected  void battle(IBattleDelegate battleDelegate, GameData data, PlayerID player)
          It is the AI's turn to fight.
 void battleInfoMessage(java.lang.String shortMessage, DiceRoll dice)
          The following methods are more for the ui, and the ai will generally not care
 void confirmEnemyCasualties(GUID battleId, java.lang.String message, PlayerID hitPlayer)
          Allows the user to pause and confirm enemy casualties
 boolean confirmMoveHariKari()
          The attempted move will kill some units
 boolean confirmMoveKamikaze()
          The attempted move will kill some air units
 void confirmOwnCasualties(GUID battleId, java.lang.String message)
           
protected  GameData getGameData()
          Get the GameData for the game.
 PlayerID getID()
           
 java.lang.String getName()
           
protected  IPlayerBridge getPlayerBridge()
          Get the IPlayerBridge for this game player.
 java.lang.Class<ITripleaPlayer> getRemotePlayerType()
           
protected  PlayerID getWhoAmI()
          What player are we playing.
 void initialize(IPlayerBridge bridge, PlayerID id)
           
protected abstract  void move(boolean nonCombat, IMoveDelegate moveDel, GameData data, PlayerID player)
          It is the AI's turn to move.
protected  void pause()
          Pause the game to allow the human player to see what is going on.
protected abstract  void place(boolean placeForBid, IAbstractPlaceDelegate placeDelegate, GameData data, PlayerID player)
          It is the AI's turn to place units.
protected abstract  void purchase(boolean purcahseForBid, int PUsToSpend, IPurchaseDelegate purchaseDelegate, GameData data, PlayerID player)
          It is the AI's turn to purchase units.
 void reportError(java.lang.String error)
          Report an error to the user.
 void reportMessage(java.lang.String message)
          report a message to the user
 void retreatNotificationMessage(java.util.Collection<Unit> units)
           
 boolean selectAttackSubs(Territory unitTerritory)
          Ask if the player wants to attack lone subs
 boolean selectAttackTransports(Territory unitTerritory)
          Ask if the player wants to attack lone transports
 boolean selectAttackUnits(Territory unitTerritory)
          Ask if the player wants to attack units
 Territory selectBombardingTerritory(Unit unit, Territory unitTerritory, java.util.Collection<Territory> territories, boolean noneAvailable)
          The following methods the AI may choose to implemenmt, but in general won't
 boolean selectShoreBombard(Territory unitTerritory)
          Ask if the player wants to shore bombard
 void start(java.lang.String name)
          The given phase has started.
protected abstract  void tech(ITechDelegate techDelegate, GameData data, PlayerID player)
          It is the AI's turn to roll for technology.
 Territory whereShouldRocketsAttack(java.util.Collection<Territory> candidates, Territory from)
          Choose where my rockets should fire
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface games.strategy.triplea.player.ITripleaPlayer
confirmMoveInFaceOfAA, getNumberOfFightersToMoveToNewCarrier, retreatQuery, selectCasualties, selectFixedDice, selectTerritoryForAirToLand, shouldBomberBomb
 

Constructor Detail

AbstractAI

public AbstractAI(java.lang.String name)
Parameters:
name - - the name of the player.
Method Detail

pause

protected void pause()
Pause the game to allow the human player to see what is going on.


initialize

public final void initialize(IPlayerBridge bridge,
                             PlayerID id)

getGameData

protected final GameData getGameData()
Get the GameData for the game.


getPlayerBridge

protected final IPlayerBridge getPlayerBridge()
Get the IPlayerBridge for this game player.


getWhoAmI

protected final PlayerID getWhoAmI()
What player are we playing.


purchase

protected abstract void purchase(boolean purcahseForBid,
                                 int PUsToSpend,
                                 IPurchaseDelegate purchaseDelegate,
                                 GameData data,
                                 PlayerID player)
It is the AI's turn to purchase units.

Parameters:
purcahseForBid - - is this a bid purchase, or a normal purchase
PUsToSpend - - how many PUs we have to spend
purchaseDelegate - - the purchase delgate to buy things with
data - - the GameData
player - - the player to buy for

tech

protected abstract void tech(ITechDelegate techDelegate,
                             GameData data,
                             PlayerID player)
It is the AI's turn to roll for technology.

Parameters:
techDelegate - - the tech delegate to roll for
data - - the game data
player - - the player to roll tech for

move

protected abstract void move(boolean nonCombat,
                             IMoveDelegate moveDel,
                             GameData data,
                             PlayerID player)
It is the AI's turn to move. Make all moves before returning from this method.

Parameters:
nonCombat - - are we moving in combat, or non combat
moveDel - - the move delegate to make moves with
data - - the current game data
player - - the player to move with

place

protected abstract void place(boolean placeForBid,
                              IAbstractPlaceDelegate placeDelegate,
                              GameData data,
                              PlayerID player)
It is the AI's turn to place units. get the units available to place with player.getUnits()

Parameters:
placeForBid - - is this a placement for bid
placeDelegate - - the place delegate to place with
data - - the current Game Data
player - - the player to place for

battle

protected void battle(IBattleDelegate battleDelegate,
                      GameData data,
                      PlayerID player)
It is the AI's turn to fight. Subclasses may override this if they want, but generally the AI does not need to worry about the order of fighting battles.

Parameters:
battleDelegate - the battle delegate to query for battles not fought and the
data - - the current GameData
player - - the player to fight for

selectBombardingTerritory

public Territory selectBombardingTerritory(Unit unit,
                                           Territory unitTerritory,
                                           java.util.Collection<Territory> territories,
                                           boolean noneAvailable)
The following methods the AI may choose to implemenmt, but in general won't

Specified by:
selectBombardingTerritory in interface ITripleaPlayer
Parameters:
unit - - the bombarding unit
unitTerritory - - where the bombarding unit is
territories - - territories where the unit can bombard
Returns:
the Territory to bombard in, null if the unit should not bombard

selectAttackSubs

public boolean selectAttackSubs(Territory unitTerritory)
Description copied from interface: ITripleaPlayer
Ask if the player wants to attack lone subs

Specified by:
selectAttackSubs in interface ITripleaPlayer
Parameters:
unitTerritory - - where the potential battle is

selectAttackTransports

public boolean selectAttackTransports(Territory unitTerritory)
Description copied from interface: ITripleaPlayer
Ask if the player wants to attack lone transports

Specified by:
selectAttackTransports in interface ITripleaPlayer
Parameters:
unitTerritory - - where the potential battle is

selectAttackUnits

public boolean selectAttackUnits(Territory unitTerritory)
Description copied from interface: ITripleaPlayer
Ask if the player wants to attack units

Specified by:
selectAttackUnits in interface ITripleaPlayer
Parameters:
unitTerritory - - where the potential battle is

selectShoreBombard

public boolean selectShoreBombard(Territory unitTerritory)
Description copied from interface: ITripleaPlayer
Ask if the player wants to shore bombard

Specified by:
selectShoreBombard in interface ITripleaPlayer
Parameters:
unitTerritory - - where the potential battle is

whereShouldRocketsAttack

public Territory whereShouldRocketsAttack(java.util.Collection<Territory> candidates,
                                          Territory from)
Description copied from interface: ITripleaPlayer
Choose where my rockets should fire

Specified by:
whereShouldRocketsAttack in interface ITripleaPlayer
Parameters:
candidates - - a collection of Territories, the possible territories to attack
from - - where the rockets are launched from, null for WW2V1 rules
Returns:
the territory to attack, null if no territory should be attacked

confirmMoveKamikaze

public boolean confirmMoveKamikaze()
Description copied from interface: ITripleaPlayer
The attempted move will kill some air units

Specified by:
confirmMoveKamikaze in interface ITripleaPlayer

confirmMoveHariKari

public boolean confirmMoveHariKari()
Description copied from interface: ITripleaPlayer
The attempted move will kill some units

Specified by:
confirmMoveHariKari in interface ITripleaPlayer

battleInfoMessage

public void battleInfoMessage(java.lang.String shortMessage,
                              DiceRoll dice)
The following methods are more for the ui, and the ai will generally not care


confirmEnemyCasualties

public void confirmEnemyCasualties(GUID battleId,
                                   java.lang.String message,
                                   PlayerID hitPlayer)
Description copied from interface: ITripleaPlayer
Allows the user to pause and confirm enemy casualties

Specified by:
confirmEnemyCasualties in interface ITripleaPlayer

retreatNotificationMessage

public void retreatNotificationMessage(java.util.Collection<Unit> units)

reportError

public void reportError(java.lang.String error)
Description copied from interface: ITripleaPlayer
Report an error to the user.

Specified by:
reportError in interface ITripleaPlayer

reportMessage

public void reportMessage(java.lang.String message)
Description copied from interface: ITripleaPlayer
report a message to the user

Specified by:
reportMessage in interface ITripleaPlayer

confirmOwnCasualties

public void confirmOwnCasualties(GUID battleId,
                                 java.lang.String message)
Specified by:
confirmOwnCasualties in interface ITripleaPlayer

start

public final void start(java.lang.String name)
The given phase has started. We parse the phase name and call the apropiate method.


getRemotePlayerType

public final java.lang.Class<ITripleaPlayer> getRemotePlayerType()

getName

public final java.lang.String getName()

getID

public final PlayerID getID()
Specified by:
getID in interface ITripleaPlayer