1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 09:39: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:
Marco Costalba 2015-05-09 11:09:06 +02:00
parent eaeb63f1d0
commit ee0371f86e
8 changed files with 52 additions and 69 deletions

View file

@ -201,17 +201,15 @@ void Bitboards::init() {
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
{
Piece pc = (PseudoAttacks[BISHOP][s1] & s2) ? W_BISHOP :
(PseudoAttacks[ROOK][s1] & s2) ? W_ROOK : NO_PIECE;
for (Piece pc = W_BISHOP; pc <= W_ROOK; ++pc)
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
{
if (!(PseudoAttacks[pc][s1] & s2))
continue;
if (pc == NO_PIECE)
continue;
LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
BetweenBB[s1][s2] = attacks_bb(pc, s1, SquareBB[s2]) & attacks_bb(pc, s2, SquareBB[s1]);
}
LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
BetweenBB[s1][s2] = attacks_bb(pc, s1, SquareBB[s2]) & attacks_bb(pc, s2, SquareBB[s1]);
}
}
}

View file

@ -33,41 +33,37 @@ namespace {
/// DD-MM-YY and show in engine_info.
const string Version = "";
/// Debug counters
int64_t hits[2], means[2];
/// 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
/// 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
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 underflow() { return buf->sgetc(); }
int uflow() { return log(buf->sbumpc(), ">> "); }
streambuf* buf;
ofstream* file;
streambuf *buf, *logBuf;
int log(int c, const char* prefix) {
static int last = '\n';
static int last = '\n'; // Single log file
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 {
Logger() : in(cin.rdbuf(), &file), out(cout.rdbuf(), &file) {}
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
~Logger() { start(false); }
ofstream file;
@ -80,7 +76,7 @@ public:
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);
cout.rdbuf(&l.out);
}
@ -124,6 +120,7 @@ const string engine_info(bool to_uci) {
/// 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 c, bool b) { if (c) dbg_hit_on(b); }

View file

@ -232,7 +232,7 @@ namespace {
if (Checks)
{
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
&& !(PseudoAttacks[Pt][from] & target & ci->checkSq[Pt]))
&& !(PseudoAttacks[Pt][from] & target & ci->checkSquares[Pt]))
continue;
if (ci->dcCandidates && (ci->dcCandidates & from))
@ -242,7 +242,7 @@ namespace {
Bitboard b = pos.attacks_from<Pt>(from) & target;
if (Checks)
b &= ci->checkSq[Pt];
b &= ci->checkSquares[Pt];
while (b)
*moveList++ = make_move(from, pop_lsb(&b));

View file

@ -94,12 +94,12 @@ CheckInfo::CheckInfo(const Position& pos) {
pinned = pos.pinned_pieces(pos.side_to_move());
dcCandidates = pos.discovered_check_candidates();
checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them);
checkSq[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
checkSq[KING] = 0;
checkSquares[PAWN] = pos.attacks_from<PAWN>(ksq, them);
checkSquares[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
checkSquares[BISHOP] = pos.attacks_from<BISHOP>(ksq);
checkSquares[ROOK] = pos.attacks_from<ROOK>(ksq);
checkSquares[QUEEN] = checkSquares[BISHOP] | checkSquares[ROOK];
checkSquares[KING] = 0;
}
@ -616,7 +616,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
Square to = to_sq(m);
// 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;
// Is there a discovered check?

View file

@ -46,7 +46,7 @@ struct CheckInfo {
Bitboard dcCandidates;
Bitboard pinned;
Bitboard checkSq[PIECE_TYPE_NB];
Bitboard checkSquares[PIECE_TYPE_NB];
Square ksq;
};

View file

@ -109,7 +109,7 @@ void init() {
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]);
}
}

View file

@ -181,15 +181,15 @@ 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 () {
TT.clear();
History.clear();
CounterMovesHistory.clear();
Gains.clear();
Countermoves.clear();
TT.clear();
History.clear();
CounterMovesHistory.clear();
Gains.clear();
Countermoves.clear();
}
@ -858,7 +858,7 @@ moves_loop: // When in check and at SpNode search starts from here
captureOrPromotion = pos.capture_or_promotion(move);
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);
dangerous = givesCheck
@ -1281,7 +1281,7 @@ moves_loop: // When in check and at SpNode search starts from here
assert(is_ok(move));
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);
// Futility pruning

View file

@ -43,34 +43,22 @@ struct TTEntry {
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
if (m)
move16 = (uint16_t)m;
// Preserve any existing move for the same position
if (m || (k >> 48) != key16)
move16 = (uint16_t)m;
// Don't overwrite more valuable values
if ( d + 2 > depth8
|| g != (genBound8 & 0xFC)
|| b == BOUND_EXACT)
{
value16 = (int16_t)v;
genBound8 = (uint8_t)(g | b);
depth8 = (int8_t)d;
}
if (ev != VALUE_NONE)
eval16 = (int16_t)ev;
}
// Don't overwrite more valuable entries
if ( (k >> 48) != key16
|| d > depth8 - 2
|| g != (genBound8 & 0xFC)
|| b == BOUND_EXACT)
{
key16 = (uint16_t)(k >> 48);
value16 = (int16_t)v;
eval16 = (int16_t)ev;
genBound8 = (uint8_t)(g | b);
depth8 = (int8_t)d;
}
}
private: