mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 12:07:43 +00:00
Compare commits
584 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c3483fa9a7 | |||
| 446a3c2522 | |||
| baf184e8d9 | |||
| 7150183d07 | |||
| 4901218d4c | |||
| 01dfdb95dc | |||
| 69204f0720 | |||
| 9f800a2577 | |||
| 114ddb789b | |||
| 7f623206f4 | |||
| 384bff4264 | |||
| bae019b53e | |||
| 09bef14c76 | |||
| 44f79bdf5a | |||
| de4e1cb88d | |||
| 56d5504f65 | |||
| 83ecfa7c33 | |||
| 44f56e04e2 | |||
| 13f70d0392 | |||
| b6482472a0 | |||
| 443787b0d1 | |||
| 3ef0c3c34a | |||
| 764b9adda6 | |||
| d00b2ec6bd | |||
| 78eeba29a2 | |||
| a6b5ba1b64 | |||
| 20484ccdd5 | |||
| 0256416bb7 | |||
| 6a6fc28551 | |||
| 97a0e4e817 | |||
| f0047ce08e | |||
| 54253bcce6 | |||
| df340a839c | |||
| 53125902e4 | |||
| 87ed9facf1 | |||
| 1fdf1f1ff5 | |||
| 3f4191392c | |||
| 37698b0396 | |||
| e0f42aa956 | |||
| fe124896b2 | |||
| 3468138210 | |||
| a00a336946 | |||
| a131975170 | |||
| 9ab2590963 | |||
| 44b6697f19 | |||
| 9b8b259388 | |||
| 5ae195ee7e | |||
| 9f312c80d9 | |||
| 3804effb34 | |||
| ef38046e73 | |||
| cff9a8672c | |||
| 474d133565 | |||
| e8fca71342 | |||
| 6f3796adaf | |||
| 1725ed39ad | |||
| 648c7ec25d | |||
| 90c0385724 | |||
| 7e89a71624 | |||
| 215cd19108 | |||
| 12d58adc68 | |||
| 472de897cb | |||
| b8e5092d07 | |||
| 80d59eea39 | |||
| 23a022980b | |||
| 0150da5c2b | |||
| 0b0b21c608 | |||
| 7264540107 | |||
| c78f8ddd86 | |||
| 2e96c513ad | |||
| ca7d4e9ac7 | |||
| 328bdd0947 | |||
| 5d1568632c | |||
| e6f4b5f463 | |||
| 005ad170c1 | |||
| abd4400c87 | |||
| 70a38d7264 | |||
| 3a3ca6af03 | |||
| 28dcd700a9 | |||
| d703d2b5e7 | |||
| 8726beba59 | |||
| 0436f01d05 | |||
| 667d24f227 | |||
| d232a4ae68 | |||
| defa1ccaa9 | |||
| 302e0f70c6 | |||
| 7756344d5d | |||
| 770c8d92f3 | |||
| 7e4c3256aa | |||
| 64af5434ed | |||
| a858defd33 | |||
| 7b06475294 | |||
| 843a6c4305 | |||
| e5cfa14f40 | |||
| a83d1a0e80 | |||
| 8a04b3a13c | |||
| db00e1625e | |||
| 8aecf26981 | |||
| 36e4a86c08 | |||
| 270b241ec1 | |||
| 61f44ce578 | |||
| 8fec883471 | |||
| 0e295fee25 | |||
| d799529b48 | |||
| 3984b8f8f0 | |||
| a016626825 | |||
| 10d2ebc6ae | |||
| 18279b24fc | |||
| d4dca9187e | |||
| 7efc39d683 | |||
| 66a3c2968b | |||
| fcee0ce6a3 | |||
| 8152a74ab4 | |||
| d980d7c0d4 | |||
| 9d3a2ecaa2 | |||
| aec918a2b6 | |||
| acdda38b93 | |||
| 33c3a04653 | |||
| dc243a3c88 | |||
| 9dc57b660e | |||
| fd96cba676 | |||
| 19509e5f13 | |||
| 3ec362e4b2 | |||
| 7090d2561a | |||
| 0dbc72d82e | |||
| 650aeaf242 | |||
| 13ba67801f | |||
| 0a8a3b8d9c | |||
| a0360cc2d4 | |||
| ff69d570d7 | |||
| 389e60741f | |||
| 82d66f6b72 | |||
| 4ae5a7b45a | |||
| c83cbe42f3 | |||
| 5a7827d59d | |||
| 93349d0dbd | |||
| fa1a2a0667 | |||
| ca51d1ee63 | |||
| 217840a6a5 | |||
| 79d06d8840 | |||
| c9d73d1aa5 | |||
| d889bb4718 | |||
| dab66631e8 | |||
| 8b4521df83 | |||
| a8de07cc26 | |||
| 4c986b0501 | |||
| 7cb8817ef2 | |||
| 37ffacf209 | |||
| 8bf21a723e | |||
| 297c40291a | |||
| 59f1d0c7dd | |||
| 466daf6fba | |||
| 46ce245763 | |||
| 8cfe27b765 | |||
| f9518de974 | |||
| a9cca5c953 | |||
| d39bc2efa1 | |||
| 2ead74d1e2 | |||
| 53d197b841 | |||
| 14e23d520f | |||
| 5935daf8a5 | |||
| 6ed81f09ff | |||
| 2d06d659c0 | |||
| 09caea5cab | |||
| 434b2c72a4 | |||
| 3edf0e6b37 | |||
| c645587270 | |||
| 190f38a7c2 | |||
| bf6b647a1a | |||
| 2985a6b5d7 | |||
| 272936eaba | |||
| 3d076a0c50 | |||
| 3a572ffb48 | |||
| 02708a4a11 | |||
| 4a7b8180ec | |||
| 44c320a572 | |||
| 4fcd78bd06 | |||
| 2d9fac1e13 | |||
| 66820a2668 | |||
| 9c7dc057d1 | |||
| a8abba0b4d | |||
| 5f4d44fda0 | |||
| 893a08a8c2 | |||
| 7df832fea6 | |||
| 8a0af1004a | |||
| ad8b78ad52 | |||
| 368f976fb6 | |||
| b6d11028bb | |||
| aba906b734 | |||
| 4e72e2a964 | |||
| 5c4002aa82 | |||
| 7ede1ed071 | |||
| e4c1f8759d | |||
| 9a11a29194 | |||
| e89bc30fdc | |||
| 6373fd56e9 | |||
| a858b5a84e | |||
| bdeb01dec0 | |||
| f21b503982 | |||
| c4fc00ec49 | |||
| 3b46df546d | |||
| 76777b663a | |||
| eb07775583 | |||
| 1594d15922 | |||
| 42d271f23c | |||
| a2cdb6e5d2 | |||
| 5928cb2b30 | |||
| 5b5687d76e | |||
| ec49e676a7 | |||
| ab4b94e173 | |||
| f98c77413b | |||
| 8fa6273ff6 | |||
| 49a1fdd3fe | |||
| fdd799bc16 | |||
| 1982fe25f8 | |||
| 0f63b35120 | |||
| aa0166fba6 | |||
| 82ad9ce9cf | |||
| 95ba7f78d5 | |||
| 76f1807baa | |||
| c858990377 | |||
| d1f76ebcd8 | |||
| 796d0ad70e | |||
| 7133598a98 | |||
| 2f11c03bbf | |||
| ea5505821d | |||
| d320de7619 | |||
| 66818f2e85 | |||
| bad18bccb6 | |||
| b8efa0daac | |||
| acc47e8b79 | |||
| 4d0981fef3 | |||
| 1aab5b4b05 | |||
| 714e857c24 | |||
| 58bbbd176b | |||
| 2bceba7f51 | |||
| c2fb0ff720 | |||
| 82ff04b992 | |||
| 7c5f5fbada | |||
| badb2aca44 | |||
| e51244cb27 | |||
| 22ef36803e | |||
| 76d2f5b94a | |||
| 3c92f849ab | |||
| 05f7d59a9a | |||
| 332b90455b | |||
| dd4796fcd5 | |||
| 6514500236 | |||
| 9050eac595 | |||
| ff97a9fdb9 | |||
| 3f7ec977cd | |||
| d1fd1a96bc | |||
| 3302349662 | |||
| 242c566c1a | |||
| 8df1cd10df | |||
| 2d0af36753 | |||
| 58d3ee6175 | |||
| 59b2486bc3 | |||
| 691a287bfe | |||
| 3acacf8471 | |||
| 3300517ecb | |||
| 3732c55c18 | |||
| 230fb6e9ad | |||
| 5446e6f408 | |||
| d07e782e22 | |||
| d2acdac101 | |||
| 70880b8e24 | |||
| f69106f7bb | |||
| bb843a00c1 | |||
| 3c576efa77 | |||
| eb6d7f537d | |||
| 79c97625a4 | |||
| 7accf07c0b | |||
| e2d3c163cb | |||
| 800031c94c | |||
| 69dc5568b3 | |||
| 14c4a40dc7 | |||
| 0194da0d80 | |||
| ade87ff8d3 | |||
| 96ac85b319 | |||
| 2089c414da | |||
| 656aad8b0c | |||
| ae5d2c38e1 | |||
| 59d32f8edd | |||
| b54bcfddaa | |||
| 0f2df4e4af | |||
| 67ae53b020 | |||
| 7240a90bf9 | |||
| 64a6138d37 | |||
| 4e2bb8fa44 | |||
| fda0161e3a | |||
| 4f3804f3f3 | |||
| 31ac538f96 | |||
| 883367d217 | |||
| e917bd59b1 | |||
| e8ffca3eb4 | |||
| 4e2e4759a1 | |||
| a8e903c33a | |||
| 090e49547e | |||
| fefc0c6789 | |||
| 5c2fbcd09b | |||
| 7b4f9c37cb | |||
| b19ad4977c | |||
| 33d9548218 | |||
| 9dc6d270fc | |||
| 982fd9c8bc | |||
| 79e3710fd2 | |||
| 9b276a6596 | |||
| b4c239b625 | |||
| 622360ad66 | |||
| 340e9ea509 | |||
| 7b6fa353a3 | |||
| de7182f4ee | |||
| 6ab92d2e1c | |||
| bb58bc215c | |||
| 6e66e7aae2 | |||
| 4b88bea4fc | |||
| 3925750945 | |||
| cf5d683408 | |||
| 3f2ec5b3d5 | |||
| b92206305f | |||
| d2274e609c | |||
| 4111f36f45 | |||
| 0e508f30bb | |||
| 4350a66ffa | |||
| 8a9c298dee | |||
| 2a7213f720 | |||
| b9f1c9bf3f | |||
| 3cbb05b1b8 | |||
| 68209c9121 | |||
| 30a905c95d | |||
| 05aa34e00e | |||
| cd732c080b | |||
| df50ea5dc6 | |||
| 9315ba60e6 | |||
| a6fe035977 | |||
| 8bb7a73708 | |||
| 3f1eb85a1c | |||
| 4a0db9ea3c | |||
| 7a61368971 | |||
| 081af90805 | |||
| bc3b148d57 | |||
| 9fff272209 | |||
| 542a2b39ed | |||
| 738a6dfd4c | |||
| 97d2cc9a9c | |||
| cb0111d3db | |||
| 0370077c37 | |||
| d615f15fce | |||
| 489357d7b2 | |||
| 8141bdd179 | |||
| bbf9daa175 | |||
| 13d06edb84 | |||
| 49b1591505 | |||
| 33b2f6398c | |||
| 0fa957cf66 | |||
| 4bef7aa5cd | |||
| 767c4ad1fc | |||
| 2bfaf45455 | |||
| f923dc0fe5 | |||
| e846a9306d | |||
| 10bb2e6cdb | |||
| 166bf90e41 | |||
| 4aa091cf44 | |||
| 8a4821923a | |||
| 6307fd08e6 | |||
| 3ac3b68540 | |||
| 28543cddc6 | |||
| f3b8a69919 | |||
| 96c3a1f2ec | |||
| d0f09de2d2 | |||
| 881cab2525 | |||
| 4d22d3e52d | |||
| 41cc4eb953 | |||
| b5581b7779 | |||
| 348cd5ed74 | |||
| f1088c9822 | |||
| 198418ee67 | |||
| bd4d2b0576 | |||
| c569cf263d | |||
| d96c1c32a2 | |||
| 571f54b176 | |||
| fae57273b2 | |||
| 9afa03b80e | |||
| ba2a2c34bb | |||
| c08e05b494 | |||
| 6184d2b2ac | |||
| 9ca014df49 | |||
| e12fc10b5c | |||
| 313f403733 | |||
| c9f80660a6 | |||
| d44701be4b | |||
| 2660a9145e | |||
| a4eda3056e | |||
| ae98927885 | |||
| c4c2e08f0d | |||
| 6e36860554 | |||
| bb56779cb6 | |||
| 38471697b7 | |||
| 50287a55d3 | |||
| 0d5fe2f156 | |||
| af1ddfd83b | |||
| 4bd24da161 | |||
| 53c07c34bb | |||
| 0365b08601 | |||
| 41bc0d5660 | |||
| 12e79be910 | |||
| 3913726d1c | |||
| 2ac35027d5 | |||
| a05793517f | |||
| ee0f5cd303 | |||
| e0f317afaa | |||
| a6fa6a9e92 | |||
| d2d4e85f25 | |||
| d2752fdc15 | |||
| 0f48095759 | |||
| 3279655f12 | |||
| e7cfa5d020 | |||
| 8c4f0ffa1d | |||
| a781535168 | |||
| af6072c8b7 | |||
| 1e9397a2df | |||
| f0a7bed6fb | |||
| efd4ca27c4 | |||
| 34321fcc2d | |||
| 062eb074c8 | |||
| 06a853eb9c | |||
| 745160572f | |||
| 9d219c07e4 | |||
| a834bfe833 | |||
| 6c36e65193 | |||
| fc3af7c4fb | |||
| 88de112b84 | |||
| 86e467520f | |||
| 2af2c67650 | |||
| 528507b303 | |||
| 231103d2cf | |||
| e4f8a4fa7f | |||
| 9597ad8cab | |||
| b939788f9d | |||
| 6b5d671cdc | |||
| f7bae2de82 | |||
| 8ef9bc5a95 | |||
| c5d6ae8c96 | |||
| a0486ecb40 | |||
| 6cc5614124 | |||
| 31b8243272 | |||
| 626d43a329 | |||
| 3d6995eae8 | |||
| d5d23bfd2d | |||
| beaadd6547 | |||
| d702203113 | |||
| 04407e35d6 | |||
| 335dc2d021 | |||
| fd4585ef07 | |||
| e8005ebe56 | |||
| 91a76331ca | |||
| aacee91a5a | |||
| bf01bd0755 | |||
| c163c2fcb0 | |||
| 255df4ffae | |||
| 76d4a80084 | |||
| fc0a1f37cf | |||
| 4d647428d8 | |||
| de0889612f | |||
| 6634f41ac9 | |||
| 8d1625d6df | |||
| 155d5417d9 | |||
| cb4bda0f49 | |||
| d4cb80b210 | |||
| 06e0134cbc | |||
| 12ef8f71a2 | |||
| 5a7cdadfb3 | |||
| 213166ba22 | |||
| d6252ef202 | |||
| 3df8cabb84 | |||
| 11967e89cd | |||
| 45072612d4 | |||
| c794c8c801 | |||
| aef7076c34 | |||
| a64d524d02 | |||
| 82f7d507ea | |||
| f7cc0026e3 | |||
| 73e8daa150 | |||
| 66af80972a | |||
| 0143c6f0c2 | |||
| 108f0da4d7 | |||
| e9aeaad052 | |||
| ae0bb6dc2b | |||
| 6413d9b1f9 | |||
| 62619fa228 | |||
| b88374b14a | |||
| 759d129e47 | |||
| 04a228f9c8 | |||
| 06a8fd2154 | |||
| 0cfb653eec | |||
| e408fd7b10 | |||
| 76f9cd4df1 | |||
| d9cac9a414 | |||
| f2681232e5 | |||
| d5e3e7d207 | |||
| c8ef80f466 | |||
| c959871a59 | |||
| 9953bfff62 | |||
| 5ce630584c | |||
| 29070bd01a | |||
| 367304e930 | |||
| 8ff2fcf299 | |||
| 280022baf7 | |||
| a03e98dcd3 | |||
| f0f6da2d30 | |||
| 62937d1007 | |||
| d40e7ee209 | |||
| ed26d71354 | |||
| bd59560480 | |||
| 1940485030 | |||
| 759b3c79cf | |||
| 350dff4464 | |||
| 96362fe3df | |||
| 8ab12c9012 | |||
| 8db75dd9ec | |||
| edf4c07d25 | |||
| b605103a34 | |||
| c5f6bd517c | |||
| b2961aded6 | |||
| efe702e9f5 | |||
| 840605c14e | |||
| 6e9337b107 | |||
| c3af52c43b | |||
| 5dc381a566 | |||
| 2c5dfb3122 | |||
| 1093047e7d | |||
| 82697f1193 | |||
| 65c3bb8586 | |||
| 6d8f583af2 | |||
| 56a104e2e0 | |||
| d42e6338ea | |||
| 43682d08f7 | |||
| 3192b09fe0 | |||
| 450f04969c | |||
| cad300cfab | |||
| b87308692a | |||
| f35e52f030 | |||
| 94b3cdd908 | |||
| 94abc2a0cf | |||
| 59d10374ca | |||
| ad5d86c771 | |||
| de642f16db | |||
| cccbecb6f8 | |||
| 1463881153 | |||
| 29bc128384 | |||
| ad2a0e356e | |||
| d438720a1c | |||
| 71cc01c2ef | |||
| 7a03450bd9 | |||
| ebb3e7df65 | |||
| 2ec36f8ae8 | |||
| 2e21aba8d9 | |||
| 8dd6875240 | |||
| 16b31bb249 | |||
| 5d57bb467a | |||
| 9246e4a6f9 | |||
| a09eee5798 | |||
| 52f92d05a9 | |||
| 820c5c25b6 | |||
| 6c898a10be | |||
| 67f5f54a29 | |||
| b2b0013d11 | |||
| 80ea80e451 | |||
| 860223c5e6 | |||
| 4c57cf0ead | |||
| baab8be324 | |||
| cb1324312d | |||
| d71adc5bd9 | |||
| 211ebc5c7a | |||
| 917fe69f84 | |||
| 69067e1988 | |||
| 312a248fa9 | |||
| ef61886332 | |||
| 414a3e6ee3 | |||
| e316e432d0 | |||
| d93baae220 | |||
| 44a7db0f9a | |||
| 83c828f31e | |||
| 0f6f42cd83 |
+14
-14
@@ -1,6 +1,5 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
sudo: required
|
dist: xenial
|
||||||
dist: trusty
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
@@ -9,20 +8,21 @@ matrix:
|
|||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
packages: ['g++-6', 'g++-6-multilib', 'g++-multilib', 'valgrind', 'expect']
|
packages: ['g++-8', 'g++-8-multilib', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
||||||
env:
|
env:
|
||||||
- COMPILER=g++-6
|
- COMPILER=g++-8
|
||||||
- COMP=gcc
|
- COMP=gcc
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-6.0']
|
||||||
packages: ['clang', 'g++-multilib', 'valgrind', 'expect']
|
packages: ['clang-6.0', 'llvm-6.0-dev', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
||||||
env:
|
env:
|
||||||
- COMPILER=clang++
|
- COMPILER=clang++-6.0
|
||||||
- COMP=clang
|
- COMP=clang
|
||||||
|
- LDFLAGS=-fuse-ld=lld
|
||||||
|
|
||||||
- os: osx
|
- os: osx
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
@@ -33,7 +33,7 @@ matrix:
|
|||||||
- os: osx
|
- os: osx
|
||||||
compiler: clang
|
compiler: clang
|
||||||
env:
|
env:
|
||||||
- COMPILER=clang++ V='Apple LLVM 6.0' # Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
|
- COMPILER=clang++ V='Apple LLVM 9.4.1' # Apple LLVM version 9.1.0 (clang-902.0.39.2)
|
||||||
- COMP=clang
|
- COMP=clang
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
@@ -45,7 +45,7 @@ before_script:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
# Obtain bench reference from git log
|
# Obtain bench reference from git log
|
||||||
- git log HEAD | grep "\b[Bb]ench[ :]\+[0-9]\{7\}" | head -n 1 | sed "s/[^0-9]*\([0-9][0-9]*\)/\1/g" > git_sig
|
- git log HEAD | grep "\b[Bb]ench[ :]\+[0-9]\{7\}" | head -n 1 | sed "s/[^0-9]*\([0-9]*\).*/\1/g" > git_sig
|
||||||
- export benchref=$(cat git_sig)
|
- export benchref=$(cat git_sig)
|
||||||
- echo "Reference bench:" $benchref
|
- echo "Reference bench:" $benchref
|
||||||
#
|
#
|
||||||
@@ -54,7 +54,7 @@ script:
|
|||||||
- make clean && make -j2 ARCH=x86-64 optimize=no debug=yes build && ../tests/signature.sh $benchref
|
- make clean && make -j2 ARCH=x86-64 optimize=no debug=yes build && ../tests/signature.sh $benchref
|
||||||
- make clean && make -j2 ARCH=x86-32 optimize=no debug=yes build && ../tests/signature.sh $benchref
|
- make clean && make -j2 ARCH=x86-32 optimize=no debug=yes build && ../tests/signature.sh $benchref
|
||||||
- make clean && make -j2 ARCH=x86-32 build && ../tests/signature.sh $benchref
|
- make clean && make -j2 ARCH=x86-32 build && ../tests/signature.sh $benchref
|
||||||
- make clean && make -j2 ARCH=x86-64 build && ../tests/signature.sh $benchref
|
|
||||||
#
|
#
|
||||||
# Check perft and reproducible search
|
# Check perft and reproducible search
|
||||||
- ../tests/perft.sh
|
- ../tests/perft.sh
|
||||||
@@ -62,12 +62,12 @@ script:
|
|||||||
#
|
#
|
||||||
# Valgrind
|
# Valgrind
|
||||||
#
|
#
|
||||||
- export CXXFLAGS=-O1
|
- export CXXFLAGS="-O1 -fno-inline"
|
||||||
- if [ -x "$(command -v valgrind )" ]; then make clean && make -j2 ARCH=x86-64 debug=yes optimize=no build > /dev/null && ../tests/instrumented.sh --valgrind; fi
|
- if [ -x "$(command -v valgrind )" ]; then make clean && make -j2 ARCH=x86-64 debug=yes optimize=no build > /dev/null && ../tests/instrumented.sh --valgrind; fi
|
||||||
- if [ -x "$(command -v valgrind )" ]; then ../tests/instrumented.sh --valgrind-thread; fi
|
- if [ -x "$(command -v valgrind )" ]; then ../tests/instrumented.sh --valgrind-thread; fi
|
||||||
#
|
#
|
||||||
# Sanitizer
|
# Sanitizer
|
||||||
#
|
#
|
||||||
# Use g++-6 as a proxy for having sanitizers, might need revision as they become available for more recent versions of clang/gcc
|
# Use g++-8 as a proxy for having sanitizers, might need revision as they become available for more recent versions of clang/gcc
|
||||||
- if [[ "$COMPILER" == "g++-6" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-undefined; fi
|
- if [[ "$COMPILER" == "g++-8" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-undefined; fi
|
||||||
- if [[ "$COMPILER" == "g++-6" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi
|
- if [[ "$COMPILER" == "g++-8" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi
|
||||||
|
|||||||
@@ -1,98 +1,163 @@
|
|||||||
# Generated with 'git shortlog -sn | cut -c8-', which sorts by commits, manually ordered the first four authors, merged duplicates
|
# List of authors for Stockfish, as of January 7, 2020
|
||||||
|
|
||||||
Tord Romstad
|
Tord Romstad (romstad)
|
||||||
Marco Costalba (mcostalba)
|
Marco Costalba (mcostalba)
|
||||||
Joona Kiiski (zamar)
|
Joona Kiiski (zamar)
|
||||||
Gary Linscott (glinscott)
|
Gary Linscott (glinscott)
|
||||||
Lucas Braesch (lucasart)
|
|
||||||
Bill Henry (VoyagerOne)
|
Aditya (absimaldata)
|
||||||
mstembera
|
Adrian Petrescu (apetresc)
|
||||||
Stéphane Nicolet (Stephane Nicolet, snicolet)
|
Ajith Chandy Jose (ajithcj)
|
||||||
Stefan Geschwentner
|
Alain Savard (Rocky640)
|
||||||
Alain SAVARD (Rocky640)
|
Alayan Feh (Alayan-stk-2)
|
||||||
Jörg Oster (Joerg Oster, joergoster)
|
|
||||||
Reuven Peleg
|
|
||||||
Chris Caino (Chris Cain, ceebo)
|
|
||||||
Jean-Francois Romang
|
|
||||||
homoSapiensSapiens
|
|
||||||
Leonid Pechenik
|
|
||||||
Stefano Cardanobile (Stefano80)
|
|
||||||
Arjun Temurnikar
|
|
||||||
Uri Blass (uriblass)
|
|
||||||
jundery
|
|
||||||
Ajith (ajithcj)
|
|
||||||
hxim
|
|
||||||
Ralph Stößer (Ralph Stoesser)
|
|
||||||
Guenther Demetz
|
|
||||||
Jonathan Calovski (Mysseno)
|
|
||||||
Tom Vijlbrief
|
|
||||||
mbootsector
|
|
||||||
Daylen Yang
|
|
||||||
ElbertoOne
|
|
||||||
Henri Wiechers
|
|
||||||
loco-loco
|
|
||||||
Joost VandeVondele (Joost Vandevondele)
|
|
||||||
Ronald de Man (syzygy)
|
|
||||||
DU-jdto
|
|
||||||
David Zar
|
|
||||||
Eelco de Groot
|
|
||||||
Jerry Donald
|
|
||||||
NicklasPersson
|
|
||||||
Ryan Schmitt
|
|
||||||
Alexander Kure
|
Alexander Kure
|
||||||
Dan Schmidt
|
Alexander Pagel (Lolligerhans)
|
||||||
H. Felix Wittmann
|
Ali AlZhrani (Cooffe)
|
||||||
Jacques
|
Andrew Grant (AndyGrant)
|
||||||
Joseph R. Prostko
|
Andrey Neporada (nepal)
|
||||||
Justin Blanchard
|
|
||||||
Linus Arver
|
|
||||||
Luca Brivio
|
|
||||||
Lyudmil Antonov
|
|
||||||
Rodrigo Exterckötter Tjäder
|
|
||||||
Ron Britvich
|
|
||||||
RyanTaker
|
|
||||||
Vince Negri
|
|
||||||
erbsenzaehler
|
|
||||||
Joseph Hellis (jhellis3)
|
|
||||||
shane31
|
|
||||||
Andrew Grant
|
|
||||||
Andy Duplain
|
Andy Duplain
|
||||||
|
Aram Tumanian (atumanian)
|
||||||
|
Arjun Temurnikar
|
||||||
Auguste Pop
|
Auguste Pop
|
||||||
Balint Pfliegel
|
Balint Pfliegel
|
||||||
Dariusz Orzechowski
|
Ben Koshy (BKSpurgeon)
|
||||||
DiscanX
|
Bill Henry (VoyagerOne)
|
||||||
Ernesto Gatti
|
Bojun Guo (noobpwnftw, Nooby)
|
||||||
Gregor Cramer
|
|
||||||
Hiraoka Takuya (HiraokaTakuya)
|
|
||||||
Hongzhi Cheng
|
|
||||||
IIvec
|
|
||||||
Kelly Wilson
|
|
||||||
Ken T Takusagawa
|
|
||||||
Kojirion
|
|
||||||
Krgp
|
|
||||||
Matt Sullivan
|
|
||||||
Matthew Lai
|
|
||||||
Matthew Sullivan
|
|
||||||
Michel Van den Bergh
|
|
||||||
Niklas Fiekas
|
|
||||||
Oskar Werkelin Ahlin
|
|
||||||
Pablo Vazquez
|
|
||||||
Pascal Romaret
|
|
||||||
Raminder Singh
|
|
||||||
Richard Lloyd
|
|
||||||
Ryan Takker
|
|
||||||
Thanar2
|
|
||||||
absimaldata
|
|
||||||
atumanian
|
|
||||||
braich
|
braich
|
||||||
|
Brian Sheppard (SapphireBrand, briansheppard-toast)
|
||||||
|
Bryan Cross (crossbr)
|
||||||
|
candirufish
|
||||||
|
Chess13234
|
||||||
|
Chris Cain (ceebo)
|
||||||
|
Dan Schmidt (dfannius)
|
||||||
|
Daniel Axtens (daxtens)
|
||||||
|
Daniel Dugovic (ddugovic)
|
||||||
|
Dariusz Orzechowski
|
||||||
|
David Zar
|
||||||
|
Daylen Yang (daylen)
|
||||||
|
DiscanX
|
||||||
|
double-beep
|
||||||
|
Eduardo Cáceres (eduherminio)
|
||||||
|
Eelco de Groot (KingDefender)
|
||||||
|
Elvin Liu (solarlight2)
|
||||||
|
erbsenzaehler
|
||||||
|
Ernesto Gatti
|
||||||
|
Fabian Beuke (madnight)
|
||||||
|
Fabian Fichter (ianfab)
|
||||||
fanon
|
fanon
|
||||||
|
Fauzi Akram Dabat (FauziAkram)
|
||||||
|
Felix Wittmann
|
||||||
gamander
|
gamander
|
||||||
gguliash
|
gguliash
|
||||||
|
Gian-Carlo Pascutto (gcp)
|
||||||
|
Gontran Lemaire (gonlem)
|
||||||
|
Goodkov Vasiliy Aleksandrovich (goodkov)
|
||||||
|
Gregor Cramer
|
||||||
|
GuardianRM
|
||||||
|
Günther Demetz (pb00067, pb00068)
|
||||||
|
Guy Vreuls (gvreuls)
|
||||||
|
Henri Wiechers
|
||||||
|
Hiraoka Takuya (HiraokaTakuya)
|
||||||
|
homoSapiensSapiens
|
||||||
|
Hongzhi Cheng
|
||||||
|
Ivan Ivec (IIvec)
|
||||||
|
Jacques B. (Timshel)
|
||||||
|
Jan Ondruš (hxim)
|
||||||
|
Jared Kish (Kurtbusch)
|
||||||
|
Jarrod Torriero (DU-jdto)
|
||||||
|
Jean Gauthier (OuaisBla)
|
||||||
|
Jean-Francois Romang (jromang)
|
||||||
|
Jekaa
|
||||||
|
Jerry Donald Watson (jerrydonaldwatson)
|
||||||
|
Jonathan Calovski (Mysseno)
|
||||||
|
Jonathan Dumale (SFisGOD)
|
||||||
|
Joost VandeVondele (vondele)
|
||||||
|
Jörg Oster (joergoster)
|
||||||
|
Joseph Ellis (jhellis3)
|
||||||
|
Joseph R. Prostko
|
||||||
|
jundery
|
||||||
|
Justin Blanchard (UncombedCoconut)
|
||||||
|
Kelly Wilson
|
||||||
|
Ken Takusagawa
|
||||||
kinderchocolate
|
kinderchocolate
|
||||||
|
Kiran Panditrao (Krgp)
|
||||||
|
Kojirion
|
||||||
|
Leonardo Ljubičić (ICCF World Champion)
|
||||||
|
Leonid Pechenik (lp--)
|
||||||
|
Linus Arver (listx)
|
||||||
|
loco-loco
|
||||||
|
Lub van den Berg (ElbertoOne)
|
||||||
|
Luca Brivio (lucabrivio)
|
||||||
|
Lucas Braesch (lucasart)
|
||||||
|
Lyudmil Antonov (lantonov)
|
||||||
|
Maciej Żenczykowski (zenczykowski)
|
||||||
|
Malcolm Campbell (xoto10)
|
||||||
|
Mark Tenzer (31m059)
|
||||||
|
marotear
|
||||||
|
Matthew Lai (matthewlai)
|
||||||
|
Matthew Sullivan (Matt14916)
|
||||||
|
Michael An (man)
|
||||||
|
Michael Byrne (MichaelB7)
|
||||||
|
Michael Chaly (Vizvezdenec)
|
||||||
|
Michael Stembera (mstembera)
|
||||||
|
Michael Whiteley (protonspring)
|
||||||
|
Michel Van den Bergh (vdbergh)
|
||||||
|
Miguel Lahoz (miguel-l)
|
||||||
|
Mikael Bäckman (mbootsector)
|
||||||
|
Mira
|
||||||
|
Miroslav Fontán (Hexik)
|
||||||
|
Moez Jellouli (MJZ1977)
|
||||||
|
Mohammed Li (tthsqe12)
|
||||||
|
Nathan Rugg (nmrugg)
|
||||||
|
Nick Pelling (nickpelling)
|
||||||
|
Nicklas Persson (NicklasPersson)
|
||||||
|
Niklas Fiekas (niklasf)
|
||||||
|
Nikolay Kostov (NikolayIT)
|
||||||
|
Ondrej Mosnáček (WOnder93)
|
||||||
|
Oskar Werkelin Ahlin
|
||||||
|
Pablo Vazquez
|
||||||
|
Panthee
|
||||||
|
Pascal Romaret
|
||||||
|
Pasquale Pigazzini (ppigazzini)
|
||||||
|
Patrick Jansen (mibere)
|
||||||
pellanda
|
pellanda
|
||||||
ppigazzini
|
Peter Zsifkovits (CoffeeOne)
|
||||||
|
Ralph Stößer (Ralph Stoesser)
|
||||||
|
Raminder Singh
|
||||||
renouve
|
renouve
|
||||||
|
Reuven Peleg
|
||||||
|
Richard Lloyd
|
||||||
|
Rodrigo Exterckötter Tjäder
|
||||||
|
Ron Britvich (Britvich)
|
||||||
|
Ronald de Man (syzygy1, syzygy)
|
||||||
|
Ryan Schmitt
|
||||||
|
Ryan Takker
|
||||||
|
Sami Kiminki (skiminki)
|
||||||
|
Sebastian Buchwald (UniQP)
|
||||||
|
Sergei Antonov (saproj)
|
||||||
|
Sergei Ivanov (svivanov72)
|
||||||
sf-x
|
sf-x
|
||||||
|
Shane Booth (shane31)
|
||||||
|
Stefan Geschwentner (locutus2)
|
||||||
|
Stefano Cardanobile (Stefano80)
|
||||||
|
Steinar Gunderson (sesse)
|
||||||
|
Stéphane Nicolet (snicolet)
|
||||||
|
Thanar2
|
||||||
thaspel
|
thaspel
|
||||||
unknown
|
theo77186
|
||||||
|
Tom Truscott
|
||||||
|
Tom Vijlbrief (tomtor)
|
||||||
|
Torsten Franz (torfranz, tfranzer)
|
||||||
|
Tracey Emery (basepr1me)
|
||||||
|
Uri Blass (uriblass)
|
||||||
|
Vince Negri (cuddlestmonkey)
|
||||||
|
|
||||||
|
|
||||||
|
# Additionally, we acknowledge the authors and maintainers of fishtest,
|
||||||
|
# an amazing and essential framework for the development of Stockfish!
|
||||||
|
#
|
||||||
|
# https://github.com/glinscott/fishtest/blob/master/AUTHORS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,66 +1,123 @@
|
|||||||
### Overview
|
## Overview
|
||||||
|
|
||||||
[](https://travis-ci.org/official-stockfish/Stockfish)
|
[](https://travis-ci.org/official-stockfish/Stockfish)
|
||||||
[](https://ci.appveyor.com/project/mcostalba/stockfish)
|
[](https://ci.appveyor.com/project/mcostalba/stockfish/branch/master)
|
||||||
|
|
||||||
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
[Stockfish](https://stockfishchess.org) is a free, powerful UCI chess engine
|
||||||
not a complete chess program and requires some UCI-compatible GUI
|
derived from Glaurung 2.1. It is not a complete chess program and requires a
|
||||||
(e.g. XBoard with PolyGlot, eboard, Arena, Sigma Chess, Shredder, Chess
|
UCI-compatible GUI (e.g. XBoard with PolyGlot, Scid, Cute Chess, eboard, Arena,
|
||||||
Partner or Fritz) in order to be used comfortably. Read the
|
Sigma Chess, Shredder, Chess Partner or Fritz) in order to be used comfortably.
|
||||||
documentation for your GUI of choice for information about how to use
|
Read the documentation for your GUI of choice for information about how to use
|
||||||
Stockfish with it.
|
Stockfish with it.
|
||||||
|
|
||||||
This version of Stockfish supports up to 512 cores. The engine defaults
|
|
||||||
to one search thread, so it is therefore recommended to inspect the value of
|
|
||||||
the *Threads* UCI parameter, and to make sure it equals the number of CPU
|
|
||||||
cores on your computer.
|
|
||||||
|
|
||||||
This version of Stockfish has support for Syzygybases.
|
## Files
|
||||||
|
|
||||||
|
|
||||||
### Files
|
|
||||||
|
|
||||||
This distribution of Stockfish consists of the following files:
|
This distribution of Stockfish consists of the following files:
|
||||||
|
|
||||||
* Readme.md, the file you are currently reading.
|
* Readme.md, the file you are currently reading.
|
||||||
|
|
||||||
* Copying.txt, a text file containing the GNU General Public License.
|
* Copying.txt, a text file containing the GNU General Public License version 3.
|
||||||
|
|
||||||
* src, a subdirectory containing the full source code, including a Makefile
|
* src, a subdirectory containing the full source code, including a Makefile
|
||||||
that can be used to compile Stockfish on Unix-like systems.
|
that can be used to compile Stockfish on Unix-like systems.
|
||||||
|
|
||||||
|
|
||||||
### Syzygybases
|
## UCI parameters
|
||||||
|
|
||||||
**Configuration**
|
Currently, Stockfish has the following UCI options:
|
||||||
|
|
||||||
Syzygybases are configured using the UCI options "SyzygyPath",
|
* #### Debug Log File
|
||||||
"SyzygyProbeDepth", "Syzygy50MoveRule" and "SyzygyProbeLimit".
|
Write all communication to and from the engine into a text file.
|
||||||
|
|
||||||
The option "SyzygyPath" should be set to the directory or directories that
|
* #### Contempt
|
||||||
contain the .rtbw and .rtbz files. Multiple directories should be
|
A positive value for contempt favors middle game positions and avoids draws.
|
||||||
separated by ";" on Windows and by ":" on Unix-based operating systems.
|
|
||||||
**Do not use spaces around the ";" or ":".**
|
|
||||||
|
|
||||||
Example: `C:\tablebases\wdl345;C:\tablebases\wdl6;D:\tablebases\dtz345;D:\tablebases\dtz6`
|
* #### Analysis Contempt
|
||||||
|
By default, contempt is set to prefer the side to move. Set this option to "White"
|
||||||
|
or "Black" to analyse with contempt for that side, or "Off" to disable contempt.
|
||||||
|
|
||||||
It is recommended to store .rtbw files on an SSD. There is no loss in
|
* #### Threads
|
||||||
storing the .rtbz files on a regular HD.
|
The number of CPU threads used for searching a position. For best performance, set
|
||||||
|
this equal to the number of CPU cores available.
|
||||||
|
|
||||||
Increasing the "SyzygyProbeDepth" option lets the engine probe less
|
* #### Hash
|
||||||
aggressively. Set this option to a higher value if you experience too much
|
The size of the hash table in MB.
|
||||||
slowdown (in terms of nps) due to TB probing.
|
|
||||||
|
|
||||||
Set the "Syzygy50MoveRule" option to false if you want tablebase positions
|
* #### Clear Hash
|
||||||
that are drawn by the 50-move rule to count as win or loss. This may be useful
|
Clear the hash table.
|
||||||
for correspondence games (because of tablebase adjudication).
|
|
||||||
|
|
||||||
The "SyzygyProbeLimit" option should normally be left at its default value.
|
* #### Ponder
|
||||||
|
Let Stockfish ponder its next move while the opponent is thinking.
|
||||||
|
|
||||||
|
* #### MultiPV
|
||||||
|
Output the N best lines (principal variations, PVs) when searching.
|
||||||
|
Leave at 1 for best performance.
|
||||||
|
|
||||||
|
* #### Skill Level
|
||||||
|
Lower the Skill Level in order to make Stockfish play weaker (see also UCI_LimitStrength).
|
||||||
|
Internally, MultiPV is enabled, and with a certain probability depending on the Skill Level a
|
||||||
|
weaker move will be played.
|
||||||
|
|
||||||
|
* #### UCI_LimitStrength
|
||||||
|
Enable weaker play aiming for an Elo rating as set by UCI_Elo. This option overrides Skill Level.
|
||||||
|
|
||||||
|
* #### UCI_Elo
|
||||||
|
If enabled by UCI_LimitStrength, aim for an engine strength of the given Elo.
|
||||||
|
This Elo rating has been calibrated at a time control of 60s+0.6s and anchored to CCRL 40/4.
|
||||||
|
|
||||||
|
* #### Move Overhead
|
||||||
|
Assume a time delay of x ms due to network and GUI overheads. This is useful to
|
||||||
|
avoid losses on time in those cases.
|
||||||
|
|
||||||
|
* #### Minimum Thinking Time
|
||||||
|
Search for at least x ms per move.
|
||||||
|
|
||||||
|
* #### Slow Mover
|
||||||
|
Lower values will make Stockfish take less time in games, higher values will
|
||||||
|
make it think longer.
|
||||||
|
|
||||||
|
* #### nodestime
|
||||||
|
Tells the engine to use nodes searched instead of wall time to account for
|
||||||
|
elapsed time. Useful for engine testing.
|
||||||
|
|
||||||
|
* #### UCI_Chess960
|
||||||
|
An option handled by your GUI. If true, Stockfish will play Chess960.
|
||||||
|
|
||||||
|
* #### UCI_AnalyseMode
|
||||||
|
An option handled by your GUI.
|
||||||
|
|
||||||
|
* #### SyzygyPath
|
||||||
|
Path to the folders/directories storing the Syzygy tablebase files. Multiple
|
||||||
|
directories are to be separated by ";" on Windows and by ":" on Unix-based
|
||||||
|
operating systems. Do not use spaces around the ";" or ":".
|
||||||
|
|
||||||
|
Example: `C:\tablebases\wdl345;C:\tablebases\wdl6;D:\tablebases\dtz345;D:\tablebases\dtz6`
|
||||||
|
|
||||||
|
It is recommended to store .rtbw files on an SSD. There is no loss in storing
|
||||||
|
the .rtbz files on a regular HD. It is recommended to verify all md5 checksums
|
||||||
|
of the downloaded tablebase files (`md5sum -c checksum.md5`) as corruption will
|
||||||
|
lead to engine crashes.
|
||||||
|
|
||||||
|
* #### SyzygyProbeDepth
|
||||||
|
Minimum remaining search depth for which a position is probed. Set this option
|
||||||
|
to a higher value to probe less agressively if you experience too much slowdown
|
||||||
|
(in terms of nps) due to TB probing.
|
||||||
|
|
||||||
|
* #### Syzygy50MoveRule
|
||||||
|
Disable to let fifty-move rule draws detected by Syzygy tablebase probes count
|
||||||
|
as wins or losses. This is useful for ICCF correspondence games.
|
||||||
|
|
||||||
|
* #### SyzygyProbeLimit
|
||||||
|
Limit Syzygy tablebase probing to positions with at most this many pieces left
|
||||||
|
(including kings and pawns).
|
||||||
|
|
||||||
|
|
||||||
|
## What to expect from Syzygybases?
|
||||||
|
|
||||||
**What to expect**
|
|
||||||
If the engine is searching a position that is not in the tablebases (e.g.
|
If the engine is searching a position that is not in the tablebases (e.g.
|
||||||
a position with 7 pieces), it will access the tablebases during the search.
|
a position with 8 pieces), it will access the tablebases during the search.
|
||||||
If the engine reports a very large score (typically 123.xx), this means
|
If the engine reports a very large score (typically 153.xx), this means
|
||||||
that it has found a winning line into a tablebase position.
|
that it has found a winning line into a tablebase position.
|
||||||
|
|
||||||
If the engine is given a position to search that is in the tablebases, it
|
If the engine is given a position to search that is in the tablebases, it
|
||||||
@@ -71,7 +128,7 @@ It will then perform a search only on those moves. **The engine will not move
|
|||||||
immediately**, unless there is only a single good move. **The engine likely
|
immediately**, unless there is only a single good move. **The engine likely
|
||||||
will not report a mate score even if the position is known to be won.**
|
will not report a mate score even if the position is known to be won.**
|
||||||
|
|
||||||
It is therefore clear that behaviour is not identical to what one might
|
It is therefore clear that this behaviour is not identical to what one might
|
||||||
be used to with Nalimov tablebases. There are technical reasons for this
|
be used to with Nalimov tablebases. There are technical reasons for this
|
||||||
difference, the main technical reason being that Nalimov tablebases use the
|
difference, the main technical reason being that Nalimov tablebases use the
|
||||||
DTM metric (distance-to-mate), while Syzygybases use a variation of the
|
DTM metric (distance-to-mate), while Syzygybases use a variation of the
|
||||||
@@ -82,7 +139,7 @@ needed for optimal play and in addition being able to take into account
|
|||||||
the 50-move rule.
|
the 50-move rule.
|
||||||
|
|
||||||
|
|
||||||
### Compiling it yourself
|
## Compiling Stockfish yourself from the sources
|
||||||
|
|
||||||
On Unix-like systems, it should be possible to compile Stockfish
|
On Unix-like systems, it should be possible to compile Stockfish
|
||||||
directly from the source code with the included Makefile.
|
directly from the source code with the included Makefile.
|
||||||
@@ -96,19 +153,49 @@ compile (for instance with Microsoft MSVC) you need to manually
|
|||||||
set/unset some switches in the compiler command line; see file *types.h*
|
set/unset some switches in the compiler command line; see file *types.h*
|
||||||
for a quick reference.
|
for a quick reference.
|
||||||
|
|
||||||
### Resource For Understanding the Code Base
|
When reporting an issue or a bug, please tell us which version and
|
||||||
|
compiler you used to create your executable. These informations can
|
||||||
|
be found by typing the following commands in a console:
|
||||||
|
|
||||||
* [Chessprogramingwiki](https://chessprogramming.wikispaces.com) has good overall chess engines explanations
|
```
|
||||||
(techniques used here are well explained like hash maps etc), it was
|
./stockfish
|
||||||
also recommended by the [support at stockfish.](http://support.stockfishchess.org/discussions/questions/1132-how-to-understand-stockfish-sources)
|
compiler
|
||||||
|
```
|
||||||
|
|
||||||
* [Here](https://chessprogramming.wikispaces.com/Stockfish) you can find a set of features and techniques used by stockfish and each of them is explained at the wiki, however, it's a generic way rather than focusing on stockfish's own implementation, but it will still help you.
|
## Understanding the code base and participating in the project
|
||||||
|
|
||||||
|
Stockfish's improvement over the last couple of years has been a great
|
||||||
|
community effort. There are a few ways to help contribute to its growth.
|
||||||
|
|
||||||
|
### Donating hardware
|
||||||
|
|
||||||
|
Improving Stockfish requires a massive amount of testing. You can donate
|
||||||
|
your hardware resources by installing the [Fishtest Worker](https://github.com/glinscott/fishtest/wiki/Running-the-worker:-overview)
|
||||||
|
and view the current tests on [Fishtest](https://tests.stockfishchess.org/tests).
|
||||||
|
|
||||||
|
### Improving the code
|
||||||
|
|
||||||
|
If you want to help improve the code, there are several valuable resources:
|
||||||
|
|
||||||
|
* [In this wiki,](https://www.chessprogramming.org) many techniques used in
|
||||||
|
Stockfish are explained with a lot of background information.
|
||||||
|
|
||||||
|
* [The section on Stockfish](https://www.chessprogramming.org/Stockfish)
|
||||||
|
describes many features and techniques used by Stockfish. However, it is
|
||||||
|
generic rather than being focused on Stockfish's precise implementation.
|
||||||
|
Nevertheless, a helpful resource.
|
||||||
|
|
||||||
|
* The latest source can always be found on [GitHub](https://github.com/official-stockfish/Stockfish).
|
||||||
|
Discussions about Stockfish take place in the [FishCooking](https://groups.google.com/forum/#!forum/fishcooking)
|
||||||
|
group and engine testing is done on [Fishtest](https://tests.stockfishchess.org/tests).
|
||||||
|
If you want to help improve Stockfish, please read this [guideline](https://github.com/glinscott/fishtest/wiki/Creating-my-first-test)
|
||||||
|
first, where the basics of Stockfish development are explained.
|
||||||
|
|
||||||
|
|
||||||
### Terms of use
|
## Terms of use
|
||||||
|
|
||||||
Stockfish is free, and distributed under the **GNU General Public License**
|
Stockfish is free, and distributed under the **GNU General Public License version 3**
|
||||||
(GPL). Essentially, this means that you are free to do almost exactly
|
(GPL v3). Essentially, this means that you are free to do almost exactly
|
||||||
what you want with the program, including distributing it among your
|
what you want with the program, including distributing it among your
|
||||||
friends, making it available for download from your web site, selling
|
friends, making it available for download from your web site, selling
|
||||||
it (either by itself or as part of some bigger software package), or
|
it (either by itself or as part of some bigger software package), or
|
||||||
@@ -119,5 +206,5 @@ some way, you must always include the full source code, or a pointer
|
|||||||
to where the source code can be found. If you make any changes to the
|
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.
|
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
|
For full details, read the copy of the GPL v3 found in the file named
|
||||||
*Copying.txt*.
|
*Copying.txt*.
|
||||||
|
|||||||
+152
-130
@@ -1,132 +1,154 @@
|
|||||||
Contributors with >10,000 CPU hours as of January 23, 2018
|
Contributors with >10,000 CPU hours as of January 7, 2020
|
||||||
Thank you!
|
Thank you!
|
||||||
|
|
||||||
Username CPU Hours Games played
|
Username CPU Hours Games played
|
||||||
mibere 518300 41835669
|
--------------------------------------------------
|
||||||
crunchy 375564 29121434
|
noobpwnftw 9305707 695548021
|
||||||
cw 371664 28748719
|
mlang 780050 61648867
|
||||||
fastgm 299773 20765374
|
dew 621626 43921547
|
||||||
JojoM 220590 15299913
|
mibere 524702 42238645
|
||||||
glinscott 204517 13932027
|
crunchy 354587 27344275
|
||||||
bking_US 187568 12233168
|
cw 354495 27274181
|
||||||
ctoks 169342 13475495
|
fastgm 332801 22804359
|
||||||
spams 149531 10940322
|
JojoM 295750 20437451
|
||||||
Thanar 137015 11714855
|
CSU_Dynasty 262015 21828122
|
||||||
velislav 127305 10047749
|
Fisherman 232181 18939229
|
||||||
vdbergh 121741 9056874
|
ctoks 218866 17622052
|
||||||
malala 117291 8126488
|
glinscott 201989 13780820
|
||||||
vdv 117218 8289983
|
tvijlbrief 201204 15337115
|
||||||
leszek 114825 8331897
|
velislav 188630 14348485
|
||||||
dsmith 114010 7622414
|
gvreuls 187164 15149976
|
||||||
CSU_Dynasty 113516 9582758
|
bking_US 180289 11876016
|
||||||
sqrt2 112407 8782694
|
nordlandia 172076 13467830
|
||||||
marrco 111143 8222921
|
leszek 157152 11443978
|
||||||
drabel 108168 9061580
|
Thanar 148021 12365359
|
||||||
BrunoBanani 104938 7448565
|
spams 141975 10319326
|
||||||
Data 94621 8433010
|
drabel 138073 11121749
|
||||||
CoffeeOne 90394 3964243
|
vdv 137850 9394330
|
||||||
BRAVONE 80811 5341681
|
mgrabiak 133578 10454324
|
||||||
psk 77195 6156031
|
TueRens 132485 10878471
|
||||||
brabos 70284 5685893
|
bcross 129683 11557084
|
||||||
Fisherman 66650 5572406
|
marrco 126078 9356740
|
||||||
nssy 64587 5369140
|
sqrt2 125830 9724586
|
||||||
Pking_cda 64499 5704075
|
robal 122873 9593418
|
||||||
sterni1971 63488 5070004
|
vdbergh 120766 8926915
|
||||||
mgrabiak 62385 5420812
|
malala 115926 8002293
|
||||||
tvijlbrief 58957 4154234
|
CoffeeOne 114241 5004100
|
||||||
jromang 58854 4704502
|
dsmith 113189 7570238
|
||||||
dv8silencer 57421 3961325
|
BrunoBanani 104644 7436849
|
||||||
sunu 56620 4609155
|
Data 92328 8220352
|
||||||
tinker 56039 4204914
|
mhoram 89333 6695109
|
||||||
biffhero 55743 4810039
|
davar 87924 7009424
|
||||||
teddybaer 52982 4740444
|
xoto 81094 6869316
|
||||||
bcross 50548 5071599
|
ElbertoOne 80899 7023771
|
||||||
renouve 50318 3544864
|
grandphish2 78067 6160199
|
||||||
Freja 50296 3805120
|
brabos 77212 6186135
|
||||||
robnjr 47504 4131742
|
psk 75733 5984901
|
||||||
eva42 46542 4044694
|
BRAVONE 73875 5054681
|
||||||
davar 46538 4030604
|
sunu 70771 5597972
|
||||||
finfish 46244 3481661
|
sterni1971 70605 5590573
|
||||||
rap 46201 3219490
|
MaZePallas 66886 5188978
|
||||||
ttruscott 45037 3645430
|
Vizvezdenec 63708 4967313
|
||||||
solarlight 44155 4074841
|
nssy 63462 5259388
|
||||||
TueRens 41372 3891510
|
jromang 61634 4940891
|
||||||
ElbertoOne 41321 3920894
|
teddybaer 61231 5407666
|
||||||
Antihistamine 39218 2792761
|
Pking_cda 60099 5293873
|
||||||
mhunt 38991 2697512
|
solarlight 57469 5028306
|
||||||
bigpen0r 37820 3149955
|
dv8silencer 56913 3883992
|
||||||
homyur 35569 3009637
|
tinker 54936 4086118
|
||||||
VoyagerOne 35137 3302650
|
renouve 49732 3501516
|
||||||
mhoram 34770 2684128
|
Freja 49543 3733019
|
||||||
racerschmacer 33022 3231055
|
robnjr 46972 4053117
|
||||||
speedycpu 32043 2531964
|
rap 46563 3219146
|
||||||
EthanOConnor 31638 2143255
|
Bobo1239 46036 3817196
|
||||||
oryx 29574 2767730
|
ttruscott 45304 3649765
|
||||||
Pyafue 28885 1986098
|
racerschmacer 44881 3975413
|
||||||
jkiiski 28014 1923255
|
finfish 44764 3370515
|
||||||
Garf 27579 2770144
|
eva42 41783 3599691
|
||||||
slakovv 27017 2031279
|
biffhero 40263 3111352
|
||||||
Bobo1239 27000 2488707
|
bigpen0r 39817 3291647
|
||||||
pb00067 26817 2306694
|
mhunt 38871 2691355
|
||||||
robal 26337 2316795
|
ronaldjerum 38820 3240695
|
||||||
hyperbolic.tom 26248 2200777
|
Antihistamine 38785 2761312
|
||||||
rkl 24898 2236013
|
pb00067 38038 3086320
|
||||||
SC 23988 2126825
|
speedycpu 37591 3003273
|
||||||
nabildanial 23524 1586321
|
rkl 37207 3289580
|
||||||
achambord 23495 1942546
|
VoyagerOne 37050 3441673
|
||||||
Sharaf_DG 22975 1790697
|
jbwiebe 35320 2805433
|
||||||
chriswk 22876 1947731
|
cuistot 34191 2146279
|
||||||
anst 22568 2013953
|
homyur 33927 2850481
|
||||||
Patrick_G 22435 1682293
|
manap 32873 2327384
|
||||||
cuistot 22201 1383031
|
gri 32538 2515779
|
||||||
gri 21901 1820968
|
oryx 31267 2899051
|
||||||
Prcuvu 21182 1890546
|
EthanOConnor 30959 2090311
|
||||||
Zirie 21171 1493227
|
SC 30832 2730764
|
||||||
JanErik 20596 1791991
|
csnodgrass 29505 2688994
|
||||||
Isidor 20560 1730290
|
jmdana 29458 2205261
|
||||||
xor12 20535 1819280
|
strelock 28219 2067805
|
||||||
team-oh 20364 1653708
|
jkiiski 27832 1904470
|
||||||
nesoneg 20264 1493435
|
Pyafue 27533 1902349
|
||||||
rstoesser 19802 1335177
|
Garf 27515 2747562
|
||||||
grandphish2 19402 1834196
|
eastorwest 27421 2317535
|
||||||
sg4032 18427 1671742
|
slakovv 26903 2021889
|
||||||
dew 18263 1423326
|
Prcuvu 24835 2170122
|
||||||
ianh2105 18133 1668562
|
anst 24714 2190091
|
||||||
MazeOfGalious 18022 1644593
|
hyperbolic.tom 24319 2017394
|
||||||
ville 17900 1539130
|
Patrick_G 23687 1801617
|
||||||
j3corre 17607 975954
|
Sharaf_DG 22896 1786697
|
||||||
eudhan 17502 1424648
|
nabildanial 22195 1519409
|
||||||
iisiraider 17175 1118788
|
chriswk 21931 1868317
|
||||||
jundery 17172 1115855
|
achambord 21665 1767323
|
||||||
SFTUser 16635 1363975
|
Zirie 20887 1472937
|
||||||
purplefishies 16621 1106850
|
team-oh 20217 1636708
|
||||||
DragonLord 16599 1252348
|
Isidor 20096 1680691
|
||||||
chris 15274 1575333
|
ncfish1 19931 1520927
|
||||||
xoto 14900 1486261
|
nesoneg 19875 1463031
|
||||||
dju 14861 901552
|
Spprtr 19853 1548165
|
||||||
dex 14647 1228763
|
JanErik 19849 1703875
|
||||||
nordlandia 14551 1369718
|
agg177 19478 1395014
|
||||||
ronaldjerum 14361 1210607
|
SFTUser 19231 1567999
|
||||||
OssumOpossum 14149 1029265
|
xor12 19017 1680165
|
||||||
IgorLeMasson 13844 1228391
|
sg4032 18431 1641865
|
||||||
enedene 13762 935618
|
rstoesser 18118 1293588
|
||||||
ako027ako 13442 1250249
|
MazeOfGalious 17917 1629593
|
||||||
AdrianSA 13324 924980
|
j3corre 17743 941444
|
||||||
bpfliegel 13318 886523
|
cisco2015 17725 1690126
|
||||||
ncfish1 13056 932344
|
ianh2105 17706 1632562
|
||||||
wei 12863 1369596
|
dex 17678 1467203
|
||||||
jpulman 12776 854815
|
jundery 17194 1115855
|
||||||
horst.prack 12436 1151505
|
iisiraider 17019 1101015
|
||||||
joster 12424 986622
|
horst.prack 17012 1465656
|
||||||
cisco2015 12265 1205019
|
Adrian.Schmidt123 16563 1281436
|
||||||
fatmurphy 12015 901134
|
purplefishies 16342 1092533
|
||||||
modolief 11228 926456
|
wei 16274 1745989
|
||||||
Dark_wizzie 11214 1017910
|
ville 16144 1384026
|
||||||
mschmidt 10973 818594
|
eudhan 15712 1283717
|
||||||
eastorwest 10970 1117836
|
OuaisBla 15581 972000
|
||||||
infinity 10762 746397
|
DragonLord 15559 1162790
|
||||||
SapphireBrand 10692 1024604
|
dju 14716 875569
|
||||||
Thomas A. 10553 736094
|
chris 14479 1487385
|
||||||
pgontarz 10294 878746
|
0xB00B1ES 14079 1001120
|
||||||
Andrew Grant 10195 922933
|
OssumOpossum 13776 1007129
|
||||||
stocky 10083 718114
|
enedene 13460 905279
|
||||||
|
bpfliegel 13346 884523
|
||||||
|
Ente 13198 1156722
|
||||||
|
IgorLeMasson 13087 1147232
|
||||||
|
jpulman 13000 870599
|
||||||
|
ako027ako 12775 1173203
|
||||||
|
Nikolay.IT 12352 1068349
|
||||||
|
Andrew Grant 12327 895539
|
||||||
|
joster 12008 950160
|
||||||
|
AdrianSA 11996 804972
|
||||||
|
Nesa92 11455 1111993
|
||||||
|
fatmurphy 11345 853210
|
||||||
|
Dark_wizzie 11108 1007152
|
||||||
|
modolief 10869 896470
|
||||||
|
mschmidt 10757 803401
|
||||||
|
infinity 10594 727027
|
||||||
|
mabichito 10524 749391
|
||||||
|
Thomas A. Anderson 10474 732094
|
||||||
|
thijsk 10431 719357
|
||||||
|
Flopzee 10339 894821
|
||||||
|
crocogoat 10104 1013854
|
||||||
|
SapphireBrand 10104 969604
|
||||||
|
stocky 10017 699440
|
||||||
|
|||||||
+3
-3
@@ -7,7 +7,7 @@ branches:
|
|||||||
- appveyor
|
- appveyor
|
||||||
|
|
||||||
# Operating system (build VM template)
|
# Operating system (build VM template)
|
||||||
os: Visual Studio 2015
|
os: Visual Studio 2017
|
||||||
|
|
||||||
# Build platform, i.e. x86, x64, AnyCPU. This setting is optional.
|
# Build platform, i.e. x86, x64, AnyCPU. This setting is optional.
|
||||||
platform:
|
platform:
|
||||||
@@ -51,7 +51,7 @@ before_build:
|
|||||||
$b = git log HEAD | sls "\b[Bb]ench[ :]+[0-9]{7}" | select -first 1
|
$b = git log HEAD | sls "\b[Bb]ench[ :]+[0-9]{7}" | select -first 1
|
||||||
$bench = $b -match '\D+(\d+)' | % { $matches[1] }
|
$bench = $b -match '\D+(\d+)' | % { $matches[1] }
|
||||||
Write-Host "Reference bench:" $bench
|
Write-Host "Reference bench:" $bench
|
||||||
$g = "Visual Studio 14 2015"
|
$g = "Visual Studio 15 2017"
|
||||||
If (${env:PLATFORM} -eq 'x64') { $g = $g + ' Win64' }
|
If (${env:PLATFORM} -eq 'x64') { $g = $g + ' Win64' }
|
||||||
cmake -G "${g}" .
|
cmake -G "${g}" .
|
||||||
Write-Host "Generated files for: " $g
|
Write-Host "Generated files for: " $g
|
||||||
@@ -61,9 +61,9 @@ build_script:
|
|||||||
|
|
||||||
before_test:
|
before_test:
|
||||||
- cd src/%CONFIGURATION%
|
- cd src/%CONFIGURATION%
|
||||||
|
- stockfish bench 2> out.txt >NUL
|
||||||
- ps: |
|
- ps: |
|
||||||
# Verify bench number
|
# Verify bench number
|
||||||
./stockfish bench 2> out.txt 1> null
|
|
||||||
$s = (gc "./out.txt" | out-string)
|
$s = (gc "./out.txt" | out-string)
|
||||||
$r = ($s -match 'Nodes searched \D+(\d+)' | % { $matches[1] })
|
$r = ($s -match 'Nodes searched \D+(\d+)' | % { $matches[1] })
|
||||||
Write-Host "Engine bench:" $r
|
Write-Host "Engine bench:" $r
|
||||||
|
|||||||
+40
-58
@@ -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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
# Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
# Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
# Copyright (C) 2015-2019 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -21,14 +21,12 @@
|
|||||||
### Section 1. General Configuration
|
### Section 1. General Configuration
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
|
|
||||||
### Establish the operating system name
|
|
||||||
KERNEL = $(shell uname -s)
|
|
||||||
ifeq ($(KERNEL),Linux)
|
|
||||||
OS = $(shell uname -o)
|
|
||||||
endif
|
|
||||||
|
|
||||||
### Executable name
|
### Executable name
|
||||||
|
ifeq ($(COMP),mingw)
|
||||||
|
EXE = stockfish.exe
|
||||||
|
else
|
||||||
EXE = stockfish
|
EXE = stockfish
|
||||||
|
endif
|
||||||
|
|
||||||
### Installation dir definitions
|
### Installation dir definitions
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
@@ -42,6 +40,12 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
|||||||
material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o \
|
material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o \
|
||||||
search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
|
search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
|
||||||
|
|
||||||
|
### Establish the operating system name
|
||||||
|
KERNEL = $(shell uname -s)
|
||||||
|
ifeq ($(KERNEL),Linux)
|
||||||
|
OS = $(shell uname -o)
|
||||||
|
endif
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Section 2. High-level Configuration
|
### Section 2. High-level Configuration
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
@@ -132,6 +136,8 @@ endif
|
|||||||
ifeq ($(ARCH),ppc-64)
|
ifeq ($(ARCH),ppc-64)
|
||||||
arch = ppc64
|
arch = ppc64
|
||||||
bits = 64
|
bits = 64
|
||||||
|
popcnt = yes
|
||||||
|
prefetch = yes
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
@@ -204,11 +210,12 @@ ifeq ($(COMP),clang)
|
|||||||
comp=clang
|
comp=clang
|
||||||
CXX=clang++
|
CXX=clang++
|
||||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||||
ifneq ($(KERNEL),Darwin)
|
|
||||||
ifneq ($(KERNEL),OpenBSD)
|
ifneq ($(KERNEL),Darwin)
|
||||||
LDFLAGS += -latomic
|
ifneq ($(KERNEL),OpenBSD)
|
||||||
endif
|
LDFLAGS += -latomic
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),armv7)
|
ifeq ($(ARCH),armv7)
|
||||||
ifeq ($(OS),Android)
|
ifeq ($(OS),Android)
|
||||||
@@ -279,39 +286,16 @@ ifeq ($(optimize),yes)
|
|||||||
CXXFLAGS += -O3
|
CXXFLAGS += -O3
|
||||||
|
|
||||||
ifeq ($(comp),gcc)
|
ifeq ($(comp),gcc)
|
||||||
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
|
||||||
ifeq ($(arch),i386)
|
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
|
||||||
endif
|
|
||||||
ifeq ($(arch),x86_64)
|
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(OS), Android)
|
ifeq ($(OS), Android)
|
||||||
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),icc)
|
ifeq ($(comp),$(filter $(comp),gcc clang icc))
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(KERNEL),Darwin)
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),clang)
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
|
||||||
CXXFLAGS += -flto
|
|
||||||
LDFLAGS += $(CXXFLAGS)
|
|
||||||
ifeq ($(arch),i386)
|
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
|
||||||
endif
|
|
||||||
ifeq ($(arch),x86_64)
|
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.4 Bits
|
### 3.4 Bits
|
||||||
@@ -331,7 +315,9 @@ endif
|
|||||||
|
|
||||||
### 3.6 popcnt
|
### 3.6 popcnt
|
||||||
ifeq ($(popcnt),yes)
|
ifeq ($(popcnt),yes)
|
||||||
ifeq ($(comp),icc)
|
ifeq ($(arch),ppc64)
|
||||||
|
CXXFLAGS += -DUSE_POPCNT
|
||||||
|
else ifeq ($(comp),icc)
|
||||||
CXXFLAGS += -msse3 -DUSE_POPCNT
|
CXXFLAGS += -msse3 -DUSE_POPCNT
|
||||||
else
|
else
|
||||||
CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
|
CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
|
||||||
@@ -342,31 +328,27 @@ endif
|
|||||||
ifeq ($(pext),yes)
|
ifeq ($(pext),yes)
|
||||||
CXXFLAGS += -DUSE_PEXT
|
CXXFLAGS += -DUSE_PEXT
|
||||||
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
CXXFLAGS += -mbmi2
|
CXXFLAGS += -msse4 -mbmi2
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.8 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
|
### 3.8 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
|
||||||
### This is a mix of compile and link time options because the lto link phase
|
### This is a mix of compile and link time options because the lto link phase
|
||||||
### needs access to the optimization flags.
|
### needs access to the optimization flags.
|
||||||
ifeq ($(comp),gcc)
|
ifeq ($(optimize),yes)
|
||||||
ifeq ($(optimize),yes)
|
ifeq ($(debug), no)
|
||||||
ifeq ($(debug),no)
|
ifeq ($(comp),$(filter $(comp),gcc clang))
|
||||||
|
CXXFLAGS += -flto
|
||||||
|
LDFLAGS += $(CXXFLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(comp),mingw)
|
||||||
|
ifeq ($(KERNEL),Linux)
|
||||||
CXXFLAGS += -flto
|
CXXFLAGS += -flto
|
||||||
LDFLAGS += $(CXXFLAGS)
|
LDFLAGS += $(CXXFLAGS)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),mingw)
|
|
||||||
ifeq ($(KERNEL),Linux)
|
|
||||||
ifeq ($(optimize),yes)
|
|
||||||
ifeq ($(debug),no)
|
|
||||||
CXXFLAGS += -flto
|
|
||||||
LDFLAGS += $(CXXFLAGS)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.9 Android 5 can only run position independent executables. Note that this
|
### 3.9 Android 5 can only run position independent executables. Note that this
|
||||||
@@ -397,10 +379,10 @@ help:
|
|||||||
@echo ""
|
@echo ""
|
||||||
@echo "Supported archs:"
|
@echo "Supported archs:"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "x86-64 > x86 64-bit"
|
@echo "x86-64-bmi2 > x86 64-bit with pext support (also enables SSE4)"
|
||||||
@echo "x86-64-modern > x86 64-bit with popcnt support"
|
@echo "x86-64-modern > x86 64-bit with popcnt support (also enables SSE3)"
|
||||||
@echo "x86-64-bmi2 > x86 64-bit with pext support"
|
@echo "x86-64 > x86 64-bit generic"
|
||||||
@echo "x86-32 > x86 32-bit with SSE support"
|
@echo "x86-32 > x86 32-bit (also enables SSE)"
|
||||||
@echo "x86-32-old > x86 32-bit fall back for old hardware"
|
@echo "x86-32-old > x86 32-bit fall back for old hardware"
|
||||||
@echo "ppc-64 > PPC 64-bit"
|
@echo "ppc-64 > PPC 64-bit"
|
||||||
@echo "ppc-32 > PPC 32-bit"
|
@echo "ppc-32 > PPC 32-bit"
|
||||||
@@ -423,7 +405,7 @@ help:
|
|||||||
@echo "Advanced examples, for experienced users: "
|
@echo "Advanced examples, for experienced users: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make build ARCH=x86-64 COMP=clang"
|
@echo "make build ARCH=x86-64 COMP=clang"
|
||||||
@echo "make profile-build ARCH=x86-64-modern COMP=gcc COMPCXX=g++-4.8"
|
@echo "make profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-4.8"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
|
|
||||||
@@ -463,7 +445,7 @@ clean: objclean profileclean
|
|||||||
|
|
||||||
# clean binaries and objects
|
# clean binaries and objects
|
||||||
objclean:
|
objclean:
|
||||||
@rm -f $(EXE) $(EXE).exe *.o ./syzygy/*.o
|
@rm -f $(EXE) *.o ./syzygy/*.o
|
||||||
|
|
||||||
# clean auxiliary profiling files
|
# clean auxiliary profiling files
|
||||||
profileclean:
|
profileclean:
|
||||||
@@ -503,7 +485,7 @@ config-sanity:
|
|||||||
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
||||||
@echo ""
|
@echo ""
|
||||||
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
||||||
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "no"
|
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "address" || test "$(sanitize)" = "no"
|
||||||
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
||||||
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
||||||
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
||||||
|
|||||||
+7
-3
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,10 @@ const vector<string> Defaults = {
|
|||||||
"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w - - 0 1",
|
"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w - - 0 1",
|
||||||
"6k1/4pp1p/3p2p1/P1pPb3/R7/1r2P1PP/3B1P2/6K1 w - - 0 1",
|
"6k1/4pp1p/3p2p1/P1pPb3/R7/1r2P1PP/3B1P2/6K1 w - - 0 1",
|
||||||
"8/3p3B/5p2/5P2/p7/PP5b/k7/6K1 w - - 0 1",
|
"8/3p3B/5p2/5P2/p7/PP5b/k7/6K1 w - - 0 1",
|
||||||
|
"5rk1/q6p/2p3bR/1pPp1rP1/1P1Pp3/P3B1Q1/1K3P2/R7 w - - 93 90",
|
||||||
|
"4rrk1/1p1nq3/p7/2p1P1pp/3P2bp/3Q1Bn1/PPPB4/1K2R1NR w - - 40 21",
|
||||||
|
"r3k2r/3nnpbp/q2pp1p1/p7/Pp1PPPP1/4BNN1/1P5P/R2Q1RK1 w kq - 0 16",
|
||||||
|
"3Qb1k1/1r2ppb1/pN1n2q1/Pp1Pp1Pr/4P2p/4BP2/4B1R1/1R5K b - - 11 40",
|
||||||
|
|
||||||
// 5-man positions
|
// 5-man positions
|
||||||
"8/8/8/8/5kp1/P7/8/1K1N4 w - - 0 1", // Kc2 - mate
|
"8/8/8/8/5kp1/P7/8/1K1N4 w - - 0 1", // Kc2 - mate
|
||||||
@@ -113,7 +117,7 @@ vector<string> setup_bench(const Position& current, istream& is) {
|
|||||||
string fenFile = (is >> token) ? token : "default";
|
string fenFile = (is >> token) ? token : "default";
|
||||||
string limitType = (is >> token) ? token : "depth";
|
string limitType = (is >> token) ? token : "depth";
|
||||||
|
|
||||||
go = "go " + limitType + " " + limit;
|
go = limitType == "eval" ? "eval" : "go " + limitType + " " + limit;
|
||||||
|
|
||||||
if (fenFile == "default")
|
if (fenFile == "default")
|
||||||
fens = Defaults;
|
fens = Defaults;
|
||||||
@@ -139,9 +143,9 @@ vector<string> setup_bench(const Position& current, istream& is) {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
list.emplace_back("ucinewgame");
|
|
||||||
list.emplace_back("setoption name Threads value " + threads);
|
list.emplace_back("setoption name Threads value " + threads);
|
||||||
list.emplace_back("setoption name Hash value " + ttSize);
|
list.emplace_back("setoption name Hash value " + ttSize);
|
||||||
|
list.emplace_back("ucinewgame");
|
||||||
|
|
||||||
for (const string& fen : fens)
|
for (const string& fen : fens)
|
||||||
if (fen.find("setoption") != string::npos)
|
if (fen.find("setoption") != string::npos)
|
||||||
|
|||||||
+8
-8
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -28,8 +27,9 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// There are 24 possible pawn squares: the first 4 files and ranks from 2 to 7
|
// There are 24 possible pawn squares: files A to D and ranks from 2 to 7.
|
||||||
const unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
// Positions with the pawn on files E to H will be mirrored before probing.
|
||||||
|
constexpr unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
||||||
|
|
||||||
// Each uint32_t stores results of 32 positions, one per bit
|
// Each uint32_t stores results of 32 positions, one per bit
|
||||||
uint32_t KPKBitbase[MAX_INDEX / 32];
|
uint32_t KPKBitbase[MAX_INDEX / 32];
|
||||||
@@ -44,7 +44,7 @@ namespace {
|
|||||||
// bit 13-14: white pawn file (from FILE_A to FILE_D)
|
// bit 13-14: white pawn file (from FILE_A to FILE_D)
|
||||||
// bit 15-17: white pawn RANK_7 - rank (from RANK_7 - RANK_7 to RANK_7 - RANK_2)
|
// bit 15-17: white pawn RANK_7 - rank (from RANK_7 - RANK_7 to RANK_7 - RANK_2)
|
||||||
unsigned index(Color us, Square bksq, Square wksq, Square psq) {
|
unsigned index(Color us, Square bksq, Square wksq, Square psq) {
|
||||||
return wksq | (bksq << 6) | (us << 12) | (file_of(psq) << 13) | ((RANK_7 - rank_of(psq)) << 15);
|
return int(wksq) | (bksq << 6) | (us << 12) | (file_of(psq) << 13) | ((RANK_7 - rank_of(psq)) << 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Result {
|
enum Result {
|
||||||
@@ -152,9 +152,9 @@ namespace {
|
|||||||
// as WIN, the position is classified as WIN, otherwise the current position is
|
// as WIN, the position is classified as WIN, otherwise the current position is
|
||||||
// classified as UNKNOWN.
|
// classified as UNKNOWN.
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Result Good = (Us == WHITE ? WIN : DRAW);
|
constexpr Result Good = (Us == WHITE ? WIN : DRAW);
|
||||||
const Result Bad = (Us == WHITE ? DRAW : WIN);
|
constexpr Result Bad = (Us == WHITE ? DRAW : WIN);
|
||||||
|
|
||||||
Result r = INVALID;
|
Result r = INVALID;
|
||||||
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
||||||
|
|||||||
+30
-134
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -19,24 +19,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
uint8_t PopCnt16[1 << 16];
|
uint8_t PopCnt16[1 << 16];
|
||||||
int SquareDistance[SQUARE_NB][SQUARE_NB];
|
uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
|
|
||||||
Bitboard SquareBB[SQUARE_NB];
|
Bitboard SquareBB[SQUARE_NB];
|
||||||
Bitboard FileBB[FILE_NB];
|
|
||||||
Bitboard RankBB[RANK_NB];
|
|
||||||
Bitboard AdjacentFilesBB[FILE_NB];
|
|
||||||
Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
|
|
||||||
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
|
||||||
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||||
Bitboard DistanceRingBB[SQUARE_NB][8];
|
|
||||||
Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
|
|
||||||
Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
|
||||||
Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
|
||||||
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
||||||
Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||||
|
|
||||||
@@ -45,77 +37,12 @@ Magic BishopMagics[SQUARE_NB];
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// De Bruijn sequences. See chessprogramming.wikispaces.com/BitScan
|
|
||||||
const uint64_t DeBruijn64 = 0x3F79D71B4CB0A89ULL;
|
|
||||||
const uint32_t DeBruijn32 = 0x783A9B23;
|
|
||||||
|
|
||||||
int MSBTable[256]; // To implement software msb()
|
|
||||||
Square BSFTable[SQUARE_NB]; // To implement software bitscan
|
|
||||||
Bitboard RookTable[0x19000]; // To store rook attacks
|
Bitboard RookTable[0x19000]; // To store rook attacks
|
||||||
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
||||||
|
|
||||||
void init_magics(Bitboard table[], Magic magics[], Direction directions[]);
|
void init_magics(Bitboard table[], Magic magics[], Direction directions[]);
|
||||||
|
|
||||||
// bsf_index() returns the index into BSFTable[] to look up the bitscan. Uses
|
|
||||||
// Matt Taylor's folding for 32 bit case, extended to 64 bit by Kim Walisch.
|
|
||||||
|
|
||||||
unsigned bsf_index(Bitboard b) {
|
|
||||||
b ^= b - 1;
|
|
||||||
return Is64Bit ? (b * DeBruijn64) >> 58
|
|
||||||
: ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn32) >> 26;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// popcount16() counts the non-zero bits using SWAR-Popcount algorithm
|
|
||||||
|
|
||||||
unsigned popcount16(unsigned u) {
|
|
||||||
u -= (u >> 1) & 0x5555U;
|
|
||||||
u = ((u >> 2) & 0x3333U) + (u & 0x3333U);
|
|
||||||
u = ((u >> 4) + u) & 0x0F0FU;
|
|
||||||
return (u * 0x0101U) >> 8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NO_BSF
|
|
||||||
|
|
||||||
/// Software fall-back of lsb() and msb() for CPU lacking hardware support
|
|
||||||
|
|
||||||
Square lsb(Bitboard b) {
|
|
||||||
assert(b);
|
|
||||||
return BSFTable[bsf_index(b)];
|
|
||||||
}
|
|
||||||
|
|
||||||
Square msb(Bitboard b) {
|
|
||||||
|
|
||||||
assert(b);
|
|
||||||
unsigned b32;
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
if (b > 0xFFFFFFFF)
|
|
||||||
{
|
|
||||||
b >>= 32;
|
|
||||||
result = 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
b32 = unsigned(b);
|
|
||||||
|
|
||||||
if (b32 > 0xFFFF)
|
|
||||||
{
|
|
||||||
b32 >>= 16;
|
|
||||||
result += 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b32 > 0xFF)
|
|
||||||
{
|
|
||||||
b32 >>= 8;
|
|
||||||
result += 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Square(result + MSBTable[b32]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ifdef NO_BSF
|
|
||||||
|
|
||||||
|
|
||||||
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
|
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
|
||||||
/// to be printed to standard output. Useful for debugging.
|
/// to be printed to standard output. Useful for debugging.
|
||||||
@@ -142,64 +69,38 @@ const std::string Bitboards::pretty(Bitboard b) {
|
|||||||
void Bitboards::init() {
|
void Bitboards::init() {
|
||||||
|
|
||||||
for (unsigned i = 0; i < (1 << 16); ++i)
|
for (unsigned i = 0; i < (1 << 16); ++i)
|
||||||
PopCnt16[i] = (uint8_t) popcount16(i);
|
PopCnt16[i] = std::bitset<16>(i).count();
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
SquareBB[s] = (1ULL << s);
|
||||||
SquareBB[s] = 1ULL << s;
|
|
||||||
BSFTable[bsf_index(SquareBB[s])] = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Bitboard b = 2; b < 256; ++b)
|
|
||||||
MSBTable[b] = MSBTable[b - 1] + !more_than_one(b);
|
|
||||||
|
|
||||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
|
||||||
FileBB[f] = f > FILE_A ? FileBB[f - 1] << 1 : FileABB;
|
|
||||||
|
|
||||||
for (Rank r = RANK_1; r <= RANK_8; ++r)
|
|
||||||
RankBB[r] = r > RANK_1 ? RankBB[r - 1] << 8 : Rank1BB;
|
|
||||||
|
|
||||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
|
||||||
AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0);
|
|
||||||
|
|
||||||
for (Rank r = RANK_1; r < RANK_8; ++r)
|
|
||||||
ForwardRanksBB[WHITE][r] = ~(ForwardRanksBB[BLACK][r + 1] = ForwardRanksBB[BLACK][r] | RankBB[r]);
|
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
|
||||||
{
|
|
||||||
ForwardFileBB [c][s] = ForwardRanksBB[c][rank_of(s)] & FileBB[file_of(s)];
|
|
||||||
PawnAttackSpan[c][s] = ForwardRanksBB[c][rank_of(s)] & AdjacentFilesBB[file_of(s)];
|
|
||||||
PassedPawnMask[c][s] = ForwardFileBB [c][s] | PawnAttackSpan[c][s];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||||
if (s1 != s2)
|
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
|
||||||
{
|
|
||||||
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
|
|
||||||
DistanceRingBB[s1][SquareDistance[s1][s2] - 1] |= s2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int steps[][5] = { {}, { 7, 9 }, { 6, 10, 15, 17 }, {}, {}, {}, { 1, 7, 8, 9 } };
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
|
{
|
||||||
|
PawnAttacks[WHITE][s] = pawn_attacks_bb<WHITE>(square_bb(s));
|
||||||
|
PawnAttacks[BLACK][s] = pawn_attacks_bb<BLACK>(square_bb(s));
|
||||||
|
}
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
// Helper returning the target bitboard of a step from a square
|
||||||
for (PieceType pt : { PAWN, KNIGHT, KING })
|
auto landing_square_bb = [&](Square s, int step)
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
{
|
||||||
for (int i = 0; steps[pt][i]; ++i)
|
Square to = Square(s + step);
|
||||||
{
|
return is_ok(to) && distance(s, to) <= 2 ? square_bb(to) : Bitboard(0);
|
||||||
Square to = s + Direction(c == WHITE ? steps[pt][i] : -steps[pt][i]);
|
};
|
||||||
|
|
||||||
if (is_ok(to) && distance(s, to) < 3)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
if (pt == PAWN)
|
for (int step : {-9, -8, -7, -1, 1, 7, 8, 9} )
|
||||||
PawnAttacks[c][s] |= to;
|
PseudoAttacks[KING][s] |= landing_square_bb(s, step);
|
||||||
else
|
|
||||||
PseudoAttacks[pt][s] |= to;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
|
for (int step : {-17, -15, -10, -6, 6, 10, 15, 17} )
|
||||||
|
PseudoAttacks[KNIGHT][s] |= landing_square_bb(s, step);
|
||||||
|
}
|
||||||
|
|
||||||
|
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
|
||||||
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
|
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
|
||||||
|
|
||||||
init_magics(RookTable, RookMagics, RookDirections);
|
init_magics(RookTable, RookMagics, RookDirections);
|
||||||
@@ -212,13 +113,8 @@ void Bitboards::init() {
|
|||||||
|
|
||||||
for (PieceType pt : { BISHOP, ROOK })
|
for (PieceType pt : { BISHOP, ROOK })
|
||||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||||
{
|
if (PseudoAttacks[pt][s1] & s2)
|
||||||
if (!(PseudoAttacks[pt][s1] & s2))
|
LineBB[s1][s2] = (attacks_bb(pt, s1, 0) & attacks_bb(pt, s2, 0)) | s1 | s2;
|
||||||
continue;
|
|
||||||
|
|
||||||
LineBB[s1][s2] = (attacks_bb(pt, s1, 0) & attacks_bb(pt, s2, 0)) | s1 | s2;
|
|
||||||
BetweenBB[s1][s2] = attacks_bb(pt, s1, SquareBB[s2]) & attacks_bb(pt, s2, SquareBB[s1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,8 +142,8 @@ namespace {
|
|||||||
|
|
||||||
// init_magics() computes all rook and bishop attacks at startup. Magic
|
// init_magics() computes all rook and bishop attacks at startup. Magic
|
||||||
// bitboards are used to look up attacks of sliding pieces. As a reference see
|
// bitboards are used to look up attacks of sliding pieces. As a reference see
|
||||||
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
|
// www.chessprogramming.org/Magic_Bitboards. In particular, here we use the so
|
||||||
// use the so called "fancy" approach.
|
// called "fancy" approach.
|
||||||
|
|
||||||
void init_magics(Bitboard table[], Magic magics[], Direction directions[]) {
|
void init_magics(Bitboard table[], Magic magics[], Direction directions[]) {
|
||||||
|
|
||||||
|
|||||||
+147
-96
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -39,40 +39,43 @@ const std::string pretty(Bitboard b);
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Bitboard AllSquares = ~Bitboard(0);
|
constexpr Bitboard AllSquares = ~Bitboard(0);
|
||||||
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
constexpr Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
constexpr Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
const Bitboard FileBBB = FileABB << 1;
|
constexpr Bitboard FileBBB = FileABB << 1;
|
||||||
const Bitboard FileCBB = FileABB << 2;
|
constexpr Bitboard FileCBB = FileABB << 2;
|
||||||
const Bitboard FileDBB = FileABB << 3;
|
constexpr Bitboard FileDBB = FileABB << 3;
|
||||||
const Bitboard FileEBB = FileABB << 4;
|
constexpr Bitboard FileEBB = FileABB << 4;
|
||||||
const Bitboard FileFBB = FileABB << 5;
|
constexpr Bitboard FileFBB = FileABB << 5;
|
||||||
const Bitboard FileGBB = FileABB << 6;
|
constexpr Bitboard FileGBB = FileABB << 6;
|
||||||
const Bitboard FileHBB = FileABB << 7;
|
constexpr Bitboard FileHBB = FileABB << 7;
|
||||||
|
|
||||||
const Bitboard Rank1BB = 0xFF;
|
constexpr Bitboard Rank1BB = 0xFF;
|
||||||
const Bitboard Rank2BB = Rank1BB << (8 * 1);
|
constexpr Bitboard Rank2BB = Rank1BB << (8 * 1);
|
||||||
const Bitboard Rank3BB = Rank1BB << (8 * 2);
|
constexpr Bitboard Rank3BB = Rank1BB << (8 * 2);
|
||||||
const Bitboard Rank4BB = Rank1BB << (8 * 3);
|
constexpr Bitboard Rank4BB = Rank1BB << (8 * 3);
|
||||||
const Bitboard Rank5BB = Rank1BB << (8 * 4);
|
constexpr Bitboard Rank5BB = Rank1BB << (8 * 4);
|
||||||
const Bitboard Rank6BB = Rank1BB << (8 * 5);
|
constexpr Bitboard Rank6BB = Rank1BB << (8 * 5);
|
||||||
const Bitboard Rank7BB = Rank1BB << (8 * 6);
|
constexpr Bitboard Rank7BB = Rank1BB << (8 * 6);
|
||||||
const Bitboard Rank8BB = Rank1BB << (8 * 7);
|
constexpr Bitboard Rank8BB = Rank1BB << (8 * 7);
|
||||||
|
|
||||||
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
|
constexpr Bitboard QueenSide = FileABB | FileBBB | FileCBB | FileDBB;
|
||||||
|
constexpr Bitboard CenterFiles = FileCBB | FileDBB | FileEBB | FileFBB;
|
||||||
|
constexpr Bitboard KingSide = FileEBB | FileFBB | FileGBB | FileHBB;
|
||||||
|
constexpr Bitboard Center = (FileDBB | FileEBB) & (Rank4BB | Rank5BB);
|
||||||
|
|
||||||
|
constexpr Bitboard KingFlank[FILE_NB] = {
|
||||||
|
QueenSide ^ FileDBB, QueenSide, QueenSide,
|
||||||
|
CenterFiles, CenterFiles,
|
||||||
|
KingSide, KingSide, KingSide ^ FileEBB
|
||||||
|
};
|
||||||
|
|
||||||
|
extern uint8_t PopCnt16[1 << 16];
|
||||||
|
extern uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
|
|
||||||
extern Bitboard SquareBB[SQUARE_NB];
|
extern Bitboard SquareBB[SQUARE_NB];
|
||||||
extern Bitboard FileBB[FILE_NB];
|
|
||||||
extern Bitboard RankBB[RANK_NB];
|
|
||||||
extern Bitboard AdjacentFilesBB[FILE_NB];
|
|
||||||
extern Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
|
|
||||||
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
|
||||||
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||||
extern Bitboard DistanceRingBB[SQUARE_NB][8];
|
|
||||||
extern Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
|
|
||||||
extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
|
||||||
extern Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
|
||||||
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
||||||
extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||||
|
|
||||||
@@ -102,117 +105,137 @@ struct Magic {
|
|||||||
extern Magic RookMagics[SQUARE_NB];
|
extern Magic RookMagics[SQUARE_NB];
|
||||||
extern Magic BishopMagics[SQUARE_NB];
|
extern Magic BishopMagics[SQUARE_NB];
|
||||||
|
|
||||||
|
inline Bitboard square_bb(Square s) {
|
||||||
|
assert(s >= SQ_A1 && s <= SQ_H8);
|
||||||
|
return SquareBB[s];
|
||||||
|
}
|
||||||
|
|
||||||
/// Overloads of bitwise operators between a Bitboard and a Square for testing
|
/// Overloads of bitwise operators between a Bitboard and a Square for testing
|
||||||
/// whether a given bit is set in a bitboard, and for setting and clearing bits.
|
/// whether a given bit is set in a bitboard, and for setting and clearing bits.
|
||||||
|
|
||||||
inline Bitboard operator&(Bitboard b, Square s) {
|
inline Bitboard operator&( Bitboard b, Square s) { return b & square_bb(s); }
|
||||||
return b & SquareBB[s];
|
inline Bitboard operator|( Bitboard b, Square s) { return b | square_bb(s); }
|
||||||
}
|
inline Bitboard operator^( Bitboard b, Square s) { return b ^ square_bb(s); }
|
||||||
|
inline Bitboard& operator|=(Bitboard& b, Square s) { return b |= square_bb(s); }
|
||||||
|
inline Bitboard& operator^=(Bitboard& b, Square s) { return b ^= square_bb(s); }
|
||||||
|
|
||||||
inline Bitboard operator|(Bitboard b, Square s) {
|
inline Bitboard operator&(Square s, Bitboard b) { return b & s; }
|
||||||
return b | SquareBB[s];
|
inline Bitboard operator|(Square s, Bitboard b) { return b | s; }
|
||||||
}
|
inline Bitboard operator^(Square s, Bitboard b) { return b ^ s; }
|
||||||
|
|
||||||
inline Bitboard operator^(Bitboard b, Square s) {
|
inline Bitboard operator|(Square s, Square s2) { return square_bb(s) | square_bb(s2); }
|
||||||
return b ^ SquareBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard& operator|=(Bitboard& b, Square s) {
|
|
||||||
return b |= SquareBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard& operator^=(Bitboard& b, Square s) {
|
|
||||||
return b ^= SquareBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool more_than_one(Bitboard b) {
|
constexpr bool more_than_one(Bitboard b) {
|
||||||
return b & (b - 1);
|
return b & (b - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool opposite_colors(Square s1, Square s2) {
|
||||||
|
return bool(DarkSquares & s1) != bool(DarkSquares & s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
||||||
/// the given file or rank.
|
/// the given file or rank.
|
||||||
|
|
||||||
inline Bitboard rank_bb(Rank r) {
|
inline Bitboard rank_bb(Rank r) {
|
||||||
return RankBB[r];
|
return Rank1BB << (8 * r);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard rank_bb(Square s) {
|
inline Bitboard rank_bb(Square s) {
|
||||||
return RankBB[rank_of(s)];
|
return rank_bb(rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard file_bb(File f) {
|
inline Bitboard file_bb(File f) {
|
||||||
return FileBB[f];
|
return FileABB << f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard file_bb(Square s) {
|
inline Bitboard file_bb(Square s) {
|
||||||
return FileBB[file_of(s)];
|
return file_bb(file_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// shift() moves a bitboard one step along direction D. Mainly for pawns
|
/// shift() moves a bitboard one step along direction D
|
||||||
|
|
||||||
template<Direction D>
|
template<Direction D>
|
||||||
constexpr Bitboard shift(Bitboard b) {
|
constexpr Bitboard shift(Bitboard b) {
|
||||||
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
|
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
|
||||||
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7
|
: D == NORTH+NORTH? b <<16 : D == SOUTH+SOUTH? b >>16
|
||||||
: D == NORTH_WEST ? (b & ~FileABB) << 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
|
: D == EAST ? (b & ~FileHBB) << 1 : D == WEST ? (b & ~FileABB) >> 1
|
||||||
|
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == NORTH_WEST ? (b & ~FileABB) << 7
|
||||||
|
: D == SOUTH_EAST ? (b & ~FileHBB) >> 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// pawn_attacks_bb() returns the squares attacked by pawns of the given color
|
||||||
|
/// from the squares in the given bitboard.
|
||||||
|
|
||||||
|
template<Color C>
|
||||||
|
constexpr Bitboard pawn_attacks_bb(Bitboard b) {
|
||||||
|
return C == WHITE ? shift<NORTH_WEST>(b) | shift<NORTH_EAST>(b)
|
||||||
|
: shift<SOUTH_WEST>(b) | shift<SOUTH_EAST>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// pawn_double_attacks_bb() returns the squares doubly attacked by pawns of the
|
||||||
|
/// given color from the squares in the given bitboard.
|
||||||
|
|
||||||
|
template<Color C>
|
||||||
|
constexpr Bitboard pawn_double_attacks_bb(Bitboard b) {
|
||||||
|
return C == WHITE ? shift<NORTH_WEST>(b) & shift<NORTH_EAST>(b)
|
||||||
|
: shift<SOUTH_WEST>(b) & shift<SOUTH_EAST>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// adjacent_files_bb() returns a bitboard representing all the squares on the
|
/// adjacent_files_bb() returns a bitboard representing all the squares on the
|
||||||
/// adjacent files of the given one.
|
/// adjacent files of the given one.
|
||||||
|
|
||||||
inline Bitboard adjacent_files_bb(File f) {
|
inline Bitboard adjacent_files_bb(Square s) {
|
||||||
return AdjacentFilesBB[f];
|
return shift<EAST>(file_bb(s)) | shift<WEST>(file_bb(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// between_bb() returns a bitboard representing all the squares between the two
|
/// between_bb() returns squares that are linearly between the given squares
|
||||||
/// given ones. For instance, between_bb(SQ_C4, SQ_F7) returns a bitboard with
|
/// If the given squares are not on a same file/rank/diagonal, return 0.
|
||||||
/// the bits for square d5 and e6 set. If s1 and s2 are not on the same rank, file
|
|
||||||
/// or diagonal, 0 is returned.
|
|
||||||
|
|
||||||
inline Bitboard between_bb(Square s1, Square s2) {
|
inline Bitboard between_bb(Square s1, Square s2) {
|
||||||
return BetweenBB[s1][s2];
|
return LineBB[s1][s2] & ( (AllSquares << (s1 + (s1 < s2)))
|
||||||
|
^(AllSquares << (s2 + !(s1 < s2))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// forward_ranks_bb() returns a bitboard representing all the squares on all the ranks
|
/// forward_ranks_bb() returns a bitboard representing the squares on the ranks
|
||||||
/// in front of the given one, from the point of view of the given color. For
|
/// in front of the given one, from the point of view of the given color. For instance,
|
||||||
/// instance, forward_ranks_bb(BLACK, SQ_D3) will return the 16 squares on ranks 1 and 2.
|
/// forward_ranks_bb(BLACK, SQ_D3) will return the 16 squares on ranks 1 and 2.
|
||||||
|
|
||||||
inline Bitboard forward_ranks_bb(Color c, Square s) {
|
inline Bitboard forward_ranks_bb(Color c, Square s) {
|
||||||
return ForwardRanksBB[c][rank_of(s)];
|
return c == WHITE ? ~Rank1BB << 8 * (rank_of(s) - RANK_1)
|
||||||
|
: ~Rank8BB >> 8 * (RANK_8 - rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// forward_file_bb() returns a bitboard representing all the squares along the line
|
/// forward_file_bb() returns a bitboard representing all the squares along the
|
||||||
/// in front of the given one, from the point of view of the given color:
|
/// line in front of the given one, from the point of view of the given color.
|
||||||
/// ForwardFileBB[c][s] = forward_ranks_bb(c, s) & file_bb(s)
|
|
||||||
|
|
||||||
inline Bitboard forward_file_bb(Color c, Square s) {
|
inline Bitboard forward_file_bb(Color c, Square s) {
|
||||||
return ForwardFileBB[c][s];
|
return forward_ranks_bb(c, s) & file_bb(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// pawn_attack_span() returns a bitboard representing all the squares that can be
|
/// pawn_attack_span() returns a bitboard representing all the squares that can
|
||||||
/// attacked by a pawn of the given color when it moves along its file, starting
|
/// be attacked by a pawn of the given color when it moves along its file,
|
||||||
/// from the given square:
|
/// starting from the given square.
|
||||||
/// PawnAttackSpan[c][s] = forward_ranks_bb(c, s) & adjacent_files_bb(file_of(s));
|
|
||||||
|
|
||||||
inline Bitboard pawn_attack_span(Color c, Square s) {
|
inline Bitboard pawn_attack_span(Color c, Square s) {
|
||||||
return PawnAttackSpan[c][s];
|
return forward_ranks_bb(c, s) & adjacent_files_bb(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// passed_pawn_mask() returns a bitboard mask which can be used to test if a
|
/// passed_pawn_span() returns a bitboard which can be used to test if a pawn of
|
||||||
/// pawn of the given color and on the given square is a passed pawn:
|
/// the given color and on the given square is a passed pawn.
|
||||||
/// PassedPawnMask[c][s] = pawn_attack_span(c, s) | forward_file_bb(c, s)
|
|
||||||
|
|
||||||
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
inline Bitboard passed_pawn_span(Color c, Square s) {
|
||||||
return PassedPawnMask[c][s];
|
return forward_ranks_bb(c, s) & (adjacent_files_bb(s) | file_bb(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -225,15 +248,16 @@ inline bool aligned(Square s1, Square s2, Square s3) {
|
|||||||
|
|
||||||
|
|
||||||
/// distance() functions return the distance between x and y, defined as the
|
/// distance() functions return the distance between x and y, defined as the
|
||||||
/// number of steps for a king in x to reach y. Works with squares, ranks, files.
|
/// number of steps for a king in x to reach y.
|
||||||
|
|
||||||
template<typename T> inline int distance(T x, T y) { return x < y ? y - x : x - y; }
|
template<typename T1 = Square> inline int distance(Square x, Square y);
|
||||||
|
template<> inline int distance<File>(Square x, Square y) { return std::abs(file_of(x) - file_of(y)); }
|
||||||
|
template<> inline int distance<Rank>(Square x, Square y) { return std::abs(rank_of(x) - rank_of(y)); }
|
||||||
template<> inline int distance<Square>(Square x, Square y) { return SquareDistance[x][y]; }
|
template<> inline int distance<Square>(Square x, Square y) { return SquareDistance[x][y]; }
|
||||||
|
|
||||||
template<typename T1, typename T2> inline int distance(T2 x, T2 y);
|
template<class T> constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
|
||||||
template<> inline int distance<File>(Square x, Square y) { return distance(file_of(x), file_of(y)); }
|
return v < lo ? lo : v > hi ? hi : v;
|
||||||
template<> inline int distance<Rank>(Square x, Square y) { return distance(rank_of(x), rank_of(y)); }
|
}
|
||||||
|
|
||||||
|
|
||||||
/// attacks_bb() returns a bitboard representing all the squares attacked by a
|
/// attacks_bb() returns a bitboard representing all the squares attacked by a
|
||||||
/// piece of type Pt (bishop or rook) placed on 's'.
|
/// piece of type Pt (bishop or rook) placed on 's'.
|
||||||
@@ -265,7 +289,6 @@ inline int popcount(Bitboard b) {
|
|||||||
|
|
||||||
#ifndef USE_POPCNT
|
#ifndef USE_POPCNT
|
||||||
|
|
||||||
extern uint8_t PopCnt16[1 << 16];
|
|
||||||
union { Bitboard bb; uint16_t u[4]; } v = { b };
|
union { Bitboard bb; uint16_t u[4]; } v = { b };
|
||||||
return PopCnt16[v.u[0]] + PopCnt16[v.u[1]] + PopCnt16[v.u[2]] + PopCnt16[v.u[3]];
|
return PopCnt16[v.u[0]] + PopCnt16[v.u[1]] + PopCnt16[v.u[2]] + PopCnt16[v.u[3]];
|
||||||
|
|
||||||
@@ -283,7 +306,7 @@ inline int popcount(Bitboard b) {
|
|||||||
|
|
||||||
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
|
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__) // GCC, Clang, ICC
|
||||||
|
|
||||||
inline Square lsb(Bitboard b) {
|
inline Square lsb(Bitboard b) {
|
||||||
assert(b);
|
assert(b);
|
||||||
@@ -295,7 +318,9 @@ inline Square msb(Bitboard b) {
|
|||||||
return Square(63 ^ __builtin_clzll(b));
|
return Square(63 ^ __builtin_clzll(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(_WIN64) && defined(_MSC_VER)
|
#elif defined(_MSC_VER) // MSVC
|
||||||
|
|
||||||
|
#ifdef _WIN64 // MSVC, WIN64
|
||||||
|
|
||||||
inline Square lsb(Bitboard b) {
|
inline Square lsb(Bitboard b) {
|
||||||
assert(b);
|
assert(b);
|
||||||
@@ -311,12 +336,39 @@ inline Square msb(Bitboard b) {
|
|||||||
return (Square) idx;
|
return (Square) idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else // MSVC, WIN32
|
||||||
|
|
||||||
#define NO_BSF // Fallback on software implementation for other cases
|
inline Square lsb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
unsigned long idx;
|
||||||
|
|
||||||
Square lsb(Bitboard b);
|
if (b & 0xffffffff) {
|
||||||
Square msb(Bitboard b);
|
_BitScanForward(&idx, int32_t(b));
|
||||||
|
return Square(idx);
|
||||||
|
} else {
|
||||||
|
_BitScanForward(&idx, int32_t(b >> 32));
|
||||||
|
return Square(idx + 32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Square msb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
unsigned long idx;
|
||||||
|
|
||||||
|
if (b >> 32) {
|
||||||
|
_BitScanReverse(&idx, int32_t(b >> 32));
|
||||||
|
return Square(idx + 32);
|
||||||
|
} else {
|
||||||
|
_BitScanReverse(&idx, int32_t(b));
|
||||||
|
return Square(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else // Compiler is neither GCC nor MSVC compatible
|
||||||
|
|
||||||
|
#error "Compiler not supported."
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -330,10 +382,9 @@ inline Square pop_lsb(Bitboard* b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// frontmost_sq() and backmost_sq() return the square corresponding to the
|
/// frontmost_sq() returns the most advanced square for the given color
|
||||||
/// most/least advanced bit relative to the given color.
|
inline Square frontmost_sq(Color c, Bitboard b) {
|
||||||
|
return c == WHITE ? msb(b) : lsb(b);
|
||||||
inline Square frontmost_sq(Color c, Bitboard b) { return c == WHITE ? msb(b) : lsb(b); }
|
}
|
||||||
inline Square backmost_sq(Color c, Bitboard b) { return c == WHITE ? lsb(b) : msb(b); }
|
|
||||||
|
|
||||||
#endif // #ifndef BITBOARD_H_INCLUDED
|
#endif // #ifndef BITBOARD_H_INCLUDED
|
||||||
|
|||||||
+67
-77
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
@@ -31,7 +30,7 @@ namespace {
|
|||||||
|
|
||||||
// Table used to drive the king towards the edge of the board
|
// Table used to drive the king towards the edge of the board
|
||||||
// in KX vs K and KQ vs KR endgames.
|
// in KX vs K and KQ vs KR endgames.
|
||||||
const int PushToEdges[SQUARE_NB] = {
|
constexpr int PushToEdges[SQUARE_NB] = {
|
||||||
100, 90, 80, 70, 70, 80, 90, 100,
|
100, 90, 80, 70, 70, 80, 90, 100,
|
||||||
90, 70, 60, 50, 50, 60, 70, 90,
|
90, 70, 60, 50, 50, 60, 70, 90,
|
||||||
80, 60, 40, 30, 30, 40, 60, 80,
|
80, 60, 40, 30, 30, 40, 60, 80,
|
||||||
@@ -44,23 +43,23 @@ namespace {
|
|||||||
|
|
||||||
// Table used to drive the king towards a corner square of the
|
// Table used to drive the king towards a corner square of the
|
||||||
// right color in KBN vs K endgames.
|
// right color in KBN vs K endgames.
|
||||||
const int PushToCorners[SQUARE_NB] = {
|
constexpr int PushToCorners[SQUARE_NB] = {
|
||||||
200, 190, 180, 170, 160, 150, 140, 130,
|
6400, 6080, 5760, 5440, 5120, 4800, 4480, 4160,
|
||||||
190, 180, 170, 160, 150, 140, 130, 140,
|
6080, 5760, 5440, 5120, 4800, 4480, 4160, 4480,
|
||||||
180, 170, 155, 140, 140, 125, 140, 150,
|
5760, 5440, 4960, 4480, 4480, 4000, 4480, 4800,
|
||||||
170, 160, 140, 120, 110, 140, 150, 160,
|
5440, 5120, 4480, 3840, 3520, 4480, 4800, 5120,
|
||||||
160, 150, 140, 110, 120, 140, 160, 170,
|
5120, 4800, 4480, 3520, 3840, 4480, 5120, 5440,
|
||||||
150, 140, 125, 140, 140, 155, 170, 180,
|
4800, 4480, 4000, 4480, 4480, 4960, 5440, 5760,
|
||||||
140, 130, 140, 150, 160, 170, 180, 190,
|
4480, 4160, 4480, 4800, 5120, 5440, 5760, 6080,
|
||||||
130, 140, 150, 160, 170, 180, 190, 200
|
4160, 4480, 4800, 5120, 5440, 5760, 6080, 6400
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tables used to drive a piece towards or away from another piece
|
// Tables used to drive a piece towards or away from another piece
|
||||||
const int PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
|
constexpr int PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
|
||||||
const int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
|
constexpr int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
|
||||||
|
|
||||||
// Pawn Rank based scaling factors used in KRPPKRP endgame
|
// Pawn Rank based scaling factors used in KRPPKRP endgame
|
||||||
const int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
|
constexpr int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
|
bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
|
||||||
@@ -75,38 +74,39 @@ namespace {
|
|||||||
assert(pos.count<PAWN>(strongSide) == 1);
|
assert(pos.count<PAWN>(strongSide) == 1);
|
||||||
|
|
||||||
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
|
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
|
||||||
sq = Square(sq ^ 7); // Mirror SQ_H1 -> SQ_A1
|
sq = Square(int(sq) ^ 7); // Mirror SQ_H1 -> SQ_A1
|
||||||
|
|
||||||
if (strongSide == BLACK)
|
return strongSide == WHITE ? sq : ~sq;
|
||||||
sq = ~sq;
|
|
||||||
|
|
||||||
return sq;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
/// Endgames members definitions
|
namespace Endgames {
|
||||||
|
|
||||||
Endgames::Endgames() {
|
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||||
|
|
||||||
add<KPK>("KPK");
|
void init() {
|
||||||
add<KNNK>("KNNK");
|
|
||||||
add<KBNK>("KBNK");
|
|
||||||
add<KRKP>("KRKP");
|
|
||||||
add<KRKB>("KRKB");
|
|
||||||
add<KRKN>("KRKN");
|
|
||||||
add<KQKP>("KQKP");
|
|
||||||
add<KQKR>("KQKR");
|
|
||||||
|
|
||||||
add<KNPK>("KNPK");
|
add<KPK>("KPK");
|
||||||
add<KNPKB>("KNPKB");
|
add<KNNK>("KNNK");
|
||||||
add<KRPKR>("KRPKR");
|
add<KBNK>("KBNK");
|
||||||
add<KRPKB>("KRPKB");
|
add<KRKP>("KRKP");
|
||||||
add<KBPKB>("KBPKB");
|
add<KRKB>("KRKB");
|
||||||
add<KBPKN>("KBPKN");
|
add<KRKN>("KRKN");
|
||||||
add<KBPPKB>("KBPPKB");
|
add<KQKP>("KQKP");
|
||||||
add<KRPPKRP>("KRPPKRP");
|
add<KQKR>("KQKR");
|
||||||
|
add<KNNKP>("KNNKP");
|
||||||
|
|
||||||
|
add<KNPK>("KNPK");
|
||||||
|
add<KNPKB>("KNPKB");
|
||||||
|
add<KRPKR>("KRPKR");
|
||||||
|
add<KRPKB>("KRPKB");
|
||||||
|
add<KBPKB>("KBPKB");
|
||||||
|
add<KBPKN>("KBPKN");
|
||||||
|
add<KBPPKB>("KBPPKB");
|
||||||
|
add<KRPPKRP>("KRPPKRP");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
|
|||||||
|
|
||||||
|
|
||||||
/// Mate with KBN vs K. This is similar to KX vs K, but we have to drive the
|
/// Mate with KBN vs K. This is similar to KX vs K, but we have to drive the
|
||||||
/// defending king towards a corner square of the right color.
|
/// defending king towards a corner square that our bishop attacks.
|
||||||
template<>
|
template<>
|
||||||
Value Endgame<KBNK>::operator()(const Position& pos) const {
|
Value Endgame<KBNK>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
@@ -155,24 +155,19 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
|
|||||||
Square loserKSq = pos.square<KING>(weakSide);
|
Square loserKSq = pos.square<KING>(weakSide);
|
||||||
Square bishopSq = pos.square<BISHOP>(strongSide);
|
Square bishopSq = pos.square<BISHOP>(strongSide);
|
||||||
|
|
||||||
// kbnk_mate_table() tries to drive toward corners A1 or H8. If we have a
|
// If our bishop does not attack A1/H8, we flip the enemy king square
|
||||||
// bishop that cannot reach the above squares, we flip the kings in order
|
// to drive to opposite corners (A8/H1).
|
||||||
// to drive the enemy toward corners A8 or H1.
|
|
||||||
if (opposite_colors(bishopSq, SQ_A1))
|
|
||||||
{
|
|
||||||
winnerKSq = ~winnerKSq;
|
|
||||||
loserKSq = ~loserKSq;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value result = VALUE_KNOWN_WIN
|
Value result = VALUE_KNOWN_WIN
|
||||||
+ PushClose[distance(winnerKSq, loserKSq)]
|
+ PushClose[distance(winnerKSq, loserKSq)]
|
||||||
+ PushToCorners[loserKSq];
|
+ PushToCorners[opposite_colors(bishopSq, SQ_A1) ? ~loserKSq : loserKSq];
|
||||||
|
|
||||||
|
assert(abs(result) < VALUE_MATE_IN_MAX_PLY);
|
||||||
return strongSide == pos.side_to_move() ? result : -result;
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// KP vs K. This endgame is evaluated with the help of a bitbase.
|
/// KP vs K. This endgame is evaluated with the help of a bitbase
|
||||||
template<>
|
template<>
|
||||||
Value Endgame<KPK>::operator()(const Position& pos) const {
|
Value Endgame<KPK>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
@@ -214,7 +209,7 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
|||||||
Value result;
|
Value result;
|
||||||
|
|
||||||
// If the stronger side's king is in front of the pawn, it's a win
|
// If the stronger side's king is in front of the pawn, it's a win
|
||||||
if (wksq < psq && file_of(wksq) == file_of(psq))
|
if (forward_file_bb(WHITE, wksq) & psq)
|
||||||
result = RookValueEg - distance(wksq, psq);
|
result = RookValueEg - distance(wksq, psq);
|
||||||
|
|
||||||
// If the weaker side's king is too far from the pawn and the rook,
|
// If the weaker side's king is too far from the pawn and the rook,
|
||||||
@@ -240,7 +235,7 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// KR vs KB. This is very simple, and always returns drawish scores. The
|
/// KR vs KB. This is very simple, and always returns drawish scores. The
|
||||||
/// score is slightly bigger when the defending king is close to the edge.
|
/// score is slightly bigger when the defending king is close to the edge.
|
||||||
template<>
|
template<>
|
||||||
Value Endgame<KRKB>::operator()(const Position& pos) const {
|
Value Endgame<KRKB>::operator()(const Position& pos) const {
|
||||||
@@ -315,6 +310,21 @@ Value Endgame<KQKR>::operator()(const Position& pos) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// KNN vs KP. Simply push the opposing king to the corner
|
||||||
|
template<>
|
||||||
|
Value Endgame<KNNKP>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
|
assert(verify_material(pos, strongSide, 2 * KnightValueMg, 0));
|
||||||
|
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
|
||||||
|
|
||||||
|
Value result = 2 * KnightValueEg
|
||||||
|
- PawnValueEg
|
||||||
|
+ PushToEdges[pos.square<KING>(weakSide)];
|
||||||
|
|
||||||
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Some cases of trivial draws
|
/// Some cases of trivial draws
|
||||||
template<> Value Endgame<KNNK>::operator()(const Position&) const { return VALUE_DRAW; }
|
template<> Value Endgame<KNNK>::operator()(const Position&) const { return VALUE_DRAW; }
|
||||||
|
|
||||||
@@ -355,7 +365,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
|
|||||||
&& pos.count<PAWN>(weakSide) >= 1)
|
&& pos.count<PAWN>(weakSide) >= 1)
|
||||||
{
|
{
|
||||||
// Get weakSide pawn that is closest to the home rank
|
// Get weakSide pawn that is closest to the home rank
|
||||||
Square weakPawnSq = backmost_sq(weakSide, pos.pieces(weakSide, PAWN));
|
Square weakPawnSq = frontmost_sq(strongSide, pos.pieces(weakSide, PAWN));
|
||||||
|
|
||||||
Square strongKingSq = pos.square<KING>(strongSide);
|
Square strongKingSq = pos.square<KING>(strongSide);
|
||||||
Square weakKingSq = pos.square<KING>(weakSide);
|
Square weakKingSq = pos.square<KING>(weakSide);
|
||||||
@@ -631,29 +641,8 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
|
|||||||
|
|
||||||
// Case 2: Opposite colored bishops
|
// Case 2: Opposite colored bishops
|
||||||
if (opposite_colors(strongBishopSq, weakBishopSq))
|
if (opposite_colors(strongBishopSq, weakBishopSq))
|
||||||
{
|
return SCALE_FACTOR_DRAW;
|
||||||
// We assume that the position is drawn in the following three situations:
|
|
||||||
//
|
|
||||||
// a. The pawn is on rank 5 or further back.
|
|
||||||
// b. The defending king is somewhere in the pawn's path.
|
|
||||||
// c. The defending bishop attacks some square along the pawn's path,
|
|
||||||
// and is at least three squares away from the pawn.
|
|
||||||
//
|
|
||||||
// These rules are probably not perfect, but in practice they work
|
|
||||||
// reasonably well.
|
|
||||||
|
|
||||||
if (relative_rank(strongSide, pawnSq) <= RANK_5)
|
|
||||||
return SCALE_FACTOR_DRAW;
|
|
||||||
|
|
||||||
Bitboard path = forward_file_bb(strongSide, pawnSq);
|
|
||||||
|
|
||||||
if (path & pos.pieces(weakSide, KING))
|
|
||||||
return SCALE_FACTOR_DRAW;
|
|
||||||
|
|
||||||
if ( (pos.attacks_from<BISHOP>(weakBishopSq) & path)
|
|
||||||
&& distance(weakBishopSq, pawnSq) >= 3)
|
|
||||||
return SCALE_FACTOR_DRAW;
|
|
||||||
}
|
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,8 +663,6 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
|
|||||||
Square ksq = pos.square<KING>(weakSide);
|
Square ksq = pos.square<KING>(weakSide);
|
||||||
Square psq1 = pos.squares<PAWN>(strongSide)[0];
|
Square psq1 = pos.squares<PAWN>(strongSide)[0];
|
||||||
Square psq2 = pos.squares<PAWN>(strongSide)[1];
|
Square psq2 = pos.squares<PAWN>(strongSide)[1];
|
||||||
Rank r1 = rank_of(psq1);
|
|
||||||
Rank r2 = rank_of(psq2);
|
|
||||||
Square blockSq1, blockSq2;
|
Square blockSq1, blockSq2;
|
||||||
|
|
||||||
if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2))
|
if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2))
|
||||||
@@ -709,7 +696,7 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
|
|||||||
&& opposite_colors(ksq, wbsq)
|
&& opposite_colors(ksq, wbsq)
|
||||||
&& ( bbsq == blockSq2
|
&& ( bbsq == blockSq2
|
||||||
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(weakSide, BISHOP))
|
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(weakSide, BISHOP))
|
||||||
|| distance(r1, r2) >= 2))
|
|| distance<Rank>(psq1, psq2) >= 2))
|
||||||
return SCALE_FACTOR_DRAW;
|
return SCALE_FACTOR_DRAW;
|
||||||
|
|
||||||
else if ( ksq == blockSq2
|
else if ( ksq == blockSq2
|
||||||
@@ -774,6 +761,9 @@ ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
|
|||||||
template<>
|
template<>
|
||||||
ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
|
ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
|
assert(verify_material(pos, strongSide, KnightValueMg, 1));
|
||||||
|
assert(verify_material(pos, weakSide, BishopValueMg, 0));
|
||||||
|
|
||||||
Square pawnSq = pos.square<PAWN>(strongSide);
|
Square pawnSq = pos.square<PAWN>(strongSide);
|
||||||
Square bishopSq = pos.square<BISHOP>(weakSide);
|
Square bishopSq = pos.square<BISHOP>(weakSide);
|
||||||
Square weakKingSq = pos.square<KING>(weakSide);
|
Square weakKingSq = pos.square<KING>(weakSide);
|
||||||
|
|||||||
+18
-16
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
#ifndef ENDGAME_H_INCLUDED
|
#ifndef ENDGAME_H_INCLUDED
|
||||||
#define ENDGAME_H_INCLUDED
|
#define ENDGAME_H_INCLUDED
|
||||||
|
|
||||||
#include <map>
|
#include <unordered_map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -37,6 +37,7 @@ enum EndgameCode {
|
|||||||
|
|
||||||
EVALUATION_FUNCTIONS,
|
EVALUATION_FUNCTIONS,
|
||||||
KNNK, // KNN vs K
|
KNNK, // KNN vs K
|
||||||
|
KNNKP, // KNN vs KP
|
||||||
KXK, // Generic "mate lone king" eval
|
KXK, // Generic "mate lone king" eval
|
||||||
KBNK, // KBN vs K
|
KBNK, // KBN vs K
|
||||||
KPK, // KP vs K
|
KPK, // KP vs K
|
||||||
@@ -64,6 +65,7 @@ enum EndgameCode {
|
|||||||
|
|
||||||
/// Endgame functions can be of two types depending on whether they return a
|
/// Endgame functions can be of two types depending on whether they return a
|
||||||
/// Value or a ScaleFactor.
|
/// Value or a ScaleFactor.
|
||||||
|
|
||||||
template<EndgameCode E> using
|
template<EndgameCode E> using
|
||||||
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
||||||
|
|
||||||
@@ -89,37 +91,37 @@ struct Endgame : public EndgameBase<T> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// The Endgames class stores the pointers to endgame evaluation and scaling
|
/// The Endgames namespace handles the pointers to endgame evaluation and scaling
|
||||||
/// base objects in two std::map. We use polymorphism to invoke the actual
|
/// base objects in two std::map. We use polymorphism to invoke the actual
|
||||||
/// endgame function by calling its virtual operator().
|
/// endgame function by calling its virtual operator().
|
||||||
|
|
||||||
class Endgames {
|
namespace Endgames {
|
||||||
|
|
||||||
template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
|
template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
|
||||||
template<typename T> using Map = std::map<Key, Ptr<T>>;
|
template<typename T> using Map = std::unordered_map<Key, Ptr<T>>;
|
||||||
|
|
||||||
|
extern std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Map<T>& map() {
|
Map<T>& map() {
|
||||||
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<EndgameCode E, typename T = eg_type<E>, typename P = Ptr<T>>
|
template<EndgameCode E, typename T = eg_type<E>>
|
||||||
void add(const std::string& code) {
|
void add(const std::string& code) {
|
||||||
|
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
map<T>()[Position().set(code, WHITE, &st).material_key()] = P(new Endgame<E>(WHITE));
|
map<T>()[Position().set(code, WHITE, &st).material_key()] = Ptr<T>(new Endgame<E>(WHITE));
|
||||||
map<T>()[Position().set(code, BLACK, &st).material_key()] = P(new Endgame<E>(BLACK));
|
map<T>()[Position().set(code, BLACK, &st).material_key()] = Ptr<T>(new Endgame<E>(BLACK));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Endgames();
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
EndgameBase<T>* probe(Key key) {
|
const EndgameBase<T>* probe(Key key) {
|
||||||
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
|
auto it = map<T>().find(key);
|
||||||
|
return it != map<T>().end() ? it->second.get() : nullptr;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
#endif // #ifndef ENDGAME_H_INCLUDED
|
#endif // #ifndef ENDGAME_H_INCLUDED
|
||||||
|
|||||||
+527
-591
File diff suppressed because it is too large
Load Diff
+2
-4
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,9 +29,7 @@ class Position;
|
|||||||
|
|
||||||
namespace Eval {
|
namespace Eval {
|
||||||
|
|
||||||
const Value Tempo = Value(20); // Must be visible to search
|
constexpr Value Tempo = Value(28); // Must be visible to search
|
||||||
|
|
||||||
extern Score Contempt;
|
|
||||||
|
|
||||||
std::string trace(const Position& pos);
|
std::string trace(const Position& pos);
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,7 @@
|
|||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "endgame.h"
|
||||||
#include "syzygy/tbprobe.h"
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
namespace PSQT {
|
namespace PSQT {
|
||||||
@@ -41,10 +42,7 @@ int main(int argc, char* argv[]) {
|
|||||||
Bitboards::init();
|
Bitboards::init();
|
||||||
Position::init();
|
Position::init();
|
||||||
Bitbases::init();
|
Bitbases::init();
|
||||||
Search::init();
|
Endgames::init();
|
||||||
Pawns::init();
|
|
||||||
Tablebases::init(Options["SyzygyPath"]);
|
|
||||||
TT.resize(Options["Hash"]);
|
|
||||||
Threads.set(Options["Threads"]);
|
Threads.set(Options["Threads"]);
|
||||||
Search::clear(); // After threads are up
|
Search::clear(); // After threads are up
|
||||||
|
|
||||||
|
|||||||
+19
-28
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm> // For std::min
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring> // For std::memset
|
#include <cstring> // For std::memset
|
||||||
|
|
||||||
@@ -31,18 +30,18 @@ namespace {
|
|||||||
|
|
||||||
// Polynomial material imbalance parameters
|
// Polynomial material imbalance parameters
|
||||||
|
|
||||||
const int QuadraticOurs[][PIECE_TYPE_NB] = {
|
constexpr int QuadraticOurs[][PIECE_TYPE_NB] = {
|
||||||
// OUR PIECES
|
// OUR PIECES
|
||||||
// pair pawn knight bishop rook queen
|
// pair pawn knight bishop rook queen
|
||||||
{1667 }, // Bishop pair
|
{1438 }, // Bishop pair
|
||||||
{ 40, 0 }, // Pawn
|
{ 40, 38 }, // Pawn
|
||||||
{ 32, 255, -3 }, // Knight OUR PIECES
|
{ 32, 255, -62 }, // Knight OUR PIECES
|
||||||
{ 0, 104, 4, 0 }, // Bishop
|
{ 0, 104, 4, 0 }, // Bishop
|
||||||
{ -26, -2, 47, 105, -149 }, // Rook
|
{ -26, -2, 47, 105, -208 }, // Rook
|
||||||
{-189, 24, 117, 133, -134, -10 } // Queen
|
{-189, 24, 117, 133, -134, -6 } // Queen
|
||||||
};
|
};
|
||||||
|
|
||||||
const int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
constexpr int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
||||||
// THEIR PIECES
|
// THEIR PIECES
|
||||||
// pair pawn knight bishop rook queen
|
// pair pawn knight bishop rook queen
|
||||||
{ 0 }, // Bishop pair
|
{ 0 }, // Bishop pair
|
||||||
@@ -68,16 +67,14 @@ namespace {
|
|||||||
&& pos.non_pawn_material(us) >= RookValueMg;
|
&& pos.non_pawn_material(us) >= RookValueMg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_KBPsKs(const Position& pos, Color us) {
|
bool is_KBPsK(const Position& pos, Color us) {
|
||||||
return pos.non_pawn_material(us) == BishopValueMg
|
return pos.non_pawn_material(us) == BishopValueMg
|
||||||
&& pos.count<BISHOP>(us) == 1
|
|
||||||
&& pos.count<PAWN >(us) >= 1;
|
&& pos.count<PAWN >(us) >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_KQKRPs(const Position& pos, Color us) {
|
bool is_KQKRPs(const Position& pos, Color us) {
|
||||||
return !pos.count<PAWN>(us)
|
return !pos.count<PAWN>(us)
|
||||||
&& pos.non_pawn_material(us) == QueenValueMg
|
&& pos.non_pawn_material(us) == QueenValueMg
|
||||||
&& pos.count<QUEEN>(us) == 1
|
|
||||||
&& pos.count<ROOK>(~us) == 1
|
&& pos.count<ROOK>(~us) == 1
|
||||||
&& pos.count<PAWN>(~us) >= 1;
|
&& pos.count<PAWN>(~us) >= 1;
|
||||||
}
|
}
|
||||||
@@ -87,7 +84,7 @@ namespace {
|
|||||||
template<Color Us>
|
template<Color Us>
|
||||||
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
int bonus = 0;
|
int bonus = 0;
|
||||||
|
|
||||||
@@ -132,7 +129,7 @@ Entry* probe(const Position& pos) {
|
|||||||
|
|
||||||
Value npm_w = pos.non_pawn_material(WHITE);
|
Value npm_w = pos.non_pawn_material(WHITE);
|
||||||
Value npm_b = pos.non_pawn_material(BLACK);
|
Value npm_b = pos.non_pawn_material(BLACK);
|
||||||
Value npm = std::max(EndgameLimit, std::min(npm_w + npm_b, MidgameLimit));
|
Value npm = clamp(npm_w + npm_b, EndgameLimit, MidgameLimit);
|
||||||
|
|
||||||
// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
|
// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
|
||||||
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
|
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
|
||||||
@@ -140,10 +137,10 @@ Entry* probe(const Position& pos) {
|
|||||||
// Let's look if we have a specialized evaluation function for this particular
|
// Let's look if we have a specialized evaluation function for this particular
|
||||||
// material configuration. Firstly we look for a fixed configuration one, then
|
// material configuration. Firstly we look for a fixed configuration one, then
|
||||||
// for a generic one if the previous search failed.
|
// for a generic one if the previous search failed.
|
||||||
if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)
|
if ((e->evaluationFunction = Endgames::probe<Value>(key)) != nullptr)
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
for (Color c : { WHITE, BLACK })
|
||||||
if (is_KXK(pos, c))
|
if (is_KXK(pos, c))
|
||||||
{
|
{
|
||||||
e->evaluationFunction = &EvaluateKXK[c];
|
e->evaluationFunction = &EvaluateKXK[c];
|
||||||
@@ -152,9 +149,9 @@ Entry* probe(const Position& pos) {
|
|||||||
|
|
||||||
// OK, we didn't find any special evaluation function for the current material
|
// OK, we didn't find any special evaluation function for the current material
|
||||||
// configuration. Is there a suitable specialized scaling function?
|
// configuration. Is there a suitable specialized scaling function?
|
||||||
EndgameBase<ScaleFactor>* sf;
|
const auto* sf = Endgames::probe<ScaleFactor>(key);
|
||||||
|
|
||||||
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
|
if (sf)
|
||||||
{
|
{
|
||||||
e->scalingFunction[sf->strongSide] = sf; // Only strong color assigned
|
e->scalingFunction[sf->strongSide] = sf; // Only strong color assigned
|
||||||
return e;
|
return e;
|
||||||
@@ -163,9 +160,9 @@ Entry* probe(const Position& pos) {
|
|||||||
// We didn't find any specialized scaling function, so fall back on generic
|
// We didn't find any specialized scaling function, so fall back on generic
|
||||||
// ones that refer to more than one material distribution. Note that in this
|
// ones that refer to more than one material distribution. Note that in this
|
||||||
// case we don't return after setting the function.
|
// case we don't return after setting the function.
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
for (Color c : { WHITE, BLACK })
|
||||||
{
|
{
|
||||||
if (is_KBPsKs(pos, c))
|
if (is_KBPsK(pos, c))
|
||||||
e->scalingFunction[c] = &ScaleKBPsK[c];
|
e->scalingFunction[c] = &ScaleKBPsK[c];
|
||||||
|
|
||||||
else if (is_KQKRPs(pos, c))
|
else if (is_KQKRPs(pos, c))
|
||||||
@@ -206,22 +203,16 @@ Entry* probe(const Position& pos) {
|
|||||||
e->factor[BLACK] = uint8_t(npm_b < RookValueMg ? SCALE_FACTOR_DRAW :
|
e->factor[BLACK] = uint8_t(npm_b < RookValueMg ? SCALE_FACTOR_DRAW :
|
||||||
npm_w <= BishopValueMg ? 4 : 14);
|
npm_w <= BishopValueMg ? 4 : 14);
|
||||||
|
|
||||||
if (pos.count<PAWN>(WHITE) == 1 && npm_w - npm_b <= BishopValueMg)
|
|
||||||
e->factor[WHITE] = (uint8_t) SCALE_FACTOR_ONEPAWN;
|
|
||||||
|
|
||||||
if (pos.count<PAWN>(BLACK) == 1 && npm_b - npm_w <= BishopValueMg)
|
|
||||||
e->factor[BLACK] = (uint8_t) SCALE_FACTOR_ONEPAWN;
|
|
||||||
|
|
||||||
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
||||||
// for the bishop pair "extended piece", which allows us to be more flexible
|
// for the bishop pair "extended piece", which allows us to be more flexible
|
||||||
// in defining bishop pair bonuses.
|
// in defining bishop pair bonuses.
|
||||||
const int PieceCount[COLOR_NB][PIECE_TYPE_NB] = {
|
const int pieceCount[COLOR_NB][PIECE_TYPE_NB] = {
|
||||||
{ pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
|
{ pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
|
||||||
pos.count<BISHOP>(WHITE) , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
|
pos.count<BISHOP>(WHITE) , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
|
||||||
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
|
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
|
||||||
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
|
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
|
||||||
|
|
||||||
e->value = int16_t((imbalance<WHITE>(PieceCount) - imbalance<BLACK>(PieceCount)) / 16);
|
e->value = int16_t((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -56,9 +56,9 @@ struct Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
EndgameBase<Value>* evaluationFunction;
|
const EndgameBase<Value>* evaluationFunction;
|
||||||
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
||||||
// side (e.g. KPKP, KBPsKs)
|
// side (e.g. KPKP, KBPsK)
|
||||||
int16_t value;
|
int16_t value;
|
||||||
uint8_t factor[COLOR_NB];
|
uint8_t factor[COLOR_NB];
|
||||||
Phase gamePhase;
|
Phase gamePhase;
|
||||||
|
|||||||
+95
-17
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,11 @@
|
|||||||
#undef _WIN32_WINNT
|
#undef _WIN32_WINNT
|
||||||
#define _WIN32_WINNT 0x0601 // Force to include needed API prototypes
|
#define _WIN32_WINNT 0x0601 // Force to include needed API prototypes
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
// The needed Windows API for processor groups could be missed from old Windows
|
// The needed Windows API for processor groups could be missed from old Windows
|
||||||
// versions, so instead of calling them directly (forcing the linker to resolve
|
// versions, so instead of calling them directly (forcing the linker to resolve
|
||||||
@@ -51,7 +56,7 @@ namespace {
|
|||||||
|
|
||||||
/// Version number. If Version is left empty, then compile date in the format
|
/// Version number. If Version is left empty, then compile date in the format
|
||||||
/// DD-MM-YY and show in engine_info.
|
/// DD-MM-YY and show in engine_info.
|
||||||
const string Version = "9";
|
const string Version = "11";
|
||||||
|
|
||||||
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
||||||
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
||||||
@@ -97,6 +102,13 @@ public:
|
|||||||
if (!fname.empty() && !l.file.is_open())
|
if (!fname.empty() && !l.file.is_open())
|
||||||
{
|
{
|
||||||
l.file.open(fname, ifstream::out);
|
l.file.open(fname, ifstream::out);
|
||||||
|
|
||||||
|
if (!l.file.is_open())
|
||||||
|
{
|
||||||
|
cerr << "Unable to open debug log file " << fname << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
cin.rdbuf(&l.in);
|
cin.rdbuf(&l.in);
|
||||||
cout.rdbuf(&l.out);
|
cout.rdbuf(&l.out);
|
||||||
}
|
}
|
||||||
@@ -139,8 +151,79 @@ const string engine_info(bool to_uci) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// compiler_info() returns a string trying to describe the compiler we use
|
||||||
|
|
||||||
|
const std::string compiler_info() {
|
||||||
|
|
||||||
|
#define STRINGIFY2(x) #x
|
||||||
|
#define STRINGIFY(x) STRINGIFY2(x)
|
||||||
|
#define VER_STRING(major, minor, patch) STRINGIFY(major) "." STRINGIFY(minor) "." STRINGIFY(patch)
|
||||||
|
|
||||||
|
/// Predefined macros hell:
|
||||||
|
///
|
||||||
|
/// __GNUC__ Compiler is gcc, Clang or Intel on Linux
|
||||||
|
/// __INTEL_COMPILER Compiler is Intel
|
||||||
|
/// _MSC_VER Compiler is MSVC or Intel on Windows
|
||||||
|
/// _WIN32 Building on Windows (any)
|
||||||
|
/// _WIN64 Building on Windows 64 bit
|
||||||
|
|
||||||
|
std::string compiler = "\nCompiled by ";
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
compiler += "clang++ ";
|
||||||
|
compiler += VER_STRING(__clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||||
|
#elif __INTEL_COMPILER
|
||||||
|
compiler += "Intel compiler ";
|
||||||
|
compiler += "(version ";
|
||||||
|
compiler += STRINGIFY(__INTEL_COMPILER) " update " STRINGIFY(__INTEL_COMPILER_UPDATE);
|
||||||
|
compiler += ")";
|
||||||
|
#elif _MSC_VER
|
||||||
|
compiler += "MSVC ";
|
||||||
|
compiler += "(version ";
|
||||||
|
compiler += STRINGIFY(_MSC_FULL_VER) "." STRINGIFY(_MSC_BUILD);
|
||||||
|
compiler += ")";
|
||||||
|
#elif __GNUC__
|
||||||
|
compiler += "g++ (GNUC) ";
|
||||||
|
compiler += VER_STRING(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||||
|
#else
|
||||||
|
compiler += "Unknown compiler ";
|
||||||
|
compiler += "(unknown version)";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
compiler += " on Apple";
|
||||||
|
#elif defined(__CYGWIN__)
|
||||||
|
compiler += " on Cygwin";
|
||||||
|
#elif defined(__MINGW64__)
|
||||||
|
compiler += " on MinGW64";
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
compiler += " on MinGW32";
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
compiler += " on Android";
|
||||||
|
#elif defined(__linux__)
|
||||||
|
compiler += " on Linux";
|
||||||
|
#elif defined(_WIN64)
|
||||||
|
compiler += " on Microsoft Windows 64-bit";
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
compiler += " on Microsoft Windows 32-bit";
|
||||||
|
#else
|
||||||
|
compiler += " on unknown system";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
compiler += "\n __VERSION__ macro expands to: ";
|
||||||
|
#ifdef __VERSION__
|
||||||
|
compiler += __VERSION__;
|
||||||
|
#else
|
||||||
|
compiler += "(undefined macro)";
|
||||||
|
#endif
|
||||||
|
compiler += "\n";
|
||||||
|
|
||||||
|
return compiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Debug functions used mainly to collect run-time statistics
|
/// Debug functions used mainly to collect run-time statistics
|
||||||
static int64_t hits[2], means[2];
|
static std::atomic<int64_t> hits[2], means[2];
|
||||||
|
|
||||||
void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; }
|
void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; }
|
||||||
void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); }
|
void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); }
|
||||||
@@ -163,7 +246,7 @@ void dbg_print() {
|
|||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, SyncCout sc) {
|
std::ostream& operator<<(std::ostream& os, SyncCout sc) {
|
||||||
|
|
||||||
static Mutex m;
|
static std::mutex m;
|
||||||
|
|
||||||
if (sc == IO_LOCK)
|
if (sc == IO_LOCK)
|
||||||
m.lock();
|
m.lock();
|
||||||
@@ -205,12 +288,6 @@ void prefetch(void* addr) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void prefetch2(void* addr) {
|
|
||||||
|
|
||||||
prefetch(addr);
|
|
||||||
prefetch((uint8_t*)addr + 64);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WinProcGroup {
|
namespace WinProcGroup {
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@@ -219,11 +296,11 @@ void bindThisThread(size_t) {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/// get_group() retrieves logical processor information using Windows specific
|
/// best_group() retrieves logical processor information using Windows specific
|
||||||
/// API and returns the best group id for the thread with index idx. Original
|
/// API and returns the best group id for the thread with index idx. Original
|
||||||
/// code from Texel by Peter Österlund.
|
/// code from Texel by Peter Österlund.
|
||||||
|
|
||||||
int get_group(size_t idx) {
|
int best_group(size_t idx) {
|
||||||
|
|
||||||
int threads = 0;
|
int threads = 0;
|
||||||
int nodes = 0;
|
int nodes = 0;
|
||||||
@@ -233,7 +310,7 @@ int get_group(size_t idx) {
|
|||||||
|
|
||||||
// Early exit if the needed API is not available at runtime
|
// Early exit if the needed API is not available at runtime
|
||||||
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
||||||
auto fun1 = (fun1_t)GetProcAddress(k32, "GetLogicalProcessorInformationEx");
|
auto fun1 = (fun1_t)(void(*)())GetProcAddress(k32, "GetLogicalProcessorInformationEx");
|
||||||
if (!fun1)
|
if (!fun1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -252,7 +329,7 @@ int get_group(size_t idx) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ptr->Size > 0 && byteOffset + ptr->Size <= returnLength)
|
while (byteOffset < returnLength)
|
||||||
{
|
{
|
||||||
if (ptr->Relationship == RelationNumaNode)
|
if (ptr->Relationship == RelationNumaNode)
|
||||||
nodes++;
|
nodes++;
|
||||||
@@ -263,6 +340,7 @@ int get_group(size_t idx) {
|
|||||||
threads += (ptr->Processor.Flags == LTP_PC_SMT) ? 2 : 1;
|
threads += (ptr->Processor.Flags == LTP_PC_SMT) ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(ptr->Size);
|
||||||
byteOffset += ptr->Size;
|
byteOffset += ptr->Size;
|
||||||
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((char*)ptr) + ptr->Size);
|
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((char*)ptr) + ptr->Size);
|
||||||
}
|
}
|
||||||
@@ -294,15 +372,15 @@ int get_group(size_t idx) {
|
|||||||
void bindThisThread(size_t idx) {
|
void bindThisThread(size_t idx) {
|
||||||
|
|
||||||
// Use only local variables to be thread-safe
|
// Use only local variables to be thread-safe
|
||||||
int group = get_group(idx);
|
int group = best_group(idx);
|
||||||
|
|
||||||
if (group == -1)
|
if (group == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Early exit if the needed API are not available at runtime
|
// Early exit if the needed API are not available at runtime
|
||||||
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
||||||
auto fun2 = (fun2_t)GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
|
auto fun2 = (fun2_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
|
||||||
auto fun3 = (fun3_t)GetProcAddress(k32, "SetThreadGroupAffinity");
|
auto fun3 = (fun3_t)(void(*)())GetProcAddress(k32, "SetThreadGroupAffinity");
|
||||||
|
|
||||||
if (!fun2 || !fun3)
|
if (!fun2 || !fun3)
|
||||||
return;
|
return;
|
||||||
|
|||||||
+5
-3
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -30,8 +30,8 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
const std::string engine_info(bool to_uci = false);
|
const std::string engine_info(bool to_uci = false);
|
||||||
|
const std::string compiler_info();
|
||||||
void prefetch(void* addr);
|
void prefetch(void* addr);
|
||||||
void prefetch2(void* addr);
|
|
||||||
void start_logger(const std::string& fname);
|
void start_logger(const std::string& fname);
|
||||||
|
|
||||||
void dbg_hit_on(bool b);
|
void dbg_hit_on(bool b);
|
||||||
@@ -41,6 +41,8 @@ void dbg_print();
|
|||||||
|
|
||||||
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
||||||
|
|
||||||
|
static_assert(sizeof(TimePoint) == sizeof(int64_t), "TimePoint should be 64 bits");
|
||||||
|
|
||||||
inline TimePoint now() {
|
inline TimePoint now() {
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>
|
return std::chrono::duration_cast<std::chrono::milliseconds>
|
||||||
(std::chrono::steady_clock::now().time_since_epoch()).count();
|
(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||||
@@ -51,7 +53,7 @@ struct HashTable {
|
|||||||
Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; }
|
Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Entry> table = std::vector<Entry>(Size);
|
std::vector<Entry> table = std::vector<Entry>(Size); // Allocate on the heap
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+43
-93
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,46 +25,6 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template<CastlingRight Cr, bool Checks, bool Chess960>
|
|
||||||
ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us) {
|
|
||||||
|
|
||||||
static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
|
|
||||||
|
|
||||||
if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
|
|
||||||
return moveList;
|
|
||||||
|
|
||||||
// After castling, the rook and king final positions are the same in Chess960
|
|
||||||
// as they would be in standard chess.
|
|
||||||
Square kfrom = pos.square<KING>(us);
|
|
||||||
Square rfrom = pos.castling_rook_square(Cr);
|
|
||||||
Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1);
|
|
||||||
Bitboard enemies = pos.pieces(~us);
|
|
||||||
|
|
||||||
assert(!pos.checkers());
|
|
||||||
|
|
||||||
const Direction K = Chess960 ? kto > kfrom ? WEST : EAST
|
|
||||||
: KingSide ? WEST : EAST;
|
|
||||||
|
|
||||||
for (Square s = kto; s != kfrom; s += K)
|
|
||||||
if (pos.attackers_to(s) & enemies)
|
|
||||||
return moveList;
|
|
||||||
|
|
||||||
// Because we generate only legal castling moves we need to verify that
|
|
||||||
// when moving the castling rook we do not discover some hidden checker.
|
|
||||||
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
|
|
||||||
if (Chess960 && (attacks_bb<ROOK>(kto, pos.pieces() ^ rfrom) & pos.pieces(~us, ROOK, QUEEN)))
|
|
||||||
return moveList;
|
|
||||||
|
|
||||||
Move m = make<CASTLING>(kfrom, rfrom);
|
|
||||||
|
|
||||||
if (Checks && !pos.gives_check(m))
|
|
||||||
return moveList;
|
|
||||||
|
|
||||||
*moveList++ = m;
|
|
||||||
return moveList;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<GenType Type, Direction D>
|
template<GenType Type, Direction D>
|
||||||
ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) {
|
ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) {
|
||||||
|
|
||||||
@@ -92,16 +52,15 @@ namespace {
|
|||||||
template<Color Us, GenType Type>
|
template<Color Us, GenType Type>
|
||||||
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
|
|
||||||
// Compute our parametrized parameters at compile time, named according to
|
// Compute some compile time parameters relative to the white side
|
||||||
// the point of view of white side.
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||||
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
constexpr Direction Up = pawn_push(Us);
|
||||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
constexpr Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
constexpr Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||||
const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
|
||||||
const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
|
||||||
|
|
||||||
|
const Square ksq = pos.square<KING>(Them);
|
||||||
Bitboard emptySquares;
|
Bitboard emptySquares;
|
||||||
|
|
||||||
Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB;
|
Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB;
|
||||||
@@ -126,8 +85,6 @@ namespace {
|
|||||||
|
|
||||||
if (Type == QUIET_CHECKS)
|
if (Type == QUIET_CHECKS)
|
||||||
{
|
{
|
||||||
Square ksq = pos.square<KING>(Them);
|
|
||||||
|
|
||||||
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
|
|
||||||
@@ -135,10 +92,10 @@ namespace {
|
|||||||
// if the pawn is not on the same file as the enemy king, because we
|
// if the pawn is not on the same file as the enemy king, because we
|
||||||
// don't generate captures. Note that a possible discovery check
|
// don't generate captures. Note that a possible discovery check
|
||||||
// promotion has been already generated amongst the captures.
|
// promotion has been already generated amongst the captures.
|
||||||
Bitboard dcCandidates = pos.discovered_check_candidates();
|
Bitboard dcCandidateQuiets = pos.blockers_for_king(Them) & pawnsNotOn7;
|
||||||
if (pawnsNotOn7 & dcCandidates)
|
if (dcCandidateQuiets)
|
||||||
{
|
{
|
||||||
Bitboard dc1 = shift<Up>(pawnsNotOn7 & dcCandidates) & emptySquares & ~file_bb(ksq);
|
Bitboard dc1 = shift<Up>(dcCandidateQuiets) & emptySquares & ~file_bb(ksq);
|
||||||
Bitboard dc2 = shift<Up>(dc1 & TRank3BB) & emptySquares;
|
Bitboard dc2 = shift<Up>(dc1 & TRank3BB) & emptySquares;
|
||||||
|
|
||||||
b1 |= dc1;
|
b1 |= dc1;
|
||||||
@@ -160,7 +117,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Promotions and underpromotions
|
// Promotions and underpromotions
|
||||||
if (pawnsOn7 && (Type != EVASIONS || (target & TRank8BB)))
|
if (pawnsOn7)
|
||||||
{
|
{
|
||||||
if (Type == CAPTURES)
|
if (Type == CAPTURES)
|
||||||
emptySquares = ~pos.pieces();
|
emptySquares = ~pos.pieces();
|
||||||
@@ -168,38 +125,36 @@ namespace {
|
|||||||
if (Type == EVASIONS)
|
if (Type == EVASIONS)
|
||||||
emptySquares &= target;
|
emptySquares &= target;
|
||||||
|
|
||||||
Bitboard b1 = shift<Right>(pawnsOn7) & enemies;
|
Bitboard b1 = shift<UpRight>(pawnsOn7) & enemies;
|
||||||
Bitboard b2 = shift<Left >(pawnsOn7) & enemies;
|
Bitboard b2 = shift<UpLeft >(pawnsOn7) & enemies;
|
||||||
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
||||||
|
|
||||||
Square ksq = pos.square<KING>(Them);
|
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
moveList = make_promotions<Type, Right>(moveList, pop_lsb(&b1), ksq);
|
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(&b1), ksq);
|
||||||
|
|
||||||
while (b2)
|
while (b2)
|
||||||
moveList = make_promotions<Type, Left >(moveList, pop_lsb(&b2), ksq);
|
moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(&b2), ksq);
|
||||||
|
|
||||||
while (b3)
|
while (b3)
|
||||||
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ksq);
|
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ksq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard and en-passant captures
|
// Standard and en-passant captures
|
||||||
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
{
|
{
|
||||||
Bitboard b1 = shift<Right>(pawnsNotOn7) & enemies;
|
Bitboard b1 = shift<UpRight>(pawnsNotOn7) & enemies;
|
||||||
Bitboard b2 = shift<Left >(pawnsNotOn7) & enemies;
|
Bitboard b2 = shift<UpLeft >(pawnsNotOn7) & enemies;
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
Square to = pop_lsb(&b1);
|
Square to = pop_lsb(&b1);
|
||||||
*moveList++ = make_move(to - Right, to);
|
*moveList++ = make_move(to - UpRight, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (b2)
|
while (b2)
|
||||||
{
|
{
|
||||||
Square to = pop_lsb(&b2);
|
Square to = pop_lsb(&b2);
|
||||||
*moveList++ = make_move(to - Left, to);
|
*moveList++ = make_move(to - UpLeft, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos.ep_square() != SQ_NONE)
|
if (pos.ep_square() != SQ_NONE)
|
||||||
@@ -229,7 +184,7 @@ namespace {
|
|||||||
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
||||||
Bitboard target) {
|
Bitboard target) {
|
||||||
|
|
||||||
assert(Pt != KING && Pt != PAWN);
|
static_assert(Pt != KING && Pt != PAWN, "Unsupported piece type in generate_moves()");
|
||||||
|
|
||||||
const Square* pl = pos.squares<Pt>(us);
|
const Square* pl = pos.squares<Pt>(us);
|
||||||
|
|
||||||
@@ -241,7 +196,7 @@ namespace {
|
|||||||
&& !(PseudoAttacks[Pt][from] & target & pos.check_squares(Pt)))
|
&& !(PseudoAttacks[Pt][from] & target & pos.check_squares(Pt)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pos.discovered_check_candidates() & from)
|
if (pos.blockers_for_king(~us) & from)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +216,9 @@ namespace {
|
|||||||
template<Color Us, GenType Type>
|
template<Color Us, GenType Type>
|
||||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
|
|
||||||
const bool Checks = Type == QUIET_CHECKS;
|
constexpr CastlingRights OO = Us & KING_SIDE;
|
||||||
|
constexpr CastlingRights OOO = Us & QUEEN_SIDE;
|
||||||
|
constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
|
||||||
|
|
||||||
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
||||||
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
|
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
|
||||||
@@ -275,19 +232,14 @@ namespace {
|
|||||||
Bitboard b = pos.attacks_from<KING>(ksq) & target;
|
Bitboard b = pos.attacks_from<KING>(ksq) & target;
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(ksq, pop_lsb(&b));
|
*moveList++ = make_move(ksq, pop_lsb(&b));
|
||||||
}
|
|
||||||
|
|
||||||
if (Type != CAPTURES && Type != EVASIONS && pos.can_castle(Us))
|
if (Type != CAPTURES && pos.can_castle(CastlingRights(OO | OOO)))
|
||||||
{
|
|
||||||
if (pos.is_chess960())
|
|
||||||
{
|
{
|
||||||
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, moveList, Us);
|
if (!pos.castling_impeded(OO) && pos.can_castle(OO))
|
||||||
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us);
|
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OO));
|
||||||
}
|
|
||||||
else
|
if (!pos.castling_impeded(OOO) && pos.can_castle(OOO))
|
||||||
{
|
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OOO));
|
||||||
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us);
|
|
||||||
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,19 +249,16 @@ namespace {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
/// generate<CAPTURES> generates all pseudo-legal captures and queen
|
/// <CAPTURES> Generates all pseudo-legal captures and queen promotions
|
||||||
/// promotions. Returns a pointer to the end of the move list.
|
/// <QUIETS> Generates all pseudo-legal non-captures and underpromotions
|
||||||
|
/// <NON_EVASIONS> Generates all pseudo-legal captures and non-captures
|
||||||
///
|
///
|
||||||
/// generate<QUIETS> generates all pseudo-legal non-captures and
|
/// Returns a pointer to the end of the move list.
|
||||||
/// underpromotions. Returns a pointer to the end of the move list.
|
|
||||||
///
|
|
||||||
/// generate<NON_EVASIONS> generates all pseudo-legal captures and
|
|
||||||
/// non-captures. Returns a pointer to the end of the move list.
|
|
||||||
|
|
||||||
template<GenType Type>
|
template<GenType Type>
|
||||||
ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS);
|
static_assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS, "Unsupported type in generate()");
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
@@ -336,7 +285,7 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
|||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Bitboard dc = pos.discovered_check_candidates();
|
Bitboard dc = pos.blockers_for_king(~us) & pos.pieces(us);
|
||||||
|
|
||||||
while (dc)
|
while (dc)
|
||||||
{
|
{
|
||||||
@@ -403,8 +352,9 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
|||||||
template<>
|
template<>
|
||||||
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
|
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
Color us = pos.side_to_move();
|
||||||
Square ksq = pos.square<KING>(pos.side_to_move());
|
Bitboard pinned = pos.blockers_for_king(us) & pos.pieces(us);
|
||||||
|
Square ksq = pos.square<KING>(us);
|
||||||
ExtMove* cur = moveList;
|
ExtMove* cur = moveList;
|
||||||
|
|
||||||
moveList = pos.checkers() ? generate<EVASIONS >(pos, moveList)
|
moveList = pos.checkers() ? generate<EVASIONS >(pos, moveList)
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
|
|||||||
+126
-189
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,12 +25,10 @@
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum Stages {
|
enum Stages {
|
||||||
MAIN_SEARCH, CAPTURES_INIT, GOOD_CAPTURES, KILLERS, COUNTERMOVE, QUIET_INIT, QUIET, BAD_CAPTURES,
|
MAIN_TT, CAPTURE_INIT, GOOD_CAPTURE, REFUTATION, QUIET_INIT, QUIET, BAD_CAPTURE,
|
||||||
EVASION, EVASIONS_INIT, ALL_EVASIONS,
|
EVASION_TT, EVASION_INIT, EVASION,
|
||||||
PROBCUT, PROBCUT_INIT, PROBCUT_CAPTURES,
|
PROBCUT_TT, PROBCUT_INIT, PROBCUT,
|
||||||
QSEARCH_WITH_CHECKS, QCAPTURES_1_INIT, QCAPTURES_1, QCHECKS,
|
QSEARCH_TT, QCAPTURE_INIT, QCAPTURE, QCHECK_INIT, QCHECK
|
||||||
QSEARCH_NO_CHECKS, QCAPTURES_2_INIT, QCAPTURES_2,
|
|
||||||
QSEARCH_RECAPTURES, QRECAPTURES
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// partial_insertion_sort() sorts moves in descending order up to and including
|
// partial_insertion_sort() sorts moves in descending order up to and including
|
||||||
@@ -48,15 +46,6 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pick_best() finds the best move in the range (begin, end) and moves it to
|
|
||||||
// the front. It's faster than sorting all the moves in advance when there
|
|
||||||
// are few moves, e.g., the possible captures.
|
|
||||||
Move pick_best(ExtMove* begin, ExtMove* end) {
|
|
||||||
|
|
||||||
std::swap(*begin, *std::max_element(begin, end));
|
|
||||||
return *begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
@@ -68,62 +57,49 @@ namespace {
|
|||||||
|
|
||||||
/// MovePicker constructor for the main search
|
/// MovePicker constructor for the main search
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||||
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers_p)
|
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers)
|
||||||
: pos(p), mainHistory(mh), captureHistory(cph), contHistory(ch), countermove(cm),
|
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch),
|
||||||
killers{killers_p[0], killers_p[1]}, depth(d){
|
refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d) {
|
||||||
|
|
||||||
assert(d > DEPTH_ZERO);
|
assert(d > 0);
|
||||||
|
|
||||||
stage = pos.checkers() ? EVASION : MAIN_SEARCH;
|
stage = pos.checkers() ? EVASION_TT : MAIN_TT;
|
||||||
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
stage += (ttMove == MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// MovePicker constructor for quiescence search
|
/// MovePicker constructor for quiescence search
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const CapturePieceToHistory* cph, Square s)
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||||
: pos(p), mainHistory(mh), captureHistory(cph) {
|
const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
|
||||||
|
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch), recaptureSquare(rs), depth(d) {
|
||||||
|
|
||||||
assert(d <= DEPTH_ZERO);
|
assert(d <= 0);
|
||||||
|
|
||||||
if (pos.checkers())
|
stage = pos.checkers() ? EVASION_TT : QSEARCH_TT;
|
||||||
stage = EVASION;
|
ttMove = ttm
|
||||||
|
&& (depth > DEPTH_QS_RECAPTURES || to_sq(ttm) == recaptureSquare)
|
||||||
else if (d > DEPTH_QS_NO_CHECKS)
|
&& pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
stage = QSEARCH_WITH_CHECKS;
|
|
||||||
|
|
||||||
else if (d > DEPTH_QS_RECAPTURES)
|
|
||||||
stage = QSEARCH_NO_CHECKS;
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stage = QSEARCH_RECAPTURES;
|
|
||||||
recaptureSquare = s;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
|
||||||
stage += (ttMove == MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// MovePicker constructor for ProbCut: we generate captures with SEE higher
|
/// MovePicker constructor for ProbCut: we generate captures with SEE greater
|
||||||
/// than or equal to the given threshold.
|
/// than or equal to the given threshold.
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Value th, const CapturePieceToHistory* cph)
|
MovePicker::MovePicker(const Position& p, Move ttm, Value th, const CapturePieceToHistory* cph)
|
||||||
: pos(p), captureHistory(cph), threshold(th) {
|
: pos(p), captureHistory(cph), threshold(th) {
|
||||||
|
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
stage = PROBCUT;
|
stage = PROBCUT_TT;
|
||||||
ttMove = ttm
|
ttMove = ttm
|
||||||
&& pos.pseudo_legal(ttm)
|
|
||||||
&& pos.capture(ttm)
|
&& pos.capture(ttm)
|
||||||
|
&& pos.pseudo_legal(ttm)
|
||||||
&& pos.see_ge(ttm, threshold) ? ttm : MOVE_NONE;
|
&& pos.see_ge(ttm, threshold) ? ttm : MOVE_NONE;
|
||||||
|
|
||||||
stage += (ttMove == MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// score() assigns a numerical value to each move in a list, used for sorting.
|
/// MovePicker::score() assigns a numerical value to each move in a list, used
|
||||||
/// Captures are ordered by Most Valuable Victim (MVV), preferring captures
|
/// for sorting. Captures are ordered by Most Valuable Victim (MVV), preferring
|
||||||
/// with a good history. Quiets are ordered using the histories.
|
/// captures with a good history. Quiets moves are ordered using the histories.
|
||||||
template<GenType Type>
|
template<GenType Type>
|
||||||
void MovePicker::score() {
|
void MovePicker::score() {
|
||||||
|
|
||||||
@@ -131,14 +107,15 @@ void MovePicker::score() {
|
|||||||
|
|
||||||
for (auto& m : *this)
|
for (auto& m : *this)
|
||||||
if (Type == CAPTURES)
|
if (Type == CAPTURES)
|
||||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
m.value = int(PieceValue[MG][pos.piece_on(to_sq(m))]) * 6
|
||||||
+ Value((*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))]);
|
+ (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))];
|
||||||
|
|
||||||
else if (Type == QUIETS)
|
else if (Type == QUIETS)
|
||||||
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||||
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
+ 2 * (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||||
+ (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
|
+ 2 * (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
|
||||||
+ (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
|
+ 2 * (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
+ (*continuationHistory[5])[pos.moved_piece(m)][to_sq(m)];
|
||||||
|
|
||||||
else // Type == EVASIONS
|
else // Type == EVASIONS
|
||||||
{
|
{
|
||||||
@@ -146,189 +123,149 @@ void MovePicker::score() {
|
|||||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||||
- Value(type_of(pos.moved_piece(m)));
|
- Value(type_of(pos.moved_piece(m)));
|
||||||
else
|
else
|
||||||
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - (1 << 28);
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||||
|
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
- (1 << 28);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// next_move() is the most important method of the MovePicker class. It returns
|
/// MovePicker::select() returns the next move satisfying a predicate function.
|
||||||
/// a new pseudo legal move every time it is called, until there are no more moves
|
/// It never returns the TT move.
|
||||||
/// left. It picks the move with the biggest value from a list of generated moves
|
template<MovePicker::PickType T, typename Pred>
|
||||||
/// taking care not to return the ttMove if it has already been searched.
|
Move MovePicker::select(Pred filter) {
|
||||||
|
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
|
if (T == Best)
|
||||||
|
std::swap(*cur, *std::max_element(cur, endMoves));
|
||||||
|
|
||||||
|
if (*cur != ttMove && filter())
|
||||||
|
return *cur++;
|
||||||
|
|
||||||
|
cur++;
|
||||||
|
}
|
||||||
|
return MOVE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// MovePicker::next_move() is the most important method of the MovePicker class. It
|
||||||
|
/// returns a new pseudo legal move every time it is called until there are no more
|
||||||
|
/// moves left, picking the move with the highest score from a list of generated moves.
|
||||||
Move MovePicker::next_move(bool skipQuiets) {
|
Move MovePicker::next_move(bool skipQuiets) {
|
||||||
|
|
||||||
Move move;
|
top:
|
||||||
|
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
|
|
||||||
case MAIN_SEARCH: case EVASION: case QSEARCH_WITH_CHECKS:
|
case MAIN_TT:
|
||||||
case QSEARCH_NO_CHECKS: case PROBCUT:
|
case EVASION_TT:
|
||||||
|
case QSEARCH_TT:
|
||||||
|
case PROBCUT_TT:
|
||||||
++stage;
|
++stage;
|
||||||
return ttMove;
|
return ttMove;
|
||||||
|
|
||||||
case CAPTURES_INIT:
|
case CAPTURE_INIT:
|
||||||
endBadCaptures = cur = moves;
|
case PROBCUT_INIT:
|
||||||
|
case QCAPTURE_INIT:
|
||||||
|
cur = endBadCaptures = moves;
|
||||||
endMoves = generate<CAPTURES>(pos, cur);
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
|
|
||||||
score<CAPTURES>();
|
score<CAPTURES>();
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
goto top;
|
||||||
|
|
||||||
case GOOD_CAPTURES:
|
case GOOD_CAPTURE:
|
||||||
while (cur < endMoves)
|
if (select<Best>([&](){
|
||||||
{
|
return pos.see_ge(*cur, Value(-55 * cur->value / 1024)) ?
|
||||||
move = pick_best(cur++, endMoves);
|
// Move losing capture to endBadCaptures to be tried later
|
||||||
if (move != ttMove)
|
true : (*endBadCaptures++ = *cur, false); }))
|
||||||
{
|
return *(cur - 1);
|
||||||
if (pos.see_ge(move, Value(-55 * (cur-1)->value / 1024)))
|
|
||||||
return move;
|
|
||||||
|
|
||||||
// Losing capture, move it to the beginning of the array
|
// Prepare the pointers to loop over the refutations array
|
||||||
*endBadCaptures++ = move;
|
cur = std::begin(refutations);
|
||||||
}
|
endMoves = std::end(refutations);
|
||||||
}
|
|
||||||
|
// If the countermove is the same as a killer, skip it
|
||||||
|
if ( refutations[0].move == refutations[2].move
|
||||||
|
|| refutations[1].move == refutations[2].move)
|
||||||
|
--endMoves;
|
||||||
|
|
||||||
++stage;
|
++stage;
|
||||||
move = killers[0]; // First killer move
|
|
||||||
if ( move != MOVE_NONE
|
|
||||||
&& move != ttMove
|
|
||||||
&& pos.pseudo_legal(move)
|
|
||||||
&& !pos.capture(move))
|
|
||||||
return move;
|
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case KILLERS:
|
case REFUTATION:
|
||||||
|
if (select<Next>([&](){ return *cur != MOVE_NONE
|
||||||
|
&& !pos.capture(*cur)
|
||||||
|
&& pos.pseudo_legal(*cur); }))
|
||||||
|
return *(cur - 1);
|
||||||
++stage;
|
++stage;
|
||||||
move = killers[1]; // Second killer move
|
|
||||||
if ( move != MOVE_NONE
|
|
||||||
&& move != ttMove
|
|
||||||
&& pos.pseudo_legal(move)
|
|
||||||
&& !pos.capture(move))
|
|
||||||
return move;
|
|
||||||
/* fallthrough */
|
|
||||||
|
|
||||||
case COUNTERMOVE:
|
|
||||||
++stage;
|
|
||||||
move = countermove;
|
|
||||||
if ( move != MOVE_NONE
|
|
||||||
&& move != ttMove
|
|
||||||
&& move != killers[0]
|
|
||||||
&& move != killers[1]
|
|
||||||
&& pos.pseudo_legal(move)
|
|
||||||
&& !pos.capture(move))
|
|
||||||
return move;
|
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case QUIET_INIT:
|
case QUIET_INIT:
|
||||||
cur = endBadCaptures;
|
if (!skipQuiets)
|
||||||
endMoves = generate<QUIETS>(pos, cur);
|
{
|
||||||
score<QUIETS>();
|
cur = endBadCaptures;
|
||||||
partial_insertion_sort(cur, endMoves, -4000 * depth / ONE_PLY);
|
endMoves = generate<QUIETS>(pos, cur);
|
||||||
|
|
||||||
|
score<QUIETS>();
|
||||||
|
partial_insertion_sort(cur, endMoves, -3000 * depth);
|
||||||
|
}
|
||||||
|
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case QUIET:
|
case QUIET:
|
||||||
while ( cur < endMoves
|
if ( !skipQuiets
|
||||||
&& (!skipQuiets || cur->value >= VALUE_ZERO))
|
&& select<Next>([&](){return *cur != refutations[0].move
|
||||||
{
|
&& *cur != refutations[1].move
|
||||||
move = *cur++;
|
&& *cur != refutations[2].move;}))
|
||||||
|
return *(cur - 1);
|
||||||
|
|
||||||
|
// Prepare the pointers to loop over the bad captures
|
||||||
|
cur = moves;
|
||||||
|
endMoves = endBadCaptures;
|
||||||
|
|
||||||
if ( move != ttMove
|
|
||||||
&& move != killers[0]
|
|
||||||
&& move != killers[1]
|
|
||||||
&& move != countermove)
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
++stage;
|
++stage;
|
||||||
cur = moves; // Point to beginning of bad captures
|
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case BAD_CAPTURES:
|
case BAD_CAPTURE:
|
||||||
if (cur < endBadCaptures)
|
return select<Next>([](){ return true; });
|
||||||
return *cur++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVASIONS_INIT:
|
case EVASION_INIT:
|
||||||
cur = moves;
|
cur = moves;
|
||||||
endMoves = generate<EVASIONS>(pos, cur);
|
endMoves = generate<EVASIONS>(pos, cur);
|
||||||
|
|
||||||
score<EVASIONS>();
|
score<EVASIONS>();
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case ALL_EVASIONS:
|
case EVASION:
|
||||||
while (cur < endMoves)
|
return select<Best>([](){ return true; });
|
||||||
{
|
|
||||||
move = pick_best(cur++, endMoves);
|
case PROBCUT:
|
||||||
if (move != ttMove)
|
return select<Best>([&](){ return pos.see_ge(*cur, threshold); });
|
||||||
return move;
|
|
||||||
}
|
case QCAPTURE:
|
||||||
break;
|
if (select<Best>([&](){ return depth > DEPTH_QS_RECAPTURES
|
||||||
|
|| to_sq(*cur) == recaptureSquare; }))
|
||||||
|
return *(cur - 1);
|
||||||
|
|
||||||
|
// If we did not find any move and we do not try checks, we have finished
|
||||||
|
if (depth != DEPTH_QS_CHECKS)
|
||||||
|
return MOVE_NONE;
|
||||||
|
|
||||||
case PROBCUT_INIT:
|
|
||||||
cur = moves;
|
|
||||||
endMoves = generate<CAPTURES>(pos, cur);
|
|
||||||
score<CAPTURES>();
|
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case PROBCUT_CAPTURES:
|
case QCHECK_INIT:
|
||||||
while (cur < endMoves)
|
|
||||||
{
|
|
||||||
move = pick_best(cur++, endMoves);
|
|
||||||
if ( move != ttMove
|
|
||||||
&& pos.see_ge(move, threshold))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QCAPTURES_1_INIT: case QCAPTURES_2_INIT:
|
|
||||||
cur = moves;
|
|
||||||
endMoves = generate<CAPTURES>(pos, cur);
|
|
||||||
score<CAPTURES>();
|
|
||||||
++stage;
|
|
||||||
/* fallthrough */
|
|
||||||
|
|
||||||
case QCAPTURES_1: case QCAPTURES_2:
|
|
||||||
while (cur < endMoves)
|
|
||||||
{
|
|
||||||
move = pick_best(cur++, endMoves);
|
|
||||||
if (move != ttMove)
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
if (stage == QCAPTURES_2)
|
|
||||||
break;
|
|
||||||
cur = moves;
|
cur = moves;
|
||||||
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
||||||
|
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case QCHECKS:
|
case QCHECK:
|
||||||
while (cur < endMoves)
|
return select<Next>([](){ return true; });
|
||||||
{
|
|
||||||
move = cur++->move;
|
|
||||||
if (move != ttMove)
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QSEARCH_RECAPTURES:
|
|
||||||
cur = moves;
|
|
||||||
endMoves = generate<CAPTURES>(pos, cur);
|
|
||||||
score<CAPTURES>();
|
|
||||||
++stage;
|
|
||||||
/* fallthrough */
|
|
||||||
|
|
||||||
case QRECAPTURES:
|
|
||||||
while (cur < endMoves)
|
|
||||||
{
|
|
||||||
move = pick_best(cur++, endMoves);
|
|
||||||
if (to_sq(move) == recaptureSquare)
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return MOVE_NONE;
|
assert(false);
|
||||||
|
return MOVE_NONE; // Silence warning
|
||||||
}
|
}
|
||||||
|
|||||||
+69
-69
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,95 +23,85 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
/// StatBoards is a generic 2-dimensional array used to store various statistics
|
/// StatsEntry stores the stat table value. It is usually a number but could
|
||||||
template<int Size1, int Size2, typename T = int16_t>
|
/// be a move or even a nested history. We use a class instead of naked value
|
||||||
struct StatBoards : public std::array<std::array<T, Size2>, Size1> {
|
/// to directly call history update operator<<() on the entry so to use stats
|
||||||
|
/// tables at caller sites as simple multi-dim arrays.
|
||||||
|
template<typename T, int D>
|
||||||
|
class StatsEntry {
|
||||||
|
|
||||||
void fill(const T& v) {
|
T entry;
|
||||||
T* p = &(*this)[0][0];
|
|
||||||
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(T& entry, int bonus, const int D) {
|
public:
|
||||||
|
void operator=(const T& v) { entry = v; }
|
||||||
|
T* operator&() { return &entry; }
|
||||||
|
T* operator->() { return &entry; }
|
||||||
|
operator const T&() const { return entry; }
|
||||||
|
|
||||||
assert(abs(bonus) <= D); // Ensure range is [-32 * D, 32 * D]
|
void operator<<(int bonus) {
|
||||||
assert(abs(32 * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
|
assert(abs(bonus) <= D); // Ensure range is [-D, D]
|
||||||
|
static_assert(D <= std::numeric_limits<T>::max(), "D overflows T");
|
||||||
|
|
||||||
entry += bonus * 32 - entry * abs(bonus) / D;
|
entry += bonus - entry * abs(bonus) / D;
|
||||||
|
|
||||||
assert(abs(entry) <= 32 * D);
|
assert(abs(entry) <= D);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// StatCubes is a generic 3-dimensional array used to store various statistics
|
/// Stats is a generic N-dimensional array used to store various statistics.
|
||||||
template<int Size1, int Size2, int Size3, typename T = int16_t>
|
/// The first template parameter T is the base type of the array, the second
|
||||||
struct StatCubes : public std::array<std::array<std::array<T, Size3>, Size2>, Size1> {
|
/// template parameter D limits the range of updates in [-D, D] when we update
|
||||||
|
/// values with the << operator, while the last parameters (Size and Sizes)
|
||||||
|
/// encode the dimensions of the array.
|
||||||
|
template <typename T, int D, int Size, int... Sizes>
|
||||||
|
struct Stats : public std::array<Stats<T, D, Sizes...>, Size>
|
||||||
|
{
|
||||||
|
typedef Stats<T, D, Size, Sizes...> stats;
|
||||||
|
|
||||||
void fill(const T& v) {
|
void fill(const T& v) {
|
||||||
T* p = &(*this)[0][0][0];
|
|
||||||
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(T& entry, int bonus, const int D, const int W) {
|
// For standard-layout 'this' points to first struct member
|
||||||
|
assert(std::is_standard_layout<stats>::value);
|
||||||
|
|
||||||
assert(abs(bonus) <= D); // Ensure range is [-W * D, W * D]
|
typedef StatsEntry<T, D> entry;
|
||||||
assert(abs(W * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
|
entry* p = reinterpret_cast<entry*>(this);
|
||||||
|
std::fill(p, p + sizeof(*this) / sizeof(entry), v);
|
||||||
entry += bonus * W - entry * abs(bonus) / D;
|
|
||||||
|
|
||||||
assert(abs(entry) <= W * D);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// ButterflyBoards are 2 tables (one for each color) indexed by the move's from
|
template <typename T, int D, int Size>
|
||||||
/// and to squares, see chessprogramming.wikispaces.com/Butterfly+Boards
|
struct Stats<T, D, Size> : public std::array<StatsEntry<T, D>, Size> {};
|
||||||
typedef StatBoards<COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyBoards;
|
|
||||||
|
|
||||||
/// PieceToBoards are addressed by a move's [piece][to] information
|
/// In stats table, D=0 means that the template parameter is not used
|
||||||
typedef StatBoards<PIECE_NB, SQUARE_NB> PieceToBoards;
|
enum StatsParams { NOT_USED = 0 };
|
||||||
|
enum StatsType { NoCaptures, Captures };
|
||||||
/// CapturePieceToBoards are addressed by a move's [piece][to][captured piece type] information
|
|
||||||
typedef StatCubes<PIECE_NB, SQUARE_NB, PIECE_TYPE_NB> CapturePieceToBoards;
|
|
||||||
|
|
||||||
/// ButterflyHistory records how often quiet moves have been successful or
|
/// ButterflyHistory records how often quiet moves have been successful or
|
||||||
/// unsuccessful during the current search, and is used for reduction and move
|
/// unsuccessful during the current search, and is used for reduction and move
|
||||||
/// ordering decisions. It uses ButterflyBoards as backing store.
|
/// ordering decisions. It uses 2 tables (one for each color) indexed by
|
||||||
struct ButterflyHistory : public ButterflyBoards {
|
/// the move's from and to squares, see www.chessprogramming.org/Butterfly_Boards
|
||||||
|
typedef Stats<int16_t, 10692, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyHistory;
|
||||||
void update(Color c, Move m, int bonus) {
|
|
||||||
StatBoards::update((*this)[c][from_to(m)], bonus, 324);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// PieceToHistory is like ButterflyHistory, but is based on PieceToBoards
|
|
||||||
struct PieceToHistory : public PieceToBoards {
|
|
||||||
|
|
||||||
void update(Piece pc, Square to, int bonus) {
|
|
||||||
StatBoards::update((*this)[pc][to], bonus, 936);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// CapturePieceToHistory is like PieceToHistory, but is based on CapturePieceToBoards
|
|
||||||
struct CapturePieceToHistory : public CapturePieceToBoards {
|
|
||||||
|
|
||||||
void update(Piece pc, Square to, PieceType captured, int bonus) {
|
|
||||||
StatCubes::update((*this)[pc][to][captured], bonus, 324, 2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous
|
/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous
|
||||||
/// move, see chessprogramming.wikispaces.com/Countermove+Heuristic
|
/// move, see www.chessprogramming.org/Countermove_Heuristic
|
||||||
typedef StatBoards<PIECE_NB, SQUARE_NB, Move> CounterMoveHistory;
|
typedef Stats<Move, NOT_USED, PIECE_NB, SQUARE_NB> CounterMoveHistory;
|
||||||
|
|
||||||
/// ContinuationHistory is the history of a given pair of moves, usually the
|
/// CapturePieceToHistory is addressed by a move's [piece][to][captured piece type]
|
||||||
/// current one given a previous one. History table is based on PieceToBoards
|
typedef Stats<int16_t, 10692, PIECE_NB, SQUARE_NB, PIECE_TYPE_NB> CapturePieceToHistory;
|
||||||
/// instead of ButterflyBoards.
|
|
||||||
typedef StatBoards<PIECE_NB, SQUARE_NB, PieceToHistory> ContinuationHistory;
|
/// PieceToHistory is like ButterflyHistory but is addressed by a move's [piece][to]
|
||||||
|
typedef Stats<int16_t, 29952, PIECE_NB, SQUARE_NB> PieceToHistory;
|
||||||
|
|
||||||
|
/// ContinuationHistory is the combined history of a given pair of moves, usually
|
||||||
|
/// the current one given a previous one. The nested history table is based on
|
||||||
|
/// PieceToHistory instead of ButterflyBoards.
|
||||||
|
typedef Stats<PieceToHistory, NOT_USED, PIECE_NB, SQUARE_NB> ContinuationHistory;
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
||||||
@@ -120,17 +110,27 @@ typedef StatBoards<PIECE_NB, SQUARE_NB, PieceToHistory> ContinuationHistory;
|
|||||||
/// when MOVE_NONE is returned. In order to improve the efficiency of the alpha
|
/// when MOVE_NONE is returned. In order to improve the efficiency of the alpha
|
||||||
/// beta algorithm, MovePicker attempts to return the moves which are most likely
|
/// beta algorithm, MovePicker attempts to return the moves which are most likely
|
||||||
/// to get a cut-off first.
|
/// to get a cut-off first.
|
||||||
|
|
||||||
class MovePicker {
|
class MovePicker {
|
||||||
|
|
||||||
|
enum PickType { Next, Best };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MovePicker(const MovePicker&) = delete;
|
MovePicker(const MovePicker&) = delete;
|
||||||
MovePicker& operator=(const MovePicker&) = delete;
|
MovePicker& operator=(const MovePicker&) = delete;
|
||||||
MovePicker(const Position&, Move, Value, const CapturePieceToHistory*);
|
MovePicker(const Position&, Move, Value, const CapturePieceToHistory*);
|
||||||
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const CapturePieceToHistory*, Square);
|
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
|
||||||
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const CapturePieceToHistory*, const PieceToHistory**, Move, Move*);
|
const CapturePieceToHistory*,
|
||||||
|
const PieceToHistory**,
|
||||||
|
Square);
|
||||||
|
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
|
||||||
|
const CapturePieceToHistory*,
|
||||||
|
const PieceToHistory**,
|
||||||
|
Move,
|
||||||
|
Move*);
|
||||||
Move next_move(bool skipQuiets = false);
|
Move next_move(bool skipQuiets = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template<PickType T, typename Pred> Move select(Pred);
|
||||||
template<GenType> void score();
|
template<GenType> void score();
|
||||||
ExtMove* begin() { return cur; }
|
ExtMove* begin() { return cur; }
|
||||||
ExtMove* end() { return endMoves; }
|
ExtMove* end() { return endMoves; }
|
||||||
@@ -138,9 +138,9 @@ private:
|
|||||||
const Position& pos;
|
const Position& pos;
|
||||||
const ButterflyHistory* mainHistory;
|
const ButterflyHistory* mainHistory;
|
||||||
const CapturePieceToHistory* captureHistory;
|
const CapturePieceToHistory* captureHistory;
|
||||||
const PieceToHistory** contHistory;
|
const PieceToHistory** continuationHistory;
|
||||||
Move ttMove, countermove, killers[2];
|
Move ttMove;
|
||||||
ExtMove *cur, *endMoves, *endBadCaptures;
|
ExtMove refutations[3], *cur, *endMoves, *endBadCaptures;
|
||||||
int stage;
|
int stage;
|
||||||
Square recaptureSquare;
|
Square recaptureSquare;
|
||||||
Value threshold;
|
Value threshold;
|
||||||
|
|||||||
+117
-161
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,153 +31,124 @@ namespace {
|
|||||||
#define V Value
|
#define V Value
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
|
|
||||||
// Isolated pawn penalty
|
// Pawn penalties
|
||||||
const Score Isolated = S(13, 18);
|
constexpr Score Backward = S( 9, 24);
|
||||||
|
constexpr Score BlockedStorm = S(82, 82);
|
||||||
|
constexpr Score Doubled = S(11, 56);
|
||||||
|
constexpr Score Isolated = S( 5, 15);
|
||||||
|
constexpr Score WeakLever = S( 0, 56);
|
||||||
|
constexpr Score WeakUnopposed = S(13, 27);
|
||||||
|
|
||||||
// Backward pawn penalty
|
// Connected pawn bonus
|
||||||
const Score Backward = S(24, 12);
|
constexpr int Connected[RANK_NB] = { 0, 7, 8, 12, 29, 48, 86 };
|
||||||
|
|
||||||
// Connected pawn bonus by opposed, phalanx, #support and rank
|
// Strength of pawn shelter for our king by [distance from edge][rank].
|
||||||
Score Connected[2][2][3][RANK_NB];
|
// RANK_1 = 0 is used for files where we have no pawn, or pawn is behind our king.
|
||||||
|
constexpr Value ShelterStrength[int(FILE_NB) / 2][RANK_NB] = {
|
||||||
// Doubled pawn penalty
|
{ V( -6), V( 81), V( 93), V( 58), V( 39), V( 18), V( 25) },
|
||||||
const Score Doubled = S(18, 38);
|
{ V(-43), V( 61), V( 35), V(-49), V(-29), V(-11), V( -63) },
|
||||||
|
{ V(-10), V( 75), V( 23), V( -2), V( 32), V( 3), V( -45) },
|
||||||
// Weakness of our pawn shelter in front of the king by [isKingFile][distance from edge][rank].
|
{ V(-39), V(-13), V(-29), V(-52), V(-48), V(-67), V(-166) }
|
||||||
// RANK_1 = 0 is used for files where we have no pawns or our pawn is behind our king.
|
|
||||||
const Value ShelterWeakness[][int(FILE_NB) / 2][RANK_NB] = {
|
|
||||||
{ { V( 97), V(17), V( 9), V(44), V( 84), V( 87), V( 99) }, // Not On King file
|
|
||||||
{ V(106), V( 6), V(33), V(86), V( 87), V(104), V(112) },
|
|
||||||
{ V(101), V( 2), V(65), V(98), V( 58), V( 89), V(115) },
|
|
||||||
{ V( 73), V( 7), V(54), V(73), V( 84), V( 83), V(111) } },
|
|
||||||
{ { V(104), V(20), V( 6), V(27), V( 86), V( 93), V( 82) }, // On King file
|
|
||||||
{ V(123), V( 9), V(34), V(96), V(112), V( 88), V( 75) },
|
|
||||||
{ V(120), V(25), V(65), V(91), V( 66), V( 78), V(117) },
|
|
||||||
{ V( 81), V( 2), V(47), V(63), V( 94), V( 93), V(104) } }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank].
|
// Danger of enemy pawns moving toward our king by [distance from edge][rank].
|
||||||
// For the unopposed and unblocked cases, RANK_1 = 0 is used when opponent has
|
// RANK_1 = 0 is used for files where the enemy has no pawn, or their pawn
|
||||||
// no pawn on the given file, or their pawn is behind our king.
|
// is behind our king. Note that UnblockedStorm[0][1-2] accommodate opponent pawn
|
||||||
const Value StormDanger[][4][RANK_NB] = {
|
// on edge, likely blocked by our king.
|
||||||
{ { V( 0), V(-290), V(-274), V(57), V(41) }, // BlockedByKing
|
constexpr Value UnblockedStorm[int(FILE_NB) / 2][RANK_NB] = {
|
||||||
{ V( 0), V( 60), V( 144), V(39), V(13) },
|
{ V( 85), V(-289), V(-166), V(97), V(50), V( 45), V( 50) },
|
||||||
{ V( 0), V( 65), V( 141), V(41), V(34) },
|
{ V( 46), V( -25), V( 122), V(45), V(37), V(-10), V( 20) },
|
||||||
{ V( 0), V( 53), V( 127), V(56), V(14) } },
|
{ V( -6), V( 51), V( 168), V(34), V(-2), V(-22), V(-14) },
|
||||||
{ { V( 4), V( 73), V( 132), V(46), V(31) }, // Unopposed
|
{ V(-15), V( -11), V( 101), V( 4), V(11), V(-15), V(-29) }
|
||||||
{ V( 1), V( 64), V( 143), V(26), V(13) },
|
|
||||||
{ V( 1), V( 47), V( 110), V(44), V(24) },
|
|
||||||
{ V( 0), V( 72), V( 127), V(50), V(31) } },
|
|
||||||
{ { V( 0), V( 0), V( 79), V(23), V( 1) }, // BlockedByPawn
|
|
||||||
{ V( 0), V( 0), V( 148), V(27), V( 2) },
|
|
||||||
{ V( 0), V( 0), V( 161), V(16), V( 1) },
|
|
||||||
{ V( 0), V( 0), V( 171), V(22), V(15) } },
|
|
||||||
{ { V(22), V( 45), V( 104), V(62), V( 6) }, // Unblocked
|
|
||||||
{ V(31), V( 30), V( 99), V(39), V(19) },
|
|
||||||
{ V(23), V( 29), V( 96), V(41), V(15) },
|
|
||||||
{ V(21), V( 23), V( 116), V(41), V(15) } }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Max bonus for king safety. Corresponds to start position with all the pawns
|
|
||||||
// in front of the king and no enemy pawn on the horizon.
|
|
||||||
const Value MaxSafetyBonus = V(258);
|
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
#undef V
|
#undef V
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
constexpr Direction Up = pawn_push(Us);
|
||||||
const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
|
||||||
const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
|
||||||
|
|
||||||
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
|
Bitboard neighbours, stoppers, support, phalanx, opposed;
|
||||||
Bitboard lever, leverPush;
|
Bitboard lever, leverPush, blocked;
|
||||||
Square s;
|
Square s;
|
||||||
bool opposed, backward;
|
bool backward, passed, doubled;
|
||||||
Score score = SCORE_ZERO;
|
Score score = SCORE_ZERO;
|
||||||
const Square* pl = pos.squares<PAWN>(Us);
|
const Square* pl = pos.squares<PAWN>(Us);
|
||||||
|
|
||||||
Bitboard ourPawns = pos.pieces( Us, PAWN);
|
Bitboard ourPawns = pos.pieces( Us, PAWN);
|
||||||
Bitboard theirPawns = pos.pieces(Them, PAWN);
|
Bitboard theirPawns = pos.pieces(Them, PAWN);
|
||||||
|
|
||||||
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = e->weakUnopposed[Us] = 0;
|
Bitboard doubleAttackThem = pawn_double_attacks_bb<Them>(theirPawns);
|
||||||
e->semiopenFiles[Us] = 0xFF;
|
|
||||||
e->kingSquares[Us] = SQ_NONE;
|
e->passedPawns[Us] = 0;
|
||||||
e->pawnAttacks[Us] = shift<Right>(ourPawns) | shift<Left>(ourPawns);
|
e->kingSquares[Us] = SQ_NONE;
|
||||||
e->pawnsOnSquares[Us][BLACK] = popcount(ourPawns & DarkSquares);
|
e->pawnAttacks[Us] = e->pawnAttacksSpan[Us] = pawn_attacks_bb<Us>(ourPawns);
|
||||||
e->pawnsOnSquares[Us][WHITE] = pos.count<PAWN>(Us) - e->pawnsOnSquares[Us][BLACK];
|
|
||||||
|
|
||||||
// Loop through all pawns of the current color and score each pawn
|
// Loop through all pawns of the current color and score each pawn
|
||||||
while ((s = *pl++) != SQ_NONE)
|
while ((s = *pl++) != SQ_NONE)
|
||||||
{
|
{
|
||||||
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
||||||
|
|
||||||
File f = file_of(s);
|
Rank r = relative_rank(Us, s);
|
||||||
|
|
||||||
e->semiopenFiles[Us] &= ~(1 << f);
|
|
||||||
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
|
|
||||||
|
|
||||||
// Flag the pawn
|
// Flag the pawn
|
||||||
opposed = theirPawns & forward_file_bb(Us, s);
|
opposed = theirPawns & forward_file_bb(Us, s);
|
||||||
stoppers = theirPawns & passed_pawn_mask(Us, s);
|
blocked = theirPawns & (s + Up);
|
||||||
|
stoppers = theirPawns & passed_pawn_span(Us, s);
|
||||||
lever = theirPawns & PawnAttacks[Us][s];
|
lever = theirPawns & PawnAttacks[Us][s];
|
||||||
leverPush = theirPawns & PawnAttacks[Us][s + Up];
|
leverPush = theirPawns & PawnAttacks[Us][s + Up];
|
||||||
doubled = ourPawns & (s - Up);
|
doubled = ourPawns & (s - Up);
|
||||||
neighbours = ourPawns & adjacent_files_bb(f);
|
neighbours = ourPawns & adjacent_files_bb(s);
|
||||||
phalanx = neighbours & rank_bb(s);
|
phalanx = neighbours & rank_bb(s);
|
||||||
supported = neighbours & rank_bb(s - Up);
|
support = neighbours & rank_bb(s - Up);
|
||||||
|
|
||||||
// A pawn is backward when it is behind all pawns of the same color on the
|
// A pawn is backward when it is behind all pawns of the same color on
|
||||||
// adjacent files and cannot be safely advanced.
|
// the adjacent files and cannot safely advance.
|
||||||
if (!neighbours || lever || relative_rank(Us, s) >= RANK_5)
|
backward = !(neighbours & forward_ranks_bb(Them, s + Up))
|
||||||
backward = false;
|
&& (leverPush | blocked);
|
||||||
else
|
|
||||||
{
|
|
||||||
// Find the backmost rank with neighbours or stoppers
|
|
||||||
b = rank_bb(backmost_sq(Us, neighbours | stoppers));
|
|
||||||
|
|
||||||
// The pawn is backward when it cannot safely progress to that rank:
|
// Compute additional span if pawn is not backward nor blocked
|
||||||
// either there is a stopper in the way on this rank, or there is a
|
if (!backward && !blocked)
|
||||||
// stopper on adjacent file which controls the way to that rank.
|
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
|
||||||
backward = (b | shift<Up>(b & adjacent_files_bb(f))) & stoppers;
|
|
||||||
|
|
||||||
assert(!(backward && (forward_ranks_bb(Them, s + Up) & neighbours)));
|
// A pawn is passed if one of the three following conditions is true:
|
||||||
}
|
// (a) there is no stoppers except some levers
|
||||||
|
// (b) the only stoppers are the leverPush, but we outnumber them
|
||||||
|
// (c) there is only one front stopper which can be levered.
|
||||||
|
passed = !(stoppers ^ lever)
|
||||||
|
|| ( !(stoppers ^ leverPush)
|
||||||
|
&& popcount(phalanx) >= popcount(leverPush))
|
||||||
|
|| ( stoppers == blocked && r >= RANK_5
|
||||||
|
&& (shift<Up>(support) & ~(theirPawns | doubleAttackThem)));
|
||||||
|
|
||||||
// Passed pawns will be properly scored in evaluation because we need
|
// Passed pawns will be properly scored later in evaluation when we have
|
||||||
// full attack info to evaluate them. Include also not passed pawns
|
// full attack info.
|
||||||
// which could become passed after one or two pawn pushes when are
|
if (passed)
|
||||||
// not attacked more times than defended.
|
|
||||||
if ( !(stoppers ^ lever ^ leverPush)
|
|
||||||
&& !(ourPawns & forward_file_bb(Us, s))
|
|
||||||
&& popcount(supported) >= popcount(lever)
|
|
||||||
&& popcount(phalanx) >= popcount(leverPush))
|
|
||||||
e->passedPawns[Us] |= s;
|
e->passedPawns[Us] |= s;
|
||||||
|
|
||||||
else if ( stoppers == SquareBB[s + Up]
|
// Score this pawn
|
||||||
&& relative_rank(Us, s) >= RANK_5)
|
if (support | phalanx)
|
||||||
{
|
{
|
||||||
b = shift<Up>(supported) & ~theirPawns;
|
int v = Connected[r] * (2 + bool(phalanx) - bool(opposed))
|
||||||
while (b)
|
+ 21 * popcount(support);
|
||||||
if (!more_than_one(theirPawns & PawnAttacks[Us][pop_lsb(&b)]))
|
|
||||||
e->passedPawns[Us] |= s;
|
score += make_score(v, v * (r - 2) / 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Score this pawn
|
|
||||||
if (supported | phalanx)
|
|
||||||
score += Connected[opposed][bool(phalanx)][popcount(supported)][relative_rank(Us, s)];
|
|
||||||
|
|
||||||
else if (!neighbours)
|
else if (!neighbours)
|
||||||
score -= Isolated, e->weakUnopposed[Us] += !opposed;
|
score -= Isolated
|
||||||
|
+ WeakUnopposed * !opposed;
|
||||||
|
|
||||||
else if (backward)
|
else if (backward)
|
||||||
score -= Backward, e->weakUnopposed[Us] += !opposed;
|
score -= Backward
|
||||||
|
+ WeakUnopposed * !opposed;
|
||||||
|
|
||||||
if (doubled && !supported)
|
if (!support)
|
||||||
score -= Doubled;
|
score -= Doubled * doubled
|
||||||
|
+ WeakLever * more_than_one(lever);
|
||||||
}
|
}
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
@@ -187,27 +158,6 @@ namespace {
|
|||||||
|
|
||||||
namespace Pawns {
|
namespace Pawns {
|
||||||
|
|
||||||
/// Pawns::init() initializes some tables needed by evaluation. Instead of using
|
|
||||||
/// hard-coded tables, when makes sense, we prefer to calculate them with a formula
|
|
||||||
/// to reduce independent parameters and to allow easier tuning and better insight.
|
|
||||||
|
|
||||||
void init() {
|
|
||||||
|
|
||||||
static const int Seed[RANK_NB] = { 0, 13, 24, 18, 76, 100, 175, 330 };
|
|
||||||
|
|
||||||
for (int opposed = 0; opposed <= 1; ++opposed)
|
|
||||||
for (int phalanx = 0; phalanx <= 1; ++phalanx)
|
|
||||||
for (int support = 0; support <= 2; ++support)
|
|
||||||
for (Rank r = RANK_2; r < RANK_8; ++r)
|
|
||||||
{
|
|
||||||
int v = 17 * support;
|
|
||||||
v += (Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0)) >> opposed;
|
|
||||||
|
|
||||||
Connected[opposed][phalanx][support][r] = make_score(v, v * (r - 2) / 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Pawns::probe() looks up the current position's pawns configuration in
|
/// Pawns::probe() looks up the current position's pawns configuration in
|
||||||
/// the pawns hash table. It returns a pointer to the Entry if the position
|
/// the pawns hash table. It returns a pointer to the Entry if the position
|
||||||
/// is found. Otherwise a new Entry is computed and stored there, so we don't
|
/// is found. Otherwise a new Entry is computed and stored there, so we don't
|
||||||
@@ -222,47 +172,46 @@ Entry* probe(const Position& pos) {
|
|||||||
return e;
|
return e;
|
||||||
|
|
||||||
e->key = key;
|
e->key = key;
|
||||||
e->score = evaluate<WHITE>(pos, e) - evaluate<BLACK>(pos, e);
|
e->scores[WHITE] = evaluate<WHITE>(pos, e);
|
||||||
e->asymmetry = popcount(e->semiopenFiles[WHITE] ^ e->semiopenFiles[BLACK]);
|
e->scores[BLACK] = evaluate<BLACK>(pos, e);
|
||||||
e->openFiles = popcount(e->semiopenFiles[WHITE] & e->semiopenFiles[BLACK]);
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Entry::shelter_storm() calculates shelter and storm penalties for the file
|
/// Entry::evaluate_shelter() calculates the shelter bonus and the storm
|
||||||
/// the king is on, as well as the two closest files.
|
/// penalty for a king, looking at the king file and the two closest files.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
enum { BlockedByKing, Unopposed, BlockedByPawn, Unblocked };
|
Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
|
||||||
|
|
||||||
Bitboard b = pos.pieces(PAWN) & (forward_ranks_bb(Us, ksq) | rank_bb(ksq));
|
|
||||||
Bitboard ourPawns = b & pos.pieces(Us);
|
Bitboard ourPawns = b & pos.pieces(Us);
|
||||||
Bitboard theirPawns = b & pos.pieces(Them);
|
Bitboard theirPawns = b & pos.pieces(Them);
|
||||||
Value safety = MaxSafetyBonus;
|
|
||||||
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
|
|
||||||
|
|
||||||
|
Score bonus = make_score(5, 5);
|
||||||
|
|
||||||
|
File center = clamp(file_of(ksq), FILE_B, FILE_G);
|
||||||
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
||||||
{
|
{
|
||||||
b = ourPawns & file_bb(f);
|
b = ourPawns & file_bb(f);
|
||||||
Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
|
int ourRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
|
||||||
|
|
||||||
b = theirPawns & file_bb(f);
|
b = theirPawns & file_bb(f);
|
||||||
Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
|
int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
|
||||||
|
|
||||||
int d = std::min(f, ~f);
|
File d = map_to_queenside(f);
|
||||||
safety -= ShelterWeakness[f == file_of(ksq)][d][rkUs]
|
bonus += make_score(ShelterStrength[d][ourRank], 0);
|
||||||
+ StormDanger
|
|
||||||
[f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing :
|
if (ourRank && (ourRank == theirRank - 1))
|
||||||
rkUs == RANK_1 ? Unopposed :
|
bonus -= BlockedStorm * int(theirRank == RANK_3);
|
||||||
rkThem == rkUs + 1 ? BlockedByPawn : Unblocked]
|
else
|
||||||
[d][rkThem];
|
bonus -= make_score(UnblockedStorm[d][theirRank], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return safety;
|
return bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -270,30 +219,37 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
|||||||
/// when king square changes, which is about 20% of total king_safety() calls.
|
/// when king square changes, which is about 20% of total king_safety() calls.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score Entry::do_king_safety(const Position& pos, Square ksq) {
|
Score Entry::do_king_safety(const Position& pos) {
|
||||||
|
|
||||||
|
Square ksq = pos.square<KING>(Us);
|
||||||
kingSquares[Us] = ksq;
|
kingSquares[Us] = ksq;
|
||||||
castlingRights[Us] = pos.can_castle(Us);
|
castlingRights[Us] = pos.castling_rights(Us);
|
||||||
int minKingPawnDistance = 0;
|
auto compare = [](Score a, Score b) { return mg_value(a) < mg_value(b); };
|
||||||
|
|
||||||
|
Score shelter = evaluate_shelter<Us>(pos, ksq);
|
||||||
|
|
||||||
|
// If we can castle use the bonus after castling if it is bigger
|
||||||
|
|
||||||
|
if (pos.can_castle(Us & KING_SIDE))
|
||||||
|
shelter = std::max(shelter, evaluate_shelter<Us>(pos, relative_square(Us, SQ_G1)), compare);
|
||||||
|
|
||||||
|
if (pos.can_castle(Us & QUEEN_SIDE))
|
||||||
|
shelter = std::max(shelter, evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1)), compare);
|
||||||
|
|
||||||
|
// In endgame we like to bring our king near our closest pawn
|
||||||
Bitboard pawns = pos.pieces(Us, PAWN);
|
Bitboard pawns = pos.pieces(Us, PAWN);
|
||||||
if (pawns)
|
int minPawnDist = pawns ? 8 : 0;
|
||||||
while (!(DistanceRingBB[ksq][minKingPawnDistance++] & pawns)) {}
|
|
||||||
|
|
||||||
Value bonus = shelter_storm<Us>(pos, ksq);
|
if (pawns & PseudoAttacks[KING][ksq])
|
||||||
|
minPawnDist = 1;
|
||||||
|
else while (pawns)
|
||||||
|
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns)));
|
||||||
|
|
||||||
// If we can castle use the bonus after the castling if it is bigger
|
return shelter - make_score(0, 16 * minPawnDist);
|
||||||
if (pos.can_castle(MakeCastling<Us, KING_SIDE>::right))
|
|
||||||
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_G1)));
|
|
||||||
|
|
||||||
if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::right))
|
|
||||||
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1)));
|
|
||||||
|
|
||||||
return make_score(bonus, -16 * minKingPawnDistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit template instantiation
|
// Explicit template instantiation
|
||||||
template Score Entry::do_king_safety<WHITE>(const Position& pos, Square ksq);
|
template Score Entry::do_king_safety<WHITE>(const Position& pos);
|
||||||
template Score Entry::do_king_safety<BLACK>(const Position& pos, Square ksq);
|
template Score Entry::do_king_safety<BLACK>(const Position& pos);
|
||||||
|
|
||||||
} // namespace Pawns
|
} // namespace Pawns
|
||||||
|
|||||||
+11
-31
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,56 +33,36 @@ namespace Pawns {
|
|||||||
|
|
||||||
struct Entry {
|
struct Entry {
|
||||||
|
|
||||||
Score pawns_score() const { return score; }
|
Score pawn_score(Color c) const { return scores[c]; }
|
||||||
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
|
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
|
||||||
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
|
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
|
||||||
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
|
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
|
||||||
int weak_unopposed(Color c) const { return weakUnopposed[c]; }
|
int passed_count() const { return popcount(passedPawns[WHITE] | passedPawns[BLACK]); }
|
||||||
int pawn_asymmetry() const { return asymmetry; }
|
|
||||||
int open_files() const { return openFiles; }
|
|
||||||
|
|
||||||
int semiopen_file(Color c, File f) const {
|
template<Color Us>
|
||||||
return semiopenFiles[c] & (1 << f);
|
Score king_safety(const Position& pos) {
|
||||||
}
|
return kingSquares[Us] == pos.square<KING>(Us) && castlingRights[Us] == pos.castling_rights(Us)
|
||||||
|
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos));
|
||||||
int semiopen_side(Color c, File f, bool leftSide) const {
|
|
||||||
return semiopenFiles[c] & (leftSide ? (1 << f) - 1 : ~((1 << (f + 1)) - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
int pawns_on_same_color_squares(Color c, Square s) const {
|
|
||||||
return pawnsOnSquares[c][bool(DarkSquares & s)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score king_safety(const Position& pos, Square ksq) {
|
Score do_king_safety(const Position& pos);
|
||||||
return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
|
|
||||||
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos, ksq));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score do_king_safety(const Position& pos, Square ksq);
|
Score evaluate_shelter(const Position& pos, Square ksq);
|
||||||
|
|
||||||
template<Color Us>
|
|
||||||
Value shelter_storm(const Position& pos, Square ksq);
|
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
Score score;
|
Score scores[COLOR_NB];
|
||||||
Bitboard passedPawns[COLOR_NB];
|
Bitboard passedPawns[COLOR_NB];
|
||||||
Bitboard pawnAttacks[COLOR_NB];
|
Bitboard pawnAttacks[COLOR_NB];
|
||||||
Bitboard pawnAttacksSpan[COLOR_NB];
|
Bitboard pawnAttacksSpan[COLOR_NB];
|
||||||
Square kingSquares[COLOR_NB];
|
Square kingSquares[COLOR_NB];
|
||||||
Score kingSafety[COLOR_NB];
|
Score kingSafety[COLOR_NB];
|
||||||
int weakUnopposed[COLOR_NB];
|
|
||||||
int castlingRights[COLOR_NB];
|
int castlingRights[COLOR_NB];
|
||||||
int semiopenFiles[COLOR_NB];
|
|
||||||
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
|
||||||
int asymmetry;
|
|
||||||
int openFiles;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef HashTable<Entry, 16384> Table;
|
typedef HashTable<Entry, 131072> Table;
|
||||||
|
|
||||||
void init();
|
|
||||||
Entry* probe(const Position& pos);
|
Entry* probe(const Position& pos);
|
||||||
|
|
||||||
} // namespace Pawns
|
} // namespace Pawns
|
||||||
|
|||||||
+251
-166
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,10 +36,6 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
namespace PSQT {
|
|
||||||
extern Score psq[PIECE_NB][SQUARE_NB];
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Zobrist {
|
namespace Zobrist {
|
||||||
|
|
||||||
Key psq[PIECE_NB][SQUARE_NB];
|
Key psq[PIECE_NB][SQUARE_NB];
|
||||||
@@ -52,38 +48,8 @@ namespace {
|
|||||||
|
|
||||||
const string PieceToChar(" PNBRQK pnbrqk");
|
const string PieceToChar(" PNBRQK pnbrqk");
|
||||||
|
|
||||||
const Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
constexpr Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
||||||
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING };
|
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING };
|
||||||
|
|
||||||
// min_attacker() is a helper function used by see_ge() to locate the least
|
|
||||||
// valuable attacker for the side to move, remove the attacker we just found
|
|
||||||
// from the bitboards and scan for new X-ray attacks behind it.
|
|
||||||
|
|
||||||
template<int Pt>
|
|
||||||
PieceType min_attacker(const Bitboard* bb, Square to, Bitboard stmAttackers,
|
|
||||||
Bitboard& occupied, Bitboard& attackers) {
|
|
||||||
|
|
||||||
Bitboard b = stmAttackers & bb[Pt];
|
|
||||||
if (!b)
|
|
||||||
return min_attacker<Pt + 1>(bb, to, stmAttackers, occupied, attackers);
|
|
||||||
|
|
||||||
occupied ^= b & ~(b - 1);
|
|
||||||
|
|
||||||
if (Pt == PAWN || Pt == BISHOP || Pt == QUEEN)
|
|
||||||
attackers |= attacks_bb<BISHOP>(to, occupied) & (bb[BISHOP] | bb[QUEEN]);
|
|
||||||
|
|
||||||
if (Pt == ROOK || Pt == QUEEN)
|
|
||||||
attackers |= attacks_bb<ROOK>(to, occupied) & (bb[ROOK] | bb[QUEEN]);
|
|
||||||
|
|
||||||
attackers &= occupied; // After X-ray that may add already processed pieces
|
|
||||||
return (PieceType)Pt;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
PieceType min_attacker<KING>(const Bitboard*, Square, Bitboard, Bitboard&, Bitboard&) {
|
|
||||||
return KING; // No need to update bitboards: it is the last cycle
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
@@ -125,6 +91,19 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Marcel van Kervinck's cuckoo algorithm for fast detection of "upcoming repetition"
|
||||||
|
// situations. Description of the algorithm in the following paper:
|
||||||
|
// https://marcelk.net/2013-04-06/paper/upcoming-rep-v2.pdf
|
||||||
|
|
||||||
|
// First and second hash functions for indexing the cuckoo tables
|
||||||
|
inline int H1(Key h) { return h & 0x1fff; }
|
||||||
|
inline int H2(Key h) { return (h >> 16) & 0x1fff; }
|
||||||
|
|
||||||
|
// Cuckoo tables with Zobrist hashes of valid reversible moves, and the moves themselves
|
||||||
|
Key cuckoo[8192];
|
||||||
|
Move cuckooMove[8192];
|
||||||
|
|
||||||
|
|
||||||
/// Position::init() initializes at startup the various arrays used to compute
|
/// Position::init() initializes at startup the various arrays used to compute
|
||||||
/// hash keys.
|
/// hash keys.
|
||||||
|
|
||||||
@@ -152,6 +131,30 @@ void Position::init() {
|
|||||||
|
|
||||||
Zobrist::side = rng.rand<Key>();
|
Zobrist::side = rng.rand<Key>();
|
||||||
Zobrist::noPawns = rng.rand<Key>();
|
Zobrist::noPawns = rng.rand<Key>();
|
||||||
|
|
||||||
|
// Prepare the cuckoo tables
|
||||||
|
std::memset(cuckoo, 0, sizeof(cuckoo));
|
||||||
|
std::memset(cuckooMove, 0, sizeof(cuckooMove));
|
||||||
|
int count = 0;
|
||||||
|
for (Piece pc : Pieces)
|
||||||
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||||
|
for (Square s2 = Square(s1 + 1); s2 <= SQ_H8; ++s2)
|
||||||
|
if (PseudoAttacks[type_of(pc)][s1] & s2)
|
||||||
|
{
|
||||||
|
Move move = make_move(s1, s2);
|
||||||
|
Key key = Zobrist::psq[pc][s1] ^ Zobrist::psq[pc][s2] ^ Zobrist::side;
|
||||||
|
int i = H1(key);
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
std::swap(cuckoo[i], key);
|
||||||
|
std::swap(cuckooMove[i], move);
|
||||||
|
if (move == MOVE_NONE) // Arrived at empty slot?
|
||||||
|
break;
|
||||||
|
i = (i == H1(key)) ? H2(key) : H1(key); // Push victim to alternative slot
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
assert(count == 3668);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -292,24 +295,18 @@ Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Th
|
|||||||
void Position::set_castling_right(Color c, Square rfrom) {
|
void Position::set_castling_right(Color c, Square rfrom) {
|
||||||
|
|
||||||
Square kfrom = square<KING>(c);
|
Square kfrom = square<KING>(c);
|
||||||
CastlingSide cs = kfrom < rfrom ? KING_SIDE : QUEEN_SIDE;
|
CastlingRights cr = c & (kfrom < rfrom ? KING_SIDE: QUEEN_SIDE);
|
||||||
CastlingRight cr = (c | cs);
|
|
||||||
|
|
||||||
st->castlingRights |= cr;
|
st->castlingRights |= cr;
|
||||||
castlingRightsMask[kfrom] |= cr;
|
castlingRightsMask[kfrom] |= cr;
|
||||||
castlingRightsMask[rfrom] |= cr;
|
castlingRightsMask[rfrom] |= cr;
|
||||||
castlingRookSquare[cr] = rfrom;
|
castlingRookSquare[cr] = rfrom;
|
||||||
|
|
||||||
Square kto = relative_square(c, cs == KING_SIDE ? SQ_G1 : SQ_C1);
|
Square kto = relative_square(c, cr & KING_SIDE ? SQ_G1 : SQ_C1);
|
||||||
Square rto = relative_square(c, cs == KING_SIDE ? SQ_F1 : SQ_D1);
|
Square rto = relative_square(c, cr & KING_SIDE ? SQ_F1 : SQ_D1);
|
||||||
|
|
||||||
for (Square s = std::min(rfrom, rto); s <= std::max(rfrom, rto); ++s)
|
castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
|
||||||
if (s != kfrom && s != rfrom)
|
& ~(square_bb(kfrom) | rfrom);
|
||||||
castlingPath[cr] |= s;
|
|
||||||
|
|
||||||
for (Square s = std::min(kfrom, kto); s <= std::max(kfrom, kto); ++s)
|
|
||||||
if (s != kfrom && s != rfrom)
|
|
||||||
castlingPath[cr] |= s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -317,8 +314,8 @@ void Position::set_castling_right(Color c, Square rfrom) {
|
|||||||
|
|
||||||
void Position::set_check_info(StateInfo* si) const {
|
void Position::set_check_info(StateInfo* si) const {
|
||||||
|
|
||||||
si->blockersForKing[WHITE] = slider_blockers(pieces(BLACK), square<KING>(WHITE), si->pinnersForKing[WHITE]);
|
si->blockersForKing[WHITE] = slider_blockers(pieces(BLACK), square<KING>(WHITE), si->pinners[BLACK]);
|
||||||
si->blockersForKing[BLACK] = slider_blockers(pieces(WHITE), square<KING>(BLACK), si->pinnersForKing[BLACK]);
|
si->blockersForKing[BLACK] = slider_blockers(pieces(WHITE), square<KING>(BLACK), si->pinners[WHITE]);
|
||||||
|
|
||||||
Square ksq = square<KING>(~sideToMove);
|
Square ksq = square<KING>(~sideToMove);
|
||||||
|
|
||||||
@@ -341,7 +338,6 @@ void Position::set_state(StateInfo* si) const {
|
|||||||
si->key = si->materialKey = 0;
|
si->key = si->materialKey = 0;
|
||||||
si->pawnKey = Zobrist::noPawns;
|
si->pawnKey = Zobrist::noPawns;
|
||||||
si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO;
|
si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO;
|
||||||
si->psq = SCORE_ZERO;
|
|
||||||
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
|
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
|
||||||
|
|
||||||
set_check_info(si);
|
set_check_info(si);
|
||||||
@@ -351,7 +347,12 @@ void Position::set_state(StateInfo* si) const {
|
|||||||
Square s = pop_lsb(&b);
|
Square s = pop_lsb(&b);
|
||||||
Piece pc = piece_on(s);
|
Piece pc = piece_on(s);
|
||||||
si->key ^= Zobrist::psq[pc][s];
|
si->key ^= Zobrist::psq[pc][s];
|
||||||
si->psq += PSQT::psq[pc][s];
|
|
||||||
|
if (type_of(pc) == PAWN)
|
||||||
|
si->pawnKey ^= Zobrist::psq[pc][s];
|
||||||
|
|
||||||
|
else if (type_of(pc) != KING)
|
||||||
|
si->nonPawnMaterial[color_of(pc)] += PieceValue[MG][pc];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (si->epSquare != SQ_NONE)
|
if (si->epSquare != SQ_NONE)
|
||||||
@@ -362,20 +363,9 @@ void Position::set_state(StateInfo* si) const {
|
|||||||
|
|
||||||
si->key ^= Zobrist::castling[si->castlingRights];
|
si->key ^= Zobrist::castling[si->castlingRights];
|
||||||
|
|
||||||
for (Bitboard b = pieces(PAWN); b; )
|
|
||||||
{
|
|
||||||
Square s = pop_lsb(&b);
|
|
||||||
si->pawnKey ^= Zobrist::psq[piece_on(s)][s];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Piece pc : Pieces)
|
for (Piece pc : Pieces)
|
||||||
{
|
|
||||||
if (type_of(pc) != PAWN && type_of(pc) != KING)
|
|
||||||
si->nonPawnMaterial[color_of(pc)] += pieceCount[pc] * PieceValue[MG][pc];
|
|
||||||
|
|
||||||
for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
|
for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
|
||||||
si->materialKey ^= Zobrist::psq[pc][cnt];
|
si->materialKey ^= Zobrist::psq[pc][cnt];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -429,18 +419,18 @@ const string Position::fen() const {
|
|||||||
ss << (sideToMove == WHITE ? " w " : " b ");
|
ss << (sideToMove == WHITE ? " w " : " b ");
|
||||||
|
|
||||||
if (can_castle(WHITE_OO))
|
if (can_castle(WHITE_OO))
|
||||||
ss << (chess960 ? char('A' + file_of(castling_rook_square(WHITE | KING_SIDE))) : 'K');
|
ss << (chess960 ? char('A' + file_of(castling_rook_square(WHITE_OO ))) : 'K');
|
||||||
|
|
||||||
if (can_castle(WHITE_OOO))
|
if (can_castle(WHITE_OOO))
|
||||||
ss << (chess960 ? char('A' + file_of(castling_rook_square(WHITE | QUEEN_SIDE))) : 'Q');
|
ss << (chess960 ? char('A' + file_of(castling_rook_square(WHITE_OOO))) : 'Q');
|
||||||
|
|
||||||
if (can_castle(BLACK_OO))
|
if (can_castle(BLACK_OO))
|
||||||
ss << (chess960 ? char('a' + file_of(castling_rook_square(BLACK | KING_SIDE))) : 'k');
|
ss << (chess960 ? char('a' + file_of(castling_rook_square(BLACK_OO ))) : 'k');
|
||||||
|
|
||||||
if (can_castle(BLACK_OOO))
|
if (can_castle(BLACK_OOO))
|
||||||
ss << (chess960 ? char('a' + file_of(castling_rook_square(BLACK | QUEEN_SIDE))) : 'q');
|
ss << (chess960 ? char('a' + file_of(castling_rook_square(BLACK_OOO))) : 'q');
|
||||||
|
|
||||||
if (!can_castle(WHITE) && !can_castle(BLACK))
|
if (!can_castle(ANY_CASTLING))
|
||||||
ss << '-';
|
ss << '-';
|
||||||
|
|
||||||
ss << (ep_square() == SQ_NONE ? " - " : " " + UCI::square(ep_square()) + " ")
|
ss << (ep_square() == SQ_NONE ? " - " : " " + UCI::square(ep_square()) + " ")
|
||||||
@@ -459,26 +449,27 @@ const string Position::fen() const {
|
|||||||
|
|
||||||
Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners) const {
|
Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners) const {
|
||||||
|
|
||||||
Bitboard result = 0;
|
Bitboard blockers = 0;
|
||||||
pinners = 0;
|
pinners = 0;
|
||||||
|
|
||||||
// Snipers are sliders that attack 's' when a piece is removed
|
// Snipers are sliders that attack 's' when a piece and other snipers are removed
|
||||||
Bitboard snipers = ( (PseudoAttacks[ ROOK][s] & pieces(QUEEN, ROOK))
|
Bitboard snipers = ( (PseudoAttacks[ ROOK][s] & pieces(QUEEN, ROOK))
|
||||||
| (PseudoAttacks[BISHOP][s] & pieces(QUEEN, BISHOP))) & sliders;
|
| (PseudoAttacks[BISHOP][s] & pieces(QUEEN, BISHOP))) & sliders;
|
||||||
|
Bitboard occupancy = pieces() ^ snipers;
|
||||||
|
|
||||||
while (snipers)
|
while (snipers)
|
||||||
{
|
{
|
||||||
Square sniperSq = pop_lsb(&snipers);
|
Square sniperSq = pop_lsb(&snipers);
|
||||||
Bitboard b = between_bb(s, sniperSq) & pieces();
|
Bitboard b = between_bb(s, sniperSq) & occupancy;
|
||||||
|
|
||||||
if (!more_than_one(b))
|
if (b && !more_than_one(b))
|
||||||
{
|
{
|
||||||
result |= b;
|
blockers |= b;
|
||||||
if (b & pieces(color_of(piece_on(s))))
|
if (b & pieces(color_of(piece_on(s))))
|
||||||
pinners |= sniperSq;
|
pinners |= sniperSq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return blockers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -504,6 +495,7 @@ bool Position::legal(Move m) const {
|
|||||||
|
|
||||||
Color us = sideToMove;
|
Color us = sideToMove;
|
||||||
Square from = from_sq(m);
|
Square from = from_sq(m);
|
||||||
|
Square to = to_sq(m);
|
||||||
|
|
||||||
assert(color_of(moved_piece(m)) == us);
|
assert(color_of(moved_piece(m)) == us);
|
||||||
assert(piece_on(square<KING>(us)) == make_piece(us, KING));
|
assert(piece_on(square<KING>(us)) == make_piece(us, KING));
|
||||||
@@ -514,7 +506,6 @@ bool Position::legal(Move m) const {
|
|||||||
if (type_of(m) == ENPASSANT)
|
if (type_of(m) == ENPASSANT)
|
||||||
{
|
{
|
||||||
Square ksq = square<KING>(us);
|
Square ksq = square<KING>(us);
|
||||||
Square to = to_sq(m);
|
|
||||||
Square capsq = to - pawn_push(us);
|
Square capsq = to - pawn_push(us);
|
||||||
Bitboard occupied = (pieces() ^ from ^ capsq) | to;
|
Bitboard occupied = (pieces() ^ from ^ capsq) | to;
|
||||||
|
|
||||||
@@ -527,16 +518,35 @@ bool Position::legal(Move m) const {
|
|||||||
&& !(attacks_bb<BISHOP>(ksq, occupied) & pieces(~us, QUEEN, BISHOP));
|
&& !(attacks_bb<BISHOP>(ksq, occupied) & pieces(~us, QUEEN, BISHOP));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the moving piece is a king, check whether the destination
|
// Castling moves generation does not check if the castling path is clear of
|
||||||
// square is attacked by the opponent. Castling moves are checked
|
// enemy attacks, it is delayed at a later time: now!
|
||||||
// for legality during move generation.
|
if (type_of(m) == CASTLING)
|
||||||
|
{
|
||||||
|
// After castling, the rook and king final positions are the same in
|
||||||
|
// Chess960 as they would be in standard chess.
|
||||||
|
to = relative_square(us, to > from ? SQ_G1 : SQ_C1);
|
||||||
|
Direction step = to > from ? WEST : EAST;
|
||||||
|
|
||||||
|
for (Square s = to; s != from; s += step)
|
||||||
|
if (attackers_to(s) & pieces(~us))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// In case of Chess960, verify that when moving the castling rook we do
|
||||||
|
// not discover some hidden checker.
|
||||||
|
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
|
||||||
|
return !chess960
|
||||||
|
|| !(attacks_bb<ROOK>(to, pieces() ^ to_sq(m)) & pieces(~us, ROOK, QUEEN));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the moving piece is a king, check whether the destination square is
|
||||||
|
// attacked by the opponent.
|
||||||
if (type_of(piece_on(from)) == KING)
|
if (type_of(piece_on(from)) == KING)
|
||||||
return type_of(m) == CASTLING || !(attackers_to(to_sq(m)) & pieces(~us));
|
return !(attackers_to(to) & pieces(~us));
|
||||||
|
|
||||||
// A non-king move is legal if and only if it is not pinned or it
|
// A non-king move is legal if and only if it is not pinned or it
|
||||||
// is moving along the ray towards or away from the king.
|
// is moving along the ray towards or away from the king.
|
||||||
return !(pinned_pieces(us) & from)
|
return !(blockers_for_king(us) & from)
|
||||||
|| aligned(from, to_sq(m), square<KING>(us));
|
|| aligned(from, to, square<KING>(us));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -573,7 +583,7 @@ bool Position::pseudo_legal(const Move m) const {
|
|||||||
{
|
{
|
||||||
// We have already handled promotion moves, so destination
|
// We have already handled promotion moves, so destination
|
||||||
// cannot be on the 8th/1st rank.
|
// cannot be on the 8th/1st rank.
|
||||||
if (rank_of(to) == relative_rank(us, RANK_8))
|
if ((Rank8BB | Rank1BB) & to)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( !(attacks_from<PAWN>(from, us) & pieces(~us) & to) // Not a capture
|
if ( !(attacks_from<PAWN>(from, us) & pieces(~us) & to) // Not a capture
|
||||||
@@ -627,7 +637,7 @@ bool Position::gives_check(Move m) const {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Is there a discovered check?
|
// Is there a discovered check?
|
||||||
if ( (discovered_check_candidates() & from)
|
if ( (st->blockersForKing[~sideToMove] & from)
|
||||||
&& !aligned(from, to, square<KING>(~sideToMove)))
|
&& !aligned(from, to, square<KING>(~sideToMove)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -712,7 +722,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
|||||||
Square rfrom, rto;
|
Square rfrom, rto;
|
||||||
do_castling<true>(us, from, to, rfrom, rto);
|
do_castling<true>(us, from, to, rfrom, rto);
|
||||||
|
|
||||||
st->psq += PSQT::psq[captured][rto] - PSQT::psq[captured][rfrom];
|
|
||||||
k ^= Zobrist::psq[captured][rfrom] ^ Zobrist::psq[captured][rto];
|
k ^= Zobrist::psq[captured][rfrom] ^ Zobrist::psq[captured][rto];
|
||||||
captured = NO_PIECE;
|
captured = NO_PIECE;
|
||||||
}
|
}
|
||||||
@@ -751,9 +760,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
|||||||
st->materialKey ^= Zobrist::psq[captured][pieceCount[captured]];
|
st->materialKey ^= Zobrist::psq[captured][pieceCount[captured]];
|
||||||
prefetch(thisThread->materialTable[st->materialKey]);
|
prefetch(thisThread->materialTable[st->materialKey]);
|
||||||
|
|
||||||
// Update incremental scores
|
|
||||||
st->psq -= PSQT::psq[captured][capsq];
|
|
||||||
|
|
||||||
// Reset rule 50 counter
|
// Reset rule 50 counter
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
}
|
}
|
||||||
@@ -807,24 +813,17 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
|||||||
st->materialKey ^= Zobrist::psq[promotion][pieceCount[promotion]-1]
|
st->materialKey ^= Zobrist::psq[promotion][pieceCount[promotion]-1]
|
||||||
^ Zobrist::psq[pc][pieceCount[pc]];
|
^ Zobrist::psq[pc][pieceCount[pc]];
|
||||||
|
|
||||||
// Update incremental score
|
|
||||||
st->psq += PSQT::psq[promotion][to] - PSQT::psq[pc][to];
|
|
||||||
|
|
||||||
// Update material
|
// Update material
|
||||||
st->nonPawnMaterial[us] += PieceValue[MG][promotion];
|
st->nonPawnMaterial[us] += PieceValue[MG][promotion];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update pawn hash key and prefetch access to pawnsTable
|
// Update pawn hash key
|
||||||
st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
|
st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
|
||||||
prefetch2(thisThread->pawnsTable[st->pawnKey]);
|
|
||||||
|
|
||||||
// Reset rule 50 draw counter
|
// Reset rule 50 draw counter
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update incremental scores
|
|
||||||
st->psq += PSQT::psq[pc][to] - PSQT::psq[pc][from];
|
|
||||||
|
|
||||||
// Set capture piece
|
// Set capture piece
|
||||||
st->capturedPiece = captured;
|
st->capturedPiece = captured;
|
||||||
|
|
||||||
@@ -839,6 +838,25 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
|||||||
// Update king attacks used for fast check detection
|
// Update king attacks used for fast check detection
|
||||||
set_check_info(st);
|
set_check_info(st);
|
||||||
|
|
||||||
|
// Calculate the repetition info. It is the ply distance from the previous
|
||||||
|
// occurrence of the same position, negative in the 3-fold case, or zero
|
||||||
|
// if the position was not repeated.
|
||||||
|
st->repetition = 0;
|
||||||
|
int end = std::min(st->rule50, st->pliesFromNull);
|
||||||
|
if (end >= 4)
|
||||||
|
{
|
||||||
|
StateInfo* stp = st->previous->previous;
|
||||||
|
for (int i = 4; i <= end; i += 2)
|
||||||
|
{
|
||||||
|
stp = stp->previous->previous;
|
||||||
|
if (stp->key == st->key)
|
||||||
|
{
|
||||||
|
st->repetition = stp->repetition ? -i : i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assert(pos_is_ok());
|
assert(pos_is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -926,7 +944,7 @@ void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Squ
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::do(undo)_null_move() is used to do(undo) a "null move": It flips
|
/// Position::do(undo)_null_move() is used to do(undo) a "null move": it flips
|
||||||
/// the side to move without executing any move on the board.
|
/// the side to move without executing any move on the board.
|
||||||
|
|
||||||
void Position::do_null_move(StateInfo& newSt) {
|
void Position::do_null_move(StateInfo& newSt) {
|
||||||
@@ -954,6 +972,8 @@ void Position::do_null_move(StateInfo& newSt) {
|
|||||||
|
|
||||||
set_check_info(st);
|
set_check_info(st);
|
||||||
|
|
||||||
|
st->repetition = 0;
|
||||||
|
|
||||||
assert(pos_is_ok());
|
assert(pos_is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -998,84 +1018,96 @@ bool Position::see_ge(Move m, Value threshold) const {
|
|||||||
return VALUE_ZERO >= threshold;
|
return VALUE_ZERO >= threshold;
|
||||||
|
|
||||||
Square from = from_sq(m), to = to_sq(m);
|
Square from = from_sq(m), to = to_sq(m);
|
||||||
PieceType nextVictim = type_of(piece_on(from));
|
|
||||||
Color stm = ~color_of(piece_on(from)); // First consider opponent's move
|
|
||||||
Value balance; // Values of the pieces taken by us minus opponent's ones
|
|
||||||
Bitboard occupied, stmAttackers;
|
|
||||||
|
|
||||||
// The opponent may be able to recapture so this is the best result
|
int swap = PieceValue[MG][piece_on(to)] - threshold;
|
||||||
// we can hope for.
|
if (swap < 0)
|
||||||
balance = PieceValue[MG][piece_on(to)] - threshold;
|
|
||||||
|
|
||||||
if (balance < VALUE_ZERO)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Now assume the worst possible result: that the opponent can
|
swap = PieceValue[MG][piece_on(from)] - swap;
|
||||||
// capture our piece for free.
|
if (swap <= 0)
|
||||||
balance -= PieceValue[MG][nextVictim];
|
|
||||||
|
|
||||||
if (balance >= VALUE_ZERO) // Always true if nextVictim == KING
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool opponentToMove = true;
|
Bitboard occupied = pieces() ^ from ^ to;
|
||||||
occupied = pieces() ^ from ^ to;
|
Color stm = color_of(piece_on(from));
|
||||||
|
Bitboard attackers = attackers_to(to, occupied);
|
||||||
// Find all attackers to the destination square, with the moving piece removed,
|
Bitboard stmAttackers, bb;
|
||||||
// but possibly an X-ray attacker added behind it.
|
int res = 1;
|
||||||
Bitboard attackers = attackers_to(to, occupied) & occupied;
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// The balance is negative only because we assumed we could win
|
stm = ~stm;
|
||||||
// the last piece for free. We are truly winning only if we can
|
attackers &= occupied;
|
||||||
// win the last piece _cheaply enough_. Test if we can actually
|
|
||||||
// do this otherwise "give up".
|
|
||||||
assert(balance < VALUE_ZERO);
|
|
||||||
|
|
||||||
stmAttackers = attackers & pieces(stm);
|
// If stm has no more attackers then give up: stm loses
|
||||||
|
if (!(stmAttackers = attackers & pieces(stm)))
|
||||||
|
break;
|
||||||
|
|
||||||
// Don't allow pinned pieces to attack pieces except the king as long all
|
// Don't allow pinned pieces to attack (except the king) as long as
|
||||||
// pinners are on their original square.
|
// there are pinners on their original square.
|
||||||
if (!(st->pinnersForKing[stm] & ~occupied))
|
if (st->pinners[~stm] & occupied)
|
||||||
stmAttackers &= ~st->blockersForKing[stm];
|
stmAttackers &= ~st->blockersForKing[stm];
|
||||||
|
|
||||||
// If we have no more attackers we must give up
|
|
||||||
if (!stmAttackers)
|
if (!stmAttackers)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Locate and remove the next least valuable attacker
|
res ^= 1;
|
||||||
nextVictim = min_attacker<PAWN>(byTypeBB, to, stmAttackers, occupied, attackers);
|
|
||||||
|
|
||||||
if (nextVictim == KING)
|
// Locate and remove the next least valuable attacker, and add to
|
||||||
|
// the bitboard 'attackers' any X-ray attackers behind it.
|
||||||
|
if ((bb = stmAttackers & pieces(PAWN)))
|
||||||
{
|
{
|
||||||
// Our only attacker is the king. If the opponent still has
|
if ((swap = PawnValueMg - swap) < res)
|
||||||
// attackers we must give up. Otherwise we make the move and
|
break;
|
||||||
// (having no more attackers) the opponent must give up.
|
|
||||||
if (!(attackers & pieces(~stm)))
|
occupied ^= lsb(bb);
|
||||||
opponentToMove = !opponentToMove;
|
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assume the opponent can win the next piece for free and switch sides
|
else if ((bb = stmAttackers & pieces(KNIGHT)))
|
||||||
balance += PieceValue[MG][nextVictim];
|
{
|
||||||
opponentToMove = !opponentToMove;
|
if ((swap = KnightValueMg - swap) < res)
|
||||||
|
break;
|
||||||
|
|
||||||
// If balance is negative after receiving a free piece then give up
|
occupied ^= lsb(bb);
|
||||||
if (balance < VALUE_ZERO)
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
// Complete the process of switching sides. The first line swaps
|
else if ((bb = stmAttackers & pieces(BISHOP)))
|
||||||
// all negative numbers with non-negative numbers. The compiler
|
{
|
||||||
// probably knows that it is just the bitwise negation ~balance.
|
if ((swap = BishopValueMg - swap) < res)
|
||||||
balance = -balance-1;
|
break;
|
||||||
stm = ~stm;
|
|
||||||
|
occupied ^= lsb(bb);
|
||||||
|
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((bb = stmAttackers & pieces(ROOK)))
|
||||||
|
{
|
||||||
|
if ((swap = RookValueMg - swap) < res)
|
||||||
|
break;
|
||||||
|
|
||||||
|
occupied ^= lsb(bb);
|
||||||
|
attackers |= attacks_bb<ROOK>(to, occupied) & pieces(ROOK, QUEEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((bb = stmAttackers & pieces(QUEEN)))
|
||||||
|
{
|
||||||
|
if ((swap = QueenValueMg - swap) < res)
|
||||||
|
break;
|
||||||
|
|
||||||
|
occupied ^= lsb(bb);
|
||||||
|
attackers |= (attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN))
|
||||||
|
| (attacks_bb<ROOK >(to, occupied) & pieces(ROOK , QUEEN));
|
||||||
|
}
|
||||||
|
|
||||||
|
else // KING
|
||||||
|
// If we "capture" with the king but opponent still has attackers,
|
||||||
|
// reverse the result.
|
||||||
|
return (attackers & ~pieces(stm)) ? res ^ 1 : res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the opponent gave up we win, otherwise we lose.
|
return bool(res);
|
||||||
return opponentToMove;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::is_draw() tests whether the position is drawn by 50-move rule
|
/// Position::is_draw() tests whether the position is drawn by 50-move rule
|
||||||
/// or by repetition. It does not detect stalemates.
|
/// or by repetition. It does not detect stalemates.
|
||||||
|
|
||||||
@@ -1084,25 +1116,78 @@ bool Position::is_draw(int ply) const {
|
|||||||
if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
|
if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// Return a draw score if a position repeats once earlier but strictly
|
||||||
|
// after the root, or repeats twice before or at the root.
|
||||||
|
if (st->repetition && st->repetition < ply)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Position::has_repeated() tests whether there has been at least one repetition
|
||||||
|
// of positions since the last capture or pawn move.
|
||||||
|
|
||||||
|
bool Position::has_repeated() const {
|
||||||
|
|
||||||
|
StateInfo* stc = st;
|
||||||
|
int end = std::min(st->rule50, st->pliesFromNull);
|
||||||
|
while (end-- >= 4)
|
||||||
|
{
|
||||||
|
if (stc->repetition)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
stc = stc->previous;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Position::has_game_cycle() tests if the position has a move which draws by repetition,
|
||||||
|
/// or an earlier position has a move that directly reaches the current position.
|
||||||
|
|
||||||
|
bool Position::has_game_cycle(int ply) const {
|
||||||
|
|
||||||
|
int j;
|
||||||
|
|
||||||
int end = std::min(st->rule50, st->pliesFromNull);
|
int end = std::min(st->rule50, st->pliesFromNull);
|
||||||
|
|
||||||
if (end < 4)
|
if (end < 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
StateInfo* stp = st->previous->previous;
|
Key originalKey = st->key;
|
||||||
int cnt = 0;
|
StateInfo* stp = st->previous;
|
||||||
|
|
||||||
for (int i = 4; i <= end; i += 2)
|
for (int i = 3; i <= end; i += 2)
|
||||||
{
|
{
|
||||||
stp = stp->previous->previous;
|
stp = stp->previous->previous;
|
||||||
|
|
||||||
// Return a draw score if a position repeats once earlier but strictly
|
Key moveKey = originalKey ^ stp->key;
|
||||||
// after the root, or repeats twice before or at the root.
|
if ( (j = H1(moveKey), cuckoo[j] == moveKey)
|
||||||
if ( stp->key == st->key
|
|| (j = H2(moveKey), cuckoo[j] == moveKey))
|
||||||
&& ++cnt + (ply > i) == 2)
|
{
|
||||||
return true;
|
Move move = cuckooMove[j];
|
||||||
}
|
Square s1 = from_sq(move);
|
||||||
|
Square s2 = to_sq(move);
|
||||||
|
|
||||||
|
if (!(between_bb(s1, s2) & pieces()))
|
||||||
|
{
|
||||||
|
if (ply > i)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// For nodes before or at the root, check that the move is a
|
||||||
|
// repetition rather than a move to the current position.
|
||||||
|
// In the cuckoo table, both moves Rc1c5 and Rc5c1 are stored in
|
||||||
|
// the same location, so we have to select which square to check.
|
||||||
|
if (color_of(piece_on(empty(s1) ? s2 : s1)) != side_to_move())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// For repetitions before or at the root, require one more
|
||||||
|
if (stp->repetition)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1148,7 +1233,7 @@ void Position::flip() {
|
|||||||
|
|
||||||
bool Position::pos_is_ok() const {
|
bool Position::pos_is_ok() const {
|
||||||
|
|
||||||
const bool Fast = true; // Quick (default) or full check?
|
constexpr bool Fast = true; // Quick (default) or full check?
|
||||||
|
|
||||||
if ( (sideToMove != WHITE && sideToMove != BLACK)
|
if ( (sideToMove != WHITE && sideToMove != BLACK)
|
||||||
|| piece_on(square<KING>(WHITE)) != W_KING
|
|| piece_on(square<KING>(WHITE)) != W_KING
|
||||||
@@ -1197,15 +1282,15 @@ bool Position::pos_is_ok() const {
|
|||||||
assert(0 && "pos_is_ok: Index");
|
assert(0 && "pos_is_ok: Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
for (Color c : { WHITE, BLACK })
|
||||||
for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s + 1))
|
for (CastlingRights cr : {c & KING_SIDE, c & QUEEN_SIDE})
|
||||||
{
|
{
|
||||||
if (!can_castle(c | s))
|
if (!can_castle(cr))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( piece_on(castlingRookSquare[c | s]) != make_piece(c, ROOK)
|
if ( piece_on(castlingRookSquare[cr]) != make_piece(c, ROOK)
|
||||||
|| castlingRightsMask[castlingRookSquare[c | s]] != (c | s)
|
|| castlingRightsMask[castlingRookSquare[cr]] != cr
|
||||||
|| (castlingRightsMask[square<KING>(c)] & (c | s)) != (c | s))
|
|| (castlingRightsMask[square<KING>(c)] & cr) != cr)
|
||||||
assert(0 && "pos_is_ok: Castling");
|
assert(0 && "pos_is_ok: Castling");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+53
-28
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -43,7 +43,6 @@ struct StateInfo {
|
|||||||
int castlingRights;
|
int castlingRights;
|
||||||
int rule50;
|
int rule50;
|
||||||
int pliesFromNull;
|
int pliesFromNull;
|
||||||
Score psq;
|
|
||||||
Square epSquare;
|
Square epSquare;
|
||||||
|
|
||||||
// Not copied when making a move (will be recomputed anyhow)
|
// Not copied when making a move (will be recomputed anyhow)
|
||||||
@@ -52,8 +51,9 @@ struct StateInfo {
|
|||||||
Piece capturedPiece;
|
Piece capturedPiece;
|
||||||
StateInfo* previous;
|
StateInfo* previous;
|
||||||
Bitboard blockersForKing[COLOR_NB];
|
Bitboard blockersForKing[COLOR_NB];
|
||||||
Bitboard pinnersForKing[COLOR_NB];
|
Bitboard pinners[COLOR_NB];
|
||||||
Bitboard checkSquares[PIECE_TYPE_NB];
|
Bitboard checkSquares[PIECE_TYPE_NB];
|
||||||
|
int repetition;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A list to keep track of the position states along the setup moves (from the
|
/// A list to keep track of the position states along the setup moves (from the
|
||||||
@@ -96,18 +96,19 @@ public:
|
|||||||
template<PieceType Pt> int count() const;
|
template<PieceType Pt> int count() const;
|
||||||
template<PieceType Pt> const Square* squares(Color c) const;
|
template<PieceType Pt> const Square* squares(Color c) const;
|
||||||
template<PieceType Pt> Square square(Color c) const;
|
template<PieceType Pt> Square square(Color c) const;
|
||||||
|
bool is_on_semiopen_file(Color c, Square s) const;
|
||||||
|
|
||||||
// Castling
|
// Castling
|
||||||
int can_castle(Color c) const;
|
int castling_rights(Color c) const;
|
||||||
int can_castle(CastlingRight cr) const;
|
bool can_castle(CastlingRights cr) const;
|
||||||
bool castling_impeded(CastlingRight cr) const;
|
bool castling_impeded(CastlingRights cr) const;
|
||||||
Square castling_rook_square(CastlingRight cr) const;
|
Square castling_rook_square(CastlingRights cr) const;
|
||||||
|
|
||||||
// Checking
|
// Checking
|
||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
Bitboard discovered_check_candidates() const;
|
Bitboard blockers_for_king(Color c) const;
|
||||||
Bitboard pinned_pieces(Color c) const;
|
|
||||||
Bitboard check_squares(PieceType pt) const;
|
Bitboard check_squares(PieceType pt) const;
|
||||||
|
bool is_discovery_check_on_king(Color c, Move m) const;
|
||||||
|
|
||||||
// Attacks to/from a given square
|
// Attacks to/from a given square
|
||||||
Bitboard attackers_to(Square s) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
@@ -130,6 +131,7 @@ public:
|
|||||||
// Piece specific
|
// Piece specific
|
||||||
bool pawn_passed(Color c, Square s) const;
|
bool pawn_passed(Color c, Square s) const;
|
||||||
bool opposite_bishops() const;
|
bool opposite_bishops() const;
|
||||||
|
int pawns_on_same_color_squares(Color c, Square s) const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void do_move(Move m, StateInfo& newSt);
|
void do_move(Move m, StateInfo& newSt);
|
||||||
@@ -153,6 +155,8 @@ public:
|
|||||||
bool is_chess960() const;
|
bool is_chess960() const;
|
||||||
Thread* this_thread() const;
|
Thread* this_thread() const;
|
||||||
bool is_draw(int ply) const;
|
bool is_draw(int ply) const;
|
||||||
|
bool has_game_cycle(int ply) const;
|
||||||
|
bool has_repeated() const;
|
||||||
int rule50_count() const;
|
int rule50_count() const;
|
||||||
Score psq_score() const;
|
Score psq_score() const;
|
||||||
Value non_pawn_material(Color c) const;
|
Value non_pawn_material(Color c) const;
|
||||||
@@ -187,11 +191,16 @@ private:
|
|||||||
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
||||||
int gamePly;
|
int gamePly;
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
|
Score psq;
|
||||||
Thread* thisThread;
|
Thread* thisThread;
|
||||||
StateInfo* st;
|
StateInfo* st;
|
||||||
bool chess960;
|
bool chess960;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace PSQT {
|
||||||
|
extern Score psq[PIECE_NB][SQUARE_NB];
|
||||||
|
}
|
||||||
|
|
||||||
extern std::ostream& operator<<(std::ostream& os, const Position& pos);
|
extern std::ostream& operator<<(std::ostream& os, const Position& pos);
|
||||||
|
|
||||||
inline Color Position::side_to_move() const {
|
inline Color Position::side_to_move() const {
|
||||||
@@ -255,25 +264,34 @@ inline Square Position::ep_square() const {
|
|||||||
return st->epSquare;
|
return st->epSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::can_castle(CastlingRight cr) const {
|
inline bool Position::is_on_semiopen_file(Color c, Square s) const {
|
||||||
|
return !(pieces(c, PAWN) & file_bb(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Position::can_castle(CastlingRights cr) const {
|
||||||
return st->castlingRights & cr;
|
return st->castlingRights & cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::can_castle(Color c) const {
|
inline int Position::castling_rights(Color c) const {
|
||||||
return st->castlingRights & ((WHITE_OO | WHITE_OOO) << (2 * c));
|
return st->castlingRights & (c == WHITE ? WHITE_CASTLING : BLACK_CASTLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::castling_impeded(CastlingRight cr) const {
|
inline bool Position::castling_impeded(CastlingRights cr) const {
|
||||||
|
assert(cr == WHITE_OO || cr == WHITE_OOO || cr == BLACK_OO || cr == BLACK_OOO);
|
||||||
|
|
||||||
return byTypeBB[ALL_PIECES] & castlingPath[cr];
|
return byTypeBB[ALL_PIECES] & castlingPath[cr];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::castling_rook_square(CastlingRight cr) const {
|
inline Square Position::castling_rook_square(CastlingRights cr) const {
|
||||||
|
assert(cr == WHITE_OO || cr == WHITE_OOO || cr == BLACK_OO || cr == BLACK_OOO);
|
||||||
|
|
||||||
return castlingRookSquare[cr];
|
return castlingRookSquare[cr];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt>
|
template<PieceType Pt>
|
||||||
inline Bitboard Position::attacks_from(Square s) const {
|
inline Bitboard Position::attacks_from(Square s) const {
|
||||||
assert(Pt != PAWN);
|
static_assert(Pt != PAWN, "Pawn attacks need color");
|
||||||
|
|
||||||
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
||||||
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
||||||
: PseudoAttacks[Pt][s];
|
: PseudoAttacks[Pt][s];
|
||||||
@@ -296,25 +314,29 @@ inline Bitboard Position::checkers() const {
|
|||||||
return st->checkersBB;
|
return st->checkersBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::discovered_check_candidates() const {
|
inline Bitboard Position::blockers_for_king(Color c) const {
|
||||||
return st->blockersForKing[~sideToMove] & pieces(sideToMove);
|
return st->blockersForKing[c];
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::pinned_pieces(Color c) const {
|
|
||||||
return st->blockersForKing[c] & pieces(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::check_squares(PieceType pt) const {
|
inline Bitboard Position::check_squares(PieceType pt) const {
|
||||||
return st->checkSquares[pt];
|
return st->checkSquares[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Position::is_discovery_check_on_king(Color c, Move m) const {
|
||||||
|
return st->blockersForKing[c] & from_sq(m);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_passed(Color c, Square s) const {
|
inline bool Position::pawn_passed(Color c, Square s) const {
|
||||||
return !(pieces(~c, PAWN) & passed_pawn_mask(c, s));
|
return !(pieces(~c, PAWN) & passed_pawn_span(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::advanced_pawn_push(Move m) const {
|
inline bool Position::advanced_pawn_push(Move m) const {
|
||||||
return type_of(moved_piece(m)) == PAWN
|
return type_of(moved_piece(m)) == PAWN
|
||||||
&& relative_rank(sideToMove, from_sq(m)) > RANK_4;
|
&& relative_rank(sideToMove, to_sq(m)) > RANK_5;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int Position::pawns_on_same_color_squares(Color c, Square s) const {
|
||||||
|
return popcount(pieces(c, PAWN) & ((DarkSquares & s) ? DarkSquares : ~DarkSquares));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::key() const {
|
inline Key Position::key() const {
|
||||||
@@ -330,7 +352,7 @@ inline Key Position::material_key() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Score Position::psq_score() const {
|
inline Score Position::psq_score() const {
|
||||||
return st->psq;
|
return psq;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::non_pawn_material(Color c) const {
|
inline Value Position::non_pawn_material(Color c) const {
|
||||||
@@ -387,6 +409,7 @@ inline void Position::put_piece(Piece pc, Square s) {
|
|||||||
index[s] = pieceCount[pc]++;
|
index[s] = pieceCount[pc]++;
|
||||||
pieceList[pc][index[s]] = s;
|
pieceList[pc][index[s]] = s;
|
||||||
pieceCount[make_piece(color_of(pc), ALL_PIECES)]++;
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]++;
|
||||||
|
psq += PSQT::psq[pc][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::remove_piece(Piece pc, Square s) {
|
inline void Position::remove_piece(Piece pc, Square s) {
|
||||||
@@ -404,20 +427,22 @@ inline void Position::remove_piece(Piece pc, Square s) {
|
|||||||
pieceList[pc][index[lastSquare]] = lastSquare;
|
pieceList[pc][index[lastSquare]] = lastSquare;
|
||||||
pieceList[pc][pieceCount[pc]] = SQ_NONE;
|
pieceList[pc][pieceCount[pc]] = SQ_NONE;
|
||||||
pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
|
||||||
|
psq -= PSQT::psq[pc][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::move_piece(Piece pc, Square from, Square to) {
|
inline void Position::move_piece(Piece pc, Square from, Square to) {
|
||||||
|
|
||||||
// index[from] is not updated and becomes stale. This works as long as index[]
|
// index[from] is not updated and becomes stale. This works as long as index[]
|
||||||
// is accessed just by known occupied squares.
|
// is accessed just by known occupied squares.
|
||||||
Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to];
|
Bitboard fromTo = from | to;
|
||||||
byTypeBB[ALL_PIECES] ^= from_to_bb;
|
byTypeBB[ALL_PIECES] ^= fromTo;
|
||||||
byTypeBB[type_of(pc)] ^= from_to_bb;
|
byTypeBB[type_of(pc)] ^= fromTo;
|
||||||
byColorBB[color_of(pc)] ^= from_to_bb;
|
byColorBB[color_of(pc)] ^= fromTo;
|
||||||
board[from] = NO_PIECE;
|
board[from] = NO_PIECE;
|
||||||
board[to] = pc;
|
board[to] = pc;
|
||||||
index[to] = index[from];
|
index[to] = index[from];
|
||||||
pieceList[pc][index[to]] = to;
|
pieceList[pc][index[to]] = to;
|
||||||
|
psq += PSQT::psq[pc][to] - PSQT::psq[pc][from];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::do_move(Move m, StateInfo& newSt) {
|
inline void Position::do_move(Move m, StateInfo& newSt) {
|
||||||
|
|||||||
+58
-54
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -35,69 +35,72 @@ namespace PSQT {
|
|||||||
// type on a given square a (middlegame, endgame) score pair is assigned. Table
|
// type on a given square a (middlegame, endgame) score pair is assigned. Table
|
||||||
// is defined for files A..D and white side: it is symmetric for black side and
|
// is defined for files A..D and white side: it is symmetric for black side and
|
||||||
// second half of the files.
|
// second half of the files.
|
||||||
const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
constexpr Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
||||||
|
{ },
|
||||||
{ },
|
{ },
|
||||||
{ // Pawn
|
|
||||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
|
||||||
{ S(-11, 7), S( 6,-4), S( 7, 8), S( 3,-2) },
|
|
||||||
{ S(-18,-4), S( -2,-5), S( 19, 5), S(24, 4) },
|
|
||||||
{ S(-17, 3), S( -9, 3), S( 20,-8), S(35,-3) },
|
|
||||||
{ S( -6, 8), S( 5, 9), S( 3, 7), S(21,-6) },
|
|
||||||
{ S( -6, 8), S( -8,-5), S( -6, 2), S(-2, 4) },
|
|
||||||
{ S( -4, 3), S( 20,-9), S( -8, 1), S(-4,18) }
|
|
||||||
},
|
|
||||||
{ // Knight
|
{ // Knight
|
||||||
{ S(-161,-105), S(-96,-82), S(-80,-46), S(-73,-14) },
|
{ S(-175, -96), S(-92,-65), S(-74,-49), S(-73,-21) },
|
||||||
{ S( -83, -69), S(-43,-54), S(-21,-17), S(-10, 9) },
|
{ S( -77, -67), S(-41,-54), S(-27,-18), S(-15, 8) },
|
||||||
{ S( -71, -50), S(-22,-39), S( 0, -7), S( 9, 28) },
|
{ S( -61, -40), S(-17,-27), S( 6, -8), S( 12, 29) },
|
||||||
{ S( -25, -41), S( 18,-25), S( 43, 6), S( 47, 38) },
|
{ S( -35, -35), S( 8, -2), S( 40, 13), S( 49, 28) },
|
||||||
{ S( -26, -46), S( 16,-25), S( 38, 3), S( 50, 40) },
|
{ S( -34, -45), S( 13,-16), S( 44, 9), S( 51, 39) },
|
||||||
{ S( -11, -54), S( 37,-38), S( 56, -7), S( 65, 27) },
|
{ S( -9, -51), S( 22,-44), S( 58,-16), S( 53, 17) },
|
||||||
{ S( -63, -65), S(-19,-50), S( 5,-24), S( 14, 13) },
|
{ S( -67, -69), S(-27,-50), S( 4,-51), S( 37, 12) },
|
||||||
{ S(-195,-109), S(-67,-89), S(-42,-50), S(-29,-13) }
|
{ S(-201,-100), S(-83,-88), S(-56,-56), S(-26,-17) }
|
||||||
},
|
},
|
||||||
{ // Bishop
|
{ // Bishop
|
||||||
{ S(-44,-58), S(-13,-31), S(-25,-37), S(-34,-19) },
|
{ S(-53,-57), S( -5,-30), S( -8,-37), S(-23,-12) },
|
||||||
{ S(-20,-34), S( 20, -9), S( 12,-14), S( 1, 4) },
|
{ S(-15,-37), S( 8,-13), S( 19,-17), S( 4, 1) },
|
||||||
{ S( -9,-23), S( 27, 0), S( 21, -3), S( 11, 16) },
|
{ S( -7,-16), S( 21, -1), S( -5, -2), S( 17, 10) },
|
||||||
{ S(-11,-26), S( 28, -3), S( 21, -5), S( 10, 16) },
|
{ S( -5,-20), S( 11, -6), S( 25, 0), S( 39, 17) },
|
||||||
{ S(-11,-26), S( 27, -4), S( 16, -7), S( 9, 14) },
|
{ S(-12,-17), S( 29, -1), S( 22,-14), S( 31, 15) },
|
||||||
{ S(-17,-24), S( 16, -2), S( 12, 0), S( 2, 13) },
|
{ S(-16,-30), S( 6, 6), S( 1, 4), S( 11, 6) },
|
||||||
{ S(-23,-34), S( 17,-10), S( 6,-12), S( -2, 6) },
|
{ S(-17,-31), S(-14,-20), S( 5, -1), S( 0, 1) },
|
||||||
{ S(-35,-55), S(-11,-32), S(-19,-36), S(-29,-17) }
|
{ S(-48,-46), S( 1,-42), S(-14,-37), S(-23,-24) }
|
||||||
},
|
},
|
||||||
{ // Rook
|
{ // Rook
|
||||||
{ S(-25, 0), S(-16, 0), S(-16, 0), S(-9, 0) },
|
{ S(-31, -9), S(-20,-13), S(-14,-10), S(-5, -9) },
|
||||||
{ S(-21, 0), S( -8, 0), S( -3, 0), S( 0, 0) },
|
{ S(-21,-12), S(-13, -9), S( -8, -1), S( 6, -2) },
|
||||||
{ S(-21, 0), S( -9, 0), S( -4, 0), S( 2, 0) },
|
{ S(-25, 6), S(-11, -8), S( -1, -2), S( 3, -6) },
|
||||||
{ S(-22, 0), S( -6, 0), S( -1, 0), S( 2, 0) },
|
{ S(-13, -6), S( -5, 1), S( -4, -9), S(-6, 7) },
|
||||||
{ S(-22, 0), S( -7, 0), S( 0, 0), S( 1, 0) },
|
{ S(-27, -5), S(-15, 8), S( -4, 7), S( 3, -6) },
|
||||||
{ S(-21, 0), S( -7, 0), S( 0, 0), S( 2, 0) },
|
{ S(-22, 6), S( -2, 1), S( 6, -7), S(12, 10) },
|
||||||
{ S(-12, 0), S( 4, 0), S( 8, 0), S(12, 0) },
|
{ S( -2, 4), S( 12, 5), S( 16, 20), S(18, -5) },
|
||||||
{ S(-23, 0), S(-15, 0), S(-11, 0), S(-5, 0) }
|
{ S(-17, 18), S(-19, 0), S( -1, 19), S( 9, 13) }
|
||||||
},
|
},
|
||||||
{ // Queen
|
{ // Queen
|
||||||
{ S( 0,-71), S(-4,-56), S(-3,-42), S(-1,-29) },
|
{ S( 3,-69), S(-5,-57), S(-5,-47), S( 4,-26) },
|
||||||
{ S(-4,-56), S( 6,-30), S( 9,-21), S( 8, -5) },
|
{ S(-3,-55), S( 5,-31), S( 8,-22), S(12, -4) },
|
||||||
{ S(-2,-39), S( 6,-17), S( 9, -8), S( 9, 5) },
|
{ S(-3,-39), S( 6,-18), S(13, -9), S( 7, 3) },
|
||||||
{ S(-1,-29), S( 8, -5), S(10, 9), S( 7, 19) },
|
{ S( 4,-23), S( 5, -3), S( 9, 13), S( 8, 24) },
|
||||||
{ S(-3,-27), S( 9, -5), S( 8, 10), S( 7, 21) },
|
{ S( 0,-29), S(14, -6), S(12, 9), S( 5, 21) },
|
||||||
{ S(-2,-40), S( 6,-16), S( 8,-10), S(10, 3) },
|
{ S(-4,-38), S(10,-18), S( 6,-12), S( 8, 1) },
|
||||||
{ S(-2,-55), S( 7,-30), S( 7,-21), S( 6, -6) },
|
{ S(-5,-50), S( 6,-27), S(10,-24), S( 8, -8) },
|
||||||
{ S(-1,-74), S(-4,-55), S(-1,-43), S( 0,-30) }
|
{ S(-2,-75), S(-2,-52), S( 1,-43), S(-2,-36) }
|
||||||
},
|
},
|
||||||
{ // King
|
{ // King
|
||||||
{ S(267, 0), S(320, 48), S(270, 75), S(195, 84) },
|
{ S(271, 1), S(327, 45), S(271, 85), S(198, 76) },
|
||||||
{ S(264, 43), S(304, 92), S(238,143), S(180,132) },
|
{ S(278, 53), S(303,100), S(234,133), S(179,135) },
|
||||||
{ S(200, 83), S(245,138), S(176,167), S(110,165) },
|
{ S(195, 88), S(258,130), S(169,169), S(120,175) },
|
||||||
{ S(177,106), S(185,169), S(148,169), S(110,179) },
|
{ S(164,103), S(190,156), S(138,172), S( 98,172) },
|
||||||
{ S(149,108), S(177,163), S(115,200), S( 66,203) },
|
{ S(154, 96), S(179,166), S(105,199), S( 70,199) },
|
||||||
{ S(118, 95), S(159,155), S( 84,176), S( 41,174) },
|
{ S(123, 92), S(145,172), S( 81,184), S( 31,191) },
|
||||||
{ S( 87, 50), S(128, 99), S( 63,122), S( 20,139) },
|
{ S( 88, 47), S(120,121), S( 65,116), S( 33,131) },
|
||||||
{ S( 63, 9), S( 88, 55), S( 47, 80), S( 0, 90) }
|
{ S( 59, 11), S( 89, 59), S( 45, 73), S( -1, 78) }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr Score PBonus[RANK_NB][FILE_NB] =
|
||||||
|
{ // Pawn (asymmetric distribution)
|
||||||
|
{ },
|
||||||
|
{ S( 3,-10), S( 3, -6), S( 10, 10), S( 19, 0), S( 16, 14), S( 19, 7), S( 7, -5), S( -5,-19) },
|
||||||
|
{ S( -9,-10), S(-15,-10), S( 11,-10), S( 15, 4), S( 32, 4), S( 22, 3), S( 5, -6), S(-22, -4) },
|
||||||
|
{ S( -8, 6), S(-23, -2), S( 6, -8), S( 20, -4), S( 40,-13), S( 17,-12), S( 4,-10), S(-12, -9) },
|
||||||
|
{ S( 13, 9), S( 0, 4), S(-13, 3), S( 1,-12), S( 11,-12), S( -2, -6), S(-13, 13), S( 5, 8) },
|
||||||
|
{ S( -5, 28), S(-12, 20), S( -7, 21), S( 22, 28), S( -8, 30), S( -5, 7), S(-15, 6), S(-18, 13) },
|
||||||
|
{ S( -7, 0), S( 7,-11), S( -3, 12), S(-13, 21), S( 5, 25), S(-16, 19), S( 10, 4), S( -8, 7) }
|
||||||
|
};
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
|
|
||||||
Score psq[PIECE_NB][SQUARE_NB];
|
Score psq[PIECE_NB][SQUARE_NB];
|
||||||
@@ -112,12 +115,13 @@ void init() {
|
|||||||
PieceValue[MG][~pc] = PieceValue[MG][pc];
|
PieceValue[MG][~pc] = PieceValue[MG][pc];
|
||||||
PieceValue[EG][~pc] = PieceValue[EG][pc];
|
PieceValue[EG][~pc] = PieceValue[EG][pc];
|
||||||
|
|
||||||
Score v = make_score(PieceValue[MG][pc], PieceValue[EG][pc]);
|
Score score = make_score(PieceValue[MG][pc], PieceValue[EG][pc]);
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
File f = std::min(file_of(s), ~file_of(s));
|
File f = map_to_queenside(file_of(s));
|
||||||
psq[ pc][ s] = v + Bonus[pc][rank_of(s)][f];
|
psq[ pc][ s] = score + (type_of(pc) == PAWN ? PBonus[rank_of(s)][file_of(s)]
|
||||||
|
: Bonus[pc][rank_of(s)][f]);
|
||||||
psq[~pc][~s] = -psq[pc][s];
|
psq[~pc][~s] = -psq[pc][s];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+784
-560
File diff suppressed because it is too large
Load Diff
+11
-8
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,7 +32,7 @@ class Position;
|
|||||||
namespace Search {
|
namespace Search {
|
||||||
|
|
||||||
/// Threshold used for countermoves based pruning
|
/// Threshold used for countermoves based pruning
|
||||||
const int CounterMovePruneThreshold = 0;
|
constexpr int CounterMovePruneThreshold = 0;
|
||||||
|
|
||||||
|
|
||||||
/// Stack struct keeps track of the information we need to remember from nodes
|
/// Stack struct keeps track of the information we need to remember from nodes
|
||||||
@@ -41,7 +41,7 @@ const int CounterMovePruneThreshold = 0;
|
|||||||
|
|
||||||
struct Stack {
|
struct Stack {
|
||||||
Move* pv;
|
Move* pv;
|
||||||
PieceToHistory* contHistory;
|
PieceToHistory* continuationHistory;
|
||||||
int ply;
|
int ply;
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Move excludedMove;
|
Move excludedMove;
|
||||||
@@ -69,6 +69,9 @@ struct RootMove {
|
|||||||
Value score = -VALUE_INFINITE;
|
Value score = -VALUE_INFINITE;
|
||||||
Value previousScore = -VALUE_INFINITE;
|
Value previousScore = -VALUE_INFINITE;
|
||||||
int selDepth = 0;
|
int selDepth = 0;
|
||||||
|
int tbRank = 0;
|
||||||
|
int bestMoveCount = 0;
|
||||||
|
Value tbScore;
|
||||||
std::vector<Move> pv;
|
std::vector<Move> pv;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,8 +84,9 @@ typedef std::vector<RootMove> RootMoves;
|
|||||||
struct LimitsType {
|
struct LimitsType {
|
||||||
|
|
||||||
LimitsType() { // Init explicitly due to broken value-initialization of non POD in MSVC
|
LimitsType() { // Init explicitly due to broken value-initialization of non POD in MSVC
|
||||||
nodes = time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] =
|
time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0);
|
||||||
npmsec = movestogo = depth = movetime = mate = perft = infinite = 0;
|
movestogo = depth = mate = perft = infinite = 0;
|
||||||
|
nodes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_time_management() const {
|
bool use_time_management() const {
|
||||||
@@ -90,10 +94,9 @@ struct LimitsType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Move> searchmoves;
|
std::vector<Move> searchmoves;
|
||||||
int time[COLOR_NB], inc[COLOR_NB], npmsec, movestogo, depth,
|
TimePoint time[COLOR_NB], inc[COLOR_NB], npmsec, movetime, startTime;
|
||||||
movetime, mate, perft, infinite;
|
int movestogo, depth, mate, perft, infinite;
|
||||||
int64_t nodes;
|
int64_t nodes;
|
||||||
TimePoint startTime;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern LimitsType Limits;
|
extern LimitsType Limits;
|
||||||
|
|||||||
+471
-571
File diff suppressed because it is too large
Load Diff
@@ -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) 2013 Ronald de Man
|
Copyright (c) 2013 Ronald de Man
|
||||||
Copyright (C) 2016-2018 Marco Costalba, Lucas Braesch
|
Copyright (C) 2016-2020 Marco Costalba, Lucas Braesch
|
||||||
|
|
||||||
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,9 +49,9 @@ extern int MaxCardinality;
|
|||||||
void init(const std::string& paths);
|
void init(const std::string& paths);
|
||||||
WDLScore probe_wdl(Position& pos, ProbeState* result);
|
WDLScore probe_wdl(Position& pos, ProbeState* result);
|
||||||
int probe_dtz(Position& pos, ProbeState* result);
|
int probe_dtz(Position& pos, ProbeState* result);
|
||||||
bool root_probe(Position& pos, Search::RootMoves& rootMoves, Value& score);
|
bool root_probe(Position& pos, Search::RootMoves& rootMoves);
|
||||||
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves, Value& score);
|
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves);
|
||||||
void filter_root_moves(Position& pos, Search::RootMoves& rootMoves);
|
void rank_root_moves(Position& pos, Search::RootMoves& rootMoves);
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& os, const WDLScore v) {
|
inline std::ostream& operator<<(std::ostream& os, const WDLScore v) {
|
||||||
|
|
||||||
|
|||||||
+39
-18
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -18,20 +18,21 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm> // For std::count
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <algorithm> // For std::count
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
#include "syzygy/tbprobe.h"
|
#include "syzygy/tbprobe.h"
|
||||||
|
#include "tt.h"
|
||||||
|
|
||||||
ThreadPool Threads; // Global object
|
ThreadPool Threads; // Global object
|
||||||
|
|
||||||
|
|
||||||
/// Thread constructor launches the thread and waits until it goes to sleep
|
/// Thread constructor launches the thread and waits until it goes to sleep
|
||||||
/// in idle_loop(). Note that 'searching' and 'exit' should be alredy set.
|
/// in idle_loop(). Note that 'searching' and 'exit' should be already set.
|
||||||
|
|
||||||
Thread::Thread(size_t n) : idx(n), stdThread(&Thread::idle_loop, this) {
|
Thread::Thread(size_t n) : idx(n), stdThread(&Thread::idle_loop, this) {
|
||||||
|
|
||||||
@@ -51,6 +52,15 @@ Thread::~Thread() {
|
|||||||
stdThread.join();
|
stdThread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Thread::bestMoveCount(Move move) return best move counter for the given root move
|
||||||
|
|
||||||
|
int Thread::best_move_count(Move move) {
|
||||||
|
|
||||||
|
auto rm = std::find(rootMoves.begin() + pvIdx,
|
||||||
|
rootMoves.begin() + pvLast, move);
|
||||||
|
|
||||||
|
return rm != rootMoves.begin() + pvLast ? rm->bestMoveCount : 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Thread::clear() reset histories, usually before a new game
|
/// Thread::clear() reset histories, usually before a new game
|
||||||
|
|
||||||
@@ -60,18 +70,22 @@ void Thread::clear() {
|
|||||||
mainHistory.fill(0);
|
mainHistory.fill(0);
|
||||||
captureHistory.fill(0);
|
captureHistory.fill(0);
|
||||||
|
|
||||||
for (auto& to : contHistory)
|
for (bool inCheck : { false, true })
|
||||||
for (auto& h : to)
|
for (StatsType c : { NoCaptures, Captures })
|
||||||
h.fill(0);
|
for (auto& to : continuationHistory[inCheck][c])
|
||||||
|
for (auto& h : to)
|
||||||
|
h->fill(0);
|
||||||
|
|
||||||
contHistory[NO_PIECE][0].fill(Search::CounterMovePruneThreshold - 1);
|
for (bool inCheck : { false, true })
|
||||||
|
for (StatsType c : { NoCaptures, Captures })
|
||||||
|
continuationHistory[inCheck][c][NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Thread::start_searching() wakes up the thread that will start the search
|
/// Thread::start_searching() wakes up the thread that will start the search
|
||||||
|
|
||||||
void Thread::start_searching() {
|
void Thread::start_searching() {
|
||||||
|
|
||||||
std::lock_guard<Mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
searching = true;
|
searching = true;
|
||||||
cv.notify_one(); // Wake up the thread in idle_loop()
|
cv.notify_one(); // Wake up the thread in idle_loop()
|
||||||
}
|
}
|
||||||
@@ -82,7 +96,7 @@ void Thread::start_searching() {
|
|||||||
|
|
||||||
void Thread::wait_for_search_finished() {
|
void Thread::wait_for_search_finished() {
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
cv.wait(lk, [&]{ return !searching; });
|
cv.wait(lk, [&]{ return !searching; });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,12 +111,12 @@ void Thread::idle_loop() {
|
|||||||
// some Windows NUMA hardware, for instance in fishtest. To make it simple,
|
// some Windows NUMA hardware, for instance in fishtest. To make it simple,
|
||||||
// just check if running threads are below a threshold, in this case all this
|
// just check if running threads are below a threshold, in this case all this
|
||||||
// NUMA machinery is not needed.
|
// NUMA machinery is not needed.
|
||||||
if (Options["Threads"] >= 8)
|
if (Options["Threads"] > 8)
|
||||||
WinProcGroup::bindThisThread(idx);
|
WinProcGroup::bindThisThread(idx);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
searching = false;
|
searching = false;
|
||||||
cv.notify_one(); // Wake up anyone waiting for search finished
|
cv.notify_one(); // Wake up anyone waiting for search finished
|
||||||
cv.wait(lk, [&]{ return searching; });
|
cv.wait(lk, [&]{ return searching; });
|
||||||
@@ -117,7 +131,7 @@ void Thread::idle_loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// ThreadPool::set() creates/destroys threads to match the requested number.
|
/// ThreadPool::set() creates/destroys threads to match the requested number.
|
||||||
/// Created and launced threads wil go immediately to sleep in idle_loop.
|
/// Created and launched threads will immediately go to sleep in idle_loop.
|
||||||
/// Upon resizing, threads are recreated to allow for binding if necessary.
|
/// Upon resizing, threads are recreated to allow for binding if necessary.
|
||||||
|
|
||||||
void ThreadPool::set(size_t requested) {
|
void ThreadPool::set(size_t requested) {
|
||||||
@@ -135,6 +149,12 @@ void ThreadPool::set(size_t requested) {
|
|||||||
while (size() < requested)
|
while (size() < requested)
|
||||||
push_back(new Thread(size()));
|
push_back(new Thread(size()));
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
// Reallocate the hash with the new threadpool size
|
||||||
|
TT.resize(Options["Hash"]);
|
||||||
|
|
||||||
|
// Init thread number dependent search params.
|
||||||
|
Search::init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +167,7 @@ void ThreadPool::clear() {
|
|||||||
|
|
||||||
main()->callsCnt = 0;
|
main()->callsCnt = 0;
|
||||||
main()->previousScore = VALUE_INFINITE;
|
main()->previousScore = VALUE_INFINITE;
|
||||||
main()->previousTimeReduction = 1;
|
main()->previousTimeReduction = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and
|
/// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and
|
||||||
@@ -158,8 +178,9 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
|
|||||||
|
|
||||||
main()->wait_for_search_finished();
|
main()->wait_for_search_finished();
|
||||||
|
|
||||||
stopOnPonderhit = stop = false;
|
main()->stopOnPonderhit = stop = false;
|
||||||
ponder = ponderMode;
|
increaseDepth = true;
|
||||||
|
main()->ponder = ponderMode;
|
||||||
Search::Limits = limits;
|
Search::Limits = limits;
|
||||||
Search::RootMoves rootMoves;
|
Search::RootMoves rootMoves;
|
||||||
|
|
||||||
@@ -169,7 +190,7 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
|
|||||||
rootMoves.emplace_back(m);
|
rootMoves.emplace_back(m);
|
||||||
|
|
||||||
if (!rootMoves.empty())
|
if (!rootMoves.empty())
|
||||||
Tablebases::filter_root_moves(pos, rootMoves);
|
Tablebases::rank_root_moves(pos, rootMoves);
|
||||||
|
|
||||||
// After ownership transfer 'states' becomes empty, so if we stop the search
|
// After ownership transfer 'states' becomes empty, so if we stop the search
|
||||||
// and call 'go' again without setting a new position states.get() == NULL.
|
// and call 'go' again without setting a new position states.get() == NULL.
|
||||||
@@ -187,8 +208,8 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
|
|||||||
|
|
||||||
for (Thread* th : *this)
|
for (Thread* th : *this)
|
||||||
{
|
{
|
||||||
th->nodes = th->tbHits = th->nmp_ply = th->nmp_odd = 0;
|
th->nodes = th->tbHits = th->nmpMinPly = 0;
|
||||||
th->rootDepth = th->completedDepth = DEPTH_ZERO;
|
th->rootDepth = th->completedDepth = 0;
|
||||||
th->rootMoves = rootMoves;
|
th->rootMoves = rootMoves;
|
||||||
th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th);
|
th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th);
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-13
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,7 +32,7 @@
|
|||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread_win32.h"
|
#include "thread_win32_osx.h"
|
||||||
|
|
||||||
|
|
||||||
/// Thread class keeps together all the thread-related stuff. We use
|
/// Thread class keeps together all the thread-related stuff. We use
|
||||||
@@ -42,11 +42,11 @@
|
|||||||
|
|
||||||
class Thread {
|
class Thread {
|
||||||
|
|
||||||
Mutex mutex;
|
std::mutex mutex;
|
||||||
ConditionVariable cv;
|
std::condition_variable cv;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
bool exit = false, searching = true; // Set before starting std::thread
|
bool exit = false, searching = true; // Set before starting std::thread
|
||||||
std::thread stdThread;
|
NativeThread stdThread;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Thread(size_t);
|
explicit Thread(size_t);
|
||||||
@@ -56,13 +56,15 @@ public:
|
|||||||
void idle_loop();
|
void idle_loop();
|
||||||
void start_searching();
|
void start_searching();
|
||||||
void wait_for_search_finished();
|
void wait_for_search_finished();
|
||||||
|
int best_move_count(Move move);
|
||||||
|
|
||||||
Pawns::Table pawnsTable;
|
Pawns::Table pawnsTable;
|
||||||
Material::Table materialTable;
|
Material::Table materialTable;
|
||||||
Endgames endgames;
|
size_t pvIdx, pvLast;
|
||||||
size_t PVIdx;
|
uint64_t ttHitAverage;
|
||||||
int selDepth, nmp_ply, nmp_odd;
|
int selDepth, nmpMinPly;
|
||||||
std::atomic<uint64_t> nodes, tbHits;
|
Color nmpColor;
|
||||||
|
std::atomic<uint64_t> nodes, tbHits, bestMoveChanges;
|
||||||
|
|
||||||
Position rootPos;
|
Position rootPos;
|
||||||
Search::RootMoves rootMoves;
|
Search::RootMoves rootMoves;
|
||||||
@@ -70,7 +72,8 @@ public:
|
|||||||
CounterMoveHistory counterMoves;
|
CounterMoveHistory counterMoves;
|
||||||
ButterflyHistory mainHistory;
|
ButterflyHistory mainHistory;
|
||||||
CapturePieceToHistory captureHistory;
|
CapturePieceToHistory captureHistory;
|
||||||
ContinuationHistory contHistory;
|
ContinuationHistory continuationHistory[2][2];
|
||||||
|
Score contempt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -83,10 +86,12 @@ struct MainThread : public Thread {
|
|||||||
void search() override;
|
void search() override;
|
||||||
void check_time();
|
void check_time();
|
||||||
|
|
||||||
bool failedLow;
|
double previousTimeReduction;
|
||||||
double bestMoveChanges, previousTimeReduction;
|
|
||||||
Value previousScore;
|
Value previousScore;
|
||||||
|
Value iterValue[4];
|
||||||
int callsCnt;
|
int callsCnt;
|
||||||
|
bool stopOnPonderhit;
|
||||||
|
std::atomic_bool ponder;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -104,7 +109,7 @@ struct ThreadPool : public std::vector<Thread*> {
|
|||||||
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
|
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
|
||||||
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
|
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
|
||||||
|
|
||||||
std::atomic_bool stop, ponder, stopOnPonderhit;
|
std::atomic_bool stop, increaseDepth;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StateListPtr setupStates;
|
StateListPtr setupStates;
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef THREAD_WIN32_H_INCLUDED
|
|
||||||
#define THREAD_WIN32_H_INCLUDED
|
|
||||||
|
|
||||||
/// STL thread library used by mingw and gcc when cross compiling for Windows
|
|
||||||
/// relies on libwinpthread. Currently libwinpthread implements mutexes directly
|
|
||||||
/// on top of Windows semaphores. Semaphores, being kernel objects, require kernel
|
|
||||||
/// mode transition in order to lock or unlock, which is very slow compared to
|
|
||||||
/// interlocked operations (about 30% slower on bench test). To work around this
|
|
||||||
/// issue, we define our wrappers to the low level Win32 calls. We use critical
|
|
||||||
/// sections to support Windows XP and older versions. Unfortunately, cond_wait()
|
|
||||||
/// is racy between unlock() and WaitForSingleObject() but they have the same
|
|
||||||
/// speed performance as the SRW locks.
|
|
||||||
|
|
||||||
#include <condition_variable>
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(_MSC_VER)
|
|
||||||
|
|
||||||
#ifndef NOMINMAX
|
|
||||||
# define NOMINMAX // Disable macros min() and max()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#undef WIN32_LEAN_AND_MEAN
|
|
||||||
#undef NOMINMAX
|
|
||||||
|
|
||||||
/// Mutex and ConditionVariable struct are wrappers of the low level locking
|
|
||||||
/// machinery and are modeled after the corresponding C++11 classes.
|
|
||||||
|
|
||||||
struct Mutex {
|
|
||||||
Mutex() { InitializeCriticalSection(&cs); }
|
|
||||||
~Mutex() { DeleteCriticalSection(&cs); }
|
|
||||||
void lock() { EnterCriticalSection(&cs); }
|
|
||||||
void unlock() { LeaveCriticalSection(&cs); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CRITICAL_SECTION cs;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::condition_variable_any ConditionVariable;
|
|
||||||
|
|
||||||
#else // Default case: use STL classes
|
|
||||||
|
|
||||||
typedef std::mutex Mutex;
|
|
||||||
typedef std::condition_variable ConditionVariable;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef THREAD_WIN32_H_INCLUDED
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef THREAD_WIN32_OSX_H_INCLUDED
|
||||||
|
#define THREAD_WIN32_OSX_H_INCLUDED
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
/// On OSX threads other than the main thread are created with a reduced stack
|
||||||
|
/// size of 512KB by default, this is too low for deep searches, which require
|
||||||
|
/// somewhat more than 1MB stack, so adjust it to TH_STACK_SIZE.
|
||||||
|
/// The implementation calls pthread_create() with the stack size parameter
|
||||||
|
/// equal to the linux 8MB default, on platforms that support it.
|
||||||
|
|
||||||
|
#if defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__)
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
static const size_t TH_STACK_SIZE = 8 * 1024 * 1024;
|
||||||
|
|
||||||
|
template <class T, class P = std::pair<T*, void(T::*)()>>
|
||||||
|
void* start_routine(void* ptr)
|
||||||
|
{
|
||||||
|
P* p = reinterpret_cast<P*>(ptr);
|
||||||
|
(p->first->*(p->second))(); // Call member function pointer
|
||||||
|
delete p;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
class NativeThread {
|
||||||
|
|
||||||
|
pthread_t thread;
|
||||||
|
|
||||||
|
public:
|
||||||
|
template<class T, class P = std::pair<T*, void(T::*)()>>
|
||||||
|
explicit NativeThread(void(T::*fun)(), T* obj) {
|
||||||
|
pthread_attr_t attr_storage, *attr = &attr_storage;
|
||||||
|
pthread_attr_init(attr);
|
||||||
|
pthread_attr_setstacksize(attr, TH_STACK_SIZE);
|
||||||
|
pthread_create(&thread, attr, start_routine<T>, new P(obj, fun));
|
||||||
|
}
|
||||||
|
void join() { pthread_join(thread, NULL); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#else // Default case: use STL classes
|
||||||
|
|
||||||
|
typedef std::thread NativeThread;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef THREAD_WIN32_OSX_H_INCLUDED
|
||||||
+31
-30
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,9 +32,9 @@ namespace {
|
|||||||
|
|
||||||
enum TimeType { OptimumTime, MaxTime };
|
enum TimeType { OptimumTime, MaxTime };
|
||||||
|
|
||||||
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
constexpr int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||||
const double MaxRatio = 7.09; // When in trouble, we can step over reserved time with this ratio
|
constexpr double MaxRatio = 7.3; // When in trouble, we can step over reserved time with this ratio
|
||||||
const double StealRatio = 0.35; // However we must not steal time from remaining moves over this ratio
|
constexpr double StealRatio = 0.34; // However we must not steal time from remaining moves over this ratio
|
||||||
|
|
||||||
|
|
||||||
// move_importance() is a skew-logistic function based on naive statistical
|
// move_importance() is a skew-logistic function based on naive statistical
|
||||||
@@ -44,21 +44,21 @@ namespace {
|
|||||||
|
|
||||||
double move_importance(int ply) {
|
double move_importance(int ply) {
|
||||||
|
|
||||||
const double XScale = 7.64;
|
constexpr double XScale = 6.85;
|
||||||
const double XShift = 58.4;
|
constexpr double XShift = 64.5;
|
||||||
const double Skew = 0.183;
|
constexpr double Skew = 0.171;
|
||||||
|
|
||||||
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
||||||
}
|
}
|
||||||
|
|
||||||
template<TimeType T>
|
template<TimeType T>
|
||||||
int remaining(int myTime, int movesToGo, int ply, int slowMover) {
|
TimePoint remaining(TimePoint myTime, int movesToGo, int ply, TimePoint slowMover) {
|
||||||
|
|
||||||
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
constexpr double TMaxRatio = (T == OptimumTime ? 1.0 : MaxRatio);
|
||||||
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
constexpr double TStealRatio = (T == OptimumTime ? 0.0 : StealRatio);
|
||||||
|
|
||||||
double moveImportance = (move_importance(ply) * slowMover) / 100;
|
double moveImportance = (move_importance(ply) * slowMover) / 100.0;
|
||||||
double otherMovesImportance = 0;
|
double otherMovesImportance = 0.0;
|
||||||
|
|
||||||
for (int i = 1; i < movesToGo; ++i)
|
for (int i = 1; i < movesToGo; ++i)
|
||||||
otherMovesImportance += move_importance(ply + 2 * i);
|
otherMovesImportance += move_importance(ply + 2 * i);
|
||||||
@@ -66,7 +66,7 @@ namespace {
|
|||||||
double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance);
|
double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance);
|
||||||
double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance);
|
double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance);
|
||||||
|
|
||||||
return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast
|
return TimePoint(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -83,22 +83,23 @@ namespace {
|
|||||||
|
|
||||||
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
||||||
|
|
||||||
int minThinkingTime = Options["Minimum Thinking Time"];
|
TimePoint minThinkingTime = Options["Minimum Thinking Time"];
|
||||||
int moveOverhead = Options["Move Overhead"];
|
TimePoint moveOverhead = Options["Move Overhead"];
|
||||||
int slowMover = Options["Slow Mover"];
|
TimePoint slowMover = Options["Slow Mover"];
|
||||||
int npmsec = Options["nodestime"];
|
TimePoint npmsec = Options["nodestime"];
|
||||||
|
TimePoint hypMyTime;
|
||||||
|
|
||||||
// If we have to play in 'nodes as time' mode, then convert from time
|
// If we have to play in 'nodes as time' mode, then convert from time
|
||||||
// to nodes, and use resulting values in time management formulas.
|
// to nodes, and use resulting values in time management formulas.
|
||||||
// WARNING: Given npms (nodes per millisecond) must be much lower then
|
// WARNING: to avoid time losses, the given npmsec (nodes per millisecond)
|
||||||
// the real engine speed to avoid time losses.
|
// must be much lower than the real engine speed.
|
||||||
if (npmsec)
|
if (npmsec)
|
||||||
{
|
{
|
||||||
if (!availableNodes) // Only once at game start
|
if (!availableNodes) // Only once at game start
|
||||||
availableNodes = npmsec * limits.time[us]; // Time is in msec
|
availableNodes = npmsec * limits.time[us]; // Time is in msec
|
||||||
|
|
||||||
// Convert from millisecs to nodes
|
// Convert from milliseconds to nodes
|
||||||
limits.time[us] = (int)availableNodes;
|
limits.time[us] = TimePoint(availableNodes);
|
||||||
limits.inc[us] *= npmsec;
|
limits.inc[us] *= npmsec;
|
||||||
limits.npmsec = npmsec;
|
limits.npmsec = npmsec;
|
||||||
}
|
}
|
||||||
@@ -106,22 +107,22 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
|||||||
startTime = limits.startTime;
|
startTime = limits.startTime;
|
||||||
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
||||||
|
|
||||||
const int MaxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
const int maxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
||||||
|
|
||||||
// We calculate optimum time usage for different hypothetical "moves to go"-values
|
// We calculate optimum time usage for different hypothetical "moves to go" values
|
||||||
// and choose the minimum of calculated search time values. Usually the greatest
|
// and choose the minimum of calculated search time values. Usually the greatest
|
||||||
// hypMTG gives the minimum values.
|
// hypMTG gives the minimum values.
|
||||||
for (int hypMTG = 1; hypMTG <= MaxMTG; ++hypMTG)
|
for (int hypMTG = 1; hypMTG <= maxMTG; ++hypMTG)
|
||||||
{
|
{
|
||||||
// Calculate thinking time for hypothetical "moves to go"-value
|
// Calculate thinking time for hypothetical "moves to go"-value
|
||||||
int hypMyTime = limits.time[us]
|
hypMyTime = limits.time[us]
|
||||||
+ limits.inc[us] * (hypMTG - 1)
|
+ limits.inc[us] * (hypMTG - 1)
|
||||||
- moveOverhead * (2 + std::min(hypMTG, 40));
|
- moveOverhead * (2 + std::min(hypMTG, 40));
|
||||||
|
|
||||||
hypMyTime = std::max(hypMyTime, 0);
|
hypMyTime = std::max(hypMyTime, TimePoint(0));
|
||||||
|
|
||||||
int t1 = minThinkingTime + remaining<OptimumTime>(hypMyTime, hypMTG, ply, slowMover);
|
TimePoint t1 = minThinkingTime + remaining<OptimumTime>(hypMyTime, hypMTG, ply, slowMover);
|
||||||
int t2 = minThinkingTime + remaining<MaxTime >(hypMyTime, hypMTG, ply, slowMover);
|
TimePoint t2 = minThinkingTime + remaining<MaxTime >(hypMyTime, hypMTG, ply, slowMover);
|
||||||
|
|
||||||
optimumTime = std::min(t1, optimumTime);
|
optimumTime = std::min(t1, optimumTime);
|
||||||
maximumTime = std::min(t2, maximumTime);
|
maximumTime = std::min(t2, maximumTime);
|
||||||
|
|||||||
+7
-6
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,16 +31,17 @@
|
|||||||
class TimeManagement {
|
class TimeManagement {
|
||||||
public:
|
public:
|
||||||
void init(Search::LimitsType& limits, Color us, int ply);
|
void init(Search::LimitsType& limits, Color us, int ply);
|
||||||
int optimum() const { return optimumTime; }
|
TimePoint optimum() const { return optimumTime; }
|
||||||
int maximum() const { return maximumTime; }
|
TimePoint maximum() const { return maximumTime; }
|
||||||
int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - startTime); }
|
TimePoint elapsed() const { return Search::Limits.npmsec ?
|
||||||
|
TimePoint(Threads.nodes_searched()) : now() - startTime; }
|
||||||
|
|
||||||
int64_t availableNodes; // When in 'nodes as time' mode
|
int64_t availableNodes; // When in 'nodes as time' mode
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimePoint startTime;
|
TimePoint startTime;
|
||||||
int optimumTime;
|
TimePoint optimumTime;
|
||||||
int maximumTime;
|
TimePoint maximumTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TimeManagement Time;
|
extern TimeManagement Time;
|
||||||
|
|||||||
+65
-25
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -20,12 +20,40 @@
|
|||||||
|
|
||||||
#include <cstring> // For std::memset
|
#include <cstring> // For std::memset
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "thread.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
|
#include "uci.h"
|
||||||
|
|
||||||
TranspositionTable TT; // Our global transposition table
|
TranspositionTable TT; // Our global transposition table
|
||||||
|
|
||||||
|
/// TTEntry::save populates the TTEntry with a new node's data, possibly
|
||||||
|
/// overwriting an old position. Update is not atomic and can be racy.
|
||||||
|
|
||||||
|
void TTEntry::save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev) {
|
||||||
|
|
||||||
|
// Preserve any existing move for the same position
|
||||||
|
if (m || (k >> 48) != key16)
|
||||||
|
move16 = (uint16_t)m;
|
||||||
|
|
||||||
|
// Overwrite less valuable entries
|
||||||
|
if ( (k >> 48) != key16
|
||||||
|
|| d - DEPTH_OFFSET > depth8 - 4
|
||||||
|
|| b == BOUND_EXACT)
|
||||||
|
{
|
||||||
|
assert(d >= DEPTH_OFFSET);
|
||||||
|
|
||||||
|
key16 = (uint16_t)(k >> 48);
|
||||||
|
value16 = (int16_t)v;
|
||||||
|
eval16 = (int16_t)ev;
|
||||||
|
genBound8 = (uint8_t)(TT.generation8 | uint8_t(pv) << 2 | b);
|
||||||
|
depth8 = (uint8_t)(d - DEPTH_OFFSET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::resize() sets the size of the transposition table,
|
/// TranspositionTable::resize() sets the size of the transposition table,
|
||||||
/// measured in megabytes. Transposition table consists of a power of 2 number
|
/// measured in megabytes. Transposition table consists of a power of 2 number
|
||||||
@@ -33,12 +61,9 @@ TranspositionTable TT; // Our global transposition table
|
|||||||
|
|
||||||
void TranspositionTable::resize(size_t mbSize) {
|
void TranspositionTable::resize(size_t mbSize) {
|
||||||
|
|
||||||
size_t newClusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
|
Threads.main()->wait_for_search_finished();
|
||||||
|
|
||||||
if (newClusterCount == clusterCount)
|
clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
|
||||||
return;
|
|
||||||
|
|
||||||
clusterCount = newClusterCount;
|
|
||||||
|
|
||||||
free(mem);
|
free(mem);
|
||||||
mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);
|
mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);
|
||||||
@@ -55,15 +80,34 @@ void TranspositionTable::resize(size_t mbSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::clear() overwrites the entire transposition table
|
/// TranspositionTable::clear() initializes the entire transposition table to zero,
|
||||||
/// with zeros. It is called whenever the table is resized, or when the
|
// in a multi-threaded way.
|
||||||
/// user asks the program to clear the table (from the UCI interface).
|
|
||||||
|
|
||||||
void TranspositionTable::clear() {
|
void TranspositionTable::clear() {
|
||||||
|
|
||||||
std::memset(table, 0, clusterCount * sizeof(Cluster));
|
std::vector<std::thread> threads;
|
||||||
}
|
|
||||||
|
|
||||||
|
for (size_t idx = 0; idx < Options["Threads"]; ++idx)
|
||||||
|
{
|
||||||
|
threads.emplace_back([this, idx]() {
|
||||||
|
|
||||||
|
// Thread binding gives faster search on systems with a first-touch policy
|
||||||
|
if (Options["Threads"] > 8)
|
||||||
|
WinProcGroup::bindThisThread(idx);
|
||||||
|
|
||||||
|
// Each thread will zero its part of the hash table
|
||||||
|
const size_t stride = clusterCount / Options["Threads"],
|
||||||
|
start = stride * idx,
|
||||||
|
len = idx != Options["Threads"] - 1 ?
|
||||||
|
stride : clusterCount - start;
|
||||||
|
|
||||||
|
std::memset(&table[start], 0, len * sizeof(Cluster));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::thread& th: threads)
|
||||||
|
th.join();
|
||||||
|
}
|
||||||
|
|
||||||
/// TranspositionTable::probe() looks up the current position in the transposition
|
/// TranspositionTable::probe() looks up the current position in the transposition
|
||||||
/// table. It returns true and a pointer to the TTEntry if the position is found.
|
/// table. It returns true and a pointer to the TTEntry if the position is found.
|
||||||
@@ -80,8 +124,7 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
|||||||
for (int i = 0; i < ClusterSize; ++i)
|
for (int i = 0; i < ClusterSize; ++i)
|
||||||
if (!tte[i].key16 || tte[i].key16 == key16)
|
if (!tte[i].key16 || tte[i].key16 == key16)
|
||||||
{
|
{
|
||||||
if ((tte[i].genBound8 & 0xFC) != generation8 && tte[i].key16)
|
tte[i].genBound8 = uint8_t(generation8 | (tte[i].genBound8 & 0x7)); // Refresh
|
||||||
tte[i].genBound8 = uint8_t(generation8 | tte[i].bound()); // Refresh
|
|
||||||
|
|
||||||
return found = (bool)tte[i].key16, &tte[i];
|
return found = (bool)tte[i].key16, &tte[i];
|
||||||
}
|
}
|
||||||
@@ -90,11 +133,11 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
|||||||
TTEntry* replace = tte;
|
TTEntry* replace = tte;
|
||||||
for (int i = 1; i < ClusterSize; ++i)
|
for (int i = 1; i < ClusterSize; ++i)
|
||||||
// Due to our packed storage format for generation and its cyclic
|
// Due to our packed storage format for generation and its cyclic
|
||||||
// nature we add 259 (256 is the modulus plus 3 to keep the lowest
|
// nature we add 263 (256 is the modulus plus 7 to keep the unrelated
|
||||||
// two bound bits from affecting the result) to calculate the entry
|
// lowest three bits from affecting the result) to calculate the entry
|
||||||
// age correctly even after generation8 overflows into the next cycle.
|
// age correctly even after generation8 overflows into the next cycle.
|
||||||
if ( replace->depth8 - ((259 + generation8 - replace->genBound8) & 0xFC) * 2
|
if ( replace->depth8 - ((263 + generation8 - replace->genBound8) & 0xF8)
|
||||||
> tte[i].depth8 - ((259 + generation8 - tte[i].genBound8) & 0xFC) * 2)
|
> tte[i].depth8 - ((263 + generation8 - tte[i].genBound8) & 0xF8))
|
||||||
replace = &tte[i];
|
replace = &tte[i];
|
||||||
|
|
||||||
return found = false, replace;
|
return found = false, replace;
|
||||||
@@ -107,12 +150,9 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
|||||||
int TranspositionTable::hashfull() const {
|
int TranspositionTable::hashfull() const {
|
||||||
|
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for (int i = 0; i < 1000 / ClusterSize; i++)
|
for (int i = 0; i < 1000 / ClusterSize; ++i)
|
||||||
{
|
for (int j = 0; j < ClusterSize; ++j)
|
||||||
const TTEntry* tte = &table[i].entry[0];
|
cnt += (table[i].entry[j].genBound8 & 0xF8) == generation8;
|
||||||
for (int j = 0; j < ClusterSize; j++)
|
|
||||||
if ((tte[j].genBound8 & 0xFC) == generation8)
|
return cnt * 1000 / (ClusterSize * (1000 / ClusterSize));
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
return cnt;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -30,7 +30,8 @@
|
|||||||
/// move 16 bit
|
/// move 16 bit
|
||||||
/// value 16 bit
|
/// value 16 bit
|
||||||
/// eval value 16 bit
|
/// eval value 16 bit
|
||||||
/// generation 6 bit
|
/// generation 5 bit
|
||||||
|
/// pv node 1 bit
|
||||||
/// bound type 2 bit
|
/// bound type 2 bit
|
||||||
/// depth 8 bit
|
/// depth 8 bit
|
||||||
|
|
||||||
@@ -39,30 +40,10 @@ struct TTEntry {
|
|||||||
Move move() const { return (Move )move16; }
|
Move move() const { return (Move )move16; }
|
||||||
Value value() const { return (Value)value16; }
|
Value value() const { return (Value)value16; }
|
||||||
Value eval() const { return (Value)eval16; }
|
Value eval() const { return (Value)eval16; }
|
||||||
Depth depth() const { return (Depth)(depth8 * int(ONE_PLY)); }
|
Depth depth() const { return (Depth)depth8 + DEPTH_OFFSET; }
|
||||||
|
bool is_pv() const { return (bool)(genBound8 & 0x4); }
|
||||||
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
||||||
|
void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev);
|
||||||
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
|
|
||||||
|
|
||||||
assert(d / ONE_PLY * ONE_PLY == d);
|
|
||||||
|
|
||||||
// Preserve any existing move for the same position
|
|
||||||
if (m || (k >> 48) != key16)
|
|
||||||
move16 = (uint16_t)m;
|
|
||||||
|
|
||||||
// Don't overwrite more valuable entries
|
|
||||||
if ( (k >> 48) != key16
|
|
||||||
|| d / ONE_PLY > depth8 - 4
|
|
||||||
/* || g != (genBound8 & 0xFC) // Matching non-zero keys are already refreshed by probe() */
|
|
||||||
|| b == BOUND_EXACT)
|
|
||||||
{
|
|
||||||
key16 = (uint16_t)(k >> 48);
|
|
||||||
value16 = (int16_t)v;
|
|
||||||
eval16 = (int16_t)ev;
|
|
||||||
genBound8 = (uint8_t)(g | b);
|
|
||||||
depth8 = (int8_t)(d / ONE_PLY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class TranspositionTable;
|
friend class TranspositionTable;
|
||||||
@@ -72,7 +53,7 @@ private:
|
|||||||
int16_t value16;
|
int16_t value16;
|
||||||
int16_t eval16;
|
int16_t eval16;
|
||||||
uint8_t genBound8;
|
uint8_t genBound8;
|
||||||
int8_t depth8;
|
uint8_t depth8;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -85,8 +66,8 @@ private:
|
|||||||
|
|
||||||
class TranspositionTable {
|
class TranspositionTable {
|
||||||
|
|
||||||
static const int CacheLineSize = 64;
|
static constexpr int CacheLineSize = 64;
|
||||||
static const int ClusterSize = 3;
|
static constexpr int ClusterSize = 3;
|
||||||
|
|
||||||
struct Cluster {
|
struct Cluster {
|
||||||
TTEntry entry[ClusterSize];
|
TTEntry entry[ClusterSize];
|
||||||
@@ -97,8 +78,7 @@ class TranspositionTable {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
~TranspositionTable() { free(mem); }
|
~TranspositionTable() { free(mem); }
|
||||||
void new_search() { generation8 += 4; } // Lower 2 bits are used by Bound
|
void new_search() { generation8 += 8; } // Lower 3 bits are used by PV flag and Bound
|
||||||
uint8_t generation() const { return generation8; }
|
|
||||||
TTEntry* probe(const Key key, bool& found) const;
|
TTEntry* probe(const Key key, bool& found) const;
|
||||||
int hashfull() const;
|
int hashfull() const;
|
||||||
void resize(size_t mbSize);
|
void resize(size_t mbSize);
|
||||||
@@ -110,6 +90,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend struct TTEntry;
|
||||||
|
|
||||||
size_t clusterCount;
|
size_t clusterCount;
|
||||||
Cluster* table;
|
Cluster* table;
|
||||||
void* mem;
|
void* mem;
|
||||||
|
|||||||
+55
-62
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
// Disable some silly and noisy warning from MSVC compiler
|
// Disable some silly and noisy warning from MSVC compiler
|
||||||
@@ -80,28 +81,28 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_POPCNT
|
#ifdef USE_POPCNT
|
||||||
const bool HasPopCnt = true;
|
constexpr bool HasPopCnt = true;
|
||||||
#else
|
#else
|
||||||
const bool HasPopCnt = false;
|
constexpr bool HasPopCnt = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_PEXT
|
#ifdef USE_PEXT
|
||||||
const bool HasPext = true;
|
constexpr bool HasPext = true;
|
||||||
#else
|
#else
|
||||||
const bool HasPext = false;
|
constexpr bool HasPext = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef IS_64BIT
|
#ifdef IS_64BIT
|
||||||
const bool Is64Bit = true;
|
constexpr bool Is64Bit = true;
|
||||||
#else
|
#else
|
||||||
const bool Is64Bit = false;
|
constexpr bool Is64Bit = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef uint64_t Key;
|
typedef uint64_t Key;
|
||||||
typedef uint64_t Bitboard;
|
typedef uint64_t Bitboard;
|
||||||
|
|
||||||
const int MAX_MOVES = 256;
|
constexpr int MAX_MOVES = 256;
|
||||||
const int MAX_PLY = 128;
|
constexpr int MAX_PLY = 246;
|
||||||
|
|
||||||
/// A move needs 16 bits to be stored
|
/// A move needs 16 bits to be stored
|
||||||
///
|
///
|
||||||
@@ -131,24 +132,20 @@ enum Color {
|
|||||||
WHITE, BLACK, COLOR_NB = 2
|
WHITE, BLACK, COLOR_NB = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CastlingSide {
|
enum CastlingRights {
|
||||||
KING_SIDE, QUEEN_SIDE, CASTLING_SIDE_NB = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum CastlingRight {
|
|
||||||
NO_CASTLING,
|
NO_CASTLING,
|
||||||
WHITE_OO,
|
WHITE_OO,
|
||||||
WHITE_OOO = WHITE_OO << 1,
|
WHITE_OOO = WHITE_OO << 1,
|
||||||
BLACK_OO = WHITE_OO << 2,
|
BLACK_OO = WHITE_OO << 2,
|
||||||
BLACK_OOO = WHITE_OO << 3,
|
BLACK_OOO = WHITE_OO << 3,
|
||||||
ANY_CASTLING = WHITE_OO | WHITE_OOO | BLACK_OO | BLACK_OOO,
|
|
||||||
CASTLING_RIGHT_NB = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
template<Color C, CastlingSide S> struct MakeCastling {
|
KING_SIDE = WHITE_OO | BLACK_OO,
|
||||||
static constexpr CastlingRight
|
QUEEN_SIDE = WHITE_OOO | BLACK_OOO,
|
||||||
right = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO
|
WHITE_CASTLING = WHITE_OO | WHITE_OOO,
|
||||||
: S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO;
|
BLACK_CASTLING = BLACK_OO | BLACK_OOO,
|
||||||
|
ANY_CASTLING = WHITE_CASTLING | BLACK_CASTLING,
|
||||||
|
|
||||||
|
CASTLING_RIGHT_NB = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Phase {
|
enum Phase {
|
||||||
@@ -159,7 +156,6 @@ enum Phase {
|
|||||||
|
|
||||||
enum ScaleFactor {
|
enum ScaleFactor {
|
||||||
SCALE_FACTOR_DRAW = 0,
|
SCALE_FACTOR_DRAW = 0,
|
||||||
SCALE_FACTOR_ONEPAWN = 48,
|
|
||||||
SCALE_FACTOR_NORMAL = 64,
|
SCALE_FACTOR_NORMAL = 64,
|
||||||
SCALE_FACTOR_MAX = 128,
|
SCALE_FACTOR_MAX = 128,
|
||||||
SCALE_FACTOR_NONE = 255
|
SCALE_FACTOR_NONE = 255
|
||||||
@@ -183,11 +179,11 @@ enum Value : int {
|
|||||||
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
||||||
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
||||||
|
|
||||||
PawnValueMg = 171, PawnValueEg = 240,
|
PawnValueMg = 128, PawnValueEg = 213,
|
||||||
KnightValueMg = 764, KnightValueEg = 848,
|
KnightValueMg = 781, KnightValueEg = 854,
|
||||||
BishopValueMg = 826, BishopValueEg = 891,
|
BishopValueMg = 825, BishopValueEg = 915,
|
||||||
RookValueMg = 1282, RookValueEg = 1373,
|
RookValueMg = 1276, RookValueEg = 1380,
|
||||||
QueenValueMg = 2526, QueenValueEg = 2646,
|
QueenValueMg = 2538, QueenValueEg = 2682,
|
||||||
|
|
||||||
MidgameLimit = 15258, EndgameLimit = 3915
|
MidgameLimit = 15258, EndgameLimit = 3915
|
||||||
};
|
};
|
||||||
@@ -195,7 +191,6 @@ enum Value : int {
|
|||||||
enum PieceType {
|
enum PieceType {
|
||||||
NO_PIECE_TYPE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING,
|
NO_PIECE_TYPE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING,
|
||||||
ALL_PIECES = 0,
|
ALL_PIECES = 0,
|
||||||
QUEEN_DIAGONAL = 7,
|
|
||||||
PIECE_TYPE_NB = 8
|
PIECE_TYPE_NB = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -208,21 +203,18 @@ enum Piece {
|
|||||||
|
|
||||||
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
||||||
|
|
||||||
enum Depth : int {
|
typedef int Depth;
|
||||||
|
|
||||||
ONE_PLY = 1,
|
enum : int {
|
||||||
|
|
||||||
DEPTH_ZERO = 0 * ONE_PLY,
|
DEPTH_QS_CHECKS = 0,
|
||||||
DEPTH_QS_CHECKS = 0 * ONE_PLY,
|
DEPTH_QS_NO_CHECKS = -1,
|
||||||
DEPTH_QS_NO_CHECKS = -1 * ONE_PLY,
|
DEPTH_QS_RECAPTURES = -5,
|
||||||
DEPTH_QS_RECAPTURES = -5 * ONE_PLY,
|
|
||||||
|
|
||||||
DEPTH_NONE = -6 * ONE_PLY,
|
DEPTH_NONE = -6,
|
||||||
DEPTH_MAX = MAX_PLY * ONE_PLY
|
DEPTH_OFFSET = DEPTH_NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(!(ONE_PLY & (ONE_PLY - 1)), "ONE_PLY is not a power of 2");
|
|
||||||
|
|
||||||
enum Square : int {
|
enum Square : int {
|
||||||
SQ_A1, SQ_B1, SQ_C1, SQ_D1, SQ_E1, SQ_F1, SQ_G1, SQ_H1,
|
SQ_A1, SQ_B1, SQ_C1, SQ_D1, SQ_E1, SQ_F1, SQ_G1, SQ_H1,
|
||||||
SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2,
|
SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2,
|
||||||
@@ -258,10 +250,10 @@ enum Rank : int {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Score enum stores a middlegame and an endgame value in a single integer
|
/// Score enum stores a middlegame and an endgame value in a single integer (enum).
|
||||||
/// (enum). The least significant 16 bits are used to store the endgame value
|
/// The least significant 16 bits are used to store the middlegame value and the
|
||||||
/// and the upper 16 bits are used to store the middlegame value. Take some
|
/// upper 16 bits are used to store the endgame value. We have to take care to
|
||||||
/// care to avoid left-shifting a signed int to avoid undefined behavior.
|
/// avoid left-shifting a signed int to avoid undefined behavior.
|
||||||
enum Score : int { SCORE_ZERO };
|
enum Score : int { SCORE_ZERO };
|
||||||
|
|
||||||
constexpr Score make_score(int mg, int eg) {
|
constexpr Score make_score(int mg, int eg) {
|
||||||
@@ -294,7 +286,6 @@ inline T& operator--(T& d) { return d = T(int(d) - 1); }
|
|||||||
|
|
||||||
#define ENABLE_FULL_OPERATORS_ON(T) \
|
#define ENABLE_FULL_OPERATORS_ON(T) \
|
||||||
ENABLE_BASE_OPERATORS_ON(T) \
|
ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
ENABLE_INCR_OPERATORS_ON(T) \
|
|
||||||
constexpr T operator*(int i, T d) { return T(i * int(d)); } \
|
constexpr T operator*(int i, T d) { return T(i * int(d)); } \
|
||||||
constexpr T operator*(T d, int i) { return T(int(d) * i); } \
|
constexpr T operator*(T d, int i) { return T(int(d) * i); } \
|
||||||
constexpr T operator/(T d, int i) { return T(int(d) / i); } \
|
constexpr T operator/(T d, int i) { return T(int(d) / i); } \
|
||||||
@@ -303,12 +294,10 @@ inline T& operator*=(T& d, int i) { return d = T(int(d) * i); } \
|
|||||||
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
||||||
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Value)
|
ENABLE_FULL_OPERATORS_ON(Value)
|
||||||
ENABLE_FULL_OPERATORS_ON(Depth)
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Direction)
|
ENABLE_FULL_OPERATORS_ON(Direction)
|
||||||
|
|
||||||
ENABLE_INCR_OPERATORS_ON(PieceType)
|
ENABLE_INCR_OPERATORS_ON(PieceType)
|
||||||
ENABLE_INCR_OPERATORS_ON(Piece)
|
ENABLE_INCR_OPERATORS_ON(Piece)
|
||||||
ENABLE_INCR_OPERATORS_ON(Color)
|
|
||||||
ENABLE_INCR_OPERATORS_ON(Square)
|
ENABLE_INCR_OPERATORS_ON(Square)
|
||||||
ENABLE_INCR_OPERATORS_ON(File)
|
ENABLE_INCR_OPERATORS_ON(File)
|
||||||
ENABLE_INCR_OPERATORS_ON(Rank)
|
ENABLE_INCR_OPERATORS_ON(Rank)
|
||||||
@@ -326,10 +315,10 @@ inline Value& operator+=(Value& v, int i) { return v = v + i; }
|
|||||||
inline Value& operator-=(Value& v, int i) { return v = v - i; }
|
inline Value& operator-=(Value& v, int i) { return v = v - i; }
|
||||||
|
|
||||||
/// Additional operators to add a Direction to a Square
|
/// Additional operators to add a Direction to a Square
|
||||||
inline Square operator+(Square s, Direction d) { return Square(int(s) + int(d)); }
|
constexpr Square operator+(Square s, Direction d) { return Square(int(s) + int(d)); }
|
||||||
inline Square operator-(Square s, Direction d) { return Square(int(s) - int(d)); }
|
constexpr Square operator-(Square s, Direction d) { return Square(int(s) - int(d)); }
|
||||||
inline Square& operator+=(Square &s, Direction d) { return s = s + d; }
|
inline Square& operator+=(Square& s, Direction d) { return s = s + d; }
|
||||||
inline Square& operator-=(Square &s, Direction d) { return s = s - d; }
|
inline Square& operator-=(Square& s, Direction d) { return s = s - d; }
|
||||||
|
|
||||||
/// Only declared but not defined. We don't want to multiply two scores due to
|
/// 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.
|
/// a very high risk of overflow. So user should explicitly convert to integer.
|
||||||
@@ -347,11 +336,16 @@ inline Score operator*(Score s, int i) {
|
|||||||
|
|
||||||
assert(eg_value(result) == (i * eg_value(s)));
|
assert(eg_value(result) == (i * eg_value(s)));
|
||||||
assert(mg_value(result) == (i * mg_value(s)));
|
assert(mg_value(result) == (i * mg_value(s)));
|
||||||
assert((i == 0) || (result / i) == s );
|
assert((i == 0) || (result / i) == s);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Multiplication of a Score by a boolean
|
||||||
|
inline Score operator*(Score s, bool b) {
|
||||||
|
return Score(int(s) * int(b));
|
||||||
|
}
|
||||||
|
|
||||||
constexpr Color operator~(Color c) {
|
constexpr Color operator~(Color c) {
|
||||||
return Color(c ^ BLACK); // Toggle color
|
return Color(c ^ BLACK); // Toggle color
|
||||||
}
|
}
|
||||||
@@ -360,16 +354,16 @@ constexpr Square operator~(Square s) {
|
|||||||
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
|
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr File operator~(File f) {
|
|
||||||
return File(f ^ FILE_H); // Horizontal flip FILE_A -> FILE_H
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Piece operator~(Piece pc) {
|
constexpr Piece operator~(Piece pc) {
|
||||||
return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
|
return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr CastlingRight operator|(Color c, CastlingSide s) {
|
inline File map_to_queenside(File f) {
|
||||||
return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
|
return std::min(f, File(FILE_H - f)); // Map files ABCDEFGH to files ABCDDCBA
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr CastlingRights operator&(Color c, CastlingRights cr) {
|
||||||
|
return CastlingRights((c == WHITE ? WHITE_CASTLING : BLACK_CASTLING) & cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Value mate_in(int ply) {
|
constexpr Value mate_in(int ply) {
|
||||||
@@ -421,11 +415,6 @@ constexpr Rank relative_rank(Color c, Square s) {
|
|||||||
return relative_rank(c, rank_of(s));
|
return relative_rank(c, rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool opposite_colors(Square s1, Square s2) {
|
|
||||||
int s = int(s1) ^ int(s2);
|
|
||||||
return ((s >> 3) ^ s) & 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Direction pawn_push(Color c) {
|
constexpr Direction pawn_push(Color c) {
|
||||||
return c == WHITE ? NORTH : SOUTH;
|
return c == WHITE ? NORTH : SOUTH;
|
||||||
}
|
}
|
||||||
@@ -450,10 +439,14 @@ constexpr PieceType promotion_type(Move m) {
|
|||||||
return PieceType(((m >> 12) & 3) + KNIGHT);
|
return PieceType(((m >> 12) & 3) + KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Move make_move(Square from, Square to) {
|
constexpr Move make_move(Square from, Square to) {
|
||||||
return Move((from << 6) + to);
|
return Move((from << 6) + to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Move reverse_move(Move m) {
|
||||||
|
return make_move(to_sq(m), from_sq(m));
|
||||||
|
}
|
||||||
|
|
||||||
template<MoveType T>
|
template<MoveType T>
|
||||||
constexpr Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
constexpr Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
||||||
return Move(T + ((pt - KNIGHT) << 12) + (from << 6) + to);
|
return Move(T + ((pt - KNIGHT) << 12) + (from << 6) + to);
|
||||||
|
|||||||
+29
-25
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,8 +28,8 @@
|
|||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "tt.h"
|
|
||||||
#include "timeman.h"
|
#include "timeman.h"
|
||||||
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
#include "syzygy/tbprobe.h"
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
@@ -89,11 +89,11 @@ namespace {
|
|||||||
|
|
||||||
// Read option name (can contain spaces)
|
// Read option name (can contain spaces)
|
||||||
while (is >> token && token != "value")
|
while (is >> token && token != "value")
|
||||||
name += string(" ", name.empty() ? 0 : 1) + token;
|
name += (name.empty() ? "" : " ") + token;
|
||||||
|
|
||||||
// Read option value (can contain spaces)
|
// Read option value (can contain spaces)
|
||||||
while (is >> token)
|
while (is >> token)
|
||||||
value += string(" ", value.empty() ? 0 : 1) + token;
|
value += (value.empty() ? "" : " ") + token;
|
||||||
|
|
||||||
if (Options.count(name))
|
if (Options.count(name))
|
||||||
Options[name] = value;
|
Options[name] = value;
|
||||||
@@ -146,7 +146,7 @@ namespace {
|
|||||||
uint64_t num, nodes = 0, cnt = 1;
|
uint64_t num, nodes = 0, cnt = 1;
|
||||||
|
|
||||||
vector<string> list = setup_bench(pos, args);
|
vector<string> list = setup_bench(pos, args);
|
||||||
num = count_if(list.begin(), list.end(), [](string s) { return s.find("go ") == 0; });
|
num = count_if(list.begin(), list.end(), [](string s) { return s.find("go ") == 0 || s.find("eval") == 0; });
|
||||||
|
|
||||||
TimePoint elapsed = now();
|
TimePoint elapsed = now();
|
||||||
|
|
||||||
@@ -155,16 +155,21 @@ namespace {
|
|||||||
istringstream is(cmd);
|
istringstream is(cmd);
|
||||||
is >> skipws >> token;
|
is >> skipws >> token;
|
||||||
|
|
||||||
if (token == "go")
|
if (token == "go" || token == "eval")
|
||||||
{
|
{
|
||||||
cerr << "\nPosition: " << cnt++ << '/' << num << endl;
|
cerr << "\nPosition: " << cnt++ << '/' << num << endl;
|
||||||
go(pos, is, states);
|
if (token == "go")
|
||||||
Threads.main()->wait_for_search_finished();
|
{
|
||||||
nodes += Threads.nodes_searched();
|
go(pos, is, states);
|
||||||
|
Threads.main()->wait_for_search_finished();
|
||||||
|
nodes += Threads.nodes_searched();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sync_cout << "\n" << Eval::trace(pos) << sync_endl;
|
||||||
}
|
}
|
||||||
else if (token == "setoption") setoption(is);
|
else if (token == "setoption") setoption(is);
|
||||||
else if (token == "position") position(pos, is, states);
|
else if (token == "position") position(pos, is, states);
|
||||||
else if (token == "ucinewgame") Search::clear();
|
else if (token == "ucinewgame") { Search::clear(); elapsed = now(); } // Search::clear() may take some while
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
||||||
@@ -191,9 +196,8 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
Position pos;
|
Position pos;
|
||||||
string token, cmd;
|
string token, cmd;
|
||||||
StateListPtr states(new std::deque<StateInfo>(1));
|
StateListPtr states(new std::deque<StateInfo>(1));
|
||||||
auto uiThread = std::make_shared<Thread>(0);
|
|
||||||
|
|
||||||
pos.set(StartFEN, false, &states->back(), uiThread.get());
|
pos.set(StartFEN, false, &states->back(), Threads.main());
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
cmd += std::string(argv[i]) + " ";
|
cmd += std::string(argv[i]) + " ";
|
||||||
@@ -207,18 +211,16 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
token.clear(); // Avoid a stale if getline() returns empty or blank line
|
token.clear(); // Avoid a stale if getline() returns empty or blank line
|
||||||
is >> skipws >> token;
|
is >> skipws >> token;
|
||||||
|
|
||||||
|
if ( token == "quit"
|
||||||
|
|| token == "stop")
|
||||||
|
Threads.stop = true;
|
||||||
|
|
||||||
// The GUI sends 'ponderhit' to tell us the user has played the expected move.
|
// The GUI sends 'ponderhit' to tell us the user has played the expected move.
|
||||||
// So 'ponderhit' will be sent if we were told to ponder on the same move the
|
// So 'ponderhit' will be sent if we were told to ponder on the same move the
|
||||||
// user has played. We should continue searching but switch from pondering to
|
// user has played. We should continue searching but switch from pondering to
|
||||||
// normal search. In case Threads.stopOnPonderhit is set we are waiting for
|
// normal search.
|
||||||
// 'ponderhit' to stop the search, for instance if max search depth is reached.
|
|
||||||
if ( token == "quit"
|
|
||||||
|| token == "stop"
|
|
||||||
|| (token == "ponderhit" && Threads.stopOnPonderhit))
|
|
||||||
Threads.stop = true;
|
|
||||||
|
|
||||||
else if (token == "ponderhit")
|
else if (token == "ponderhit")
|
||||||
Threads.ponder = false; // Switch to normal search
|
Threads.main()->ponder = false; // Switch to normal search
|
||||||
|
|
||||||
else if (token == "uci")
|
else if (token == "uci")
|
||||||
sync_cout << "id name " << engine_info(true)
|
sync_cout << "id name " << engine_info(true)
|
||||||
@@ -231,11 +233,13 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
else if (token == "ucinewgame") Search::clear();
|
else if (token == "ucinewgame") Search::clear();
|
||||||
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
||||||
|
|
||||||
// Additional custom non-UCI commands, mainly for debugging
|
// Additional custom non-UCI commands, mainly for debugging.
|
||||||
else if (token == "flip") pos.flip();
|
// Do not use these commands during a search!
|
||||||
else if (token == "bench") bench(pos, is, states);
|
else if (token == "flip") pos.flip();
|
||||||
else if (token == "d") sync_cout << pos << sync_endl;
|
else if (token == "bench") bench(pos, is, states);
|
||||||
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
else if (token == "d") sync_cout << pos << sync_endl;
|
||||||
|
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
||||||
|
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
||||||
else
|
else
|
||||||
sync_cout << "Unknown command: " << cmd << sync_endl;
|
sync_cout << "Unknown command: " << cmd << sync_endl;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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,12 +49,14 @@ public:
|
|||||||
Option(OnChange = nullptr);
|
Option(OnChange = nullptr);
|
||||||
Option(bool v, OnChange = nullptr);
|
Option(bool v, OnChange = nullptr);
|
||||||
Option(const char* v, OnChange = nullptr);
|
Option(const char* v, OnChange = nullptr);
|
||||||
Option(int v, int minv, int maxv, OnChange = nullptr);
|
Option(double v, int minv, int maxv, OnChange = nullptr);
|
||||||
|
Option(const char* v, const char* cur, OnChange = nullptr);
|
||||||
|
|
||||||
Option& operator=(const std::string&);
|
Option& operator=(const std::string&);
|
||||||
void operator<<(const Option&);
|
void operator<<(const Option&);
|
||||||
operator int() const;
|
operator double() const;
|
||||||
operator std::string() const;
|
operator std::string() const;
|
||||||
|
bool operator==(const char*) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
|
friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
|
||||||
|
|||||||
+40
-13
@@ -2,7 +2,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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, 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
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
@@ -56,10 +57,11 @@ bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const
|
|||||||
void init(OptionsMap& o) {
|
void init(OptionsMap& o) {
|
||||||
|
|
||||||
// at most 2^32 clusters.
|
// at most 2^32 clusters.
|
||||||
const int MaxHashMB = Is64Bit ? 131072 : 2048;
|
constexpr int MaxHashMB = Is64Bit ? 131072 : 2048;
|
||||||
|
|
||||||
o["Debug Log File"] << Option("", on_logger);
|
o["Debug Log File"] << Option("", on_logger);
|
||||||
o["Contempt"] << Option(20, -100, 100);
|
o["Contempt"] << Option(24, -100, 100);
|
||||||
|
o["Analysis Contempt"] << Option("Both var Off var White var Black var Both", "Both");
|
||||||
o["Threads"] << Option(1, 1, 512, on_threads);
|
o["Threads"] << Option(1, 1, 512, on_threads);
|
||||||
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
|
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
|
||||||
o["Clear Hash"] << Option(on_clear_hash);
|
o["Clear Hash"] << Option(on_clear_hash);
|
||||||
@@ -68,13 +70,16 @@ void init(OptionsMap& o) {
|
|||||||
o["Skill Level"] << Option(20, 0, 20);
|
o["Skill Level"] << Option(20, 0, 20);
|
||||||
o["Move Overhead"] << Option(30, 0, 5000);
|
o["Move Overhead"] << Option(30, 0, 5000);
|
||||||
o["Minimum Thinking Time"] << Option(20, 0, 5000);
|
o["Minimum Thinking Time"] << Option(20, 0, 5000);
|
||||||
o["Slow Mover"] << Option(89, 10, 1000);
|
o["Slow Mover"] << Option(84, 10, 1000);
|
||||||
o["nodestime"] << Option(0, 0, 10000);
|
o["nodestime"] << Option(0, 0, 10000);
|
||||||
o["UCI_Chess960"] << Option(false);
|
o["UCI_Chess960"] << Option(false);
|
||||||
|
o["UCI_AnalyseMode"] << Option(false);
|
||||||
|
o["UCI_LimitStrength"] << Option(false);
|
||||||
|
o["UCI_Elo"] << Option(1350, 1350, 2850);
|
||||||
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
||||||
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
||||||
o["Syzygy50MoveRule"] << Option(true);
|
o["Syzygy50MoveRule"] << Option(true);
|
||||||
o["SyzygyProbeLimit"] << Option(6, 0, 6);
|
o["SyzygyProbeLimit"] << Option(7, 0, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,11 +95,13 @@ std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
|
|||||||
const Option& o = it.second;
|
const Option& o = it.second;
|
||||||
os << "\noption name " << it.first << " type " << o.type;
|
os << "\noption name " << it.first << " type " << o.type;
|
||||||
|
|
||||||
if (o.type != "button")
|
if (o.type == "string" || o.type == "check" || o.type == "combo")
|
||||||
os << " default " << o.defaultValue;
|
os << " default " << o.defaultValue;
|
||||||
|
|
||||||
if (o.type == "spin")
|
if (o.type == "spin")
|
||||||
os << " min " << o.min << " max " << o.max;
|
os << " default " << int(stof(o.defaultValue))
|
||||||
|
<< " min " << o.min
|
||||||
|
<< " max " << o.max;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -114,12 +121,15 @@ Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f)
|
|||||||
Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
|
Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
|
Option::Option(double v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
|
||||||
{ defaultValue = currentValue = std::to_string(v); }
|
{ defaultValue = currentValue = std::to_string(v); }
|
||||||
|
|
||||||
Option::operator int() const {
|
Option::Option(const char* v, const char* cur, OnChange f) : type("combo"), min(0), max(0), on_change(f)
|
||||||
|
{ defaultValue = v; currentValue = cur; }
|
||||||
|
|
||||||
|
Option::operator double() const {
|
||||||
assert(type == "check" || type == "spin");
|
assert(type == "check" || type == "spin");
|
||||||
return (type == "spin" ? stoi(currentValue) : currentValue == "true");
|
return (type == "spin" ? stof(currentValue) : currentValue == "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
Option::operator std::string() const {
|
Option::operator std::string() const {
|
||||||
@@ -127,6 +137,12 @@ Option::operator std::string() const {
|
|||||||
return currentValue;
|
return currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Option::operator==(const char* s) const {
|
||||||
|
assert(type == "combo");
|
||||||
|
return !CaseInsensitiveLess()(currentValue, s)
|
||||||
|
&& !CaseInsensitiveLess()(s, currentValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// operator<<() inits options and assigns idx in the correct printing order
|
/// operator<<() inits options and assigns idx in the correct printing order
|
||||||
|
|
||||||
@@ -140,8 +156,8 @@ void Option::operator<<(const Option& o) {
|
|||||||
|
|
||||||
|
|
||||||
/// operator=() updates currentValue and triggers on_change() action. It's up to
|
/// operator=() updates currentValue and triggers on_change() action. It's up to
|
||||||
/// the GUI to check for option's limits, but we could receive the new value from
|
/// the GUI to check for option's limits, but we could receive the new value
|
||||||
/// the user by console window, so let's check the bounds anyway.
|
/// from the user by console window, so let's check the bounds anyway.
|
||||||
|
|
||||||
Option& Option::operator=(const string& v) {
|
Option& Option::operator=(const string& v) {
|
||||||
|
|
||||||
@@ -149,9 +165,20 @@ Option& Option::operator=(const string& v) {
|
|||||||
|
|
||||||
if ( (type != "button" && v.empty())
|
if ( (type != "button" && v.empty())
|
||||||
|| (type == "check" && v != "true" && v != "false")
|
|| (type == "check" && v != "true" && v != "false")
|
||||||
|| (type == "spin" && (stoi(v) < min || stoi(v) > max)))
|
|| (type == "spin" && (stof(v) < min || stof(v) > max)))
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
|
if (type == "combo")
|
||||||
|
{
|
||||||
|
OptionsMap comboMap; // To have case insensitive compare
|
||||||
|
string token;
|
||||||
|
std::istringstream ss(defaultValue);
|
||||||
|
while (ss >> token)
|
||||||
|
comboMap[token] << Option();
|
||||||
|
if (!comboMap.count(v) || v == "var")
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
if (type != "button")
|
if (type != "button")
|
||||||
currentValue = v;
|
currentValue = v;
|
||||||
|
|
||||||
|
|||||||
+28
-6
@@ -28,14 +28,14 @@ case $1 in
|
|||||||
echo "sanitizer-undefined testing started"
|
echo "sanitizer-undefined testing started"
|
||||||
prefix='!'
|
prefix='!'
|
||||||
exeprefix=''
|
exeprefix=''
|
||||||
postfix='2>&1 | grep "runtime error:"'
|
postfix='2>&1 | grep -A50 "runtime error:"'
|
||||||
threads="1"
|
threads="1"
|
||||||
;;
|
;;
|
||||||
--sanitizer-thread)
|
--sanitizer-thread)
|
||||||
echo "sanitizer-thread testing started"
|
echo "sanitizer-thread testing started"
|
||||||
prefix='!'
|
prefix='!'
|
||||||
exeprefix=''
|
exeprefix=''
|
||||||
postfix='2>&1 | grep "WARNING: ThreadSanitizer:"'
|
postfix='2>&1 | grep -A50 "WARNING: ThreadSanitizer:"'
|
||||||
threads="2"
|
threads="2"
|
||||||
|
|
||||||
cat << EOF > tsan.supp
|
cat << EOF > tsan.supp
|
||||||
@@ -45,6 +45,7 @@ race:TTEntry::bound
|
|||||||
race:TTEntry::save
|
race:TTEntry::save
|
||||||
race:TTEntry::value
|
race:TTEntry::value
|
||||||
race:TTEntry::eval
|
race:TTEntry::eval
|
||||||
|
race:TTEntry::is_pv
|
||||||
|
|
||||||
race:TranspositionTable::probe
|
race:TranspositionTable::probe
|
||||||
race:TranspositionTable::hashfull
|
race:TranspositionTable::hashfull
|
||||||
@@ -108,13 +109,34 @@ cat << EOF > game.exp
|
|||||||
exit \$value
|
exit \$value
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
for exps in game.exp
|
#download TB as needed
|
||||||
|
if [ ! -d ../tests/syzygy ]; then
|
||||||
|
curl -sL https://api.github.com/repos/niklasf/python-chess/tarball/9b9aa13f9f36d08aadfabff872882f4ab1494e95 | tar -xzf -
|
||||||
|
mv niklasf-python-chess-9b9aa13 ../tests/syzygy
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat << EOF > syzygy.exp
|
||||||
|
set timeout 240
|
||||||
|
spawn $exeprefix ./stockfish
|
||||||
|
send "uci\n"
|
||||||
|
send "setoption name SyzygyPath value ../tests/syzygy/\n"
|
||||||
|
expect "info string Found 35 tablebases" {} timeout {exit 1}
|
||||||
|
send "bench 128 1 10 default depth\n"
|
||||||
|
send "quit\n"
|
||||||
|
expect eof
|
||||||
|
|
||||||
|
# return error code of the spawned program, useful for valgrind
|
||||||
|
lassign [wait] pid spawnid os_error_flag value
|
||||||
|
exit \$value
|
||||||
|
EOF
|
||||||
|
|
||||||
|
for exp in game.exp syzygy.exp
|
||||||
do
|
do
|
||||||
|
|
||||||
echo "$prefix expect $exps $postfix"
|
echo "$prefix expect $exp $postfix"
|
||||||
eval "$prefix expect $exps $postfix"
|
eval "$prefix expect $exp $postfix"
|
||||||
|
|
||||||
rm $exps
|
rm $exp
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# verify perft numbers (positions from https://chessprogramming.wikispaces.com/Perft+Results)
|
# verify perft numbers (positions from www.chessprogramming.org/Perft_Results)
|
||||||
|
|
||||||
error()
|
error()
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-1
@@ -16,7 +16,11 @@ signature=`./stockfish bench 2>&1 | grep "Nodes searched : " | awk '{print $4}'
|
|||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
# compare to given reference
|
# compare to given reference
|
||||||
if [ "$1" != "$signature" ]; then
|
if [ "$1" != "$signature" ]; then
|
||||||
echo "signature mismatch: reference $1 obtained $signature"
|
if [ -z "$signature" ]; then
|
||||||
|
echo "No signature obtained from bench. Code crashed or assert triggered ?"
|
||||||
|
else
|
||||||
|
echo "signature mismatch: reference $1 obtained: $signature ."
|
||||||
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "signature OK: $signature"
|
echo "signature OK: $signature"
|
||||||
|
|||||||
Reference in New Issue
Block a user