# HG changeset patch # User Jaroslav Tulach # Date 1271367805 -7200 # Node ID 38db4aae19d939d1cd45f39c790da8a280615256 # Parent efbcc47cd8340859c7de0828776918ad4fd374f3 Jumping forth and back shall be prohibited diff -r efbcc47cd834 -r 38db4aae19d9 pom.xml --- a/pom.xml Sun Apr 11 15:39:11 2010 +0200 +++ b/pom.xml Thu Apr 15 23:43:25 2010 +0200 @@ -34,8 +34,8 @@ http://apidesign.org - 1.1 - 1.15 + 1.2 + 1.16 1.0-SNAPSHOT 1.60 1.0 diff -r efbcc47cd834 -r 38db4aae19d9 quoridor/src/main/java/cz/xelfi/quoridor/Board.java --- a/quoridor/src/main/java/cz/xelfi/quoridor/Board.java Sun Apr 11 15:39:11 2010 +0200 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Board.java Thu Apr 15 23:43:25 2010 +0200 @@ -31,7 +31,6 @@ import java.io.EOFException; import java.io.IOException; import java.io.Reader; -import java.io.StringReader; import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; @@ -276,6 +275,9 @@ throw new IllegalPositionException ("You have to jump straight if there is no wall"); // NOI18N } arr[index] = newPosition (oneStep, where[1]); + if (arr[index].equals(player)) { + throw new IllegalPositionException("You cannot jump forth and back"); // NOI18N + } return new Board (turn + 1, Arrays.asList (arr), fences); } } diff -r efbcc47cd834 -r 38db4aae19d9 quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java --- a/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java Sun Apr 11 15:39:11 2010 +0200 +++ b/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java Thu Apr 15 23:43:25 2010 +0200 @@ -256,6 +256,33 @@ b = move(b, 1, Player.Direction.SOUTH, Player.Direction.SOUTH); } + public void testJumpBackForbidden() throws Exception { + Board b = board; + + for (int i = 0; i < 3; i++) { + b = move(b, 0, Player.Direction.NORTH); + b = move(b, 1, Player.Direction.SOUTH); + } + + b = move(b, 0, Player.Direction.NORTH); + + b = fence(b, 1, 'D', 6, Orientation.HORIZONTAL); + + try { + b = move(b, 0, Player.Direction.NORTH, Player.Direction.NORTH); + fail("Can't jump over a pawn when there is a fence"); + } catch (IllegalPositionException ex) { + // OK + } + + try { + b = move(b, 0, Player.Direction.NORTH, Player.Direction.SOUTH); + fail("Can't bounce from the fence back neither"); + } catch (IllegalPositionException ex) { + // OK + } + } + public void testCannotJumpOverFence () throws Exception { Board b = fence (board, 0, 'D', 8, Fence.Orientation.HORIZONTAL); assertEquals("One fence is present", 1, b.getFences().size());