1.1 --- a/icfp-model/src/main/java/ru/bosony/model/game/Game.java Mon Jul 16 13:19:10 2012 +0400
1.2 +++ b/icfp-model/src/main/java/ru/bosony/model/game/Game.java Wed Jul 18 09:42:52 2012 +0400
1.3 @@ -12,7 +12,9 @@
1.4 import static ru.bosony.model.cellscontents.CellContent.WadlersBeard;
1.5
1.6 import java.util.ArrayList;
1.7 +import java.util.HashMap;
1.8 import java.util.List;
1.9 +import java.util.Map;
1.10
1.11 import ru.bosony.model.cellscontents.CellContent;
1.12 import ru.bosony.model.mine.Cell;
1.13 @@ -32,6 +34,7 @@
1.14 protected int lastScoreChange = 0;
1.15 protected GameState state = GameState.Game;
1.16 protected int lambdaCollectedCount = 0;
1.17 + protected List<Mine> history = new ArrayList<Mine>();
1.18 protected List<Movement> route = new ArrayList<Movement>();
1.19 protected int underwater = 0;
1.20
1.21 @@ -69,6 +72,7 @@
1.22
1.23 // Moving and scoring
1.24 route.add(mov);
1.25 + history.add(mine.clone());
1.26 Cell robotCell = mine.getRobotCell();
1.27 Coordinate robotCoord = robotCell.getCoordinate();
1.28 Coordinate nextRobotCoord = null;
1.29 @@ -349,4 +353,24 @@
1.30 public int getUnderwater() {
1.31 return underwater;
1.32 }
1.33 +
1.34 + public boolean hasViciousCircle() {
1.35 + if (route.size() != history.size())
1.36 + throw new RuntimeException("Desynchronized history");
1.37 + Map<Mine, Movement> state = new HashMap<Mine, Movement>();
1.38 + for (int i = route.size() - 1; i >= 0; i--) {
1.39 + Mine mine = history.get(i);
1.40 + Movement mov = route.get(i);
1.41 + if (state.get(mine) == mov)
1.42 + return true;
1.43 + state.put(mine, mov);
1.44 + }
1.45 + return false;
1.46 + }
1.47 +
1.48 + @Override
1.49 + public String toString() {
1.50 + return state.toString() + ", score = " + score + ", " + route.size() + " steps: "
1.51 + + (route.size() > 100 ? getStringRoute().substring(0, 100) + "..." : getStringRoute()) + "\n\n" + mine;
1.52 + }
1.53 }