src/main/java/ru/alphatech/icfpc/policy/OneArgumentCardsPolicy.java
changeset 84 f247a56bde48
parent 75 40ad0dd24185
child 85 7292b7aea7e3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/OneArgumentCardsPolicy.java	Sun Jun 19 17:13:33 2011 +0400
     1.3 @@ -0,0 +1,103 @@
     1.4 +package ru.alphatech.icfpc.policy;
     1.5 +
     1.6 +import java.util.ArrayList;
     1.7 +
     1.8 +import ru.alphatech.icfpc.cards.Copy;
     1.9 +import ru.alphatech.icfpc.cards.Dec;
    1.10 +import ru.alphatech.icfpc.cards.Get;
    1.11 +import ru.alphatech.icfpc.cards.ICard;
    1.12 +import ru.alphatech.icfpc.cards.Inc;
    1.13 +import ru.alphatech.icfpc.cards.K;
    1.14 +import ru.alphatech.icfpc.cards.Put;
    1.15 +import ru.alphatech.icfpc.cards.Revive;
    1.16 +import ru.alphatech.icfpc.cards.S;
    1.17 +import ru.alphatech.icfpc.cards.Zero;
    1.18 +import ru.alphatech.icfpc.game.AbstractPolicy;
    1.19 +import ru.alphatech.icfpc.game.Batch;
    1.20 +import ru.alphatech.icfpc.game.IValue;
    1.21 +import ru.alphatech.icfpc.game.Run;
    1.22 +import ru.alphatech.icfpc.game.Slot;
    1.23 +import ru.alphatech.icfpc.game.Value;
    1.24 +import ru.alphatech.icfpc.game.Batch.OperationType;
    1.25 +
    1.26 +public class OneArgumentCardsPolicy extends AbstractPolicy{
    1.27 +	
    1.28 +	public enum TYPE {
    1.29 +		DEC,
    1.30 +		INC,
    1.31 +		COPY,
    1.32 +		REVIVE
    1.33 +	}
    1.34 +	
    1.35 +	private TYPE type;
    1.36 +	private int processingSlotIndex = -1;
    1.37 +	private int registerIndex = -1;
    1.38 +	private int targetSlotIndex = -1;
    1.39 +	
    1.40 +	
    1.41 +	public OneArgumentCardsPolicy(TYPE type, int processingSlot, int target) {
    1.42 +		this.type = type;
    1.43 +		this.processingSlotIndex = processingSlot;
    1.44 +		this.targetSlotIndex = target;
    1.45 +	}
    1.46 +	
    1.47 +	public ICard getCard(){
    1.48 +		switch (type) {
    1.49 +			case DEC:
    1.50 +			return new Dec();
    1.51 +			case INC:
    1.52 +			return new Inc();
    1.53 +			case COPY:
    1.54 +			return new Copy();
    1.55 +			case REVIVE:
    1.56 +			return new Revive();
    1.57 +		}
    1.58 +		return null;
    1.59 +	}
    1.60 +	
    1.61 +	protected boolean isEqualsCard(IValue value){
    1.62 +		if(value instanceof IValue)
    1.63 +			return false;
    1.64 +		if( type == TYPE.DEC && value instanceof Dec)
    1.65 +			return true;
    1.66 +		if( type == TYPE.INC && value instanceof Inc)
    1.67 +			return true;
    1.68 +		if( type == TYPE.COPY && value instanceof Copy)
    1.69 +			return true;
    1.70 +		if( type == TYPE.REVIVE && value instanceof Revive)
    1.71 +			return true;
    1.72 +		return false;
    1.73 +	}
    1.74 +
    1.75 +	@Override
    1.76 +	public ArrayList<Batch> getBatches() {
    1.77 +		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.78 +		
    1.79 +		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex));
    1.80 +		
    1.81 +		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
    1.82 +		IValue slotValue = processingSlot.getValue();
    1.83 +		
    1.84 +		if(slotValue instanceof Value){
    1.85 +			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
    1.86 +			retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
    1.87 +		}else{
    1.88 +			ICard currentCard = (ICard) slotValue;
    1.89 +			if(!(currentCard instanceof Dec && type == TYPE.DEC) || 
    1.90 +			   !(currentCard instanceof Inc && type == TYPE.INC))
    1.91 +			{
    1.92 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
    1.93 +				retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
    1.94 +			}
    1.95 +		}
    1.96 +		
    1.97 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.98 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.99 +		
   1.100 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   1.101 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   1.102 +		
   1.103 +		return retArray;
   1.104 +	}
   1.105 +	
   1.106 +}