src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java
author Igor R. Nikitin <0-range@bazon.ru>
Sun, 19 Jun 2011 12:53:34 +0400
changeset 43 4ba83edc4361
parent 32 04ac70718172
child 38 d727078107f4
permissions -rw-r--r--
skdjhfkdjghkshgfkjsd
akhmetovlz@19
     1
package ru.alphatech.icfpc.policy;
akhmetovlz@19
     2
akhmetovlz@32
     3
import java.util.ArrayList;
akhmetovlz@32
     4
akhmetovlz@32
     5
import ru.alphatech.icfpc.cards.Dbl;
akhmetovlz@32
     6
import ru.alphatech.icfpc.cards.ICard;
akhmetovlz@32
     7
import ru.alphatech.icfpc.cards.Put;
akhmetovlz@32
     8
import ru.alphatech.icfpc.cards.Zero;
akhmetovlz@32
     9
import ru.alphatech.icfpc.game.Batch;
akhmetovlz@32
    10
import ru.alphatech.icfpc.game.IValue;
akhmetovlz@19
    11
import ru.alphatech.icfpc.game.Player;
akhmetovlz@32
    12
import ru.alphatech.icfpc.game.Slot;
akhmetovlz@32
    13
import ru.alphatech.icfpc.game.Value;
akhmetovlz@32
    14
import ru.alphatech.icfpc.game.Batch.OperationType;
akhmetovlz@19
    15
akhmetovlz@19
    16
public abstract class AbstractPolicy {
akhmetovlz@19
    17
akhmetovlz@19
    18
	protected Player player = null;
akhmetovlz@19
    19
	
akhmetovlz@32
    20
	protected ArrayList<Batch> batches = new ArrayList<Batch>();
akhmetovlz@19
    21
	
akhmetovlz@32
    22
	public AbstractPolicy(Player player){
akhmetovlz@19
    23
		this.player = player;
akhmetovlz@32
    24
	}	
akhmetovlz@32
    25
	
akhmetovlz@32
    26
	public void setRegister0( int num ){
akhmetovlz@32
    27
		
akhmetovlz@19
    28
	}
akhmetovlz@19
    29
	
akhmetovlz@32
    30
	public void setRegister1( int num ){
akhmetovlz@32
    31
		
akhmetovlz@19
    32
	}
akhmetovlz@19
    33
	
akhmetovlz@32
    34
	public void setRegister2( int num ){
akhmetovlz@32
    35
		
akhmetovlz@19
    36
	}
akhmetovlz@19
    37
	
akhmetovlz@32
    38
	protected ArrayList<Batch> numberIntoSlotField(int slot, int number)
akhmetovlz@32
    39
	{	
akhmetovlz@32
    40
		ArrayList<Batch> retArray = new ArrayList<Batch>();
akhmetovlz@32
    41
		
akhmetovlz@32
    42
		Slot targetSlot = player.getSlot(slot);
akhmetovlz@32
    43
		IValue targetValue = targetSlot.getValue();
akhmetovlz@32
    44
		
akhmetovlz@32
    45
		if(targetValue instanceof ICard){
akhmetovlz@32
    46
			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
akhmetovlz@19
    47
		}
akhmetovlz@32
    48
		
akhmetovlz@32
    49
		Value numTargetValue = (Value) targetValue;
akhmetovlz@32
    50
		if( numTargetValue.getValue() == number ){
akhmetovlz@32
    51
			return retArray;
akhmetovlz@32
    52
		}else
akhmetovlz@32
    53
		if( numTargetValue.getValue() < number ){
akhmetovlz@32
    54
			int buffValue = numTargetValue.getValue();
akhmetovlz@32
    55
			while( buffValue*2 < number){
akhmetovlz@32
    56
				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
akhmetovlz@32
    57
			}
akhmetovlz@32
    58
			while( buffValue != number){
akhmetovlz@32
    59
				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
akhmetovlz@32
    60
			}
akhmetovlz@32
    61
		}else{
akhmetovlz@32
    62
			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
akhmetovlz@32
    63
			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
akhmetovlz@32
    64
			int buffValue = numTargetValue.getValue();
akhmetovlz@32
    65
			while( buffValue*2 < number){
akhmetovlz@32
    66
				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
akhmetovlz@32
    67
			}
akhmetovlz@32
    68
			while( buffValue != number){
akhmetovlz@32
    69
				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
akhmetovlz@32
    70
			}
akhmetovlz@32
    71
		}
akhmetovlz@32
    72
		
akhmetovlz@32
    73
		return retArray;
akhmetovlz@32
    74
		
akhmetovlz@19
    75
	}
akhmetovlz@19
    76
	
akhmetovlz@19
    77
}