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