mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 10:57:43 +00:00
Compare commits
545 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 86c2d2fc3b | |||
| f9d3b48ad0 | |||
| d720778b2b | |||
| e2880f9b8e | |||
| 909e3adede | |||
| 626b1f8c6a | |||
| 06a350f1ae | |||
| a9e9746495 | |||
| 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 | |||
| aaa07fb161 | |||
| 1361ba75cb | |||
| da9c423989 | |||
| 3713bb26ef | |||
| cff9ff2198 | |||
| a6c6037813 | |||
| e677185567 | |||
| 237dd331d5 | |||
| 98c8a83bb8 | |||
| 73be819426 | |||
| 2940abdac8 | |||
| fa0bffeafa | |||
| d56345c9ae | |||
| 60e23693f0 | |||
| 91f0c08789 | |||
| 6bf22f354f | |||
| 48b74142ef | |||
| dcb323bf0d | |||
| 44cb792c76 | |||
| e68e135771 | |||
| 46141b078c | |||
| 02fd34a5e8 | |||
| 20cac227bb | |||
| 4346445be3 | |||
| 21850536d5 | |||
| 0179a32cf5 | |||
| 8487069058 | |||
| 43ca5c926d | |||
| aed542d74c | |||
| aaffcf973e | |||
| 746bcb348f | |||
| a7cb05b1eb | |||
| 9741694fca | |||
| e145c0d3e2 | |||
| 24cc3a97a4 | |||
| e4277c06bf | |||
| dd80b9abaf | |||
| 84d6fe0f31 | |||
| 6845397c5c | |||
| f74f42b298 | |||
| 0e0adfe2e1 | |||
| 049139d025 | |||
| 62a8f393f1 | |||
| c5f44ef45b | |||
| 7c55b0e880 | |||
| 77ac1e7953 | |||
| cddda7cd19 | |||
| c81010a878 | |||
| 6709b01903 | |||
| 3863cd191c | |||
| f205fe1fe5 | |||
| 9f28d8a854 | |||
| 76bed11f7b | |||
| e33c94883f | |||
| 46ffea46ea | |||
| 03d6a86900 | |||
| 17c5119222 | |||
| cf71efc34b | |||
| c9d364f9ca | |||
| 97dd7568ed | |||
| af220cfd52 | |||
| 1130c8d815 | |||
| 607ac0687a | |||
| e9de96f0e4 | |||
| 9ab84a8165 | |||
| ac65b14d30 | |||
| 9e4befe3f1 | |||
| 6cf28d4aa7 | |||
| 129cde008c | |||
| b088f0aefd | |||
| a5d699d62f | |||
| f6d2452916 | |||
| 268c53ac51 | |||
| 595a90dfd0 | |||
| e217407450 | |||
| 2078878376 | |||
| d1d4437699 | |||
| ba04eb0446 | |||
| ed347e7cbd | |||
| 95af1e28be | |||
| e9aa20ad13 | |||
| e01fefbbaf | |||
| e4fc957898 | |||
| 693b38a5e7 | |||
| fbec55e52e | |||
| 05e70d6740 | |||
| b4cb1a3a9e | |||
| ec14fb1b33 | |||
| cb506d3b16 | |||
| e0c47a6ceb | |||
| f3d0b76feb | |||
| bfd4421f49 | |||
| fd12e8cb23 | |||
| 166c09a7a0 | |||
| 8d369600ec | |||
| f4140ecc0c | |||
| 60b5da4cc8 | |||
| 55c46b2399 | |||
| 76ae0e36be | |||
| 4251eac860 | |||
| cd4604b05c | |||
| e6863f46de | |||
| 6f1475b6fc | |||
| 4a777954e1 | |||
| 54382f8b07 | |||
| 339bb8a524 | |||
| aa925a0e29 | |||
| 23ceb66950 | |||
| 565d12bf42 | |||
| 00eab73399 | |||
| 5be3d98d17 | |||
| 5b3fcab1ad | |||
| 977ca40d6d | |||
| ae49677446 | |||
| 2fff532f4e | |||
| da854fe83a | |||
| a1096e55cf | |||
| dad632ce5b | |||
| 2f7723fd44 | |||
| 152f3b13b7 | |||
| bb1b049b83 | |||
| 50f92bed06 | |||
| bdb586ac2b | |||
| 1b0303b6e9 | |||
| 5f232e0667 | |||
| 080a4995a3 | |||
| 20224a5bbf | |||
| 8654fee18c | |||
| 8b45b60327 | |||
| 044ad593b3 | |||
| 5600d91cff | |||
| 1cc44bcaae | |||
| 15eb59683e | |||
| 620cfbb676 | |||
| fe523b2d18 | |||
| 2a203d8d6f | |||
| b8326edea3 | |||
| 20e8738901 | |||
| b3b1d3aaa7 | |||
| 0d69ac33ff | |||
| 342c8c883c | |||
| 297c12e595 | |||
| 5c20f59788 | |||
| ea06200423 | |||
| 3849beb979 | |||
| 20ed03fc0b | |||
| 2a461b4b74 | |||
| 6f39a3fc80 | |||
| 7eefc1f6cc | |||
| 7622793080 | |||
| 174b40c28d | |||
| 03f524c591 | |||
| 3444b94735 | |||
| 2693db616d | |||
| a5fce1958b |
+90
-89
@@ -1,89 +1,90 @@
|
|||||||
1. Introduction
|
1. Introduction
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
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
|
not a complete chess program, but requires some UCI compatible GUI
|
||||||
(like XBoard with PolyGlot, eboard, Jos�, Arena, Sigma Chess, Shredder,
|
(like XBoard with PolyGlot, eboard, Jos�, Arena, Sigma Chess, Shredder,
|
||||||
Chess Partner, or Fritz) in order to be used comfortably. Read the
|
Chess Partner, or Fritz) in order to be used comfortably. Read the
|
||||||
documentation for your GUI of choice for information about how to use
|
documentation for your GUI of choice for information about how to use
|
||||||
Stockfish with your GUI.
|
Stockfish with your GUI.
|
||||||
|
|
||||||
This version of Stockfish supports up to 8 CPUs, but has not been
|
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
|
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
|
number of CPUs on your computer and set the number of search threads
|
||||||
accordingly, but please be aware that the detection is not always
|
accordingly, but please be aware that the detection is not always
|
||||||
correct. It is therefore recommended to inspect the value of the
|
correct. It is therefore recommended to inspect the value of the
|
||||||
"Threads" UCI parameter, and to make sure it equals the number of CPU
|
"Threads" UCI parameter, and to make sure it equals the number of CPU
|
||||||
cores on your computer.
|
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
|
|
||||||
--------
|
|
||||||
|
2. Files
|
||||||
This distribution of Stockfish consists of the following files:
|
--------
|
||||||
|
|
||||||
* Readme.txt, the file you are currently reading.
|
This distribution of Stockfish consists of the following files:
|
||||||
|
|
||||||
* Copying.txt, a text file containing the GNU General Public
|
* Readme.txt, the file you are currently reading.
|
||||||
License.
|
|
||||||
|
* Copying.txt, a text file containing the GNU General Public
|
||||||
* src/, a subdirectory containing the full source code, including a
|
License.
|
||||||
Makefile that can be used to compile Stockfish on Unix-like
|
|
||||||
systems. For further information about how to compile Stockfish
|
* src/, a subdirectory containing the full source code, including a
|
||||||
yourself, read section 4 below.
|
Makefile that can be used to compile Stockfish on Unix-like
|
||||||
|
systems. For further information about how to compile Stockfish
|
||||||
* polyglot.ini, for using Stockfish with Fabien Letouzey's PolyGlot
|
yourself, read section 4 below.
|
||||||
adapter.
|
|
||||||
|
* polyglot.ini, for using Stockfish with Fabien Letouzey's PolyGlot
|
||||||
|
adapter.
|
||||||
3. Opening books
|
|
||||||
----------------
|
|
||||||
|
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
|
This version of Stockfish has experimental support for PolyGlot opening
|
||||||
UCI parameter "Book File".
|
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
|
|
||||||
------------------------
|
|
||||||
|
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
|
On Unix-like systems, it should usually be possible to compile
|
||||||
Macintoshes. Some of the bitboard routines in the current version of
|
Stockfish directly from the source code with the included Makefile.
|
||||||
Stockfish are endianness-sensitive, and won't work on a big-endian CPU.
|
|
||||||
|
For big-endian machines like Power PC you need to enable the proper
|
||||||
Stockfish has POPCNT instruction runtime detection and support. This can
|
flag changing from -DNBIGENDIAN to -DBIGENDIAN in the Makefile.
|
||||||
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
|
Stockfish has POPCNT instruction runtime detection and support. This can
|
||||||
before to compile.
|
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
|
On 64 bit Unix-like systems the 'bsfq' assembly instruction will be used
|
||||||
experience compile problems you can comment out #define USE_BSFQ line in types.h
|
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
|
|
||||||
---------------
|
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
|
Stockfish is free, and distributed under the GNU General Public License
|
||||||
what you want with the program, including distributing it among your
|
(GPL). Essentially, this means that you are free to do almost exactly
|
||||||
friends, making it available for download from your web site, selling
|
what you want with the program, including distributing it among your
|
||||||
it (either by itself or as part of some bigger software package), or
|
friends, making it available for download from your web site, selling
|
||||||
using it as the starting point for a software project of your own.
|
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
|
The only real limitation is that whenever you distribute Stockfish in
|
||||||
to where the source code can be found. If you make any changes to the
|
some way, you must always include the full source code, or a pointer
|
||||||
source code, these changes must also be made available under the GPL.
|
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.
|
For full details, read the copy of the GPL found in the file named
|
||||||
|
Copying.txt.
|
||||||
|
|
||||||
6. Feedback
|
|
||||||
-----------
|
6. Feedback
|
||||||
|
-----------
|
||||||
The author's e-mail address is mcostalba@gmail.com
|
|
||||||
|
The author's e-mail address is mcostalba@gmail.com
|
||||||
|
|||||||
+292
-107
@@ -18,133 +18,318 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
###
|
### Executable name. Do not change
|
||||||
### Files
|
|
||||||
###
|
|
||||||
|
|
||||||
EXE = stockfish
|
EXE = stockfish
|
||||||
|
|
||||||
|
### Installation dir definitions
|
||||||
|
PREFIX = /usr/local
|
||||||
|
BINDIR = $(PREFIX)/bin
|
||||||
|
|
||||||
|
|
||||||
|
### ==========================================================================
|
||||||
|
### Compiler speed switches for both GCC and ICC. These settings are generally
|
||||||
|
### fast on a broad range of systems, but may be changed experimentally
|
||||||
|
### ==========================================================================
|
||||||
|
GCCFLAGS = -O3 -msse
|
||||||
|
ICCFLAGS = -fast -msse
|
||||||
|
ICCFLAGS-OSX = -fast -mdynamic-no-pic
|
||||||
|
|
||||||
|
|
||||||
|
### ==========================================================================
|
||||||
|
### Enable/disable debugging, disabled by default
|
||||||
|
### ==========================================================================
|
||||||
|
GCCFLAGS += -DNDEBUG
|
||||||
|
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
|
||||||
|
### ==========================================================================
|
||||||
|
PGOBENCH = ./$(EXE) bench 32 1 10 default depth
|
||||||
|
|
||||||
|
|
||||||
|
### General compiler settings. Do not change
|
||||||
|
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
|
||||||
|
LDFLAGS = -lpthread
|
||||||
|
|
||||||
|
|
||||||
|
### Object files. Do not change
|
||||||
OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
|
OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
|
||||||
misc.o move.o movegen.o history.o movepick.o search.o piece.o \
|
misc.o move.o movegen.o history.o movepick.o search.o piece.o \
|
||||||
position.o direction.o tt.o value.o uci.o ucioption.o \
|
position.o direction.o tt.o value.o uci.o ucioption.o \
|
||||||
mersenne.o book.o bitbase.o san.o benchmark.o
|
mersenne.o book.o bitbase.o san.o benchmark.o
|
||||||
|
|
||||||
|
|
||||||
###
|
### General rules. Do not change
|
||||||
### Rules
|
default:
|
||||||
###
|
$(MAKE) gcc
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo ""
|
||||||
|
@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++"
|
||||||
|
@echo "make osx-x86_64 > x86-Mac OS X 64 bit. Compiler = g++"
|
||||||
|
@echo "make osx-icc32 > x86-Mac OS X 32 bit. Compiler = icpc"
|
||||||
|
@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
|
all: $(EXE) .depend
|
||||||
|
|
||||||
|
test check: default
|
||||||
|
@$(PGOBENCH)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o .depend stockfish
|
$(RM) *.o .depend *~ $(EXE) core bench.txt
|
||||||
|
|
||||||
|
|
||||||
###
|
### Possible targets. You may add your own ones here
|
||||||
### Compiler:
|
gcc:
|
||||||
###
|
$(MAKE) \
|
||||||
|
CXX='g++' \
|
||||||
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
|
all
|
||||||
|
|
||||||
CXX = g++
|
gcc-popcnt:
|
||||||
# CXX = icpc
|
$(MAKE) \
|
||||||
|
CXX='g++' \
|
||||||
|
CXXFLAGS="$(GCCFLAGS) -DUSE_POPCNT" \
|
||||||
|
all
|
||||||
|
|
||||||
|
|
||||||
###
|
icc:
|
||||||
### Dependencies
|
$(MAKE) \
|
||||||
###
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS)" \
|
||||||
|
all
|
||||||
|
|
||||||
|
icc-profile-make:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS)" \
|
||||||
|
CXXFLAGS+='-prof-gen=srcpos -prof_dir ./profdir' \
|
||||||
|
all
|
||||||
|
|
||||||
|
icc-profile-use:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS)" \
|
||||||
|
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
||||||
|
all
|
||||||
|
|
||||||
|
icc-profile:
|
||||||
|
@rm -rf profdir
|
||||||
|
@mkdir profdir
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(MAKE) icc-profile-make
|
||||||
|
@echo ""
|
||||||
|
@echo "Running benchmark for pgo-build ..."
|
||||||
|
@$(PGOBENCH) > /dev/null
|
||||||
|
@echo "Benchmark finished. Build final executable now ..."
|
||||||
|
@echo ""
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(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
|
||||||
|
|
||||||
|
osx-ppc64:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='g++' \
|
||||||
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
|
CXXFLAGS+='-arch ppc64' \
|
||||||
|
CXXFLAGS+='-DBIGENDIAN' \
|
||||||
|
LDFLAGS+='-arch ppc64' \
|
||||||
|
all
|
||||||
|
|
||||||
|
osx-x86:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='g++' \
|
||||||
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
|
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 -mdynamic-no-pic' \
|
||||||
|
LDFLAGS+='-arch x86_64 -mdynamic-no-pic' \
|
||||||
|
all
|
||||||
|
|
||||||
|
osx-icc32:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||||
|
CXXFLAGS+='-arch i386' \
|
||||||
|
LDFLAGS+='-arch i386' \
|
||||||
|
all
|
||||||
|
|
||||||
|
osx-icc64:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||||
|
CXXFLAGS+='-arch x86_64' \
|
||||||
|
LDFLAGS+='-arch x86_64' \
|
||||||
|
all
|
||||||
|
|
||||||
|
osx-icc32-profile-make:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||||
|
CXXFLAGS+='-arch i386' \
|
||||||
|
CXXFLAGS+='-prof_gen -prof_dir ./profdir' \
|
||||||
|
LDFLAGS+='-arch i386' \
|
||||||
|
all
|
||||||
|
|
||||||
|
osx-icc32-profile-use:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||||
|
CXXFLAGS+='-arch i386' \
|
||||||
|
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
||||||
|
LDFLAGS+='-arch i386' \
|
||||||
|
all
|
||||||
|
|
||||||
|
osx-icc32-profile:
|
||||||
|
@rm -rf profdir
|
||||||
|
@mkdir profdir
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(MAKE) osx-icc32-profile-make
|
||||||
|
@echo ""
|
||||||
|
@echo "Running benchmark for pgo-build ..."
|
||||||
|
@$(PGOBENCH) > /dev/null
|
||||||
|
@echo "Benchmark finished. Build final executable now ..."
|
||||||
|
@echo ""
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(MAKE) osx-icc32-profile-use
|
||||||
|
@rm -rf profdir bench.txt
|
||||||
|
|
||||||
|
osx-icc64-profile-make:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||||
|
CXXFLAGS+='-arch x86_64' \
|
||||||
|
CXXFLAGS+='-prof_gen -prof_dir ./profdir' \
|
||||||
|
LDFLAGS+='-arch x86_64' \
|
||||||
|
all
|
||||||
|
|
||||||
|
osx-icc64-profile-use:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='icpc' \
|
||||||
|
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||||
|
CXXFLAGS+='-arch x86_64' \
|
||||||
|
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
||||||
|
LDFLAGS+='-arch x86_64' \
|
||||||
|
all
|
||||||
|
|
||||||
|
osx-icc64-profile:
|
||||||
|
@rm -rf profdir
|
||||||
|
@mkdir profdir
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(MAKE) osx-icc64-profile-make
|
||||||
|
@echo ""
|
||||||
|
@echo "Running benchmark for pgo-build ..."
|
||||||
|
@$(PGOBENCH) > /dev/null
|
||||||
|
@echo "Benchmark finished. Build final executable now ..."
|
||||||
|
@echo ""
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(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:
|
||||||
|
strip $(EXE)
|
||||||
|
|
||||||
|
|
||||||
|
### Compilation. Do not change
|
||||||
$(EXE): $(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
install: default
|
||||||
|
-mkdir -p -m 755 $(BINDIR)
|
||||||
|
-cp $(EXE) $(BINDIR)
|
||||||
|
-strip $(BINDIR)/$(EXE)
|
||||||
|
|
||||||
|
### Dependencies. Do not change
|
||||||
.depend:
|
.depend:
|
||||||
$(CXX) -MM $(OBJS:.o=.cpp) > $@
|
-@$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
||||||
|
|
||||||
include .depend
|
-include .depend
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Compiler and linker switches
|
|
||||||
###
|
|
||||||
|
|
||||||
# Enable/disable debugging, disabled by default
|
|
||||||
|
|
||||||
CXXFLAGS += -DNDEBUG
|
|
||||||
|
|
||||||
|
|
||||||
# Compile with full warnings, and symbol names stripped, you can use
|
|
||||||
# -g instead of -s to compile symbol's table in, useful for debugging.
|
|
||||||
|
|
||||||
CXXFLAGS += -Wall -s
|
|
||||||
|
|
||||||
|
|
||||||
# General optimization flags. Note that -O2 might be faster than -O3 on some
|
|
||||||
# systems; this requires testing.
|
|
||||||
|
|
||||||
CXXFLAGS += -O3 -fno-exceptions -fno-rtti -fno-strict-aliasing
|
|
||||||
|
|
||||||
# Disable most annoying warnings for the Intel C++ compiler
|
|
||||||
|
|
||||||
# CXXFLAGS += -wd383,869,981
|
|
||||||
|
|
||||||
|
|
||||||
# Compiler optimization flags for the Intel C++ compiler in Mac OS X:
|
|
||||||
|
|
||||||
# CXXFLAGS += -mdynamic-no-pic -no-prec-div -ipo -static -xP
|
|
||||||
|
|
||||||
|
|
||||||
# Profiler guided optimization with the Intel C++ compiler v11. To use it, first
|
|
||||||
# create the directory ./profdata if it does not already exist, and delete its
|
|
||||||
# contents if it does exist. Then compile with -prof_gen, and run the
|
|
||||||
# resulting binary for a while (for instance, do ./stockfish bench 128 1, and
|
|
||||||
# wait 15 minutes for the benchmark to complete). Then do a 'make clean', and
|
|
||||||
# recompile with -prof_use.
|
|
||||||
|
|
||||||
# CXXFLAGS += -prof-gen -prof-dir./profdata
|
|
||||||
# CXXFLAGS += -prof-use -ipo -prof_dir./profdata
|
|
||||||
|
|
||||||
|
|
||||||
# Profiler guided optimization with GCC. I've never been able to make this
|
|
||||||
# work.
|
|
||||||
|
|
||||||
# CXXFLAGS += -fprofile-generate
|
|
||||||
# LDFLAGS += -fprofile-generate
|
|
||||||
# CXXFLAGS += -fprofile-use
|
|
||||||
# CXXFLAGS += -fprofile-use
|
|
||||||
|
|
||||||
|
|
||||||
# General linker flags
|
|
||||||
|
|
||||||
LDFLAGS += -lm -lpthread
|
|
||||||
|
|
||||||
|
|
||||||
# Compiler switches for generating binaries for various CPUs in Mac OS X.
|
|
||||||
# Note that 'arch ppc' and 'arch ppc64' only works with g++, and not with
|
|
||||||
# the intel compiler.
|
|
||||||
|
|
||||||
# CXXFLAGS += -arch ppc
|
|
||||||
# CXXFLAGS += -arch ppc64
|
|
||||||
# CXXFLAGS += -arch i386
|
|
||||||
# CXXFLAGS += -arch x86_64
|
|
||||||
# LDFLAGS += -arch ppc
|
|
||||||
# LDFLAGS += -arch ppc64
|
|
||||||
# LDFLAGS += -arch i386
|
|
||||||
# LDFLAGS += -arch x86_64
|
|
||||||
|
|
||||||
|
|
||||||
# Backwards compatibility with Mac OS X 10.4 when compiling under 10.5 with
|
|
||||||
# GCC 4.0. I haven't found a way to make it work with GCC 4.2.
|
|
||||||
|
|
||||||
# CXXFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
|
|
||||||
# CXXFLAGS += -mmacosx-version-min=10.4
|
|
||||||
# LDFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
|
|
||||||
# LDFLAGS += -Wl,-syslibroot /Developer/SDKs/MacOSX10.4u.sdk
|
|
||||||
# LDFLAGS += -mmacosx-version-min=10.4
|
|
||||||
|
|
||||||
|
|
||||||
# Backwards compatibility with Mac OS X 10.4 when compiling with ICC. Doesn't
|
|
||||||
# work yet. :-(
|
|
||||||
|
|
||||||
# CXXFLAGS += -DMAC_OS_X_VERSION_MIN_REQUIRED=1040
|
|
||||||
# CXXFLAGS += -DMAC_OS_X_VERSION_MAX_ALLOWED=1040
|
|
||||||
# CXXFLAGS += -D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1040
|
|
||||||
# CXXFLAGS += -F/Developer/SDKs/MacOSX10.4u.sdk/
|
|
||||||
# LDFLAGS += -Wl,-syslibroot -Wl,/Developer/SDKs/MacOSX10.4u.sdk
|
|
||||||
|
|||||||
+5
-9
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -47,9 +47,9 @@ Application::Application() {
|
|||||||
init_uci_options();
|
init_uci_options();
|
||||||
Position::init_zobrist();
|
Position::init_zobrist();
|
||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
MovePicker::init_phase_table();
|
|
||||||
init_eval(1);
|
init_eval(1);
|
||||||
init_bitbases();
|
init_bitbases();
|
||||||
|
init_search();
|
||||||
init_threads();
|
init_threads();
|
||||||
|
|
||||||
// Make random number generation less deterministic, for book moves
|
// Make random number generation less deterministic, for book moves
|
||||||
@@ -59,19 +59,15 @@ Application::Application() {
|
|||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
|
||||||
stop_threads();
|
exit_threads();
|
||||||
quit_eval();
|
quit_eval();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::initialize() {
|
void Application::initialize() {
|
||||||
|
|
||||||
instance();
|
// A static Application object is allocated
|
||||||
}
|
// once only when this function is called.
|
||||||
|
|
||||||
Application& Application::instance() {
|
|
||||||
|
|
||||||
static Application singleton;
|
static Application singleton;
|
||||||
return singleton;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::exit_with_failure() {
|
void Application::exit_with_failure() {
|
||||||
|
|||||||
+2
-9
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,18 +29,11 @@ class Application {
|
|||||||
|
|
||||||
Application();
|
Application();
|
||||||
Application(const Application&);
|
Application(const Application&);
|
||||||
|
~Application();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void initialize();
|
static void initialize();
|
||||||
static void exit_with_failure();
|
static void exit_with_failure();
|
||||||
|
|
||||||
~Application();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static Application& instance();
|
|
||||||
|
|
||||||
void init();
|
|
||||||
void deallocateAll();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !defined(APPLICATION_H_INCLUDED)
|
#endif // !defined(APPLICATION_H_INCLUDED)
|
||||||
|
|||||||
+7
-5
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -84,9 +84,9 @@ void benchmark(const string& commandLine) {
|
|||||||
}
|
}
|
||||||
csStr >> threads;
|
csStr >> threads;
|
||||||
csVal >> val;
|
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();
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
set_option_value("Hash", ttSize);
|
set_option_value("Hash", ttSize);
|
||||||
@@ -104,7 +104,7 @@ void benchmark(const string& commandLine) {
|
|||||||
|
|
||||||
if (limitType == "time")
|
if (limitType == "time")
|
||||||
secsPerPos = val * 1000;
|
secsPerPos = val * 1000;
|
||||||
else if (limitType == "depth")
|
else if (limitType == "depth" || limitType == "perft")
|
||||||
maxDepth = val;
|
maxDepth = val;
|
||||||
else
|
else
|
||||||
maxNodes = val;
|
maxNodes = val;
|
||||||
@@ -153,7 +153,9 @@ void benchmark(const string& commandLine) {
|
|||||||
int dummy[2] = {0, 0};
|
int dummy[2] = {0, 0};
|
||||||
Position pos(*it);
|
Position pos(*it);
|
||||||
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
|
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;
|
break;
|
||||||
totalNodes += nodes_searched();
|
totalNodes += nodes_searched();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+110
-20
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -163,6 +163,53 @@ const int RShift[64] = {
|
|||||||
|
|
||||||
#endif // defined(IS_64BIT)
|
#endif // defined(IS_64BIT)
|
||||||
|
|
||||||
|
const Bitboard SquaresByColorBB[2] = { BlackSquaresBB, WhiteSquaresBB };
|
||||||
|
|
||||||
|
const Bitboard FileBB[8] = {
|
||||||
|
FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard NeighboringFilesBB[8] = {
|
||||||
|
FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB,
|
||||||
|
FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard ThisAndNeighboringFilesBB[8] = {
|
||||||
|
FileABB|FileBBB, FileABB|FileBBB|FileCBB,
|
||||||
|
FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB,
|
||||||
|
FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB,
|
||||||
|
FileFBB|FileGBB|FileHBB, FileGBB|FileHBB
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard RankBB[8] = {
|
||||||
|
Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard RelativeRankBB[2][8] = {
|
||||||
|
{ Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB },
|
||||||
|
{ Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard InFrontBB[2][8] = {
|
||||||
|
{ Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank7BB | Rank8BB,
|
||||||
|
Rank8BB,
|
||||||
|
EmptyBoardBB
|
||||||
|
},
|
||||||
|
{ EmptyBoardBB,
|
||||||
|
Rank1BB,
|
||||||
|
Rank2BB | Rank1BB,
|
||||||
|
Rank3BB | Rank2BB | Rank1BB,
|
||||||
|
Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||||
|
Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||||
|
Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||||
|
Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Bitboard RMask[64];
|
Bitboard RMask[64];
|
||||||
int RAttackIndex[64];
|
int RAttackIndex[64];
|
||||||
@@ -186,6 +233,8 @@ Bitboard BishopPseudoAttacks[64];
|
|||||||
Bitboard RookPseudoAttacks[64];
|
Bitboard RookPseudoAttacks[64];
|
||||||
Bitboard QueenPseudoAttacks[64];
|
Bitboard QueenPseudoAttacks[64];
|
||||||
|
|
||||||
|
uint8_t BitCount8Bit[256];
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
@@ -248,7 +297,8 @@ void init_bitboards() {
|
|||||||
|
|
||||||
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
||||||
|
|
||||||
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,
|
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,
|
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,
|
16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43,
|
||||||
@@ -267,7 +317,8 @@ Square pop_1st_bit(Bitboard* b) {
|
|||||||
|
|
||||||
#elif !defined(USE_BSFQ)
|
#elif !defined(USE_BSFQ)
|
||||||
|
|
||||||
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,
|
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,
|
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,
|
26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28,
|
||||||
@@ -285,36 +336,72 @@ union b_union {
|
|||||||
|
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
struct {
|
struct {
|
||||||
|
#if defined (BIGENDIAN)
|
||||||
|
uint32_t h;
|
||||||
|
uint32_t l;
|
||||||
|
#else
|
||||||
uint32_t l;
|
uint32_t l;
|
||||||
uint32_t h;
|
uint32_t h;
|
||||||
|
#endif
|
||||||
} dw;
|
} dw;
|
||||||
};
|
};
|
||||||
|
|
||||||
// WARNING: Needs -fno-strict-aliasing compiler option
|
|
||||||
Square pop_1st_bit(Bitboard* bb) {
|
Square pop_1st_bit(Bitboard* bb) {
|
||||||
|
|
||||||
b_union u;
|
b_union u;
|
||||||
uint32_t b;
|
Square ret;
|
||||||
|
|
||||||
u.b = *bb;
|
u.b = *bb;
|
||||||
|
|
||||||
if (u.dw.l)
|
if (u.dw.l)
|
||||||
{
|
{
|
||||||
b = u.dw.l;
|
ret = Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||||
*((uint32_t*)bb) = b & (b - 1);
|
u.dw.l &= (u.dw.l - 1);
|
||||||
b ^= (b - 1);
|
*bb = u.b;
|
||||||
}
|
return ret;
|
||||||
else
|
}
|
||||||
{
|
ret = Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
||||||
b = u.dw.h;
|
u.dw.h &= (u.dw.h - 1);
|
||||||
*((uint32_t*)bb+1) = b & (b - 1); // Little endian only?
|
*bb = u.b;
|
||||||
b = ~(b ^ (b - 1));
|
return ret;
|
||||||
}
|
|
||||||
return Square(BitTable[(b * 0x783a9b23) >> 26]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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 {
|
namespace {
|
||||||
|
|
||||||
// All functions below are used to precompute various bitboards during
|
// All functions below are used to precompute various bitboards during
|
||||||
@@ -335,6 +422,9 @@ namespace {
|
|||||||
in_front_bb(c, s) & this_and_neighboring_files_bb(s);
|
in_front_bb(c, s) & this_and_neighboring_files_bb(s);
|
||||||
OutpostMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
OutpostMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Bitboard b = 0ULL; b < 256ULL; b++)
|
||||||
|
BitCount8Bit[b] = (uint8_t)count_1s(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+13
-49
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -40,7 +40,6 @@ const Bitboard EmptyBoardBB = 0ULL;
|
|||||||
|
|
||||||
const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL;
|
const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL;
|
||||||
const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL;
|
const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL;
|
||||||
const Bitboard SquaresByColorBB[2] = { BlackSquaresBB, WhiteSquaresBB };
|
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
const Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
const Bitboard FileBBB = 0x0202020202020202ULL;
|
const Bitboard FileBBB = 0x0202020202020202ULL;
|
||||||
@@ -51,22 +50,6 @@ const Bitboard FileFBB = 0x2020202020202020ULL;
|
|||||||
const Bitboard FileGBB = 0x4040404040404040ULL;
|
const Bitboard FileGBB = 0x4040404040404040ULL;
|
||||||
const Bitboard FileHBB = 0x8080808080808080ULL;
|
const Bitboard FileHBB = 0x8080808080808080ULL;
|
||||||
|
|
||||||
const Bitboard FileBB[8] = {
|
|
||||||
FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard NeighboringFilesBB[8] = {
|
|
||||||
FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB,
|
|
||||||
FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard ThisAndNeighboringFilesBB[8] = {
|
|
||||||
FileABB|FileBBB, FileABB|FileBBB|FileCBB,
|
|
||||||
FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB,
|
|
||||||
FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB,
|
|
||||||
FileFBB|FileGBB|FileHBB, FileGBB|FileHBB
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard Rank1BB = 0xFFULL;
|
const Bitboard Rank1BB = 0xFFULL;
|
||||||
const Bitboard Rank2BB = 0xFF00ULL;
|
const Bitboard Rank2BB = 0xFF00ULL;
|
||||||
const Bitboard Rank3BB = 0xFF0000ULL;
|
const Bitboard Rank3BB = 0xFF0000ULL;
|
||||||
@@ -76,35 +59,13 @@ const Bitboard Rank6BB = 0xFF0000000000ULL;
|
|||||||
const Bitboard Rank7BB = 0xFF000000000000ULL;
|
const Bitboard Rank7BB = 0xFF000000000000ULL;
|
||||||
const Bitboard Rank8BB = 0xFF00000000000000ULL;
|
const Bitboard Rank8BB = 0xFF00000000000000ULL;
|
||||||
|
|
||||||
const Bitboard RankBB[8] = {
|
extern const Bitboard SquaresByColorBB[2];
|
||||||
Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
|
extern const Bitboard FileBB[8];
|
||||||
};
|
extern const Bitboard NeighboringFilesBB[8];
|
||||||
|
extern const Bitboard ThisAndNeighboringFilesBB[8];
|
||||||
const Bitboard RelativeRankBB[2][8] = {
|
extern const Bitboard RankBB[8];
|
||||||
{ Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB },
|
extern const Bitboard RelativeRankBB[2][8];
|
||||||
{ Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB }
|
extern const Bitboard InFrontBB[2][8];
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard InFrontBB[2][8] = {
|
|
||||||
{ Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank7BB | Rank8BB,
|
|
||||||
Rank8BB,
|
|
||||||
EmptyBoardBB
|
|
||||||
},
|
|
||||||
{ EmptyBoardBB,
|
|
||||||
Rank1BB,
|
|
||||||
Rank2BB | Rank1BB,
|
|
||||||
Rank3BB | Rank2BB | Rank1BB,
|
|
||||||
Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
|
||||||
Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
|
||||||
Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
|
||||||
Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern Bitboard SetMaskBB[65];
|
extern Bitboard SetMaskBB[65];
|
||||||
extern Bitboard ClearMaskBB[65];
|
extern Bitboard ClearMaskBB[65];
|
||||||
@@ -132,6 +93,8 @@ extern Bitboard BishopPseudoAttacks[64];
|
|||||||
extern Bitboard RookPseudoAttacks[64];
|
extern Bitboard RookPseudoAttacks[64];
|
||||||
extern Bitboard QueenPseudoAttacks[64];
|
extern Bitboard QueenPseudoAttacks[64];
|
||||||
|
|
||||||
|
extern uint8_t BitCount8Bit[256];
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Inline functions
|
//// Inline functions
|
||||||
@@ -360,13 +323,13 @@ inline Bitboard isolated_pawn_mask(Square s) {
|
|||||||
|
|
||||||
#if defined(USE_BSFQ) // Assembly code by Heinz van Saanen
|
#if defined(USE_BSFQ) // Assembly code by Heinz van Saanen
|
||||||
|
|
||||||
inline Square __attribute__((always_inline)) first_1(Bitboard b) {
|
inline Square first_1(Bitboard b) {
|
||||||
Bitboard dummy;
|
Bitboard dummy;
|
||||||
__asm__("bsfq %1, %0": "=r"(dummy): "rm"(b) );
|
__asm__("bsfq %1, %0": "=r"(dummy): "rm"(b) );
|
||||||
return (Square)(dummy);
|
return (Square)(dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square __attribute__((always_inline)) pop_1st_bit(Bitboard* b) {
|
inline Square pop_1st_bit(Bitboard* b) {
|
||||||
const Square s = first_1(*b);
|
const Square s = first_1(*b);
|
||||||
*b &= ~(1ULL<<s);
|
*b &= ~(1ULL<<s);
|
||||||
return s;
|
return s;
|
||||||
@@ -386,6 +349,7 @@ extern Square pop_1st_bit(Bitboard* b);
|
|||||||
|
|
||||||
extern void print_bitboard(Bitboard b);
|
extern void print_bitboard(Bitboard b);
|
||||||
extern void init_bitboards();
|
extern void init_bitboards();
|
||||||
|
extern int bitScanReverse32(uint32_t b);
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(BITBOARD_H_INCLUDED)
|
#endif // !defined(BITBOARD_H_INCLUDED)
|
||||||
|
|||||||
+26
-53
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,62 +22,22 @@
|
|||||||
#if !defined(BITCOUNT_H_INCLUDED)
|
#if !defined(BITCOUNT_H_INCLUDED)
|
||||||
#define 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"
|
#include "types.h"
|
||||||
|
|
||||||
// Select type of intrinsic bit count instruction to use
|
// Select type of intrinsic bit count instruction to use, see
|
||||||
|
// README.txt on how to pgo compile with POPCNT support.
|
||||||
#if defined(__INTEL_COMPILER) && defined(IS_64BIT) && defined(USE_POPCNT) // Intel compiler
|
#if !defined(USE_POPCNT)
|
||||||
|
|
||||||
#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; }
|
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) 0
|
#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
|
/// 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
|
// Global constant initialized at startup that is set to true if
|
||||||
// CPU on which application runs supports POPCNT intrinsic. Unless
|
// CPU on which application runs supports POPCNT intrinsic. Unless
|
||||||
// USE_POPCNT is not defined.
|
// USE_POPCNT is not defined.
|
||||||
|
#if defined(USE_POPCNT)
|
||||||
const bool CpuHasPOPCNT = cpu_has_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
|
// Global constant used to print info about the use of 64 optimized
|
||||||
|
|||||||
+7
-7
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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,
|
/// Book::file_name() returns the file name of the currently active book,
|
||||||
/// or the empty string if no book is open.
|
/// 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 : "";
|
return is_open() ? fileName : "";
|
||||||
}
|
}
|
||||||
@@ -429,11 +429,11 @@ Move Book::get_move(const Position& pos) {
|
|||||||
if (!bookMove)
|
if (!bookMove)
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
|
|
||||||
MoveStack moves[256];
|
MoveStack mlist[256];
|
||||||
int n = generate_legal_moves(pos, moves);
|
MoveStack* last = generate_moves(pos, mlist);
|
||||||
for (int j = 0; j < n; j++)
|
for (MoveStack* cur = mlist; cur != last; cur++)
|
||||||
if ((int(moves[j].move) & 07777) == bookMove)
|
if ((int(cur->move) & 07777) == bookMove)
|
||||||
return moves[j].move;
|
return cur->move;
|
||||||
|
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -53,11 +53,14 @@ struct BookEntry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Book : private std::ifstream {
|
class Book : private std::ifstream {
|
||||||
|
Book(const Book&); // just decleared..
|
||||||
|
Book& operator=(const Book&); // ..to avoid a warning
|
||||||
public:
|
public:
|
||||||
|
Book() {}
|
||||||
~Book();
|
~Book();
|
||||||
void open(const std::string& fName);
|
void open(const std::string& fName);
|
||||||
void close();
|
void close();
|
||||||
const std::string file_name() const;
|
const std::string file_name();
|
||||||
Move get_move(const Position& pos);
|
Move get_move(const Position& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+5
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,7 +27,8 @@
|
|||||||
|
|
||||||
enum Depth {
|
enum Depth {
|
||||||
DEPTH_ZERO = 0,
|
DEPTH_ZERO = 0,
|
||||||
DEPTH_MAX = 200 // 100 * OnePly;
|
DEPTH_MAX = 200, // 100 * OnePly;
|
||||||
|
DEPTH_ENSURE_SIGNED = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -48,7 +49,8 @@ inline void operator+= (Depth &d, int i) { d = Depth(int(d) + i); }
|
|||||||
inline void operator+= (Depth &d1, Depth d2) { d1 += int(d2); }
|
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 d, int i) { return Depth(int(d) - i); }
|
||||||
inline Depth operator- (Depth d1, Depth d2) { return Depth(int(d1) - int(d2)); }
|
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* (Depth d, int i) { return Depth(int(d) * i); }
|
||||||
inline Depth operator* (int i, Depth d) { 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); }
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+22
-51
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,41 +29,6 @@
|
|||||||
#include "endgame.h"
|
#include "endgame.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Constants and variables
|
|
||||||
////
|
|
||||||
|
|
||||||
/// Evaluation functions
|
|
||||||
|
|
||||||
// Generic "mate lone king" eval
|
|
||||||
EvaluationFunction<KXK> EvaluateKXK(WHITE), EvaluateKKX(BLACK);
|
|
||||||
|
|
||||||
// K and two minors vs K and one or two minors
|
|
||||||
EvaluationFunction<KmmKm> EvaluateKmmKm(WHITE);
|
|
||||||
|
|
||||||
EvaluationFunction<KBNK> EvaluateKBNK(WHITE), EvaluateKKBN(BLACK); // KBN vs K
|
|
||||||
EvaluationFunction<KPK> EvaluateKPK(WHITE), EvaluateKKP(BLACK); // KP vs K
|
|
||||||
EvaluationFunction<KRKP> EvaluateKRKP(WHITE), EvaluateKPKR(BLACK); // KR vs KP
|
|
||||||
EvaluationFunction<KRKB> EvaluateKRKB(WHITE), EvaluateKBKR(BLACK); // KR vs KB
|
|
||||||
EvaluationFunction<KRKN> EvaluateKRKN(WHITE), EvaluateKNKR(BLACK); // KR vs KN
|
|
||||||
EvaluationFunction<KQKR> EvaluateKQKR(WHITE), EvaluateKRKQ(BLACK); // KQ vs KR
|
|
||||||
EvaluationFunction<KBBKN> EvaluateKBBKN(WHITE), EvaluateKNKBB(BLACK); // KBB vs KN
|
|
||||||
|
|
||||||
|
|
||||||
/// Scaling functions
|
|
||||||
|
|
||||||
ScalingFunction<KBPK> ScaleKBPK(WHITE), ScaleKKBP(BLACK); // KBP vs K
|
|
||||||
ScalingFunction<KQKRP> ScaleKQKRP(WHITE), ScaleKRPKQ(BLACK); // KQ vs KRP
|
|
||||||
ScalingFunction<KRPKR> ScaleKRPKR(WHITE), ScaleKRKRP(BLACK); // KRP vs KR
|
|
||||||
ScalingFunction<KRPPKRP> ScaleKRPPKRP(WHITE), ScaleKRPKRPP(BLACK); // KRPP vs KRP
|
|
||||||
ScalingFunction<KPsK> ScaleKPsK(WHITE), ScaleKKPs(BLACK); // King and pawns vs king
|
|
||||||
ScalingFunction<KBPKB> ScaleKBPKB(WHITE), ScaleKBKBP(BLACK); // KBP vs KB
|
|
||||||
ScalingFunction<KBPPKB> ScaleKBPPKB(WHITE), ScaleKBKBPP(BLACK); // KBPP vs KB
|
|
||||||
ScalingFunction<KBPKN> ScaleKBPKN(WHITE), ScaleKNKBP(BLACK); // KBP vs KN
|
|
||||||
ScalingFunction<KNPK> ScaleKNPK(WHITE), ScaleKKNP(BLACK); // KNP vs K
|
|
||||||
ScalingFunction<KPKP> ScaleKPKPw(WHITE), ScaleKPKPb(BLACK); // KPKP
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
////
|
////
|
||||||
@@ -364,7 +329,7 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
|
|||||||
assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
|
||||||
assert(pos.piece_count(weakerSide, KNIGHT) == 1);
|
assert(pos.piece_count(weakerSide, KNIGHT) == 1);
|
||||||
assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
|
assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
|
||||||
assert(pos.pawns() == EmptyBoardBB);
|
assert(pos.pieces(PAWN) == EmptyBoardBB);
|
||||||
|
|
||||||
Value result = BishopValueEndgame;
|
Value result = BishopValueEndgame;
|
||||||
Square wksq = pos.king_square(strongerSide);
|
Square wksq = pos.king_square(strongerSide);
|
||||||
@@ -378,16 +343,23 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
|
|||||||
result += Value(square_distance(bksq, nsq) * 32);
|
result += Value(square_distance(bksq, nsq) * 32);
|
||||||
|
|
||||||
// Bonus for restricting the knight's mobility
|
// Bonus for restricting the knight's mobility
|
||||||
result += Value((8 - count_1s_max_15(pos.piece_attacks<KNIGHT>(nsq))) * 8);
|
result += Value((8 - count_1s_max_15(pos.attacks_from<KNIGHT>(nsq))) * 8);
|
||||||
|
|
||||||
return (strongerSide == pos.side_to_move() ? result : -result);
|
return (strongerSide == pos.side_to_move() ? result : -result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// K and two minors vs K and one or two minors or K and two knights against
|
||||||
|
/// king alone are always draw.
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KmmKm>::apply(const Position&) {
|
Value EvaluationFunction<KmmKm>::apply(const Position&) {
|
||||||
return Value(0);
|
return Value(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
Value EvaluationFunction<KNNK>::apply(const Position&) {
|
||||||
|
return Value(0);
|
||||||
|
}
|
||||||
|
|
||||||
/// KBPKScalingFunction scales endgames where the stronger side has king,
|
/// KBPKScalingFunction scales endgames where the stronger side has king,
|
||||||
/// bishop and one or more pawns. It checks for draws with rook pawns and a
|
/// bishop and one or more pawns. It checks for draws with rook pawns and a
|
||||||
@@ -395,7 +367,7 @@ Value EvaluationFunction<KmmKm>::apply(const Position&) {
|
|||||||
/// returned. If not, the return value is SCALE_FACTOR_NONE, i.e. no scaling
|
/// returned. If not, the return value is SCALE_FACTOR_NONE, i.e. no scaling
|
||||||
/// will be used.
|
/// will be used.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
|
ScaleFactor ScalingFunction<KBPsK>::apply(const Position& pos) {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
||||||
@@ -404,7 +376,7 @@ ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
|
|||||||
// No assertions about the material of weakerSide, because we want draws to
|
// No assertions about the material of weakerSide, because we want draws to
|
||||||
// be detected even when the weaker side has some pawns.
|
// be detected even when the weaker side has some pawns.
|
||||||
|
|
||||||
Bitboard pawns = pos.pawns(strongerSide);
|
Bitboard pawns = pos.pieces(PAWN, strongerSide);
|
||||||
File pawnFile = square_file(pos.piece_list(strongerSide, PAWN, 0));
|
File pawnFile = square_file(pos.piece_list(strongerSide, PAWN, 0));
|
||||||
|
|
||||||
// All pawns are on a single rook file ?
|
// All pawns are on a single rook file ?
|
||||||
@@ -421,7 +393,6 @@ ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
|
|||||||
// The bishop has the wrong color, and the defending king is on the
|
// The bishop has the wrong color, and the defending king is on the
|
||||||
// file of the pawn(s) or the neighboring file. Find the rank of the
|
// file of the pawn(s) or the neighboring file. Find the rank of the
|
||||||
// frontmost pawn.
|
// frontmost pawn.
|
||||||
|
|
||||||
Rank rank;
|
Rank rank;
|
||||||
if (strongerSide == WHITE)
|
if (strongerSide == WHITE)
|
||||||
{
|
{
|
||||||
@@ -450,7 +421,7 @@ ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
|
|||||||
/// It tests for fortress draws with a rook on the third rank defended by
|
/// It tests for fortress draws with a rook on the third rank defended by
|
||||||
/// a pawn.
|
/// a pawn.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KQKRP>::apply(const Position& pos) {
|
ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, QUEEN) == 1);
|
assert(pos.piece_count(strongerSide, QUEEN) == 1);
|
||||||
@@ -461,12 +432,12 @@ ScaleFactor ScalingFunction<KQKRP>::apply(const Position& pos) {
|
|||||||
Square kingSq = pos.king_square(weakerSide);
|
Square kingSq = pos.king_square(weakerSide);
|
||||||
if ( relative_rank(weakerSide, kingSq) <= RANK_2
|
if ( relative_rank(weakerSide, kingSq) <= RANK_2
|
||||||
&& relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
|
&& relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
|
||||||
&& (pos.rooks(weakerSide) & relative_rank_bb(weakerSide, RANK_3))
|
&& (pos.pieces(ROOK, weakerSide) & relative_rank_bb(weakerSide, RANK_3))
|
||||||
&& (pos.pawns(weakerSide) & relative_rank_bb(weakerSide, RANK_2))
|
&& (pos.pieces(PAWN, weakerSide) & relative_rank_bb(weakerSide, RANK_2))
|
||||||
&& (pos.piece_attacks<KING>(kingSq) & pos.pawns(weakerSide)))
|
&& (pos.attacks_from<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
|
||||||
{
|
{
|
||||||
Square rsq = pos.piece_list(weakerSide, ROOK, 0);
|
Square rsq = pos.piece_list(weakerSide, ROOK, 0);
|
||||||
if (pos.pawn_attacks(strongerSide, rsq) & pos.pawns(weakerSide))
|
if (pos.attacks_from<PAWN>(rsq, strongerSide) & pos.pieces(PAWN, weakerSide))
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
}
|
}
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
@@ -645,7 +616,7 @@ ScaleFactor ScalingFunction<KPsK>::apply(const Position &pos) {
|
|||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
||||||
assert(pos.piece_count(weakerSide, PAWN) == 0);
|
assert(pos.piece_count(weakerSide, PAWN) == 0);
|
||||||
|
|
||||||
Bitboard pawns = pos.pawns(strongerSide);
|
Bitboard pawns = pos.pieces(PAWN, strongerSide);
|
||||||
|
|
||||||
// Are all pawns on the 'a' file?
|
// Are all pawns on the 'a' file?
|
||||||
if ((pawns & ~FileABB) == EmptyBoardBB)
|
if ((pawns & ~FileABB) == EmptyBoardBB)
|
||||||
@@ -723,9 +694,9 @@ ScaleFactor ScalingFunction<KBPKB>::apply(const Position &pos) {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Bitboard ray = ray_bb(pawnSq, (strongerSide == WHITE)? SIGNED_DIR_N : SIGNED_DIR_S);
|
Bitboard ray = ray_bb(pawnSq, (strongerSide == WHITE)? SIGNED_DIR_N : SIGNED_DIR_S);
|
||||||
if (ray & pos.kings(weakerSide))
|
if (ray & pos.pieces(KING, weakerSide))
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
if( (pos.piece_attacks<BISHOP>(weakerBishopSq) & ray)
|
if( (pos.attacks_from<BISHOP>(weakerBishopSq) & ray)
|
||||||
&& square_distance(weakerBishopSq, pawnSq) >= 3)
|
&& square_distance(weakerBishopSq, pawnSq) >= 3)
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
}
|
}
|
||||||
@@ -790,13 +761,13 @@ ScaleFactor ScalingFunction<KBPPKB>::apply(const Position& pos) {
|
|||||||
if ( ksq == blockSq1
|
if ( ksq == blockSq1
|
||||||
&& square_color(ksq) != square_color(wbsq)
|
&& square_color(ksq) != square_color(wbsq)
|
||||||
&& ( bbsq == blockSq2
|
&& ( bbsq == blockSq2
|
||||||
|| (pos.piece_attacks<BISHOP>(blockSq2) & pos.bishops(weakerSide))
|
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
|
||||||
|| rank_distance(r1, r2) >= 2))
|
|| rank_distance(r1, r2) >= 2))
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
else if ( ksq == blockSq2
|
else if ( ksq == blockSq2
|
||||||
&& square_color(ksq) != square_color(wbsq)
|
&& square_color(ksq) != square_color(wbsq)
|
||||||
&& ( bbsq == blockSq1
|
&& ( bbsq == blockSq1
|
||||||
|| (pos.piece_attacks<BISHOP>(blockSq1) & pos.bishops(weakerSide))))
|
|| (pos.attacks_from<BISHOP>(blockSq1) & pos.pieces(BISHOP, weakerSide))))
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
else
|
else
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
|
|||||||
+7
-28
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -45,11 +45,12 @@ enum EndgameType {
|
|||||||
KRKN, // KR vs KN
|
KRKN, // KR vs KN
|
||||||
KQKR, // KQ vs KR
|
KQKR, // KQ vs KR
|
||||||
KBBKN, // KBB vs KN
|
KBBKN, // KBB vs KN
|
||||||
|
KNNK, // KNN vs K
|
||||||
KmmKm, // K and two minors vs K and one or two minors
|
KmmKm, // K and two minors vs K and one or two minors
|
||||||
|
|
||||||
// Scaling functions
|
// Scaling functions
|
||||||
KBPK, // KBP vs K
|
KBPsK, // KB+pawns vs K
|
||||||
KQKRP, // KQ vs KRP
|
KQKRPs, // KQ vs KR+pawns
|
||||||
KRPKR, // KRP vs KR
|
KRPKR, // KRP vs KR
|
||||||
KRPPKRP, // KRPP vs KRP
|
KRPPKRP, // KRPP vs KRP
|
||||||
KPsK, // King and pawns vs king
|
KPsK, // King and pawns vs king
|
||||||
@@ -68,6 +69,7 @@ public:
|
|||||||
EndgameFunctionBase(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
|
EndgameFunctionBase(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
|
||||||
virtual ~EndgameFunctionBase() {}
|
virtual ~EndgameFunctionBase() {}
|
||||||
virtual T apply(const Position&) = 0;
|
virtual T apply(const Position&) = 0;
|
||||||
|
Color color() const { return strongerSide; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Color strongerSide, weakerSide;
|
Color strongerSide, weakerSide;
|
||||||
@@ -81,42 +83,19 @@ typedef EndgameFunctionBase<ScaleFactor> EndgameScalingFunctionBase;
|
|||||||
|
|
||||||
template<EndgameType>
|
template<EndgameType>
|
||||||
struct EvaluationFunction : public EndgameEvaluationFunctionBase {
|
struct EvaluationFunction : public EndgameEvaluationFunctionBase {
|
||||||
|
typedef EndgameEvaluationFunctionBase Base;
|
||||||
explicit EvaluationFunction(Color c): EndgameEvaluationFunctionBase(c) {}
|
explicit EvaluationFunction(Color c): EndgameEvaluationFunctionBase(c) {}
|
||||||
Value apply(const Position&);
|
Value apply(const Position&);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<EndgameType>
|
template<EndgameType>
|
||||||
struct ScalingFunction : public EndgameScalingFunctionBase {
|
struct ScalingFunction : public EndgameScalingFunctionBase {
|
||||||
|
typedef EndgameScalingFunctionBase Base;
|
||||||
explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
|
explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
|
||||||
ScaleFactor apply(const Position&);
|
ScaleFactor apply(const Position&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Constants and variables
|
|
||||||
////
|
|
||||||
|
|
||||||
extern EvaluationFunction<KXK> EvaluateKXK, EvaluateKKX; // Generic "mate lone king" eval
|
|
||||||
extern EvaluationFunction<KBNK> EvaluateKBNK, EvaluateKKBN; // KBN vs K
|
|
||||||
extern EvaluationFunction<KPK> EvaluateKPK, EvaluateKKP; // KP vs K
|
|
||||||
extern EvaluationFunction<KRKP> EvaluateKRKP, EvaluateKPKR; // KR vs KP
|
|
||||||
extern EvaluationFunction<KRKB> EvaluateKRKB, EvaluateKBKR; // KR vs KB
|
|
||||||
extern EvaluationFunction<KRKN> EvaluateKRKN, EvaluateKNKR; // KR vs KN
|
|
||||||
extern EvaluationFunction<KQKR> EvaluateKQKR, EvaluateKRKQ; // KQ vs KR
|
|
||||||
extern EvaluationFunction<KBBKN> EvaluateKBBKN, EvaluateKNKBB; // KBB vs KN
|
|
||||||
extern EvaluationFunction<KmmKm> EvaluateKmmKm; // K and two minors vs K and one or two minors:
|
|
||||||
|
|
||||||
extern ScalingFunction<KBPK> ScaleKBPK, ScaleKKBP; // KBP vs K
|
|
||||||
extern ScalingFunction<KQKRP> ScaleKQKRP, ScaleKRPKQ; // KQ vs KRP
|
|
||||||
extern ScalingFunction<KRPKR> ScaleKRPKR, ScaleKRKRP; // KRP vs KR
|
|
||||||
extern ScalingFunction<KRPPKRP> ScaleKRPPKRP, ScaleKRPKRPP; // KRPP vs KRP
|
|
||||||
extern ScalingFunction<KPsK> ScaleKPsK, ScaleKKPs; // King and pawns vs king
|
|
||||||
extern ScalingFunction<KBPKB> ScaleKBPKB, ScaleKBKBP; // KBP vs KB
|
|
||||||
extern ScalingFunction<KBPPKB> ScaleKBPPKB, ScaleKBKBPP; // KBPP vs KB
|
|
||||||
extern ScalingFunction<KBPKN> ScaleKBPKN, ScaleKNKBP; // KBP vs KN
|
|
||||||
extern ScalingFunction<KNPK> ScaleKNPK, ScaleKKNP; // KNP vs K
|
|
||||||
extern ScalingFunction<KPKP> ScaleKPKPw, ScaleKPKPb; // KP vs KP
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|||||||
+574
-580
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
|
|
||||||
@@ -45,8 +47,10 @@ class Position;
|
|||||||
|
|
||||||
struct EvalInfo {
|
struct EvalInfo {
|
||||||
|
|
||||||
|
EvalInfo() { futilityMargin[0] = futilityMargin[1] = Value(0); }
|
||||||
|
|
||||||
// Middle game and endgame evaluations
|
// Middle game and endgame evaluations
|
||||||
Value mgValue, egValue;
|
Score value;
|
||||||
|
|
||||||
// Pointers to material and pawn hash table entries
|
// Pointers to material and pawn hash table entries
|
||||||
MaterialInfo* mi;
|
MaterialInfo* mi;
|
||||||
@@ -89,11 +93,11 @@ struct EvalInfo {
|
|||||||
Move mateThreat[2];
|
Move mateThreat[2];
|
||||||
|
|
||||||
// Middle game and endgame mobility scores.
|
// Middle game and endgame mobility scores.
|
||||||
Value mgMobility, egMobility;
|
Score mobility;
|
||||||
|
|
||||||
// Extra futility margin. This is added to the standard futility margin
|
// Extra futility margin. This is added to the standard futility margin
|
||||||
// in the quiescence search.
|
// in the quiescence search. One for each color.
|
||||||
Value futilityMargin;
|
Value futilityMargin[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +106,6 @@ struct EvalInfo {
|
|||||||
////
|
////
|
||||||
|
|
||||||
extern Value evaluate(const Position& pos, EvalInfo& ei, int threadID);
|
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 init_eval(int threads);
|
||||||
extern void quit_eval();
|
extern void quit_eval();
|
||||||
extern void read_weights(Color sideToMove);
|
extern void read_weights(Color sideToMove);
|
||||||
|
|||||||
+25
-15
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -42,8 +42,7 @@ History::History() { clear(); }
|
|||||||
|
|
||||||
void History::clear() {
|
void History::clear() {
|
||||||
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
||||||
memset(successCount, 0, 2 * 8 * 64 * sizeof(int));
|
memset(maxStaticValueDelta, 0, 2 * 8 * 64 * sizeof(int));
|
||||||
memset(failureCount, 0, 2 * 8 * 64 * sizeof(int));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,13 +57,12 @@ void History::success(Piece p, Square to, Depth d) {
|
|||||||
assert(square_is_ok(to));
|
assert(square_is_ok(to));
|
||||||
|
|
||||||
history[p][to] += int(d) * int(d);
|
history[p][to] += int(d) * int(d);
|
||||||
successCount[p][to]++;
|
|
||||||
|
|
||||||
// Prevent history overflow
|
// Prevent history overflow
|
||||||
if (history[p][to] >= HistoryMax)
|
if (history[p][to] >= HistoryMax)
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
for (int j = 0; j < 64; j++)
|
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
|
/// called for each non-capturing move which failed to produce a beta cutoff
|
||||||
/// at a node where a beta cutoff was finally found.
|
/// 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(piece_is_ok(p));
|
||||||
assert(square_is_ok(to));
|
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
|
/// History::set_gain() and History::gain() store and retrieve the
|
||||||
/// unsuccessful that it makes sense to prune it entirely.
|
/// 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 {
|
void History::set_gain(Piece p, Square to, Value delta)
|
||||||
|
{
|
||||||
assert(piece_is_ok(p));
|
if (delta >= maxStaticValueDelta[p][to])
|
||||||
assert(square_is_ok(to));
|
maxStaticValueDelta[p][to] = delta;
|
||||||
|
else
|
||||||
return (int(d) * successCount[p][to] < failureCount[p][to]);
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
|
#include "value.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -47,14 +48,14 @@ public:
|
|||||||
History();
|
History();
|
||||||
void clear();
|
void clear();
|
||||||
void success(Piece p, Square to, Depth d);
|
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;
|
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:
|
private:
|
||||||
int history[16][64]; // [piece][square]
|
int history[16][64]; // [piece][square]
|
||||||
int successCount[16][64];
|
int maxStaticValueDelta[16][64]; // [piece][from_square][to_square]
|
||||||
int failureCount[16][64];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ private:
|
|||||||
/// recently have a bigger importance for move ordering than the moves which
|
/// recently have a bigger importance for move ordering than the moves which
|
||||||
/// have been searched a long time ago.
|
/// have been searched a long time ago.
|
||||||
|
|
||||||
const int HistoryMax = 25000 * OnePly;
|
const int HistoryMax = 50000 * OnePly;
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(HISTORY_H_INCLUDED)
|
#endif // !defined(HISTORY_H_INCLUDED)
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -86,8 +86,9 @@ typedef pthread_mutex_t Lock;
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
typedef CRITICAL_SECTION Lock;
|
typedef CRITICAL_SECTION Lock;
|
||||||
# define lock_init(x, y) InitializeCriticalSection(x)
|
# define lock_init(x, y) InitializeCriticalSection(x)
|
||||||
@@ -98,5 +99,4 @@ typedef CRITICAL_SECTION Lock;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(LOCK_H_INCLUDED)
|
#endif // !defined(LOCK_H_INCLUDED)
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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)
|
if (string(argv[1]) != "bench" || argc < 4 || argc > 8)
|
||||||
cout << "Usage: stockfish bench <hash size> <threads> "
|
cout << "Usage: stockfish bench <hash size> <threads> "
|
||||||
<< "[time = 60s] [fen positions file = default] "
|
<< "[time = 60s] [fen positions file = default] "
|
||||||
<< "[time, depth or node limited = time] "
|
<< "[time, depth, perft or node limited = time] "
|
||||||
<< "[timing file name = none]" << endl;
|
<< "[timing file name = none]" << endl;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
+168
-130
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,7 +28,8 @@
|
|||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
|
||||||
using std::string;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
@@ -37,67 +38,95 @@ using std::string;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Values modified by Joona Kiiski
|
// Values modified by Joona Kiiski
|
||||||
const Value BishopPairMidgameBonus = Value(109);
|
const Value MidgameLimit = Value(15581);
|
||||||
const Value BishopPairEndgameBonus = Value(97);
|
const Value EndgameLimit = Value(3998);
|
||||||
|
|
||||||
Key KNNKMaterialKey, KKNNMaterialKey;
|
// 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 QuadraticCoefficientsSameColor[][6] = {
|
||||||
|
{ 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 },
|
||||||
|
{ 7, 25, 4, 7, 7, 7 }, { -27, -2, 46, 100, 56, 7 }, { 58, 29, 83, 148, -3, -25 } };
|
||||||
|
|
||||||
|
const int QuadraticCoefficientsOppositeColor[][6] = {
|
||||||
|
{ 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 },
|
||||||
|
{ 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } };
|
||||||
|
|
||||||
|
// Named endgame evaluation and scaling functions, these
|
||||||
|
// are accessed direcly and not through the function maps.
|
||||||
|
EvaluationFunction<KmmKm> EvaluateKmmKm(WHITE);
|
||||||
|
EvaluationFunction<KXK> EvaluateKXK(WHITE), EvaluateKKX(BLACK);
|
||||||
|
ScalingFunction<KBPsK> ScaleKBPsK(WHITE), ScaleKKBPs(BLACK);
|
||||||
|
ScalingFunction<KQKRPs> ScaleKQKRPs(WHITE), ScaleKRPsKQ(BLACK);
|
||||||
|
ScalingFunction<KPsK> ScaleKPsK(WHITE), ScaleKKPs(BLACK);
|
||||||
|
ScalingFunction<KPKP> ScaleKPKPw(WHITE), ScaleKPKPb(BLACK);
|
||||||
|
|
||||||
|
typedef EndgameEvaluationFunctionBase EF;
|
||||||
|
typedef EndgameScalingFunctionBase SF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Classes
|
//// Classes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
/// EndgameFunctions class stores endgame evaluation and scaling functions
|
||||||
/// See header for a class description. It is declared here to avoid
|
/// in two std::map. Because STL library is not guaranteed to be thread
|
||||||
/// to include <map> in the header file.
|
/// safe even for read access, the maps, although with identical content,
|
||||||
|
/// are replicated for each thread. This is faster then using locks.
|
||||||
|
|
||||||
class EndgameFunctions {
|
class EndgameFunctions {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EndgameFunctions();
|
EndgameFunctions();
|
||||||
EndgameEvaluationFunctionBase* getEEF(Key key) const;
|
~EndgameFunctions();
|
||||||
EndgameScalingFunctionBase* getESF(Key key, Color* c) const;
|
template<class T> T* get(Key key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void add(const string& keyCode, EndgameEvaluationFunctionBase* f);
|
template<class T> void add(const string& keyCode);
|
||||||
void add(const string& keyCode, Color c, EndgameScalingFunctionBase* f);
|
|
||||||
Key buildKey(const string& keyCode);
|
|
||||||
|
|
||||||
struct ScalingInfo
|
static Key buildKey(const string& keyCode);
|
||||||
{
|
static const string swapColors(const string& keyCode);
|
||||||
Color col;
|
|
||||||
EndgameScalingFunctionBase* fun;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::map<Key, EndgameEvaluationFunctionBase*> EEFmap;
|
// Here we store two maps, for evaluate and scaling functions
|
||||||
std::map<Key, ScalingInfo> ESFmap;
|
pair<map<Key, EF*>, map<Key, SF*> > maps;
|
||||||
|
|
||||||
|
// Maps accessing functions returning const and non-const references
|
||||||
|
template<typename T> const map<Key, T*>& get() const { return maps.first; }
|
||||||
|
template<typename T> map<Key, T*>& get() { return maps.first; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Explicit specializations of a member function shall be declared in
|
||||||
|
// the namespace of which the class template is a member.
|
||||||
|
template<> const map<Key, SF*>&
|
||||||
|
EndgameFunctions::get<SF>() const { return maps.second; }
|
||||||
|
|
||||||
|
template<> map<Key, SF*>&
|
||||||
|
EndgameFunctions::get<SF>() { return maps.second; }
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
|
/// MaterialInfoTable c'tor and d'tor, called once by each thread
|
||||||
/// Constructor for the MaterialInfoTable class
|
|
||||||
|
|
||||||
MaterialInfoTable::MaterialInfoTable(unsigned int numOfEntries) {
|
MaterialInfoTable::MaterialInfoTable(unsigned int numOfEntries) {
|
||||||
|
|
||||||
size = numOfEntries;
|
size = numOfEntries;
|
||||||
entries = new MaterialInfo[size];
|
entries = new MaterialInfo[size];
|
||||||
funcs = new EndgameFunctions();
|
funcs = new EndgameFunctions();
|
||||||
|
|
||||||
if (!entries || !funcs)
|
if (!entries || !funcs)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(MaterialInfo))
|
cerr << "Failed to allocate " << numOfEntries * sizeof(MaterialInfo)
|
||||||
<< " bytes for material hash table." << std::endl;
|
<< " bytes for material hash table." << endl;
|
||||||
Application::exit_with_failure();
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Destructor for the MaterialInfoTable class
|
|
||||||
|
|
||||||
MaterialInfoTable::~MaterialInfoTable() {
|
MaterialInfoTable::~MaterialInfoTable() {
|
||||||
|
|
||||||
delete funcs;
|
delete funcs;
|
||||||
@@ -105,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,
|
/// MaterialInfoTable::get_material_info() takes a position object as input,
|
||||||
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
|
/// 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
|
/// If the material configuration is not already present in the table, it
|
||||||
@@ -127,18 +172,13 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
mi->clear();
|
mi->clear();
|
||||||
mi->key = key;
|
mi->key = key;
|
||||||
|
|
||||||
// A special case before looking for a specialized evaluation function
|
// Store game phase
|
||||||
// KNN vs K is a draw.
|
mi->gamePhase = MaterialInfoTable::game_phase(pos);
|
||||||
if (key == KNNKMaterialKey || key == KKNNMaterialKey)
|
|
||||||
{
|
|
||||||
mi->factor[WHITE] = mi->factor[BLACK] = 0;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let's look if we have a specialized evaluation function for this
|
// Let's look if we have a specialized evaluation function for this
|
||||||
// particular material configuration. First we look for a fixed
|
// particular material configuration. First we look for a fixed
|
||||||
// configuration one, then a generic one if previous search failed.
|
// configuration one, then a generic one if previous search failed.
|
||||||
if ((mi->evaluationFunction = funcs->getEEF(key)) != NULL)
|
if ((mi->evaluationFunction = funcs->get<EF>(key)) != NULL)
|
||||||
return mi;
|
return mi;
|
||||||
|
|
||||||
else if ( pos.non_pawn_material(BLACK) == Value(0)
|
else if ( pos.non_pawn_material(BLACK) == Value(0)
|
||||||
@@ -155,14 +195,14 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
mi->evaluationFunction = &EvaluateKKX;
|
mi->evaluationFunction = &EvaluateKKX;
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
else if ( pos.pawns() == EmptyBoardBB
|
else if ( pos.pieces(PAWN) == EmptyBoardBB
|
||||||
&& pos.rooks() == EmptyBoardBB
|
&& pos.pieces(ROOK) == EmptyBoardBB
|
||||||
&& pos.queens() == EmptyBoardBB)
|
&& pos.pieces(QUEEN) == EmptyBoardBB)
|
||||||
{
|
{
|
||||||
// Minor piece endgame with at least one minor piece per side,
|
// Minor piece endgame with at least one minor piece per side and
|
||||||
// and no pawns.
|
// no pawns. Note that the case KmmK is already handled by KXK.
|
||||||
assert(pos.knights(WHITE) | pos.bishops(WHITE));
|
assert((pos.pieces(KNIGHT, WHITE) | pos.pieces(BISHOP, WHITE)));
|
||||||
assert(pos.knights(BLACK) | pos.bishops(BLACK));
|
assert((pos.pieces(KNIGHT, BLACK) | pos.pieces(BISHOP, BLACK)));
|
||||||
|
|
||||||
if ( pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
|
if ( pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
|
||||||
&& pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
|
&& pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
|
||||||
@@ -176,41 +216,43 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
// material configuration. Is there a suitable scaling function?
|
// material configuration. Is there a suitable scaling function?
|
||||||
//
|
//
|
||||||
// The code below is rather messy, and it could easily get worse later,
|
// The code below is rather messy, and it could easily get worse later,
|
||||||
// if we decide to add more special cases. We face problems when there
|
// if we decide to add more special cases. We face problems when there
|
||||||
// are several conflicting applicable scaling functions and we need to
|
// are several conflicting applicable scaling functions and we need to
|
||||||
// decide which one to use.
|
// decide which one to use.
|
||||||
Color c;
|
SF* sf;
|
||||||
EndgameScalingFunctionBase* sf;
|
|
||||||
|
|
||||||
if ((sf = funcs->getESF(key, &c)) != NULL)
|
if ((sf = funcs->get<SF>(key)) != NULL)
|
||||||
{
|
{
|
||||||
mi->scalingFunction[c] = sf;
|
mi->scalingFunction[sf->color()] = sf;
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generic scaling functions that refer to more then one material
|
||||||
|
// distribution. Should be probed after the specialized ones.
|
||||||
|
// Note that these ones don't return after setting the function.
|
||||||
if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
|
if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
|
||||||
&& pos.piece_count(WHITE, BISHOP) == 1
|
&& pos.piece_count(WHITE, BISHOP) == 1
|
||||||
&& pos.piece_count(WHITE, PAWN) >= 1)
|
&& pos.piece_count(WHITE, PAWN) >= 1)
|
||||||
mi->scalingFunction[WHITE] = &ScaleKBPK;
|
mi->scalingFunction[WHITE] = &ScaleKBPsK;
|
||||||
|
|
||||||
if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
|
if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
|
||||||
&& pos.piece_count(BLACK, BISHOP) == 1
|
&& pos.piece_count(BLACK, BISHOP) == 1
|
||||||
&& pos.piece_count(BLACK, PAWN) >= 1)
|
&& pos.piece_count(BLACK, PAWN) >= 1)
|
||||||
mi->scalingFunction[BLACK] = &ScaleKKBP;
|
mi->scalingFunction[BLACK] = &ScaleKKBPs;
|
||||||
|
|
||||||
if ( pos.piece_count(WHITE, PAWN) == 0
|
if ( pos.piece_count(WHITE, PAWN) == 0
|
||||||
&& pos.non_pawn_material(WHITE) == QueenValueMidgame
|
&& pos.non_pawn_material(WHITE) == QueenValueMidgame
|
||||||
&& pos.piece_count(WHITE, QUEEN) == 1
|
&& pos.piece_count(WHITE, QUEEN) == 1
|
||||||
&& pos.piece_count(BLACK, ROOK) == 1
|
&& pos.piece_count(BLACK, ROOK) == 1
|
||||||
&& pos.piece_count(BLACK, PAWN) >= 1)
|
&& pos.piece_count(BLACK, PAWN) >= 1)
|
||||||
mi->scalingFunction[WHITE] = &ScaleKQKRP;
|
mi->scalingFunction[WHITE] = &ScaleKQKRPs;
|
||||||
|
|
||||||
else if ( pos.piece_count(BLACK, PAWN) == 0
|
else if ( pos.piece_count(BLACK, PAWN) == 0
|
||||||
&& pos.non_pawn_material(BLACK) == QueenValueMidgame
|
&& pos.non_pawn_material(BLACK) == QueenValueMidgame
|
||||||
&& pos.piece_count(BLACK, QUEEN) == 1
|
&& pos.piece_count(BLACK, QUEEN) == 1
|
||||||
&& pos.piece_count(WHITE, ROOK) == 1
|
&& pos.piece_count(WHITE, ROOK) == 1
|
||||||
&& pos.piece_count(WHITE, PAWN) >= 1)
|
&& pos.piece_count(WHITE, PAWN) >= 1)
|
||||||
mi->scalingFunction[BLACK] = &ScaleKRPKQ;
|
mi->scalingFunction[BLACK] = &ScaleKRPsKQ;
|
||||||
|
|
||||||
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
|
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
|
||||||
{
|
{
|
||||||
@@ -226,6 +268,8 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
}
|
}
|
||||||
else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
|
else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
|
||||||
{
|
{
|
||||||
|
// This is a special case because we set scaling functions
|
||||||
|
// for both colors instead of only one.
|
||||||
mi->scalingFunction[WHITE] = &ScaleKPKPw;
|
mi->scalingFunction[WHITE] = &ScaleKPKPw;
|
||||||
mi->scalingFunction[BLACK] = &ScaleKPKPb;
|
mi->scalingFunction[BLACK] = &ScaleKPKPb;
|
||||||
}
|
}
|
||||||
@@ -244,10 +288,13 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate the material balance
|
// Evaluate the material balance
|
||||||
|
const int pieceCount[2][6] = { { pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT),
|
||||||
int sign;
|
pos.piece_count(WHITE, BISHOP), pos.piece_count(WHITE, ROOK), pos.piece_count(WHITE, QUEEN) },
|
||||||
Value egValue = Value(0);
|
{ pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
|
||||||
Value mgValue = Value(0);
|
pos.piece_count(BLACK, BISHOP), pos.piece_count(BLACK, ROOK), pos.piece_count(BLACK, QUEEN) } };
|
||||||
|
Color c, them;
|
||||||
|
int sign, pt1, pt2, pc;
|
||||||
|
int v, vv, matValue = 0;
|
||||||
|
|
||||||
for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
|
for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
|
||||||
{
|
{
|
||||||
@@ -274,73 +321,68 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bishop pair
|
// Redundancy of major pieces, formula based on Kaufman's paper
|
||||||
if (pos.piece_count(c, BISHOP) >= 2)
|
// "The Evaluation of Material Imbalances in Chess"
|
||||||
{
|
|
||||||
mgValue += sign * BishopPairMidgameBonus;
|
|
||||||
egValue += sign * BishopPairEndgameBonus;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Knights are stronger when there are many pawns on the board. The
|
|
||||||
// formula is taken from Larry Kaufman's paper "The Evaluation of Material
|
|
||||||
// Imbalances in Chess":
|
|
||||||
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
|
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
|
||||||
mgValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
|
if (pieceCount[c][ROOK] >= 1)
|
||||||
egValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
|
matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);
|
||||||
|
|
||||||
// Redundancy of major pieces, again based on Kaufman's paper:
|
them = opposite_color(c);
|
||||||
if (pos.piece_count(c, ROOK) >= 1)
|
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 (pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
||||||
{
|
{
|
||||||
Value v = Value((pos.piece_count(c, ROOK) - 1) * 32 + pos.piece_count(c, QUEEN) * 16);
|
pc = pieceCount[c][pt1];
|
||||||
mgValue -= sign * v;
|
if (!pc)
|
||||||
egValue -= sign * v;
|
continue;
|
||||||
|
|
||||||
|
vv = LinearCoefficients[pt1];
|
||||||
|
|
||||||
|
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->mgValue = int16_t(mgValue);
|
mi->value = int16_t(matValue / 16);
|
||||||
mi->egValue = int16_t(egValue);
|
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// EndgameFunctions member definitions. This class is used to store the maps
|
/// EndgameFunctions member definitions.
|
||||||
/// of end game and scaling functions that MaterialInfoTable will query for
|
|
||||||
/// each key. The maps are constant and are populated only at construction,
|
|
||||||
/// but are per-thread instead of globals to avoid expensive locks.
|
|
||||||
|
|
||||||
EndgameFunctions::EndgameFunctions() {
|
EndgameFunctions::EndgameFunctions() {
|
||||||
|
|
||||||
KNNKMaterialKey = buildKey("KNNK");
|
add<EvaluationFunction<KNNK> >("KNNK");
|
||||||
KKNNMaterialKey = buildKey("KKNN");
|
add<EvaluationFunction<KPK> >("KPK");
|
||||||
|
add<EvaluationFunction<KBNK> >("KBNK");
|
||||||
|
add<EvaluationFunction<KRKP> >("KRKP");
|
||||||
|
add<EvaluationFunction<KRKB> >("KRKB");
|
||||||
|
add<EvaluationFunction<KRKN> >("KRKN");
|
||||||
|
add<EvaluationFunction<KQKR> >("KQKR");
|
||||||
|
add<EvaluationFunction<KBBKN> >("KBBKN");
|
||||||
|
|
||||||
add("KPK", &EvaluateKPK);
|
add<ScalingFunction<KNPK> >("KNPK");
|
||||||
add("KKP", &EvaluateKKP);
|
add<ScalingFunction<KRPKR> >("KRPKR");
|
||||||
add("KBNK", &EvaluateKBNK);
|
add<ScalingFunction<KBPKB> >("KBPKB");
|
||||||
add("KKBN", &EvaluateKKBN);
|
add<ScalingFunction<KBPPKB> >("KBPPKB");
|
||||||
add("KRKP", &EvaluateKRKP);
|
add<ScalingFunction<KBPKN> >("KBPKN");
|
||||||
add("KPKR", &EvaluateKPKR);
|
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||||
add("KRKB", &EvaluateKRKB);
|
}
|
||||||
add("KBKR", &EvaluateKBKR);
|
|
||||||
add("KRKN", &EvaluateKRKN);
|
|
||||||
add("KNKR", &EvaluateKNKR);
|
|
||||||
add("KQKR", &EvaluateKQKR);
|
|
||||||
add("KRKQ", &EvaluateKRKQ);
|
|
||||||
add("KBBKN", &EvaluateKBBKN);
|
|
||||||
add("KNKBB", &EvaluateKNKBB);
|
|
||||||
|
|
||||||
add("KNPK", WHITE, &ScaleKNPK);
|
EndgameFunctions::~EndgameFunctions() {
|
||||||
add("KKNP", BLACK, &ScaleKKNP);
|
|
||||||
add("KRPKR", WHITE, &ScaleKRPKR);
|
for (map<Key, EF*>::iterator it = maps.first.begin(); it != maps.first.end(); ++it)
|
||||||
add("KRKRP", BLACK, &ScaleKRKRP);
|
delete (*it).second;
|
||||||
add("KBPKB", WHITE, &ScaleKBPKB);
|
|
||||||
add("KBKBP", BLACK, &ScaleKBKBP);
|
for (map<Key, SF*>::iterator it = maps.second.begin(); it != maps.second.end(); ++it)
|
||||||
add("KBPPKB", WHITE, &ScaleKBPPKB);
|
delete (*it).second;
|
||||||
add("KBKBPP", BLACK, &ScaleKBKBPP);
|
|
||||||
add("KBPKN", WHITE, &ScaleKBPKN);
|
|
||||||
add("KNKBP", BLACK, &ScaleKNKBP);
|
|
||||||
add("KRPPKRP", WHITE, &ScaleKRPPKRP);
|
|
||||||
add("KRPKRPP", BLACK, &ScaleKRPKRPP);
|
|
||||||
add("KRPPKRP", WHITE, &ScaleKRPPKRP);
|
|
||||||
add("KRPKRPP", BLACK, &ScaleKRPKRPP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Key EndgameFunctions::buildKey(const string& keyCode) {
|
Key EndgameFunctions::buildKey(const string& keyCode) {
|
||||||
@@ -348,11 +390,11 @@ Key EndgameFunctions::buildKey(const string& keyCode) {
|
|||||||
assert(keyCode.length() > 0 && keyCode[0] == 'K');
|
assert(keyCode.length() > 0 && keyCode[0] == 'K');
|
||||||
assert(keyCode.length() < 8);
|
assert(keyCode.length() < 8);
|
||||||
|
|
||||||
std::stringstream s;
|
stringstream s;
|
||||||
bool upcase = false;
|
bool upcase = false;
|
||||||
|
|
||||||
// Build up a fen substring with the given pieces, note
|
// Build up a fen string with the given pieces, note that
|
||||||
// that the fen string could be of an illegal position.
|
// the fen string could be of an illegal position.
|
||||||
for (size_t i = 0; i < keyCode.length(); i++)
|
for (size_t i = 0; i < keyCode.length(); i++)
|
||||||
{
|
{
|
||||||
if (keyCode[i] == 'K')
|
if (keyCode[i] == 'K')
|
||||||
@@ -364,29 +406,25 @@ Key EndgameFunctions::buildKey(const string& keyCode) {
|
|||||||
return Position(s.str()).get_material_key();
|
return Position(s.str()).get_material_key();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndgameFunctions::add(const string& keyCode, EndgameEvaluationFunctionBase* f) {
|
const string EndgameFunctions::swapColors(const string& keyCode) {
|
||||||
|
|
||||||
EEFmap.insert(std::pair<Key, EndgameEvaluationFunctionBase*>(buildKey(keyCode), f));
|
// Build corresponding key for the opposite color: "KBPKN" -> "KNKBP"
|
||||||
|
size_t idx = keyCode.find("K", 1);
|
||||||
|
return keyCode.substr(idx) + keyCode.substr(0, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndgameFunctions::add(const string& keyCode, Color c, EndgameScalingFunctionBase* f) {
|
template<class T>
|
||||||
|
void EndgameFunctions::add(const string& keyCode) {
|
||||||
|
|
||||||
ScalingInfo s = {c, f};
|
typedef typename T::Base F;
|
||||||
ESFmap.insert(std::pair<Key, ScalingInfo>(buildKey(keyCode), s));
|
|
||||||
|
get<F>().insert(pair<Key, F*>(buildKey(keyCode), new T(WHITE)));
|
||||||
|
get<F>().insert(pair<Key, F*>(buildKey(swapColors(keyCode)), new T(BLACK)));
|
||||||
}
|
}
|
||||||
|
|
||||||
EndgameEvaluationFunctionBase* EndgameFunctions::getEEF(Key key) const {
|
template<class T>
|
||||||
|
T* EndgameFunctions::get(Key key) const {
|
||||||
|
|
||||||
std::map<Key, EndgameEvaluationFunctionBase*>::const_iterator it(EEFmap.find(key));
|
typename map<Key, T*>::const_iterator it(get<T>().find(key));
|
||||||
return (it != EEFmap.end() ? it->second : NULL);
|
return (it != get<T>().end() ? it->second : NULL);
|
||||||
}
|
|
||||||
|
|
||||||
EndgameScalingFunctionBase* EndgameFunctions::getESF(Key key, Color* c) const {
|
|
||||||
|
|
||||||
std::map<Key, ScalingInfo>::const_iterator it(ESFmap.find(key));
|
|
||||||
if (it == ESFmap.end())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
*c = it->second.col;
|
|
||||||
return it->second.fun;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -51,10 +51,10 @@ class MaterialInfo {
|
|||||||
public:
|
public:
|
||||||
MaterialInfo() : key(0) { clear(); }
|
MaterialInfo() : key(0) { clear(); }
|
||||||
|
|
||||||
Value mg_value() const;
|
Score material_value() const;
|
||||||
Value eg_value() const;
|
|
||||||
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
||||||
int space_weight() const;
|
int space_weight() const;
|
||||||
|
Phase game_phase() const;
|
||||||
bool specialized_eval_exists() const;
|
bool specialized_eval_exists() const;
|
||||||
Value evaluate(const Position& pos) const;
|
Value evaluate(const Position& pos) const;
|
||||||
|
|
||||||
@@ -62,27 +62,19 @@ private:
|
|||||||
inline void clear();
|
inline void clear();
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
int16_t mgValue;
|
int16_t value;
|
||||||
int16_t egValue;
|
|
||||||
uint8_t factor[2];
|
uint8_t factor[2];
|
||||||
EndgameEvaluationFunctionBase* evaluationFunction;
|
EndgameEvaluationFunctionBase* evaluationFunction;
|
||||||
EndgameScalingFunctionBase* scalingFunction[2];
|
EndgameScalingFunctionBase* scalingFunction[2];
|
||||||
int spaceWeight;
|
int spaceWeight;
|
||||||
|
Phase gamePhase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// EndgameFunctions class stores the endgame evaluation functions std::map.
|
|
||||||
/// Because STL library is not thread safe even for read access, the maps,
|
|
||||||
/// although with identical content, are replicated for each thread. This
|
|
||||||
/// is faster then using locks with an unique set of global maps.
|
|
||||||
|
|
||||||
class EndgameFunctions;
|
|
||||||
|
|
||||||
|
|
||||||
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
||||||
/// just an array of MaterialInfo objects and a few methods for accessing these
|
/// just an array of MaterialInfo objects and a few methods for accessing these
|
||||||
/// objects. The most important method is get_material_info, which looks up a
|
/// objects. The most important method is get_material_info, which looks up a
|
||||||
/// position in the table and returns a pointer to a MaterialInfo object.
|
/// position in the table and returns a pointer to a MaterialInfo object.
|
||||||
|
class EndgameFunctions;
|
||||||
|
|
||||||
class MaterialInfoTable {
|
class MaterialInfoTable {
|
||||||
|
|
||||||
@@ -91,6 +83,8 @@ public:
|
|||||||
~MaterialInfoTable();
|
~MaterialInfoTable();
|
||||||
MaterialInfo* get_material_info(const Position& pos);
|
MaterialInfo* get_material_info(const Position& pos);
|
||||||
|
|
||||||
|
static Phase game_phase(const Position& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned size;
|
unsigned size;
|
||||||
MaterialInfo* entries;
|
MaterialInfo* entries;
|
||||||
@@ -102,17 +96,13 @@ private:
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// MaterialInfo::mg_value and MaterialInfo::eg_value simply returns the
|
|
||||||
/// material balance evaluation for the middle game and the endgame.
|
|
||||||
|
|
||||||
inline Value MaterialInfo::mg_value() const {
|
/// MaterialInfo::material_value simply returns the material balance
|
||||||
|
/// evaluation that is independent from game phase.
|
||||||
|
|
||||||
return Value(mgValue);
|
inline Score MaterialInfo::material_value() const {
|
||||||
}
|
|
||||||
|
|
||||||
inline Value MaterialInfo::eg_value() const {
|
return make_score(value, value);
|
||||||
|
|
||||||
return Value(egValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,7 +111,7 @@ inline Value MaterialInfo::eg_value() const {
|
|||||||
|
|
||||||
inline void MaterialInfo::clear() {
|
inline void MaterialInfo::clear() {
|
||||||
|
|
||||||
mgValue = egValue = 0;
|
value = 0;
|
||||||
factor[WHITE] = factor[BLACK] = uint8_t(SCALE_FACTOR_NORMAL);
|
factor[WHITE] = factor[BLACK] = uint8_t(SCALE_FACTOR_NORMAL);
|
||||||
evaluationFunction = NULL;
|
evaluationFunction = NULL;
|
||||||
scalingFunction[WHITE] = scalingFunction[BLACK] = NULL;
|
scalingFunction[WHITE] = scalingFunction[BLACK] = NULL;
|
||||||
@@ -156,6 +146,14 @@ inline int MaterialInfo::space_weight() const {
|
|||||||
return spaceWeight;
|
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
|
/// MaterialInfo::specialized_eval_exists decides whether there is a
|
||||||
/// specialized evaluation function for the current material configuration,
|
/// 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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+29
-33
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,35 +27,15 @@
|
|||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
# if defined(__hpux)
|
||||||
|
# include <sys/pstat.h>
|
||||||
|
# endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/*
|
|
||||||
(c) Copyright 1992 Eric Backus
|
|
||||||
|
|
||||||
This software may be used freely so long as this copyright notice is
|
#define _CRT_SECURE_NO_DEPRECATE
|
||||||
left intact. There is no warrantee on this software.
|
#include <windows.h>
|
||||||
*/
|
#include <sys/timeb.h>
|
||||||
# include <windows.h>
|
|
||||||
# include <time.h>
|
|
||||||
# include "dos.h"
|
|
||||||
|
|
||||||
static int gettimeofday(struct timeval* tp, struct timezone*)
|
|
||||||
{
|
|
||||||
SYSTEMTIME systime;
|
|
||||||
|
|
||||||
if (tp)
|
|
||||||
{
|
|
||||||
struct tm tmrec;
|
|
||||||
time_t theTime = time(NULL);
|
|
||||||
|
|
||||||
tmrec = *localtime(&theTime);
|
|
||||||
tp->tv_sec = mktime(&tmrec);
|
|
||||||
GetLocalTime(&systime); /* system time */
|
|
||||||
|
|
||||||
tp->tv_usec = systime.wMilliseconds * 1000;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -67,13 +47,14 @@ static int gettimeofday(struct timeval* tp, struct timezone*)
|
|||||||
|
|
||||||
#include "bitcount.h"
|
#include "bitcount.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/// Version number. If this is left empty, the current date (in the format
|
/// Version number. If this is left empty, the current date (in the format
|
||||||
/// YYMMDD) is used as a version number.
|
/// YYMMDD) is used as a version number.
|
||||||
|
|
||||||
static const string EngineVersion = "1.4";
|
static const string EngineVersion = "1.7.1";
|
||||||
static const string AppName = "Stockfish";
|
static const string AppName = "Stockfish";
|
||||||
static const string AppTag = "";
|
static const string AppTag = "";
|
||||||
|
|
||||||
@@ -189,9 +170,16 @@ const string engine_name() {
|
|||||||
/// milliseconds.
|
/// milliseconds.
|
||||||
|
|
||||||
int get_system_time() {
|
int get_system_time() {
|
||||||
struct timeval t;
|
|
||||||
gettimeofday(&t, NULL);
|
#if defined(_MSC_VER)
|
||||||
return t.tv_sec*1000 + t.tv_usec/1000;
|
struct _timeb t;
|
||||||
|
_ftime(&t);
|
||||||
|
return int(t.time*1000 + t.millitm);
|
||||||
|
#else
|
||||||
|
struct timeval t;
|
||||||
|
gettimeofday(&t, NULL);
|
||||||
|
return t.tv_sec*1000 + t.tv_usec/1000;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -201,7 +189,15 @@ int get_system_time() {
|
|||||||
|
|
||||||
# if defined(_SC_NPROCESSORS_ONLN)
|
# if defined(_SC_NPROCESSORS_ONLN)
|
||||||
int cpu_count() {
|
int cpu_count() {
|
||||||
return Min(sysconf(_SC_NPROCESSORS_ONLN), 8);
|
return Min(sysconf(_SC_NPROCESSORS_ONLN), MAX_THREADS);
|
||||||
|
}
|
||||||
|
# elif defined(__hpux)
|
||||||
|
int 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, MAX_THREADS);
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
int cpu_count() {
|
int cpu_count() {
|
||||||
@@ -214,7 +210,7 @@ int cpu_count() {
|
|||||||
int cpu_count() {
|
int cpu_count() {
|
||||||
SYSTEM_INFO s;
|
SYSTEM_INFO s;
|
||||||
GetSystemInfo(&s);
|
GetSystemInfo(&s);
|
||||||
return Min(s.dwNumberOfProcessors, 8);
|
return Min(s.dwNumberOfProcessors, MAX_THREADS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -62,9 +62,83 @@ struct MoveStack {
|
|||||||
int score;
|
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; }
|
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
|
//// Inline functions
|
||||||
@@ -82,6 +156,10 @@ inline PieceType move_promotion_piece(Move m) {
|
|||||||
return PieceType((int(m) >> 12) & 7);
|
return PieceType((int(m) >> 12) & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int move_is_special(Move m) {
|
||||||
|
return m & (0x1F << 12);
|
||||||
|
}
|
||||||
|
|
||||||
inline int move_is_promotion(Move m) {
|
inline int move_is_promotion(Move m) {
|
||||||
return m & (7 << 12);
|
return m & (7 << 12);
|
||||||
}
|
}
|
||||||
|
|||||||
+327
-600
File diff suppressed because it is too large
Load Diff
+7
-6
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -32,12 +32,13 @@
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern int generate_captures(const Position& pos, MoveStack* mlist);
|
extern MoveStack* generate_captures(const Position& pos, MoveStack* mlist);
|
||||||
extern int generate_noncaptures(const Position& pos, MoveStack* mlist);
|
extern MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist);
|
||||||
extern int generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc);
|
extern MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist);
|
||||||
extern int generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
|
extern MoveStack* generate_evasions(const Position& pos, MoveStack* mlist);
|
||||||
extern int generate_legal_moves(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, Bitboard pinned);
|
||||||
|
extern bool move_is_legal(const Position& pos, const Move m);
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(MOVEGEN_H_INCLUDED)
|
#endif // !defined(MOVEGEN_H_INCLUDED)
|
||||||
|
|||||||
+238
-292
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,11 +23,9 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "evaluate.h"
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
@@ -40,14 +38,23 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Variables
|
enum MovegenPhase {
|
||||||
|
PH_TT_MOVES, // Transposition table move and mate killer
|
||||||
MovePicker::MovegenPhase PhaseTable[32];
|
PH_GOOD_CAPTURES, // Queen promotions and captures with SEE values >= 0
|
||||||
int MainSearchPhaseIndex;
|
PH_KILLERS, // Killer moves from the current ply
|
||||||
int EvasionsPhaseIndex;
|
PH_NONCAPTURES, // Non-captures and underpromotions
|
||||||
int QsearchWithChecksPhaseIndex;
|
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < 0
|
||||||
int QsearchWithoutChecksPhaseIndex;
|
PH_EVASIONS, // Check evasions
|
||||||
|
PH_QCAPTURES, // Captures in quiescence search
|
||||||
|
PH_QCHECKS, // Non-capture checks in quiescence search
|
||||||
|
PH_STOP
|
||||||
|
};
|
||||||
|
|
||||||
|
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_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};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -56,7 +63,7 @@ namespace {
|
|||||||
////
|
////
|
||||||
|
|
||||||
|
|
||||||
/// Constructor for the MovePicker class. Apart from the position for which
|
/// Constructor for the MovePicker class. Apart from the position for which
|
||||||
/// it is asked to pick legal moves, MovePicker also wants some information
|
/// it is asked to pick legal moves, MovePicker also wants some information
|
||||||
/// to help it to return the presumably good moves first, to decide which
|
/// to help it to return the presumably good moves first, to decide which
|
||||||
/// moves to return (in the quiescence search, for instance, we only want to
|
/// moves to return (in the quiescence search, for instance, we only want to
|
||||||
@@ -64,203 +71,145 @@ namespace {
|
|||||||
/// move ordering is at the current node.
|
/// move ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
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) {
|
||||||
ttMove = ttm;
|
int searchTT = ttm;
|
||||||
if (ss)
|
ttMoves[0].move = ttm;
|
||||||
{
|
lastBadCapture = badCaptures;
|
||||||
mateKiller = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller;
|
badCaptureThreshold = 0;
|
||||||
killer1 = ss->killers[0];
|
|
||||||
killer2 = ss->killers[1];
|
|
||||||
} else
|
|
||||||
mateKiller = killer1 = killer2 = MOVE_NONE;
|
|
||||||
|
|
||||||
movesPicked = numOfMoves = numOfBadCaptures = 0;
|
pinned = p.pinned_pieces(pos.side_to_move());
|
||||||
checkKillers = checkLegal = finished = false;
|
|
||||||
|
if (ss && !p.is_check())
|
||||||
|
{
|
||||||
|
ttMoves[1].move = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller;
|
||||||
|
searchTT |= ttMoves[1].move;
|
||||||
|
killers[0].move = ss->killers[0];
|
||||||
|
killers[1].move = ss->killers[1];
|
||||||
|
} else
|
||||||
|
ttMoves[1].move = killers[0].move = killers[1].move = MOVE_NONE;
|
||||||
|
|
||||||
if (p.is_check())
|
if (p.is_check())
|
||||||
phaseIndex = EvasionsPhaseIndex;
|
phasePtr = EvasionsPhaseTable;
|
||||||
else if (d > Depth(0))
|
else if (d > Depth(0))
|
||||||
phaseIndex = MainSearchPhaseIndex;
|
{
|
||||||
else if (d == Depth(0))
|
// Consider sligtly negative captures as good if at low
|
||||||
phaseIndex = QsearchWithChecksPhaseIndex;
|
// depth and far from beta.
|
||||||
|
if (ss && ss->eval < beta - PawnValueMidgame && d < 3 * OnePly)
|
||||||
|
badCaptureThreshold = -PawnValueMidgame;
|
||||||
|
|
||||||
|
phasePtr = MainSearchPhaseTable;
|
||||||
|
} else if (d == Depth(0))
|
||||||
|
phasePtr = QsearchWithChecksPhaseTable;
|
||||||
else
|
else
|
||||||
phaseIndex = QsearchWithoutChecksPhaseIndex;
|
{
|
||||||
|
phasePtr = QsearchWithoutChecksPhaseTable;
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
dc = p.discovered_check_candidates(us);
|
phasePtr += !searchTT - 1;
|
||||||
pinned = p.pinned_pieces(us);
|
go_next_phase();
|
||||||
|
|
||||||
finished = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::get_next_move() is the most important method of the MovePicker
|
/// MovePicker::go_next_phase() generates, scores and sorts the next bunch
|
||||||
/// class. It returns a new legal move every time it is called, until there
|
/// of moves when there are no more moves to try for the current phase.
|
||||||
/// are no more moves left of the types we are interested in.
|
|
||||||
|
|
||||||
Move MovePicker::get_next_move() {
|
void MovePicker::go_next_phase() {
|
||||||
|
|
||||||
Move move;
|
curMove = moves;
|
||||||
|
phase = *(++phasePtr);
|
||||||
|
switch (phase) {
|
||||||
|
|
||||||
while (true)
|
case PH_TT_MOVES:
|
||||||
{
|
curMove = ttMoves;
|
||||||
// If we already have a list of generated moves, pick the best move from
|
lastMove = curMove + 2;
|
||||||
// the list, and return it.
|
return;
|
||||||
move = pick_move_from_list();
|
|
||||||
if (move != MOVE_NONE)
|
|
||||||
{
|
|
||||||
assert(move_is_ok(move));
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next phase
|
case PH_GOOD_CAPTURES:
|
||||||
phaseIndex++;
|
lastMove = generate_captures(pos, moves);
|
||||||
switch (PhaseTable[phaseIndex]) {
|
score_captures();
|
||||||
|
return;
|
||||||
|
|
||||||
case PH_TT_MOVE:
|
case PH_KILLERS:
|
||||||
if (ttMove != MOVE_NONE)
|
curMove = killers;
|
||||||
{
|
lastMove = curMove + 2;
|
||||||
assert(move_is_ok(ttMove));
|
return;
|
||||||
if (move_is_legal(pos, ttMove, pinned))
|
|
||||||
return ttMove;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_MATE_KILLER:
|
case PH_NONCAPTURES:
|
||||||
if (mateKiller != MOVE_NONE)
|
lastMove = generate_noncaptures(pos, moves);
|
||||||
{
|
score_noncaptures();
|
||||||
assert(move_is_ok(mateKiller));
|
sort_moves(moves, lastMove, &lastGoodNonCapture);
|
||||||
if (move_is_legal(pos, mateKiller, pinned))
|
return;
|
||||||
return mateKiller;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_GOOD_CAPTURES:
|
case PH_BAD_CAPTURES:
|
||||||
numOfMoves = generate_captures(pos, moves);
|
// Bad captures SEE value is already calculated so just sort them
|
||||||
score_captures();
|
// to get SEE move ordering.
|
||||||
std::sort(moves, moves + numOfMoves);
|
curMove = badCaptures;
|
||||||
movesPicked = 0;
|
lastMove = lastBadCapture;
|
||||||
checkLegal = true;
|
return;
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_KILLERS:
|
case PH_EVASIONS:
|
||||||
movesPicked = numOfMoves = 0;
|
assert(pos.is_check());
|
||||||
checkLegal = false;
|
lastMove = generate_evasions(pos, moves);
|
||||||
if (killer1 != MOVE_NONE && move_is_legal(pos, killer1, pinned) && !pos.move_is_capture(killer1))
|
score_evasions_or_checks();
|
||||||
moves[numOfMoves++].move = killer1;
|
return;
|
||||||
if (killer2 != MOVE_NONE && move_is_legal(pos, killer2, pinned) && !pos.move_is_capture(killer2) )
|
|
||||||
moves[numOfMoves++].move = killer2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
case PH_QCAPTURES:
|
||||||
checkKillers = (numOfMoves != 0); // previous phase is PH_KILLERS
|
lastMove = generate_captures(pos, moves);
|
||||||
numOfMoves = generate_noncaptures(pos, moves);
|
score_captures();
|
||||||
score_noncaptures();
|
return;
|
||||||
std::sort(moves, moves + numOfMoves);
|
|
||||||
movesPicked = 0;
|
|
||||||
checkLegal = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
case PH_QCHECKS:
|
||||||
// Bad captures SEE value is already calculated by score_captures()
|
lastMove = generate_non_capture_checks(pos, moves);
|
||||||
// so just sort them to get SEE move ordering.
|
score_evasions_or_checks();
|
||||||
std::sort(badCaptures, badCaptures + numOfBadCaptures);
|
return;
|
||||||
movesPicked = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_EVASIONS:
|
case PH_STOP:
|
||||||
assert(pos.is_check());
|
lastMove = curMove + 1; // Avoids another go_next_phase() call
|
||||||
numOfMoves = generate_evasions(pos, moves, pinned);
|
return;
|
||||||
score_evasions();
|
|
||||||
std::sort(moves, moves + numOfMoves);
|
|
||||||
movesPicked = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
default:
|
||||||
numOfMoves = generate_captures(pos, moves);
|
assert(false);
|
||||||
score_qcaptures();
|
return;
|
||||||
std::sort(moves, moves + numOfMoves);
|
|
||||||
movesPicked = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_QCHECKS:
|
|
||||||
// Perhaps we should order moves move here? FIXME
|
|
||||||
numOfMoves = generate_non_capture_checks(pos, moves, dc);
|
|
||||||
movesPicked = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_STOP:
|
|
||||||
return MOVE_NONE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// A variant of get_next_move() which takes a lock as a parameter, used to
|
/// MovePicker::score_captures(), MovePicker::score_noncaptures() and
|
||||||
/// prevent multiple threads from picking the same move at a split point.
|
/// MovePicker::score_evasions() assign a numerical move ordering score
|
||||||
|
/// to each move in a move list. The moves with highest scores will be
|
||||||
Move MovePicker::get_next_move(Lock &lock) {
|
/// picked first by get_next_move().
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::score_captures(), MovePicker::score_noncaptures(),
|
|
||||||
/// MovePicker::score_evasions() and MovePicker::score_qcaptures() assign a
|
|
||||||
/// numerical move ordering score to each move in a move list. The moves
|
|
||||||
/// with highest scores will be picked first by pick_move_from_list().
|
|
||||||
|
|
||||||
void MovePicker::score_captures() {
|
void MovePicker::score_captures() {
|
||||||
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
||||||
// Suprisingly, this appears to perform slightly better than SEE based
|
// Suprisingly, this appears to perform slightly better than SEE based
|
||||||
// move ordering. The reason is probably that in a position with a winning
|
// move ordering. The reason is probably that in a position with a winning
|
||||||
// capture, capturing a more valuable (but sufficiently defended) piece
|
// capture, capturing a more valuable (but sufficiently defended) piece
|
||||||
// first usually doesn't hurt. The opponent will have to recapture, and
|
// first usually doesn't hurt. The opponent will have to recapture, and
|
||||||
// the hanging piece will still be hanging (except in the unusual cases
|
// the hanging piece will still be hanging (except in the unusual cases
|
||||||
// where it is possible to recapture with the hanging piece). Exchanging
|
// where it is possible to recapture with the hanging piece). Exchanging
|
||||||
// big pieces before capturing a hanging piece probably helps to reduce
|
// big pieces before capturing a hanging piece probably helps to reduce
|
||||||
// the subtree size.
|
// the subtree size.
|
||||||
// While scoring captures it moves all captures with negative SEE values
|
// In main search we want to push captures with negative SEE values to
|
||||||
// to the badCaptures[] array.
|
// badCaptures[] array, but instead of doing it now we delay till when
|
||||||
|
// the move has been picked up in pick_move_from_list(), this way we save
|
||||||
|
// some SEE calls in case we get a cutoff (idea from Pablo Vazquez).
|
||||||
Move m;
|
Move m;
|
||||||
int seeValue;
|
|
||||||
|
|
||||||
for (int i = 0; i < numOfMoves; i++)
|
// Use MVV/LVA ordering
|
||||||
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
{
|
{
|
||||||
m = moves[i].move;
|
m = cur->move;
|
||||||
seeValue = pos.see(m);
|
if (move_is_promotion(m))
|
||||||
if (seeValue >= 0)
|
cur->score = QueenValueMidgame;
|
||||||
{
|
|
||||||
if (move_is_promotion(m))
|
|
||||||
moves[i].score = QueenValueMidgame;
|
|
||||||
else
|
|
||||||
moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
|
||||||
-int(pos.type_of_piece_on(move_from(m)));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
||||||
// Losing capture, move it to the badCaptures[] array
|
- pos.type_of_piece_on(move_from(m));
|
||||||
assert(numOfBadCaptures < 63);
|
|
||||||
moves[i].score = seeValue;
|
|
||||||
badCaptures[numOfBadCaptures++] = moves[i];
|
|
||||||
moves[i--] = moves[--numOfMoves];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,154 +217,151 @@ void MovePicker::score_noncaptures() {
|
|||||||
// First score by history, when no history is available then use
|
// First score by history, when no history is available then use
|
||||||
// piece/square tables values. This seems to be better then a
|
// piece/square tables values. This seems to be better then a
|
||||||
// random choice when we don't have an history for any move.
|
// random choice when we don't have an history for any move.
|
||||||
|
Move m;
|
||||||
Piece piece;
|
Piece piece;
|
||||||
Square from, to;
|
Square from, to;
|
||||||
int hs;
|
int hs;
|
||||||
|
|
||||||
for (int i = 0; i < numOfMoves; i++)
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
{
|
{
|
||||||
from = move_from(moves[i].move);
|
m = cur->move;
|
||||||
to = move_to(moves[i].move);
|
from = move_from(m);
|
||||||
|
to = move_to(m);
|
||||||
piece = pos.piece_on(from);
|
piece = pos.piece_on(from);
|
||||||
hs = H.move_ordering_score(piece, to);
|
hs = H.move_ordering_score(piece, to);
|
||||||
|
|
||||||
// Ensure history is always preferred to pst
|
// Ensure history has always highest priority
|
||||||
if (hs > 0)
|
if (hs > 0)
|
||||||
hs += 1000;
|
hs += 10000;
|
||||||
|
|
||||||
// pst based scoring
|
// Gain table based scoring
|
||||||
moves[i].score = hs + pos.pst_delta<Position::MidGame>(piece, from, to);
|
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;
|
||||||
|
|
||||||
for (int i = 0; i < numOfMoves; i++)
|
// Skip if we don't have at least two moves to order
|
||||||
|
if (lastMove < moves + 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
{
|
{
|
||||||
Move m = moves[i].move;
|
m = cur->move;
|
||||||
if (m == ttMove)
|
if ((seeScore = pos.see_sign(m)) < 0)
|
||||||
moves[i].score = 2*HistoryMax;
|
cur->score = seeScore - HistoryMax; // Be sure are at the bottom
|
||||||
else if (!pos.square_is_empty(move_to(m)))
|
else if (pos.move_is_capture(m))
|
||||||
{
|
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
||||||
int seeScore = pos.see(m);
|
- pos.type_of_piece_on(move_from(m)) + HistoryMax;
|
||||||
moves[i].score = (seeScore >= 0)? seeScore + HistoryMax : seeScore;
|
|
||||||
} else
|
|
||||||
moves[i].score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MovePicker::score_qcaptures() {
|
|
||||||
|
|
||||||
// Use MVV/LVA ordering
|
|
||||||
for (int i = 0; i < numOfMoves; i++)
|
|
||||||
{
|
|
||||||
Move m = moves[i].move;
|
|
||||||
if (move_is_promotion(m))
|
|
||||||
moves[i].score = QueenValueMidgame;
|
|
||||||
else
|
else
|
||||||
moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
cur->score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
|
||||||
-int(pos.type_of_piece_on(move_from(m)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// MovePicker::get_next_move() is the most important method of the MovePicker
|
||||||
|
/// class. It returns a new legal move every time it is called, until there
|
||||||
|
/// 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.
|
||||||
|
|
||||||
/// MovePicker::pick_move_from_list() picks the move with the biggest score
|
Move MovePicker::get_next_move() {
|
||||||
/// from a list of generated moves (moves[] or badCaptures[], depending on
|
|
||||||
/// the current move generation phase). It takes care not to return the
|
|
||||||
/// transposition table move if that has already been serched previously.
|
|
||||||
|
|
||||||
Move MovePicker::pick_move_from_list() {
|
Move move;
|
||||||
|
|
||||||
assert(movesPicked >= 0);
|
while (true)
|
||||||
assert(!pos.is_check() || PhaseTable[phaseIndex] == PH_EVASIONS || PhaseTable[phaseIndex] == PH_STOP);
|
{
|
||||||
assert( pos.is_check() || PhaseTable[phaseIndex] != PH_EVASIONS);
|
while (curMove != lastMove)
|
||||||
|
|
||||||
switch (PhaseTable[phaseIndex]) {
|
|
||||||
|
|
||||||
case PH_GOOD_CAPTURES:
|
|
||||||
case PH_KILLERS:
|
|
||||||
case PH_NONCAPTURES:
|
|
||||||
while (movesPicked < numOfMoves)
|
|
||||||
{
|
{
|
||||||
Move move = moves[movesPicked++].move;
|
switch (phase) {
|
||||||
if ( move != ttMove
|
|
||||||
&& move != mateKiller
|
case PH_TT_MOVES:
|
||||||
&& (!checkKillers || (move != killer1 && move != killer2))
|
move = (curMove++)->move;
|
||||||
&& (!checkLegal || pos.pl_move_is_legal(move, pinned)))
|
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 >= badCaptureThreshold)
|
||||||
|
return move;
|
||||||
|
|
||||||
|
// Losing capture, move it to the badCaptures[] array, note
|
||||||
|
// that move has now been already checked for legality.
|
||||||
|
assert(int(lastBadCapture - badCaptures) < 63);
|
||||||
|
lastBadCapture->move = move;
|
||||||
|
lastBadCapture->score = seeValue;
|
||||||
|
lastBadCapture++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PH_KILLERS:
|
||||||
|
move = (curMove++)->move;
|
||||||
|
if ( move != MOVE_NONE
|
||||||
|
&& move != ttMoves[0].move
|
||||||
|
&& move != ttMoves[1].move
|
||||||
|
&& move_is_legal(pos, move, pinned)
|
||||||
|
&& !pos.move_is_capture(move))
|
||||||
|
return 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
|
||||||
|
&& move != killers[1].move
|
||||||
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
|
return move;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PH_BAD_CAPTURES:
|
||||||
|
move = pick_best(curMove++, lastMove).move;
|
||||||
return 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:
|
||||||
|
move = (curMove++)->move;
|
||||||
|
if ( move != ttMoves[0].move
|
||||||
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
|
return move;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PH_STOP:
|
||||||
|
return MOVE_NONE;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
go_next_phase();
|
||||||
|
|
||||||
case PH_EVASIONS:
|
|
||||||
if (movesPicked < numOfMoves)
|
|
||||||
return moves[movesPicked++].move;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
|
||||||
while (movesPicked < numOfBadCaptures)
|
|
||||||
{
|
|
||||||
Move move = badCaptures[movesPicked++].move;
|
|
||||||
if ( move != ttMove
|
|
||||||
&& move != mateKiller
|
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
|
||||||
case PH_QCHECKS:
|
|
||||||
while (movesPicked < numOfMoves)
|
|
||||||
{
|
|
||||||
Move move = moves[movesPicked++].move;
|
|
||||||
// Maybe postpone the legality check until after futility pruning?
|
|
||||||
if ( move != ttMove
|
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::init_phase_table() initializes the PhaseTable[],
|
|
||||||
/// MainSearchPhaseIndex, EvasionPhaseIndex, QsearchWithChecksPhaseIndex
|
|
||||||
/// and QsearchWithoutChecksPhaseIndex. It is only called once during
|
|
||||||
/// program startup, and never again while the program is running.
|
|
||||||
|
|
||||||
void MovePicker::init_phase_table() {
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
// Main search
|
|
||||||
MainSearchPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_TT_MOVE;
|
|
||||||
PhaseTable[i++] = PH_MATE_KILLER;
|
|
||||||
PhaseTable[i++] = PH_GOOD_CAPTURES;
|
|
||||||
PhaseTable[i++] = PH_KILLERS;
|
|
||||||
PhaseTable[i++] = PH_NONCAPTURES;
|
|
||||||
PhaseTable[i++] = PH_BAD_CAPTURES;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
|
|
||||||
// Check evasions
|
|
||||||
EvasionsPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_EVASIONS;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
|
|
||||||
// Quiescence search with checks
|
|
||||||
QsearchWithChecksPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_TT_MOVE;
|
|
||||||
PhaseTable[i++] = PH_QCAPTURES;
|
|
||||||
PhaseTable[i++] = PH_QCHECKS;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
|
|
||||||
// Quiescence search without checks
|
|
||||||
QsearchWithoutChecksPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_TT_MOVE;
|
|
||||||
PhaseTable[i++] = PH_QCAPTURES;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
}
|
|
||||||
|
|||||||
+17
-47
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +34,6 @@
|
|||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
struct EvalInfo;
|
|
||||||
struct SearchStack;
|
struct SearchStack;
|
||||||
|
|
||||||
/// MovePicker is a class which is used to pick one legal move at a time from
|
/// MovePicker is a class which is used to pick one legal move at a time from
|
||||||
@@ -51,45 +49,24 @@ class MovePicker {
|
|||||||
MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
|
MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL, Value beta = -VALUE_INFINITE);
|
||||||
enum MovegenPhase {
|
|
||||||
PH_TT_MOVE, // Transposition table move
|
|
||||||
PH_MATE_KILLER, // Mate killer from the current ply
|
|
||||||
PH_GOOD_CAPTURES, // Queen promotions and captures with SEE values >= 0
|
|
||||||
PH_KILLERS, // Killer moves from the current ply
|
|
||||||
PH_NONCAPTURES, // Non-captures and underpromotions
|
|
||||||
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < 0
|
|
||||||
PH_EVASIONS, // Check evasions
|
|
||||||
PH_QCAPTURES, // Captures in quiescence search
|
|
||||||
PH_QCHECKS, // Non-capture checks in quiescence search
|
|
||||||
PH_STOP
|
|
||||||
};
|
|
||||||
|
|
||||||
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL);
|
|
||||||
Move get_next_move();
|
Move get_next_move();
|
||||||
Move get_next_move(Lock& lock);
|
int number_of_evasions() const;
|
||||||
int number_of_moves() const;
|
|
||||||
Bitboard discovered_check_candidates() const;
|
|
||||||
|
|
||||||
static void init_phase_table();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void score_captures();
|
void score_captures();
|
||||||
void score_noncaptures();
|
void score_noncaptures();
|
||||||
void score_evasions();
|
void score_evasions_or_checks();
|
||||||
void score_qcaptures();
|
void go_next_phase();
|
||||||
Move pick_move_from_list();
|
|
||||||
|
|
||||||
const Position& pos;
|
const Position& pos;
|
||||||
const History& H;
|
const History& H;
|
||||||
Move ttMove, mateKiller, killer1, killer2;
|
MoveStack ttMoves[2], killers[2];
|
||||||
Bitboard pinned, dc;
|
int badCaptureThreshold, phase;
|
||||||
|
const uint8_t* phasePtr;
|
||||||
|
MoveStack *curMove, *lastMove, *lastGoodNonCapture, *lastBadCapture;
|
||||||
|
Bitboard pinned;
|
||||||
MoveStack moves[256], badCaptures[64];
|
MoveStack moves[256], badCaptures[64];
|
||||||
int phaseIndex;
|
|
||||||
int numOfMoves, numOfBadCaptures;
|
|
||||||
int movesPicked;
|
|
||||||
bool checkKillers, checkLegal;
|
|
||||||
bool finished;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -97,21 +74,14 @@ private:
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// MovePicker::number_of_moves() simply returns the numOfMoves member
|
/// MovePicker::number_of_evasions() simply returns the number of moves in
|
||||||
/// variable. It is intended to be used in positions where the side to move
|
/// evasions phase. It is intended to be used in positions where the side to
|
||||||
/// is in check, for detecting checkmates or situations where there is only
|
/// move is in check, for detecting checkmates or situations where there is
|
||||||
/// a single reply to check.
|
/// only a single reply to check.
|
||||||
|
/// WARNING: It works as long as PH_EVASIONS is the _only_ phase for evasions.
|
||||||
|
|
||||||
inline int MovePicker::number_of_moves() const {
|
inline int MovePicker::number_of_evasions() const {
|
||||||
return numOfMoves;
|
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)
|
#endif // !defined(MOVEPICK_H_INCLUDED)
|
||||||
|
|||||||
+231
-260
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "bitcount.h"
|
#include "bitcount.h"
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
@@ -37,67 +38,39 @@ namespace {
|
|||||||
|
|
||||||
/// Constants and variables
|
/// Constants and variables
|
||||||
|
|
||||||
// Doubled pawn penalty by file, middle game.
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
const Value DoubledPawnMidgamePenalty[8] = {
|
|
||||||
Value(13), Value(20), Value(23), Value(23),
|
// Doubled pawn penalty by file
|
||||||
Value(23), Value(23), Value(20), Value(13)
|
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.
|
// Isolated pawn penalty by file
|
||||||
const Value DoubledPawnEndgamePenalty[8] = {
|
const Score IsolatedPawnPenalty[8] = {
|
||||||
Value(43), Value(48), Value(48), Value(48),
|
S(25, 30), S(36, 35), S(40, 35), S(40, 35),
|
||||||
Value(48), Value(48), Value(48), Value(43)
|
S(40, 35), S(40, 35), S(36, 35), S(25, 30)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Isolated pawn penalty by file, middle game.
|
// Backward pawn penalty by file
|
||||||
const Value IsolatedPawnMidgamePenalty[8] = {
|
const Score BackwardPawnPenalty[8] = {
|
||||||
Value(25), Value(36), Value(40), Value(40),
|
S(20, 28), S(29, 31), S(33, 31), S(33, 31),
|
||||||
Value(40), Value(40), Value(36), Value(25)
|
S(33, 31), S(33, 31), S(29, 31), S(20, 28)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Isolated pawn penalty by file, endgame.
|
// Pawn chain membership bonus by file
|
||||||
const Value IsolatedPawnEndgamePenalty[8] = {
|
const Score ChainBonus[8] = {
|
||||||
Value(30), Value(35), Value(35), Value(35),
|
S(11,-1), S(13,-1), S(13,-1), S(14,-1),
|
||||||
Value(35), Value(35), Value(35), Value(30)
|
S(14,-1), S(13,-1), S(13,-1), S(11,-1)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Backward pawn penalty by file, middle game.
|
// Candidate passed pawn bonus by rank
|
||||||
const Value BackwardPawnMidgamePenalty[8] = {
|
const Score CandidateBonus[8] = {
|
||||||
Value(20), Value(29), Value(33), Value(33),
|
S( 0, 0), S( 6, 13), S(6,13), S(14,29),
|
||||||
Value(33), Value(33), Value(29), Value(20)
|
S(34,68), S(83,166), S(0, 0), S( 0, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Backward pawn penalty by file, endgame.
|
// Pawn storm tables for positions with opposite castling
|
||||||
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)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Pawn storm tables for positions with opposite castling:
|
|
||||||
const int QStormTable[64] = {
|
const int QStormTable[64] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
-22,-22,-22,-14,-6, 0, 0, 0,
|
-22,-22,-22,-14,-6, 0, 0, 0,
|
||||||
@@ -140,7 +113,7 @@ PawnInfoTable::PawnInfoTable(unsigned numOfEntries) {
|
|||||||
|
|
||||||
size = numOfEntries;
|
size = numOfEntries;
|
||||||
entries = new PawnInfo[size];
|
entries = new PawnInfo[size];
|
||||||
if (entries == NULL)
|
if (!entries)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(PawnInfo))
|
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(PawnInfo))
|
||||||
<< " bytes for pawn hash table." << std::endl;
|
<< " bytes for pawn hash table." << std::endl;
|
||||||
@@ -156,22 +129,32 @@ PawnInfoTable::~PawnInfoTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// PawnInfo::clear() resets to zero the PawnInfo entry. Note that
|
||||||
|
/// kingSquares[] is initialized to SQ_NONE instead.
|
||||||
|
|
||||||
|
void PawnInfo::clear() {
|
||||||
|
|
||||||
|
memset(this, 0, sizeof(PawnInfo));
|
||||||
|
kingSquares[WHITE] = kingSquares[BLACK] = SQ_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// PawnInfoTable::get_pawn_info() takes a position object as input, computes
|
/// PawnInfoTable::get_pawn_info() takes a position object as input, computes
|
||||||
/// a PawnInfo object, and returns a pointer to it. The result is also
|
/// a PawnInfo object, and returns a pointer to it. The result is also
|
||||||
/// stored in a hash table, so we don't have to recompute everything when
|
/// stored in a hash table, so we don't have to recompute everything when
|
||||||
/// the same pawn structure occurs again.
|
/// the same pawn structure occurs again.
|
||||||
|
|
||||||
PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
Key key = pos.get_pawn_key();
|
Key key = pos.get_pawn_key();
|
||||||
int index = int(key & (size - 1));
|
int index = int(key & (size - 1));
|
||||||
PawnInfo *pi = entries + index;
|
PawnInfo* pi = entries + index;
|
||||||
|
|
||||||
// If pi->key matches the position's pawn hash key, it means that we
|
// If pi->key matches the position's pawn hash key, it means that we
|
||||||
// have analysed this pawn structure before, and we can simply return the
|
// have analysed this pawn structure before, and we can simply return
|
||||||
// information we found the last time instead of recomputing it
|
// the information we found the last time instead of recomputing it.
|
||||||
if (pi->key == key)
|
if (pi->key == key)
|
||||||
return pi;
|
return pi;
|
||||||
|
|
||||||
@@ -179,209 +162,197 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
|||||||
pi->clear();
|
pi->clear();
|
||||||
pi->key = key;
|
pi->key = key;
|
||||||
|
|
||||||
Value mgValue[2] = {Value(0), Value(0)};
|
// Calculate pawn attacks
|
||||||
Value egValue[2] = {Value(0), Value(0)};
|
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
|
// Evaluate pawns for both colors
|
||||||
for (Color us = WHITE; us <= BLACK; us++)
|
pi->value = evaluate_pawns<WHITE>(pos, whitePawns, blackPawns, pi)
|
||||||
{
|
- evaluate_pawns<BLACK>(pos, blackPawns, whitePawns, pi);
|
||||||
Color them = opposite_color(us);
|
|
||||||
Bitboard ourPawns = pos.pawns(us);
|
|
||||||
Bitboard theirPawns = pos.pawns(them);
|
|
||||||
Bitboard pawns = ourPawns;
|
|
||||||
int bonus;
|
|
||||||
|
|
||||||
// Initialize pawn storm scores by giving bonuses for open files
|
|
||||||
for (File f = FILE_A; f <= FILE_H; f++)
|
|
||||||
if (Position::file_is_half_open(ourPawns, f))
|
|
||||||
{
|
|
||||||
pi->ksStormValue[us] += KStormOpenFileBonus[f];
|
|
||||||
pi->qsStormValue[us] += QStormOpenFileBonus[f];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through all pawns of the current color and score each pawn
|
|
||||||
while (pawns)
|
|
||||||
{
|
|
||||||
bool passed, doubled, isolated, backward, chain, candidate;
|
|
||||||
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));
|
|
||||||
|
|
||||||
// The file containing the pawn is not half open
|
|
||||||
pi->halfOpenFiles[us] &= ~(1 << f);
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
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.
|
|
||||||
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
|
|
||||||
|| (pos.pawn_attacks(us, s) & 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;
|
|
||||||
if (us == WHITE)
|
|
||||||
{
|
|
||||||
for (b = pos.pawn_attacks(us, s); !(b & (ourPawns | theirPawns)); b <<= 8);
|
|
||||||
backward = (b | (b << 8)) & theirPawns;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (b = pos.pawn_attacks(us, s); !(b & (ourPawns | theirPawns)); b >>= 8);
|
|
||||||
backward = (b | (b >> 8)) & theirPawns;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test for candidate passed pawn
|
|
||||||
candidate = !passed
|
|
||||||
&& Position::file_is_half_open(theirPawns, 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)))
|
|
||||||
{
|
|
||||||
// candidate = true;
|
|
||||||
passed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Score this pawn
|
|
||||||
Value mv = Value(0), ev = Value(0);
|
|
||||||
if (isolated)
|
|
||||||
{
|
|
||||||
mv -= IsolatedPawnMidgamePenalty[f];
|
|
||||||
ev -= IsolatedPawnEndgamePenalty[f];
|
|
||||||
if (Position::file_is_half_open(theirPawns, f))
|
|
||||||
{
|
|
||||||
mv -= IsolatedPawnMidgamePenalty[f] / 2;
|
|
||||||
ev -= IsolatedPawnEndgamePenalty[f] / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (doubled)
|
|
||||||
{
|
|
||||||
mv -= DoubledPawnMidgamePenalty[f];
|
|
||||||
ev -= DoubledPawnEndgamePenalty[f];
|
|
||||||
}
|
|
||||||
if (backward)
|
|
||||||
{
|
|
||||||
mv -= BackwardPawnMidgamePenalty[f];
|
|
||||||
ev -= BackwardPawnEndgamePenalty[f];
|
|
||||||
if (Position::file_is_half_open(theirPawns, f))
|
|
||||||
{
|
|
||||||
mv -= BackwardPawnMidgamePenalty[f] / 2;
|
|
||||||
ev -= BackwardPawnEndgamePenalty[f] / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (chain)
|
|
||||||
{
|
|
||||||
mv += ChainMidgameBonus[f];
|
|
||||||
ev += ChainEndgameBonus[f];
|
|
||||||
}
|
|
||||||
if (candidate)
|
|
||||||
{
|
|
||||||
mv += CandidateMidgameBonus[relative_rank(us, s)];
|
|
||||||
ev += CandidateEndgameBonus[relative_rank(us, s)];
|
|
||||||
}
|
|
||||||
|
|
||||||
mgValue[us] += mv;
|
|
||||||
egValue[us] += ev;
|
|
||||||
|
|
||||||
// If the pawn is passed, set the square of the pawn in the passedPawns
|
|
||||||
// bitboard
|
|
||||||
if (passed)
|
|
||||||
set_bit(&(pi->passedPawns), s);
|
|
||||||
} // while(pawns)
|
|
||||||
} // for(colors)
|
|
||||||
|
|
||||||
pi->mgValue = int16_t(mgValue[WHITE] - mgValue[BLACK]);
|
|
||||||
pi->egValue = int16_t(egValue[WHITE] - egValue[BLACK]);
|
|
||||||
return 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) {
|
||||||
|
|
||||||
|
unsigned shelter = 0;
|
||||||
|
Bitboard pawns = pos.pieces(PAWN, c) & this_and_neighboring_files_bb(ksq);
|
||||||
|
unsigned r = ksq & (7 << 3);
|
||||||
|
for (int i = 1, k = (c ? -8 : 8); i < 4; i++)
|
||||||
|
{
|
||||||
|
r += k;
|
||||||
|
shelter += BitCount8Bit[(pawns >> r) & 0xFF] * (128 >> i);
|
||||||
|
}
|
||||||
|
kingSquares[c] = ksq;
|
||||||
|
kingShelters[c] = shelter;
|
||||||
|
return shelter;
|
||||||
|
}
|
||||||
|
|||||||
+21
-33
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -45,29 +45,30 @@ class PawnInfo {
|
|||||||
friend class PawnInfoTable;
|
friend class PawnInfoTable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PawnInfo() : key(0) { clear(); }
|
PawnInfo() { clear(); }
|
||||||
|
|
||||||
Value mg_value() const;
|
Score pawns_value() const;
|
||||||
Value eg_value() const;
|
|
||||||
Value kingside_storm_value(Color c) const;
|
Value kingside_storm_value(Color c) const;
|
||||||
Value queenside_storm_value(Color c) const;
|
Value queenside_storm_value(Color c) const;
|
||||||
|
Bitboard pawn_attacks(Color c) const;
|
||||||
Bitboard passed_pawns() const;
|
Bitboard passed_pawns() const;
|
||||||
int file_is_half_open(Color c, File f) const;
|
int file_is_half_open(Color c, File f) const;
|
||||||
int has_open_file_to_left(Color c, File f) const;
|
int has_open_file_to_left(Color c, File f) const;
|
||||||
int has_open_file_to_right(Color c, File f) const;
|
int has_open_file_to_right(Color c, File f) const;
|
||||||
int kingShelter(Color c, Square ksq) const;
|
int get_king_shelter(const Position& pos, Color c, Square ksq);
|
||||||
void setKingShelter(Color c, Square ksq, int value);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void clear();
|
void clear();
|
||||||
|
int updateShelter(const Position& pos, Color c, Square ksq);
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
Bitboard passedPawns;
|
Bitboard passedPawns;
|
||||||
int16_t mgValue, egValue;
|
Bitboard pawnAttacks[2];
|
||||||
|
Score value;
|
||||||
int16_t ksStormValue[2], qsStormValue[2];
|
int16_t ksStormValue[2], qsStormValue[2];
|
||||||
uint8_t halfOpenFiles[2];
|
uint8_t halfOpenFiles[2];
|
||||||
Square kingSquares[2];
|
Square kingSquares[2];
|
||||||
int16_t kingShelters[2];
|
uint8_t kingShelters[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The PawnInfoTable class represents a pawn hash table. It is basically
|
/// The PawnInfoTable class represents a pawn hash table. It is basically
|
||||||
@@ -83,6 +84,9 @@ public:
|
|||||||
PawnInfo* get_pawn_info(const Position& pos);
|
PawnInfo* get_pawn_info(const Position& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template<Color Us>
|
||||||
|
Score evaluate_pawns(const Position& pos, Bitboard ourPawns, Bitboard theirPawns, PawnInfo* pi);
|
||||||
|
|
||||||
unsigned size;
|
unsigned size;
|
||||||
PawnInfo* entries;
|
PawnInfo* entries;
|
||||||
};
|
};
|
||||||
@@ -92,18 +96,18 @@ private:
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
inline Value PawnInfo::mg_value() const {
|
inline Score PawnInfo::pawns_value() const {
|
||||||
return Value(mgValue);
|
return value;
|
||||||
}
|
|
||||||
|
|
||||||
inline Value PawnInfo::eg_value() const {
|
|
||||||
return Value(egValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard PawnInfo::passed_pawns() const {
|
inline Bitboard PawnInfo::passed_pawns() const {
|
||||||
return passedPawns;
|
return passedPawns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Bitboard PawnInfo::pawn_attacks(Color c) const {
|
||||||
|
return pawnAttacks[c];
|
||||||
|
}
|
||||||
|
|
||||||
inline Value PawnInfo::kingside_storm_value(Color c) const {
|
inline Value PawnInfo::kingside_storm_value(Color c) const {
|
||||||
return Value(ksStormValue[c]);
|
return Value(ksStormValue[c]);
|
||||||
}
|
}
|
||||||
@@ -124,24 +128,8 @@ inline int PawnInfo::has_open_file_to_right(Color c, File f) const {
|
|||||||
return halfOpenFiles[c] & ~((1 << int(f+1)) - 1);
|
return halfOpenFiles[c] & ~((1 << int(f+1)) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int PawnInfo::kingShelter(Color c, Square ksq) const {
|
inline int PawnInfo::get_king_shelter(const Position& pos, Color c, Square ksq) {
|
||||||
return (kingSquares[c] == ksq ? kingShelters[c] : -1);
|
return (kingSquares[c] == ksq ? kingShelters[c] : updateShelter(pos, c, ksq));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PawnInfo::setKingShelter(Color c, Square ksq, int value) {
|
|
||||||
kingSquares[c] = ksq;
|
|
||||||
kingShelters[c] = (int16_t)value;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void PawnInfo::clear() {
|
|
||||||
|
|
||||||
passedPawns = EmptyBoardBB;
|
|
||||||
mgValue = egValue = 0;
|
|
||||||
ksStormValue[WHITE] = ksStormValue[BLACK] = 0;
|
|
||||||
qsStormValue[WHITE] = qsStormValue[BLACK] = 0;
|
|
||||||
halfOpenFiles[WHITE] = halfOpenFiles[BLACK] = 0xFF;
|
|
||||||
kingSquares[WHITE] = kingSquares[BLACK] = SQ_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(PAWNS_H_INCLUDED)
|
#endif // !defined(PAWNS_H_INCLUDED)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-5
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -83,10 +83,6 @@ inline int piece_is_slider(Piece p) {
|
|||||||
return SlidingArray[int(p)];
|
return SlidingArray[int(p)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int piece_is_slider(PieceType pt) {
|
|
||||||
return SlidingArray[int(pt)];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SquareDelta pawn_push(Color c) {
|
inline SquareDelta pawn_push(Color c) {
|
||||||
return (c == WHITE ? DELTA_N : DELTA_S);
|
return (c == WHITE ? DELTA_N : DELTA_S);
|
||||||
}
|
}
|
||||||
|
|||||||
+660
-822
File diff suppressed because it is too large
Load Diff
+98
-245
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -63,6 +63,18 @@ const int MaxGameLength = 220;
|
|||||||
//// Types
|
//// 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
|
/// Castle rights, encoded as bit fields
|
||||||
|
|
||||||
enum CastleRights {
|
enum CastleRights {
|
||||||
@@ -87,12 +99,13 @@ enum Phase {
|
|||||||
/// must be passed as a parameter.
|
/// must be passed as a parameter.
|
||||||
|
|
||||||
struct StateInfo {
|
struct StateInfo {
|
||||||
Key key, pawnKey, materialKey;
|
Key pawnKey, materialKey;
|
||||||
int castleRights, rule50;
|
int castleRights, rule50, pliesFromNull;
|
||||||
Square epSquare;
|
Square epSquare;
|
||||||
Value mgValue, egValue;
|
Score value;
|
||||||
Value npMaterial[2];
|
Value npMaterial[2];
|
||||||
|
|
||||||
|
Key key;
|
||||||
PieceType capture;
|
PieceType capture;
|
||||||
Bitboard checkersBB;
|
Bitboard checkersBB;
|
||||||
StateInfo* previous;
|
StateInfo* previous;
|
||||||
@@ -133,9 +146,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
Position() {};
|
Position();
|
||||||
Position(const Position& pos);
|
explicit Position(const Position& pos);
|
||||||
Position(const std::string& fen);
|
explicit Position(const std::string& fen);
|
||||||
|
|
||||||
// Text input/output
|
// Text input/output
|
||||||
void from_fen(const std::string& fen);
|
void from_fen(const std::string& fen);
|
||||||
@@ -143,7 +156,6 @@ public:
|
|||||||
void print(Move m = MOVE_NONE) const;
|
void print(Move m = MOVE_NONE) const;
|
||||||
|
|
||||||
// Copying
|
// Copying
|
||||||
void copy(const Position& pos);
|
|
||||||
void flipped_copy(const Position& pos);
|
void flipped_copy(const Position& pos);
|
||||||
|
|
||||||
// The piece on a given square
|
// The piece on a given square
|
||||||
@@ -162,26 +174,10 @@ public:
|
|||||||
Bitboard empty_squares() const;
|
Bitboard empty_squares() const;
|
||||||
Bitboard occupied_squares() const;
|
Bitboard occupied_squares() const;
|
||||||
Bitboard pieces_of_color(Color c) const;
|
Bitboard pieces_of_color(Color c) const;
|
||||||
Bitboard pieces_of_type(PieceType pt) const;
|
Bitboard pieces(PieceType pt) const;
|
||||||
Bitboard pieces_of_color_and_type(Color c, PieceType pt) const;
|
Bitboard pieces(PieceType pt, Color c) const;
|
||||||
Bitboard pawns() const;
|
Bitboard pieces(PieceType pt1, PieceType pt2) const;
|
||||||
Bitboard knights() const;
|
Bitboard pieces(PieceType pt1, PieceType pt2, Color c) const;
|
||||||
Bitboard bishops() const;
|
|
||||||
Bitboard rooks() const;
|
|
||||||
Bitboard queens() const;
|
|
||||||
Bitboard kings() const;
|
|
||||||
Bitboard rooks_and_queens() const;
|
|
||||||
Bitboard bishops_and_queens() const;
|
|
||||||
Bitboard sliders() const;
|
|
||||||
Bitboard pawns(Color c) const;
|
|
||||||
Bitboard knights(Color c) const;
|
|
||||||
Bitboard bishops(Color c) const;
|
|
||||||
Bitboard rooks(Color c) const;
|
|
||||||
Bitboard queens(Color c) const;
|
|
||||||
Bitboard kings(Color c) const;
|
|
||||||
Bitboard rooks_and_queens(Color c) const;
|
|
||||||
Bitboard bishops_and_queens(Color c) const;
|
|
||||||
Bitboard sliders_of_color(Color c) const;
|
|
||||||
|
|
||||||
// Number of pieces of each color and type
|
// Number of pieces of each color and type
|
||||||
int piece_count(Color c, PieceType pt) const;
|
int piece_count(Color c, PieceType pt) const;
|
||||||
@@ -199,66 +195,50 @@ public:
|
|||||||
Square initial_kr_square(Color c) const;
|
Square initial_kr_square(Color c) const;
|
||||||
Square initial_qr_square(Color c) const;
|
Square initial_qr_square(Color c) const;
|
||||||
|
|
||||||
// Attack bitboards
|
|
||||||
Bitboard sliding_attacks(Square s, Direction d) const;
|
|
||||||
Bitboard ray_attacks(Square s, SignedDirection d) const;
|
|
||||||
Bitboard pawn_attacks(Color c, Square s) const;
|
|
||||||
|
|
||||||
template<PieceType>
|
|
||||||
Bitboard piece_attacks(Square s) const;
|
|
||||||
|
|
||||||
// Bitboards for pinned pieces and discovered check candidates
|
// Bitboards for pinned pieces and discovered check candidates
|
||||||
Bitboard discovered_check_candidates(Color c) const;
|
Bitboard discovered_check_candidates(Color c) const;
|
||||||
Bitboard pinned_pieces(Color c, Bitboard& p) const;
|
|
||||||
Bitboard pinned_pieces(Color c) const;
|
Bitboard pinned_pieces(Color c) const;
|
||||||
|
|
||||||
// Checking pieces
|
// Checking pieces and under check information
|
||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
|
bool is_check() const;
|
||||||
|
|
||||||
// Piece lists
|
// Piece lists
|
||||||
Square piece_list(Color c, PieceType pt, int index) const;
|
Square piece_list(Color c, PieceType pt, int index) const;
|
||||||
|
const Square* piece_list_begin(Color c, PieceType pt) const;
|
||||||
|
|
||||||
// Attack information for a given square
|
// Information about attacks to or from a given square
|
||||||
bool square_is_attacked(Square s, Color c) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
Bitboard attacks_to(Square s) const;
|
Bitboard attacks_from(Piece p, Square s) const;
|
||||||
Bitboard attacks_to(Square s, Color c) const;
|
template<PieceType> Bitboard attacks_from(Square s) const;
|
||||||
bool is_check() const;
|
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||||
bool pawn_attacks_square(Color c, Square f, Square t) const;
|
|
||||||
|
|
||||||
template<PieceType>
|
|
||||||
Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
|
|
||||||
|
|
||||||
bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time
|
|
||||||
|
|
||||||
// Properties of moves
|
// 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_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) 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(Move m) const;
|
||||||
bool move_is_deep_pawn_push(Move m) const;
|
bool move_is_capture_or_promotion(Move m) const;
|
||||||
bool move_is_pawn_push_to_7th(Move m) const;
|
|
||||||
bool move_is_passed_pawn_push(Move m) const;
|
bool move_is_passed_pawn_push(Move m) const;
|
||||||
bool move_was_passed_pawn_push(Move m) const;
|
|
||||||
bool move_attacks_square(Move m, Square s) const;
|
bool move_attacks_square(Move m, Square s) const;
|
||||||
|
|
||||||
|
// Piece captured with previous moves
|
||||||
|
PieceType captured_piece() const;
|
||||||
|
|
||||||
// Information about pawns
|
// Information about pawns
|
||||||
bool pawn_is_passed(Color c, Square s) const;
|
bool pawn_is_passed(Color c, Square s) const;
|
||||||
static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
|
static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
|
||||||
static bool pawn_is_isolated(Bitboard ourPawns, Square s);
|
static bool pawn_is_isolated(Bitboard ourPawns, Square s);
|
||||||
static bool pawn_is_doubled(Bitboard ourPawns, Color c, Square s);
|
static bool pawn_is_doubled(Bitboard ourPawns, Color c, Square s);
|
||||||
|
|
||||||
// Open and half-open files
|
|
||||||
static bool file_is_open(Bitboard pawns, File f);
|
|
||||||
static bool file_is_half_open(Bitboard pawns, File f);
|
|
||||||
|
|
||||||
// Weak squares
|
// Weak squares
|
||||||
bool square_is_weak(Square s, Color c) const;
|
bool square_is_weak(Square s, Color c) const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void saveState();
|
void detach();
|
||||||
void do_move(Move m, StateInfo& st);
|
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 undo_move(Move m);
|
||||||
void do_null_move(StateInfo& st);
|
void do_null_move(StateInfo& st);
|
||||||
void undo_null_move();
|
void undo_null_move();
|
||||||
@@ -267,18 +247,18 @@ public:
|
|||||||
int see(Square from, Square to) const;
|
int see(Square from, Square to) const;
|
||||||
int see(Move m) const;
|
int see(Move m) const;
|
||||||
int see(Square to) const;
|
int see(Square to) const;
|
||||||
|
int see_sign(Move m) const;
|
||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key get_key() const;
|
Key get_key() const;
|
||||||
|
Key get_exclusion_key() const;
|
||||||
Key get_pawn_key() const;
|
Key get_pawn_key() const;
|
||||||
Key get_material_key() const;
|
Key get_material_key() const;
|
||||||
|
|
||||||
// Incremental evaluation
|
// Incremental evaluation
|
||||||
Value mg_value() const;
|
Score value() const;
|
||||||
Value eg_value() const;
|
|
||||||
Value non_pawn_material(Color c) const;
|
Value non_pawn_material(Color c) const;
|
||||||
Phase game_phase() const;
|
Score pst_delta(Piece piece, Square from, Square to) const;
|
||||||
template<GamePhase> Value pst_delta(Piece piece, Square from, Square to) const;
|
|
||||||
|
|
||||||
// Game termination checks
|
// Game termination checks
|
||||||
bool is_mate() const;
|
bool is_mate() const;
|
||||||
@@ -300,7 +280,7 @@ public:
|
|||||||
// Position consistency check, for debugging
|
// Position consistency check, for debugging
|
||||||
bool is_ok(int* failedStep = NULL) const;
|
bool is_ok(int* failedStep = NULL) const;
|
||||||
|
|
||||||
// Static member functions:
|
// Static member functions
|
||||||
static void init_zobrist();
|
static void init_zobrist();
|
||||||
static void init_piece_square_tables();
|
static void init_piece_square_tables();
|
||||||
|
|
||||||
@@ -313,18 +293,11 @@ private:
|
|||||||
void allow_ooo(Color c);
|
void allow_ooo(Color c);
|
||||||
|
|
||||||
// Helper functions for doing and undoing moves
|
// Helper functions for doing and undoing moves
|
||||||
void do_capture_move(PieceType capture, Color them, Square to);
|
void do_capture_move(Bitboard& key, PieceType capture, Color them, Square to, bool ep);
|
||||||
void do_castle_move(Move m);
|
void do_castle_move(Move m);
|
||||||
void do_promotion_move(Move m);
|
|
||||||
void do_ep_move(Move m);
|
|
||||||
void undo_castle_move(Move m);
|
void undo_castle_move(Move m);
|
||||||
void undo_promotion_move(Move m);
|
|
||||||
void undo_ep_move(Move m);
|
|
||||||
void find_checkers();
|
void find_checkers();
|
||||||
|
|
||||||
template<PieceType Piece>
|
|
||||||
void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
|
|
||||||
|
|
||||||
template<bool FindPinned>
|
template<bool FindPinned>
|
||||||
Bitboard hidden_checkers(Color c) const;
|
Bitboard hidden_checkers(Color c) const;
|
||||||
|
|
||||||
@@ -334,41 +307,40 @@ private:
|
|||||||
Key compute_material_key() const;
|
Key compute_material_key() const;
|
||||||
|
|
||||||
// Computing incremental evaluation scores and material counts
|
// Computing incremental evaluation scores and material counts
|
||||||
template<GamePhase> Value pst(Color c, PieceType pt, Square s) const;
|
Score pst(Color c, PieceType pt, Square s) const;
|
||||||
template<GamePhase> Value compute_value() const;
|
Score compute_value() const;
|
||||||
Value compute_non_pawn_material(Color c) const;
|
Value compute_non_pawn_material(Color c) const;
|
||||||
|
|
||||||
// Bitboards
|
|
||||||
Bitboard byColorBB[2], byTypeBB[8];
|
|
||||||
|
|
||||||
// Board
|
// Board
|
||||||
Piece board[64];
|
Piece board[64];
|
||||||
|
|
||||||
|
// Bitboards
|
||||||
|
Bitboard byTypeBB[8], byColorBB[2];
|
||||||
|
|
||||||
// Piece counts
|
// Piece counts
|
||||||
int pieceCount[2][8]; // [color][pieceType]
|
int pieceCount[2][8]; // [color][pieceType]
|
||||||
|
|
||||||
// Piece lists
|
// Piece lists
|
||||||
Square pieceList[2][8][16]; // [color][pieceType][index]
|
Square pieceList[2][8][16]; // [color][pieceType][index]
|
||||||
int index[64];
|
int index[64]; // [square]
|
||||||
|
|
||||||
// Other info
|
// Other info
|
||||||
Square kingSquare[2];
|
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
int gamePly;
|
int gamePly;
|
||||||
Key history[MaxGameLength];
|
Key history[MaxGameLength];
|
||||||
|
int castleRightsMask[64];
|
||||||
File initialKFile, initialKRFile, initialQRFile;
|
File initialKFile, initialKRFile, initialQRFile;
|
||||||
StateInfo startState;
|
StateInfo startState;
|
||||||
StateInfo* st;
|
StateInfo* st;
|
||||||
|
|
||||||
// Static variables
|
// Static variables
|
||||||
static int castleRightsMask[64];
|
|
||||||
static Key zobrist[2][8][64];
|
static Key zobrist[2][8][64];
|
||||||
static Key zobEp[64];
|
static Key zobEp[64];
|
||||||
static Key zobCastle[16];
|
static Key zobCastle[16];
|
||||||
static Key zobMaterial[2][8][16];
|
static Key zobMaterial[2][8][16];
|
||||||
static Key zobSideToMove;
|
static Key zobSideToMove;
|
||||||
static Value MgPieceSquareTable[16][64];
|
static Score PieceSquareTable[16][64];
|
||||||
static Value EgPieceSquareTable[16][64];
|
static Key zobExclusion;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -420,80 +392,20 @@ inline Bitboard Position::pieces_of_color(Color c) const {
|
|||||||
return byColorBB[c];
|
return byColorBB[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces_of_type(PieceType pt) const {
|
inline Bitboard Position::pieces(PieceType pt) const {
|
||||||
return byTypeBB[pt];
|
return byTypeBB[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces_of_color_and_type(Color c, PieceType pt) const {
|
inline Bitboard Position::pieces(PieceType pt, Color c) const {
|
||||||
return pieces_of_color(c) & pieces_of_type(pt);
|
return byTypeBB[pt] & byColorBB[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pawns() const {
|
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2) const {
|
||||||
return pieces_of_type(PAWN);
|
return byTypeBB[pt1] | byTypeBB[pt2];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::knights() const {
|
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2, Color c) const {
|
||||||
return pieces_of_type(KNIGHT);
|
return (byTypeBB[pt1] | byTypeBB[pt2]) & byColorBB[c];
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::bishops() const {
|
|
||||||
return pieces_of_type(BISHOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::rooks() const {
|
|
||||||
return pieces_of_type(ROOK);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::queens() const {
|
|
||||||
return pieces_of_type(QUEEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::kings() const {
|
|
||||||
return pieces_of_type(KING);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::rooks_and_queens() const {
|
|
||||||
return rooks() | queens();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::bishops_and_queens() const {
|
|
||||||
return bishops() | queens();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::sliders() const {
|
|
||||||
return bishops() | queens() | rooks();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::pawns(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, PAWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::knights(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, KNIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::bishops(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, BISHOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::rooks(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, ROOK);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::queens(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, QUEEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::kings(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, KING);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::rooks_and_queens(Color c) const {
|
|
||||||
return rooks_and_queens() & pieces_of_color(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::bishops_and_queens(Color c) const {
|
|
||||||
return bishops_and_queens() & pieces_of_color(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::piece_count(Color c, PieceType pt) const {
|
inline int Position::piece_count(Color c, PieceType pt) const {
|
||||||
@@ -504,12 +416,16 @@ inline Square Position::piece_list(Color c, PieceType pt, int index) const {
|
|||||||
return pieceList[c][pt][index];
|
return pieceList[c][pt][index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const Square* Position::piece_list_begin(Color c, PieceType pt) const {
|
||||||
|
return pieceList[c][pt];
|
||||||
|
}
|
||||||
|
|
||||||
inline Square Position::ep_square() const {
|
inline Square Position::ep_square() const {
|
||||||
return st->epSquare;
|
return st->epSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::king_square(Color c) const {
|
inline Square Position::king_square(Color c) const {
|
||||||
return kingSquare[c];
|
return pieceList[c][KING][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::can_castle_kingside(Color side) const {
|
inline bool Position::can_castle_kingside(Color side) const {
|
||||||
@@ -532,33 +448,29 @@ inline Square Position::initial_qr_square(Color c) const {
|
|||||||
return relative_square(c, make_square(initialQRFile, RANK_1));
|
return relative_square(c, make_square(initialQRFile, RANK_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pawn_attacks(Color c, Square s) const {
|
template<>
|
||||||
|
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
||||||
return StepAttackBB[piece_of_color_and_type(c, PAWN)][s];
|
return StepAttackBB[piece_of_color_and_type(c, PAWN)][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Piece> // Knight and King
|
template<PieceType Piece> // Knight and King and white pawns
|
||||||
inline Bitboard Position::piece_attacks(Square s) const {
|
inline Bitboard Position::attacks_from(Square s) const {
|
||||||
return StepAttackBB[Piece][s];
|
return StepAttackBB[Piece][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
|
inline Bitboard Position::attacks_from<BISHOP>(Square s) const {
|
||||||
return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s];
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline Bitboard Position::piece_attacks<BISHOP>(Square s) const {
|
|
||||||
return bishop_attacks_bb(s, occupied_squares());
|
return bishop_attacks_bb(s, occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<ROOK>(Square s) const {
|
inline Bitboard Position::attacks_from<ROOK>(Square s) const {
|
||||||
return rook_attacks_bb(s, occupied_squares());
|
return rook_attacks_bb(s, occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<QUEEN>(Square s) const {
|
inline Bitboard Position::attacks_from<QUEEN>(Square s) const {
|
||||||
return piece_attacks<ROOK>(s) | piece_attacks<BISHOP>(s);
|
return attacks_from<ROOK>(s) | attacks_from<BISHOP>(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::checkers() const {
|
inline Bitboard Position::checkers() const {
|
||||||
@@ -569,27 +481,8 @@ inline bool Position::is_check() const {
|
|||||||
return st->checkersBB != EmptyBoardBB;
|
return st->checkersBB != EmptyBoardBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const {
|
|
||||||
return bit_is_set(pawn_attacks(c, f), t);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<PieceType Piece>
|
|
||||||
Bitboard Position::piece_attacks_square(Square f, Square t) const {
|
|
||||||
return bit_is_set(piece_attacks<Piece>(f), t);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::attacks_to(Square s, Color c) const {
|
|
||||||
|
|
||||||
return attacks_to(s) & pieces_of_color(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::square_is_attacked(Square s, Color c) const {
|
|
||||||
|
|
||||||
return attacks_to(s, c) != EmptyBoardBB;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
||||||
return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s));
|
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) {
|
inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) {
|
||||||
@@ -604,22 +497,18 @@ inline bool Position::pawn_is_doubled(Bitboard ourPawns, Color c, Square s) {
|
|||||||
return ourPawns & squares_behind(c, s);
|
return ourPawns & squares_behind(c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::file_is_open(Bitboard pawns, File f) {
|
|
||||||
return !(pawns & file_bb(f));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::file_is_half_open(Bitboard pawns, File f) {
|
|
||||||
return !(pawns & file_bb(f));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::square_is_weak(Square s, Color c) const {
|
inline bool Position::square_is_weak(Square s, Color c) const {
|
||||||
return !(pawns(c) & outpost_mask(opposite_color(c), s));
|
return !(pieces(PAWN, c) & outpost_mask(opposite_color(c), s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_key() const {
|
inline Key Position::get_key() const {
|
||||||
return st->key;
|
return st->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Key Position::get_exclusion_key() const {
|
||||||
|
return st->key ^ zobExclusion;
|
||||||
|
}
|
||||||
|
|
||||||
inline Key Position::get_pawn_key() const {
|
inline Key Position::get_pawn_key() const {
|
||||||
return st->pawnKey;
|
return st->pawnKey;
|
||||||
}
|
}
|
||||||
@@ -628,60 +517,22 @@ inline Key Position::get_material_key() const {
|
|||||||
return st->materialKey;
|
return st->materialKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Position::GamePhase Ph>
|
inline Score Position::pst(Color c, PieceType pt, Square s) const {
|
||||||
inline Value Position::pst(Color c, PieceType pt, Square s) const {
|
return PieceSquareTable[piece_of_color_and_type(c, pt)][s];
|
||||||
return (Ph == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
|
|
||||||
: EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Position::GamePhase Ph>
|
inline Score Position::pst_delta(Piece piece, Square from, Square to) const {
|
||||||
inline Value Position::pst_delta(Piece piece, Square from, Square to) const {
|
return PieceSquareTable[piece][to] - PieceSquareTable[piece][from];
|
||||||
return (Ph == MidGame ? MgPieceSquareTable[piece][to] - MgPieceSquareTable[piece][from]
|
|
||||||
: EgPieceSquareTable[piece][to] - EgPieceSquareTable[piece][from]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::mg_value() const {
|
inline Score Position::value() const {
|
||||||
return st->mgValue;
|
return st->value;
|
||||||
}
|
|
||||||
|
|
||||||
inline Value Position::eg_value() const {
|
|
||||||
return st->egValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::non_pawn_material(Color c) const {
|
inline Value Position::non_pawn_material(Color c) const {
|
||||||
return st->npMaterial[c];
|
return st->npMaterial[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Phase Position::game_phase() const {
|
|
||||||
|
|
||||||
// Values modified by Joona Kiiski
|
|
||||||
static const Value MidgameLimit = Value(15713);
|
|
||||||
static const Value EndgameLimit = Value(4428);
|
|
||||||
|
|
||||||
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_deep_pawn_push(Move m) const {
|
|
||||||
|
|
||||||
Color c = side_to_move();
|
|
||||||
return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN)
|
|
||||||
&& relative_rank(c, move_to(m)) > RANK_4;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::move_is_pawn_push_to_7th(Move m) const {
|
|
||||||
|
|
||||||
Color c = side_to_move();
|
|
||||||
return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN)
|
|
||||||
&& relative_rank(c, move_to(m)) == RANK_7;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
||||||
|
|
||||||
Color c = side_to_move();
|
Color c = side_to_move();
|
||||||
@@ -689,13 +540,6 @@ inline bool Position::move_is_passed_pawn_push(Move m) const {
|
|||||||
&& pawn_is_passed(c, move_to(m));
|
&& pawn_is_passed(c, move_to(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::move_was_passed_pawn_push(Move m) const {
|
|
||||||
|
|
||||||
Color c = opposite_color(side_to_move());
|
|
||||||
return piece_on(move_to(m)) == piece_of_color_and_type(c, PAWN)
|
|
||||||
&& pawn_is_passed(c, move_to(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Position::rule_50_counter() const {
|
inline int Position::rule_50_counter() const {
|
||||||
|
|
||||||
return st->rule50;
|
return st->rule50;
|
||||||
@@ -710,14 +554,23 @@ inline bool Position::opposite_colored_bishops() const {
|
|||||||
|
|
||||||
inline bool Position::has_pawn_on_7th(Color c) const {
|
inline bool Position::has_pawn_on_7th(Color c) const {
|
||||||
|
|
||||||
return pawns(c) & relative_rank_bb(c, RANK_7);
|
return pieces(PAWN, c) & relative_rank_bb(c, RANK_7);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::move_is_capture(Move m) const {
|
inline bool Position::move_is_capture(Move m) const {
|
||||||
|
|
||||||
// Move must not be MOVE_NONE !
|
// 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)
|
#endif // !defined(POSITION_H_INCLUDED)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
/// that the move is a legal move from the position. The return value is
|
||||||
/// a string containing the move in short algebraic notation.
|
/// 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(pos.is_ok());
|
||||||
assert(move_is_ok(m));
|
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,
|
// Position::move_is_check doesn't detect all checks (not castling moves,
|
||||||
// promotions and en passant captures).
|
// promotions and en passant captures).
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
Position p(pos);
|
pos.do_move(m, st);
|
||||||
p.do_move(m, st);
|
if (pos.is_check())
|
||||||
if (p.is_check())
|
san += pos.is_mate() ? "#" : "+";
|
||||||
san += p.is_mate()? "#" : "+";
|
pos.undo_move(m);
|
||||||
|
|
||||||
return san;
|
return san;
|
||||||
}
|
}
|
||||||
@@ -142,13 +142,14 @@ Move move_from_san(const Position& pos, const string& movestr) {
|
|||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
||||||
|
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||||
|
|
||||||
// Castling moves
|
// Castling moves
|
||||||
if (movestr == "O-O-O" || movestr == "O-O-O+")
|
if (movestr == "O-O-O" || movestr == "O-O-O+")
|
||||||
{
|
{
|
||||||
Move m;
|
Move m;
|
||||||
while ((m = mp.get_next_move()) != MOVE_NONE)
|
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 m;
|
||||||
|
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
@@ -157,7 +158,7 @@ Move move_from_san(const Position& pos, const string& movestr) {
|
|||||||
{
|
{
|
||||||
Move m;
|
Move m;
|
||||||
while ((m = mp.get_next_move()) != MOVE_NONE)
|
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 m;
|
||||||
|
|
||||||
return MOVE_NONE;
|
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").
|
/// when the UCI parameter "Use Search Log" is "true").
|
||||||
|
|
||||||
const string pretty_pv(const Position& pos, int time, int depth,
|
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;
|
std::stringstream s;
|
||||||
|
|
||||||
// Depth
|
// Depth
|
||||||
s << std::setw(2) << depth << " ";
|
s << std::setw(2) << depth << " ";
|
||||||
|
|
||||||
// Score
|
// 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
|
// Time
|
||||||
s << std::setw(8) << time_string(time) << " ";
|
s << std::setw(8) << time_string(time) << " ";
|
||||||
@@ -366,11 +368,12 @@ namespace {
|
|||||||
return AMBIGUITY_NONE;
|
return AMBIGUITY_NONE;
|
||||||
|
|
||||||
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
||||||
|
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||||
Move mv, moveList[8];
|
Move mv, moveList[8];
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while ((mv = mp.get_next_move()) != MOVE_NONE)
|
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;
|
moveList[n++] = mv;
|
||||||
|
|
||||||
if (n == 1)
|
if (n == 1)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -36,9 +36,9 @@
|
|||||||
//// Prototypes
|
//// 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 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 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)
|
#endif // !defined(SAN_H_INCLUDED)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1825
-1549
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "move.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
|
/// from nodes shallower and deeper in the tree during the search. Each
|
||||||
/// search thread has its own array of SearchStack objects, indexed by the
|
/// search thread has its own array of SearchStack objects, indexed by the
|
||||||
/// current ply.
|
/// current ply.
|
||||||
|
struct EvalInfo;
|
||||||
|
|
||||||
struct SearchStack {
|
struct SearchStack {
|
||||||
Move pv[PLY_MAX];
|
Move pv[PLY_MAX_PLUS_2];
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Move mateKiller;
|
Move mateKiller;
|
||||||
Move threatMove;
|
Move threatMove;
|
||||||
Move killers[KILLER_MAX];
|
Move killers[KILLER_MAX];
|
||||||
Depth reduction;
|
Depth reduction;
|
||||||
|
Value eval;
|
||||||
|
|
||||||
void init(int ply);
|
void init(int ply);
|
||||||
void initKillers();
|
void initKillers();
|
||||||
@@ -64,11 +67,13 @@ struct SearchStack {
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
extern void init_search();
|
||||||
extern void init_threads();
|
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,
|
extern bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
||||||
int time[], int increment[], int movesToGo, int maxDepth,
|
int time[], int increment[], int movesToGo, int maxDepth,
|
||||||
int maxNodes, int maxTime, Move searchMoves[]);
|
int maxNodes, int maxTime, Move searchMoves[]);
|
||||||
|
extern int perft(Position &pos, Depth depth);
|
||||||
extern int64_t nodes_searched();
|
extern int64_t nodes_searched();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,6 +26,8 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
@@ -36,7 +38,8 @@
|
|||||||
//// Constants and variables
|
//// 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 {
|
struct SplitPoint {
|
||||||
SplitPoint *parent;
|
|
||||||
Position pos;
|
// Const data after splitPoint has been setup
|
||||||
SearchStack sstack[THREAD_MAX][PLY_MAX];
|
SplitPoint* parent;
|
||||||
SearchStack *parentSstack;
|
const Position* pos;
|
||||||
int ply;
|
|
||||||
Depth depth;
|
|
||||||
volatile Value alpha, beta, bestValue;
|
|
||||||
bool pvNode;
|
bool pvNode;
|
||||||
Bitboard dcCandidates;
|
Depth depth;
|
||||||
int master, slaves[THREAD_MAX];
|
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;
|
Lock lock;
|
||||||
MovePicker *mp;
|
volatile Value alpha;
|
||||||
|
volatile Value bestValue;
|
||||||
volatile int moves;
|
volatile int moves;
|
||||||
volatile int cpus;
|
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 {
|
struct Thread {
|
||||||
SplitPoint *splitPoint;
|
SplitPoint* splitPoint;
|
||||||
int activeSplitPoints;
|
volatile int activeSplitPoints;
|
||||||
uint64_t nodes;
|
uint64_t nodes;
|
||||||
uint64_t betaCutOffs[2];
|
uint64_t betaCutOffs[2];
|
||||||
bool failHighPly1;
|
volatile ThreadState state;
|
||||||
volatile bool stop;
|
|
||||||
volatile bool running;
|
|
||||||
volatile bool idle;
|
|
||||||
volatile bool workIsWaiting;
|
|
||||||
volatile bool printCurrentLine;
|
|
||||||
unsigned char pad[64]; // set some distance among local data for each thread
|
unsigned char pad[64]; // set some distance among local data for each thread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+92
-25
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,9 +25,15 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#if !(defined(__hpux) || defined(__ppc__) || defined(__ppc64__) || defined(__arm__))
|
||||||
|
# include <xmmintrin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "movegen.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
|
|
||||||
|
// The main transposition table
|
||||||
|
TranspositionTable TT;
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
@@ -49,22 +55,20 @@ TranspositionTable::~TranspositionTable() {
|
|||||||
/// TranspositionTable::set_size sets the size of the transposition table,
|
/// TranspositionTable::set_size sets the size of the transposition table,
|
||||||
/// measured in megabytes.
|
/// measured in megabytes.
|
||||||
|
|
||||||
void TranspositionTable::set_size(unsigned mbSize) {
|
void TranspositionTable::set_size(size_t mbSize) {
|
||||||
|
|
||||||
assert(mbSize >= 4 && mbSize <= 4096);
|
size_t newSize = 1024;
|
||||||
|
|
||||||
unsigned newSize = 1024;
|
// We store a cluster of ClusterSize number of TTEntry for each position
|
||||||
|
// and newSize is the maximum number of storable positions.
|
||||||
// We store a cluster of 4 TTEntry for each position and newSize is
|
while ((2 * newSize) * sizeof(TTCluster) <= (mbSize << 20))
|
||||||
// the maximum number of storable positions
|
|
||||||
while ((2 * newSize) * 4 * (sizeof(TTEntry)) <= (mbSize << 20))
|
|
||||||
newSize *= 2;
|
newSize *= 2;
|
||||||
|
|
||||||
if (newSize != size)
|
if (newSize != size)
|
||||||
{
|
{
|
||||||
size = newSize;
|
size = newSize;
|
||||||
delete [] entries;
|
delete [] entries;
|
||||||
entries = new TTEntry[size * 4];
|
entries = new TTCluster[size];
|
||||||
if (!entries)
|
if (!entries)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to allocate " << mbSize
|
std::cerr << "Failed to allocate " << mbSize
|
||||||
@@ -83,7 +87,17 @@ void TranspositionTable::set_size(unsigned mbSize) {
|
|||||||
|
|
||||||
void TranspositionTable::clear() {
|
void TranspositionTable::clear() {
|
||||||
|
|
||||||
memset(entries, 0, size * 4 * sizeof(TTEntry));
|
memset(entries, 0, size * sizeof(TTCluster));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// TranspositionTable::first_entry returns a pointer to the first
|
||||||
|
/// entry of a cluster given a position. The low 32 bits of the key
|
||||||
|
/// are used to get the index in the table.
|
||||||
|
|
||||||
|
inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
|
||||||
|
|
||||||
|
return entries[uint32_t(posKey) & (size - 1)].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -100,20 +114,22 @@ void TranspositionTable::clear() {
|
|||||||
void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, Move m) {
|
void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, Move m) {
|
||||||
|
|
||||||
TTEntry *tte, *replace;
|
TTEntry *tte, *replace;
|
||||||
|
uint32_t posKey32 = posKey >> 32; // Use the high 32 bits as key
|
||||||
|
|
||||||
tte = replace = first_entry(posKey);
|
tte = replace = first_entry(posKey);
|
||||||
for (int i = 0; i < 4; i++, tte++)
|
for (int i = 0; i < ClusterSize; i++, tte++)
|
||||||
{
|
{
|
||||||
if (!tte->key() || tte->key() == posKey) // empty or overwrite old
|
if (!tte->key() || tte->key() == posKey32) // empty or overwrite old
|
||||||
{
|
{
|
||||||
// Do not overwrite when new type is VALUE_TYPE_EVAL
|
// Do not overwrite when new type is VALUE_TYPE_EV_LO
|
||||||
if (tte->key() && t == VALUE_TYPE_EVAL)
|
if (tte->key() && t == VALUE_TYPE_EV_LO)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Preserve any exsisting ttMove
|
||||||
if (m == MOVE_NONE)
|
if (m == MOVE_NONE)
|
||||||
m = tte->move();
|
m = tte->move();
|
||||||
|
|
||||||
*tte = TTEntry(posKey, v, t, d, m, generation);
|
*tte = TTEntry(posKey32, v, t, d, m, generation);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (i == 0) // replace would be a no-op in this common case
|
else if (i == 0) // replace would be a no-op in this common case
|
||||||
@@ -126,7 +142,7 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
|
|||||||
if (c1 + c2 + c3 > 0)
|
if (c1 + c2 + c3 > 0)
|
||||||
replace = tte;
|
replace = tte;
|
||||||
}
|
}
|
||||||
*replace = TTEntry(posKey, v, t, d, m, generation);
|
*replace = TTEntry(posKey32, v, t, d, m, generation);
|
||||||
writes++;
|
writes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,24 +153,42 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
|
|||||||
|
|
||||||
TTEntry* TranspositionTable::retrieve(const Key posKey) const {
|
TTEntry* TranspositionTable::retrieve(const Key posKey) const {
|
||||||
|
|
||||||
TTEntry *tte = first_entry(posKey);
|
uint32_t posKey32 = posKey >> 32;
|
||||||
|
TTEntry* tte = first_entry(posKey);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++, tte++)
|
for (int i = 0; i < ClusterSize; i++, tte++)
|
||||||
if (tte->key() == posKey)
|
if (tte->key() == posKey32)
|
||||||
return tte;
|
return tte;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::first_entry returns a pointer to the first
|
/// TranspositionTable::prefetch looks up the current position in the
|
||||||
/// entry of a cluster given a position.
|
/// transposition table and load it in L1/L2 cache. This is a non
|
||||||
|
/// blocking function and do not stalls the CPU waiting for data
|
||||||
|
/// 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
|
||||||
|
|
||||||
inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
|
void TranspositionTable::prefetch(const Key posKey) const {
|
||||||
|
|
||||||
return entries + (int(posKey & (size - 1)) << 2);
|
#if defined(__INTEL_COMPILER) || defined(__ICL)
|
||||||
|
// This hack prevents prefetches to be optimized away by
|
||||||
|
// Intel compiler. Both MSVC and gcc seems not affected.
|
||||||
|
__asm__ ("");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char const* addr = (char*)first_entry(posKey);
|
||||||
|
_mm_prefetch(addr, _MM_HINT_T2);
|
||||||
|
_mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/// TranspositionTable::new_search() is called at the beginning of every new
|
/// TranspositionTable::new_search() is called at the beginning of every new
|
||||||
/// search. It increments the "generation" variable, which is used to
|
/// search. It increments the "generation" variable, which is used to
|
||||||
/// distinguish transposition table entries from previous searches from
|
/// distinguish transposition table entries from previous searches from
|
||||||
@@ -179,18 +213,51 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
|||||||
|
|
||||||
for (int i = 0; pv[i] != MOVE_NONE; i++)
|
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);
|
p.do_move(pv[i], st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// TranspositionTable::extract_pv() extends a PV by adding moves from the
|
||||||
|
/// transposition table at the end. This should ensure that the PV is almost
|
||||||
|
/// always at least two plies long, which is important, because otherwise we
|
||||||
|
/// 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[], const int PLY_MAX) {
|
||||||
|
|
||||||
|
const TTEntry* tte;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
pv[ply] = tte->move();
|
||||||
|
p.do_move(pv[ply++], st);
|
||||||
|
}
|
||||||
|
pv[ply] = MOVE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::full() returns the permill of all transposition table
|
/// TranspositionTable::full() returns the permill of all transposition table
|
||||||
/// entries which have received at least one write during the current search.
|
/// entries which have received at least one write during the current search.
|
||||||
/// It is used to display the "info hashfull ..." information in UCI.
|
/// It is used to display the "info hashfull ..." information in UCI.
|
||||||
|
|
||||||
int TranspositionTable::full() const {
|
int TranspositionTable::full() const {
|
||||||
|
|
||||||
double N = double(size) * 4.0;
|
double N = double(size) * ClusterSize;
|
||||||
return int(1000 * (1 - exp(writes * log(1.0 - 1.0/N))));
|
return int(1000 * (1 - exp(writes * log(1.0 - 1.0/N))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -36,43 +36,57 @@
|
|||||||
|
|
||||||
/// The TTEntry class is the class of transposition table entries
|
/// The TTEntry class is the class of transposition table entries
|
||||||
///
|
///
|
||||||
/// A TTEntry needs 128 bits to be stored
|
/// A TTEntry needs 96 bits to be stored
|
||||||
///
|
///
|
||||||
/// bit 0-63: key
|
/// bit 0-31: key
|
||||||
/// bit 64-95: data
|
/// bit 32-63: data
|
||||||
/// bit 96-111: value
|
/// bit 64-79: value
|
||||||
/// bit 112-127: depth
|
/// bit 80-95: depth
|
||||||
///
|
///
|
||||||
/// the 32 bits of the data field are so defined
|
/// the 32 bits of the data field are so defined
|
||||||
///
|
///
|
||||||
/// bit 0-16: move
|
/// bit 0-16: move
|
||||||
/// bit 17-19: not used
|
/// bit 17-18: not used
|
||||||
/// bit 20-22: value type
|
/// bit 19-22: value type
|
||||||
/// bit 23-31: generation
|
/// bit 23-31: generation
|
||||||
|
|
||||||
class TTEntry {
|
class TTEntry {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TTEntry() {}
|
TTEntry() {}
|
||||||
TTEntry(Key k, Value v, ValueType t, Depth d, Move m, int generation)
|
TTEntry(uint32_t k, Value v, ValueType t, Depth d, Move m, int generation)
|
||||||
: key_ (k), data((m & 0x1FFFF) | (t << 20) | (generation << 23)),
|
: key_ (k), data((m & 0x1FFFF) | (t << 19) | (generation << 23)),
|
||||||
value_(int16_t(v)), depth_(int16_t(d)) {}
|
value_(int16_t(v)), depth_(int16_t(d)) {}
|
||||||
|
|
||||||
Key key() const { return key_; }
|
uint32_t key() const { return key_; }
|
||||||
Depth depth() const { return Depth(depth_); }
|
Depth depth() const { return Depth(depth_); }
|
||||||
Move move() const { return Move(data & 0x1FFFF); }
|
Move move() const { return Move(data & 0x1FFFF); }
|
||||||
Value value() const { return Value(value_); }
|
Value value() const { return Value(value_); }
|
||||||
ValueType type() const { return ValueType((data >> 20) & 7); }
|
ValueType type() const { return ValueType((data >> 19) & 0xF); }
|
||||||
int generation() const { return (data >> 23); }
|
int generation() const { return (data >> 23); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Key key_;
|
uint32_t key_;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
int16_t value_;
|
int16_t value_;
|
||||||
int16_t depth_;
|
int16_t depth_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The transposition table class. This is basically just a huge array
|
|
||||||
|
/// This is the number of TTEntry slots for each position
|
||||||
|
const int ClusterSize = 5;
|
||||||
|
|
||||||
|
/// Each group of ClusterSize number of TTEntry form a TTCluster
|
||||||
|
/// that is indexed by a single position key. Cluster is padded
|
||||||
|
/// to a cache line size so to guarantee always aligned accesses.
|
||||||
|
|
||||||
|
struct TTCluster {
|
||||||
|
TTEntry data[ClusterSize];
|
||||||
|
char cache_line_padding[64 - sizeof(TTEntry[ClusterSize])];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// The transposition table class. This is basically just a huge array
|
||||||
/// containing TTEntry objects, and a few methods for writing new entries
|
/// containing TTEntry objects, and a few methods for writing new entries
|
||||||
/// and reading new ones.
|
/// and reading new ones.
|
||||||
|
|
||||||
@@ -81,26 +95,30 @@ class TranspositionTable {
|
|||||||
public:
|
public:
|
||||||
TranspositionTable();
|
TranspositionTable();
|
||||||
~TranspositionTable();
|
~TranspositionTable();
|
||||||
void set_size(unsigned mbSize);
|
void set_size(size_t mbSize);
|
||||||
void clear();
|
void clear();
|
||||||
void store(const Key posKey, Value v, ValueType type, Depth d, Move m);
|
void store(const Key posKey, Value v, ValueType type, Depth d, Move m);
|
||||||
TTEntry* retrieve(const Key posKey) const;
|
TTEntry* retrieve(const Key posKey) const;
|
||||||
|
void prefetch(const Key posKey) const;
|
||||||
void new_search();
|
void new_search();
|
||||||
void insert_pv(const Position& pos, Move pv[]);
|
void insert_pv(const Position& pos, Move pv[]);
|
||||||
|
void extract_pv(const Position& pos, Move pv[], const int PLY_MAX);
|
||||||
int full() const;
|
int full() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline TTEntry* first_entry(const Key posKey) const;
|
inline TTEntry* first_entry(const Key posKey) const;
|
||||||
|
|
||||||
// Be sure 'writes' is at least one cacheline away
|
// Be sure 'writes' is at least one cache line away
|
||||||
// from read only variables.
|
// from read only variables.
|
||||||
unsigned char pad_before[64 - sizeof(unsigned)];
|
unsigned char pad_before[64 - sizeof(unsigned)];
|
||||||
unsigned writes; // heavy SMP read/write access here
|
unsigned writes; // heavy SMP read/write access here
|
||||||
unsigned char pad_after[64];
|
unsigned char pad_after[64];
|
||||||
|
|
||||||
unsigned size;
|
size_t size;
|
||||||
TTEntry* entries;
|
TTCluster* entries;
|
||||||
uint8_t generation;
|
uint8_t generation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern TranspositionTable TT;
|
||||||
|
|
||||||
#endif // !defined(TT_H_INCLUDED)
|
#endif // !defined(TT_H_INCLUDED)
|
||||||
|
|||||||
+35
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,9 +31,9 @@ typedef __int8 int8_t;
|
|||||||
typedef unsigned __int8 uint8_t;
|
typedef unsigned __int8 uint8_t;
|
||||||
typedef __int16 int16;
|
typedef __int16 int16;
|
||||||
typedef unsigned __int16 uint16_t;
|
typedef unsigned __int16 uint16_t;
|
||||||
typedef __int32 int32;
|
typedef __int32 int32_t;
|
||||||
typedef unsigned __int32 uint32_t;
|
typedef unsigned __int32 uint32_t;
|
||||||
typedef __int64 int64;
|
typedef __int64 int64_t;
|
||||||
typedef unsigned __int64 uint64_t;
|
typedef unsigned __int64 uint64_t;
|
||||||
|
|
||||||
typedef __int16 int16_t;
|
typedef __int16 int16_t;
|
||||||
@@ -62,8 +62,39 @@ typedef uint64_t Bitboard;
|
|||||||
#define IS_64BIT
|
#define IS_64BIT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IS_64BIT) && !defined(_WIN64) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
|
#if defined(IS_64BIT) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
|
||||||
#define USE_BSFQ
|
#define USE_BSFQ
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Cache line alignment specification
|
||||||
|
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||||
|
#define CACHE_LINE_ALIGNMENT __declspec(align(64))
|
||||||
|
#else
|
||||||
|
#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)
|
#endif // !defined(TYPES_H_INCLUDED)
|
||||||
|
|||||||
+50
-43
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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_option(UCIInputParser& uip);
|
||||||
void set_position(UCIInputParser& uip);
|
void set_position(UCIInputParser& uip);
|
||||||
bool go(UCIInputParser& uip);
|
bool go(UCIInputParser& uip);
|
||||||
|
void perft(UCIInputParser& uip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,7 +107,8 @@ namespace {
|
|||||||
UCIInputParser uip(command);
|
UCIInputParser uip(command);
|
||||||
string token;
|
string token;
|
||||||
|
|
||||||
uip >> token; // operator>>() skips any whitespace
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
|
return true;
|
||||||
|
|
||||||
if (token == "quit")
|
if (token == "quit")
|
||||||
return false;
|
return false;
|
||||||
@@ -123,7 +125,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
else if (token == "ucinewgame")
|
else if (token == "ucinewgame")
|
||||||
{
|
{
|
||||||
push_button("Clear Hash");
|
push_button("New Game");
|
||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
}
|
}
|
||||||
@@ -147,23 +149,19 @@ namespace {
|
|||||||
else if (token == "eval")
|
else if (token == "eval")
|
||||||
{
|
{
|
||||||
EvalInfo ei;
|
EvalInfo ei;
|
||||||
cout << "Incremental mg: " << RootPosition.mg_value()
|
cout << "Incremental mg: " << mg_value(RootPosition.value())
|
||||||
<< "\nIncremental eg: " << RootPosition.eg_value()
|
<< "\nIncremental eg: " << eg_value(RootPosition.value())
|
||||||
<< "\nFull eval: " << evaluate(RootPosition, ei, 0) << endl;
|
<< "\nFull eval: " << evaluate(RootPosition, ei, 0) << endl;
|
||||||
}
|
}
|
||||||
else if (token == "key")
|
else if (token == "key")
|
||||||
cout << "key: " << hex << RootPosition.get_key()
|
cout << "key: " << hex << RootPosition.get_key()
|
||||||
<< "\nmaterial key: " << RootPosition.get_material_key()
|
<< "\nmaterial key: " << RootPosition.get_material_key()
|
||||||
<< "\npawn key: " << RootPosition.get_pawn_key() << endl;
|
<< "\npawn key: " << RootPosition.get_pawn_key() << endl;
|
||||||
|
else if (token == "perft")
|
||||||
|
perft(uip);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
cout << "Unknown command: " << command << endl;
|
cout << "Unknown command: " << command << endl;
|
||||||
while (!uip.eof())
|
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
cout << token << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,33 +176,33 @@ namespace {
|
|||||||
|
|
||||||
string token;
|
string token;
|
||||||
|
|
||||||
uip >> token; // operator>>() skips any whitespace
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
|
return;
|
||||||
|
|
||||||
if (token == "startpos")
|
if (token == "startpos")
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
else if (token == "fen")
|
else if (token == "fen")
|
||||||
{
|
{
|
||||||
string fen;
|
string fen;
|
||||||
while (token != "moves" && !uip.eof())
|
while (uip >> token && token != "moves")
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
fen += token;
|
fen += token;
|
||||||
fen += ' ';
|
fen += ' ';
|
||||||
}
|
}
|
||||||
RootPosition.from_fen(fen);
|
RootPosition.from_fen(fen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uip.eof())
|
if (uip.good())
|
||||||
{
|
{
|
||||||
if (token != "moves")
|
if (token != "moves")
|
||||||
uip >> token;
|
uip >> token;
|
||||||
|
|
||||||
if (token == "moves")
|
if (token == "moves")
|
||||||
{
|
{
|
||||||
Move move;
|
Move move;
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
move = move_from_string(RootPosition, token);
|
move = move_from_string(RootPosition, token);
|
||||||
RootPosition.do_move(move, st);
|
RootPosition.do_move(move, st);
|
||||||
if (RootPosition.rule_50_counter() == 0)
|
if (RootPosition.rule_50_counter() == 0)
|
||||||
@@ -212,7 +210,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
// Our StateInfo st is about going out of scope so copy
|
// Our StateInfo st is about going out of scope so copy
|
||||||
// its content inside RootPosition before they disappear.
|
// its content inside RootPosition before they disappear.
|
||||||
RootPosition.saveState();
|
RootPosition.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,24 +224,22 @@ namespace {
|
|||||||
|
|
||||||
void set_option(UCIInputParser& uip) {
|
void set_option(UCIInputParser& uip) {
|
||||||
|
|
||||||
string token, name;
|
string token, name, value;
|
||||||
|
|
||||||
uip >> token;
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
if (token == "name")
|
return;
|
||||||
|
|
||||||
|
if (token == "name" && uip >> name)
|
||||||
{
|
{
|
||||||
uip >> name;
|
while (uip >> token && token != "value")
|
||||||
while (!uip.eof())
|
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
if (token == "value")
|
|
||||||
break;
|
|
||||||
|
|
||||||
name += (" " + token);
|
name += (" " + token);
|
||||||
}
|
|
||||||
if (token == "value")
|
if (token == "value" && uip >> value)
|
||||||
{
|
{
|
||||||
getline(uip, token); // reads until end of line
|
while (uip >> token)
|
||||||
set_option_value(name, token);
|
value += (" " + token);
|
||||||
|
|
||||||
|
set_option_value(name, value);
|
||||||
} else
|
} else
|
||||||
push_button(name);
|
push_button(name);
|
||||||
}
|
}
|
||||||
@@ -270,10 +266,8 @@ namespace {
|
|||||||
|
|
||||||
searchMoves[0] = MOVE_NONE;
|
searchMoves[0] = MOVE_NONE;
|
||||||
|
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
|
|
||||||
if (token == "infinite")
|
if (token == "infinite")
|
||||||
infinite = true;
|
infinite = true;
|
||||||
else if (token == "ponder")
|
else if (token == "ponder")
|
||||||
@@ -297,22 +291,35 @@ namespace {
|
|||||||
else if (token == "searchmoves")
|
else if (token == "searchmoves")
|
||||||
{
|
{
|
||||||
int numOfMoves = 0;
|
int numOfMoves = 0;
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
||||||
}
|
|
||||||
searchMoves[numOfMoves] = MOVE_NONE;
|
searchMoves[numOfMoves] = MOVE_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moveTime)
|
|
||||||
infinite = true; // HACK
|
|
||||||
|
|
||||||
assert(RootPosition.is_ok());
|
assert(RootPosition.is_ok());
|
||||||
|
|
||||||
return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
|
return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
|
||||||
time, inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+52
-46
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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["Space"] = Option(100, 0, 200);
|
||||||
o["Aggressiveness"] = Option(100, 0, 200);
|
o["Aggressiveness"] = Option(100, 0, 200);
|
||||||
o["Cowardice"] = 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 (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
o["Single Reply Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Single Evasion Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Single Reply Extension (non-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 (PV nodes)"] = Option(0, 0, 2);
|
||||||
o["Mate Threat Extension (non-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);
|
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
@@ -116,23 +100,21 @@ namespace {
|
|||||||
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
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 (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Full Depth Moves (PV nodes)"] = Option(14, 1, 100);
|
|
||||||
o["Full Depth Moves (non-PV nodes)"] = Option(3, 1, 100);
|
|
||||||
o["Threat Depth"] = Option(5, 0, 100);
|
|
||||||
o["LSN filtering"] = Option(false);
|
|
||||||
o["LSN Time Margin (sec)"] = Option(4, 1, 10);
|
|
||||||
o["LSN Value Margin"] = Option(200, 100, 600);
|
|
||||||
o["Randomness"] = Option(0, 0, 10);
|
o["Randomness"] = Option(0, 0, 10);
|
||||||
o["Minimum Split Depth"] = Option(4, 4, 7);
|
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||||
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
||||||
o["Threads"] = Option(1, 1, 8);
|
o["Threads"] = Option(1, 1, MAX_THREADS);
|
||||||
o["Hash"] = Option(32, 4, 4096);
|
o["Hash"] = Option(32, 4, 8192);
|
||||||
o["Clear Hash"] = Option(false, BUTTON);
|
o["Clear Hash"] = Option(false, BUTTON);
|
||||||
|
o["New Game"] = Option(false, BUTTON);
|
||||||
o["Ponder"] = Option(true);
|
o["Ponder"] = Option(true);
|
||||||
o["OwnBook"] = Option(true);
|
o["OwnBook"] = Option(true);
|
||||||
o["MultiPV"] = Option(1, 1, 500);
|
o["MultiPV"] = Option(1, 1, 500);
|
||||||
o["UCI_ShowCurrLine"] = Option(false);
|
|
||||||
o["UCI_Chess960"] = Option(false);
|
o["UCI_Chess960"] = Option(false);
|
||||||
|
o["UCI_AnalyseMode"] = Option(false);
|
||||||
|
|
||||||
|
// Temporary hack for 1.7.1 to be removed in next release
|
||||||
|
o["Zugzwang detection"] = Option(false);
|
||||||
|
|
||||||
// Any option should know its name so to be easily printed
|
// Any option should know its name so to be easily printed
|
||||||
for (Options::iterator it = o.begin(); it != o.end(); ++it)
|
for (Options::iterator it = o.begin(); it != o.end(); ++it)
|
||||||
@@ -171,6 +153,18 @@ namespace {
|
|||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -185,24 +179,18 @@ void init_uci_options() {
|
|||||||
|
|
||||||
load_defaults(options);
|
load_defaults(options);
|
||||||
|
|
||||||
// Limit the default value of "Threads" to 7 even if we have 8 CPU cores.
|
// Set optimal value for parameter "Minimum Split Depth"
|
||||||
// According to Ken Dail's tests, Glaurung plays much better with 7 than
|
// according to number of available cores.
|
||||||
// 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.
|
|
||||||
assert(options.find("Threads") != options.end());
|
assert(options.find("Threads") != options.end());
|
||||||
assert(options.find("Minimum Split Depth") != options.end());
|
assert(options.find("Minimum Split Depth") != options.end());
|
||||||
|
|
||||||
options["Threads"].defaultValue = stringify(Min(cpu_count(), 7));
|
Option& thr = options["Threads"];
|
||||||
options["Threads"].currentValue = stringify(Min(cpu_count(), 7));
|
Option& msd = options["Minimum Split Depth"];
|
||||||
|
|
||||||
// Increase the minimum split depth when the number of CPUs is big.
|
thr.defaultValue = thr.currentValue = stringify(cpu_count());
|
||||||
// It would probably be better to let this depend on the number of threads
|
|
||||||
// instead.
|
if (cpu_count() >= 8)
|
||||||
if (cpu_count() > 4)
|
msd.defaultValue = msd.currentValue = stringify(7);
|
||||||
{
|
|
||||||
options["Minimum Split Depth"].defaultValue = "6";
|
|
||||||
options["Minimum Split Depth"].currentValue = "6";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -290,10 +278,28 @@ void set_option_value(const string& name, const string& value) {
|
|||||||
else if (v == "false")
|
else if (v == "false")
|
||||||
v = "0";
|
v = "0";
|
||||||
|
|
||||||
if (options.find(name) != options.end())
|
if (options.find(name) == options.end())
|
||||||
options[name].currentValue = v;
|
{
|
||||||
else
|
|
||||||
std::cout << "No such option: " << name << std::endl;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -313,7 +319,7 @@ void push_button(const string& buttonName) {
|
|||||||
bool button_was_pressed(const string& buttonName) {
|
bool button_was_pressed(const string& buttonName) {
|
||||||
|
|
||||||
if (!get_option_value<bool>(buttonName))
|
if (!get_option_value<bool>(buttonName))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
set_option_value(buttonName, "false");
|
set_option_value(buttonName, "false");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+49
-6
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
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
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,11 +33,16 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
enum ValueType {
|
enum ValueType {
|
||||||
VALUE_TYPE_NONE = 0,
|
VALUE_TYPE_NONE = 0,
|
||||||
VALUE_TYPE_UPPER = 1, // Upper bound
|
VALUE_TYPE_UPPER = 1, // Upper bound
|
||||||
VALUE_TYPE_LOWER = 2, // Lower bound
|
VALUE_TYPE_LOWER = 2, // Lower bound
|
||||||
VALUE_TYPE_EXACT = 3, // Exact score
|
VALUE_TYPE_EXACT = 3, // Exact score
|
||||||
VALUE_TYPE_EVAL = 4 // Evaluation cache
|
VALUE_TYPE_EVAL = 4, // Static evaluation value
|
||||||
|
VALUE_TYPE_NULL = 8, // Null search value
|
||||||
|
|
||||||
|
VALUE_TYPE_EV_UP = VALUE_TYPE_EVAL | VALUE_TYPE_UPPER,
|
||||||
|
VALUE_TYPE_EV_LO = VALUE_TYPE_EVAL | VALUE_TYPE_LOWER,
|
||||||
|
VALUE_TYPE_NS_LO = VALUE_TYPE_NULL | VALUE_TYPE_LOWER,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -46,10 +51,49 @@ enum Value {
|
|||||||
VALUE_KNOWN_WIN = 15000,
|
VALUE_KNOWN_WIN = 15000,
|
||||||
VALUE_MATE = 30000,
|
VALUE_MATE = 30000,
|
||||||
VALUE_INFINITE = 30001,
|
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
|
//// Constants and variables
|
||||||
////
|
////
|
||||||
@@ -95,8 +139,7 @@ const Value PieceValueEndgame[17] = {
|
|||||||
|
|
||||||
/// Bonus for having the side to move (modified by Joona Kiiski)
|
/// Bonus for having the side to move (modified by Joona Kiiski)
|
||||||
|
|
||||||
const Value TempoValueMidgame = Value(48);
|
const Score TempoValue = make_score(48, 22);
|
||||||
const Value TempoValueEndgame = Value(21);
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|||||||
Reference in New Issue
Block a user