Testing the game
authorindvdum (gotoindvdum[at]gmail[dot]com)
Sun, 15 Jul 2012 00:05:12 +0400
changeset 164e0d86c1c22a
parent 15 fd89eea0ea15
child 17 0e81a28e9ccf
Testing the game
icfp-model/src/main/java/ru/bosony/model/game/Game.java
icfp-model/src/test/java/ru/bosony/tests/TestGame.java
     1.1 --- a/icfp-model/src/main/java/ru/bosony/model/game/Game.java	Sat Jul 14 23:44:32 2012 +0400
     1.2 +++ b/icfp-model/src/main/java/ru/bosony/model/game/Game.java	Sun Jul 15 00:05:12 2012 +0400
     1.3 @@ -8,7 +8,9 @@
     1.4  import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift;
     1.5  import static ru.bosony.model.cellscontents.CellContent.Rock;
     1.6  
     1.7 +import java.util.ArrayList;
     1.8  import java.util.Arrays;
     1.9 +import java.util.List;
    1.10  
    1.11  import ru.bosony.model.cellscontents.CellContent;
    1.12  import ru.bosony.model.mine.Cell;
    1.13 @@ -175,6 +177,28 @@
    1.14  		return state;
    1.15  	}
    1.16  
    1.17 +	public GameState move(List<Movement> movs) {
    1.18 +		for (Movement mov : movs) {
    1.19 +			if (move(mov) != GameState.Game)
    1.20 +				return state;
    1.21 +		}
    1.22 +		return state;
    1.23 +	}
    1.24 +
    1.25 +	public GameState move(String sMovs) {
    1.26 +		List<Movement> movs = new ArrayList<Movement>();
    1.27 +		for (int i = 0; i < sMovs.length(); i++) {
    1.28 +			String s = "" + sMovs.charAt(i);
    1.29 +			for (Movement mov : Movement.values()) {
    1.30 +				if (mov.toText().equals(s)) {
    1.31 +					movs.add(mov);
    1.32 +					break;
    1.33 +				}
    1.34 +			}
    1.35 +		}
    1.36 +		return move(movs);
    1.37 +	}
    1.38 +
    1.39  	protected CellContent getContent(Cell cell) {
    1.40  		if (cell == null)
    1.41  			return null;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/icfp-model/src/test/java/ru/bosony/tests/TestGame.java	Sun Jul 15 00:05:12 2012 +0400
     2.3 @@ -0,0 +1,61 @@
     2.4 +package ru.bosony.tests;
     2.5 +
     2.6 +import static org.junit.Assert.*;
     2.7 +
     2.8 +import org.junit.Test;
     2.9 +
    2.10 +import ru.bosony.model.game.Game;
    2.11 +import ru.bosony.model.game.GameState;
    2.12 +import ru.bosony.model.mine.Mine;
    2.13 +
    2.14 +/**
    2.15 + * @author 	indvdum (gotoindvdum[at]gmail[dot]com) <br>
    2.16 + * 			14.07.2012 23:55:07
    2.17 + *
    2.18 + */
    2.19 +public class TestGame {
    2.20 +
    2.21 +	@Test
    2.22 +	public void testMapFromTask() {
    2.23 +		/* Map from task (15x15)
    2.24 +		 * 
    2.25 +			###############
    2.26 +			#***...R......#
    2.27 +			#***... ...*..#
    2.28 +			#\\\... ..\\\.#
    2.29 +			#...... ...*..#
    2.30 +			#..     .. ...#
    2.31 +			#.... .... ...#
    2.32 +			#.... .... ...#
    2.33 +			#.. .       ..#
    2.34 +			#..*. .. .....#
    2.35 +			#.... .. .....#
    2.36 +			#.\.. .......*#
    2.37 +			#.............#
    2.38 +			#.........   .#
    2.39 +			#############L#
    2.40 +
    2.41 +		 */
    2.42 +		String map = 
    2.43 +				"###############\n" + 
    2.44 +				"#***...R......#\n" + 
    2.45 +				"#***... ...*..#\n" + 
    2.46 +				"#\\\\\\... ..\\\\\\.#\n" + 
    2.47 +				"#...... ...*..#\n" + 
    2.48 +				"#..     .. ...#\n" + 
    2.49 +				"#.... .... ...#\n" + 
    2.50 +				"#.... .... ...#\n" + 
    2.51 +				"#.. .       ..#\n" + 
    2.52 +				"#..*. .. .....#\n" + 
    2.53 +				"#.... .. .....#\n" + 
    2.54 +				"#.\\.. .......*#\n" + 
    2.55 +				"#.............#\n" + 
    2.56 +				"#.........   .#\n" + 
    2.57 +				"#############L#";
    2.58 +		Mine mine = new Mine(map);
    2.59 +		Game game = new Game(mine);
    2.60 +		String route = "DDDLLLLLLURRRRRRRRRRRRDDDDDDDLLLLLLLLLLLDDDRRRRRRRRRRRD"; 
    2.61 +		assertEquals(game.move(route), GameState.Win);
    2.62 +	}
    2.63 +
    2.64 +}