#include <list>
#include <sstream>
#include <type_traits>
+#include <mutex>
#include "../bitboard.h"
#include "../movegen.h"
#include "../position.h"
#include "../search.h"
-#include "../thread_win32.h"
#include "../types.h"
#include "../uci.h"
#include <sys/stat.h>
#else
#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
+#ifndef NOMINMAX
+# define NOMINMAX // Disable macros min() and max()
+#endif
#include <windows.h>
#endif
hasPawns = pos.pieces(PAWN);
hasUniquePieces = false;
- for (Color c = WHITE; c <= BLACK; ++c)
+ for (Color c : { WHITE, BLACK })
for (PieceType pt = PAWN; pt < KING; ++pt)
if (popcount(pos.pieces(c, pt)) == 1)
hasUniquePieces = true;
std::swap(squares[0], *std::max_element(squares, squares + leadPawnsCnt, pawns_comp));
- tbFile = file_of(squares[0]);
- if (tbFile > FILE_D)
- tbFile = file_of(squares[0] ^ 7); // Horizontal flip: SQ_H1 -> SQ_A1
+ tbFile = map_to_queenside(file_of(squares[0]));
}
// DTZ tables are one-sided, i.e. they store positions only for white to
// Then we reorder the pieces to have the same sequence as the one stored
// in pieces[i]: the sequence that ensures the best compression.
- for (int i = leadPawnsCnt; i < size; ++i)
- for (int j = i; j < size; ++j)
+ for (int i = leadPawnsCnt; i < size - 1; ++i)
+ for (int j = i + 1; j < size; ++j)
if (d->pieces[i] == pieces[j])
{
std::swap(pieces[i], pieces[j]);
enum { Split = 1, HasPawns = 2 };
- assert(e.hasPawns == !!(*data & HasPawns));
- assert((e.key != e.key2) == !!(*data & Split));
+ assert(e.hasPawns == bool(*data & HasPawns));
+ assert((e.key != e.key2) == bool(*data & Split));
data++; // First byte stores flags
template<TBType Type>
void* mapped(TBTable<Type>& e, const Position& pos) {
- static Mutex mutex;
+ static std::mutex mutex;
// Use 'acquire' to avoid a thread reading 'ready' == true while
// another is still working. (compiler reordering may cause this).
if (e.ready.load(std::memory_order_acquire))
return e.baseAddress; // Could be nullptr if file does not exist
- std::unique_lock<Mutex> lk(mutex);
+ std::unique_lock<std::mutex> lk(mutex);
if (e.ready.load(std::memory_order_relaxed)) // Recheck under lock
return e.baseAddress;