|
akhmetovlz@52
|
1 |
package ru.alphatech.icfpc.game;
|
|
akhmetovlz@51
|
2 |
|
|
akhmetovlz@51
|
3 |
import java.util.ArrayList;
|
|
akhmetovlz@51
|
4 |
|
|
akhmetovlz@62
|
5 |
import ru.alphatech.icfpc.cards.Attack;
|
|
akhmetovlz@51
|
6 |
import ru.alphatech.icfpc.cards.Dbl;
|
|
akhmetovlz@62
|
7 |
import ru.alphatech.icfpc.cards.Get;
|
|
akhmetovlz@62
|
8 |
import ru.alphatech.icfpc.cards.Help;
|
|
akhmetovlz@51
|
9 |
import ru.alphatech.icfpc.cards.ICard;
|
|
akhmetovlz@62
|
10 |
import ru.alphatech.icfpc.cards.K;
|
|
akhmetovlz@51
|
11 |
import ru.alphatech.icfpc.cards.Put;
|
|
akhmetovlz@62
|
12 |
import ru.alphatech.icfpc.cards.S;
|
|
akhmetovlz@51
|
13 |
import ru.alphatech.icfpc.cards.Succ;
|
|
akhmetovlz@51
|
14 |
import ru.alphatech.icfpc.cards.Zero;
|
|
akhmetovlz@52
|
15 |
import ru.alphatech.icfpc.game.Batch.OperationType;
|
|
akhmetovlz@51
|
16 |
|
|
akhmetovlz@51
|
17 |
/**
|
|
akhmetovlz@51
|
18 |
*
|
|
akhmetovlz@51
|
19 |
* TODO
|
|
akhmetovlz@51
|
20 |
*
|
|
akhmetovlz@51
|
21 |
* @author akhmetovlz
|
|
akhmetovlz@51
|
22 |
*
|
|
akhmetovlz@51
|
23 |
*/
|
|
akhmetovlz@51
|
24 |
public abstract class AbstractPolicy {
|
|
akhmetovlz@51
|
25 |
|
|
akhmetovlz@51
|
26 |
protected ArrayList<Batch> batches = new ArrayList<Batch>();
|
|
akhmetovlz@51
|
27 |
|
|
akhmetovlz@51
|
28 |
public AbstractPolicy(){
|
|
akhmetovlz@51
|
29 |
}
|
|
akhmetovlz@51
|
30 |
|
|
akhmetovlz@51
|
31 |
public void setRegister(int registerIndex, int num ){
|
|
akhmetovlz@51
|
32 |
if( registerIndex < 4) {
|
|
akhmetovlz@51
|
33 |
Slot registerSlot = Run.getRegisterByIndex(registerIndex);
|
|
akhmetovlz@51
|
34 |
batches.addAll( numberIntoSlotField( registerSlot, num ) );
|
|
akhmetovlz@51
|
35 |
}
|
|
akhmetovlz@51
|
36 |
}
|
|
akhmetovlz@51
|
37 |
|
|
akhmetovlz@51
|
38 |
protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
|
|
akhmetovlz@51
|
39 |
{
|
|
akhmetovlz@51
|
40 |
ArrayList<Batch> retArray = new ArrayList<Batch>();
|
|
akhmetovlz@51
|
41 |
|
|
akhmetovlz@51
|
42 |
IValue targetValue = targetSlot.getValue();
|
|
akhmetovlz@51
|
43 |
|
|
akhmetovlz@51
|
44 |
if(targetValue instanceof ICard){
|
|
akhmetovlz@51
|
45 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
|
|
akhmetovlz@51
|
46 |
}
|
|
akhmetovlz@51
|
47 |
|
|
akhmetovlz@51
|
48 |
Value numTargetValue = (Value) targetValue;
|
|
akhmetovlz@51
|
49 |
if( numTargetValue.getValue() == number ){
|
|
akhmetovlz@51
|
50 |
return retArray;
|
|
akhmetovlz@51
|
51 |
}else
|
|
akhmetovlz@51
|
52 |
if( numTargetValue.getValue() > number ){
|
|
akhmetovlz@51
|
53 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
|
|
akhmetovlz@51
|
54 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
|
|
akhmetovlz@51
|
55 |
stupidAlg(0, number, targetSlot);
|
|
akhmetovlz@51
|
56 |
}else{
|
|
akhmetovlz@51
|
57 |
stupidAlg(numTargetValue.getValue(), number, targetSlot);
|
|
akhmetovlz@51
|
58 |
}
|
|
akhmetovlz@51
|
59 |
|
|
akhmetovlz@51
|
60 |
return retArray;
|
|
akhmetovlz@51
|
61 |
}
|
|
akhmetovlz@51
|
62 |
|
|
akhmetovlz@51
|
63 |
|
|
akhmetovlz@51
|
64 |
protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
|
|
akhmetovlz@51
|
65 |
ArrayList<Batch> retArray = new ArrayList<Batch>();
|
|
akhmetovlz@51
|
66 |
while( begin*2 < end){
|
|
akhmetovlz@51
|
67 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
|
|
akhmetovlz@51
|
68 |
begin *= 2;
|
|
akhmetovlz@51
|
69 |
}
|
|
akhmetovlz@51
|
70 |
while( begin != end){
|
|
akhmetovlz@51
|
71 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
|
|
akhmetovlz@51
|
72 |
begin ++;
|
|
akhmetovlz@51
|
73 |
}
|
|
akhmetovlz@51
|
74 |
return retArray;
|
|
akhmetovlz@51
|
75 |
}
|
|
akhmetovlz@51
|
76 |
|
|
akhmetovlz@51
|
77 |
protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
|
|
akhmetovlz@51
|
78 |
ArrayList<Batch> retArray = new ArrayList<Batch>();
|
|
akhmetovlz@51
|
79 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
|
|
akhmetovlz@51
|
80 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
|
|
akhmetovlz@51
|
81 |
while(end >= 2){
|
|
akhmetovlz@51
|
82 |
int d = end % 2;
|
|
akhmetovlz@51
|
83 |
if( d == 0 ) {
|
|
akhmetovlz@51
|
84 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
|
|
akhmetovlz@51
|
85 |
} else {
|
|
akhmetovlz@51
|
86 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
|
|
akhmetovlz@51
|
87 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
|
|
akhmetovlz@51
|
88 |
}
|
|
akhmetovlz@51
|
89 |
end = end / 2;
|
|
akhmetovlz@51
|
90 |
}
|
|
akhmetovlz@51
|
91 |
return retArray;
|
|
akhmetovlz@51
|
92 |
}
|
|
akhmetovlz@51
|
93 |
|
|
akhmetovlz@51
|
94 |
public abstract ArrayList<Batch> getBatches();
|
|
akhmetovlz@51
|
95 |
}
|