package net.ciklum.icfpc11.controller.ai import net.ciklum.icfpc11.parser.Command import static net.ciklum.icfpc11.domain.Card.* import static net.ciklum.icfpc11.parser.Application.LEFT import net.ciklum.icfpc11.domain.Game import net.ciklum.icfpc11.domain.greenspoon10.ConstantFunction /** * blabla * @author vic */ @Typed final class ReviveStrategy implements Strategy { private final Game game private final int slotToRevive final int slotForAddress private BuildConstantStrategy buildConstantStrategy ReviveStrategy(Game game, int slotToRevive, int slotForAddress) { this.game = game this.slotToRevive = slotToRevive this.slotForAddress = slotForAddress buildConstantStrategy = new BuildConstantStrategy(game, slotForAddress, slotToRevive) } Command getNextCommand() { if (complete) { throw new IndexOutOfBoundsException('Revival is complete or cant complete') } def addrSlotValue = game.currentProponent.getSlot(slotForAddress).value if (addrSlotValue == ConstantFunction.valueOf(slotToRevive)) { // got the right argument return new Command(LEFT, slotForAddress, revive) } else { return commandToObtainConstant(slotToRevive) } } private Command commandToObtainConstant(int slotToRevive) { return buildConstantStrategy.nextCommand } boolean isComplete() { game.currentProponent.getSlot(slotToRevive).alive || !game.currentProponent.getSlot(slotForAddress).alive } }