stellar

Stellar - UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

commit 5dcc9ef4920e4b1ca8a653d066c9f4ace83f315c
parent 8bfcd0ddad32537cc686a87dc8200626e7be81d5
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 13 Mar 2024 23:10:19 +0000

Improve Zobrist lookup tables

Diffstat:
MCMakeLists.txt | 2+-
Msrc/board/board.cpp | 10+++++++---
Msrc/board/board.hpp | 6++----
Msrc/board/zobrist.hpp | 14++++++--------
4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project( Stellar - VERSION 1.3.5 + VERSION 1.3.6 DESCRIPTION "Chess engine written in C++" HOMEPAGE_URL https://git.dimitrijedobrota.com/stellar.git LANGUAGES CXX diff --git a/src/board/board.cpp b/src/board/board.cpp @@ -8,10 +8,14 @@ #include "utils_ui.hpp" #include "zobrist.hpp" +namespace zobrist { + /* Init arrays for Zobris hashing */ -std::array<std::array<U64, 64>, 12> zobrist::keys_piece = {{{0}}}; -std::array<U64, 64> zobrist::keys_enpassant = {{0}}; -std::array<U64, 16> zobrist::keys_castle = {{0}}; +U64 keys_piece[2][12][64] = {0}; +U64 keys_enpassant[64] = {0}; +U64 keys_castle[16] = {0}; + +} // namespace zobrist /* Getters */ diff --git a/src/board/board.hpp b/src/board/board.hpp @@ -197,13 +197,11 @@ U64 zobrist::hash(const Board &board) { uint8_t square = 0; for (Type type = PAWN; type <= KING; ++type) { - int piece_white_index = piece::get_index(type, WHITE); U64 bitboard_white = board.get_bitboard_piece(type, WHITE); - bitboard_for_each_bit(square, bitboard_white) { key_final ^= keys_piece[piece_white_index][square]; } + bitboard_for_each_bit(square, bitboard_white) { key_final ^= keys_piece[WHITE][type][square]; } - int piece_black_index = piece::get_index(type, BLACK); U64 bitboard_black = board.get_bitboard_piece(type, BLACK); - bitboard_for_each_bit(square, bitboard_black) { key_final ^= keys_piece[piece_black_index][square]; } + bitboard_for_each_bit(square, bitboard_black) { key_final ^= keys_piece[BLACK][type][square]; } } key_final ^= keys_castle[board.get_castle()]; diff --git a/src/board/zobrist.hpp b/src/board/zobrist.hpp @@ -11,20 +11,18 @@ class Board; namespace zobrist { -extern std::array<std::array<U64, 64>, 12> keys_piece; -extern std::array<U64, 64> keys_enpassant; -extern std::array<U64, 16> keys_castle; +extern U64 keys_piece[2][12][64]; +extern U64 keys_enpassant[64]; +extern U64 keys_castle[16]; const U64 keys_side = Random(C32(1699391443))(); inline void init() { Random gen1(C64(1804289383)); for (Type type = PAWN; type <= KING; ++type) { - int piece_index_white = piece::get(type, Color::WHITE).index; - int piece_index_black = piece::get(type, Color::BLACK).index; for (int square = 0; square < 64; square++) { - keys_piece[piece_index_white][square] = gen1(); - keys_piece[piece_index_black][square] = gen1(); + keys_piece[WHITE][type][square] = gen1(); + keys_piece[BLACK][type][square] = gen1(); } } @@ -44,7 +42,7 @@ inline constexpr U64 key_side() { return keys_side; } inline constexpr U64 key_castle(int exp) { return keys_castle[exp]; } inline constexpr U64 key_enpassant(Square square) { return keys_enpassant[square]; } inline constexpr U64 key_piece(Type type, Color color, Square square) { - return keys_piece[piece::get_index(type, color)][square]; + return keys_piece[color][type][square]; } }; // namespace zobrist