icfp-model/src/main/java/ru/bosony/model/game/Game.java
branchCleverSearch
changeset 47 b3d48e364f9e
parent 30 666821484adc
child 50 9530f55e9639
     1.1 --- a/icfp-model/src/main/java/ru/bosony/model/game/Game.java	Mon Jul 16 15:20:48 2012 +0400
     1.2 +++ b/icfp-model/src/main/java/ru/bosony/model/game/Game.java	Mon Jul 16 18:58:08 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,11 @@
    1.22  
    1.23  		// Moving and scoring
    1.24  		route.add(mov);
    1.25 +		try {
    1.26 +			history.add(mine.clone());
    1.27 +		} catch (CloneNotSupportedException e) {
    1.28 +			throw new RuntimeException(e);
    1.29 +		}
    1.30  		Cell robotCell = mine.getRobotCell();
    1.31  		Coordinate robotCoord = robotCell.getCoordinate();
    1.32  		Coordinate nextRobotCoord = null;
    1.33 @@ -349,4 +357,18 @@
    1.34  	public int getUnderwater() {
    1.35  		return underwater;
    1.36  	}
    1.37 +
    1.38 +	public boolean hasViciousCircle() {
    1.39 +		if (route.size() != history.size())
    1.40 +			throw new RuntimeException("Desynchronized history");
    1.41 +		Map<Mine, Movement> state = new HashMap<Mine, Movement>();
    1.42 +		for (int i = route.size() - 1; i >= 0; i--) {
    1.43 +			Mine mine = history.get(i);
    1.44 +			Movement mov = route.get(i);
    1.45 +			if (state.get(mine) == mov)
    1.46 +				return true;
    1.47 +			state.put(mine, mov);
    1.48 +		}
    1.49 +		return false;
    1.50 +	}
    1.51  }