info-gnu-chess
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Chess960


From: Jason Sidabras
Subject: Chess960
Date: Wed, 20 Aug 2008 20:21:43 -0500

Hello,

I have just made a patch for gnuchess 5.07 which adds the -n switch to
play chess960 and increments to version 5.08. Testing is needed for
castling but I think everything should work.

"Chess960 is a chess variant produced by the late former World
Champion Bobby Fischer by modifying the rules of Shuffle Chess so that
castling possibilities exist for all starting positions. Fischer's
goal was to create a chess variant in which chess creativity and
talent would be more important than memorization and analysis of
opening moves."

Enjoy!

Jason

----------- BEGIN: gnuchess-5.07_5.08.diff  --------------

/diff -ur ../gnuchess-5.07/configure ./configure
--- ../gnuchess-5.07/configure  Thu Aug  7 06:55:12 2003
+++ ./configure Wed Aug 20 17:50:47 2008
@@ -1545,7 +1545,7 @@

 # Define the identity of the package.
  PACKAGE=gnuchess
- VERSION=5.07
+ VERSION=5.08

 cat >>confdefs.h <<_ACEOF
diff -ur ../gnuchess-5.07/src/cmd.c ./src/cmd.c
--- ../gnuchess-5.07/src/cmd.c  Mon Jun 30 06:00:02 2003
+++ ./src/cmd.c Tue Aug 19 18:38:34 2008
@@ -536,6 +536,11 @@
      " Options xboard and post are accepted without leading dashes\n"
      " for backward compatibility\n"
      "\n"
+     " Type of Game: "
+     "\n"
+     " -n, --chess960      Chess960, Fischer Random Chess Game"
+     "\n"
+     "\n"
      "Report bugs to
<bug-gnu-ch...<http://groups.google.com/groups/unlock?_done=/group/gnu.chess/browse_thread/thread/96942ddaf90181d8&msg=f369fe9d6d700b2d>
@gnu.org>.\n"
      "\n", progname);
      }
diff -ur ../gnuchess-5.07/src/common.h ./src/common.h
--- ../gnuchess-5.07/src/common.h       Mon Jun 30 06:28:38 2003
+++ ./src/common.h      Wed Aug 20 12:59:16 2008
@@ -533,6 +533,7 @@
 void InitRotAtak (void);
 void InitDistance (void);
 void InitVars (void);
+void Init960 (void);
 void InitHashCode (void);
 void InitHashTable (void);
 void CalcHashSize (int);
diff -ur ../gnuchess-5.07/src/init.c ./src/init.c
--- ../gnuchess-5.07/src/init.c Thu Jun 12 16:33:06 2003
+++ ./src/init.c        Wed Aug 20 17:52:38 2008
@@ -61,7 +61,36 @@
    InitInput ();
 }

+void Initialize960 (void)
+/
**************************************************************************
+ *
+ *  The main initialization driver.
+ *
+
**************************************************************************/
+{
+   InitLzArray ();
+   InitBitPosArray ();
+   InitMoveArray ();
+   InitRay ();
+   InitFromToRay ();
+   InitRankFileBit ();
+   InitPassedPawnMask ();
+   InitIsolaniMask ();
+   InitSquarePawnMask ();
+   InitBitCount ();
+   InitRotAtak ();
+   InitRandomMasks ();
+   InitDistance ();
+   Init960 ();
+   InitHashCode ();
+   InitHashTable ();
+   CalcHashKey ();
+   ShowSmallBoard ();
+   InitInput ();
+}

+
+
 void InitFICS (void)
 {
    if (flags & XBOARD) {
@@ -793,3 +822,216 @@
    nmovesfrombook = 0;
    ExchCnt[white] = ExchCnt[black] = 0;
 }
+
+int Die6 (void)
+{
+/
***************************************************************************
+ *
+ * Simulate 6-sided die for random board placement
+ *
+
***************************************************************************/

+
+   int i;
+   /*
+   ** Seed the random number generator with the current time
+   ** of day.
+   */
+   srand( (unsigned int)time( NULL ) );
+
+   i = rand() % 5;
+   return i;
+
+}
+
+void Init960 (void)
+/
***************************************************************************
+ *
+ * Uses the Bodlaender's dice-rolling method to determine the
starting
+ * random placement of pieces.
+ *
+
***************************************************************************/

+{
+static const int KnownBoard[16] =
+{
+   A1, B1, C1, D1, E1, F1, G1, H1,
+   A8, B8, C8, D8, E8, F8, G8, H8
+};
+
+static int ninboard[64] =
+{ empty, empty,  empty,  empty, empty, empty,  empty,  empty,
+  pawn,  pawn,   pawn,   pawn,  pawn,  pawn,   pawn,   pawn,
+  empty, empty,  empty,  empty, empty, empty,  empty,  empty,
+  empty, empty,  empty,  empty, empty, empty,  empty,  empty,
+  empty, empty,  empty,  empty, empty, empty,  empty,  empty,
+  empty, empty,  empty,  empty, empty, empty,  empty,  empty,
+  pawn,  pawn,   pawn,   pawn,  pawn,  pawn,   pawn,   pawn,
+  empty, empty,  empty,  empty, empty, empty,  empty,  empty};
+
+   int j;
+   int i;
+
+   memset (&board, 0, sizeof (board));
+
+   /* Initialzie Pawns */
+   for (i = 8; i < 16; i++)
+      SETBIT (board.b[white][pawn], i);
+   for (i = 48; i < 56; i++)
+      SETBIT (board.b[black][pawn], i);
+
+   /* Bishop placement */
+   do {
+       j = Die6 ();
+   } while ( j == 4 || j == 5 && ninboard[j] != empty );
+
+   /* Black Squares Bishop */
+   SETBIT (board.b[white][bishop], 2*j);
+   ninboard[2*j] = bishop;
+   SETBIT (board.b[black][bishop], 63-2*j);
+   ninboard[63-2*j] = bishop;
+
+
+   do {
+      j = Die6 ();
+   } while ( j == 4 || j == 5 && ninboard[j] != empty );
+
+   /* White Squares Bishop */
+   SETBIT (board.b[white][bishop], 2*j+1);
+   ninboard[2*j+1] = bishop;
+   SETBIT (board.b[black][bishop], 63-2*j-1);
+   ninboard[63-2*j-1] = bishop;
+
+   /* Queen Placement */
+   do {
+      j = Die6 ();
+   } while ( ninboard[j] != empty );
+
+   SETBIT (board.b[white][queen], j);
+   ninboard[j] = queen;
+   SETBIT (board.b[black][queen], 63-j);
+   ninboard[63-j] = queen;
+
+   /* Knight Placement */
+   do {
+      j = Die6 ();
+   } while ( ninboard[j] != empty );
+
+   SETBIT (board.b[white][knight], j);
+   ninboard[j] = knight;
+   SETBIT (board.b[black][knight], 63-j);
+   ninboard[63-j] = knight;
+
+   do {
+      j = Die6 ();
+   } while ( ninboard[j] != empty );
+
+   SETBIT (board.b[white][knight], j);
+   ninboard[j] = knight;
+   SETBIT (board.b[black][knight], 63-j);
+   ninboard[63-j] = knight;
+
+   /* Set Rook King Rook combination */
+
+   int p = 3;
+
+   for ( j = 0; j < 8; j ++ ) {
+      if ( p == 1 || p == 3 && ninboard[j] == empty ) {
+         SETBIT (board.b[white][rook], j);
+         ninboard[j] = rook;
+         SETBIT (board.b[black][rook], 63-j);
+         ninboard[63-j] = rook;
+         p = p - 1;
+      }
+      if ( p == 2 && ninboard[j] == empty ) {
+         SETBIT (board.b[white][king], j);
+         ninboard[j] = king;
+         SETBIT (board.b[black][king], 63-j);
+         ninboard[63-j] = king;
+         board.king[white] = KnownBoard[j];
+         board.king[black] = KnownBoard[15-j];
+         p = p - 1;
+      }
+   }
+
+
+   SETBIT (stonewall[white], D4); /* SMC */
+   SETBIT (stonewall[white], E3); /* SMC */
+   SETBIT (stonewall[white], F4); /* SMC */
+
+   SETBIT (stonewall[black], D5); /* SMC */
+   SETBIT (stonewall[black], E6); /* SMC */
+   SETBIT (stonewall[black], F5); /* SMC */
+
+   rings[0] = ULL(0x0000001818000000);
+   rings[1] = ULL(0x00003C24243C0000);
+   rings[2] = ULL(0x007E424242427E00);
+   rings[3] = ULL(0xFF818181818181FF);
+
+   boxes[0] = ULL(0x00003C3C3C3C0000); /* rings[0] | rings[1] */
+   boxes[1] = ULL(0x007E7E7E7E7E7E00); /* rings[0] | rings[1] |
rings[2] */
+
+   boardhalf[white] = RankBit[0]|RankBit[1]|RankBit[2]|RankBit[3];
+   boardhalf[black] = RankBit[4]|RankBit[5]|RankBit[6]|RankBit[7];
+   boardside[ks] = FileBit[4]|FileBit[5]|FileBit[6]|FileBit[7];
+   boardside[qs] = FileBit[0]|FileBit[1]|FileBit[2]|FileBit[3];
+
+   board.flag |= (WCASTLE | BCASTLE);
+   RealSide = board.side = white;
+   board.ep = -1;
+   RealGameCnt = GameCnt = -1;
+   Game50 = 0;
+   computer = black;
+   CalcHashKey ();
+   Game[0].hashkey = HashKey;
+   board.pmaterial[white] = board.pmaterial[black] =
+      2*ValueR + 2*ValueN + 2*ValueB + ValueQ;
+   board.material[white] = board.material[black] =
+      board.pmaterial[white] + 8*ValueP;
+
+   /* Initialize pgn values */
+   initial_comments = NULL;
+   /* Reset values; doing this again will cause a trivial memory leak
+    * when reloading PGN files as games, but it's not worth fixing.
*/
+   pgn_event = pgn_site =
+   pgn_date = pgn_round = pgn_white = pgn_black =
+   pgn_whiteELO = pgn_blackELO = pgn_result =
+   pgn_othertags = NULL;
+
+
+   UpdateFriends ();
+   UpdateCBoard ();
+   UpdateMvboard ();
+
+   for (i = A1; i <= H8; i++)
+   {
+      if (cboard[i])
+      {
+         SETBIT (board.blockerr90, r90[i]);
+         SETBIT (board.blockerr45, r45[i]);
+         SETBIT (board.blockerr315, r315[i]);
+      }
+   }
+
+   /* TreePtr[0] is practically unused.  TreePtr[1] points to the
+    * base of the tree.
+    */
+   TreePtr[0] = TreePtr[1] = Tree;
+
+   /* Initialize some of the game flags */
+   SET (flags, USEHASH);
+   SET (flags, USENULL);
+   SearchTime = 5;
+   SearchDepth = 0;
+   board.castled[white] = board.castled[black] = false;
+   phase = PHASE;
+
+/*  Calculate the ttable hashmask & pawntable hashmask */
+   if ( HashSize == 0 )
+     CalcHashSize(HashSize);
+
+   signal (SIGINT, EndSearch);
+
+   nmovesfrombook = 0;
+
+
+}
+
diff -ur ../gnuchess-5.07/src/main.c ./src/main.c
--- ../gnuchess-5.07/src/main.c Mon Jun 30 06:00:02 2003
+++ ./src/main.c        Wed Aug 20 17:20:38 2008
@@ -298,7 +298,7 @@
    */

   int c;
-  int opt_help = 0, opt_version = 0, opt_post = 0, opt_xboard = 0,
opt_hash = 0, opt_easy = 0, opt_manual = 0;
+  int opt_help = 0, opt_version = 0, opt_post = 0, opt_xboard = 0,
opt_hash = 0, opt_easy = 0, opt_manual = 0, opt_ninesixty = 0;
   char *endptr;

   progname = argv[0]; /* Save in global for cmd_usage */
@@ -309,6 +309,7 @@
     {
         {"hashsize", 1, 0, 's'},
         {"version", 0, 0, 'v'},
+        {"chess960", 0, 0, 'n'},
         {"help", 0, 0, 'h'},
         {"xboard", 0, 0, 'x'},
         {"post", 0, 0, 'p'},
@@ -321,7 +322,7 @@

     int option_index = 0;

-    c = getopt_long (argc, argv, "ehmpvxs:",
+    c = getopt_long (argc, argv, "ehmpnvxs:",
              long_options, &option_index);

     /* Detect the end of the options. */
@@ -350,6 +351,9 @@
      case 'e':
        opt_easy = 1;
        break;
+     case 'n':
+       opt_ninesixty = 1;
+       break;
      case 'm':
        opt_manual = 1;
        break;
@@ -417,7 +421,13 @@
   if ( opt_hash != 0)
     CalcHashSize(opt_hash);

-  Initialize ();
+
+  if ( opt_ninesixty == 1 ) {
+     printf("Generating Random Board...\n");
+     Initialize960 ();
+  }
+  else
+     Initialize ();

   if ( opt_easy == 0)
    SET (flags, HARD);
------------ END gnuchess-5.07_5.08.diff --------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]