src/main/java/ru/alphatech/icfpc/policy/OneArgumentCardsPolicy.java
changeset 84 f247a56bde48
parent 75 40ad0dd24185
child 85 7292b7aea7e3
equal deleted inserted replaced
79:0bfd181c663e 84:f247a56bde48
       
     1 package ru.alphatech.icfpc.policy;
       
     2 
       
     3 import java.util.ArrayList;
       
     4 
       
     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;
       
    22 
       
    23 public class OneArgumentCardsPolicy extends AbstractPolicy{
       
    24 	
       
    25 	public enum TYPE {
       
    26 		DEC,
       
    27 		INC,
       
    28 		COPY,
       
    29 		REVIVE
       
    30 	}
       
    31 	
       
    32 	private TYPE type;
       
    33 	private int processingSlotIndex = -1;
       
    34 	private int registerIndex = -1;
       
    35 	private int targetSlotIndex = -1;
       
    36 	
       
    37 	
       
    38 	public OneArgumentCardsPolicy(TYPE type, int processingSlot, int target) {
       
    39 		this.type = type;
       
    40 		this.processingSlotIndex = processingSlot;
       
    41 		this.targetSlotIndex = target;
       
    42 	}
       
    43 	
       
    44 	public ICard getCard(){
       
    45 		switch (type) {
       
    46 			case DEC:
       
    47 			return new Dec();
       
    48 			case INC:
       
    49 			return new Inc();
       
    50 			case COPY:
       
    51 			return new Copy();
       
    52 			case REVIVE:
       
    53 			return new Revive();
       
    54 		}
       
    55 		return null;
       
    56 	}
       
    57 	
       
    58 	protected boolean isEqualsCard(IValue value){
       
    59 		if(value instanceof IValue)
       
    60 			return false;
       
    61 		if( type == TYPE.DEC && value instanceof Dec)
       
    62 			return true;
       
    63 		if( type == TYPE.INC && value instanceof Inc)
       
    64 			return true;
       
    65 		if( type == TYPE.COPY && value instanceof Copy)
       
    66 			return true;
       
    67 		if( type == TYPE.REVIVE && value instanceof Revive)
       
    68 			return true;
       
    69 		return false;
       
    70 	}
       
    71 
       
    72 	@Override
       
    73 	public ArrayList<Batch> getBatches() {
       
    74 		ArrayList<Batch> retArray = new ArrayList<Batch>();
       
    75 		
       
    76 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex));
       
    77 		
       
    78 		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
       
    79 		IValue slotValue = processingSlot.getValue();
       
    80 		
       
    81 		if(slotValue instanceof Value){
       
    82 			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
       
    83 			retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
       
    84 		}else{
       
    85 			ICard currentCard = (ICard) slotValue;
       
    86 			if(!(currentCard instanceof Dec && type == TYPE.DEC) || 
       
    87 			   !(currentCard instanceof Inc && type == TYPE.INC))
       
    88 			{
       
    89 				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
       
    90 				retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
       
    91 			}
       
    92 		}
       
    93 		
       
    94 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
       
    95 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
       
    96 		
       
    97 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
       
    98 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
       
    99 		
       
   100 		return retArray;
       
   101 	}
       
   102 	
       
   103 }