`Fifteen' was getting the parity wrong on any size of board where
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 3 May 2004 07:56:23 +0000 (07:56 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 3 May 2004 07:56:23 +0000 (07:56 +0000)
the top left and bottom right corners didn't have the same
chessboard colour.

git-svn-id: svn://svn.tartarus.org/sgt/puzzles@4185 cda61777-01e9-0310-a592-d414129be87e

fifteen.c

index 7f6769a..04a8f75 100644 (file)
--- a/fifteen.c
+++ b/fifteen.c
@@ -199,15 +199,16 @@ char *new_game_seed(game_params *params)
      * Determine the required parity of the overall permutation.
      * This is the XOR of:
      * 
-     *  - The chessboard parity ((x^y)&1) of the gap square. The
-     *    bottom right, and therefore also the top left, count as
-     *    even.
+     *         - The chessboard parity ((x^y)&1) of the gap square. The
+     *           bottom right counts as even.
      * 
      *  - The parity of n. (The target permutation is 1,...,n-1,0
      *    rather than 0,...,n-1; this is a cyclic permutation of
      *    the starting point and hence is odd iff n is even.)
      */
-    parity = (X(params, gap) ^ Y(params, gap) ^ (n+1)) & 1;
+    parity = ((X(params, gap) - (params->w-1)) ^
+             (Y(params, gap) - (params->h-1)) ^
+             (n+1)) & 1;
 
     /*
      * Try the last two tiles one way round. If that fails, swap