public void addChild(T child) { children.add(new TreeNode<>(child)); }
public int getNumberOfChildren() { return getChildren().size(); }
@Override public String toString() { return getData().toString(); }
protected void addBlockSimulations(List<Permanent> blockers, TreeNode<CombatSimulator> node, Game game) { int numGroups = node.getData().groups.size(); Copier<CombatSimulator> copier = new Copier<>(); for (Permanent blocker : blockers) { List<Permanent> subList = remove(blockers, blocker); for (int i = 0; i < numGroups; i++) { if (node.getData().groups.get(i).canBlock(blocker, game)) { CombatSimulator combat = copier.copy(node.getData()); combat.groups.get(i).blockers.add(new CreatureSimulator(blocker)); TreeNode<CombatSimulator> child = new TreeNode<>(combat); node.addChild(child); addBlockSimulations(subList, child, game); combat.simulate(); } } } }
protected CombatSimulator getBestSimulation(TreeNode<CombatSimulator> simulations) { CombatSimulator best = simulations.getData(); int bestResult = best.evaluate(); for (TreeNode<CombatSimulator> node : simulations.getChildren()) { CombatSimulator bestSub = getBestSimulation(node); if (bestSub.evaluate() > bestResult) { best = node.getData(); bestResult = best.evaluate(); } } return best; }
public TreeNode(T data) { this(); setData(data); }
public boolean hasChildren() { return (getNumberOfChildren() > 0); }
protected CombatSimulator getWorstSimulation(TreeNode<CombatSimulator> simulations) { CombatSimulator worst = simulations.getData(); int worstResult = worst.evaluate(); for (TreeNode<CombatSimulator> node : simulations.getChildren()) { CombatSimulator worstSub = getWorstSimulation(node); if (worstSub.evaluate() < worstResult) { worst = node.getData(); worstResult = worst.evaluate(); } } return worst; }
protected CombatSimulator simulateBlock(CombatSimulator combat, List<Permanent> blockers, Game game) { log.debug("simulateBlock"); TreeNode<CombatSimulator> simulations; simulations = new TreeNode<>(combat); addBlockSimulations(blockers, simulations, game); combat.simulate(); return getWorstSimulation(simulations); }
@Override public int hashCode() { return getData().hashCode(); }