merge
authorIgor R. Nikitin <0-range@bazon.ru>
Sun, 19 Jun 2011 12:13:34 +0400
changeset 365b57bc39cc92
parent 35 743564afa994
parent 34 85894dec2280
child 37 6e56ba8c71c3
merge
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/game/Batch.java	Sun Jun 19 12:13:34 2011 +0400
     1.3 @@ -0,0 +1,23 @@
     1.4 +package ru.alphatech.icfpc.game;
     1.5 +
     1.6 +import ru.alphatech.icfpc.cards.ICard;
     1.7 +
     1.8 +public class Batch {
     1.9 +	
    1.10 +	public enum OperationType {
    1.11 +		CARD_TO_SLOT,
    1.12 +		SLOT_TO_CARD
    1.13 +	}
    1.14 +	
    1.15 +	OperationType operationType;
    1.16 +	
    1.17 +	public ICard card = null;
    1.18 +	public Slot  slot = null;
    1.19 +	
    1.20 +	public Batch(OperationType type, ICard card, Slot slot){
    1.21 +		this.operationType = type;
    1.22 +		this.card = card;
    1.23 +		this.slot = slot;
    1.24 +	}
    1.25 +	
    1.26 +}
     2.1 --- a/src/main/java/ru/alphatech/icfpc/game/Player.java	Sun Jun 19 12:12:55 2011 +0400
     2.2 +++ b/src/main/java/ru/alphatech/icfpc/game/Player.java	Sun Jun 19 12:13:34 2011 +0400
     2.3 @@ -1,13 +1,35 @@
     2.4  package ru.alphatech.icfpc.game;
     2.5  
     2.6 +import ru.alphatech.icfpc.cards.I;
     2.7 +
     2.8  import ru.alphatech.icfpc.cards.ICard;
     2.9  
    2.10  
    2.11  public class Player
    2.12  {
    2.13 +	private Slot[] slots = new Slot[256];
    2.14 +	int registers[] = new int[4];
    2.15 +	
    2.16 +	public Player()
    2.17 +    {
    2.18 +		for(int i = 0; i < 255; i++)
    2.19 +		{
    2.20 +			slots[i].setVitality(10000);
    2.21 +			slots[i].putValue(new I());
    2.22 +		}
    2.23 +		registers[0] = 0;
    2.24 +		registers[1] = 1;
    2.25 +		registers[2] = 2;
    2.26 +		registers[3] = 3;
    2.27 +    }
    2.28 +	
    2.29  	public Slot getSlot(int i)
    2.30  	{
    2.31 -		throw new RuntimeException("Not impilemented yet.");
    2.32 +		return slots[i];
    2.33 +	}
    2.34 +	
    2.35 +	public Slot getRegisterByIndex(int registerIdex){
    2.36 +		return getSlot( registers[registerIdex] );
    2.37  	}
    2.38  	
    2.39  	public void applyCardToSlot(ICard card, Slot slot){
    2.40 @@ -21,4 +43,6 @@
    2.41  	public PlayerStatistic getStatistic(){
    2.42  		throw new RuntimeException("Not impilemented yet.");
    2.43  	}
    2.44 +	
    2.45 +	
    2.46  }
     3.1 --- a/src/main/java/ru/alphatech/icfpc/game/Run.java	Sun Jun 19 12:12:55 2011 +0400
     3.2 +++ b/src/main/java/ru/alphatech/icfpc/game/Run.java	Sun Jun 19 12:13:34 2011 +0400
     3.3 @@ -6,11 +6,11 @@
     3.4  package ru.alphatech.icfpc.game;
     3.5  
     3.6  import java.io.BufferedReader;
     3.7 -import java.io.File;
     3.8 -import java.io.FileWriter;
     3.9  import java.io.IOException;
    3.10  import java.io.InputStreamReader;
    3.11 -import java.io.PrintWriter;
    3.12 +import java.util.ArrayList;
    3.13 +import java.util.LinkedList;
    3.14 +import java.util.List;
    3.15  
    3.16  public class Run
    3.17  {
    3.18 @@ -20,15 +20,39 @@
    3.19  	
    3.20  	private static Player opponent = new Player();
    3.21  	
    3.22 +	private LinkedList<Batch> batches = new LinkedList<Batch>();
    3.23 +	
    3.24 +	public void clearBatcher(){
    3.25 +		batches.removeAll(batches);
    3.26 +	}
    3.27 +	
    3.28 +	public void addBatcher(List<Batch> batches){
    3.29 +		this.batches.addAll(this.batches);
    3.30 +	}
    3.31 +	
    3.32  	private static void readOpponent() throws IOException
    3.33  	{
    3.34  		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    3.35 +		String turnCase = breader.readLine();
    3.36 +		String card = null;
    3.37 +		String slot = null;
    3.38  		
    3.39 -		String l1 = breader.readLine();
    3.40 -		String l2 = breader.readLine();
    3.41 -		String l3 = breader.readLine();
    3.42 +		if("1".equals(turnCase))
    3.43 +		{
    3.44 +			card = breader.readLine();
    3.45 +			slot = breader.readLine();
    3.46 +		}
    3.47 +		else if("2".equals(turnCase))
    3.48 +		{
    3.49 +			slot = breader.readLine();
    3.50 +			card = breader.readLine();
    3.51 +		}
    3.52 +		else
    3.53 +		{
    3.54 +			// do nothing
    3.55 +		}
    3.56  		
    3.57 -		if(l1 == null || l2 == null || l3 == null)
    3.58 +		if(turnCase == null || card == null || slot == null)
    3.59  		{
    3.60  			endgame = true;
    3.61  		}
     4.1 --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java	Sun Jun 19 12:12:55 2011 +0400
     4.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java	Sun Jun 19 12:13:34 2011 +0400
     4.3 @@ -1,35 +1,77 @@
     4.4  package ru.alphatech.icfpc.policy;
     4.5  
     4.6 +import java.util.ArrayList;
     4.7 +
     4.8 +import ru.alphatech.icfpc.cards.Dbl;
     4.9 +import ru.alphatech.icfpc.cards.ICard;
    4.10 +import ru.alphatech.icfpc.cards.Put;
    4.11 +import ru.alphatech.icfpc.cards.Zero;
    4.12 +import ru.alphatech.icfpc.game.Batch;
    4.13 +import ru.alphatech.icfpc.game.IValue;
    4.14  import ru.alphatech.icfpc.game.Player;
    4.15 +import ru.alphatech.icfpc.game.Slot;
    4.16 +import ru.alphatech.icfpc.game.Value;
    4.17 +import ru.alphatech.icfpc.game.Batch.OperationType;
    4.18  
    4.19  public abstract class AbstractPolicy {
    4.20  
    4.21  	protected Player player = null;
    4.22  	
    4.23 -	private int turnCount   = 0;
    4.24 -	private int turnCurrent = 0;
    4.25 +	protected ArrayList<Batch> batches = new ArrayList<Batch>();
    4.26  	
    4.27 -	public AbstractPolicy(int turnCount, Player player){
    4.28 +	public AbstractPolicy(Player player){
    4.29  		this.player = player;
    4.30 -		this.turnCount = turnCount;
    4.31 -		this.turnCurrent = 0;
    4.32 +	}	
    4.33 +	
    4.34 +	public void setRegister0( int num ){
    4.35 +		
    4.36  	}
    4.37  	
    4.38 -	public int getCurrentTurns() {
    4.39 -		return turnCurrent;
    4.40 +	public void setRegister1( int num ){
    4.41 +		
    4.42  	}
    4.43  	
    4.44 -	public int getTurnsCount(){
    4.45 -		return turnCount;
    4.46 +	public void setRegister2( int num ){
    4.47 +		
    4.48  	}
    4.49  	
    4.50 -	public boolean next(){
    4.51 -		if( turnCurrent < turnCount ){
    4.52 -			turnCurrent++;
    4.53 -			return true;
    4.54 +	protected ArrayList<Batch> numberIntoSlotField(int slot, int number)
    4.55 +	{	
    4.56 +		ArrayList<Batch> retArray = new ArrayList<Batch>();
    4.57 +		
    4.58 +		Slot targetSlot = player.getSlot(slot);
    4.59 +		IValue targetValue = targetSlot.getValue();
    4.60 +		
    4.61 +		if(targetValue instanceof ICard){
    4.62 +			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    4.63  		}
    4.64 -		return false;
    4.65 +		
    4.66 +		Value numTargetValue = (Value) targetValue;
    4.67 +		if( numTargetValue.getValue() == number ){
    4.68 +			return retArray;
    4.69 +		}else
    4.70 +		if( numTargetValue.getValue() < number ){
    4.71 +			int buffValue = numTargetValue.getValue();
    4.72 +			while( buffValue*2 < number){
    4.73 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    4.74 +			}
    4.75 +			while( buffValue != number){
    4.76 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    4.77 +			}
    4.78 +		}else{
    4.79 +			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    4.80 +			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
    4.81 +			int buffValue = numTargetValue.getValue();
    4.82 +			while( buffValue*2 < number){
    4.83 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    4.84 +			}
    4.85 +			while( buffValue != number){
    4.86 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
    4.87 +			}
    4.88 +		}
    4.89 +		
    4.90 +		return retArray;
    4.91 +		
    4.92  	}
    4.93  	
    4.94 -	
    4.95  }
     5.1 --- a/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java	Sun Jun 19 12:12:55 2011 +0400
     5.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java	Sun Jun 19 12:13:34 2011 +0400
     5.3 @@ -1,52 +1,11 @@
     5.4  package ru.alphatech.icfpc.policy;
     5.5  
     5.6 -import ru.alphatech.icfpc.cards.Dbl;
     5.7 -import ru.alphatech.icfpc.cards.Succ;
     5.8 -import ru.alphatech.icfpc.cards.Zero;
     5.9  import ru.alphatech.icfpc.game.Player;
    5.10  
    5.11  public class VitalityBoostPolicy extends AbstractPolicy {
    5.12 -	
    5.13 -	public static final int turnsCount = 100;
    5.14 -	
    5.15 -	public VitalityBoostPolicy(int targetSlot, Player player) {
    5.16 -		super(turnsCount, player);
    5.17 -		this.targetSlot = targetSlot;
    5.18 -		
    5.19 -		maxValueSlotNum = player.getStatistic().maxValueSlotNum;
    5.20 -		maxValue = player.getStatistic().maxValue;
    5.21 -		firstIdentitySlot = -1;
    5.22 +
    5.23 +	public VitalityBoostPolicy(Player player) {
    5.24 +		super(player);
    5.25  	}
    5.26  	
    5.27 -	protected int targetSlot = -1;
    5.28 -	protected int maxValueSlotNum = -1;
    5.29 -	protected int maxValue = -1;
    5.30 -	protected int firstIdentitySlot = -1;
    5.31 -	
    5.32 -	public boolean next() {
    5.33 -		if ( super.next() ){
    5.34 -			
    5.35 -			switch (getCurrentTurns()) {
    5.36 -				case 0:
    5.37 -				break;
    5.38 -				case 1:
    5.39 -				case 2:
    5.40 -				break;
    5.41 -				case 3:
    5.42 -				case 4:
    5.43 -				case 5:
    5.44 -				case 6:
    5.45 -				case 7:
    5.46 -				case 8:
    5.47 -				case 9:
    5.48 -				case 10:
    5.49 -				break;
    5.50 -				case 11:
    5.51 -				break;
    5.52 -			}
    5.53 -			
    5.54 -		}
    5.55 -		return false;
    5.56 -	}
    5.57 -
    5.58  }