version 1.4.63b
[polyglot.git] / hash.c
diff --git a/hash.c b/hash.c
index 4baa0aa..4205130 100644 (file)
--- a/hash.c
+++ b/hash.c
-\r
-// hash.c\r
-\r
-// includes\r
-\r
-#include "board.h"\r
-#include "hash.h"\r
-#include "piece.h"\r
-#include "random.h"\r
-#include "square.h"\r
-#include "util.h"\r
-\r
-// variables\r
-\r
-static uint64 Castle64[16];\r
-\r
-// prototypes\r
-\r
-static uint64 hash_castle_key_debug (int flags);\r
-\r
-// functions\r
-\r
-// hash_init()\r
-\r
-void hash_init() {\r
-\r
-   int i;\r
-\r
-   for (i = 0; i < 16; i++) Castle64[i] = hash_castle_key_debug(i);\r
-}\r
-\r
-// hash_key()\r
-\r
-uint64 hash_key(const board_t * board) {\r
-\r
-   uint64 key;\r
-   int colour;\r
-   const uint8 * ptr;\r
-   int sq, piece;\r
-\r
-   ASSERT(board_is_ok(board));\r
-\r
-   // init\r
-\r
-   key = 0;\r
-\r
-   // pieces\r
-\r
-   for (colour = 1; colour <= 2; colour++) { // HACK\r
-      for (ptr = board->list[colour]; (sq=*ptr) != SquareNone; ptr++) {\r
-         piece = board->square[sq];\r
-         key ^= hash_piece_key(piece,sq);\r
-      }\r
-   }\r
-\r
-   // castle flags\r
-\r
-   key ^= hash_castle_key(board_flags(board));\r
-\r
-   // en-passant square\r
-\r
-   sq = board->ep_square;\r
-   if (sq != SquareNone) key ^= hash_ep_key(sq);\r
-\r
-   // turn\r
-\r
-   key ^= hash_turn_key(board->turn);\r
-\r
-   return key;\r
-}\r
-\r
-// hash_piece_key()\r
-\r
-uint64 hash_piece_key(int piece, int square) {\r
-\r
-   ASSERT(piece_is_ok(piece));\r
-   ASSERT(square_is_ok(square));\r
-\r
-   return random_64(RandomPiece+piece_to_12(piece)*64+square_to_64(square));\r
-}\r
-\r
-// hash_castle_key()\r
-\r
-uint64 hash_castle_key(int flags) {\r
-\r
-   ASSERT((flags&~0xF)==0);\r
-\r
-   return Castle64[flags];\r
-}\r
-\r
-// hash_castle_key_debug()\r
-\r
-static uint64 hash_castle_key_debug(int flags) {\r
-\r
-   uint64 key;\r
-   int i;\r
-\r
-   ASSERT((flags&~0xF)==0);\r
-\r
-   key = 0;\r
-\r
-   for (i = 0; i < 4; i++) {\r
-      if ((flags & (1<<i)) != 0) key ^= random_64(RandomCastle+i);\r
-   }\r
-\r
-   return key;\r
-}\r
-\r
-// hash_ep_key()\r
-\r
-uint64 hash_ep_key(int square) {\r
-\r
-   ASSERT(square_is_ok(square));\r
-\r
-   return random_64(RandomEnPassant+square_file(square));\r
-}\r
-\r
-// hash_turn_key()\r
-\r
-uint64 hash_turn_key(int colour) {\r
-\r
-   ASSERT(colour_is_ok(colour));\r
-\r
-   return (colour_is_white(colour)) ? random_64(RandomTurn) : 0;\r
-}\r
-\r
-// end of hash.cpp\r
-\r
+
+// hash.c
+
+// includes
+
+#include "board.h"
+#include "hash.h"
+#include "piece.h"
+#include "random.h"
+#include "square.h"
+#include "util.h"
+
+// variables
+
+static uint64 Castle64[16];
+
+// prototypes
+
+static uint64 hash_castle_key_debug (int flags);
+
+// functions
+
+// hash_init()
+
+void hash_init() {
+
+   int i;
+
+   for (i = 0; i < 16; i++) Castle64[i] = hash_castle_key_debug(i);
+}
+
+// hash_key()
+
+uint64 hash_key(const board_t * board) {
+
+   uint64 key;
+   int colour;
+   const uint8 * ptr;
+   int sq, piece;
+
+   ASSERT(board_is_ok(board));
+
+   // init
+
+   key = 0;
+
+   // pieces
+
+   for (colour = 1; colour <= 2; colour++) { // HACK
+      for (ptr = board->list[colour]; (sq=*ptr) != SquareNone; ptr++) {
+         piece = board->square[sq];
+         key ^= hash_piece_key(piece,sq);
+      }
+   }
+
+   // castle flags
+
+   key ^= hash_castle_key(board_flags(board));
+
+   // en-passant square
+
+   sq = board->ep_square;
+   if (sq != SquareNone) key ^= hash_ep_key(sq);
+
+   // turn
+
+   key ^= hash_turn_key(board->turn);
+
+   return key;
+}
+
+// hash_piece_key()
+
+uint64 hash_piece_key(int piece, int square) {
+
+   ASSERT(piece_is_ok(piece));
+   ASSERT(square_is_ok(square));
+
+   return random_64(RandomPiece+piece_to_12(piece)*64+square_to_64(square));
+}
+
+// hash_castle_key()
+
+uint64 hash_castle_key(int flags) {
+
+   ASSERT((flags&~0xF)==0);
+
+   return Castle64[flags];
+}
+
+// hash_castle_key_debug()
+
+static uint64 hash_castle_key_debug(int flags) {
+
+   uint64 key;
+   int i;
+
+   ASSERT((flags&~0xF)==0);
+
+   key = 0;
+
+   for (i = 0; i < 4; i++) {
+      if ((flags & (1<<i)) != 0) key ^= random_64(RandomCastle+i);
+   }
+
+   return key;
+}
+
+// hash_ep_key()
+
+uint64 hash_ep_key(int square) {
+
+   ASSERT(square_is_ok(square));
+
+   return random_64(RandomEnPassant+square_file(square));
+}
+
+// hash_turn_key()
+
+uint64 hash_turn_key(int colour) {
+
+   ASSERT(colour_is_ok(colour));
+
+   return (colour_is_white(colour)) ? random_64(RandomTurn) : 0;
+}
+
+// end of hash.cpp
+