Skip to content

Commit 1494d50

Browse files
committed
bench
No functional change
1 parent ed96a1c commit 1494d50

7 files changed

Lines changed: 82 additions & 12 deletions

File tree

‎main.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ using namespace engine;
1212
int main() {
1313
std::cout << std::unitbuf;
1414
std::cout << "cppchess_engine version " << BUILD_VERSION << '\n';
15+
options.add("Threads", Option(1, 1, 1));
1516
options.add("Move Overhead", Option(10, 0, 1000));
1617
options.add("Hash", Option(16, 1, 1 << 25, [](const Option &o) {
1718
try {

‎score.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Score {
3939
int value;
4040
};
4141

42-
Score() : score(InternalUnits{ VALUE_ZERO }){};
42+
Score() : score(InternalUnits{ VALUE_ZERO }) {};
4343
Score(Value v);
4444

4545
template <typename T> bool is() const { return std::holds_alternative<T>(score); }

‎search.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ Value doSearch(
372372

373373
// Futility pruning at shallow depths
374374
if (!inCheck && !isCapture && !givesCheck && depth <= 2 && ply > 0 && movesSearched > 0) {
375-
Value margin = Value(200 + 128 * depth);
375+
Value margin = Value(128 + 128 * depth);
376376
if (staticEval + margin <= alpha && std::abs(alpha) < VALUE_TB_WIN_IN_MAX_PLY)
377377
continue;
378378
}
@@ -385,7 +385,7 @@ Value doSearch(
385385
// SEE pruning for losing captures at shallow depths
386386
if (!inCheck && isCapture && !givesCheck && depth <= 2 && movesSearched > 0 && move.type_of() != PROMOTION &&
387387
std::abs(alpha) < VALUE_TB_WIN_IN_MAX_PLY) {
388-
if (movepick::see(board, move) < -20)
388+
if (movepick::see(board, move) < 0)
389389
continue;
390390
}
391391

@@ -408,7 +408,7 @@ Value doSearch(
408408
else if (staticEval - 50 >= alphaOrig)
409409
reduction--;
410410
} else if (movesSearched >= 6) {
411-
reduction = 1 + movesSearched / 6;
411+
reduction = 1 + movesSearched / 8;
412412
}
413413
if (reduction > 0)
414414
reduction = std::clamp(reduction, 1, depth - 2);
@@ -526,7 +526,7 @@ std::string extract_pv(const chess::Position &root, int maxPly) {
526526
return pv;
527527
}
528528

529-
void search(const chess::Position &board, const timeman::LimitsType timecontrol) {
529+
uint64_t search(const chess::Position &board, const timeman::LimitsType timecontrol) {
530530
stopSearch = false;
531531
tt.newSearch();
532532
static double originalTimeAdjust = -1;
@@ -653,5 +653,6 @@ void search(const chess::Position &board, const timeman::LimitsType timecontrol)
653653
if (entry && entry->getMove() != Move::none().raw())
654654
report(chess::uci::moveToUci(Move(entry->getMove()), board.chess960()));
655655
}
656+
return session.nodes;
656657
}
657658
} // namespace engine::search

‎search.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "eval.h"
33
#include "timeman.h"
44
#include "tt.h"
5+
#include <cstdint>
56
#include <position.h>
67
namespace engine::search {
78
struct Session {
@@ -18,7 +19,7 @@ struct Session {
1819
chess::Color ogcolor;
1920
};
2021
void stop();
21-
void search(const chess::Position &, const timeman::LimitsType);
22+
uint64_t search(const chess::Position &, const timeman::LimitsType);
2223
bool isStopped();
2324
extern engine::TranspositionTable tt;
2425
} // namespace engine::search

‎timeman.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ void TimeManagement::init(LimitsType &limits, chess::Color us, int ply, double &
2222

2323
// If we have no time, we don't need to fully initialize TM.
2424
// startTime is used by movetime and useNodesTime is used in elapsed calls.
25-
startTime = limits.startTime;
25+
startTime = now();
2626
if (limits.movetime != 0) {
2727
optimumTime = maximumTime = TimePoint(limits.movetime);
2828
return;
2929
}
30-
if (limits.time[us] == 0 && limits.movetime == 0) {
30+
if (!limits.use_time_management()) {
3131
optimumTime = maximumTime = INFINITE_TIME;
3232
return;
3333
}

‎timeman.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct LimitsType {
1515

1616
// Init explicitly due to broken value-initialization of non POD in MSVC
1717
LimitsType() {
18-
time[chess::WHITE] = time[chess::BLACK] = inc[chess::WHITE] = inc[chess::BLACK] = movetime = startTime = TimePoint(0);
18+
time[chess::WHITE] = time[chess::BLACK] = inc[chess::WHITE] = inc[chess::BLACK] = movetime = TimePoint(0);
1919
movestogo = mate = perft = infinite = 0;
2020
depth = 64;
2121
nodes = 0;
@@ -25,7 +25,7 @@ struct LimitsType {
2525
bool use_time_management() const { return time[chess::WHITE] || time[chess::BLACK]; }
2626

2727
std::vector<std::string> searchmoves;
28-
TimePoint time[chess::COLOR_NB], inc[chess::COLOR_NB], movetime, startTime;
28+
TimePoint time[chess::COLOR_NB], inc[chess::COLOR_NB], movetime;
2929
int movestogo, depth, mate, perft, infinite;
3030
uint64_t nodes;
3131
bool ponderMode;

‎uci.cpp‎

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ timeman::LimitsType parse_limits(std::istream &is) {
8383
timeman::LimitsType limits;
8484
std::string token;
8585

86-
limits.startTime = timeman::now(); // The search starts as early as possible
87-
8886
while (is >> token)
8987
if (token == "searchmoves") // Needs to be the last command on the line
9088
while (is >> token) {
@@ -240,6 +238,75 @@ void execCmd(const std::string &line) {
240238
score = -score;
241239
std::cout << score << std::endl;
242240
break;
241+
} else if (token == "bench") {
242+
uint64_t nodes = 0;
243+
const std::vector<std::string> Defaults = {
244+
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
245+
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
246+
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
247+
"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
248+
"rq3r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q3/5Kp1/P6b/8 w - - 0 1",
265+
"8/2p5/8/2kPKp1p/2p4P/2P5/3P4/8 w - - 0 1",
266+
"8/1p3pp1/7p/5P1P/2k3P1/8/2K2P2/8 w - - 0 1",
267+
"8/pp2r1k1/2p1p3/3pP2p/1P1P1P1P/P5KR/8/8 w - - 0 1",
268+
"8/3p4/p1bk3p/Pp6/1Kp1PpPp/2P2P1P/2P5/5B2 b - - 0 1",
269+
"5k2/7R/4P2p/5K2/p1r2P1p/8/8/8 b - - 0 1",
270+
"6k1/6p1/P6p/r1N5/5p2/7P/1b3PP1/4R1K1 w - - 0 1",
271+
"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w - - 0 1",
272+
"6k1/4pp1p/3p2p1/P1pPb3/R7/1r2P1PP/3B1P2/6K1 w - - 0 1",
273+
"8/3p3B/5p2/5P2/p7/PP5b/k7/6K1 w - - 0 1",
274+
"5rk1/q6p/2p3bR/1pPp1rP1/1P1Pp3/P3B1Q1/1K3P2/R7 w - - 93 90",
275+
"4rrk1/1p1nq3/p7/2p1P1pp/3P2bp/3Q1Bn1/PPPB4/1K2R1NR w - - 40 21",
276+
"r3k2r/3nnpbp/q2pp1p1/p7/Pp1PPPP1/4BNN1/1P5P/R2Q1RK1 w kq - 0 16",
277+
"3Qb1k1/1r2ppb1/pN1n2q1/Pp1Pp1Pr/4P2p/4BP2/4B1R1/1R5K b - - 11 40",
278+
"4k3/3q1r2/1N2r1b1/3ppN2/2nPP3/1B1R2n1/2R1Q3/3K4 w - - 5 1",
279+
"1r6/1P4bk/3qr1p1/N6p/3pp2P/6R1/3Q1PP1/1R4K1 w - - 1 42",
280+
281+
// 5-man positions
282+
"8/8/8/8/5kp1/P7/8/1K1N4 w - - 0 1", // Kc2 - mate
283+
"8/8/8/5N2/8/p7/8/2NK3k w - - 0 1", // Na2 - mate
284+
"8/3k4/8/8/8/4B3/4KB2/2B5 w - - 0 1", // draw
285+
286+
// 6-man positions
287+
"8/8/1P6/5pr1/8/4R3/7k/2K5 w - - 0 1", // Re5 - mate
288+
"8/2p4P/8/kr6/6R1/8/8/1K6 w - - 0 1", // Ka2 - mate
289+
"8/8/3P3k/8/1p6/8/1P6/1K3n2 b - - 0 1", // Nd2 - draw
290+
291+
// 7-man positions
292+
"8/R7/2q5/8/6k1/8/1P5p/K6R w - - 0 124", // Draw
293+
294+
// Mate and stalemate positions
295+
"6k1/3b3r/1p1p4/p1n2p2/1PPNpP1q/P3Q1p1/1R1RB1P1/5K2 b - - 0 1",
296+
"r2r1n2/pp2bk2/2p1p2p/3q4/3PN1QP/2P3R1/P4PP1/5RK1 w - - 0 1",
297+
"8/8/8/8/8/6k1/6p1/6K1 w - -",
298+
"7k/7P/6K1/8/3B4/8/8/8 b - -",
299+
};
300+
timeman::LimitsType tc{};tc.depth=10;
301+
auto start = std::chrono::high_resolution_clock::now();
302+
for (auto& fen: Defaults){
303+
std::cerr<<fen<<'\n';
304+
chess::Position pos(fen);
305+
nodes+=search::search(pos, tc);
306+
}
307+
auto end = std::chrono::high_resolution_clock::now();
308+
auto duration_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
309+
std::cout << "nodes " << nodes << " nps " << nodes / (duration_ms / 1000.0) << std::endl;
243310
} else if (token == "export_weights") {
244311
std::string weights_header = "Weights.h";
245312
ss >> weights_header;

0 commit comments

Comments
 (0)