Package net.sf.colossus.client
Class PredictSplitNode
- java.lang.Object
-
- net.sf.colossus.client.PredictSplitNode
-
- All Implemented Interfaces:
java.lang.Comparable<PredictSplitNode>
public class PredictSplitNode extends java.lang.Object implements java.lang.Comparable<PredictSplitNode>
Predicts splits for one enemy player, and adjusts predictions as creatures are revealed.- Author:
- David Ripton, Kim Milvang-Jensen See docs/SplitPrediction.txt
-
-
Field Summary
Fields Modifier and Type Field Description private CreatureTypeangelprivate PredictSplitNodechild1private PredictSplitNodechild2private intchildSize2private static CreatureInfoComparatorcicprivate CreatureInfoListcreaturesprivate java.lang.StringmarkerIdprivate PredictSplitNodeparentprivate CreatureInfoListremovedprivate CreatureTypetitanprivate intturnCreatedprivate Variantvariant
-
Constructor Summary
Constructors Constructor Description PredictSplitNode(java.lang.String markerId, int turnCreated, CreatureInfoList cil, PredictSplitNode parent, Variant variant)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddCreature(CreatureType type)(package private) booleanallCertain()(package private) booleanallDescendentsCertain()Return true if all of this node's children, grandchildren, etc.(package private) java.util.List<CreatureType>chooseCreaturesToSplitOut(java.util.List<java.util.List<CreatureType>> possibleSplits)Decide how to split this legion, and return a list of creatures names to remove.private voidclearChildren()intcompareTo(PredictSplitNode other)(package private) voidcomputeSplit(int childSize, java.util.List<CreatureType> knownKeep, java.util.List<CreatureType> knownSplit, CreatureInfoList keepList, CreatureInfoList splitList)Computes the predicted split of childsize, given that we may already know some pieces that are keept or spilt.(package private) intcount(java.util.List<?> li, java.lang.Object ob)Return the number of times ob is found in li(package private) static intcount(java.util.List<java.lang.String> li, java.lang.String name)Return the number of times name occurs in li(package private) java.util.List<java.util.List<CreatureType>>findAllPossibleSplits(int childSize, java.util.List<CreatureType> knownKeep, java.util.List<CreatureType> knownSplit)Return a list of all legal combinations of splitoffs.(package private) CreatureInfoListgetAfterSplitCreatures()Return list of CreatureInfo where atSplit == false.(package private) CreatureInfoListgetAtSplitOrRemovedCreatures()Return list of CreatureInfo where atSplit == true, plus removed creatures.(package private) CreatureInfoListgetCertainAtSplitOrRemovedCreatures()Return list of CreatureInfo where both certain and atSplit are true, plus removed creatures.(package private) CreatureInfoListgetCertainCreatures()Return list of CreatureInfo where certain == true.PredictSplitNodegetChild1()PredictSplitNodegetChild2()(package private) java.util.List<PredictSplitNode>getChildren()(package private) CreatureInfoListgetCreatures()Return list of CreatureInfojava.lang.StringgetFullName()(package private) intgetHeight()java.lang.StringgetMarkerId()(package private) java.lang.StringgetOtherChildMarkerId()PredictSplitNodegetParent()(package private) CreatureInfoListgetRemovedCreatures()Return list of CreatureInfointgetTurnCreated()(package private) booleanhasSplit()booleanisLegalInitialSplitoff(java.util.List<CreatureType> types)(package private) voidmerge(PredictSplitNode other)Recombine this legion and other, because it was not possible to move.(package private) static intminCount(java.util.List<java.util.List<java.lang.String>> lili, java.lang.String name)lili is a list of lists.(package private) intnumCertainCreatures()(package private) intnumUncertainCreatures()(package private) voidremoveCreature(CreatureType type)(package private) voidremoveCreatures(java.util.List<CreatureType> creatureTypes)(package private) voidreSplit()Recompute the split of a stack, taking advantage of any information potentially gained from the children(package private) voidrevealCreatures(java.util.List<CreatureType> cnl)private static <T> booleansafeEquals(T obj1, T obj2)(package private) voidsetCreatures(CreatureInfoList creatures)(package private) voidsplit(int childSize, Legion otherLegion, int turn)Perform the initial split of a stack, and create the children(package private) static <T> java.util.List<T>subtractLists(java.util.List<T> big, java.util.List<T> little)(package private) static <T> booleansuperset(java.util.List<T> big, java.util.List<T> little)Return true if big is a superset of little.java.lang.StringtoString()(package private) voidupdateInitialSplitInfo(CreatureInfoList newList)This takes potentially new information about the legion's composition at split and applies the later changes to the legion to get a new predicton of contents.
-
-
-
Field Detail
-
markerId
private final java.lang.String markerId
-
turnCreated
private final int turnCreated
-
creatures
private CreatureInfoList creatures
-
removed
private final CreatureInfoList removed
-
parent
private final PredictSplitNode parent
-
childSize2
private int childSize2
-
child1
private PredictSplitNode child1
-
child2
private PredictSplitNode child2
-
variant
private final Variant variant
-
titan
private final CreatureType titan
-
angel
private final CreatureType angel
-
cic
private static CreatureInfoComparator cic
-
-
Constructor Detail
-
PredictSplitNode
PredictSplitNode(java.lang.String markerId, int turnCreated, CreatureInfoList cil, PredictSplitNode parent, Variant variant)
-
-
Method Detail
-
clearChildren
private void clearChildren()
-
getMarkerId
public java.lang.String getMarkerId()
-
getFullName
public java.lang.String getFullName()
-
getChild1
public PredictSplitNode getChild1()
-
getChild2
public PredictSplitNode getChild2()
-
getParent
public PredictSplitNode getParent()
-
getTurnCreated
public int getTurnCreated()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getCreatures
CreatureInfoList getCreatures()
Return list of CreatureInfo
-
setCreatures
void setCreatures(CreatureInfoList creatures)
-
getRemovedCreatures
CreatureInfoList getRemovedCreatures()
Return list of CreatureInfo
-
getCertainCreatures
CreatureInfoList getCertainCreatures()
Return list of CreatureInfo where certain == true.
-
numCertainCreatures
int numCertainCreatures()
-
numUncertainCreatures
int numUncertainCreatures()
-
allCertain
boolean allCertain()
-
hasSplit
boolean hasSplit()
-
getChildren
java.util.List<PredictSplitNode> getChildren()
-
allDescendentsCertain
boolean allDescendentsCertain()
Return true if all of this node's children, grandchildren, etc. have no uncertain creatures
-
getAtSplitOrRemovedCreatures
CreatureInfoList getAtSplitOrRemovedCreatures()
Return list of CreatureInfo where atSplit == true, plus removed creatures.
-
getAfterSplitCreatures
CreatureInfoList getAfterSplitCreatures()
Return list of CreatureInfo where atSplit == false.
-
getCertainAtSplitOrRemovedCreatures
CreatureInfoList getCertainAtSplitOrRemovedCreatures()
Return list of CreatureInfo where both certain and atSplit are true, plus removed creatures.
-
getOtherChildMarkerId
java.lang.String getOtherChildMarkerId()
-
getHeight
int getHeight()
-
superset
static <T> boolean superset(java.util.List<T> big, java.util.List<T> little)Return true if big is a superset of little. Note that this treats repeated elements as distinct, i.e. if the little list contains two copies of something, then the big list has to contain two copies, too. It differs in that regard from Collection.containsAll(Collection) which is implemented in a fashion where this is not necessary (the specification as of JDK 1.5 is actually blurry on the matter).
-
revealCreatures
void revealCreatures(java.util.List<CreatureType> cnl)
-
isLegalInitialSplitoff
public boolean isLegalInitialSplitoff(java.util.List<CreatureType> types)
-
findAllPossibleSplits
java.util.List<java.util.List<CreatureType>> findAllPossibleSplits(int childSize, java.util.List<CreatureType> knownKeep, java.util.List<CreatureType> knownSplit)
Return a list of all legal combinations of splitoffs. Also update knownKeep and knownSplit if we conclude that more creatures are certain.- Parameters:
childSize-knownKeep-knownSplit-- Returns:
-
safeEquals
private static <T> boolean safeEquals(T obj1, T obj2)
-
chooseCreaturesToSplitOut
java.util.List<CreatureType> chooseCreaturesToSplitOut(java.util.List<java.util.List<CreatureType>> possibleSplits)
Decide how to split this legion, and return a list of creatures names to remove. Return empty list on error.
-
count
int count(java.util.List<?> li, java.lang.Object ob)Return the number of times ob is found in li
-
computeSplit
void computeSplit(int childSize, java.util.List<CreatureType> knownKeep, java.util.List<CreatureType> knownSplit, CreatureInfoList keepList, CreatureInfoList splitList)Computes the predicted split of childsize, given that we may already know some pieces that are keept or spilt. Also makes the new CreatureInfoLists. Note that knownKeep and knownSplit will be altered, and be empty after call- Parameters:
childSize-knownKeep- certain creatures to keepknownSplit- certain creatures to splitkeepList- return argumentsplitList- return argument
-
split
void split(int childSize, Legion otherLegion, int turn)Perform the initial split of a stack, and create the children- Parameters:
childSize-otherMarkerId-turn-
-
reSplit
void reSplit()
Recompute the split of a stack, taking advantage of any information potentially gained from the children
-
updateInitialSplitInfo
void updateInitialSplitInfo(CreatureInfoList newList)
This takes potentially new information about the legion's composition at split and applies the later changes to the legion to get a new predicton of contents. It then recursively resplits.- Parameters:
newList-
-
merge
void merge(PredictSplitNode other)
Recombine this legion and other, because it was not possible to move. They must share a parent. If either legion has the parent's markerId, then that legion will remain. Otherwise this legion will remain. Also used to undo splits.
-
addCreature
void addCreature(CreatureType type)
-
removeCreature
void removeCreature(CreatureType type)
-
removeCreatures
void removeCreatures(java.util.List<CreatureType> creatureTypes)
-
compareTo
public int compareTo(PredictSplitNode other)
- Specified by:
compareToin interfacejava.lang.Comparable<PredictSplitNode>
-
subtractLists
static <T> java.util.List<T> subtractLists(java.util.List<T> big, java.util.List<T> little)
-
count
static int count(java.util.List<java.lang.String> li, java.lang.String name)Return the number of times name occurs in li
-
minCount
static int minCount(java.util.List<java.util.List<java.lang.String>> lili, java.lang.String name)lili is a list of lists. Return the minimum number of times name appears in any of the lists contained in lili.
-
-