# HG changeset patch # User indvdum # Date 1308489200 -14400 # Node ID da95a7576365b5cbf826fc6b6ca365ef199afa58 # Parent fcdce54b2f25058367a8b75749c929242a30d23b# Parent 7eacf1e212130dd456698ddfeb53cf6b8c2a0354 * merge diff -r fcdce54b2f25 -r da95a7576365 src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java --- a/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:09:51 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:13:20 2011 +0400 @@ -91,63 +91,5 @@ return retArray; } - protected ArrayList BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){ - ArrayList retArray = new ArrayList(); - - if(!(function instanceof Attack || function instanceof Help)){ - throw new ICFPCException(); - } - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); - retArray.add(new Batch(OperationType.SLOT_TO_CARD, function, processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot)); - - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); - - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); - - return retArray; - } - public abstract ArrayList getBatches(); } diff -r fcdce54b2f25 -r da95a7576365 src/main/java/ru/alphatech/icfpc/game/Run.java --- a/src/main/java/ru/alphatech/icfpc/game/Run.java Sun Jun 19 17:09:51 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/game/Run.java Sun Jun 19 17:13:20 2011 +0400 @@ -15,6 +15,8 @@ public class Run { + private static boolean automodeapply = false; + private static boolean endgame = false; private static Player proponent = new Player(); @@ -77,6 +79,11 @@ strategy.moving(proponent, opponent, System.out); } + public static boolean getAutoMode() + { + return automodeapply; + } + public static void main(String[] args) throws IOException { String playerNum = args[0]; diff -r fcdce54b2f25 -r da95a7576365 src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java Sun Jun 19 17:09:51 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java Sun Jun 19 17:13:20 2011 +0400 @@ -67,7 +67,8 @@ return type == TYPE.ATTACK ? new Attack() : new Help(); } - protected ArrayList BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){ + protected ArrayList BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot) + { ArrayList retArray = new ArrayList(); if(!(function instanceof Attack || function instanceof Help)){ diff -r fcdce54b2f25 -r da95a7576365 src/main/java/ru/alphatech/icfpc/policy/CompositionPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/CompositionPolicy.java Sun Jun 19 17:09:51 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/CompositionPolicy.java Sun Jun 19 17:13:20 2011 +0400 @@ -5,19 +5,19 @@ import ru.alphatech.icfpc.game.AbstractPolicy; import ru.alphatech.icfpc.game.Batch; -public class CompositionPolicy extends AbstractPolicy{ +public abstract class CompositionPolicy extends AbstractPolicy{ protected ArrayList policies = new ArrayList(); - public void addPolicy(AbstractPolicy policy){ + protected void addPolicy(AbstractPolicy policy){ policies.add(policy); } - public void removePolicy(AbstractPolicy policy){ + protected void removePolicy(AbstractPolicy policy){ policies.remove(policy); } - public AbstractPolicy getPolicy(int index){ + protected AbstractPolicy getPolicy(int index){ return policies.get(index); } diff -r fcdce54b2f25 -r da95a7576365 src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java Sun Jun 19 17:13:20 2011 +0400 @@ -0,0 +1,74 @@ +package ru.alphatech.icfpc.policy; + +import java.util.ArrayList; + +import ru.alphatech.icfpc.cards.Dec; +import ru.alphatech.icfpc.cards.Get; +import ru.alphatech.icfpc.cards.ICard; +import ru.alphatech.icfpc.cards.Inc; +import ru.alphatech.icfpc.cards.K; +import ru.alphatech.icfpc.cards.Put; +import ru.alphatech.icfpc.cards.S; +import ru.alphatech.icfpc.cards.Zero; +import ru.alphatech.icfpc.game.AbstractPolicy; +import ru.alphatech.icfpc.game.Batch; +import ru.alphatech.icfpc.game.IValue; +import ru.alphatech.icfpc.game.Run; +import ru.alphatech.icfpc.game.Slot; +import ru.alphatech.icfpc.game.Value; +import ru.alphatech.icfpc.game.Batch.OperationType; + +public class DecIncPolicy extends AbstractPolicy{ + + public enum TYPE { + DEC, + INC + } + + private TYPE type; + private int processingSlotIndex = -1; + private int targetSlotIndex = -1; + + + public DecIncPolicy(TYPE type, int processingSlot, int target) { + this.type = type; + this.processingSlotIndex = processingSlot; + this.targetSlotIndex = target; + } + + public ICard getCard(){ + return type == TYPE.DEC ? new Dec() : new Inc(); + } + + @Override + public ArrayList getBatches() { + ArrayList retArray = new ArrayList(); + + retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex)); + + Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex); + IValue slotValue = processingSlot.getValue(); + + if(slotValue instanceof Value){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot)); + }else{ + ICard currentCard = (ICard) slotValue; + if(!(currentCard instanceof Dec && type == TYPE.DEC) || + !(currentCard instanceof Inc && type == TYPE.INC)) + { + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot)); + } + } + + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); + + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); + + return retArray; + } + +}