# HG changeset patch # User Igor R. Nikitin <0-range@bazon.ru> # Date 1308473652 -14400 # Node ID 39d35165179c61cf27807028385043bdb9ce1353 # Parent 4ba83edc43612babf5681aaf454059fde3ddee0d# Parent ee46d43195c1f45a054d0c837a0303501ae35e67 merge diff -r 4ba83edc4361 -r 39d35165179c src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 12:53:34 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 12:54:12 2011 +0400 @@ -5,6 +5,7 @@ import ru.alphatech.icfpc.cards.Dbl; import ru.alphatech.icfpc.cards.ICard; import ru.alphatech.icfpc.cards.Put; +import ru.alphatech.icfpc.cards.Succ; import ru.alphatech.icfpc.cards.Zero; import ru.alphatech.icfpc.game.Batch; import ru.alphatech.icfpc.game.IValue; @@ -13,6 +14,13 @@ import ru.alphatech.icfpc.game.Value; import ru.alphatech.icfpc.game.Batch.OperationType; +/** + * + * TODO + * + * @author akhmetovlz + * + */ public abstract class AbstractPolicy { protected Player player = null; @@ -23,23 +31,17 @@ this.player = player; } - public void setRegister0( int num ){ - + public void setRegister(int registerIndex, int num ){ + if( registerIndex < 4) { + Slot registerSlot = player.getRegisterByIndex(registerIndex); + batches.addAll( numberIntoSlotField( registerSlot, num ) ); + } } - public void setRegister1( int num ){ - - } - - public void setRegister2( int num ){ - - } - - protected ArrayList numberIntoSlotField(int slot, int number) + protected ArrayList numberIntoSlotField(Slot targetSlot, int number) { ArrayList retArray = new ArrayList(); - Slot targetSlot = player.getSlot(slot); IValue targetValue = targetSlot.getValue(); if(targetValue instanceof ICard){ @@ -50,28 +52,47 @@ if( numTargetValue.getValue() == number ){ return retArray; }else - if( numTargetValue.getValue() < number ){ - int buffValue = numTargetValue.getValue(); - while( buffValue*2 < number){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); - } - while( buffValue != number){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); - } - }else{ + if( numTargetValue.getValue() > number ){ retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); - int buffValue = numTargetValue.getValue(); - while( buffValue*2 < number){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); - } - while( buffValue != number){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); - } + stupidAlg(0, number, targetSlot); + }else{ + stupidAlg(numTargetValue.getValue(), number, targetSlot); } return retArray; - } + + protected ArrayList stupidAlg(int begin, int end, Slot targetSlot){ + ArrayList retArray = new ArrayList(); + while( begin*2 < end){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); + begin *= 2; + } + while( begin != end){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); + begin ++; + } + return retArray; + } + + protected ArrayList smartAlg(int begin, int end, Slot targetSlot){ + ArrayList retArray = new ArrayList(); + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); + while(end >= 2){ + int d = end % 2; + if( d == 0 ) { + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); + } else { + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); + } + end = end / 2; + } + return retArray; + } + + public abstract ArrayList getBatches(); } diff -r 4ba83edc4361 -r 39d35165179c src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 12:53:34 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 12:54:12 2011 +0400 @@ -1,5 +1,8 @@ package ru.alphatech.icfpc.policy; +import java.util.ArrayList; + +import ru.alphatech.icfpc.game.Batch; import ru.alphatech.icfpc.game.Player; public class VitalityBoostPolicy extends AbstractPolicy { @@ -7,5 +10,10 @@ public VitalityBoostPolicy(Player player) { super(player); } + + @Override + public ArrayList getBatches() { + return null; + } }