1 package ru.alphatech.icfpc.policy;
3 import java.util.ArrayList;
5 import ru.alphatech.icfpc.cards.Dbl;
6 import ru.alphatech.icfpc.cards.ICard;
7 import ru.alphatech.icfpc.cards.Put;
8 import ru.alphatech.icfpc.cards.Succ;
9 import ru.alphatech.icfpc.cards.Zero;
18 public abstract class AbstractPolicy {
20 protected ArrayList<Batch> batches = new ArrayList<Batch>();
22 public AbstractPolicy(){
25 public void setRegister(int registerIndex, int num ){
26 if( registerIndex < 4) {
27 Slot registerSlot = Run.getRegisterByIndex(registerIndex);
28 batches.addAll( numberIntoSlotField( registerSlot, num ) );
32 protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
34 ArrayList<Batch> retArray = new ArrayList<Batch>();
36 IValue targetValue = targetSlot.getValue();
38 if(targetValue instanceof ICard){
39 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
42 Value numTargetValue = (Value) targetValue;
43 if( numTargetValue.getValue() == number ){
46 if( numTargetValue.getValue() > number ){
47 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
48 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
49 stupidAlg(0, number, targetSlot);
51 stupidAlg(numTargetValue.getValue(), number, targetSlot);
58 protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
59 ArrayList<Batch> retArray = new ArrayList<Batch>();
60 while( begin*2 < end){
61 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
65 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
71 protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
72 ArrayList<Batch> retArray = new ArrayList<Batch>();
73 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
74 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
78 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
80 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
81 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
88 public abstract ArrayList<Batch> getBatches();