package net.ciklum.icfpc11.controller.ai import net.ciklum.icfpc11.parser.Command import static net.ciklum.icfpc11.plan.FunctionTreeBuilder.* import net.ciklum.icfpc11.domain.Game import net.ciklum.icfpc11.plan.MovePlanner import net.ciklum.icfpc11.plan.MovePlanner.BinaryTree import net.ciklum.icfpc11.domain.Card import net.ciklum.icfpc11.parser.Application import net.ciklum.icfpc11.domain.greenspoon10.ConstantFunction /** * Mega-gun * uses [2,13,255] * @author mym */ @Typed final class UberpushkaStrategy implements Strategy { static final BinaryTree HELP_TREE = S(K(help(get(get(zero)), get(get(zero)))), K(get(dbl(dbl(succ(zero)))))) static final BinaryTree ZOMBIE_TREE = zombie(get(zero), get(succ(succ(zero)))) private final Game game private int slotToKill private List commands private int commandNo = 0 UberpushkaStrategy(Game game, int slotToKill) { this.game = game this.slotToKill = slotToKill commands = [] if (game.currentProponent.getSlot(2).value.toString() != 'I') { commands << new Command(Application.LEFT, 2, Card.put) } if (game.currentProponent.getSlot(13).value.toString() != 'I') { commands << new Command(Application.LEFT, 13, Card.put) } // increment 255 def slot255 = game.currentProponent.getSlot(255).value if (slot255 instanceof ConstantFunction && slot255.value <= slotToKill) { // increment the slot value int nInc = slotToKill - slot255.value for (int i = 0; i < nInc; i++) { commands << new Command(Application.LEFT, 255, Card.succ) } } else { if (game.currentProponent.getSlot(255).value.toString() != 'I') { commands << new Command(Application.LEFT, 255, Card.put) } MovePlanner saveSlotPlanner = new MovePlanner(255) List saveSlotCommands = saveSlotPlanner.plan(n(slotToKill)) commands.addAll(saveSlotCommands) } MovePlanner helpPlanner = new MovePlanner(2) List helpCommands = helpPlanner.plan(HELP_TREE) commands.addAll(helpCommands) MovePlanner zombiePlanner = new MovePlanner(13) def zombieCommands = zombiePlanner.plan(ZOMBIE_TREE) commands.addAll(zombieCommands) } Command getNextCommand() { if (complete) { throw new IndexOutOfBoundsException('UberpushkaStrategy is complete') } def currentCommand = commands[commandNo] commandNo++ return currentCommand } boolean isComplete() { commandNo >= commands.size() } }