# HG changeset patch # User indvdum (gotoindvdum[at]gmail[dot]com) # Date 1342388814 -14400 # Node ID 666821484adcf4991003dbb94f79d2fd96111551 # Parent 66aa96e8fd92d007d58022232c5cb69f033e3443 Add HighOrderRock diff -r 66aa96e8fd92 -r 666821484adc icfp-interpreter/src/main/java/ru/bosony/interpreters/TextInterpreter.java --- a/icfp-interpreter/src/main/java/ru/bosony/interpreters/TextInterpreter.java Mon Jul 16 00:05:50 2012 +0400 +++ b/icfp-interpreter/src/main/java/ru/bosony/interpreters/TextInterpreter.java Mon Jul 16 01:46:54 2012 +0400 @@ -46,18 +46,21 @@ writer.newLine(); writer.write("********************************************************************************"); writer.newLine(); - writer.write("State: " + game.getState()); + writer.write("State: " + game.getState()); writer.newLine(); - writer.write("Score: " + game.getScore() + " (" + writer.write("Score: " + game.getScore() + " (" + (game.getLastScoreChange() >= 0 ? "+" + game.getLastScoreChange() : game.getLastScoreChange()) + ")"); writer.newLine(); - writer.write("Steps: " + game.getRoute().size()); + writer.write("Steps: " + game.getRoute().size()); writer.newLine(); - writer.write("Route: " + game.getStringRoute()); + writer.write("Route: " + game.getStringRoute()); writer.newLine(); - writer.write("Underwater: " + game.getUnderwater() + " of " + mine.getRobotWaterproof()); + writer.write("Underwater: " + game.getUnderwater() + " of " + mine.getRobotWaterproof()); writer.newLine(); - writer.write("Razors: " + mine.getRazorsCount()); + writer.write("Razors: " + mine.getRazorsCount()); + writer.newLine(); + writer.write("Labmdas found: " + game.getLambdaCollectedCount() + " of " + + mine.getLambdasAndHighOrderRocksStartCount()); writer.newLine(); writer.newLine(); writer.write(mine.toText()); diff -r 66aa96e8fd92 -r 666821484adc icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java --- a/icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java Mon Jul 16 00:05:50 2012 +0400 +++ b/icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java Mon Jul 16 01:46:54 2012 +0400 @@ -39,7 +39,8 @@ Target8("8"), Target9("9"), WadlersBeard("W"), - HuttonsRazor("!"); + HuttonsRazor("!"), + HighOrderRock("@"); private String text; private CellContent trampolineTarget = null; diff -r 66aa96e8fd92 -r 666821484adc icfp-model/src/main/java/ru/bosony/model/game/Game.java --- a/icfp-model/src/main/java/ru/bosony/model/game/Game.java Mon Jul 16 00:05:50 2012 +0400 +++ b/icfp-model/src/main/java/ru/bosony/model/game/Game.java Mon Jul 16 01:46:54 2012 +0400 @@ -3,11 +3,12 @@ import static ru.bosony.model.cellscontents.CellContent.ClosedLambdaLift; import static ru.bosony.model.cellscontents.CellContent.Earth; import static ru.bosony.model.cellscontents.CellContent.Empty; +import static ru.bosony.model.cellscontents.CellContent.HighOrderRock; +import static ru.bosony.model.cellscontents.CellContent.HuttonsRazor; import static ru.bosony.model.cellscontents.CellContent.Lambda; import static ru.bosony.model.cellscontents.CellContent.MiningRobot; import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift; import static ru.bosony.model.cellscontents.CellContent.Rock; -import static ru.bosony.model.cellscontents.CellContent.HuttonsRazor; import static ru.bosony.model.cellscontents.CellContent.WadlersBeard; import java.util.ArrayList; @@ -130,6 +131,14 @@ && getContent(mine.getCell(nextRobotCoord.left())) == Empty) { moveRobot(nextRobotCell); mine.getCell(nextRobotCoord.left()).setContent(Rock); + } else if (robotCoord.right().equals(nextRobotCoord) && nextRobotCellContent == HighOrderRock + && getContent(mine.getCell(nextRobotCoord.right())) == Empty) { + moveRobot(nextRobotCell); + mine.getCell(nextRobotCoord.right()).setContent(HighOrderRock); + } else if (robotCoord.left().equals(nextRobotCoord) && nextRobotCellContent == HighOrderRock + && getContent(mine.getCell(nextRobotCoord.left())) == Empty) { + moveRobot(nextRobotCell); + mine.getCell(nextRobotCoord.left()).setContent(HighOrderRock); } else if (CellContent.getTrampolines().contains(nextRobotCellContent) && CellContent.getTargets().contains(nextRobotCellContent.getTrampolineTarget())) { CellContent trampoline = nextRobotCellContent; @@ -174,20 +183,53 @@ if (getContent(curCell) == Rock && getContent(downCell) == Empty) { getCell(curCoord, newCells).setContent(Empty); getCell(downCoord, newCells).setContent(Rock); - } else if (getContent(curCell) == Rock && getContent(downCell) == Rock + } else if (getContent(curCell) == HighOrderRock && getContent(downCell) == Empty) { + getCell(curCoord, newCells).setContent(Empty); + if (getContent(mine.getCell(downCoord.down())) != Empty) + getCell(downCoord, newCells).setContent(Lambda); + else + getCell(downCoord, newCells).setContent(HighOrderRock); + } else if (getContent(curCell) == Rock + && (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock) && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) { getCell(curCoord, newCells).setContent(Empty); getCell(rightAndDownCoord, newCells).setContent(Rock); - } else if (getContent(curCell) == Rock && getContent(downCell) == Rock + } else if (getContent(curCell) == HighOrderRock + && (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock) + && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) { + getCell(curCoord, newCells).setContent(Empty); + if (getContent(mine.getCell(rightAndDownCoord.down())) != Empty) + getCell(rightAndDownCoord, newCells).setContent(Lambda); + else + getCell(rightAndDownCoord, newCells).setContent(HighOrderRock); + } else if (getContent(curCell) == Rock + && (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock) && (getContent(rightCell) != Empty || getContent(rightAndDownCell) != Empty) && getContent(leftCell) == Empty && getContent(leftAndDownCell) == Empty) { getCell(curCoord, newCells).setContent(Empty); getCell(leftAndDownCoord, newCells).setContent(Rock); + } else if (getContent(curCell) == HighOrderRock + && (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock) + && (getContent(rightCell) != Empty || getContent(rightAndDownCell) != Empty) + && getContent(leftCell) == Empty && getContent(leftAndDownCell) == Empty) { + getCell(curCoord, newCells).setContent(Empty); + if (getContent(mine.getCell(leftAndDownCoord.down())) != Empty) + getCell(leftAndDownCoord, newCells).setContent(Lambda); + else + getCell(leftAndDownCoord, newCells).setContent(HighOrderRock); } else if (getContent(curCell) == Rock && getContent(downCell) == Lambda && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) { getCell(curCoord, newCells).setContent(Empty); getCell(rightAndDownCoord, newCells).setContent(Rock); - } else if (getContent(curCell) == ClosedLambdaLift && mine.findCells(Lambda).size() == 0) { + } else if (getContent(curCell) == HighOrderRock && getContent(downCell) == Lambda + && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) { + getCell(curCoord, newCells).setContent(Empty); + if (getContent(mine.getCell(rightAndDownCoord.down())) != Empty) + getCell(rightAndDownCoord, newCells).setContent(Lambda); + else + getCell(rightAndDownCoord, newCells).setContent(HighOrderRock); + } else if (getContent(curCell) == ClosedLambdaLift + && mine.getLambdasAndHighOrderRocksStartCount() == lambdaCollectedCount) { getCell(curCoord, newCells).setContent(OpenLambdaLift); } else if (getContent(curCell) == WadlersBeard && mine.getGrowth() > 0 && route.size() % mine.getGrowth() == 0) { @@ -213,7 +255,11 @@ // Other ending conditions robotCoord = mine.getRobotCell().getCoordinate(); - if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock) { + if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock + || getContent(mine.getCell(robotCoord.up())) != HighOrderRock + && getContent(getCell(robotCoord.up(), newCells)) == HighOrderRock + || getContent(mine.getCell(robotCoord.up())) == Empty + && getContent(getCell(robotCoord.up(), newCells)) == Lambda) { mine.setCells(newCells); lastScoreChange = score - prevScore; diff -r 66aa96e8fd92 -r 666821484adc icfp-model/src/main/java/ru/bosony/model/maps/ExampleMaps.java --- a/icfp-model/src/main/java/ru/bosony/model/maps/ExampleMaps.java Mon Jul 16 00:05:50 2012 +0400 +++ b/icfp-model/src/main/java/ru/bosony/model/maps/ExampleMaps.java Mon Jul 16 01:46:54 2012 +0400 @@ -320,6 +320,38 @@ ), /** *
+		#################
+		#A       .@@@@@@#
+		#  ..    #*...*1#
+		#  .##########*##
+		#  ..@   \\\\#* #
+		#  ..#   #####*.#
+		#   .#####    * #
+		#LR .......   . #
+		#################
+		
+		Trampoline A targets 1
+		Flooding 10
+		Water 0
+	 * 
+ */ + HOROCK_2( + "#################\n" + + "#A .@@@@@@#\n" + + "# .. #*...*1#\n" + + "# .##########*##\n" + + "# ..@ \\\\\\\\#* #\n" + + "# ..# #####*.#\n" + + "# .##### * #\n" + + "#LR ....... . #\n" + + "#################\n" + + "\n" + + "Trampoline A targets 1\n" + + "Flooding 10\n" + + "Water 0" + ), + /** + *
 		###############
 		#***...R......#
 		#***... ...*..#
diff -r 66aa96e8fd92 -r 666821484adc icfp-model/src/main/java/ru/bosony/model/mine/Mine.java
--- a/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java	Mon Jul 16 00:05:50 2012 +0400
+++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java	Mon Jul 16 01:46:54 2012 +0400
@@ -28,21 +28,23 @@
 	protected Cell[][]			cells;
 	protected int				sizeX;
 	protected int				sizeY;
-	protected int				waterLevel				= 0;
-	protected int				flooding				= 0;
-	protected int				robotWaterproof			= 10;
-	protected int				growth					= 25;
-	protected int				razorsCount				= 0;
-	protected static Pattern	minePattern				= Pattern
-																.compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*|Trampoline.*|Growth.*|Razors.*)|$)");
-	protected static Pattern	waterPattern			= Pattern.compile("(?s).*(?<=.*Water )(\\d+).*");
-	protected static Pattern	floodingPattern			= Pattern.compile("(?s).*(?<=.*Flooding )(\\d+).*");
-	protected static Pattern	waterproofPattern		= Pattern.compile("(?s).*(?<=.*Waterproof )(\\d+).*");
-	protected static Pattern	growthPattern			= Pattern.compile("(?s).*(?<=.*Growth )(\\d+).*");
-	protected static Pattern	razorsPattern			= Pattern.compile("(?s).*(?<=.*Razors )(\\d+).*");
-	protected static Pattern	trampolinePattern		= Pattern
-																.compile("(?s).*?Trampoline ([A-I]) targets ([1-9]).*");
-	protected static String		firstTrampolineRegexp	= "(?s).*?Trampoline ([A-I]) targets ([1-9])";
+	protected int				waterLevel							= 0;
+	protected int				flooding							= 0;
+	protected int				robotWaterproof						= 10;
+	protected int				growth								= 25;
+	protected int				razorsCount							= 0;
+	protected int				lambdasAndHighOrderRocksStartCount	= 0;
+	protected static Pattern	minePattern							= Pattern
+																			.compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*|Trampoline.*|Growth.*|Razors.*)|$)");
+	protected static Pattern	waterPattern						= Pattern.compile("(?s).*(?<=.*Water )(\\d+).*");
+	protected static Pattern	floodingPattern						= Pattern.compile("(?s).*(?<=.*Flooding )(\\d+).*");
+	protected static Pattern	waterproofPattern					= Pattern
+																			.compile("(?s).*(?<=.*Waterproof )(\\d+).*");
+	protected static Pattern	growthPattern						= Pattern.compile("(?s).*(?<=.*Growth )(\\d+).*");
+	protected static Pattern	razorsPattern						= Pattern.compile("(?s).*(?<=.*Razors )(\\d+).*");
+	protected static Pattern	trampolinePattern					= Pattern
+																			.compile("(?s).*?Trampoline ([A-I]) targets ([1-9]).*");
+	protected static String		firstTrampolineRegexp				= "(?s).*?Trampoline ([A-I]) targets ([1-9])";
 
 	public Mine(String text) {
 		fromText(text);
@@ -52,6 +54,7 @@
 			throw new RuntimeException("New map does not contain a robot!");
 		if (findCells(ClosedLambdaLift).size() != 1)
 			throw new RuntimeException("New map does not contain a ClosedLambdaLift!");
+		lambdasAndHighOrderRocksStartCount = findCells(Lambda).size() + findCells(CellContent.HighOrderRock).size();
 	}
 
 	@Override
@@ -294,4 +297,8 @@
 		this.razorsCount = razorsCount;
 	}
 
+	public int getLambdasAndHighOrderRocksStartCount() {
+		return lambdasAndHighOrderRocksStartCount;
+	}
+
 }
diff -r 66aa96e8fd92 -r 666821484adc icfp-model/src/test/java/ru/bosony/tests/TestHighOrderRocks.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/icfp-model/src/test/java/ru/bosony/tests/TestHighOrderRocks.java	Mon Jul 16 01:46:54 2012 +0400
@@ -0,0 +1,28 @@
+package ru.bosony.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import ru.bosony.model.game.Game;
+import ru.bosony.model.game.GameState;
+import ru.bosony.model.maps.ExampleMaps;
+import ru.bosony.model.mine.Mine;
+
+/**
+ * @author indvdum (gotoindvdum[at]gmail[dot]com) 
+ * 16.07.2012 1:43:29 + * + */ +public class TestHighOrderRocks { + + @Test + public void test() { + String map = ExampleMaps.HOROCK_2.getMap(); + Mine mine = new Mine(map); + Game game = new Game(mine); + assertEquals(game.move("RRRRRRRRRRRRLLLLLLLLLLUUURRRRRRRRLLLLLLDULLLLLUUULRLLLLRRLLRLULLLLLLLLLLDDDDDD"), + GameState.Win); + } + +}