1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-13 04:29:15 +00:00
FauziAkram 2023-11-20 19:09:48 +01:00 committed by Disservin
parent b59786e750
commit b4e9ee72e3
6 changed files with 38 additions and 44 deletions

View file

@ -393,8 +393,8 @@ void dbg_print() {
} }
// Used to serialize access to std::cout to avoid multiple threads writing at // Used to serialize access to std::cout
// the same time. // to avoid multiple threads writing at the same time.
std::ostream& operator<<(std::ostream& os, SyncCout sc) { std::ostream& operator<<(std::ostream& os, SyncCout sc) {
static std::mutex m; static std::mutex m;
@ -558,7 +558,7 @@ void* aligned_large_pages_alloc(size_t allocSize) {
constexpr size_t alignment = 4096; // assumed small page size constexpr size_t alignment = 4096; // assumed small page size
#endif #endif
// round up to multiples of alignment // Round up to multiples of alignment
size_t size = ((allocSize + alignment - 1) / alignment) * alignment; size_t size = ((allocSize + alignment - 1) / alignment) * alignment;
void* mem = std_aligned_alloc(alignment, size); void* mem = std_aligned_alloc(alignment, size);
#if defined(MADV_HUGEPAGE) #if defined(MADV_HUGEPAGE)
@ -600,7 +600,7 @@ void bindThisThread(size_t) {}
#else #else
// Retrieves logical processor information using Windows specific // Retrieves logical processor information using Windows-specific
// API and returns the best node id for the thread with index idx. Original // API and returns the best node id for the thread with index idx. Original
// code from Texel by Peter Österlund. // code from Texel by Peter Österlund.
static int best_node(size_t idx) { static int best_node(size_t idx) {
@ -660,8 +660,7 @@ static int best_node(size_t idx) {
groups.push_back(n); groups.push_back(n);
// In case a core has more than one logical processor (we assume 2) and we // In case a core has more than one logical processor (we assume 2) and we
// have still threads to allocate, then spread them evenly across available // still have threads to allocate, spread them evenly across available nodes.
// nodes.
for (int t = 0; t < threads - cores; t++) for (int t = 0; t < threads - cores; t++)
groups.push_back(t % nodes); groups.push_back(t % nodes);
@ -731,7 +730,7 @@ std::string workingDirectory; // path of the working directory
void init([[maybe_unused]] int argc, char* argv[]) { void init([[maybe_unused]] int argc, char* argv[]) {
std::string pathSeparator; std::string pathSeparator;
// extract the path+name of the executable binary // Extract the path+name of the executable binary
argv0 = argv[0]; argv0 = argv[0];
#ifdef _WIN32 #ifdef _WIN32
@ -747,14 +746,14 @@ void init([[maybe_unused]] int argc, char* argv[]) {
pathSeparator = "/"; pathSeparator = "/";
#endif #endif
// extract the working directory // Extract the working directory
workingDirectory = ""; workingDirectory = "";
char buff[40000]; char buff[40000];
char* cwd = GETCWD(buff, 40000); char* cwd = GETCWD(buff, 40000);
if (cwd) if (cwd)
workingDirectory = cwd; workingDirectory = cwd;
// extract the binary directory path from argv0 // Extract the binary directory path from argv0
binaryDirectory = argv0; binaryDirectory = argv0;
size_t pos = binaryDirectory.find_last_of("\\/"); size_t pos = binaryDirectory.find_last_of("\\/");
if (pos == std::string::npos) if (pos == std::string::npos)
@ -762,7 +761,7 @@ void init([[maybe_unused]] int argc, char* argv[]) {
else else
binaryDirectory.resize(pos + 1); binaryDirectory.resize(pos + 1);
// pattern replacement: "./" at the start of path is replaced by the working directory // Pattern replacement: "./" at the start of path is replaced by the working directory
if (binaryDirectory.find("." + pathSeparator) == 0) if (binaryDirectory.find("." + pathSeparator) == 0)
binaryDirectory.replace(0, 1, workingDirectory); binaryDirectory.replace(0, 1, workingDirectory);
} }

View file

@ -96,11 +96,10 @@ enum StatsType {
Captures Captures
}; };
// ButterflyHistory records how often quiet moves have been successful or // ButterflyHistory records how often quiet moves have been successful or unsuccessful
// unsuccessful during the current search, and is used for reduction and move // during the current search, and is used for reduction and move ordering decisions.
// ordering decisions. It uses 2 tables (one for each color) indexed by // It uses 2 tables (one for each color) indexed by the move's from and to squares,
// the move's from and to squares, see www.chessprogramming.org/Butterfly_Boards // see www.chessprogramming.org/Butterfly_Boards (~11 elo)
// (~11 elo)
using ButterflyHistory = Stats<int16_t, 7183, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)>; using ButterflyHistory = Stats<int16_t, 7183, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)>;
// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous // CounterMoveHistory stores counter moves indexed by [piece][to] of the previous

View file

@ -371,9 +371,8 @@ void Position::set_state() const {
} }
// Overload to initialize the position object with // Overload to initialize the position object with the given endgame code string
// the given endgame code string like "KBPKN". It is mainly a helper to // like "KBPKN". It's mainly a helper to get the material key out of an endgame code.
// get the material key out of an endgame code.
Position& Position::set(const string& code, Color c, StateInfo* si) { Position& Position::set(const string& code, Color c, StateInfo* si) {
assert(code[0] == 'K'); assert(code[0] == 'K');
@ -472,8 +471,8 @@ void Position::update_slider_blockers(Color c) const {
} }
// Computes a bitboard of all pieces which attack a // Computes a bitboard of all pieces which attack a given square.
// given square. Slider attacks use the occupied bitboard to indicate occupancy. // Slider attacks use the occupied bitboard to indicate occupancy.
Bitboard Position::attackers_to(Square s, Bitboard occupied) const { Bitboard Position::attackers_to(Square s, Bitboard occupied) const {
return (pawn_attacks_bb(BLACK, s) & pieces(WHITE, PAWN)) return (pawn_attacks_bb(BLACK, s) & pieces(WHITE, PAWN))
@ -575,8 +574,7 @@ bool Position::pseudo_legal(const Move m) const {
// Handle the special case of a pawn move // Handle the special case of a pawn move
if (type_of(pc) == PAWN) if (type_of(pc) == PAWN)
{ {
// We have already handled promotion moves, so destination // We have already handled promotion moves, so destination cannot be on the 8th/1st rank
// cannot be on the 8th/1st rank.
if ((Rank8BB | Rank1BB) & to) if ((Rank8BB | Rank1BB) & to)
return false; return false;
@ -639,10 +637,9 @@ bool Position::gives_check(Move m) const {
case PROMOTION : case PROMOTION :
return attacks_bb(promotion_type(m), to, pieces() ^ from) & square<KING>(~sideToMove); return attacks_bb(promotion_type(m), to, pieces() ^ from) & square<KING>(~sideToMove);
// En passant capture with check? We have already handled the case // En passant capture with check? We have already handled the case of direct
// of direct checks and ordinary discovered check, so the only case we // checks and ordinary discovered check, so the only case we need to handle
// need to handle is the unusual case of a discovered check through // is the unusual case of a discovered check through the captured pawn.
// the captured pawn.
case EN_PASSANT : { case EN_PASSANT : {
Square capsq = make_square(file_of(to), rank_of(from)); Square capsq = make_square(file_of(to), rank_of(from));
Bitboard b = (pieces() ^ from ^ capsq) | to; Bitboard b = (pieces() ^ from ^ capsq) | to;
@ -928,8 +925,8 @@ void Position::undo_move(Move m) {
} }
// Helper used to do/undo a castling move. This // Helper used to do/undo a castling move. This is a bit
// is a bit tricky in Chess960 where from/to squares can overlap. // tricky in Chess960 where from/to squares can overlap.
template<bool Do> template<bool Do>
void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto) { void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto) {
@ -1244,8 +1241,8 @@ void Position::flip() {
} }
// Performs some consistency checks for the // Performs some consistency checks for the position object
// position object and raise an assert if something wrong is detected. // and raise an assert if something wrong is detected.
// This is meant to be helpful when debugging. // This is meant to be helpful when debugging.
bool Position::pos_is_ok() const { bool Position::pos_is_ok() const {

View file

@ -834,8 +834,7 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo
if (depth <= 0) if (depth <= 0)
return qsearch<PV>(pos, ss, alpha, beta); return qsearch<PV>(pos, ss, alpha, beta);
// For cutNodes without a ttMove, we decrease depth by 2 // For cutNodes without a ttMove, we decrease depth by 2 if depth is high enough.
// if current depth >= 8.
if (cutNode && depth >= 8 && !ttMove) if (cutNode && depth >= 8 && !ttMove)
depth -= 2; depth -= 2;
@ -1037,7 +1036,7 @@ moves_loop: // When in check, search starts here
// Note: the depth margin and singularBeta margin are known for having non-linear // Note: the depth margin and singularBeta margin are known for having non-linear
// scaling. Their values are optimized to time controls of 180+1.8 and longer // scaling. Their values are optimized to time controls of 180+1.8 and longer
// so changing them requires tests at this type of time controls. // so changing them requires tests at these types of time controls.
// Recursive singular search is avoided. // Recursive singular search is avoided.
if (!rootNode && move == ttMove && !excludedMove if (!rootNode && move == ttMove && !excludedMove
&& depth >= 4 - (thisThread->completedDepth > 24) + 2 * (PvNode && tte->is_pv()) && depth >= 4 - (thisThread->completedDepth > 24) + 2 * (PvNode && tte->is_pv())
@ -1079,7 +1078,7 @@ moves_loop: // When in check, search starts here
// we do not know if the ttMove is singular or can do a multi-cut, // we do not know if the ttMove is singular or can do a multi-cut,
// so we reduce the ttMove in favor of other moves based on some conditions: // so we reduce the ttMove in favor of other moves based on some conditions:
// If the ttMove is assumed to fail high over currnet beta (~7 Elo) // If the ttMove is assumed to fail high over current beta (~7 Elo)
else if (ttValue >= beta) else if (ttValue >= beta)
extension = -2 - !PvNode; extension = -2 - !PvNode;
@ -1155,7 +1154,7 @@ moves_loop: // When in check, search starts here
if ((ss + 1)->cutoffCnt > 3) if ((ss + 1)->cutoffCnt > 3)
r++; r++;
// Set reduction to 0 for first generated move (ttMove) // Set reduction to 0 for first picked move (ttMove) (~2 Elo)
// Nullifies all previous reduction adjustments to ttMove and leaves only history to do them // Nullifies all previous reduction adjustments to ttMove and leaves only history to do them
else if (move == ttMove) else if (move == ttMove)
r = 0; r = 0;
@ -1189,8 +1188,9 @@ moves_loop: // When in check, search starts here
{ {
// Adjust full-depth search based on LMR results - if the result // Adjust full-depth search based on LMR results - if the result
// was good enough search deeper, if it was bad enough search shallower. // was good enough search deeper, if it was bad enough search shallower.
const bool doDeeperSearch = value > (bestValue + 51 + 10 * (newDepth - d)); const bool doDeeperSearch =
const bool doShallowerSearch = value < bestValue + newDepth; value > (bestValue + 51 + 10 * (newDepth - d)); // (~1 Elo)
const bool doShallowerSearch = value < bestValue + newDepth; // (~2 Elo)
newDepth += doDeeperSearch - doShallowerSearch; newDepth += doDeeperSearch - doShallowerSearch;
@ -1459,7 +1459,7 @@ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
bestValue = ttValue; bestValue = ttValue;
} }
else else
// In case of null move search use previous static eval with a different sign // In case of null move search, use previous static eval with a different sign
ss->staticEval = bestValue = ss->staticEval = bestValue =
(ss - 1)->currentMove != MOVE_NULL ? evaluate(pos) : -(ss - 1)->staticEval; (ss - 1)->currentMove != MOVE_NULL ? evaluate(pos) : -(ss - 1)->staticEval;

View file

@ -82,8 +82,8 @@ void position(Position& pos, std::istringstream& is, StateListPtr& states) {
} }
} }
// Prints the evaluation of the current position, consistent with // Prints the evaluation of the current position,
// the UCI options set so far. // consistent with the UCI options set so far.
void trace_eval(Position& pos) { void trace_eval(Position& pos) {
StateListPtr states(new std::deque<StateInfo>(1)); StateListPtr states(new std::deque<StateInfo>(1));
@ -122,9 +122,8 @@ void setoption(std::istringstream& is) {
} }
// Called when the engine receives the "go" UCI command. The function // Called when the engine receives the "go" UCI command. The function sets the
// sets the thinking time and other parameters from the input string, then starts // thinking time and other parameters from the input string then stars with a search
// with a search.
void go(Position& pos, std::istringstream& is, StateListPtr& states) { void go(Position& pos, std::istringstream& is, StateListPtr& states) {

View file

@ -36,7 +36,7 @@ namespace UCI {
// to the UCI centipawn result used in output. This value is derived from // to the UCI centipawn result used in output. This value is derived from
// the win_rate_model() such that Stockfish outputs an advantage of // the win_rate_model() such that Stockfish outputs an advantage of
// "100 centipawns" for a position if the engine has a 50% probability to win // "100 centipawns" for a position if the engine has a 50% probability to win
// from this position in selfplay at fishtest LTC time control. // from this position in self-play at fishtest LTC time control.
const int NormalizeToPawnValue = 328; const int NormalizeToPawnValue = 328;
class Option; class Option;