net.sf.colossus.ai
Class RationalAI

java.lang.Object
  extended by net.sf.colossus.ai.AbstractAI
      extended by net.sf.colossus.ai.SimpleAI
          extended by net.sf.colossus.ai.RationalAI
All Implemented Interfaces:
AI
Direct Known Subclasses:
HumanHaterRationalAI, MilvangAI

public class RationalAI
extends SimpleAI

Simple implementation of a Titan AI

Author:
Bruce Sherrod, David Ripton, Romain Dolbeau, Corwin Joy, extensively rewritten on 02-Oct-2003

Nested Class Summary
(package private) static class RationalAI.BattleResults
           
 class RationalAI.CompCreaturesByValueName
           
private  class RationalAI.LegionBoardMove
           
private  class RationalAI.MoveFinder
           
(package private)  class RationalAI.MusteredCreatures
           
 
Nested classes/interfaces inherited from class net.sf.colossus.ai.SimpleAI
SimpleAI.PowerSkill, SimpleAI.TriggerTimeIsUp
 
Nested classes/interfaces inherited from class net.sf.colossus.ai.AbstractAI
AbstractAI.AbstractAIOracle, AbstractAI.CreatureValueConstants, AbstractAI.MoveInfo
 
Field Summary
private  java.util.List<RationalAI.LegionBoardMove> bestMoveList
           
private  java.util.Iterator<RationalAI.LegionBoardMove> bestMoveListIter
           
private  java.util.Map<MasterHex,java.util.List<Legion>>[] enemyAttackMap
           
private  java.util.Map<java.lang.String,java.lang.Integer> evaluateMoveMap
           
(package private)  boolean I_HATE_HUMANS
           
(package private)  double KILLPOINTS
           
private  java.util.List<Legion> legionsToSplit
           
private static java.util.logging.Logger logger
           
(package private) static int RECRUIT_AT_7
           
(package private) static int RECRUIT_FALSE
           
(package private) static int RECRUIT_TRUE
           
(package private)  int TITAN_SURVIVAL
           
 
Fields inherited from class net.sf.colossus.ai.SimpleAI
MIN_ITERATIONS, timeIsUp, timeLimit
 
Fields inherited from class net.sf.colossus.ai.AbstractAI
bec, client, cvc, hintSectionUsed, random, variant
 
Constructor Summary
RationalAI(Client client)
           
 
Method Summary
(package private)  RationalAI.MusteredCreatures chooseCreaturesToSplitOut(Legion legion, boolean at_risk)
          Decide how to split this legion, and return a list of Creatures to remove + status flag indicating if these creatures have mustered or not
 boolean concede(Legion legion, Legion enemy)
          choose whether legion should concede to enemy
(package private)  RationalAI.BattleResults estimateBattleResults(Legion attacker, Legion defender, MasterHex hex)
           
private  RationalAI.BattleResults estimateBattleResults(Legion attacker, Legion defender, MasterHex hex, CreatureType callable)
           
private  int evaluateCombat(Legion attacker, Legion defender, MasterHex hex)
           
private  int evaluateHexAttack(Legion attacker, MasterHex hex, int canRecruitHere)
           
private  int evaluateMove(Legion legion, MasterHex hex, int canRecruitHere, int depth, boolean addHexRisk)
          Memoizing wrapper for evaluateMoveInner
private  int evaluateMoveInner(Legion legion, MasterHex hex, int canRecruitHere, int depth, boolean normalHexRisk)
           
private  double expectedValueSplitLegion(LegionClientSide legion, LegionClientSide child_legion)
           
private  boolean findMoveList(java.util.List<? extends Legion> legions, java.util.List<java.util.List<RationalAI.LegionBoardMove>> all_legionMoves, MultiSet<MasterHex> occupiedHexes, boolean teleportsOnly)
           
private  boolean fireSplits()
          Return true if done with all splits and callbacks
 boolean flee(Legion legion, Legion enemy)
          choose whether legion should flee from enemy
 java.util.List<SimpleAI.PowerSkill> getCombatList(Legion legion, MasterBoardTerrain terrain, boolean defender)
           
private  boolean handleForcedSingleMove(Player player)
           
private  boolean handleForcedSplitMoves(Player player)
           
private  boolean handleVoluntaryMoves(Player player)
          Return true if we moved something and need to be called again.
private  double hexRisk(Legion legion, MasterHex hex, boolean invert)
           
 boolean masterMove()
          Return true if we need to run this method again after the server updates the client with the results of a move or mulligan.
private static double r3(double value)
           
private  double recruitValue(Legion legion, MasterHex hex, Legion enemy, MasterBoardTerrain terrain)
          Find value of recruiting, including possibly attacking an enemy set enemy = null to indicate no enemy
private  java.util.List<CreatureType> removeMustered(java.util.List<CreatureType> sortedCreatures)
           
private  java.util.List<CreatureType> sortCreaturesByValueName(Legion legion)
           
 boolean split()
          make splits for current player.
 boolean splitCallback(Legion parent, Legion child)
          If parentId and childId are null, this is a callback to an undo split
(package private)  boolean splitOneLegion(Player player, Legion legion)
          Return true if done, false if waiting for callback.
private  boolean splitOneLegionCallback(LegionClientSide parent, LegionClientSide child)
          Return true if done, false if waiting for undo split
 
Methods inherited from class net.sf.colossus.ai.SimpleAI
acquireAngel, battleMove, chooseRecruit, doInitialGameSplit, evaluateCritterMove_Defender, evaluateCritterMove_Rangestrike, evaluateCritterMove_Strike, evaluateCritterMove_Titan, evaluateLegionBattleMove, evaluateLegionBattleMoveAsAWhole, findBestLegionMove, findLegionMoves, findWeakestTwoCritters, getCreatureMoveLimit, getNativeValue, handleCarries, handleMulligans, muster, pickColor, pickEngagement, pickEntrySide, pickMarker, pickStrikePenalty, RATIO_DRAW, RATIO_LOSE_HEAVY_LOSS, RATIO_WIN_HEAVY_LOSS, RATIO_WIN_MINIMAL_LOSS, reinforce, retryFailedBattleMoves, setupTimer, strike, summonAngel
 
Methods inherited from class net.sf.colossus.ai.AbstractAI
buildEnemyAttackMap, cleanupBattle, couldRecruitUp, countCreatureAccrossAllLegionFromPlayer, findStrikeMap, generateDamageMap, generateLegionMoves, getAcqStepValue, getBattleStrike, getBattleUnit, getCaretaker, getHintedRecruitmentValue, getHintedRecruitmentValueNonTitan, getHintedRecruitmentValueNonTitan, getInitialSplitHint, getKillValue, getKillValue, getNumberOfWaysToTerrain, getVariantRecruitHint, hasOpponentNativeCreature, initBattle, isHumanLegion, makeLegionMove, rangeToClosestOpponent, setVariant
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

I_HATE_HUMANS

boolean I_HATE_HUMANS

legionsToSplit

private final java.util.List<Legion> legionsToSplit

enemyAttackMap

private java.util.Map<MasterHex,java.util.List<Legion>>[] enemyAttackMap

evaluateMoveMap

private final java.util.Map<java.lang.String,java.lang.Integer> evaluateMoveMap

bestMoveList

private java.util.List<RationalAI.LegionBoardMove> bestMoveList

bestMoveListIter

private java.util.Iterator<RationalAI.LegionBoardMove> bestMoveListIter

TITAN_SURVIVAL

final int TITAN_SURVIVAL
See Also:
Constant Field Values

RECRUIT_FALSE

static final int RECRUIT_FALSE
See Also:
Constant Field Values

RECRUIT_TRUE

static final int RECRUIT_TRUE
See Also:
Constant Field Values

RECRUIT_AT_7

static final int RECRUIT_AT_7
See Also:
Constant Field Values

KILLPOINTS

final double KILLPOINTS
See Also:
Constant Field Values
Constructor Detail

RationalAI

public RationalAI(Client client)
Method Detail

r3

private static double r3(double value)

split

public boolean split()
Description copied from interface: AI
make splits for current player. Return true if done

Specified by:
split in interface AI
Overrides:
split in class SimpleAI

fireSplits

private boolean fireSplits()
Return true if done with all splits and callbacks


splitCallback

public boolean splitCallback(Legion parent,
                             Legion child)
If parentId and childId are null, this is a callback to an undo split

Specified by:
splitCallback in interface AI
Overrides:
splitCallback in class SimpleAI

expectedValueSplitLegion

private double expectedValueSplitLegion(LegionClientSide legion,
                                        LegionClientSide child_legion)

splitOneLegion

boolean splitOneLegion(Player player,
                       Legion legion)
Return true if done, false if waiting for callback.


splitOneLegionCallback

private boolean splitOneLegionCallback(LegionClientSide parent,
                                       LegionClientSide child)
Return true if done, false if waiting for undo split


recruitValue

private double recruitValue(Legion legion,
                            MasterHex hex,
                            Legion enemy,
                            MasterBoardTerrain terrain)
Find value of recruiting, including possibly attacking an enemy set enemy = null to indicate no enemy


removeMustered

private java.util.List<CreatureType> removeMustered(java.util.List<CreatureType> sortedCreatures)

sortCreaturesByValueName

private java.util.List<CreatureType> sortCreaturesByValueName(Legion legion)

chooseCreaturesToSplitOut

RationalAI.MusteredCreatures chooseCreaturesToSplitOut(Legion legion,
                                                       boolean at_risk)
Decide how to split this legion, and return a list of Creatures to remove + status flag indicating if these creatures have mustered or not


masterMove

public boolean masterMove()
Return true if we need to run this method again after the server updates the client with the results of a move or mulligan.

Specified by:
masterMove in interface AI
Overrides:
masterMove in class SimpleAI

findMoveList

private boolean findMoveList(java.util.List<? extends Legion> legions,
                             java.util.List<java.util.List<RationalAI.LegionBoardMove>> all_legionMoves,
                             MultiSet<MasterHex> occupiedHexes,
                             boolean teleportsOnly)

handleVoluntaryMoves

private boolean handleVoluntaryMoves(Player player)
Return true if we moved something and need to be called again.


handleForcedSplitMoves

private boolean handleForcedSplitMoves(Player player)

handleForcedSingleMove

private boolean handleForcedSingleMove(Player player)

hexRisk

private double hexRisk(Legion legion,
                       MasterHex hex,
                       boolean invert)

evaluateCombat

private int evaluateCombat(Legion attacker,
                           Legion defender,
                           MasterHex hex)

evaluateHexAttack

private int evaluateHexAttack(Legion attacker,
                              MasterHex hex,
                              int canRecruitHere)

evaluateMove

private int evaluateMove(Legion legion,
                         MasterHex hex,
                         int canRecruitHere,
                         int depth,
                         boolean addHexRisk)
Memoizing wrapper for evaluateMoveInner


evaluateMoveInner

private int evaluateMoveInner(Legion legion,
                              MasterHex hex,
                              int canRecruitHere,
                              int depth,
                              boolean normalHexRisk)

estimateBattleResults

RationalAI.BattleResults estimateBattleResults(Legion attacker,
                                               Legion defender,
                                               MasterHex hex)

estimateBattleResults

private RationalAI.BattleResults estimateBattleResults(Legion attacker,
                                                       Legion defender,
                                                       MasterHex hex,
                                                       CreatureType callable)

flee

public boolean flee(Legion legion,
                    Legion enemy)
Description copied from interface: AI
choose whether legion should flee from enemy

Specified by:
flee in interface AI
Overrides:
flee in class SimpleAI

concede

public boolean concede(Legion legion,
                       Legion enemy)
Description copied from interface: AI
choose whether legion should concede to enemy

Specified by:
concede in interface AI
Overrides:
concede in class SimpleAI

getCombatList

public java.util.List<SimpleAI.PowerSkill> getCombatList(Legion legion,
                                                         MasterBoardTerrain terrain,
                                                         boolean defender)