Package net.sf.colossus.ai
Class AbstractAI
- java.lang.Object
-
- net.sf.colossus.ai.AbstractAI
-
- All Implemented Interfaces:
AI
- Direct Known Subclasses:
SimpleAI
public abstract class AbstractAI extends java.lang.Object implements AI
Abstract implementation of the Colossus AI interface. This class should hold most of the helper functions. Ideally, most (all) "data-gathering" functions from the AIs should be here, mostly as "final protected". AIs should mostly only use information gathered from here to make decisions. There's still a LOT of work to do...- Author:
- Romain Dolbeau Also contains extracted code from SimpleAI:, Bruce Sherrod, David Ripton, Romain Dolbeau Also contains extracted code from RationalAI:, Bruce Sherrod, David Ripton, Romain Dolbeau, Corwin Joy
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractAI.AbstractAIOracleprotected classAbstractAI.CreatureValueConstantsVarious constants used by the AIs code for creature evaluation.protected classAbstractAI.MoveInfolittle helper to store info about possible moves
-
Field Summary
Fields Modifier and Type Field Description BattleEvalConstantsbecprotected ClientclientThe Client we're working for.protected AbstractAI.CreatureValueConstantscvcprivate java.util.Set<BattleHex>duplicateHexCheckerSet of hex name, to check for duplicates.protected java.util.List<IVariantHint.AIStyle>hintSectionUsedFor the Oracle Hint stuff, the play style we use.private static java.util.logging.LoggerLOGGERprotected java.util.RandomrandomOur random source.protected Variantvariant
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractAI(Client client)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<MasterHex,java.util.List<Legion>>[]buildEnemyAttackMap(Player player)arrays and generics don't work well together -- TODO replace the array with a list or model some intermediate classesvoidcleanupBattle()a Battle is finishedprotected booleancouldRecruitUp(Legion legion, MasterHex hex, Legion enemy)Return true if the legion could recruit or acquire something better than its worst creature in hexLabel.intcountCreatureAccrossAllLegionFromPlayer(Creature creature)private booleandoesSetContainHexWithTerrain(java.util.Set<MasterHex> set, java.lang.String terrainTypeName)java.util.Map<BattleHex,java.lang.Integer>findStrikeMap()Return a map of target hex label to number of friendly creatures that can strike itprotected java.util.Map<BattleCritter,java.lang.Double>generateDamageMap()Create a map containing each target and the number of hits it would likely take if all possible creatures attacked it.protected java.util.Collection<LegionMove>generateLegionMoves(java.util.List<java.util.List<CritterMove>> allCritterMoves, boolean forceAll)allCritterMoves is a List of sorted MoveLists.protected intgetAcqStepValue()Shortcut to ask for the acquirables basic value from the variantBattleStrikegetBattleStrike()protected BattleUnitgetBattleUnit(BattleHex hex)CaretakergetCaretaker()protected intgetHintedRecruitmentValue(CreatureType creature, Legion legion, java.util.List<IVariantHint.AIStyle> styles)intgetHintedRecruitmentValueNonTitan(CreatureType creature)intgetHintedRecruitmentValueNonTitan(CreatureType creature, java.util.List<IVariantHint.AIStyle> styles)protected java.util.List<CreatureType>getInitialSplitHint(MasterHex hex)Return which creature the variant suggest splitting at turn 1 when starting in a specific hex.intgetKillValue(BattleCritter battleCritter, MasterBoardTerrain terrain)Get the 'kill value' of a creature on a specific terrain.protected intgetKillValue(CreatureType creature)Get the 'kill value' of a creature on an unspecified terrain.private intgetKillValue(CreatureType creature, MasterBoardTerrain terrain)Get the 'kill value' of a creature on a specific terrain.protected intgetNumberOfWaysToTerrain(Legion legion, MasterHex hex, java.lang.String terrainTypeName)CreatureTypegetVariantRecruitHint(LegionClientSide legion, MasterHex hex, java.util.List<CreatureType> recruits)protected booleanhasOpponentNativeCreature(HazardTerrain terrain)voidinitBattle()a Battle startprotected booleanisHumanLegion(Legion legion)Test whether a Legion belongs to a Human playerstatic LegionMovemakeLegionMove(int[] indexes, java.util.List<java.util.List<CritterMove>> critterMoves)critterMoves is a List of sorted MoveLists.private voidnestForLoop(int[] indexes, int level, java.util.List<java.util.List<CritterMove>> critterMoves, java.util.List<LegionMove> legionMoves, boolean forceAll)Private helper for generateLegionMoves If forceAll is true, generate all possible moves.protected intrangeToClosestOpponent(BattleHex hex)voidsetVariant(Variant v)private booleantrimCritterMoves(java.util.List<java.util.List<CritterMove>> allCritterMoves)Modify allCritterMoves in place, and return true if it changed.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.colossus.ai.AI
acquireAngel, battleMove, concede, flee, handleCarries, masterMove, muster, pickColor, pickEngagement, pickEntrySide, pickMarker, pickStrikePenalty, reinforce, retryFailedBattleMoves, split, splitCallback, strike, summonAngel
-
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
bec
public final BattleEvalConstants bec
-
cvc
protected final AbstractAI.CreatureValueConstants cvc
-
client
protected final Client client
The Client we're working for.
-
variant
protected Variant variant
-
random
protected final java.util.Random random
Our random source.
-
hintSectionUsed
protected java.util.List<IVariantHint.AIStyle> hintSectionUsed
For the Oracle Hint stuff, the play style we use. This can be replaced by AI implementation.
-
duplicateHexChecker
private final java.util.Set<BattleHex> duplicateHexChecker
Set of hex name, to check for duplicates. I assume the reason it is a class variable and not a local variable inside the function is performance (avoiding creation/recreation).
-
-
Constructor Detail
-
AbstractAI
protected AbstractAI(Client client)
-
-
Method Detail
-
setVariant
public void setVariant(Variant v)
- Specified by:
setVariantin interfaceAI
-
getVariantRecruitHint
public final CreatureType getVariantRecruitHint(LegionClientSide legion, MasterHex hex, java.util.List<CreatureType> recruits)
- Specified by:
getVariantRecruitHintin interfaceAI
-
buildEnemyAttackMap
protected final java.util.Map<MasterHex,java.util.List<Legion>>[] buildEnemyAttackMap(Player player)
arrays and generics don't work well together -- TODO replace the array with a list or model some intermediate classes
-
getNumberOfWaysToTerrain
protected final int getNumberOfWaysToTerrain(Legion legion, MasterHex hex, java.lang.String terrainTypeName)
-
doesSetContainHexWithTerrain
private final boolean doesSetContainHexWithTerrain(java.util.Set<MasterHex> set, java.lang.String terrainTypeName)
-
findStrikeMap
public final java.util.Map<BattleHex,java.lang.Integer> findStrikeMap()
Return a map of target hex label to number of friendly creatures that can strike it
-
generateDamageMap
protected final java.util.Map<BattleCritter,java.lang.Double> generateDamageMap()
Create a map containing each target and the number of hits it would likely take if all possible creatures attacked it.
-
getInitialSplitHint
protected final java.util.List<CreatureType> getInitialSplitHint(MasterHex hex)
Return which creature the variant suggest splitting at turn 1 when starting in a specific hex.- Parameters:
hex- The masterboard hex where the split occurs.- Returns:
- The List of Creaturetype to split.
-
getKillValue
public int getKillValue(BattleCritter battleCritter, MasterBoardTerrain terrain)
Get the 'kill value' of a creature on a specific terrain.- Parameters:
battleCritter- The BattleCritter whose value is requested.terrain- The terrain on which the value is requested, or null.- Returns:
- The 'kill value' value of the critter, on terrain if non-null
-
getKillValue
protected int getKillValue(CreatureType creature)
Get the 'kill value' of a creature on an unspecified terrain.- Parameters:
creature- The CreatureType whose value is requested.- Returns:
- The 'kill value' value of creature.
-
getKillValue
private int getKillValue(CreatureType creature, MasterBoardTerrain terrain)
Get the 'kill value' of a creature on a specific terrain.- Parameters:
creature- The CreatureType whose value is requested.terrain- The terrain on which the value is requested, or null- Returns:
- The 'kill value' value of chit, on terrain if non-null
-
getAcqStepValue
protected int getAcqStepValue()
Shortcut to ask for the acquirables basic value from the variant
-
couldRecruitUp
protected final boolean couldRecruitUp(Legion legion, MasterHex hex, Legion enemy)
Return true if the legion could recruit or acquire something better than its worst creature in hexLabel.
-
getHintedRecruitmentValueNonTitan
public int getHintedRecruitmentValueNonTitan(CreatureType creature)
-
getHintedRecruitmentValueNonTitan
public int getHintedRecruitmentValueNonTitan(CreatureType creature, java.util.List<IVariantHint.AIStyle> styles)
-
getHintedRecruitmentValue
protected final int getHintedRecruitmentValue(CreatureType creature, Legion legion, java.util.List<IVariantHint.AIStyle> styles)
-
isHumanLegion
protected final boolean isHumanLegion(Legion legion)
Test whether a Legion belongs to a Human player
-
hasOpponentNativeCreature
protected final boolean hasOpponentNativeCreature(HazardTerrain terrain)
-
rangeToClosestOpponent
protected final int rangeToClosestOpponent(BattleHex hex)
-
generateLegionMoves
protected final java.util.Collection<LegionMove> generateLegionMoves(java.util.List<java.util.List<CritterMove>> allCritterMoves, boolean forceAll)
allCritterMoves is a List of sorted MoveLists. A MoveList is a sorted List of CritterMoves for one critter. Return a sorted List of LegionMoves. A LegionMove is a List of one CritterMove per mobile critter in the legion, where no two critters move to the same hex. This implementation try to build a near-exhaustive List of all possible moves. It will be fully exhaustive if forceAll is true. Otherwise, it will try to limit to a reasonable number (the exact algorithm is in nestForLoop)
-
nestForLoop
private final void nestForLoop(int[] indexes, int level, java.util.List<java.util.List<CritterMove>> critterMoves, java.util.List<LegionMove> legionMoves, boolean forceAll)Private helper for generateLegionMoves If forceAll is true, generate all possible moves. Otherwise, this function tries to limit the number of moves. This function uses an intermediate array of indexes (called and this is not a surprise, 'indexes') using recursion. The minimum number of try should be the level (level one is the most important creature and should always get his own favorite spot, higher levels need to be able to fall back on a not-so-good choice).
-
makeLegionMove
public static final LegionMove makeLegionMove(int[] indexes, java.util.List<java.util.List<CritterMove>> critterMoves)
critterMoves is a List of sorted MoveLists. indexes is a list of indexes, one per MoveList. This return a LegionMove, made of one CritterMove per MoveList. The CritterMove is selected by the index.
-
trimCritterMoves
private final boolean trimCritterMoves(java.util.List<java.util.List<CritterMove>> allCritterMoves)
Modify allCritterMoves in place, and return true if it changed.
-
initBattle
public void initBattle()
Description copied from interface:AIa Battle start- Specified by:
initBattlein interfaceAI
-
cleanupBattle
public void cleanupBattle()
Description copied from interface:AIa Battle is finished- Specified by:
cleanupBattlein interfaceAI
-
getBattleUnit
protected BattleUnit getBattleUnit(BattleHex hex)
-
getBattleStrike
public BattleStrike getBattleStrike()
-
countCreatureAccrossAllLegionFromPlayer
public final int countCreatureAccrossAllLegionFromPlayer(Creature creature)
-
getCaretaker
public Caretaker getCaretaker()
- Specified by:
getCaretakerin interfaceAI
-
-