|
@@ -0,0 +1,38 @@
|
|
|
+#include "TranspositionTable.h"
|
|
|
+#include "MoveGeneration.h"
|
|
|
+#include <random>
|
|
|
+
|
|
|
+using namespace chessy;
|
|
|
+
|
|
|
+
|
|
|
+HashValue ZobristValues::getHash(const ChessGame& cg) const
|
|
|
+{
|
|
|
+ HashValue value;
|
|
|
+ const Board& b = cg.getBoard();
|
|
|
+ // iterate over all piece types
|
|
|
+ for (int i = 0; i < 12; i++) {
|
|
|
+ Bitboard t = b.getBitboards(i < 6 ? WHITE_SIDE : BLACK_SIDE)[i];
|
|
|
+ for (auto pos : PositionSet{ t }) {
|
|
|
+ value ^= getNumber(PieceType(i), pos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ value ^= castlingRights[cg.getCastlingRights()];
|
|
|
+ if (cg.getEnPassantIndex() != -1)
|
|
|
+ value ^= enPassant[cg.getEnPassantIndex()];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void ZobristValues::create(uint64_t seed)
|
|
|
+{
|
|
|
+ std::mt19937_64 engine(seed);
|
|
|
+ std::uniform_int_distribution<HashValue> distribution;
|
|
|
+ auto rnd = [&]() { return distribution(engine); };
|
|
|
+
|
|
|
+ for (auto& v : pieces)
|
|
|
+ v = rnd();
|
|
|
+ for (auto& v : castlingRights)
|
|
|
+ v = rnd();
|
|
|
+ for (auto& v : enPassant)
|
|
|
+ v = rnd();
|
|
|
+ turn = rnd();
|
|
|
+}
|