Skip to content

Commit 3960f2d

Browse files
authored
Merge pull request official-stockfish#980 from IIvec/master
nm
2 parents a4962d7 + 2f03428 commit 3960f2d

File tree

14 files changed

+305
-241
lines changed

14 files changed

+305
-241
lines changed

AUTHORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ Joona Kiiski (zamar)
66
Gary Linscott (glinscott)
77

88
Aditya (absimaldata)
9+
Adrian Petrescu (apetresc)
910
Ajith Chandy Jose (ajithcj)
1011
Alain Savard (Rocky640)
12+
alayan-stk-2
1113
Alexander Kure
1214
Ali AlZhrani (Cooffe)
1315
Andrew Grant (AndyGrant)
@@ -31,6 +33,7 @@ David Zar
3133
Daylen Yang (daylen)
3234
DiscanX
3335
Eelco de Groot
36+
Elvin Liu (solarlight2)
3437
erbsenzaehler
3538
Ernesto Gatti
3639
Fabian Beuke (madnight)

Readme.md

Lines changed: 114 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,112 @@
1-
### Overview
1+
## Overview
22

33
[![Build Status](https://travis-ci.org/official-stockfish/Stockfish.svg?branch=master)](https://travis-ci.org/official-stockfish/Stockfish)
44
[![Build Status](https://ci.appveyor.com/api/projects/status/github/official-stockfish/Stockfish?svg=true)](https://ci.appveyor.com/project/mcostalba/stockfish)
55

6-
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
7-
not a complete chess program and requires some UCI-compatible GUI
8-
(e.g. XBoard with PolyGlot, eboard, Arena, Sigma Chess, Shredder, Chess
9-
Partner or Fritz) in order to be used comfortably. Read the
10-
documentation for your GUI of choice for information about how to use
6+
[Stockfish](https://stockfishchess.org) is a free, powerful UCI chess engine
7+
derived from Glaurung 2.1. It is not a complete chess program and requires a
8+
UCI-compatible GUI (e.g. XBoard with PolyGlot, Scid, Cute Chess, eboard, Arena,
9+
Sigma Chess, Shredder, Chess Partner or Fritz) in order to be used comfortably.
10+
Read the documentation for your GUI of choice for information about how to use
1111
Stockfish with it.
1212

13-
This version of Stockfish supports up to 512 cores. The engine defaults
14-
to one search thread, so it is therefore recommended to inspect the value of
15-
the *Threads* UCI parameter, and to make sure it equals the number of CPU
16-
cores on your computer.
1713

18-
This version of Stockfish has support for Syzygybases.
19-
20-
21-
### Files
14+
## Files
2215

2316
This distribution of Stockfish consists of the following files:
2417

2518
* Readme.md, the file you are currently reading.
2619

27-
* Copying.txt, a text file containing the GNU General Public License.
20+
* Copying.txt, a text file containing the GNU General Public License version 3.
2821

2922
* src, a subdirectory containing the full source code, including a Makefile
3023
that can be used to compile Stockfish on Unix-like systems.
3124

3225

33-
### Syzygybases
26+
## UCI parameters
27+
28+
Currently, Stockfish has the following UCI options:
29+
30+
* #### Debug Log File
31+
Write all communication to and from the engine into a text file.
32+
33+
* #### Contempt
34+
A positive value for contempt favors middle game positions and avoids draws.
35+
36+
* #### Analysis Contempt
37+
By default, contempt is set to prefer the side to move. Set this option to "White"
38+
or "Black" to analyse with contempt for that side, or "Off" to disable contempt.
39+
40+
* #### Threads
41+
The number of CPU threads used for searching a position. For best performance, set
42+
this equal to the number of CPU cores available.
43+
44+
* #### Hash
45+
The size of the hash table in MB.
46+
47+
* #### Clear Hash
48+
Clear the hash table.
49+
50+
* #### Ponder
51+
Let Stockfish ponder its next move while the opponent is thinking.
52+
53+
* #### MultiPV
54+
Output the N best lines (principal variations, PVs) when searching.
55+
Leave at 1 for best performance.
56+
57+
* #### Skill Level
58+
Lower the Skill Level in order to make Stockfish play weaker.
3459

35-
**Configuration**
60+
* #### Move Overhead
61+
Assume a time delay of x ms due to network and GUI overheads. This is useful to
62+
avoid losses on time in those cases.
3663

37-
Syzygybases are configured using the UCI options "SyzygyPath",
38-
"SyzygyProbeDepth", "Syzygy50MoveRule" and "SyzygyProbeLimit".
64+
* #### Minimum Thinking Time
65+
Search for at least x ms per move.
3966

40-
The option "SyzygyPath" should be set to the directory or directories that
41-
contain the .rtbw and .rtbz files. Multiple directories should be
42-
separated by ";" on Windows and by ":" on Unix-based operating systems.
43-
**Do not use spaces around the ";" or ":".**
67+
* #### Slow Mover
68+
Lower values will make Stockfish take less time in games, higher values will
69+
make it think longer.
4470

45-
Example: `C:\tablebases\wdl345;C:\tablebases\wdl6;D:\tablebases\dtz345;D:\tablebases\dtz6`
71+
* #### nodestime
72+
Tells the engine to use nodes searched instead of wall time to account for
73+
elapsed time. Useful for engine testing.
4674

47-
It is recommended to store .rtbw files on an SSD. There is no loss in
48-
storing the .rtbz files on a regular HD.
75+
* #### UCI_Chess960
76+
An option handled by your GUI. If true, Stockfish will play Chess960.
4977

50-
Increasing the "SyzygyProbeDepth" option lets the engine probe less
51-
aggressively. Set this option to a higher value if you experience too much
52-
slowdown (in terms of nps) due to TB probing.
78+
* #### UCI_AnalyseMode
79+
An option handled by your GUI.
5380

54-
Set the "Syzygy50MoveRule" option to false if you want tablebase positions
55-
that are drawn by the 50-move rule to count as win or loss. This may be useful
56-
for correspondence games (because of tablebase adjudication).
81+
* #### SyzygyPath
82+
Path to the folders/directories storing the Syzygy tablebase files. Multiple
83+
directories are to be separated by ";" on Windows and by ":" on Unix-based
84+
operating systems. Do not use spaces around the ";" or ":".
85+
86+
Example: `C:\tablebases\wdl345;C:\tablebases\wdl6;D:\tablebases\dtz345;D:\tablebases\dtz6`
87+
88+
It is recommended to store .rtbw files on an SSD. There is no loss in storing
89+
the .rtbz files on a regular HD.
5790

58-
The "SyzygyProbeLimit" option should normally be left at its default value.
91+
* #### SyzygyProbeDepth
92+
Minimum remaining search depth for which a position is probed. Set this option
93+
to a higher value to probe less agressively if you experience too much slowdown
94+
(in terms of nps) due to TB probing.
95+
96+
* #### Syzygy50MoveRule
97+
Disable to let fifty-move rule draws detected by Syzygy tablebase probes count
98+
as wins or losses. This is useful for ICCF correspondence games.
99+
100+
* #### SyzygyProbeLimit
101+
Limit Syzygy tablebase probing to positions with at most this many pieces left
102+
(including kings and pawns).
103+
104+
105+
## What to expect from Syzygybases?
59106

60-
**What to expect**
61107
If the engine is searching a position that is not in the tablebases (e.g.
62108
a position with 8 pieces), it will access the tablebases during the search.
63-
If the engine reports a very large score (typically 123.xx), this means
109+
If the engine reports a very large score (typically 153.xx), this means
64110
that it has found a winning line into a tablebase position.
65111

66112
If the engine is given a position to search that is in the tablebases, it
@@ -71,7 +117,7 @@ It will then perform a search only on those moves. **The engine will not move
71117
immediately**, unless there is only a single good move. **The engine likely
72118
will not report a mate score even if the position is known to be won.**
73119

74-
It is therefore clear that behaviour is not identical to what one might
120+
It is therefore clear that this behaviour is not identical to what one might
75121
be used to with Nalimov tablebases. There are technical reasons for this
76122
difference, the main technical reason being that Nalimov tablebases use the
77123
DTM metric (distance-to-mate), while Syzygybases use a variation of the
@@ -82,7 +128,7 @@ needed for optimal play and in addition being able to take into account
82128
the 50-move rule.
83129

84130

85-
### Compiling it yourself
131+
## Compiling Stockfish yourself from the sources
86132

87133
On Unix-like systems, it should be possible to compile Stockfish
88134
directly from the source code with the included Makefile.
@@ -96,23 +142,41 @@ compile (for instance with Microsoft MSVC) you need to manually
96142
set/unset some switches in the compiler command line; see file *types.h*
97143
for a quick reference.
98144

99-
### Resource For Understanding the Code Base
100145

101-
* [Chess Programming Wiki](https://www.chessprogramming.org/Main_Page)
102-
has good overall chess engines explanations
103-
(techniques used here are well explained like hash maps etc), it was
104-
also recommended by the [support team at stockfish.](http://support.stockfishchess.org/discussions/questions/1132-how-to-understand-stockfish-sources)
146+
## Understanding the code base and participating in the project
147+
148+
Stockfish's improvement over the last couple of years has been a great
149+
community effort. There are a few ways to help contribute to its growth.
150+
151+
### Donating hardware
152+
153+
Improving Stockfish requires a massive amount of testing. You can donate
154+
your hardware resources by installing the [Fishtest Worker](https://github.com/glinscott/fishtest/wiki/Running-the-worker)
155+
and view the current tests on [Fishtest](http://tests.stockfishchess.org/tests).
156+
157+
### Improving the code
158+
159+
If you want to help improve the code, there are several valuable ressources:
160+
161+
* [In this wiki,](https://www.chessprogramming.org) many techniques used in
162+
Stockfish are explained with a lot of background information.
163+
164+
* [The section on Stockfish](https://www.chessprogramming.org/Stockfish)
165+
describes many features and techniques used by Stockfish. However, it is
166+
generic rather than being focused on Stockfish's precise implementation.
167+
Nevertheless, a helpful resource.
105168

106-
* [Here](https://www.chessprogramming.org/Stockfish) you can find a set
107-
of features and techniques used by Stockfish and each of them is explained
108-
at the wiki, however, it's a generic way rather than focusing on Stockfish's
109-
own implementation, but it will still help you.
169+
* The latest source can always be found on [GitHub](https://github.com/official-stockfish/Stockfish).
170+
Discussions about Stockfish take place in the [FishCooking](https://groups.google.com/forum/#!forum/fishcooking)
171+
group and engine testing is done on [Fishtest](http://tests.stockfishchess.org/tests).
172+
If you want to help improve Stockfish, please read this [guideline](https://github.com/glinscott/fishtest/wiki/Creating-my-first-test)
173+
first, where the basics of Stockfish development are explained.
110174

111175

112-
### Terms of use
176+
## Terms of use
113177

114-
Stockfish is free, and distributed under the **GNU General Public License**
115-
(GPL). Essentially, this means that you are free to do almost exactly
178+
Stockfish is free, and distributed under the **GNU General Public License version 3**
179+
(GPL v3). Essentially, this means that you are free to do almost exactly
116180
what you want with the program, including distributing it among your
117181
friends, making it available for download from your web site, selling
118182
it (either by itself or as part of some bigger software package), or
@@ -123,5 +187,5 @@ some way, you must always include the full source code, or a pointer
123187
to where the source code can be found. If you make any changes to the
124188
source code, these changes must also be made available under the GPL.
125189

126-
For full details, read the copy of the GPL found in the file named
190+
For full details, read the copy of the GPL v3 found in the file named
127191
*Copying.txt*.

src/bitboard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ namespace {
184184

185185
// init_magics() computes all rook and bishop attacks at startup. Magic
186186
// bitboards are used to look up attacks of sliding pieces. As a reference see
187-
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
188-
// use the so called "fancy" approach.
187+
// www.chessprogramming.org/Magic_Bitboards. In particular, here we use the so
188+
// called "fancy" approach.
189189

190190
void init_magics(Bitboard table[], Magic magics[], Direction directions[]) {
191191

src/endgame.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
131131
Square loserKSq = pos.square<KING>(weakSide);
132132
Square bishopSq = pos.square<BISHOP>(strongSide);
133133

134-
// If our Bishop does not attack A1/H8, we flip the enemy king square
134+
// If our Bishop does not attack A1/H8, we flip the enemy king square
135135
// to drive to opposite corners (A8/H1).
136136

137137
Value result = VALUE_KNOWN_WIN
@@ -724,6 +724,9 @@ ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
724724
template<>
725725
ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
726726

727+
assert(verify_material(pos, strongSide, KnightValueMg, 1));
728+
assert(verify_material(pos, weakSide, BishopValueMg, 0));
729+
727730
Square pawnSq = pos.square<PAWN>(strongSide);
728731
Square bishopSq = pos.square<BISHOP>(weakSide);
729732
Square weakKingSq = pos.square<KING>(weakSide);

src/evaluate.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace {
212212
// kingRing[color] are the squares adjacent to the king, plus (only for a
213213
// king on its first rank) the squares two ranks in front. For instance,
214214
// if black's king is on g8, kingRing[BLACK] is f8, h8, f7, g7, h7, f6, g6
215-
// and h6. It is set to 0 when king safety evaluation is skipped.
215+
// and h6.
216216
Bitboard kingRing[COLOR_NB];
217217

218218
// kingAttackersCount[color] is the number of pieces of the given color
@@ -504,7 +504,7 @@ namespace {
504504
Score score = SCORE_ZERO;
505505

506506
// Non-pawn enemies
507-
nonPawnEnemies = pos.pieces(Them) & ~pos.pieces(Them, PAWN);
507+
nonPawnEnemies = pos.pieces(Them) & ~pos.pieces(PAWN);
508508

509509
// Squares strongly protected by the enemy, either because they defend the
510510
// square with a pawn, or because they defend the square twice and we don't.
@@ -716,7 +716,8 @@ namespace {
716716
behind |= (Us == WHITE ? behind >> 16 : behind << 16);
717717

718718
int bonus = popcount(safe) + popcount(behind & safe);
719-
int weight = pos.count<ALL_PIECES>(Us) - 2 * pe->open_files();
719+
int weight = pos.count<ALL_PIECES>(Us)
720+
- 2 * popcount(pe->semiopenFiles[WHITE] & pe->semiopenFiles[BLACK]);
720721

721722
Score score = make_score(bonus * weight * weight / 16, 0);
722723

src/movegen.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace {
2828
template<Color Us, CastlingSide Cs, bool Checks, bool Chess960>
2929
ExtMove* generate_castling(const Position& pos, ExtMove* moveList) {
3030

31+
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
3132
constexpr CastlingRight Cr = Us | Cs;
3233
constexpr bool KingSide = (Cs == KING_SIDE);
3334

@@ -39,7 +40,7 @@ namespace {
3940
Square kfrom = pos.square<KING>(Us);
4041
Square rfrom = pos.castling_rook_square(Cr);
4142
Square kto = relative_square(Us, KingSide ? SQ_G1 : SQ_C1);
42-
Bitboard enemies = pos.pieces(~Us);
43+
Bitboard enemies = pos.pieces(Them);
4344

4445
assert(!pos.checkers());
4546

@@ -53,7 +54,7 @@ namespace {
5354
// Because we generate only legal castling moves we need to verify that
5455
// when moving the castling rook we do not discover some hidden checker.
5556
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
56-
if (Chess960 && (attacks_bb<ROOK>(kto, pos.pieces() ^ rfrom) & pos.pieces(~Us, ROOK, QUEEN)))
57+
if (Chess960 && (attacks_bb<ROOK>(kto, pos.pieces() ^ rfrom) & pos.pieces(Them, ROOK, QUEEN)))
5758
return moveList;
5859

5960
Move m = make<CASTLING>(kfrom, rfrom);
@@ -93,10 +94,8 @@ namespace {
9394
template<Color Us, GenType Type>
9495
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
9596

96-
// Compute our parametrized parameters at compile time, named according to
97-
// the point of view of white side.
97+
// Compute some compile time parameters relative to the white side
9898
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
99-
constexpr Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
10099
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
101100
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
102101
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
@@ -161,7 +160,7 @@ namespace {
161160
}
162161

163162
// Promotions and underpromotions
164-
if (pawnsOn7 && (Type != EVASIONS || (target & TRank8BB)))
163+
if (pawnsOn7)
165164
{
166165
if (Type == CAPTURES)
167166
emptySquares = ~pos.pieces();

src/movepick.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ namespace {
3131
QSEARCH_TT, QCAPTURE_INIT, QCAPTURE, QCHECK_INIT, QCHECK
3232
};
3333

34-
// Helper filter used with select()
35-
const auto Any = [](){ return true; };
36-
3734
// partial_insertion_sort() sorts moves in descending order up to and including
3835
// a given limit. The order of moves smaller than the limit is left unspecified.
3936
void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit) {
@@ -225,7 +222,7 @@ Move MovePicker::next_move(bool skipQuiets) {
225222
/* fallthrough */
226223

227224
case BAD_CAPTURE:
228-
return select<Next>(Any);
225+
return select<Next>([](){ return true; });
229226

230227
case EVASION_INIT:
231228
cur = moves;
@@ -236,7 +233,7 @@ Move MovePicker::next_move(bool skipQuiets) {
236233
/* fallthrough */
237234

238235
case EVASION:
239-
return select<Best>(Any);
236+
return select<Best>([](){ return true; });
240237

241238
case PROBCUT:
242239
return select<Best>([&](){ return pos.see_ge(move, threshold); });
@@ -261,7 +258,7 @@ Move MovePicker::next_move(bool skipQuiets) {
261258
/* fallthrough */
262259

263260
case QCHECK:
264-
return select<Next>(Any);
261+
return select<Next>([](){ return true; });
265262
}
266263

267264
assert(false);

0 commit comments

Comments
 (0)