# HG changeset patch # User indvdum # Date 1308490609 -14400 # Node ID 179dd516b115f205d68afe1b626e449e2843b54c # Parent 774e7ce00b5f88dace1dec5f918056aac14cefa0# Parent b6543dcda02678a9ac6bfb81859c9c45838b4203 * merging diff -r 774e7ce00b5f -r 179dd516b115 src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java --- a/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:35:56 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:36:49 2011 +0400 @@ -1,6 +1,8 @@ package ru.alphatech.icfpc.game; import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import ru.alphatech.icfpc.cards.Attack; import ru.alphatech.icfpc.cards.Dbl; @@ -74,22 +76,57 @@ return retArray; } - protected ArrayList smartAlg(int begin, int end, Slot targetSlot){ + protected static List smartAlg(int begin, int end, Slot targetSlot){ ArrayList retArray = new ArrayList(); retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); - while(end >= 2){ - int d = end % 2; - if( d == 0 ) { - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); - } else { - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); - } - end = end / 2; + + List list1 = buildNumberOperations(0, end, targetSlot); + List list2 = buildNumberOperations(begin, end, targetSlot); + if (list1.size() <= list2.size()) + { + Collections.reverse(list1); + retArray.addAll(list1); + } + else + { + Collections.reverse(list2); + retArray.addAll(list2); } return retArray; } + protected static List buildNumberOperations(int begin, int end, Slot targetSlot){ + List list = new ArrayList(); + + while(end >= 2){ + int d = end % 2; + if (begin > 0 && 2*begin > end) + { + for (int i = 0; i < end - begin; i++) + { + list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); + } + break; + } + if( d == 0 ) { + list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); + end = end / 2; + } else { + list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); + list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); + end = (end-1) / 2; + } + } + return list; + } + public abstract ArrayList getBatches(); + + public static void main(String[] args) + { + Slot slot = new Slot(1); + List list = smartAlg(5, 12, slot); + System.out.println(list.toArray().toString()); + } } diff -r 774e7ce00b5f -r 179dd516b115 src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java Sun Jun 19 17:35:56 2011 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -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; - } - -} diff -r 774e7ce00b5f -r 179dd516b115 src/main/java/ru/alphatech/icfpc/policy/OneArgumentCardsPolicy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/ru/alphatech/icfpc/policy/OneArgumentCardsPolicy.java Sun Jun 19 17:36:49 2011 +0400 @@ -0,0 +1,104 @@ +package ru.alphatech.icfpc.policy; + +import java.util.ArrayList; + +import ru.alphatech.icfpc.cards.Copy; +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.Revive; +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 OneArgumentCardsPolicy extends AbstractPolicy{ + + public enum TYPE { + DEC, + INC, + COPY, + REVIVE + } + + private TYPE type; + private int processingSlotIndex = -1; + private int registerIndex = -1; + private int targetSlotIndex = -1; + + + public OneArgumentCardsPolicy(TYPE type, int processingSlot, int target, int registerIndex) { + this.type = type; + this.processingSlotIndex = processingSlot; + this.targetSlotIndex = target; + this.registerIndex = registerIndex; + } + + public ICard getCard(){ + switch (type) { + case DEC: + return new Dec(); + case INC: + return new Inc(); + case COPY: + return new Copy(); + case REVIVE: + return new Revive(); + } + return null; + } + + protected boolean isEqualsCard(IValue value){ + if(value instanceof IValue) + return false; + if( type == TYPE.DEC && value instanceof Dec) + return true; + if( type == TYPE.INC && value instanceof Inc) + return true; + if( type == TYPE.COPY && value instanceof Copy) + return true; + if( type == TYPE.REVIVE && value instanceof Revive) + return true; + return false; + } + + @Override + public ArrayList getBatches() { + ArrayList retArray = new ArrayList(); + + retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(registerIndex), 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; + } + +} diff -r 774e7ce00b5f -r 179dd516b115 src/main/java/ru/alphatech/icfpc/policy/ZombiePolicy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/ru/alphatech/icfpc/policy/ZombiePolicy.java Sun Jun 19 17:36:49 2011 +0400 @@ -0,0 +1,15 @@ +package ru.alphatech.icfpc.policy; + +import java.util.ArrayList; + +import ru.alphatech.icfpc.game.AbstractPolicy; +import ru.alphatech.icfpc.game.Batch; + +public class ZombiePolicy extends AbstractPolicy { + + @Override + public ArrayList getBatches() { + return null; + } + +}