# HG changeset patch # User akhmetovlz # Date 1308487921 -14400 # Node ID 40ad0dd24185e9f04d785b3e8dcb30b2a87d28c1 # Parent 50ef27b8b7dc5a1b9ad2bc817830f153c8719d59 (no commit message) diff -r 50ef27b8b7dc -r 40ad0dd24185 src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java Sun Jun 19 16:52:01 2011 +0400 @@ -0,0 +1,74 @@ +package ru.alphatech.icfpc.policy; + +import java.util.ArrayList; + +import ru.alphatech.icfpc.cards.Dec; +import ru.alphatech.icfpc.cards.Get; +import ru.alphatech.icfpc.cards.ICard; +import ru.alphatech.icfpc.cards.Inc; +import ru.alphatech.icfpc.cards.K; +import ru.alphatech.icfpc.cards.Put; +import ru.alphatech.icfpc.cards.S; +import ru.alphatech.icfpc.cards.Zero; +import ru.alphatech.icfpc.game.AbstractPolicy; +import ru.alphatech.icfpc.game.Batch; +import ru.alphatech.icfpc.game.IValue; +import ru.alphatech.icfpc.game.Run; +import ru.alphatech.icfpc.game.Slot; +import ru.alphatech.icfpc.game.Value; +import ru.alphatech.icfpc.game.Batch.OperationType; + +public class DecIncPolicy extends AbstractPolicy{ + + public enum TYPE { + DEC, + INC + } + + private TYPE type; + private int processingSlotIndex = -1; + private int targetSlotIndex = -1; + + + public DecIncPolicy(TYPE type, int processingSlot, int target) { + this.type = type; + this.processingSlotIndex = processingSlot; + this.targetSlotIndex = target; + } + + public ICard getCard(){ + return type == TYPE.DEC ? new Dec() : new Inc(); + } + + @Override + public ArrayList getBatches() { + ArrayList retArray = new ArrayList(); + + retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex)); + + Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex); + IValue slotValue = processingSlot.getValue(); + + if(slotValue instanceof Value){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot)); + }else{ + ICard currentCard = (ICard) slotValue; + if(!(currentCard instanceof Dec && type == TYPE.DEC) || + !(currentCard instanceof Inc && type == TYPE.INC)) + { + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot)); + } + } + + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); + + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); + + return retArray; + } + +}