mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 07:27:46 +00:00
Compare commits
382 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7fcdfd6bf | |||
| 41816b7ced | |||
| 13224e1d9d | |||
| 10c1ae8da0 | |||
| 3a62738174 | |||
| 84451191f3 | |||
| 2ed3358faf | |||
| 08634b06a3 | |||
| 0e33fc6fd4 | |||
| a5a8830e97 | |||
| 2a14123550 | |||
| 8fabd69d4a | |||
| 1fc88071d1 | |||
| 7dca461927 | |||
| 7618ee2df1 | |||
| 661d48c27b | |||
| 42de93ac15 | |||
| 426f55b78d | |||
| b638f6b035 | |||
| 3de0bc43a2 | |||
| 9fc602bae7 | |||
| 49c50399fe | |||
| a4551c59e0 | |||
| c853b87c08 | |||
| 92bada1a32 | |||
| eaed535c5f | |||
| 49dfc50b12 | |||
| c835ee8853 | |||
| 7ff9678651 | |||
| 4ef068a506 | |||
| f23a9e8f88 | |||
| cc2a249952 | |||
| 55f0d6377f | |||
| aeb664e0ea | |||
| 8abdb131c8 | |||
| 43c93cb151 | |||
| 8d1d9f7181 | |||
| a303bde26c | |||
| 0f50f10327 | |||
| 8286e6ded2 | |||
| 3a558a3d8b | |||
| 14dbeb22dd | |||
| 68eb7e77f1 | |||
| 57340c109b | |||
| 111aa44662 | |||
| 29fb389760 | |||
| 0d292d1a2d | |||
| 5bb9da9287 | |||
| 34c7f1387d | |||
| fc23466236 | |||
| 01b228b5e1 | |||
| 2142be7d7f | |||
| 3888d14bd4 | |||
| 7bcd97933a | |||
| 9d4abbc6eb | |||
| c3b3dcc31a | |||
| e6f2d43b8a | |||
| 1a03f0b0d3 | |||
| 62f6d39204 | |||
| 936cd5b83d | |||
| 3c31776a20 | |||
| 0980f43ab0 | |||
| 9eedc0a463 | |||
| 195b54c312 | |||
| 89b4ad6433 | |||
| 77bb9a94ae | |||
| 8a78ac84f3 | |||
| 5c944fb3b4 | |||
| c974d9ef33 | |||
| 12feb5866f | |||
| 80810e4951 | |||
| c67b9916f1 | |||
| 78c6bb1079 | |||
| 85e60bfc8e | |||
| 79b57dd4ca | |||
| b9537edbb0 | |||
| d38f4f61e7 | |||
| 27c74c5245 | |||
| 2f2e8a68d8 | |||
| 1ea70dd9dd | |||
| 13c096f839 | |||
| 2de2b76896 | |||
| 8b99e94562 | |||
| 512a4e4ff0 | |||
| 2da290d72b | |||
| b39a24ecca | |||
| 189a005a0b | |||
| 7c61b8ad2a | |||
| a093f33154 | |||
| 0895f1ac71 | |||
| b29198354c | |||
| 40a7ffd53f | |||
| 8eae6a95fb | |||
| 2b740f5495 | |||
| fb5ba1d329 | |||
| 78e494fcbc | |||
| a16415f44d | |||
| 8a504d36f9 | |||
| 093dd8fe88 | |||
| 6382324afd | |||
| cb08413dc4 | |||
| 711ef615c7 | |||
| 74203e181d | |||
| 97fe0ac777 | |||
| 7ae16a193b | |||
| 8261f61964 | |||
| 6e1cb6e45b | |||
| 4bfa0c429e | |||
| 2e70a2873f | |||
| 9429d2d028 | |||
| d44fa46082 | |||
| c7866a4215 | |||
| 69644d3f73 | |||
| b0858877ae | |||
| 321f6d1d19 | |||
| e738fa7d10 | |||
| c5d546e18e | |||
| 8d65fcc0f3 | |||
| d8e5b8c133 | |||
| 6fe36d13de | |||
| 337ec0f3d0 | |||
| 5b1043ee11 | |||
| 439aea9ab7 | |||
| 770db27164 | |||
| 21d32aa7fe | |||
| 95d33aef9f | |||
| b5a4edd86f | |||
| 35ada63174 | |||
| 06a695d5b8 | |||
| 4b55d3d883 | |||
| 8008f78415 | |||
| 3941e4bdb3 | |||
| d7d2c1b7e3 | |||
| 17502a5659 | |||
| e84488ed6b | |||
| 252844e899 | |||
| b651e5334b | |||
| bd358533a4 | |||
| e4d3a15656 | |||
| 1d7a3f26e0 | |||
| a0005ba45f | |||
| bdd61b1744 | |||
| 973e574e1f | |||
| 27393ebae2 | |||
| 3c7eebb48d | |||
| 548bae80bd | |||
| 2360c8aa2f | |||
| 32bd6e44f0 | |||
| c83fd08fd4 | |||
| 62b43130e2 | |||
| cd112ee8eb | |||
| bb968fd42a | |||
| 307909bed8 | |||
| b95ba7b37e | |||
| f37741cc83 | |||
| 54b3d44194 | |||
| ea53006a9d | |||
| 6247f27a05 | |||
| 5b2fc1e1c0 | |||
| 05a8c318b8 | |||
| 22b8dc8c98 | |||
| cfe59de27d | |||
| c43c5fe9e0 | |||
| d0daa16769 | |||
| 87303d7ed3 | |||
| cf9bf4e58f | |||
| 5ca4284027 | |||
| dac1bcab90 | |||
| 81cfd81366 | |||
| d844a75d2c | |||
| c5e71f5150 | |||
| c5858ff9ae | |||
| 0ff91e16da | |||
| c2df60048e | |||
| 84ec1f7331 | |||
| b1ac6c69a0 | |||
| 56e09b4cc8 | |||
| 5ed0a60203 | |||
| 1588a4e846 | |||
| 5894c759cd | |||
| 3975a2b94f | |||
| eb6ddd54f1 | |||
| 01ebb3d996 | |||
| 285df57a9a | |||
| 806c1d8723 | |||
| a1b8c8109b | |||
| c01af56769 | |||
| 66d5c13a88 | |||
| 0edad63b44 | |||
| b833c8247a | |||
| 419c5b69ca | |||
| 72e1e9b986 | |||
| 1062459029 | |||
| b5d38ad1e5 | |||
| 000a975eaf | |||
| d457594197 | |||
| 942c18ef66 | |||
| 007285be2d | |||
| e817a55bc6 | |||
| 638f3d31cc | |||
| 55745f4105 | |||
| 968c3de8e0 | |||
| 6a6facc058 | |||
| 5b21c10afb | |||
| dba072c449 | |||
| e2e360fcbc | |||
| 49b1c5dccd | |||
| c99d963fa5 | |||
| 7c0679ad61 | |||
| cc974fa7a4 | |||
| 807844eab1 | |||
| 860260c3b1 | |||
| d11af1de11 | |||
| 721d557681 | |||
| 0e15b0f1d3 | |||
| 9e6d38d224 | |||
| c8af7a867e | |||
| 5c8f571459 | |||
| 0256db2a11 | |||
| 12d8f74242 | |||
| 7824603549 | |||
| 0f39e5c4ff | |||
| 990d83a72d | |||
| cf486cf229 | |||
| e0a8b36436 | |||
| 8d724220a7 | |||
| 0973cc2ef6 | |||
| 3f14f9a478 | |||
| aa86d81f79 | |||
| b884351cc7 | |||
| 4d9e9ac3d4 | |||
| 3dc9f95225 | |||
| bc0871acbc | |||
| 2643f1552f | |||
| ba07b95ee0 | |||
| ef58551a2d | |||
| 7d34e7bf84 | |||
| 12aeac5e14 | |||
| 734fb9a13b | |||
| c12364bb67 | |||
| ad5b5cef4a | |||
| 0d88b832e3 | |||
| 14c3da5cad | |||
| 0b9b34655f | |||
| a66f31f129 | |||
| 2161d8b0b3 | |||
| 7bc72d092f | |||
| b056e5d40a | |||
| d0b8bc5fdf | |||
| 9a46ac6b2c | |||
| 0fc9d9ef61 | |||
| bd618941ce | |||
| 403db5a6e9 | |||
| 3f3365221b | |||
| ae0b965711 | |||
| 455993b289 | |||
| c7a77dd3c0 | |||
| af3dd21e90 | |||
| 1a7047f544 | |||
| 25c22ffe7a | |||
| ae6157fcf3 | |||
| 5bec768d42 | |||
| 6ae30e7cb1 | |||
| 5ea8167921 | |||
| 55b5b03273 | |||
| 850c021f86 | |||
| cd0c7373cd | |||
| 9a59535962 | |||
| 48246468f2 | |||
| 2b6bc70f7b | |||
| 8b3fdec7ec | |||
| 58452de86d | |||
| 93c9f342ca | |||
| 16acf57773 | |||
| 77eec9f9cb | |||
| bc35f4c42d | |||
| 889c8538a8 | |||
| c52da3b806 | |||
| b599da01fa | |||
| 52bca81dcb | |||
| 0eedf47661 | |||
| 989833205f | |||
| 87507121d5 | |||
| 89fe8bc0a6 | |||
| 4c58db0dab | |||
| 71e852ea81 | |||
| 314faa905a | |||
| a530fc2b60 | |||
| 7d0e0ff95e | |||
| 764229a2e2 | |||
| 5e340346db | |||
| bf395c6be1 | |||
| ad44ff2bca | |||
| 8e96149c8c | |||
| 3c085775d7 | |||
| dd5a3ae4a6 | |||
| f7f09b91ea | |||
| 8a116ce691 | |||
| 16626dd655 | |||
| 2f01d67a92 | |||
| 975d5e9c64 | |||
| 30075e4abc | |||
| 37398d9456 | |||
| e05039156c | |||
| f35ddb04af | |||
| ef6fca98a0 | |||
| fea46a8212 | |||
| 776c7df30c | |||
| 5e112f16da | |||
| 15ec3e911e | |||
| 1ecd8e13ee | |||
| 444c7c5183 | |||
| e9757f7610 | |||
| 1ab01f1c14 | |||
| 4626ec2890 | |||
| dda7e4639a | |||
| 1ae8c59c0b | |||
| 06f06a9be8 | |||
| 2f5ee9e4e8 | |||
| dd884b65b7 | |||
| 0fdc75c0bd | |||
| dae7cacd3b | |||
| 7c0cb8e73d | |||
| 53ce6ce49c | |||
| 7a68916ff9 | |||
| 82a1e2d5fc | |||
| dc286d2673 | |||
| a9e536a7eb | |||
| e59d053984 | |||
| 1c73c1c150 | |||
| 423b8b9ded | |||
| 94dcac1fee | |||
| 0855d93de8 | |||
| deecb3757c | |||
| 53c2bf0697 | |||
| 483a257618 | |||
| 12461996a5 | |||
| 70b7404a63 | |||
| dddaeff7d8 | |||
| 941d923bf8 | |||
| 23de3e16f1 | |||
| 8ebe5075eb | |||
| fa49311b36 | |||
| d9b920acfb | |||
| 12b0517d1b | |||
| b38685625a | |||
| 73da3a431c | |||
| b50921fd5c | |||
| a72c55283d | |||
| cf4df0327a | |||
| 51c3af9dd0 | |||
| f0b0a3b135 | |||
| 4dd7fccfd1 | |||
| c1ea5ed6f7 | |||
| 53f882ff1a | |||
| d8e7ce1863 | |||
| 181d34e5a0 | |||
| 2655f93c32 | |||
| ab4d26f9bd | |||
| d6b04c2798 | |||
| e2e249eabd | |||
| ed19a9f909 | |||
| eddfd46a10 | |||
| a806d7c3d6 | |||
| ccdb634b77 | |||
| 564ed5b38c | |||
| f05d059b17 | |||
| 06a5b602dc | |||
| d892063cd3 | |||
| 64d6ba2e98 | |||
| 5a5dc6fa10 | |||
| 8ee0842c81 | |||
| e59ff49a55 | |||
| 225dcfeeb7 | |||
| 8dd01fda12 | |||
| 18cd83a380 | |||
| fd2b3df770 | |||
| da948cc94e | |||
| e49b21eacb | |||
| 60bc30275d | |||
| 32dfaa56b0 | |||
| 3701a8e57d |
+87
-88
@@ -1,91 +1,90 @@
|
||||
1. Introduction
|
||||
---------------
|
||||
|
||||
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
||||
not a complete chess program, but requires some UCI compatible GUI
|
||||
(like XBoard with PolyGlot, eboard, Jos�, Arena, Sigma Chess, Shredder,
|
||||
Chess Partner, or Fritz) in order to be used comfortably. Read the
|
||||
documentation for your GUI of choice for information about how to use
|
||||
Stockfish with your GUI.
|
||||
|
||||
This version of Stockfish supports up to 8 CPUs, but has not been
|
||||
tested thoroughly with more than 2. The program tries to detect the
|
||||
number of CPUs on your computer and set the number of search threads
|
||||
accordingly, but please be aware that the detection is not always
|
||||
correct. It is therefore recommended to inspect the value of the
|
||||
"Threads" UCI parameter, and to make sure it equals the number of CPU
|
||||
1. Introduction
|
||||
---------------
|
||||
|
||||
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
||||
not a complete chess program, but requires some UCI compatible GUI
|
||||
(like XBoard with PolyGlot, eboard, Jos�, Arena, Sigma Chess, Shredder,
|
||||
Chess Partner, or Fritz) in order to be used comfortably. Read the
|
||||
documentation for your GUI of choice for information about how to use
|
||||
Stockfish with your GUI.
|
||||
|
||||
This version of Stockfish supports up to 8 CPUs, but has not been
|
||||
tested thoroughly with more than 2. The program tries to detect the
|
||||
number of CPUs on your computer and set the number of search threads
|
||||
accordingly, but please be aware that the detection is not always
|
||||
correct. It is therefore recommended to inspect the value of the
|
||||
"Threads" UCI parameter, and to make sure it equals the number of CPU
|
||||
cores on your computer. If you are using more than four threads, it
|
||||
is recommended to raise the value of "Minimum Split Depth" UCI parameter
|
||||
to 6.
|
||||
|
||||
|
||||
2. Files
|
||||
--------
|
||||
|
||||
This distribution of Stockfish consists of the following files:
|
||||
|
||||
* Readme.txt, the file you are currently reading.
|
||||
|
||||
* Copying.txt, a text file containing the GNU General Public
|
||||
License.
|
||||
|
||||
* src/, a subdirectory containing the full source code, including a
|
||||
Makefile that can be used to compile Stockfish on Unix-like
|
||||
systems. For further information about how to compile Stockfish
|
||||
yourself, read section 4 below.
|
||||
|
||||
* polyglot.ini, for using Stockfish with Fabien Letouzey's PolyGlot
|
||||
adapter.
|
||||
|
||||
|
||||
3. Opening books
|
||||
----------------
|
||||
|
||||
This version of Stockfish has experimental support for PolyGlot opening
|
||||
books. For information about how to create such books, consult the
|
||||
PolyGlot documentation. The book file can be selected by setting the
|
||||
UCI parameter "Book File".
|
||||
|
||||
|
||||
4. Compiling it yourself
|
||||
------------------------
|
||||
|
||||
On Unix-like systems, it should usually be possible to compile
|
||||
Stockfish directly from the source code with the included Makefile.
|
||||
The exception is computer with big-endian CPUs, like PowerPC
|
||||
Macintoshes. Some of the bitboard routines in the current version of
|
||||
Stockfish are endianness-sensitive, and won't work on a big-endian CPU.
|
||||
|
||||
Stockfish has POPCNT instruction runtime detection and support. This can
|
||||
give an extra speed on Core i7 or similar systems. To enable this feature
|
||||
(disabled by default) simply uncomment #define USE_POPCNT in bitcount.h
|
||||
before to compile.
|
||||
|
||||
On 64 bit Unix-like systems the 'bsfq' assembly instruction will be used
|
||||
for bit counting. Detection is automatic at compile time, but in case you
|
||||
experience compile problems you can comment out #define USE_BSFQ line in types.h
|
||||
|
||||
|
||||
5. Terms of use
|
||||
---------------
|
||||
|
||||
Stockfish is free, and distributed under the GNU General Public License
|
||||
(GPL). Essentially, this means that you are free to do almost exactly
|
||||
what you want with the program, including distributing it among your
|
||||
friends, making it available for download from your web site, selling
|
||||
it (either by itself or as part of some bigger software package), or
|
||||
using it as the starting point for a software project of your own.
|
||||
|
||||
The only real limitation is that whenever you distribute Stockfish in
|
||||
some way, you must always include the full source code, or a pointer
|
||||
to where the source code can be found. If you make any changes to the
|
||||
source code, these changes must also be made available under the GPL.
|
||||
|
||||
For full details, read the copy of the GPL found in the file named
|
||||
Copying.txt.
|
||||
|
||||
|
||||
6. Feedback
|
||||
-----------
|
||||
|
||||
The author's e-mail address is mcostalba@gmail.com
|
||||
|
||||
|
||||
2. Files
|
||||
--------
|
||||
|
||||
This distribution of Stockfish consists of the following files:
|
||||
|
||||
* Readme.txt, the file you are currently reading.
|
||||
|
||||
* Copying.txt, a text file containing the GNU General Public
|
||||
License.
|
||||
|
||||
* src/, a subdirectory containing the full source code, including a
|
||||
Makefile that can be used to compile Stockfish on Unix-like
|
||||
systems. For further information about how to compile Stockfish
|
||||
yourself, read section 4 below.
|
||||
|
||||
* polyglot.ini, for using Stockfish with Fabien Letouzey's PolyGlot
|
||||
adapter.
|
||||
|
||||
|
||||
3. Opening books
|
||||
----------------
|
||||
|
||||
This version of Stockfish has experimental support for PolyGlot opening
|
||||
books. For information about how to create such books, consult the
|
||||
PolyGlot documentation. The book file can be selected by setting the
|
||||
UCI parameter "Book File".
|
||||
|
||||
|
||||
4. Compiling it yourself
|
||||
------------------------
|
||||
|
||||
On Unix-like systems, it should usually be possible to compile
|
||||
Stockfish directly from the source code with the included Makefile.
|
||||
|
||||
For big-endian machines like Power PC you need to enable the proper
|
||||
flag changing from -DNBIGENDIAN to -DBIGENDIAN in the Makefile.
|
||||
|
||||
Stockfish has POPCNT instruction runtime detection and support. This can
|
||||
give an extra speed on Core i7 or similar systems. To enable this feature
|
||||
compile with 'make icc-profile-popcnt'
|
||||
|
||||
On 64 bit Unix-like systems the 'bsfq' assembly instruction will be used
|
||||
for bit counting. Detection is automatic at compile time, but in case you
|
||||
experience compile problems you can comment out #define USE_BSFQ line in types.h
|
||||
|
||||
|
||||
5. Terms of use
|
||||
---------------
|
||||
|
||||
Stockfish is free, and distributed under the GNU General Public License
|
||||
(GPL). Essentially, this means that you are free to do almost exactly
|
||||
what you want with the program, including distributing it among your
|
||||
friends, making it available for download from your web site, selling
|
||||
it (either by itself or as part of some bigger software package), or
|
||||
using it as the starting point for a software project of your own.
|
||||
|
||||
The only real limitation is that whenever you distribute Stockfish in
|
||||
some way, you must always include the full source code, or a pointer
|
||||
to where the source code can be found. If you make any changes to the
|
||||
source code, these changes must also be made available under the GPL.
|
||||
|
||||
For full details, read the copy of the GPL found in the file named
|
||||
Copying.txt.
|
||||
|
||||
|
||||
6. Feedback
|
||||
-----------
|
||||
|
||||
The author's e-mail address is mcostalba@gmail.com
|
||||
|
||||
+82
-10
@@ -21,6 +21,10 @@
|
||||
### Executable name. Do not change
|
||||
EXE = stockfish
|
||||
|
||||
### Installation dir definitions
|
||||
PREFIX = /usr/local
|
||||
BINDIR = $(PREFIX)/bin
|
||||
|
||||
|
||||
### ==========================================================================
|
||||
### Compiler speed switches for both GCC and ICC. These settings are generally
|
||||
@@ -39,6 +43,14 @@ ICCFLAGS += -DNDEBUG
|
||||
ICCFLAGS-OSX += -DNDEBUG
|
||||
|
||||
|
||||
### ==========================================================================
|
||||
### Remove below comments to compile for a big-endian machine
|
||||
### ==========================================================================
|
||||
#GCCFLAGS += -DBIGENDIAN
|
||||
#ICCFLAGS += -DBIGENDIAN
|
||||
#ICCFLAGS-OSX += -DBIGENDIAN
|
||||
|
||||
|
||||
### ==========================================================================
|
||||
### Run built-in benchmark for pgo-builds with: 32MB hash 1 thread 10 depth
|
||||
### These settings are generally fast, but may be changed experimentally
|
||||
@@ -47,9 +59,9 @@ PGOBENCH = ./$(EXE) bench 32 1 10 default depth
|
||||
|
||||
|
||||
### General compiler settings. Do not change
|
||||
GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing
|
||||
ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -wd383,869,981,10187,10188,11505,11503
|
||||
ICCFLAGS-OSX += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -wd383,869,981,10187,10188,11505,11503
|
||||
GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti
|
||||
ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -wd383,869,981,10187,10188,11505,11503
|
||||
ICCFLAGS-OSX += -g -Wall -fno-exceptions -fno-rtti -wd383,869,981,10187,10188,11505,11503
|
||||
|
||||
|
||||
### General linker settings. Do not change
|
||||
@@ -72,8 +84,10 @@ help:
|
||||
@echo "Makefile options:"
|
||||
@echo ""
|
||||
@echo "make > Default: Compiler = g++"
|
||||
@echo "make gcc-popcnt > Compiler = g++ + popcnt-support"
|
||||
@echo "make icc > Compiler = icpc"
|
||||
@echo "make icc-profile > Compiler = icpc + automatic pgo-build"
|
||||
@echo "make icc-profile-popcnt > Compiler = icpc + automatic pgo-build + popcnt-support"
|
||||
@echo "make osx-ppc32 > PPC-Mac OS X 32 bit. Compiler = g++"
|
||||
@echo "make osx-ppc64 > PPC-Mac OS X 64 bit. Compiler = g++"
|
||||
@echo "make osx-x86 > x86-Mac OS X 32 bit. Compiler = g++"
|
||||
@@ -82,14 +96,18 @@ help:
|
||||
@echo "make osx-icc64 > x86-Mac OS X 64 bit. Compiler = icpc"
|
||||
@echo "make osx-icc32-profile > OSX 32 bit. Compiler = icpc + automatic pgo-build"
|
||||
@echo "make osx-icc64-profile > OSX 64 bit. Compiler = icpc + automatic pgo-build"
|
||||
@echo "make hpux > HP-UX. Compiler = aCC"
|
||||
@echo "make strip > Strip executable"
|
||||
@echo "make clean > Clean up"
|
||||
@echo ""
|
||||
|
||||
all: $(EXE) .depend
|
||||
|
||||
test check: default
|
||||
@$(PGOBENCH)
|
||||
|
||||
clean:
|
||||
$(RM) *.o .depend *~ $(EXE)
|
||||
$(RM) *.o .depend *~ $(EXE) core bench.txt
|
||||
|
||||
|
||||
### Possible targets. You may add your own ones here
|
||||
@@ -99,6 +117,13 @@ gcc:
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
all
|
||||
|
||||
gcc-popcnt:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS) -DUSE_POPCNT" \
|
||||
all
|
||||
|
||||
|
||||
icc:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
@@ -133,11 +158,46 @@ icc-profile:
|
||||
$(MAKE) icc-profile-use
|
||||
@rm -rf profdir bench.txt
|
||||
|
||||
icc-profile-make-with-popcnt:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS) -DUSE_POPCNT" \
|
||||
CXXFLAGS+='-prof-gen=srcpos -prof_dir ./profdir' \
|
||||
all
|
||||
|
||||
icc-profile-use-with-popcnt:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS) -DUSE_POPCNT" \
|
||||
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
||||
all
|
||||
|
||||
icc-profile-popcnt:
|
||||
@rm -rf profdir
|
||||
@mkdir profdir
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) icc-profile-make
|
||||
@echo ""
|
||||
@echo "Running benchmark for pgo-build (popcnt disabled)..."
|
||||
@$(PGOBENCH) > /dev/null
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) icc-profile-make-with-popcnt
|
||||
@echo ""
|
||||
@echo "Running benchmark for pgo-build (popcnt enabled)..."
|
||||
@$(PGOBENCH) > /dev/null
|
||||
@echo "Benchmarks finished. Build final executable now ..."
|
||||
@echo ""
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) icc-profile-use-with-popcnt
|
||||
@rm -rf profdir bench.txt
|
||||
|
||||
|
||||
osx-ppc32:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
CXXFLAGS+='-arch ppc' \
|
||||
CXXFLAGS+='-DBIGENDIAN' \
|
||||
LDFLAGS+='-arch ppc' \
|
||||
all
|
||||
|
||||
@@ -146,6 +206,7 @@ osx-ppc64:
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
CXXFLAGS+='-arch ppc64' \
|
||||
CXXFLAGS+='-DBIGENDIAN' \
|
||||
LDFLAGS+='-arch ppc64' \
|
||||
all
|
||||
|
||||
@@ -153,16 +214,16 @@ osx-x86:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
CXXFLAGS+='-arch i386' \
|
||||
LDFLAGS+='-arch i386' \
|
||||
CXXFLAGS+='-arch i386 -mdynamic-no-pic' \
|
||||
LDFLAGS+='-arch i386 -mdynamic-no-pic' \
|
||||
all
|
||||
|
||||
osx-x86_64:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
CXXFLAGS+='-arch x86_64' \
|
||||
LDFLAGS+='-arch x86_64' \
|
||||
CXXFLAGS+='-arch x86_64 -mdynamic-no-pic' \
|
||||
LDFLAGS+='-arch x86_64 -mdynamic-no-pic' \
|
||||
all
|
||||
|
||||
osx-icc32:
|
||||
@@ -245,6 +306,12 @@ osx-icc64-profile:
|
||||
$(MAKE) osx-icc64-profile-use
|
||||
@rm -rf profdir bench.txt
|
||||
|
||||
hpux:
|
||||
$(MAKE) \
|
||||
CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG' \
|
||||
CXXFLAGS="" \
|
||||
LDFLAGS="" \
|
||||
all
|
||||
|
||||
|
||||
strip:
|
||||
@@ -255,9 +322,14 @@ strip:
|
||||
$(EXE): $(OBJS)
|
||||
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
||||
|
||||
### Installation
|
||||
install: default
|
||||
-mkdir -p -m 755 $(BINDIR)
|
||||
-cp $(EXE) $(BINDIR)
|
||||
-strip $(BINDIR)/$(EXE)
|
||||
|
||||
### Dependencies. Do not change
|
||||
.depend:
|
||||
$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@
|
||||
-@$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
||||
|
||||
include .depend
|
||||
-include .depend
|
||||
|
||||
+3
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -49,6 +49,7 @@ Application::Application() {
|
||||
Position::init_piece_square_tables();
|
||||
init_eval(1);
|
||||
init_bitbases();
|
||||
init_search();
|
||||
init_threads();
|
||||
|
||||
// Make random number generation less deterministic, for book moves
|
||||
@@ -58,7 +59,7 @@ Application::Application() {
|
||||
|
||||
Application::~Application() {
|
||||
|
||||
stop_threads();
|
||||
exit_threads();
|
||||
quit_eval();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+7
-5
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -84,9 +84,9 @@ void benchmark(const string& commandLine) {
|
||||
}
|
||||
csStr >> threads;
|
||||
csVal >> val;
|
||||
if (val < 1 || val > THREAD_MAX)
|
||||
if (val < 1 || val > MAX_THREADS)
|
||||
{
|
||||
cerr << "The number of threads must be between 1 and " << THREAD_MAX << endl;
|
||||
cerr << "The number of threads must be between 1 and " << MAX_THREADS << endl;
|
||||
Application::exit_with_failure();
|
||||
}
|
||||
set_option_value("Hash", ttSize);
|
||||
@@ -104,7 +104,7 @@ void benchmark(const string& commandLine) {
|
||||
|
||||
if (limitType == "time")
|
||||
secsPerPos = val * 1000;
|
||||
else if (limitType == "depth")
|
||||
else if (limitType == "depth" || limitType == "perft")
|
||||
maxDepth = val;
|
||||
else
|
||||
maxNodes = val;
|
||||
@@ -153,7 +153,9 @@ void benchmark(const string& commandLine) {
|
||||
int dummy[2] = {0, 0};
|
||||
Position pos(*it);
|
||||
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
|
||||
if (!think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
|
||||
if (limitType == "perft")
|
||||
totalNodes += perft(pos, maxDepth * OnePly);
|
||||
else if (!think(pos, false, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
|
||||
break;
|
||||
totalNodes += nodes_searched();
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+58
-16
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -297,8 +297,8 @@ void init_bitboards() {
|
||||
|
||||
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
||||
|
||||
CACHE_LINE_ALIGNMENT
|
||||
static const int BitTable[64] = {
|
||||
static CACHE_LINE_ALIGNMENT
|
||||
const int BitTable[64] = {
|
||||
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15,
|
||||
46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39,
|
||||
16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43,
|
||||
@@ -317,8 +317,8 @@ Square pop_1st_bit(Bitboard* b) {
|
||||
|
||||
#elif !defined(USE_BSFQ)
|
||||
|
||||
CACHE_LINE_ALIGNMENT
|
||||
static const int BitTable[64] = {
|
||||
static CACHE_LINE_ALIGNMENT
|
||||
const int BitTable[64] = {
|
||||
63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
|
||||
51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52,
|
||||
26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28,
|
||||
@@ -336,30 +336,72 @@ union b_union {
|
||||
|
||||
Bitboard b;
|
||||
struct {
|
||||
#if defined (BIGENDIAN)
|
||||
uint32_t h;
|
||||
uint32_t l;
|
||||
#else
|
||||
uint32_t l;
|
||||
uint32_t h;
|
||||
#endif
|
||||
} dw;
|
||||
};
|
||||
|
||||
// WARNING: Needs -fno-strict-aliasing compiler option
|
||||
Square pop_1st_bit(Bitboard* bb) {
|
||||
|
||||
b_union u;
|
||||
b_union u;
|
||||
Square ret;
|
||||
|
||||
u.b = *bb;
|
||||
u.b = *bb;
|
||||
|
||||
if (u.dw.l)
|
||||
{
|
||||
*((uint32_t*)bb) = u.dw.l & (u.dw.l - 1);
|
||||
return Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||
}
|
||||
|
||||
*((uint32_t*)bb+1) = u.dw.h & (u.dw.h - 1); // Little endian only?
|
||||
return Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
||||
if (u.dw.l)
|
||||
{
|
||||
ret = Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||
u.dw.l &= (u.dw.l - 1);
|
||||
*bb = u.b;
|
||||
return ret;
|
||||
}
|
||||
ret = Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
||||
u.dw.h &= (u.dw.h - 1);
|
||||
*bb = u.b;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Optimized bitScanReverse32() implementation by Pascal Georges. Note
|
||||
// that first bit is 1, this allow to differentiate between 0 and 1.
|
||||
static CACHE_LINE_ALIGNMENT
|
||||
const char MsbTable[256] = {
|
||||
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
|
||||
};
|
||||
|
||||
int bitScanReverse32(uint32_t b)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (b > 0xFFFF)
|
||||
{
|
||||
b >>= 16;
|
||||
result += 16;
|
||||
}
|
||||
if (b > 0xFF)
|
||||
{
|
||||
b >>= 8;
|
||||
result += 8;
|
||||
}
|
||||
return result + MsbTable[b];
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// All functions below are used to precompute various bitboards during
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -349,6 +349,7 @@ extern Square pop_1st_bit(Bitboard* b);
|
||||
|
||||
extern void print_bitboard(Bitboard b);
|
||||
extern void init_bitboards();
|
||||
extern int bitScanReverse32(uint32_t b);
|
||||
|
||||
|
||||
#endif // !defined(BITBOARD_H_INCLUDED)
|
||||
|
||||
+26
-53
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -22,62 +22,22 @@
|
||||
#if !defined(BITCOUNT_H_INCLUDED)
|
||||
#define BITCOUNT_H_INCLUDED
|
||||
|
||||
// To enable POPCNT support uncomment USE_POPCNT define. For PGO compile on a Core i7
|
||||
// you may want to collect profile data first with USE_POPCNT disabled and then, in a
|
||||
// second profiling session, with USE_POPCNT enabled so to exercise both paths. Don't
|
||||
// forget to leave USE_POPCNT enabled for the final optimized compile though ;-)
|
||||
|
||||
//#define USE_POPCNT
|
||||
|
||||
|
||||
#include "types.h"
|
||||
|
||||
// Select type of intrinsic bit count instruction to use
|
||||
|
||||
#if defined(__INTEL_COMPILER) && defined(IS_64BIT) && defined(USE_POPCNT) // Intel compiler
|
||||
|
||||
#include <nmmintrin.h>
|
||||
|
||||
inline bool cpu_has_popcnt() {
|
||||
|
||||
int CPUInfo[4] = {-1};
|
||||
__cpuid(CPUInfo, 0x00000001);
|
||||
return (CPUInfo[2] >> 23) & 1;
|
||||
}
|
||||
|
||||
// Define a dummy template to workaround a compile error if _mm_popcnt_u64() is not defined.
|
||||
//
|
||||
// If _mm_popcnt_u64() is defined in <nmmintrin.h> it will be choosen first due to
|
||||
// C++ overload rules that always prefer a function to a template with the same name.
|
||||
// If not, we avoid a compile error and because cpu_has_popcnt() should return false,
|
||||
// our templetized _mm_popcnt_u64() is never called anyway.
|
||||
template<typename T> inline unsigned _mm_popcnt_u64(T) { return 0; } // Is never called
|
||||
|
||||
#define POPCNT_INTRINSIC(x) _mm_popcnt_u64(x)
|
||||
|
||||
#elif defined(_MSC_VER) && defined(IS_64BIT) && defined(USE_POPCNT) // Microsoft compiler
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
inline bool cpu_has_popcnt() {
|
||||
|
||||
int CPUInfo[4] = {-1};
|
||||
__cpuid(CPUInfo, 0x00000001);
|
||||
return (CPUInfo[2] >> 23) & 1;
|
||||
}
|
||||
|
||||
// See comment of _mm_popcnt_u64<>() few lines above for an explanation.
|
||||
template<typename T> inline unsigned __popcnt64(T) { return 0; } // Is never called
|
||||
|
||||
#define POPCNT_INTRINSIC(x) __popcnt64(x)
|
||||
|
||||
#else // Safe fallback for unsupported compilers or when USE_POPCNT is disabled
|
||||
|
||||
inline bool cpu_has_popcnt() { return false; }
|
||||
|
||||
// Select type of intrinsic bit count instruction to use, see
|
||||
// README.txt on how to pgo compile with POPCNT support.
|
||||
#if !defined(USE_POPCNT)
|
||||
#define POPCNT_INTRINSIC(x) 0
|
||||
#elif defined(_MSC_VER)
|
||||
#define POPCNT_INTRINSIC(x) (int)__popcnt64(x)
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
#endif // cpu_has_popcnt() and POPCNT_INTRINSIC() definitions
|
||||
#define POPCNT_INTRINSIC(x) ({ \
|
||||
unsigned long __ret; \
|
||||
__asm__("popcnt %1, %0" : "=r" (__ret) : "r" (x)); \
|
||||
__ret; })
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/// Software implementation of bit count functions
|
||||
@@ -144,10 +104,23 @@ inline int count_1s_max_15(Bitboard b) {
|
||||
}
|
||||
|
||||
|
||||
// Detect hardware POPCNT support
|
||||
inline bool cpu_has_popcnt() {
|
||||
|
||||
int CPUInfo[4] = {-1};
|
||||
__cpuid(CPUInfo, 0x00000001);
|
||||
return (CPUInfo[2] >> 23) & 1;
|
||||
}
|
||||
|
||||
|
||||
// Global constant initialized at startup that is set to true if
|
||||
// CPU on which application runs supports POPCNT intrinsic. Unless
|
||||
// USE_POPCNT is not defined.
|
||||
#if defined(USE_POPCNT)
|
||||
const bool CpuHasPOPCNT = cpu_has_popcnt();
|
||||
#else
|
||||
const bool CpuHasPOPCNT = false;
|
||||
#endif
|
||||
|
||||
|
||||
// Global constant used to print info about the use of 64 optimized
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -390,7 +390,7 @@ void Book::close() {
|
||||
/// Book::file_name() returns the file name of the currently active book,
|
||||
/// or the empty string if no book is open.
|
||||
|
||||
const string Book::file_name() const {
|
||||
const string Book::file_name() { // Not const to compile on HP-UX 11.X
|
||||
|
||||
return is_open() ? fileName : "";
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -53,11 +53,14 @@ struct BookEntry {
|
||||
};
|
||||
|
||||
class Book : private std::ifstream {
|
||||
Book(const Book&); // just decleared..
|
||||
Book& operator=(const Book&); // ..to avoid a warning
|
||||
public:
|
||||
Book() {}
|
||||
~Book();
|
||||
void open(const std::string& fName);
|
||||
void close();
|
||||
const std::string file_name() const;
|
||||
const std::string file_name();
|
||||
Move get_move(const Position& pos);
|
||||
|
||||
private:
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+3
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -48,7 +48,8 @@ inline void operator+= (Depth &d, int i) { d = Depth(int(d) + i); }
|
||||
inline void operator+= (Depth &d1, Depth d2) { d1 += int(d2); }
|
||||
inline Depth operator- (Depth d, int i) { return Depth(int(d) - i); }
|
||||
inline Depth operator- (Depth d1, Depth d2) { return Depth(int(d1) - int(d2)); }
|
||||
inline void operator-= (Depth & d, int i) { d = Depth(int(d) - i); }
|
||||
inline void operator-= (Depth &d, int i) { d = Depth(int(d) - i); }
|
||||
inline void operator-= (Depth &d1, Depth d2) { d1 -= int(d2); }
|
||||
inline Depth operator* (Depth d, int i) { return Depth(int(d) * i); }
|
||||
inline Depth operator* (int i, Depth d) { return Depth(int(d) * i); }
|
||||
inline void operator*= (Depth &d, int i) { d = Depth(int(d) * i); }
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+468
-460
File diff suppressed because it is too large
Load Diff
+9
-6
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -25,6 +25,8 @@
|
||||
//// Includes
|
||||
////
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "material.h"
|
||||
#include "pawns.h"
|
||||
|
||||
@@ -45,8 +47,10 @@ class Position;
|
||||
|
||||
struct EvalInfo {
|
||||
|
||||
EvalInfo() { futilityMargin[0] = futilityMargin[1] = Value(0); }
|
||||
|
||||
// Middle game and endgame evaluations
|
||||
Value mgValue, egValue;
|
||||
Score value;
|
||||
|
||||
// Pointers to material and pawn hash table entries
|
||||
MaterialInfo* mi;
|
||||
@@ -89,11 +93,11 @@ struct EvalInfo {
|
||||
Move mateThreat[2];
|
||||
|
||||
// Middle game and endgame mobility scores.
|
||||
Value mgMobility, egMobility;
|
||||
Score mobility;
|
||||
|
||||
// Extra futility margin. This is added to the standard futility margin
|
||||
// in the quiescence search.
|
||||
Value futilityMargin;
|
||||
// in the quiescence search. One for each color.
|
||||
Value futilityMargin[2];
|
||||
};
|
||||
|
||||
|
||||
@@ -102,7 +106,6 @@ struct EvalInfo {
|
||||
////
|
||||
|
||||
extern Value evaluate(const Position& pos, EvalInfo& ei, int threadID);
|
||||
extern Value quick_evaluate(const Position& pos);
|
||||
extern void init_eval(int threads);
|
||||
extern void quit_eval();
|
||||
extern void read_weights(Color sideToMove);
|
||||
|
||||
+25
-15
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -42,8 +42,7 @@ History::History() { clear(); }
|
||||
|
||||
void History::clear() {
|
||||
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
||||
memset(successCount, 0, 2 * 8 * 64 * sizeof(int));
|
||||
memset(failureCount, 0, 2 * 8 * 64 * sizeof(int));
|
||||
memset(maxStaticValueDelta, 0, 2 * 8 * 64 * sizeof(int));
|
||||
}
|
||||
|
||||
|
||||
@@ -58,13 +57,12 @@ void History::success(Piece p, Square to, Depth d) {
|
||||
assert(square_is_ok(to));
|
||||
|
||||
history[p][to] += int(d) * int(d);
|
||||
successCount[p][to]++;
|
||||
|
||||
// Prevent history overflow
|
||||
if (history[p][to] >= HistoryMax)
|
||||
for (int i = 0; i < 16; i++)
|
||||
for (int j = 0; j < 64; j++)
|
||||
history[i][j] /= 4;
|
||||
history[i][j] /= 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,12 +70,18 @@ void History::success(Piece p, Square to, Depth d) {
|
||||
/// called for each non-capturing move which failed to produce a beta cutoff
|
||||
/// at a node where a beta cutoff was finally found.
|
||||
|
||||
void History::failure(Piece p, Square to) {
|
||||
void History::failure(Piece p, Square to, Depth d) {
|
||||
|
||||
assert(piece_is_ok(p));
|
||||
assert(square_is_ok(to));
|
||||
|
||||
failureCount[p][to]++;
|
||||
history[p][to] -= int(d) * int(d);
|
||||
|
||||
// Prevent history underflow
|
||||
if (history[p][to] <= -HistoryMax)
|
||||
for (int i = 0; i < 16; i++)
|
||||
for (int j = 0; j < 64; j++)
|
||||
history[i][j] /= 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,13 +97,19 @@ int History::move_ordering_score(Piece p, Square to) const {
|
||||
}
|
||||
|
||||
|
||||
/// History::ok_to_prune() decides whether a move has been sufficiently
|
||||
/// unsuccessful that it makes sense to prune it entirely.
|
||||
/// History::set_gain() and History::gain() store and retrieve the
|
||||
/// gain of a move given the delta of the static position evaluations
|
||||
/// before and after the move.
|
||||
|
||||
bool History::ok_to_prune(Piece p, Square to, Depth d) const {
|
||||
|
||||
assert(piece_is_ok(p));
|
||||
assert(square_is_ok(to));
|
||||
|
||||
return (int(d) * successCount[p][to] < failureCount[p][to]);
|
||||
void History::set_gain(Piece p, Square to, Value delta)
|
||||
{
|
||||
if (delta >= maxStaticValueDelta[p][to])
|
||||
maxStaticValueDelta[p][to] = delta;
|
||||
else
|
||||
maxStaticValueDelta[p][to]--;
|
||||
}
|
||||
|
||||
Value History::gain(Piece p, Square to) const
|
||||
{
|
||||
return Value(maxStaticValueDelta[p][to]);
|
||||
}
|
||||
|
||||
+7
-6
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "depth.h"
|
||||
#include "move.h"
|
||||
#include "piece.h"
|
||||
#include "value.h"
|
||||
|
||||
|
||||
////
|
||||
@@ -47,14 +48,14 @@ public:
|
||||
History();
|
||||
void clear();
|
||||
void success(Piece p, Square to, Depth d);
|
||||
void failure(Piece p, Square to);
|
||||
void failure(Piece p, Square to, Depth d);
|
||||
int move_ordering_score(Piece p, Square to) const;
|
||||
bool ok_to_prune(Piece p, Square to, Depth d) const;
|
||||
void set_gain(Piece p, Square to, Value delta);
|
||||
Value gain(Piece p, Square to) const;
|
||||
|
||||
private:
|
||||
int history[16][64]; // [piece][square]
|
||||
int successCount[16][64];
|
||||
int failureCount[16][64];
|
||||
int maxStaticValueDelta[16][64]; // [piece][from_square][to_square]
|
||||
};
|
||||
|
||||
|
||||
@@ -70,7 +71,7 @@ private:
|
||||
/// recently have a bigger importance for move ordering than the moves which
|
||||
/// have been searched a long time ago.
|
||||
|
||||
const int HistoryMax = 25000 * OnePly;
|
||||
const int HistoryMax = 50000 * OnePly;
|
||||
|
||||
|
||||
#endif // !defined(HISTORY_H_INCLUDED)
|
||||
|
||||
+1
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -99,5 +99,4 @@ typedef CRITICAL_SECTION Lock;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // !defined(LOCK_H_INCLUDED)
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
|
||||
if (string(argv[1]) != "bench" || argc < 4 || argc > 8)
|
||||
cout << "Usage: stockfish bench <hash size> <threads> "
|
||||
<< "[time = 60s] [fen positions file = default] "
|
||||
<< "[time, depth or node limited = time] "
|
||||
<< "[time, depth, perft or node limited = time] "
|
||||
<< "[timing file name = none]" << endl;
|
||||
else
|
||||
{
|
||||
|
||||
+39
-14
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -37,10 +37,15 @@ using namespace std;
|
||||
|
||||
namespace {
|
||||
|
||||
// Values modified by Joona Kiiski
|
||||
const Value MidgameLimit = Value(15581);
|
||||
const Value EndgameLimit = Value(3998);
|
||||
|
||||
// Polynomial material balance parameters
|
||||
const Value RedundantQueenPenalty = Value(320);
|
||||
const Value RedundantRookPenalty = Value(554);
|
||||
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
||||
|
||||
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
||||
|
||||
const int QuadraticCoefficientsSameColor[][6] = {
|
||||
{ 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 },
|
||||
@@ -129,6 +134,22 @@ MaterialInfoTable::~MaterialInfoTable() {
|
||||
}
|
||||
|
||||
|
||||
/// MaterialInfoTable::game_phase() calculates the phase given the current
|
||||
/// position. Because the phase is strictly a function of the material, it
|
||||
/// is stored in MaterialInfo.
|
||||
|
||||
Phase MaterialInfoTable::game_phase(const Position& pos) {
|
||||
|
||||
Value npm = pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK);
|
||||
|
||||
if (npm >= MidgameLimit)
|
||||
return PHASE_MIDGAME;
|
||||
else if (npm <= EndgameLimit)
|
||||
return PHASE_ENDGAME;
|
||||
|
||||
return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
|
||||
}
|
||||
|
||||
/// MaterialInfoTable::get_material_info() takes a position object as input,
|
||||
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
|
||||
/// If the material configuration is not already present in the table, it
|
||||
@@ -151,6 +172,9 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
mi->clear();
|
||||
mi->key = key;
|
||||
|
||||
// Store game phase
|
||||
mi->gamePhase = MaterialInfoTable::game_phase(pos);
|
||||
|
||||
// Let's look if we have a specialized evaluation function for this
|
||||
// particular material configuration. First we look for a fixed
|
||||
// configuration one, then a generic one if previous search failed.
|
||||
@@ -269,8 +293,8 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
{ pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
|
||||
pos.piece_count(BLACK, BISHOP), pos.piece_count(BLACK, ROOK), pos.piece_count(BLACK, QUEEN) } };
|
||||
Color c, them;
|
||||
int sign;
|
||||
int matValue = 0;
|
||||
int sign, pt1, pt2, pc;
|
||||
int v, vv, matValue = 0;
|
||||
|
||||
for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
|
||||
{
|
||||
@@ -304,25 +328,27 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);
|
||||
|
||||
them = opposite_color(c);
|
||||
v = 0;
|
||||
|
||||
// Second-degree polynomial material imbalance by Tord Romstad
|
||||
//
|
||||
// We use NO_PIECE_TYPE as a place holder for the bishop pair "extended piece",
|
||||
// this allow us to be more flexible in defining bishop pair bonuses.
|
||||
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
||||
for (pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
||||
{
|
||||
int c1 = sign * pieceCount[c][pt1];
|
||||
if (!c1)
|
||||
pc = pieceCount[c][pt1];
|
||||
if (!pc)
|
||||
continue;
|
||||
|
||||
matValue += c1 * LinearCoefficients[pt1];
|
||||
vv = LinearCoefficients[pt1];
|
||||
|
||||
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
|
||||
{
|
||||
matValue += c1 * pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2];
|
||||
matValue += c1 * pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];
|
||||
}
|
||||
for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
|
||||
vv += pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2]
|
||||
+ pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];
|
||||
|
||||
v += pc * vv;
|
||||
}
|
||||
matValue += sign * v;
|
||||
}
|
||||
mi->value = int16_t(matValue / 16);
|
||||
return mi;
|
||||
@@ -348,7 +374,6 @@ EndgameFunctions::EndgameFunctions() {
|
||||
add<ScalingFunction<KBPPKB> >("KBPPKB");
|
||||
add<ScalingFunction<KBPKN> >("KBPKN");
|
||||
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||
}
|
||||
|
||||
EndgameFunctions::~EndgameFunctions() {
|
||||
|
||||
+17
-4
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -51,9 +51,10 @@ class MaterialInfo {
|
||||
public:
|
||||
MaterialInfo() : key(0) { clear(); }
|
||||
|
||||
Value material_value() const;
|
||||
Score material_value() const;
|
||||
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
||||
int space_weight() const;
|
||||
Phase game_phase() const;
|
||||
bool specialized_eval_exists() const;
|
||||
Value evaluate(const Position& pos) const;
|
||||
|
||||
@@ -66,6 +67,7 @@ private:
|
||||
EndgameEvaluationFunctionBase* evaluationFunction;
|
||||
EndgameScalingFunctionBase* scalingFunction[2];
|
||||
int spaceWeight;
|
||||
Phase gamePhase;
|
||||
};
|
||||
|
||||
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
||||
@@ -81,6 +83,8 @@ public:
|
||||
~MaterialInfoTable();
|
||||
MaterialInfo* get_material_info(const Position& pos);
|
||||
|
||||
static Phase game_phase(const Position& pos);
|
||||
|
||||
private:
|
||||
unsigned size;
|
||||
MaterialInfo* entries;
|
||||
@@ -92,12 +96,13 @@ private:
|
||||
//// Inline functions
|
||||
////
|
||||
|
||||
|
||||
/// MaterialInfo::material_value simply returns the material balance
|
||||
/// evaluation that is independent from game phase.
|
||||
|
||||
inline Value MaterialInfo::material_value() const {
|
||||
inline Score MaterialInfo::material_value() const {
|
||||
|
||||
return Value(value);
|
||||
return make_score(value, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +146,14 @@ inline int MaterialInfo::space_weight() const {
|
||||
return spaceWeight;
|
||||
}
|
||||
|
||||
/// MaterialInfo::game_phase() returns the game phase according
|
||||
/// to this material configuration.
|
||||
|
||||
inline Phase MaterialInfo::game_phase() const {
|
||||
|
||||
return gamePhase;
|
||||
}
|
||||
|
||||
|
||||
/// MaterialInfo::specialized_eval_exists decides whether there is a
|
||||
/// specialized evaluation function for the current material configuration,
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+64
-6
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -27,6 +27,9 @@
|
||||
# include <sys/time.h>
|
||||
# include <sys/types.h>
|
||||
# include <unistd.h>
|
||||
# if defined(__hpux)
|
||||
# include <sys/pstat.h>
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
@@ -38,6 +41,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@@ -50,7 +54,7 @@ using namespace std;
|
||||
/// Version number. If this is left empty, the current date (in the format
|
||||
/// YYMMDD) is used as a version number.
|
||||
|
||||
static const string EngineVersion = "1.5";
|
||||
static const string EngineVersion = "1.7";
|
||||
static const string AppName = "Stockfish";
|
||||
static const string AppTag = "";
|
||||
|
||||
@@ -179,23 +183,32 @@ int get_system_time() {
|
||||
}
|
||||
|
||||
|
||||
/// cpu_count() tries to detect the number of CPU cores.
|
||||
/// builtin_cpu_count() tries to detect the number of CPU cores, if
|
||||
/// hyper-threading is enabled this is the number of logical processors.
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
|
||||
# if defined(_SC_NPROCESSORS_ONLN)
|
||||
int cpu_count() {
|
||||
static int builtin_cpu_count() {
|
||||
return Min(sysconf(_SC_NPROCESSORS_ONLN), 8);
|
||||
}
|
||||
# elif defined(__hpux)
|
||||
static int builtin_cpu_count() {
|
||||
struct pst_dynamic psd;
|
||||
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) == -1)
|
||||
return 1;
|
||||
|
||||
return Min(psd.psd_proc_cnt, 8);
|
||||
}
|
||||
# else
|
||||
int cpu_count() {
|
||||
static int builtin_cpu_count() {
|
||||
return 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
int cpu_count() {
|
||||
static int builtin_cpu_count() {
|
||||
SYSTEM_INFO s;
|
||||
GetSystemInfo(&s);
|
||||
return Min(s.dwNumberOfProcessors, 8);
|
||||
@@ -204,6 +217,51 @@ int cpu_count() {
|
||||
#endif
|
||||
|
||||
|
||||
/// HT_enabled() returns true if hyper-threading is enabled on current machine
|
||||
|
||||
static bool HT_enabled() {
|
||||
|
||||
char CPUString[0x20];
|
||||
int CPUInfo[4] = {-1};
|
||||
int nIds, nLogicalCPU, nCores;
|
||||
|
||||
// Detect CPU producer
|
||||
__cpuid(CPUInfo, 0);
|
||||
nIds = CPUInfo[0];
|
||||
|
||||
memset(CPUString, 0, sizeof(CPUString));
|
||||
memcpy(&CPUString[0], &CPUInfo[1], sizeof(int));
|
||||
memcpy(&CPUString[4], &CPUInfo[3], sizeof(int));
|
||||
memcpy(&CPUString[8], &CPUInfo[2], sizeof(int));
|
||||
|
||||
// Not an Intel CPU or CPUID.4 not supported
|
||||
if (strcmp(CPUString, "GenuineIntel") || nIds < 4)
|
||||
return false;
|
||||
|
||||
// Detect if HT Technology is supported
|
||||
__cpuid(CPUInfo, 1);
|
||||
if (!((CPUInfo[3] >> 28) & 1))
|
||||
return false;
|
||||
|
||||
nLogicalCPU = (CPUInfo[1] >> 16) & 0xFF;
|
||||
|
||||
// Detect number of cores
|
||||
__cpuid(CPUInfo, 4);
|
||||
nCores = 1 + ((CPUInfo[0] >> 26) & 0x3F);
|
||||
|
||||
return nLogicalCPU > nCores;
|
||||
}
|
||||
|
||||
|
||||
/// cpu_count() tries to detect the number of physical CPU cores taking
|
||||
/// in account hyper-threading.
|
||||
|
||||
int cpu_count() {
|
||||
|
||||
return HT_enabled() ? builtin_cpu_count() / 2 : builtin_cpu_count();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
From Beowulf, from Olithink
|
||||
*/
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+80
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -62,9 +62,83 @@ struct MoveStack {
|
||||
int score;
|
||||
};
|
||||
|
||||
// Note that operator< is set up such that std::sort() will sort in descending order
|
||||
// Note that operator< is set up such that sorting will be in descending order
|
||||
inline bool operator<(const MoveStack& f, const MoveStack& s) { return s.score < f.score; }
|
||||
|
||||
// An helper insertion sort implementation
|
||||
template<typename T>
|
||||
inline void insertion_sort(T* firstMove, T* lastMove)
|
||||
{
|
||||
T value;
|
||||
T *cur, *p, *d;
|
||||
|
||||
if (firstMove != lastMove)
|
||||
for (cur = firstMove + 1; cur != lastMove; cur++)
|
||||
{
|
||||
p = d = cur;
|
||||
value = *p--;
|
||||
if (value < *p)
|
||||
{
|
||||
do *d = *p;
|
||||
while (--d != firstMove && value < *--p);
|
||||
*d = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Our dedicated sort in range [firstMove, lastMove), first splits
|
||||
// positive scores from ramining then order seaprately the two sets.
|
||||
template<typename T>
|
||||
inline void sort_moves(T* firstMove, T* lastMove, T** lastPositive)
|
||||
{
|
||||
T tmp;
|
||||
T *p, *d;
|
||||
|
||||
d = lastMove;
|
||||
p = firstMove - 1;
|
||||
|
||||
d->score = -1; // right guard
|
||||
|
||||
// Split positives vs non-positives
|
||||
do {
|
||||
while ((++p)->score > 0);
|
||||
|
||||
if (p != d)
|
||||
{
|
||||
while (--d != p && d->score <= 0);
|
||||
|
||||
tmp = *p;
|
||||
*p = *d;
|
||||
*d = tmp;
|
||||
}
|
||||
|
||||
} while (p != d);
|
||||
|
||||
// Sort just positive scored moves, remaining only when we get there
|
||||
insertion_sort<T>(firstMove, p);
|
||||
*lastPositive = p;
|
||||
}
|
||||
|
||||
// Picks up the best move in range [curMove, lastMove), one per cycle.
|
||||
// It is faster then sorting all the moves in advance when moves are few,
|
||||
// as normally are the possible captures. Note that is not a stable alghoritm.
|
||||
template<typename T>
|
||||
inline T pick_best(T* curMove, T* lastMove)
|
||||
{
|
||||
T bestMove, tmp;
|
||||
|
||||
bestMove = *curMove;
|
||||
while (++curMove != lastMove)
|
||||
{
|
||||
if (*curMove < bestMove)
|
||||
{
|
||||
tmp = *curMove;
|
||||
*curMove = bestMove;
|
||||
bestMove = tmp;
|
||||
}
|
||||
}
|
||||
return bestMove;
|
||||
}
|
||||
|
||||
////
|
||||
//// Inline functions
|
||||
@@ -82,6 +156,10 @@ inline PieceType move_promotion_piece(Move m) {
|
||||
return PieceType((int(m) >> 12) & 7);
|
||||
}
|
||||
|
||||
inline int move_is_special(Move m) {
|
||||
return m & (0x1F << 12);
|
||||
}
|
||||
|
||||
inline int move_is_promotion(Move m) {
|
||||
return m & (7 << 12);
|
||||
}
|
||||
|
||||
+234
-319
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -52,16 +52,12 @@ namespace {
|
||||
EVASION
|
||||
};
|
||||
|
||||
// Functions
|
||||
bool castling_is_check(const Position&, CastlingSide);
|
||||
|
||||
// Helper templates
|
||||
template<CastlingSide Side>
|
||||
MoveStack* generate_castle_moves(const Position&, MoveStack*);
|
||||
|
||||
template<Color Us, MoveType Type>
|
||||
MoveStack* generate_pawn_moves(const Position&, MoveStack*, Bitboard = EmptyBoardBB,
|
||||
Square = SQ_NONE, Bitboard = EmptyBoardBB);
|
||||
MoveStack* generate_pawn_moves(const Position&, MoveStack*, Bitboard, Square);
|
||||
|
||||
// Template generate_piece_moves (captures and non-captures) with specializations and overloads
|
||||
template<PieceType>
|
||||
@@ -71,37 +67,29 @@ namespace {
|
||||
MoveStack* generate_piece_moves<KING>(const Position&, MoveStack*, Color, Bitboard);
|
||||
|
||||
template<PieceType Piece, MoveType Type>
|
||||
inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us) {
|
||||
inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) {
|
||||
|
||||
assert(Piece == PAWN);
|
||||
assert(Type == CAPTURE || Type == NON_CAPTURE);
|
||||
assert(Type == CAPTURE || Type == NON_CAPTURE || Type == EVASION);
|
||||
|
||||
return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m)
|
||||
: generate_pawn_moves<BLACK, Type>(p, m));
|
||||
return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m, t, SQ_NONE)
|
||||
: generate_pawn_moves<BLACK, Type>(p, m, t, SQ_NONE));
|
||||
}
|
||||
|
||||
// Template generate_piece_checks with specializations
|
||||
// Templates for non-capture checks generation
|
||||
|
||||
template<PieceType Piece>
|
||||
MoveStack* generate_discovered_checks(const Position&, MoveStack*, Square);
|
||||
|
||||
template<PieceType>
|
||||
MoveStack* generate_piece_checks(const Position&, MoveStack*, Color, Bitboard, Square);
|
||||
MoveStack* generate_direct_checks(const Position&, MoveStack*, Color, Bitboard, Square);
|
||||
|
||||
template<>
|
||||
inline MoveStack* generate_piece_checks<PAWN>(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) {
|
||||
inline MoveStack* generate_direct_checks<PAWN>(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) {
|
||||
|
||||
return (us == WHITE ? generate_pawn_moves<WHITE, CHECK>(p, m, dc, ksq)
|
||||
: generate_pawn_moves<BLACK, CHECK>(p, m, dc, ksq));
|
||||
}
|
||||
|
||||
// Template generate_piece_evasions with specializations
|
||||
template<PieceType>
|
||||
MoveStack* generate_piece_evasions(const Position&, MoveStack*, Color, Bitboard, Bitboard);
|
||||
|
||||
template<>
|
||||
inline MoveStack* generate_piece_evasions<PAWN>(const Position& p, MoveStack* m,
|
||||
Color us, Bitboard t, Bitboard pnd) {
|
||||
|
||||
return (us == WHITE ? generate_pawn_moves<WHITE, EVASION>(p, m, pnd, SQ_NONE, t)
|
||||
: generate_pawn_moves<BLACK, EVASION>(p, m, pnd, SQ_NONE, t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +113,7 @@ MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
|
||||
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<PAWN, CAPTURE>(pos, mlist, us);
|
||||
mlist = generate_piece_moves<PAWN, CAPTURE>(pos, mlist, us, target);
|
||||
return generate_piece_moves<KING>(pos, mlist, us, target);
|
||||
}
|
||||
|
||||
@@ -141,7 +129,7 @@ MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
|
||||
Color us = pos.side_to_move();
|
||||
Bitboard target = pos.empty_squares();
|
||||
|
||||
mlist = generate_piece_moves<PAWN, NON_CAPTURE>(pos, mlist, us);
|
||||
mlist = generate_piece_moves<PAWN, NON_CAPTURE>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
||||
@@ -152,175 +140,111 @@ MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
|
||||
}
|
||||
|
||||
|
||||
/// generate_non_capture_checks() generates all pseudo-legal non-captures and
|
||||
/// generate_non_capture_checks() generates all pseudo-legal non-captures and knight
|
||||
/// underpromotions that give check. Returns a pointer to the end of the move list.
|
||||
|
||||
MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
|
||||
MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(!pos.is_check());
|
||||
|
||||
Bitboard b, dc;
|
||||
Square from;
|
||||
Color us = pos.side_to_move();
|
||||
Square ksq = pos.king_square(opposite_color(us));
|
||||
|
||||
assert(pos.piece_on(ksq) == piece_of_color_and_type(opposite_color(us), KING));
|
||||
|
||||
// Pieces moves
|
||||
mlist = generate_piece_checks<PAWN>(pos, mlist, us, dc, ksq);
|
||||
mlist = generate_piece_checks<KNIGHT>(pos, mlist, us, dc, ksq);
|
||||
mlist = generate_piece_checks<BISHOP>(pos, mlist, us, dc, ksq);
|
||||
mlist = generate_piece_checks<ROOK>(pos, mlist, us, dc, ksq);
|
||||
mlist = generate_piece_checks<QUEEN>(pos, mlist, us, dc, ksq);
|
||||
mlist = generate_piece_checks<KING>(pos, mlist, us, dc, ksq);
|
||||
// Discovered non-capture checks
|
||||
b = dc = pos.discovered_check_candidates(us);
|
||||
|
||||
// Castling moves that give check. Very rare but nice to have!
|
||||
if ( pos.can_castle_queenside(us)
|
||||
&& (square_rank(ksq) == square_rank(pos.king_square(us)) || square_file(ksq) == FILE_D)
|
||||
&& castling_is_check(pos, QUEEN_SIDE))
|
||||
mlist = generate_castle_moves<QUEEN_SIDE>(pos, mlist);
|
||||
while (b)
|
||||
{
|
||||
from = pop_1st_bit(&b);
|
||||
switch (pos.type_of_piece_on(from))
|
||||
{
|
||||
case PAWN: /* Will be generated togheter with pawns direct checks */ break;
|
||||
case KNIGHT: mlist = generate_discovered_checks<KNIGHT>(pos, mlist, from); break;
|
||||
case BISHOP: mlist = generate_discovered_checks<BISHOP>(pos, mlist, from); break;
|
||||
case ROOK: mlist = generate_discovered_checks<ROOK>(pos, mlist, from); break;
|
||||
case KING: mlist = generate_discovered_checks<KING>(pos, mlist, from); break;
|
||||
default: assert(false); break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( pos.can_castle_kingside(us)
|
||||
&& (square_rank(ksq) == square_rank(pos.king_square(us)) || square_file(ksq) == FILE_F)
|
||||
&& castling_is_check(pos, KING_SIDE))
|
||||
mlist = generate_castle_moves<KING_SIDE>(pos, mlist);
|
||||
|
||||
return mlist;
|
||||
// Direct non-capture checks
|
||||
mlist = generate_direct_checks<PAWN>(pos, mlist, us, dc, ksq);
|
||||
mlist = generate_direct_checks<KNIGHT>(pos, mlist, us, dc, ksq);
|
||||
mlist = generate_direct_checks<BISHOP>(pos, mlist, us, dc, ksq);
|
||||
mlist = generate_direct_checks<ROOK>(pos, mlist, us, dc, ksq);
|
||||
return generate_direct_checks<QUEEN>(pos, mlist, us, dc, ksq);
|
||||
}
|
||||
|
||||
|
||||
/// generate_evasions() generates all check evasions when the side to move is
|
||||
/// in check. Unlike the other move generation functions, this one generates
|
||||
/// only legal moves. Returns a pointer to the end of the move list.
|
||||
/// generate_evasions() generates all pseudo-legal check evasions when
|
||||
/// the side to move is in check. Returns a pointer to the end of the move list.
|
||||
|
||||
MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned) {
|
||||
MoveStack* generate_evasions(const Position& pos, MoveStack* mlist) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(pos.is_check());
|
||||
|
||||
Square from, to;
|
||||
Bitboard b, target;
|
||||
Square from, checksq;
|
||||
int checkersCnt = 0;
|
||||
Color us = pos.side_to_move();
|
||||
Color them = opposite_color(us);
|
||||
Square ksq = pos.king_square(us);
|
||||
Bitboard sliderAttacks = EmptyBoardBB;
|
||||
Bitboard checkers = pos.checkers();
|
||||
Bitboard sliderAttacks = EmptyBoardBB;
|
||||
|
||||
assert(pos.piece_on(ksq) == piece_of_color_and_type(us, KING));
|
||||
|
||||
// The bitboard of occupied pieces without our king
|
||||
Bitboard b_noKing = pos.occupied_squares();
|
||||
clear_bit(&b_noKing, ksq);
|
||||
assert(checkers);
|
||||
|
||||
// Find squares attacked by slider checkers, we will remove
|
||||
// them from the king evasions set so to avoid a couple
|
||||
// of cycles in the slow king evasions legality check loop
|
||||
// and to be able to use attackers_to().
|
||||
Bitboard b = checkers & pos.pieces(BISHOP, QUEEN);
|
||||
while (b)
|
||||
// them from the king evasions set so to early skip known
|
||||
// illegal moves and avoid an useless legality check later.
|
||||
b = checkers;
|
||||
do
|
||||
{
|
||||
from = pop_1st_bit(&b);
|
||||
sliderAttacks |= bishop_attacks_bb(from, b_noKing);
|
||||
}
|
||||
checkersCnt++;
|
||||
checksq = pop_1st_bit(&b);
|
||||
|
||||
b = checkers & pos.pieces(ROOK, QUEEN);
|
||||
while (b)
|
||||
{
|
||||
from = pop_1st_bit(&b);
|
||||
sliderAttacks |= rook_attacks_bb(from, b_noKing);
|
||||
}
|
||||
assert(pos.color_of_piece_on(checksq) == opposite_color(us));
|
||||
|
||||
switch (pos.type_of_piece_on(checksq))
|
||||
{
|
||||
case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break;
|
||||
case ROOK: sliderAttacks |= RookPseudoAttacks[checksq]; break;
|
||||
case QUEEN:
|
||||
// In case of a queen remove also squares attacked in the other direction to
|
||||
// avoid possible illegal moves when queen and king are on adjacent squares.
|
||||
if (direction_is_straight(checksq, ksq))
|
||||
sliderAttacks |= RookPseudoAttacks[checksq] | pos.attacks_from<BISHOP>(checksq);
|
||||
else
|
||||
sliderAttacks |= BishopPseudoAttacks[checksq] | pos.attacks_from<ROOK>(checksq);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (b);
|
||||
|
||||
// Generate evasions for king, capture and non capture moves
|
||||
Bitboard enemy = pos.pieces_of_color(them);
|
||||
Bitboard b1 = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~sliderAttacks;
|
||||
while (b1)
|
||||
{
|
||||
// Note that we can use attackers_to() only because we have already
|
||||
// removed from b1 the squares attacked by slider checkers.
|
||||
to = pop_1st_bit(&b1);
|
||||
if (!(pos.attackers_to(to) & enemy))
|
||||
(*mlist++).move = make_move(ksq, to);
|
||||
}
|
||||
b = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~sliderAttacks;
|
||||
from = ksq;
|
||||
SERIALIZE_MOVES(b);
|
||||
|
||||
// Generate evasions for other pieces only if not double check. We use a
|
||||
// simple bit twiddling hack here rather than calling count_1s in order to
|
||||
// save some time (we know that pos.checkers() has at most two nonzero bits).
|
||||
if (!(checkers & (checkers - 1))) // Only one bit set?
|
||||
{
|
||||
Square checksq = first_1(checkers);
|
||||
// Generate evasions for other pieces only if not double check
|
||||
if (checkersCnt > 1)
|
||||
return mlist;
|
||||
|
||||
assert(pos.color_of_piece_on(checksq) == them);
|
||||
// Find squares where a blocking evasion or a capture of the
|
||||
// checker piece is possible.
|
||||
target = squares_between(checksq, ksq) | checkers;
|
||||
|
||||
// Generate captures of the checking piece
|
||||
|
||||
// Pawn captures
|
||||
b1 = pos.attacks_from<PAWN>(checksq, them) & pos.pieces(PAWN, us) & ~pinned;
|
||||
while (b1)
|
||||
{
|
||||
from = pop_1st_bit(&b1);
|
||||
if (relative_rank(us, checksq) == RANK_8)
|
||||
{
|
||||
(*mlist++).move = make_promotion_move(from, checksq, QUEEN);
|
||||
(*mlist++).move = make_promotion_move(from, checksq, ROOK);
|
||||
(*mlist++).move = make_promotion_move(from, checksq, BISHOP);
|
||||
(*mlist++).move = make_promotion_move(from, checksq, KNIGHT);
|
||||
} else
|
||||
(*mlist++).move = make_move(from, checksq);
|
||||
}
|
||||
|
||||
// Pieces captures
|
||||
b1 = ( (pos.attacks_from<KNIGHT>(checksq) & pos.pieces(KNIGHT, us))
|
||||
| (pos.attacks_from<BISHOP>(checksq) & pos.pieces(BISHOP, QUEEN, us))
|
||||
| (pos.attacks_from<ROOK>(checksq) & pos.pieces(ROOK, QUEEN, us)) ) & ~pinned;
|
||||
|
||||
while (b1)
|
||||
{
|
||||
from = pop_1st_bit(&b1);
|
||||
(*mlist++).move = make_move(from, checksq);
|
||||
}
|
||||
|
||||
// Blocking check evasions are possible only if the checking piece is a slider
|
||||
if (sliderAttacks)
|
||||
{
|
||||
Bitboard blockSquares = squares_between(checksq, ksq);
|
||||
|
||||
assert((pos.occupied_squares() & blockSquares) == EmptyBoardBB);
|
||||
|
||||
if (blockSquares)
|
||||
{
|
||||
mlist = generate_piece_evasions<PAWN>(pos, mlist, us, blockSquares, pinned);
|
||||
mlist = generate_piece_evasions<KNIGHT>(pos, mlist, us, blockSquares, pinned);
|
||||
mlist = generate_piece_evasions<BISHOP>(pos, mlist, us, blockSquares, pinned);
|
||||
mlist = generate_piece_evasions<ROOK>(pos, mlist, us, blockSquares, pinned);
|
||||
mlist = generate_piece_evasions<QUEEN>(pos, mlist, us, blockSquares, pinned);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, the special case of en passant captures. An en passant
|
||||
// capture can only be a check evasion if the check is not a discovered
|
||||
// check. If pos.ep_square() is set, the last move made must have been
|
||||
// a double pawn push. If, furthermore, the checking piece is a pawn,
|
||||
// an en passant check evasion may be possible.
|
||||
if (pos.ep_square() != SQ_NONE && (checkers & pos.pieces(PAWN, them)))
|
||||
{
|
||||
to = pos.ep_square();
|
||||
b1 = pos.attacks_from<PAWN>(to, them) & pos.pieces(PAWN, us);
|
||||
|
||||
// The checking pawn cannot be a discovered (bishop) check candidate
|
||||
// otherwise we were in check also before last double push move.
|
||||
assert(!bit_is_set(pos.discovered_check_candidates(them), checksq));
|
||||
assert(count_1s(b1) == 1 || count_1s(b1) == 2);
|
||||
|
||||
b1 &= ~pinned;
|
||||
while (b1)
|
||||
{
|
||||
from = pop_1st_bit(&b1);
|
||||
// Move is always legal because checking pawn is not a discovered
|
||||
// check candidate and our capturing pawn has been already tested
|
||||
// against pinned pieces.
|
||||
(*mlist++).move = make_ep_move(from, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mlist;
|
||||
mlist = generate_piece_moves<PAWN, EVASION>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
||||
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
||||
return generate_piece_moves<QUEEN>(pos, mlist, us, target);
|
||||
}
|
||||
|
||||
|
||||
@@ -332,24 +256,25 @@ MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLega
|
||||
|
||||
assert(pos.is_ok());
|
||||
|
||||
MoveStack *last, *cur = mlist;
|
||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||
|
||||
if (pos.is_check())
|
||||
return generate_evasions(pos, mlist, pinned);
|
||||
|
||||
// Generate pseudo-legal moves
|
||||
MoveStack* last = generate_captures(pos, mlist);
|
||||
last = generate_noncaptures(pos, last);
|
||||
if (pos.is_check())
|
||||
last = generate_evasions(pos, mlist);
|
||||
else
|
||||
last = generate_noncaptures(pos, generate_captures(pos, mlist));
|
||||
|
||||
if (pseudoLegal)
|
||||
return last;
|
||||
|
||||
// Remove illegal moves from the list
|
||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
||||
if (!pos.pl_move_is_legal(cur->move, pinned))
|
||||
{
|
||||
while (cur != last)
|
||||
if (pos.pl_move_is_legal(cur->move, pinned))
|
||||
cur++;
|
||||
else
|
||||
cur->move = (--last)->move;
|
||||
cur--;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
@@ -361,10 +286,11 @@ MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLega
|
||||
bool move_is_legal(const Position& pos, const Move m) {
|
||||
|
||||
MoveStack mlist[256];
|
||||
MoveStack* last = generate_moves(pos, mlist, true);
|
||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
||||
MoveStack *cur, *last = generate_moves(pos, mlist, true);
|
||||
|
||||
for (cur = mlist; cur != last; cur++)
|
||||
if (cur->move == m)
|
||||
return pos.pl_move_is_legal(m);
|
||||
return pos.pl_move_is_legal(m, pos.pinned_pieces(pos.side_to_move()));
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -372,25 +298,23 @@ bool move_is_legal(const Position& pos, const Move m) {
|
||||
|
||||
/// Fast version of move_is_legal() that takes a position a move and a
|
||||
/// bitboard of pinned pieces as input, and tests whether the move is legal.
|
||||
/// This version must only be used when the side to move is not in check.
|
||||
|
||||
bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(!pos.is_check());
|
||||
assert(move_is_ok(m));
|
||||
assert(pinned == pos.pinned_pieces(pos.side_to_move()));
|
||||
|
||||
// Use a slower but simpler function for uncommon cases
|
||||
if (move_is_ep(m) || move_is_castle(m))
|
||||
return move_is_legal(pos, m);
|
||||
|
||||
Color us = pos.side_to_move();
|
||||
Color them = opposite_color(us);
|
||||
Square from = move_from(m);
|
||||
Square to = move_to(m);
|
||||
Piece pc = pos.piece_on(from);
|
||||
|
||||
// Use a slower but simpler function for uncommon cases
|
||||
if (move_is_ep(m) || move_is_castle(m))
|
||||
return move_is_legal(pos, m);
|
||||
|
||||
// If the from square is not occupied by a piece belonging to the side to
|
||||
// move, the move is obviously not legal.
|
||||
if (color_of_piece(pc) != us)
|
||||
@@ -459,13 +383,13 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
||||
return false;
|
||||
}
|
||||
// The move is pseudo-legal, check if it is also legal
|
||||
return pos.pl_move_is_legal(m, pinned);
|
||||
return pos.is_check() ? pos.pl_move_is_evasion(m, pinned) : pos.pl_move_is_legal(m, pinned);
|
||||
}
|
||||
|
||||
// Luckly we can handle all the other pieces in one go
|
||||
return ( bit_is_set(pos.attacks_from(pc, from), to)
|
||||
&& pos.pl_move_is_legal(m, pinned)
|
||||
&& !move_is_promotion(m));
|
||||
return bit_is_set(pos.attacks_from(pc, from), to)
|
||||
&& (pos.is_check() ? pos.pl_move_is_evasion(m, pinned) : pos.pl_move_is_legal(m, pinned))
|
||||
&& !move_is_promotion(m);
|
||||
}
|
||||
|
||||
|
||||
@@ -474,8 +398,8 @@ namespace {
|
||||
template<PieceType Piece>
|
||||
MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) {
|
||||
|
||||
Square from;
|
||||
Bitboard b;
|
||||
Square from;
|
||||
const Square* ptr = pos.piece_list_begin(us, Piece);
|
||||
|
||||
while ((from = *ptr++) != SQ_NONE)
|
||||
@@ -497,24 +421,6 @@ namespace {
|
||||
return mlist;
|
||||
}
|
||||
|
||||
template<PieceType Piece>
|
||||
MoveStack* generate_piece_evasions(const Position& pos, MoveStack* mlist,
|
||||
Color us, Bitboard target, Bitboard pinned) {
|
||||
Square from;
|
||||
Bitboard b;
|
||||
const Square* ptr = pos.piece_list_begin(us, Piece);
|
||||
|
||||
while ((from = *ptr++) != SQ_NONE)
|
||||
{
|
||||
if (pinned && bit_is_set(pinned, from))
|
||||
continue;
|
||||
|
||||
b = pos.attacks_from<Piece>(from) & target;
|
||||
SERIALIZE_MOVES(b);
|
||||
}
|
||||
return mlist;
|
||||
}
|
||||
|
||||
template<Color Us, SquareDelta Direction>
|
||||
inline Bitboard move_pawns(Bitboard p) {
|
||||
|
||||
@@ -528,8 +434,8 @@ namespace {
|
||||
return p;
|
||||
}
|
||||
|
||||
template<Color Us, SquareDelta Diagonal>
|
||||
MoveStack* generate_pawn_diagonal_captures(MoveStack* mlist, Bitboard pawns, Bitboard enemyPieces, bool promotion) {
|
||||
template<Color Us, MoveType Type, SquareDelta Diagonal>
|
||||
inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard enemyPieces) {
|
||||
|
||||
// Calculate our parametrized parameters at compile time
|
||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||
@@ -538,136 +444,152 @@ namespace {
|
||||
const SquareDelta TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW);
|
||||
const SquareDelta TTDELTA_NE = (Diagonal == DELTA_NE ? TDELTA_NE : TDELTA_NW);
|
||||
|
||||
Bitboard b1, b2;
|
||||
Square to;
|
||||
|
||||
// Captures in the a1-h8 (a8-h1 for black) diagonal or in the h1-a8 (h8-a1 for black)
|
||||
Bitboard b1 = move_pawns<Us, Diagonal>(pawns) & ~TFileABB & enemyPieces;
|
||||
b1 = move_pawns<Us, Diagonal>(pawns) & ~TFileABB & enemyPieces;
|
||||
|
||||
// Capturing promotions
|
||||
if (promotion)
|
||||
// Capturing promotions and under-promotions
|
||||
if (b1 & TRank8BB)
|
||||
{
|
||||
Bitboard b2 = b1 & TRank8BB;
|
||||
b2 = b1 & TRank8BB;
|
||||
b1 &= ~TRank8BB;
|
||||
while (b2)
|
||||
{
|
||||
to = pop_1st_bit(&b2);
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, QUEEN);
|
||||
|
||||
if (Type == CAPTURE || Type == EVASION)
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, QUEEN);
|
||||
|
||||
if (Type == NON_CAPTURE || Type == EVASION)
|
||||
{
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, ROOK);
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, BISHOP);
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, KNIGHT);
|
||||
}
|
||||
|
||||
// This is the only possible under promotion that can give a check
|
||||
// not already included in the queen-promotion. It is not sure that
|
||||
// the promoted knight will give check, but it doesn't worth to verify.
|
||||
if (Type == CHECK)
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, KNIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
// Capturing non-promotions
|
||||
SERIALIZE_MOVES_D(b1, -TTDELTA_NE);
|
||||
// Serialize standard captures
|
||||
if (Type == CAPTURE || Type == EVASION)
|
||||
SERIALIZE_MOVES_D(b1, -TTDELTA_NE);
|
||||
|
||||
return mlist;
|
||||
}
|
||||
|
||||
template<Color Us, MoveType Type>
|
||||
MoveStack* generate_pawn_moves(const Position& pos, MoveStack* mlist, Bitboard dcp,
|
||||
Square ksq, Bitboard blockSquares) {
|
||||
MoveStack* generate_pawn_moves(const Position& pos, MoveStack* mlist, Bitboard target, Square ksq) {
|
||||
|
||||
// Calculate our parametrized parameters at compile time
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
const SquareDelta TDELTA_NE = (Us == WHITE ? DELTA_NE : DELTA_SE);
|
||||
const SquareDelta TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW);
|
||||
const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S);
|
||||
|
||||
Bitboard b1, b2, dcPawns1, dcPawns2;
|
||||
Square to;
|
||||
Bitboard pawns = (Type == EVASION ? pos.pieces(PAWN, Us) & ~dcp : pos.pieces(PAWN, Us));
|
||||
bool possiblePromotion = pawns & TRank7BB;
|
||||
Bitboard b1, b2, enemyPieces, emptySquares;
|
||||
Bitboard pawns = pos.pieces(PAWN, Us);
|
||||
|
||||
if (Type == CAPTURE)
|
||||
// Standard captures and capturing promotions and underpromotions
|
||||
if (Type == CAPTURE || Type == EVASION || (pawns & TRank7BB))
|
||||
{
|
||||
// Standard captures and capturing promotions in both directions
|
||||
Bitboard enemyPieces = pos.pieces_of_color(opposite_color(Us));
|
||||
mlist = generate_pawn_diagonal_captures<Us, DELTA_NE>(mlist, pawns, enemyPieces, possiblePromotion);
|
||||
mlist = generate_pawn_diagonal_captures<Us, DELTA_NW>(mlist, pawns, enemyPieces, possiblePromotion);
|
||||
enemyPieces = (Type == CAPTURE ? target : pos.pieces_of_color(opposite_color(Us)));
|
||||
|
||||
if (Type == EVASION)
|
||||
enemyPieces &= target; // Capture only the checker piece
|
||||
|
||||
mlist = generate_pawn_captures<Us, Type, DELTA_NE>(mlist, pawns, enemyPieces);
|
||||
mlist = generate_pawn_captures<Us, Type, DELTA_NW>(mlist, pawns, enemyPieces);
|
||||
}
|
||||
|
||||
if (possiblePromotion)
|
||||
// Non-capturing promotions and underpromotions
|
||||
if (pawns & TRank7BB)
|
||||
{
|
||||
// When generating checks consider under-promotion moves (both captures
|
||||
// and non captures) only if can give a discovery check. Note that dcp
|
||||
// is dc bitboard or pinned bitboard when Type == EVASION.
|
||||
Bitboard pp = (Type == CHECK ? pawns & dcp : pawns);
|
||||
b1 = move_pawns<Us, DELTA_N>(pawns) & TRank8BB & pos.empty_squares();
|
||||
|
||||
if (Type != EVASION && Type != CAPTURE)
|
||||
{
|
||||
Bitboard enemyPieces = pos.pieces_of_color(opposite_color(Us));
|
||||
|
||||
// Underpromotion captures in the a1-h8 (a8-h1 for black) direction
|
||||
b1 = move_pawns<Us, DELTA_NE>(pp) & ~FileABB & enemyPieces & TRank8BB;
|
||||
while (b1)
|
||||
{
|
||||
to = pop_1st_bit(&b1);
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_NE, to, ROOK);
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_NE, to, BISHOP);
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_NE, to, KNIGHT);
|
||||
}
|
||||
|
||||
// Underpromotion captures in the h1-a8 (h8-a1 for black) direction
|
||||
b1 = move_pawns<Us, DELTA_NW>(pp) & ~FileHBB & enemyPieces & TRank8BB;
|
||||
while (b1)
|
||||
{
|
||||
to = pop_1st_bit(&b1);
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_NW, to, ROOK);
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_NW, to, BISHOP);
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_NW, to, KNIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
// Underpromotion pawn pushes. Also queen promotions for evasions and captures.
|
||||
b1 = move_pawns<Us, DELTA_N>(pp) & TRank8BB;
|
||||
b1 &= (Type == EVASION ? blockSquares : pos.empty_squares());
|
||||
if (Type == EVASION)
|
||||
b1 &= target; // Only blocking promotion pushes
|
||||
|
||||
while (b1)
|
||||
{
|
||||
to = pop_1st_bit(&b1);
|
||||
if (Type == EVASION || Type == CAPTURE)
|
||||
|
||||
if (Type == CAPTURE || Type == EVASION)
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, QUEEN);
|
||||
|
||||
if (Type != CAPTURE)
|
||||
if (Type == NON_CAPTURE || Type == EVASION)
|
||||
{
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, ROOK);
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, BISHOP);
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT);
|
||||
}
|
||||
|
||||
// This is the only possible under promotion that can give a check
|
||||
// not already included in the queen-promotion.
|
||||
if (Type == CHECK && bit_is_set(pos.attacks_from<KNIGHT>(to), pos.king_square(Them)))
|
||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
// Standard pawn pushes and double pushes
|
||||
if (Type != CAPTURE)
|
||||
{
|
||||
Bitboard emptySquares = pos.empty_squares();
|
||||
dcPawns1 = dcPawns2 = EmptyBoardBB;
|
||||
if (Type == CHECK && (pawns & dcp))
|
||||
{
|
||||
// Pawn moves which gives discovered check. This is possible only if the
|
||||
// pawn is not on the same file as the enemy king, because we don't
|
||||
// generate captures.
|
||||
dcPawns1 = move_pawns<Us, DELTA_N>(pawns & dcp & ~file_bb(ksq)) & emptySquares & ~TRank8BB;
|
||||
dcPawns2 = move_pawns<Us, DELTA_N>(dcPawns1 & TRank3BB) & emptySquares;
|
||||
}
|
||||
emptySquares = (Type == NON_CAPTURE ? target : pos.empty_squares());
|
||||
|
||||
// Single pawn pushes
|
||||
// Single and double pawn pushes
|
||||
b1 = move_pawns<Us, DELTA_N>(pawns) & emptySquares & ~TRank8BB;
|
||||
b2 = (Type == CHECK ? (b1 & pos.attacks_from<PAWN>(ksq, Them)) | dcPawns1 :
|
||||
(Type == EVASION ? b1 & blockSquares : b1));
|
||||
SERIALIZE_MOVES_D(b2, -TDELTA_N);
|
||||
b2 = move_pawns<Us, DELTA_N>(b1 & TRank3BB) & emptySquares;
|
||||
|
||||
// Double pawn pushes
|
||||
b1 = move_pawns<Us, DELTA_N>(b1 & TRank3BB) & emptySquares;
|
||||
b2 = (Type == CHECK ? (b1 & pos.attacks_from<PAWN>(ksq, Them)) | dcPawns2 :
|
||||
(Type == EVASION ? b1 & blockSquares : b1));
|
||||
// Filter out unwanted pushes according to the move type
|
||||
if (Type == EVASION)
|
||||
{
|
||||
b1 &= target;
|
||||
b2 &= target;
|
||||
}
|
||||
else if (Type == CHECK)
|
||||
{
|
||||
// Pawn moves which give direct cheks
|
||||
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||
|
||||
// Pawn moves which gives discovered check. This is possible only if
|
||||
// the pawn is not on the same file as the enemy king, because we
|
||||
// don't generate captures.
|
||||
if (pawns & target) // For CHECK type target is dc bitboard
|
||||
{
|
||||
Bitboard dc1 = move_pawns<Us, DELTA_N>(pawns & target & ~file_bb(ksq)) & emptySquares & ~TRank8BB;
|
||||
Bitboard dc2 = move_pawns<Us, DELTA_N>(dc1 & TRank3BB) & emptySquares;
|
||||
|
||||
b1 |= dc1;
|
||||
b2 |= dc2;
|
||||
}
|
||||
}
|
||||
SERIALIZE_MOVES_D(b1, -TDELTA_N);
|
||||
SERIALIZE_MOVES_D(b2, -TDELTA_N -TDELTA_N);
|
||||
}
|
||||
else if (pos.ep_square() != SQ_NONE) // En passant captures
|
||||
|
||||
// En passant captures
|
||||
if ((Type == CAPTURE || Type == EVASION) && pos.ep_square() != SQ_NONE)
|
||||
{
|
||||
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
|
||||
assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
|
||||
|
||||
// An en passant capture can be an evasion only if the checking piece
|
||||
// is the double pushed pawn and so is in the target. Otherwise this
|
||||
// is a discovery check and we are forced to do otherwise.
|
||||
if (Type == EVASION && !bit_is_set(target, pos.ep_square() - TDELTA_N))
|
||||
return mlist;
|
||||
|
||||
b1 = pawns & pos.attacks_from<PAWN>(pos.ep_square(), Them);
|
||||
|
||||
assert(b1 != EmptyBoardBB);
|
||||
|
||||
while (b1)
|
||||
@@ -680,43 +602,49 @@ namespace {
|
||||
}
|
||||
|
||||
template<PieceType Piece>
|
||||
MoveStack* generate_piece_checks(const Position& pos, MoveStack* mlist, Color us,
|
||||
MoveStack* generate_discovered_checks(const Position& pos, MoveStack* mlist, Square from) {
|
||||
|
||||
assert(Piece != QUEEN);
|
||||
|
||||
Bitboard b = pos.attacks_from<Piece>(from) & pos.empty_squares();
|
||||
if (Piece == KING)
|
||||
{
|
||||
Square ksq = pos.king_square(opposite_color(pos.side_to_move()));
|
||||
b &= ~QueenPseudoAttacks[ksq];
|
||||
}
|
||||
SERIALIZE_MOVES(b);
|
||||
return mlist;
|
||||
}
|
||||
|
||||
template<PieceType Piece>
|
||||
MoveStack* generate_direct_checks(const Position& pos, MoveStack* mlist, Color us,
|
||||
Bitboard dc, Square ksq) {
|
||||
assert(Piece != KING);
|
||||
|
||||
Bitboard target = pos.pieces(Piece, us);
|
||||
Bitboard checkSqs, b;
|
||||
Square from;
|
||||
const Square* ptr = pos.piece_list_begin(us, Piece);
|
||||
|
||||
// Discovered non-capture checks
|
||||
Bitboard b = target & dc;
|
||||
if ((from = *ptr++) == SQ_NONE)
|
||||
return mlist;
|
||||
|
||||
assert(Piece != QUEEN || !b);
|
||||
checkSqs = pos.attacks_from<Piece>(ksq) & pos.empty_squares();
|
||||
|
||||
while (b)
|
||||
do
|
||||
{
|
||||
Square from = pop_1st_bit(&b);
|
||||
Bitboard bb = pos.attacks_from<Piece>(from) & pos.empty_squares();
|
||||
if (Piece == KING)
|
||||
bb &= ~QueenPseudoAttacks[ksq];
|
||||
if ( (Piece == QUEEN && !(QueenPseudoAttacks[from] & checkSqs))
|
||||
|| (Piece == ROOK && !(RookPseudoAttacks[from] & checkSqs))
|
||||
|| (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
|
||||
continue;
|
||||
|
||||
SERIALIZE_MOVES(bb);
|
||||
}
|
||||
if (dc && bit_is_set(dc, from))
|
||||
continue;
|
||||
|
||||
// Direct non-capture checks
|
||||
b = target & ~dc;
|
||||
Bitboard checkSqs = pos.attacks_from<Piece>(ksq) & pos.empty_squares();
|
||||
if (Piece != KING && checkSqs)
|
||||
{
|
||||
while (b)
|
||||
{
|
||||
Square from = pop_1st_bit(&b);
|
||||
if ( (Piece == QUEEN && !(QueenPseudoAttacks[from] & checkSqs))
|
||||
|| (Piece == ROOK && !(RookPseudoAttacks[from] & checkSqs))
|
||||
|| (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
|
||||
continue;
|
||||
b = pos.attacks_from<Piece>(from) & checkSqs;
|
||||
SERIALIZE_MOVES(b);
|
||||
|
||||
} while ((from = *ptr++) != SQ_NONE);
|
||||
|
||||
Bitboard bb = pos.attacks_from<Piece>(from) & checkSqs;
|
||||
SERIALIZE_MOVES(bb);
|
||||
}
|
||||
}
|
||||
return mlist;
|
||||
}
|
||||
|
||||
@@ -762,17 +690,4 @@ namespace {
|
||||
}
|
||||
return mlist;
|
||||
}
|
||||
|
||||
bool castling_is_check(const Position& pos, CastlingSide side) {
|
||||
|
||||
// After castling opponent king is attacked by the castled rook?
|
||||
File rookFile = (side == QUEEN_SIDE ? FILE_D : FILE_F);
|
||||
Color us = pos.side_to_move();
|
||||
Square ksq = pos.king_square(us);
|
||||
Bitboard occ = pos.occupied_squares();
|
||||
|
||||
clear_bit(&occ, ksq); // Remove our king from the board
|
||||
Square rsq = make_square(rookFile, square_rank(ksq));
|
||||
return bit_is_set(rook_attacks_bb(rsq, occ), pos.king_square(opposite_color(us)));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -34,8 +34,8 @@
|
||||
|
||||
extern MoveStack* generate_captures(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc);
|
||||
extern MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
|
||||
extern MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_evasions(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLegal = false);
|
||||
extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned);
|
||||
extern bool move_is_legal(const Position& pos, const Move m);
|
||||
|
||||
+76
-68
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -23,7 +23,6 @@
|
||||
//// Includes
|
||||
////
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "history.h"
|
||||
@@ -53,7 +52,7 @@ namespace {
|
||||
|
||||
CACHE_LINE_ALIGNMENT
|
||||
const uint8_t MainSearchPhaseTable[] = { PH_TT_MOVES, PH_GOOD_CAPTURES, PH_KILLERS, PH_NONCAPTURES, PH_BAD_CAPTURES, PH_STOP};
|
||||
const uint8_t EvasionsPhaseTable[] = { PH_EVASIONS, PH_STOP};
|
||||
const uint8_t EvasionsPhaseTable[] = { PH_TT_MOVES, PH_EVASIONS, PH_STOP};
|
||||
const uint8_t QsearchWithChecksPhaseTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_QCHECKS, PH_STOP};
|
||||
const uint8_t QsearchWithoutChecksPhaseTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_STOP};
|
||||
}
|
||||
@@ -72,13 +71,15 @@ namespace {
|
||||
/// move ordering is at the current node.
|
||||
|
||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
||||
const History& h, SearchStack* ss) : pos(p), H(h) {
|
||||
const History& h, SearchStack* ss, Value beta) : pos(p), H(h) {
|
||||
int searchTT = ttm;
|
||||
ttMoves[0].move = ttm;
|
||||
finished = false;
|
||||
lastBadCapture = badCaptures;
|
||||
badCaptureThreshold = 0;
|
||||
|
||||
if (ss)
|
||||
pinned = p.pinned_pieces(pos.side_to_move());
|
||||
|
||||
if (ss && !p.is_check())
|
||||
{
|
||||
ttMoves[1].move = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller;
|
||||
searchTT |= ttMoves[1].move;
|
||||
@@ -87,21 +88,30 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
||||
} else
|
||||
ttMoves[1].move = killers[0].move = killers[1].move = MOVE_NONE;
|
||||
|
||||
Color us = pos.side_to_move();
|
||||
|
||||
dc = p.discovered_check_candidates(us);
|
||||
pinned = p.pinned_pieces(us);
|
||||
|
||||
if (p.is_check())
|
||||
phasePtr = EvasionsPhaseTable;
|
||||
else if (d > Depth(0))
|
||||
phasePtr = MainSearchPhaseTable + !searchTT;
|
||||
else if (d == Depth(0))
|
||||
phasePtr = QsearchWithChecksPhaseTable + !searchTT;
|
||||
else
|
||||
phasePtr = QsearchWithoutChecksPhaseTable + !searchTT;
|
||||
{
|
||||
// Consider sligtly negative captures as good if at low
|
||||
// depth and far from beta.
|
||||
if (ss && ss->eval < beta - PawnValueMidgame && d < 3 * OnePly)
|
||||
badCaptureThreshold = -PawnValueMidgame;
|
||||
|
||||
phasePtr--;
|
||||
phasePtr = MainSearchPhaseTable;
|
||||
} else if (d == Depth(0))
|
||||
phasePtr = QsearchWithChecksPhaseTable;
|
||||
else
|
||||
{
|
||||
phasePtr = QsearchWithoutChecksPhaseTable;
|
||||
|
||||
// Skip TT move if is not a capture or a promotion, this avoids
|
||||
// qsearch tree explosion due to a possible perpetual check or
|
||||
// similar rare cases when TT table is full.
|
||||
if (ttm != MOVE_NONE && !pos.move_is_capture_or_promotion(ttm))
|
||||
searchTT = ttMoves[0].move = MOVE_NONE;
|
||||
}
|
||||
|
||||
phasePtr += !searchTT - 1;
|
||||
go_next_phase();
|
||||
}
|
||||
|
||||
@@ -123,7 +133,6 @@ void MovePicker::go_next_phase() {
|
||||
case PH_GOOD_CAPTURES:
|
||||
lastMove = generate_captures(pos, moves);
|
||||
score_captures();
|
||||
std::sort(moves, lastMove);
|
||||
return;
|
||||
|
||||
case PH_KILLERS:
|
||||
@@ -134,7 +143,7 @@ void MovePicker::go_next_phase() {
|
||||
case PH_NONCAPTURES:
|
||||
lastMove = generate_noncaptures(pos, moves);
|
||||
score_noncaptures();
|
||||
std::sort(moves, lastMove);
|
||||
sort_moves(moves, lastMove, &lastGoodNonCapture);
|
||||
return;
|
||||
|
||||
case PH_BAD_CAPTURES:
|
||||
@@ -142,29 +151,26 @@ void MovePicker::go_next_phase() {
|
||||
// to get SEE move ordering.
|
||||
curMove = badCaptures;
|
||||
lastMove = lastBadCapture;
|
||||
std::sort(badCaptures, lastMove);
|
||||
return;
|
||||
|
||||
case PH_EVASIONS:
|
||||
assert(pos.is_check());
|
||||
lastMove = generate_evasions(pos, moves, pinned);
|
||||
score_evasions();
|
||||
std::sort(moves, lastMove);
|
||||
lastMove = generate_evasions(pos, moves);
|
||||
score_evasions_or_checks();
|
||||
return;
|
||||
|
||||
case PH_QCAPTURES:
|
||||
lastMove = generate_captures(pos, moves);
|
||||
score_captures();
|
||||
std::sort(moves, lastMove);
|
||||
return;
|
||||
|
||||
case PH_QCHECKS:
|
||||
// Perhaps we should order moves move here? FIXME
|
||||
lastMove = generate_non_capture_checks(pos, moves, dc);
|
||||
lastMove = generate_non_capture_checks(pos, moves);
|
||||
score_evasions_or_checks();
|
||||
return;
|
||||
|
||||
case PH_STOP:
|
||||
lastMove = curMove + 1; // hack to be friendly for get_next_move()
|
||||
lastMove = curMove + 1; // Avoids another go_next_phase() call
|
||||
return;
|
||||
|
||||
default:
|
||||
@@ -202,8 +208,8 @@ void MovePicker::score_captures() {
|
||||
if (move_is_promotion(m))
|
||||
cur->score = QueenValueMidgame;
|
||||
else
|
||||
cur->score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
||||
-int(pos.type_of_piece_on(move_from(m)));
|
||||
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
||||
- pos.type_of_piece_on(move_from(m));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,29 +230,36 @@ void MovePicker::score_noncaptures() {
|
||||
piece = pos.piece_on(from);
|
||||
hs = H.move_ordering_score(piece, to);
|
||||
|
||||
// Ensure history is always preferred to pst
|
||||
// Ensure history has always highest priority
|
||||
if (hs > 0)
|
||||
hs += 1000;
|
||||
hs += 10000;
|
||||
|
||||
// pst based scoring
|
||||
cur->score = hs + pos.pst_delta<Position::MidGame>(piece, from, to);
|
||||
// Gain table based scoring
|
||||
cur->score = hs + 16 * H.gain(piece, to);
|
||||
}
|
||||
}
|
||||
|
||||
void MovePicker::score_evasions() {
|
||||
|
||||
void MovePicker::score_evasions_or_checks() {
|
||||
// Try good captures ordered by MVV/LVA, then non-captures if
|
||||
// destination square is not under attack, ordered by history
|
||||
// value, and at the end bad-captures and non-captures with a
|
||||
// negative SEE. This last group is ordered by the SEE score.
|
||||
Move m;
|
||||
int seeScore;
|
||||
|
||||
// Skip if we don't have at least two moves to order
|
||||
if (lastMove < moves + 2)
|
||||
return;
|
||||
|
||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||
{
|
||||
m = cur->move;
|
||||
if (m == ttMoves[0].move)
|
||||
cur->score = 2 * HistoryMax;
|
||||
else if (!pos.square_is_empty(move_to(m)))
|
||||
{
|
||||
int seeScore = pos.see(m);
|
||||
cur->score = seeScore + (seeScore >= 0 ? HistoryMax : 0);
|
||||
} else
|
||||
if ((seeScore = pos.see_sign(m)) < 0)
|
||||
cur->score = seeScore - HistoryMax; // Be sure are at the bottom
|
||||
else if (pos.move_is_capture(m))
|
||||
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
||||
- pos.type_of_piece_on(move_from(m)) + HistoryMax;
|
||||
else
|
||||
cur->score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
|
||||
}
|
||||
}
|
||||
@@ -256,36 +269,35 @@ void MovePicker::score_evasions() {
|
||||
/// are no more moves left.
|
||||
/// It picks the move with the biggest score from a list of generated moves taking
|
||||
/// care not to return the tt move if has already been searched previously.
|
||||
/// Note that this function is not thread safe so should be lock protected by
|
||||
/// caller when accessed through a shared MovePicker object.
|
||||
|
||||
Move MovePicker::get_next_move() {
|
||||
|
||||
assert(!pos.is_check() || *phasePtr == PH_EVASIONS || *phasePtr == PH_STOP);
|
||||
assert( pos.is_check() || *phasePtr != PH_EVASIONS);
|
||||
|
||||
Move move;
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (curMove != lastMove)
|
||||
{
|
||||
move = (curMove++)->move;
|
||||
|
||||
switch (phase) {
|
||||
|
||||
case PH_TT_MOVES:
|
||||
move = (curMove++)->move;
|
||||
if ( move != MOVE_NONE
|
||||
&& move_is_legal(pos, move, pinned))
|
||||
return move;
|
||||
break;
|
||||
|
||||
case PH_GOOD_CAPTURES:
|
||||
move = pick_best(curMove++, lastMove).move;
|
||||
if ( move != ttMoves[0].move
|
||||
&& move != ttMoves[1].move
|
||||
&& pos.pl_move_is_legal(move, pinned))
|
||||
{
|
||||
// Check for a non negative SEE now
|
||||
int seeValue = pos.see_sign(move);
|
||||
if (seeValue >= 0)
|
||||
if (seeValue >= badCaptureThreshold)
|
||||
return move;
|
||||
|
||||
// Losing capture, move it to the badCaptures[] array, note
|
||||
@@ -298,6 +310,7 @@ Move MovePicker::get_next_move() {
|
||||
break;
|
||||
|
||||
case PH_KILLERS:
|
||||
move = (curMove++)->move;
|
||||
if ( move != MOVE_NONE
|
||||
&& move != ttMoves[0].move
|
||||
&& move != ttMoves[1].move
|
||||
@@ -307,6 +320,12 @@ Move MovePicker::get_next_move() {
|
||||
break;
|
||||
|
||||
case PH_NONCAPTURES:
|
||||
|
||||
// Sort negative scored moves only when we get there
|
||||
if (curMove == lastGoodNonCapture)
|
||||
insertion_sort(lastGoodNonCapture, lastMove);
|
||||
|
||||
move = (curMove++)->move;
|
||||
if ( move != ttMoves[0].move
|
||||
&& move != ttMoves[1].move
|
||||
&& move != killers[0].move
|
||||
@@ -315,13 +334,20 @@ Move MovePicker::get_next_move() {
|
||||
return move;
|
||||
break;
|
||||
|
||||
case PH_EVASIONS:
|
||||
case PH_BAD_CAPTURES:
|
||||
move = pick_best(curMove++, lastMove).move;
|
||||
return move;
|
||||
|
||||
case PH_EVASIONS:
|
||||
case PH_QCAPTURES:
|
||||
move = pick_best(curMove++, lastMove).move;
|
||||
if ( move != ttMoves[0].move
|
||||
&& pos.pl_move_is_legal(move, pinned))
|
||||
return move;
|
||||
break;
|
||||
|
||||
case PH_QCHECKS:
|
||||
// Maybe postpone the legality check until after futility pruning?
|
||||
move = (curMove++)->move;
|
||||
if ( move != ttMoves[0].move
|
||||
&& pos.pl_move_is_legal(move, pinned))
|
||||
return move;
|
||||
@@ -339,21 +365,3 @@ Move MovePicker::get_next_move() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of get_next_move() which takes a lock as a parameter, used to
|
||||
/// prevent multiple threads from picking the same move at a split point.
|
||||
|
||||
Move MovePicker::get_next_move(Lock &lock) {
|
||||
|
||||
lock_grab(&lock);
|
||||
if (finished)
|
||||
{
|
||||
lock_release(&lock);
|
||||
return MOVE_NONE;
|
||||
}
|
||||
Move m = get_next_move();
|
||||
if (m == MOVE_NONE)
|
||||
finished = true;
|
||||
|
||||
lock_release(&lock);
|
||||
return m;
|
||||
}
|
||||
|
||||
+6
-18
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "depth.h"
|
||||
#include "history.h"
|
||||
#include "lock.h"
|
||||
#include "position.h"
|
||||
|
||||
|
||||
@@ -50,26 +49,23 @@ class MovePicker {
|
||||
MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
|
||||
|
||||
public:
|
||||
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL);
|
||||
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL, Value beta = -VALUE_INFINITE);
|
||||
Move get_next_move();
|
||||
Move get_next_move(Lock& lock);
|
||||
int number_of_evasions() const;
|
||||
Bitboard discovered_check_candidates() const;
|
||||
|
||||
private:
|
||||
void score_captures();
|
||||
void score_noncaptures();
|
||||
void score_evasions();
|
||||
void score_evasions_or_checks();
|
||||
void go_next_phase();
|
||||
|
||||
const Position& pos;
|
||||
const History& H;
|
||||
MoveStack ttMoves[2], killers[2];
|
||||
bool finished;
|
||||
int phase;
|
||||
int badCaptureThreshold, phase;
|
||||
const uint8_t* phasePtr;
|
||||
MoveStack *curMove, *lastMove, *lastBadCapture;
|
||||
Bitboard dc, pinned;
|
||||
MoveStack *curMove, *lastMove, *lastGoodNonCapture, *lastBadCapture;
|
||||
Bitboard pinned;
|
||||
MoveStack moves[256], badCaptures[64];
|
||||
};
|
||||
|
||||
@@ -88,12 +84,4 @@ inline int MovePicker::number_of_evasions() const {
|
||||
return int(lastMove - moves);
|
||||
}
|
||||
|
||||
/// MovePicker::discovered_check_candidates() returns a bitboard containing
|
||||
/// all pieces which can possibly give discovered check. This bitboard is
|
||||
/// computed by the constructor function.
|
||||
|
||||
inline Bitboard MovePicker::discovered_check_candidates() const {
|
||||
return dc;
|
||||
}
|
||||
|
||||
#endif // !defined(MOVEPICK_H_INCLUDED)
|
||||
|
||||
+195
-246
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -38,64 +38,36 @@ namespace {
|
||||
|
||||
/// Constants and variables
|
||||
|
||||
// Doubled pawn penalty by file, middle game
|
||||
const Value DoubledPawnMidgamePenalty[8] = {
|
||||
Value(13), Value(20), Value(23), Value(23),
|
||||
Value(23), Value(23), Value(20), Value(13)
|
||||
#define S(mg, eg) make_score(mg, eg)
|
||||
|
||||
// Doubled pawn penalty by file
|
||||
const Score DoubledPawnPenalty[8] = {
|
||||
S(13, 43), S(20, 48), S(23, 48), S(23, 48),
|
||||
S(23, 48), S(23, 48), S(20, 48), S(13, 43)
|
||||
};
|
||||
|
||||
// Doubled pawn penalty by file, endgame
|
||||
const Value DoubledPawnEndgamePenalty[8] = {
|
||||
Value(43), Value(48), Value(48), Value(48),
|
||||
Value(48), Value(48), Value(48), Value(43)
|
||||
// Isolated pawn penalty by file
|
||||
const Score IsolatedPawnPenalty[8] = {
|
||||
S(25, 30), S(36, 35), S(40, 35), S(40, 35),
|
||||
S(40, 35), S(40, 35), S(36, 35), S(25, 30)
|
||||
};
|
||||
|
||||
// Isolated pawn penalty by file, middle game
|
||||
const Value IsolatedPawnMidgamePenalty[8] = {
|
||||
Value(25), Value(36), Value(40), Value(40),
|
||||
Value(40), Value(40), Value(36), Value(25)
|
||||
// Backward pawn penalty by file
|
||||
const Score BackwardPawnPenalty[8] = {
|
||||
S(20, 28), S(29, 31), S(33, 31), S(33, 31),
|
||||
S(33, 31), S(33, 31), S(29, 31), S(20, 28)
|
||||
};
|
||||
|
||||
// Isolated pawn penalty by file, endgame
|
||||
const Value IsolatedPawnEndgamePenalty[8] = {
|
||||
Value(30), Value(35), Value(35), Value(35),
|
||||
Value(35), Value(35), Value(35), Value(30)
|
||||
// Pawn chain membership bonus by file
|
||||
const Score ChainBonus[8] = {
|
||||
S(11,-1), S(13,-1), S(13,-1), S(14,-1),
|
||||
S(14,-1), S(13,-1), S(13,-1), S(11,-1)
|
||||
};
|
||||
|
||||
// Backward pawn penalty by file, middle game
|
||||
const Value BackwardPawnMidgamePenalty[8] = {
|
||||
Value(20), Value(29), Value(33), Value(33),
|
||||
Value(33), Value(33), Value(29), Value(20)
|
||||
};
|
||||
|
||||
// Backward pawn penalty by file, endgame
|
||||
const Value BackwardPawnEndgamePenalty[8] = {
|
||||
Value(28), Value(31), Value(31), Value(31),
|
||||
Value(31), Value(31), Value(31), Value(28)
|
||||
};
|
||||
|
||||
// Pawn chain membership bonus by file, middle game
|
||||
const Value ChainMidgameBonus[8] = {
|
||||
Value(11), Value(13), Value(13), Value(14),
|
||||
Value(14), Value(13), Value(13), Value(11)
|
||||
};
|
||||
|
||||
// Pawn chain membership bonus by file, endgame
|
||||
const Value ChainEndgameBonus[8] = {
|
||||
Value(-1), Value(-1), Value(-1), Value(-1),
|
||||
Value(-1), Value(-1), Value(-1), Value(-1)
|
||||
};
|
||||
|
||||
// Candidate passed pawn bonus by rank, middle game
|
||||
const Value CandidateMidgameBonus[8] = {
|
||||
Value( 0), Value( 6), Value(6), Value(14),
|
||||
Value(34), Value(83), Value(0), Value( 0)
|
||||
};
|
||||
|
||||
// Candidate passed pawn bonus by rank, endgame
|
||||
const Value CandidateEndgameBonus[8] = {
|
||||
Value( 0), Value( 13), Value(13), Value(29),
|
||||
Value(68), Value(166), Value( 0), Value( 0)
|
||||
// Candidate passed pawn bonus by rank
|
||||
const Score CandidateBonus[8] = {
|
||||
S( 0, 0), S( 6, 13), S(6,13), S(14,29),
|
||||
S(34,68), S(83,166), S(0, 0), S( 0, 0)
|
||||
};
|
||||
|
||||
// Pawn storm tables for positions with opposite castling
|
||||
@@ -190,207 +162,184 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
||||
pi->clear();
|
||||
pi->key = key;
|
||||
|
||||
Value mgValue[2] = {Value(0), Value(0)};
|
||||
Value egValue[2] = {Value(0), Value(0)};
|
||||
|
||||
// Calculate pawn attacks
|
||||
pi->pawnAttacks[WHITE] = ((pos.pieces(PAWN, WHITE) << 9) & ~FileABB) | ((pos.pieces(PAWN, WHITE) << 7) & ~FileHBB);
|
||||
pi->pawnAttacks[BLACK] = ((pos.pieces(PAWN, BLACK) >> 7) & ~FileABB) | ((pos.pieces(PAWN, BLACK) >> 9) & ~FileHBB);
|
||||
Bitboard whitePawns = pos.pieces(PAWN, WHITE);
|
||||
Bitboard blackPawns = pos.pieces(PAWN, BLACK);
|
||||
pi->pawnAttacks[WHITE] = ((whitePawns << 9) & ~FileABB) | ((whitePawns << 7) & ~FileHBB);
|
||||
pi->pawnAttacks[BLACK] = ((blackPawns >> 7) & ~FileABB) | ((blackPawns >> 9) & ~FileHBB);
|
||||
|
||||
// Loop through the pawns for both colors
|
||||
for (Color us = WHITE; us <= BLACK; us++)
|
||||
{
|
||||
Color them = opposite_color(us);
|
||||
Bitboard ourPawns = pos.pieces(PAWN, us);
|
||||
Bitboard theirPawns = pos.pieces(PAWN, them);
|
||||
Bitboard pawns = ourPawns;
|
||||
|
||||
// Initialize pawn storm scores by giving bonuses for open files
|
||||
for (File f = FILE_A; f <= FILE_H; f++)
|
||||
if (!(pawns & file_bb(f)))
|
||||
{
|
||||
pi->ksStormValue[us] += KStormOpenFileBonus[f];
|
||||
pi->qsStormValue[us] += QStormOpenFileBonus[f];
|
||||
pi->halfOpenFiles[us] |= (1 << f);
|
||||
}
|
||||
|
||||
// Loop through all pawns of the current color and score each pawn
|
||||
while (pawns)
|
||||
{
|
||||
Square s = pop_1st_bit(&pawns);
|
||||
File f = square_file(s);
|
||||
Rank r = square_rank(s);
|
||||
|
||||
assert(pos.piece_on(s) == piece_of_color_and_type(us, PAWN));
|
||||
|
||||
// Passed, isolated or doubled pawn?
|
||||
bool passed = Position::pawn_is_passed(theirPawns, us, s);
|
||||
bool isolated = Position::pawn_is_isolated(ourPawns, s);
|
||||
bool doubled = Position::pawn_is_doubled(ourPawns, us, s);
|
||||
|
||||
// We calculate kingside and queenside pawn storm
|
||||
// scores for both colors. These are used when evaluating
|
||||
// middle game positions with opposite side castling.
|
||||
//
|
||||
// Each pawn is given a base score given by a piece square table
|
||||
// (KStormTable[] or QStormTable[]). Pawns which seem to have good
|
||||
// chances of creating an open file by exchanging itself against an
|
||||
// enemy pawn on an adjacent file gets an additional bonus.
|
||||
|
||||
// Kingside pawn storms
|
||||
int bonus = KStormTable[relative_square(us, s)];
|
||||
if (f >= FILE_F)
|
||||
{
|
||||
Bitboard b = outpost_mask(us, s) & theirPawns & (FileFBB | FileGBB | FileHBB);
|
||||
while (b)
|
||||
{
|
||||
Square s2 = pop_1st_bit(&b);
|
||||
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||
{
|
||||
// The enemy pawn has no pawn beside itself, which makes it
|
||||
// particularly vulnerable. Big bonus, especially against a
|
||||
// weakness on the rook file.
|
||||
if (square_file(s2) == FILE_H)
|
||||
bonus += 4*StormLeverBonus[f] - 8*square_distance(s, s2);
|
||||
else
|
||||
bonus += 2*StormLeverBonus[f] - 4*square_distance(s, s2);
|
||||
} else
|
||||
// There is at least one enemy pawn beside the enemy pawn we look
|
||||
// at, which means that the pawn has somewhat better chances of
|
||||
// defending itself by advancing. Smaller bonus.
|
||||
bonus += StormLeverBonus[f] - 2*square_distance(s, s2);
|
||||
}
|
||||
}
|
||||
pi->ksStormValue[us] += bonus;
|
||||
|
||||
// Queenside pawn storms
|
||||
bonus = QStormTable[relative_square(us, s)];
|
||||
if (f <= FILE_C)
|
||||
{
|
||||
Bitboard b = outpost_mask(us, s) & theirPawns & (FileABB | FileBBB | FileCBB);
|
||||
while (b)
|
||||
{
|
||||
Square s2 = pop_1st_bit(&b);
|
||||
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||
{
|
||||
// The enemy pawn has no pawn beside itself, which makes it
|
||||
// particularly vulnerable. Big bonus, especially against a
|
||||
// weakness on the rook file.
|
||||
if (square_file(s2) == FILE_A)
|
||||
bonus += 4*StormLeverBonus[f] - 16*square_distance(s, s2);
|
||||
else
|
||||
bonus += 2*StormLeverBonus[f] - 8*square_distance(s, s2);
|
||||
} else
|
||||
// There is at least one enemy pawn beside the enemy pawn we look
|
||||
// at, which means that the pawn has somewhat better chances of
|
||||
// defending itself by advancing. Smaller bonus.
|
||||
bonus += StormLeverBonus[f] - 4*square_distance(s, s2);
|
||||
}
|
||||
}
|
||||
pi->qsStormValue[us] += bonus;
|
||||
|
||||
// Member of a pawn chain (but not the backward one)? We could speed up
|
||||
// the test a little by introducing an array of masks indexed by color
|
||||
// and square for doing the test, but because everything is hashed,
|
||||
// it probably won't make any noticable difference.
|
||||
bool chain = ourPawns
|
||||
& neighboring_files_bb(f)
|
||||
& (rank_bb(r) | rank_bb(r - (us == WHITE ? 1 : -1)));
|
||||
|
||||
// Test for backward pawn
|
||||
//
|
||||
// If the pawn is passed, isolated, or member of a pawn chain
|
||||
// it cannot be backward. If can capture an enemy pawn or if
|
||||
// there are friendly pawns behind on neighboring files it cannot
|
||||
// be backward either.
|
||||
bool backward;
|
||||
if ( passed
|
||||
|| isolated
|
||||
|| chain
|
||||
|| (pos.attacks_from<PAWN>(s, us) & theirPawns)
|
||||
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
|
||||
backward = false;
|
||||
else
|
||||
{
|
||||
// We now know that there are no friendly pawns beside or behind this
|
||||
// pawn on neighboring files. We now check whether the pawn is
|
||||
// backward by looking in the forward direction on the neighboring
|
||||
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
||||
Bitboard b = pos.attacks_from<PAWN>(s, us);
|
||||
if (us == WHITE)
|
||||
{
|
||||
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
|
||||
backward = (b | (b << 8)) & theirPawns;
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( ; !(b & (ourPawns | theirPawns)); b >>= 8);
|
||||
backward = (b | (b >> 8)) & theirPawns;
|
||||
}
|
||||
}
|
||||
|
||||
// Test for candidate passed pawn
|
||||
bool candidate;
|
||||
candidate = !passed
|
||||
&& !(theirPawns & file_bb(f))
|
||||
&& ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns)
|
||||
- count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns)
|
||||
>= 0);
|
||||
|
||||
// In order to prevent doubled passed pawns from receiving a too big
|
||||
// bonus, only the frontmost passed pawn on each file is considered as
|
||||
// a true passed pawn.
|
||||
if (passed && (ourPawns & squares_in_front_of(us, s)))
|
||||
passed = false;
|
||||
|
||||
// Score this pawn
|
||||
if (passed)
|
||||
set_bit(&(pi->passedPawns), s);
|
||||
|
||||
if (isolated)
|
||||
{
|
||||
mgValue[us] -= IsolatedPawnMidgamePenalty[f];
|
||||
egValue[us] -= IsolatedPawnEndgamePenalty[f];
|
||||
if (!(theirPawns & file_bb(f)))
|
||||
{
|
||||
mgValue[us] -= IsolatedPawnMidgamePenalty[f] / 2;
|
||||
egValue[us] -= IsolatedPawnEndgamePenalty[f] / 2;
|
||||
}
|
||||
}
|
||||
if (doubled)
|
||||
{
|
||||
mgValue[us] -= DoubledPawnMidgamePenalty[f];
|
||||
egValue[us] -= DoubledPawnEndgamePenalty[f];
|
||||
}
|
||||
if (backward)
|
||||
{
|
||||
mgValue[us] -= BackwardPawnMidgamePenalty[f];
|
||||
egValue[us] -= BackwardPawnEndgamePenalty[f];
|
||||
if (!(theirPawns & file_bb(f)))
|
||||
{
|
||||
mgValue[us] -= BackwardPawnMidgamePenalty[f] / 2;
|
||||
egValue[us] -= BackwardPawnEndgamePenalty[f] / 2;
|
||||
}
|
||||
}
|
||||
if (chain)
|
||||
{
|
||||
mgValue[us] += ChainMidgameBonus[f];
|
||||
egValue[us] += ChainEndgameBonus[f];
|
||||
}
|
||||
if (candidate)
|
||||
{
|
||||
mgValue[us] += CandidateMidgameBonus[relative_rank(us, s)];
|
||||
egValue[us] += CandidateEndgameBonus[relative_rank(us, s)];
|
||||
}
|
||||
} // while(pawns)
|
||||
} // for(colors)
|
||||
|
||||
pi->mgValue = int16_t(mgValue[WHITE] - mgValue[BLACK]);
|
||||
pi->egValue = int16_t(egValue[WHITE] - egValue[BLACK]);
|
||||
// Evaluate pawns for both colors
|
||||
pi->value = evaluate_pawns<WHITE>(pos, whitePawns, blackPawns, pi)
|
||||
- evaluate_pawns<BLACK>(pos, blackPawns, whitePawns, pi);
|
||||
return pi;
|
||||
}
|
||||
|
||||
|
||||
/// PawnInfoTable::evaluate_pawns() evaluates each pawn of the given color
|
||||
|
||||
template<Color Us>
|
||||
Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
|
||||
Bitboard theirPawns, PawnInfo* pi) {
|
||||
Square s;
|
||||
File f;
|
||||
Rank r;
|
||||
bool passed, isolated, doubled, chain, backward, candidate;
|
||||
int bonus;
|
||||
Score value = make_score(0, 0);
|
||||
const Square* ptr = pos.piece_list_begin(Us, PAWN);
|
||||
|
||||
// Initialize pawn storm scores by giving bonuses for open files
|
||||
for (f = FILE_A; f <= FILE_H; f++)
|
||||
if (!(ourPawns & file_bb(f)))
|
||||
{
|
||||
pi->ksStormValue[Us] += KStormOpenFileBonus[f];
|
||||
pi->qsStormValue[Us] += QStormOpenFileBonus[f];
|
||||
pi->halfOpenFiles[Us] |= (1 << f);
|
||||
}
|
||||
|
||||
// Loop through all pawns of the current color and score each pawn
|
||||
while ((s = *ptr++) != SQ_NONE)
|
||||
{
|
||||
f = square_file(s);
|
||||
r = square_rank(s);
|
||||
|
||||
assert(pos.piece_on(s) == piece_of_color_and_type(Us, PAWN));
|
||||
|
||||
// Passed, isolated or doubled pawn?
|
||||
passed = Position::pawn_is_passed(theirPawns, Us, s);
|
||||
isolated = Position::pawn_is_isolated(ourPawns, s);
|
||||
doubled = Position::pawn_is_doubled(ourPawns, Us, s);
|
||||
|
||||
// We calculate kingside and queenside pawn storm
|
||||
// scores for both colors. These are used when evaluating
|
||||
// middle game positions with opposite side castling.
|
||||
//
|
||||
// Each pawn is given a base score given by a piece square table
|
||||
// (KStormTable[] or QStormTable[]). Pawns which seem to have good
|
||||
// chances of creating an open file by exchanging itself against an
|
||||
// enemy pawn on an adjacent file gets an additional bonus.
|
||||
|
||||
// Kingside pawn storms
|
||||
bonus = KStormTable[relative_square(Us, s)];
|
||||
if (f >= FILE_F)
|
||||
{
|
||||
Bitboard b = outpost_mask(Us, s) & theirPawns & (FileFBB | FileGBB | FileHBB);
|
||||
while (b)
|
||||
{
|
||||
// Give a bonus according to the distance of the nearest enemy pawn
|
||||
Square s2 = pop_1st_bit(&b);
|
||||
int v = StormLeverBonus[f] - 2 * square_distance(s, s2);
|
||||
|
||||
// If enemy pawn has no pawn beside itself is particularly vulnerable.
|
||||
// Big bonus, especially against a weakness on the rook file
|
||||
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||
v *= (square_file(s2) == FILE_H ? 4 : 2);
|
||||
|
||||
bonus += v;
|
||||
}
|
||||
}
|
||||
pi->ksStormValue[Us] += bonus;
|
||||
|
||||
// Queenside pawn storms
|
||||
bonus = QStormTable[relative_square(Us, s)];
|
||||
if (f <= FILE_C)
|
||||
{
|
||||
Bitboard b = outpost_mask(Us, s) & theirPawns & (FileABB | FileBBB | FileCBB);
|
||||
while (b)
|
||||
{
|
||||
// Give a bonus according to the distance of the nearest enemy pawn
|
||||
Square s2 = pop_1st_bit(&b);
|
||||
int v = StormLeverBonus[f] - 4 * square_distance(s, s2);
|
||||
|
||||
// If enemy pawn has no pawn beside itself is particularly vulnerable.
|
||||
// Big bonus, especially against a weakness on the rook file
|
||||
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||
v *= (square_file(s2) == FILE_A ? 4 : 2);
|
||||
|
||||
bonus += v;
|
||||
}
|
||||
}
|
||||
pi->qsStormValue[Us] += bonus;
|
||||
|
||||
// Member of a pawn chain (but not the backward one)? We could speed up
|
||||
// the test a little by introducing an array of masks indexed by color
|
||||
// and square for doing the test, but because everything is hashed,
|
||||
// it probably won't make any noticable difference.
|
||||
chain = ourPawns
|
||||
& neighboring_files_bb(f)
|
||||
& (rank_bb(r) | rank_bb(r - (Us == WHITE ? 1 : -1)));
|
||||
|
||||
// Test for backward pawn
|
||||
//
|
||||
// If the pawn is passed, isolated, or member of a pawn chain
|
||||
// it cannot be backward. If can capture an enemy pawn or if
|
||||
// there are friendly pawns behind on neighboring files it cannot
|
||||
// be backward either.
|
||||
if ( (passed | isolated | chain)
|
||||
|| (ourPawns & behind_bb(Us, r) & neighboring_files_bb(f))
|
||||
|| (pos.attacks_from<PAWN>(s, Us) & theirPawns))
|
||||
backward = false;
|
||||
else
|
||||
{
|
||||
// We now know that there are no friendly pawns beside or behind this
|
||||
// pawn on neighboring files. We now check whether the pawn is
|
||||
// backward by looking in the forward direction on the neighboring
|
||||
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
||||
Bitboard b = pos.attacks_from<PAWN>(s, Us);
|
||||
|
||||
// Note that we are sure to find something because pawn is not passed
|
||||
// nor isolated, so loop is potentially infinite, but it isn't.
|
||||
while (!(b & (ourPawns | theirPawns)))
|
||||
Us == WHITE ? b <<= 8 : b >>= 8;
|
||||
|
||||
// The friendly pawn needs to be at least two ranks closer than the enemy
|
||||
// pawn in order to help the potentially backward pawn advance.
|
||||
backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns;
|
||||
}
|
||||
|
||||
// Test for candidate passed pawn
|
||||
candidate = !passed
|
||||
&& !(theirPawns & file_bb(f))
|
||||
&& ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(Us, r) | rank_bb(r)) & ourPawns)
|
||||
- count_1s_max_15(neighboring_files_bb(f) & in_front_bb(Us, r) & theirPawns)
|
||||
>= 0);
|
||||
|
||||
// In order to prevent doubled passed pawns from receiving a too big
|
||||
// bonus, only the frontmost passed pawn on each file is considered as
|
||||
// a true passed pawn.
|
||||
if (passed && (ourPawns & squares_in_front_of(Us, s)))
|
||||
passed = false;
|
||||
|
||||
// Score this pawn
|
||||
if (passed)
|
||||
set_bit(&(pi->passedPawns), s);
|
||||
|
||||
if (isolated)
|
||||
{
|
||||
value -= IsolatedPawnPenalty[f];
|
||||
if (!(theirPawns & file_bb(f)))
|
||||
value -= IsolatedPawnPenalty[f] / 2;
|
||||
}
|
||||
if (doubled)
|
||||
value -= DoubledPawnPenalty[f];
|
||||
|
||||
if (backward)
|
||||
{
|
||||
value -= BackwardPawnPenalty[f];
|
||||
if (!(theirPawns & file_bb(f)))
|
||||
value -= BackwardPawnPenalty[f] / 2;
|
||||
}
|
||||
if (chain)
|
||||
value += ChainBonus[f];
|
||||
|
||||
if (candidate)
|
||||
value += CandidateBonus[relative_rank(Us, s)];
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/// PawnInfo::updateShelter calculates and caches king shelter. It is called
|
||||
/// only when king square changes, about 20% of total get_king_shelter() calls.
|
||||
int PawnInfo::updateShelter(const Position& pos, Color c, Square ksq) {
|
||||
|
||||
+9
-11
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -45,10 +45,9 @@ class PawnInfo {
|
||||
friend class PawnInfoTable;
|
||||
|
||||
public:
|
||||
PawnInfo() : key(0) { clear(); }
|
||||
PawnInfo() { clear(); }
|
||||
|
||||
Value mg_value() const;
|
||||
Value eg_value() const;
|
||||
Score pawns_value() const;
|
||||
Value kingside_storm_value(Color c) const;
|
||||
Value queenside_storm_value(Color c) const;
|
||||
Bitboard pawn_attacks(Color c) const;
|
||||
@@ -65,7 +64,7 @@ private:
|
||||
Key key;
|
||||
Bitboard passedPawns;
|
||||
Bitboard pawnAttacks[2];
|
||||
int16_t mgValue, egValue;
|
||||
Score value;
|
||||
int16_t ksStormValue[2], qsStormValue[2];
|
||||
uint8_t halfOpenFiles[2];
|
||||
Square kingSquares[2];
|
||||
@@ -85,6 +84,9 @@ public:
|
||||
PawnInfo* get_pawn_info(const Position& pos);
|
||||
|
||||
private:
|
||||
template<Color Us>
|
||||
Score evaluate_pawns(const Position& pos, Bitboard ourPawns, Bitboard theirPawns, PawnInfo* pi);
|
||||
|
||||
unsigned size;
|
||||
PawnInfo* entries;
|
||||
};
|
||||
@@ -94,12 +96,8 @@ private:
|
||||
//// Inline functions
|
||||
////
|
||||
|
||||
inline Value PawnInfo::mg_value() const {
|
||||
return Value(mgValue);
|
||||
}
|
||||
|
||||
inline Value PawnInfo::eg_value() const {
|
||||
return Value(egValue);
|
||||
inline Score PawnInfo::pawns_value() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
inline Bitboard PawnInfo::passed_pawns() const {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+362
-353
File diff suppressed because it is too large
Load Diff
+56
-55
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -63,6 +63,18 @@ const int MaxGameLength = 220;
|
||||
//// Types
|
||||
////
|
||||
|
||||
/// struct checkInfo is initialized at c'tor time and keeps
|
||||
/// info used to detect if a move gives check.
|
||||
|
||||
struct CheckInfo {
|
||||
|
||||
CheckInfo(const Position&);
|
||||
|
||||
Square ksq;
|
||||
Bitboard dcCandidates;
|
||||
Bitboard checkSq[8];
|
||||
};
|
||||
|
||||
/// Castle rights, encoded as bit fields
|
||||
|
||||
enum CastleRights {
|
||||
@@ -87,12 +99,13 @@ enum Phase {
|
||||
/// must be passed as a parameter.
|
||||
|
||||
struct StateInfo {
|
||||
Key key, pawnKey, materialKey;
|
||||
int castleRights, rule50;
|
||||
Key pawnKey, materialKey;
|
||||
int castleRights, rule50, pliesFromNull;
|
||||
Square epSquare;
|
||||
Value mgValue, egValue;
|
||||
Score value;
|
||||
Value npMaterial[2];
|
||||
|
||||
Key key;
|
||||
PieceType capture;
|
||||
Bitboard checkersBB;
|
||||
StateInfo* previous;
|
||||
@@ -133,9 +146,9 @@ public:
|
||||
};
|
||||
|
||||
// Constructors
|
||||
Position() {}
|
||||
Position(const Position& pos);
|
||||
Position(const std::string& fen);
|
||||
Position();
|
||||
explicit Position(const Position& pos);
|
||||
explicit Position(const std::string& fen);
|
||||
|
||||
// Text input/output
|
||||
void from_fen(const std::string& fen);
|
||||
@@ -143,7 +156,6 @@ public:
|
||||
void print(Move m = MOVE_NONE) const;
|
||||
|
||||
// Copying
|
||||
void copy(const Position& pos);
|
||||
void flipped_copy(const Position& pos);
|
||||
|
||||
// The piece on a given square
|
||||
@@ -202,14 +214,18 @@ public:
|
||||
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||
|
||||
// Properties of moves
|
||||
bool pl_move_is_legal(Move m) const;
|
||||
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
||||
bool pl_move_is_evasion(Move m, Bitboard pinned) const;
|
||||
bool move_is_check(Move m) const;
|
||||
bool move_is_check(Move m, Bitboard dcCandidates) const;
|
||||
bool move_is_check(Move m, const CheckInfo& ci) const;
|
||||
bool move_is_capture(Move m) const;
|
||||
bool move_is_capture_or_promotion(Move m) const;
|
||||
bool move_is_passed_pawn_push(Move m) const;
|
||||
bool move_attacks_square(Move m, Square s) const;
|
||||
|
||||
// Piece captured with previous moves
|
||||
PieceType captured_piece() const;
|
||||
|
||||
// Information about pawns
|
||||
bool pawn_is_passed(Color c, Square s) const;
|
||||
static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
|
||||
@@ -220,9 +236,9 @@ public:
|
||||
bool square_is_weak(Square s, Color c) const;
|
||||
|
||||
// Doing and undoing moves
|
||||
void saveState();
|
||||
void detach();
|
||||
void do_move(Move m, StateInfo& st);
|
||||
void do_move(Move m, StateInfo& st, Bitboard dcCandidates);
|
||||
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
||||
void undo_move(Move m);
|
||||
void do_null_move(StateInfo& st);
|
||||
void undo_null_move();
|
||||
@@ -235,15 +251,14 @@ public:
|
||||
|
||||
// Accessing hash keys
|
||||
Key get_key() const;
|
||||
Key get_exclusion_key() const;
|
||||
Key get_pawn_key() const;
|
||||
Key get_material_key() const;
|
||||
|
||||
// Incremental evaluation
|
||||
Value mg_value() const;
|
||||
Value eg_value() const;
|
||||
Score value() const;
|
||||
Value non_pawn_material(Color c) const;
|
||||
Phase game_phase() const;
|
||||
template<GamePhase> Value pst_delta(Piece piece, Square from, Square to) const;
|
||||
Score pst_delta(Piece piece, Square from, Square to) const;
|
||||
|
||||
// Game termination checks
|
||||
bool is_mate() const;
|
||||
@@ -283,9 +298,6 @@ private:
|
||||
void undo_castle_move(Move m);
|
||||
void find_checkers();
|
||||
|
||||
template<PieceType Piece>
|
||||
void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
|
||||
|
||||
template<bool FindPinned>
|
||||
Bitboard hidden_checkers(Color c) const;
|
||||
|
||||
@@ -295,8 +307,8 @@ private:
|
||||
Key compute_material_key() const;
|
||||
|
||||
// Computing incremental evaluation scores and material counts
|
||||
template<GamePhase> Value pst(Color c, PieceType pt, Square s) const;
|
||||
template<GamePhase> Value compute_value() const;
|
||||
Score pst(Color c, PieceType pt, Square s) const;
|
||||
Score compute_value() const;
|
||||
Value compute_non_pawn_material(Color c) const;
|
||||
|
||||
// Board
|
||||
@@ -316,19 +328,19 @@ private:
|
||||
Color sideToMove;
|
||||
int gamePly;
|
||||
Key history[MaxGameLength];
|
||||
int castleRightsMask[64];
|
||||
File initialKFile, initialKRFile, initialQRFile;
|
||||
StateInfo startState;
|
||||
StateInfo* st;
|
||||
|
||||
// Static variables
|
||||
static int castleRightsMask[64];
|
||||
static Key zobrist[2][8][64];
|
||||
static Key zobEp[64];
|
||||
static Key zobCastle[16];
|
||||
static Key zobMaterial[2][8][16];
|
||||
static Key zobSideToMove;
|
||||
static Value MgPieceSquareTable[16][64];
|
||||
static Value EgPieceSquareTable[16][64];
|
||||
static Score PieceSquareTable[16][64];
|
||||
static Key zobExclusion;
|
||||
};
|
||||
|
||||
|
||||
@@ -493,6 +505,10 @@ inline Key Position::get_key() const {
|
||||
return st->key;
|
||||
}
|
||||
|
||||
inline Key Position::get_exclusion_key() const {
|
||||
return st->key ^ zobExclusion;
|
||||
}
|
||||
|
||||
inline Key Position::get_pawn_key() const {
|
||||
return st->pawnKey;
|
||||
}
|
||||
@@ -501,46 +517,22 @@ inline Key Position::get_material_key() const {
|
||||
return st->materialKey;
|
||||
}
|
||||
|
||||
template<Position::GamePhase Ph>
|
||||
inline Value Position::pst(Color c, PieceType pt, Square s) const {
|
||||
return (Ph == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
|
||||
: EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
|
||||
inline Score Position::pst(Color c, PieceType pt, Square s) const {
|
||||
return PieceSquareTable[piece_of_color_and_type(c, pt)][s];
|
||||
}
|
||||
|
||||
template<Position::GamePhase Ph>
|
||||
inline Value Position::pst_delta(Piece piece, Square from, Square to) const {
|
||||
return (Ph == MidGame ? MgPieceSquareTable[piece][to] - MgPieceSquareTable[piece][from]
|
||||
: EgPieceSquareTable[piece][to] - EgPieceSquareTable[piece][from]);
|
||||
inline Score Position::pst_delta(Piece piece, Square from, Square to) const {
|
||||
return PieceSquareTable[piece][to] - PieceSquareTable[piece][from];
|
||||
}
|
||||
|
||||
inline Value Position::mg_value() const {
|
||||
return st->mgValue;
|
||||
}
|
||||
|
||||
inline Value Position::eg_value() const {
|
||||
return st->egValue;
|
||||
inline Score Position::value() const {
|
||||
return st->value;
|
||||
}
|
||||
|
||||
inline Value Position::non_pawn_material(Color c) const {
|
||||
return st->npMaterial[c];
|
||||
}
|
||||
|
||||
inline Phase Position::game_phase() const {
|
||||
|
||||
// Values modified by Joona Kiiski
|
||||
static const Value MidgameLimit = Value(15581);
|
||||
static const Value EndgameLimit = Value(3998);
|
||||
|
||||
Value npm = non_pawn_material(WHITE) + non_pawn_material(BLACK);
|
||||
|
||||
if (npm >= MidgameLimit)
|
||||
return PHASE_MIDGAME;
|
||||
else if(npm <= EndgameLimit)
|
||||
return PHASE_ENDGAME;
|
||||
else
|
||||
return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
|
||||
}
|
||||
|
||||
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
||||
|
||||
Color c = side_to_move();
|
||||
@@ -568,8 +560,17 @@ inline bool Position::has_pawn_on_7th(Color c) const {
|
||||
inline bool Position::move_is_capture(Move m) const {
|
||||
|
||||
// Move must not be MOVE_NONE !
|
||||
return (m & (3 << 15)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
|
||||
}
|
||||
|
||||
return (!square_is_empty(move_to(m)) && !move_is_castle(m)) || move_is_ep(m);
|
||||
inline bool Position::move_is_capture_or_promotion(Move m) const {
|
||||
|
||||
// Move must not be MOVE_NONE !
|
||||
return (m & (0x1F << 12)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
|
||||
}
|
||||
|
||||
inline PieceType Position::captured_piece() const {
|
||||
return st->capture;
|
||||
}
|
||||
|
||||
#endif // !defined(POSITION_H_INCLUDED)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+14
-11
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -63,7 +63,7 @@ namespace {
|
||||
/// that the move is a legal move from the position. The return value is
|
||||
/// a string containing the move in short algebraic notation.
|
||||
|
||||
const string move_to_san(const Position& pos, Move m) {
|
||||
const string move_to_san(Position& pos, Move m) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(move_is_ok(m));
|
||||
@@ -123,10 +123,10 @@ const string move_to_san(const Position& pos, Move m) {
|
||||
// Position::move_is_check doesn't detect all checks (not castling moves,
|
||||
// promotions and en passant captures).
|
||||
StateInfo st;
|
||||
Position p(pos);
|
||||
p.do_move(m, st);
|
||||
if (p.is_check())
|
||||
san += p.is_mate()? "#" : "+";
|
||||
pos.do_move(m, st);
|
||||
if (pos.is_check())
|
||||
san += pos.is_mate() ? "#" : "+";
|
||||
pos.undo_move(m);
|
||||
|
||||
return san;
|
||||
}
|
||||
@@ -142,13 +142,14 @@ Move move_from_san(const Position& pos, const string& movestr) {
|
||||
assert(pos.is_ok());
|
||||
|
||||
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||
|
||||
// Castling moves
|
||||
if (movestr == "O-O-O" || movestr == "O-O-O+")
|
||||
{
|
||||
Move m;
|
||||
while ((m = mp.get_next_move()) != MOVE_NONE)
|
||||
if (move_is_long_castle(m) && pos.pl_move_is_legal(m))
|
||||
if (move_is_long_castle(m) && pos.pl_move_is_legal(m, pinned))
|
||||
return m;
|
||||
|
||||
return MOVE_NONE;
|
||||
@@ -157,7 +158,7 @@ Move move_from_san(const Position& pos, const string& movestr) {
|
||||
{
|
||||
Move m;
|
||||
while ((m = mp.get_next_move()) != MOVE_NONE)
|
||||
if (move_is_short_castle(m) && pos.pl_move_is_legal(m))
|
||||
if (move_is_short_castle(m) && pos.pl_move_is_legal(m, pinned))
|
||||
return m;
|
||||
|
||||
return MOVE_NONE;
|
||||
@@ -325,14 +326,15 @@ const string line_to_san(const Position& pos, Move line[], int startColumn, bool
|
||||
/// when the UCI parameter "Use Search Log" is "true").
|
||||
|
||||
const string pretty_pv(const Position& pos, int time, int depth,
|
||||
uint64_t nodes, Value score, Move pv[]) {
|
||||
uint64_t nodes, Value score, ValueType type, Move pv[]) {
|
||||
std::stringstream s;
|
||||
|
||||
// Depth
|
||||
s << std::setw(2) << depth << " ";
|
||||
|
||||
// Score
|
||||
s << std::setw(8) << score_string(score);
|
||||
s << ((type == VALUE_TYPE_LOWER)? ">" : ((type == VALUE_TYPE_UPPER)? "<" : " "));
|
||||
s << std::setw(7) << score_string(score);
|
||||
|
||||
// Time
|
||||
s << std::setw(8) << time_string(time) << " ";
|
||||
@@ -366,11 +368,12 @@ namespace {
|
||||
return AMBIGUITY_NONE;
|
||||
|
||||
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||
Move mv, moveList[8];
|
||||
|
||||
int n = 0;
|
||||
while ((mv = mp.get_next_move()) != MOVE_NONE)
|
||||
if (move_to(mv) == to && pos.piece_on(move_from(mv)) == pc && pos.pl_move_is_legal(mv))
|
||||
if (move_to(mv) == to && pos.piece_on(move_from(mv)) == pc && pos.pl_move_is_legal(mv, pinned))
|
||||
moveList[n++] = mv;
|
||||
|
||||
if (n == 1)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -36,9 +36,9 @@
|
||||
//// Prototypes
|
||||
////
|
||||
|
||||
extern const std::string move_to_san(const Position& pos, Move m);
|
||||
extern const std::string move_to_san(Position& pos, Move m);
|
||||
extern Move move_from_san(const Position& pos, const std::string& str);
|
||||
extern const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines);
|
||||
extern const std::string pretty_pv(const Position& pos, int time, int depth, uint64_t nodes, Value score, Move pv[]);
|
||||
extern const std::string pretty_pv(const Position& pos, int time, int depth, uint64_t nodes, Value score, ValueType type, Move pv[]);
|
||||
|
||||
#endif // !defined(SAN_H_INCLUDED)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1784
-1544
File diff suppressed because it is too large
Load Diff
+8
-3
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "depth.h"
|
||||
#include "move.h"
|
||||
#include "value.h"
|
||||
|
||||
|
||||
////
|
||||
@@ -46,14 +47,16 @@ const int KILLER_MAX = 2;
|
||||
/// from nodes shallower and deeper in the tree during the search. Each
|
||||
/// search thread has its own array of SearchStack objects, indexed by the
|
||||
/// current ply.
|
||||
struct EvalInfo;
|
||||
|
||||
struct SearchStack {
|
||||
Move pv[PLY_MAX];
|
||||
Move pv[PLY_MAX_PLUS_2];
|
||||
Move currentMove;
|
||||
Move mateKiller;
|
||||
Move threatMove;
|
||||
Move killers[KILLER_MAX];
|
||||
Depth reduction;
|
||||
Value eval;
|
||||
|
||||
void init(int ply);
|
||||
void initKillers();
|
||||
@@ -64,11 +67,13 @@ struct SearchStack {
|
||||
//// Prototypes
|
||||
////
|
||||
|
||||
extern void init_search();
|
||||
extern void init_threads();
|
||||
extern void stop_threads();
|
||||
extern void exit_threads();
|
||||
extern bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
||||
int time[], int increment[], int movesToGo, int maxDepth,
|
||||
int maxNodes, int maxTime, Move searchMoves[]);
|
||||
extern int perft(Position &pos, Depth depth);
|
||||
extern int64_t nodes_searched();
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+37
-21
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -26,6 +26,8 @@
|
||||
//// Includes
|
||||
////
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "lock.h"
|
||||
#include "movepick.h"
|
||||
#include "position.h"
|
||||
@@ -36,7 +38,8 @@
|
||||
//// Constants and variables
|
||||
////
|
||||
|
||||
const int THREAD_MAX = 8;
|
||||
const int MAX_THREADS = 8;
|
||||
const int ACTIVE_SPLIT_POINTS_MAX = 8;
|
||||
|
||||
|
||||
////
|
||||
@@ -44,35 +47,48 @@ const int THREAD_MAX = 8;
|
||||
////
|
||||
|
||||
struct SplitPoint {
|
||||
SplitPoint *parent;
|
||||
Position pos;
|
||||
SearchStack sstack[THREAD_MAX][PLY_MAX];
|
||||
SearchStack *parentSstack;
|
||||
int ply;
|
||||
Depth depth;
|
||||
volatile Value alpha, beta, bestValue;
|
||||
|
||||
// Const data after splitPoint has been setup
|
||||
SplitPoint* parent;
|
||||
const Position* pos;
|
||||
bool pvNode;
|
||||
Bitboard dcCandidates;
|
||||
int master, slaves[THREAD_MAX];
|
||||
Depth depth;
|
||||
bool mateThreat;
|
||||
Value beta;
|
||||
int ply, master, slaves[MAX_THREADS];
|
||||
SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
|
||||
|
||||
// Const pointers to shared data
|
||||
MovePicker* mp;
|
||||
SearchStack* parentSstack;
|
||||
|
||||
// Shared data
|
||||
Lock lock;
|
||||
MovePicker *mp;
|
||||
volatile Value alpha;
|
||||
volatile Value bestValue;
|
||||
volatile int moves;
|
||||
volatile int cpus;
|
||||
bool finished;
|
||||
volatile bool stopRequest;
|
||||
};
|
||||
|
||||
// ThreadState type is used to represent thread's current state
|
||||
|
||||
enum ThreadState
|
||||
{
|
||||
THREAD_SEARCHING, // thread is performing work
|
||||
THREAD_AVAILABLE, // thread is polling for work
|
||||
THREAD_SLEEPING, // we are not thinking, so thread is sleeping
|
||||
THREAD_BOOKED, // other thread (master) has booked us as a slave
|
||||
THREAD_WORKISWAITING, // master has ordered us to start
|
||||
THREAD_TERMINATED // we are quitting and thread is terminated
|
||||
};
|
||||
|
||||
struct Thread {
|
||||
SplitPoint *splitPoint;
|
||||
int activeSplitPoints;
|
||||
SplitPoint* splitPoint;
|
||||
volatile int activeSplitPoints;
|
||||
uint64_t nodes;
|
||||
uint64_t betaCutOffs[2];
|
||||
bool failHighPly1;
|
||||
volatile bool stop;
|
||||
volatile bool running;
|
||||
volatile bool idle;
|
||||
volatile bool workIsWaiting;
|
||||
volatile bool printCurrentLine;
|
||||
volatile ThreadState state;
|
||||
unsigned char pad[64]; // set some distance among local data for each thread
|
||||
};
|
||||
|
||||
|
||||
+31
-25
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -25,7 +25,9 @@
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <xmmintrin.h>
|
||||
#if !(defined(__hpux) || defined(__ppc__) || defined(__ppc64__) || defined(__arm__))
|
||||
# include <xmmintrin.h>
|
||||
#endif
|
||||
|
||||
#include "movegen.h"
|
||||
#include "tt.h"
|
||||
@@ -53,11 +55,9 @@ TranspositionTable::~TranspositionTable() {
|
||||
/// TranspositionTable::set_size sets the size of the transposition table,
|
||||
/// measured in megabytes.
|
||||
|
||||
void TranspositionTable::set_size(unsigned mbSize) {
|
||||
void TranspositionTable::set_size(size_t mbSize) {
|
||||
|
||||
assert(mbSize >= 4 && mbSize <= 4096);
|
||||
|
||||
unsigned newSize = 1024;
|
||||
size_t newSize = 1024;
|
||||
|
||||
// We store a cluster of ClusterSize number of TTEntry for each position
|
||||
// and newSize is the maximum number of storable positions.
|
||||
@@ -125,6 +125,7 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
|
||||
if (tte->key() && t == VALUE_TYPE_EV_LO)
|
||||
return;
|
||||
|
||||
// Preserve any exsisting ttMove
|
||||
if (m == MOVE_NONE)
|
||||
m = tte->move();
|
||||
|
||||
@@ -169,11 +170,14 @@ TTEntry* TranspositionTable::retrieve(const Key posKey) const {
|
||||
/// to be loaded from RAM, that can be very slow. When we will
|
||||
/// subsequently call retrieve() the TT data will be already
|
||||
/// quickly accessible in L1/L2 CPU cache.
|
||||
#if defined(__hpux) || defined(__ppc__) || defined(__ppc64__) || defined(__arm__)
|
||||
void TranspositionTable::prefetch(const Key) const {} // Not supported on HP UX
|
||||
#else
|
||||
|
||||
void TranspositionTable::prefetch(const Key posKey) const {
|
||||
|
||||
#if defined(__INTEL_COMPILER) || defined(__ICL)
|
||||
// This hack prevents prefetches to be optimized away by the
|
||||
// This hack prevents prefetches to be optimized away by
|
||||
// Intel compiler. Both MSVC and gcc seems not affected.
|
||||
__asm__ ("");
|
||||
#endif
|
||||
@@ -183,6 +187,7 @@ void TranspositionTable::prefetch(const Key posKey) const {
|
||||
_mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// TranspositionTable::new_search() is called at the beginning of every new
|
||||
/// search. It increments the "generation" variable, which is used to
|
||||
@@ -208,7 +213,9 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
||||
|
||||
for (int i = 0; pv[i] != MOVE_NONE; i++)
|
||||
{
|
||||
store(p.get_key(), VALUE_NONE, VALUE_TYPE_NONE, Depth(-127*OnePly), pv[i]);
|
||||
TTEntry *tte = retrieve(p.get_key());
|
||||
if (!tte || tte->move() != pv[i])
|
||||
store(p.get_key(), VALUE_NONE, VALUE_TYPE_NONE, Depth(-127*OnePly), pv[i]);
|
||||
p.do_move(pv[i], st);
|
||||
}
|
||||
}
|
||||
@@ -220,27 +227,26 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
||||
/// will often get single-move PVs when the search stops while failing high,
|
||||
/// and a single-move PV means that we don't have a ponder move.
|
||||
|
||||
void TranspositionTable::extract_pv(const Position& pos, Move pv[]) {
|
||||
void TranspositionTable::extract_pv(const Position& pos, Move pv[], const int PLY_MAX) {
|
||||
|
||||
int ply;
|
||||
Position p(pos);
|
||||
StateInfo st[100];
|
||||
|
||||
for (ply = 0; pv[ply] != MOVE_NONE; ply++)
|
||||
p.do_move(pv[ply], st[ply]);
|
||||
|
||||
bool stop;
|
||||
const TTEntry* tte;
|
||||
for (stop = false, tte = retrieve(p.get_key());
|
||||
tte && tte->move() != MOVE_NONE && !stop;
|
||||
tte = retrieve(p.get_key()), ply++)
|
||||
StateInfo st;
|
||||
Position p(pos);
|
||||
int ply = 0;
|
||||
|
||||
// Update position to the end of current PV
|
||||
while (pv[ply] != MOVE_NONE)
|
||||
p.do_move(pv[ply++], st);
|
||||
|
||||
// Try to add moves from TT while possible
|
||||
while ( (tte = retrieve(p.get_key())) != NULL
|
||||
&& tte->move() != MOVE_NONE
|
||||
&& move_is_legal(p, tte->move())
|
||||
&& (!p.is_draw() || ply < 2)
|
||||
&& ply < PLY_MAX)
|
||||
{
|
||||
if (!move_is_legal(p, tte->move()))
|
||||
break;
|
||||
pv[ply] = tte->move();
|
||||
p.do_move(pv[ply], st[ply]);
|
||||
for (int j = 0; j < ply; j++)
|
||||
if (st[j].key == p.get_key()) stop = true;
|
||||
p.do_move(pv[ply++], st);
|
||||
}
|
||||
pv[ply] = MOVE_NONE;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -95,14 +95,14 @@ class TranspositionTable {
|
||||
public:
|
||||
TranspositionTable();
|
||||
~TranspositionTable();
|
||||
void set_size(unsigned mbSize);
|
||||
void set_size(size_t mbSize);
|
||||
void clear();
|
||||
void store(const Key posKey, Value v, ValueType type, Depth d, Move m);
|
||||
TTEntry* retrieve(const Key posKey) const;
|
||||
void prefetch(const Key posKey) const;
|
||||
void new_search();
|
||||
void insert_pv(const Position& pos, Move pv[]);
|
||||
void extract_pv(const Position& pos, Move pv[]);
|
||||
void extract_pv(const Position& pos, Move pv[], const int PLY_MAX);
|
||||
int full() const;
|
||||
|
||||
private:
|
||||
@@ -114,7 +114,7 @@ private:
|
||||
unsigned writes; // heavy SMP read/write access here
|
||||
unsigned char pad_after[64];
|
||||
|
||||
unsigned size;
|
||||
size_t size;
|
||||
TTCluster* entries;
|
||||
uint8_t generation;
|
||||
};
|
||||
|
||||
+26
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -33,7 +33,7 @@ typedef __int16 int16;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
typedef __int16 int16_t;
|
||||
@@ -73,4 +73,28 @@ typedef uint64_t Bitboard;
|
||||
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
|
||||
#endif
|
||||
|
||||
// Define a __cpuid() function for gcc compilers, for Intel and MSVC
|
||||
// is already available as an intrinsic.
|
||||
#if defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
inline void __cpuid(int CPUInfo[4], int InfoType)
|
||||
{
|
||||
int* eax = CPUInfo + 0;
|
||||
int* ebx = CPUInfo + 1;
|
||||
int* ecx = CPUInfo + 2;
|
||||
int* edx = CPUInfo + 3;
|
||||
|
||||
*eax = InfoType;
|
||||
*ecx = 0;
|
||||
__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
|
||||
: "0" (*eax), "2" (*ecx));
|
||||
}
|
||||
#else
|
||||
inline void __cpuid(int CPUInfo[4], int)
|
||||
{
|
||||
CPUInfo[0] = CPUInfo[1] = CPUInfo[2] = CPUInfo[3] = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !defined(TYPES_H_INCLUDED)
|
||||
|
||||
+50
-46
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -61,6 +61,7 @@ namespace {
|
||||
void set_option(UCIInputParser& uip);
|
||||
void set_position(UCIInputParser& uip);
|
||||
bool go(UCIInputParser& uip);
|
||||
void perft(UCIInputParser& uip);
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +107,8 @@ namespace {
|
||||
UCIInputParser uip(command);
|
||||
string token;
|
||||
|
||||
uip >> token; // operator>>() skips any whitespace
|
||||
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||
return true;
|
||||
|
||||
if (token == "quit")
|
||||
return false;
|
||||
@@ -123,7 +125,7 @@ namespace {
|
||||
}
|
||||
else if (token == "ucinewgame")
|
||||
{
|
||||
push_button("Clear Hash");
|
||||
push_button("New Game");
|
||||
Position::init_piece_square_tables();
|
||||
RootPosition.from_fen(StartPosition);
|
||||
}
|
||||
@@ -147,23 +149,19 @@ namespace {
|
||||
else if (token == "eval")
|
||||
{
|
||||
EvalInfo ei;
|
||||
cout << "Incremental mg: " << RootPosition.mg_value()
|
||||
<< "\nIncremental eg: " << RootPosition.eg_value()
|
||||
cout << "Incremental mg: " << mg_value(RootPosition.value())
|
||||
<< "\nIncremental eg: " << eg_value(RootPosition.value())
|
||||
<< "\nFull eval: " << evaluate(RootPosition, ei, 0) << endl;
|
||||
}
|
||||
else if (token == "key")
|
||||
cout << "key: " << hex << RootPosition.get_key()
|
||||
<< "\nmaterial key: " << RootPosition.get_material_key()
|
||||
<< "\npawn key: " << RootPosition.get_pawn_key() << endl;
|
||||
else if (token == "perft")
|
||||
perft(uip);
|
||||
else
|
||||
{
|
||||
cout << "Unknown command: " << command << endl;
|
||||
while (!uip.eof())
|
||||
{
|
||||
uip >> token;
|
||||
cout << token << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -178,33 +176,33 @@ namespace {
|
||||
|
||||
string token;
|
||||
|
||||
uip >> token; // operator>>() skips any whitespace
|
||||
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||
return;
|
||||
|
||||
if (token == "startpos")
|
||||
RootPosition.from_fen(StartPosition);
|
||||
else if (token == "fen")
|
||||
{
|
||||
string fen;
|
||||
while (token != "moves" && !uip.eof())
|
||||
while (uip >> token && token != "moves")
|
||||
{
|
||||
uip >> token;
|
||||
fen += token;
|
||||
fen += ' ';
|
||||
}
|
||||
RootPosition.from_fen(fen);
|
||||
}
|
||||
|
||||
if (!uip.eof())
|
||||
if (uip.good())
|
||||
{
|
||||
if (token != "moves")
|
||||
uip >> token;
|
||||
|
||||
if (token == "moves")
|
||||
{
|
||||
Move move;
|
||||
StateInfo st;
|
||||
while (!uip.eof())
|
||||
while (uip >> token)
|
||||
{
|
||||
uip >> token;
|
||||
move = move_from_string(RootPosition, token);
|
||||
RootPosition.do_move(move, st);
|
||||
if (RootPosition.rule_50_counter() == 0)
|
||||
@@ -212,7 +210,7 @@ namespace {
|
||||
}
|
||||
// Our StateInfo st is about going out of scope so copy
|
||||
// its content inside RootPosition before they disappear.
|
||||
RootPosition.saveState();
|
||||
RootPosition.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,27 +224,22 @@ namespace {
|
||||
|
||||
void set_option(UCIInputParser& uip) {
|
||||
|
||||
string token, name;
|
||||
string token, name, value;
|
||||
|
||||
uip >> token;
|
||||
if (token == "name")
|
||||
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||
return;
|
||||
|
||||
if (token == "name" && uip >> name)
|
||||
{
|
||||
uip >> name;
|
||||
while (!uip.eof())
|
||||
{
|
||||
uip >> token;
|
||||
if (token == "value")
|
||||
break;
|
||||
|
||||
while (uip >> token && token != "value")
|
||||
name += (" " + token);
|
||||
}
|
||||
if (token == "value")
|
||||
{
|
||||
// Reads until end of line and left trim white space
|
||||
getline(uip, token);
|
||||
token.erase(0, token.find_first_not_of(" \n\r\t"));
|
||||
|
||||
set_option_value(name, token);
|
||||
if (token == "value" && uip >> value)
|
||||
{
|
||||
while (uip >> token)
|
||||
value += (" " + token);
|
||||
|
||||
set_option_value(name, value);
|
||||
} else
|
||||
push_button(name);
|
||||
}
|
||||
@@ -273,10 +266,8 @@ namespace {
|
||||
|
||||
searchMoves[0] = MOVE_NONE;
|
||||
|
||||
while (!uip.eof())
|
||||
while (uip >> token)
|
||||
{
|
||||
uip >> token;
|
||||
|
||||
if (token == "infinite")
|
||||
infinite = true;
|
||||
else if (token == "ponder")
|
||||
@@ -300,22 +291,35 @@ namespace {
|
||||
else if (token == "searchmoves")
|
||||
{
|
||||
int numOfMoves = 0;
|
||||
while (!uip.eof())
|
||||
{
|
||||
uip >> token;
|
||||
while (uip >> token)
|
||||
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
||||
}
|
||||
|
||||
searchMoves[numOfMoves] = MOVE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (moveTime)
|
||||
infinite = true; // HACK
|
||||
|
||||
assert(RootPosition.is_ok());
|
||||
|
||||
return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
|
||||
time, inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
||||
}
|
||||
|
||||
void perft(UCIInputParser& uip) {
|
||||
|
||||
string token;
|
||||
int depth, tm, n;
|
||||
Position pos(RootPosition);
|
||||
|
||||
if (!(uip >> depth))
|
||||
return;
|
||||
|
||||
tm = get_system_time();
|
||||
|
||||
n = perft(pos, depth * OnePly);
|
||||
|
||||
tm = get_system_time() - tm;
|
||||
std::cout << "\nNodes " << n
|
||||
<< "\nTime (ms) " << tm
|
||||
<< "\nNodes/second " << (int)(n/(tm/1000.0)) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+49
-35
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -88,26 +88,10 @@ namespace {
|
||||
o["Space"] = Option(100, 0, 200);
|
||||
o["Aggressiveness"] = Option(100, 0, 200);
|
||||
o["Cowardice"] = Option(100, 0, 200);
|
||||
o["King Safety Curve"] = Option("Quadratic", COMBO);
|
||||
|
||||
o["King Safety Curve"].comboValues.push_back("Quadratic");
|
||||
o["King Safety Curve"].comboValues.push_back("Linear"); /*, "From File"*/
|
||||
|
||||
o["King Safety Coefficient"] = Option(40, 1, 100);
|
||||
o["King Safety X Intercept"] = Option(0, 0, 20);
|
||||
o["King Safety Max Slope"] = Option(30, 10, 100);
|
||||
o["King Safety Max Value"] = Option(500, 100, 1000);
|
||||
o["Queen Contact Check Bonus"] = Option(3, 0, 8);
|
||||
o["Queen Check Bonus"] = Option(2, 0, 4);
|
||||
o["Rook Check Bonus"] = Option(1, 0, 4);
|
||||
o["Bishop Check Bonus"] = Option(1, 0, 4);
|
||||
o["Knight Check Bonus"] = Option(1, 0, 4);
|
||||
o["Discovered Check Bonus"] = Option(3, 0, 8);
|
||||
o["Mate Threat Bonus"] = Option(3, 0, 8);
|
||||
o["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
||||
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||
o["Single Reply Extension (PV nodes)"] = Option(2, 0, 2);
|
||||
o["Single Reply Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||
o["Single Evasion Extension (PV nodes)"] = Option(2, 0, 2);
|
||||
o["Single Evasion Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||
o["Mate Threat Extension (PV nodes)"] = Option(0, 0, 2);
|
||||
o["Mate Threat Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
||||
@@ -116,19 +100,16 @@ namespace {
|
||||
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
||||
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||
o["Full Depth Moves (PV nodes)"] = Option(10, 1, 100);
|
||||
o["Full Depth Moves (non-PV nodes)"] = Option(3, 1, 100);
|
||||
o["Threat Depth"] = Option(5, 0, 100);
|
||||
o["Randomness"] = Option(0, 0, 10);
|
||||
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
||||
o["Threads"] = Option(1, 1, 8);
|
||||
o["Hash"] = Option(32, 4, 4096);
|
||||
o["Threads"] = Option(1, 1, MAX_THREADS);
|
||||
o["Hash"] = Option(32, 4, 8192);
|
||||
o["Clear Hash"] = Option(false, BUTTON);
|
||||
o["New Game"] = Option(false, BUTTON);
|
||||
o["Ponder"] = Option(true);
|
||||
o["OwnBook"] = Option(true);
|
||||
o["MultiPV"] = Option(1, 1, 500);
|
||||
o["UCI_ShowCurrLine"] = Option(false);
|
||||
o["UCI_Chess960"] = Option(false);
|
||||
o["UCI_AnalyseMode"] = Option(false);
|
||||
|
||||
@@ -169,6 +150,18 @@ namespace {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Specialization for std::string where instruction 'ss >> ret;'
|
||||
// would erroneusly tokenize a string with spaces.
|
||||
|
||||
template<>
|
||||
string get_option_value<string>(const string& optionName) {
|
||||
|
||||
if (options.find(optionName) == options.end())
|
||||
return string();
|
||||
|
||||
return options[optionName].currentValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
////
|
||||
@@ -183,15 +176,18 @@ void init_uci_options() {
|
||||
|
||||
load_defaults(options);
|
||||
|
||||
// Limit the default value of "Threads" to 7 even if we have 8 CPU cores.
|
||||
// According to Ken Dail's tests, Glaurung plays much better with 7 than
|
||||
// with 8 threads. This is weird, but it is probably difficult to find out
|
||||
// why before I have a 8-core computer to experiment with myself.
|
||||
// Set optimal value for parameter "Minimum Split Depth"
|
||||
// according to number of available cores.
|
||||
assert(options.find("Threads") != options.end());
|
||||
assert(options.find("Minimum Split Depth") != options.end());
|
||||
|
||||
options["Threads"].defaultValue = stringify(Min(cpu_count(), 7));
|
||||
options["Threads"].currentValue = stringify(Min(cpu_count(), 7));
|
||||
Option& thr = options["Threads"];
|
||||
Option& msd = options["Minimum Split Depth"];
|
||||
|
||||
thr.defaultValue = thr.currentValue = stringify(cpu_count());
|
||||
|
||||
if (cpu_count() >= 8)
|
||||
msd.defaultValue = msd.currentValue = stringify(7);
|
||||
}
|
||||
|
||||
|
||||
@@ -279,10 +275,28 @@ void set_option_value(const string& name, const string& value) {
|
||||
else if (v == "false")
|
||||
v = "0";
|
||||
|
||||
if (options.find(name) != options.end())
|
||||
options[name].currentValue = v;
|
||||
else
|
||||
if (options.find(name) == options.end())
|
||||
{
|
||||
std::cout << "No such option: " << name << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Normally it's up to the GUI to check for option's limits,
|
||||
// but we could receive the new value directly from the user
|
||||
// by teminal window. So let's check the bounds anyway.
|
||||
Option& opt = options[name];
|
||||
|
||||
if (opt.type == CHECK && v != "0" && v != "1")
|
||||
return;
|
||||
|
||||
else if (opt.type == SPIN)
|
||||
{
|
||||
int val = atoi(v.c_str());
|
||||
if (val < opt.minValue || val > opt.maxValue)
|
||||
return;
|
||||
}
|
||||
|
||||
opt.currentValue = v;
|
||||
}
|
||||
|
||||
|
||||
@@ -302,7 +316,7 @@ void push_button(const string& buttonName) {
|
||||
bool button_was_pressed(const string& buttonName) {
|
||||
|
||||
if (!get_option_value<bool>(buttonName))
|
||||
return false;
|
||||
return false;
|
||||
|
||||
set_option_value(buttonName, "false");
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+42
-4
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2009 Marco Costalba
|
||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -48,10 +48,49 @@ enum Value {
|
||||
VALUE_KNOWN_WIN = 15000,
|
||||
VALUE_MATE = 30000,
|
||||
VALUE_INFINITE = 30001,
|
||||
VALUE_NONE = 30002
|
||||
VALUE_NONE = 30002,
|
||||
VALUE_ENSURE_SIGNED = -1
|
||||
};
|
||||
|
||||
|
||||
/// Score enum keeps a midgame and an endgame value in a single
|
||||
/// integer (enum), first LSB 16 bits are used to store endgame
|
||||
/// value, while upper bits are used for midgame value.
|
||||
|
||||
// Compiler is free to choose the enum type as long as can keep
|
||||
// its data, so ensure Score to be an integer type.
|
||||
enum Score { ENSURE_32_BITS_SIZE_P = (1 << 16), ENSURE_32_BITS_SIZE_N = -(1 << 16)};
|
||||
|
||||
// Extracting the _signed_ lower and upper 16 bits it not so trivial
|
||||
// because according to the standard a simple cast to short is
|
||||
// implementation defined and so is a right shift of a signed integer.
|
||||
inline Value mg_value(Score s) { return Value(((int(s) + 32768) & ~0xffff) / 0x10000); }
|
||||
|
||||
// Unfortunatly on Intel 64 bit we have a small speed regression, so use a faster code in
|
||||
// this case, although not 100% standard compliant it seems to work for Intel and MSVC.
|
||||
#if defined(IS_64BIT) && (!defined(__GNUC__) || defined(__INTEL_COMPILER))
|
||||
inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); }
|
||||
#else
|
||||
inline Value eg_value(Score s) { return Value((int)(unsigned(s) & 0x7fffu) - (int)(unsigned(s) & 0x8000u)); }
|
||||
#endif
|
||||
|
||||
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
|
||||
|
||||
inline Score operator-(Score s) { return Score(-int(s)); }
|
||||
inline Score operator+(Score s1, Score s2) { return Score(int(s1) + int(s2)); }
|
||||
inline Score operator-(Score s1, Score s2) { return Score(int(s1) - int(s2)); }
|
||||
inline void operator+=(Score& s1, Score s2) { s1 = Score(int(s1) + int(s2)); }
|
||||
inline void operator-=(Score& s1, Score s2) { s1 = Score(int(s1) - int(s2)); }
|
||||
inline Score operator*(int i, Score s) { return Score(i * int(s)); }
|
||||
|
||||
// Division must be handled separately for each term
|
||||
inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); }
|
||||
|
||||
// Only declared but not defined. We don't want to multiply two scores due to
|
||||
// a very high risk of overflow. So user should explicitly convert to integer.
|
||||
inline Score operator*(Score s1, Score s2);
|
||||
|
||||
|
||||
////
|
||||
//// Constants and variables
|
||||
////
|
||||
@@ -97,8 +136,7 @@ const Value PieceValueEndgame[17] = {
|
||||
|
||||
/// Bonus for having the side to move (modified by Joona Kiiski)
|
||||
|
||||
const Value TempoValueMidgame = Value(48);
|
||||
const Value TempoValueEndgame = Value(22);
|
||||
const Score TempoValue = make_score(48, 22);
|
||||
|
||||
|
||||
////
|
||||
|
||||
Reference in New Issue
Block a user