1 package ru.alphatech.icfpc.game;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import ru.alphatech.icfpc.cards.Attack;
8 import ru.alphatech.icfpc.cards.Dbl;
9 import ru.alphatech.icfpc.cards.Get;
10 import ru.alphatech.icfpc.cards.Help;
11 import ru.alphatech.icfpc.cards.ICard;
12 import ru.alphatech.icfpc.cards.K;
13 import ru.alphatech.icfpc.cards.Put;
14 import ru.alphatech.icfpc.cards.S;
15 import ru.alphatech.icfpc.cards.Succ;
16 import ru.alphatech.icfpc.cards.Zero;
17 import ru.alphatech.icfpc.game.Batch.OperationType;
26 public abstract class AbstractPolicy {
28 protected ArrayList<Batch> batches = new ArrayList<Batch>();
30 public AbstractPolicy(){
33 public void setRegister(int registerIndex, int num ){
34 if( registerIndex < 4) {
35 Slot registerSlot = Run.getRegisterByIndex(registerIndex);
36 batches.addAll( numberIntoSlotField( registerSlot, num ) );
40 protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
42 ArrayList<Batch> retArray = new ArrayList<Batch>();
44 IValue targetValue = targetSlot.getValue();
46 if(targetValue instanceof ICard){
47 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
50 Value numTargetValue = (Value) targetValue;
51 if( numTargetValue.getValue() == number ){
54 if( numTargetValue.getValue() > number ){
55 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
56 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
57 stupidAlg(0, number, targetSlot);
59 stupidAlg(numTargetValue.getValue(), number, targetSlot);
66 protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
67 ArrayList<Batch> retArray = new ArrayList<Batch>();
68 while( begin*2 < end){
69 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
73 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
79 protected static List<Batch> smartAlg(int begin, int end, Slot targetSlot){
80 ArrayList<Batch> retArray = new ArrayList<Batch>();
81 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
82 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
84 List<Batch> list1 = buildNumberOperations(0, end, targetSlot);
85 List<Batch> list2 = buildNumberOperations(begin, end, targetSlot);
86 if (list1.size() <= list2.size())
88 Collections.reverse(list1);
89 retArray.addAll(list1);
93 Collections.reverse(list2);
94 retArray.addAll(list2);
99 protected static List<Batch> buildNumberOperations(int begin, int end, Slot targetSlot){
100 List<Batch> list = new ArrayList<Batch>();
104 if (begin > 0 && 2*begin > end)
106 for (int i = 0; i < end - begin; i++)
108 list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
113 list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
116 list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
117 list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
124 public abstract ArrayList<Batch> getBatches();
126 public static void main(String[] args)
128 Slot slot = new Slot();
129 List<Batch> list = smartAlg(5, 12, slot);
130 System.out.println(list.toArray().toString());