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;
10 import ru.alphatech.icfpc.game.Batch;
11 import ru.alphatech.icfpc.game.IValue;
12 import ru.alphatech.icfpc.game.Player;
13 import ru.alphatech.icfpc.game.Run;
14 import ru.alphatech.icfpc.game.Slot;
15 import ru.alphatech.icfpc.game.Value;
16 import ru.alphatech.icfpc.game.Batch.OperationType;
25 public abstract class AbstractPolicy {
27 protected ArrayList<Batch> batches = new ArrayList<Batch>();
29 public AbstractPolicy(){
32 public void setRegister(int registerIndex, int num ){
33 if( registerIndex < 4) {
34 Slot registerSlot = Run.getRegisterByIndex(registerIndex);
35 batches.addAll( numberIntoSlotField( registerSlot, num ) );
39 protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
41 ArrayList<Batch> retArray = new ArrayList<Batch>();
43 IValue targetValue = targetSlot.getValue();
45 if(targetValue instanceof ICard){
46 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
49 Value numTargetValue = (Value) targetValue;
50 if( numTargetValue.getValue() == number ){
53 if( numTargetValue.getValue() > number ){
54 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
55 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
56 stupidAlg(0, number, targetSlot);
58 stupidAlg(numTargetValue.getValue(), number, targetSlot);
65 protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
66 ArrayList<Batch> retArray = new ArrayList<Batch>();
67 while( begin*2 < end){
68 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
72 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
78 protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
79 ArrayList<Batch> retArray = new ArrayList<Batch>();
80 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
81 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
85 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
87 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
88 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
95 public abstract ArrayList<Batch> getBatches();