akhmetovlz@75: package ru.alphatech.icfpc.policy; akhmetovlz@75: akhmetovlz@75: import java.util.ArrayList; akhmetovlz@75: akhmetovlz@84: import ru.alphatech.icfpc.cards.Copy; 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@84: import ru.alphatech.icfpc.cards.Revive; 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@84: public class OneArgumentCardsPolicy extends AbstractPolicy{ akhmetovlz@75: akhmetovlz@75: public enum TYPE { akhmetovlz@75: DEC, akhmetovlz@84: INC, akhmetovlz@84: COPY, akhmetovlz@84: REVIVE akhmetovlz@75: } akhmetovlz@75: akhmetovlz@75: private TYPE type; akhmetovlz@75: private int processingSlotIndex = -1; akhmetovlz@84: private int registerIndex = -1; akhmetovlz@75: private int targetSlotIndex = -1; akhmetovlz@75: akhmetovlz@75: akhmetovlz@84: public OneArgumentCardsPolicy(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@84: switch (type) { akhmetovlz@84: case DEC: akhmetovlz@84: return new Dec(); akhmetovlz@84: case INC: akhmetovlz@84: return new Inc(); akhmetovlz@84: case COPY: akhmetovlz@84: return new Copy(); akhmetovlz@84: case REVIVE: akhmetovlz@84: return new Revive(); akhmetovlz@84: } akhmetovlz@84: return null; akhmetovlz@84: } akhmetovlz@84: akhmetovlz@84: protected boolean isEqualsCard(IValue value){ akhmetovlz@84: if(value instanceof IValue) akhmetovlz@84: return false; akhmetovlz@84: if( type == TYPE.DEC && value instanceof Dec) akhmetovlz@84: return true; akhmetovlz@84: if( type == TYPE.INC && value instanceof Inc) akhmetovlz@84: return true; akhmetovlz@84: if( type == TYPE.COPY && value instanceof Copy) akhmetovlz@84: return true; akhmetovlz@84: if( type == TYPE.REVIVE && value instanceof Revive) akhmetovlz@84: return true; akhmetovlz@84: return false; 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: }