mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 15:37:47 +00:00
Compare commits
1009 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 378c8bdbb8 | |||
| 2e11388581 | |||
| 0a5b03af3f | |||
| fd4d800c98 | |||
| a5a98d822e | |||
| 254d995e18 | |||
| 5451687efb | |||
| b61759e907 | |||
| b508f9561c | |||
| 1b6459195c | |||
| aa88261a8f | |||
| 33682bfb98 | |||
| 66ce8ad5fd | |||
| 9afa1d7330 | |||
| 2ba47416cb | |||
| 7d4d3a2c3a | |||
| 1c50d8cbf5 | |||
| 2198cd0524 | |||
| b53239d641 | |||
| 83e829c9dc | |||
| f6981b1321 | |||
| be6fafd079 | |||
| 020dd69a35 | |||
| 70262f2027 | |||
| 196ae7c38b | |||
| be382bb0cf | |||
| d193482213 | |||
| 54f6ce70fd | |||
| 822695d4d3 | |||
| 2acda1fde3 | |||
| 28b6a457c2 | |||
| ccd6bad512 | |||
| 8a5a64eac5 | |||
| a87a1005ad | |||
| 7dd1f4a7c0 | |||
| d64ffd9621 | |||
| c769d4df84 | |||
| 03a9b3bd8d | |||
| 53239d7d3d | |||
| 3f44f5303b | |||
| 87452f3a8c | |||
| 8cfcca12d1 | |||
| 0a74c16ffe | |||
| 652199d840 | |||
| 4bc11984fc | |||
| 486c8175c4 | |||
| e0d2fdc843 | |||
| e50af36a00 | |||
| 287e2e2f74 | |||
| 86ac50403d | |||
| 0dc3b0978d | |||
| 9d79138682 | |||
| 43c186c645 | |||
| b36489742b | |||
| 452e5154cf | |||
| 07b5a28a68 | |||
| c33af32dad | |||
| 0e949ac2c9 | |||
| ba4e215493 | |||
| 043a469f83 | |||
| 21926ce2d8 | |||
| ed8286eb1b | |||
| 3ac47c84d3 | |||
| 741523eda8 | |||
| 04eb87fd08 | |||
| 323925b91c | |||
| 5ba4373522 | |||
| 3fd7e37868 | |||
| 9d95d43c57 | |||
| e385f194e9 | |||
| 7b4c9852e1 | |||
| bf485f4aff | |||
| a2b8f91cfa | |||
| d5f883ab29 | |||
| 92c39522b1 | |||
| 5ef94eb970 | |||
| 002bf4d8db | |||
| 5ea327d924 | |||
| fe60caba94 | |||
| 7aa7dfd4df | |||
| fa5b0936ee | |||
| 45e254a0a0 | |||
| 444d99b6d2 | |||
| e10255339f | |||
| daf0fe1f57 | |||
| 4d511512d2 | |||
| 9c35b9365d | |||
| 01d97521fd | |||
| d482e3a890 | |||
| 9001f55147 | |||
| ae6a4ebf1f | |||
| 232c50fed0 | |||
| c3e964f35e | |||
| df6cb446ea | |||
| bdeda52efd | |||
| 5837228aa0 | |||
| 2783203428 | |||
| 66c5eaebd8 | |||
| 44236f4ed9 | |||
| 5410424e3d | |||
| 750dfa0521 | |||
| dbc984d9f8 | |||
| f731bcadb7 | |||
| b40e45c1cc | |||
| 53c2d9df5e | |||
| b24bd762b2 | |||
| 722e1e0da6 | |||
| 973ede008a | |||
| a6ae2d3a31 | |||
| 272e4d1ac7 | |||
| e551afbab7 | |||
| d31f068312 | |||
| 377d77dbe9 | |||
| 36a93d90f7 | |||
| 0371a8f8c4 | |||
| c8e5384c3a | |||
| 802fca6fdd | |||
| 01b6cdb76b | |||
| c0cb713a00 | |||
| 6d24ef8585 | |||
| 69eb391cd7 | |||
| 7e897a64f2 | |||
| 05513a6641 | |||
| fa1e3427bd | |||
| 77342126d8 | |||
| 612d93234b | |||
| 0149a4c3d6 | |||
| 336901fdb0 | |||
| 3cb0200459 | |||
| 2c237da546 | |||
| b73016bb41 | |||
| 27ba611a3d | |||
| f907d5b7d9 | |||
| ebc563059c | |||
| 659990b43f | |||
| 6d89d0b64a | |||
| 1781439fc2 | |||
| ecd3218b6b | |||
| 24df0f72c0 | |||
| 1d31065e1d | |||
| c216dcbe7b | |||
| cf893bcded | |||
| 732aa34e3d | |||
| 862934d7ae | |||
| 7edd1f7ccd | |||
| 0c1f119069 | |||
| 99d914985f | |||
| 6b4959e3e0 | |||
| ae97941628 | |||
| 69ec09bd4b | |||
| 25296547d0 | |||
| 321a27fbe3 | |||
| 8b15961349 | |||
| e9f26cccdd | |||
| a18c2c2c3f | |||
| b948b037a5 | |||
| e06a117d5e | |||
| b1b19343cd | |||
| 49a9d4cf99 | |||
| d06a8d0c18 | |||
| b48439e906 | |||
| 6b9a22b40d | |||
| 0868de705d | |||
| 9da3b44ddc | |||
| ced29248c9 | |||
| 2d96e8fbe9 | |||
| d4b9ee0f1d | |||
| 57a3334322 | |||
| 9d3ed9ed2e | |||
| 06175c6055 | |||
| 1454831220 | |||
| b258b4fee7 | |||
| 72a501c6fe | |||
| 35b77b120e | |||
| ebe021f6a5 | |||
| 06eba14dc9 | |||
| c5de4080db | |||
| 3b7c1a17e4 | |||
| afe75571d8 | |||
| 30c583204f | |||
| 352bd6f5aa | |||
| c80d52c845 | |||
| c076216a32 | |||
| a6d6a2c2fa | |||
| d01b66ae8f | |||
| c3d2e6aba9 | |||
| d490bb9973 | |||
| cc76524c2e | |||
| 3627348e2b | |||
| 728ce2195c | |||
| 1810c4d758 | |||
| 8f7e032b8c | |||
| f1e3dfea74 | |||
| 9f48e1ec15 | |||
| eefbe967c2 | |||
| c243cd5f4a | |||
| 05cf45f2d1 | |||
| faedcf08a8 | |||
| 83fb4547f6 | |||
| 1e814e0ca0 | |||
| e0d91f4c44 | |||
| a753e20bd4 | |||
| 5205d44f87 | |||
| 0553b46829 | |||
| ddecdc97d7 | |||
| fa24cc25a4 | |||
| 5254a6040c | |||
| 471f7a1b5c | |||
| 58c181de9a | |||
| cf4a38e0cb | |||
| 9eed183489 | |||
| 243a9f5484 | |||
| 9f8f093fd6 | |||
| de02768af7 | |||
| 99cd513264 | |||
| d2971f3fca | |||
| d40351243b | |||
| d8f683760c | |||
| 332b5013b5 | |||
| 34e47ca87d | |||
| e0504ab876 | |||
| d9dd520896 | |||
| 394e9cd892 | |||
| ba15781be8 | |||
| d39ffbeea6 | |||
| 3ab3e55bb5 | |||
| 1c316c41bb | |||
| 90b052462c | |||
| 8b2c81d3ea | |||
| fe99de20ff | |||
| 6b16ebc825 | |||
| e3a8b8bcff | |||
| 1052ce74f6 | |||
| e258c5a779 | |||
| b7b9d7c9c7 | |||
| 881a9dfb0a | |||
| 43f6b33e50 | |||
| ab4f498bbc | |||
| 8765f9ce16 | |||
| 3728e833aa | |||
| af7412e58a | |||
| 1ceaea701b | |||
| f72b7dc99a | |||
| ee22b61f5e | |||
| 8c61bbda54 | |||
| 847bc0e80f | |||
| 1b62d413c1 | |||
| 589049a0e5 | |||
| a47bbca0ea | |||
| 0d33466bcd | |||
| 46d066b041 | |||
| bf8b45fe63 | |||
| e70da0d2eb | |||
| 1e76ba7cec | |||
| 535435b7fc | |||
| 7a3844e6ef | |||
| fbb2ffacfd | |||
| 8f30d233f8 | |||
| ec83e8a72c | |||
| e7289465b9 | |||
| 8ceb1ff53b | |||
| 2ec626ddae | |||
| 9eccba7761 | |||
| ca464fc89e | |||
| 0d9a9f5e98 | |||
| 6036303bb6 | |||
| b5d10d17c2 | |||
| 797602938d | |||
| 76d113f5f0 | |||
| 18df1698f4 | |||
| 7f4de0196b | |||
| cddc8d4546 | |||
| a90fc4c877 | |||
| e6c2899020 | |||
| de269ee18e | |||
| dc4655e1f9 | |||
| 0fa80c9ba3 | |||
| 61c727fdcb | |||
| 876f07cbee | |||
| f5d3f0ded6 | |||
| e4659693de | |||
| 52cb348023 | |||
| 0d669be76c | |||
| 23f384cac3 | |||
| b915fdc889 | |||
| 67d19447f4 | |||
| d4abf54247 | |||
| 445aade39c | |||
| f3cd7002aa | |||
| c43146edb7 | |||
| c0bb041539 | |||
| 369eff437c | |||
| 344616e917 | |||
| 40b1b27178 | |||
| bf51b4796a | |||
| e18e557e77 | |||
| 818b4a126d | |||
| e77f38c431 | |||
| e18321f55a | |||
| ca67752645 | |||
| 3686e719a1 | |||
| 9893e7fd53 | |||
| 99f3ad6858 | |||
| e27d3bb884 | |||
| 16e1881126 | |||
| e1f600f186 | |||
| a3fe80c36a | |||
| fdf3a51c68 | |||
| e61f7b1e6d | |||
| f799610d4b | |||
| 073eed590e | |||
| 1e586288ca | |||
| 0162fb83c2 | |||
| ab26c61971 | |||
| eccccba0ce | |||
| b77bae0529 | |||
| 7ae3c05795 | |||
| 351844061e | |||
| 8662bdfa12 | |||
| 28240d375c | |||
| 943ae89be1 | |||
| 4b0043ae7c | |||
| 92f01aa2bd | |||
| ea41f18e6e | |||
| 057d710fc2 | |||
| 01f2466f6e | |||
| 5c58d1f5cb | |||
| b96dd754ed | |||
| 01ee509a5c | |||
| 95ad2b51b7 | |||
| 438805aee8 | |||
| ace8e951d7 | |||
| 90ce24b11e | |||
| 4c95edddbf | |||
| 602d7fbb07 | |||
| d909d10f33 | |||
| 38428ada54 | |||
| e340ce221c | |||
| ca6c9f85a5 | |||
| c5828c4eba | |||
| d37dfe9ae4 | |||
| 13b4444d9e | |||
| 7f2eb10e93 | |||
| 5cffc032da | |||
| 2731bbaf6b | |||
| 6aa9308f08 | |||
| b4f6728e61 | |||
| 2b57b61cb1 | |||
| 1ee2838214 | |||
| 0b944c7186 | |||
| 805afcbf3d | |||
| 4c5cbb1b14 | |||
| 133808851d | |||
| 9bd856e28e | |||
| 3e739f883f | |||
| 0b4f6e562b | |||
| 5596492f6e | |||
| 8493c8c6b8 | |||
| e3af492142 | |||
| 9585f8ef58 | |||
| 7396c08b79 | |||
| 3d10cfcdd2 | |||
| 8abb98455f | |||
| b3525fa9ea | |||
| 85924db496 | |||
| f2f3a06a1a | |||
| 714329dbdc | |||
| 76971d8acb | |||
| f619f1d38c | |||
| 82d02a3133 | |||
| 1d09ee70f7 | |||
| eb20a87c67 | |||
| ade3bb9a4e | |||
| 716a145a6c | |||
| 190d2ea4bc | |||
| c2c0e6b07d | |||
| c94145b65c | |||
| 09efbf915e | |||
| 6d58bf777c | |||
| 1c0c4db677 | |||
| 8e45e70e55 | |||
| 126036abb0 | |||
| ca14345ba2 | |||
| 7d2a79f037 | |||
| 7c5d724724 | |||
| 6fed8ff22a | |||
| 0c076f1136 | |||
| e48c7547c5 | |||
| 6e2ca97d93 | |||
| 5f096e9bef | |||
| 20023ac9b8 | |||
| 3549d98d07 | |||
| 07b247f943 | |||
| abac509ccb | |||
| ab0f4c0353 | |||
| 71bfbb22fc | |||
| 7cb8cbb403 | |||
| 0784bd542b | |||
| 16c603ce9b | |||
| 969982406c | |||
| 4b9ed6566a | |||
| 5e4cd3fc0d | |||
| 5486911e01 | |||
| 3487eb9f9e | |||
| dc0030de4f | |||
| 2dd24dc4e6 | |||
| 8f934dff9a | |||
| 2694ef23c3 | |||
| e082112cfe | |||
| 4048bae47b | |||
| c737062436 | |||
| 94e41274bb | |||
| ec6aab0136 | |||
| 7eaea3848c | |||
| ee7a68ea5f | |||
| d30994ecd5 | |||
| bd04f9a0f1 | |||
| 1cbba8d6fa | |||
| e9e5f72c74 | |||
| 29b5842da8 | |||
| 8fb45caade | |||
| 900279a06f | |||
| d5b24ad77b | |||
| f256388e08 | |||
| db4b0d8b7d | |||
| 24dac5ccd3 | |||
| 8788612828 | |||
| 5d1644ba69 | |||
| 60590577f2 | |||
| 04be84e0e2 | |||
| 647402ff79 | |||
| a273b6ef8c | |||
| e1a7d135b2 | |||
| c1be0c68c7 | |||
| c13052f344 | |||
| 8de29390f2 | |||
| 45a309d92e | |||
| d5ba8e827d | |||
| 77fa960f89 | |||
| bfe9044ad9 | |||
| 744ed85a4d | |||
| 56dd58e6f9 | |||
| 4f6aa15228 | |||
| aedebe35cf | |||
| 9a10313a9d | |||
| 8c3a5bbc52 | |||
| 28933a580e | |||
| 12eb345ebd | |||
| ebec2fa48e | |||
| 552b3ccb66 | |||
| 356147d99a | |||
| 89723339d9 | |||
| 74e2fa97b7 | |||
| dcd8ce7094 | |||
| 4d1220d672 | |||
| aa31f7f096 | |||
| 1de97337c2 | |||
| 9eceb894ac | |||
| 5972c4a678 | |||
| dd9cf30581 | |||
| d4af15f682 | |||
| 9742fb10fd | |||
| 7cafbab529 | |||
| 6a79d5d10e | |||
| 3e4fed3a91 | |||
| a5c76d69c3 | |||
| 1b5b900a29 | |||
| 90f5937373 | |||
| 1e8836d921 | |||
| e3c85c314d | |||
| da34023cfc | |||
| ed72a1e9ba | |||
| 5bbd944099 | |||
| 38adb487ca | |||
| 2c1797ab81 | |||
| 9fac5774f4 | |||
| 69240a982d | |||
| 7904a7d930 | |||
| 8315620522 | |||
| 52eac1e535 | |||
| 5d077bb482 | |||
| 5a42427cb8 | |||
| 5339ab57d8 | |||
| 388630ae28 | |||
| 79f393084a | |||
| 328098d027 | |||
| 93195555ed | |||
| 07e0741dfb | |||
| 27ca89d479 | |||
| cccf3c815c | |||
| 76ed0ab501 | |||
| ce84ab6e9d | |||
| fca8dbc029 | |||
| e6eeb17aa6 | |||
| 9c9205860c | |||
| 27c5cb5912 | |||
| 86f04dbcc0 | |||
| aa242d2f84 | |||
| 8d858783e1 | |||
| 80d7556af7 | |||
| 00d9e9fd28 | |||
| 3428a28751 | |||
| 307a5a4f63 | |||
| 55758344d3 | |||
| 4eca981e55 | |||
| 5066e17eba | |||
| 328d314f2f | |||
| ecc5ff6693 | |||
| 7ea5659c5f | |||
| 8fd34d7763 | |||
| 55b46ffa90 | |||
| 08d6465d90 | |||
| 5f4d9309c8 | |||
| 436c303731 | |||
| 540b49a152 | |||
| 2e45447957 | |||
| dc3508d157 | |||
| ca38358574 | |||
| 83e19fbed5 | |||
| 9f5b31c21d | |||
| 3c0fe1d9b2 | |||
| 77b4f4c2e7 | |||
| 68fbb1e052 | |||
| 01fab4d432 | |||
| 660c38f781 | |||
| 613dc66c12 | |||
| 3e2591d83c | |||
| 46b5a5f0db | |||
| 84a641b8bb | |||
| 7f300a7698 | |||
| 087b638f6c | |||
| 7ad85fca6d | |||
| bf6bc1b37b | |||
| c052e03426 | |||
| 69a1a808c8 | |||
| 600234f2e2 | |||
| 9dbb3ae8b2 | |||
| f4ace94f91 | |||
| 1aae35b8b7 | |||
| e6310b3469 | |||
| 68d61b80c6 | |||
| a2410227cc | |||
| 4a6d59c6c7 | |||
| 51330414c4 | |||
| 42b77ea7ee | |||
| 4095ff0ee5 | |||
| 1d977aa79e | |||
| d8aeaab79c | |||
| 3054db989d | |||
| b2edac7075 | |||
| aa0dc16b75 | |||
| 112607bf49 | |||
| 7e9f776fca | |||
| 3f1bc9e013 | |||
| e8cc5c9968 | |||
| 00563be5cc | |||
| ad87d707ff | |||
| 7b8ffe0f5d | |||
| c1d3bd2dba | |||
| 5ebdf2f8c8 | |||
| 4502a1934f | |||
| 2795aedbc3 | |||
| 8e95c39bfa | |||
| 80a759d544 | |||
| 2e0ec4ad6f | |||
| e14046517e | |||
| 411e704fdf | |||
| ee0371f86e | |||
| eaeb63f1d0 | |||
| 92dbee7875 | |||
| 2e86d1febc | |||
| 946fa47625 | |||
| 7231b18af1 | |||
| 578b21bbee | |||
| 59f64fda4f | |||
| cc54a91ca5 | |||
| b7063ef65b | |||
| 078625e333 | |||
| 6c040c821a | |||
| 20e92895af | |||
| fb03188fc7 | |||
| a66c73deef | |||
| 27efc5ac99 | |||
| 36f2133df3 | |||
| ef4d89c9bd | |||
| aaf17326e2 | |||
| 2ca142a5b4 | |||
| ffbaa1c5a8 | |||
| 57dfe41ddb | |||
| 926f215061 | |||
| df722521ba | |||
| 5d1b92e8f9 | |||
| 6661a31541 | |||
| 6c42575208 | |||
| 61a6e46664 | |||
| 60beb18efc | |||
| 8463fa479e | |||
| 63500274db | |||
| 1d5eaba573 | |||
| ac8e6ff000 | |||
| 3a6753328c | |||
| 50182f1100 | |||
| e51965aa57 | |||
| a7381d5e81 | |||
| dc3a5f791e | |||
| 35a082064f | |||
| be77406a55 | |||
| 26dabb1e6b | |||
| 35b6079852 | |||
| ebf3735754 | |||
| 966bc477af | |||
| c6f987d1ad | |||
| d477a0d611 | |||
| 54889618c2 | |||
| 9a6cfee73b | |||
| 2e8552db76 | |||
| a4b2eeea75 | |||
| 13d4df95cd | |||
| bae4679de2 | |||
| a3943b2aa7 | |||
| f04f50b368 | |||
| a4b98a052e | |||
| e5da0e4b79 | |||
| d71f707040 | |||
| 558b0c848c | |||
| 062ca91db5 | |||
| 13c11f4048 | |||
| 81c7975dcd | |||
| 4b59347194 | |||
| 6027652773 | |||
| 04372316b3 | |||
| 8725494966 | |||
| be50952533 | |||
| e53774bc49 | |||
| 3017e8c604 | |||
| 8fcaa78a04 | |||
| a590d1d52d | |||
| 856a5f3aaa | |||
| 6fa6da3ee1 | |||
| cb2111f0b6 | |||
| 6645115377 | |||
| 63a5fc2366 | |||
| 0da7295795 | |||
| 1e6d21dbb6 | |||
| 9369f4963d | |||
| a459709fcc | |||
| 2dbb1adf2a | |||
| 8a2c4134a6 | |||
| fce799294c | |||
| 0b36ba74fc | |||
| 153fb216a1 | |||
| d3d26a94b3 | |||
| 38112060dc | |||
| 775f8239d3 | |||
| 098f645d26 | |||
| 29ff925fd8 | |||
| 8d16111ffd | |||
| e2226cbb20 | |||
| 5fd5453e59 | |||
| e74c2df907 | |||
| 41ccc885ec | |||
| 2f46592736 | |||
| 7ff965eebf | |||
| a6f873cd8d | |||
| 40548c9153 | |||
| 667f350737 | |||
| 950c8436ed | |||
| 8d47caa16e | |||
| b9d4e6f7fd | |||
| 193a7ae35b | |||
| 4f906a2589 | |||
| dccaa145d2 | |||
| 6656ed8904 | |||
| d65f75c153 | |||
| f8f5dcbb68 | |||
| 686b45e121 | |||
| dc13004283 | |||
| 901bfb1f55 | |||
| 20a5c07472 | |||
| e38eb2302d | |||
| 0af24a1445 | |||
| a8f9c7a790 | |||
| c0a80afe89 | |||
| 44a571c1c7 | |||
| ce8ac7997c | |||
| e118570038 | |||
| 8f10f6c9cd | |||
| 3184852bdc | |||
| 99c9cae586 | |||
| 152a4dc5cd | |||
| 47a0768102 | |||
| 170bdf40cd | |||
| 8b0fee9998 | |||
| 1277a42823 | |||
| 35aa21c1fe | |||
| 18b0809639 | |||
| f4136c5434 | |||
| ddccb5355c | |||
| 1c7a727795 | |||
| e56e5045dd | |||
| 20d6a8e57f | |||
| 0dc6f16992 | |||
| 21120288a3 | |||
| 519b2fe849 | |||
| f3189bdc9a | |||
| 65f46794af | |||
| 81d6c4a0d6 | |||
| 60c121f3b1 | |||
| 45eac9507c | |||
| bfd0f95f06 | |||
| 1b947aafbf | |||
| a7592e69d7 | |||
| a3b4e9e23c | |||
| f6f1d24223 | |||
| ce0a95c2c0 | |||
| 8aa8608c2a | |||
| 7837fb2aca | |||
| 9f0d5241bf | |||
| 14f7d9a629 | |||
| 69407ae9b8 | |||
| 18375e3bfb | |||
| 6390a3da94 | |||
| 36f8814aa6 | |||
| 96e36a7897 | |||
| 2ca2c3f35b | |||
| f54c44e6be | |||
| ca3622f8e8 | |||
| 712bbb052e | |||
| fe4fda474f | |||
| f7d8ea3866 | |||
| f53aea45e3 | |||
| 3c07603dac |
+74
@@ -0,0 +1,74 @@
|
||||
language: cpp
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-7', 'g++-7-multilib', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
||||
env:
|
||||
- COMPILER=g++-7
|
||||
- COMP=gcc
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
|
||||
packages: ['clang-5.0', 'llvm-5.0-dev', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
||||
env:
|
||||
- COMPILER=clang++-5.0
|
||||
- COMP=clang
|
||||
- LDFLAGS=-fuse-ld=gold
|
||||
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
env:
|
||||
- COMPILER=g++
|
||||
- COMP=gcc
|
||||
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env:
|
||||
- COMPILER=clang++ V='Apple LLVM 6.0' # Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
|
||||
- COMP=clang
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
before_script:
|
||||
- cd src
|
||||
|
||||
script:
|
||||
# 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]*\).*/\1/g" > git_sig
|
||||
- export benchref=$(cat git_sig)
|
||||
- echo "Reference bench:" $benchref
|
||||
#
|
||||
# Verify bench number against various builds
|
||||
- export CXXFLAGS=-Werror
|
||||
- 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 build && ../tests/signature.sh $benchref
|
||||
- make clean && make -j2 ARCH=x86-64 build && ../tests/signature.sh $benchref
|
||||
#
|
||||
# Check perft and reproducible search
|
||||
- ../tests/perft.sh
|
||||
- ../tests/reprosearch.sh
|
||||
#
|
||||
# Valgrind
|
||||
#
|
||||
- export CXXFLAGS=-O1
|
||||
- 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
|
||||
#
|
||||
# Sanitizer
|
||||
#
|
||||
# Use g++-7 as a proxy for having sanitizers, might need revision as they become available for more recent versions of clang/gcc
|
||||
- if [[ "$COMPILER" == "g++-7" ]]; 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++-7" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi
|
||||
@@ -1,64 +1,129 @@
|
||||
# Generated with git shortlog -sn | cut -c8-', which sorts by commits (manually moved Tord to top)
|
||||
# List of authors for Stockfish, updated for version 10
|
||||
|
||||
Tord Romstad
|
||||
Marco Costalba
|
||||
Joona Kiiski
|
||||
Gary Linscott
|
||||
Lucas Braesch
|
||||
Reuven Peleg
|
||||
Chris Caino
|
||||
homoSapiensSapiens
|
||||
Jean-Francois Romang
|
||||
jundery
|
||||
Arjun Temurnikar
|
||||
Uri Blass
|
||||
Ralph Stößer
|
||||
Stefan Geschwentner
|
||||
Tom Vijlbrief
|
||||
Daylen Yang
|
||||
Henri Wiechers
|
||||
Leonid Pechenik
|
||||
mstembera
|
||||
Eelco de Groot
|
||||
Jerry Donald
|
||||
Jörg Oster
|
||||
Ryan Schmitt
|
||||
mcostalba
|
||||
Tord Romstad (romstad)
|
||||
Marco Costalba (mcostalba)
|
||||
Joona Kiiski (zamar)
|
||||
Gary Linscott (glinscott)
|
||||
|
||||
Aditya (absimaldata)
|
||||
Ajith Chandy Jose (ajithcj)
|
||||
Alain Savard (Rocky640)
|
||||
Alexander Kure
|
||||
Dan Schmidt
|
||||
H. Felix Wittmann
|
||||
Justin Blanchard
|
||||
Linus Arver
|
||||
RyanTaker
|
||||
ceebo
|
||||
Joseph H Ellis
|
||||
Stephane Nicolet
|
||||
Ajith
|
||||
Ali AlZhrani (Cooffe)
|
||||
Andrew Grant (AndyGrant)
|
||||
Andrey Neporada (nepal)
|
||||
Andy Duplain
|
||||
Aram Tumanian (atumanian)
|
||||
Arjun Temurnikar
|
||||
Auguste Pop
|
||||
Balint Pfliegel
|
||||
Chris Cain
|
||||
Ben Koshy (BKSpurgeon)
|
||||
Bill Henry (VoyagerOne)
|
||||
braich
|
||||
Brian Sheppard (SapphireBrand)
|
||||
Bryan Cross (crossbr)
|
||||
Bujun Guo (noobpwnftw)
|
||||
Chris Cain (ceebo)
|
||||
Dan Schmidt
|
||||
Daniel Dugovic (ddugovic)
|
||||
Dariusz Orzechowski
|
||||
David Zar
|
||||
Daylen Yang (daylen)
|
||||
DiscanX
|
||||
Eelco de Groot
|
||||
ElbertoOne
|
||||
erbsenzaehler
|
||||
Ernesto Gatti
|
||||
Fabian Beuke (madnight)
|
||||
Fabian Fichter (ianfab)
|
||||
fanon
|
||||
Fauzi Akram Dabat (FauziAkram)
|
||||
Felix Wittmann
|
||||
gamander
|
||||
gguliash
|
||||
Gian-Carlo Pascutto (gcp)
|
||||
Gontran Lemaire (gonlem)
|
||||
Goodkov Vasiliy Aleksandrovich (goodkov)
|
||||
Gregor Cramer
|
||||
Hiraoka Takuya
|
||||
GuardianRM
|
||||
Günther Demetz (pb00067, pb00068)
|
||||
Guy Vreuls (gvreuls)
|
||||
Henri Wiechers
|
||||
Hiraoka Takuya (HiraokaTakuya)
|
||||
homoSapiensSapiens
|
||||
Hongzhi Cheng
|
||||
Jonathan Calovski
|
||||
Ivan Ivec (IIvec)
|
||||
Jacques B. (Timshel)
|
||||
Jan Ondruš (hxim)
|
||||
Jared Kish (Kurtbusch)
|
||||
Jarrod Torriero (DU-jdto)
|
||||
Jean-Francois Romang (jromang)
|
||||
Jerry Donald Watson (jerrydonaldwatson)
|
||||
Jonathan Calovski (Mysseno)
|
||||
Jonathan D. (SFisGOD)
|
||||
Joost VandeVondele (vondele)
|
||||
Jörg Oster (joergoster)
|
||||
Joseph Ellis (jhellis3)
|
||||
Joseph R. Prostko
|
||||
jundery
|
||||
Justin Blanchard
|
||||
Kelly Wilson
|
||||
Kojirion
|
||||
Matt Sullivan
|
||||
Matthew Sullivan
|
||||
Michel Van den Bergh
|
||||
Mysseno
|
||||
Pablo Vazquez
|
||||
Raminder Singh
|
||||
Richard Lloyd
|
||||
Ron Britvich
|
||||
Ronald de Man
|
||||
Ryan Takker
|
||||
Thanar2
|
||||
Ken Takusagawa
|
||||
kinderchocolate
|
||||
Kiran Panditrao (Krgp)
|
||||
Kojirion
|
||||
Leonardo Ljubičić (ICCF World Champion)
|
||||
Leonid Pechenik (lp--)
|
||||
Linus Arver
|
||||
loco-loco
|
||||
Luca Brivio (lucabrivio)
|
||||
Lucas Braesch (lucasart)
|
||||
Lyudmil Antonov (lantonov)
|
||||
Matthew Lai (matthewlai)
|
||||
Matthew Sullivan
|
||||
Mark Tenzer (31m059)
|
||||
Michael Byrne (MichaelB7)
|
||||
Michael Stembera (mstembera)
|
||||
Michael Chaly (Vizvezdenec)
|
||||
Michel Van den Bergh (vdbergh)
|
||||
Miguel Lahoz (miguel-l)
|
||||
Mikael Bäckman (mbootsector)
|
||||
Mike Whiteley (protonspring)
|
||||
Miroslav Fontán (Hexik)
|
||||
Moez Jellouli (MJZ1977)
|
||||
Mohammed Li (tthsqe12)
|
||||
Nathan Rugg (nmrugg)
|
||||
Nicklas Persson (NicklasPersson)
|
||||
Niklas Fiekas (niklasf)
|
||||
Ondrej Mosnáček (WOnder93)
|
||||
Oskar Werkelin Ahlin
|
||||
Pablo Vazquez
|
||||
Pascal Romaret
|
||||
Pasquale Pigazzini (ppigazzini)
|
||||
Patrick Jansen (mibere)
|
||||
pellanda
|
||||
Peter Zsifkovits (CoffeeOne)
|
||||
Ralph Stößer (Ralph Stoesser)
|
||||
Raminder Singh
|
||||
renouve
|
||||
Reuven Peleg
|
||||
Richard Lloyd
|
||||
Rodrigo Exterckötter Tjäder
|
||||
Ron Britvich (Britvich)
|
||||
Ronald de Man (syzygy1)
|
||||
Ryan Schmitt
|
||||
Ryan Takker
|
||||
Sebastian Buchwald (UniQP)
|
||||
Sergei Antonov (saproj)
|
||||
sf-x
|
||||
shane31
|
||||
Steinar Gunderson (sesse)
|
||||
Stefan Geschwentner (locutus2)
|
||||
Stefano Cardanobile (Stefano80)
|
||||
Stéphane Nicolet (snicolet)
|
||||
Thanar2
|
||||
thaspel
|
||||
Tom Vijlbrief (tomtor)
|
||||
Torsten Franz (torfranz)
|
||||
Uri Blass (uriblass)
|
||||
Vince Negri
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
### Overview
|
||||
|
||||
[](https://travis-ci.org/official-stockfish/Stockfish)
|
||||
[](https://ci.appveyor.com/project/mcostalba/stockfish)
|
||||
|
||||
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
||||
not a complete chess program and requires some UCI-compatible GUI
|
||||
(e.g. XBoard with PolyGlot, eboard, Arena, Sigma Chess, Shredder, Chess
|
||||
@@ -7,7 +10,7 @@ Partner or Fritz) in order to be used comfortably. Read the
|
||||
documentation for your GUI of choice for information about how to use
|
||||
Stockfish with it.
|
||||
|
||||
This version of Stockfish supports up to 128 cores. The engine defaults
|
||||
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.
|
||||
@@ -54,9 +57,9 @@ for correspondence games (because of tablebase adjudication).
|
||||
|
||||
The "SyzygyProbeLimit" option should normally be left at its default value.
|
||||
|
||||
**What to expect**
|
||||
**What to expect**
|
||||
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
|
||||
that it has found a winning line into a tablebase position.
|
||||
|
||||
@@ -93,6 +96,18 @@ compile (for instance with Microsoft MSVC) you need to manually
|
||||
set/unset some switches in the compiler command line; see file *types.h*
|
||||
for a quick reference.
|
||||
|
||||
### Resource For Understanding the Code Base
|
||||
|
||||
* [Chess Programming Wiki](https://www.chessprogramming.org/Main_Page)
|
||||
has good overall chess engines explanations
|
||||
(techniques used here are well explained like hash maps etc), it was
|
||||
also recommended by the [support team at stockfish.](http://support.stockfishchess.org/discussions/questions/1132-how-to-understand-stockfish-sources)
|
||||
|
||||
* [Here](https://www.chessprogramming.org/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.
|
||||
|
||||
|
||||
### Terms of use
|
||||
|
||||
@@ -109,4 +124,4 @@ to where the source code can be found. If you make any changes to the
|
||||
source code, these changes must also be made available under the GPL.
|
||||
|
||||
For full details, read the copy of the GPL found in the file named
|
||||
*Copying.txt*
|
||||
*Copying.txt*.
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
Contributors with >10,000 CPU hours as of November 4, 2018
|
||||
Thank you!
|
||||
|
||||
Username CPU Hours Games played
|
||||
noobpwnftw 3730975 292309380
|
||||
mibere 535242 43333774
|
||||
crunchy 375564 29121434
|
||||
cw 371664 28748719
|
||||
fastgm 318178 22283584
|
||||
JojoM 295354 20958931
|
||||
dew 215476 17079219
|
||||
ctoks 214031 17312035
|
||||
glinscott 204517 13932027
|
||||
bking_US 187568 12233168
|
||||
velislav 168404 13336219
|
||||
CSU_Dynasty 168069 14417712
|
||||
Thanar 162373 13842179
|
||||
spams 149531 10940322
|
||||
Fisherman 141137 12099359
|
||||
drabel 134441 11180178
|
||||
leszek 133658 9812120
|
||||
marrco 133566 10115202
|
||||
sqrt2 128420 10022279
|
||||
vdbergh 123230 9200516
|
||||
tvijlbrief 123007 9498831
|
||||
vdv 120381 8555423
|
||||
malala 117291 8126488
|
||||
dsmith 114010 7622414
|
||||
BrunoBanani 104938 7448565
|
||||
CoffeeOne 100042 4593596
|
||||
Data 94621 8433010
|
||||
mgrabiak 92248 7787406
|
||||
bcross 89440 8506568
|
||||
brabos 81868 6647613
|
||||
BRAVONE 80811 5341681
|
||||
psk 77195 6156031
|
||||
nordlandia 74833 6231930
|
||||
robal 72818 5969856
|
||||
TueRens 72523 6383294
|
||||
sterni1971 71049 5647590
|
||||
sunu 65855 5360884
|
||||
mhoram 65034 5192880
|
||||
davar 64794 5457564
|
||||
nssy 64607 5371952
|
||||
Pking_cda 64499 5704075
|
||||
biffhero 63557 5480444
|
||||
teddybaer 62147 5585620
|
||||
solarlight 61278 5402642
|
||||
ElbertoOne 60156 5504304
|
||||
jromang 58854 4704502
|
||||
dv8silencer 57421 3961325
|
||||
tinker 56039 4204914
|
||||
Freja 50331 3808121
|
||||
renouve 50318 3544864
|
||||
robnjr 47504 4131742
|
||||
grandphish2 47377 4110003
|
||||
eva42 46857 4075716
|
||||
ttruscott 46802 3811534
|
||||
finfish 46244 3481661
|
||||
rap 46201 3219490
|
||||
ronaldjerum 45641 3964331
|
||||
xoto 44998 4170431
|
||||
gvreuls 44359 3902234
|
||||
bigpen0r 41780 3448224
|
||||
Bobo1239 40767 3657490
|
||||
Antihistamine 39218 2792761
|
||||
mhunt 38991 2697512
|
||||
racerschmacer 38929 3756111
|
||||
VoyagerOne 35896 3378887
|
||||
homyur 35561 3012398
|
||||
rkl 33217 2978536
|
||||
pb00067 33034 2803485
|
||||
speedycpu 32043 2531964
|
||||
SC 31954 2848432
|
||||
EthanOConnor 31638 2143255
|
||||
oryx 30962 2899534
|
||||
gri 30108 2429137
|
||||
csnodgrass 29396 2808611
|
||||
Garf 28887 2873564
|
||||
Pyafue 28885 1986098
|
||||
jkiiski 28014 1923255
|
||||
slakovv 27017 2031279
|
||||
Prcuvu 26300 2307154
|
||||
hyperbolic.tom 26248 2200777
|
||||
jbwiebe 25663 2129063
|
||||
anst 25525 2279159
|
||||
Patrick_G 24222 1835674
|
||||
nabildanial 23524 1586321
|
||||
achambord 23495 1942546
|
||||
Sharaf_DG 22975 1790697
|
||||
chriswk 22876 1947731
|
||||
ncfish1 22689 1830009
|
||||
cuistot 22201 1383031
|
||||
Zirie 21171 1493227
|
||||
Isidor 20634 1736219
|
||||
JanErik 20596 1791991
|
||||
xor12 20535 1819280
|
||||
team-oh 20364 1653708
|
||||
nesoneg 20264 1493435
|
||||
dex 20110 1682756
|
||||
rstoesser 19802 1335177
|
||||
Vizvezdenec 19750 1695579
|
||||
eastorwest 19531 1841839
|
||||
sg4032 18913 1720157
|
||||
horst.prack 18425 1708197
|
||||
cisco2015 18408 1793774
|
||||
ianh2105 18133 1668562
|
||||
MazeOfGalious 18022 1644593
|
||||
ville 17900 1539130
|
||||
j3corre 17607 975954
|
||||
eudhan 17502 1424648
|
||||
jmdana 17351 1287546
|
||||
iisiraider 17175 1118788
|
||||
jundery 17172 1115855
|
||||
wei 16852 1822582
|
||||
SFTUser 16635 1363975
|
||||
purplefishies 16621 1106850
|
||||
DragonLord 16599 1252348
|
||||
chris 15274 1575333
|
||||
IgorLeMasson 15201 1364148
|
||||
dju 15074 914278
|
||||
Flopzee 14700 1331632
|
||||
OssumOpossum 14149 1029265
|
||||
enedene 13762 935618
|
||||
ako027ako 13442 1250249
|
||||
AdrianSA 13324 924980
|
||||
bpfliegel 13318 886523
|
||||
Nikolay.IT 13260 1155612
|
||||
jpulman 12776 854815
|
||||
joster 12438 988413
|
||||
fatmurphy 12015 901134
|
||||
Nesa92 11711 1132245
|
||||
Adrian.Schmidt123 11542 898699
|
||||
modolief 11228 926456
|
||||
Dark_wizzie 11214 1017910
|
||||
mschmidt 10973 818594
|
||||
Andrew Grant 10780 947859
|
||||
infinity 10762 746397
|
||||
SapphireBrand 10692 1024604
|
||||
Thomas A. Anderson 10553 736094
|
||||
basepi 10434 935168
|
||||
lantonov 10325 972610
|
||||
pgontarz 10294 878746
|
||||
Spprtr 10189 823246
|
||||
crocogoat 10115 1017325
|
||||
stocky 10083 718114
|
||||
@@ -0,0 +1,71 @@
|
||||
version: 1.0.{build}
|
||||
clone_depth: 50
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- appveyor
|
||||
|
||||
# Operating system (build VM template)
|
||||
os: Visual Studio 2015
|
||||
|
||||
# Build platform, i.e. x86, x64, AnyCPU. This setting is optional.
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
|
||||
# build Configuration, i.e. Debug, Release, etc.
|
||||
configuration:
|
||||
- Debug
|
||||
- Release
|
||||
|
||||
matrix:
|
||||
# The build fail immediately once one of the job fails
|
||||
fast_finish: true
|
||||
|
||||
# Scripts that are called at very beginning, before repo cloning
|
||||
init:
|
||||
- cmake --version
|
||||
- msbuild /version
|
||||
|
||||
before_build:
|
||||
- ps: |
|
||||
# Get sources
|
||||
$src = get-childitem -Path *.cpp -Recurse | select -ExpandProperty FullName
|
||||
$src = $src -join ' '
|
||||
$src = $src.Replace("\", "/")
|
||||
|
||||
# Build CMakeLists.txt
|
||||
$t = 'cmake_minimum_required(VERSION 3.8)',
|
||||
'project(Stockfish)',
|
||||
'set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/src)',
|
||||
'set(source_files', $src, ')',
|
||||
'add_executable(stockfish ${source_files})'
|
||||
|
||||
# Write CMakeLists.txt withouth BOM
|
||||
$MyPath = (Get-Item -Path "." -Verbose).FullName + '\CMakeLists.txt'
|
||||
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
|
||||
[System.IO.File]::WriteAllLines($MyPath, $t, $Utf8NoBomEncoding)
|
||||
|
||||
# Obtain bench reference from git log
|
||||
$b = git log HEAD | sls "\b[Bb]ench[ :]+[0-9]{7}" | select -first 1
|
||||
$bench = $b -match '\D+(\d+)' | % { $matches[1] }
|
||||
Write-Host "Reference bench:" $bench
|
||||
$g = "Visual Studio 14 2015"
|
||||
If (${env:PLATFORM} -eq 'x64') { $g = $g + ' Win64' }
|
||||
cmake -G "${g}" .
|
||||
Write-Host "Generated files for: " $g
|
||||
|
||||
build_script:
|
||||
- cmake --build . --config %CONFIGURATION% -- /verbosity:minimal
|
||||
|
||||
before_test:
|
||||
- cd src/%CONFIGURATION%
|
||||
- stockfish bench 2> out.txt >NUL
|
||||
- ps: |
|
||||
# Verify bench number
|
||||
$s = (gc "./out.txt" | out-string)
|
||||
$r = ($s -match 'Nodes searched \D+(\d+)' | % { $matches[1] })
|
||||
Write-Host "Engine bench:" $r
|
||||
Write-Host "Reference bench:" $bench
|
||||
If ($r -ne $bench) { exit 1 }
|
||||
+179
-128
@@ -1,6 +1,7 @@
|
||||
# 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-2019 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
|
||||
@@ -20,24 +21,31 @@
|
||||
### Section 1. General Configuration
|
||||
### ==========================================================================
|
||||
|
||||
### Establish the operating system name
|
||||
UNAME = $(shell uname)
|
||||
|
||||
### Executable name
|
||||
ifeq ($(COMP),mingw)
|
||||
EXE = stockfish.exe
|
||||
else
|
||||
EXE = stockfish
|
||||
endif
|
||||
|
||||
### Installation dir definitions
|
||||
PREFIX = /usr/local
|
||||
BINDIR = $(PREFIX)/bin
|
||||
|
||||
### Built-in benchmark for pgo-builds
|
||||
PGOBENCH = ./$(EXE) bench 16 1 1000 default time
|
||||
PGOBENCH = ./$(EXE) bench
|
||||
|
||||
### Object files
|
||||
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 \
|
||||
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
|
||||
|
||||
### Establish the operating system name
|
||||
KERNEL = $(shell uname -s)
|
||||
ifeq ($(KERNEL),Linux)
|
||||
OS = $(shell uname -o)
|
||||
endif
|
||||
|
||||
### ==========================================================================
|
||||
### Section 2. High-level Configuration
|
||||
### ==========================================================================
|
||||
@@ -46,13 +54,14 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
||||
# ----------------------------------------------------------------------------
|
||||
#
|
||||
# debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
|
||||
# sanitize = undefined/thread/no (-fsanitize )
|
||||
# --- ( undefined ) --- enable undefined behavior checks
|
||||
# --- ( thread ) --- enable threading error checks
|
||||
# optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
|
||||
# arch = (name) --- (-arch) --- Target architecture
|
||||
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
||||
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
|
||||
# bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
|
||||
# with GCC and ICC 64-bit)
|
||||
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
|
||||
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
|
||||
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
|
||||
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
||||
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
||||
#
|
||||
@@ -63,9 +72,9 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
||||
### 2.1. General and architecture defaults
|
||||
optimize = yes
|
||||
debug = no
|
||||
sanitize = no
|
||||
bits = 32
|
||||
prefetch = no
|
||||
bsfq = no
|
||||
popcnt = no
|
||||
sse = no
|
||||
pext = no
|
||||
@@ -95,7 +104,6 @@ ifeq ($(ARCH),x86-64)
|
||||
arch = x86_64
|
||||
bits = 64
|
||||
prefetch = yes
|
||||
bsfq = yes
|
||||
sse = yes
|
||||
endif
|
||||
|
||||
@@ -103,7 +111,6 @@ ifeq ($(ARCH),x86-64-modern)
|
||||
arch = x86_64
|
||||
bits = 64
|
||||
prefetch = yes
|
||||
bsfq = yes
|
||||
popcnt = yes
|
||||
sse = yes
|
||||
endif
|
||||
@@ -112,7 +119,6 @@ ifeq ($(ARCH),x86-64-bmi2)
|
||||
arch = x86_64
|
||||
bits = 64
|
||||
prefetch = yes
|
||||
bsfq = yes
|
||||
popcnt = yes
|
||||
sse = yes
|
||||
pext = yes
|
||||
@@ -121,7 +127,6 @@ endif
|
||||
ifeq ($(ARCH),armv7)
|
||||
arch = armv7
|
||||
prefetch = yes
|
||||
bsfq = yes
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),ppc-32)
|
||||
@@ -140,7 +145,8 @@ endif
|
||||
|
||||
### 3.1 Selecting compiler (default = gcc)
|
||||
|
||||
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
|
||||
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
|
||||
DEPENDFLAGS += -std=c++11
|
||||
LDFLAGS += $(EXTRALDFLAGS)
|
||||
|
||||
ifeq ($(COMP),)
|
||||
@@ -150,14 +156,46 @@ endif
|
||||
ifeq ($(COMP),gcc)
|
||||
comp=gcc
|
||||
CXX=g++
|
||||
CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
|
||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||
|
||||
ifeq ($(ARCH),armv7)
|
||||
ifeq ($(OS),Android)
|
||||
CXXFLAGS += -m$(bits)
|
||||
LDFLAGS += -m$(bits)
|
||||
endif
|
||||
else
|
||||
CXXFLAGS += -m$(bits)
|
||||
LDFLAGS += -m$(bits)
|
||||
endif
|
||||
|
||||
ifneq ($(KERNEL),Darwin)
|
||||
LDFLAGS += -Wl,--no-as-needed
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(COMP),mingw)
|
||||
comp=mingw
|
||||
CXX=g++
|
||||
|
||||
ifeq ($(KERNEL),Linux)
|
||||
ifeq ($(bits),64)
|
||||
ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
|
||||
CXX=x86_64-w64-mingw32-c++
|
||||
else
|
||||
CXX=x86_64-w64-mingw32-c++-posix
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell which i686-w64-mingw32-c++-posix),)
|
||||
CXX=i686-w64-mingw32-c++
|
||||
else
|
||||
CXX=i686-w64-mingw32-c++-posix
|
||||
endif
|
||||
endif
|
||||
else
|
||||
CXX=g++
|
||||
endif
|
||||
|
||||
CXXFLAGS += -Wextra -Wshadow
|
||||
LDFLAGS += -static-libstdc++ -static-libgcc
|
||||
LDFLAGS += -static
|
||||
endif
|
||||
|
||||
ifeq ($(COMP),icc)
|
||||
@@ -169,100 +207,101 @@ endif
|
||||
ifeq ($(COMP),clang)
|
||||
comp=clang
|
||||
CXX=clang++
|
||||
CXXFLAGS += -pedantic -Wno-long-long -Wextra -Wshadow
|
||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||
|
||||
ifneq ($(KERNEL),Darwin)
|
||||
ifneq ($(KERNEL),OpenBSD)
|
||||
LDFLAGS += -latomic
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),armv7)
|
||||
ifeq ($(OS),Android)
|
||||
CXXFLAGS += -m$(bits)
|
||||
LDFLAGS += -m$(bits)
|
||||
endif
|
||||
else
|
||||
CXXFLAGS += -m$(bits)
|
||||
LDFLAGS += -m$(bits)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(comp),icc)
|
||||
profile_prepare = icc-profile-prepare
|
||||
profile_make = icc-profile-make
|
||||
profile_use = icc-profile-use
|
||||
profile_clean = icc-profile-clean
|
||||
else
|
||||
profile_prepare = gcc-profile-prepare
|
||||
ifeq ($(comp),clang)
|
||||
profile_make = clang-profile-make
|
||||
profile_use = clang-profile-use
|
||||
else
|
||||
profile_make = gcc-profile-make
|
||||
profile_use = gcc-profile-use
|
||||
profile_clean = gcc-profile-clean
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME),Darwin)
|
||||
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.6
|
||||
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.6
|
||||
ifeq ($(KERNEL),Darwin)
|
||||
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
||||
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
||||
endif
|
||||
|
||||
### Travis CI script uses COMPILER to overwrite CXX
|
||||
ifdef COMPILER
|
||||
COMPCXX=$(COMPILER)
|
||||
endif
|
||||
|
||||
### Allow overwriting CXX from command line
|
||||
ifdef COMPCXX
|
||||
CXX=$(COMPCXX)
|
||||
endif
|
||||
|
||||
### On mingw use Windows threads, otherwise POSIX
|
||||
ifneq ($(comp),mingw)
|
||||
# On Android Bionic's C library comes with its own pthread implementation bundled in
|
||||
ifneq ($(arch),armv7)
|
||||
ifneq ($(OS),Android)
|
||||
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
||||
ifneq ($(UNAME),Haiku)
|
||||
ifneq ($(KERNEL),Haiku)
|
||||
LDFLAGS += -lpthread
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
### 3.4 Debugging
|
||||
### 3.2.1 Debugging
|
||||
ifeq ($(debug),no)
|
||||
CXXFLAGS += -DNDEBUG
|
||||
else
|
||||
CXXFLAGS += -g
|
||||
endif
|
||||
|
||||
### 3.5 Optimization
|
||||
### 3.2.2 Debugging with undefined behavior sanitizers
|
||||
ifneq ($(sanitize),no)
|
||||
CXXFLAGS += -g3 -fsanitize=$(sanitize) -fuse-ld=gold
|
||||
LDFLAGS += -fsanitize=$(sanitize) -fuse-ld=gold
|
||||
endif
|
||||
|
||||
### 3.3 Optimization
|
||||
ifeq ($(optimize),yes)
|
||||
|
||||
CXXFLAGS += -O3
|
||||
|
||||
ifeq ($(comp),gcc)
|
||||
CXXFLAGS += -O3
|
||||
|
||||
ifeq ($(UNAME),Darwin)
|
||||
ifeq ($(arch),i386)
|
||||
CXXFLAGS += -mdynamic-no-pic
|
||||
endif
|
||||
ifeq ($(arch),x86_64)
|
||||
CXXFLAGS += -mdynamic-no-pic
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(arch),armv7)
|
||||
ifeq ($(OS), Android)
|
||||
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(comp),mingw)
|
||||
CXXFLAGS += -O3
|
||||
endif
|
||||
|
||||
ifeq ($(comp),icc)
|
||||
ifeq ($(UNAME),Darwin)
|
||||
CXXFLAGS += -fast -mdynamic-no-pic
|
||||
else
|
||||
CXXFLAGS += -fast
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(comp),clang)
|
||||
CXXFLAGS += -O3
|
||||
|
||||
ifeq ($(UNAME),Darwin)
|
||||
ifeq ($(pext),no)
|
||||
CXXFLAGS += -flto
|
||||
LDFLAGS += $(CXXFLAGS)
|
||||
endif
|
||||
ifeq ($(arch),i386)
|
||||
CXXFLAGS += -mdynamic-no-pic
|
||||
endif
|
||||
ifeq ($(arch),x86_64)
|
||||
CXXFLAGS += -mdynamic-no-pic
|
||||
endif
|
||||
|
||||
ifeq ($(comp),$(filter $(comp),gcc clang icc))
|
||||
ifeq ($(KERNEL),Darwin)
|
||||
CXXFLAGS += -mdynamic-no-pic
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
### 3.6. Bits
|
||||
### 3.4 Bits
|
||||
ifeq ($(bits),64)
|
||||
CXXFLAGS += -DIS_64BIT
|
||||
endif
|
||||
|
||||
### 3.7 prefetch
|
||||
### 3.5 prefetch
|
||||
ifeq ($(prefetch),yes)
|
||||
ifeq ($(sse),yes)
|
||||
CXXFLAGS += -msse
|
||||
@@ -272,12 +311,7 @@ else
|
||||
CXXFLAGS += -DNO_PREFETCH
|
||||
endif
|
||||
|
||||
### 3.8 bsfq
|
||||
ifeq ($(bsfq),yes)
|
||||
CXXFLAGS += -DUSE_BSFQ
|
||||
endif
|
||||
|
||||
### 3.9 popcnt
|
||||
### 3.6 popcnt
|
||||
ifeq ($(popcnt),yes)
|
||||
ifeq ($(comp),icc)
|
||||
CXXFLAGS += -msse3 -DUSE_POPCNT
|
||||
@@ -286,33 +320,36 @@ ifeq ($(popcnt),yes)
|
||||
endif
|
||||
endif
|
||||
|
||||
### 3.10 pext
|
||||
### 3.7 pext
|
||||
ifeq ($(pext),yes)
|
||||
CXXFLAGS += -DUSE_PEXT
|
||||
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||
CXXFLAGS += -mbmi -mbmi2
|
||||
CXXFLAGS += -mbmi2
|
||||
endif
|
||||
endif
|
||||
|
||||
### 3.11 Link Time Optimization, it works since gcc 4.5 but not on mingw.
|
||||
### 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
|
||||
### needs access to the optimization flags.
|
||||
ifeq ($(comp),gcc)
|
||||
ifeq ($(optimize),yes)
|
||||
ifeq ($(debug),no)
|
||||
GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
|
||||
GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
|
||||
ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
|
||||
CXXFLAGS += -flto
|
||||
LDFLAGS += $(CXXFLAGS)
|
||||
endif
|
||||
ifeq ($(optimize),yes)
|
||||
ifeq ($(debug), no)
|
||||
ifeq ($(comp),$(filter $(comp),gcc clang))
|
||||
CXXFLAGS += -flto
|
||||
LDFLAGS += $(CXXFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(comp),mingw)
|
||||
ifeq ($(KERNEL),Linux)
|
||||
CXXFLAGS += -flto
|
||||
LDFLAGS += $(CXXFLAGS)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
### 3.12 Android 5 can only run position independent executables. Note that this
|
||||
### 3.9 Android 5 can only run position independent executables. Note that this
|
||||
### breaks Android 4.0 and earlier.
|
||||
ifeq ($(arch),armv7)
|
||||
ifeq ($(OS), Android)
|
||||
CXXFLAGS += -fPIE
|
||||
LDFLAGS += -fPIE -pie
|
||||
endif
|
||||
@@ -326,7 +363,7 @@ help:
|
||||
@echo ""
|
||||
@echo "To compile stockfish, type: "
|
||||
@echo ""
|
||||
@echo "make target ARCH=arch [COMP=comp]"
|
||||
@echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
|
||||
@echo ""
|
||||
@echo "Supported targets:"
|
||||
@echo ""
|
||||
@@ -356,36 +393,39 @@ help:
|
||||
@echo "clang > LLVM Clang compiler"
|
||||
@echo "icc > Intel compiler"
|
||||
@echo ""
|
||||
@echo "Examples. If you don't know what to do, you likely want to run: "
|
||||
@echo "Simple examples. If you don't know what to do, you likely want to run: "
|
||||
@echo ""
|
||||
@echo "make build ARCH=x86-64 (This is for 64-bit systems)"
|
||||
@echo "make build ARCH=x86-32 (This is for 32-bit systems)"
|
||||
@echo ""
|
||||
@echo "Advanced examples, for experienced users: "
|
||||
@echo ""
|
||||
@echo "make build ARCH=x86-64 COMP=clang"
|
||||
@echo "make profile-build ARCH=x86-64-modern COMP=gcc COMPCXX=g++-4.8"
|
||||
@echo ""
|
||||
|
||||
.PHONY: build profile-build
|
||||
build:
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
||||
|
||||
.PHONY: help build profile-build strip install clean objclean profileclean help \
|
||||
config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \
|
||||
clang-profile-use clang-profile-make
|
||||
|
||||
build: config-sanity
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
||||
|
||||
profile-build:
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
||||
profile-build: config-sanity objclean profileclean
|
||||
@echo ""
|
||||
@echo "Step 0/4. Preparing for profile build."
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
|
||||
@echo ""
|
||||
@echo "Step 1/4. Building executable for benchmark ..."
|
||||
@touch *.cpp *.h syzygy/*.cpp syzygy/*.h
|
||||
@echo "Step 1/4. Building instrumented executable ..."
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
||||
@echo ""
|
||||
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
||||
@$(PGOBENCH) > /dev/null
|
||||
$(PGOBENCH) > /dev/null
|
||||
@echo ""
|
||||
@echo "Step 3/4. Building final executable ..."
|
||||
@touch *.cpp *.h syzygy/*.cpp syzygy/*.h
|
||||
@echo "Step 3/4. Building optimized executable ..."
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
||||
@echo ""
|
||||
@echo "Step 4/4. Deleting profile data ..."
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
|
||||
|
||||
strip:
|
||||
strip $(EXE)
|
||||
@@ -395,8 +435,19 @@ install:
|
||||
-cp $(EXE) $(BINDIR)
|
||||
-strip $(BINDIR)/$(EXE)
|
||||
|
||||
clean:
|
||||
$(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda ./syzygy/*.o ./syzygy/*.gcda
|
||||
#clean all
|
||||
clean: objclean profileclean
|
||||
@rm -f .depend *~ core
|
||||
|
||||
# clean binaries and objects
|
||||
objclean:
|
||||
@rm -f $(EXE) *.o ./syzygy/*.o
|
||||
|
||||
# clean auxiliary profiling files
|
||||
profileclean:
|
||||
@rm -rf profdir
|
||||
@rm -f bench.txt *.gcda ./syzygy/*.gcda *.gcno ./syzygy/*.gcno
|
||||
@rm -f stockfish.profdata *.profraw
|
||||
|
||||
default:
|
||||
help
|
||||
@@ -411,11 +462,13 @@ config-sanity:
|
||||
@echo ""
|
||||
@echo "Config:"
|
||||
@echo "debug: '$(debug)'"
|
||||
@echo "sanitize: '$(sanitize)'"
|
||||
@echo "optimize: '$(optimize)'"
|
||||
@echo "arch: '$(arch)'"
|
||||
@echo "bits: '$(bits)'"
|
||||
@echo "kernel: '$(KERNEL)'"
|
||||
@echo "os: '$(OS)'"
|
||||
@echo "prefetch: '$(prefetch)'"
|
||||
@echo "bsfq: '$(bsfq)'"
|
||||
@echo "popcnt: '$(popcnt)'"
|
||||
@echo "sse: '$(sse)'"
|
||||
@echo "pext: '$(pext)'"
|
||||
@@ -428,12 +481,12 @@ config-sanity:
|
||||
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
||||
@echo ""
|
||||
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
||||
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "no"
|
||||
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
||||
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
||||
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
||||
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
||||
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
||||
@test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
|
||||
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
||||
@test "$(sse)" = "yes" || test "$(sse)" = "no"
|
||||
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
||||
@@ -442,32 +495,33 @@ config-sanity:
|
||||
$(EXE): $(OBJS)
|
||||
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
||||
|
||||
gcc-profile-prepare:
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
|
||||
clang-profile-make:
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||
EXTRACXXFLAGS='-fprofile-instr-generate ' \
|
||||
EXTRALDFLAGS=' -fprofile-instr-generate' \
|
||||
all
|
||||
|
||||
clang-profile-use:
|
||||
llvm-profdata merge -output=stockfish.profdata *.profraw
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||
EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
|
||||
EXTRALDFLAGS='-fprofile-use ' \
|
||||
all
|
||||
|
||||
gcc-profile-make:
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||
EXTRACXXFLAGS='-fprofile-arcs' \
|
||||
EXTRACXXFLAGS='-fprofile-generate' \
|
||||
EXTRALDFLAGS='-lgcov' \
|
||||
all
|
||||
|
||||
gcc-profile-use:
|
||||
# Deleting corrupt ucioption.gc* profile files is necessary to avoid an
|
||||
# "internal compiler error" for gcc versions 4.7.x
|
||||
@rm -f ucioption.gc*
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||
EXTRACXXFLAGS='-fbranch-probabilities' \
|
||||
EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \
|
||||
EXTRALDFLAGS='-lgcov' \
|
||||
all
|
||||
|
||||
gcc-profile-clean:
|
||||
@rm -rf *.gcda *.gcno syzygy/*.gcda syzygy/*.gcno bench.txt
|
||||
|
||||
icc-profile-prepare:
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
|
||||
@mkdir profdir
|
||||
|
||||
icc-profile-make:
|
||||
@mkdir -p profdir
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||
EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
|
||||
all
|
||||
@@ -477,9 +531,6 @@ icc-profile-use:
|
||||
EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
|
||||
all
|
||||
|
||||
icc-profile-clean:
|
||||
@rm -rf profdir bench.txt
|
||||
|
||||
.depend:
|
||||
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
||||
|
||||
|
||||
+44
-63
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -17,30 +18,25 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
#include "misc.h"
|
||||
#include "position.h"
|
||||
#include "search.h"
|
||||
#include "thread.h"
|
||||
#include "tt.h"
|
||||
#include "uci.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
|
||||
const char* Defaults[] = {
|
||||
const vector<string> Defaults = {
|
||||
"setoption name UCI_Chess960 value false",
|
||||
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
||||
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
|
||||
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
|
||||
"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
|
||||
"rq3rk1/ppp2ppp/1bnpb3/3N2B1/3NP3/7P/PPPQ1PP1/2KR3R w - - 7 14",
|
||||
"r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14",
|
||||
"rq3rk1/ppp2ppp/1bnpb3/3N2B1/3NP3/7P/PPPQ1PP1/2KR3R w - - 7 14 moves d4e6",
|
||||
"r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14 moves g2g4",
|
||||
"r3r1k1/2p2ppp/p1p1bn2/8/1q2P3/2NPQN2/PPP3PP/R4RK1 b - - 2 15",
|
||||
"r1bbk1nr/pp3p1p/2n5/1N4p1/2Np1B2/8/PPP2PPP/2KR1B1R w kq - 0 13",
|
||||
"r1bq1rk1/ppp1nppp/4n3/3p3Q/3P4/1BP1B3/PP1N2PP/R4RK1 w - - 1 16",
|
||||
@@ -53,7 +49,7 @@ const char* Defaults[] = {
|
||||
"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b - - 4 26",
|
||||
"6k1/6p1/6Pp/ppp5/3pn2P/1P3K2/1PP2P2/3N4 b - - 0 1",
|
||||
"3b4/5kp1/1p1p1p1p/pP1PpP1P/P1P1P3/3KN3/8/8 w - - 0 1",
|
||||
"2K5/p7/7P/5pR1/8/5k2/r7/8 w - - 0 1",
|
||||
"2K5/p7/7P/5pR1/8/5k2/r7/8 w - - 0 1 moves g5g6 f3e3 g6g5 e3f3",
|
||||
"8/6pk/1p6/8/PP3p1p/5P2/4KP1q/3Q4 w - - 0 1",
|
||||
"7k/3p2pp/4q3/8/4Q3/5Kp1/P6b/8 w - - 0 1",
|
||||
"8/2p5/8/2kPKp1p/2p4P/2P5/3P4/8 w - - 0 1",
|
||||
@@ -78,23 +74,37 @@ const char* Defaults[] = {
|
||||
|
||||
// 7-man positions
|
||||
"8/R7/2q5/8/6k1/8/1P5p/K6R w - - 0 124", // Draw
|
||||
|
||||
// Mate and stalemate positions
|
||||
"6k1/3b3r/1p1p4/p1n2p2/1PPNpP1q/P3Q1p1/1R1RB1P1/5K2 b - - 0 1",
|
||||
"r2r1n2/pp2bk2/2p1p2p/3q4/3PN1QP/2P3R1/P4PP1/5RK1 w - - 0 1",
|
||||
"8/8/8/8/8/6k1/6p1/6K1 w - -",
|
||||
"7k/7P/6K1/8/3B4/8/8/8 b - -",
|
||||
|
||||
// Chess 960
|
||||
"setoption name UCI_Chess960 value true",
|
||||
"bbqnnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w KQkq - 0 1 moves g2g3 d7d5 d2d4 c8h3 c1g5 e8d6 g5e7 f7f6",
|
||||
"setoption name UCI_Chess960 value false"
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
/// benchmark() runs a simple benchmark by letting Stockfish analyze a set
|
||||
/// of positions for a given limit each. There are five parameters: the
|
||||
/// transposition table size, the number of search threads that should
|
||||
/// be used, the limit value spent for each position (optional, default is
|
||||
/// depth 13), an optional file name where to look for positions in FEN
|
||||
/// format (defaults are the positions defined above) and the type of the
|
||||
/// limit value: depth (default), time in millisecs or number of nodes.
|
||||
/// setup_bench() builds a list of UCI commands to be run by bench. There
|
||||
/// are five parameters: TT size in MB, number of search threads that
|
||||
/// should be used, the limit value spent for each position, a file name
|
||||
/// where to look for positions in FEN format and the type of the limit:
|
||||
/// depth, perft, nodes and movetime (in millisecs).
|
||||
///
|
||||
/// bench -> search default positions up to depth 13
|
||||
/// bench 64 1 15 -> search default positions up to depth 15 (TT = 64MB)
|
||||
/// bench 64 4 5000 current movetime -> search current position with 4 threads for 5 sec
|
||||
/// bench 64 1 100000 default nodes -> search default positions for 100K nodes each
|
||||
/// bench 16 1 5 default perft -> run a perft 5 on default positions
|
||||
|
||||
void benchmark(const Position& current, istream& is) {
|
||||
vector<string> setup_bench(const Position& current, istream& is) {
|
||||
|
||||
string token;
|
||||
Search::LimitsType limits;
|
||||
vector<string> fens;
|
||||
vector<string> fens, list;
|
||||
string go, token;
|
||||
|
||||
// Assign default values to missing arguments
|
||||
string ttSize = (is >> token) ? token : "16";
|
||||
@@ -103,24 +113,10 @@ void benchmark(const Position& current, istream& is) {
|
||||
string fenFile = (is >> token) ? token : "default";
|
||||
string limitType = (is >> token) ? token : "depth";
|
||||
|
||||
Options["Hash"] = ttSize;
|
||||
Options["Threads"] = threads;
|
||||
TT.clear();
|
||||
|
||||
if (limitType == "time")
|
||||
limits.movetime = atoi(limit.c_str()); // movetime is in ms
|
||||
|
||||
else if (limitType == "nodes")
|
||||
limits.nodes = atoi(limit.c_str());
|
||||
|
||||
else if (limitType == "mate")
|
||||
limits.mate = atoi(limit.c_str());
|
||||
|
||||
else
|
||||
limits.depth = atoi(limit.c_str());
|
||||
go = "go " + limitType + " " + limit;
|
||||
|
||||
if (fenFile == "default")
|
||||
fens.assign(Defaults, Defaults + 37);
|
||||
fens = Defaults;
|
||||
|
||||
else if (fenFile == "current")
|
||||
fens.push_back(current.fen());
|
||||
@@ -128,12 +124,12 @@ void benchmark(const Position& current, istream& is) {
|
||||
else
|
||||
{
|
||||
string fen;
|
||||
ifstream file(fenFile.c_str());
|
||||
ifstream file(fenFile);
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
cerr << "Unable to open file " << fenFile << endl;
|
||||
return;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (getline(file, fen))
|
||||
@@ -143,33 +139,18 @@ void benchmark(const Position& current, istream& is) {
|
||||
file.close();
|
||||
}
|
||||
|
||||
uint64_t nodes = 0;
|
||||
Search::StateStackPtr st;
|
||||
Time::point elapsed = Time::now();
|
||||
|
||||
for (size_t i = 0; i < fens.size(); ++i)
|
||||
{
|
||||
Position pos(fens[i], Options["UCI_Chess960"], Threads.main());
|
||||
|
||||
cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl;
|
||||
|
||||
if (limitType == "perft")
|
||||
nodes += Search::perft<true>(pos, limits.depth * ONE_PLY);
|
||||
list.emplace_back("ucinewgame");
|
||||
list.emplace_back("setoption name Threads value " + threads);
|
||||
list.emplace_back("setoption name Hash value " + ttSize);
|
||||
|
||||
for (const string& fen : fens)
|
||||
if (fen.find("setoption") != string::npos)
|
||||
list.emplace_back(fen);
|
||||
else
|
||||
{
|
||||
Threads.start_thinking(pos, limits, st);
|
||||
Threads.wait_for_think_finished();
|
||||
nodes += Search::RootPos.nodes_searched();
|
||||
list.emplace_back("position fen " + fen);
|
||||
list.emplace_back(go);
|
||||
}
|
||||
}
|
||||
|
||||
elapsed = std::max(Time::now() - elapsed, Time::point(1)); // Avoid a 'divide by zero'
|
||||
|
||||
dbg_print(); // Just before to exit
|
||||
|
||||
cerr << "\n==========================="
|
||||
<< "\nTotal time (ms) : " << elapsed
|
||||
<< "\nNodes searched : " << nodes
|
||||
<< "\nNodes/second : " << 1000 * nodes / elapsed << endl;
|
||||
return list;
|
||||
}
|
||||
|
||||
+52
-47
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -17,7 +18,9 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
#include "bitboard.h"
|
||||
@@ -26,7 +29,7 @@
|
||||
namespace {
|
||||
|
||||
// There are 24 possible pawn squares: the first 4 files and ranks from 2 to 7
|
||||
const unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
||||
constexpr unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
||||
|
||||
// Each uint32_t stores results of 32 positions, one per bit
|
||||
uint32_t KPKBitbase[MAX_INDEX / 32];
|
||||
@@ -51,20 +54,19 @@ namespace {
|
||||
WIN = 4
|
||||
};
|
||||
|
||||
inline Result& operator|=(Result& r, Result v) { return r = Result(r | v); }
|
||||
Result& operator|=(Result& r, Result v) { return r = Result(r | v); }
|
||||
|
||||
struct KPKPosition {
|
||||
|
||||
KPKPosition(unsigned idx);
|
||||
KPKPosition() = default;
|
||||
explicit KPKPosition(unsigned idx);
|
||||
operator Result() const { return result; }
|
||||
Result classify(const std::vector<KPKPosition>& db)
|
||||
{ return us == WHITE ? classify<WHITE>(db) : classify<BLACK>(db); }
|
||||
|
||||
private:
|
||||
template<Color Us> Result classify(const std::vector<KPKPosition>& db);
|
||||
|
||||
Color us;
|
||||
Square bksq, wksq, psq;
|
||||
Square ksq[COLOR_NB], psq;
|
||||
Result result;
|
||||
};
|
||||
|
||||
@@ -82,13 +84,12 @@ bool Bitbases::probe(Square wksq, Square wpsq, Square bksq, Color us) {
|
||||
|
||||
void Bitbases::init() {
|
||||
|
||||
std::vector<KPKPosition> db(MAX_INDEX);
|
||||
unsigned idx, repeat = 1;
|
||||
std::vector<KPKPosition> db;
|
||||
db.reserve(MAX_INDEX);
|
||||
|
||||
// Initialize db with known win / draw positions
|
||||
for (idx = 0; idx < MAX_INDEX; ++idx)
|
||||
db.push_back(KPKPosition(idx));
|
||||
db[idx] = KPKPosition(idx);
|
||||
|
||||
// Iterate through the positions until none of the unknown positions can be
|
||||
// changed to either wins or draws (15 cycles needed).
|
||||
@@ -107,69 +108,73 @@ namespace {
|
||||
|
||||
KPKPosition::KPKPosition(unsigned idx) {
|
||||
|
||||
wksq = Square((idx >> 0) & 0x3F);
|
||||
bksq = Square((idx >> 6) & 0x3F);
|
||||
us = Color ((idx >> 12) & 0x01);
|
||||
psq = make_square(File((idx >> 13) & 0x3), RANK_7 - Rank((idx >> 15) & 0x7));
|
||||
result = UNKNOWN;
|
||||
ksq[WHITE] = Square((idx >> 0) & 0x3F);
|
||||
ksq[BLACK] = Square((idx >> 6) & 0x3F);
|
||||
us = Color ((idx >> 12) & 0x01);
|
||||
psq = make_square(File((idx >> 13) & 0x3), Rank(RANK_7 - ((idx >> 15) & 0x7)));
|
||||
|
||||
// Check if two pieces are on the same square or if a king can be captured
|
||||
if ( distance(wksq, bksq) <= 1
|
||||
|| wksq == psq
|
||||
|| bksq == psq
|
||||
|| (us == WHITE && (StepAttacksBB[PAWN][psq] & bksq)))
|
||||
if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
|
||||
|| ksq[WHITE] == psq
|
||||
|| ksq[BLACK] == psq
|
||||
|| (us == WHITE && (PawnAttacks[WHITE][psq] & ksq[BLACK])))
|
||||
result = INVALID;
|
||||
|
||||
else if (us == WHITE)
|
||||
{
|
||||
// Immediate win if a pawn can be promoted without getting captured
|
||||
if ( rank_of(psq) == RANK_7
|
||||
&& wksq != psq + DELTA_N
|
||||
&& ( distance(bksq, psq + DELTA_N) > 1
|
||||
||(StepAttacksBB[KING][wksq] & (psq + DELTA_N))))
|
||||
result = WIN;
|
||||
}
|
||||
// Immediate win if a pawn can be promoted without getting captured
|
||||
else if ( us == WHITE
|
||||
&& rank_of(psq) == RANK_7
|
||||
&& ksq[us] != psq + NORTH
|
||||
&& ( distance(ksq[~us], psq + NORTH) > 1
|
||||
|| (PseudoAttacks[KING][ksq[us]] & (psq + NORTH))))
|
||||
result = WIN;
|
||||
|
||||
// Immediate draw if it is a stalemate or a king captures undefended pawn
|
||||
else if ( !(StepAttacksBB[KING][bksq] & ~(StepAttacksBB[KING][wksq] | StepAttacksBB[PAWN][psq]))
|
||||
|| (StepAttacksBB[KING][bksq] & psq & ~StepAttacksBB[KING][wksq]))
|
||||
else if ( us == BLACK
|
||||
&& ( !(PseudoAttacks[KING][ksq[us]] & ~(PseudoAttacks[KING][ksq[~us]] | PawnAttacks[~us][psq]))
|
||||
|| (PseudoAttacks[KING][ksq[us]] & psq & ~PseudoAttacks[KING][ksq[~us]])))
|
||||
result = DRAW;
|
||||
|
||||
// Position will be classified later
|
||||
else
|
||||
result = UNKNOWN;
|
||||
}
|
||||
|
||||
template<Color Us>
|
||||
Result KPKPosition::classify(const std::vector<KPKPosition>& db) {
|
||||
|
||||
// White to Move: If one move leads to a position classified as WIN, the result
|
||||
// White to move: If one move leads to a position classified as WIN, the result
|
||||
// of the current position is WIN. If all moves lead to positions classified
|
||||
// as DRAW, the current position is classified as DRAW, otherwise the current
|
||||
// position is classified as UNKNOWN.
|
||||
//
|
||||
// Black to Move: If one move leads to a position classified as DRAW, the result
|
||||
// Black to move: If one move leads to a position classified as DRAW, the result
|
||||
// of the current position is DRAW. If all moves lead to positions classified
|
||||
// as WIN, the position is classified as WIN, otherwise the current position is
|
||||
// classified as UNKNOWN.
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Result Good = (Us == WHITE ? WIN : DRAW);
|
||||
constexpr Result Bad = (Us == WHITE ? DRAW : WIN);
|
||||
|
||||
Result r = INVALID;
|
||||
Bitboard b = StepAttacksBB[KING][Us == WHITE ? wksq : bksq];
|
||||
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
||||
|
||||
while (b)
|
||||
r |= Us == WHITE ? db[index(Them, bksq, pop_lsb(&b), psq)]
|
||||
: db[index(Them, pop_lsb(&b), wksq, psq)];
|
||||
|
||||
if (Us == WHITE && rank_of(psq) < RANK_7)
|
||||
{
|
||||
Square s = psq + DELTA_N;
|
||||
r |= db[index(BLACK, bksq, wksq, s)]; // Single push
|
||||
|
||||
if (rank_of(psq) == RANK_2 && s != wksq && s != bksq)
|
||||
r |= db[index(BLACK, bksq, wksq, s + DELTA_N)]; // Double push
|
||||
}
|
||||
r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)]
|
||||
: db[index(Them, pop_lsb(&b), ksq[Them] , psq)];
|
||||
|
||||
if (Us == WHITE)
|
||||
return result = r & WIN ? WIN : r & UNKNOWN ? UNKNOWN : DRAW;
|
||||
else
|
||||
return result = r & DRAW ? DRAW : r & UNKNOWN ? UNKNOWN : WIN;
|
||||
{
|
||||
if (rank_of(psq) < RANK_7) // Single push
|
||||
r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH)];
|
||||
|
||||
if ( rank_of(psq) == RANK_2 // Double push
|
||||
&& psq + NORTH != ksq[Us]
|
||||
&& psq + NORTH != ksq[Them])
|
||||
r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH + NORTH)];
|
||||
}
|
||||
|
||||
return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
+80
-137
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -18,102 +19,47 @@
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring> // For std::memset
|
||||
|
||||
#include "bitboard.h"
|
||||
#include "bitcount.h"
|
||||
#include "misc.h"
|
||||
|
||||
uint8_t PopCnt16[1 << 16];
|
||||
int SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||
|
||||
Bitboard RookMasks [SQUARE_NB];
|
||||
Bitboard RookMagics [SQUARE_NB];
|
||||
Bitboard* RookAttacks[SQUARE_NB];
|
||||
unsigned RookShifts [SQUARE_NB];
|
||||
|
||||
Bitboard BishopMasks [SQUARE_NB];
|
||||
Bitboard BishopMagics [SQUARE_NB];
|
||||
Bitboard* BishopAttacks[SQUARE_NB];
|
||||
unsigned BishopShifts [SQUARE_NB];
|
||||
|
||||
Bitboard SquareBB[SQUARE_NB];
|
||||
Bitboard FileBB[FILE_NB];
|
||||
Bitboard RankBB[RANK_NB];
|
||||
Bitboard AdjacentFilesBB[FILE_NB];
|
||||
Bitboard InFrontBB[COLOR_NB][RANK_NB];
|
||||
Bitboard StepAttacksBB[PIECE_NB][SQUARE_NB];
|
||||
Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
|
||||
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
||||
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||
Bitboard DistanceRingBB[SQUARE_NB][8];
|
||||
Bitboard ForwardBB[COLOR_NB][SQUARE_NB];
|
||||
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 PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||
|
||||
Magic RookMagics[SQUARE_NB];
|
||||
Magic BishopMagics[SQUARE_NB];
|
||||
|
||||
namespace {
|
||||
|
||||
// De Bruijn sequences. See chessprogramming.wikispaces.com/BitScan
|
||||
const uint64_t DeBruijn64 = 0x3F79D71B4CB0A89ULL;
|
||||
const uint32_t DeBruijn32 = 0x783A9B23;
|
||||
|
||||
int MS1BTable[256]; // To implement software msb()
|
||||
Square BSFTable[SQUARE_NB]; // To implement software bitscan
|
||||
Bitboard RookTable[0x19000]; // To store rook attacks
|
||||
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
||||
|
||||
typedef unsigned (Fn)(Square, Bitboard);
|
||||
void init_magics(Bitboard table[], Magic magics[], Direction directions[]);
|
||||
|
||||
void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
|
||||
Bitboard masks[], unsigned shifts[], Square deltas[], Fn index);
|
||||
// popcount16() counts the non-zero bits using SWAR-Popcount algorithm
|
||||
|
||||
// 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.
|
||||
|
||||
FORCE_INLINE unsigned bsf_index(Bitboard b) {
|
||||
b ^= b - 1;
|
||||
return Is64Bit ? (b * DeBruijn64) >> 58
|
||||
: ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn32) >> 26;
|
||||
unsigned popcount16(unsigned u) {
|
||||
u -= (u >> 1) & 0x5555U;
|
||||
u = ((u >> 2) & 0x3333U) + (u & 0x3333U);
|
||||
u = ((u >> 4) + u) & 0x0F0FU;
|
||||
return (u * 0x0101U) >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef USE_BSFQ
|
||||
|
||||
/// Software fall-back of lsb() and msb() for CPU lacking hardware support
|
||||
|
||||
Square lsb(Bitboard b) {
|
||||
return BSFTable[bsf_index(b)];
|
||||
}
|
||||
|
||||
Square msb(Bitboard 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 + MS1BTable[b32]);
|
||||
}
|
||||
|
||||
#endif // ifndef USE_BSFQ
|
||||
|
||||
|
||||
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
|
||||
/// to be printed to standard output. Useful for debugging.
|
||||
@@ -125,9 +71,9 @@ const std::string Bitboards::pretty(Bitboard b) {
|
||||
for (Rank r = RANK_8; r >= RANK_1; --r)
|
||||
{
|
||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||
s.append(b & make_square(f, r) ? "| X " : "| ");
|
||||
s += b & make_square(f, r) ? "| X " : "| ";
|
||||
|
||||
s.append("|\n+---+---+---+---+---+---+---+---+\n");
|
||||
s += "|\n+---+---+---+---+---+---+---+---+\n";
|
||||
}
|
||||
|
||||
return s;
|
||||
@@ -139,14 +85,11 @@ const std::string Bitboards::pretty(Bitboard b) {
|
||||
|
||||
void Bitboards::init() {
|
||||
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
{
|
||||
SquareBB[s] = 1ULL << s;
|
||||
BSFTable[bsf_index(SquareBB[s])] = s;
|
||||
}
|
||||
for (unsigned i = 0; i < (1 << 16); ++i)
|
||||
PopCnt16[i] = (uint8_t) popcount16(i);
|
||||
|
||||
for (Bitboard b = 1; b < 256; ++b)
|
||||
MS1BTable[b] = more_than_one(b) ? MS1BTable[b - 1] : lsb(b);
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
SquareBB[s] = (1ULL << s);
|
||||
|
||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||
FileBB[f] = f > FILE_A ? FileBB[f - 1] << 1 : FileABB;
|
||||
@@ -158,14 +101,14 @@ void Bitboards::init() {
|
||||
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)
|
||||
InFrontBB[WHITE][r] = ~(InFrontBB[BLACK][r + 1] = InFrontBB[BLACK][r] | RankBB[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)
|
||||
{
|
||||
ForwardBB[c][s] = InFrontBB[c][rank_of(s)] & FileBB[file_of(s)];
|
||||
PawnAttackSpan[c][s] = InFrontBB[c][rank_of(s)] & AdjacentFilesBB[file_of(s)];
|
||||
PassedPawnMask[c][s] = ForwardBB[c][s] | PawnAttackSpan[c][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)
|
||||
@@ -173,59 +116,61 @@ void Bitboards::init() {
|
||||
if (s1 != s2)
|
||||
{
|
||||
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
|
||||
DistanceRingBB[s1][SquareDistance[s1][s2] - 1] |= s2;
|
||||
DistanceRingBB[s1][SquareDistance[s1][s2]] |= s2;
|
||||
}
|
||||
|
||||
int steps[][9] = { {}, { 7, 9 }, { 17, 15, 10, 6, -6, -10, -15, -17 },
|
||||
{}, {}, {}, { 9, 7, -7, -9, 8, 1, -1, -8 } };
|
||||
int steps[][5] = { {}, { 7, 9 }, { 6, 10, 15, 17 }, {}, {}, {}, { 1, 7, 8, 9 } };
|
||||
|
||||
for (Color c = WHITE; c <= BLACK; ++c)
|
||||
for (PieceType pt = PAWN; pt <= KING; ++pt)
|
||||
for (PieceType pt : { PAWN, KNIGHT, KING })
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
for (int i = 0; steps[pt][i]; ++i)
|
||||
{
|
||||
Square to = s + Square(c == WHITE ? steps[pt][i] : -steps[pt][i]);
|
||||
Square to = s + Direction(c == WHITE ? steps[pt][i] : -steps[pt][i]);
|
||||
|
||||
if (is_ok(to) && distance(s, to) < 3)
|
||||
StepAttacksBB[make_piece(c, pt)][s] |= to;
|
||||
{
|
||||
if (pt == PAWN)
|
||||
PawnAttacks[c][s] |= to;
|
||||
else
|
||||
PseudoAttacks[pt][s] |= to;
|
||||
}
|
||||
}
|
||||
|
||||
Square RookDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
|
||||
Square BishopDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW };
|
||||
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
|
||||
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
|
||||
|
||||
init_magics(RookTable, RookAttacks, RookMagics, RookMasks, RookShifts, RookDeltas, magic_index<ROOK>);
|
||||
init_magics(BishopTable, BishopAttacks, BishopMagics, BishopMasks, BishopShifts, BishopDeltas, magic_index<BISHOP>);
|
||||
init_magics(RookTable, RookMagics, RookDirections);
|
||||
init_magics(BishopTable, BishopMagics, BishopDirections);
|
||||
|
||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||
{
|
||||
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
||||
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
||||
|
||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||
{
|
||||
Piece pc = (PseudoAttacks[BISHOP][s1] & s2) ? W_BISHOP :
|
||||
(PseudoAttacks[ROOK][s1] & s2) ? W_ROOK : NO_PIECE;
|
||||
for (PieceType pt : { BISHOP, ROOK })
|
||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||
{
|
||||
if (!(PseudoAttacks[pt][s1] & s2))
|
||||
continue;
|
||||
|
||||
if (pc == NO_PIECE)
|
||||
continue;
|
||||
|
||||
LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
|
||||
BetweenBB[s1][s2] = attacks_bb(pc, s1, SquareBB[s2]) & attacks_bb(pc, s2, SquareBB[s1]);
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
Bitboard sliding_attack(Square deltas[], Square sq, Bitboard occupied) {
|
||||
Bitboard sliding_attack(Direction directions[], Square sq, Bitboard occupied) {
|
||||
|
||||
Bitboard attack = 0;
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (Square s = sq + deltas[i];
|
||||
is_ok(s) && distance(s, s - deltas[i]) == 1;
|
||||
s += deltas[i])
|
||||
for (Square s = sq + directions[i];
|
||||
is_ok(s) && distance(s, s - directions[i]) == 1;
|
||||
s += directions[i])
|
||||
{
|
||||
attack |= s;
|
||||
|
||||
@@ -242,17 +187,14 @@ namespace {
|
||||
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
|
||||
// use the so called "fancy" approach.
|
||||
|
||||
void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
|
||||
Bitboard masks[], unsigned shifts[], Square deltas[], Fn index) {
|
||||
void init_magics(Bitboard table[], Magic magics[], Direction directions[]) {
|
||||
|
||||
// Optimal PRNG seeds to pick the correct magics in the shortest time
|
||||
int seeds[][RANK_NB] = { { 8977, 44560, 54343, 38998, 5731, 95205, 104912, 17020 },
|
||||
{ 728, 10316, 55013, 32803, 12281, 15100, 16645, 255 } };
|
||||
|
||||
Bitboard occupancy[4096], reference[4096], edges, b;
|
||||
int i, size;
|
||||
|
||||
// attacks[s] is a pointer to the beginning of the attacks table for square 's'
|
||||
attacks[SQ_A1] = table;
|
||||
int epoch[4096] = {}, cnt = 0, size = 0;
|
||||
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
{
|
||||
@@ -264,28 +206,28 @@ namespace {
|
||||
// all the attacks for each possible subset of the mask and so is 2 power
|
||||
// the number of 1s of the mask. Hence we deduce the size of the shift to
|
||||
// apply to the 64 or 32 bits word to get the index.
|
||||
masks[s] = sliding_attack(deltas, s, 0) & ~edges;
|
||||
shifts[s] = (Is64Bit ? 64 : 32) - popcount<Max15>(masks[s]);
|
||||
Magic& m = magics[s];
|
||||
m.mask = sliding_attack(directions, s, 0) & ~edges;
|
||||
m.shift = (Is64Bit ? 64 : 32) - popcount(m.mask);
|
||||
|
||||
// Set the offset for the attacks table of the square. We have individual
|
||||
// table sizes for each square with "Fancy Magic Bitboards".
|
||||
m.attacks = s == SQ_A1 ? table : magics[s - 1].attacks + size;
|
||||
|
||||
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and
|
||||
// store the corresponding sliding attack bitboard in reference[].
|
||||
b = size = 0;
|
||||
do {
|
||||
occupancy[size] = b;
|
||||
reference[size] = sliding_attack(deltas, s, b);
|
||||
reference[size] = sliding_attack(directions, s, b);
|
||||
|
||||
if (HasPext)
|
||||
attacks[s][pext(b, masks[s])] = reference[size];
|
||||
m.attacks[pext(b, m.mask)] = reference[size];
|
||||
|
||||
size++;
|
||||
b = (b - masks[s]) & masks[s];
|
||||
b = (b - m.mask) & m.mask;
|
||||
} while (b);
|
||||
|
||||
// Set the offset for the table of the next square. We have individual
|
||||
// table sizes for each square with "Fancy Magic Bitboards".
|
||||
if (s < SQ_H8)
|
||||
attacks[s + 1] = attacks[s] + size;
|
||||
|
||||
if (HasPext)
|
||||
continue;
|
||||
|
||||
@@ -293,29 +235,30 @@ namespace {
|
||||
|
||||
// Find a magic for square 's' picking up an (almost) random number
|
||||
// until we find the one that passes the verification test.
|
||||
do {
|
||||
do
|
||||
magics[s] = rng.sparse_rand<Bitboard>();
|
||||
while (popcount<Max15>((magics[s] * masks[s]) >> 56) < 6);
|
||||
|
||||
std::memset(attacks[s], 0, size * sizeof(Bitboard));
|
||||
for (int i = 0; i < size; )
|
||||
{
|
||||
for (m.magic = 0; popcount((m.magic * m.mask) >> 56) < 6; )
|
||||
m.magic = rng.sparse_rand<Bitboard>();
|
||||
|
||||
// A good magic must map every possible occupancy to an index that
|
||||
// looks up the correct sliding attack in the attacks[s] database.
|
||||
// Note that we build up the database for square 's' as a side
|
||||
// effect of verifying the magic.
|
||||
for (i = 0; i < size; ++i)
|
||||
// effect of verifying the magic. Keep track of the attempt count
|
||||
// and save it in epoch[], little speed-up trick to avoid resetting
|
||||
// m.attacks[] after every failed attempt.
|
||||
for (++cnt, i = 0; i < size; ++i)
|
||||
{
|
||||
Bitboard& attack = attacks[s][index(s, occupancy[i])];
|
||||
unsigned idx = m.index(occupancy[i]);
|
||||
|
||||
if (attack && attack != reference[i])
|
||||
if (epoch[idx] < cnt)
|
||||
{
|
||||
epoch[idx] = cnt;
|
||||
m.attacks[idx] = reference[i];
|
||||
}
|
||||
else if (m.attacks[idx] != reference[i])
|
||||
break;
|
||||
|
||||
assert(reference[i]);
|
||||
|
||||
attack = reference[i];
|
||||
}
|
||||
} while (i < size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+159
-115
@@ -2,13 +2,13 @@
|
||||
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-2019 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
|
||||
@@ -39,81 +39,102 @@ const std::string pretty(Bitboard b);
|
||||
|
||||
}
|
||||
|
||||
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
||||
constexpr Bitboard AllSquares = ~Bitboard(0);
|
||||
constexpr Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
||||
|
||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
||||
const Bitboard FileBBB = FileABB << 1;
|
||||
const Bitboard FileCBB = FileABB << 2;
|
||||
const Bitboard FileDBB = FileABB << 3;
|
||||
const Bitboard FileEBB = FileABB << 4;
|
||||
const Bitboard FileFBB = FileABB << 5;
|
||||
const Bitboard FileGBB = FileABB << 6;
|
||||
const Bitboard FileHBB = FileABB << 7;
|
||||
constexpr Bitboard FileABB = 0x0101010101010101ULL;
|
||||
constexpr Bitboard FileBBB = FileABB << 1;
|
||||
constexpr Bitboard FileCBB = FileABB << 2;
|
||||
constexpr Bitboard FileDBB = FileABB << 3;
|
||||
constexpr Bitboard FileEBB = FileABB << 4;
|
||||
constexpr Bitboard FileFBB = FileABB << 5;
|
||||
constexpr Bitboard FileGBB = FileABB << 6;
|
||||
constexpr Bitboard FileHBB = FileABB << 7;
|
||||
|
||||
const Bitboard Rank1BB = 0xFF;
|
||||
const Bitboard Rank2BB = Rank1BB << (8 * 1);
|
||||
const Bitboard Rank3BB = Rank1BB << (8 * 2);
|
||||
const Bitboard Rank4BB = Rank1BB << (8 * 3);
|
||||
const Bitboard Rank5BB = Rank1BB << (8 * 4);
|
||||
const Bitboard Rank6BB = Rank1BB << (8 * 5);
|
||||
const Bitboard Rank7BB = Rank1BB << (8 * 6);
|
||||
const Bitboard Rank8BB = Rank1BB << (8 * 7);
|
||||
constexpr Bitboard Rank1BB = 0xFF;
|
||||
constexpr Bitboard Rank2BB = Rank1BB << (8 * 1);
|
||||
constexpr Bitboard Rank3BB = Rank1BB << (8 * 2);
|
||||
constexpr Bitboard Rank4BB = Rank1BB << (8 * 3);
|
||||
constexpr Bitboard Rank5BB = Rank1BB << (8 * 4);
|
||||
constexpr Bitboard Rank6BB = Rank1BB << (8 * 5);
|
||||
constexpr Bitboard Rank7BB = Rank1BB << (8 * 6);
|
||||
constexpr Bitboard Rank8BB = Rank1BB << (8 * 7);
|
||||
|
||||
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||
|
||||
extern Bitboard RookMasks [SQUARE_NB];
|
||||
extern Bitboard RookMagics [SQUARE_NB];
|
||||
extern Bitboard* RookAttacks[SQUARE_NB];
|
||||
extern unsigned RookShifts [SQUARE_NB];
|
||||
|
||||
extern Bitboard BishopMasks [SQUARE_NB];
|
||||
extern Bitboard BishopMagics [SQUARE_NB];
|
||||
extern Bitboard* BishopAttacks[SQUARE_NB];
|
||||
extern unsigned BishopShifts [SQUARE_NB];
|
||||
|
||||
extern Bitboard SquareBB[SQUARE_NB];
|
||||
extern Bitboard FileBB[FILE_NB];
|
||||
extern Bitboard RankBB[RANK_NB];
|
||||
extern Bitboard AdjacentFilesBB[FILE_NB];
|
||||
extern Bitboard InFrontBB[COLOR_NB][RANK_NB];
|
||||
extern Bitboard StepAttacksBB[PIECE_NB][SQUARE_NB];
|
||||
extern Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
|
||||
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
||||
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||
extern Bitboard DistanceRingBB[SQUARE_NB][8];
|
||||
extern Bitboard ForwardBB[COLOR_NB][SQUARE_NB];
|
||||
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 PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||
|
||||
|
||||
/// Magic holds all magic bitboards relevant data for a single square
|
||||
struct Magic {
|
||||
Bitboard mask;
|
||||
Bitboard magic;
|
||||
Bitboard* attacks;
|
||||
unsigned shift;
|
||||
|
||||
// Compute the attack's index using the 'magic bitboards' approach
|
||||
unsigned index(Bitboard occupied) const {
|
||||
|
||||
if (HasPext)
|
||||
return unsigned(pext(occupied, mask));
|
||||
|
||||
if (Is64Bit)
|
||||
return unsigned(((occupied & mask) * magic) >> shift);
|
||||
|
||||
unsigned lo = unsigned(occupied) & unsigned(mask);
|
||||
unsigned hi = unsigned(occupied >> 32) & unsigned(mask >> 32);
|
||||
return (lo * unsigned(magic) ^ hi * unsigned(magic >> 32)) >> shift;
|
||||
}
|
||||
};
|
||||
|
||||
extern Magic RookMagics[SQUARE_NB];
|
||||
extern Magic BishopMagics[SQUARE_NB];
|
||||
|
||||
|
||||
/// 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.
|
||||
|
||||
inline Bitboard operator&(Bitboard b, Square s) {
|
||||
assert(s >= SQ_A1 && s <= SQ_H8);
|
||||
return b & SquareBB[s];
|
||||
}
|
||||
|
||||
inline Bitboard operator|(Bitboard b, Square s) {
|
||||
assert(s >= SQ_A1 && s <= SQ_H8);
|
||||
return b | SquareBB[s];
|
||||
}
|
||||
|
||||
inline Bitboard operator^(Bitboard b, Square s) {
|
||||
assert(s >= SQ_A1 && s <= SQ_H8);
|
||||
return b ^ SquareBB[s];
|
||||
}
|
||||
|
||||
inline Bitboard& operator|=(Bitboard& b, Square s) {
|
||||
assert(s >= SQ_A1 && s <= SQ_H8);
|
||||
return b |= SquareBB[s];
|
||||
}
|
||||
|
||||
inline Bitboard& operator^=(Bitboard& b, Square s) {
|
||||
assert(s >= SQ_A1 && s <= SQ_H8);
|
||||
return b ^= SquareBB[s];
|
||||
}
|
||||
|
||||
inline bool more_than_one(Bitboard b) {
|
||||
constexpr bool more_than_one(Bitboard b) {
|
||||
return b & (b - 1);
|
||||
}
|
||||
|
||||
|
||||
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
||||
/// the given file or rank.
|
||||
|
||||
@@ -134,17 +155,28 @@ inline Bitboard file_bb(Square s) {
|
||||
}
|
||||
|
||||
|
||||
/// shift_bb() moves a bitboard one step along direction Delta. Mainly for pawns
|
||||
/// shift() moves a bitboard one step along direction D (mainly for pawns)
|
||||
|
||||
template<Square Delta>
|
||||
inline Bitboard shift_bb(Bitboard b) {
|
||||
return Delta == DELTA_N ? b << 8 : Delta == DELTA_S ? b >> 8
|
||||
: Delta == DELTA_NE ? (b & ~FileHBB) << 9 : Delta == DELTA_SE ? (b & ~FileHBB) >> 7
|
||||
: Delta == DELTA_NW ? (b & ~FileABB) << 7 : Delta == DELTA_SW ? (b & ~FileABB) >> 9
|
||||
template<Direction D>
|
||||
constexpr Bitboard shift(Bitboard b) {
|
||||
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
|
||||
: 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;
|
||||
}
|
||||
|
||||
|
||||
/// pawn_attacks_bb() returns the pawn attacks for 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);
|
||||
}
|
||||
|
||||
|
||||
/// adjacent_files_bb() returns a bitboard representing all the squares on the
|
||||
/// adjacent files of the given one.
|
||||
|
||||
@@ -163,28 +195,28 @@ inline Bitboard between_bb(Square s1, Square s2) {
|
||||
}
|
||||
|
||||
|
||||
/// in_front_bb() returns a bitboard representing all the squares on all the ranks
|
||||
/// in front of the given one, from the point of view of the given color. For
|
||||
/// instance, in_front_bb(BLACK, RANK_3) will return the squares on ranks 1 and 2.
|
||||
/// forward_ranks_bb() returns a bitboard representing the squares on all the ranks
|
||||
/// in front of the given one, from the point of view of the given color. For instance,
|
||||
/// forward_ranks_bb(BLACK, SQ_D3) will return the 16 squares on ranks 1 and 2.
|
||||
|
||||
inline Bitboard in_front_bb(Color c, Rank r) {
|
||||
return InFrontBB[c][r];
|
||||
inline Bitboard forward_ranks_bb(Color c, Square s) {
|
||||
return ForwardRanksBB[c][rank_of(s)];
|
||||
}
|
||||
|
||||
|
||||
/// forward_bb() returns a bitboard representing all the squares along the line
|
||||
/// forward_file_bb() returns a bitboard representing all the squares along the line
|
||||
/// in front of the given one, from the point of view of the given color:
|
||||
/// ForwardBB[c][s] = in_front_bb(c, s) & file_bb(s)
|
||||
/// ForwardFileBB[c][s] = forward_ranks_bb(c, s) & file_bb(s)
|
||||
|
||||
inline Bitboard forward_bb(Color c, Square s) {
|
||||
return ForwardBB[c][s];
|
||||
inline Bitboard forward_file_bb(Color c, Square s) {
|
||||
return ForwardFileBB[c][s];
|
||||
}
|
||||
|
||||
|
||||
/// pawn_attack_span() returns a bitboard representing all the squares that can be
|
||||
/// attacked by a pawn of the given color when it moves along its file, starting
|
||||
/// from the given square:
|
||||
/// PawnAttackSpan[c][s] = in_front_bb(c, s) & adjacent_files_bb(s);
|
||||
/// PawnAttackSpan[c][s] = forward_ranks_bb(c, s) & adjacent_files_bb(file_of(s));
|
||||
|
||||
inline Bitboard pawn_attack_span(Color c, Square s) {
|
||||
return PawnAttackSpan[c][s];
|
||||
@@ -193,21 +225,13 @@ inline Bitboard pawn_attack_span(Color c, Square s) {
|
||||
|
||||
/// passed_pawn_mask() returns a bitboard mask which can be used to test if a
|
||||
/// pawn of the given color and on the given square is a passed pawn:
|
||||
/// PassedPawnMask[c][s] = pawn_attack_span(c, s) | forward_bb(c, s)
|
||||
/// PassedPawnMask[c][s] = pawn_attack_span(c, s) | forward_file_bb(c, s)
|
||||
|
||||
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
||||
return PassedPawnMask[c][s];
|
||||
}
|
||||
|
||||
|
||||
/// squares_of_color() returns a bitboard representing all the squares of the
|
||||
/// same color of the given one.
|
||||
|
||||
inline Bitboard squares_of_color(Square s) {
|
||||
return DarkSquares & s ? DarkSquares : ~DarkSquares;
|
||||
}
|
||||
|
||||
|
||||
/// aligned() returns true if the squares s1, s2 and s3 are aligned either on a
|
||||
/// straight or on a diagonal line.
|
||||
|
||||
@@ -228,103 +252,123 @@ template<> inline int distance<Rank>(Square x, Square y) { return distance(rank_
|
||||
|
||||
|
||||
/// attacks_bb() returns a bitboard representing all the squares attacked by a
|
||||
/// piece of type Pt (bishop or rook) placed on 's'. The helper magic_index()
|
||||
/// looks up the index using the 'magic bitboards' approach.
|
||||
template<PieceType Pt>
|
||||
FORCE_INLINE unsigned magic_index(Square s, Bitboard occupied) {
|
||||
|
||||
Bitboard* const Masks = Pt == ROOK ? RookMasks : BishopMasks;
|
||||
Bitboard* const Magics = Pt == ROOK ? RookMagics : BishopMagics;
|
||||
unsigned* const Shifts = Pt == ROOK ? RookShifts : BishopShifts;
|
||||
|
||||
if (HasPext)
|
||||
return unsigned(pext(occupied, Masks[s]));
|
||||
|
||||
if (Is64Bit)
|
||||
return unsigned(((occupied & Masks[s]) * Magics[s]) >> Shifts[s]);
|
||||
|
||||
unsigned lo = unsigned(occupied) & unsigned(Masks[s]);
|
||||
unsigned hi = unsigned(occupied >> 32) & unsigned(Masks[s] >> 32);
|
||||
return (lo * unsigned(Magics[s]) ^ hi * unsigned(Magics[s] >> 32)) >> Shifts[s];
|
||||
}
|
||||
/// piece of type Pt (bishop or rook) placed on 's'.
|
||||
|
||||
template<PieceType Pt>
|
||||
inline Bitboard attacks_bb(Square s, Bitboard occupied) {
|
||||
return (Pt == ROOK ? RookAttacks : BishopAttacks)[s][magic_index<Pt>(s, occupied)];
|
||||
|
||||
const Magic& m = Pt == ROOK ? RookMagics[s] : BishopMagics[s];
|
||||
return m.attacks[m.index(occupied)];
|
||||
}
|
||||
|
||||
inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occupied) {
|
||||
inline Bitboard attacks_bb(PieceType pt, Square s, Bitboard occupied) {
|
||||
|
||||
switch (type_of(pc))
|
||||
assert(pt != PAWN);
|
||||
|
||||
switch (pt)
|
||||
{
|
||||
case BISHOP: return attacks_bb<BISHOP>(s, occupied);
|
||||
case ROOK : return attacks_bb<ROOK>(s, occupied);
|
||||
case ROOK : return attacks_bb< ROOK>(s, occupied);
|
||||
case QUEEN : return attacks_bb<BISHOP>(s, occupied) | attacks_bb<ROOK>(s, occupied);
|
||||
default : return StepAttacksBB[pc][s];
|
||||
default : return PseudoAttacks[pt][s];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// popcount() counts the number of non-zero bits in a bitboard
|
||||
|
||||
inline int popcount(Bitboard b) {
|
||||
|
||||
#ifndef USE_POPCNT
|
||||
|
||||
extern uint8_t PopCnt16[1 << 16];
|
||||
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]];
|
||||
|
||||
#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||
|
||||
return (int)_mm_popcnt_u64(b);
|
||||
|
||||
#else // Assumed gcc or compatible compiler
|
||||
|
||||
return __builtin_popcountll(b);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
|
||||
|
||||
#ifdef USE_BSFQ
|
||||
#if defined(__GNUC__) // GCC, Clang, ICC
|
||||
|
||||
# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
|
||||
inline Square lsb(Bitboard b) {
|
||||
assert(b);
|
||||
return Square(__builtin_ctzll(b));
|
||||
}
|
||||
|
||||
FORCE_INLINE Square lsb(Bitboard b) {
|
||||
inline Square msb(Bitboard b) {
|
||||
assert(b);
|
||||
return Square(63 ^ __builtin_clzll(b));
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER) // MSVC
|
||||
|
||||
#ifdef _WIN64 // MSVC, WIN64
|
||||
|
||||
inline Square lsb(Bitboard b) {
|
||||
assert(b);
|
||||
unsigned long idx;
|
||||
_BitScanForward64(&idx, b);
|
||||
return (Square) idx;
|
||||
}
|
||||
|
||||
FORCE_INLINE Square msb(Bitboard b) {
|
||||
inline Square msb(Bitboard b) {
|
||||
assert(b);
|
||||
unsigned long idx;
|
||||
_BitScanReverse64(&idx, b);
|
||||
return (Square) idx;
|
||||
}
|
||||
|
||||
# elif defined(__arm__)
|
||||
#else // MSVC, WIN32
|
||||
|
||||
FORCE_INLINE int lsb32(uint32_t v) {
|
||||
__asm__("rbit %0, %1" : "=r"(v) : "r"(v));
|
||||
return __builtin_clz(v);
|
||||
inline Square lsb(Bitboard b) {
|
||||
assert(b);
|
||||
unsigned long idx;
|
||||
|
||||
if (b & 0xffffffff) {
|
||||
_BitScanForward(&idx, int32_t(b));
|
||||
return Square(idx);
|
||||
} else {
|
||||
_BitScanForward(&idx, int32_t(b >> 32));
|
||||
return Square(idx + 32);
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE Square msb(Bitboard b) {
|
||||
return (Square) (63 - __builtin_clzll(b));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE Square lsb(Bitboard b) {
|
||||
return (Square) (uint32_t(b) ? lsb32(uint32_t(b)) : 32 + lsb32(uint32_t(b >> 32)));
|
||||
}
|
||||
#endif
|
||||
|
||||
# else // Assumed gcc or compatible compiler
|
||||
#else // Compiler is neither GCC nor MSVC compatible
|
||||
|
||||
FORCE_INLINE Square lsb(Bitboard b) { // Assembly code by Heinz van Saanen
|
||||
Bitboard idx;
|
||||
__asm__("bsfq %1, %0": "=r"(idx): "rm"(b) );
|
||||
return (Square) idx;
|
||||
}
|
||||
|
||||
FORCE_INLINE Square msb(Bitboard b) {
|
||||
Bitboard idx;
|
||||
__asm__("bsrq %1, %0": "=r"(idx): "rm"(b) );
|
||||
return (Square) idx;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
#else // ifdef(USE_BSFQ)
|
||||
|
||||
Square lsb(Bitboard b);
|
||||
Square msb(Bitboard b);
|
||||
#error "Compiler not supported."
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/// pop_lsb() finds and clears the least significant bit in a non-zero bitboard
|
||||
|
||||
FORCE_INLINE Square pop_lsb(Bitboard* b) {
|
||||
inline Square pop_lsb(Bitboard* b) {
|
||||
const Square s = lsb(*b);
|
||||
*b &= *b - 1;
|
||||
return s;
|
||||
|
||||
-105
@@ -1,105 +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
|
||||
|
||||
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 BITCOUNT_H_INCLUDED
|
||||
#define BITCOUNT_H_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
enum BitCountType {
|
||||
CNT_64,
|
||||
CNT_64_MAX15,
|
||||
CNT_32,
|
||||
CNT_32_MAX15,
|
||||
CNT_HW_POPCNT
|
||||
};
|
||||
|
||||
/// Determine at compile time the best popcount<> specialization according to
|
||||
/// whether the platform is 32 or 64 bit, the maximum number of non-zero
|
||||
/// bits to count and if the hardware popcnt instruction is available.
|
||||
const BitCountType Full = HasPopCnt ? CNT_HW_POPCNT : Is64Bit ? CNT_64 : CNT_32;
|
||||
const BitCountType Max15 = HasPopCnt ? CNT_HW_POPCNT : Is64Bit ? CNT_64_MAX15 : CNT_32_MAX15;
|
||||
|
||||
|
||||
/// popcount() counts the number of non-zero bits in a bitboard
|
||||
template<BitCountType> inline int popcount(Bitboard);
|
||||
|
||||
template<>
|
||||
inline int popcount<CNT_64>(Bitboard b) {
|
||||
b -= (b >> 1) & 0x5555555555555555ULL;
|
||||
b = ((b >> 2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
||||
b = ((b >> 4) + b) & 0x0F0F0F0F0F0F0F0FULL;
|
||||
return (b * 0x0101010101010101ULL) >> 56;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline int popcount<CNT_64_MAX15>(Bitboard b) {
|
||||
b -= (b >> 1) & 0x5555555555555555ULL;
|
||||
b = ((b >> 2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
||||
return (b * 0x1111111111111111ULL) >> 60;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline int popcount<CNT_32>(Bitboard b) {
|
||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
||||
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
||||
w -= (w >> 1) & 0x55555555;
|
||||
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
||||
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
||||
v = ((v >> 4) + v + (w >> 4) + w) & 0x0F0F0F0F;
|
||||
return (v * 0x01010101) >> 24;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline int popcount<CNT_32_MAX15>(Bitboard b) {
|
||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
||||
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
||||
w -= (w >> 1) & 0x55555555;
|
||||
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
||||
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
||||
return ((v + w) * 0x11111111) >> 28;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline int popcount<CNT_HW_POPCNT>(Bitboard b) {
|
||||
|
||||
#ifndef USE_POPCNT
|
||||
|
||||
assert(false);
|
||||
return b != 0; // Avoid 'b not used' warning
|
||||
|
||||
#elif defined(_MSC_VER) && defined(__INTEL_COMPILER)
|
||||
|
||||
return _mm_popcnt_u64(b);
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
return (int)__popcnt64(b);
|
||||
|
||||
#else // Assumed gcc or compatible compiler
|
||||
|
||||
return __builtin_popcountll(b);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // #ifndef BITCOUNT_H_INCLUDED
|
||||
+96
-182
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -21,7 +22,6 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "bitboard.h"
|
||||
#include "bitcount.h"
|
||||
#include "endgame.h"
|
||||
#include "movegen.h"
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace {
|
||||
|
||||
// Table used to drive the king towards the edge of the board
|
||||
// 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,
|
||||
90, 70, 60, 50, 50, 60, 70, 90,
|
||||
80, 60, 40, 30, 30, 40, 60, 80,
|
||||
@@ -39,12 +39,12 @@ namespace {
|
||||
70, 50, 30, 20, 20, 30, 50, 70,
|
||||
80, 60, 40, 30, 30, 40, 60, 80,
|
||||
90, 70, 60, 50, 50, 60, 70, 90,
|
||||
100, 90, 80, 70, 70, 80, 90, 100,
|
||||
100, 90, 80, 70, 70, 80, 90, 100
|
||||
};
|
||||
|
||||
// Table used to drive the king towards a corner square of the
|
||||
// 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,
|
||||
190, 180, 170, 160, 150, 140, 130, 140,
|
||||
180, 170, 155, 140, 140, 125, 140, 150,
|
||||
@@ -56,8 +56,11 @@ namespace {
|
||||
};
|
||||
|
||||
// Tables used to drive a piece towards or away from another piece
|
||||
const 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 PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
|
||||
constexpr int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
|
||||
|
||||
// Pawn Rank based scaling factors used in KRPPKRP endgame
|
||||
constexpr int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
|
||||
@@ -71,7 +74,7 @@ namespace {
|
||||
|
||||
assert(pos.count<PAWN>(strongSide) == 1);
|
||||
|
||||
if (file_of(pos.list<PAWN>(strongSide)[0]) >= FILE_E)
|
||||
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
|
||||
sq = Square(sq ^ 7); // Mirror SQ_H1 -> SQ_A1
|
||||
|
||||
if (strongSide == BLACK)
|
||||
@@ -80,68 +83,9 @@ namespace {
|
||||
return sq;
|
||||
}
|
||||
|
||||
// Get the material key of Position out of the given endgame key code
|
||||
// like "KBPKN". The trick here is to first forge an ad-hoc FEN string
|
||||
// and then let a Position object do the work for us.
|
||||
Key key(const string& code, Color c) {
|
||||
|
||||
assert(code.length() > 0 && code.length() < 8);
|
||||
assert(code[0] == 'K');
|
||||
|
||||
string sides[] = { code.substr(code.find('K', 1)), // Weak
|
||||
code.substr(0, code.find('K', 1)) }; // Strong
|
||||
|
||||
std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
|
||||
|
||||
string fen = sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
|
||||
+ sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";
|
||||
|
||||
return Position(fen, false, NULL).material_key();
|
||||
}
|
||||
|
||||
template<typename M>
|
||||
void delete_endgame(const typename M::value_type& p) { delete p.second; }
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
/// Endgames members definitions
|
||||
|
||||
Endgames::Endgames() {
|
||||
|
||||
add<KPK>("KPK");
|
||||
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<KNPKB>("KNPKB");
|
||||
add<KRPKR>("KRPKR");
|
||||
add<KRPKB>("KRPKB");
|
||||
add<KBPKB>("KBPKB");
|
||||
add<KBPKN>("KBPKN");
|
||||
add<KBPPKB>("KBPPKB");
|
||||
add<KRPPKRP>("KRPPKRP");
|
||||
}
|
||||
|
||||
Endgames::~Endgames() {
|
||||
|
||||
for_each(m1.begin(), m1.end(), delete_endgame<M1>);
|
||||
for_each(m2.begin(), m2.end(), delete_endgame<M2>);
|
||||
}
|
||||
|
||||
template<EndgameType E>
|
||||
void Endgames::add(const string& code) {
|
||||
|
||||
map((Endgame<E>*)0)[key(code, WHITE)] = new Endgame<E>(WHITE);
|
||||
map((Endgame<E>*)0)[key(code, BLACK)] = new Endgame<E>(BLACK);
|
||||
}
|
||||
|
||||
|
||||
/// Mate with KX vs K. This function is used to evaluate positions with
|
||||
/// king and plenty of material vs a lone king. It simply gives the
|
||||
/// attacking side a bonus for driving the defending king towards the edge
|
||||
@@ -156,8 +100,8 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
|
||||
if (pos.side_to_move() == weakSide && !MoveList<LEGAL>(pos).size())
|
||||
return VALUE_DRAW;
|
||||
|
||||
Square winnerKSq = pos.king_square(strongSide);
|
||||
Square loserKSq = pos.king_square(weakSide);
|
||||
Square winnerKSq = pos.square<KING>(strongSide);
|
||||
Square loserKSq = pos.square<KING>(weakSide);
|
||||
|
||||
Value result = pos.non_pawn_material(strongSide)
|
||||
+ pos.count<PAWN>(strongSide) * PawnValueEg
|
||||
@@ -167,9 +111,9 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
|
||||
if ( pos.count<QUEEN>(strongSide)
|
||||
|| pos.count<ROOK>(strongSide)
|
||||
||(pos.count<BISHOP>(strongSide) && pos.count<KNIGHT>(strongSide))
|
||||
||(pos.count<BISHOP>(strongSide) > 1 && opposite_colors(pos.list<BISHOP>(strongSide)[0],
|
||||
pos.list<BISHOP>(strongSide)[1])))
|
||||
result += VALUE_KNOWN_WIN;
|
||||
|| ( (pos.pieces(strongSide, BISHOP) & ~DarkSquares)
|
||||
&& (pos.pieces(strongSide, BISHOP) & DarkSquares)))
|
||||
result = std::min(result + VALUE_KNOWN_WIN, VALUE_MATE_IN_MAX_PLY - 1);
|
||||
|
||||
return strongSide == pos.side_to_move() ? result : -result;
|
||||
}
|
||||
@@ -183,9 +127,9 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, KnightValueMg + BishopValueMg, 0));
|
||||
assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
|
||||
|
||||
Square winnerKSq = pos.king_square(strongSide);
|
||||
Square loserKSq = pos.king_square(weakSide);
|
||||
Square bishopSq = pos.list<BISHOP>(strongSide)[0];
|
||||
Square winnerKSq = pos.square<KING>(strongSide);
|
||||
Square loserKSq = pos.square<KING>(weakSide);
|
||||
Square bishopSq = pos.square<BISHOP>(strongSide);
|
||||
|
||||
// kbnk_mate_table() tries to drive toward corners A1 or H8. If we have a
|
||||
// bishop that cannot reach the above squares, we flip the kings in order
|
||||
@@ -212,9 +156,9 @@ Value Endgame<KPK>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
|
||||
|
||||
// Assume strongSide is white and the pawn is on files A-D
|
||||
Square wksq = normalize(pos, strongSide, pos.king_square(strongSide));
|
||||
Square bksq = normalize(pos, strongSide, pos.king_square(weakSide));
|
||||
Square psq = normalize(pos, strongSide, pos.list<PAWN>(strongSide)[0]);
|
||||
Square wksq = normalize(pos, strongSide, pos.square<KING>(strongSide));
|
||||
Square bksq = normalize(pos, strongSide, pos.square<KING>(weakSide));
|
||||
Square psq = normalize(pos, strongSide, pos.square<PAWN>(strongSide));
|
||||
|
||||
Color us = strongSide == pos.side_to_move() ? WHITE : BLACK;
|
||||
|
||||
@@ -237,16 +181,16 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, RookValueMg, 0));
|
||||
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
|
||||
|
||||
Square wksq = relative_square(strongSide, pos.king_square(strongSide));
|
||||
Square bksq = relative_square(strongSide, pos.king_square(weakSide));
|
||||
Square rsq = relative_square(strongSide, pos.list<ROOK>(strongSide)[0]);
|
||||
Square psq = relative_square(strongSide, pos.list<PAWN>(weakSide)[0]);
|
||||
Square wksq = relative_square(strongSide, pos.square<KING>(strongSide));
|
||||
Square bksq = relative_square(strongSide, pos.square<KING>(weakSide));
|
||||
Square rsq = relative_square(strongSide, pos.square<ROOK>(strongSide));
|
||||
Square psq = relative_square(strongSide, pos.square<PAWN>(weakSide));
|
||||
|
||||
Square queeningSq = make_square(file_of(psq), RANK_1);
|
||||
Value result;
|
||||
|
||||
// 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);
|
||||
|
||||
// If the weaker side's king is too far from the pawn and the rook,
|
||||
@@ -264,15 +208,15 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
||||
result = Value(80) - 8 * distance(wksq, psq);
|
||||
|
||||
else
|
||||
result = Value(200) - 8 * ( distance(wksq, psq + DELTA_S)
|
||||
- distance(bksq, psq + DELTA_S)
|
||||
result = Value(200) - 8 * ( distance(wksq, psq + SOUTH)
|
||||
- distance(bksq, psq + SOUTH)
|
||||
- distance(psq, queeningSq));
|
||||
|
||||
return strongSide == pos.side_to_move() ? result : -result;
|
||||
}
|
||||
|
||||
|
||||
/// 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.
|
||||
template<>
|
||||
Value Endgame<KRKB>::operator()(const Position& pos) const {
|
||||
@@ -280,7 +224,7 @@ Value Endgame<KRKB>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, RookValueMg, 0));
|
||||
assert(verify_material(pos, weakSide, BishopValueMg, 0));
|
||||
|
||||
Value result = Value(PushToEdges[pos.king_square(weakSide)]);
|
||||
Value result = Value(PushToEdges[pos.square<KING>(weakSide)]);
|
||||
return strongSide == pos.side_to_move() ? result : -result;
|
||||
}
|
||||
|
||||
@@ -293,8 +237,8 @@ Value Endgame<KRKN>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, RookValueMg, 0));
|
||||
assert(verify_material(pos, weakSide, KnightValueMg, 0));
|
||||
|
||||
Square bksq = pos.king_square(weakSide);
|
||||
Square bnsq = pos.list<KNIGHT>(weakSide)[0];
|
||||
Square bksq = pos.square<KING>(weakSide);
|
||||
Square bnsq = pos.square<KNIGHT>(weakSide);
|
||||
Value result = Value(PushToEdges[bksq] + PushAway[distance(bksq, bnsq)]);
|
||||
return strongSide == pos.side_to_move() ? result : -result;
|
||||
}
|
||||
@@ -310,9 +254,9 @@ Value Endgame<KQKP>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, QueenValueMg, 0));
|
||||
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
|
||||
|
||||
Square winnerKSq = pos.king_square(strongSide);
|
||||
Square loserKSq = pos.king_square(weakSide);
|
||||
Square pawnSq = pos.list<PAWN>(weakSide)[0];
|
||||
Square winnerKSq = pos.square<KING>(strongSide);
|
||||
Square loserKSq = pos.square<KING>(weakSide);
|
||||
Square pawnSq = pos.square<PAWN>(weakSide);
|
||||
|
||||
Value result = Value(PushClose[distance(winnerKSq, loserKSq)]);
|
||||
|
||||
@@ -335,8 +279,8 @@ Value Endgame<KQKR>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, QueenValueMg, 0));
|
||||
assert(verify_material(pos, weakSide, RookValueMg, 0));
|
||||
|
||||
Square winnerKSq = pos.king_square(strongSide);
|
||||
Square loserKSq = pos.king_square(weakSide);
|
||||
Square winnerKSq = pos.square<KING>(strongSide);
|
||||
Square loserKSq = pos.square<KING>(weakSide);
|
||||
|
||||
Value result = QueenValueEg
|
||||
- RookValueEg
|
||||
@@ -365,15 +309,15 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
|
||||
// be detected even when the weaker side has some pawns.
|
||||
|
||||
Bitboard pawns = pos.pieces(strongSide, PAWN);
|
||||
File pawnFile = file_of(pos.list<PAWN>(strongSide)[0]);
|
||||
File pawnsFile = file_of(lsb(pawns));
|
||||
|
||||
// All pawns are on a single rook file ?
|
||||
if ( (pawnFile == FILE_A || pawnFile == FILE_H)
|
||||
&& !(pawns & ~file_bb(pawnFile)))
|
||||
// All pawns are on a single rook file?
|
||||
if ( (pawnsFile == FILE_A || pawnsFile == FILE_H)
|
||||
&& !(pawns & ~file_bb(pawnsFile)))
|
||||
{
|
||||
Square bishopSq = pos.list<BISHOP>(strongSide)[0];
|
||||
Square queeningSq = relative_square(strongSide, make_square(pawnFile, RANK_8));
|
||||
Square kingSq = pos.king_square(weakSide);
|
||||
Square bishopSq = pos.square<BISHOP>(strongSide);
|
||||
Square queeningSq = relative_square(strongSide, make_square(pawnsFile, RANK_8));
|
||||
Square kingSq = pos.square<KING>(weakSide);
|
||||
|
||||
if ( opposite_colors(queeningSq, bishopSq)
|
||||
&& distance(queeningSq, kingSq) <= 1)
|
||||
@@ -381,17 +325,17 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
|
||||
}
|
||||
|
||||
// If all the pawns are on the same B or G file, then it's potentially a draw
|
||||
if ( (pawnFile == FILE_B || pawnFile == FILE_G)
|
||||
&& !(pos.pieces(PAWN) & ~file_bb(pawnFile))
|
||||
if ( (pawnsFile == FILE_B || pawnsFile == FILE_G)
|
||||
&& !(pos.pieces(PAWN) & ~file_bb(pawnsFile))
|
||||
&& pos.non_pawn_material(weakSide) == 0
|
||||
&& pos.count<PAWN>(weakSide) >= 1)
|
||||
{
|
||||
// Get weakSide pawn that is closest to the home rank
|
||||
Square weakPawnSq = backmost_sq(weakSide, pos.pieces(weakSide, PAWN));
|
||||
|
||||
Square strongKingSq = pos.king_square(strongSide);
|
||||
Square weakKingSq = pos.king_square(weakSide);
|
||||
Square bishopSq = pos.list<BISHOP>(strongSide)[0];
|
||||
Square strongKingSq = pos.square<KING>(strongSide);
|
||||
Square weakKingSq = pos.square<KING>(weakSide);
|
||||
Square bishopSq = pos.square<BISHOP>(strongSide);
|
||||
|
||||
// There's potential for a draw if our pawn is blocked on the 7th rank,
|
||||
// the bishop cannot attack it or they only have one pawn left
|
||||
@@ -428,11 +372,11 @@ ScaleFactor Endgame<KQKRPs>::operator()(const Position& pos) const {
|
||||
assert(pos.count<ROOK>(weakSide) == 1);
|
||||
assert(pos.count<PAWN>(weakSide) >= 1);
|
||||
|
||||
Square kingSq = pos.king_square(weakSide);
|
||||
Square rsq = pos.list<ROOK>(weakSide)[0];
|
||||
Square kingSq = pos.square<KING>(weakSide);
|
||||
Square rsq = pos.square<ROOK>(weakSide);
|
||||
|
||||
if ( relative_rank(weakSide, kingSq) <= RANK_2
|
||||
&& relative_rank(weakSide, pos.king_square(strongSide)) >= RANK_4
|
||||
&& relative_rank(weakSide, pos.square<KING>(strongSide)) >= RANK_4
|
||||
&& relative_rank(weakSide, rsq) == RANK_3
|
||||
&& ( pos.pieces(weakSide, PAWN)
|
||||
& pos.attacks_from<KING>(kingSq)
|
||||
@@ -456,11 +400,11 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, weakSide, RookValueMg, 0));
|
||||
|
||||
// Assume strongSide is white and the pawn is on files A-D
|
||||
Square wksq = normalize(pos, strongSide, pos.king_square(strongSide));
|
||||
Square bksq = normalize(pos, strongSide, pos.king_square(weakSide));
|
||||
Square wrsq = normalize(pos, strongSide, pos.list<ROOK>(strongSide)[0]);
|
||||
Square wpsq = normalize(pos, strongSide, pos.list<PAWN>(strongSide)[0]);
|
||||
Square brsq = normalize(pos, strongSide, pos.list<ROOK>(weakSide)[0]);
|
||||
Square wksq = normalize(pos, strongSide, pos.square<KING>(strongSide));
|
||||
Square bksq = normalize(pos, strongSide, pos.square<KING>(weakSide));
|
||||
Square wrsq = normalize(pos, strongSide, pos.square<ROOK>(strongSide));
|
||||
Square wpsq = normalize(pos, strongSide, pos.square<PAWN>(strongSide));
|
||||
Square brsq = normalize(pos, strongSide, pos.square<ROOK>(weakSide));
|
||||
|
||||
File f = file_of(wpsq);
|
||||
Rank r = rank_of(wpsq);
|
||||
@@ -480,7 +424,7 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
|
||||
if ( r == RANK_6
|
||||
&& distance(bksq, queeningSq) <= 1
|
||||
&& rank_of(wksq) + tempo <= RANK_6
|
||||
&& (rank_of(brsq) == RANK_1 || (!tempo && distance(file_of(brsq), f) >= 3)))
|
||||
&& (rank_of(brsq) == RANK_1 || (!tempo && distance<File>(brsq, wpsq) >= 3)))
|
||||
return SCALE_FACTOR_DRAW;
|
||||
|
||||
if ( r >= RANK_6
|
||||
@@ -501,7 +445,7 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
|
||||
// If the defending king blocks the pawn and the attacking king is too far
|
||||
// away, it's a draw.
|
||||
if ( r <= RANK_5
|
||||
&& bksq == wpsq + DELTA_N
|
||||
&& bksq == wpsq + NORTH
|
||||
&& distance(wksq, wpsq) - tempo >= 2
|
||||
&& distance(wksq, brsq) - tempo >= 2)
|
||||
return SCALE_FACTOR_DRAW;
|
||||
@@ -522,10 +466,10 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
|
||||
&& file_of(wrsq) == f
|
||||
&& wrsq < wpsq
|
||||
&& (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo)
|
||||
&& (distance(wksq, wpsq + DELTA_N) < distance(bksq, wpsq + DELTA_N) - 2 + tempo)
|
||||
&& (distance(wksq, wpsq + NORTH) < distance(bksq, wpsq + NORTH) - 2 + tempo)
|
||||
&& ( distance(bksq, wrsq) + tempo >= 3
|
||||
|| ( distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo
|
||||
&& (distance(wksq, wpsq + DELTA_N) < distance(bksq, wrsq) + tempo))))
|
||||
&& (distance(wksq, wpsq + NORTH) < distance(bksq, wrsq) + tempo))))
|
||||
return ScaleFactor( SCALE_FACTOR_MAX
|
||||
- 8 * distance(wpsq, queeningSq)
|
||||
- 2 * distance(wksq, queeningSq));
|
||||
@@ -552,11 +496,11 @@ ScaleFactor Endgame<KRPKB>::operator()(const Position& pos) const {
|
||||
// Test for a rook pawn
|
||||
if (pos.pieces(PAWN) & (FileABB | FileHBB))
|
||||
{
|
||||
Square ksq = pos.king_square(weakSide);
|
||||
Square bsq = pos.list<BISHOP>(weakSide)[0];
|
||||
Square psq = pos.list<PAWN>(strongSide)[0];
|
||||
Square ksq = pos.square<KING>(weakSide);
|
||||
Square bsq = pos.square<BISHOP>(weakSide);
|
||||
Square psq = pos.square<PAWN>(strongSide);
|
||||
Rank rk = relative_rank(strongSide, psq);
|
||||
Square push = pawn_push(strongSide);
|
||||
Direction push = pawn_push(strongSide);
|
||||
|
||||
// If the pawn is on the 5th rank and the pawn (currently) is on
|
||||
// the same color square as the bishop then there is a chance of
|
||||
@@ -567,7 +511,7 @@ ScaleFactor Endgame<KRPKB>::operator()(const Position& pos) const {
|
||||
{
|
||||
int d = distance(psq + 3 * push, ksq);
|
||||
|
||||
if (d <= 2 && !(d == 0 && ksq == pos.king_square(strongSide) + 2 * push))
|
||||
if (d <= 2 && !(d == 0 && ksq == pos.square<KING>(strongSide) + 2 * push))
|
||||
return ScaleFactor(24);
|
||||
else
|
||||
return ScaleFactor(48);
|
||||
@@ -595,9 +539,9 @@ ScaleFactor Endgame<KRPPKRP>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, RookValueMg, 2));
|
||||
assert(verify_material(pos, weakSide, RookValueMg, 1));
|
||||
|
||||
Square wpsq1 = pos.list<PAWN>(strongSide)[0];
|
||||
Square wpsq2 = pos.list<PAWN>(strongSide)[1];
|
||||
Square bksq = pos.king_square(weakSide);
|
||||
Square wpsq1 = pos.squares<PAWN>(strongSide)[0];
|
||||
Square wpsq2 = pos.squares<PAWN>(strongSide)[1];
|
||||
Square bksq = pos.square<KING>(weakSide);
|
||||
|
||||
// Does the stronger side have a passed pawn?
|
||||
if (pos.pawn_passed(strongSide, wpsq1) || pos.pawn_passed(strongSide, wpsq2))
|
||||
@@ -609,14 +553,8 @@ ScaleFactor Endgame<KRPPKRP>::operator()(const Position& pos) const {
|
||||
&& distance<File>(bksq, wpsq2) <= 1
|
||||
&& relative_rank(strongSide, bksq) > r)
|
||||
{
|
||||
switch (r) {
|
||||
case RANK_2: return ScaleFactor(10);
|
||||
case RANK_3: return ScaleFactor(10);
|
||||
case RANK_4: return ScaleFactor(15);
|
||||
case RANK_5: return ScaleFactor(20);
|
||||
case RANK_6: return ScaleFactor(40);
|
||||
default: assert(false);
|
||||
}
|
||||
assert(r > RANK_1 && r < RANK_7);
|
||||
return ScaleFactor(KRPPKRPScaleFactors[r]);
|
||||
}
|
||||
return SCALE_FACTOR_NONE;
|
||||
}
|
||||
@@ -631,15 +569,14 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
|
||||
assert(pos.count<PAWN>(strongSide) >= 2);
|
||||
assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
|
||||
|
||||
Square ksq = pos.king_square(weakSide);
|
||||
Square ksq = pos.square<KING>(weakSide);
|
||||
Bitboard pawns = pos.pieces(strongSide, PAWN);
|
||||
Square psq = pos.list<PAWN>(strongSide)[0];
|
||||
|
||||
// If all pawns are ahead of the king, on a single rook file and
|
||||
// the king is within one file of the pawns, it's a draw.
|
||||
if ( !(pawns & ~in_front_bb(weakSide, rank_of(ksq)))
|
||||
if ( !(pawns & ~forward_ranks_bb(weakSide, ksq))
|
||||
&& !((pawns & ~FileABB) && (pawns & ~FileHBB))
|
||||
&& distance<File>(ksq, psq) <= 1)
|
||||
&& distance<File>(ksq, lsb(pawns)) <= 1)
|
||||
return SCALE_FACTOR_DRAW;
|
||||
|
||||
return SCALE_FACTOR_NONE;
|
||||
@@ -656,10 +593,10 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, BishopValueMg, 1));
|
||||
assert(verify_material(pos, weakSide, BishopValueMg, 0));
|
||||
|
||||
Square pawnSq = pos.list<PAWN>(strongSide)[0];
|
||||
Square strongBishopSq = pos.list<BISHOP>(strongSide)[0];
|
||||
Square weakBishopSq = pos.list<BISHOP>(weakSide)[0];
|
||||
Square weakKingSq = pos.king_square(weakSide);
|
||||
Square pawnSq = pos.square<PAWN>(strongSide);
|
||||
Square strongBishopSq = pos.square<BISHOP>(strongSide);
|
||||
Square weakBishopSq = pos.square<BISHOP>(weakSide);
|
||||
Square weakKingSq = pos.square<KING>(weakSide);
|
||||
|
||||
// Case 1: Defending king blocks the pawn, and cannot be driven away
|
||||
if ( file_of(weakKingSq) == file_of(pawnSq)
|
||||
@@ -670,31 +607,8 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
|
||||
|
||||
// Case 2: Opposite colored bishops
|
||||
if (opposite_colors(strongBishopSq, weakBishopSq))
|
||||
{
|
||||
// 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.
|
||||
return SCALE_FACTOR_DRAW;
|
||||
|
||||
if (relative_rank(strongSide, pawnSq) <= RANK_5)
|
||||
return SCALE_FACTOR_DRAW;
|
||||
else
|
||||
{
|
||||
Bitboard path = forward_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;
|
||||
}
|
||||
|
||||
@@ -706,15 +620,15 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, BishopValueMg, 2));
|
||||
assert(verify_material(pos, weakSide, BishopValueMg, 0));
|
||||
|
||||
Square wbsq = pos.list<BISHOP>(strongSide)[0];
|
||||
Square bbsq = pos.list<BISHOP>(weakSide)[0];
|
||||
Square wbsq = pos.square<BISHOP>(strongSide);
|
||||
Square bbsq = pos.square<BISHOP>(weakSide);
|
||||
|
||||
if (!opposite_colors(wbsq, bbsq))
|
||||
return SCALE_FACTOR_NONE;
|
||||
|
||||
Square ksq = pos.king_square(weakSide);
|
||||
Square psq1 = pos.list<PAWN>(strongSide)[0];
|
||||
Square psq2 = pos.list<PAWN>(strongSide)[1];
|
||||
Square ksq = pos.square<KING>(weakSide);
|
||||
Square psq1 = pos.squares<PAWN>(strongSide)[0];
|
||||
Square psq2 = pos.squares<PAWN>(strongSide)[1];
|
||||
Rank r1 = rank_of(psq1);
|
||||
Rank r2 = rank_of(psq2);
|
||||
Square blockSq1, blockSq2;
|
||||
@@ -777,9 +691,9 @@ ScaleFactor Endgame<KBPKN>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, strongSide, BishopValueMg, 1));
|
||||
assert(verify_material(pos, weakSide, KnightValueMg, 0));
|
||||
|
||||
Square pawnSq = pos.list<PAWN>(strongSide)[0];
|
||||
Square strongBishopSq = pos.list<BISHOP>(strongSide)[0];
|
||||
Square weakKingSq = pos.king_square(weakSide);
|
||||
Square pawnSq = pos.square<PAWN>(strongSide);
|
||||
Square strongBishopSq = pos.square<BISHOP>(strongSide);
|
||||
Square weakKingSq = pos.square<KING>(weakSide);
|
||||
|
||||
if ( file_of(weakKingSq) == file_of(pawnSq)
|
||||
&& relative_rank(strongSide, pawnSq) < relative_rank(strongSide, weakKingSq)
|
||||
@@ -800,8 +714,8 @@ ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
|
||||
|
||||
// Assume strongSide is white and the pawn is on files A-D
|
||||
Square pawnSq = normalize(pos, strongSide, pos.list<PAWN>(strongSide)[0]);
|
||||
Square weakKingSq = normalize(pos, strongSide, pos.king_square(weakSide));
|
||||
Square pawnSq = normalize(pos, strongSide, pos.square<PAWN>(strongSide));
|
||||
Square weakKingSq = normalize(pos, strongSide, pos.square<KING>(weakSide));
|
||||
|
||||
if (pawnSq == SQ_A7 && distance(SQ_A8, weakKingSq) <= 1)
|
||||
return SCALE_FACTOR_DRAW;
|
||||
@@ -815,13 +729,13 @@ ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
|
||||
template<>
|
||||
ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
|
||||
|
||||
Square pawnSq = pos.list<PAWN>(strongSide)[0];
|
||||
Square bishopSq = pos.list<BISHOP>(weakSide)[0];
|
||||
Square weakKingSq = pos.king_square(weakSide);
|
||||
Square pawnSq = pos.square<PAWN>(strongSide);
|
||||
Square bishopSq = pos.square<BISHOP>(weakSide);
|
||||
Square weakKingSq = pos.square<KING>(weakSide);
|
||||
|
||||
// King needs to get close to promoting pawn to prevent knight from blocking.
|
||||
// Rules for this are very tricky, so just approximate.
|
||||
if (forward_bb(strongSide, pawnSq) & pos.attacks_from<BISHOP>(bishopSq))
|
||||
if (forward_file_bb(strongSide, pawnSq) & pos.attacks_from<BISHOP>(bishopSq))
|
||||
return ScaleFactor(distance(weakKingSq, pawnSq));
|
||||
|
||||
return SCALE_FACTOR_NONE;
|
||||
@@ -840,9 +754,9 @@ ScaleFactor Endgame<KPKP>::operator()(const Position& pos) const {
|
||||
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
|
||||
|
||||
// Assume strongSide is white and the pawn is on files A-D
|
||||
Square wksq = normalize(pos, strongSide, pos.king_square(strongSide));
|
||||
Square bksq = normalize(pos, strongSide, pos.king_square(weakSide));
|
||||
Square psq = normalize(pos, strongSide, pos.list<PAWN>(strongSide)[0]);
|
||||
Square wksq = normalize(pos, strongSide, pos.square<KING>(strongSide));
|
||||
Square bksq = normalize(pos, strongSide, pos.square<KING>(weakSide));
|
||||
Square psq = normalize(pos, strongSide, pos.square<PAWN>(strongSide));
|
||||
|
||||
Color us = strongSide == pos.side_to_move() ? WHITE : BLACK;
|
||||
|
||||
|
||||
+55
-32
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -21,18 +22,20 @@
|
||||
#define ENDGAME_H_INCLUDED
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "position.h"
|
||||
#include "types.h"
|
||||
|
||||
|
||||
/// EndgameType lists all supported endgames
|
||||
/// EndgameCode lists all supported endgame functions by corresponding codes
|
||||
|
||||
enum EndgameType {
|
||||
|
||||
// Evaluation functions
|
||||
enum EndgameCode {
|
||||
|
||||
EVALUATION_FUNCTIONS,
|
||||
KNNK, // KNN vs K
|
||||
KXK, // Generic "mate lone king" eval
|
||||
KBNK, // KBN vs K
|
||||
@@ -43,10 +46,7 @@ enum EndgameType {
|
||||
KQKP, // KQ vs KP
|
||||
KQKR, // KQ vs KR
|
||||
|
||||
|
||||
// Scaling functions
|
||||
SCALING_FUNCTIONS,
|
||||
|
||||
KBPsK, // KB and pawns vs K
|
||||
KQKRPs, // KQ vs KR and pawns
|
||||
KRPKR, // KRP vs KR
|
||||
@@ -63,33 +63,30 @@ enum EndgameType {
|
||||
|
||||
|
||||
/// Endgame functions can be of two types depending on whether they return a
|
||||
/// Value or a ScaleFactor. Type eg_fun<int>::type returns either ScaleFactor
|
||||
/// or Value depending on whether the template parameter is 0 or 1.
|
||||
/// Value or a ScaleFactor.
|
||||
|
||||
template<int> struct eg_fun { typedef Value type; };
|
||||
template<> struct eg_fun<1> { typedef ScaleFactor type; };
|
||||
template<EndgameCode E> using
|
||||
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
||||
|
||||
|
||||
/// Base and derived templates for endgame evaluation and scaling functions
|
||||
/// Base and derived functors for endgame evaluation and scaling functions
|
||||
|
||||
template<typename T>
|
||||
struct EndgameBase {
|
||||
|
||||
virtual ~EndgameBase() {}
|
||||
virtual Color strong_side() const = 0;
|
||||
explicit EndgameBase(Color c) : strongSide(c), weakSide(~c) {}
|
||||
virtual ~EndgameBase() = default;
|
||||
virtual T operator()(const Position&) const = 0;
|
||||
|
||||
const Color strongSide, weakSide;
|
||||
};
|
||||
|
||||
|
||||
template<EndgameType E, typename T = typename eg_fun<(E > SCALING_FUNCTIONS)>::type>
|
||||
template<EndgameCode E, typename T = eg_type<E>>
|
||||
struct Endgame : public EndgameBase<T> {
|
||||
|
||||
explicit Endgame(Color c) : strongSide(c), weakSide(~c) {}
|
||||
Color strong_side() const { return strongSide; }
|
||||
T operator()(const Position&) const;
|
||||
|
||||
private:
|
||||
Color strongSide, weakSide;
|
||||
explicit Endgame(Color c) : EndgameBase<T>(c) {}
|
||||
T operator()(const Position&) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -99,23 +96,49 @@ private:
|
||||
|
||||
class Endgames {
|
||||
|
||||
typedef std::map<Key, EndgameBase<eg_fun<0>::type>*> M1;
|
||||
typedef std::map<Key, EndgameBase<eg_fun<1>::type>*> M2;
|
||||
template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
|
||||
template<typename T> using Map = std::map<Key, Ptr<T>>;
|
||||
|
||||
M1 m1;
|
||||
M2 m2;
|
||||
template<typename T>
|
||||
Map<T>& map() {
|
||||
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
||||
}
|
||||
|
||||
M1& map(M1::mapped_type) { return m1; }
|
||||
M2& map(M2::mapped_type) { return m2; }
|
||||
template<EndgameCode E, typename T = eg_type<E>>
|
||||
void add(const std::string& code) {
|
||||
|
||||
template<EndgameType E> void add(const std::string& code);
|
||||
StateInfo st;
|
||||
map<T>()[Position().set(code, WHITE, &st).material_key()] = Ptr<T>(new Endgame<E>(WHITE));
|
||||
map<T>()[Position().set(code, BLACK, &st).material_key()] = Ptr<T>(new Endgame<E>(BLACK));
|
||||
}
|
||||
|
||||
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||
|
||||
public:
|
||||
Endgames();
|
||||
~Endgames();
|
||||
Endgames() {
|
||||
|
||||
template<typename T> T probe(Key key, T& eg) {
|
||||
return eg = map(eg).count(key) ? map(eg)[key] : NULL;
|
||||
add<KPK>("KPK");
|
||||
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<KNPKB>("KNPKB");
|
||||
add<KRPKR>("KRPKR");
|
||||
add<KRPKB>("KRPKB");
|
||||
add<KBPKB>("KBPKB");
|
||||
add<KBPKN>("KBPKN");
|
||||
add<KBPPKB>("KBPPKB");
|
||||
add<KRPPKRP>("KRPPKRP");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const EndgameBase<T>* probe(Key key) {
|
||||
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+659
-645
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -28,12 +29,11 @@ class Position;
|
||||
|
||||
namespace Eval {
|
||||
|
||||
const Value Tempo = Value(17); // Must be visible to search
|
||||
constexpr Value Tempo = Value(20); // Must be visible to search
|
||||
|
||||
void init();
|
||||
Value evaluate(const Position& pos);
|
||||
std::string trace(const Position& pos);
|
||||
|
||||
Value evaluate(const Position& pos);
|
||||
}
|
||||
|
||||
#endif // #ifndef EVALUATE_H_INCLUDED
|
||||
|
||||
+10
-6
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -20,7 +21,6 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "bitboard.h"
|
||||
#include "evaluate.h"
|
||||
#include "position.h"
|
||||
#include "search.h"
|
||||
#include "thread.h"
|
||||
@@ -28,22 +28,26 @@
|
||||
#include "uci.h"
|
||||
#include "syzygy/tbprobe.h"
|
||||
|
||||
namespace PSQT {
|
||||
void init();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
std::cout << engine_info() << std::endl;
|
||||
|
||||
UCI::init(Options);
|
||||
PSQT::init();
|
||||
Bitboards::init();
|
||||
Position::init();
|
||||
Bitbases::init();
|
||||
Search::init();
|
||||
Eval::init();
|
||||
Pawns::init();
|
||||
Threads.init();
|
||||
Tablebases::init(Options["SyzygyPath"]);
|
||||
TT.resize(Options["Hash"]);
|
||||
Threads.set(Options["Threads"]);
|
||||
Search::clear(); // After threads are up
|
||||
|
||||
UCI::loop(argc, argv);
|
||||
|
||||
Threads.exit();
|
||||
Threads.set(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+59
-75
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -30,29 +31,26 @@ namespace {
|
||||
|
||||
// Polynomial material imbalance parameters
|
||||
|
||||
// pair pawn knight bishop rook queen
|
||||
const int Linear[6] = { 1852, -162, -1122, -183, 249, -154 };
|
||||
|
||||
const int QuadraticOurs[][PIECE_TYPE_NB] = {
|
||||
constexpr int QuadraticOurs[][PIECE_TYPE_NB] = {
|
||||
// OUR PIECES
|
||||
// pair pawn knight bishop rook queen
|
||||
{ 0 }, // Bishop pair
|
||||
{ 39, 2 }, // Pawn
|
||||
{ 35, 271, -4 }, // Knight OUR PIECES
|
||||
{ 0, 105, 4, 0 }, // Bishop
|
||||
{ -27, -2, 46, 100, -141 }, // Rook
|
||||
{-177, 25, 129, 142, -137, 0 } // Queen
|
||||
{1438 }, // Bishop pair
|
||||
{ 40, 38 }, // Pawn
|
||||
{ 32, 255, -62 }, // Knight OUR PIECES
|
||||
{ 0, 104, 4, 0 }, // Bishop
|
||||
{ -26, -2, 47, 105, -208 }, // Rook
|
||||
{-189, 24, 117, 133, -134, -6 } // Queen
|
||||
};
|
||||
|
||||
const int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
||||
constexpr int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
||||
// THEIR PIECES
|
||||
// pair pawn knight bishop rook queen
|
||||
{ 0 }, // Bishop pair
|
||||
{ 37, 0 }, // Pawn
|
||||
{ 10, 62, 0 }, // Knight OUR PIECES
|
||||
{ 57, 64, 39, 0 }, // Bishop
|
||||
{ 50, 40, 23, -22, 0 }, // Rook
|
||||
{ 98, 105, -39, 141, 274, 0 } // Queen
|
||||
{ 36, 0 }, // Pawn
|
||||
{ 9, 63, 0 }, // Knight OUR PIECES
|
||||
{ 59, 65, 42, 0 }, // Bishop
|
||||
{ 46, 39, 24, -24, 0 }, // Rook
|
||||
{ 97, 100, -42, 137, 268, 0 } // Queen
|
||||
};
|
||||
|
||||
// Endgame evaluation and scaling functions are accessed directly and not through
|
||||
@@ -64,45 +62,42 @@ namespace {
|
||||
Endgame<KPsK> ScaleKPsK[] = { Endgame<KPsK>(WHITE), Endgame<KPsK>(BLACK) };
|
||||
Endgame<KPKP> ScaleKPKP[] = { Endgame<KPKP>(WHITE), Endgame<KPKP>(BLACK) };
|
||||
|
||||
// Helper templates used to detect a given material distribution
|
||||
template<Color Us> bool is_KXK(const Position& pos) {
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
return !more_than_one(pos.pieces(Them))
|
||||
&& pos.non_pawn_material(Us) >= RookValueMg;
|
||||
// Helper used to detect a given material distribution
|
||||
bool is_KXK(const Position& pos, Color us) {
|
||||
return !more_than_one(pos.pieces(~us))
|
||||
&& pos.non_pawn_material(us) >= RookValueMg;
|
||||
}
|
||||
|
||||
template<Color Us> bool is_KBPsKs(const Position& pos) {
|
||||
return pos.non_pawn_material(Us) == BishopValueMg
|
||||
&& pos.count<BISHOP>(Us) == 1
|
||||
&& pos.count<PAWN >(Us) >= 1;
|
||||
bool is_KBPsK(const Position& pos, Color us) {
|
||||
return pos.non_pawn_material(us) == BishopValueMg
|
||||
&& pos.count<BISHOP>(us) == 1
|
||||
&& pos.count<PAWN >(us) >= 1;
|
||||
}
|
||||
|
||||
template<Color Us> bool is_KQKRPs(const Position& pos) {
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
return !pos.count<PAWN>(Us)
|
||||
&& pos.non_pawn_material(Us) == QueenValueMg
|
||||
&& pos.count<QUEEN>(Us) == 1
|
||||
&& pos.count<ROOK>(Them) == 1
|
||||
&& pos.count<PAWN>(Them) >= 1;
|
||||
bool is_KQKRPs(const Position& pos, Color us) {
|
||||
return !pos.count<PAWN>(us)
|
||||
&& pos.non_pawn_material(us) == QueenValueMg
|
||||
&& pos.count<QUEEN>(us) == 1
|
||||
&& pos.count<ROOK>(~us) == 1
|
||||
&& pos.count<PAWN>(~us) >= 1;
|
||||
}
|
||||
|
||||
/// imbalance() calculates the imbalance by comparing the piece count of each
|
||||
/// piece type for both colors.
|
||||
|
||||
template<Color Us>
|
||||
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;
|
||||
|
||||
// Second-degree polynomial material imbalance by Tord Romstad
|
||||
// Second-degree polynomial material imbalance, by Tord Romstad
|
||||
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)
|
||||
{
|
||||
if (!pieceCount[Us][pt1])
|
||||
continue;
|
||||
|
||||
int v = Linear[pt1];
|
||||
int v = 0;
|
||||
|
||||
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; ++pt2)
|
||||
v += QuadraticOurs[pt1][pt2] * pieceCount[Us][pt2]
|
||||
@@ -134,53 +129,48 @@ Entry* probe(const Position& pos) {
|
||||
std::memset(e, 0, sizeof(Entry));
|
||||
e->key = key;
|
||||
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
|
||||
e->gamePhase = pos.game_phase();
|
||||
|
||||
Value npm_w = pos.non_pawn_material(WHITE);
|
||||
Value npm_b = pos.non_pawn_material(BLACK);
|
||||
Value npm = std::max(EndgameLimit, std::min(npm_w + npm_b, MidgameLimit));
|
||||
|
||||
// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
|
||||
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
|
||||
|
||||
// Let's look if we have a specialized evaluation function for this particular
|
||||
// material configuration. Firstly we look for a fixed configuration one, then
|
||||
// for a generic one if the previous search failed.
|
||||
if (pos.this_thread()->endgames.probe(key, e->evaluationFunction))
|
||||
if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)
|
||||
return e;
|
||||
|
||||
if (is_KXK<WHITE>(pos))
|
||||
{
|
||||
e->evaluationFunction = &EvaluateKXK[WHITE];
|
||||
return e;
|
||||
}
|
||||
|
||||
if (is_KXK<BLACK>(pos))
|
||||
{
|
||||
e->evaluationFunction = &EvaluateKXK[BLACK];
|
||||
return e;
|
||||
}
|
||||
for (Color c = WHITE; c <= BLACK; ++c)
|
||||
if (is_KXK(pos, c))
|
||||
{
|
||||
e->evaluationFunction = &EvaluateKXK[c];
|
||||
return e;
|
||||
}
|
||||
|
||||
// OK, we didn't find any special evaluation function for the current material
|
||||
// configuration. Is there a suitable specialized scaling function?
|
||||
EndgameBase<ScaleFactor>* sf;
|
||||
const EndgameBase<ScaleFactor>* sf;
|
||||
|
||||
if (pos.this_thread()->endgames.probe(key, sf))
|
||||
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
|
||||
{
|
||||
e->scalingFunction[sf->strong_side()] = sf; // Only strong color assigned
|
||||
e->scalingFunction[sf->strongSide] = sf; // Only strong color assigned
|
||||
return e;
|
||||
}
|
||||
|
||||
// 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
|
||||
// case we don't return after setting the function.
|
||||
if (is_KBPsKs<WHITE>(pos))
|
||||
e->scalingFunction[WHITE] = &ScaleKBPsK[WHITE];
|
||||
for (Color c = WHITE; c <= BLACK; ++c)
|
||||
{
|
||||
if (is_KBPsK(pos, c))
|
||||
e->scalingFunction[c] = &ScaleKBPsK[c];
|
||||
|
||||
if (is_KBPsKs<BLACK>(pos))
|
||||
e->scalingFunction[BLACK] = &ScaleKBPsK[BLACK];
|
||||
|
||||
if (is_KQKRPs<WHITE>(pos))
|
||||
e->scalingFunction[WHITE] = &ScaleKQKRPs[WHITE];
|
||||
|
||||
else if (is_KQKRPs<BLACK>(pos))
|
||||
e->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
|
||||
|
||||
Value npm_w = pos.non_pawn_material(WHITE);
|
||||
Value npm_b = pos.non_pawn_material(BLACK);
|
||||
else if (is_KQKRPs(pos, c))
|
||||
e->scalingFunction[c] = &ScaleKQKRPs[c];
|
||||
}
|
||||
|
||||
if (npm_w + npm_b == VALUE_ZERO && pos.pieces(PAWN)) // Only pawns on the board
|
||||
{
|
||||
@@ -210,28 +200,22 @@ Entry* probe(const Position& pos) {
|
||||
// drawish scale factor for cases such as KRKBP and KmmKm (except for KBBKN).
|
||||
if (!pos.count<PAWN>(WHITE) && npm_w - npm_b <= BishopValueMg)
|
||||
e->factor[WHITE] = uint8_t(npm_w < RookValueMg ? SCALE_FACTOR_DRAW :
|
||||
npm_b <= BishopValueMg ? 4 : 12);
|
||||
npm_b <= BishopValueMg ? 4 : 14);
|
||||
|
||||
if (!pos.count<PAWN>(BLACK) && npm_b - npm_w <= BishopValueMg)
|
||||
e->factor[BLACK] = uint8_t(npm_b < RookValueMg ? SCALE_FACTOR_DRAW :
|
||||
npm_w <= BishopValueMg ? 4 : 12);
|
||||
|
||||
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;
|
||||
npm_w <= BishopValueMg ? 4 : 14);
|
||||
|
||||
// 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
|
||||
// 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) , 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) , 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;
|
||||
}
|
||||
|
||||
|
||||
+8
-7
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -40,7 +41,7 @@ struct Entry {
|
||||
|
||||
Score imbalance() const { return make_score(value, value); }
|
||||
Phase game_phase() const { return gamePhase; }
|
||||
bool specialized_eval_exists() const { return evaluationFunction != NULL; }
|
||||
bool specialized_eval_exists() const { return evaluationFunction != nullptr; }
|
||||
Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
|
||||
|
||||
// scale_factor takes a position and a color as input and returns a scale factor
|
||||
@@ -49,17 +50,17 @@ struct Entry {
|
||||
// the position. For instance, in KBP vs K endgames, the scaling function looks
|
||||
// for rook pawns and wrong-colored bishops.
|
||||
ScaleFactor scale_factor(const Position& pos, Color c) const {
|
||||
return !scalingFunction[c]
|
||||
|| (*scalingFunction[c])(pos) == SCALE_FACTOR_NONE ? ScaleFactor(factor[c])
|
||||
: (*scalingFunction[c])(pos);
|
||||
ScaleFactor sf = scalingFunction[c] ? (*scalingFunction[c])(pos)
|
||||
: SCALE_FACTOR_NONE;
|
||||
return sf != SCALE_FACTOR_NONE ? sf : ScaleFactor(factor[c]);
|
||||
}
|
||||
|
||||
Key key;
|
||||
const EndgameBase<Value>* evaluationFunction;
|
||||
const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
||||
// side (e.g. KPKP, KBPsKs)
|
||||
int16_t value;
|
||||
uint8_t factor[COLOR_NB];
|
||||
EndgameBase<Value>* evaluationFunction;
|
||||
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
||||
// side (e.g. KPKP, KBPsKs)
|
||||
Phase gamePhase;
|
||||
};
|
||||
|
||||
|
||||
+161
-47
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -17,10 +18,34 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#if _WIN32_WINNT < 0x0601
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0601 // Force to include needed API prototypes
|
||||
#endif
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
// 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
|
||||
// the calls at compile time), try to load them at runtime. To do this we need
|
||||
// first to define the corresponding function pointers.
|
||||
extern "C" {
|
||||
typedef bool(*fun1_t)(LOGICAL_PROCESSOR_RELATIONSHIP,
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, PDWORD);
|
||||
typedef bool(*fun2_t)(USHORT, PGROUP_AFFINITY);
|
||||
typedef bool(*fun3_t)(HANDLE, CONST GROUP_AFFINITY*, PGROUP_AFFINITY);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include "misc.h"
|
||||
#include "thread.h"
|
||||
@@ -31,60 +56,56 @@ namespace {
|
||||
|
||||
/// Version number. If Version is left empty, then compile date in the format
|
||||
/// DD-MM-YY and show in engine_info.
|
||||
const string Version = "6";
|
||||
|
||||
/// Debug counters
|
||||
int64_t hits[2], means[2];
|
||||
const string Version = "10";
|
||||
|
||||
/// 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
|
||||
/// can toggle the logging of std::cout and std:cin at runtime whilst preserving
|
||||
/// usual i/o functionality, all without changing a single line of code!
|
||||
/// usual I/O functionality, all without changing a single line of code!
|
||||
/// Idea from http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81
|
||||
|
||||
struct Tie: public streambuf { // MSVC requires splitted streambuf for cin and cout
|
||||
struct Tie: public streambuf { // MSVC requires split streambuf for cin and cout
|
||||
|
||||
Tie(streambuf* b, ofstream* f) : buf(b), file(f) {}
|
||||
Tie(streambuf* b, streambuf* l) : buf(b), logBuf(l) {}
|
||||
|
||||
int sync() { return file->rdbuf()->pubsync(), buf->pubsync(); }
|
||||
int overflow(int c) { return log(buf->sputc((char)c), "<< "); }
|
||||
int underflow() { return buf->sgetc(); }
|
||||
int uflow() { return log(buf->sbumpc(), ">> "); }
|
||||
int sync() override { return logBuf->pubsync(), buf->pubsync(); }
|
||||
int overflow(int c) override { return log(buf->sputc((char)c), "<< "); }
|
||||
int underflow() override { return buf->sgetc(); }
|
||||
int uflow() override { return log(buf->sbumpc(), ">> "); }
|
||||
|
||||
streambuf* buf;
|
||||
ofstream* file;
|
||||
streambuf *buf, *logBuf;
|
||||
|
||||
int log(int c, const char* prefix) {
|
||||
|
||||
static int last = '\n';
|
||||
static int last = '\n'; // Single log file
|
||||
|
||||
if (last == '\n')
|
||||
file->rdbuf()->sputn(prefix, 3);
|
||||
logBuf->sputn(prefix, 3);
|
||||
|
||||
return last = file->rdbuf()->sputc((char)c);
|
||||
return last = logBuf->sputc((char)c);
|
||||
}
|
||||
};
|
||||
|
||||
class Logger {
|
||||
|
||||
Logger() : in(cin.rdbuf(), &file), out(cout.rdbuf(), &file) {}
|
||||
~Logger() { start(false); }
|
||||
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
|
||||
~Logger() { start(""); }
|
||||
|
||||
ofstream file;
|
||||
Tie in, out;
|
||||
|
||||
public:
|
||||
static void start(bool b) {
|
||||
static void start(const std::string& fname) {
|
||||
|
||||
static Logger l;
|
||||
|
||||
if (b && !l.file.is_open())
|
||||
if (!fname.empty() && !l.file.is_open())
|
||||
{
|
||||
l.file.open("io_log.txt", ifstream::out | ifstream::app);
|
||||
l.file.open(fname, ifstream::out);
|
||||
cin.rdbuf(&l.in);
|
||||
cout.rdbuf(&l.out);
|
||||
}
|
||||
else if (!b && l.file.is_open())
|
||||
else if (fname.empty() && l.file.is_open())
|
||||
{
|
||||
cout.rdbuf(l.out.buf);
|
||||
cin.rdbuf(l.in.buf);
|
||||
@@ -117,16 +138,17 @@ const string engine_info(bool to_uci) {
|
||||
ss << (Is64Bit ? " 64" : "")
|
||||
<< (HasPext ? " BMI2" : (HasPopCnt ? " POPCNT" : ""))
|
||||
<< (to_uci ? "\nid author ": " by ")
|
||||
<< "Tord Romstad, Marco Costalba and Joona Kiiski";
|
||||
<< "T. Romstad, M. Costalba, J. Kiiski, G. Linscott";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
/// Debug functions used mainly to collect run-time statistics
|
||||
static int64_t hits[2], means[2];
|
||||
|
||||
void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; }
|
||||
void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); }
|
||||
void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); }
|
||||
void dbg_mean_of(int v) { ++means[0]; means[1] += v; }
|
||||
|
||||
void dbg_print() {
|
||||
@@ -159,26 +181,7 @@ std::ostream& operator<<(std::ostream& os, SyncCout sc) {
|
||||
|
||||
|
||||
/// Trampoline helper to avoid moving Logger to misc.h
|
||||
void start_logger(bool b) { Logger::start(b); }
|
||||
|
||||
|
||||
/// timed_wait() waits for msec milliseconds. It is mainly a helper to wrap
|
||||
/// the conversion from milliseconds to struct timespec, as used by pthreads.
|
||||
|
||||
void timed_wait(WaitCondition& sleepCond, Lock& sleepLock, int msec) {
|
||||
|
||||
#ifdef _WIN32
|
||||
int tm = msec;
|
||||
#else
|
||||
timespec ts, *tm = &ts;
|
||||
uint64_t ms = Time::now() + msec;
|
||||
|
||||
ts.tv_sec = ms / 1000;
|
||||
ts.tv_nsec = (ms % 1000) * 1000000LL;
|
||||
#endif
|
||||
|
||||
cond_timedwait(sleepCond, sleepLock, tm);
|
||||
}
|
||||
void start_logger(const std::string& fname) { Logger::start(fname); }
|
||||
|
||||
|
||||
/// prefetch() preloads the given address in L1/L2 cache. This is a non-blocking
|
||||
@@ -186,11 +189,11 @@ void timed_wait(WaitCondition& sleepCond, Lock& sleepLock, int msec) {
|
||||
/// which can be quite slow.
|
||||
#ifdef NO_PREFETCH
|
||||
|
||||
void prefetch(char*) {}
|
||||
void prefetch(void*) {}
|
||||
|
||||
#else
|
||||
|
||||
void prefetch(char* addr) {
|
||||
void prefetch(void* addr) {
|
||||
|
||||
# if defined(__INTEL_COMPILER)
|
||||
// This hack prevents prefetches from being optimized away by
|
||||
@@ -199,10 +202,121 @@ void prefetch(char* addr) {
|
||||
# endif
|
||||
|
||||
# if defined(__INTEL_COMPILER) || defined(_MSC_VER)
|
||||
_mm_prefetch(addr, _MM_HINT_T0);
|
||||
_mm_prefetch((char*)addr, _MM_HINT_T0);
|
||||
# else
|
||||
__builtin_prefetch(addr);
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void prefetch2(void* addr) {
|
||||
|
||||
prefetch(addr);
|
||||
prefetch((uint8_t*)addr + 64);
|
||||
}
|
||||
|
||||
namespace WinProcGroup {
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
void bindThisThread(size_t) {}
|
||||
|
||||
#else
|
||||
|
||||
/// best_group() retrieves logical processor information using Windows specific
|
||||
/// API and returns the best group id for the thread with index idx. Original
|
||||
/// code from Texel by Peter Österlund.
|
||||
|
||||
int best_group(size_t idx) {
|
||||
|
||||
int threads = 0;
|
||||
int nodes = 0;
|
||||
int cores = 0;
|
||||
DWORD returnLength = 0;
|
||||
DWORD byteOffset = 0;
|
||||
|
||||
// Early exit if the needed API is not available at runtime
|
||||
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
||||
auto fun1 = (fun1_t)(void(*)())GetProcAddress(k32, "GetLogicalProcessorInformationEx");
|
||||
if (!fun1)
|
||||
return -1;
|
||||
|
||||
// First call to get returnLength. We expect it to fail due to null buffer
|
||||
if (fun1(RelationAll, nullptr, &returnLength))
|
||||
return -1;
|
||||
|
||||
// Once we know returnLength, allocate the buffer
|
||||
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buffer, *ptr;
|
||||
ptr = buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(returnLength);
|
||||
|
||||
// Second call, now we expect to succeed
|
||||
if (!fun1(RelationAll, buffer, &returnLength))
|
||||
{
|
||||
free(buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (ptr->Size > 0 && byteOffset + ptr->Size <= returnLength)
|
||||
{
|
||||
if (ptr->Relationship == RelationNumaNode)
|
||||
nodes++;
|
||||
|
||||
else if (ptr->Relationship == RelationProcessorCore)
|
||||
{
|
||||
cores++;
|
||||
threads += (ptr->Processor.Flags == LTP_PC_SMT) ? 2 : 1;
|
||||
}
|
||||
|
||||
byteOffset += ptr->Size;
|
||||
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((char*)ptr) + ptr->Size);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
std::vector<int> groups;
|
||||
|
||||
// Run as many threads as possible on the same node until core limit is
|
||||
// reached, then move on filling the next node.
|
||||
for (int n = 0; n < nodes; n++)
|
||||
for (int i = 0; i < cores / nodes; i++)
|
||||
groups.push_back(n);
|
||||
|
||||
// In case a core has more than one logical processor (we assume 2) and we
|
||||
// have still threads to allocate, then spread them evenly across available
|
||||
// nodes.
|
||||
for (int t = 0; t < threads - cores; t++)
|
||||
groups.push_back(t % nodes);
|
||||
|
||||
// If we still have more threads than the total number of logical processors
|
||||
// then return -1 and let the OS to decide what to do.
|
||||
return idx < groups.size() ? groups[idx] : -1;
|
||||
}
|
||||
|
||||
|
||||
/// bindThisThread() set the group affinity of the current thread
|
||||
|
||||
void bindThisThread(size_t idx) {
|
||||
|
||||
// Use only local variables to be thread-safe
|
||||
int group = best_group(idx);
|
||||
|
||||
if (group == -1)
|
||||
return;
|
||||
|
||||
// Early exit if the needed API are not available at runtime
|
||||
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
||||
auto fun2 = (fun2_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
|
||||
auto fun3 = (fun3_t)(void(*)())GetProcAddress(k32, "SetThreadGroupAffinity");
|
||||
|
||||
if (!fun2 || !fun3)
|
||||
return;
|
||||
|
||||
GROUP_AFFINITY affinity;
|
||||
if (fun2(group, &affinity))
|
||||
fun3(GetCurrentThread(), &affinity, nullptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace WinProcGroup
|
||||
|
||||
+24
-10
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -21,6 +22,7 @@
|
||||
#define MISC_H_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -28,29 +30,30 @@
|
||||
#include "types.h"
|
||||
|
||||
const std::string engine_info(bool to_uci = false);
|
||||
void timed_wait(WaitCondition&, Lock&, int);
|
||||
void prefetch(char* addr);
|
||||
void start_logger(bool b);
|
||||
void prefetch(void* addr);
|
||||
void prefetch2(void* addr);
|
||||
void start_logger(const std::string& fname);
|
||||
|
||||
void dbg_hit_on(bool b);
|
||||
void dbg_hit_on_c(bool c, bool b);
|
||||
void dbg_hit_on(bool c, bool b);
|
||||
void dbg_mean_of(int v);
|
||||
void dbg_print();
|
||||
|
||||
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
||||
|
||||
namespace Time {
|
||||
typedef int64_t point;
|
||||
inline point now() { return system_time_to_msec(); }
|
||||
static_assert(sizeof(TimePoint) == sizeof(int64_t), "TimePoint should be 64 bits");
|
||||
|
||||
inline TimePoint now() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>
|
||||
(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
|
||||
|
||||
template<class Entry, int Size>
|
||||
struct HashTable {
|
||||
HashTable() : table(Size, Entry()) {}
|
||||
Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; }
|
||||
|
||||
private:
|
||||
std::vector<Entry> table;
|
||||
std::vector<Entry> table = std::vector<Entry>(Size);
|
||||
};
|
||||
|
||||
|
||||
@@ -97,4 +100,15 @@ public:
|
||||
{ return T(rand64() & rand64() & rand64()); }
|
||||
};
|
||||
|
||||
|
||||
/// Under Windows it is not possible for a process to run on more than one
|
||||
/// logical processor group. This usually means to be limited to use max 64
|
||||
/// cores. To overcome this, some special platform specific API should be
|
||||
/// called to set group affinity for each thread. Original code from Texel by
|
||||
/// Peter Österlund.
|
||||
|
||||
namespace WinProcGroup {
|
||||
void bindThisThread(size_t idx);
|
||||
}
|
||||
|
||||
#endif // #ifndef MISC_H_INCLUDED
|
||||
|
||||
+91
-87
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -24,84 +25,83 @@
|
||||
|
||||
namespace {
|
||||
|
||||
template<CastlingRight Cr, bool Checks, bool Chess960>
|
||||
ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us, const CheckInfo* ci) {
|
||||
template<Color Us, CastlingSide Cs, bool Checks, bool Chess960>
|
||||
ExtMove* generate_castling(const Position& pos, ExtMove* moveList) {
|
||||
|
||||
static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
|
||||
constexpr CastlingRight Cr = Us | Cs;
|
||||
constexpr 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.king_square(us);
|
||||
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);
|
||||
Square kto = relative_square(Us, KingSide ? SQ_G1 : SQ_C1);
|
||||
Bitboard enemies = pos.pieces(~Us);
|
||||
|
||||
assert(!pos.checkers());
|
||||
|
||||
const Square K = Chess960 ? kto > kfrom ? DELTA_W : DELTA_E
|
||||
: KingSide ? DELTA_W : DELTA_E;
|
||||
const Direction step = Chess960 ? kto > kfrom ? WEST : EAST
|
||||
: KingSide ? WEST : EAST;
|
||||
|
||||
for (Square s = kto; s != kfrom; s += K)
|
||||
for (Square s = kto; s != kfrom; s += step)
|
||||
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)))
|
||||
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, *ci))
|
||||
if (Checks && !pos.gives_check(m))
|
||||
return moveList;
|
||||
|
||||
(moveList++)->move = m;
|
||||
|
||||
*moveList++ = m;
|
||||
return moveList;
|
||||
}
|
||||
|
||||
|
||||
template<GenType Type, Square Delta>
|
||||
inline ExtMove* make_promotions(ExtMove* moveList, Square to, const CheckInfo* ci) {
|
||||
template<GenType Type, Direction D>
|
||||
ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) {
|
||||
|
||||
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
||||
(moveList++)->move = make<PROMOTION>(to - Delta, to, QUEEN);
|
||||
*moveList++ = make<PROMOTION>(to - D, to, QUEEN);
|
||||
|
||||
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
|
||||
{
|
||||
(moveList++)->move = make<PROMOTION>(to - Delta, to, ROOK);
|
||||
(moveList++)->move = make<PROMOTION>(to - Delta, to, BISHOP);
|
||||
(moveList++)->move = make<PROMOTION>(to - Delta, to, KNIGHT);
|
||||
*moveList++ = make<PROMOTION>(to - D, to, ROOK);
|
||||
*moveList++ = make<PROMOTION>(to - D, to, BISHOP);
|
||||
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
||||
}
|
||||
|
||||
// Knight promotion is the only promotion that can give a direct check
|
||||
// that's not already included in the queen promotion.
|
||||
if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq))
|
||||
(moveList++)->move = make<PROMOTION>(to - Delta, to, KNIGHT);
|
||||
if (Type == QUIET_CHECKS && (PseudoAttacks[KNIGHT][to] & ksq))
|
||||
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
||||
else
|
||||
(void)ci; // Silence a warning under MSVC
|
||||
(void)ksq; // Silence a warning under MSVC
|
||||
|
||||
return moveList;
|
||||
}
|
||||
|
||||
|
||||
template<Color Us, GenType Type>
|
||||
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList,
|
||||
Bitboard target, const CheckInfo* ci) {
|
||||
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||
|
||||
// Compute our parametrized parameters at compile time, named according to
|
||||
// the point of view of white side.
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);
|
||||
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
||||
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
constexpr Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||
constexpr Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||
|
||||
Bitboard emptySquares;
|
||||
|
||||
@@ -116,8 +116,8 @@ namespace {
|
||||
{
|
||||
emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces());
|
||||
|
||||
Bitboard b1 = shift_bb<Up>(pawnsNotOn7) & emptySquares;
|
||||
Bitboard b2 = shift_bb<Up>(b1 & TRank3BB) & emptySquares;
|
||||
Bitboard b1 = shift<Up>(pawnsNotOn7) & emptySquares;
|
||||
Bitboard b2 = shift<Up>(b1 & TRank3BB) & emptySquares;
|
||||
|
||||
if (Type == EVASIONS) // Consider only blocking squares
|
||||
{
|
||||
@@ -127,17 +127,20 @@ namespace {
|
||||
|
||||
if (Type == QUIET_CHECKS)
|
||||
{
|
||||
b1 &= pos.attacks_from<PAWN>(ci->ksq, Them);
|
||||
b2 &= pos.attacks_from<PAWN>(ci->ksq, Them);
|
||||
Square ksq = pos.square<KING>(Them);
|
||||
|
||||
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||
|
||||
// Add pawn pushes which give discovered check. This is possible only
|
||||
// if the pawn is not on the same file as the enemy king, because we
|
||||
// don't generate captures. Note that a possible discovery check
|
||||
// promotion has been already generated amongst the captures.
|
||||
if (pawnsNotOn7 & ci->dcCandidates)
|
||||
Bitboard dcCandidates = pos.blockers_for_king(Them);
|
||||
if (pawnsNotOn7 & dcCandidates)
|
||||
{
|
||||
Bitboard dc1 = shift_bb<Up>(pawnsNotOn7 & ci->dcCandidates) & emptySquares & ~file_bb(ci->ksq);
|
||||
Bitboard dc2 = shift_bb<Up>(dc1 & TRank3BB) & emptySquares;
|
||||
Bitboard dc1 = shift<Up>(pawnsNotOn7 & dcCandidates) & emptySquares & ~file_bb(ksq);
|
||||
Bitboard dc2 = shift<Up>(dc1 & TRank3BB) & emptySquares;
|
||||
|
||||
b1 |= dc1;
|
||||
b2 |= dc2;
|
||||
@@ -147,13 +150,13 @@ namespace {
|
||||
while (b1)
|
||||
{
|
||||
Square to = pop_lsb(&b1);
|
||||
(moveList++)->move = make_move(to - Up, to);
|
||||
*moveList++ = make_move(to - Up, to);
|
||||
}
|
||||
|
||||
while (b2)
|
||||
{
|
||||
Square to = pop_lsb(&b2);
|
||||
(moveList++)->move = make_move(to - Up - Up, to);
|
||||
*moveList++ = make_move(to - Up - Up, to);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,36 +169,38 @@ namespace {
|
||||
if (Type == EVASIONS)
|
||||
emptySquares &= target;
|
||||
|
||||
Bitboard b1 = shift_bb<Right>(pawnsOn7) & enemies;
|
||||
Bitboard b2 = shift_bb<Left >(pawnsOn7) & enemies;
|
||||
Bitboard b3 = shift_bb<Up >(pawnsOn7) & emptySquares;
|
||||
Bitboard b1 = shift<UpRight>(pawnsOn7) & enemies;
|
||||
Bitboard b2 = shift<UpLeft >(pawnsOn7) & enemies;
|
||||
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
||||
|
||||
Square ksq = pos.square<KING>(Them);
|
||||
|
||||
while (b1)
|
||||
moveList = make_promotions<Type, Right>(moveList, pop_lsb(&b1), ci);
|
||||
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(&b1), ksq);
|
||||
|
||||
while (b2)
|
||||
moveList = make_promotions<Type, Left >(moveList, pop_lsb(&b2), ci);
|
||||
moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(&b2), ksq);
|
||||
|
||||
while (b3)
|
||||
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ci);
|
||||
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ksq);
|
||||
}
|
||||
|
||||
// Standard and en-passant captures
|
||||
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
||||
{
|
||||
Bitboard b1 = shift_bb<Right>(pawnsNotOn7) & enemies;
|
||||
Bitboard b2 = shift_bb<Left >(pawnsNotOn7) & enemies;
|
||||
Bitboard b1 = shift<UpRight>(pawnsNotOn7) & enemies;
|
||||
Bitboard b2 = shift<UpLeft >(pawnsNotOn7) & enemies;
|
||||
|
||||
while (b1)
|
||||
{
|
||||
Square to = pop_lsb(&b1);
|
||||
(moveList++)->move = make_move(to - Right, to);
|
||||
*moveList++ = make_move(to - UpRight, to);
|
||||
}
|
||||
|
||||
while (b2)
|
||||
{
|
||||
Square to = pop_lsb(&b2);
|
||||
(moveList++)->move = make_move(to - Left, to);
|
||||
*moveList++ = make_move(to - UpLeft, to);
|
||||
}
|
||||
|
||||
if (pos.ep_square() != SQ_NONE)
|
||||
@@ -213,7 +218,7 @@ namespace {
|
||||
assert(b1);
|
||||
|
||||
while (b1)
|
||||
(moveList++)->move = make<ENPASSANT>(pop_lsb(&b1), pos.ep_square());
|
||||
*moveList++ = make<ENPASSANT>(pop_lsb(&b1), pos.ep_square());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,70 +226,69 @@ namespace {
|
||||
}
|
||||
|
||||
|
||||
template<PieceType Pt, bool Checks> FORCE_INLINE
|
||||
template<PieceType Pt, bool Checks>
|
||||
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
||||
Bitboard target, const CheckInfo* ci) {
|
||||
Bitboard target) {
|
||||
|
||||
assert(Pt != KING && Pt != PAWN);
|
||||
|
||||
const Square* pl = pos.list<Pt>(us);
|
||||
const Square* pl = pos.squares<Pt>(us);
|
||||
|
||||
for (Square from = *pl; from != SQ_NONE; from = *++pl)
|
||||
{
|
||||
if (Checks)
|
||||
{
|
||||
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
|
||||
&& !(PseudoAttacks[Pt][from] & target & ci->checkSq[Pt]))
|
||||
&& !(PseudoAttacks[Pt][from] & target & pos.check_squares(Pt)))
|
||||
continue;
|
||||
|
||||
if (ci->dcCandidates && (ci->dcCandidates & from))
|
||||
if (pos.blockers_for_king(~us) & from)
|
||||
continue;
|
||||
}
|
||||
|
||||
Bitboard b = pos.attacks_from<Pt>(from) & target;
|
||||
|
||||
if (Checks)
|
||||
b &= ci->checkSq[Pt];
|
||||
b &= pos.check_squares(Pt);
|
||||
|
||||
while (b)
|
||||
(moveList++)->move = make_move(from, pop_lsb(&b));
|
||||
*moveList++ = make_move(from, pop_lsb(&b));
|
||||
}
|
||||
|
||||
return moveList;
|
||||
}
|
||||
|
||||
|
||||
template<Color Us, GenType Type> FORCE_INLINE
|
||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target,
|
||||
const CheckInfo* ci = NULL) {
|
||||
template<Color Us, GenType Type>
|
||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||
|
||||
const bool Checks = Type == QUIET_CHECKS;
|
||||
constexpr bool Checks = Type == QUIET_CHECKS;
|
||||
|
||||
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target, ci);
|
||||
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target, ci);
|
||||
moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target, ci);
|
||||
moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target, ci);
|
||||
moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target, ci);
|
||||
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
||||
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
|
||||
moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target);
|
||||
moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target);
|
||||
moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target);
|
||||
|
||||
if (Type != QUIET_CHECKS && Type != EVASIONS)
|
||||
{
|
||||
Square ksq = pos.king_square(Us);
|
||||
Square ksq = pos.square<KING>(Us);
|
||||
Bitboard b = pos.attacks_from<KING>(ksq) & target;
|
||||
while (b)
|
||||
(moveList++)->move = make_move(ksq, pop_lsb(&b));
|
||||
*moveList++ = make_move(ksq, pop_lsb(&b));
|
||||
}
|
||||
|
||||
if (Type != CAPTURES && Type != EVASIONS && pos.can_castle(Us))
|
||||
{
|
||||
if (pos.is_chess960())
|
||||
{
|
||||
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
|
||||
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
|
||||
moveList = generate_castling<Us, KING_SIDE, Checks, true>(pos, moveList);
|
||||
moveList = generate_castling<Us, QUEEN_SIDE, Checks, true>(pos, moveList);
|
||||
}
|
||||
else
|
||||
{
|
||||
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
|
||||
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
|
||||
moveList = generate_castling<Us, KING_SIDE, Checks, false>(pos, moveList);
|
||||
moveList = generate_castling<Us, QUEEN_SIDE, Checks, false>(pos, moveList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,8 +337,7 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
||||
assert(!pos.checkers());
|
||||
|
||||
Color us = pos.side_to_move();
|
||||
CheckInfo ci(pos);
|
||||
Bitboard dc = ci.dcCandidates;
|
||||
Bitboard dc = pos.blockers_for_king(~us) & pos.pieces(us);
|
||||
|
||||
while (dc)
|
||||
{
|
||||
@@ -344,17 +347,17 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
||||
if (pt == PAWN)
|
||||
continue; // Will be generated together with direct checks
|
||||
|
||||
Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.pieces();
|
||||
Bitboard b = pos.attacks_from(pt, from) & ~pos.pieces();
|
||||
|
||||
if (pt == KING)
|
||||
b &= ~PseudoAttacks[QUEEN][ci.ksq];
|
||||
b &= ~PseudoAttacks[QUEEN][pos.square<KING>(~us)];
|
||||
|
||||
while (b)
|
||||
(moveList++)->move = make_move(from, pop_lsb(&b));
|
||||
*moveList++ = make_move(from, pop_lsb(&b));
|
||||
}
|
||||
|
||||
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci)
|
||||
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci);
|
||||
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces())
|
||||
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces());
|
||||
}
|
||||
|
||||
|
||||
@@ -366,7 +369,7 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
||||
assert(pos.checkers());
|
||||
|
||||
Color us = pos.side_to_move();
|
||||
Square ksq = pos.king_square(us);
|
||||
Square ksq = pos.square<KING>(us);
|
||||
Bitboard sliderAttacks = 0;
|
||||
Bitboard sliders = pos.checkers() & ~pos.pieces(KNIGHT, PAWN);
|
||||
|
||||
@@ -382,7 +385,7 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
||||
// Generate evasions for king, capture and non capture moves
|
||||
Bitboard b = pos.attacks_from<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;
|
||||
while (b)
|
||||
(moveList++)->move = make_move(ksq, pop_lsb(&b));
|
||||
*moveList++ = make_move(ksq, pop_lsb(&b));
|
||||
|
||||
if (more_than_one(pos.checkers()))
|
||||
return moveList; // Double check, only a king move can save the day
|
||||
@@ -401,16 +404,17 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
||||
template<>
|
||||
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
|
||||
|
||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||
Square ksq = pos.king_square(pos.side_to_move());
|
||||
Color us = pos.side_to_move();
|
||||
Bitboard pinned = pos.blockers_for_king(us) & pos.pieces(us);
|
||||
Square ksq = pos.square<KING>(us);
|
||||
ExtMove* cur = moveList;
|
||||
|
||||
moveList = pos.checkers() ? generate<EVASIONS >(pos, moveList)
|
||||
: generate<NON_EVASIONS>(pos, moveList);
|
||||
while (cur != moveList)
|
||||
if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT)
|
||||
&& !pos.legal(cur->move, pinned))
|
||||
cur->move = (--moveList)->move;
|
||||
if ( (pinned || from_sq(*cur) == ksq || type_of(*cur) == ENPASSANT)
|
||||
&& !pos.legal(*cur))
|
||||
*cur = (--moveList)->move;
|
||||
else
|
||||
++cur;
|
||||
|
||||
|
||||
+17
-9
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -20,6 +21,8 @@
|
||||
#ifndef MOVEGEN_H_INCLUDED
|
||||
#define MOVEGEN_H_INCLUDED
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
class Position;
|
||||
@@ -35,7 +38,14 @@ enum GenType {
|
||||
|
||||
struct ExtMove {
|
||||
Move move;
|
||||
Value value;
|
||||
int value;
|
||||
|
||||
operator Move() const { return move; }
|
||||
void operator=(Move m) { move = m; }
|
||||
|
||||
// Inhibit unwanted implicit conversions to Move
|
||||
// with an ambiguity that yields to a compile error.
|
||||
operator float() const = delete;
|
||||
};
|
||||
|
||||
inline bool operator<(const ExtMove& f, const ExtMove& s) {
|
||||
@@ -50,18 +60,16 @@ ExtMove* generate(const Position& pos, ExtMove* moveList);
|
||||
template<GenType T>
|
||||
struct MoveList {
|
||||
|
||||
explicit MoveList(const Position& pos) : cur(moveList), last(generate<T>(pos, moveList)) { last->move = MOVE_NONE; }
|
||||
void operator++() { ++cur; }
|
||||
Move operator*() const { return cur->move; }
|
||||
explicit MoveList(const Position& pos) : last(generate<T>(pos, moveList)) {}
|
||||
const ExtMove* begin() const { return moveList; }
|
||||
const ExtMove* end() const { return last; }
|
||||
size_t size() const { return last - moveList; }
|
||||
bool contains(Move m) const {
|
||||
for (const ExtMove* it(moveList); it != last; ++it) if (it->move == m) return true;
|
||||
return false;
|
||||
bool contains(Move move) const {
|
||||
return std::find(begin(), end(), move) != end();
|
||||
}
|
||||
|
||||
private:
|
||||
ExtMove moveList[MAX_MOVES];
|
||||
ExtMove *cur, *last;
|
||||
ExtMove moveList[MAX_MOVES], *last;
|
||||
};
|
||||
|
||||
#endif // #ifndef MOVEGEN_H_INCLUDED
|
||||
|
||||
+181
-297
@@ -2,13 +2,13 @@
|
||||
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-2019 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
|
||||
@@ -21,365 +21,249 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "movepick.h"
|
||||
#include "thread.h"
|
||||
|
||||
namespace {
|
||||
|
||||
enum Stages {
|
||||
MAIN_SEARCH, CAPTURES_S1, KILLERS_S1, QUIETS_1_S1, QUIETS_2_S1, BAD_CAPTURES_S1,
|
||||
EVASION, EVASIONS_S2,
|
||||
QSEARCH_0, CAPTURES_S3, QUIET_CHECKS_S3,
|
||||
QSEARCH_1, CAPTURES_S4,
|
||||
PROBCUT, CAPTURES_S5,
|
||||
RECAPTURE, CAPTURES_S6,
|
||||
STOP
|
||||
MAIN_TT, CAPTURE_INIT, GOOD_CAPTURE, REFUTATION, QUIET_INIT, QUIET, BAD_CAPTURE,
|
||||
EVASION_TT, EVASION_INIT, EVASION,
|
||||
PROBCUT_TT, PROBCUT_INIT, PROBCUT,
|
||||
QSEARCH_TT, QCAPTURE_INIT, QCAPTURE, QCHECK_INIT, QCHECK
|
||||
};
|
||||
|
||||
// Our insertion sort, which is guaranteed (and also needed) to be stable
|
||||
void insertion_sort(ExtMove* begin, ExtMove* end)
|
||||
{
|
||||
ExtMove tmp, *p, *q;
|
||||
// Helper filter used with select()
|
||||
const auto Any = [](){ return true; };
|
||||
|
||||
for (p = begin + 1; p < end; ++p)
|
||||
{
|
||||
tmp = *p;
|
||||
for (q = p; q != begin && *(q-1) < tmp; --q)
|
||||
*q = *(q-1);
|
||||
*q = tmp;
|
||||
}
|
||||
// partial_insertion_sort() sorts moves in descending order up to and including
|
||||
// a given limit. The order of moves smaller than the limit is left unspecified.
|
||||
void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit) {
|
||||
|
||||
for (ExtMove *sortedEnd = begin, *p = begin + 1; p < end; ++p)
|
||||
if (p->value >= limit)
|
||||
{
|
||||
ExtMove tmp = *p, *q;
|
||||
*p = *++sortedEnd;
|
||||
for (q = sortedEnd; q != begin && *(q - 1) < tmp; --q)
|
||||
*q = *(q - 1);
|
||||
*q = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// Unary predicate used by std::partition to split positive values from remaining
|
||||
// ones so as to sort the two sets separately, with the second sort delayed.
|
||||
inline bool has_positive_value(const ExtMove& move) { return move.value > VALUE_ZERO; }
|
||||
|
||||
// Picks 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. possible captures.
|
||||
inline ExtMove* pick_best(ExtMove* begin, ExtMove* end)
|
||||
{
|
||||
std::swap(*begin, *std::max_element(begin, end));
|
||||
return begin;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
/// Constructors of the MovePicker class. As arguments we pass information
|
||||
/// to help it to return the (presumably) good moves first, to decide which
|
||||
/// moves to return (in the quiescence search, for instance, we only want to
|
||||
/// search captures, promotions and some checks) and how important good move
|
||||
/// search captures, promotions, and some checks) and how important good move
|
||||
/// ordering is at the current node.
|
||||
|
||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
|
||||
Move* cm, Move* fm, Search::Stack* s) : pos(p), history(h), depth(d) {
|
||||
/// MovePicker constructor for the main search
|
||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers)
|
||||
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch),
|
||||
refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d) {
|
||||
|
||||
assert(d > DEPTH_ZERO);
|
||||
|
||||
cur = end = moves;
|
||||
endBadCaptures = moves + MAX_MOVES - 1;
|
||||
countermoves = cm;
|
||||
followupmoves = fm;
|
||||
ss = s;
|
||||
|
||||
if (pos.checkers())
|
||||
stage = EVASION;
|
||||
|
||||
else
|
||||
stage = MAIN_SEARCH;
|
||||
|
||||
ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
||||
end += (ttMove != MOVE_NONE);
|
||||
stage = pos.checkers() ? EVASION_TT : MAIN_TT;
|
||||
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||
stage += (ttMove == MOVE_NONE);
|
||||
}
|
||||
|
||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
|
||||
Square s) : pos(p), history(h), cur(moves), end(moves) {
|
||||
/// MovePicker constructor for quiescence search
|
||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||
const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
|
||||
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch), recaptureSquare(rs), depth(d) {
|
||||
|
||||
assert(d <= DEPTH_ZERO);
|
||||
|
||||
if (pos.checkers())
|
||||
stage = EVASION;
|
||||
|
||||
else if (d > DEPTH_QS_NO_CHECKS)
|
||||
stage = QSEARCH_0;
|
||||
|
||||
else if (d > DEPTH_QS_RECAPTURES)
|
||||
stage = QSEARCH_1;
|
||||
|
||||
else
|
||||
{
|
||||
stage = RECAPTURE;
|
||||
recaptureSquare = s;
|
||||
ttm = MOVE_NONE;
|
||||
}
|
||||
|
||||
ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
||||
end += (ttMove != MOVE_NONE);
|
||||
stage = pos.checkers() ? EVASION_TT : QSEARCH_TT;
|
||||
ttMove = ttm
|
||||
&& pos.pseudo_legal(ttm)
|
||||
&& (depth > DEPTH_QS_RECAPTURES || to_sq(ttm) == recaptureSquare) ? ttm : MOVE_NONE;
|
||||
stage += (ttMove == MOVE_NONE);
|
||||
}
|
||||
|
||||
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, PieceType pt)
|
||||
: pos(p), history(h), cur(moves), end(moves) {
|
||||
/// MovePicker constructor for ProbCut: we generate captures with SEE greater
|
||||
/// than or equal to the given threshold.
|
||||
MovePicker::MovePicker(const Position& p, Move ttm, Value th, const CapturePieceToHistory* cph)
|
||||
: pos(p), captureHistory(cph), threshold(th) {
|
||||
|
||||
assert(!pos.checkers());
|
||||
|
||||
stage = PROBCUT;
|
||||
|
||||
// In ProbCut we generate only captures that are better than the parent's
|
||||
// captured piece.
|
||||
captureThreshold = PieceValue[MG][pt];
|
||||
ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
||||
|
||||
if (ttMove && (!pos.capture(ttMove) || pos.see(ttMove) <= captureThreshold))
|
||||
ttMove = MOVE_NONE;
|
||||
|
||||
end += (ttMove != MOVE_NONE);
|
||||
stage = PROBCUT_TT;
|
||||
ttMove = ttm
|
||||
&& pos.pseudo_legal(ttm)
|
||||
&& pos.capture(ttm)
|
||||
&& pos.see_ge(ttm, threshold) ? ttm : MOVE_NONE;
|
||||
stage += (ttMove == MOVE_NONE);
|
||||
}
|
||||
|
||||
/// MovePicker::score() assigns a numerical value to each move in a list, used
|
||||
/// for sorting. Captures are ordered by Most Valuable Victim (MVV), preferring
|
||||
/// captures with a good history. Quiets moves are ordered using the histories.
|
||||
template<GenType Type>
|
||||
void MovePicker::score() {
|
||||
|
||||
/// score() assign a numerical value to each move in a move list. The moves with
|
||||
/// highest values will be picked first.
|
||||
template<>
|
||||
void MovePicker::score<CAPTURES>() {
|
||||
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
||||
// Suprisingly, this appears to perform slightly better than SEE based
|
||||
// move ordering. The reason is probably that in a position with a winning
|
||||
// capture, capturing a more valuable (but sufficiently defended) piece
|
||||
// first usually doesn't hurt. The opponent will have to recapture, and
|
||||
// the hanging piece will still be hanging (except in the unusual cases
|
||||
// where it is possible to recapture with the hanging piece). Exchanging
|
||||
// big pieces before capturing a hanging piece probably helps to reduce
|
||||
// the subtree size.
|
||||
// In main search we want to push captures with negative SEE values to the
|
||||
// badCaptures[] array, but instead of doing it now we delay until the move
|
||||
// has been picked up in pick_move_from_list(). This way we save some SEE
|
||||
// calls in case we get a cutoff.
|
||||
Move m;
|
||||
static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
|
||||
|
||||
for (ExtMove* it = moves; it != end; ++it)
|
||||
for (auto& m : *this)
|
||||
if (Type == CAPTURES)
|
||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||
+ (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))] / 8;
|
||||
|
||||
else if (Type == QUIETS)
|
||||
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||
+ (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
|
||||
+ (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)];
|
||||
|
||||
else // Type == EVASIONS
|
||||
{
|
||||
if (pos.capture(m))
|
||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||
- Value(type_of(pos.moved_piece(m)));
|
||||
else
|
||||
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||
- (1 << 28);
|
||||
}
|
||||
}
|
||||
|
||||
/// MovePicker::select() returns the next move satisfying a predicate function.
|
||||
/// It never returns the TT move.
|
||||
template<MovePicker::PickType T, typename Pred>
|
||||
Move MovePicker::select(Pred filter) {
|
||||
|
||||
while (cur < endMoves)
|
||||
{
|
||||
m = it->move;
|
||||
it->value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||
- Value(type_of(pos.moved_piece(m)));
|
||||
if (T == Best)
|
||||
std::swap(*cur, *std::max_element(cur, endMoves));
|
||||
|
||||
if (type_of(m) == ENPASSANT)
|
||||
it->value += PieceValue[MG][PAWN];
|
||||
move = *cur++;
|
||||
|
||||
else if (type_of(m) == PROMOTION)
|
||||
it->value += PieceValue[MG][promotion_type(m)] - PieceValue[MG][PAWN];
|
||||
if (move != ttMove && filter())
|
||||
return move;
|
||||
}
|
||||
return move = MOVE_NONE;
|
||||
}
|
||||
|
||||
template<>
|
||||
void MovePicker::score<QUIETS>() {
|
||||
/// 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 m;
|
||||
top:
|
||||
switch (stage) {
|
||||
|
||||
for (ExtMove* it = moves; it != end; ++it)
|
||||
{
|
||||
m = it->move;
|
||||
it->value = history[pos.moved_piece(m)][to_sq(m)];
|
||||
}
|
||||
}
|
||||
case MAIN_TT:
|
||||
case EVASION_TT:
|
||||
case QSEARCH_TT:
|
||||
case PROBCUT_TT:
|
||||
++stage;
|
||||
return ttMove;
|
||||
|
||||
template<>
|
||||
void MovePicker::score<EVASIONS>() {
|
||||
// Try good captures ordered by MVV/LVA, then non-captures if destination square
|
||||
// is not under attack, ordered by history value, then bad-captures and quiet
|
||||
// moves with a negative SEE. This last group is ordered by the SEE value.
|
||||
Move m;
|
||||
Value see;
|
||||
case CAPTURE_INIT:
|
||||
case PROBCUT_INIT:
|
||||
case QCAPTURE_INIT:
|
||||
cur = endBadCaptures = moves;
|
||||
endMoves = generate<CAPTURES>(pos, cur);
|
||||
|
||||
for (ExtMove* it = moves; it != end; ++it)
|
||||
{
|
||||
m = it->move;
|
||||
if ((see = pos.see_sign(m)) < VALUE_ZERO)
|
||||
it->value = see - HistoryStats::Max; // At the bottom
|
||||
|
||||
else if (pos.capture(m))
|
||||
it->value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||
- Value(type_of(pos.moved_piece(m))) + HistoryStats::Max;
|
||||
else
|
||||
it->value = history[pos.moved_piece(m)][to_sq(m)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// generate_next_stage() generates, scores and sorts the next bunch of moves,
|
||||
/// when there are no more moves to try for the current stage.
|
||||
|
||||
void MovePicker::generate_next_stage() {
|
||||
|
||||
cur = moves;
|
||||
|
||||
switch (++stage) {
|
||||
|
||||
case CAPTURES_S1: case CAPTURES_S3: case CAPTURES_S4: case CAPTURES_S5: case CAPTURES_S6:
|
||||
end = generate<CAPTURES>(pos, moves);
|
||||
score<CAPTURES>();
|
||||
return;
|
||||
++stage;
|
||||
goto top;
|
||||
|
||||
case KILLERS_S1:
|
||||
cur = killers;
|
||||
end = cur + 2;
|
||||
case GOOD_CAPTURE:
|
||||
if (select<Best>([&](){
|
||||
return pos.see_ge(move, Value(-55 * (cur-1)->value / 1024)) ?
|
||||
// Move losing capture to endBadCaptures to be tried later
|
||||
true : (*endBadCaptures++ = move, false); }))
|
||||
return move;
|
||||
|
||||
killers[0].move = ss->killers[0];
|
||||
killers[1].move = ss->killers[1];
|
||||
killers[2].move = killers[3].move = MOVE_NONE;
|
||||
killers[4].move = killers[5].move = MOVE_NONE;
|
||||
// Prepare the pointers to loop over the refutations array
|
||||
cur = std::begin(refutations);
|
||||
endMoves = std::end(refutations);
|
||||
|
||||
// Please note that following code is racy and could yield to rare (less
|
||||
// than 1 out of a million) duplicated entries in SMP case. This is harmless.
|
||||
// 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;
|
||||
|
||||
// Be sure countermoves are different from killers
|
||||
for (int i = 0; i < 2; ++i)
|
||||
if ( countermoves[i] != (cur+0)->move
|
||||
&& countermoves[i] != (cur+1)->move)
|
||||
(end++)->move = countermoves[i];
|
||||
++stage;
|
||||
/* fallthrough */
|
||||
|
||||
// Be sure followupmoves are different from killers and countermoves
|
||||
for (int i = 0; i < 2; ++i)
|
||||
if ( followupmoves[i] != (cur+0)->move
|
||||
&& followupmoves[i] != (cur+1)->move
|
||||
&& followupmoves[i] != (cur+2)->move
|
||||
&& followupmoves[i] != (cur+3)->move)
|
||||
(end++)->move = followupmoves[i];
|
||||
return;
|
||||
case REFUTATION:
|
||||
if (select<Next>([&](){ return move != MOVE_NONE
|
||||
&& !pos.capture(move)
|
||||
&& pos.pseudo_legal(move); }))
|
||||
return move;
|
||||
++stage;
|
||||
/* fallthrough */
|
||||
|
||||
case QUIET_INIT:
|
||||
cur = endBadCaptures;
|
||||
endMoves = generate<QUIETS>(pos, cur);
|
||||
|
||||
case QUIETS_1_S1:
|
||||
endQuiets = end = generate<QUIETS>(pos, moves);
|
||||
score<QUIETS>();
|
||||
end = std::partition(cur, end, has_positive_value);
|
||||
insertion_sort(cur, end);
|
||||
return;
|
||||
partial_insertion_sort(cur, endMoves, -4000 * depth / ONE_PLY);
|
||||
++stage;
|
||||
/* fallthrough */
|
||||
|
||||
case QUIETS_2_S1:
|
||||
cur = end;
|
||||
end = endQuiets;
|
||||
if (depth >= 3 * ONE_PLY)
|
||||
insertion_sort(cur, end);
|
||||
return;
|
||||
case QUIET:
|
||||
if ( !skipQuiets
|
||||
&& select<Next>([&](){return move != refutations[0]
|
||||
&& move != refutations[1]
|
||||
&& move != refutations[2];}))
|
||||
return move;
|
||||
|
||||
case BAD_CAPTURES_S1:
|
||||
// Just pick them in reverse order to get MVV/LVA ordering
|
||||
cur = moves + MAX_MOVES - 1;
|
||||
end = endBadCaptures;
|
||||
return;
|
||||
// Prepare the pointers to loop over the bad captures
|
||||
cur = moves;
|
||||
endMoves = endBadCaptures;
|
||||
|
||||
case EVASIONS_S2:
|
||||
end = generate<EVASIONS>(pos, moves);
|
||||
if (end > moves + 1)
|
||||
score<EVASIONS>();
|
||||
return;
|
||||
++stage;
|
||||
/* fallthrough */
|
||||
|
||||
case QUIET_CHECKS_S3:
|
||||
end = generate<QUIET_CHECKS>(pos, moves);
|
||||
return;
|
||||
case BAD_CAPTURE:
|
||||
return select<Next>(Any);
|
||||
|
||||
case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT: case RECAPTURE:
|
||||
stage = STOP;
|
||||
/* Fall through */
|
||||
case EVASION_INIT:
|
||||
cur = moves;
|
||||
endMoves = generate<EVASIONS>(pos, cur);
|
||||
|
||||
case STOP:
|
||||
end = cur + 1; // Avoid another next_phase() call
|
||||
return;
|
||||
score<EVASIONS>();
|
||||
++stage;
|
||||
/* fallthrough */
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
case EVASION:
|
||||
return select<Best>(Any);
|
||||
|
||||
case PROBCUT:
|
||||
return select<Best>([&](){ return pos.see_ge(move, threshold); });
|
||||
|
||||
/// 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. It picks the move with the biggest value from a list of generated moves
|
||||
/// taking care not to return the ttMove if it has already been searched.
|
||||
template<>
|
||||
Move MovePicker::next_move<false>() {
|
||||
case QCAPTURE:
|
||||
if (select<Best>([&](){ return depth > DEPTH_QS_RECAPTURES
|
||||
|| to_sq(move) == recaptureSquare; }))
|
||||
return move;
|
||||
|
||||
Move move;
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (cur == end)
|
||||
generate_next_stage();
|
||||
|
||||
switch (stage) {
|
||||
|
||||
case MAIN_SEARCH: case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT:
|
||||
++cur;
|
||||
return ttMove;
|
||||
|
||||
case CAPTURES_S1:
|
||||
move = pick_best(cur++, end)->move;
|
||||
if (move != ttMove)
|
||||
{
|
||||
if (pos.see_sign(move) >= VALUE_ZERO)
|
||||
return move;
|
||||
|
||||
// Losing capture, move it to the tail of the array
|
||||
(endBadCaptures--)->move = move;
|
||||
}
|
||||
break;
|
||||
|
||||
case KILLERS_S1:
|
||||
move = (cur++)->move;
|
||||
if ( move != MOVE_NONE
|
||||
&& move != ttMove
|
||||
&& pos.pseudo_legal(move)
|
||||
&& !pos.capture(move))
|
||||
return move;
|
||||
break;
|
||||
|
||||
case QUIETS_1_S1: case QUIETS_2_S1:
|
||||
move = (cur++)->move;
|
||||
if ( move != ttMove
|
||||
&& move != killers[0].move
|
||||
&& move != killers[1].move
|
||||
&& move != killers[2].move
|
||||
&& move != killers[3].move
|
||||
&& move != killers[4].move
|
||||
&& move != killers[5].move)
|
||||
return move;
|
||||
break;
|
||||
|
||||
case BAD_CAPTURES_S1:
|
||||
return (cur--)->move;
|
||||
|
||||
case EVASIONS_S2: case CAPTURES_S3: case CAPTURES_S4:
|
||||
move = pick_best(cur++, end)->move;
|
||||
if (move != ttMove)
|
||||
return move;
|
||||
break;
|
||||
|
||||
case CAPTURES_S5:
|
||||
move = pick_best(cur++, end)->move;
|
||||
if (move != ttMove && pos.see(move) > captureThreshold)
|
||||
return move;
|
||||
break;
|
||||
|
||||
case CAPTURES_S6:
|
||||
move = pick_best(cur++, end)->move;
|
||||
if (to_sq(move) == recaptureSquare)
|
||||
return move;
|
||||
break;
|
||||
|
||||
case QUIET_CHECKS_S3:
|
||||
move = (cur++)->move;
|
||||
if (move != ttMove)
|
||||
return move;
|
||||
break;
|
||||
|
||||
case STOP:
|
||||
// If we did not find any move and we do not try checks, we have finished
|
||||
if (depth != DEPTH_QS_CHECKS)
|
||||
return MOVE_NONE;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
++stage;
|
||||
/* fallthrough */
|
||||
|
||||
case QCHECK_INIT:
|
||||
cur = moves;
|
||||
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
||||
|
||||
++stage;
|
||||
/* fallthrough */
|
||||
|
||||
case QCHECK:
|
||||
return select<Next>(Any);
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return MOVE_NONE; // Silence warning
|
||||
}
|
||||
|
||||
|
||||
/// Version of next_move() to use at split point nodes where the move is grabbed
|
||||
/// from the split point's shared MovePicker object. This function is not thread
|
||||
/// safe so must be lock protected by the caller.
|
||||
template<>
|
||||
Move MovePicker::next_move<true>() { return ss->splitPoint->movePicker->next_move<false>(); }
|
||||
|
||||
+94
-54
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -20,56 +21,87 @@
|
||||
#ifndef MOVEPICK_H_INCLUDED
|
||||
#define MOVEPICK_H_INCLUDED
|
||||
|
||||
#include <algorithm> // For std::max
|
||||
#include <cstring> // For std::memset
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
#include "movegen.h"
|
||||
#include "position.h"
|
||||
#include "search.h"
|
||||
#include "types.h"
|
||||
|
||||
/// StatsEntry stores the stat table value. It is usually a number but could
|
||||
/// be a move or even a nested history. We use a class instead of naked value
|
||||
/// 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 {
|
||||
|
||||
/// The Stats struct stores moves statistics. According to the template parameter
|
||||
/// the class can store History, Gains and Countermoves. History records how often
|
||||
/// different moves have been successful or unsuccessful during the current search
|
||||
/// and is used for reduction and move ordering decisions. Gains records the move's
|
||||
/// best evaluation gain from one ply to the next and is used for pruning decisions.
|
||||
/// Countermoves store the move that refute a previous one. Entries are stored
|
||||
/// using only the moving piece and destination square, hence two moves with
|
||||
/// different origin but same destination and piece will be considered identical.
|
||||
template<bool Gain, typename T>
|
||||
struct Stats {
|
||||
T entry;
|
||||
|
||||
static const Value Max = Value(250);
|
||||
public:
|
||||
void operator=(const T& v) { entry = v; }
|
||||
T* operator&() { return &entry; }
|
||||
T* operator->() { return &entry; }
|
||||
operator const T&() const { return entry; }
|
||||
|
||||
const T* operator[](Piece pc) const { return table[pc]; }
|
||||
void clear() { std::memset(table, 0, sizeof(table)); }
|
||||
void operator<<(int bonus) {
|
||||
assert(abs(bonus) <= D); // Ensure range is [-D, D]
|
||||
static_assert(D <= std::numeric_limits<T>::max(), "D overflows T");
|
||||
|
||||
void update(Piece pc, Square to, Move m) {
|
||||
entry += bonus - entry * abs(bonus) / D;
|
||||
|
||||
if (m == table[pc][to].first)
|
||||
return;
|
||||
|
||||
table[pc][to].second = table[pc][to].first;
|
||||
table[pc][to].first = m;
|
||||
assert(abs(entry) <= D);
|
||||
}
|
||||
|
||||
void update(Piece pc, Square to, Value v) {
|
||||
|
||||
if (Gain)
|
||||
table[pc][to] = std::max(v, table[pc][to] - 1);
|
||||
|
||||
else if (abs(table[pc][to] + v) < Max)
|
||||
table[pc][to] += v;
|
||||
}
|
||||
|
||||
private:
|
||||
T table[PIECE_NB][SQUARE_NB];
|
||||
};
|
||||
|
||||
typedef Stats< true, Value> GainsStats;
|
||||
typedef Stats<false, Value> HistoryStats;
|
||||
typedef Stats<false, std::pair<Move, Move> > MovesStats;
|
||||
/// Stats is a generic N-dimensional array used to store various statistics.
|
||||
/// The first template parameter T is the base type of the array, the second
|
||||
/// 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) {
|
||||
|
||||
// For standard-layout 'this' points to first struct member
|
||||
assert(std::is_standard_layout<stats>::value);
|
||||
|
||||
typedef StatsEntry<T, D> entry;
|
||||
entry* p = reinterpret_cast<entry*>(this);
|
||||
std::fill(p, p + sizeof(*this) / sizeof(entry), v);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, int D, int Size>
|
||||
struct Stats<T, D, Size> : public std::array<StatsEntry<T, D>, Size> {};
|
||||
|
||||
/// In stats table, D=0 means that the template parameter is not used
|
||||
enum StatsParams { NOT_USED = 0 };
|
||||
|
||||
|
||||
/// ButterflyHistory records how often quiet moves have been successful or
|
||||
/// unsuccessful during the current search, and is used for reduction and move
|
||||
/// ordering decisions. It uses 2 tables (one for each color) indexed by
|
||||
/// the move's from and to squares, see chessprogramming.wikispaces.com/Butterfly+Boards
|
||||
typedef Stats<int16_t, 10692, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyHistory;
|
||||
|
||||
/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous
|
||||
/// move, see chessprogramming.wikispaces.com/Countermove+Heuristic
|
||||
typedef Stats<Move, NOT_USED, PIECE_NB, SQUARE_NB> CounterMoveHistory;
|
||||
|
||||
/// CapturePieceToHistory is addressed by a move's [piece][to][captured piece type]
|
||||
typedef Stats<int16_t, 10692, PIECE_NB, SQUARE_NB, PIECE_TYPE_NB> CapturePieceToHistory;
|
||||
|
||||
/// 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
|
||||
@@ -78,34 +110,42 @@ typedef Stats<false, std::pair<Move, Move> > MovesStats;
|
||||
/// 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
|
||||
/// to get a cut-off first.
|
||||
|
||||
class MovePicker {
|
||||
|
||||
MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
|
||||
enum PickType { Next, Best };
|
||||
|
||||
public:
|
||||
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
|
||||
MovePicker(const Position&, Move, const HistoryStats&, PieceType);
|
||||
MovePicker(const Position&, Move, Depth, const HistoryStats&, Move*, Move*, Search::Stack*);
|
||||
|
||||
template<bool SpNode> Move next_move();
|
||||
MovePicker(const MovePicker&) = delete;
|
||||
MovePicker& operator=(const MovePicker&) = delete;
|
||||
MovePicker(const Position&, Move, Value, const CapturePieceToHistory*);
|
||||
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
|
||||
const CapturePieceToHistory*,
|
||||
const PieceToHistory**,
|
||||
Square);
|
||||
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
|
||||
const CapturePieceToHistory*,
|
||||
const PieceToHistory**,
|
||||
Move,
|
||||
Move*);
|
||||
Move next_move(bool skipQuiets = false);
|
||||
|
||||
private:
|
||||
template<PickType T, typename Pred> Move select(Pred);
|
||||
template<GenType> void score();
|
||||
void generate_next_stage();
|
||||
ExtMove* begin() { return cur; }
|
||||
ExtMove* end() { return endMoves; }
|
||||
|
||||
const Position& pos;
|
||||
const HistoryStats& history;
|
||||
Search::Stack* ss;
|
||||
Move* countermoves;
|
||||
Move* followupmoves;
|
||||
Depth depth;
|
||||
const ButterflyHistory* mainHistory;
|
||||
const CapturePieceToHistory* captureHistory;
|
||||
const PieceToHistory** continuationHistory;
|
||||
Move ttMove;
|
||||
ExtMove killers[6];
|
||||
Square recaptureSquare;
|
||||
Value captureThreshold;
|
||||
ExtMove refutations[3], *cur, *endMoves, *endBadCaptures;
|
||||
int stage;
|
||||
ExtMove *cur, *end, *endQuiets, *endBadCaptures;
|
||||
Move move;
|
||||
Square recaptureSquare;
|
||||
Value threshold;
|
||||
Depth depth;
|
||||
ExtMove moves[MAX_MOVES];
|
||||
};
|
||||
|
||||
|
||||
+121
-170
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -21,7 +22,6 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "bitboard.h"
|
||||
#include "bitcount.h"
|
||||
#include "pawns.h"
|
||||
#include "position.h"
|
||||
#include "thread.h"
|
||||
@@ -31,65 +31,32 @@ namespace {
|
||||
#define V Value
|
||||
#define S(mg, eg) make_score(mg, eg)
|
||||
|
||||
// Doubled pawn penalty by file
|
||||
const Score Doubled[FILE_NB] = {
|
||||
S(13, 43), S(20, 48), S(23, 48), S(23, 48),
|
||||
S(23, 48), S(23, 48), S(20, 48), S(13, 43) };
|
||||
// Pawn penalties
|
||||
constexpr Score Backward = S( 9, 24);
|
||||
constexpr Score Doubled = S(11, 56);
|
||||
constexpr Score Isolated = S( 5, 15);
|
||||
|
||||
// Isolated pawn penalty by opposed flag and file
|
||||
const Score Isolated[2][FILE_NB] = {
|
||||
{ S(37, 45), S(54, 52), S(60, 52), S(60, 52),
|
||||
S(60, 52), S(60, 52), S(54, 52), S(37, 45) },
|
||||
{ S(25, 30), S(36, 35), S(40, 35), S(40, 35),
|
||||
S(40, 35), S(40, 35), S(36, 35), S(25, 30) } };
|
||||
// Connected pawn bonus by opposed, phalanx, #support and rank
|
||||
Score Connected[2][2][3][RANK_NB];
|
||||
|
||||
// Backward pawn penalty by opposed flag and file
|
||||
const Score Backward[2][FILE_NB] = {
|
||||
{ S(30, 42), S(43, 46), S(49, 46), S(49, 46),
|
||||
S(49, 46), S(49, 46), S(43, 46), S(30, 42) },
|
||||
{ S(20, 28), S(29, 31), S(33, 31), S(33, 31),
|
||||
S(33, 31), S(33, 31), S(29, 31), S(20, 28) } };
|
||||
// Strength of pawn shelter for our king by [distance from edge][rank].
|
||||
// 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] = {
|
||||
{ V( -6), V( 81), V( 93), V( 58), V( 39), V( 18), V( 25) },
|
||||
{ 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) },
|
||||
{ V(-39), V(-13), V(-29), V(-52), V(-48), V(-67), V(-166) }
|
||||
};
|
||||
|
||||
// Connected pawn bonus by opposed, phalanx flags and rank
|
||||
Score Connected[2][2][RANK_NB];
|
||||
|
||||
// Levers bonus by rank
|
||||
const Score Lever[RANK_NB] = {
|
||||
S( 0, 0), S( 0, 0), S(0, 0), S(0, 0),
|
||||
S(20,20), S(40,40), S(0, 0), S(0, 0) };
|
||||
|
||||
// Unsupported pawn penalty
|
||||
const Score UnsupportedPawnPenalty = S(20, 10);
|
||||
|
||||
// Weakness of our pawn shelter in front of the king by [distance from edge][rank]
|
||||
const Value ShelterWeakness[][RANK_NB] = {
|
||||
{ V(100), V(13), V(24), V(64), V(89), V( 93), V(104) },
|
||||
{ V(110), V( 1), V(29), V(75), V(96), V(102), V(107) },
|
||||
{ V(102), V( 0), V(39), V(74), V(88), V(101), V( 98) },
|
||||
{ V( 88), V( 4), V(33), V(67), V(92), V( 94), V(107) } };
|
||||
|
||||
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank]
|
||||
const Value StormDanger[][4][RANK_NB] = {
|
||||
{ { V( 0), V( 63), V( 128), V(43), V(27) },
|
||||
{ V( 0), V( 62), V( 131), V(44), V(26) },
|
||||
{ V( 0), V( 59), V( 121), V(50), V(28) },
|
||||
{ V( 0), V( 62), V( 127), V(54), V(28) } },
|
||||
{ { V(24), V( 40), V( 93), V(42), V(22) },
|
||||
{ V(24), V( 28), V( 101), V(38), V(20) },
|
||||
{ V(24), V( 32), V( 95), V(36), V(23) },
|
||||
{ V(27), V( 24), V( 99), V(36), V(24) } },
|
||||
{ { V( 0), V( 0), V( 81), V(16), V( 6) },
|
||||
{ V( 0), V( 0), V( 165), V(29), V( 9) },
|
||||
{ V( 0), V( 0), V( 163), V(23), V(12) },
|
||||
{ V( 0), V( 0), V( 161), V(28), V(13) } },
|
||||
{ { V( 0), V(-296), V(-299), V(55), V(25) },
|
||||
{ V( 0), V( 67), V( 131), V(46), V(21) },
|
||||
{ V( 0), V( 65), V( 135), V(50), V(31) },
|
||||
{ V( 0), V( 62), V( 128), V(51), V(24) } } };
|
||||
|
||||
// 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(257);
|
||||
// Danger of enemy pawns moving toward our king by [distance from edge][rank].
|
||||
// RANK_1 = 0 is used for files where the enemy has no pawn, or their pawn
|
||||
// is behind our king.
|
||||
constexpr Value UnblockedStorm[int(FILE_NB) / 2][RANK_NB] = {
|
||||
{ V( 89), V(107), V(123), V(93), V(57), V( 45), V( 51) },
|
||||
{ V( 44), V(-18), V(123), V(46), V(39), V( -7), V( 23) },
|
||||
{ V( 4), V( 52), V(162), V(37), V( 7), V(-14), V( -2) },
|
||||
{ V(-10), V(-14), V( 90), V(15), V( 2), V( -7), V(-16) }
|
||||
};
|
||||
|
||||
#undef S
|
||||
#undef V
|
||||
@@ -97,26 +64,24 @@ namespace {
|
||||
template<Color Us>
|
||||
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);
|
||||
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
||||
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
|
||||
Bitboard b, p, doubled, connected;
|
||||
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
|
||||
Bitboard lever, leverPush;
|
||||
Square s;
|
||||
bool passed, isolated, opposed, phalanx, backward, unsupported, lever;
|
||||
bool opposed, backward;
|
||||
Score score = SCORE_ZERO;
|
||||
const Square* pl = pos.list<PAWN>(Us);
|
||||
const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)];
|
||||
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);
|
||||
|
||||
e->passedPawns[Us] = 0;
|
||||
e->kingSquares[Us] = SQ_NONE;
|
||||
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = e->weakUnopposed[Us] = 0;
|
||||
e->semiopenFiles[Us] = 0xFF;
|
||||
e->pawnAttacks[Us] = shift_bb<Right>(ourPawns) | shift_bb<Left>(ourPawns);
|
||||
e->pawnsOnSquares[Us][BLACK] = popcount<Max15>(ourPawns & DarkSquares);
|
||||
e->kingSquares[Us] = SQ_NONE;
|
||||
e->pawnAttacks[Us] = pawn_attacks_bb<Us>(ourPawns);
|
||||
e->pawnsOnSquares[Us][BLACK] = popcount(ourPawns & DarkSquares);
|
||||
e->pawnsOnSquares[Us][WHITE] = pos.count<PAWN>(Us) - e->pawnsOnSquares[Us][BLACK];
|
||||
|
||||
// Loop through all pawns of the current color and score each pawn
|
||||
@@ -126,76 +91,56 @@ namespace {
|
||||
|
||||
File f = file_of(s);
|
||||
|
||||
// This file cannot be semi-open
|
||||
e->semiopenFiles[Us] &= ~(1 << f);
|
||||
e->semiopenFiles[Us] &= ~(1 << f);
|
||||
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
|
||||
|
||||
// Previous rank
|
||||
p = rank_bb(s - pawn_push(Us));
|
||||
// Flag the pawn
|
||||
opposed = theirPawns & forward_file_bb(Us, s);
|
||||
stoppers = theirPawns & passed_pawn_mask(Us, s);
|
||||
lever = theirPawns & PawnAttacks[Us][s];
|
||||
leverPush = theirPawns & PawnAttacks[Us][s + Up];
|
||||
doubled = ourPawns & (s - Up);
|
||||
neighbours = ourPawns & adjacent_files_bb(f);
|
||||
phalanx = neighbours & rank_bb(s);
|
||||
supported = neighbours & rank_bb(s - Up);
|
||||
|
||||
// Flag the pawn as passed, isolated, doubled,
|
||||
// unsupported or connected (but not the backward one).
|
||||
connected = ourPawns & adjacent_files_bb(f) & (rank_bb(s) | p);
|
||||
phalanx = connected & rank_bb(s);
|
||||
unsupported = !(ourPawns & adjacent_files_bb(f) & p);
|
||||
isolated = !(ourPawns & adjacent_files_bb(f));
|
||||
doubled = ourPawns & forward_bb(Us, s);
|
||||
opposed = theirPawns & forward_bb(Us, s);
|
||||
passed = !(theirPawns & passed_pawn_mask(Us, s));
|
||||
lever = theirPawns & pawnAttacksBB[s];
|
||||
|
||||
// Test for backward pawn.
|
||||
// If the pawn is passed, isolated, or connected it cannot be
|
||||
// backward. If there are friendly pawns behind on adjacent files
|
||||
// or if it can capture an enemy pawn it cannot be backward either.
|
||||
if ( (passed | isolated | connected)
|
||||
|| (ourPawns & pawn_attack_span(Them, s))
|
||||
|| (pos.attacks_from<PAWN>(s, Us) & theirPawns))
|
||||
backward = false;
|
||||
else
|
||||
{
|
||||
// We now know that there are no friendly pawns beside or behind this
|
||||
// pawn on adjacent files. We now check whether the pawn is
|
||||
// backward by looking in the forward direction on the adjacent
|
||||
// files, and picking the closest pawn there.
|
||||
b = pawn_attack_span(Us, s) & (ourPawns | theirPawns);
|
||||
b = pawn_attack_span(Us, s) & rank_bb(backmost_sq(Us, b));
|
||||
|
||||
// If we have an enemy pawn in the same or next rank, the pawn is
|
||||
// backward because it cannot advance without being captured.
|
||||
backward = (b | shift_bb<Up>(b)) & theirPawns;
|
||||
}
|
||||
|
||||
assert(opposed | passed | (pawn_attack_span(Us, s) & theirPawns));
|
||||
// A pawn is backward when it is behind all pawns of the same color
|
||||
// on the adjacent files and cannot be safely advanced.
|
||||
backward = !(ourPawns & pawn_attack_span(Them, s + Up))
|
||||
&& (stoppers & (leverPush | (s + Up)));
|
||||
|
||||
// Passed pawns will be properly scored in evaluation because we need
|
||||
// full attack info to evaluate passed pawns. Only the frontmost passed
|
||||
// pawn on each file is considered a true passed pawn.
|
||||
if (passed && !doubled)
|
||||
// full attack info to evaluate them. Include also not passed pawns
|
||||
// which could become passed after one or two pawn pushes when are
|
||||
// not attacked more times than defended.
|
||||
if ( !(stoppers ^ lever ^ leverPush)
|
||||
&& popcount(supported) >= popcount(lever) - 1
|
||||
&& popcount(phalanx) >= popcount(leverPush))
|
||||
e->passedPawns[Us] |= s;
|
||||
|
||||
else if ( stoppers == SquareBB[s + Up]
|
||||
&& relative_rank(Us, s) >= RANK_5)
|
||||
{
|
||||
b = shift<Up>(supported) & ~theirPawns;
|
||||
while (b)
|
||||
if (!more_than_one(theirPawns & PawnAttacks[Us][pop_lsb(&b)]))
|
||||
e->passedPawns[Us] |= s;
|
||||
}
|
||||
|
||||
// Score this pawn
|
||||
if (isolated)
|
||||
score -= Isolated[opposed][f];
|
||||
if (supported | phalanx)
|
||||
score += Connected[opposed][bool(phalanx)][popcount(supported)][relative_rank(Us, s)];
|
||||
|
||||
if (unsupported && !isolated)
|
||||
score -= UnsupportedPawnPenalty;
|
||||
else if (!neighbours)
|
||||
score -= Isolated, e->weakUnopposed[Us] += !opposed;
|
||||
|
||||
if (doubled)
|
||||
score -= Doubled[f] / distance<Rank>(s, frontmost_sq(Us, doubled));
|
||||
else if (backward)
|
||||
score -= Backward, e->weakUnopposed[Us] += !opposed;
|
||||
|
||||
if (backward)
|
||||
score -= Backward[opposed][f];
|
||||
|
||||
if (connected)
|
||||
score += Connected[opposed][phalanx][relative_rank(Us, s)];
|
||||
|
||||
if (lever)
|
||||
score += Lever[relative_rank(Us, s)];
|
||||
if (doubled && !supported)
|
||||
score -= Doubled;
|
||||
}
|
||||
|
||||
b = e->semiopenFiles[Us] ^ 0xFF;
|
||||
e->pawnSpan[Us] = b ? int(msb(b) - lsb(b)) : 0;
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -207,17 +152,20 @@ namespace Pawns {
|
||||
/// 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, 6, 15, 10, 57, 75, 135, 258 };
|
||||
void init() {
|
||||
|
||||
static constexpr int Seed[RANK_NB] = { 0, 13, 24, 18, 65, 100, 175, 330 };
|
||||
|
||||
for (int opposed = 0; opposed <= 1; ++opposed)
|
||||
for (int phalanx = 0; phalanx <= 1; ++phalanx)
|
||||
for (Rank r = RANK_2; r < RANK_8; ++r)
|
||||
{
|
||||
int bonus = Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0);
|
||||
Connected[opposed][phalanx][r] = make_score(bonus / 2, bonus >> opposed);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -235,41 +183,46 @@ Entry* probe(const Position& pos) {
|
||||
return e;
|
||||
|
||||
e->key = key;
|
||||
e->score = evaluate<WHITE>(pos, e) - evaluate<BLACK>(pos, e);
|
||||
e->scores[WHITE] = evaluate<WHITE>(pos, e);
|
||||
e->scores[BLACK] = evaluate<BLACK>(pos, e);
|
||||
e->openFiles = popcount(e->semiopenFiles[WHITE] & e->semiopenFiles[BLACK]);
|
||||
e->asymmetry = popcount( (e->passedPawns[WHITE] | e->passedPawns[BLACK])
|
||||
| (e->semiopenFiles[WHITE] ^ e->semiopenFiles[BLACK]));
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
/// Entry::shelter_storm() calculates shelter and storm penalties for the file
|
||||
/// the king is on, as well as the two adjacent files.
|
||||
/// Entry::evaluate_shelter() calculates the shelter bonus and the storm
|
||||
/// penalty for a king, looking at the king file and the two closest files.
|
||||
|
||||
template<Color Us>
|
||||
Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
||||
Value Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
|
||||
constexpr Bitboard BlockRanks = (Us == WHITE ? Rank1BB | Rank2BB : Rank8BB | Rank7BB);
|
||||
|
||||
enum { NoFriendlyPawn, Unblocked, BlockedByPawn, BlockedByKing };
|
||||
|
||||
Bitboard b = pos.pieces(PAWN) & (in_front_bb(Us, rank_of(ksq)) | rank_bb(ksq));
|
||||
Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
|
||||
Bitboard ourPawns = b & pos.pieces(Us);
|
||||
Bitboard theirPawns = b & pos.pieces(Them);
|
||||
Value safety = MaxSafetyBonus;
|
||||
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
|
||||
|
||||
for (File f = center - File(1); f <= center + File(1); ++f)
|
||||
Value safety = (shift<Down>(theirPawns) & (FileABB | FileHBB) & BlockRanks & ksq) ?
|
||||
Value(374) : Value(5);
|
||||
|
||||
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
|
||||
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
||||
{
|
||||
b = ourPawns & file_bb(f);
|
||||
Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
|
||||
int ourRank = b ? relative_rank(Us, backmost_sq(Us, b)) : 0;
|
||||
|
||||
b = theirPawns & file_bb(f);
|
||||
Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
|
||||
b = theirPawns & file_bb(f);
|
||||
int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
|
||||
|
||||
safety -= ShelterWeakness[std::min(f, FILE_H - f)][rkUs]
|
||||
+ StormDanger
|
||||
[f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing :
|
||||
rkUs == RANK_1 ? NoFriendlyPawn :
|
||||
rkThem == rkUs + 1 ? BlockedByPawn : Unblocked]
|
||||
[std::min(f, FILE_H - f)][rkThem];
|
||||
int d = std::min(f, ~f);
|
||||
safety += ShelterStrength[d][ourRank];
|
||||
safety -= (ourRank && (ourRank == theirRank - 1)) ? 66 * (theirRank == RANK_3)
|
||||
: UnblockedStorm[d][theirRank];
|
||||
}
|
||||
|
||||
return safety;
|
||||
@@ -280,33 +233,31 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
||||
/// when king square changes, which is about 20% of total king_safety() calls.
|
||||
|
||||
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;
|
||||
castlingRights[Us] = pos.can_castle(Us);
|
||||
minKingPawnDistance[Us] = 0;
|
||||
int minKingPawnDistance = 0;
|
||||
|
||||
Bitboard pawns = pos.pieces(Us, PAWN);
|
||||
if (pawns)
|
||||
while (!(DistanceRingBB[ksq][minKingPawnDistance[Us]++] & pawns)) {}
|
||||
while (!(DistanceRingBB[ksq][++minKingPawnDistance] & pawns)) {}
|
||||
|
||||
if (relative_rank(Us, ksq) > RANK_4)
|
||||
return make_score(0, -16 * minKingPawnDistance[Us]);
|
||||
|
||||
Value bonus = shelter_storm<Us>(pos, ksq);
|
||||
Value bonus = evaluate_shelter<Us>(pos, ksq);
|
||||
|
||||
// If we can castle use the bonus after the castling if it is bigger
|
||||
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(Us | KING_SIDE))
|
||||
bonus = std::max(bonus, evaluate_shelter<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)));
|
||||
if (pos.can_castle(Us | QUEEN_SIDE))
|
||||
bonus = std::max(bonus, evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1)));
|
||||
|
||||
return make_score(bonus, -16 * minKingPawnDistance[Us]);
|
||||
return make_score(bonus, -16 * minKingPawnDistance);
|
||||
}
|
||||
|
||||
// Explicit template instantiation
|
||||
template Score Entry::do_king_safety<WHITE>(const Position& pos, Square ksq);
|
||||
template Score Entry::do_king_safety<BLACK>(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);
|
||||
|
||||
} // namespace Pawns
|
||||
|
||||
+17
-15
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -32,46 +33,47 @@ namespace Pawns {
|
||||
|
||||
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 passed_pawns(Color c) const { return passedPawns[c]; }
|
||||
int pawn_span(Color c) const { return pawnSpan[c]; }
|
||||
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
|
||||
int weak_unopposed(Color c) const { return weakUnopposed[c]; }
|
||||
int pawn_asymmetry() const { return asymmetry; }
|
||||
int open_files() const { return openFiles; }
|
||||
|
||||
int semiopen_file(Color c, File f) const {
|
||||
return semiopenFiles[c] & (1 << f);
|
||||
}
|
||||
|
||||
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][!!(DarkSquares & s)];
|
||||
return pawnsOnSquares[c][bool(DarkSquares & s)];
|
||||
}
|
||||
|
||||
template<Color Us>
|
||||
Score king_safety(const Position& pos, Square ksq) {
|
||||
return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
|
||||
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos, ksq));
|
||||
Score king_safety(const Position& pos) {
|
||||
return kingSquares[Us] == pos.square<KING>(Us) && castlingRights[Us] == pos.can_castle(Us)
|
||||
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos));
|
||||
}
|
||||
|
||||
template<Color Us>
|
||||
Score do_king_safety(const Position& pos, Square ksq);
|
||||
Score do_king_safety(const Position& pos);
|
||||
|
||||
template<Color Us>
|
||||
Value shelter_storm(const Position& pos, Square ksq);
|
||||
Value evaluate_shelter(const Position& pos, Square ksq);
|
||||
|
||||
Key key;
|
||||
Score score;
|
||||
Score scores[COLOR_NB];
|
||||
Bitboard passedPawns[COLOR_NB];
|
||||
Bitboard pawnAttacks[COLOR_NB];
|
||||
Bitboard pawnAttacksSpan[COLOR_NB];
|
||||
Square kingSquares[COLOR_NB];
|
||||
Score kingSafety[COLOR_NB];
|
||||
int minKingPawnDistance[COLOR_NB];
|
||||
int weakUnopposed[COLOR_NB];
|
||||
int castlingRights[COLOR_NB];
|
||||
int semiopenFiles[COLOR_NB];
|
||||
int pawnSpan[COLOR_NB];
|
||||
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
||||
int asymmetry;
|
||||
int openFiles;
|
||||
};
|
||||
|
||||
typedef HashTable<Entry, 16384> Table;
|
||||
|
||||
-116
@@ -1,116 +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
|
||||
|
||||
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 PLATFORM_H_INCLUDED
|
||||
#define PLATFORM_H_INCLUDED
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
// Disable some silly and noisy warnings from MSVC compiler
|
||||
#pragma warning(disable: 4127) // Conditional expression is constant
|
||||
#pragma warning(disable: 4146) // Unary minus operator applied to unsigned type
|
||||
#pragma warning(disable: 4800) // Forcing value to bool 'true' or 'false'
|
||||
#pragma warning(disable: 4996) // Function _ftime() may be unsafe
|
||||
|
||||
// MSVC does not support <inttypes.h>
|
||||
typedef signed __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
#else
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32 // Linux - Unix
|
||||
|
||||
# include <sys/time.h>
|
||||
|
||||
inline int64_t system_time_to_msec() {
|
||||
timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return t.tv_sec * 1000LL + t.tv_usec / 1000;
|
||||
}
|
||||
|
||||
# include <pthread.h>
|
||||
typedef pthread_mutex_t Lock;
|
||||
typedef pthread_cond_t WaitCondition;
|
||||
typedef pthread_t NativeHandle;
|
||||
typedef void*(*pt_start_fn)(void*);
|
||||
|
||||
# define lock_init(x) pthread_mutex_init(&(x), NULL)
|
||||
# define lock_grab(x) pthread_mutex_lock(&(x))
|
||||
# define lock_release(x) pthread_mutex_unlock(&(x))
|
||||
# define lock_destroy(x) pthread_mutex_destroy(&(x))
|
||||
# define cond_destroy(x) pthread_cond_destroy(&(x))
|
||||
# define cond_init(x) pthread_cond_init(&(x), NULL)
|
||||
# define cond_signal(x) pthread_cond_signal(&(x))
|
||||
# define cond_wait(x,y) pthread_cond_wait(&(x),&(y))
|
||||
# define cond_timedwait(x,y,z) pthread_cond_timedwait(&(x),&(y),z)
|
||||
# define thread_create(x,f,t) pthread_create(&(x),NULL,(pt_start_fn)f,t)
|
||||
# define thread_join(x) pthread_join(x, NULL)
|
||||
|
||||
#else // Windows and MinGW
|
||||
|
||||
# include <sys/timeb.h>
|
||||
|
||||
inline int64_t system_time_to_msec() {
|
||||
_timeb t;
|
||||
_ftime(&t);
|
||||
return t.time * 1000LL + t.millitm;
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
// We use critical sections on Windows to support Windows XP and older versions.
|
||||
// Unfortunately, cond_wait() is racy between lock_release() and WaitForSingleObject()
|
||||
// but apart from this they have the same speed performance of SRW locks.
|
||||
typedef CRITICAL_SECTION Lock;
|
||||
typedef HANDLE WaitCondition;
|
||||
typedef HANDLE NativeHandle;
|
||||
|
||||
// On Windows 95 and 98 parameter lpThreadId may not be null
|
||||
inline DWORD* dwWin9xKludge() { static DWORD dw; return &dw; }
|
||||
|
||||
# define lock_init(x) InitializeCriticalSection(&(x))
|
||||
# define lock_grab(x) EnterCriticalSection(&(x))
|
||||
# define lock_release(x) LeaveCriticalSection(&(x))
|
||||
# define lock_destroy(x) DeleteCriticalSection(&(x))
|
||||
# define cond_init(x) { x = CreateEvent(0, FALSE, FALSE, 0); }
|
||||
# define cond_destroy(x) CloseHandle(x)
|
||||
# define cond_signal(x) SetEvent(x)
|
||||
# define cond_wait(x,y) { lock_release(y); WaitForSingleObject(x, INFINITE); lock_grab(y); }
|
||||
# define cond_timedwait(x,y,z) { lock_release(y); WaitForSingleObject(x,z); lock_grab(y); }
|
||||
# define thread_create(x,f,t) (x = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)f,t,0,dwWin9xKludge()))
|
||||
# define thread_join(x) { WaitForSingleObject(x, INFINITE); CloseHandle(x); }
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef PLATFORM_H_INCLUDED
|
||||
+486
-453
File diff suppressed because it is too large
Load Diff
+119
-128
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -21,28 +22,13 @@
|
||||
#define POSITION_H_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef> // For offsetof()
|
||||
#include <deque>
|
||||
#include <memory> // For std::unique_ptr
|
||||
#include <string>
|
||||
|
||||
#include "bitboard.h"
|
||||
#include "types.h"
|
||||
|
||||
class Position;
|
||||
struct Thread;
|
||||
|
||||
/// CheckInfo struct is initialized at c'tor time and keeps info used to detect
|
||||
/// if a move gives check.
|
||||
|
||||
struct CheckInfo {
|
||||
|
||||
explicit CheckInfo(const Position&);
|
||||
|
||||
Bitboard dcCandidates;
|
||||
Bitboard pinned;
|
||||
Bitboard checkSq[PIECE_TYPE_NB];
|
||||
Square ksq;
|
||||
};
|
||||
|
||||
|
||||
/// StateInfo struct stores information needed to restore a Position object to
|
||||
/// its previous state when we retract a move. Whenever a move is made on the
|
||||
@@ -57,43 +43,42 @@ struct StateInfo {
|
||||
int castlingRights;
|
||||
int rule50;
|
||||
int pliesFromNull;
|
||||
Score psq;
|
||||
Square epSquare;
|
||||
|
||||
// Not copied when making a move
|
||||
// Not copied when making a move (will be recomputed anyhow)
|
||||
Key key;
|
||||
Bitboard checkersBB;
|
||||
PieceType capturedType;
|
||||
Piece capturedPiece;
|
||||
StateInfo* previous;
|
||||
Bitboard blockersForKing[COLOR_NB];
|
||||
Bitboard pinners[COLOR_NB];
|
||||
Bitboard checkSquares[PIECE_TYPE_NB];
|
||||
};
|
||||
|
||||
|
||||
/// When making a move the current StateInfo up to 'key' excluded is copied to
|
||||
/// the new one. Here we calculate the quad words (64 bit) needed to be copied.
|
||||
const size_t StateCopySize64 = offsetof(StateInfo, key) / sizeof(uint64_t) + 1;
|
||||
/// A list to keep track of the position states along the setup moves (from the
|
||||
/// start position to the position just before the search starts). Needed by
|
||||
/// 'draw by repetition' detection. Use a std::deque because pointers to
|
||||
/// elements are not invalidated upon list resizing.
|
||||
typedef std::unique_ptr<std::deque<StateInfo>> StateListPtr;
|
||||
|
||||
|
||||
/// Position class stores information regarding the board representation as
|
||||
/// pieces, side to move, hash keys, castling info, etc. Important methods are
|
||||
/// do_move() and undo_move(), used by the search to update node info when
|
||||
/// traversing the search tree.
|
||||
class Thread;
|
||||
|
||||
class Position {
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&, const Position&);
|
||||
|
||||
Position(const Position&); // Disable the default copy constructor
|
||||
|
||||
public:
|
||||
static void init();
|
||||
|
||||
Position() {} // To define the global object RootPos
|
||||
Position(const Position& pos, Thread* th) { *this = pos; thisThread = th; }
|
||||
Position(const std::string& f, bool c960, Thread* th) { set(f, c960, th); }
|
||||
Position& operator=(const Position&); // To assign RootPos from UCI
|
||||
Position() = default;
|
||||
Position(const Position&) = delete;
|
||||
Position& operator=(const Position&) = delete;
|
||||
|
||||
// FEN string input/output
|
||||
void set(const std::string& fenStr, bool isChess960, Thread* th);
|
||||
Position& set(const std::string& fenStr, bool isChess960, StateInfo* si, Thread* th);
|
||||
Position& set(const std::string& code, Color c, StateInfo* si);
|
||||
const std::string fen() const;
|
||||
|
||||
// Position representation
|
||||
@@ -104,11 +89,12 @@ public:
|
||||
Bitboard pieces(Color c, PieceType pt) const;
|
||||
Bitboard pieces(Color c, PieceType pt1, PieceType pt2) const;
|
||||
Piece piece_on(Square s) const;
|
||||
Square king_square(Color c) const;
|
||||
Square ep_square() const;
|
||||
bool empty(Square s) const;
|
||||
template<PieceType Pt> int count(Color c) const;
|
||||
template<PieceType Pt> const Square* list(Color c) const;
|
||||
template<PieceType Pt> int count() const;
|
||||
template<PieceType Pt> const Square* squares(Color c) const;
|
||||
template<PieceType Pt> Square square(Color c) const;
|
||||
|
||||
// Castling
|
||||
int can_castle(Color c) const;
|
||||
@@ -118,99 +104,101 @@ public:
|
||||
|
||||
// Checking
|
||||
Bitboard checkers() const;
|
||||
Bitboard discovered_check_candidates() const;
|
||||
Bitboard pinned_pieces(Color c) const;
|
||||
Bitboard blockers_for_king(Color c) const;
|
||||
Bitboard check_squares(PieceType pt) const;
|
||||
|
||||
// Attacks to/from a given square
|
||||
Bitboard attackers_to(Square s) const;
|
||||
Bitboard attackers_to(Square s, Bitboard occupied) const;
|
||||
Bitboard attacks_from(Piece pc, Square s) const;
|
||||
Bitboard attacks_from(PieceType pt, Square s) const;
|
||||
template<PieceType> Bitboard attacks_from(Square s) const;
|
||||
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||
Bitboard slider_blockers(Bitboard sliders, Square s, Bitboard& pinners) const;
|
||||
|
||||
// Properties of moves
|
||||
bool legal(Move m, Bitboard pinned) const;
|
||||
bool legal(Move m) const;
|
||||
bool pseudo_legal(const Move m) const;
|
||||
bool capture(Move m) const;
|
||||
bool capture_or_promotion(Move m) const;
|
||||
bool gives_check(Move m, const CheckInfo& ci) const;
|
||||
bool gives_check(Move m) const;
|
||||
bool advanced_pawn_push(Move m) const;
|
||||
Piece moved_piece(Move m) const;
|
||||
PieceType captured_piece_type() const;
|
||||
Piece captured_piece() const;
|
||||
|
||||
// Piece specific
|
||||
bool pawn_passed(Color c, Square s) const;
|
||||
bool pawn_on_7th(Color c) const;
|
||||
bool opposite_bishops() const;
|
||||
|
||||
// Doing and undoing moves
|
||||
void do_move(Move m, StateInfo& st);
|
||||
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
||||
void do_move(Move m, StateInfo& newSt);
|
||||
void do_move(Move m, StateInfo& newSt, bool givesCheck);
|
||||
void undo_move(Move m);
|
||||
void do_null_move(StateInfo& st);
|
||||
void do_null_move(StateInfo& newSt);
|
||||
void undo_null_move();
|
||||
|
||||
// Static exchange evaluation
|
||||
Value see(Move m) const;
|
||||
Value see_sign(Move m) const;
|
||||
// Static Exchange Evaluation
|
||||
bool see_ge(Move m, Value threshold = VALUE_ZERO) const;
|
||||
|
||||
// Accessing hash keys
|
||||
Key key() const;
|
||||
Key key_after(Move m) const;
|
||||
Key exclusion_key() const;
|
||||
Key material_key() const;
|
||||
Key pawn_key() const;
|
||||
|
||||
// Other properties of the position
|
||||
Color side_to_move() const;
|
||||
Phase game_phase() const;
|
||||
int game_ply() const;
|
||||
bool is_chess960() const;
|
||||
Thread* this_thread() const;
|
||||
uint64_t nodes_searched() const;
|
||||
void set_nodes_searched(uint64_t n);
|
||||
bool is_draw() const;
|
||||
bool is_draw(int ply) const;
|
||||
bool has_game_cycle(int ply) const;
|
||||
bool has_repeated() const;
|
||||
int rule50_count() const;
|
||||
Score psq_score() const;
|
||||
Value non_pawn_material(Color c) const;
|
||||
Value non_pawn_material() const;
|
||||
|
||||
// Position consistency check, for debugging
|
||||
bool pos_is_ok(int* step = NULL) const;
|
||||
bool pos_is_ok() const;
|
||||
void flip();
|
||||
|
||||
private:
|
||||
// Initialization helpers (used while setting up a position)
|
||||
void clear();
|
||||
void set_castling_right(Color c, Square rfrom);
|
||||
void set_state(StateInfo* si) const;
|
||||
void set_check_info(StateInfo* si) const;
|
||||
|
||||
// Other helpers
|
||||
Bitboard check_blockers(Color c, Color kingColor) const;
|
||||
void put_piece(Square s, Color c, PieceType pt);
|
||||
void remove_piece(Square s, Color c, PieceType pt);
|
||||
void move_piece(Square from, Square to, Color c, PieceType pt);
|
||||
void put_piece(Piece pc, Square s);
|
||||
void remove_piece(Piece pc, Square s);
|
||||
void move_piece(Piece pc, Square from, Square to);
|
||||
template<bool Do>
|
||||
void do_castling(Square from, Square& to, Square& rfrom, Square& rto);
|
||||
void do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto);
|
||||
|
||||
// Data members
|
||||
Piece board[SQUARE_NB];
|
||||
Bitboard byTypeBB[PIECE_TYPE_NB];
|
||||
Bitboard byColorBB[COLOR_NB];
|
||||
int pieceCount[COLOR_NB][PIECE_TYPE_NB];
|
||||
Square pieceList[COLOR_NB][PIECE_TYPE_NB][16];
|
||||
int pieceCount[PIECE_NB];
|
||||
Square pieceList[PIECE_NB][16];
|
||||
int index[SQUARE_NB];
|
||||
int castlingRightsMask[SQUARE_NB];
|
||||
Square castlingRookSquare[CASTLING_RIGHT_NB];
|
||||
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
||||
StateInfo startState;
|
||||
uint64_t nodes;
|
||||
int gamePly;
|
||||
Color sideToMove;
|
||||
Score psq;
|
||||
Thread* thisThread;
|
||||
StateInfo* st;
|
||||
bool chess960;
|
||||
};
|
||||
|
||||
namespace PSQT {
|
||||
extern Score psq[PIECE_NB][SQUARE_NB];
|
||||
}
|
||||
|
||||
extern std::ostream& operator<<(std::ostream& os, const Position& pos);
|
||||
|
||||
inline Color Position::side_to_move() const {
|
||||
return sideToMove;
|
||||
}
|
||||
@@ -252,15 +240,20 @@ inline Bitboard Position::pieces(Color c, PieceType pt1, PieceType pt2) const {
|
||||
}
|
||||
|
||||
template<PieceType Pt> inline int Position::count(Color c) const {
|
||||
return pieceCount[c][Pt];
|
||||
return pieceCount[make_piece(c, Pt)];
|
||||
}
|
||||
|
||||
template<PieceType Pt> inline const Square* Position::list(Color c) const {
|
||||
return pieceList[c][Pt];
|
||||
template<PieceType Pt> inline int Position::count() const {
|
||||
return pieceCount[make_piece(WHITE, Pt)] + pieceCount[make_piece(BLACK, Pt)];
|
||||
}
|
||||
|
||||
inline Square Position::king_square(Color c) const {
|
||||
return pieceList[c][KING][0];
|
||||
template<PieceType Pt> inline const Square* Position::squares(Color c) const {
|
||||
return pieceList[make_piece(c, Pt)];
|
||||
}
|
||||
|
||||
template<PieceType Pt> inline Square Position::square(Color c) const {
|
||||
assert(pieceCount[make_piece(c, Pt)] == 1);
|
||||
return pieceList[make_piece(c, Pt)][0];
|
||||
}
|
||||
|
||||
inline Square Position::ep_square() const {
|
||||
@@ -285,18 +278,19 @@ inline Square Position::castling_rook_square(CastlingRight cr) const {
|
||||
|
||||
template<PieceType Pt>
|
||||
inline Bitboard Position::attacks_from(Square s) const {
|
||||
assert(Pt != PAWN);
|
||||
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
||||
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
||||
: StepAttacksBB[Pt][s];
|
||||
: PseudoAttacks[Pt][s];
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
||||
return StepAttacksBB[make_piece(c, PAWN)][s];
|
||||
return PawnAttacks[c][s];
|
||||
}
|
||||
|
||||
inline Bitboard Position::attacks_from(Piece pc, Square s) const {
|
||||
return attacks_bb(pc, s, byTypeBB[ALL_PIECES]);
|
||||
inline Bitboard Position::attacks_from(PieceType pt, Square s) const {
|
||||
return attacks_bb(pt, s, byTypeBB[ALL_PIECES]);
|
||||
}
|
||||
|
||||
inline Bitboard Position::attackers_to(Square s) const {
|
||||
@@ -307,12 +301,12 @@ inline Bitboard Position::checkers() const {
|
||||
return st->checkersBB;
|
||||
}
|
||||
|
||||
inline Bitboard Position::discovered_check_candidates() const {
|
||||
return check_blockers(sideToMove, ~sideToMove);
|
||||
inline Bitboard Position::blockers_for_king(Color c) const {
|
||||
return st->blockersForKing[c];
|
||||
}
|
||||
|
||||
inline Bitboard Position::pinned_pieces(Color c) const {
|
||||
return check_blockers(c, c);
|
||||
inline Bitboard Position::check_squares(PieceType pt) const {
|
||||
return st->checkSquares[pt];
|
||||
}
|
||||
|
||||
inline bool Position::pawn_passed(Color c, Square s) const {
|
||||
@@ -337,13 +331,17 @@ inline Key Position::material_key() const {
|
||||
}
|
||||
|
||||
inline Score Position::psq_score() const {
|
||||
return st->psq;
|
||||
return psq;
|
||||
}
|
||||
|
||||
inline Value Position::non_pawn_material(Color c) const {
|
||||
return st->nonPawnMaterial[c];
|
||||
}
|
||||
|
||||
inline Value Position::non_pawn_material() const {
|
||||
return st->nonPawnMaterial[WHITE] + st->nonPawnMaterial[BLACK];
|
||||
}
|
||||
|
||||
inline int Position::game_ply() const {
|
||||
return gamePly;
|
||||
}
|
||||
@@ -352,22 +350,10 @@ inline int Position::rule50_count() const {
|
||||
return st->rule50;
|
||||
}
|
||||
|
||||
inline uint64_t Position::nodes_searched() const {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
inline void Position::set_nodes_searched(uint64_t n) {
|
||||
nodes = n;
|
||||
}
|
||||
|
||||
inline bool Position::opposite_bishops() const {
|
||||
return pieceCount[WHITE][BISHOP] == 1
|
||||
&& pieceCount[BLACK][BISHOP] == 1
|
||||
&& opposite_colors(pieceList[WHITE][BISHOP][0], pieceList[BLACK][BISHOP][0]);
|
||||
}
|
||||
|
||||
inline bool Position::pawn_on_7th(Color c) const {
|
||||
return pieces(c, PAWN) & rank_bb(relative_rank(c, RANK_7));
|
||||
return pieceCount[W_BISHOP] == 1
|
||||
&& pieceCount[B_BISHOP] == 1
|
||||
&& opposite_colors(square<BISHOP>(WHITE), square<BISHOP>(BLACK));
|
||||
}
|
||||
|
||||
inline bool Position::is_chess960() const {
|
||||
@@ -375,66 +361,71 @@ inline bool Position::is_chess960() const {
|
||||
}
|
||||
|
||||
inline bool Position::capture_or_promotion(Move m) const {
|
||||
|
||||
assert(is_ok(m));
|
||||
return type_of(m) != NORMAL ? type_of(m) != CASTLING : !empty(to_sq(m));
|
||||
}
|
||||
|
||||
inline bool Position::capture(Move m) const {
|
||||
|
||||
// Castling is encoded as "king captures the rook"
|
||||
assert(is_ok(m));
|
||||
// Castling is encoded as "king captures rook"
|
||||
return (!empty(to_sq(m)) && type_of(m) != CASTLING) || type_of(m) == ENPASSANT;
|
||||
}
|
||||
|
||||
inline PieceType Position::captured_piece_type() const {
|
||||
return st->capturedType;
|
||||
inline Piece Position::captured_piece() const {
|
||||
return st->capturedPiece;
|
||||
}
|
||||
|
||||
inline Thread* Position::this_thread() const {
|
||||
return thisThread;
|
||||
}
|
||||
|
||||
inline void Position::put_piece(Square s, Color c, PieceType pt) {
|
||||
inline void Position::put_piece(Piece pc, Square s) {
|
||||
|
||||
board[s] = make_piece(c, pt);
|
||||
board[s] = pc;
|
||||
byTypeBB[ALL_PIECES] |= s;
|
||||
byTypeBB[pt] |= s;
|
||||
byColorBB[c] |= s;
|
||||
index[s] = pieceCount[c][pt]++;
|
||||
pieceList[c][pt][index[s]] = s;
|
||||
pieceCount[c][ALL_PIECES]++;
|
||||
byTypeBB[type_of(pc)] |= s;
|
||||
byColorBB[color_of(pc)] |= s;
|
||||
index[s] = pieceCount[pc]++;
|
||||
pieceList[pc][index[s]] = s;
|
||||
pieceCount[make_piece(color_of(pc), ALL_PIECES)]++;
|
||||
psq += PSQT::psq[pc][s];
|
||||
}
|
||||
|
||||
inline void Position::move_piece(Square from, Square to, Color c, PieceType pt) {
|
||||
|
||||
// index[from] is not updated and becomes stale. This works as long as index[]
|
||||
// is accessed just by known occupied squares.
|
||||
Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to];
|
||||
byTypeBB[ALL_PIECES] ^= from_to_bb;
|
||||
byTypeBB[pt] ^= from_to_bb;
|
||||
byColorBB[c] ^= from_to_bb;
|
||||
board[from] = NO_PIECE;
|
||||
board[to] = make_piece(c, pt);
|
||||
index[to] = index[from];
|
||||
pieceList[c][pt][index[to]] = to;
|
||||
}
|
||||
|
||||
inline void Position::remove_piece(Square s, Color c, PieceType pt) {
|
||||
inline void Position::remove_piece(Piece pc, Square s) {
|
||||
|
||||
// WARNING: This is not a reversible operation. If we remove a piece in
|
||||
// do_move() and then replace it in undo_move() we will put it at the end of
|
||||
// the list and not in its original place, it means index[] and pieceList[]
|
||||
// are not guaranteed to be invariant to a do_move() + undo_move() sequence.
|
||||
// are not invariant to a do_move() + undo_move() sequence.
|
||||
byTypeBB[ALL_PIECES] ^= s;
|
||||
byTypeBB[pt] ^= s;
|
||||
byColorBB[c] ^= s;
|
||||
byTypeBB[type_of(pc)] ^= s;
|
||||
byColorBB[color_of(pc)] ^= s;
|
||||
/* board[s] = NO_PIECE; Not needed, overwritten by the capturing one */
|
||||
Square lastSquare = pieceList[c][pt][--pieceCount[c][pt]];
|
||||
Square lastSquare = pieceList[pc][--pieceCount[pc]];
|
||||
index[lastSquare] = index[s];
|
||||
pieceList[c][pt][index[lastSquare]] = lastSquare;
|
||||
pieceList[c][pt][pieceCount[c][pt]] = SQ_NONE;
|
||||
pieceCount[c][ALL_PIECES]--;
|
||||
pieceList[pc][index[lastSquare]] = lastSquare;
|
||||
pieceList[pc][pieceCount[pc]] = SQ_NONE;
|
||||
pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
|
||||
psq -= PSQT::psq[pc][s];
|
||||
}
|
||||
|
||||
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[]
|
||||
// is accessed just by known occupied squares.
|
||||
Bitboard fromTo = SquareBB[from] ^ SquareBB[to];
|
||||
byTypeBB[ALL_PIECES] ^= fromTo;
|
||||
byTypeBB[type_of(pc)] ^= fromTo;
|
||||
byColorBB[color_of(pc)] ^= fromTo;
|
||||
board[from] = NO_PIECE;
|
||||
board[to] = pc;
|
||||
index[to] = index[from];
|
||||
pieceList[pc][index[to]] = to;
|
||||
psq += PSQT::psq[pc][to] - PSQT::psq[pc][from];
|
||||
}
|
||||
|
||||
inline void Position::do_move(Move m, StateInfo& newSt) {
|
||||
do_move(m, newSt, gives_check(m));
|
||||
}
|
||||
|
||||
#endif // #ifndef POSITION_H_INCLUDED
|
||||
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
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-2019 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/>.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
Value PieceValue[PHASE_NB][PIECE_NB] = {
|
||||
{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg },
|
||||
{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg }
|
||||
};
|
||||
|
||||
namespace PSQT {
|
||||
|
||||
#define S(mg, eg) make_score(mg, eg)
|
||||
|
||||
// Bonus[PieceType][Square / 2] contains Piece-Square scores. For each piece
|
||||
// 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
|
||||
// second half of the files.
|
||||
constexpr Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
||||
{ },
|
||||
{ // Pawn
|
||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
||||
{ S(-11,-3), S( 7, -1), S( 7, 7), S(17, 2) },
|
||||
{ S(-16,-2), S( -3, 2), S( 23, 6), S(23,-1) },
|
||||
{ S(-14, 7), S( -7, -4), S( 20,-8), S(24, 2) },
|
||||
{ S( -5,13), S( -2, 10), S( -1,-1), S(12,-8) },
|
||||
{ S(-11,16), S(-12, 6), S( -2, 1), S( 4,16) },
|
||||
{ S( -2, 1), S( 20,-12), S(-10, 6), S(-2,25) }
|
||||
},
|
||||
{ // Knight
|
||||
{ S(-169,-105), S(-96,-74), S(-80,-46), S(-79,-18) },
|
||||
{ S( -79, -70), S(-39,-56), S(-24,-15), S( -9, 6) },
|
||||
{ S( -64, -38), S(-20,-33), S( 4, -5), S( 19, 27) },
|
||||
{ S( -28, -36), S( 5, 0), S( 41, 13), S( 47, 34) },
|
||||
{ S( -29, -41), S( 13,-20), S( 42, 4), S( 52, 35) },
|
||||
{ S( -11, -51), S( 28,-38), S( 63,-17), S( 55, 19) },
|
||||
{ S( -67, -64), S(-21,-45), S( 6,-37), S( 37, 16) },
|
||||
{ S(-200, -98), S(-80,-89), S(-53,-53), S(-32,-16) }
|
||||
},
|
||||
{ // Bishop
|
||||
{ S(-49,-58), S(- 7,-31), S(-10,-37), S(-34,-19) },
|
||||
{ S(-24,-34), S( 9, -9), S( 15,-14), S( 1, 4) },
|
||||
{ S( -9,-23), S( 22, 0), S( -3, -3), S( 12, 16) },
|
||||
{ S( 4,-26), S( 9, -3), S( 18, -5), S( 40, 16) },
|
||||
{ S( -8,-26), S( 27, -4), S( 13, -7), S( 30, 14) },
|
||||
{ S(-17,-24), S( 14, -2), S( -6, 0), S( 6, 13) },
|
||||
{ S(-19,-34), S(-13,-10), S( 7,-12), S(-11, 6) },
|
||||
{ S(-47,-55), S( -7,-32), S(-17,-36), S(-29,-17) }
|
||||
},
|
||||
{ // Rook
|
||||
{ S(-24, 0), S(-15, 3), S( -8, 0), S( 0, 3) },
|
||||
{ S(-18,-7), S( -5,-5), S( -1,-5), S( 1,-1) },
|
||||
{ S(-19, 6), S(-10,-7), S( 1, 3), S( 0, 3) },
|
||||
{ S(-21, 0), S( -7, 4), S( -4,-2), S(-4, 1) },
|
||||
{ S(-21,-7), S(-12, 5), S( -1,-5), S( 4,-7) },
|
||||
{ S(-23, 3), S(-10, 2), S( 1,-1), S( 6, 3) },
|
||||
{ S(-11,-1), S( 8, 7), S( 9,11), S(12,-1) },
|
||||
{ S(-25, 6), S(-18, 4), S(-11, 6), S( 2, 2) }
|
||||
},
|
||||
{ // Queen
|
||||
{ S( 3,-69), S(-5,-57), S(-5,-47), S( 4,-26) },
|
||||
{ S( -3,-55), S( 5,-31), S( 8,-22), S(12, -4) },
|
||||
{ S( -3,-39), S( 6,-18), S(13, -9), S( 7, 3) },
|
||||
{ S( 4,-23), S( 5, -3), S( 9, 13), S( 8, 24) },
|
||||
{ S( 0,-29), S(14, -6), S(12, 9), S( 5, 21) },
|
||||
{ S( -4,-38), S(10,-18), S( 6,-12), S( 8, 1) },
|
||||
{ S( -5,-50), S( 6,-27), S(10,-24), S( 8, -8) },
|
||||
{ S( -2,-75), S(-2,-52), S( 1,-43), S(-2,-36) }
|
||||
},
|
||||
{ // King
|
||||
{ S(272, 0), S(325, 41), S(273, 80), S(190, 93) },
|
||||
{ S(277, 57), S(305, 98), S(241,138), S(183,131) },
|
||||
{ S(198, 86), S(253,138), S(168,165), S(120,173) },
|
||||
{ S(169,103), S(191,152), S(136,168), S(108,169) },
|
||||
{ S(145, 98), S(176,166), S(112,197), S(69, 194) },
|
||||
{ S(122, 87), S(159,164), S(85, 174), S(36, 189) },
|
||||
{ S(87, 40), S(120, 99), S(64, 128), S(25, 141) },
|
||||
{ S(64, 5), S(87, 60), S(49, 75), S(0, 75) }
|
||||
}
|
||||
};
|
||||
|
||||
#undef S
|
||||
|
||||
Score psq[PIECE_NB][SQUARE_NB];
|
||||
|
||||
// init() initializes piece-square tables: the white halves of the tables are
|
||||
// copied from Bonus[] adding the piece value, then the black halves of the
|
||||
// tables are initialized by flipping and changing the sign of the white scores.
|
||||
void init() {
|
||||
|
||||
for (Piece pc = W_PAWN; pc <= W_KING; ++pc)
|
||||
{
|
||||
PieceValue[MG][~pc] = PieceValue[MG][pc];
|
||||
PieceValue[EG][~pc] = PieceValue[EG][pc];
|
||||
|
||||
Score score = make_score(PieceValue[MG][pc], PieceValue[EG][pc]);
|
||||
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
{
|
||||
File f = std::min(file_of(s), ~file_of(s));
|
||||
psq[ pc][ s] = score + Bonus[pc][rank_of(s)][f];
|
||||
psq[~pc][~s] = -psq[pc][s];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace PSQT
|
||||
@@ -1,98 +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
|
||||
|
||||
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 PSQTAB_H_INCLUDED
|
||||
#define PSQTAB_H_INCLUDED
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define S(mg, eg) make_score(mg, eg)
|
||||
|
||||
|
||||
/// PSQT[PieceType][Square] contains Piece-Square scores. For each piece type on
|
||||
/// a given square a (middlegame, endgame) score pair is assigned. PSQT is defined
|
||||
/// for the white side and the tables are symmetric for the black side.
|
||||
|
||||
static const Score PSQT[][SQUARE_NB] = {
|
||||
{ },
|
||||
{ // Pawn
|
||||
S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S(0, 0), S( 0, 0), S( 0, 0), S( 0, 0),
|
||||
S(-20, 0), S( 0, 0), S( 0, 0), S( 0, 0), S(0, 0), S( 0, 0), S( 0, 0), S(-20, 0),
|
||||
S(-20, 0), S( 0, 0), S(10, 0), S(20, 0), S(20, 0), S(10, 0), S( 0, 0), S(-20, 0),
|
||||
S(-20, 0), S( 0, 0), S(20, 0), S(40, 0), S(40, 0), S(20, 0), S( 0, 0), S(-20, 0),
|
||||
S(-20, 0), S( 0, 0), S(10, 0), S(20, 0), S(20, 0), S(10, 0), S( 0, 0), S(-20, 0),
|
||||
S(-20, 0), S( 0, 0), S( 0, 0), S( 0, 0), S(0, 0), S( 0, 0), S( 0, 0), S(-20, 0),
|
||||
S(-20, 0), S( 0, 0), S( 0, 0), S( 0, 0), S(0, 0), S( 0, 0), S( 0, 0), S(-20, 0),
|
||||
S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S(0, 0), S( 0, 0), S( 0, 0), S( 0, 0)
|
||||
},
|
||||
{ // Knight
|
||||
S(-144,-98), S(-109,-83), S(-85,-51), S(-73,-16), S(-73,-16), S(-85,-51), S(-109,-83), S(-144,-98),
|
||||
S( -88,-68), S( -43,-53), S(-19,-21), S( -7, 14), S( -7, 14), S(-19,-21), S( -43,-53), S( -88,-68),
|
||||
S( -69,-53), S( -24,-38), S( 0, -6), S( 12, 29), S( 12, 29), S( 0, -6), S( -24,-38), S( -69,-53),
|
||||
S( -28,-42), S( 17,-27), S( 41, 5), S( 53, 40), S( 53, 40), S( 41, 5), S( 17,-27), S( -28,-42),
|
||||
S( -30,-42), S( 15,-27), S( 39, 5), S( 51, 40), S( 51, 40), S( 39, 5), S( 15,-27), S( -30,-42),
|
||||
S( -10,-53), S( 35,-38), S( 59, -6), S( 71, 29), S( 71, 29), S( 59, -6), S( 35,-38), S( -10,-53),
|
||||
S( -64,-68), S( -19,-53), S( 5,-21), S( 17, 14), S( 17, 14), S( 5,-21), S( -19,-53), S( -64,-68),
|
||||
S(-200,-98), S( -65,-83), S(-41,-51), S(-29,-16), S(-29,-16), S(-41,-51), S( -65,-83), S(-200,-98)
|
||||
},
|
||||
{ // Bishop
|
||||
S(-54,-65), S(-27,-42), S(-34,-44), S(-43,-26), S(-43,-26), S(-34,-44), S(-27,-42), S(-54,-65),
|
||||
S(-29,-43), S( 8,-20), S( 1,-22), S( -8, -4), S( -8, -4), S( 1,-22), S( 8,-20), S(-29,-43),
|
||||
S(-20,-33), S( 17,-10), S( 10,-12), S( 1, 6), S( 1, 6), S( 10,-12), S( 17,-10), S(-20,-33),
|
||||
S(-19,-35), S( 18,-12), S( 11,-14), S( 2, 4), S( 2, 4), S( 11,-14), S( 18,-12), S(-19,-35),
|
||||
S(-22,-35), S( 15,-12), S( 8,-14), S( -1, 4), S( -1, 4), S( 8,-14), S( 15,-12), S(-22,-35),
|
||||
S(-28,-33), S( 9,-10), S( 2,-12), S( -7, 6), S( -7, 6), S( 2,-12), S( 9,-10), S(-28,-33),
|
||||
S(-32,-43), S( 5,-20), S( -2,-22), S(-11, -4), S(-11, -4), S( -2,-22), S( 5,-20), S(-32,-43),
|
||||
S(-49,-65), S(-22,-42), S(-29,-44), S(-38,-26), S(-38,-26), S(-29,-44), S(-22,-42), S(-49,-65)
|
||||
},
|
||||
{ // Rook
|
||||
S(-22, 3), S(-17, 3), S(-12, 3), S(-8, 3), S(-8, 3), S(-12, 3), S(-17, 3), S(-22, 3),
|
||||
S(-22, 3), S( -7, 3), S( -2, 3), S( 2, 3), S( 2, 3), S( -2, 3), S( -7, 3), S(-22, 3),
|
||||
S(-22, 3), S( -7, 3), S( -2, 3), S( 2, 3), S( 2, 3), S( -2, 3), S( -7, 3), S(-22, 3),
|
||||
S(-22, 3), S( -7, 3), S( -2, 3), S( 2, 3), S( 2, 3), S( -2, 3), S( -7, 3), S(-22, 3),
|
||||
S(-22, 3), S( -7, 3), S( -2, 3), S( 2, 3), S( 2, 3), S( -2, 3), S( -7, 3), S(-22, 3),
|
||||
S(-22, 3), S( -7, 3), S( -2, 3), S( 2, 3), S( 2, 3), S( -2, 3), S( -7, 3), S(-22, 3),
|
||||
S(-11, 3), S( 4, 3), S( 9, 3), S(13, 3), S(13, 3), S( 9, 3), S( 4, 3), S(-11, 3),
|
||||
S(-22, 3), S(-17, 3), S(-12, 3), S(-8, 3), S(-8, 3), S(-12, 3), S(-17, 3), S(-22, 3)
|
||||
},
|
||||
{ // Queen
|
||||
S(-2,-80), S(-2,-54), S(-2,-42), S(-2,-30), S(-2,-30), S(-2,-42), S(-2,-54), S(-2,-80),
|
||||
S(-2,-54), S( 8,-30), S( 8,-18), S( 8, -6), S( 8, -6), S( 8,-18), S( 8,-30), S(-2,-54),
|
||||
S(-2,-42), S( 8,-18), S( 8, -6), S( 8, 6), S( 8, 6), S( 8, -6), S( 8,-18), S(-2,-42),
|
||||
S(-2,-30), S( 8, -6), S( 8, 6), S( 8, 18), S( 8, 18), S( 8, 6), S( 8, -6), S(-2,-30),
|
||||
S(-2,-30), S( 8, -6), S( 8, 6), S( 8, 18), S( 8, 18), S( 8, 6), S( 8, -6), S(-2,-30),
|
||||
S(-2,-42), S( 8,-18), S( 8, -6), S( 8, 6), S( 8, 6), S( 8, -6), S( 8,-18), S(-2,-42),
|
||||
S(-2,-54), S( 8,-30), S( 8,-18), S( 8, -6), S( 8, -6), S( 8,-18), S( 8,-30), S(-2,-54),
|
||||
S(-2,-80), S(-2,-54), S(-2,-42), S(-2,-30), S(-2,-30), S(-2,-42), S(-2,-54), S(-2,-80)
|
||||
},
|
||||
{ // King
|
||||
S(298, 27), S(332, 81), S(273,108), S(225,116), S(225,116), S(273,108), S(332, 81), S(298, 27),
|
||||
S(287, 74), S(321,128), S(262,155), S(214,163), S(214,163), S(262,155), S(321,128), S(287, 74),
|
||||
S(224,111), S(258,165), S(199,192), S(151,200), S(151,200), S(199,192), S(258,165), S(224,111),
|
||||
S(196,135), S(230,189), S(171,216), S(123,224), S(123,224), S(171,216), S(230,189), S(196,135),
|
||||
S(173,135), S(207,189), S(148,216), S(100,224), S(100,224), S(148,216), S(207,189), S(173,135),
|
||||
S(146,111), S(180,165), S(121,192), S( 73,200), S( 73,200), S(121,192), S(180,165), S(146,111),
|
||||
S(119, 74), S(153,128), S( 94,155), S( 46,163), S( 46,163), S( 94,155), S(153,128), S(119, 74),
|
||||
S( 98, 27), S(132, 81), S( 73,108), S( 25,116), S( 25,116), S( 73,108), S(132, 81), S( 98, 27)
|
||||
}
|
||||
};
|
||||
|
||||
#undef S
|
||||
|
||||
#endif // #ifndef PSQTAB_H_INCLUDED
|
||||
+1073
-1051
File diff suppressed because it is too large
Load Diff
+32
-38
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -20,94 +21,87 @@
|
||||
#ifndef SEARCH_H_INCLUDED
|
||||
#define SEARCH_H_INCLUDED
|
||||
|
||||
#include <memory> // For std::auto_ptr
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
#include "misc.h"
|
||||
#include "position.h"
|
||||
#include "movepick.h"
|
||||
#include "types.h"
|
||||
|
||||
struct SplitPoint;
|
||||
class Position;
|
||||
|
||||
namespace Search {
|
||||
|
||||
/// Threshold used for countermoves based pruning
|
||||
constexpr int CounterMovePruneThreshold = 0;
|
||||
|
||||
|
||||
/// Stack struct keeps track of the information we need to remember from nodes
|
||||
/// shallower and deeper in the tree during the search. Each search thread has
|
||||
/// its own array of Stack objects, indexed by the current ply.
|
||||
|
||||
struct Stack {
|
||||
SplitPoint* splitPoint;
|
||||
Move* pv;
|
||||
PieceToHistory* continuationHistory;
|
||||
int ply;
|
||||
Move currentMove;
|
||||
Move ttMove;
|
||||
Move excludedMove;
|
||||
Move killers[2];
|
||||
Depth reduction;
|
||||
Value staticEval;
|
||||
bool skipEarlyPruning;
|
||||
int statScore;
|
||||
int moveCount;
|
||||
};
|
||||
|
||||
|
||||
/// RootMove struct is used for moves at the root of the tree. For each root move
|
||||
/// we store a score and a PV (really a refutation in the case of moves which
|
||||
/// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves.
|
||||
|
||||
struct RootMove {
|
||||
|
||||
RootMove(Move m) : score(-VALUE_INFINITE), previousScore(-VALUE_INFINITE), pv(1, m) {}
|
||||
|
||||
bool operator<(const RootMove& m) const { return score > m.score; } // Ascending sort
|
||||
explicit RootMove(Move m) : pv(1, m) {}
|
||||
bool extract_ponder_from_tt(Position& pos);
|
||||
bool operator==(const Move& m) const { return pv[0] == m; }
|
||||
void insert_pv_in_tt(Position& pos);
|
||||
Move extract_ponder_from_tt(Position& pos);
|
||||
bool operator<(const RootMove& m) const { // Sort in descending order
|
||||
return m.score != score ? m.score < score
|
||||
: m.previousScore < previousScore;
|
||||
}
|
||||
|
||||
Value score;
|
||||
Value previousScore;
|
||||
Value score = -VALUE_INFINITE;
|
||||
Value previousScore = -VALUE_INFINITE;
|
||||
int selDepth = 0;
|
||||
int tbRank;
|
||||
Value tbScore;
|
||||
std::vector<Move> pv;
|
||||
};
|
||||
|
||||
typedef std::vector<RootMove> RootMoveVector;
|
||||
typedef std::vector<RootMove> RootMoves;
|
||||
|
||||
|
||||
/// LimitsType struct stores information sent by GUI about available time to
|
||||
/// search the current move, maximum depth/time, if we are in analysis mode or
|
||||
/// if we have to ponder while it's our opponent's turn to move.
|
||||
/// search the current move, maximum depth/time, or if we are in analysis mode.
|
||||
|
||||
struct LimitsType {
|
||||
|
||||
LimitsType() { // Init explicitly due to broken value-initialization of non POD in MSVC
|
||||
nodes = time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = movestogo =
|
||||
depth = movetime = mate = infinite = ponder = 0;
|
||||
time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0);
|
||||
movestogo = depth = mate = perft = infinite = 0;
|
||||
nodes = 0;
|
||||
}
|
||||
|
||||
bool use_time_management() const {
|
||||
return !(mate | movetime | depth | nodes | infinite);
|
||||
return !(mate | movetime | depth | nodes | perft | infinite);
|
||||
}
|
||||
|
||||
std::vector<Move> searchmoves;
|
||||
int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, movetime, mate, infinite, ponder;
|
||||
TimePoint time[COLOR_NB], inc[COLOR_NB], npmsec, movetime, startTime;
|
||||
int movestogo, depth, mate, perft, infinite;
|
||||
int64_t nodes;
|
||||
};
|
||||
|
||||
/// The SignalsType struct stores volatile flags updated during the search
|
||||
/// typically in an async fashion e.g. to stop the search by the GUI.
|
||||
|
||||
struct SignalsType {
|
||||
bool stop, stopOnPonderhit, firstRootMove, failedLowAtRoot;
|
||||
};
|
||||
|
||||
typedef std::auto_ptr<std::stack<StateInfo> > StateStackPtr;
|
||||
|
||||
extern volatile SignalsType Signals;
|
||||
extern LimitsType Limits;
|
||||
extern RootMoveVector RootMoves;
|
||||
extern Position RootPos;
|
||||
extern Time::point SearchTime;
|
||||
extern StateStackPtr SetupStates;
|
||||
|
||||
void init();
|
||||
void think();
|
||||
template<bool Root> uint64_t perft(Position& pos, Depth depth);
|
||||
void clear();
|
||||
|
||||
} // namespace Search
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2011-2013 Ronald de Man
|
||||
*/
|
||||
|
||||
#ifndef TBCORE_H
|
||||
#define TBCORE_H
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pthread.h>
|
||||
#define SEP_CHAR ':'
|
||||
#define FD int
|
||||
#define FD_ERR -1
|
||||
#else
|
||||
#include <windows.h>
|
||||
#define SEP_CHAR ';'
|
||||
#define FD HANDLE
|
||||
#define FD_ERR INVALID_HANDLE_VALUE
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#define LOCK_T pthread_mutex_t
|
||||
#define LOCK_INIT(x) pthread_mutex_init(&(x), NULL)
|
||||
#define LOCK(x) pthread_mutex_lock(&(x))
|
||||
#define UNLOCK(x) pthread_mutex_unlock(&(x))
|
||||
#else
|
||||
#define LOCK_T HANDLE
|
||||
#define LOCK_INIT(x) do { x = CreateMutex(NULL, FALSE, NULL); } while (0)
|
||||
#define LOCK(x) WaitForSingleObject(x, INFINITE)
|
||||
#define UNLOCK(x) ReleaseMutex(x)
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define BSWAP32(v) __builtin_bswap32(v)
|
||||
#define BSWAP64(v) __builtin_bswap64(v)
|
||||
#else
|
||||
#define BSWAP32(v) _byteswap_ulong(v)
|
||||
#define BSWAP64(v) _byteswap_uint64(v)
|
||||
#endif
|
||||
|
||||
#define WDLSUFFIX ".rtbw"
|
||||
#define DTZSUFFIX ".rtbz"
|
||||
#define WDLDIR "RTBWDIR"
|
||||
#define DTZDIR "RTBZDIR"
|
||||
#define TBPIECES 6
|
||||
|
||||
typedef unsigned long long uint64;
|
||||
typedef unsigned int uint32;
|
||||
typedef unsigned char ubyte;
|
||||
typedef unsigned short ushort;
|
||||
|
||||
const ubyte WDL_MAGIC[4] = { 0x71, 0xe8, 0x23, 0x5d };
|
||||
const ubyte DTZ_MAGIC[4] = { 0xd7, 0x66, 0x0c, 0xa5 };
|
||||
|
||||
#define TBHASHBITS 10
|
||||
|
||||
struct TBHashEntry;
|
||||
|
||||
typedef uint64 base_t;
|
||||
|
||||
struct PairsData {
|
||||
char *indextable;
|
||||
ushort *sizetable;
|
||||
ubyte *data;
|
||||
ushort *offset;
|
||||
ubyte *symlen;
|
||||
ubyte *sympat;
|
||||
int blocksize;
|
||||
int idxbits;
|
||||
int min_len;
|
||||
base_t base[1]; // C++ complains about base[]...
|
||||
};
|
||||
|
||||
struct TBEntry {
|
||||
char *data;
|
||||
uint64 key;
|
||||
uint64 mapping;
|
||||
ubyte ready;
|
||||
ubyte num;
|
||||
ubyte symmetric;
|
||||
ubyte has_pawns;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
__attribute__((__may_alias__))
|
||||
#endif
|
||||
;
|
||||
|
||||
struct TBEntry_piece {
|
||||
char *data;
|
||||
uint64 key;
|
||||
uint64 mapping;
|
||||
ubyte ready;
|
||||
ubyte num;
|
||||
ubyte symmetric;
|
||||
ubyte has_pawns;
|
||||
ubyte enc_type;
|
||||
struct PairsData *precomp[2];
|
||||
int factor[2][TBPIECES];
|
||||
ubyte pieces[2][TBPIECES];
|
||||
ubyte norm[2][TBPIECES];
|
||||
};
|
||||
|
||||
struct TBEntry_pawn {
|
||||
char *data;
|
||||
uint64 key;
|
||||
uint64 mapping;
|
||||
ubyte ready;
|
||||
ubyte num;
|
||||
ubyte symmetric;
|
||||
ubyte has_pawns;
|
||||
ubyte pawns[2];
|
||||
struct {
|
||||
struct PairsData *precomp[2];
|
||||
int factor[2][TBPIECES];
|
||||
ubyte pieces[2][TBPIECES];
|
||||
ubyte norm[2][TBPIECES];
|
||||
} file[4];
|
||||
};
|
||||
|
||||
struct DTZEntry_piece {
|
||||
char *data;
|
||||
uint64 key;
|
||||
uint64 mapping;
|
||||
ubyte ready;
|
||||
ubyte num;
|
||||
ubyte symmetric;
|
||||
ubyte has_pawns;
|
||||
ubyte enc_type;
|
||||
struct PairsData *precomp;
|
||||
int factor[TBPIECES];
|
||||
ubyte pieces[TBPIECES];
|
||||
ubyte norm[TBPIECES];
|
||||
ubyte flags; // accurate, mapped, side
|
||||
ushort map_idx[4];
|
||||
ubyte *map;
|
||||
};
|
||||
|
||||
struct DTZEntry_pawn {
|
||||
char *data;
|
||||
uint64 key;
|
||||
uint64 mapping;
|
||||
ubyte ready;
|
||||
ubyte num;
|
||||
ubyte symmetric;
|
||||
ubyte has_pawns;
|
||||
ubyte pawns[2];
|
||||
struct {
|
||||
struct PairsData *precomp;
|
||||
int factor[TBPIECES];
|
||||
ubyte pieces[TBPIECES];
|
||||
ubyte norm[TBPIECES];
|
||||
} file[4];
|
||||
ubyte flags[4];
|
||||
ushort map_idx[4][4];
|
||||
ubyte *map;
|
||||
};
|
||||
|
||||
struct TBHashEntry {
|
||||
uint64 key;
|
||||
struct TBEntry *ptr;
|
||||
};
|
||||
|
||||
struct DTZTableEntry {
|
||||
uint64 key1;
|
||||
uint64 key2;
|
||||
struct TBEntry *entry;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+1500
-748
File diff suppressed because it is too large
Load Diff
+66
-5
@@ -1,17 +1,78 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (c) 2013 Ronald de Man
|
||||
Copyright (C) 2016-2018 Marco Costalba, Lucas Braesch
|
||||
|
||||
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 TBPROBE_H
|
||||
#define TBPROBE_H
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "../search.h"
|
||||
|
||||
namespace Tablebases {
|
||||
|
||||
enum WDLScore {
|
||||
WDLLoss = -2, // Loss
|
||||
WDLBlessedLoss = -1, // Loss, but draw under 50-move rule
|
||||
WDLDraw = 0, // Draw
|
||||
WDLCursedWin = 1, // Win, but draw under 50-move rule
|
||||
WDLWin = 2, // Win
|
||||
|
||||
WDLScoreNone = -1000
|
||||
};
|
||||
|
||||
// Possible states after a probing operation
|
||||
enum ProbeState {
|
||||
FAIL = 0, // Probe failed (missing file table)
|
||||
OK = 1, // Probe succesful
|
||||
CHANGE_STM = -1, // DTZ should check the other side
|
||||
ZEROING_BEST_MOVE = 2 // Best move zeroes DTZ (capture or pawn move)
|
||||
};
|
||||
|
||||
extern int MaxCardinality;
|
||||
|
||||
void init(const std::string& path);
|
||||
int probe_wdl(Position& pos, int *success);
|
||||
int probe_dtz(Position& pos, int *success);
|
||||
bool root_probe(Position& pos, Search::RootMoveVector& rootMoves, Value& score);
|
||||
bool root_probe_wdl(Position& pos, Search::RootMoveVector& rootMoves, Value& score);
|
||||
void init(const std::string& paths);
|
||||
WDLScore probe_wdl(Position& pos, ProbeState* result);
|
||||
int probe_dtz(Position& pos, ProbeState* result);
|
||||
bool root_probe(Position& pos, Search::RootMoves& rootMoves);
|
||||
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves);
|
||||
void rank_root_moves(Position& pos, Search::RootMoves& rootMoves);
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const WDLScore v) {
|
||||
|
||||
os << (v == WDLLoss ? "Loss" :
|
||||
v == WDLBlessedLoss ? "Blessed loss" :
|
||||
v == WDLDraw ? "Draw" :
|
||||
v == WDLCursedWin ? "Cursed win" :
|
||||
v == WDLWin ? "Win" : "None");
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const ProbeState v) {
|
||||
|
||||
os << (v == FAIL ? "Failed" :
|
||||
v == OK ? "Success" :
|
||||
v == CHANGE_STM ? "Probed opponent side" :
|
||||
v == ZEROING_BEST_MOVE ? "Best move zeroes DTZ" : "None");
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+142
-324
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -24,362 +25,179 @@
|
||||
#include "search.h"
|
||||
#include "thread.h"
|
||||
#include "uci.h"
|
||||
|
||||
using namespace Search;
|
||||
#include "syzygy/tbprobe.h"
|
||||
#include "tt.h"
|
||||
|
||||
ThreadPool Threads; // Global object
|
||||
|
||||
extern void check_time();
|
||||
|
||||
namespace {
|
||||
/// Thread constructor launches the thread and waits until it goes to sleep
|
||||
/// in idle_loop(). Note that 'searching' and 'exit' should be alredy set.
|
||||
|
||||
// start_routine() is the C function which is called when a new thread
|
||||
// is launched. It is a wrapper to the virtual function idle_loop().
|
||||
|
||||
extern "C" { long start_routine(ThreadBase* th) { th->idle_loop(); return 0; } }
|
||||
|
||||
|
||||
// Helpers to launch a thread after creation and joining before delete. Must be
|
||||
// outside Thread c'tor and d'tor because the object must be fully initialized
|
||||
// when start_routine (and hence virtual idle_loop) is called and when joining.
|
||||
|
||||
template<typename T> T* new_thread() {
|
||||
T* th = new T();
|
||||
thread_create(th->handle, start_routine, th); // Will go to sleep
|
||||
return th;
|
||||
}
|
||||
|
||||
void delete_thread(ThreadBase* th) {
|
||||
|
||||
th->mutex.lock();
|
||||
th->exit = true; // Search must be already finished
|
||||
th->mutex.unlock();
|
||||
|
||||
th->notify_one();
|
||||
thread_join(th->handle); // Wait for thread termination
|
||||
delete th;
|
||||
}
|
||||
Thread::Thread(size_t n) : idx(n), stdThread(&Thread::idle_loop, this) {
|
||||
|
||||
wait_for_search_finished();
|
||||
}
|
||||
|
||||
|
||||
// ThreadBase::notify_one() wakes up the thread when there is some work to do
|
||||
/// Thread destructor wakes up the thread in idle_loop() and waits
|
||||
/// for its termination. Thread should be already waiting.
|
||||
|
||||
void ThreadBase::notify_one() {
|
||||
Thread::~Thread() {
|
||||
|
||||
mutex.lock();
|
||||
sleepCondition.notify_one();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
// ThreadBase::wait_for() set the thread to sleep until 'condition' turns true
|
||||
|
||||
void ThreadBase::wait_for(volatile const bool& condition) {
|
||||
|
||||
mutex.lock();
|
||||
while (!condition) sleepCondition.wait(mutex);
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
// Thread c'tor makes some init but does not launch any execution thread that
|
||||
// will be started only when c'tor returns.
|
||||
|
||||
Thread::Thread() /* : splitPoints() */ { // Initialization of non POD broken in MSVC
|
||||
|
||||
searching = false;
|
||||
maxPly = splitPointsSize = 0;
|
||||
activeSplitPoint = NULL;
|
||||
activePosition = NULL;
|
||||
idx = Threads.size(); // Starts from 0
|
||||
}
|
||||
|
||||
|
||||
// Thread::cutoff_occurred() checks whether a beta cutoff has occurred in the
|
||||
// current active split point, or in some ancestor of the split point.
|
||||
|
||||
bool Thread::cutoff_occurred() const {
|
||||
|
||||
for (SplitPoint* sp = activeSplitPoint; sp; sp = sp->parentSplitPoint)
|
||||
if (sp->cutoff)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Thread::available_to() checks whether the thread is available to help the
|
||||
// thread 'master' at a split point. An obvious requirement is that thread must
|
||||
// be idle. With more than two threads, this is not sufficient: If the thread is
|
||||
// the master of some split point, it is only available as a slave to the slaves
|
||||
// which are busy searching the split point at the top of slave's split point
|
||||
// stack (the "helpful master concept" in YBWC terminology).
|
||||
|
||||
bool Thread::available_to(const Thread* master) const {
|
||||
|
||||
if (searching)
|
||||
return false;
|
||||
|
||||
// Make a local copy to be sure it doesn't become zero under our feet while
|
||||
// testing next condition and so leading to an out of bounds access.
|
||||
const int size = splitPointsSize;
|
||||
|
||||
// No split points means that the thread is available as a slave for any
|
||||
// other thread otherwise apply the "helpful master" concept if possible.
|
||||
return !size || splitPoints[size - 1].slavesMask.test(master->idx);
|
||||
}
|
||||
|
||||
|
||||
// Thread::split() does the actual work of distributing the work at a node between
|
||||
// several available threads. If it does not succeed in splitting the node
|
||||
// (because no idle threads are available), the function immediately returns.
|
||||
// If splitting is possible, a SplitPoint object is initialized with all the
|
||||
// data that must be copied to the helper threads and then helper threads are
|
||||
// informed that they have been assigned work. This will cause them to instantly
|
||||
// leave their idle loops and call search(). When all threads have returned from
|
||||
// search() then split() returns.
|
||||
|
||||
void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bestValue,
|
||||
Move* bestMove, Depth depth, int moveCount,
|
||||
MovePicker* movePicker, int nodeType, bool cutNode) {
|
||||
|
||||
assert(searching);
|
||||
assert(-VALUE_INFINITE < *bestValue && *bestValue <= alpha && alpha < beta && beta <= VALUE_INFINITE);
|
||||
assert(depth >= Threads.minimumSplitDepth);
|
||||
assert(splitPointsSize < MAX_SPLITPOINTS_PER_THREAD);
|
||||
|
||||
// Pick and init the next available split point
|
||||
SplitPoint& sp = splitPoints[splitPointsSize];
|
||||
|
||||
sp.masterThread = this;
|
||||
sp.parentSplitPoint = activeSplitPoint;
|
||||
sp.slavesMask = 0, sp.slavesMask.set(idx);
|
||||
sp.depth = depth;
|
||||
sp.bestValue = *bestValue;
|
||||
sp.bestMove = *bestMove;
|
||||
sp.alpha = alpha;
|
||||
sp.beta = beta;
|
||||
sp.nodeType = nodeType;
|
||||
sp.cutNode = cutNode;
|
||||
sp.movePicker = movePicker;
|
||||
sp.moveCount = moveCount;
|
||||
sp.pos = &pos;
|
||||
sp.nodes = 0;
|
||||
sp.cutoff = false;
|
||||
sp.ss = ss;
|
||||
|
||||
// Try to allocate available threads and ask them to start searching setting
|
||||
// 'searching' flag. This must be done under lock protection to avoid concurrent
|
||||
// allocation of the same slave by another master.
|
||||
Threads.mutex.lock();
|
||||
sp.mutex.lock();
|
||||
|
||||
sp.allSlavesSearching = true; // Must be set under lock protection
|
||||
++splitPointsSize;
|
||||
activeSplitPoint = &sp;
|
||||
activePosition = NULL;
|
||||
|
||||
Thread* slave;
|
||||
|
||||
while ((slave = Threads.available_slave(this)) != NULL)
|
||||
{
|
||||
sp.slavesMask.set(slave->idx);
|
||||
slave->activeSplitPoint = &sp;
|
||||
slave->searching = true; // Slave leaves idle_loop()
|
||||
slave->notify_one(); // Could be sleeping
|
||||
}
|
||||
|
||||
// Everything is set up. The master thread enters the idle loop, from which
|
||||
// it will instantly launch a search, because its 'searching' flag is set.
|
||||
// The thread will return from the idle loop when all slaves have finished
|
||||
// their work at this split point.
|
||||
sp.mutex.unlock();
|
||||
Threads.mutex.unlock();
|
||||
|
||||
Thread::idle_loop(); // Force a call to base class idle_loop()
|
||||
|
||||
// In the helpful master concept, a master can help only a sub-tree of its
|
||||
// split point and because everything is finished here, it's not possible
|
||||
// for the master to be booked.
|
||||
assert(!searching);
|
||||
assert(!activePosition);
|
||||
|
||||
// We have returned from the idle loop, which means that all threads are
|
||||
// finished. Note that setting 'searching' and decreasing splitPointsSize must
|
||||
// be done under lock protection to avoid a race with Thread::available_to().
|
||||
Threads.mutex.lock();
|
||||
sp.mutex.lock();
|
||||
exit = true;
|
||||
start_searching();
|
||||
stdThread.join();
|
||||
}
|
||||
|
||||
|
||||
/// Thread::clear() reset histories, usually before a new game
|
||||
|
||||
void Thread::clear() {
|
||||
|
||||
counterMoves.fill(MOVE_NONE);
|
||||
mainHistory.fill(0);
|
||||
captureHistory.fill(0);
|
||||
|
||||
for (auto& to : continuationHistory)
|
||||
for (auto& h : to)
|
||||
h->fill(0);
|
||||
|
||||
continuationHistory[NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
|
||||
}
|
||||
|
||||
/// Thread::start_searching() wakes up the thread that will start the search
|
||||
|
||||
void Thread::start_searching() {
|
||||
|
||||
std::lock_guard<Mutex> lk(mutex);
|
||||
searching = true;
|
||||
--splitPointsSize;
|
||||
activeSplitPoint = sp.parentSplitPoint;
|
||||
activePosition = &pos;
|
||||
pos.set_nodes_searched(pos.nodes_searched() + sp.nodes);
|
||||
*bestMove = sp.bestMove;
|
||||
*bestValue = sp.bestValue;
|
||||
|
||||
sp.mutex.unlock();
|
||||
Threads.mutex.unlock();
|
||||
cv.notify_one(); // Wake up the thread in idle_loop()
|
||||
}
|
||||
|
||||
|
||||
// TimerThread::idle_loop() is where the timer thread waits Resolution milliseconds
|
||||
// and then calls check_time(). When not searching, thread sleeps until it's woken up.
|
||||
/// Thread::wait_for_search_finished() blocks on the condition variable
|
||||
/// until the thread has finished searching.
|
||||
|
||||
void TimerThread::idle_loop() {
|
||||
void Thread::wait_for_search_finished() {
|
||||
|
||||
while (!exit)
|
||||
std::unique_lock<Mutex> lk(mutex);
|
||||
cv.wait(lk, [&]{ return !searching; });
|
||||
}
|
||||
|
||||
|
||||
/// Thread::idle_loop() is where the thread is parked, blocked on the
|
||||
/// condition variable, when it has no work to do.
|
||||
|
||||
void Thread::idle_loop() {
|
||||
|
||||
// If OS already scheduled us on a different group than 0 then don't overwrite
|
||||
// the choice, eventually we are one of many one-threaded processes running on
|
||||
// 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
|
||||
// NUMA machinery is not needed.
|
||||
if (Options["Threads"] > 8)
|
||||
WinProcGroup::bindThisThread(idx);
|
||||
|
||||
while (true)
|
||||
{
|
||||
mutex.lock();
|
||||
std::unique_lock<Mutex> lk(mutex);
|
||||
searching = false;
|
||||
cv.notify_one(); // Wake up anyone waiting for search finished
|
||||
cv.wait(lk, [&]{ return searching; });
|
||||
|
||||
if (!exit)
|
||||
sleepCondition.wait_for(mutex, run ? Resolution : INT_MAX);
|
||||
if (exit)
|
||||
return;
|
||||
|
||||
mutex.unlock();
|
||||
lk.unlock();
|
||||
|
||||
if (run)
|
||||
check_time();
|
||||
search();
|
||||
}
|
||||
}
|
||||
|
||||
/// ThreadPool::set() creates/destroys threads to match the requested number.
|
||||
/// Created and launched threads will go immediately to sleep in idle_loop.
|
||||
/// Upon resizing, threads are recreated to allow for binding if necessary.
|
||||
|
||||
// MainThread::idle_loop() is where the main thread is parked waiting to be started
|
||||
// when there is a new search. The main thread will launch all the slave threads.
|
||||
void ThreadPool::set(size_t requested) {
|
||||
|
||||
void MainThread::idle_loop() {
|
||||
if (size() > 0) { // destroy any existing thread(s)
|
||||
main()->wait_for_search_finished();
|
||||
|
||||
while (!exit)
|
||||
{
|
||||
mutex.lock();
|
||||
|
||||
thinking = false;
|
||||
|
||||
while (!thinking && !exit)
|
||||
{
|
||||
Threads.sleepCondition.notify_one(); // Wake up the UI thread if needed
|
||||
sleepCondition.wait(mutex);
|
||||
}
|
||||
|
||||
mutex.unlock();
|
||||
|
||||
if (!exit)
|
||||
{
|
||||
searching = true;
|
||||
|
||||
Search::think();
|
||||
|
||||
assert(searching);
|
||||
|
||||
searching = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ThreadPool::init() is called at startup to create and launch requested threads,
|
||||
// that will go immediately to sleep. We cannot use a c'tor because Threads is a
|
||||
// static object and we need a fully initialized engine at this point due to
|
||||
// allocation of Endgames in Thread c'tor.
|
||||
|
||||
void ThreadPool::init() {
|
||||
|
||||
timer = new_thread<TimerThread>();
|
||||
push_back(new_thread<MainThread>());
|
||||
read_uci_options();
|
||||
}
|
||||
|
||||
|
||||
// ThreadPool::exit() terminates the threads before the program exits. Cannot be
|
||||
// done in d'tor because threads must be terminated before freeing us.
|
||||
|
||||
void ThreadPool::exit() {
|
||||
|
||||
delete_thread(timer); // As first because check_time() accesses threads data
|
||||
|
||||
for (iterator it = begin(); it != end(); ++it)
|
||||
delete_thread(*it);
|
||||
}
|
||||
|
||||
|
||||
// ThreadPool::read_uci_options() updates internal threads parameters from the
|
||||
// corresponding UCI options and creates/destroys threads to match the requested
|
||||
// number. Thread objects are dynamically allocated to avoid creating all possible
|
||||
// threads in advance (which include pawns and material tables), even if only a
|
||||
// few are to be used.
|
||||
|
||||
void ThreadPool::read_uci_options() {
|
||||
|
||||
minimumSplitDepth = Options["Min Split Depth"] * ONE_PLY;
|
||||
size_t requested = Options["Threads"];
|
||||
|
||||
assert(requested > 0);
|
||||
|
||||
// If zero (default) then set best minimum split depth automatically
|
||||
if (!minimumSplitDepth)
|
||||
minimumSplitDepth = requested < 8 ? 4 * ONE_PLY : 7 * ONE_PLY;
|
||||
|
||||
while (size() < requested)
|
||||
push_back(new_thread<Thread>());
|
||||
|
||||
while (size() > requested)
|
||||
{
|
||||
delete_thread(back());
|
||||
pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ThreadPool::available_slave() tries to find an idle thread which is available
|
||||
// as a slave for the thread 'master'.
|
||||
|
||||
Thread* ThreadPool::available_slave(const Thread* master) const {
|
||||
|
||||
for (const_iterator it = begin(); it != end(); ++it)
|
||||
if ((*it)->available_to(master))
|
||||
return *it;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// ThreadPool::wait_for_think_finished() waits for main thread to finish the search
|
||||
|
||||
void ThreadPool::wait_for_think_finished() {
|
||||
|
||||
MainThread* th = main();
|
||||
th->mutex.lock();
|
||||
while (th->thinking) sleepCondition.wait(th->mutex);
|
||||
th->mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
// ThreadPool::start_thinking() wakes up the main thread sleeping in
|
||||
// MainThread::idle_loop() and starts a new search, then returns immediately.
|
||||
|
||||
void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
|
||||
StateStackPtr& states) {
|
||||
wait_for_think_finished();
|
||||
|
||||
SearchTime = Time::now(); // As early as possible
|
||||
|
||||
Signals.stopOnPonderhit = Signals.firstRootMove = false;
|
||||
Signals.stop = Signals.failedLowAtRoot = false;
|
||||
|
||||
RootMoves.clear();
|
||||
RootPos = pos;
|
||||
Limits = limits;
|
||||
if (states.get()) // If we don't set a new position, preserve current state
|
||||
{
|
||||
SetupStates = states; // Ownership transfer here
|
||||
assert(!states.get());
|
||||
while (size() > 0)
|
||||
delete back(), pop_back();
|
||||
}
|
||||
|
||||
for (MoveList<LEGAL> it(pos); *it; ++it)
|
||||
if (requested > 0) { // create new thread(s)
|
||||
push_back(new MainThread(0));
|
||||
|
||||
while (size() < requested)
|
||||
push_back(new Thread(size()));
|
||||
clear();
|
||||
}
|
||||
|
||||
// Reallocate the hash with the new threadpool size
|
||||
TT.resize(Options["Hash"]);
|
||||
}
|
||||
|
||||
/// ThreadPool::clear() sets threadPool data to initial values.
|
||||
|
||||
void ThreadPool::clear() {
|
||||
|
||||
for (Thread* th : *this)
|
||||
th->clear();
|
||||
|
||||
main()->callsCnt = 0;
|
||||
main()->previousScore = VALUE_INFINITE;
|
||||
main()->previousTimeReduction = 1.0;
|
||||
}
|
||||
|
||||
/// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and
|
||||
/// returns immediately. Main thread will wake up other threads and start the search.
|
||||
|
||||
void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
|
||||
const Search::LimitsType& limits, bool ponderMode) {
|
||||
|
||||
main()->wait_for_search_finished();
|
||||
|
||||
stopOnPonderhit = stop = false;
|
||||
ponder = ponderMode;
|
||||
Search::Limits = limits;
|
||||
Search::RootMoves rootMoves;
|
||||
|
||||
for (const auto& m : MoveList<LEGAL>(pos))
|
||||
if ( limits.searchmoves.empty()
|
||||
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), *it))
|
||||
RootMoves.push_back(RootMove(*it));
|
||||
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m))
|
||||
rootMoves.emplace_back(m);
|
||||
|
||||
main()->thinking = true;
|
||||
main()->notify_one(); // Starts main thread
|
||||
if (!rootMoves.empty())
|
||||
Tablebases::rank_root_moves(pos, rootMoves);
|
||||
|
||||
// After ownership transfer 'states' becomes empty, so if we stop the search
|
||||
// and call 'go' again without setting a new position states.get() == NULL.
|
||||
assert(states.get() || setupStates.get());
|
||||
|
||||
if (states.get())
|
||||
setupStates = std::move(states); // Ownership transfer, states is now empty
|
||||
|
||||
// We use Position::set() to set root position across threads. But there are
|
||||
// some StateInfo fields (previous, pliesFromNull, capturedPiece) that cannot
|
||||
// be deduced from a fen string, so set() clears them and to not lose the info
|
||||
// we need to backup and later restore setupStates->back(). Note that setupStates
|
||||
// is shared by threads but is accessed in read-only mode.
|
||||
StateInfo tmp = setupStates->back();
|
||||
|
||||
for (Thread* th : *this)
|
||||
{
|
||||
th->nodes = th->tbHits = th->nmpMinPly = 0;
|
||||
th->rootDepth = th->completedDepth = DEPTH_ZERO;
|
||||
th->rootMoves = rootMoves;
|
||||
th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th);
|
||||
}
|
||||
|
||||
setupStates->back() = tmp;
|
||||
|
||||
main()->start_searching();
|
||||
}
|
||||
|
||||
+64
-126
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -20,7 +21,10 @@
|
||||
#ifndef THREAD_H_INCLUDED
|
||||
#define THREAD_H_INCLUDED
|
||||
|
||||
#include <bitset>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "material.h"
|
||||
@@ -28,157 +32,91 @@
|
||||
#include "pawns.h"
|
||||
#include "position.h"
|
||||
#include "search.h"
|
||||
|
||||
struct Thread;
|
||||
|
||||
const int MAX_THREADS = 128;
|
||||
const int MAX_SPLITPOINTS_PER_THREAD = 8;
|
||||
|
||||
/// Mutex and ConditionVariable struct are wrappers of the low level locking
|
||||
/// machinery and are modeled after the corresponding C++11 classes.
|
||||
|
||||
struct Mutex {
|
||||
Mutex() { lock_init(l); }
|
||||
~Mutex() { lock_destroy(l); }
|
||||
|
||||
void lock() { lock_grab(l); }
|
||||
void unlock() { lock_release(l); }
|
||||
|
||||
private:
|
||||
friend struct ConditionVariable;
|
||||
|
||||
Lock l;
|
||||
};
|
||||
|
||||
struct ConditionVariable {
|
||||
ConditionVariable() { cond_init(c); }
|
||||
~ConditionVariable() { cond_destroy(c); }
|
||||
|
||||
void wait(Mutex& m) { cond_wait(c, m.l); }
|
||||
void wait_for(Mutex& m, int ms) { timed_wait(c, m.l, ms); }
|
||||
void notify_one() { cond_signal(c); }
|
||||
|
||||
private:
|
||||
WaitCondition c;
|
||||
};
|
||||
#include "thread_win32.h"
|
||||
|
||||
|
||||
/// SplitPoint struct stores information shared by the threads searching in
|
||||
/// parallel below the same split point. It is populated at splitting time.
|
||||
/// Thread class keeps together all the thread-related stuff. We use
|
||||
/// per-thread pawn and material hash tables so that once we get a
|
||||
/// pointer to an entry its life time is unlimited and we don't have
|
||||
/// to care about someone changing the entry under our feet.
|
||||
|
||||
struct SplitPoint {
|
||||
|
||||
// Const data after split point has been setup
|
||||
const Position* pos;
|
||||
Search::Stack* ss;
|
||||
Thread* masterThread;
|
||||
Depth depth;
|
||||
Value beta;
|
||||
int nodeType;
|
||||
bool cutNode;
|
||||
|
||||
// Const pointers to shared data
|
||||
MovePicker* movePicker;
|
||||
SplitPoint* parentSplitPoint;
|
||||
|
||||
// Shared variable data
|
||||
Mutex mutex;
|
||||
std::bitset<MAX_THREADS> slavesMask;
|
||||
volatile bool allSlavesSearching;
|
||||
volatile uint64_t nodes;
|
||||
volatile Value alpha;
|
||||
volatile Value bestValue;
|
||||
volatile Move bestMove;
|
||||
volatile int moveCount;
|
||||
volatile bool cutoff;
|
||||
};
|
||||
|
||||
|
||||
/// ThreadBase struct is the base of the hierarchy from where we derive all the
|
||||
/// specialized thread classes.
|
||||
|
||||
struct ThreadBase {
|
||||
|
||||
ThreadBase() : handle(NativeHandle()), exit(false) {}
|
||||
virtual ~ThreadBase() {}
|
||||
virtual void idle_loop() = 0;
|
||||
void notify_one();
|
||||
void wait_for(volatile const bool& b);
|
||||
class Thread {
|
||||
|
||||
Mutex mutex;
|
||||
ConditionVariable sleepCondition;
|
||||
NativeHandle handle;
|
||||
volatile bool exit;
|
||||
};
|
||||
ConditionVariable cv;
|
||||
size_t idx;
|
||||
bool exit = false, searching = true; // Set before starting std::thread
|
||||
std::thread stdThread;
|
||||
|
||||
public:
|
||||
explicit Thread(size_t);
|
||||
virtual ~Thread();
|
||||
virtual void search();
|
||||
void clear();
|
||||
void idle_loop();
|
||||
void start_searching();
|
||||
void wait_for_search_finished();
|
||||
|
||||
/// Thread struct keeps together all the thread related stuff like locks, state
|
||||
/// and especially split points. We also use per-thread pawn and material hash
|
||||
/// tables so that once we get a pointer to an entry its life time is unlimited
|
||||
/// and we don't have to care about someone changing the entry under our feet.
|
||||
|
||||
struct Thread : public ThreadBase {
|
||||
|
||||
Thread();
|
||||
virtual void idle_loop();
|
||||
bool cutoff_occurred() const;
|
||||
bool available_to(const Thread* master) const;
|
||||
|
||||
void split(Position& pos, Search::Stack* ss, Value alpha, Value beta, Value* bestValue, Move* bestMove,
|
||||
Depth depth, int moveCount, MovePicker* movePicker, int nodeType, bool cutNode);
|
||||
|
||||
SplitPoint splitPoints[MAX_SPLITPOINTS_PER_THREAD];
|
||||
Pawns::Table pawnsTable;
|
||||
Material::Table materialTable;
|
||||
Endgames endgames;
|
||||
Position* activePosition;
|
||||
size_t idx;
|
||||
int maxPly;
|
||||
SplitPoint* volatile activeSplitPoint;
|
||||
volatile int splitPointsSize;
|
||||
volatile bool searching;
|
||||
size_t pvIdx, pvLast;
|
||||
int selDepth, nmpMinPly;
|
||||
Color nmpColor;
|
||||
std::atomic<uint64_t> nodes, tbHits;
|
||||
|
||||
Position rootPos;
|
||||
Search::RootMoves rootMoves;
|
||||
Depth rootDepth, completedDepth;
|
||||
CounterMoveHistory counterMoves;
|
||||
ButterflyHistory mainHistory;
|
||||
CapturePieceToHistory captureHistory;
|
||||
ContinuationHistory continuationHistory;
|
||||
Score contempt;
|
||||
};
|
||||
|
||||
|
||||
/// MainThread and TimerThread are derived classes used to characterize the two
|
||||
/// special threads: the main one and the recurring timer.
|
||||
/// MainThread is a derived class specific for main thread
|
||||
|
||||
struct MainThread : public Thread {
|
||||
MainThread() : thinking(true) {} // Avoid a race with start_thinking()
|
||||
virtual void idle_loop();
|
||||
volatile bool thinking;
|
||||
};
|
||||
|
||||
struct TimerThread : public ThreadBase {
|
||||
using Thread::Thread;
|
||||
|
||||
static const int Resolution = 5; // Millisec between two check_time() calls
|
||||
void search() override;
|
||||
void check_time();
|
||||
|
||||
TimerThread() : run(false) {}
|
||||
virtual void idle_loop();
|
||||
|
||||
bool run;
|
||||
double bestMoveChanges, previousTimeReduction;
|
||||
Value previousScore;
|
||||
int callsCnt;
|
||||
};
|
||||
|
||||
|
||||
/// ThreadPool struct handles all the threads related stuff like init, starting,
|
||||
/// parking and, most importantly, launching a slave thread at a split point.
|
||||
/// All the access to shared thread data is done through this class.
|
||||
/// ThreadPool struct handles all the threads-related stuff like init, starting,
|
||||
/// parking and, most importantly, launching a thread. All the access to threads
|
||||
/// is done through this class.
|
||||
|
||||
struct ThreadPool : public std::vector<Thread*> {
|
||||
|
||||
void init(); // No c'tor and d'tor, threads rely on globals that should be
|
||||
void exit(); // initialized and are valid during the whole thread lifetime.
|
||||
void start_thinking(Position&, StateListPtr&, const Search::LimitsType&, bool = false);
|
||||
void clear();
|
||||
void set(size_t);
|
||||
|
||||
MainThread* main() { return static_cast<MainThread*>(at(0)); }
|
||||
void read_uci_options();
|
||||
Thread* available_slave(const Thread* master) const;
|
||||
void wait_for_think_finished();
|
||||
void start_thinking(const Position&, const Search::LimitsType&, Search::StateStackPtr&);
|
||||
MainThread* main() const { return static_cast<MainThread*>(front()); }
|
||||
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
|
||||
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
|
||||
|
||||
Depth minimumSplitDepth;
|
||||
Mutex mutex;
|
||||
ConditionVariable sleepCondition;
|
||||
TimerThread* timer;
|
||||
std::atomic_bool stop, ponder, stopOnPonderhit;
|
||||
|
||||
private:
|
||||
StateListPtr setupStates;
|
||||
|
||||
uint64_t accumulate(std::atomic<uint64_t> Thread::* member) const {
|
||||
|
||||
uint64_t sum = 0;
|
||||
for (Thread* th : *this)
|
||||
sum += (th->*member).load(std::memory_order_relaxed);
|
||||
return sum;
|
||||
}
|
||||
};
|
||||
|
||||
extern ThreadPool Threads;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
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-2019 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
|
||||
+53
-36
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -25,37 +26,39 @@
|
||||
#include "timeman.h"
|
||||
#include "uci.h"
|
||||
|
||||
TimeManagement Time; // Our global time management object
|
||||
|
||||
namespace {
|
||||
|
||||
enum TimeType { OptimumTime, MaxTime };
|
||||
|
||||
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||
const double MaxRatio = 7.0; // When in trouble, we can step over reserved time with this ratio
|
||||
const double StealRatio = 0.33; // However we must not steal time from remaining moves over this ratio
|
||||
constexpr int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||
constexpr double MaxRatio = 7.3; // When in trouble, we can step over reserved time with 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
|
||||
// analysis of "how many games are still undecided after n half-moves". Game
|
||||
// is considered "undecided" as long as neither side has >275cp advantage.
|
||||
// Data was extracted from CCRL game database with some simple filtering criteria.
|
||||
// Data was extracted from the CCRL game database with some simple filtering criteria.
|
||||
|
||||
double move_importance(int ply) {
|
||||
|
||||
const double XScale = 9.3;
|
||||
const double XShift = 59.8;
|
||||
const double Skew = 0.172;
|
||||
constexpr double XScale = 6.85;
|
||||
constexpr double XShift = 64.5;
|
||||
constexpr double Skew = 0.171;
|
||||
|
||||
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
||||
}
|
||||
|
||||
template<TimeType T>
|
||||
int remaining(int myTime, int movesToGo, int ply, int slowMover)
|
||||
{
|
||||
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
||||
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
||||
TimePoint remaining(TimePoint myTime, int movesToGo, int ply, TimePoint slowMover) {
|
||||
|
||||
double moveImportance = (move_importance(ply) * slowMover) / 100;
|
||||
double otherMovesImportance = 0;
|
||||
constexpr double TMaxRatio = (T == OptimumTime ? 1.0 : MaxRatio);
|
||||
constexpr double TStealRatio = (T == OptimumTime ? 0.0 : StealRatio);
|
||||
|
||||
double moveImportance = (move_importance(ply) * slowMover) / 100.0;
|
||||
double otherMovesImportance = 0.0;
|
||||
|
||||
for (int i = 1; i < movesToGo; ++i)
|
||||
otherMovesImportance += move_importance(ply + 2 * i);
|
||||
@@ -63,7 +66,7 @@ namespace {
|
||||
double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance);
|
||||
double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance);
|
||||
|
||||
return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks an explicit cast
|
||||
return TimePoint(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -78,39 +81,53 @@ namespace {
|
||||
/// inc > 0 && movestogo == 0 means: x basetime + z increment
|
||||
/// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment
|
||||
|
||||
void TimeManager::init(const Search::LimitsType& limits, Color us, int ply)
|
||||
{
|
||||
int minThinkingTime = Options["Minimum Thinking Time"];
|
||||
int moveOverhead = Options["Move Overhead"];
|
||||
int slowMover = Options["Slow Mover"];
|
||||
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
||||
|
||||
// Initialize unstablePvFactor to 1 and search times to maximum values
|
||||
unstablePvFactor = 1;
|
||||
optimumSearchTime = maximumSearchTime = std::max(limits.time[us], minThinkingTime);
|
||||
TimePoint minThinkingTime = Options["Minimum Thinking Time"];
|
||||
TimePoint moveOverhead = Options["Move Overhead"];
|
||||
TimePoint slowMover = Options["Slow Mover"];
|
||||
TimePoint npmsec = Options["nodestime"];
|
||||
TimePoint hypMyTime;
|
||||
|
||||
const int MaxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
||||
// If we have to play in 'nodes as time' mode, then convert from time
|
||||
// to nodes, and use resulting values in time management formulas.
|
||||
// WARNING: to avoid time losses, the given npmsec (nodes per millisecond)
|
||||
// must be much lower than the real engine speed.
|
||||
if (npmsec)
|
||||
{
|
||||
if (!availableNodes) // Only once at game start
|
||||
availableNodes = npmsec * limits.time[us]; // Time is in msec
|
||||
|
||||
// We calculate optimum time usage for different hypothetical "moves to go"-values
|
||||
// Convert from milliseconds to nodes
|
||||
limits.time[us] = TimePoint(availableNodes);
|
||||
limits.inc[us] *= npmsec;
|
||||
limits.npmsec = npmsec;
|
||||
}
|
||||
|
||||
startTime = limits.startTime;
|
||||
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
||||
|
||||
const int maxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
||||
|
||||
// We calculate optimum time usage for different hypothetical "moves to go" values
|
||||
// and choose the minimum of calculated search time values. Usually the greatest
|
||||
// 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
|
||||
int hypMyTime = limits.time[us]
|
||||
+ limits.inc[us] * (hypMTG - 1)
|
||||
- moveOverhead * (2 + std::min(hypMTG, 40));
|
||||
hypMyTime = limits.time[us]
|
||||
+ limits.inc[us] * (hypMTG - 1)
|
||||
- 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);
|
||||
int t2 = minThinkingTime + remaining<MaxTime >(hypMyTime, hypMTG, ply, slowMover);
|
||||
TimePoint t1 = minThinkingTime + remaining<OptimumTime>(hypMyTime, hypMTG, ply, slowMover);
|
||||
TimePoint t2 = minThinkingTime + remaining<MaxTime >(hypMyTime, hypMTG, ply, slowMover);
|
||||
|
||||
optimumSearchTime = std::min(t1, optimumSearchTime);
|
||||
maximumSearchTime = std::min(t2, maximumSearchTime);
|
||||
optimumTime = std::min(t1, optimumTime);
|
||||
maximumTime = std::min(t2, maximumTime);
|
||||
}
|
||||
|
||||
if (Options["Ponder"])
|
||||
optimumSearchTime += optimumSearchTime / 4;
|
||||
|
||||
optimumSearchTime = std::min(optimumSearchTime, maximumSearchTime);
|
||||
optimumTime += optimumTime / 4;
|
||||
}
|
||||
|
||||
+20
-10
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -20,20 +21,29 @@
|
||||
#ifndef TIMEMAN_H_INCLUDED
|
||||
#define TIMEMAN_H_INCLUDED
|
||||
|
||||
/// The TimeManager class computes the optimal time to think depending on the
|
||||
/// maximum available time, the game move number and other parameters.
|
||||
#include "misc.h"
|
||||
#include "search.h"
|
||||
#include "thread.h"
|
||||
|
||||
class TimeManager {
|
||||
/// The TimeManagement class computes the optimal time to think depending on
|
||||
/// the maximum available time, the game move number and other parameters.
|
||||
|
||||
class TimeManagement {
|
||||
public:
|
||||
void init(const Search::LimitsType& limits, Color us, int ply);
|
||||
void pv_instability(double bestMoveChanges) { unstablePvFactor = 1 + bestMoveChanges; }
|
||||
int available_time() const { return int(optimumSearchTime * unstablePvFactor * 0.71); }
|
||||
int maximum_time() const { return maximumSearchTime; }
|
||||
void init(Search::LimitsType& limits, Color us, int ply);
|
||||
TimePoint optimum() const { return optimumTime; }
|
||||
TimePoint maximum() const { return maximumTime; }
|
||||
TimePoint elapsed() const { return Search::Limits.npmsec ?
|
||||
TimePoint(Threads.nodes_searched()) : now() - startTime; }
|
||||
|
||||
int64_t availableNodes; // When in 'nodes as time' mode
|
||||
|
||||
private:
|
||||
int optimumSearchTime;
|
||||
int maximumSearchTime;
|
||||
double unstablePvFactor;
|
||||
TimePoint startTime;
|
||||
TimePoint optimumTime;
|
||||
TimePoint maximumTime;
|
||||
};
|
||||
|
||||
extern TimeManagement Time;
|
||||
|
||||
#endif // #ifndef TIMEMAN_H_INCLUDED
|
||||
|
||||
+80
-22
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -19,12 +20,37 @@
|
||||
|
||||
#include <cstring> // For std::memset
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "bitboard.h"
|
||||
#include "misc.h"
|
||||
#include "tt.h"
|
||||
#include "uci.h"
|
||||
|
||||
TranspositionTable TT; // Our global transposition table
|
||||
|
||||
/// TTEntry::save saves a TTEntry
|
||||
void TTEntry::save(Key k, Value v, Bound b, Depth d, Move m, Value ev) {
|
||||
|
||||
assert(d / ONE_PLY * ONE_PLY == d);
|
||||
|
||||
// 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 / ONE_PLY > depth8 - 4
|
||||
|| b == BOUND_EXACT)
|
||||
{
|
||||
key16 = (uint16_t)(k >> 48);
|
||||
value16 = (int16_t)v;
|
||||
eval16 = (int16_t)ev;
|
||||
genBound8 = (uint8_t)(TT.generation8 | b);
|
||||
depth8 = (int8_t)(d / ONE_PLY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// TranspositionTable::resize() sets the size of the transposition table,
|
||||
/// measured in megabytes. Transposition table consists of a power of 2 number
|
||||
@@ -32,17 +58,10 @@ TranspositionTable TT; // Our global transposition table
|
||||
|
||||
void TranspositionTable::resize(size_t mbSize) {
|
||||
|
||||
assert(sizeof(Cluster) == CacheLineSize / 2);
|
||||
|
||||
size_t newClusterCount = size_t(1) << msb((mbSize * 1024 * 1024) / sizeof(Cluster));
|
||||
|
||||
if (newClusterCount == clusterCount)
|
||||
return;
|
||||
|
||||
clusterCount = newClusterCount;
|
||||
clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
|
||||
|
||||
free(mem);
|
||||
mem = calloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1, 1);
|
||||
mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);
|
||||
|
||||
if (!mem)
|
||||
{
|
||||
@@ -52,25 +71,45 @@ void TranspositionTable::resize(size_t mbSize) {
|
||||
}
|
||||
|
||||
table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
/// TranspositionTable::clear() overwrites the entire transposition table
|
||||
/// with zeros. It is called whenever the table is resized, or when the
|
||||
/// user asks the program to clear the table (from the UCI interface).
|
||||
/// TranspositionTable::clear() initializes the entire transposition table to zero,
|
||||
// in a multi-threaded way.
|
||||
|
||||
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
|
||||
/// table. It returns true and a pointer to the TTEntry if the position is found.
|
||||
/// Otherwise, it returns false and a pointer to an empty or least valuable TTEntry
|
||||
/// to be replaced later. A TTEntry t1 is considered to be more valuable than a
|
||||
/// TTEntry t2 if t1 is from the current search and t2 is from a previous search,
|
||||
/// or if the depth of t1 is bigger than the depth of t2.
|
||||
/// to be replaced later. The replace value of an entry is calculated as its depth
|
||||
/// minus 8 times its relative age. TTEntry t1 is considered more valuable than
|
||||
/// TTEntry t2 if its replace value is greater than that of t2.
|
||||
|
||||
TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
||||
|
||||
@@ -80,8 +119,7 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
||||
for (int i = 0; i < ClusterSize; ++i)
|
||||
if (!tte[i].key16 || tte[i].key16 == key16)
|
||||
{
|
||||
if (tte[i].key16)
|
||||
tte[i].genBound8 = uint8_t(generation8 | tte[i].bound()); // Refresh
|
||||
tte[i].genBound8 = uint8_t(generation8 | tte[i].bound()); // Refresh
|
||||
|
||||
return found = (bool)tte[i].key16, &tte[i];
|
||||
}
|
||||
@@ -89,10 +127,30 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
||||
// Find an entry to be replaced according to the replacement strategy
|
||||
TTEntry* replace = tte;
|
||||
for (int i = 1; i < ClusterSize; ++i)
|
||||
if ( (( tte[i].genBound8 & 0xFC) == generation8 || tte[i].bound() == BOUND_EXACT)
|
||||
- ((replace->genBound8 & 0xFC) == generation8)
|
||||
- (tte[i].depth8 < replace->depth8) < 0)
|
||||
// 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
|
||||
// two bound bits from affecting the result) to calculate the entry
|
||||
// age correctly even after generation8 overflows into the next cycle.
|
||||
if ( replace->depth8 - ((259 + generation8 - replace->genBound8) & 0xFC) * 2
|
||||
> tte[i].depth8 - ((259 + generation8 - tte[i].genBound8) & 0xFC) * 2)
|
||||
replace = &tte[i];
|
||||
|
||||
return found = false, replace;
|
||||
}
|
||||
|
||||
|
||||
/// TranspositionTable::hashfull() returns an approximation of the hashtable
|
||||
/// occupation during a search. The hash is x permill full, as per UCI protocol.
|
||||
|
||||
int TranspositionTable::hashfull() const {
|
||||
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < 1000 / ClusterSize; i++)
|
||||
{
|
||||
const TTEntry* tte = &table[i].entry[0];
|
||||
for (int j = 0; j < ClusterSize; j++)
|
||||
if ((tte[j].genBound8 & 0xFC) == generation8)
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -38,20 +39,9 @@ struct TTEntry {
|
||||
Move move() const { return (Move )move16; }
|
||||
Value value() const { return (Value)value16; }
|
||||
Value eval() const { return (Value)eval16; }
|
||||
Depth depth() const { return (Depth)depth8; }
|
||||
Depth depth() const { return (Depth)(depth8 * int(ONE_PLY)); }
|
||||
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
||||
|
||||
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
|
||||
|
||||
if (m || (k >> 48) != key16) // Preserve any existing move for the same position
|
||||
move16 = (uint16_t)m;
|
||||
|
||||
key16 = (uint16_t)(k >> 48);
|
||||
value16 = (int16_t)v;
|
||||
eval16 = (int16_t)ev;
|
||||
genBound8 = (uint8_t)(g | b);
|
||||
depth8 = (int8_t)d;
|
||||
}
|
||||
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev);
|
||||
|
||||
private:
|
||||
friend class TranspositionTable;
|
||||
@@ -68,33 +58,38 @@ private:
|
||||
/// A TranspositionTable consists of a power of 2 number of clusters and each
|
||||
/// cluster consists of ClusterSize number of TTEntry. Each non-empty entry
|
||||
/// contains information of exactly one position. The size of a cluster should
|
||||
/// not be bigger than a cache line size. In case it is less, it should be padded
|
||||
/// to guarantee always aligned accesses.
|
||||
/// divide the size of a cache line size, to ensure that clusters never cross
|
||||
/// cache lines. This ensures best cache performance, as the cacheline is
|
||||
/// prefetched, as soon as possible.
|
||||
|
||||
class TranspositionTable {
|
||||
|
||||
static const int CacheLineSize = 64;
|
||||
static const int ClusterSize = 3;
|
||||
static constexpr int CacheLineSize = 64;
|
||||
static constexpr int ClusterSize = 3;
|
||||
|
||||
struct Cluster {
|
||||
TTEntry entry[ClusterSize];
|
||||
char padding[2]; // Align to the cache line size
|
||||
char padding[2]; // Align to a divisor of the cache line size
|
||||
};
|
||||
|
||||
static_assert(CacheLineSize % sizeof(Cluster) == 0, "Cluster size incorrect");
|
||||
|
||||
public:
|
||||
~TranspositionTable() { free(mem); }
|
||||
void new_search() { generation8 += 4; } // Lower 2 bits are used by Bound
|
||||
uint8_t generation() const { return generation8; }
|
||||
TTEntry* probe(const Key key, bool& found) const;
|
||||
int hashfull() const;
|
||||
void resize(size_t mbSize);
|
||||
void clear();
|
||||
|
||||
// The lowest order bits of the key are used to get the index of the cluster
|
||||
// The 32 lowest order bits of the key are used to get the index of the cluster
|
||||
TTEntry* first_entry(const Key key) const {
|
||||
return &table[(size_t)key & (clusterCount - 1)].entry[0];
|
||||
return &table[(uint32_t(key) * uint64_t(clusterCount)) >> 32].entry[0];
|
||||
}
|
||||
|
||||
private:
|
||||
friend struct TTEntry;
|
||||
|
||||
size_t clusterCount;
|
||||
Cluster* table;
|
||||
void* mem;
|
||||
|
||||
+161
-139
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -33,13 +34,22 @@
|
||||
///
|
||||
/// -DUSE_POPCNT | Add runtime support for use of popcnt asm-instruction. Works
|
||||
/// | only in 64-bit mode and requires hardware with popcnt support.
|
||||
///
|
||||
/// -DUSE_PEXT | Add runtime support for use of pext asm-instruction. Works
|
||||
/// | only in 64-bit mode and requires hardware with pext support.
|
||||
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "platform.h"
|
||||
#if defined(_MSC_VER)
|
||||
// Disable some silly and noisy warning from MSVC compiler
|
||||
#pragma warning(disable: 4127) // Conditional expression is constant
|
||||
#pragma warning(disable: 4146) // Unary minus operator applied to unsigned type
|
||||
#pragma warning(disable: 4800) // Forcing value to bool 'true' or 'false'
|
||||
#endif
|
||||
|
||||
/// Predefined macros hell:
|
||||
///
|
||||
@@ -49,14 +59,13 @@
|
||||
/// _WIN32 Building on Windows (any)
|
||||
/// _WIN64 Building on Windows 64 bit
|
||||
|
||||
#if defined(_WIN64) && !defined(IS_64BIT) // Last condition means Makefile is not used
|
||||
# include <intrin.h> // MSVC popcnt and bsfq instrinsics
|
||||
#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
|
||||
# include <intrin.h> // Microsoft header for _BitScanForward64()
|
||||
# define IS_64BIT
|
||||
# define USE_BSFQ
|
||||
#endif
|
||||
|
||||
#if defined(USE_POPCNT) && defined(__INTEL_COMPILER) && defined(_MSC_VER)
|
||||
# include <nmmintrin.h> // Intel header for _mm_popcnt_u64() intrinsic
|
||||
#if defined(USE_POPCNT) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
||||
# include <nmmintrin.h> // Intel and Microsoft header for _mm_popcnt_u64()
|
||||
#endif
|
||||
|
||||
#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
||||
@@ -67,40 +76,32 @@
|
||||
# include <immintrin.h> // Header for _pext_u64() intrinsic
|
||||
# define pext(b, m) _pext_u64(b, m)
|
||||
#else
|
||||
# define pext(b, m) (0)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define FORCE_INLINE __forceinline
|
||||
#elif defined(__GNUC__)
|
||||
# define FORCE_INLINE inline __attribute__((always_inline))
|
||||
#else
|
||||
# define FORCE_INLINE inline
|
||||
# define pext(b, m) 0
|
||||
#endif
|
||||
|
||||
#ifdef USE_POPCNT
|
||||
const bool HasPopCnt = true;
|
||||
constexpr bool HasPopCnt = true;
|
||||
#else
|
||||
const bool HasPopCnt = false;
|
||||
constexpr bool HasPopCnt = false;
|
||||
#endif
|
||||
|
||||
#ifdef USE_PEXT
|
||||
const bool HasPext = true;
|
||||
constexpr bool HasPext = true;
|
||||
#else
|
||||
const bool HasPext = false;
|
||||
constexpr bool HasPext = false;
|
||||
#endif
|
||||
|
||||
#ifdef IS_64BIT
|
||||
const bool Is64Bit = true;
|
||||
constexpr bool Is64Bit = true;
|
||||
#else
|
||||
const bool Is64Bit = false;
|
||||
constexpr bool Is64Bit = false;
|
||||
#endif
|
||||
|
||||
typedef uint64_t Key;
|
||||
typedef uint64_t Bitboard;
|
||||
|
||||
const int MAX_MOVES = 256;
|
||||
const int MAX_PLY = 128;
|
||||
constexpr int MAX_MOVES = 256;
|
||||
constexpr int MAX_PLY = 128;
|
||||
|
||||
/// A move needs 16 bits to be stored
|
||||
///
|
||||
@@ -114,7 +115,7 @@ const int MAX_PLY = 128;
|
||||
/// any normal move destination square is always different from origin square
|
||||
/// while MOVE_NONE and MOVE_NULL have the same origin and destination square.
|
||||
|
||||
enum Move {
|
||||
enum Move : int {
|
||||
MOVE_NONE,
|
||||
MOVE_NULL = 65
|
||||
};
|
||||
@@ -127,7 +128,7 @@ enum MoveType {
|
||||
};
|
||||
|
||||
enum Color {
|
||||
WHITE, BLACK, NO_COLOR, COLOR_NB = 2
|
||||
WHITE, BLACK, COLOR_NB = 2
|
||||
};
|
||||
|
||||
enum CastlingSide {
|
||||
@@ -144,12 +145,6 @@ enum CastlingRight {
|
||||
CASTLING_RIGHT_NB = 16
|
||||
};
|
||||
|
||||
template<Color C, CastlingSide S> struct MakeCastling {
|
||||
static const CastlingRight
|
||||
right = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO
|
||||
: S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO;
|
||||
};
|
||||
|
||||
enum Phase {
|
||||
PHASE_ENDGAME,
|
||||
PHASE_MIDGAME = 128,
|
||||
@@ -158,7 +153,6 @@ enum Phase {
|
||||
|
||||
enum ScaleFactor {
|
||||
SCALE_FACTOR_DRAW = 0,
|
||||
SCALE_FACTOR_ONEPAWN = 48,
|
||||
SCALE_FACTOR_NORMAL = 64,
|
||||
SCALE_FACTOR_MAX = 128,
|
||||
SCALE_FACTOR_NONE = 255
|
||||
@@ -171,7 +165,7 @@ enum Bound {
|
||||
BOUND_EXACT = BOUND_UPPER | BOUND_LOWER
|
||||
};
|
||||
|
||||
enum Value {
|
||||
enum Value : int {
|
||||
VALUE_ZERO = 0,
|
||||
VALUE_DRAW = 0,
|
||||
VALUE_KNOWN_WIN = 10000,
|
||||
@@ -182,16 +176,13 @@ enum Value {
|
||||
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
||||
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
||||
|
||||
VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX,
|
||||
VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN,
|
||||
PawnValueMg = 136, PawnValueEg = 208,
|
||||
KnightValueMg = 782, KnightValueEg = 865,
|
||||
BishopValueMg = 830, BishopValueEg = 918,
|
||||
RookValueMg = 1289, RookValueEg = 1378,
|
||||
QueenValueMg = 2529, QueenValueEg = 2687,
|
||||
|
||||
PawnValueMg = 198, PawnValueEg = 258,
|
||||
KnightValueMg = 817, KnightValueEg = 846,
|
||||
BishopValueMg = 836, BishopValueEg = 857,
|
||||
RookValueMg = 1270, RookValueEg = 1278,
|
||||
QueenValueMg = 2521, QueenValueEg = 2558,
|
||||
|
||||
MidgameLimit = 15581, EndgameLimit = 3998
|
||||
MidgameLimit = 15258, EndgameLimit = 3915
|
||||
};
|
||||
|
||||
enum PieceType {
|
||||
@@ -207,20 +198,24 @@ enum Piece {
|
||||
PIECE_NB = 16
|
||||
};
|
||||
|
||||
enum Depth {
|
||||
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
||||
|
||||
enum Depth : int {
|
||||
|
||||
ONE_PLY = 1,
|
||||
|
||||
DEPTH_ZERO = 0,
|
||||
DEPTH_QS_CHECKS = 0,
|
||||
DEPTH_QS_NO_CHECKS = -1,
|
||||
DEPTH_QS_RECAPTURES = -5,
|
||||
DEPTH_ZERO = 0 * ONE_PLY,
|
||||
DEPTH_QS_CHECKS = 0 * ONE_PLY,
|
||||
DEPTH_QS_NO_CHECKS = -1 * ONE_PLY,
|
||||
DEPTH_QS_RECAPTURES = -5 * ONE_PLY,
|
||||
|
||||
DEPTH_NONE = -6,
|
||||
DEPTH_MAX = MAX_PLY
|
||||
DEPTH_NONE = -6 * ONE_PLY,
|
||||
DEPTH_MAX = MAX_PLY * ONE_PLY
|
||||
};
|
||||
|
||||
enum Square {
|
||||
static_assert(!(ONE_PLY & (ONE_PLY - 1)), "ONE_PLY is not a power of 2");
|
||||
|
||||
enum Square : int {
|
||||
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_A3, SQ_B3, SQ_C3, SQ_D3, SQ_E3, SQ_F3, SQ_G3, SQ_H3,
|
||||
@@ -231,138 +226,161 @@ enum Square {
|
||||
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
||||
SQ_NONE,
|
||||
|
||||
SQUARE_NB = 64,
|
||||
|
||||
DELTA_N = 8,
|
||||
DELTA_E = 1,
|
||||
DELTA_S = -8,
|
||||
DELTA_W = -1,
|
||||
|
||||
DELTA_NN = DELTA_N + DELTA_N,
|
||||
DELTA_NE = DELTA_N + DELTA_E,
|
||||
DELTA_SE = DELTA_S + DELTA_E,
|
||||
DELTA_SS = DELTA_S + DELTA_S,
|
||||
DELTA_SW = DELTA_S + DELTA_W,
|
||||
DELTA_NW = DELTA_N + DELTA_W
|
||||
SQUARE_NB = 64
|
||||
};
|
||||
|
||||
enum File {
|
||||
enum Direction : int {
|
||||
NORTH = 8,
|
||||
EAST = 1,
|
||||
SOUTH = -NORTH,
|
||||
WEST = -EAST,
|
||||
|
||||
NORTH_EAST = NORTH + EAST,
|
||||
SOUTH_EAST = SOUTH + EAST,
|
||||
SOUTH_WEST = SOUTH + WEST,
|
||||
NORTH_WEST = NORTH + WEST
|
||||
};
|
||||
|
||||
enum File : int {
|
||||
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB
|
||||
};
|
||||
|
||||
enum Rank {
|
||||
enum Rank : int {
|
||||
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
|
||||
};
|
||||
|
||||
|
||||
/// Score enum stores a middlegame and an endgame value in a single integer.
|
||||
/// The least significant 16 bits are used to store the endgame value and
|
||||
/// the upper 16 bits are used to store the middlegame value. The compiler
|
||||
/// is free to choose the enum type as long as it can store the data, so we
|
||||
/// ensure that Score is an integer type by assigning some big int values.
|
||||
enum Score {
|
||||
SCORE_ZERO,
|
||||
SCORE_ENSURE_INTEGER_SIZE_P = INT_MAX,
|
||||
SCORE_ENSURE_INTEGER_SIZE_N = INT_MIN
|
||||
};
|
||||
/// Score enum stores a middlegame and an endgame value in a single integer (enum).
|
||||
/// The least significant 16 bits are used to store the middlegame value and the
|
||||
/// upper 16 bits are used to store the endgame value. We have to take care to
|
||||
/// avoid left-shifting a signed int to avoid undefined behavior.
|
||||
enum Score : int { SCORE_ZERO };
|
||||
|
||||
inline Score make_score(int mg, int eg) {
|
||||
return Score((mg << 16) + eg);
|
||||
constexpr Score make_score(int mg, int eg) {
|
||||
return Score((int)((unsigned int)eg << 16) + mg);
|
||||
}
|
||||
|
||||
/// Extracting the signed lower and upper 16 bits is not so trivial because
|
||||
/// according to the standard a simple cast to short is implementation defined
|
||||
/// and so is a right shift of a signed integer.
|
||||
inline Value mg_value(Score s) {
|
||||
|
||||
union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s + 0x8000) >> 16) };
|
||||
return Value(mg.s);
|
||||
}
|
||||
|
||||
inline Value eg_value(Score s) {
|
||||
|
||||
union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s)) };
|
||||
union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s + 0x8000) >> 16) };
|
||||
return Value(eg.s);
|
||||
}
|
||||
|
||||
#define ENABLE_BASE_OPERATORS_ON(T) \
|
||||
inline T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
|
||||
inline T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \
|
||||
inline T operator*(int i, T d) { return T(i * int(d)); } \
|
||||
inline T operator*(T d, int i) { return T(int(d) * i); } \
|
||||
inline T operator-(T d) { return T(-int(d)); } \
|
||||
inline T& operator+=(T& d1, T d2) { return d1 = d1 + d2; } \
|
||||
inline T& operator-=(T& d1, T d2) { return d1 = d1 - d2; } \
|
||||
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); }
|
||||
inline Value mg_value(Score s) {
|
||||
union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s)) };
|
||||
return Value(mg.s);
|
||||
}
|
||||
|
||||
#define ENABLE_FULL_OPERATORS_ON(T) \
|
||||
ENABLE_BASE_OPERATORS_ON(T) \
|
||||
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
||||
inline T& operator--(T& d) { return d = T(int(d) - 1); } \
|
||||
inline T operator/(T d, int i) { return T(int(d) / i); } \
|
||||
inline int operator/(T d1, T d2) { return int(d1) / int(d2); } \
|
||||
#define ENABLE_BASE_OPERATORS_ON(T) \
|
||||
constexpr T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
|
||||
constexpr T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \
|
||||
constexpr T operator-(T d) { return T(-int(d)); } \
|
||||
inline T& operator+=(T& d1, T d2) { return d1 = d1 + d2; } \
|
||||
inline T& operator-=(T& d1, T d2) { return d1 = d1 - d2; }
|
||||
|
||||
#define ENABLE_INCR_OPERATORS_ON(T) \
|
||||
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
||||
inline T& operator--(T& d) { return d = T(int(d) - 1); }
|
||||
|
||||
#define ENABLE_FULL_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*(T d, int i) { return T(int(d) * i); } \
|
||||
constexpr T operator/(T d, int i) { return T(int(d) / i); } \
|
||||
constexpr int operator/(T d1, T d2) { return int(d1) / int(d2); } \
|
||||
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(PieceType)
|
||||
ENABLE_FULL_OPERATORS_ON(Piece)
|
||||
ENABLE_FULL_OPERATORS_ON(Color)
|
||||
ENABLE_FULL_OPERATORS_ON(Depth)
|
||||
ENABLE_FULL_OPERATORS_ON(Square)
|
||||
ENABLE_FULL_OPERATORS_ON(File)
|
||||
ENABLE_FULL_OPERATORS_ON(Rank)
|
||||
ENABLE_FULL_OPERATORS_ON(Direction)
|
||||
|
||||
ENABLE_INCR_OPERATORS_ON(PieceType)
|
||||
ENABLE_INCR_OPERATORS_ON(Piece)
|
||||
ENABLE_INCR_OPERATORS_ON(Color)
|
||||
ENABLE_INCR_OPERATORS_ON(Square)
|
||||
ENABLE_INCR_OPERATORS_ON(File)
|
||||
ENABLE_INCR_OPERATORS_ON(Rank)
|
||||
|
||||
ENABLE_BASE_OPERATORS_ON(Score)
|
||||
|
||||
#undef ENABLE_FULL_OPERATORS_ON
|
||||
#undef ENABLE_INCR_OPERATORS_ON
|
||||
#undef ENABLE_BASE_OPERATORS_ON
|
||||
|
||||
/// Additional operators to add integers to a Value
|
||||
inline Value operator+(Value v, int i) { return Value(int(v) + i); }
|
||||
inline Value operator-(Value v, int i) { return Value(int(v) - i); }
|
||||
constexpr Value operator+(Value v, int i) { return Value(int(v) + i); }
|
||||
constexpr Value operator-(Value v, int i) { return Value(int(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
|
||||
constexpr 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; }
|
||||
|
||||
/// Only declared but not defined. We don't want to multiply two scores due to
|
||||
/// a very high risk of overflow. So user should explicitly convert to integer.
|
||||
inline Score operator*(Score s1, Score s2);
|
||||
Score operator*(Score, Score) = delete;
|
||||
|
||||
/// Division of a Score must be handled separately for each term
|
||||
inline Score operator/(Score s, int i) {
|
||||
return make_score(mg_value(s) / i, eg_value(s) / i);
|
||||
}
|
||||
|
||||
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
||||
/// Multiplication of a Score by an integer. We check for overflow in debug mode.
|
||||
inline Score operator*(Score s, int i) {
|
||||
|
||||
inline Color operator~(Color c) {
|
||||
return Color(c ^ BLACK);
|
||||
Score result = Score(int(s) * i);
|
||||
|
||||
assert(eg_value(result) == (i * eg_value(s)));
|
||||
assert(mg_value(result) == (i * mg_value(s)));
|
||||
assert((i == 0) || (result / i) == s);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Square operator~(Square s) {
|
||||
constexpr Color operator~(Color c) {
|
||||
return Color(c ^ BLACK); // Toggle color
|
||||
}
|
||||
|
||||
constexpr Square operator~(Square s) {
|
||||
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
|
||||
}
|
||||
|
||||
inline CastlingRight operator|(Color c, CastlingSide s) {
|
||||
constexpr File operator~(File f) {
|
||||
return File(f ^ FILE_H); // Horizontal flip FILE_A -> FILE_H
|
||||
}
|
||||
|
||||
constexpr Piece operator~(Piece pc) {
|
||||
return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
|
||||
}
|
||||
|
||||
constexpr CastlingRight operator|(Color c, CastlingSide s) {
|
||||
return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
|
||||
}
|
||||
|
||||
inline Value mate_in(int ply) {
|
||||
constexpr Value mate_in(int ply) {
|
||||
return VALUE_MATE - ply;
|
||||
}
|
||||
|
||||
inline Value mated_in(int ply) {
|
||||
constexpr Value mated_in(int ply) {
|
||||
return -VALUE_MATE + ply;
|
||||
}
|
||||
|
||||
inline Square make_square(File f, Rank r) {
|
||||
return Square((r << 3) | f);
|
||||
constexpr Square make_square(File f, Rank r) {
|
||||
return Square((r << 3) + f);
|
||||
}
|
||||
|
||||
inline Piece make_piece(Color c, PieceType pt) {
|
||||
return Piece((c << 3) | pt);
|
||||
constexpr Piece make_piece(Color c, PieceType pt) {
|
||||
return Piece((c << 3) + pt);
|
||||
}
|
||||
|
||||
inline PieceType type_of(Piece pc) {
|
||||
constexpr PieceType type_of(Piece pc) {
|
||||
return PieceType(pc & 7);
|
||||
}
|
||||
|
||||
@@ -371,27 +389,27 @@ inline Color color_of(Piece pc) {
|
||||
return Color(pc >> 3);
|
||||
}
|
||||
|
||||
inline bool is_ok(Square s) {
|
||||
constexpr bool is_ok(Square s) {
|
||||
return s >= SQ_A1 && s <= SQ_H8;
|
||||
}
|
||||
|
||||
inline File file_of(Square s) {
|
||||
constexpr File file_of(Square s) {
|
||||
return File(s & 7);
|
||||
}
|
||||
|
||||
inline Rank rank_of(Square s) {
|
||||
constexpr Rank rank_of(Square s) {
|
||||
return Rank(s >> 3);
|
||||
}
|
||||
|
||||
inline Square relative_square(Color c, Square s) {
|
||||
constexpr Square relative_square(Color c, Square s) {
|
||||
return Square(s ^ (c * 56));
|
||||
}
|
||||
|
||||
inline Rank relative_rank(Color c, Rank r) {
|
||||
constexpr Rank relative_rank(Color c, Rank r) {
|
||||
return Rank(r ^ (c * 7));
|
||||
}
|
||||
|
||||
inline Rank relative_rank(Color c, Square s) {
|
||||
constexpr Rank relative_rank(Color c, Square s) {
|
||||
return relative_rank(c, rank_of(s));
|
||||
}
|
||||
|
||||
@@ -400,36 +418,40 @@ inline bool opposite_colors(Square s1, Square s2) {
|
||||
return ((s >> 3) ^ s) & 1;
|
||||
}
|
||||
|
||||
inline Square pawn_push(Color c) {
|
||||
return c == WHITE ? DELTA_N : DELTA_S;
|
||||
constexpr Direction pawn_push(Color c) {
|
||||
return c == WHITE ? NORTH : SOUTH;
|
||||
}
|
||||
|
||||
inline Square from_sq(Move m) {
|
||||
constexpr Square from_sq(Move m) {
|
||||
return Square((m >> 6) & 0x3F);
|
||||
}
|
||||
|
||||
inline Square to_sq(Move m) {
|
||||
constexpr Square to_sq(Move m) {
|
||||
return Square(m & 0x3F);
|
||||
}
|
||||
|
||||
inline MoveType type_of(Move m) {
|
||||
constexpr int from_to(Move m) {
|
||||
return m & 0xFFF;
|
||||
}
|
||||
|
||||
constexpr MoveType type_of(Move m) {
|
||||
return MoveType(m & (3 << 14));
|
||||
}
|
||||
|
||||
inline PieceType promotion_type(Move m) {
|
||||
return PieceType(((m >> 12) & 3) + 2);
|
||||
constexpr PieceType promotion_type(Move m) {
|
||||
return PieceType(((m >> 12) & 3) + KNIGHT);
|
||||
}
|
||||
|
||||
inline Move make_move(Square from, Square to) {
|
||||
return Move(to | (from << 6));
|
||||
constexpr Move make_move(Square from, Square to) {
|
||||
return Move((from << 6) + to);
|
||||
}
|
||||
|
||||
template<MoveType T>
|
||||
inline Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
||||
return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12));
|
||||
constexpr Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
||||
return Move(T + ((pt - KNIGHT) << 12) + (from << 6) + to);
|
||||
}
|
||||
|
||||
inline bool is_ok(Move m) {
|
||||
constexpr bool is_ok(Move m) {
|
||||
return from_sq(m) != to_sq(m); // Catch MOVE_NULL and MOVE_NONE
|
||||
}
|
||||
|
||||
|
||||
+93
-59
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -17,6 +18,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -26,30 +28,27 @@
|
||||
#include "position.h"
|
||||
#include "search.h"
|
||||
#include "thread.h"
|
||||
#include "timeman.h"
|
||||
#include "tt.h"
|
||||
#include "uci.h"
|
||||
#include "syzygy/tbprobe.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern void benchmark(const Position& pos, istream& is);
|
||||
extern vector<string> setup_bench(const Position&, istream&);
|
||||
|
||||
namespace {
|
||||
|
||||
// FEN string of the initial position, normal chess
|
||||
const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||
|
||||
// Stack to keep track of the position states along the setup moves (from the
|
||||
// start position to the position just before the search starts). Needed by
|
||||
// 'draw by repetition' detection.
|
||||
Search::StateStackPtr SetupStates;
|
||||
|
||||
|
||||
// position() is called when engine receives the "position" UCI command.
|
||||
// The function sets up the position described in the given FEN string ("fen")
|
||||
// or the starting position ("startpos") and then makes the moves given in the
|
||||
// following move list ("moves").
|
||||
|
||||
void position(Position& pos, istringstream& is) {
|
||||
void position(Position& pos, istringstream& is, StateListPtr& states) {
|
||||
|
||||
Move m;
|
||||
string token, fen;
|
||||
@@ -67,14 +66,14 @@ namespace {
|
||||
else
|
||||
return;
|
||||
|
||||
pos.set(fen, Options["UCI_Chess960"], Threads.main());
|
||||
SetupStates = Search::StateStackPtr(new std::stack<StateInfo>());
|
||||
states = StateListPtr(new std::deque<StateInfo>(1)); // Drop old and create a new one
|
||||
pos.set(fen, Options["UCI_Chess960"], &states->back(), Threads.main());
|
||||
|
||||
// Parse move list (if any)
|
||||
while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE)
|
||||
{
|
||||
SetupStates->push(StateInfo());
|
||||
pos.do_move(m, SetupStates->top());
|
||||
states->emplace_back();
|
||||
pos.do_move(m, states->back());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,11 +89,11 @@ namespace {
|
||||
|
||||
// Read option name (can contain spaces)
|
||||
while (is >> token && token != "value")
|
||||
name += string(" ", !name.empty()) + token;
|
||||
name += (name.empty() ? "" : " ") + token;
|
||||
|
||||
// Read option value (can contain spaces)
|
||||
while (is >> token)
|
||||
value += string(" ", !value.empty()) + token;
|
||||
value += (value.empty() ? "" : " ") + token;
|
||||
|
||||
if (Options.count(name))
|
||||
Options[name] = value;
|
||||
@@ -107,10 +106,13 @@ namespace {
|
||||
// the thinking time and other parameters from the input string, then starts
|
||||
// the search.
|
||||
|
||||
void go(const Position& pos, istringstream& is) {
|
||||
void go(Position& pos, istringstream& is, StateListPtr& states) {
|
||||
|
||||
Search::LimitsType limits;
|
||||
string token;
|
||||
bool ponderMode = false;
|
||||
|
||||
limits.startTime = now(); // As early as possible!
|
||||
|
||||
while (is >> token)
|
||||
if (token == "searchmoves")
|
||||
@@ -126,10 +128,53 @@ namespace {
|
||||
else if (token == "nodes") is >> limits.nodes;
|
||||
else if (token == "movetime") is >> limits.movetime;
|
||||
else if (token == "mate") is >> limits.mate;
|
||||
else if (token == "infinite") limits.infinite = true;
|
||||
else if (token == "ponder") limits.ponder = true;
|
||||
else if (token == "perft") is >> limits.perft;
|
||||
else if (token == "infinite") limits.infinite = 1;
|
||||
else if (token == "ponder") ponderMode = true;
|
||||
|
||||
Threads.start_thinking(pos, limits, SetupStates);
|
||||
Threads.start_thinking(pos, states, limits, ponderMode);
|
||||
}
|
||||
|
||||
|
||||
// bench() is called when engine receives the "bench" command. Firstly
|
||||
// a list of UCI commands is setup according to bench parameters, then
|
||||
// it is run one by one printing a summary at the end.
|
||||
|
||||
void bench(Position& pos, istream& args, StateListPtr& states) {
|
||||
|
||||
string token;
|
||||
uint64_t num, nodes = 0, cnt = 1;
|
||||
|
||||
vector<string> list = setup_bench(pos, args);
|
||||
num = count_if(list.begin(), list.end(), [](string s) { return s.find("go ") == 0; });
|
||||
|
||||
TimePoint elapsed = now();
|
||||
|
||||
for (const auto& cmd : list)
|
||||
{
|
||||
istringstream is(cmd);
|
||||
is >> skipws >> token;
|
||||
|
||||
if (token == "go")
|
||||
{
|
||||
cerr << "\nPosition: " << cnt++ << '/' << num << endl;
|
||||
go(pos, is, states);
|
||||
Threads.main()->wait_for_search_finished();
|
||||
nodes += Threads.nodes_searched();
|
||||
}
|
||||
else if (token == "setoption") setoption(is);
|
||||
else if (token == "position") position(pos, is, states);
|
||||
else if (token == "ucinewgame") Search::clear();
|
||||
}
|
||||
|
||||
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
||||
|
||||
dbg_print(); // Just before exiting
|
||||
|
||||
cerr << "\n==========================="
|
||||
<< "\nTotal time (ms) : " << elapsed
|
||||
<< "\nNodes searched : " << nodes
|
||||
<< "\nNodes/second : " << 1000 * nodes / elapsed << endl;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -143,8 +188,12 @@ namespace {
|
||||
|
||||
void UCI::loop(int argc, char* argv[]) {
|
||||
|
||||
Position pos(StartFEN, false, Threads.main()); // The root position
|
||||
Position pos;
|
||||
string token, cmd;
|
||||
StateListPtr states(new std::deque<StateInfo>(1));
|
||||
auto uiThread = std::make_shared<Thread>(0);
|
||||
|
||||
pos.set(StartFEN, false, &states->back(), uiThread.get());
|
||||
|
||||
for (int i = 1; i < argc; ++i)
|
||||
cmd += std::string(argv[i]) + " ";
|
||||
@@ -155,57 +204,42 @@ void UCI::loop(int argc, char* argv[]) {
|
||||
|
||||
istringstream is(cmd);
|
||||
|
||||
token.clear(); // getline() could return empty or blank line
|
||||
token.clear(); // Avoid a stale if getline() returns empty or blank line
|
||||
is >> skipws >> token;
|
||||
|
||||
// The GUI sends 'ponderhit' to tell us to ponder on the same move the
|
||||
// opponent has played. In case Signals.stopOnPonderhit is set we are
|
||||
// waiting for 'ponderhit' to stop the search (for instance because we
|
||||
// already ran out of time), otherwise we should continue searching but
|
||||
// switching from pondering to normal search.
|
||||
// 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
|
||||
// user has played. We should continue searching but switch from pondering to
|
||||
// normal search. In case Threads.stopOnPonderhit is set we are waiting for
|
||||
// 'ponderhit' to stop the search, for instance if max search depth is reached.
|
||||
if ( token == "quit"
|
||||
|| token == "stop"
|
||||
|| (token == "ponderhit" && Search::Signals.stopOnPonderhit))
|
||||
{
|
||||
Search::Signals.stop = true;
|
||||
Threads.main()->notify_one(); // Could be sleeping
|
||||
}
|
||||
|| (token == "ponderhit" && Threads.stopOnPonderhit))
|
||||
Threads.stop = true;
|
||||
|
||||
else if (token == "ponderhit")
|
||||
Search::Limits.ponder = false; // Switch to normal search
|
||||
Threads.ponder = false; // Switch to normal search
|
||||
|
||||
else if (token == "uci")
|
||||
sync_cout << "id name " << engine_info(true)
|
||||
<< "\n" << Options
|
||||
<< "\nuciok" << sync_endl;
|
||||
|
||||
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
||||
else if (token == "ucinewgame") TT.clear();
|
||||
else if (token == "go") go(pos, is);
|
||||
else if (token == "position") position(pos, is);
|
||||
else if (token == "setoption") setoption(is);
|
||||
else if (token == "go") go(pos, is, states);
|
||||
else if (token == "position") position(pos, is, states);
|
||||
else if (token == "ucinewgame") Search::clear();
|
||||
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
||||
|
||||
// Additional custom non-UCI commands, useful for debugging
|
||||
else if (token == "flip") pos.flip();
|
||||
else if (token == "bench") benchmark(pos, is);
|
||||
else if (token == "d") sync_cout << pos << sync_endl;
|
||||
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
||||
else if (token == "perft")
|
||||
{
|
||||
int depth;
|
||||
stringstream ss;
|
||||
|
||||
is >> depth;
|
||||
ss << Options["Hash"] << " "
|
||||
<< Options["Threads"] << " " << depth << " current perft";
|
||||
|
||||
benchmark(pos, ss);
|
||||
}
|
||||
// Additional custom non-UCI commands, mainly for debugging
|
||||
else if (token == "flip") pos.flip();
|
||||
else if (token == "bench") bench(pos, is, states);
|
||||
else if (token == "d") sync_cout << pos << sync_endl;
|
||||
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
||||
else
|
||||
sync_cout << "Unknown command: " << cmd << sync_endl;
|
||||
|
||||
} while (token != "quit" && argc == 1); // Passed args have one-shot behaviour
|
||||
|
||||
Threads.wait_for_think_finished(); // Cannot quit whilst the search is running
|
||||
} while (token != "quit" && argc == 1); // Command line args are one-shot
|
||||
}
|
||||
|
||||
|
||||
@@ -218,6 +252,8 @@ void UCI::loop(int argc, char* argv[]) {
|
||||
|
||||
string UCI::value(Value v) {
|
||||
|
||||
assert(-VALUE_INFINITE < v && v < VALUE_INFINITE);
|
||||
|
||||
stringstream ss;
|
||||
|
||||
if (abs(v) < VALUE_MATE - MAX_PLY)
|
||||
@@ -232,9 +268,7 @@ string UCI::value(Value v) {
|
||||
/// UCI::square() converts a Square to a string in algebraic notation (g1, a7, etc.)
|
||||
|
||||
std::string UCI::square(Square s) {
|
||||
|
||||
char sq[] = { char('a' + file_of(s)), char('1' + rank_of(s)), 0 }; // NULL terminated
|
||||
return sq;
|
||||
return std::string{ char('a' + file_of(s)), char('1' + rank_of(s)) };
|
||||
}
|
||||
|
||||
|
||||
@@ -274,9 +308,9 @@ Move UCI::to_move(const Position& pos, string& str) {
|
||||
if (str.length() == 5) // Junior could send promotion piece in uppercase
|
||||
str[4] = char(tolower(str[4]));
|
||||
|
||||
for (MoveList<LEGAL> it(pos); *it; ++it)
|
||||
if (str == UCI::move(*it, pos.is_chess960()))
|
||||
return *it;
|
||||
for (const auto& m : MoveList<LEGAL>(pos))
|
||||
if (str == UCI::move(m, pos.is_chess960()))
|
||||
return m;
|
||||
|
||||
return MOVE_NONE;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -17,8 +18,8 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UCIOPTION_H_INCLUDED
|
||||
#define UCIOPTION_H_INCLUDED
|
||||
#ifndef UCI_H_INCLUDED
|
||||
#define UCI_H_INCLUDED
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -45,15 +46,17 @@ class Option {
|
||||
typedef void (*OnChange)(const Option&);
|
||||
|
||||
public:
|
||||
Option(OnChange = NULL);
|
||||
Option(bool v, OnChange = NULL);
|
||||
Option(const char* v, OnChange = NULL);
|
||||
Option(int v, int min, int max, OnChange = NULL);
|
||||
Option(OnChange = nullptr);
|
||||
Option(bool v, OnChange = nullptr);
|
||||
Option(const char* v, 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&);
|
||||
void operator<<(const Option&);
|
||||
operator int() const;
|
||||
operator double() const;
|
||||
operator std::string() const;
|
||||
bool operator==(const char*) const;
|
||||
|
||||
private:
|
||||
friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
|
||||
@@ -69,10 +72,11 @@ void loop(int argc, char* argv[]);
|
||||
std::string value(Value v);
|
||||
std::string square(Square s);
|
||||
std::string move(Move m, bool chess960);
|
||||
std::string pv(const Position& pos, Depth depth, Value alpha, Value beta);
|
||||
Move to_move(const Position& pos, std::string& str);
|
||||
|
||||
} // namespace UCI
|
||||
|
||||
extern UCI::OptionsMap Options;
|
||||
|
||||
#endif // #ifndef UCIOPTION_H_INCLUDED
|
||||
#endif // #ifndef UCI_H_INCLUDED
|
||||
|
||||
+41
-26
@@ -2,6 +2,7 @@
|
||||
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-2019 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
|
||||
@@ -19,10 +20,10 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <ostream>
|
||||
|
||||
#include "misc.h"
|
||||
#include "search.h"
|
||||
#include "thread.h"
|
||||
#include "tt.h"
|
||||
#include "uci.h"
|
||||
@@ -35,18 +36,18 @@ UCI::OptionsMap Options; // Global object
|
||||
namespace UCI {
|
||||
|
||||
/// 'On change' actions, triggered by an option's value change
|
||||
void on_clear_hash(const Option&) { TT.clear(); }
|
||||
void on_clear_hash(const Option&) { Search::clear(); }
|
||||
void on_hash_size(const Option& o) { TT.resize(o); }
|
||||
void on_logger(const Option& o) { start_logger(o); }
|
||||
void on_threads(const Option&) { Threads.read_uci_options(); }
|
||||
void on_threads(const Option& o) { Threads.set(o); }
|
||||
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
||||
|
||||
|
||||
/// Our case insensitive less() function as required by UCI protocol
|
||||
bool ci_less(char c1, char c2) { return tolower(c1) < tolower(c2); }
|
||||
|
||||
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
|
||||
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
|
||||
|
||||
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
|
||||
[](char c1, char c2) { return tolower(c1) < tolower(c2); });
|
||||
}
|
||||
|
||||
|
||||
@@ -54,25 +55,28 @@ bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const
|
||||
|
||||
void init(OptionsMap& o) {
|
||||
|
||||
const int MaxHashMB = Is64Bit ? 1024 * 1024 : 2048;
|
||||
// at most 2^32 clusters.
|
||||
constexpr int MaxHashMB = Is64Bit ? 131072 : 2048;
|
||||
|
||||
o["Write Debug Log"] << Option(false, on_logger);
|
||||
o["Contempt"] << Option(0, -100, 100);
|
||||
o["Min Split Depth"] << Option(0, 0, 12, on_threads);
|
||||
o["Threads"] << Option(1, 1, MAX_THREADS, on_threads);
|
||||
o["Debug Log File"] << Option("", on_logger);
|
||||
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["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
|
||||
o["Clear Hash"] << Option(on_clear_hash);
|
||||
o["Ponder"] << Option(true);
|
||||
o["Ponder"] << Option(false);
|
||||
o["MultiPV"] << Option(1, 1, 500);
|
||||
o["Skill Level"] << Option(20, 0, 20);
|
||||
o["Move Overhead"] << Option(30, 0, 5000);
|
||||
o["Minimum Thinking Time"] << Option(20, 0, 5000);
|
||||
o["Slow Mover"] << Option(80, 10, 1000);
|
||||
o["Slow Mover"] << Option(84, 10, 1000);
|
||||
o["nodestime"] << Option(0, 0, 10000);
|
||||
o["UCI_Chess960"] << Option(false);
|
||||
o["UCI_AnalyseMode"] << Option(false);
|
||||
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
||||
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
||||
o["Syzygy50MoveRule"] << Option(true);
|
||||
o["SyzygyProbeLimit"] << Option(6, 0, 6);
|
||||
o["SyzygyProbeLimit"] << Option(7, 0, 7);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,20 +86,23 @@ void init(OptionsMap& o) {
|
||||
std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
|
||||
|
||||
for (size_t idx = 0; idx < om.size(); ++idx)
|
||||
for (OptionsMap::const_iterator it = om.begin(); it != om.end(); ++it)
|
||||
if (it->second.idx == idx)
|
||||
for (const auto& it : om)
|
||||
if (it.second.idx == idx)
|
||||
{
|
||||
const Option& o = it->second;
|
||||
os << "\noption name " << it->first << " type " << o.type;
|
||||
const Option& o = it.second;
|
||||
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;
|
||||
|
||||
if (o.type == "spin")
|
||||
os << " min " << o.min << " max " << o.max;
|
||||
os << " default " << int(stof(o.defaultValue))
|
||||
<< " min " << o.min
|
||||
<< " max " << o.max;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -111,13 +118,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(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
|
||||
{ std::ostringstream ss; ss << v; defaultValue = currentValue = ss.str(); }
|
||||
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); }
|
||||
|
||||
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 int() const {
|
||||
Option::operator double() const {
|
||||
assert(type == "check" || type == "spin");
|
||||
return (type == "spin" ? atoi(currentValue.c_str()) : currentValue == "true");
|
||||
return (type == "spin" ? stof(currentValue) : currentValue == "true");
|
||||
}
|
||||
|
||||
Option::operator std::string() const {
|
||||
@@ -125,6 +134,12 @@ Option::operator std::string() const {
|
||||
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
|
||||
|
||||
@@ -147,7 +162,7 @@ Option& Option::operator=(const string& v) {
|
||||
|
||||
if ( (type != "button" && v.empty())
|
||||
|| (type == "check" && v != "true" && v != "false")
|
||||
|| (type == "spin" && (atoi(v.c_str()) < min || atoi(v.c_str()) > max)))
|
||||
|| (type == "spin" && (stof(v) < min || stof(v) > max)))
|
||||
return *this;
|
||||
|
||||
if (type != "button")
|
||||
|
||||
Executable
+144
@@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
# check for errors under valgrind or sanitizers.
|
||||
|
||||
error()
|
||||
{
|
||||
echo "instrumented testing failed on line $1"
|
||||
exit 1
|
||||
}
|
||||
trap 'error ${LINENO}' ERR
|
||||
|
||||
# define suitable post and prefixes for testing options
|
||||
case $1 in
|
||||
--valgrind)
|
||||
echo "valgrind testing started"
|
||||
prefix=''
|
||||
exeprefix='valgrind --error-exitcode=42'
|
||||
postfix='1>/dev/null'
|
||||
threads="1"
|
||||
;;
|
||||
--valgrind-thread)
|
||||
echo "valgrind-thread testing started"
|
||||
prefix=''
|
||||
exeprefix='valgrind --error-exitcode=42'
|
||||
postfix='1>/dev/null'
|
||||
threads="2"
|
||||
;;
|
||||
--sanitizer-undefined)
|
||||
echo "sanitizer-undefined testing started"
|
||||
prefix='!'
|
||||
exeprefix=''
|
||||
postfix='2>&1 | grep "runtime error:"'
|
||||
threads="1"
|
||||
;;
|
||||
--sanitizer-thread)
|
||||
echo "sanitizer-thread testing started"
|
||||
prefix='!'
|
||||
exeprefix=''
|
||||
postfix='2>&1 | grep "WARNING: ThreadSanitizer:"'
|
||||
threads="2"
|
||||
|
||||
cat << EOF > tsan.supp
|
||||
race:TTEntry::move
|
||||
race:TTEntry::depth
|
||||
race:TTEntry::bound
|
||||
race:TTEntry::save
|
||||
race:TTEntry::value
|
||||
race:TTEntry::eval
|
||||
|
||||
race:TranspositionTable::probe
|
||||
race:TranspositionTable::hashfull
|
||||
|
||||
EOF
|
||||
|
||||
export TSAN_OPTIONS="suppressions=./tsan.supp"
|
||||
|
||||
;;
|
||||
*)
|
||||
echo "unknown testing started"
|
||||
prefix=''
|
||||
exeprefix=''
|
||||
postfix=''
|
||||
threads="1"
|
||||
;;
|
||||
esac
|
||||
|
||||
# simple command line testing
|
||||
for args in "eval" \
|
||||
"go nodes 1000" \
|
||||
"go depth 10" \
|
||||
"go movetime 1000" \
|
||||
"go wtime 8000 btime 8000 winc 500 binc 500" \
|
||||
"bench 128 $threads 10 default depth"
|
||||
do
|
||||
|
||||
echo "$prefix $exeprefix ./stockfish $args $postfix"
|
||||
eval "$prefix $exeprefix ./stockfish $args $postfix"
|
||||
|
||||
done
|
||||
|
||||
# more general testing, following an uci protocol exchange
|
||||
cat << EOF > game.exp
|
||||
set timeout 10
|
||||
spawn $exeprefix ./stockfish
|
||||
|
||||
send "uci\n"
|
||||
expect "uciok"
|
||||
|
||||
send "setoption name Threads value $threads\n"
|
||||
|
||||
send "ucinewgame\n"
|
||||
send "position startpos\n"
|
||||
send "go nodes 1000\n"
|
||||
expect "bestmove"
|
||||
|
||||
send "position startpos moves e2e4 e7e6\n"
|
||||
send "go nodes 1000\n"
|
||||
expect "bestmove"
|
||||
|
||||
send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
|
||||
send "go depth 30\n"
|
||||
expect "bestmove"
|
||||
|
||||
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
|
||||
|
||||
#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
|
||||
|
||||
echo "$prefix expect $exp $postfix"
|
||||
eval "$prefix expect $exp $postfix"
|
||||
|
||||
rm $exp
|
||||
|
||||
done
|
||||
|
||||
rm -f tsan.supp
|
||||
|
||||
echo "instrumented testing OK"
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
# verify perft numbers (positions from https://chessprogramming.wikispaces.com/Perft+Results)
|
||||
|
||||
error()
|
||||
{
|
||||
echo "perft testing failed on line $1"
|
||||
exit 1
|
||||
}
|
||||
trap 'error ${LINENO}' ERR
|
||||
|
||||
echo "perft testing started"
|
||||
|
||||
cat << EOF > perft.exp
|
||||
set timeout 10
|
||||
lassign \$argv pos depth result
|
||||
spawn ./stockfish
|
||||
send "position \$pos\\ngo perft \$depth\\n"
|
||||
expect "Nodes searched? \$result" {} timeout {exit 1}
|
||||
send "quit\\n"
|
||||
expect eof
|
||||
EOF
|
||||
|
||||
expect perft.exp startpos 5 4865609 > /dev/null
|
||||
expect perft.exp "fen r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -" 5 193690690 > /dev/null
|
||||
expect perft.exp "fen 8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -" 6 11030083 > /dev/null
|
||||
expect perft.exp "fen r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1" 5 15833292 > /dev/null
|
||||
expect perft.exp "fen rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8" 5 89941194 > /dev/null
|
||||
expect perft.exp "fen r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10" 5 164075551 > /dev/null
|
||||
|
||||
rm perft.exp
|
||||
|
||||
echo "perft testing OK"
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
# verify reproducible search
|
||||
|
||||
error()
|
||||
{
|
||||
echo "reprosearch testing failed on line $1"
|
||||
exit 1
|
||||
}
|
||||
trap 'error ${LINENO}' ERR
|
||||
|
||||
echo "reprosearch testing started"
|
||||
|
||||
# repeat two short games, separated by ucinewgame.
|
||||
# with go nodes $nodes they should result in exactly
|
||||
# the same node count for each iteration.
|
||||
cat << EOF > repeat.exp
|
||||
set timeout 10
|
||||
spawn ./stockfish
|
||||
lassign \$argv nodes
|
||||
|
||||
send "uci\n"
|
||||
expect "uciok"
|
||||
|
||||
send "ucinewgame\n"
|
||||
send "position startpos\n"
|
||||
send "go nodes \$nodes\n"
|
||||
expect "bestmove"
|
||||
|
||||
send "position startpos moves e2e4 e7e6\n"
|
||||
send "go nodes \$nodes\n"
|
||||
expect "bestmove"
|
||||
|
||||
send "ucinewgame\n"
|
||||
send "position startpos\n"
|
||||
send "go nodes \$nodes\n"
|
||||
expect "bestmove"
|
||||
|
||||
send "position startpos moves e2e4 e7e6\n"
|
||||
send "go nodes \$nodes\n"
|
||||
expect "bestmove"
|
||||
|
||||
send "quit\n"
|
||||
expect eof
|
||||
EOF
|
||||
|
||||
# to increase the likelyhood of finding a non-reproducible case,
|
||||
# the allowed number of nodes are varied systematically
|
||||
for i in `seq 1 20`
|
||||
do
|
||||
|
||||
nodes=$((100*3**i/2**i))
|
||||
echo "reprosearch testing with $nodes nodes"
|
||||
|
||||
# each line should appear exactly an even number of times
|
||||
expect repeat.exp $nodes 2>&1 | grep -o "nodes [0-9]*" | sort | uniq -c | awk '{if ($1%2!=0) exit(1)}'
|
||||
|
||||
done
|
||||
|
||||
rm repeat.exp
|
||||
|
||||
echo "reprosearch testing OK"
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
# obtain and optionally verify Bench / signature
|
||||
# if no reference is given, the output is deliberately limited to just the signature
|
||||
|
||||
error()
|
||||
{
|
||||
echo "running bench for signature failed on line $1"
|
||||
exit 1
|
||||
}
|
||||
trap 'error ${LINENO}' ERR
|
||||
|
||||
# obtain
|
||||
|
||||
signature=`./stockfish bench 2>&1 | grep "Nodes searched : " | awk '{print $4}'`
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
# compare to given reference
|
||||
if [ "$1" != "$signature" ]; then
|
||||
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
|
||||
else
|
||||
echo "signature OK: $signature"
|
||||
fi
|
||||
else
|
||||
# just report signature
|
||||
echo $signature
|
||||
fi
|
||||
Reference in New Issue
Block a user