1.1 --- a/icfp-model/src/main/java/ru/bosony/model/game/Game.java Sun Jul 15 02:08:45 2012 +0400
1.2 +++ b/icfp-model/src/main/java/ru/bosony/model/game/Game.java Sun Jul 15 04:09:14 2012 +0400
1.3 @@ -9,13 +9,12 @@
1.4 import static ru.bosony.model.cellscontents.CellContent.Rock;
1.5
1.6 import java.util.ArrayList;
1.7 -import java.util.Arrays;
1.8 import java.util.List;
1.9
1.10 import ru.bosony.model.cellscontents.CellContent;
1.11 import ru.bosony.model.mine.Cell;
1.12 -import ru.bosony.model.mine.Coordinate;
1.13 import ru.bosony.model.mine.Mine;
1.14 +import ru.bosony.model.moving.Coordinate;
1.15 import ru.bosony.model.moving.Movement;
1.16
1.17 /**
1.18 @@ -25,8 +24,7 @@
1.19 */
1.20 public class Game {
1.21
1.22 - Mine mine = null;
1.23 - private Cell[][] prevStepCells;
1.24 + protected Mine mine = null;
1.25 protected int score = 0;
1.26 protected int lastScoreChange = 0;
1.27 protected GameState state = GameState.Game;
1.28 @@ -56,7 +54,6 @@
1.29 protected void moveRobot(Cell nextRobotCell) {
1.30 mine.getRobotCell().setContent(Empty);
1.31 nextRobotCell.setContent(MiningRobot);
1.32 - mine.setRobotCell(nextRobotCell);
1.33 }
1.34
1.35 public GameState move(Movement mov) {
1.36 @@ -69,6 +66,7 @@
1.37
1.38 // Moving and scoring
1.39 route.add(mov);
1.40 + Coordinate robotCoord = mine.getRobotCell().getCoordinate();
1.41 Coordinate nextRobotCoord = null;
1.42 switch (mov) {
1.43 case ABORT:
1.44 @@ -80,16 +78,16 @@
1.45 case WAIT:
1.46 break;
1.47 case LEFT:
1.48 - nextRobotCoord = mine.getRobotCell().getCoordinate().left();
1.49 + nextRobotCoord = robotCoord.left();
1.50 break;
1.51 case UP:
1.52 - nextRobotCoord = mine.getRobotCell().getCoordinate().up();
1.53 + nextRobotCoord = robotCoord.up();
1.54 break;
1.55 case RIGHT:
1.56 - nextRobotCoord = mine.getRobotCell().getCoordinate().right();
1.57 + nextRobotCoord = robotCoord.right();
1.58 break;
1.59 case DOWN:
1.60 - nextRobotCoord = mine.getRobotCell().getCoordinate().down();
1.61 + nextRobotCoord = robotCoord.down();
1.62 break;
1.63 }
1.64 Cell nextRobotCell = mine.getCell(nextRobotCoord);
1.65 @@ -107,11 +105,11 @@
1.66 lastScoreChange = score - prevScore;
1.67 state = GameState.Win;
1.68 return state;
1.69 - } else if (mine.getRobotCell().getCoordinate().right() == nextRobotCoord && nextRobotCellContent == Rock
1.70 + } else if (robotCoord.right() == nextRobotCoord && nextRobotCellContent == Rock
1.71 && getContent(mine.getCell(nextRobotCoord.right())) == Empty) {
1.72 moveRobot(nextRobotCell);
1.73 mine.getCell(nextRobotCoord.right()).setContent(Rock);
1.74 - } else if (mine.getRobotCell().getCoordinate().left() == nextRobotCoord && nextRobotCellContent == Rock
1.75 + } else if (robotCoord.left() == nextRobotCoord && nextRobotCellContent == Rock
1.76 && getContent(mine.getCell(nextRobotCoord.left())) == Empty) {
1.77 moveRobot(nextRobotCell);
1.78 mine.getCell(nextRobotCoord.left()).setContent(Rock);
1.79 @@ -119,16 +117,8 @@
1.80 mov = Movement.WAIT;
1.81 }
1.82
1.83 - // Other ending conditions
1.84 - if (getContent(getCell(mine.getRobotCell().getCoordinate().up(), prevStepCells)) != Rock
1.85 - && getContent(mine.getCell(mine.getRobotCell().getCoordinate().up())) == Rock) {
1.86 - lastScoreChange = score - prevScore;
1.87 - state = GameState.Lose;
1.88 - return state;
1.89 - }
1.90 -
1.91 // World changes
1.92 - Cell[][] newCells = Arrays.copyOf(mine.getCells(), mine.getCells().length);
1.93 + Cell[][] newCells = mine.cloneCells();
1.94 for (int y = 1; y <= mine.getSizeY(); y++) {
1.95 for (int x = 1; x <= mine.getSizeX(); x++) {
1.96 Coordinate curCoord = new Coordinate(x, y);
1.97 @@ -171,7 +161,16 @@
1.98 }
1.99 }
1.100 }
1.101 - prevStepCells = mine.getCells();
1.102 +
1.103 + // Other ending conditions
1.104 + robotCoord = mine.getRobotCell().getCoordinate();
1.105 + if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock) {
1.106 + mine.setCells(newCells);
1.107 + lastScoreChange = score - prevScore;
1.108 + state = GameState.Lose;
1.109 + return state;
1.110 + }
1.111 +
1.112 mine.setCells(newCells);
1.113
1.114 lastScoreChange = score - prevScore;