|
akhmetovlz@75
|
1 |
package ru.alphatech.icfpc.policy;
|
|
akhmetovlz@75
|
2 |
|
|
akhmetovlz@75
|
3 |
import java.util.ArrayList;
|
|
akhmetovlz@75
|
4 |
|
|
akhmetovlz@84
|
5 |
import ru.alphatech.icfpc.cards.Copy;
|
|
akhmetovlz@75
|
6 |
import ru.alphatech.icfpc.cards.Dec;
|
|
akhmetovlz@75
|
7 |
import ru.alphatech.icfpc.cards.Get;
|
|
akhmetovlz@75
|
8 |
import ru.alphatech.icfpc.cards.ICard;
|
|
akhmetovlz@75
|
9 |
import ru.alphatech.icfpc.cards.Inc;
|
|
akhmetovlz@75
|
10 |
import ru.alphatech.icfpc.cards.K;
|
|
akhmetovlz@75
|
11 |
import ru.alphatech.icfpc.cards.Put;
|
|
akhmetovlz@84
|
12 |
import ru.alphatech.icfpc.cards.Revive;
|
|
akhmetovlz@75
|
13 |
import ru.alphatech.icfpc.cards.S;
|
|
akhmetovlz@75
|
14 |
import ru.alphatech.icfpc.cards.Zero;
|
|
akhmetovlz@75
|
15 |
import ru.alphatech.icfpc.game.AbstractPolicy;
|
|
akhmetovlz@75
|
16 |
import ru.alphatech.icfpc.game.Batch;
|
|
akhmetovlz@75
|
17 |
import ru.alphatech.icfpc.game.IValue;
|
|
akhmetovlz@75
|
18 |
import ru.alphatech.icfpc.game.Run;
|
|
akhmetovlz@75
|
19 |
import ru.alphatech.icfpc.game.Slot;
|
|
akhmetovlz@75
|
20 |
import ru.alphatech.icfpc.game.Value;
|
|
akhmetovlz@75
|
21 |
import ru.alphatech.icfpc.game.Batch.OperationType;
|
|
akhmetovlz@75
|
22 |
|
|
akhmetovlz@84
|
23 |
public class OneArgumentCardsPolicy extends AbstractPolicy{
|
|
akhmetovlz@75
|
24 |
|
|
akhmetovlz@75
|
25 |
public enum TYPE {
|
|
akhmetovlz@75
|
26 |
DEC,
|
|
akhmetovlz@84
|
27 |
INC,
|
|
akhmetovlz@84
|
28 |
COPY,
|
|
akhmetovlz@84
|
29 |
REVIVE
|
|
akhmetovlz@75
|
30 |
}
|
|
akhmetovlz@75
|
31 |
|
|
akhmetovlz@75
|
32 |
private TYPE type;
|
|
akhmetovlz@75
|
33 |
private int processingSlotIndex = -1;
|
|
akhmetovlz@84
|
34 |
private int registerIndex = -1;
|
|
akhmetovlz@75
|
35 |
private int targetSlotIndex = -1;
|
|
akhmetovlz@75
|
36 |
|
|
akhmetovlz@75
|
37 |
|
|
akhmetovlz@84
|
38 |
public OneArgumentCardsPolicy(TYPE type, int processingSlot, int target) {
|
|
akhmetovlz@75
|
39 |
this.type = type;
|
|
akhmetovlz@75
|
40 |
this.processingSlotIndex = processingSlot;
|
|
akhmetovlz@75
|
41 |
this.targetSlotIndex = target;
|
|
akhmetovlz@75
|
42 |
}
|
|
akhmetovlz@75
|
43 |
|
|
akhmetovlz@75
|
44 |
public ICard getCard(){
|
|
akhmetovlz@84
|
45 |
switch (type) {
|
|
akhmetovlz@84
|
46 |
case DEC:
|
|
akhmetovlz@84
|
47 |
return new Dec();
|
|
akhmetovlz@84
|
48 |
case INC:
|
|
akhmetovlz@84
|
49 |
return new Inc();
|
|
akhmetovlz@84
|
50 |
case COPY:
|
|
akhmetovlz@84
|
51 |
return new Copy();
|
|
akhmetovlz@84
|
52 |
case REVIVE:
|
|
akhmetovlz@84
|
53 |
return new Revive();
|
|
akhmetovlz@84
|
54 |
}
|
|
akhmetovlz@84
|
55 |
return null;
|
|
akhmetovlz@84
|
56 |
}
|
|
akhmetovlz@84
|
57 |
|
|
akhmetovlz@84
|
58 |
protected boolean isEqualsCard(IValue value){
|
|
akhmetovlz@84
|
59 |
if(value instanceof IValue)
|
|
akhmetovlz@84
|
60 |
return false;
|
|
akhmetovlz@84
|
61 |
if( type == TYPE.DEC && value instanceof Dec)
|
|
akhmetovlz@84
|
62 |
return true;
|
|
akhmetovlz@84
|
63 |
if( type == TYPE.INC && value instanceof Inc)
|
|
akhmetovlz@84
|
64 |
return true;
|
|
akhmetovlz@84
|
65 |
if( type == TYPE.COPY && value instanceof Copy)
|
|
akhmetovlz@84
|
66 |
return true;
|
|
akhmetovlz@84
|
67 |
if( type == TYPE.REVIVE && value instanceof Revive)
|
|
akhmetovlz@84
|
68 |
return true;
|
|
akhmetovlz@84
|
69 |
return false;
|
|
akhmetovlz@75
|
70 |
}
|
|
akhmetovlz@75
|
71 |
|
|
akhmetovlz@75
|
72 |
@Override
|
|
akhmetovlz@75
|
73 |
public ArrayList<Batch> getBatches() {
|
|
akhmetovlz@75
|
74 |
ArrayList<Batch> retArray = new ArrayList<Batch>();
|
|
akhmetovlz@75
|
75 |
|
|
akhmetovlz@75
|
76 |
retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex));
|
|
akhmetovlz@75
|
77 |
|
|
akhmetovlz@75
|
78 |
Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
|
|
akhmetovlz@75
|
79 |
IValue slotValue = processingSlot.getValue();
|
|
akhmetovlz@75
|
80 |
|
|
akhmetovlz@75
|
81 |
if(slotValue instanceof Value){
|
|
akhmetovlz@75
|
82 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
|
|
akhmetovlz@75
|
83 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
|
|
akhmetovlz@75
|
84 |
}else{
|
|
akhmetovlz@75
|
85 |
ICard currentCard = (ICard) slotValue;
|
|
akhmetovlz@75
|
86 |
if(!(currentCard instanceof Dec && type == TYPE.DEC) ||
|
|
akhmetovlz@75
|
87 |
!(currentCard instanceof Inc && type == TYPE.INC))
|
|
akhmetovlz@75
|
88 |
{
|
|
akhmetovlz@75
|
89 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
|
|
akhmetovlz@75
|
90 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
|
|
akhmetovlz@75
|
91 |
}
|
|
akhmetovlz@75
|
92 |
}
|
|
akhmetovlz@75
|
93 |
|
|
akhmetovlz@75
|
94 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
|
|
akhmetovlz@75
|
95 |
retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
|
|
akhmetovlz@75
|
96 |
|
|
akhmetovlz@75
|
97 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
|
|
akhmetovlz@75
|
98 |
retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
|
|
akhmetovlz@75
|
99 |
|
|
akhmetovlz@75
|
100 |
return retArray;
|
|
akhmetovlz@75
|
101 |
}
|
|
akhmetovlz@75
|
102 |
|
|
akhmetovlz@75
|
103 |
}
|