src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java
author indvdum
Sun, 19 Jun 2011 17:13:20 +0400
changeset 81 da95a7576365
parent 75 40ad0dd24185
permissions -rw-r--r--
* merge
akhmetovlz@75
     1
package ru.alphatech.icfpc.policy;
akhmetovlz@75
     2
akhmetovlz@75
     3
import java.util.ArrayList;
akhmetovlz@75
     4
akhmetovlz@75
     5
import ru.alphatech.icfpc.cards.Dec;
akhmetovlz@75
     6
import ru.alphatech.icfpc.cards.Get;
akhmetovlz@75
     7
import ru.alphatech.icfpc.cards.ICard;
akhmetovlz@75
     8
import ru.alphatech.icfpc.cards.Inc;
akhmetovlz@75
     9
import ru.alphatech.icfpc.cards.K;
akhmetovlz@75
    10
import ru.alphatech.icfpc.cards.Put;
akhmetovlz@75
    11
import ru.alphatech.icfpc.cards.S;
akhmetovlz@75
    12
import ru.alphatech.icfpc.cards.Zero;
akhmetovlz@75
    13
import ru.alphatech.icfpc.game.AbstractPolicy;
akhmetovlz@75
    14
import ru.alphatech.icfpc.game.Batch;
akhmetovlz@75
    15
import ru.alphatech.icfpc.game.IValue;
akhmetovlz@75
    16
import ru.alphatech.icfpc.game.Run;
akhmetovlz@75
    17
import ru.alphatech.icfpc.game.Slot;
akhmetovlz@75
    18
import ru.alphatech.icfpc.game.Value;
akhmetovlz@75
    19
import ru.alphatech.icfpc.game.Batch.OperationType;
akhmetovlz@75
    20
akhmetovlz@75
    21
public class DecIncPolicy extends AbstractPolicy{
akhmetovlz@75
    22
	
akhmetovlz@75
    23
	public enum TYPE {
akhmetovlz@75
    24
		DEC,
akhmetovlz@75
    25
		INC
akhmetovlz@75
    26
	}
akhmetovlz@75
    27
	
akhmetovlz@75
    28
	private TYPE type;
akhmetovlz@75
    29
	private int processingSlotIndex = -1;
akhmetovlz@75
    30
	private int targetSlotIndex = -1;
akhmetovlz@75
    31
	
akhmetovlz@75
    32
	
akhmetovlz@75
    33
	public DecIncPolicy(TYPE type, int processingSlot, int target) {
akhmetovlz@75
    34
		this.type = type;
akhmetovlz@75
    35
		this.processingSlotIndex = processingSlot;
akhmetovlz@75
    36
		this.targetSlotIndex = target;
akhmetovlz@75
    37
	}
akhmetovlz@75
    38
	
akhmetovlz@75
    39
	public ICard getCard(){
akhmetovlz@75
    40
		return type == TYPE.DEC ? new Dec() : new Inc();
akhmetovlz@75
    41
	}
akhmetovlz@75
    42
akhmetovlz@75
    43
	@Override
akhmetovlz@75
    44
	public ArrayList<Batch> getBatches() {
akhmetovlz@75
    45
		ArrayList<Batch> retArray = new ArrayList<Batch>();
akhmetovlz@75
    46
		
akhmetovlz@75
    47
		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex));
akhmetovlz@75
    48
		
akhmetovlz@75
    49
		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
akhmetovlz@75
    50
		IValue slotValue = processingSlot.getValue();
akhmetovlz@75
    51
		
akhmetovlz@75
    52
		if(slotValue instanceof Value){
akhmetovlz@75
    53
			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
akhmetovlz@75
    54
			retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
akhmetovlz@75
    55
		}else{
akhmetovlz@75
    56
			ICard currentCard = (ICard) slotValue;
akhmetovlz@75
    57
			if(!(currentCard instanceof Dec && type == TYPE.DEC) || 
akhmetovlz@75
    58
			   !(currentCard instanceof Inc && type == TYPE.INC))
akhmetovlz@75
    59
			{
akhmetovlz@75
    60
				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
akhmetovlz@75
    61
				retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
akhmetovlz@75
    62
			}
akhmetovlz@75
    63
		}
akhmetovlz@75
    64
		
akhmetovlz@75
    65
		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
akhmetovlz@75
    66
		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
akhmetovlz@75
    67
		
akhmetovlz@75
    68
		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
akhmetovlz@75
    69
		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
akhmetovlz@75
    70
		
akhmetovlz@75
    71
		return retArray;
akhmetovlz@75
    72
	}
akhmetovlz@75
    73
	
akhmetovlz@75
    74
}