Мего метод.
1 package ru.alphatech.icfpc.game;
3 import java.util.ArrayList;
5 import ru.alphatech.icfpc.cards.Attack;
6 import ru.alphatech.icfpc.cards.Dbl;
7 import ru.alphatech.icfpc.cards.Get;
8 import ru.alphatech.icfpc.cards.Help;
9 import ru.alphatech.icfpc.cards.ICard;
10 import ru.alphatech.icfpc.cards.K;
11 import ru.alphatech.icfpc.cards.Put;
12 import ru.alphatech.icfpc.cards.S;
13 import ru.alphatech.icfpc.cards.Succ;
14 import ru.alphatech.icfpc.cards.Zero;
15 import ru.alphatech.icfpc.game.Batch.OperationType;
24 public abstract class AbstractPolicy {
26 protected ArrayList<Batch> batches = new ArrayList<Batch>();
28 public AbstractPolicy(){
31 public void setRegister(int registerIndex, int num ){
32 if( registerIndex < 4) {
33 Slot registerSlot = Run.getRegisterByIndex(registerIndex);
34 batches.addAll( numberIntoSlotField( registerSlot, num ) );
38 protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
40 ArrayList<Batch> retArray = new ArrayList<Batch>();
42 IValue targetValue = targetSlot.getValue();
44 if(targetValue instanceof ICard){
45 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
48 Value numTargetValue = (Value) targetValue;
49 if( numTargetValue.getValue() == number ){
52 if( numTargetValue.getValue() > number ){
53 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
54 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
55 stupidAlg(0, number, targetSlot);
57 stupidAlg(numTargetValue.getValue(), number, targetSlot);
64 protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
65 ArrayList<Batch> retArray = new ArrayList<Batch>();
66 while( begin*2 < end){
67 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
71 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
77 protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
78 ArrayList<Batch> retArray = new ArrayList<Batch>();
79 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
80 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
84 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
86 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
87 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
94 protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){
95 ArrayList<Batch> retArray = new ArrayList<Batch>();
97 if(!(function instanceof Attack || function instanceof Help)){
98 throw new ICFPCException();
101 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
102 retArray.add(new Batch(OperationType.SLOT_TO_CARD, function, processingSlot));
104 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
105 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
107 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
109 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
110 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
112 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
114 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
115 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
117 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
119 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
120 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
122 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
124 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
125 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
127 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
129 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
130 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
132 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
134 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
135 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
137 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
139 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
140 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
142 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
144 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
145 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
147 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
152 public abstract ArrayList<Batch> getBatches();