merge
authorIgor R. Nikitin <0-range@bazon.ru>
Sun, 19 Jun 2011 12:54:12 +0400
changeset 4439d35165179c
parent 43 4ba83edc4361
parent 42 ee46d43195c1
child 45 f8281a814079
child 46 c592dd7b0595
merge
     1.1 --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java	Sun Jun 19 12:53:34 2011 +0400
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java	Sun Jun 19 12:54:12 2011 +0400
     1.3 @@ -5,6 +5,7 @@
     1.4  import ru.alphatech.icfpc.cards.Dbl;
     1.5  import ru.alphatech.icfpc.cards.ICard;
     1.6  import ru.alphatech.icfpc.cards.Put;
     1.7 +import ru.alphatech.icfpc.cards.Succ;
     1.8  import ru.alphatech.icfpc.cards.Zero;
     1.9  import ru.alphatech.icfpc.game.Batch;
    1.10  import ru.alphatech.icfpc.game.IValue;
    1.11 @@ -13,6 +14,13 @@
    1.12  import ru.alphatech.icfpc.game.Value;
    1.13  import ru.alphatech.icfpc.game.Batch.OperationType;
    1.14  
    1.15 +/**
    1.16 + * 
    1.17 + * TODO 
    1.18 + * 
    1.19 + * @author akhmetovlz
    1.20 + *
    1.21 + */
    1.22  public abstract class AbstractPolicy {
    1.23  
    1.24  	protected Player player = null;
    1.25 @@ -23,23 +31,17 @@
    1.26  		this.player = player;
    1.27  	}	
    1.28  	
    1.29 -	public void setRegister0( int num ){
    1.30 -		
    1.31 +	public void setRegister(int registerIndex, int num ){
    1.32 +		if( registerIndex < 4) {
    1.33 +			Slot registerSlot = player.getRegisterByIndex(registerIndex);
    1.34 +			batches.addAll( numberIntoSlotField( registerSlot, num ) );
    1.35 +		}
    1.36  	}
    1.37  	
    1.38 -	public void setRegister1( int num ){
    1.39 -		
    1.40 -	}
    1.41 -	
    1.42 -	public void setRegister2( int num ){
    1.43 -		
    1.44 -	}
    1.45 -	
    1.46 -	protected ArrayList<Batch> numberIntoSlotField(int slot, int number)
    1.47 +	protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
    1.48  	{	
    1.49  		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.50  		
    1.51 -		Slot targetSlot = player.getSlot(slot);
    1.52  		IValue targetValue = targetSlot.getValue();
    1.53  		
    1.54  		if(targetValue instanceof ICard){
    1.55 @@ -50,28 +52,47 @@
    1.56  		if( numTargetValue.getValue() == number ){
    1.57  			return retArray;
    1.58  		}else
    1.59 -		if( numTargetValue.getValue() < number ){
    1.60 -			int buffValue = numTargetValue.getValue();
    1.61 -			while( buffValue*2 < number){
    1.62 -				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    1.63 -			}
    1.64 -			while( buffValue != number){
    1.65 -				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    1.66 -			}
    1.67 -		}else{
    1.68 +		if( numTargetValue.getValue() > number ){
    1.69  			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    1.70  			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
    1.71 -			int buffValue = numTargetValue.getValue();
    1.72 -			while( buffValue*2 < number){
    1.73 -				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    1.74 -			}
    1.75 -			while( buffValue != number){
    1.76 -				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    1.77 -			}
    1.78 +			stupidAlg(0, number, targetSlot);
    1.79 +		}else{
    1.80 +			stupidAlg(numTargetValue.getValue(), number, targetSlot);
    1.81  		}
    1.82  		
    1.83  		return retArray;
    1.84 -		
    1.85  	}
    1.86  	
    1.87 +	
    1.88 +	protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
    1.89 +		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.90 +		while( begin*2 < end){
    1.91 +			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    1.92 +			begin *= 2;
    1.93 +		}
    1.94 +		while( begin != end){
    1.95 +			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
    1.96 +			begin ++;
    1.97 +		}
    1.98 +		return retArray;
    1.99 +	}
   1.100 +	
   1.101 +	protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
   1.102 +		ArrayList<Batch> retArray = new ArrayList<Batch>();
   1.103 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
   1.104 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
   1.105 +		while(end >= 2){
   1.106 +			int d = end % 2;
   1.107 +			if( d == 0 ) {
   1.108 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
   1.109 +			} else {
   1.110 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
   1.111 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
   1.112 +			}
   1.113 +			end = end / 2; 
   1.114 +		}
   1.115 +		return retArray;
   1.116 +	}
   1.117 +	
   1.118 +	public abstract ArrayList<Batch> getBatches();
   1.119  }
     2.1 --- a/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java	Sun Jun 19 12:53:34 2011 +0400
     2.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java	Sun Jun 19 12:54:12 2011 +0400
     2.3 @@ -1,5 +1,8 @@
     2.4  package ru.alphatech.icfpc.policy;
     2.5  
     2.6 +import java.util.ArrayList;
     2.7 +
     2.8 +import ru.alphatech.icfpc.game.Batch;
     2.9  import ru.alphatech.icfpc.game.Player;
    2.10  
    2.11  public class VitalityBoostPolicy extends AbstractPolicy {
    2.12 @@ -7,5 +10,10 @@
    2.13  	public VitalityBoostPolicy(Player player) {
    2.14  		super(player);
    2.15  	}
    2.16 +
    2.17 +	@Override
    2.18 +	public ArrayList<Batch> getBatches() {
    2.19 +		return null;
    2.20 +	}
    2.21  	
    2.22  }