# HG changeset patch # User indvdum (gotoindvdum[at]gmail[dot]com) # Date 1342294031 -14400 # Node ID 59fca1d3cb55ee8f8242c22dfd297ab81e89e4e8 # Parent 3ceb637cf53d6ec8d12edb3dfa8b69824f567a63# Parent 9e380ddb888578eb242570de21b114b0cd9fd979 Merge with branch indvdum diff -r 3ceb637cf53d -r 59fca1d3cb55 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,8 @@ +syntax: glob +*.log + +syntax: regexp +.*target\/.* +.*\.settings\/.* +\.classpath +\.project diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/pom.xml Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,61 @@ + + + 4.0.0 + icfp-model + icfp-model + jar + icfp-model + + ru.bosony.icfp-2012 + icfp-2012-all + 0.0.1.0-SNAPSHOT + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + groovy-eclipse-compiler + nowarn + true + + + + org.codehaus.groovy + groovy-eclipse-compiler + ${groovy-eclipse-compiler.version} + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + + + add-source + generate-sources + + add-source + + + + src/main/groovy + src/test/groovy + + + + + + + + + + org.codehaus.groovy + groovy-all + ${groovy.version} + + + diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,40 @@ +package ru.bosony.model.cellscontents; + +import ru.bosony.model.io.TextRepresentable; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 13.07.2012 21:25:49 + * + */ +public enum CellContent implements TextRepresentable { + + ClosedLambdaLift("L"), + Earth("."), + Empty(" "), + Lambda("\\"), + MiningRobot("R"), + OpenLambdaLift("O"), + Rock("*"), + Wall("#"); + + private String text; + + private CellContent(String text) { + this.text = text; + } + + @Override + public String toText() { + return text; + } + + public static CellContent fromText(String text) { + for (CellContent content : values()) { + if (text != null && text.equals(content.toText())) + return content; + } + return null; + } + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/main/java/ru/bosony/model/game/Game.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/main/java/ru/bosony/model/game/Game.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,199 @@ +package ru.bosony.model.game; + +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.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 java.util.Arrays; + +import ru.bosony.model.cellscontents.CellContent; +import ru.bosony.model.mine.Cell; +import ru.bosony.model.mine.Coordinate; +import ru.bosony.model.mine.Mine; +import ru.bosony.model.moving.Movement; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 14.07.2012 22:51:20 + * + */ +public class Game { + + Mine mine = null; + private Cell[][] prevStepCells; + protected int score = 0; + protected int lastScoreChange = 0; + protected GameState state = GameState.Game; + protected int lambdaCollectedCount = 0; + + public Game(Mine mine) { + this.mine = mine; + } + + public Mine getMine() { + return mine; + } + + protected Cell getCell(Coordinate coordinate, Cell[][] cells) { + if (coordinate == null) + return null; + int x = coordinate.x; + int y = coordinate.y; + if (cells == null) + return null; + if (x < 1 || x > mine.getSizeX() || y < 1 || y > mine.getSizeY()) + return null; + return cells[x - 1][mine.getSizeY() - y]; + } + + protected void moveRobot(Cell nextRobotCell) { + mine.getRobotCell().setContent(Empty); + nextRobotCell.setContent(MiningRobot); + mine.setRobotCell(nextRobotCell); + } + + public GameState move(Movement mov) { + if (state != GameState.Game) + throw new RuntimeException("Game over!"); + + // Score + int prevScore = score; + score--; + + // Moving and scoring + Coordinate nextRobotCoord = null; + switch (mov) { + case ABORT: + score += 25 * lambdaCollectedCount; + + lastScoreChange = score - prevScore; + state = GameState.Abort; + return state; + case WAIT: + break; + case LEFT: + nextRobotCoord = mine.getRobotCell().getCoordinate().left(); + break; + case UP: + nextRobotCoord = mine.getRobotCell().getCoordinate().up(); + break; + case RIGHT: + nextRobotCoord = mine.getRobotCell().getCoordinate().right(); + break; + case DOWN: + nextRobotCoord = mine.getRobotCell().getCoordinate().down(); + break; + } + Cell nextRobotCell = mine.getCell(nextRobotCoord); + CellContent nextRobotCellContent = getContent(nextRobotCell); + if (nextRobotCellContent == Empty || nextRobotCellContent == Earth) { + moveRobot(nextRobotCell); + } else if (nextRobotCellContent == Lambda) { + moveRobot(nextRobotCell); + lambdaCollectedCount++; + score += 25; + } else if (nextRobotCellContent == OpenLambdaLift) { + moveRobot(nextRobotCell); + score += 50 * lambdaCollectedCount; + + lastScoreChange = score - prevScore; + state = GameState.Win; + return state; + } else if (mine.getRobotCell().getCoordinate().right() == nextRobotCoord && nextRobotCellContent == Rock + && getContent(mine.getCell(nextRobotCoord.right())) == Empty) { + moveRobot(nextRobotCell); + mine.getCell(nextRobotCoord.right()).setContent(Rock); + } else if (mine.getRobotCell().getCoordinate().left() == nextRobotCoord && nextRobotCellContent == Rock + && getContent(mine.getCell(nextRobotCoord.left())) == Empty) { + moveRobot(nextRobotCell); + mine.getCell(nextRobotCoord.left()).setContent(Rock); + } else { + mov = Movement.WAIT; + } + + // Other ending conditions + if (getContent(getCell(mine.getRobotCell().getCoordinate().up(), prevStepCells)) != Rock + && getContent(mine.getCell(mine.getRobotCell().getCoordinate().up())) == Rock) { + lastScoreChange = score - prevScore; + state = GameState.Lose; + return state; + } + + // World changes + Cell[][] newCells = Arrays.copyOf(mine.getCells(), mine.getCells().length); + for (int y = 1; y <= mine.getSizeY(); y++) { + for (int x = 1; x <= mine.getSizeX(); x++) { + Coordinate curCoord = new Coordinate(x, y); + Coordinate leftCoord = curCoord.left(); + Coordinate upCoord = curCoord.up(); + Coordinate rightCoord = curCoord.right(); + Coordinate downCoord = curCoord.down(); + Coordinate leftAndUpCoord = curCoord.leftAndUp(); + Coordinate rightAndUpCoord = curCoord.rightAndUp(); + Coordinate rightAndDownCoord = curCoord.rightAndDown(); + Coordinate leftAndDownCoord = curCoord.leftAndDown(); + Cell curCell = mine.getCell(curCoord); + Cell leftCell = mine.getCell(leftCoord); + Cell upCell = mine.getCell(upCoord); + Cell rightCell = mine.getCell(rightCoord); + Cell downCell = mine.getCell(downCoord); + Cell leftAndUpCell = mine.getCell(leftAndUpCoord); + Cell rightAndUpCell = mine.getCell(rightAndUpCoord); + Cell rightAndDownCell = mine.getCell(rightAndDownCoord); + Cell leftAndDownCell = mine.getCell(leftAndDownCoord); + + if (getContent(curCell) == Rock && getContent(downCell) == Empty) { + getCell(curCoord, newCells).setContent(Empty); + getCell(downCoord, newCells).setContent(Rock); + } else if (getContent(curCell) == Rock && getContent(downCell) == Empty + && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) { + getCell(curCoord, newCells).setContent(Empty); + getCell(rightAndDownCoord, newCells).setContent(Rock); + } else if (getContent(curCell) == Rock && getContent(downCell) == Rock + && (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) == 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) { + getCell(curCoord, newCells).setContent(OpenLambdaLift); + } + } + } + prevStepCells = mine.getCells(); + mine.setCells(newCells); + + lastScoreChange = score - prevScore; + state = GameState.Game; + return state; + } + + protected CellContent getContent(Cell cell) { + if (cell == null) + return null; + return cell.getContent(); + } + + public int getLastScoreChange() { + return lastScoreChange; + } + + public int getScore() { + return score; + } + + public GameState getState() { + return state; + } + + public int getLambdaCollectedCount() { + return lambdaCollectedCount; + } +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/main/java/ru/bosony/model/game/GameState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/main/java/ru/bosony/model/game/GameState.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,13 @@ +package ru.bosony.model.game; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 14.07.2012 21:15:05 + * + */ +public enum GameState { + Game, + Win, + Abort, + Lose, +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/main/java/ru/bosony/model/io/TextRepresentable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/main/java/ru/bosony/model/io/TextRepresentable.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,12 @@ +package ru.bosony.model.io; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 13.07.2012 21:32:34 + * + */ +public interface TextRepresentable { + + public String toText(); + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/main/java/ru/bosony/model/mine/Cell.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Cell.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,32 @@ +package ru.bosony.model.mine; + +import ru.bosony.model.cellscontents.CellContent; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 13.07.2012 22:10:18 + * + */ +public class Cell { + + protected Coordinate coordinate; + protected CellContent content; + + public Cell(Coordinate coordinate, CellContent content) { + this.coordinate = coordinate; + this.content = content; + } + + public CellContent getContent() { + return content; + } + + public void setContent(CellContent content) { + this.content = content; + } + + public Coordinate getCoordinate() { + return coordinate; + } + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/main/java/ru/bosony/model/mine/Coordinate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Coordinate.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,92 @@ +package ru.bosony.model.mine; + +import java.util.HashSet; +import java.util.Set; + +import ru.bosony.model.moving.Movement; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 14.07.2012 1:07:51 + * + */ +public class Coordinate { + + public Coordinate(int x, int y) { + this.x = x; + this.y = y; + } + + public int x; + public int y; + + public Coordinate left() { + return new Coordinate(x - 1, y); + } + + public Coordinate up() { + return new Coordinate(x, y + 1); + } + + public Coordinate right() { + return new Coordinate(x + 1, y); + } + + public Coordinate down() { + return new Coordinate(x, y - 1); + } + + public Coordinate leftAndUp() { + return new Coordinate(x - 1, y + 1); + } + + public Coordinate rightAndUp() { + return new Coordinate(x + 1, y + 1); + } + + public Coordinate rightAndDown() { + return new Coordinate(x + 1, y - 1); + } + + public Coordinate leftAndDown() { + return new Coordinate(x - 1, y - 1); + } + + public Set getNeighboringCoordinates() { + Set coords = new HashSet(); + coords.add(left()); + coords.add(up()); + coords.add(right()); + coords.add(down()); + coords.add(leftAndUp()); + coords.add(rightAndUp()); + coords.add(rightAndDown()); + coords.add(leftAndDown()); + return coords; + } + + public Movement getNecessaryMovement(Coordinate nCoordinate) { + if (left().equals(nCoordinate)) + return Movement.LEFT; + if (up().equals(nCoordinate)) + return Movement.UP; + if (right().equals(nCoordinate)) + return Movement.RIGHT; + if (down().equals(nCoordinate)) + return Movement.DOWN; + return null; + } + + @Override + public int hashCode() { + return x ^ y; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Coordinate) + return x == ((Coordinate)obj).x && y == ((Coordinate)obj).y; + return super.equals(obj); + } + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/main/java/ru/bosony/model/mine/Mine.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,161 @@ +package ru.bosony.model.mine; + +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.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 java.util.HashSet; +import java.util.Set; + +import ru.bosony.model.cellscontents.CellContent; +import ru.bosony.model.io.TextRepresentable; +import ru.bosony.model.moving.Movement; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 14.07.2012 2:02:18 + * + */ +public class Mine implements TextRepresentable { + + protected Cell[][] cells; + protected int sizeX; + protected int sizeY; + protected Cell robotCell; + + public Mine(String text) { + fromText(text); + if (findCells(OpenLambdaLift).size() != 0) + throw new RuntimeException("Detected OpenLambdaLift in new map!"); + if (findCells(MiningRobot).size() != 1) + 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!"); + for (Cell cell : findCells(MiningRobot)) + robotCell = cell; + } + + @Override + public String toText() { + String text = ""; + for (int y = 0; y < sizeY; y++) { + for (int x = 0; x < sizeX; x++) { + text += cells[x][y].getContent().toText(); + } + text += "\n"; + } + return text.replaceAll("\n*$", ""); + } + + protected void fromText(String text) { + String[] rows = text.split("\n+"); + int y = rows.length; + int x = 0; + for (String row : rows) { + if (x < row.length()) + x = row.length(); + } + sizeX = x; + sizeY = y; + cells = new Cell[x][y]; + for (int curY = 0; curY < rows.length; curY++) { + String row = rows[curY]; + for (int curX = 0; curX < row.length() || curX < x; curX++) { + CellContent content = null; + if (curX < row.length()) + content = CellContent.fromText("" + row.charAt(curX)); + else + content = Empty; + Cell cell = new Cell(new Coordinate(curX + 1, rows.length - curY), content); + cells[curX][curY] = cell; + } + } + } + + public Cell getCell(Coordinate coordinate) { + if (coordinate == null) + return null; + int x = coordinate.x; + int y = coordinate.y; + if (x < 1 || x > sizeX || y < 1 || y > sizeY) + return null; + return cells[x - 1][sizeY - y]; + } + + @Override + public String toString() { + return toText(); + } + + public int getSizeX() { + return sizeX; + } + + public int getSizeY() { + return sizeY; + } + + public Set getAvailableRobotMovements() { + Set movs = new HashSet(); + Set nCells = getNeighboringCells(robotCell); + for (Cell nCell : nCells) { + CellContent nContent = nCell.getContent(); + Coordinate nCoordinate = nCell.getCoordinate(); + Cell rightNCell = getCell(nCoordinate.right()); + Cell leftNCell = getCell(nCoordinate.left()); + if (nContent == Empty + || nContent == Earth + || nContent == Lambda + || nContent == OpenLambdaLift + || (nContent == Rock && robotCell.getCoordinate().right().equals(nCoordinate) && rightNCell != null && rightNCell + .getContent() == Empty) + || (nContent == Rock && robotCell.getCoordinate().left().equals(nCoordinate) && leftNCell != null && leftNCell + .getContent() == Empty)) { + Movement mov = robotCell.getCoordinate().getNecessaryMovement(nCoordinate); + movs.add(mov); + } + } + movs.add(Movement.ABORT); + movs.add(Movement.WAIT); + return movs; + } + + public Set getNeighboringCells(Cell cell) { + Set cells = new HashSet(); + for (Coordinate coordinate : cell.getCoordinate().getNeighboringCoordinates()) + cells.add(getCell(coordinate)); + return cells; + } + + public Set findCells(CellContent content) { + Set finded = new HashSet(); + for (int y = sizeY - 1; y >= 0; y--) { + for (int x = 0; x < sizeX - 1; x++) { + if (cells[x][y].getContent() == content) + finded.add(cells[x][y]); + } + } + return finded; + } + + public Cell[][] getCells() { + return cells; + } + + public void setCells(Cell[][] cells) { + this.cells = cells; + } + + public Cell getRobotCell() { + return robotCell; + } + + public void setRobotCell(Cell robotCell) { + this.robotCell = robotCell; + } + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/main/java/ru/bosony/model/moving/Movement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/main/java/ru/bosony/model/moving/Movement.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,38 @@ +package ru.bosony.model.moving; + +import ru.bosony.model.io.TextRepresentable; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 14.07.2012 0:40:35 + * + */ +public enum Movement implements TextRepresentable { + + LEFT("L"), + RIGHT("R"), + UP("U"), + DOWN("D"), + WAIT("W"), + ABORT("A"); + + private String text; + + private Movement(String text) { + this.text = text; + } + + @Override + public String toText() { + return text; + } + + public static Movement fromText(String text) { + for (Movement content : values()) { + if (text != null && text.equals(content.toText())) + return content; + } + return null; + } + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/test/java/ru/bosony/tests/TestMineParsing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/test/java/ru/bosony/tests/TestMineParsing.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,246 @@ +package ru.bosony.tests; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import ru.bosony.model.cellscontents.CellContent; +import ru.bosony.model.mine.Cell; +import ru.bosony.model.mine.Mine; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 14.07.2012 0:37:14 + * + */ +public class TestMineParsing { + + protected static String alignMap(String map) { + String alignedMap = ""; + String[] rows = map.split("\n"); + int y = rows.length; + int x = 0; + for (String row : rows) { + if (x < row.length()) + x = row.length(); + } + for (int curY = 0; curY < rows.length; curY++) { + String row = rows[curY]; + for (int curX = 0; curX < row.length() || curX < x; curX++) { + if (curX < row.length()) + alignedMap += row.charAt(curX); + else + alignedMap += " "; + } + alignedMap += "\n"; + } + return alignedMap.replaceAll("\n$", ""); + } + + @Test + public void testMap01() { + String map = + "######\n" + + "#. *R#\n" + + "# \\.#\n" + + "#\\ * #\n" + + "L .\\#\n" + + "######"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap02() { + String map = + "#######\n" + + "#..***#\n" + + "#..\\\\\\#\n" + + "#...**#\n" + + "#.*.*\\#\n" + + "LR....#\n" + + "#######"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap03() { + String map = + "########\n" + + "#..R...#\n" + + "#..*...#\n" + + "#..#...#\n" + + "#.\\.\\..L\n" + + "####**.#\n" + + "#\\.....#\n" + + "#\\..* .#\n" + + "########"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap04() { + String map = + "#########\n" + + "#.*..#\\.#\n" + + "#.\\..#\\.L\n" + + "#.R .##.#\n" + + "#.\\ ...#\n" + + "#..\\ ..#\n" + + "#...\\ ##\n" + + "#....\\ \\#\n" + + "#########"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap05() { + String map = + "############\n" + + "#..........#\n" + + "#.....*....#\n" + + "#..\\\\\\\\\\\\..#\n" + + "#. ....#\n" + + "#..\\\\\\\\\\\\\\.#\n" + + "#..\\.. .#\n" + + "#..\\.. ....#\n" + + "#..... ..* #\n" + + "#..### ### #\n" + + "#...R#\\#\\\\.#\n" + + "######L#####"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap06() { + String map = + "###############\n" + + "#\\\\\\.......** #\n" + + "#\\\\#.#####...##\n" + + "#\\\\#.....*##. #\n" + + "#\\#####\\...## #\n" + + "#\\......####* #\n" + + "#\\.######* #.\\#\n" + + "#\\.#. *...##.##\n" + + "#\\##. .. *...#\n" + + "#\\...... L#.#.#\n" + + "###########.#.#\n" + + "#\\..........#.#\n" + + "##.##########.#\n" + + "#R.#\\.........#\n" + + "###############"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap07() { + String map = + " #######\n" + + " ## *#\n" + + " ##R *##\n" + + " ##\\\\\\\\##\n" + + " ##....##\n" + + " ##..\\ . ##\n" + + " ## . L . ##\n" + + " ##\\\\\\# #\\\\\\\\##\n" + + " ###### #######"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap08() { + String map = + "##############\n" + + "#\\\\... ......#\n" + + "###.#. ...*..#\n" + + " #.#. ... ..#\n" + + "### #. \\ ..#\n" + + "#. .#..... **#######\n" + + "#.#\\#..... ..\\\\\\*. #\n" + + "#*\\\\#.###. ####\\\\\\ #\n" + + "#\\\\.#. ...## \\ #\n" + + "#\\#.#..... ....# \\ # \n" + + "###.#..... ....# ##\n" + + "#\\\\.#..... ....#\\ # \n" + + "########.. ..###*####\n" + + "#......... .........#\n" + + "#......... ....***..#\n" + + "#..\\\\\\\\\\ # ####.....#\n" + + "#........*R..\\\\\\ .#\n" + + "##########L##########"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap09() { + String map = + " #L#######\n" + + " #*** \\\\ #\n" + + " #\\\\\\ .. #\n" + + "#########.## ##########\n" + + "#.......\\ ..........* .#\n" + + "#*******\\......#....#\\\\ .#\n" + + "###\\.\\\\\\...**..#....... *#\n" + + "#*****\\\\ .\\\\..## #\\.#\n" + + "######### .... ##########\n" + + " # #\n" + + " ####*#### \n" + + " #.......#\n" + + "######### \\\\\\\\*##########\n" + + "#*\\\\ **# *..*\\ \\\\\\\\\\#\n" + + "#.\\**\\*** .....**.# \\\\##\\#\n" + + "#\\R...... .\\\\.. \\\\\\\\\\#\n" + + "##########################"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + + @Test + public void testMap10() { + String map = + "#############################\n" + + "#..........................\\#\n" + + "#..\\\\###...#.... ###.#\n" + + "#..\\*\\\\\\.. #.... ..##\\\\..\\#.#\n" + + "#..\\*\\.... #.... ..#\\#....#.#\n" + + "#...\\###.. #.... ....#....#.#\n" + + "#... ..... ..... .####......#\n" + + "#\\\\. #.... .......#\n" + + "#... #..#. .....*\\ ##.......#\n" + + "#.#....... ...#.. ....######\n" + + "#. ...#... ...#.\\ ....#..* #\n" + + "##........ ...#.. #....#.#\\\\#\n" + + "#.....*... .....*\\#\\\\.....*.#\n" + + "#.***.* .......*\\****.....#.#\n" + + "#.\\\\\\.. ................ .#\n" + + "#.##### .###### ##### #\n" + + "#....\\\\.................... #\n" + + "#....****...#.##.....\\\\\\\\..\\#\n" + + "#....\\\\\\\\...#.........*....\\#\n" + + "#....\\\\\\\\...#.\\\\. #\\###.\\#\n" + + "#.... ..#.... ...#\\\\\\\\. #\n" + + "#........ ..#.... ...#..... #\n" + + "#........ ........#R#\n" + + "###########################L#"; + Mine mine = new Mine(map); + String parsed = mine.toText(); + assertEquals(alignMap(map), parsed); + } + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/test/java/ru/bosony/tests/TestMovements.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/test/java/ru/bosony/tests/TestMovements.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,47 @@ +package ru.bosony.tests; + +import static org.junit.Assert.*; + +import java.util.Set; + +import org.junit.Test; + +import ru.bosony.model.mine.Mine; +import ru.bosony.model.moving.Movement; + +/** + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 14.07.2012 2:29:05 + * + */ +public class TestMovements { + + @Test + public void test() { + /* Map 01 (6x6) + * + ###### + #. *R# + # \.# + #\ * # + L .\# + ###### + */ + String map = + "######\n" + + "#. *R#\n" + + "# \\.#\n" + + "#\\ * #\n" + + "L .\\#\n" + + "######"; + Mine mine = new Mine(map); + assertEquals(mine.getSizeX(), 6); + assertEquals(mine.getSizeY(), 6); + Set movs = mine.getAvailableRobotMovements(); + assertFalse(movs.contains(Movement.UP)); + assertFalse(movs.contains(Movement.RIGHT)); + assertTrue(movs.contains(Movement.DOWN)); + assertTrue(movs.contains(Movement.LEFT)); + } + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 icfp-model/src/test/java/ru/bosony/tests/TestScore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/icfp-model/src/test/java/ru/bosony/tests/TestScore.java Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,37 @@ +package ru.bosony.tests; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import ru.bosony.model.game.Game; +import ru.bosony.model.mine.Mine; +import ru.bosony.model.moving.Movement; + +public class TestScore { + + @Test + public void test() { + /* Map 01 (6x6) + * + ###### + #. *R# + # \.# + #\ * # + L .\# + ###### + */ + String map = + "######\n" + + "#. *R#\n" + + "# \\.#\n" + + "#\\ * #\n" + + "L .\\#\n" + + "######"; + Mine mine = new Mine(map); + Game game = new Game(mine); + game.move(Movement.ABORT); + assertEquals(game.getScore(), -1); + } + +} diff -r 3ceb637cf53d -r 59fca1d3cb55 pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Sat Jul 14 23:27:11 2012 +0400 @@ -0,0 +1,75 @@ + + + 4.0.0 + ru.bosony.icfp-2012 + icfp-2012-all + icfp-2012-all + 0.0.1.0-SNAPSHOT + pom + + 2.0.0 + 2.3.2 + 2.5.1-1 + 1.5 + 1.6.6 + 2.5 + 4.10 + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.6 + 1.6 + UTF-8 + true + 128m + 512m + + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + UTF-8 + + + + + + + + ru.bosony.icfp-2012 + icfp-model + ${project.version} + + + + + + org.slf4j + slf4j-simple + ${slf4j-simple.version} + + + junit + junit + ${junit.version} + test + + + + icfp-model + +