1.1 --- a/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:35:56 2011 +0400
1.2 +++ b/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:36:49 2011 +0400
1.3 @@ -1,6 +1,8 @@
1.4 package ru.alphatech.icfpc.game;
1.5
1.6 import java.util.ArrayList;
1.7 +import java.util.Collections;
1.8 +import java.util.List;
1.9
1.10 import ru.alphatech.icfpc.cards.Attack;
1.11 import ru.alphatech.icfpc.cards.Dbl;
1.12 @@ -74,22 +76,57 @@
1.13 return retArray;
1.14 }
1.15
1.16 - protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
1.17 + protected static List<Batch> smartAlg(int begin, int end, Slot targetSlot){
1.18 ArrayList<Batch> retArray = new ArrayList<Batch>();
1.19 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
1.20 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
1.21 - while(end >= 2){
1.22 - int d = end % 2;
1.23 - if( d == 0 ) {
1.24 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.25 - } else {
1.26 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.27 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.28 - }
1.29 - end = end / 2;
1.30 +
1.31 + List<Batch> list1 = buildNumberOperations(0, end, targetSlot);
1.32 + List<Batch> list2 = buildNumberOperations(begin, end, targetSlot);
1.33 + if (list1.size() <= list2.size())
1.34 + {
1.35 + Collections.reverse(list1);
1.36 + retArray.addAll(list1);
1.37 + }
1.38 + else
1.39 + {
1.40 + Collections.reverse(list2);
1.41 + retArray.addAll(list2);
1.42 }
1.43 return retArray;
1.44 }
1.45
1.46 + protected static List<Batch> buildNumberOperations(int begin, int end, Slot targetSlot){
1.47 + List<Batch> list = new ArrayList<Batch>();
1.48 +
1.49 + while(end >= 2){
1.50 + int d = end % 2;
1.51 + if (begin > 0 && 2*begin > end)
1.52 + {
1.53 + for (int i = 0; i < end - begin; i++)
1.54 + {
1.55 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.56 + }
1.57 + break;
1.58 + }
1.59 + if( d == 0 ) {
1.60 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.61 + end = end / 2;
1.62 + } else {
1.63 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.64 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.65 + end = (end-1) / 2;
1.66 + }
1.67 + }
1.68 + return list;
1.69 + }
1.70 +
1.71 public abstract ArrayList<Batch> getBatches();
1.72 +
1.73 + public static void main(String[] args)
1.74 + {
1.75 + Slot slot = new Slot(1);
1.76 + List<Batch> list = smartAlg(5, 12, slot);
1.77 + System.out.println(list.toArray().toString());
1.78 + }
1.79 }
2.1 --- a/src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java Sun Jun 19 17:35:56 2011 +0400
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,74 +0,0 @@
2.4 -package ru.alphatech.icfpc.policy;
2.5 -
2.6 -import java.util.ArrayList;
2.7 -
2.8 -import ru.alphatech.icfpc.cards.Dec;
2.9 -import ru.alphatech.icfpc.cards.Get;
2.10 -import ru.alphatech.icfpc.cards.ICard;
2.11 -import ru.alphatech.icfpc.cards.Inc;
2.12 -import ru.alphatech.icfpc.cards.K;
2.13 -import ru.alphatech.icfpc.cards.Put;
2.14 -import ru.alphatech.icfpc.cards.S;
2.15 -import ru.alphatech.icfpc.cards.Zero;
2.16 -import ru.alphatech.icfpc.game.AbstractPolicy;
2.17 -import ru.alphatech.icfpc.game.Batch;
2.18 -import ru.alphatech.icfpc.game.IValue;
2.19 -import ru.alphatech.icfpc.game.Run;
2.20 -import ru.alphatech.icfpc.game.Slot;
2.21 -import ru.alphatech.icfpc.game.Value;
2.22 -import ru.alphatech.icfpc.game.Batch.OperationType;
2.23 -
2.24 -public class DecIncPolicy extends AbstractPolicy{
2.25 -
2.26 - public enum TYPE {
2.27 - DEC,
2.28 - INC
2.29 - }
2.30 -
2.31 - private TYPE type;
2.32 - private int processingSlotIndex = -1;
2.33 - private int targetSlotIndex = -1;
2.34 -
2.35 -
2.36 - public DecIncPolicy(TYPE type, int processingSlot, int target) {
2.37 - this.type = type;
2.38 - this.processingSlotIndex = processingSlot;
2.39 - this.targetSlotIndex = target;
2.40 - }
2.41 -
2.42 - public ICard getCard(){
2.43 - return type == TYPE.DEC ? new Dec() : new Inc();
2.44 - }
2.45 -
2.46 - @Override
2.47 - public ArrayList<Batch> getBatches() {
2.48 - ArrayList<Batch> retArray = new ArrayList<Batch>();
2.49 -
2.50 - retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex));
2.51 -
2.52 - Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
2.53 - IValue slotValue = processingSlot.getValue();
2.54 -
2.55 - if(slotValue instanceof Value){
2.56 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
2.57 - retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
2.58 - }else{
2.59 - ICard currentCard = (ICard) slotValue;
2.60 - if(!(currentCard instanceof Dec && type == TYPE.DEC) ||
2.61 - !(currentCard instanceof Inc && type == TYPE.INC))
2.62 - {
2.63 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
2.64 - retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
2.65 - }
2.66 - }
2.67 -
2.68 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
2.69 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
2.70 -
2.71 - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
2.72 - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
2.73 -
2.74 - return retArray;
2.75 - }
2.76 -
2.77 -}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/OneArgumentCardsPolicy.java Sun Jun 19 17:36:49 2011 +0400
3.3 @@ -0,0 +1,104 @@
3.4 +package ru.alphatech.icfpc.policy;
3.5 +
3.6 +import java.util.ArrayList;
3.7 +
3.8 +import ru.alphatech.icfpc.cards.Copy;
3.9 +import ru.alphatech.icfpc.cards.Dec;
3.10 +import ru.alphatech.icfpc.cards.Get;
3.11 +import ru.alphatech.icfpc.cards.ICard;
3.12 +import ru.alphatech.icfpc.cards.Inc;
3.13 +import ru.alphatech.icfpc.cards.K;
3.14 +import ru.alphatech.icfpc.cards.Put;
3.15 +import ru.alphatech.icfpc.cards.Revive;
3.16 +import ru.alphatech.icfpc.cards.S;
3.17 +import ru.alphatech.icfpc.cards.Zero;
3.18 +import ru.alphatech.icfpc.game.AbstractPolicy;
3.19 +import ru.alphatech.icfpc.game.Batch;
3.20 +import ru.alphatech.icfpc.game.IValue;
3.21 +import ru.alphatech.icfpc.game.Run;
3.22 +import ru.alphatech.icfpc.game.Slot;
3.23 +import ru.alphatech.icfpc.game.Value;
3.24 +import ru.alphatech.icfpc.game.Batch.OperationType;
3.25 +
3.26 +public class OneArgumentCardsPolicy extends AbstractPolicy{
3.27 +
3.28 + public enum TYPE {
3.29 + DEC,
3.30 + INC,
3.31 + COPY,
3.32 + REVIVE
3.33 + }
3.34 +
3.35 + private TYPE type;
3.36 + private int processingSlotIndex = -1;
3.37 + private int registerIndex = -1;
3.38 + private int targetSlotIndex = -1;
3.39 +
3.40 +
3.41 + public OneArgumentCardsPolicy(TYPE type, int processingSlot, int target, int registerIndex) {
3.42 + this.type = type;
3.43 + this.processingSlotIndex = processingSlot;
3.44 + this.targetSlotIndex = target;
3.45 + this.registerIndex = registerIndex;
3.46 + }
3.47 +
3.48 + public ICard getCard(){
3.49 + switch (type) {
3.50 + case DEC:
3.51 + return new Dec();
3.52 + case INC:
3.53 + return new Inc();
3.54 + case COPY:
3.55 + return new Copy();
3.56 + case REVIVE:
3.57 + return new Revive();
3.58 + }
3.59 + return null;
3.60 + }
3.61 +
3.62 + protected boolean isEqualsCard(IValue value){
3.63 + if(value instanceof IValue)
3.64 + return false;
3.65 + if( type == TYPE.DEC && value instanceof Dec)
3.66 + return true;
3.67 + if( type == TYPE.INC && value instanceof Inc)
3.68 + return true;
3.69 + if( type == TYPE.COPY && value instanceof Copy)
3.70 + return true;
3.71 + if( type == TYPE.REVIVE && value instanceof Revive)
3.72 + return true;
3.73 + return false;
3.74 + }
3.75 +
3.76 + @Override
3.77 + public ArrayList<Batch> getBatches() {
3.78 + ArrayList<Batch> retArray = new ArrayList<Batch>();
3.79 +
3.80 + retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(registerIndex), targetSlotIndex));
3.81 +
3.82 + Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
3.83 + IValue slotValue = processingSlot.getValue();
3.84 +
3.85 + if(slotValue instanceof Value){
3.86 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
3.87 + retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
3.88 + }else{
3.89 + ICard currentCard = (ICard) slotValue;
3.90 + if(!(currentCard instanceof Dec && type == TYPE.DEC) ||
3.91 + !(currentCard instanceof Inc && type == TYPE.INC))
3.92 + {
3.93 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
3.94 + retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
3.95 + }
3.96 + }
3.97 +
3.98 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
3.99 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
3.100 +
3.101 + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
3.102 + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
3.103 +
3.104 + return retArray;
3.105 + }
3.106 +
3.107 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/ZombiePolicy.java Sun Jun 19 17:36:49 2011 +0400
4.3 @@ -0,0 +1,15 @@
4.4 +package ru.alphatech.icfpc.policy;
4.5 +
4.6 +import java.util.ArrayList;
4.7 +
4.8 +import ru.alphatech.icfpc.game.AbstractPolicy;
4.9 +import ru.alphatech.icfpc.game.Batch;
4.10 +
4.11 +public class ZombiePolicy extends AbstractPolicy {
4.12 +
4.13 + @Override
4.14 + public ArrayList<Batch> getBatches() {
4.15 + return null;
4.16 + }
4.17 +
4.18 +}