src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java
changeset 56 1ff9e4ee2b02
parent 55 26d05bc45f1d
parent 54 0ffe63f2aa46
child 59 9307831f7658
     1.1 --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java	Sun Jun 19 13:37:56 2011 +0400
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,96 +0,0 @@
     1.4 -package ru.alphatech.icfpc.policy;
     1.5 -
     1.6 -import java.util.ArrayList;
     1.7 -
     1.8 -import ru.alphatech.icfpc.cards.Dbl;
     1.9 -import ru.alphatech.icfpc.cards.ICard;
    1.10 -import ru.alphatech.icfpc.cards.Put;
    1.11 -import ru.alphatech.icfpc.cards.Succ;
    1.12 -import ru.alphatech.icfpc.cards.Zero;
    1.13 -import ru.alphatech.icfpc.game.Batch;
    1.14 -import ru.alphatech.icfpc.game.IValue;
    1.15 -import ru.alphatech.icfpc.game.Player;
    1.16 -import ru.alphatech.icfpc.game.Run;
    1.17 -import ru.alphatech.icfpc.game.Slot;
    1.18 -import ru.alphatech.icfpc.game.Value;
    1.19 -import ru.alphatech.icfpc.game.Batch.OperationType;
    1.20 -
    1.21 -/**
    1.22 - * 
    1.23 - * TODO 
    1.24 - * 
    1.25 - * @author akhmetovlz
    1.26 - *
    1.27 - */
    1.28 -public abstract class AbstractPolicy {
    1.29 -
    1.30 -	protected ArrayList<Batch> batches = new ArrayList<Batch>();
    1.31 -	
    1.32 -	public AbstractPolicy(){
    1.33 -	}	
    1.34 -	
    1.35 -	public void setRegister(int registerIndex, int num ){
    1.36 -		if( registerIndex < 4) {
    1.37 -			Slot registerSlot = Run.getRegisterByIndex(registerIndex);
    1.38 -			batches.addAll( numberIntoSlotField( registerSlot, num ) );
    1.39 -		}
    1.40 -	}
    1.41 -	
    1.42 -	protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
    1.43 -	{	
    1.44 -		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.45 -		
    1.46 -		IValue targetValue = targetSlot.getValue();
    1.47 -		
    1.48 -		if(targetValue instanceof ICard){
    1.49 -			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    1.50 -		}
    1.51 -		
    1.52 -		Value numTargetValue = (Value) targetValue;
    1.53 -		if( numTargetValue.getValue() == number ){
    1.54 -			return retArray;
    1.55 -		}else
    1.56 -		if( numTargetValue.getValue() > number ){
    1.57 -			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    1.58 -			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
    1.59 -			stupidAlg(0, number, targetSlot);
    1.60 -		}else{
    1.61 -			stupidAlg(numTargetValue.getValue(), number, targetSlot);
    1.62 -		}
    1.63 -		
    1.64 -		return retArray;
    1.65 -	}
    1.66 -	
    1.67 -	
    1.68 -	protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
    1.69 -		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.70 -		while( begin*2 < end){
    1.71 -			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    1.72 -			begin *= 2;
    1.73 -		}
    1.74 -		while( begin != end){
    1.75 -			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
    1.76 -			begin ++;
    1.77 -		}
    1.78 -		return retArray;
    1.79 -	}
    1.80 -	
    1.81 -	protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
    1.82 -		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.83 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    1.84 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
    1.85 -		while(end >= 2){
    1.86 -			int d = end % 2;
    1.87 -			if( d == 0 ) {
    1.88 -				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
    1.89 -			} else {
    1.90 -				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
    1.91 -				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
    1.92 -			}
    1.93 -			end = end / 2; 
    1.94 -		}
    1.95 -		return retArray;
    1.96 -	}
    1.97 -	
    1.98 -	public abstract ArrayList<Batch> getBatches();
    1.99 -}