package net.ciklum.icfpc11.controller.ai import net.ciklum.icfpc11.parser.Command import net.ciklum.icfpc11.domain.Game import net.ciklum.icfpc11.domain.Slot import net.ciklum.icfpc11.domain.Card import net.ciklum.icfpc11.parser.Application import net.ciklum.icfpc11.domain.greenspoon10.ConstantFunction /** * Finds a weak slot with 1-2 vitality and dec() it. * @author vic */ @Typed final class DecWeaklingStrategy implements Strategy { private final int targetSlotEncoded private final int slotForAddress private final Game game private BuildConstantStrategy buildConstantStrategy DecWeaklingStrategy(Game game, int targetSlot, int slotForAddress) { this.game = game this.targetSlotEncoded = 255-targetSlot this.slotForAddress = slotForAddress buildConstantStrategy = new BuildConstantStrategy(game, slotForAddress, this.targetSlotEncoded) } // ... or survivor static int findWeakling(Game game) { // int index = game.currentOpponent.slots.findIndexOf { Slot it -> it.vitality in [1, 2] } // if (index >= 0) return index Slot minSlot = game.currentOpponent.slots.findAll{ it.alive }.min { Slot it -> it.vitality } int index = game.currentOpponent.slots.indexOf(minSlot) return index } Command getNextCommand() { if (complete) { throw new IndexOutOfBoundsException('Revival is complete or cant complete') } def addrSlotValue = game.currentProponent.getSlot(slotForAddress).value if (addrSlotValue == ConstantFunction.valueOf(targetSlotEncoded)) { // got the right argument return new Command(Application.LEFT, slotForAddress, Card.dec) } else { return commandToObtainConstant(targetSlotEncoded) } } private Command commandToObtainConstant(int slotToRevive) { return buildConstantStrategy.nextCommand } boolean isComplete() { Game.instance.currentOpponent.getSlot(255-targetSlotEncoded).vitality <= 0 || // Game.instance.currentOpponent.getSlot(targetSlotEncoded).vitality > 2 || !game.currentProponent.getSlot(slotForAddress).alive } }