using pseudo-random generated numbers in PlayRandMoves | bench 1136338
This commit is contained in:
1 parent
ff17972725
commit
1449a1545f
3 files changed
+29
-12
No files matched your search
+5
-7
@@ -9,6 +9,7 @@
|
||||
#include "evaluate.h"
|
||||
#include "search.h"
|
||||
#include "movegen.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@@ -59,17 +60,12 @@ static bool IsGameOver(Board &board, SEARCH::SearchContext& ctx) {
|
||||
}
|
||||
|
||||
static void PlayRandMoves(Board &board, SEARCH::SearchContext& ctx) {
|
||||
std::random_device dev;
|
||||
std::mt19937_64 rng(dev());
|
||||
|
||||
std::uniform_int_distribution<int> moveDist(0, 1);
|
||||
bool plusOne = moveDist(rng);
|
||||
bool plusOne = UTILS::RandomBool();
|
||||
|
||||
for (int count = 0; count < RAND_MOVES + plusOne; count++) {
|
||||
MOVEGEN::GenerateMoves<All>(board);
|
||||
std::uniform_int_distribution<int> dist(0, board.currentMoveIndex - 1);
|
||||
|
||||
bool isLegal = board.MakeMove(board.moveList[dist(rng)]);
|
||||
bool isLegal = board.MakeMove(board.moveList[UTILS::RandomInt(0, board.currentMoveIndex - 1)]);
|
||||
|
||||
if (!isLegal) {
|
||||
count--;
|
||||
@@ -79,6 +75,8 @@ static void PlayRandMoves(Board &board, SEARCH::SearchContext& ctx) {
|
||||
MOVEGEN::GenerateMoves<All>(board);
|
||||
if (IsGameOver(board, ctx)) break;
|
||||
}
|
||||
|
||||
board.PrintBoard();
|
||||
}
|
||||
|
||||
static void WriteToFile(std::vector<Game> &gamesBuffer, std::ofstream &file) {
|
||||
|
||||
+21
-5
@@ -8,35 +8,51 @@ namespace UTILS {
|
||||
U64 initialSeed = 0x60919C48E57863B9;
|
||||
|
||||
// PRNG using xorshift
|
||||
static U64 RandomNum() {
|
||||
static U64 RandomU64() {
|
||||
initialSeed ^= initialSeed << 13;
|
||||
initialSeed ^= initialSeed >> 7;
|
||||
initialSeed ^= initialSeed << 17;
|
||||
return initialSeed;
|
||||
}
|
||||
|
||||
bool RandomBool() {
|
||||
return (RandomU64() & 1) == 1;
|
||||
}
|
||||
|
||||
int RandomInt(int min, int max) {
|
||||
if (max < min) {
|
||||
int temp = min;
|
||||
min = max;
|
||||
max = temp;
|
||||
}
|
||||
|
||||
int range = max - min + 1;
|
||||
|
||||
return min + (RandomU64() % range);
|
||||
}
|
||||
|
||||
void InitZobrist() {
|
||||
// init piece square keys
|
||||
for (int i = White; i <= Black; i++) {
|
||||
for (int j = Pawn; j <= King; j++) {
|
||||
for (int k = a1; k <= h8; k++) {
|
||||
zKeys[i][j][k] = RandomNum();
|
||||
zKeys[i][j][k] = RandomU64();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// init en passant file keys
|
||||
for (int i = 0; i < 8; i++) {
|
||||
zEnPassant[i] = RandomNum();
|
||||
zEnPassant[i] = RandomU64();
|
||||
}
|
||||
|
||||
// init castling rights keys
|
||||
for (int i = 0; i < 16; i++) {
|
||||
zCastle[i] = RandomNum();
|
||||
zCastle[i] = RandomU64();
|
||||
}
|
||||
|
||||
// init side key
|
||||
zSide = RandomNum();
|
||||
zSide = RandomU64();
|
||||
}
|
||||
|
||||
U64 GetHashKey(Board &board) {
|
||||
|
||||
@@ -21,6 +21,9 @@ inline U64 zCastle[16];
|
||||
|
||||
inline U64 zSide;
|
||||
|
||||
bool RandomBool();
|
||||
int RandomInt(int min, int max);
|
||||
|
||||
void InitZobrist();
|
||||
U64 GetHashKey(Board &board);
|
||||
|
||||
|
||||
Reference in new issue
Block a user