quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 18 Jul 2010 09:37:40 +0200
changeset 245 ba49bfb120f7
parent 237 38db4aae19d9
child 253 ee02205edf13
permissions -rw-r--r--
Trying to simulate Tomas Holy's problem. Unsuccessfully.
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * The contents of this file are subject to the terms of either the GNU
     5  * General Public License Version 2 only ("GPL") or the Common
     6  * Development and Distribution License("CDDL") (collectively, the
     7  * "License"). You may not use this file except in compliance with the
     8  * License. You can obtain a copy of the License at
     9  * http://www.netbeans.org/cddl-gplv2.html
    10  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    11  * specific language governing permissions and limitations under the
    12  * License.  When distributing the software, include this License Header
    13  * Notice in each file and include the License file at
    14  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    15  * particular file as subject to the "Classpath" exception as provided
    16  * by Sun in the GPL Version 2 section of the License file that
    17  * accompanied this code. If applicable, add the following below the
    18  * License Header, with the fields enclosed by brackets [] replaced by
    19  * your own identifying information:
    20  * "Portions Copyrighted [year] [name of copyright owner]"
    21  *
    22  * Contributor(s):
    23  *
    24  * Portions Copyrighted 2009 Jaroslav Tulach
    25  */
    26 package cz.xelfi.quoridor;
    27 
    28 import cz.xelfi.quoridor.Fence.Orientation;
    29 import cz.xelfi.quoridor.Player.Direction;
    30 import java.io.IOException;
    31 import java.io.StringReader;
    32 import java.io.StringWriter;
    33 import java.util.List;
    34 import junit.framework.TestCase;
    35 
    36 /**
    37  *
    38  * @author Jaroslav Tulach <jtulach@netbeans.org>
    39  */
    40 public abstract class BoardCase extends TestCase {
    41     protected Board board;
    42 
    43     protected BoardCase(String n) {
    44         super(n);
    45         board = Board.empty();
    46     }
    47 
    48     protected abstract Board move(Board b, int player, Player.Direction... where)
    49     throws IllegalPositionException;
    50 
    51     protected abstract Board fence(Board b, int player, char x, int y, Fence.Orientation orie)
    52     throws IllegalPositionException;
    53 
    54     protected abstract Board apply(Board b, Move move) throws IllegalPositionException;
    55 
    56 
    57     public void testResignWhite() throws IllegalPositionException {
    58         List<Player> list = board.getPlayers();
    59         assertEquals ("Two", 2, list.size ());
    60         Board b = board.apply(Move.RESIGN);
    61         assertEquals(b.getPlayers().get(1), b.getWinner());
    62         try {
    63             b.apply(Move.EAST);
    64             fail("No more moves allowed, the player resigned");
    65         } catch (IllegalPositionException ex) {
    66             // OK
    67         }
    68         assertNull("No player", b.getCurrentPlayer());
    69     }
    70     public void testResignBlack() throws IllegalPositionException {
    71         List<Player> list = board.getPlayers();
    72         assertEquals ("Two", 2, list.size ());
    73         Board b = board.apply(Move.NORTH).apply(Move.RESIGN);
    74         assertEquals(b.getPlayers().get(0), b.getWinner());
    75         try {
    76             b.apply(Move.EAST);
    77             fail("No more moves allowed, the player resigned");
    78         } catch (IllegalPositionException ex) {
    79             // OK
    80         }
    81         assertNull("No player", b.getCurrentPlayer());
    82     }
    83     public void testTwoPlayers () {
    84         List<Player> list = board.getPlayers();
    85         assertEquals ("Two", 2, list.size ());
    86         assertFalse ("Both are non-null", list.contains (null));
    87         try {
    88             list.add (null);
    89             fail ("Modifications are not allowed");
    90         } catch (UnsupportedOperationException ex) {
    91             // ok
    92         }
    93         try {
    94             list.remove (0);
    95             fail ("Modifications are not allowed");
    96         } catch (UnsupportedOperationException ex) {
    97             // ok
    98         }
    99         
   100         
   101         assertEquals (8, list.get (0).getXInternal());
   102         assertEquals (0, list.get (0).getYInternal());
   103         assertEquals (10, list.get (0).getFences ());
   104         assertEquals (8, list.get (1).getXInternal());
   105         assertEquals (16, list.get (1).getYInternal());
   106         assertEquals (10, list.get (1).getFences ());
   107     }
   108     
   109     public void testFences () throws IllegalPositionException {
   110         assertEquals ("No on board", 0, board.getFences ().size ());
   111         try {
   112             board.getFences ().add (null);
   113             fail ("Should be unmodifiable");
   114         } catch (java.lang.UnsupportedOperationException ex) {
   115             // ok
   116         }
   117 
   118         {
   119             Board b = board.apply(Move.fence('A', 1, Orientation.HORIZONTAL));
   120             assertEquals("One fence placed: ", 1, b.getFences().size());
   121             Fence f = b.getFences().iterator().next();
   122             assertEquals("Row", 1, f.getRow());
   123             assertEquals("Column", 'A', f.getColumn());
   124         }
   125 
   126         {
   127             Board b = board.apply(Move.fence('A', 1, Orientation.VERTICAL));
   128             assertEquals("One fence placed: ", 1, b.getFences().size());
   129             Fence f = b.getFences().iterator().next();
   130             assertEquals("Row", 1, f.getRow());
   131             assertEquals("Column", 'A', f.getColumn());
   132         }
   133 
   134         {
   135             Board b = board.apply(Move.fence('H', 8, Orientation.HORIZONTAL));
   136             assertEquals("One fence placed: ", 1, b.getFences().size());
   137             Fence f = b.getFences().iterator().next();
   138             assertEquals("Row", 8, f.getRow());
   139             assertEquals("Column", 'H', f.getColumn());
   140         }
   141 
   142         {
   143             Board b = board.apply(Move.fence('H', 8, Orientation.VERTICAL));
   144             assertEquals("One fence placed: ", 1, b.getFences().size());
   145             Fence f = b.getFences().iterator().next();
   146             assertEquals("Row", 8, f.getRow());
   147             assertEquals("Column", 'H', f.getColumn());
   148         }
   149     }
   150     public void testTwoFencesInTheSamePosition() throws IllegalPositionException {
   151         assertEquals ("No on board", 0, board.getFences ().size ());
   152         Board one = board.apply(Move.fence('A', 1, Orientation.HORIZONTAL));
   153         try {
   154             Board snd = one.apply(Move.fence('A', 1, Orientation.HORIZONTAL));
   155             fail("Cannot place fence twice to the same place");
   156         } catch (IllegalPositionException ex) {
   157             // OK
   158         }
   159     }
   160     
   161     public void testSelfDestructionForbidden() throws Exception {
   162         Board b = board;
   163 
   164         b = fence(b, 0, 'D', 1, Orientation.VERTICAL);
   165         b = move(b, 1, Player.Direction.SOUTH);
   166         b = fence(b, 0, 'E', 1, Orientation.VERTICAL);
   167         b = move(b, 1, Player.Direction.SOUTH);
   168         try {
   169             b = fence(b, 0, 'E', 2, Orientation.HORIZONTAL);
   170             fail ("Forbidden. Player 0 has no way to reach the end");
   171         } catch (IllegalPositionException ex) {
   172             // ok
   173         }
   174 
   175     }
   176     public void testRealSelfDestructionForbidden() throws Exception {
   177         String b = "" +
   178             "                         [N]    \n" +
   179             "\n" +
   180 "            A   B   C   D   E   F   G   H\n" +
   181 "            |   |   |   |   |   |   |   |\n" +
   182 "        +*----------------------------------+\n" +
   183 "        |                                   |\n" +
   184 "     8--|-------+-------+-------+-------+   |--8\n" +
   185 "        |               |           |       |\n" +
   186 "     7--|   +   +   +   |-------+   |   +   |--7\n" +
   187 "        |               |       |   |       |\n" +
   188 "     6--|   +   +   +   +   +   |   +   +   |--6\n" +
   189 "        |                   |   |           |\n" +
   190 "     5--|   +   +   +   +   |-------+   +   |--5\n" +
   191 "[W]     |                   |               |     [E]\n" +
   192 "     4--|   +   +   +   +   +-------+   +   |--4\n" +
   193 "        |                           |   |   |\n" +
   194 "     3--|   +   +   +   +   +   +   |   |   |--3\n" +
   195 "        |                         P | Q |   |\n" +
   196 "     2--|   +   +   +   +   +   +   +   +   |--2\n" +
   197 "        |                       |           |\n" +
   198 "     1--|   +   +   +   +   +   |   +-------|--1\n" +
   199 "        |                       |           |\n" +
   200 "        +||||-------------------------------+\n" +
   201 "            |   |   |   |   |   |   |   |\n" +
   202 "            A   B   C   D   E   F   G   H\n" +
   203 "\n" +
   204 "                         [S]                 \n";
   205 
   206         b = picture2board(b).toString();
   207         Board begin = Board.valueOf(b);
   208 
   209         try {
   210             Board bad = fence(begin, 0, 'G', 2, Orientation.HORIZONTAL);
   211             fail("Not allowed move:\n" + bad.toString());
   212         } catch (IllegalPositionException ex) {
   213             // OK
   214         }
   215     }
   216     public void testFourTimesInAgainstEachOtherResultsInInvalidPosition () throws Exception {
   217         Board b = board;
   218         
   219         for (int i = 0; i < 3; i++) {
   220             b = move(b, 0, Player.Direction.NORTH);
   221             b = move(b, 1, Player.Direction.SOUTH);
   222         }
   223         
   224         b = move(b, 0, Player.Direction.NORTH);
   225         try {
   226             b = move(b, 1, Player.Direction.SOUTH);
   227             fail ("Now the positions of two players are supposed to be the same, this results in exception");
   228         } catch (IllegalPositionException ex) {
   229             // ok
   230         }
   231         
   232     }
   233 
   234     public void testCrossFences () throws Exception {
   235         Board b1 = board.fence (board.getPlayers ().get(0), 'A', 1, Fence.Orientation.HORIZONTAL);
   236         
   237         try {
   238             b1.fence (b1.getPlayers ().get(1), 'A', 1, Fence.Orientation.VERTICAL);
   239             fail ("This must fail, as the fences overlap");
   240         } catch (IllegalPositionException ex) {
   241             // ok
   242         }
   243     }
   244     
   245     public void testPawnsCanJumpOverEachOther () throws Exception {
   246         Board b = board;
   247         
   248         for (int i = 0; i < 3; i++) {
   249             b = move(b, 0, Player.Direction.NORTH);
   250             b = move(b, 1, Player.Direction.SOUTH);
   251         }
   252         
   253         b = move(b, 0, Player.Direction.NORTH);
   254         
   255         // jump over
   256         b = move(b, 1, Player.Direction.SOUTH, Player.Direction.SOUTH);
   257     }
   258 
   259     public void testJumpBackForbidden() throws Exception {
   260         Board b = board;
   261 
   262         for (int i = 0; i < 3; i++) {
   263             b = move(b, 0, Player.Direction.NORTH);
   264             b = move(b, 1, Player.Direction.SOUTH);
   265         }
   266 
   267         b = move(b, 0, Player.Direction.NORTH);
   268 
   269         b = fence(b, 1, 'D', 6, Orientation.HORIZONTAL);
   270 
   271         try {
   272             b = move(b, 0, Player.Direction.NORTH, Player.Direction.NORTH);
   273             fail("Can't jump over a pawn when there is a fence");
   274         } catch (IllegalPositionException ex) {
   275             // OK
   276         }
   277 
   278         try {
   279             b = move(b, 0, Player.Direction.NORTH, Player.Direction.SOUTH);
   280             fail("Can't bounce from the fence back neither");
   281         } catch (IllegalPositionException ex) {
   282             // OK
   283         }
   284     }
   285 
   286     public void testCannotJumpOverFence () throws Exception {
   287         Board b = fence (board, 0, 'D', 8, Fence.Orientation.HORIZONTAL);
   288         assertEquals("One fence is present", 1, b.getFences().size());
   289         final Fence f = b.getFences().iterator().next();
   290         assertEquals("Row is 8", 8, f.getRow());
   291         assertEquals("Column is D", 'D', f.getColumn());
   292         try {
   293             move(b, 1, Player.Direction.SOUTH);
   294             fail ("This shall not be allowed, as there is the fence");
   295         } catch (IllegalPositionException ex) {
   296             // ok
   297         }
   298     }
   299     
   300 
   301     public void testSideJumpsNotAllowedWhenThereIsNoFence () throws Exception {
   302         Board b = board;
   303         
   304         for (int i = 0; i < 3; i++) {
   305             b = move(b, 0, Player.Direction.NORTH);
   306             b = move(b, 1, Player.Direction.SOUTH);
   307         }
   308         
   309         b = move(b, 0, Player.Direction.NORTH);
   310         
   311         try {
   312             b = move(b, 1, Player.Direction.SOUTH, Player.Direction.WEST);
   313             fail ("Cannot just jump aside");
   314         } catch (IllegalPositionException ex) {
   315             // ok
   316         }
   317     }
   318     
   319     public void testSideJumpsAllowedWhenThereAFence () throws Exception {
   320         Board b = board;
   321         
   322         for (int i = 0; i < 3; i++) {
   323             b = move(b, 0, Player.Direction.NORTH);
   324             b = move(b, 1, Player.Direction.SOUTH);
   325         }
   326         
   327         b = move(b, 0, Player.Direction.NORTH);
   328         
   329         assertEquals (8, b.getPlayers ().get (0).getXInternal());
   330         assertEquals (8, b.getPlayers ().get (0).getYInternal());
   331         
   332         b = fence(b, 0, 'D', 4, Fence.Orientation.HORIZONTAL);
   333         
   334         // we can over jump to west
   335         move(b, 1, Player.Direction.SOUTH, Player.Direction.WEST);
   336         // as well as east
   337         move(b, 1, Player.Direction.SOUTH, Player.Direction.EAST);
   338     }
   339 
   340     public void testPlaceAllFences() throws Exception {
   341         doPlaceAllFences(0);
   342     }
   343     public void testPlaceAllFences2() throws Exception {
   344         doPlaceAllFences(1);
   345     }
   346 
   347     private void doPlaceAllFences(int player) throws Exception {
   348         Board b = board;
   349 
   350         int cnt = 10;
   351         for (int i = 1; i <= 5; i++) {
   352             b = fence(b, player, 'A', i, Fence.Orientation.HORIZONTAL);
   353             b = fence(b, player, 'D', i, Fence.Orientation.HORIZONTAL);
   354             cnt -= 2;
   355             assertEquals("Two less" + i, cnt, b.getPlayers().get(player).getFences());
   356         }
   357 
   358         try {
   359             fence(b, player, 'F', 7, Fence.Orientation.VERTICAL);
   360             fail("We shall run out of fences");
   361         } catch (IllegalPositionException ex) {
   362             // OK
   363         }
   364     }
   365     
   366     public void testAlwaysHasToHaveAccessToEndLine () throws Exception {
   367         Board b = board;
   368         
   369         b = b.fence (b.getPlayers ().get (0), 'E', 1, Fence.Orientation.HORIZONTAL);
   370         b = b.fence (b.getPlayers ().get (0), 'F', 1, Fence.Orientation.VERTICAL);
   371 
   372         try {
   373             b = b.fence (b.getPlayers ().get (0), 'D', 1, Fence.Orientation.VERTICAL);
   374             fail ("This is not allowed as player 0 cannot now reach the final line");
   375         } catch (IllegalPositionException ex) {
   376             // ok
   377         }
   378         
   379     }
   380     
   381     public void testEqualsOfPlayers () throws Exception {
   382         Player p1 = new Player (1, 1, 10, Player.Direction.EAST);
   383         Player p2 = new Player (1, 1, 10, Player.Direction.EAST);
   384         Player p3 = new Player (2, 1, 10, Player.Direction.EAST);
   385         Player p4 = new Player (1, 1, 10, Player.Direction.WEST);
   386         Player p5 = new Player (1, 2, 10, Player.Direction.EAST);
   387         Player p6 = new Player (1, 1, 5, Player.Direction.EAST);
   388         
   389         assertEquals ("p1 == p2", p1, p2);
   390         if (p2.equals (p3)) fail ();
   391         if (p2.equals (p4)) fail ();
   392         if (p2.equals (p5)) fail ();
   393         if (p2.equals (p6)) fail ();
   394         if (p3.equals (p6)) fail ();
   395         if (p4.equals (p3)) fail ();
   396         if (p6.equals (p3)) fail ();
   397         if (p5.equals (p3)) fail ();
   398         if (p5.equals (p3)) fail ();
   399         if (p4.equals (p3)) fail ();
   400         if (p3.equals (p4)) fail ();
   401         if (p3.equals (p5)) fail ();
   402         if (p4.equals (p5)) fail ();
   403         if (p5.equals (p4)) fail ();
   404     }
   405     
   406     public void testEqualsOfFences () throws Exception {
   407         Fence f1 = new Fence (1, 1, Fence.Orientation.HORIZONTAL);
   408         Fence f2 = new Fence (1, 1, Fence.Orientation.HORIZONTAL);
   409         Fence f3 = new Fence (3, 1, Fence.Orientation.HORIZONTAL);
   410         Fence f4 = new Fence (1, 3, Fence.Orientation.HORIZONTAL);
   411         Fence f5 = new Fence (1, 1, Fence.Orientation.VERTICAL);
   412         
   413         assertEquals ("f1 == f2", f1, f2);
   414         if (f1.equals (f3)) fail ();
   415         if (f3.equals (f1)) fail ();
   416         if (f5.equals (f1)) fail ();
   417         if (f1.equals (f5)) fail ();
   418         if (f4.equals (f1)) fail ();
   419         if (f1.equals (f4)) fail ();
   420     }
   421     
   422     public void testEqualsOfBoards1 () throws Exception {
   423         Board b1 = board.move (board.getPlayers ().get (0), Player.Direction.NORTH);
   424         Board b2 = board.move (board.getPlayers ().get (0), Player.Direction.NORTH);
   425         Board b3 = board.move (board.getPlayers ().get (0), Player.Direction.EAST);
   426         
   427         if (b1.equals (b3)) fail ();
   428         if (b3.equals (b1)) fail ();
   429         
   430         assertEquals ("b1 == b2", b1, b2);
   431     }
   432     public void testEqualsOfBoards2 () throws Exception {
   433         Board b1 = board.fence (board.getPlayers ().get (0), 'E', 3, Fence.Orientation.HORIZONTAL);
   434         Board b2 = board.fence (board.getPlayers ().get (0), 'E', 3, Fence.Orientation.HORIZONTAL);
   435         Board b3 = board.fence (board.getPlayers ().get (0), 'D', 3, Fence.Orientation.HORIZONTAL);
   436         Board b4 = board.fence (board.getPlayers ().get (0), 'E', 4, Fence.Orientation.HORIZONTAL);
   437         Board b5 = board.fence (board.getPlayers ().get (0), 'E', 3, Fence.Orientation.VERTICAL);
   438         
   439         if (b1.equals (b3)) fail ();
   440         if (b3.equals (b1)) fail ();
   441         if (b1.equals (b4)) fail ();
   442         if (b1.equals (b5)) fail ();
   443         if (b5.equals (b1)) fail ();
   444         if (b4.equals (b1)) fail ();
   445         
   446         assertEquals ("b1 == b2", b1, b2);
   447     }
   448     public void testEqualsOfBoardsWhenJumpOver () throws Exception {
   449         Board b = board;
   450         
   451         for (int i = 0; i < 3; i++) {
   452             b = move(b, 0, Player.Direction.NORTH);
   453             b = move(b, 1, Player.Direction.SOUTH);
   454         }
   455         
   456         Board b1 = move(b, 0, Player.Direction.NORTH);
   457         
   458         Board b2 = move(b, 1, Player.Direction.SOUTH);
   459         b2 = b2.move (b2.getPlayers ().get (0), Player.Direction.NORTH, Player.Direction.NORTH);
   460         
   461         if (b1.equals (b2)) fail ("Not the same, pawns are reverted");
   462         if (b2.equals (b1)) fail ("Not the same, pawns are reverted");
   463     }
   464 
   465     public void testMoveAltersCurrentPlayer() throws Exception {
   466         assertEquals("First player ready", board.getCurrentPlayer(), board.getPlayers().get(0));
   467         Board b = apply(board, Move.EAST);
   468 
   469         for (int i = 0; i < 7; i++) {
   470             assertEquals("Snd player ready", b.getCurrentPlayer(), b.getPlayers().get(1));
   471             b = apply(b, Move.SOUTH);
   472             assertEquals("First player ready", b.getCurrentPlayer(), b.getPlayers().get(0));
   473             b = apply(b, Move.NORTH);
   474         }
   475 
   476         Board fin = b.apply(Move.NORTH).apply(Move.NORTH);
   477         assertNotNull("There is a winner", fin.getWinner());
   478         assertEquals("And the winner is", fin.getPlayers().get(0), fin.getWinner());
   479 
   480         assertFalse("No next move can be applied", fin.isApplicable(Move.fence('D', 3, Fence.Orientation.HORIZONTAL)));
   481 
   482         try {
   483             fin.apply(Move.EAST);
   484             fail("No moves allow when we are in final position");
   485         } catch (IllegalPositionException ex) {
   486             // OK
   487         }
   488 
   489     }
   490 
   491     public void testDetectInvalidFence() {
   492         try {
   493             Move m = Move.fence('D', 9, Orientation.HORIZONTAL);
   494             fail("Move shall not be allowed: " + m);
   495         } catch (IllegalPositionException ex) {
   496             // OK
   497         }
   498     }
   499 
   500     public void testEqualityOfMoves() throws Exception {
   501 
   502         for (Direction m1 : Direction.values()) {
   503             for (Direction m2 : Direction.values()) {
   504                 Move both1 = Move.jump(m1, m2);
   505                 Move both2 = Move.jump(m1, m2);
   506                 Move opposite = Move.jump(m2, m1);
   507 
   508                 assertTrue("Both boths are equal", both1.equals(both2));
   509                 assertFalse("Not north", Move.NORTH.equals(both1));
   510                 assertFalse("Not east", Move.EAST.equals(both1));
   511                 assertFalse("Not west", Move.WEST.equals(both1));
   512                 assertFalse("Not south", Move.SOUTH.equals(both1));
   513                 if (m1 == m2) {
   514                     continue;
   515                 }
   516                 assertFalse("Not equal to opposite", both1.equals(opposite));
   517             }
   518         }
   519 
   520         Move f1 = Move.fence('D', 6, Orientation.HORIZONTAL);
   521         Move f2 = Move.fence('D', 6, Orientation.HORIZONTAL);
   522         Move f3 = Move.fence('D', 6, Orientation.VERTICAL);
   523         Move f4 = Move.fence('E', 6, Orientation.VERTICAL);
   524         Move f5 = Move.fence('E', 5, Orientation.VERTICAL);
   525 
   526         assertEquals(f1, f2);
   527         assertFalse(f1.equals(f3));
   528         assertFalse(f4.equals(f5));
   529         assertFalse(f3.equals(f5));
   530     }
   531 
   532     public void testBrokenWriteOfAGameDanVsJarda() throws Exception {
   533         Board b = board.apply(Move.NORTH).apply(Move.SOUTH).
   534             apply(Move.NORTH).apply(Move.SOUTH).
   535             apply(Move.NORTH).apply(Move.SOUTH).
   536             apply(Move.WEST).apply(Move.fence('C', 6, Orientation.HORIZONTAL)).
   537             apply(Move.EAST).apply(Move.SOUTH).
   538             apply(Move.fence('E', 2, Orientation.HORIZONTAL)).apply(Move.fence('E', 5, Orientation.HORIZONTAL)).
   539             apply(Move.fence('F', 3, Orientation.VERTICAL)).apply(Move.fence('D', 6, Orientation.VERTICAL)).
   540             apply(Move.jump(Direction.NORTH, Direction.EAST)).apply(Move.fence('F', 5, Orientation.VERTICAL)).
   541             apply(Move.fence('E', 1, Orientation.VERTICAL)).apply(Move.fence('E', 4, Orientation.VERTICAL)).
   542             apply(Move.fence('D', 8, Orientation.HORIZONTAL)).apply(Move.fence('D', 7, Orientation.HORIZONTAL)).
   543             apply(Move.fence('D', 4, Orientation.HORIZONTAL)).apply(Move.fence('E', 8, Orientation.VERTICAL)).
   544             apply(Move.fence('C', 3, Orientation.HORIZONTAL)).apply(Move.WEST).
   545             apply(Move.fence('D', 2, Orientation.VERTICAL)).apply(Move.fence('A', 4, Orientation.HORIZONTAL)).
   546             apply(Move.fence('B', 2, Orientation.HORIZONTAL)).apply(Move.WEST).
   547             apply(Move.SOUTH).apply(Move.SOUTH).
   548             apply(Move.SOUTH).apply(Move.WEST);
   549         Board m = move(b, 0, Direction.WEST);
   550         Board f = fence(m, 1, 'A', 1, Orientation.VERTICAL);
   551         Board l = fence(f, 0, 'A', 3, Orientation.VERTICAL);
   552     }
   553     
   554     public void testTomasHolyCannotJumpWS() throws Exception {
   555 /*
   556 N   S 
   557 N   S 
   558 N   S 
   559  */
   560         Board b = apply(board, Move.NORTH);
   561         b = apply(b, Move.SOUTH);
   562         b = apply(b, Move.NORTH);
   563         b = apply(b, Move.SOUTH);
   564         b = apply(b, Move.NORTH);
   565         b = apply(b, Move.SOUTH);
   566 /*        
   567 HD3   HE6 
   568 HB6   HG3 
   569 VE3   HD4 
   570 HA4   VB5 
   571  */
   572         b = fence(b, 0, 'D', 3, Orientation.HORIZONTAL);
   573         b = fence(b, 1, 'E', 6, Orientation.HORIZONTAL);
   574         b = fence(b, 0, 'B', 6, Orientation.HORIZONTAL);
   575         b = fence(b, 1, 'G', 3, Orientation.HORIZONTAL);
   576         b = fence(b, 0, 'E', 3, Orientation.VERTICAL);
   577         b = fence(b, 1, 'D', 4, Orientation.HORIZONTAL);
   578         b = fence(b, 0, 'A', 4, Orientation.HORIZONTAL);
   579         b = fence(b, 1, 'B', 5, Orientation.VERTICAL);
   580 /*        
   581 VE1   HC5 
   582 VE5   HF2 
   583 VH2   HH1 
   584 HB3   HF1 
   585 HA1   S 
   586  */
   587         b = fence(b, 0, 'E', 1, Orientation.VERTICAL);
   588         b = fence(b, 1, 'C', 5, Orientation.HORIZONTAL);
   589         b = fence(b, 0, 'E', 5, Orientation.VERTICAL);
   590         b = fence(b, 1, 'F', 2, Orientation.HORIZONTAL);
   591         b = fence(b, 0, 'H', 2, Orientation.VERTICAL);
   592         b = fence(b, 1, 'H', 1, Orientation.HORIZONTAL);
   593         b = fence(b, 0, 'B', 3, Orientation.HORIZONTAL);
   594         b = fence(b, 1, 'F', 1, Orientation.HORIZONTAL);
   595         b = fence(b, 0, 'A', 1, Orientation.HORIZONTAL);
   596         b = apply(b, Move.SOUTH);
   597         
   598 /*
   599 W   W 
   600 W   HC8 
   601 HC1   HE8 
   602 N                
   603 */
   604         b = apply(b, Move.WEST);
   605         b = apply(b, Move.WEST);
   606         b = apply(b, Move.WEST);
   607         b = fence(b, 1, 'C', 8, Orientation.HORIZONTAL);
   608         b = fence(b, 0, 'C', 1, Orientation.HORIZONTAL);
   609         b = fence(b, 1, 'E', 8, Orientation.HORIZONTAL);
   610         b = apply(b, Move.NORTH);
   611 /* and now try WS */
   612         b = move(b, 1, Direction.WEST, Direction.SOUTH);
   613         assertNotNull("Board is OK", b);
   614         /*
   615         StringWriter sw = new StringWriter();
   616         b.write(sw);
   617         fail(sw.toString());
   618          */
   619     }
   620 
   621     static Board picture2board(String text) throws IOException, IllegalPositionException {
   622         StringReader sr = new StringReader(text);
   623         return Board.read(sr);
   624     }
   625 }