|
akhmetovlz@70
|
1 |
package ru.alphatech.icfpc.policy;
|
|
akhmetovlz@70
|
2 |
|
|
akhmetovlz@70
|
3 |
import java.util.ArrayList;
|
|
akhmetovlz@70
|
4 |
|
|
akhmetovlz@70
|
5 |
import ru.alphatech.icfpc.cards.Attack;
|
|
akhmetovlz@70
|
6 |
import ru.alphatech.icfpc.cards.Get;
|
|
akhmetovlz@70
|
7 |
import ru.alphatech.icfpc.cards.Help;
|
|
akhmetovlz@70
|
8 |
import ru.alphatech.icfpc.cards.ICard;
|
|
akhmetovlz@70
|
9 |
import ru.alphatech.icfpc.cards.K;
|
|
akhmetovlz@70
|
10 |
import ru.alphatech.icfpc.cards.Put;
|
|
akhmetovlz@70
|
11 |
import ru.alphatech.icfpc.cards.S;
|
|
akhmetovlz@70
|
12 |
import ru.alphatech.icfpc.cards.Succ;
|
|
akhmetovlz@70
|
13 |
import ru.alphatech.icfpc.cards.Zero;
|
|
akhmetovlz@70
|
14 |
import ru.alphatech.icfpc.game.AbstractPolicy;
|
|
akhmetovlz@70
|
15 |
import ru.alphatech.icfpc.game.Batch;
|
|
akhmetovlz@70
|
16 |
import ru.alphatech.icfpc.game.ICFPCException;
|
|
akhmetovlz@70
|
17 |
import ru.alphatech.icfpc.game.Run;
|
|
akhmetovlz@70
|
18 |
import ru.alphatech.icfpc.game.Slot;
|
|
akhmetovlz@70
|
19 |
import ru.alphatech.icfpc.game.Batch.OperationType;
|
|
akhmetovlz@70
|
20 |
|
|
akhmetovlz@70
|
21 |
public class AttackHelpPolicy extends AbstractPolicy {
|
|
akhmetovlz@70
|
22 |
|
|
akhmetovlz@70
|
23 |
private int donorSlotIndex = -1;
|
|
akhmetovlz@70
|
24 |
private int targetSlotIndex = -1;
|
|
akhmetovlz@70
|
25 |
private int pointsSlotIndex = -1;
|
|
akhmetovlz@70
|
26 |
private int processingSlotIndex = -1;
|
|
akhmetovlz@101
|
27 |
private boolean execute = false;
|
|
akhmetovlz@70
|
28 |
|
|
akhmetovlz@70
|
29 |
private TYPE type;
|
|
akhmetovlz@70
|
30 |
|
|
akhmetovlz@70
|
31 |
public enum TYPE {
|
|
akhmetovlz@70
|
32 |
ATTACK,
|
|
akhmetovlz@70
|
33 |
HELP
|
|
akhmetovlz@70
|
34 |
}
|
|
akhmetovlz@70
|
35 |
|
|
akhmetovlz@70
|
36 |
/**
|
|
akhmetovlz@101
|
37 |
* @param type - ATTACK or HELP
|
|
akhmetovlz@70
|
38 |
* @param processingSlot - в какой ячейке проводить
|
|
akhmetovlz@70
|
39 |
* @param donor - от кого забирать хп
|
|
akhmetovlz@70
|
40 |
* @param target - слот который надо атаковать
|
|
akhmetovlz@70
|
41 |
* @param points - количество хп отнимаемое у донора
|
|
akhmetovlz@101
|
42 |
* @param execute - выполнить после завершения либо просто сохранить в слоте.
|
|
akhmetovlz@70
|
43 |
*/
|
|
akhmetovlz@101
|
44 |
public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points, boolean execute) {
|
|
akhmetovlz@70
|
45 |
this.donorSlotIndex = donor;
|
|
akhmetovlz@70
|
46 |
this.targetSlotIndex = target;
|
|
akhmetovlz@70
|
47 |
this.pointsSlotIndex = points;
|
|
akhmetovlz@70
|
48 |
this.processingSlotIndex = processingSlot;
|
|
akhmetovlz@101
|
49 |
this.execute = execute;
|
|
akhmetovlz@70
|
50 |
|
|
akhmetovlz@70
|
51 |
this.type = type;
|
|
akhmetovlz@70
|
52 |
}
|
|
akhmetovlz@70
|
53 |
|
|
akhmetovlz@70
|
54 |
@Override
|
|
akhmetovlz@70
|
55 |
public ArrayList<Batch> getBatches() {
|
|
akhmetovlz@70
|
56 |
ArrayList<Batch> retArray = new ArrayList<Batch>();
|
|
akhmetovlz@70
|
57 |
|
|
akhmetovlz@70
|
58 |
Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
|
|
akhmetovlz@70
|
59 |
|
|
akhmetovlz@101
|
60 |
retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), donorSlotIndex));
|
|
akhmetovlz@101
|
61 |
retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(1), targetSlotIndex));
|
|
akhmetovlz@101
|
62 |
retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(2), pointsSlotIndex));
|
|
akhmetovlz@70
|
63 |
|
|
akhmetovlz@115
|
64 |
// retArray.addAll(BcombineForFunctWith3ParamsInRegister(getCard(), processingSlot));
|
|
akhmetovlz@115
|
65 |
retArray.addAll(BcombineForFunctWith3ParamsInRegister2(getCard(), processingSlot));
|
|
akhmetovlz@70
|
66 |
|
|
akhmetovlz@70
|
67 |
return retArray;
|
|
akhmetovlz@70
|
68 |
}
|
|
akhmetovlz@70
|
69 |
|
|
akhmetovlz@70
|
70 |
public ICard getCard(){
|
|
akhmetovlz@70
|
71 |
return type == TYPE.ATTACK ? new Attack() : new Help();
|
|
akhmetovlz@70
|
72 |
}
|
|
akhmetovlz@70
|
73 |
|
|
akhmetovlz@115
|
74 |
|
|
akhmetovlz@115
|
75 |
|
|
akhmetovlz@115
|
76 |
/**
|
|
akhmetovlz@115
|
77 |
* С корректировкой регистров
|
|
akhmetovlz@115
|
78 |
* @param function
|
|
akhmetovlz@115
|
79 |
* @param processingSlot
|
|
akhmetovlz@115
|
80 |
* @return
|
|
akhmetovlz@115
|
81 |
*/
|
|
akhmetovlz@115
|
82 |
protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister2(ICard function, Slot processingSlot)
|
|
akhmetovlz@115
|
83 |
{
|
|
akhmetovlz@115
|
84 |
ArrayList<Batch> retArray = new ArrayList<Batch>();
|
|
akhmetovlz@115
|
85 |
|
|
akhmetovlz@115
|
86 |
if(!(function instanceof Attack || function instanceof Help)){
|
|
akhmetovlz@115
|
87 |
throw new ICFPCException();
|
|
akhmetovlz@115
|
88 |
}
|
|
akhmetovlz@115
|
89 |
|
|
akhmetovlz@115
|
90 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
|
|
akhmetovlz@115
|
91 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, function, processingSlot));
|
|
akhmetovlz@115
|
92 |
|
|
akhmetovlz@115
|
93 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@115
|
94 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@115
|
95 |
|
|
akhmetovlz@115
|
96 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@115
|
97 |
|
|
akhmetovlz@115
|
98 |
retArray.addAll(correctRegister(0, processingSlot));
|
|
akhmetovlz@115
|
99 |
|
|
akhmetovlz@115
|
100 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@115
|
101 |
|
|
akhmetovlz@115
|
102 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@115
|
103 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@115
|
104 |
|
|
akhmetovlz@115
|
105 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@115
|
106 |
|
|
akhmetovlz@115
|
107 |
retArray.addAll(correctRegister(1, processingSlot));
|
|
akhmetovlz@115
|
108 |
|
|
akhmetovlz@115
|
109 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@115
|
110 |
|
|
akhmetovlz@115
|
111 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@115
|
112 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@115
|
113 |
|
|
akhmetovlz@115
|
114 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@115
|
115 |
|
|
akhmetovlz@115
|
116 |
retArray.addAll(correctRegister(2, processingSlot));
|
|
akhmetovlz@115
|
117 |
|
|
akhmetovlz@115
|
118 |
if(execute)
|
|
akhmetovlz@115
|
119 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@115
|
120 |
|
|
akhmetovlz@115
|
121 |
return retArray;
|
|
akhmetovlz@115
|
122 |
}
|
|
akhmetovlz@115
|
123 |
|
|
akhmetovlz@115
|
124 |
/***
|
|
akhmetovlz@115
|
125 |
* @deprecated
|
|
akhmetovlz@115
|
126 |
* @param function
|
|
akhmetovlz@115
|
127 |
* @param processingSlot
|
|
akhmetovlz@115
|
128 |
* @return
|
|
akhmetovlz@115
|
129 |
*/
|
|
akhmetovlz@76
|
130 |
protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot)
|
|
akhmetovlz@76
|
131 |
{
|
|
akhmetovlz@70
|
132 |
ArrayList<Batch> retArray = new ArrayList<Batch>();
|
|
akhmetovlz@70
|
133 |
|
|
akhmetovlz@70
|
134 |
if(!(function instanceof Attack || function instanceof Help)){
|
|
akhmetovlz@70
|
135 |
throw new ICFPCException();
|
|
akhmetovlz@70
|
136 |
}
|
|
akhmetovlz@70
|
137 |
|
|
akhmetovlz@70
|
138 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
|
|
akhmetovlz@70
|
139 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, function, processingSlot));
|
|
akhmetovlz@70
|
140 |
|
|
akhmetovlz@70
|
141 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@70
|
142 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@70
|
143 |
|
|
akhmetovlz@70
|
144 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@70
|
145 |
|
|
akhmetovlz@70
|
146 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@70
|
147 |
|
|
akhmetovlz@70
|
148 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@70
|
149 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@70
|
150 |
|
|
akhmetovlz@70
|
151 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@70
|
152 |
|
|
akhmetovlz@70
|
153 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@70
|
154 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@70
|
155 |
|
|
akhmetovlz@70
|
156 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
|
|
akhmetovlz@70
|
157 |
|
|
akhmetovlz@70
|
158 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@70
|
159 |
|
|
akhmetovlz@70
|
160 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@70
|
161 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@70
|
162 |
|
|
akhmetovlz@70
|
163 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@70
|
164 |
|
|
akhmetovlz@70
|
165 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@70
|
166 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@70
|
167 |
|
|
akhmetovlz@70
|
168 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
|
|
akhmetovlz@70
|
169 |
|
|
akhmetovlz@70
|
170 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@70
|
171 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@70
|
172 |
|
|
akhmetovlz@70
|
173 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
|
|
akhmetovlz@70
|
174 |
|
|
akhmetovlz@101
|
175 |
if(execute)
|
|
akhmetovlz@101
|
176 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@70
|
177 |
|
|
akhmetovlz@70
|
178 |
return retArray;
|
|
akhmetovlz@70
|
179 |
}
|
|
akhmetovlz@70
|
180 |
}
|