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, int registerIndex) {
40 this.processingSlotIndex = processingSlot;
41 this.targetSlotIndex = target;
42 this.registerIndex = registerIndex;
45 public ICard getCard(){
59 protected boolean isEqualsCard(IValue value){
60 if(value instanceof IValue)
62 if( type == TYPE.DEC && value instanceof Dec)
64 if( type == TYPE.INC && value instanceof Inc)
66 if( type == TYPE.COPY && value instanceof Copy)
68 if( type == TYPE.REVIVE && value instanceof Revive)
74 public ArrayList<Batch> getBatches() {
75 ArrayList<Batch> retArray = new ArrayList<Batch>();
77 retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(registerIndex), targetSlotIndex));
79 Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
80 IValue slotValue = processingSlot.getValue();
82 if(slotValue instanceof Value){
83 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
84 retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
86 ICard currentCard = (ICard) slotValue;
87 if(!(currentCard instanceof Dec && type == TYPE.DEC) ||
88 !(currentCard instanceof Inc && type == TYPE.INC))
90 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
91 retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
95 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
96 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
98 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
99 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));