mirror of
https://github.com/sockspls/badfish
synced 2025-05-03 01:59:36 +00:00
Cleanup work in misc.cpp
Also some code style tidy up of latest patches. Also renamed checkSq -> checkSquares because it is a bitboard and not a square. No functional change.
This commit is contained in:
parent
eaeb63f1d0
commit
ee0371f86e
8 changed files with 52 additions and 69 deletions
|
@ -201,12 +201,10 @@ void Bitboards::init() {
|
||||||
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
||||||
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
||||||
|
|
||||||
|
for (Piece pc = W_BISHOP; pc <= W_ROOK; ++pc)
|
||||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||||
{
|
{
|
||||||
Piece pc = (PseudoAttacks[BISHOP][s1] & s2) ? W_BISHOP :
|
if (!(PseudoAttacks[pc][s1] & s2))
|
||||||
(PseudoAttacks[ROOK][s1] & s2) ? W_ROOK : NO_PIECE;
|
|
||||||
|
|
||||||
if (pc == NO_PIECE)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
|
LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
|
||||||
|
|
23
src/misc.cpp
23
src/misc.cpp
|
@ -33,41 +33,37 @@ namespace {
|
||||||
/// DD-MM-YY and show in engine_info.
|
/// DD-MM-YY and show in engine_info.
|
||||||
const string Version = "";
|
const string Version = "";
|
||||||
|
|
||||||
/// Debug counters
|
|
||||||
int64_t hits[2], means[2];
|
|
||||||
|
|
||||||
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
||||||
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
||||||
/// can toggle the logging of std::cout and std:cin at runtime whilst preserving
|
/// can toggle the logging of std::cout and std:cin at runtime whilst preserving
|
||||||
/// usual i/o functionality, all without changing a single line of code!
|
/// usual I/O functionality, all without changing a single line of code!
|
||||||
/// Idea from http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81
|
/// Idea from http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81
|
||||||
|
|
||||||
struct Tie: public streambuf { // MSVC requires splitted streambuf for cin and cout
|
struct Tie: public streambuf { // MSVC requires splitted streambuf for cin and cout
|
||||||
|
|
||||||
Tie(streambuf* b, ofstream* f) : buf(b), file(f) {}
|
Tie(streambuf* b, streambuf* l) : buf(b), logBuf(l) {}
|
||||||
|
|
||||||
int sync() { return file->rdbuf()->pubsync(), buf->pubsync(); }
|
int sync() { return logBuf->pubsync(), buf->pubsync(); }
|
||||||
int overflow(int c) { return log(buf->sputc((char)c), "<< "); }
|
int overflow(int c) { return log(buf->sputc((char)c), "<< "); }
|
||||||
int underflow() { return buf->sgetc(); }
|
int underflow() { return buf->sgetc(); }
|
||||||
int uflow() { return log(buf->sbumpc(), ">> "); }
|
int uflow() { return log(buf->sbumpc(), ">> "); }
|
||||||
|
|
||||||
streambuf* buf;
|
streambuf *buf, *logBuf;
|
||||||
ofstream* file;
|
|
||||||
|
|
||||||
int log(int c, const char* prefix) {
|
int log(int c, const char* prefix) {
|
||||||
|
|
||||||
static int last = '\n';
|
static int last = '\n'; // Single log file
|
||||||
|
|
||||||
if (last == '\n')
|
if (last == '\n')
|
||||||
file->rdbuf()->sputn(prefix, 3);
|
logBuf->sputn(prefix, 3);
|
||||||
|
|
||||||
return last = file->rdbuf()->sputc((char)c);
|
return last = logBuf->sputc((char)c);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
|
|
||||||
Logger() : in(cin.rdbuf(), &file), out(cout.rdbuf(), &file) {}
|
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
|
||||||
~Logger() { start(false); }
|
~Logger() { start(false); }
|
||||||
|
|
||||||
ofstream file;
|
ofstream file;
|
||||||
|
@ -80,7 +76,7 @@ public:
|
||||||
|
|
||||||
if (b && !l.file.is_open())
|
if (b && !l.file.is_open())
|
||||||
{
|
{
|
||||||
l.file.open("io_log.txt", ifstream::out | ifstream::app);
|
l.file.open("io_log.txt", ifstream::out);
|
||||||
cin.rdbuf(&l.in);
|
cin.rdbuf(&l.in);
|
||||||
cout.rdbuf(&l.out);
|
cout.rdbuf(&l.out);
|
||||||
}
|
}
|
||||||
|
@ -124,6 +120,7 @@ const string engine_info(bool to_uci) {
|
||||||
|
|
||||||
|
|
||||||
/// Debug functions used mainly to collect run-time statistics
|
/// Debug functions used mainly to collect run-time statistics
|
||||||
|
static int64_t hits[2], means[2];
|
||||||
|
|
||||||
void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; }
|
void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; }
|
||||||
void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); }
|
void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); }
|
||||||
|
|
|
@ -232,7 +232,7 @@ namespace {
|
||||||
if (Checks)
|
if (Checks)
|
||||||
{
|
{
|
||||||
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
|
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
|
||||||
&& !(PseudoAttacks[Pt][from] & target & ci->checkSq[Pt]))
|
&& !(PseudoAttacks[Pt][from] & target & ci->checkSquares[Pt]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ci->dcCandidates && (ci->dcCandidates & from))
|
if (ci->dcCandidates && (ci->dcCandidates & from))
|
||||||
|
@ -242,7 +242,7 @@ namespace {
|
||||||
Bitboard b = pos.attacks_from<Pt>(from) & target;
|
Bitboard b = pos.attacks_from<Pt>(from) & target;
|
||||||
|
|
||||||
if (Checks)
|
if (Checks)
|
||||||
b &= ci->checkSq[Pt];
|
b &= ci->checkSquares[Pt];
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(from, pop_lsb(&b));
|
*moveList++ = make_move(from, pop_lsb(&b));
|
||||||
|
|
|
@ -94,12 +94,12 @@ CheckInfo::CheckInfo(const Position& pos) {
|
||||||
pinned = pos.pinned_pieces(pos.side_to_move());
|
pinned = pos.pinned_pieces(pos.side_to_move());
|
||||||
dcCandidates = pos.discovered_check_candidates();
|
dcCandidates = pos.discovered_check_candidates();
|
||||||
|
|
||||||
checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them);
|
checkSquares[PAWN] = pos.attacks_from<PAWN>(ksq, them);
|
||||||
checkSq[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
|
checkSquares[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
|
||||||
checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
|
checkSquares[BISHOP] = pos.attacks_from<BISHOP>(ksq);
|
||||||
checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
|
checkSquares[ROOK] = pos.attacks_from<ROOK>(ksq);
|
||||||
checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
|
checkSquares[QUEEN] = checkSquares[BISHOP] | checkSquares[ROOK];
|
||||||
checkSq[KING] = 0;
|
checkSquares[KING] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -616,7 +616,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
|
||||||
Square to = to_sq(m);
|
Square to = to_sq(m);
|
||||||
|
|
||||||
// Is there a direct check?
|
// Is there a direct check?
|
||||||
if (ci.checkSq[type_of(piece_on(from))] & to)
|
if (ci.checkSquares[type_of(piece_on(from))] & to)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Is there a discovered check?
|
// Is there a discovered check?
|
||||||
|
|
|
@ -46,7 +46,7 @@ struct CheckInfo {
|
||||||
|
|
||||||
Bitboard dcCandidates;
|
Bitboard dcCandidates;
|
||||||
Bitboard pinned;
|
Bitboard pinned;
|
||||||
Bitboard checkSq[PIECE_TYPE_NB];
|
Bitboard checkSquares[PIECE_TYPE_NB];
|
||||||
Square ksq;
|
Square ksq;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ void init() {
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
int edgeDistance = int(file_of(s) < FILE_E ? file_of(s) : FILE_H - file_of(s));
|
int edgeDistance = file_of(s) < FILE_E ? file_of(s) : FILE_H - file_of(s);
|
||||||
psq[BLACK][pt][~s] = -(psq[WHITE][pt][s] = v + Bonus[pt][rank_of(s)][edgeDistance]);
|
psq[BLACK][pt][~s] = -(psq[WHITE][pt][s] = v + Bonus[pt][rank_of(s)][edgeDistance]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ void Search::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Search::reset() clears all search memory, to restore a deterministic state
|
/// Search::reset() clears all search memory, to obtain reproducible search results
|
||||||
|
|
||||||
void Search::reset () {
|
void Search::reset () {
|
||||||
|
|
||||||
|
@ -858,7 +858,7 @@ moves_loop: // When in check and at SpNode search starts from here
|
||||||
captureOrPromotion = pos.capture_or_promotion(move);
|
captureOrPromotion = pos.capture_or_promotion(move);
|
||||||
|
|
||||||
givesCheck = type_of(move) == NORMAL && !ci.dcCandidates
|
givesCheck = type_of(move) == NORMAL && !ci.dcCandidates
|
||||||
? ci.checkSq[type_of(pos.piece_on(from_sq(move)))] & to_sq(move)
|
? ci.checkSquares[type_of(pos.piece_on(from_sq(move)))] & to_sq(move)
|
||||||
: pos.gives_check(move, ci);
|
: pos.gives_check(move, ci);
|
||||||
|
|
||||||
dangerous = givesCheck
|
dangerous = givesCheck
|
||||||
|
@ -1281,7 +1281,7 @@ moves_loop: // When in check and at SpNode search starts from here
|
||||||
assert(is_ok(move));
|
assert(is_ok(move));
|
||||||
|
|
||||||
givesCheck = type_of(move) == NORMAL && !ci.dcCandidates
|
givesCheck = type_of(move) == NORMAL && !ci.dcCandidates
|
||||||
? ci.checkSq[type_of(pos.piece_on(from_sq(move)))] & to_sq(move)
|
? ci.checkSquares[type_of(pos.piece_on(from_sq(move)))] & to_sq(move)
|
||||||
: pos.gives_check(move, ci);
|
: pos.gives_check(move, ci);
|
||||||
|
|
||||||
// Futility pruning
|
// Futility pruning
|
||||||
|
|
24
src/tt.h
24
src/tt.h
|
@ -43,34 +43,22 @@ struct TTEntry {
|
||||||
|
|
||||||
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
|
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
|
||||||
|
|
||||||
if (key16 != (k >> 48))
|
|
||||||
{
|
|
||||||
key16 = (uint16_t)(k >> 48);
|
|
||||||
move16 = (uint16_t)m;
|
|
||||||
value16 = (int16_t)v;
|
|
||||||
eval16 = (int16_t)ev;
|
|
||||||
genBound8 = (uint8_t)(g | b);
|
|
||||||
depth8 = (int8_t)d;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Preserve any existing move for the same position
|
// Preserve any existing move for the same position
|
||||||
if (m)
|
if (m || (k >> 48) != key16)
|
||||||
move16 = (uint16_t)m;
|
move16 = (uint16_t)m;
|
||||||
|
|
||||||
// Don't overwrite more valuable values
|
// Don't overwrite more valuable entries
|
||||||
if ( d + 2 > depth8
|
if ( (k >> 48) != key16
|
||||||
|
|| d > depth8 - 2
|
||||||
|| g != (genBound8 & 0xFC)
|
|| g != (genBound8 & 0xFC)
|
||||||
|| b == BOUND_EXACT)
|
|| b == BOUND_EXACT)
|
||||||
{
|
{
|
||||||
|
key16 = (uint16_t)(k >> 48);
|
||||||
value16 = (int16_t)v;
|
value16 = (int16_t)v;
|
||||||
|
eval16 = (int16_t)ev;
|
||||||
genBound8 = (uint8_t)(g | b);
|
genBound8 = (uint8_t)(g | b);
|
||||||
depth8 = (int8_t)d;
|
depth8 = (int8_t)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev != VALUE_NONE)
|
|
||||||
eval16 = (int16_t)ev;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue