1 package ru.alphatech.icfpc.policy;
3 import java.util.ArrayList;
5 import ru.alphatech.icfpc.cards.Copy;
6 import ru.alphatech.icfpc.cards.Dec;
7 import ru.alphatech.icfpc.cards.Get;
8 import ru.alphatech.icfpc.cards.ICard;
9 import ru.alphatech.icfpc.cards.Inc;
10 import ru.alphatech.icfpc.cards.K;
11 import ru.alphatech.icfpc.cards.Put;
12 import ru.alphatech.icfpc.cards.Revive;
13 import ru.alphatech.icfpc.cards.S;
14 import ru.alphatech.icfpc.cards.Zero;
15 import ru.alphatech.icfpc.game.AbstractPolicy;
16 import ru.alphatech.icfpc.game.Batch;
17 import ru.alphatech.icfpc.game.IValue;
18 import ru.alphatech.icfpc.game.Run;
19 import ru.alphatech.icfpc.game.Slot;
20 import ru.alphatech.icfpc.game.Value;
21 import ru.alphatech.icfpc.game.Batch.OperationType;
23 public class OneArgumentCardsPolicy extends AbstractPolicy{
33 private int processingSlotIndex = -1;
34 private int registerIndex = -1;
35 private int targetSlotIndex = -1;
38 public OneArgumentCardsPolicy(TYPE type, int processingSlot, int target) {
40 this.processingSlotIndex = processingSlot;
41 this.targetSlotIndex = target;
44 public ICard getCard(){
58 protected boolean isEqualsCard(IValue value){
59 if(value instanceof IValue)
61 if( type == TYPE.DEC && value instanceof Dec)
63 if( type == TYPE.INC && value instanceof Inc)
65 if( type == TYPE.COPY && value instanceof Copy)
67 if( type == TYPE.REVIVE && value instanceof Revive)
73 public ArrayList<Batch> getBatches() {
74 ArrayList<Batch> retArray = new ArrayList<Batch>();
76 retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex));
78 Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
79 IValue slotValue = processingSlot.getValue();
81 if(slotValue instanceof Value){
82 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
83 retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
85 ICard currentCard = (ICard) slotValue;
86 if(!(currentCard instanceof Dec && type == TYPE.DEC) ||
87 !(currentCard instanceof Inc && type == TYPE.INC))
89 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
90 retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
94 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
95 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
97 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
98 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));