1.1 --- a/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 15:11:22 2011 +0400
1.2 +++ b/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:30:18 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,21 +76,49 @@
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 +
1.22 + List<Batch> list1 = buildNumberOperations(0, end, targetSlot);
1.23 + List<Batch> list2 = buildNumberOperations(begin, end, targetSlot);
1.24 + if (list1.size() <= list2.size())
1.25 + {
1.26 + Collections.reverse(list1);
1.27 + retArray.addAll(list1);
1.28 + }
1.29 + else
1.30 + {
1.31 + Collections.reverse(list2);
1.32 + retArray.addAll(list2);
1.33 + }
1.34 + return retArray;
1.35 + }
1.36 +
1.37 + protected static List<Batch> buildNumberOperations(int begin, int end, Slot targetSlot){
1.38 + List<Batch> list = new ArrayList<Batch>();
1.39 +
1.40 while(end >= 2){
1.41 int d = end % 2;
1.42 + if (begin > 0 && 2*begin > end)
1.43 + {
1.44 + for (int i = 0; i < end - begin; i++)
1.45 + {
1.46 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.47 + }
1.48 + break;
1.49 + }
1.50 if( d == 0 ) {
1.51 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.52 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.53 + end = end / 2;
1.54 } else {
1.55 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.56 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.57 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.58 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.59 + end = (end-1) / 2;
1.60 }
1.61 - end = end / 2;
1.62 }
1.63 - return retArray;
1.64 + return list;
1.65 }
1.66
1.67 protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){
1.68 @@ -150,4 +180,11 @@
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.76 + List<Batch> list = smartAlg(5, 12, slot);
1.77 + System.out.println(list.toArray().toString());
1.78 + }
1.79 }