|
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@62
|
94 |
protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){
|
|
akhmetovlz@62
|
95 |
ArrayList<Batch> retArray = new ArrayList<Batch>();
|
|
akhmetovlz@62
|
96 |
|
|
akhmetovlz@62
|
97 |
if(!(function instanceof Attack || function instanceof Help)){
|
|
akhmetovlz@62
|
98 |
throw new ICFPCException();
|
|
akhmetovlz@62
|
99 |
}
|
|
akhmetovlz@62
|
100 |
|
|
akhmetovlz@62
|
101 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
|
|
akhmetovlz@62
|
102 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, function, processingSlot));
|
|
akhmetovlz@62
|
103 |
|
|
akhmetovlz@62
|
104 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
105 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
106 |
|
|
akhmetovlz@62
|
107 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@62
|
108 |
|
|
akhmetovlz@62
|
109 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
110 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
111 |
|
|
akhmetovlz@62
|
112 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@62
|
113 |
|
|
akhmetovlz@62
|
114 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
115 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
116 |
|
|
akhmetovlz@62
|
117 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@62
|
118 |
|
|
akhmetovlz@62
|
119 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
120 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
121 |
|
|
akhmetovlz@62
|
122 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
|
|
akhmetovlz@62
|
123 |
|
|
akhmetovlz@62
|
124 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
125 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
126 |
|
|
akhmetovlz@62
|
127 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@62
|
128 |
|
|
akhmetovlz@62
|
129 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
130 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
131 |
|
|
akhmetovlz@62
|
132 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@62
|
133 |
|
|
akhmetovlz@62
|
134 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
135 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
136 |
|
|
akhmetovlz@62
|
137 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
|
|
akhmetovlz@62
|
138 |
|
|
akhmetovlz@62
|
139 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
140 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
141 |
|
|
akhmetovlz@62
|
142 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
|
|
akhmetovlz@62
|
143 |
|
|
akhmetovlz@62
|
144 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@62
|
145 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@62
|
146 |
|
|
akhmetovlz@62
|
147 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@62
|
148 |
|
|
akhmetovlz@62
|
149 |
return retArray;
|
|
akhmetovlz@62
|
150 |
}
|
|
akhmetovlz@62
|
151 |
|
|
akhmetovlz@51
|
152 |
public abstract ArrayList<Batch> getBatches();
|
|
akhmetovlz@51
|
153 |
}
|