diff -r 9530f55e9639 -r b431cec961d7 icfp-model/src/main/java/ru/bosony/model/mine/Mine.java --- a/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Tue Jul 17 21:38:39 2012 +0400 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Wed Jul 18 01:25:43 2012 +0400 @@ -8,6 +8,7 @@ import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift; import static ru.bosony.model.cellscontents.CellContent.Rock; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; @@ -78,6 +79,10 @@ return text; } + public String toTextWithoutRobot() { + return toText().replaceAll(CellContent.MiningRobot.toText(), CellContent.Empty.toText()); + } + protected void fromText(String str) { Matcher matcher = minePattern.matcher(str); if (!matcher.matches()) @@ -178,6 +183,18 @@ return cells[x - 1][sizeY - y]; } + public Set getCells(Collection coordinates) { + Set cells = new HashSet(); + if (coordinates == null) + return cells; + for (Coordinate coordinate : coordinates) { + Cell cell = getCell(coordinate); + if (cell != null) + cells.add(cell); + } + return cells; + } + @Override public String toString() { return toText(); @@ -219,15 +236,21 @@ public Set getNeighboringCells(Cell cell) { Set cells = new HashSet(); - for (Coordinate coordinate : cell.getCoordinate().getNeighboringCoordinates()) - cells.add(getCell(coordinate)); + for (Coordinate coordinate : cell.getCoordinate().getNeighboringCoordinates()) { + Cell nextCell = getCell(coordinate); + if (nextCell != null) + cells.add(nextCell); + } return cells; } public Set getAdjacentCells(Cell cell) { Set cells = new HashSet(); - for (Coordinate coordinate : cell.getCoordinate().getAdjacentCoordinates()) - cells.add(getCell(coordinate)); + for (Coordinate coordinate : cell.getCoordinate().getAdjacentCoordinates()) { + Cell nextCell = getCell(coordinate); + if (nextCell != null) + cells.add(nextCell); + } return cells; }