src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java
changeset 32 04ac70718172
parent 19 624552552ae7
child 38 d727078107f4
equal deleted inserted replaced
31:7b9682308866 32:04ac70718172
     1 package ru.alphatech.icfpc.policy;
     1 package ru.alphatech.icfpc.policy;
     2 
     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;
     3 import ru.alphatech.icfpc.game.Player;
    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;
     4 
    15 
     5 public abstract class AbstractPolicy {
    16 public abstract class AbstractPolicy {
     6 
    17 
     7 	protected Player player = null;
    18 	protected Player player = null;
     8 	
    19 	
     9 	private int turnCount   = 0;
    20 	protected ArrayList<Batch> batches = new ArrayList<Batch>();
    10 	private int turnCurrent = 0;
       
    11 	
    21 	
    12 	public AbstractPolicy(int turnCount, Player player){
    22 	public AbstractPolicy(Player player){
    13 		this.player = player;
    23 		this.player = player;
    14 		this.turnCount = turnCount;
    24 	}	
    15 		this.turnCurrent = 0;
    25 	
       
    26 	public void setRegister0( int num ){
       
    27 		
    16 	}
    28 	}
    17 	
    29 	
    18 	public int getCurrentTurns() {
    30 	public void setRegister1( int num ){
    19 		return turnCurrent;
    31 		
    20 	}
    32 	}
    21 	
    33 	
    22 	public int getTurnsCount(){
    34 	public void setRegister2( int num ){
    23 		return turnCount;
    35 		
    24 	}
    36 	}
    25 	
    37 	
    26 	public boolean next(){
    38 	protected ArrayList<Batch> numberIntoSlotField(int slot, int number)
    27 		if( turnCurrent < turnCount ){
    39 	{	
    28 			turnCurrent++;
    40 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    29 			return true;
    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));
    30 		}
    47 		}
    31 		return false;
    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 		
    32 	}
    75 	}
    33 	
    76 	
    34 	
       
    35 }
    77 }