1.1 --- a/icfp-interpreter/src/main/java/ru/bosony/interpreters/TextInterpreter.java Mon Jul 16 00:05:50 2012 +0400
1.2 +++ b/icfp-interpreter/src/main/java/ru/bosony/interpreters/TextInterpreter.java Mon Jul 16 01:46:54 2012 +0400
1.3 @@ -46,18 +46,21 @@
1.4 writer.newLine();
1.5 writer.write("********************************************************************************");
1.6 writer.newLine();
1.7 - writer.write("State: " + game.getState());
1.8 + writer.write("State: " + game.getState());
1.9 writer.newLine();
1.10 - writer.write("Score: " + game.getScore() + " ("
1.11 + writer.write("Score: " + game.getScore() + " ("
1.12 + (game.getLastScoreChange() >= 0 ? "+" + game.getLastScoreChange() : game.getLastScoreChange()) + ")");
1.13 writer.newLine();
1.14 - writer.write("Steps: " + game.getRoute().size());
1.15 + writer.write("Steps: " + game.getRoute().size());
1.16 writer.newLine();
1.17 - writer.write("Route: " + game.getStringRoute());
1.18 + writer.write("Route: " + game.getStringRoute());
1.19 writer.newLine();
1.20 - writer.write("Underwater: " + game.getUnderwater() + " of " + mine.getRobotWaterproof());
1.21 + writer.write("Underwater: " + game.getUnderwater() + " of " + mine.getRobotWaterproof());
1.22 writer.newLine();
1.23 - writer.write("Razors: " + mine.getRazorsCount());
1.24 + writer.write("Razors: " + mine.getRazorsCount());
1.25 + writer.newLine();
1.26 + writer.write("Labmdas found: " + game.getLambdaCollectedCount() + " of "
1.27 + + mine.getLambdasAndHighOrderRocksStartCount());
1.28 writer.newLine();
1.29 writer.newLine();
1.30 writer.write(mine.toText());
2.1 --- a/icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java Mon Jul 16 00:05:50 2012 +0400
2.2 +++ b/icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java Mon Jul 16 01:46:54 2012 +0400
2.3 @@ -39,7 +39,8 @@
2.4 Target8("8"),
2.5 Target9("9"),
2.6 WadlersBeard("W"),
2.7 - HuttonsRazor("!");
2.8 + HuttonsRazor("!"),
2.9 + HighOrderRock("@");
2.10
2.11 private String text;
2.12 private CellContent trampolineTarget = null;
3.1 --- a/icfp-model/src/main/java/ru/bosony/model/game/Game.java Mon Jul 16 00:05:50 2012 +0400
3.2 +++ b/icfp-model/src/main/java/ru/bosony/model/game/Game.java Mon Jul 16 01:46:54 2012 +0400
3.3 @@ -3,11 +3,12 @@
3.4 import static ru.bosony.model.cellscontents.CellContent.ClosedLambdaLift;
3.5 import static ru.bosony.model.cellscontents.CellContent.Earth;
3.6 import static ru.bosony.model.cellscontents.CellContent.Empty;
3.7 +import static ru.bosony.model.cellscontents.CellContent.HighOrderRock;
3.8 +import static ru.bosony.model.cellscontents.CellContent.HuttonsRazor;
3.9 import static ru.bosony.model.cellscontents.CellContent.Lambda;
3.10 import static ru.bosony.model.cellscontents.CellContent.MiningRobot;
3.11 import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift;
3.12 import static ru.bosony.model.cellscontents.CellContent.Rock;
3.13 -import static ru.bosony.model.cellscontents.CellContent.HuttonsRazor;
3.14 import static ru.bosony.model.cellscontents.CellContent.WadlersBeard;
3.15
3.16 import java.util.ArrayList;
3.17 @@ -130,6 +131,14 @@
3.18 && getContent(mine.getCell(nextRobotCoord.left())) == Empty) {
3.19 moveRobot(nextRobotCell);
3.20 mine.getCell(nextRobotCoord.left()).setContent(Rock);
3.21 + } else if (robotCoord.right().equals(nextRobotCoord) && nextRobotCellContent == HighOrderRock
3.22 + && getContent(mine.getCell(nextRobotCoord.right())) == Empty) {
3.23 + moveRobot(nextRobotCell);
3.24 + mine.getCell(nextRobotCoord.right()).setContent(HighOrderRock);
3.25 + } else if (robotCoord.left().equals(nextRobotCoord) && nextRobotCellContent == HighOrderRock
3.26 + && getContent(mine.getCell(nextRobotCoord.left())) == Empty) {
3.27 + moveRobot(nextRobotCell);
3.28 + mine.getCell(nextRobotCoord.left()).setContent(HighOrderRock);
3.29 } else if (CellContent.getTrampolines().contains(nextRobotCellContent)
3.30 && CellContent.getTargets().contains(nextRobotCellContent.getTrampolineTarget())) {
3.31 CellContent trampoline = nextRobotCellContent;
3.32 @@ -174,20 +183,53 @@
3.33 if (getContent(curCell) == Rock && getContent(downCell) == Empty) {
3.34 getCell(curCoord, newCells).setContent(Empty);
3.35 getCell(downCoord, newCells).setContent(Rock);
3.36 - } else if (getContent(curCell) == Rock && getContent(downCell) == Rock
3.37 + } else if (getContent(curCell) == HighOrderRock && getContent(downCell) == Empty) {
3.38 + getCell(curCoord, newCells).setContent(Empty);
3.39 + if (getContent(mine.getCell(downCoord.down())) != Empty)
3.40 + getCell(downCoord, newCells).setContent(Lambda);
3.41 + else
3.42 + getCell(downCoord, newCells).setContent(HighOrderRock);
3.43 + } else if (getContent(curCell) == Rock
3.44 + && (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock)
3.45 && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
3.46 getCell(curCoord, newCells).setContent(Empty);
3.47 getCell(rightAndDownCoord, newCells).setContent(Rock);
3.48 - } else if (getContent(curCell) == Rock && getContent(downCell) == Rock
3.49 + } else if (getContent(curCell) == HighOrderRock
3.50 + && (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock)
3.51 + && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
3.52 + getCell(curCoord, newCells).setContent(Empty);
3.53 + if (getContent(mine.getCell(rightAndDownCoord.down())) != Empty)
3.54 + getCell(rightAndDownCoord, newCells).setContent(Lambda);
3.55 + else
3.56 + getCell(rightAndDownCoord, newCells).setContent(HighOrderRock);
3.57 + } else if (getContent(curCell) == Rock
3.58 + && (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock)
3.59 && (getContent(rightCell) != Empty || getContent(rightAndDownCell) != Empty)
3.60 && getContent(leftCell) == Empty && getContent(leftAndDownCell) == Empty) {
3.61 getCell(curCoord, newCells).setContent(Empty);
3.62 getCell(leftAndDownCoord, newCells).setContent(Rock);
3.63 + } else if (getContent(curCell) == HighOrderRock
3.64 + && (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock)
3.65 + && (getContent(rightCell) != Empty || getContent(rightAndDownCell) != Empty)
3.66 + && getContent(leftCell) == Empty && getContent(leftAndDownCell) == Empty) {
3.67 + getCell(curCoord, newCells).setContent(Empty);
3.68 + if (getContent(mine.getCell(leftAndDownCoord.down())) != Empty)
3.69 + getCell(leftAndDownCoord, newCells).setContent(Lambda);
3.70 + else
3.71 + getCell(leftAndDownCoord, newCells).setContent(HighOrderRock);
3.72 } else if (getContent(curCell) == Rock && getContent(downCell) == Lambda
3.73 && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
3.74 getCell(curCoord, newCells).setContent(Empty);
3.75 getCell(rightAndDownCoord, newCells).setContent(Rock);
3.76 - } else if (getContent(curCell) == ClosedLambdaLift && mine.findCells(Lambda).size() == 0) {
3.77 + } else if (getContent(curCell) == HighOrderRock && getContent(downCell) == Lambda
3.78 + && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
3.79 + getCell(curCoord, newCells).setContent(Empty);
3.80 + if (getContent(mine.getCell(rightAndDownCoord.down())) != Empty)
3.81 + getCell(rightAndDownCoord, newCells).setContent(Lambda);
3.82 + else
3.83 + getCell(rightAndDownCoord, newCells).setContent(HighOrderRock);
3.84 + } else if (getContent(curCell) == ClosedLambdaLift
3.85 + && mine.getLambdasAndHighOrderRocksStartCount() == lambdaCollectedCount) {
3.86 getCell(curCoord, newCells).setContent(OpenLambdaLift);
3.87 } else if (getContent(curCell) == WadlersBeard && mine.getGrowth() > 0
3.88 && route.size() % mine.getGrowth() == 0) {
3.89 @@ -213,7 +255,11 @@
3.90
3.91 // Other ending conditions
3.92 robotCoord = mine.getRobotCell().getCoordinate();
3.93 - if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock) {
3.94 + if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock
3.95 + || getContent(mine.getCell(robotCoord.up())) != HighOrderRock
3.96 + && getContent(getCell(robotCoord.up(), newCells)) == HighOrderRock
3.97 + || getContent(mine.getCell(robotCoord.up())) == Empty
3.98 + && getContent(getCell(robotCoord.up(), newCells)) == Lambda) {
3.99 mine.setCells(newCells);
3.100
3.101 lastScoreChange = score - prevScore;
4.1 --- a/icfp-model/src/main/java/ru/bosony/model/maps/ExampleMaps.java Mon Jul 16 00:05:50 2012 +0400
4.2 +++ b/icfp-model/src/main/java/ru/bosony/model/maps/ExampleMaps.java Mon Jul 16 01:46:54 2012 +0400
4.3 @@ -320,6 +320,38 @@
4.4 ),
4.5 /**
4.6 * <pre>
4.7 + #################
4.8 + #A .@@@@@@#
4.9 + # .. #*...*1#
4.10 + # .##########*##
4.11 + # ..@ \\\\#* #
4.12 + # ..# #####*.#
4.13 + # .##### * #
4.14 + #LR ....... . #
4.15 + #################
4.16 +
4.17 + Trampoline A targets 1
4.18 + Flooding 10
4.19 + Water 0
4.20 + * </pre>
4.21 + */
4.22 + HOROCK_2(
4.23 + "#################\n" +
4.24 + "#A .@@@@@@#\n" +
4.25 + "# .. #*...*1#\n" +
4.26 + "# .##########*##\n" +
4.27 + "# ..@ \\\\\\\\#* #\n" +
4.28 + "# ..# #####*.#\n" +
4.29 + "# .##### * #\n" +
4.30 + "#LR ....... . #\n" +
4.31 + "#################\n" +
4.32 + "\n" +
4.33 + "Trampoline A targets 1\n" +
4.34 + "Flooding 10\n" +
4.35 + "Water 0"
4.36 + ),
4.37 + /**
4.38 + * <pre>
4.39 ###############
4.40 #***...R......#
4.41 #***... ...*..#
5.1 --- a/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Mon Jul 16 00:05:50 2012 +0400
5.2 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Mon Jul 16 01:46:54 2012 +0400
5.3 @@ -28,21 +28,23 @@
5.4 protected Cell[][] cells;
5.5 protected int sizeX;
5.6 protected int sizeY;
5.7 - protected int waterLevel = 0;
5.8 - protected int flooding = 0;
5.9 - protected int robotWaterproof = 10;
5.10 - protected int growth = 25;
5.11 - protected int razorsCount = 0;
5.12 - protected static Pattern minePattern = Pattern
5.13 - .compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*|Trampoline.*|Growth.*|Razors.*)|$)");
5.14 - protected static Pattern waterPattern = Pattern.compile("(?s).*(?<=.*Water )(\\d+).*");
5.15 - protected static Pattern floodingPattern = Pattern.compile("(?s).*(?<=.*Flooding )(\\d+).*");
5.16 - protected static Pattern waterproofPattern = Pattern.compile("(?s).*(?<=.*Waterproof )(\\d+).*");
5.17 - protected static Pattern growthPattern = Pattern.compile("(?s).*(?<=.*Growth )(\\d+).*");
5.18 - protected static Pattern razorsPattern = Pattern.compile("(?s).*(?<=.*Razors )(\\d+).*");
5.19 - protected static Pattern trampolinePattern = Pattern
5.20 - .compile("(?s).*?Trampoline ([A-I]) targets ([1-9]).*");
5.21 - protected static String firstTrampolineRegexp = "(?s).*?Trampoline ([A-I]) targets ([1-9])";
5.22 + protected int waterLevel = 0;
5.23 + protected int flooding = 0;
5.24 + protected int robotWaterproof = 10;
5.25 + protected int growth = 25;
5.26 + protected int razorsCount = 0;
5.27 + protected int lambdasAndHighOrderRocksStartCount = 0;
5.28 + protected static Pattern minePattern = Pattern
5.29 + .compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*|Trampoline.*|Growth.*|Razors.*)|$)");
5.30 + protected static Pattern waterPattern = Pattern.compile("(?s).*(?<=.*Water )(\\d+).*");
5.31 + protected static Pattern floodingPattern = Pattern.compile("(?s).*(?<=.*Flooding )(\\d+).*");
5.32 + protected static Pattern waterproofPattern = Pattern
5.33 + .compile("(?s).*(?<=.*Waterproof )(\\d+).*");
5.34 + protected static Pattern growthPattern = Pattern.compile("(?s).*(?<=.*Growth )(\\d+).*");
5.35 + protected static Pattern razorsPattern = Pattern.compile("(?s).*(?<=.*Razors )(\\d+).*");
5.36 + protected static Pattern trampolinePattern = Pattern
5.37 + .compile("(?s).*?Trampoline ([A-I]) targets ([1-9]).*");
5.38 + protected static String firstTrampolineRegexp = "(?s).*?Trampoline ([A-I]) targets ([1-9])";
5.39
5.40 public Mine(String text) {
5.41 fromText(text);
5.42 @@ -52,6 +54,7 @@
5.43 throw new RuntimeException("New map does not contain a robot!");
5.44 if (findCells(ClosedLambdaLift).size() != 1)
5.45 throw new RuntimeException("New map does not contain a ClosedLambdaLift!");
5.46 + lambdasAndHighOrderRocksStartCount = findCells(Lambda).size() + findCells(CellContent.HighOrderRock).size();
5.47 }
5.48
5.49 @Override
5.50 @@ -294,4 +297,8 @@
5.51 this.razorsCount = razorsCount;
5.52 }
5.53
5.54 + public int getLambdasAndHighOrderRocksStartCount() {
5.55 + return lambdasAndHighOrderRocksStartCount;
5.56 + }
5.57 +
5.58 }
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/icfp-model/src/test/java/ru/bosony/tests/TestHighOrderRocks.java Mon Jul 16 01:46:54 2012 +0400
6.3 @@ -0,0 +1,28 @@
6.4 +package ru.bosony.tests;
6.5 +
6.6 +import static org.junit.Assert.assertEquals;
6.7 +
6.8 +import org.junit.Test;
6.9 +
6.10 +import ru.bosony.model.game.Game;
6.11 +import ru.bosony.model.game.GameState;
6.12 +import ru.bosony.model.maps.ExampleMaps;
6.13 +import ru.bosony.model.mine.Mine;
6.14 +
6.15 +/**
6.16 + * @author indvdum (gotoindvdum[at]gmail[dot]com) <br>
6.17 + * 16.07.2012 1:43:29
6.18 + *
6.19 + */
6.20 +public class TestHighOrderRocks {
6.21 +
6.22 + @Test
6.23 + public void test() {
6.24 + String map = ExampleMaps.HOROCK_2.getMap();
6.25 + Mine mine = new Mine(map);
6.26 + Game game = new Game(mine);
6.27 + assertEquals(game.move("RRRRRRRRRRRRLLLLLLLLLLUUURRRRRRRRLLLLLLDULLLLLUUULRLLLLRRLLRLULLLLLLLLLLDDDDDD"),
6.28 + GameState.Win);
6.29 + }
6.30 +
6.31 +}