akhmetovlz@75: package ru.alphatech.icfpc.policy; akhmetovlz@75: akhmetovlz@75: import java.util.ArrayList; akhmetovlz@75: akhmetovlz@75: import ru.alphatech.icfpc.cards.Dec; akhmetovlz@75: import ru.alphatech.icfpc.cards.Get; akhmetovlz@75: import ru.alphatech.icfpc.cards.ICard; akhmetovlz@75: import ru.alphatech.icfpc.cards.Inc; akhmetovlz@75: import ru.alphatech.icfpc.cards.K; akhmetovlz@75: import ru.alphatech.icfpc.cards.Put; akhmetovlz@75: import ru.alphatech.icfpc.cards.S; akhmetovlz@75: import ru.alphatech.icfpc.cards.Zero; akhmetovlz@75: import ru.alphatech.icfpc.game.AbstractPolicy; akhmetovlz@75: import ru.alphatech.icfpc.game.Batch; akhmetovlz@75: import ru.alphatech.icfpc.game.IValue; akhmetovlz@75: import ru.alphatech.icfpc.game.Run; akhmetovlz@75: import ru.alphatech.icfpc.game.Slot; akhmetovlz@75: import ru.alphatech.icfpc.game.Value; akhmetovlz@75: import ru.alphatech.icfpc.game.Batch.OperationType; akhmetovlz@75: akhmetovlz@75: public class DecIncPolicy extends AbstractPolicy{ akhmetovlz@75: akhmetovlz@75: public enum TYPE { akhmetovlz@75: DEC, akhmetovlz@75: INC akhmetovlz@75: } akhmetovlz@75: akhmetovlz@75: private TYPE type; akhmetovlz@75: private int processingSlotIndex = -1; akhmetovlz@75: private int targetSlotIndex = -1; akhmetovlz@75: akhmetovlz@75: akhmetovlz@75: public DecIncPolicy(TYPE type, int processingSlot, int target) { akhmetovlz@75: this.type = type; akhmetovlz@75: this.processingSlotIndex = processingSlot; akhmetovlz@75: this.targetSlotIndex = target; akhmetovlz@75: } akhmetovlz@75: akhmetovlz@75: public ICard getCard(){ akhmetovlz@75: return type == TYPE.DEC ? new Dec() : new Inc(); akhmetovlz@75: } akhmetovlz@75: akhmetovlz@75: @Override akhmetovlz@75: public ArrayList getBatches() { akhmetovlz@75: ArrayList retArray = new ArrayList(); akhmetovlz@75: akhmetovlz@75: retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex)); akhmetovlz@75: akhmetovlz@75: Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex); akhmetovlz@75: IValue slotValue = processingSlot.getValue(); akhmetovlz@75: akhmetovlz@75: if(slotValue instanceof Value){ akhmetovlz@75: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); akhmetovlz@75: retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot)); akhmetovlz@75: }else{ akhmetovlz@75: ICard currentCard = (ICard) slotValue; akhmetovlz@75: if(!(currentCard instanceof Dec && type == TYPE.DEC) || akhmetovlz@75: !(currentCard instanceof Inc && type == TYPE.INC)) akhmetovlz@75: { akhmetovlz@75: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); akhmetovlz@75: retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot)); akhmetovlz@75: } akhmetovlz@75: } akhmetovlz@75: akhmetovlz@75: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); akhmetovlz@75: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); akhmetovlz@75: akhmetovlz@75: retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); akhmetovlz@75: retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); akhmetovlz@75: akhmetovlz@75: return retArray; akhmetovlz@75: } akhmetovlz@75: akhmetovlz@75: }