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.Slot;
14 import ru.alphatech.icfpc.game.Value;
15 import ru.alphatech.icfpc.game.Batch.OperationType;
24 public abstract class AbstractPolicy {
26 protected Player player = null;
28 protected ArrayList<Batch> batches = new ArrayList<Batch>();
30 public AbstractPolicy(Player player){
34 public void setRegister(int registerIndex, int num ){
35 if( registerIndex < 4) {
36 Slot registerSlot = player.getRegisterByIndex(registerIndex);
37 batches.addAll( numberIntoSlotField( registerSlot, num ) );
41 protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
43 ArrayList<Batch> retArray = new ArrayList<Batch>();
45 IValue targetValue = targetSlot.getValue();
47 if(targetValue instanceof ICard){
48 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
51 Value numTargetValue = (Value) targetValue;
52 if( numTargetValue.getValue() == number ){
55 if( numTargetValue.getValue() > number ){
56 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
57 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
58 stupidAlg(0, number, targetSlot);
60 stupidAlg(numTargetValue.getValue(), number, targetSlot);
67 protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
68 ArrayList<Batch> retArray = new ArrayList<Batch>();
69 while( begin*2 < end){
70 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
74 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
80 protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
81 ArrayList<Batch> retArray = new ArrayList<Batch>();
82 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
83 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
87 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
89 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
90 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
97 public abstract ArrayList<Batch> getBatches();