Jumping forth and back shall be prohibited
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 15 Apr 2010 23:43:25 +0200
changeset 23738db4aae19d9
parent 236 efbcc47cd834
child 238 a4f6aca595e8
Jumping forth and back shall be prohibited
pom.xml
quoridor/src/main/java/cz/xelfi/quoridor/Board.java
quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java
     1.1 --- a/pom.xml	Sun Apr 11 15:39:11 2010 +0200
     1.2 +++ b/pom.xml	Thu Apr 15 23:43:25 2010 +0200
     1.3 @@ -34,8 +34,8 @@
     1.4        <url>http://apidesign.org</url>
     1.5    </organization>
     1.6    <properties>
     1.7 -      <quoridorVersion>1.1</quoridorVersion>
     1.8 -      <webidorVersion>1.15</webidorVersion>
     1.9 +      <quoridorVersion>1.2</quoridorVersion>
    1.10 +      <webidorVersion>1.16</webidorVersion>
    1.11        <visidorVersion>1.0-SNAPSHOT</visidorVersion>
    1.12        <freemarkerVersion>1.60</freemarkerVersion>
    1.13        <emailerVersion>1.0</emailerVersion>
     2.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Board.java	Sun Apr 11 15:39:11 2010 +0200
     2.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Board.java	Thu Apr 15 23:43:25 2010 +0200
     2.3 @@ -31,7 +31,6 @@
     2.4  import java.io.EOFException;
     2.5  import java.io.IOException;
     2.6  import java.io.Reader;
     2.7 -import java.io.StringReader;
     2.8  import java.io.Writer;
     2.9  import java.util.ArrayList;
    2.10  import java.util.Arrays;
    2.11 @@ -276,6 +275,9 @@
    2.12                      throw new IllegalPositionException ("You have to jump straight if there is no wall"); // NOI18N
    2.13                  }
    2.14                  arr[index] = newPosition (oneStep, where[1]);
    2.15 +                if (arr[index].equals(player)) {
    2.16 +                    throw new IllegalPositionException("You cannot jump forth and back"); // NOI18N
    2.17 +                }
    2.18                  return new Board (turn + 1, Arrays.asList (arr), fences);
    2.19              }
    2.20          }
     3.1 --- a/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java	Sun Apr 11 15:39:11 2010 +0200
     3.2 +++ b/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java	Thu Apr 15 23:43:25 2010 +0200
     3.3 @@ -256,6 +256,33 @@
     3.4          b = move(b, 1, Player.Direction.SOUTH, Player.Direction.SOUTH);
     3.5      }
     3.6  
     3.7 +    public void testJumpBackForbidden() throws Exception {
     3.8 +        Board b = board;
     3.9 +
    3.10 +        for (int i = 0; i < 3; i++) {
    3.11 +            b = move(b, 0, Player.Direction.NORTH);
    3.12 +            b = move(b, 1, Player.Direction.SOUTH);
    3.13 +        }
    3.14 +
    3.15 +        b = move(b, 0, Player.Direction.NORTH);
    3.16 +
    3.17 +        b = fence(b, 1, 'D', 6, Orientation.HORIZONTAL);
    3.18 +
    3.19 +        try {
    3.20 +            b = move(b, 0, Player.Direction.NORTH, Player.Direction.NORTH);
    3.21 +            fail("Can't jump over a pawn when there is a fence");
    3.22 +        } catch (IllegalPositionException ex) {
    3.23 +            // OK
    3.24 +        }
    3.25 +
    3.26 +        try {
    3.27 +            b = move(b, 0, Player.Direction.NORTH, Player.Direction.SOUTH);
    3.28 +            fail("Can't bounce from the fence back neither");
    3.29 +        } catch (IllegalPositionException ex) {
    3.30 +            // OK
    3.31 +        }
    3.32 +    }
    3.33 +
    3.34      public void testCannotJumpOverFence () throws Exception {
    3.35          Board b = fence (board, 0, 'D', 8, Fence.Orientation.HORIZONTAL);
    3.36          assertEquals("One fence is present", 1, b.getFences().size());