1 package ru.alphatech.icfpc.game;
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;
10 import ru.alphatech.icfpc.game.Batch.OperationType;
19 public abstract class AbstractPolicy {
21 protected ArrayList<Batch> batches = new ArrayList<Batch>();
23 public AbstractPolicy(){
26 public void setRegister(int registerIndex, int num ){
27 if( registerIndex < 4) {
28 Slot registerSlot = Run.getRegisterByIndex(registerIndex);
29 batches.addAll( numberIntoSlotField( registerSlot, num ) );
33 protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
35 ArrayList<Batch> retArray = new ArrayList<Batch>();
37 IValue targetValue = targetSlot.getValue();
39 if(targetValue instanceof ICard){
40 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
43 Value numTargetValue = (Value) targetValue;
44 if( numTargetValue.getValue() == number ){
47 if( numTargetValue.getValue() > number ){
48 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
49 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
50 stupidAlg(0, number, targetSlot);
52 stupidAlg(numTargetValue.getValue(), number, targetSlot);
59 protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
60 ArrayList<Batch> retArray = new ArrayList<Batch>();
61 while( begin*2 < end){
62 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
66 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
72 protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
73 ArrayList<Batch> retArray = new ArrayList<Batch>();
74 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
75 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
79 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
81 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
82 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
89 public abstract ArrayList<Batch> getBatches();