1.1 --- a/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Sun Jul 15 02:08:45 2012 +0400
1.2 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Sun Jul 15 04:09:14 2012 +0400
1.3 @@ -13,6 +13,7 @@
1.4
1.5 import ru.bosony.model.cellscontents.CellContent;
1.6 import ru.bosony.model.io.TextRepresentable;
1.7 +import ru.bosony.model.moving.Coordinate;
1.8 import ru.bosony.model.moving.Movement;
1.9
1.10 /**
1.11 @@ -25,7 +26,6 @@
1.12 protected Cell[][] cells;
1.13 protected int sizeX;
1.14 protected int sizeY;
1.15 - protected Cell robotCell;
1.16
1.17 public Mine(String text) {
1.18 fromText(text);
1.19 @@ -35,8 +35,6 @@
1.20 throw new RuntimeException("New map does not contain a robot!");
1.21 if (findCells(ClosedLambdaLift).size() != 1)
1.22 throw new RuntimeException("New map does not contain a ClosedLambdaLift!");
1.23 - for (Cell cell : findCells(MiningRobot))
1.24 - robotCell = cell;
1.25 }
1.26
1.27 @Override
1.28 @@ -70,6 +68,8 @@
1.29 content = CellContent.fromText("" + row.charAt(curX));
1.30 else
1.31 content = Empty;
1.32 + if (content == null)
1.33 + content = Empty;
1.34 Cell cell = new Cell(new Coordinate(curX + 1, rows.length - curY), content);
1.35 cells[curX][curY] = cell;
1.36 }
1.37 @@ -101,6 +101,7 @@
1.38
1.39 public Set<Movement> getAvailableRobotMovements() {
1.40 Set<Movement> movs = new HashSet<Movement>();
1.41 + Cell robotCell = getRobotCell();
1.42 Set<Cell> nCells = getNeighboringCells(robotCell);
1.43 for (Cell nCell : nCells) {
1.44 CellContent nContent = nCell.getContent();
1.45 @@ -142,20 +143,29 @@
1.46 return finded;
1.47 }
1.48
1.49 - public Cell[][] getCells() {
1.50 - return cells;
1.51 - }
1.52 -
1.53 public void setCells(Cell[][] cells) {
1.54 this.cells = cells;
1.55 }
1.56
1.57 public Cell getRobotCell() {
1.58 - return robotCell;
1.59 + for (Cell cell : findCells(MiningRobot)) {
1.60 + return cell;
1.61 + }
1.62 + throw new RuntimeException("Where is robot!?");
1.63 }
1.64
1.65 - public void setRobotCell(Cell robotCell) {
1.66 - this.robotCell = robotCell;
1.67 + public Cell[][] cloneCells() {
1.68 + Cell[][] clone = new Cell[sizeX][sizeY];
1.69 + for (int y = sizeY - 1; y >= 0; y--) {
1.70 + for (int x = 0; x < sizeX; x++) {
1.71 + try {
1.72 + clone[x][y] = cells[x][y].clone();
1.73 + } catch (CloneNotSupportedException e) {
1.74 + throw new RuntimeException(e);
1.75 + }
1.76 + }
1.77 + }
1.78 + return clone;
1.79 }
1.80
1.81 }