diff -r 660ac71d13b8 -r 70cfa8a066df icfp-model/src/main/java/ru/bosony/model/game/Game.java --- a/icfp-model/src/main/java/ru/bosony/model/game/Game.java Mon Jul 16 15:46:08 2012 +0400 +++ b/icfp-model/src/main/java/ru/bosony/model/game/Game.java Mon Jul 16 18:59:13 2012 +0400 @@ -12,7 +12,9 @@ import static ru.bosony.model.cellscontents.CellContent.WadlersBeard; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import ru.bosony.model.cellscontents.CellContent; import ru.bosony.model.mine.Cell; @@ -32,6 +34,7 @@ protected int lastScoreChange = 0; protected GameState state = GameState.Game; protected int lambdaCollectedCount = 0; + protected List history = new ArrayList(); protected List route = new ArrayList(); protected int underwater = 0; @@ -69,6 +72,11 @@ // Moving and scoring route.add(mov); + try { + history.add(mine.clone()); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } Cell robotCell = mine.getRobotCell(); Coordinate robotCoord = robotCell.getCoordinate(); Coordinate nextRobotCoord = null; @@ -349,4 +357,18 @@ public int getUnderwater() { return underwater; } + + public boolean hasViciousCircle() { + if (route.size() != history.size()) + throw new RuntimeException("Desynchronized history"); + Map state = new HashMap(); + for (int i = route.size() - 1; i >= 0; i--) { + Mine mine = history.get(i); + Movement mov = route.get(i); + if (state.get(mine) == mov) + return true; + state.put(mine, mov); + } + return false; + } }