1.1 --- a/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Tue Jul 17 21:38:39 2012 +0400
1.2 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Wed Jul 18 01:25:43 2012 +0400
1.3 @@ -8,6 +8,7 @@
1.4 import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift;
1.5 import static ru.bosony.model.cellscontents.CellContent.Rock;
1.6
1.7 +import java.util.Collection;
1.8 import java.util.HashSet;
1.9 import java.util.Set;
1.10 import java.util.regex.Matcher;
1.11 @@ -78,6 +79,10 @@
1.12 return text;
1.13 }
1.14
1.15 + public String toTextWithoutRobot() {
1.16 + return toText().replaceAll(CellContent.MiningRobot.toText(), CellContent.Empty.toText());
1.17 + }
1.18 +
1.19 protected void fromText(String str) {
1.20 Matcher matcher = minePattern.matcher(str);
1.21 if (!matcher.matches())
1.22 @@ -178,6 +183,18 @@
1.23 return cells[x - 1][sizeY - y];
1.24 }
1.25
1.26 + public Set<Cell> getCells(Collection<Coordinate> coordinates) {
1.27 + Set<Cell> cells = new HashSet<Cell>();
1.28 + if (coordinates == null)
1.29 + return cells;
1.30 + for (Coordinate coordinate : coordinates) {
1.31 + Cell cell = getCell(coordinate);
1.32 + if (cell != null)
1.33 + cells.add(cell);
1.34 + }
1.35 + return cells;
1.36 + }
1.37 +
1.38 @Override
1.39 public String toString() {
1.40 return toText();
1.41 @@ -219,15 +236,21 @@
1.42
1.43 public Set<Cell> getNeighboringCells(Cell cell) {
1.44 Set<Cell> cells = new HashSet<Cell>();
1.45 - for (Coordinate coordinate : cell.getCoordinate().getNeighboringCoordinates())
1.46 - cells.add(getCell(coordinate));
1.47 + for (Coordinate coordinate : cell.getCoordinate().getNeighboringCoordinates()) {
1.48 + Cell nextCell = getCell(coordinate);
1.49 + if (nextCell != null)
1.50 + cells.add(nextCell);
1.51 + }
1.52 return cells;
1.53 }
1.54
1.55 public Set<Cell> getAdjacentCells(Cell cell) {
1.56 Set<Cell> cells = new HashSet<Cell>();
1.57 - for (Coordinate coordinate : cell.getCoordinate().getAdjacentCoordinates())
1.58 - cells.add(getCell(coordinate));
1.59 + for (Coordinate coordinate : cell.getCoordinate().getAdjacentCoordinates()) {
1.60 + Cell nextCell = getCell(coordinate);
1.61 + if (nextCell != null)
1.62 + cells.add(nextCell);
1.63 + }
1.64 return cells;
1.65 }
1.66