mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Rework init
And fix compile on MSVC due to conflicting use of std::min No functional change.
This commit is contained in:
parent
9173d29c41
commit
f0650d499f
2 changed files with 57 additions and 76 deletions
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
#include "tbcore.h"
|
#include "tbcore.h"
|
||||||
|
#include "../types.h"
|
||||||
|
|
||||||
#define TBMAX_PIECE 254
|
#define TBMAX_PIECE 254
|
||||||
#define TBMAX_PAWN 256
|
#define TBMAX_PAWN 256
|
||||||
|
@ -26,7 +28,6 @@
|
||||||
|
|
||||||
static Mutex TB_mutex;
|
static Mutex TB_mutex;
|
||||||
|
|
||||||
static bool initialized = false;
|
|
||||||
static std::vector<std::string> paths;
|
static std::vector<std::string> paths;
|
||||||
|
|
||||||
static int TBnum_piece, TBnum_pawn;
|
static int TBnum_piece, TBnum_pawn;
|
||||||
|
@ -156,10 +157,9 @@ static void add_to_hash(TBEntry *ptr, uint64_t key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string pchr = " PNBRQK";
|
static const std::string pchr = " PNBRQK";
|
||||||
static std::string pchr_rev = "KQRBNP ";
|
|
||||||
|
|
||||||
static void init_tb(std::string str)
|
static void init_tb(const std::string& str)
|
||||||
{
|
{
|
||||||
FD fd;
|
FD fd;
|
||||||
TBEntry *entry;
|
TBEntry *entry;
|
||||||
|
@ -261,23 +261,22 @@ static void init_tb(std::string str)
|
||||||
|
|
||||||
void Tablebases::init(const std::string& path)
|
void Tablebases::init(const std::string& path)
|
||||||
{
|
{
|
||||||
char str[16];
|
static bool initialized = false;
|
||||||
int i, j, k, l;
|
|
||||||
|
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
TBEntry *entry;
|
TBEntry *entry;
|
||||||
|
|
||||||
for (i = 0; i < TBnum_piece; i++) {
|
for (int i = 0; i < TBnum_piece; i++) {
|
||||||
entry = (TBEntry *)&TB_piece[i];
|
entry = (TBEntry *)&TB_piece[i];
|
||||||
free_wdl_entry(entry);
|
free_wdl_entry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < TBnum_pawn; i++) {
|
for (int i = 0; i < TBnum_pawn; i++) {
|
||||||
entry = (TBEntry *)&TB_pawn[i];
|
entry = (TBEntry *)&TB_pawn[i];
|
||||||
free_wdl_entry(entry);
|
free_wdl_entry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < DTZ_ENTRIES; i++)
|
for (int i = 0; i < DTZ_ENTRIES; i++)
|
||||||
if (DTZ_table[i].entry)
|
if (DTZ_table[i].entry)
|
||||||
free_dtz_entry(DTZ_table[i].entry);
|
free_dtz_entry(DTZ_table[i].entry);
|
||||||
} else {
|
} else {
|
||||||
|
@ -288,82 +287,61 @@ void Tablebases::init(const std::string& path)
|
||||||
if (path.empty() || path == "<empty>")
|
if (path.empty() || path == "<empty>")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Argument path is set to the directory or directories where the .rtbw and
|
||||||
|
// .rtbz files can be found. Multiple directories are separated by ";" on
|
||||||
|
// Windows and by ":" on Unix-based operating systems.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// C:\tb\wdl345;C:\tb\wdl6;D:\tb\dtz345;D:\tb\dtz6
|
||||||
|
|
||||||
// Tokenize path into paths[] using SEP_CHAR delimiter
|
// Tokenize path into paths[] using SEP_CHAR delimiter
|
||||||
std::string s(path);
|
std::stringstream ss(path);
|
||||||
size_t pos = 0;
|
std::string token;
|
||||||
|
|
||||||
while ((pos = s.find(SEP_CHAR)) != std::string::npos) {
|
while (std::getline(ss, token, SEP_CHAR))
|
||||||
paths.push_back(s.substr(0, pos));
|
paths.push_back(token);
|
||||||
s.erase(0, pos + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
paths.push_back(s);
|
|
||||||
|
|
||||||
TBnum_piece = TBnum_pawn = 0;
|
TBnum_piece = TBnum_pawn = 0;
|
||||||
MaxCardinality = 0;
|
MaxCardinality = 0;
|
||||||
|
|
||||||
for (i = 0; i < (1 << TBHASHBITS); i++)
|
for (int i = 0; i < (1 << TBHASHBITS); i++)
|
||||||
for (j = 0; j < HSHMAX; j++) {
|
for (int j = 0; j < HSHMAX; j++) {
|
||||||
TB_hash[i][j].key = 0ULL;
|
TB_hash[i][j].key = 0;
|
||||||
TB_hash[i][j].ptr = NULL;
|
TB_hash[i][j].ptr = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < DTZ_ENTRIES; i++)
|
for (int i = 0; i < DTZ_ENTRIES; i++)
|
||||||
DTZ_table[i].entry = NULL;
|
DTZ_table[i].entry = nullptr;
|
||||||
|
|
||||||
for (i = 1; i < 6; i++) {
|
const std::string K("K");
|
||||||
sprintf(str, "K%cvK", pchr_rev[i]);
|
|
||||||
init_tb(str);
|
for (PieceType p1 = PAWN; p1 < KING; ++p1)
|
||||||
|
{
|
||||||
|
init_tb(K + pchr[p1] + "vK");
|
||||||
|
|
||||||
|
for (PieceType p2 = PAWN; p2 <= p1; ++p2)
|
||||||
|
{
|
||||||
|
init_tb(K + pchr[p1] + pchr[p2] + "vK");
|
||||||
|
init_tb(K + pchr[p1] + "vK" + pchr[p2]);
|
||||||
|
|
||||||
|
for (PieceType p3 = PAWN; p3 < KING; ++p3)
|
||||||
|
init_tb(K + pchr[p1] + pchr[p2] + "vK" + pchr[p3]);
|
||||||
|
|
||||||
|
for (PieceType p3 = PAWN; p3 <= p2; ++p3)
|
||||||
|
{
|
||||||
|
init_tb(K + pchr[p1] + pchr[p2] + pchr[p3] + "vK");
|
||||||
|
|
||||||
|
for (PieceType p4 = PAWN; p4 <= p3; ++p4)
|
||||||
|
init_tb(K + pchr[p1] + pchr[p2] + pchr[p3] + pchr[p4] + "vK");
|
||||||
|
|
||||||
|
for (PieceType p4 = PAWN; p4 < KING; ++p4)
|
||||||
|
init_tb(K + pchr[p1] + pchr[p2] + pchr[p3] + "vK" + pchr[p4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i < 6; i++)
|
for (PieceType p3 = PAWN; p3 <= p1; ++p3)
|
||||||
for (j = i; j < 6; j++) {
|
for (PieceType p4 = PAWN; p4 <= (p1 == p3 ? p2 : p3); ++p4)
|
||||||
sprintf(str, "K%cvK%c", pchr_rev[i], pchr_rev[j]);
|
init_tb(K + pchr[p1] + pchr[p2] + "vK" + pchr[p3] + pchr[p4]);
|
||||||
init_tb(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i < 6; i++)
|
|
||||||
for (j = i; j < 6; j++) {
|
|
||||||
sprintf(str, "K%c%cvK", pchr_rev[i], pchr_rev[j]);
|
|
||||||
init_tb(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < 6; i++)
|
|
||||||
for (j = i; j < 6; j++)
|
|
||||||
for (k = 1; k < 6; k++) {
|
|
||||||
sprintf(str, "K%c%cvK%c", pchr_rev[i], pchr_rev[j], pchr_rev[k]);
|
|
||||||
init_tb(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < 6; i++)
|
|
||||||
for (j = i; j < 6; j++)
|
|
||||||
for (k = j; k < 6; k++) {
|
|
||||||
sprintf(str, "K%c%c%cvK", pchr_rev[i], pchr_rev[j], pchr_rev[k]);
|
|
||||||
init_tb(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < 6; i++)
|
|
||||||
for (j = i; j < 6; j++)
|
|
||||||
for (k = i; k < 6; k++)
|
|
||||||
for (l = (i == k) ? j : k; l < 6; l++) {
|
|
||||||
sprintf(str, "K%c%cvK%c%c", pchr_rev[i], pchr_rev[j], pchr_rev[k], pchr_rev[l]);
|
|
||||||
init_tb(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < 6; i++)
|
|
||||||
for (j = i; j < 6; j++)
|
|
||||||
for (k = j; k < 6; k++)
|
|
||||||
for (l = 1; l < 6; l++) {
|
|
||||||
sprintf(str, "K%c%c%cvK%c", pchr_rev[i], pchr_rev[j], pchr_rev[k], pchr_rev[l]);
|
|
||||||
init_tb(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < 6; i++)
|
|
||||||
for (j = i; j < 6; j++)
|
|
||||||
for (k = j; k < 6; k++)
|
|
||||||
for (l = k; l < 6; l++) {
|
|
||||||
sprintf(str, "K%c%c%c%cvK", pchr_rev[i], pchr_rev[j], pchr_rev[k], pchr_rev[l]);
|
|
||||||
init_tb(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "info string Found " << TBnum_piece + TBnum_pawn << " tablebases\n";
|
std::cerr << "info string Found " << TBnum_piece + TBnum_pawn << " tablebases\n";
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
#define FD_ERR -1
|
#define FD_ERR -1
|
||||||
#else
|
#else
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#define SEP_CHAR ';'
|
#define SEP_CHAR ';'
|
||||||
#define FD HANDLE
|
#define FD HANDLE
|
||||||
|
|
Loading…
Add table
Reference in a new issue