stellar

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

commit 500ef277aef9ef459745b6d68e39cd092c0a4103
parent 177bc921f0554ab8d0059328fbe2880333e7d2a6
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 21 Sep 2022 00:05:01 +0200

get_random_U64_number() and generata_magic_number() functions

Diffstat:
Msrc/engine.c | 50+++++++++++++++++++++++++++++++++-----------------
1 file changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/engine.c b/src/engine.c @@ -12,6 +12,7 @@ #define MAX(a, b) ((a > b) ? a : b) #define MIN(a, b) ((a < b) ? a : b) +// define number types typedef unsigned long long U64; // define bitboard data type #define C64(constantU64) constantU64##ULL // define shorthand for constants @@ -46,6 +47,36 @@ static inline int bit_lsb_index(U64 bitboard) { return bit_count((bitboard & -bitboard) - 1); } +// pseudo random numbers + +U32 state = C32(1804289383); + +U32 get_random_U32_number() { + U32 number = state; + + number ^= number << 13; + number ^= number >> 17; + number ^= number << 5; + + return state = number; +} + +U64 get_random_U64_number() { + U64 n1, n2, n3, n4; + + n1 = (U64)(get_random_U32_number()) & C64(0xFFFF); + n2 = (U64)(get_random_U32_number()) & C64(0xFFFF); + n3 = (U64)(get_random_U32_number()) & C64(0xFFFF); + n4 = (U64)(get_random_U32_number()) & C64(0xFFFF); + + return n1 | (n2 << 16) | (n3 << 32) | (n4 << 48); +} + +U64 generate_magic_number() { + return get_random_U64_number() & get_random_U64_number() & + get_random_U64_number(); +} + // squares // clang-format off enum enumSquare { @@ -285,24 +316,9 @@ U64 set_occupancy(int index, int bits_in_mask, U64 attack_mask) { return occupancy; } -// pseudo random number state -U32 state = C32(1804289383); -U32 get_random_U32_number() { - U32 number = state; - - number ^= number << 13; - number ^= number >> 17; - number ^= number << 5; - - return state = number; -} - int main(void) { init_leapers_attacks(); - printf("%u\n", get_random_U32_number()); - printf("%u\n", get_random_U32_number()); - printf("%u\n", get_random_U32_number()); - printf("%u\n", get_random_U32_number()); - printf("%u\n", get_random_U32_number()); + + bitboard_print(generate_magic_number()); return 0; }