package net.ciklum.icfpc11.controller.ai import junit.framework.TestCase import net.ciklum.icfpc11.controller.Controller import net.ciklum.icfpc11.domain.Game import net.ciklum.icfpc11.domain.Player import net.ciklum.icfpc11.parser.Command import static net.ciklum.icfpc11.plan.FunctionTreeBuilder.* import net.ciklum.icfpc11.plan.MovePlanner import net.ciklum.icfpc11.domain.greenspoon10.ConstantFunction /** * * @author mym */ class MegagunTest extends TestCase { private Controller controller void setUp() { controller = new Controller(Game.push(new Player('p0'), new Player('p1'))) } void tearDown() { Game.pop() } void test_help_and_zombie() { def helpTree = S(K(help(get(get(zero)), get(get(zero)))), K(get(dbl(dbl(succ(zero)))))) MovePlanner helpPlanner = new MovePlanner(2) List helpCommands = helpPlanner.plan(helpTree) controller.game.currentProponent.getSlot(0).value = ConstantFunction.valueOf(255) controller.game.currentProponent.getSlot(1).value = ConstantFunction.valueOf(255) controller.game.currentProponent.getSlot(4).value = ConstantFunction.valueOf(8160) controller.game.currentProponent.getSlot(255).value = ConstantFunction.valueOf(17) def zombieTree = zombie(get(zero), get(succ(succ(zero)))) MovePlanner zombiePlanner = new MovePlanner(177) def zombieCommands = zombiePlanner.plan(zombieTree) println "Gun costs ${helpCommands.size() + zombieCommands.size()} moves to assemble" helpCommands.each {Command c -> controller.applyCommand(c) } assert 'S(K(help(const(17),const(17))),K(const(8160)))' == controller.game.currentProponent.getSlot(2).value.toString() controller.game.currentOpponent.getSlot(0).vitality = 0 zombieCommands.each {Command c -> controller.applyCommand(c) } assertEquals 'I', controller.game.currentProponent.getSlot(177).value.toString() assert -1 == controller.game.currentOpponent.getSlot(0).vitality assertEquals 'S(K(help(const(17),const(17))),K(const(8160)))', controller.game.currentOpponent.getSlot(0).value.toString() controller.game.nextTurn() assert 0 == controller.game.currentProponent.getSlot(0).vitality assertEquals 'I', controller.game.currentProponent.getSlot(0).value.toString() assert 0 == controller.game.currentProponent.getSlot(17).vitality } }