# HG changeset patch # User Igor R. Nikitin <0-range@bazon.ru> # Date 1308471214 -14400 # Node ID 5b57bc39cc92e671b850641d2ce78ca292784dac # Parent 743564afa994b3103b55788fb3911818f5f00fe0# Parent 85894dec228098b464af914a389d24c2b23a4777 merge diff -r 743564afa994 -r 5b57bc39cc92 src/main/java/ru/alphatech/icfpc/game/Batch.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/ru/alphatech/icfpc/game/Batch.java Sun Jun 19 12:13:34 2011 +0400 @@ -0,0 +1,23 @@ +package ru.alphatech.icfpc.game; + +import ru.alphatech.icfpc.cards.ICard; + +public class Batch { + + public enum OperationType { + CARD_TO_SLOT, + SLOT_TO_CARD + } + + OperationType operationType; + + public ICard card = null; + public Slot slot = null; + + public Batch(OperationType type, ICard card, Slot slot){ + this.operationType = type; + this.card = card; + this.slot = slot; + } + +} diff -r 743564afa994 -r 5b57bc39cc92 src/main/java/ru/alphatech/icfpc/game/Player.java --- a/src/main/java/ru/alphatech/icfpc/game/Player.java Sun Jun 19 12:12:55 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/game/Player.java Sun Jun 19 12:13:34 2011 +0400 @@ -1,13 +1,35 @@ package ru.alphatech.icfpc.game; +import ru.alphatech.icfpc.cards.I; + import ru.alphatech.icfpc.cards.ICard; public class Player { + private Slot[] slots = new Slot[256]; + int registers[] = new int[4]; + + public Player() + { + for(int i = 0; i < 255; i++) + { + slots[i].setVitality(10000); + slots[i].putValue(new I()); + } + registers[0] = 0; + registers[1] = 1; + registers[2] = 2; + registers[3] = 3; + } + public Slot getSlot(int i) { - throw new RuntimeException("Not impilemented yet."); + return slots[i]; + } + + public Slot getRegisterByIndex(int registerIdex){ + return getSlot( registers[registerIdex] ); } public void applyCardToSlot(ICard card, Slot slot){ @@ -21,4 +43,6 @@ public PlayerStatistic getStatistic(){ throw new RuntimeException("Not impilemented yet."); } + + } diff -r 743564afa994 -r 5b57bc39cc92 src/main/java/ru/alphatech/icfpc/game/Run.java --- a/src/main/java/ru/alphatech/icfpc/game/Run.java Sun Jun 19 12:12:55 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/game/Run.java Sun Jun 19 12:13:34 2011 +0400 @@ -6,11 +6,11 @@ package ru.alphatech.icfpc.game; import java.io.BufferedReader; -import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; -import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; public class Run { @@ -20,15 +20,39 @@ private static Player opponent = new Player(); + private LinkedList batches = new LinkedList(); + + public void clearBatcher(){ + batches.removeAll(batches); + } + + public void addBatcher(List batches){ + this.batches.addAll(this.batches); + } + private static void readOpponent() throws IOException { BufferedReader breader = new BufferedReader(new InputStreamReader(System.in)); + String turnCase = breader.readLine(); + String card = null; + String slot = null; - String l1 = breader.readLine(); - String l2 = breader.readLine(); - String l3 = breader.readLine(); + if("1".equals(turnCase)) + { + card = breader.readLine(); + slot = breader.readLine(); + } + else if("2".equals(turnCase)) + { + slot = breader.readLine(); + card = breader.readLine(); + } + else + { + // do nothing + } - if(l1 == null || l2 == null || l3 == null) + if(turnCase == null || card == null || slot == null) { endgame = true; } diff -r 743564afa994 -r 5b57bc39cc92 src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 12:12:55 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 12:13:34 2011 +0400 @@ -1,35 +1,77 @@ package ru.alphatech.icfpc.policy; +import java.util.ArrayList; + +import ru.alphatech.icfpc.cards.Dbl; +import ru.alphatech.icfpc.cards.ICard; +import ru.alphatech.icfpc.cards.Put; +import ru.alphatech.icfpc.cards.Zero; +import ru.alphatech.icfpc.game.Batch; +import ru.alphatech.icfpc.game.IValue; import ru.alphatech.icfpc.game.Player; +import ru.alphatech.icfpc.game.Slot; +import ru.alphatech.icfpc.game.Value; +import ru.alphatech.icfpc.game.Batch.OperationType; public abstract class AbstractPolicy { protected Player player = null; - private int turnCount = 0; - private int turnCurrent = 0; + protected ArrayList batches = new ArrayList(); - public AbstractPolicy(int turnCount, Player player){ + public AbstractPolicy(Player player){ this.player = player; - this.turnCount = turnCount; - this.turnCurrent = 0; + } + + public void setRegister0( int num ){ + } - public int getCurrentTurns() { - return turnCurrent; + public void setRegister1( int num ){ + } - public int getTurnsCount(){ - return turnCount; + public void setRegister2( int num ){ + } - public boolean next(){ - if( turnCurrent < turnCount ){ - turnCurrent++; - return true; + protected ArrayList numberIntoSlotField(int slot, int number) + { + ArrayList retArray = new ArrayList(); + + Slot targetSlot = player.getSlot(slot); + IValue targetValue = targetSlot.getValue(); + + if(targetValue instanceof ICard){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); } - return false; + + Value numTargetValue = (Value) targetValue; + 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{ + 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)); + } + } + + return retArray; + } - } diff -r 743564afa994 -r 5b57bc39cc92 src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 12:12:55 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 12:13:34 2011 +0400 @@ -1,52 +1,11 @@ package ru.alphatech.icfpc.policy; -import ru.alphatech.icfpc.cards.Dbl; -import ru.alphatech.icfpc.cards.Succ; -import ru.alphatech.icfpc.cards.Zero; import ru.alphatech.icfpc.game.Player; public class VitalityBoostPolicy extends AbstractPolicy { - - public static final int turnsCount = 100; - - public VitalityBoostPolicy(int targetSlot, Player player) { - super(turnsCount, player); - this.targetSlot = targetSlot; - - maxValueSlotNum = player.getStatistic().maxValueSlotNum; - maxValue = player.getStatistic().maxValue; - firstIdentitySlot = -1; + + public VitalityBoostPolicy(Player player) { + super(player); } - protected int targetSlot = -1; - protected int maxValueSlotNum = -1; - protected int maxValue = -1; - protected int firstIdentitySlot = -1; - - public boolean next() { - if ( super.next() ){ - - switch (getCurrentTurns()) { - case 0: - break; - case 1: - case 2: - break; - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - break; - case 11: - break; - } - - } - return false; - } - }