Skip to content

Commit dac072c

Browse files
authored
Merge pull request official-stockfish#1657 from IIvec/master
New master
2 parents 48f174c + fcbb02f commit dac072c

File tree

6 files changed

+86
-47
lines changed

6 files changed

+86
-47
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Hisayori Noda (nodchip)
1212
# All other authors of Stockfish code (in alphabetical order)
1313
Aditya (absimaldata)
1414
Adrian Petrescu (apetresc)
15+
Ahmed Kerimov (wcdbmv)
1516
Ajith Chandy Jose (ajithcj)
1617
Alain Savard (Rocky640)
1718
Alayan Feh (Alayan-stk-2)

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ HEADERS = benchmark.h bitboard.h evaluate.h misc.h movegen.h movepick.h \
6363
nnue/layers/sqr_clipped_relu.h nnue/nnue_accumulator.h nnue/nnue_architecture.h \
6464
nnue/nnue_common.h nnue/nnue_feature_transformer.h position.h \
6565
search.h syzygy/tbprobe.h thread.h thread_win32_osx.h timeman.h \
66-
tt.h tune.h types.h uci.h ucioption.h
66+
tt.h tune.h types.h uci.h ucioption.h perft.h
6767

6868
OBJS = $(notdir $(SRCS:.cpp=.o))
6969

src/perft.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3+
Copyright (C) 2004-2024 The Stockfish developers (see AUTHORS file)
4+
5+
Stockfish is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
Stockfish is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef PERFT_H_INCLUDED
20+
#define PERFT_H_INCLUDED
21+
22+
#include <cstdint>
23+
24+
#include "movegen.h"
25+
#include "position.h"
26+
#include "types.h"
27+
#include "uci.h"
28+
29+
namespace Stockfish {
30+
31+
// Utility to verify move generation. All the leaf nodes up
32+
// to the given depth are generated and counted, and the sum is returned.
33+
template<bool Root>
34+
uint64_t perft(Position& pos, Depth depth) {
35+
36+
StateInfo st;
37+
ASSERT_ALIGNED(&st, Eval::NNUE::CacheLineSize);
38+
39+
uint64_t cnt, nodes = 0;
40+
const bool leaf = (depth == 2);
41+
42+
for (const auto& m : MoveList<LEGAL>(pos))
43+
{
44+
if (Root && depth <= 1)
45+
cnt = 1, nodes++;
46+
else
47+
{
48+
pos.do_move(m, st);
49+
cnt = leaf ? MoveList<LEGAL>(pos).size() : perft<false>(pos, depth - 1);
50+
nodes += cnt;
51+
pos.undo_move(m);
52+
}
53+
if (Root)
54+
sync_cout << UCI::move(m, pos.is_chess960()) << ": " << cnt << sync_endl;
55+
}
56+
return nodes;
57+
}
58+
59+
inline void perft(const std::string& fen, Depth depth, bool isChess960) {
60+
StateListPtr states(new std::deque<StateInfo>(1));
61+
Position p;
62+
p.set(fen, isChess960, &states->back());
63+
64+
uint64_t nodes = perft<true>(p, depth);
65+
sync_cout << "\nNodes searched: " << nodes << "\n" << sync_endl;
66+
}
67+
}
68+
69+
#endif // PERFT_H_INCLUDED

src/search.cpp

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -122,37 +122,8 @@ void update_all_stats(const Position& pos,
122122
int captureCount,
123123
Depth depth);
124124

125-
// Utility to verify move generation. All the leaf nodes up
126-
// to the given depth are generated and counted, and the sum is returned.
127-
template<bool Root>
128-
uint64_t perft(Position& pos, Depth depth) {
129-
130-
StateInfo st;
131-
ASSERT_ALIGNED(&st, Eval::NNUE::CacheLineSize);
132-
133-
uint64_t cnt, nodes = 0;
134-
const bool leaf = (depth == 2);
135-
136-
for (const auto& m : MoveList<LEGAL>(pos))
137-
{
138-
if (Root && depth <= 1)
139-
cnt = 1, nodes++;
140-
else
141-
{
142-
pos.do_move(m, st);
143-
cnt = leaf ? MoveList<LEGAL>(pos).size() : perft<false>(pos, depth - 1);
144-
nodes += cnt;
145-
pos.undo_move(m);
146-
}
147-
if (Root)
148-
sync_cout << UCI::move(m, pos.is_chess960()) << ": " << cnt << sync_endl;
149-
}
150-
return nodes;
151-
}
152-
153125
} // namespace
154126

155-
156127
Search::Worker::Worker(SharedState& sharedState,
157128
std::unique_ptr<ISearchManager> sm,
158129
size_t thread_id) :
@@ -173,13 +144,6 @@ void Search::Worker::start_searching() {
173144
return;
174145
}
175146

176-
if (limits.perft)
177-
{
178-
nodes = perft<true>(rootPos, limits.perft);
179-
sync_cout << "\nNodes searched: " << nodes << "\n" << sync_endl;
180-
return;
181-
}
182-
183147
main_manager()->tm.init(limits, rootPos.side_to_move(), rootPos.game_ply(), options);
184148
tt.new_search();
185149

@@ -1035,10 +999,9 @@ Value Search::Worker::search(
1035999
if (lmrDepth < 6 && history < -4195 * depth)
10361000
continue;
10371001

1038-
history += 69 * thisThread->mainHistory[us][move.from_to()] / 32;
1002+
history += 2 * thisThread->mainHistory[us][move.from_to()];
10391003

10401004
lmrDepth += history / 6992;
1041-
lmrDepth = std::max(lmrDepth, -1);
10421005

10431006
// Futility pruning: parent node (~13 Elo)
10441007
if (!ss->inCheck && lmrDepth < 15
@@ -1070,7 +1033,7 @@ Value Search::Worker::search(
10701033
// so changing them requires tests at these types of time controls.
10711034
// Recursive singular search is avoided.
10721035
if (!rootNode && move == ttMove && !excludedMove
1073-
&& depth >= 4 - (thisThread->completedDepth > 31) + 2 * (PvNode && tte->is_pv())
1036+
&& depth >= 4 - (thisThread->completedDepth > 31) + ss->ttPv
10741037
&& std::abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && (tte->bound() & BOUND_LOWER)
10751038
&& tte->depth() >= depth - 3)
10761039
{
@@ -1088,7 +1051,7 @@ Value Search::Worker::search(
10881051
singularQuietLMR = !ttCapture;
10891052

10901053
// Avoid search explosion by limiting the number of double extensions
1091-
if (!PvNode && value < singularBeta - 16 && ss->doubleExtensions <= 12)
1054+
if (!PvNode && value < singularBeta - 2 && ss->doubleExtensions <= 12)
10921055
{
10931056
extension = 2;
10941057
depth += depth < 15;

src/uci.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "syzygy/tbprobe.h"
4040
#include "types.h"
4141
#include "ucioption.h"
42+
#include "perft.h"
4243

4344
namespace Stockfish {
4445

@@ -172,7 +173,6 @@ void UCI::loop() {
172173

173174
void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) {
174175

175-
176176
Search::LimitsType limits;
177177
std::string token;
178178
bool ponderMode = false;
@@ -211,6 +211,12 @@ void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) {
211211

212212
Eval::NNUE::verify(options, evalFiles);
213213

214+
if (limits.perft)
215+
{
216+
perft(pos.fen(), limits.perft, options["UCI_Chess960"]);
217+
return;
218+
}
219+
214220
threads.start_thinking(options, pos, states, limits, ponderMode);
215221
}
216222

src/ucioption.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,37 +68,37 @@ Option::Option(const char* v, OnChange f) :
6868
type("string"),
6969
min(0),
7070
max(0),
71-
on_change(f) {
71+
on_change(std::move(f)) {
7272
defaultValue = currentValue = v;
7373
}
7474

7575
Option::Option(bool v, OnChange f) :
7676
type("check"),
7777
min(0),
7878
max(0),
79-
on_change(f) {
79+
on_change(std::move(f)) {
8080
defaultValue = currentValue = (v ? "true" : "false");
8181
}
8282

8383
Option::Option(OnChange f) :
8484
type("button"),
8585
min(0),
8686
max(0),
87-
on_change(f) {}
87+
on_change(std::move(f)) {}
8888

8989
Option::Option(double v, int minv, int maxv, OnChange f) :
9090
type("spin"),
9191
min(minv),
9292
max(maxv),
93-
on_change(f) {
93+
on_change(std::move(f)) {
9494
defaultValue = currentValue = std::to_string(v);
9595
}
9696

9797
Option::Option(const char* v, const char* cur, OnChange f) :
9898
type("combo"),
9999
min(0),
100100
max(0),
101-
on_change(f) {
101+
on_change(std::move(f)) {
102102
defaultValue = v;
103103
currentValue = cur;
104104
}

0 commit comments

Comments
 (0)