1.1 --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 12:12:55 2011 +0400
1.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 12:13:34 2011 +0400
1.3 @@ -1,35 +1,77 @@
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.Zero;
1.12 +import ru.alphatech.icfpc.game.Batch;
1.13 +import ru.alphatech.icfpc.game.IValue;
1.14 import ru.alphatech.icfpc.game.Player;
1.15 +import ru.alphatech.icfpc.game.Slot;
1.16 +import ru.alphatech.icfpc.game.Value;
1.17 +import ru.alphatech.icfpc.game.Batch.OperationType;
1.18
1.19 public abstract class AbstractPolicy {
1.20
1.21 protected Player player = null;
1.22
1.23 - private int turnCount = 0;
1.24 - private int turnCurrent = 0;
1.25 + protected ArrayList<Batch> batches = new ArrayList<Batch>();
1.26
1.27 - public AbstractPolicy(int turnCount, Player player){
1.28 + public AbstractPolicy(Player player){
1.29 this.player = player;
1.30 - this.turnCount = turnCount;
1.31 - this.turnCurrent = 0;
1.32 + }
1.33 +
1.34 + public void setRegister0( int num ){
1.35 +
1.36 }
1.37
1.38 - public int getCurrentTurns() {
1.39 - return turnCurrent;
1.40 + public void setRegister1( int num ){
1.41 +
1.42 }
1.43
1.44 - public int getTurnsCount(){
1.45 - return turnCount;
1.46 + public void setRegister2( int num ){
1.47 +
1.48 }
1.49
1.50 - public boolean next(){
1.51 - if( turnCurrent < turnCount ){
1.52 - turnCurrent++;
1.53 - return true;
1.54 + protected ArrayList<Batch> numberIntoSlotField(int slot, int number)
1.55 + {
1.56 + ArrayList<Batch> retArray = new ArrayList<Batch>();
1.57 +
1.58 + Slot targetSlot = player.getSlot(slot);
1.59 + IValue targetValue = targetSlot.getValue();
1.60 +
1.61 + if(targetValue instanceof ICard){
1.62 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
1.63 }
1.64 - return false;
1.65 +
1.66 + Value numTargetValue = (Value) targetValue;
1.67 + if( numTargetValue.getValue() == number ){
1.68 + return retArray;
1.69 + }else
1.70 + if( numTargetValue.getValue() < number ){
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 + }else{
1.79 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
1.80 + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
1.81 + int buffValue = numTargetValue.getValue();
1.82 + while( buffValue*2 < number){
1.83 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
1.84 + }
1.85 + while( buffValue != number){
1.86 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
1.87 + }
1.88 + }
1.89 +
1.90 + return retArray;
1.91 +
1.92 }
1.93
1.94 -
1.95 }