mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 13:17:44 +00:00
Compare commits
2373 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 5b555525d2 | |||
| c4518e395e | |||
| d8b3ad2208 | |||
| ec36b8dea9 | |||
| 14f7d9a629 | |||
| 8ebf30d44a | |||
| 5154ac9cff | |||
| 54b5b528d9 | |||
| 44643c2770 | |||
| 69407ae9b8 | |||
| 18375e3bfb | |||
| 6390a3da94 | |||
| 36f8814aa6 | |||
| 96e36a7897 | |||
| 2ca2c3f35b | |||
| f54c44e6be | |||
| ca3622f8e8 | |||
| 97a034ad3e | |||
| 1b62b47b62 | |||
| 7f51610103 | |||
| 712bbb052e | |||
| fe4fda474f | |||
| f7d8ea3866 | |||
| f53aea45e3 | |||
| 3c07603dac | |||
| c73f33f37e | |||
| 05cb58f4fc | |||
| 595fc342cf | |||
| 58fdb84b0d | |||
| ab276357d7 | |||
| 4abe333e1f | |||
| 7b20bb6e1a | |||
| 4eb2d8ce09 | |||
| b97df4c236 | |||
| 17bcdb9212 | |||
| 202a78e8e4 | |||
| 42b48b08e8 | |||
| aea2fde611 | |||
| b73ae56ee1 | |||
| 3fda064a66 | |||
| a6e292034a | |||
| c7332d5610 | |||
| 9d1e2c0e76 | |||
| c150f07291 | |||
| 62f531254e | |||
| 91cc82aa25 | |||
| 19b8249ff4 | |||
| 25b492ab58 | |||
| 4c9b423161 | |||
| 2416242c96 | |||
| 6933f05f4b | |||
| f9571e8d57 | |||
| 2bfacf136c | |||
| 296534f234 | |||
| e5c7b44f7a | |||
| 3231038262 | |||
| 9cae6e66ce | |||
| 46d5fff01f | |||
| b8fd1a78dc | |||
| 413b243809 | |||
| 0edb6348d2 | |||
| 14cf27e6f6 | |||
| 7b4828b68c | |||
| f6d220ab14 | |||
| afafdf7b73 | |||
| b15dcd9774 | |||
| 94dd204c3b | |||
| 5943600a89 | |||
| 589c711449 | |||
| 158864270a | |||
| a87da2c4b3 | |||
| fbb53524ef | |||
| ba1464751d | |||
| eeb6d923fa | |||
| c30eb4c9c9 | |||
| 35c1ccef39 | |||
| 0935dca9a6 | |||
| 314d446518 | |||
| c014444f09 | |||
| 9b4e123fbe | |||
| a43f633c19 | |||
| 66f5cd3f9d | |||
| fe07ae4cb4 | |||
| 2c52147dbf | |||
| 7caa6cd338 | |||
| 4509eb1342 | |||
| 7ad59d9ac9 | |||
| 48127fe5d3 | |||
| 84408e5cd6 | |||
| 79232be02a | |||
| 0a1f54975f | |||
| bffe32f4fe | |||
| 4aca11ae2a | |||
| 1a939cd8c8 | |||
| d65c9a3262 | |||
| 99f2c1a2a6 | |||
| 3b1f552b08 | |||
| 4840643fed | |||
| 4739037f96 | |||
| 234344500f | |||
| b777b17f6f | |||
| db4b8ee000 | |||
| c6d45c60b5 | |||
| d709a5f1c5 | |||
| 1b0df1ae14 | |||
| 57fdfdedcf | |||
| 6fb0a1bc40 | |||
| 8631b08d97 | |||
| 3d2aab11d8 | |||
| 7ebb872409 | |||
| 375797d51c | |||
| 8e98bd616e | |||
| bc83515c9e | |||
| bcbab19376 | |||
| d29a68f585 | |||
| 0608d6aaec | |||
| 2fd075d1ea | |||
| d12378497c | |||
| 8ab9c2511a | |||
| fc0733087a | |||
| 42a20920e5 | |||
| 79fa72f392 | |||
| d3091971b7 | |||
| d9caede324 | |||
| 8a7876d48d | |||
| 2ee1250294 | |||
| 5644e14d0e | |||
| d07a875398 | |||
| 460892382a | |||
| 5605cc7684 | |||
| 7d42752158 | |||
| fefb27bab4 | |||
| 7de40076ac | |||
| f1359845de | |||
| 5ab55827b8 | |||
| 9ba391c5cb | |||
| 2469daebb1 | |||
| aa60c80ade | |||
| 5cbcff55cc | |||
| 428962a2e8 | |||
| 4f6b1bf3be | |||
| 8d62ece945 | |||
| 480682b670 | |||
| 89d9db2979 | |||
| 907f912463 | |||
| c97b702f4d | |||
| 91de6b0f37 | |||
| 069073ea68 | |||
| 15e2191111 | |||
| 8a9b9ec96a | |||
| 74829342ef | |||
| 4b926f227d | |||
| 82d065b011 | |||
| e60cdca9b0 | |||
| a1b62d68ec | |||
| 222f59b9c1 | |||
| 27a1877299 | |||
| ea9c424bba | |||
| 7ed15af371 | |||
| d6613b7589 | |||
| fed3e752ae | |||
| 766fb9c67d | |||
| b652720903 | |||
| 4d0a6c5a6f | |||
| 2eec710318 | |||
| aa10d0aaa6 | |||
| ff480bdb83 | |||
| b66552fc27 | |||
| cd065dd584 | |||
| 95b24083fb | |||
| 877313a413 | |||
| 8b8885ab07 | |||
| a903ed07e0 | |||
| 880e3cd7c8 | |||
| a67c22611a | |||
| 2efeded6e3 | |||
| 6044f25d71 | |||
| 9da015517c | |||
| 888a1d3445 | |||
| 8b88ca9017 | |||
| 94fe366779 | |||
| 535f70088e | |||
| 1b69910865 | |||
| 29451de874 | |||
| 5adc678628 | |||
| f2053ba19f | |||
| 68171ecaca | |||
| 6b82a234d0 | |||
| 4758fd31b1 | |||
| 7f68fc611c | |||
| 896bd917f8 | |||
| 67a5e1ecf9 | |||
| a9b8e8b931 | |||
| 94b1bbb68b | |||
| f133f61e3f | |||
| eb50793cff | |||
| 9b30913996 | |||
| ac7780bd35 | |||
| c192b692cf | |||
| 85b08ce3ad | |||
| b9a88da4ab | |||
| a69f1d7c20 | |||
| 24ba204931 | |||
| 6b354305e1 | |||
| ffedfa3354 | |||
| e4e423bb05 | |||
| ccd823a4ff | |||
| 7ff865b924 | |||
| ec627911f0 | |||
| 22ffb588e5 | |||
| e6a8d03dd8 | |||
| 747e035c7d | |||
| 6c9f4cf36f | |||
| ab580106fd | |||
| aa23eb4440 | |||
| e8baf2b772 | |||
| 58bb23d0c3 | |||
| bbacff5e01 | |||
| 43efd7fad7 | |||
| 3b315c9ada | |||
| f7926ea41e | |||
| 264c8637a3 | |||
| 55a3e0af8d | |||
| 66c93245e0 | |||
| 73ca93f3c0 | |||
| c6fc51c5ea | |||
| 2cb4c7052e | |||
| 3c1201c20c | |||
| 84dabe5982 | |||
| e10276f45d | |||
| 2312c26722 | |||
| b6cd89aeaf | |||
| ce1c260ea9 | |||
| 4d30126e4b | |||
| 7f56d2949d | |||
| d10ae90dea | |||
| 2f75639485 | |||
| ad1167c482 | |||
| 08753771fc | |||
| 69ac45d903 | |||
| 323a006666 | |||
| 16e170d105 | |||
| adeded29fb | |||
| 187a9fe5e7 | |||
| 6f48367094 | |||
| 83a574ff27 | |||
| f4dcec0b94 | |||
| e4fc9d84d7 | |||
| 07a525cdfd | |||
| f5622cd5ec | |||
| 54f8a9cb13 | |||
| ad937d0b2d | |||
| 495a0fa699 | |||
| 585655b16e | |||
| e49eb67119 | |||
| 88b5100e29 | |||
| 40f5abba10 | |||
| 5e03734eac | |||
| e46a72dd1d | |||
| 5ec63eb6b6 | |||
| a3c8c4b70d | |||
| 696d6cedb9 | |||
| 9f843adf89 | |||
| bfd8704a7d | |||
| f89a8f0769 | |||
| 6ba1d3ead6 | |||
| 7e3dba4f4c | |||
| f6e98a924a | |||
| 8f6a494ad7 | |||
| b8e6f83cfb | |||
| 5413fda739 | |||
| 145d293142 | |||
| f1240483fb | |||
| c0d3010438 | |||
| a9e93fa6a5 | |||
| 9e8bf82350 | |||
| dc87ec7258 | |||
| 43973f43c6 | |||
| bee4f1cf09 | |||
| da91a34c09 | |||
| 626dc8a03b | |||
| cf50e265fa | |||
| d3ffd0ffca | |||
| db229504e2 | |||
| 918c29f83a | |||
| a1f39c1ef9 | |||
| 9f2a64abd2 | |||
| 93e3b06fe2 | |||
| 86c20416c8 | |||
| c9e396b542 | |||
| fe23f27086 | |||
| de6fe2cb4e | |||
| 057c3d60cd | |||
| cb4ac4221e | |||
| 55604f156b | |||
| 7ddbcf7e87 | |||
| 3705559fdb | |||
| 6579a65bbb | |||
| f70cef3b79 | |||
| a89b26bedd | |||
| 8bfb53efe2 | |||
| a66e6e5ad9 | |||
| 56273fca1e | |||
| ef43e6b05d | |||
| 223ebe7b40 | |||
| 0e8ad40ef0 | |||
| eced15fe36 | |||
| a4d058bca2 | |||
| 619d66b7ab | |||
| 9073866491 | |||
| 7bce8831d3 | |||
| 81a8c1118b | |||
| b2c0634d48 | |||
| ada55c5d0a | |||
| 17cb7e7fa3 | |||
| 800ba28e83 | |||
| 0b2794ae12 | |||
| 226bbc1e63 | |||
| da2f8880b9 | |||
| c556fe1d71 | |||
| 2bfe61c33b | |||
| 2f92e3b525 | |||
| 0510112f91 | |||
| 4597324572 | |||
| ce6b7a1b85 | |||
| e3b54235ad | |||
| 8863afeb84 | |||
| 5c75455c8e | |||
| 0d8a4c7565 | |||
| 64d29a6330 | |||
| fcf2a34080 | |||
| 698b645e10 | |||
| d28ea7b518 | |||
| be641e881f | |||
| 3b19ea6ae5 | |||
| ccf59b0228 | |||
| 299afcd886 | |||
| c15b132f03 | |||
| 0ba814b3ca | |||
| d2caba1f66 | |||
| 1efc19ade0 | |||
| 678425f274 | |||
| 422c9c2acd | |||
| 9350d0dce5 | |||
| 4833887842 | |||
| f811a5693e | |||
| af0c13ba6a | |||
| c7cf45241c | |||
| 865b71309c | |||
| e7362dae78 | |||
| 9e72e35942 | |||
| bc183b0c04 | |||
| ffdf63ff7c | |||
| f12449d492 | |||
| 441a34a1c6 | |||
| 5f12069cbf | |||
| 4eee603433 | |||
| c714b90594 | |||
| aab5863dd4 | |||
| fa3f6dcbea | |||
| a091ae4cc8 | |||
| a1a7bc84da | |||
| 6e4b4c42ed | |||
| 142874b058 | |||
| 36c381154b | |||
| d0587f2c7f | |||
| 1f4798a173 | |||
| 61e4443342 | |||
| 6571acffaa | |||
| 6f3d787692 | |||
| 1e032ece92 | |||
| cc3002ff04 | |||
| c40d4e0133 | |||
| ca0804dfe4 | |||
| d2a8ba3299 | |||
| 20ff12e1be | |||
| 5cf9e0b254 | |||
| 1d1b7df7c6 | |||
| 13b9e1e098 | |||
| 553ead429d | |||
| bbd69c0260 | |||
| 708cb311a0 | |||
| 3e5470d88f | |||
| 3d8c0f16c2 | |||
| de2ba70830 | |||
| 9f0485e343 | |||
| b917cd275e | |||
| 0949f06a60 | |||
| 012f20d66e | |||
| b8cfc255d4 | |||
| 9fcefb2760 | |||
| 64a71c3c02 | |||
| 7b0a2f2a90 | |||
| 17ffc22279 | |||
| 52ebf87238 | |||
| d91079d4b0 | |||
| 62c0dc5dea | |||
| 7bdb8c9c5c | |||
| 3336963185 | |||
| 4808d15a85 | |||
| 67f88f5e3e | |||
| b3470d7ab1 | |||
| e4695f15bc | |||
| ffd6685f79 | |||
| 72e8640f4d | |||
| e6523e56b8 | |||
| b534176d4a | |||
| ddeb01612b | |||
| 41641e3b1e | |||
| 2f5aaf7de6 | |||
| d48a304262 | |||
| 0a1092f64e | |||
| 399968f1d0 | |||
| e5c3effdb1 | |||
| e88ef801af | |||
| d8796fe7e9 | |||
| 77341f67f3 | |||
| 93f95cc936 | |||
| f434cea287 | |||
| 216972186e | |||
| 074c7a3c30 | |||
| cf95a55d76 | |||
| a08a21d5a0 | |||
| cabd512916 | |||
| 40c863d41a | |||
| be61edbd19 | |||
| df201175c6 | |||
| 53ab32ef0b | |||
| 402a7ae151 | |||
| 3d58092ec1 | |||
| db05b1f9f5 | |||
| 262c380c4b | |||
| 6a6fd0b5f5 | |||
| f14cd1bb89 | |||
| a5869d8d25 | |||
| 45dbd9cd03 | |||
| a646f74e6a | |||
| 1fee23a598 | |||
| 1574428f64 | |||
| 0118623495 | |||
| 8454d871ec | |||
| 153309e287 | |||
| c9dcda6ac4 | |||
| 29e0d8caa7 | |||
| a795187c50 | |||
| 92faa74dfa | |||
| c5d478b923 | |||
| 9b1d594456 | |||
| 71440cf77b | |||
| 082fbf4264 | |||
| f7742669cb | |||
| 59a9bc9351 | |||
| 8ca80cb0f1 | |||
| 14aebe2b7c | |||
| cf0a2a26a9 | |||
| 899a2c033e | |||
| 8aa4f3fde4 | |||
| 26689d8c2a | |||
| f196c1bad8 | |||
| e460ab74ad | |||
| f5727deee3 | |||
| b96079f86b | |||
| 86347100a5 | |||
| 8e9d4081ee | |||
| 4630ab5743 | |||
| 1ff5ce8863 | |||
| b71418defa | |||
| 47b89f2e37 | |||
| 431c3ac485 | |||
| 190aea4cdc | |||
| f026517e5e | |||
| b71cedb2b0 | |||
| 69a14554ee | |||
| 2408243cf4 | |||
| 342fd6385b | |||
| e6c9ce6358 | |||
| c7e7d9217b | |||
| a8af78c833 | |||
| 13a73f67c0 | |||
| 500b9b0eb3 | |||
| f99cb3dc27 | |||
| dd4e5db2be | |||
| 5f2bf91ad1 | |||
| 034a2b04f2 | |||
| 6ea5dc294c | |||
| 8f5deaea61 | |||
| c5bb9b9da9 | |||
| 67e5581e37 | |||
| 3ede7daab3 | |||
| dbd6156fce | |||
| 691ed425ba | |||
| c376ffce0f | |||
| 917944e9c5 | |||
| d9c7cad630 | |||
| 9763c69fa5 | |||
| 555d9a8711 | |||
| b9768b8bc5 | |||
| 4ef6b2c32a | |||
| 1d18647e73 | |||
| a518d5d3ad | |||
| 091aff0445 | |||
| 3ed86ed3f9 | |||
| e4d34e1815 | |||
| 42caebfaa5 | |||
| eed508b444 | |||
| 343544f3f7 | |||
| 13d1f0ae43 | |||
| ecd07e51d0 | |||
| 52ae0efccf | |||
| 53c04c0429 | |||
| 1064288b38 | |||
| d34bb889b1 | |||
| a3a0df92a3 | |||
| e8f9447b11 | |||
| 3cc47edf62 | |||
| d454cd4216 | |||
| 48f38f3092 | |||
| 281472e50e | |||
| f011a5af11 | |||
| 67b0da83da | |||
| 3674f18b97 | |||
| 72f7282ad4 | |||
| fbfce2132a | |||
| 2c825294ec | |||
| f86d2aee29 | |||
| 35ea39bed2 | |||
| 97015afce8 | |||
| f22a63ce67 | |||
| c08e7419a0 | |||
| 67f91bc5ea | |||
| 4bc2374450 | |||
| f5e872a0e3 | |||
| 25cb851f8a | |||
| 3cddb0c076 | |||
| 2bf18bfc63 | |||
| 5aeb907fa1 | |||
| 0c68971c13 | |||
| d9be00342c | |||
| 027d85e82a | |||
| 3bc3c069f1 | |||
| e9366fa155 | |||
| 549b5c478f | |||
| b15e148b5e | |||
| bb83a417cb | |||
| 984ee9d05b | |||
| a0cc15ccbc | |||
| 7f142d6817 | |||
| bd1c3ed7e3 | |||
| cca34e234c | |||
| ed95ad1c0e | |||
| c65d67feb5 | |||
| bc6faf633e | |||
| 8d1c1074d5 | |||
| e654209211 | |||
| b742a3f29a | |||
| 800410eef1 | |||
| 7b2cda95d9 | |||
| c2cefa6de0 | |||
| d7f5f15d69 | |||
| 84906b83ec | |||
| 274079990a | |||
| 10cb19d534 | |||
| d50b33cacd | |||
| 77b5ee0117 | |||
| af750bd2ef | |||
| 21cbfafc03 | |||
| d3947b2f3e | |||
| a71209868b | |||
| 7a1ff6d8ff | |||
| 82f6779c2e | |||
| 3abccdc82d | |||
| 8d6d0223bf | |||
| fc17d0de77 | |||
| 27f2ce8f6e | |||
| 45b0aea875 | |||
| 4803d5772c | |||
| 738c5595ad | |||
| bebd6e16f6 | |||
| 49e110c52b | |||
| 4d90aeb0ab | |||
| 03cd049c68 | |||
| 6ab8b9b6c6 | |||
| 490f67a3f8 | |||
| 0515ad0fb0 | |||
| bf51db2526 | |||
| 59702aca0d | |||
| c86eee3918 | |||
| 10b53e1c5e | |||
| a30d3571ca | |||
| 457ac26de5 | |||
| 679c2ea227 | |||
| 9ff594c3a9 | |||
| 849b089a63 | |||
| aee404f532 | |||
| 0915f85895 | |||
| 5e8bc6ac2a | |||
| 3e4dcaa06e | |||
| 14f47c8ac6 | |||
| 5d90c149b5 | |||
| 4b9e338541 | |||
| a0cf424cfc | |||
| aecdbfc4a0 | |||
| e6482b7d97 | |||
| 6e6c5b6103 | |||
| 04fd7efdfa | |||
| 5e331f9618 | |||
| b9f5d1c6ff | |||
| c4533e0d94 | |||
| f39cf1b008 | |||
| c6baefb79d | |||
| 4d120ee02e | |||
| f45eee318b | |||
| 8c2fd2170a | |||
| 91c2c44fb1 | |||
| 27e9fc1067 | |||
| e005270fb6 | |||
| 4f55ed14d3 | |||
| a6c0ba2100 | |||
| fc316cbca9 | |||
| 11b1a76f35 | |||
| bd8f463b7e | |||
| 4d14f97482 | |||
| 15616ad199 | |||
| 94a3608ab9 | |||
| 5769509d72 | |||
| fff6b9f061 | |||
| 56d2c3844a | |||
| 23b6809f3d | |||
| f31847302d | |||
| b1a4a18d63 | |||
| f7096ea7ce | |||
| a16ba5bbd1 | |||
| 408e6ee9b6 | |||
| 7b4f5c8f72 | |||
| 55948623e7 | |||
| 4d46d29efe | |||
| cc608a7aba | |||
| 1f40cd6d02 | |||
| 28bc8ed462 | |||
| 5ee16a180a | |||
| d30dfc084c | |||
| 6373e88b5b | |||
| 7487eb0dca | |||
| 2067a99c07 | |||
| 002062ae93 | |||
| 4064ee5406 | |||
| b0fd2b6b98 | |||
| d0bc951835 | |||
| 73131e7c78 | |||
| 1cc18d8a7a | |||
| c45c6d308f | |||
| f73bb438aa | |||
| 71dd8a333f | |||
| 9207baed65 | |||
| b191df5ebe | |||
| 3e95800814 | |||
| 2ed56f4d5f | |||
| 7b0b463720 | |||
| a6c5b4c6fb | |||
| 0504a6975d | |||
| a5b5a91512 | |||
| 1a8f63a896 | |||
| ee5514b8fd | |||
| 99e547f4cb | |||
| 110644d918 | |||
| 4b3a0fdab0 | |||
| 05e31c5e5f | |||
| 46fdb14b2f | |||
| cbb1a8ed31 | |||
| a6c5f60caa | |||
| 9518cc3254 | |||
| b0a177bc67 | |||
| 5b7b330616 | |||
| 3f64a2af6a | |||
| 9749f1f14c | |||
| 4ede49cd85 | |||
| 6960f41e03 | |||
| bf90499fc3 | |||
| 404c4122ce | |||
| 2a0bbb9faa | |||
| 128e097d03 | |||
| c1264e46d0 | |||
| 366f6b0dab | |||
| 58aee9a9ea | |||
| 4b703b1429 | |||
| 62d38f0196 | |||
| 7e575512ae | |||
| a55fb76dcc | |||
| 838255ef91 | |||
| 6fbe027da0 | |||
| ddcb572c41 | |||
| 12c0dfc113 | |||
| db53883f06 | |||
| 13ffb08136 | |||
| 2d82db1d14 | |||
| b88bc7b766 | |||
| e074a19f5c | |||
| b8930d0c26 | |||
| 4fc7734547 | |||
| 92dcbfa658 | |||
| b50eb6bea8 | |||
| 6f079ae720 | |||
| 203fdc9ac1 | |||
| 17d41b3861 | |||
| 8cff4862a6 | |||
| 908d98820b | |||
| a4c11b71ac | |||
| b2fadf32aa | |||
| 378bcfe760 | |||
| fe2ed42661 | |||
| e215a88cdd | |||
| e95e69515a | |||
| e05c80a088 | |||
| 7b31e81d77 | |||
| c0964fc70f | |||
| cd782c11ec | |||
| 5ea984ac35 | |||
| 1fd020a8ba | |||
| 02420d4670 | |||
| 2c7ab488a8 | |||
| d54e8a5955 | |||
| 4bebb15e94 | |||
| 3b8f66f8ac | |||
| b6e9d901b0 | |||
| 1b7223a53c | |||
| de1dc4f2de | |||
| a6e0f62a4f | |||
| 81e242a96d | |||
| dd1855eb2f | |||
| db4cd89cb8 | |||
| 7e95495b35 | |||
| 55eb7dd1e9 | |||
| 902c0566a6 | |||
| bc02cc0c8a | |||
| 05c6f7a40b | |||
| 2a98042c21 | |||
| 46409a7852 | |||
| d8b266af8b | |||
| abb40777bf | |||
| 90abcac1c7 | |||
| 7222f47350 | |||
| eafb66e1aa | |||
| d4a02b135d | |||
| d3608c4e79 | |||
| 38cfbeeb50 | |||
| 77547a4ef1 | |||
| 8ceef92266 | |||
| f7c013edd0 | |||
| 148490f04c | |||
| 7c6f346c90 | |||
| 1a34496761 | |||
| 049e5ca191 | |||
| 19dd0de4ff | |||
| 8a61b030a6 | |||
| c7e31d5aa8 | |||
| 818a3537a7 | |||
| bcbc9bfd1f | |||
| 7eda7335fd | |||
| 02606a8c83 | |||
| e7505324f6 | |||
| 653c0527a7 | |||
| 7f4c7cd785 | |||
| 0958e5c6d3 | |||
| 9fc77bc414 | |||
| 3b92159908 | |||
| e00bb13e85 | |||
| 3b41e62666 | |||
| 37c91aa94c | |||
| 43f67eab5f | |||
| 11d30b6298 | |||
| 3edb15d183 | |||
| d44ac0a485 | |||
| 481eda4ca0 | |||
| 7323231786 | |||
| e381951a24 | |||
| aa2368a687 | |||
| 293c44bc09 | |||
| 06b9140e5c | |||
| 156635749b | |||
| 083fe58124 | |||
| e508494a99 | |||
| 2ef53ee368 | |||
| d810441b35 | |||
| 79bcb2ca54 | |||
| 289a767ab3 | |||
| 4381ea23fe | |||
| 817ca1820b | |||
| 8df17204f4 | |||
| f84f04742a | |||
| cc40d1c46a | |||
| 818e0b2d2b | |||
| 3e4dfb49a7 | |||
| 87436e5544 | |||
| fe72c93141 | |||
| 75221fcf5e | |||
| a95cbca568 | |||
| d23454854e | |||
| c2902112e5 | |||
| 9498b2af82 | |||
| 2a5ae34bb2 | |||
| d3fe153fe6 | |||
| 889922041b | |||
| 7bad50773a | |||
| d3c3c4f8e7 | |||
| 2097cd1221 | |||
| 0c1b40c5e2 | |||
| 8c10029df1 | |||
| 6e2371a86b | |||
| 36c82b751c | |||
| 7d42d02ec7 | |||
| c89274d8fb | |||
| f2638816bf | |||
| 0b4ea54da9 | |||
| 09f1fdf52f | |||
| d39b22927e | |||
| 81e9cf043a | |||
| 077e32efc9 | |||
| 52f3e717fa | |||
| 0586b51f9c | |||
| d2eeef89aa | |||
| 70d20326b0 | |||
| ccf4ec6768 | |||
| a24da071f0 | |||
| 3698d9aa55 | |||
| 10429dd616 | |||
| db322e6a63 | |||
| 45dba12c5b | |||
| ccad601389 | |||
| d165d5af91 | |||
| 3ce43c20de | |||
| def50020ad | |||
| 0d68b523a3 | |||
| 0e1ad3ad33 | |||
| 0fc9a01933 | |||
| 68d1bebd8e | |||
| 57b6df4874 | |||
| bc38efd128 | |||
| 335b57b5ef | |||
| dbd28bc7f8 | |||
| ccf21f5595 | |||
| 1d1fcf80a0 | |||
| 373503f4a9 | |||
| 9a1d5f0f1d | |||
| d5e49a3ad4 | |||
| ea4e22be1d | |||
| dc8c6ea2d1 | |||
| c5ec94d0f1 | |||
| d570260a28 | |||
| 76caef8ba1 | |||
| 5a156df719 | |||
| e0dfb0bc34 | |||
| 3922ac2fe4 | |||
| 66a1a77487 | |||
| cd0ecace19 | |||
| 10d29add18 | |||
| f2950ae206 | |||
| d0c2faa5fd | |||
| 671f24ff35 | |||
| f32f899467 | |||
| 17b71fe51d | |||
| 30c2e3828a | |||
| a7cdf7299a | |||
| 733d0099b2 | |||
| 0be7b8c542 | |||
| c698362680 | |||
| fe3352665b | |||
| 3f44be9baa | |||
| 0c06b4509d | |||
| e5bc79fb9c | |||
| 880726c13a | |||
| 50a7200b18 | |||
| c67fb8ef04 | |||
| 14c2c1395b | |||
| 88c3670edf | |||
| f69c185e02 | |||
| bf706c4a4f | |||
| 1a414cd9cb | |||
| 91427c8242 | |||
| b8c5ea869c | |||
| 6560e4cc5b | |||
| 08d615cc95 | |||
| 1c4e6d7ea2 | |||
| 5f58db8c99 | |||
| ddbe6082c4 | |||
| 53051eefc7 | |||
| a72710c660 | |||
| 9f94d22801 | |||
| 0901e12102 | |||
| 58c9fbacc7 | |||
| 483c98a69e | |||
| 2218a5836a | |||
| 76a0d3c05a | |||
| 52cab06fff | |||
| bd87ab9ff5 | |||
| 57797822f8 | |||
| 7062db7cb2 | |||
| 166cc0292c | |||
| 496c7497cb | |||
| e83b9075ff | |||
| 6950d07bf4 | |||
| 054d117d25 | |||
| 62b32a4737 | |||
| 588670e8d2 | |||
| c465f4c4df | |||
| 8737b26a23 | |||
| 78a9531773 | |||
| d1143794a0 | |||
| e70eae2c91 | |||
| 99ae47716a | |||
| dda7de17e7 | |||
| 869c924410 | |||
| ea6c1f7a17 | |||
| 81cd7d787e | |||
| a523cea772 | |||
| a66a7c3870 | |||
| 89a89eb605 | |||
| 3b14b17664 | |||
| 3a836dab59 | |||
| e1191b35e8 | |||
| edce2a8448 | |||
| 9b1cf3cf43 | |||
| bff65a211f | |||
| 2d60995c00 | |||
| 0454bbc54f | |||
| 900e2d4e1e | |||
| 9d1151575d | |||
| 193741218c | |||
| 896420b166 | |||
| 009a0f88e0 | |||
| e1d681458e | |||
| ce063f59cd | |||
| 3cf6471738 | |||
| f78b68b7ff | |||
| e9ab7353de | |||
| 9d1978e217 | |||
| db097921bc | |||
| 894c43a1d6 | |||
| b5b799b5ab | |||
| e82382703c | |||
| 3b49aeb4f2 | |||
| 423c6d8a8a | |||
| 158014b39d | |||
| 231f62baf7 | |||
| 52bbf372bb | |||
| 3ddf91d9d1 | |||
| a2f46446cf | |||
| 9edc7d6958 | |||
| 55db871472 | |||
| da98a45bcb | |||
| feeafb0a50 | |||
| 22c557ca7c | |||
| 6a93488291 | |||
| 6fa83f5188 | |||
| ce248e7920 | |||
| 23bdd06442 | |||
| 98cd8239cc | |||
| 2a585b63b8 | |||
| a5ea3a202e | |||
| 69de670353 | |||
| 4e5d834e8e | |||
| 4502917665 | |||
| 5af8179647 | |||
| 55df3fa2d7 | |||
| 8367cf15da | |||
| 942989939a | |||
| 239d7b3fd1 | |||
| 116234d6c6 | |||
| c45a4e0b48 | |||
| 96d3b1c92b | |||
| 3b87314331 | |||
| c581b7ea36 | |||
| a5b1f4774f | |||
| 37e9802411 | |||
| a87831230d | |||
| dd5b3086f5 | |||
| 47f988f05f | |||
| 07989712af | |||
| d0d69a5358 | |||
| 972de506a0 | |||
| ed1574e46c | |||
| 52f55179a8 | |||
| bbdf9e4737 | |||
| 94ecdef8ac | |||
| e3b0327812 | |||
| c039103b31 | |||
| fe1cbe2638 | |||
| 4e31c39a64 | |||
| 13f90a30ef | |||
| ad1941fd00 | |||
| cee6336515 | |||
| b3d030294b | |||
| cd80762c13 | |||
| 00a853950f | |||
| 4c7a71a44b | |||
| c594b989c0 | |||
| 71f37ac1aa | |||
| 77c91ac1ba | |||
| 5436d98fc5 | |||
| 0587c5b605 | |||
| c1f4000426 | |||
| 22715259a0 | |||
| 4eda653a56 | |||
| e8e5b9f537 | |||
| 9c2b3faec4 | |||
| 70b1b79264 | |||
| 5fc8b27db9 | |||
| dbbbd3880c | |||
| e40b06a050 | |||
| e304db9d1e | |||
| 6b909b2343 | |||
| 55bd27b8f0 | |||
| 1018474853 | |||
| c11edd3b0b | |||
| f0298862f5 | |||
| 739d23f2a3 | |||
| 3aa2d6db18 | |||
| 6a75291ab1 | |||
| eb1a4f11fa | |||
| d023be5a21 | |||
| c2cd75843e | |||
| 189b6fc270 | |||
| 6c8663341e | |||
| aba152ea3a | |||
| 7f9ebf8e86 | |||
| 4e7da9be3d | |||
| 46c01b5083 | |||
| dae843d4d6 | |||
| 78fe0cfb8d | |||
| d77d555c72 | |||
| bbaef048cd | |||
| 7e2d49368d | |||
| 954fc950d9 | |||
| d777c4d789 | |||
| cedbd3332a | |||
| ff9ca3e76e | |||
| b8948e84b8 | |||
| 1ac417edb8 | |||
| d471c49700 | |||
| c9f9262a49 | |||
| bd7a0d4ce4 | |||
| 561eb34aea | |||
| 4c91dbc28e | |||
| 1b6b711c44 | |||
| faaa1f1116 | |||
| ed0fb0b05f | |||
| e5463eb3ae | |||
| d53c928261 | |||
| bc8f5fe0bf | |||
| 9204a60dbb | |||
| 1cb2722c95 | |||
| 3caeabf73b | |||
| fdbe8006e0 | |||
| 09acdac56b | |||
| e4a0482e43 | |||
| 22a5f91aa7 | |||
| 9ce7469846 | |||
| 4b7dbb3922 | |||
| e0035e9ca9 | |||
| 0a18adb02a | |||
| 630b3b2482 | |||
| 6008f6538e | |||
| afcee1e8a4 | |||
| e0bd0f250b | |||
| 1598a3edf8 | |||
| 0dacab65eb | |||
| 834bd9edd7 | |||
| 6e840f8033 | |||
| 2379312028 | |||
| 37db62b2ea | |||
| b50ce5ebfb | |||
| 5900ab76a0 | |||
| e6d8e74152 | |||
| 9cdca7516c | |||
| 6436e75858 | |||
| 831f91b859 | |||
| 1258c7aabe | |||
| 8dcb4bc3cc | |||
| 0a003d3ba1 | |||
| 92e759a676 | |||
| 3df2c01b57 | |||
| 8991a6f005 | |||
| 16f380e5c1 | |||
| cbd7ce468c | |||
| b6883c872d | |||
| fde0b9e701 | |||
| 7a2825053e | |||
| 4e619a13d6 | |||
| 0de9257610 | |||
| b84af67f4c | |||
| 7c8b7222f5 | |||
| ec9038b7b4 | |||
| ab65d3fd0e | |||
| e8b7109eff | |||
| 0c6ed5929c | |||
| 2f4a9a140a | |||
| dba1bc354a | |||
| 4b19430103 | |||
| 7c1f8dbde9 | |||
| 2c1ba2ab0d | |||
| b011818917 | |||
| bc4de9edae | |||
| 9de4ee6d32 | |||
| 90ec4a403a | |||
| b61ec33f22 | |||
| 1f7b5d9a79 | |||
| 5c6ba81cf2 | |||
| 591adf564a | |||
| f0db6a6c0b | |||
| 520e680278 | |||
| abc6a0be2f | |||
| 9dbda6652e | |||
| 5dc0df8435 | |||
| 6e5a334c95 | |||
| 6becc81446 | |||
| 6b5322ce00 | |||
| 67d91dfd50 | |||
| 089e54c7fd | |||
| 0b3ffb54b7 | |||
| 775488340e | |||
| 7d2530873e | |||
| 18505f1fc4 | |||
| dc88cd691f | |||
| ebe8009aff | |||
| 628808a113 | |||
| dc7fd868f4 | |||
| 7b4aa10708 | |||
| 960a689769 | |||
| 5f5d056c8f | |||
| 9c7e2c8f9d | |||
| 4f5680950a | |||
| 9793fa1906 | |||
| 0446fc85de | |||
| 764d3f44b6 | |||
| 0412f4a1ee | |||
| 6828325881 | |||
| 61a054b170 | |||
| 3361ad4242 | |||
| 6c9c6dd989 | |||
| a358dfe934 | |||
| 0ecc920a09 | |||
| f86182e791 | |||
| c19a6ef82d | |||
| ecb84464f9 | |||
| 1b2af05ea6 | |||
| caef319219 | |||
| 2f47844c7c | |||
| b9bc6e823f | |||
| 5e90580088 | |||
| ef0496ff40 | |||
| 96f4ab48d8 | |||
| 39c08c17c5 | |||
| b93693b831 | |||
| cdfe43eb8f | |||
| 456f37b8ab | |||
| e8d89ca5b0 | |||
| 2aac860db3 | |||
| 8b00e50cb7 | |||
| be3b8f3ae9 | |||
| ce159b16b9 | |||
| 5392007a24 | |||
| f59323b56a | |||
| 25a9b601b2 | |||
| c645aca199 | |||
| 44432f67d7 | |||
| d66b765eb6 | |||
| e72b93e44f | |||
| 68885f78f3 | |||
| 4a310baae2 | |||
| d549497144 | |||
| e56342ed00 | |||
| 0049d3f337 | |||
| e0cae4bef8 | |||
| 9546b79e20 | |||
| cc04a745e2 | |||
| ce5b972736 | |||
| f30f384757 | |||
| 676b2c8435 | |||
| c2fc80e5d1 | |||
| b1f57e92ce | |||
| bed4075580 | |||
| 5a2d525048 | |||
| e1919384a2 | |||
| 699f700162 | |||
| 797c960d20 | |||
| 673bc5526f | |||
| 0439a79566 | |||
| 37fa8adc2b | |||
| 2f99de0c6c | |||
| 7a8429d9f1 | |||
| dda0fa1a43 | |||
| 7eb6a488ad | |||
| 72641dcaae | |||
| 6e00aa6bae | |||
| 9bbd27a80f | |||
| adb71b8096 | |||
| 32c504076f | |||
| 304deb5e83 | |||
| d84865eac3 | |||
| cc6c745b54 | |||
| d033d5e06a | |||
| b0b9bb3462 | |||
| 5e18b81e87 | |||
| 10e64e0509 | |||
| 76622342ec | |||
| d6e3a40c81 | |||
| 46a50cbf38 | |||
| cc2b3ece5c | |||
| 22e294e044 | |||
| 4124c94583 | |||
| a56322fde8 | |||
| 3d0d0237c5 | |||
| d11a529904 | |||
| 3aa471f2a9 | |||
| 374c9e6b63 | |||
| 32d3a07c67 | |||
| b978eb05dc | |||
| e4efc8b741 | |||
| 58c2fe391d | |||
| dbe5e28eaa | |||
| c483ffc773 | |||
| 41561c9bb8 | |||
| 553655eb07 | |||
| f01b53c374 | |||
| 8ec421fa14 | |||
| 11b0c7b44a | |||
| f8224fc7d3 | |||
| b356e0fae3 | |||
| 06f33ff1ee | |||
| c47a74ec62 | |||
| e26d13bb31 | |||
| f41a21fefd | |||
| d4c9abb967 | |||
| d1e18fc7dd | |||
| 3c6a4bfbed | |||
| 3b7dbc4f6d | |||
| 17d1940278 | |||
| 258da28e79 | |||
| df80232495 | |||
| eb28a683bd | |||
| 2dfc94e0b6 | |||
| 7bc3688714 | |||
| fc3ea7365a | |||
| 55376219b7 | |||
| 9b26356347 | |||
| 7c8a8e038f | |||
| ee838f56f7 | |||
| 9934b8ec31 | |||
| 3dccdf5b83 | |||
| 4220f191d8 | |||
| 843a5961e1 | |||
| d8e56cbe54 | |||
| 2ef5b4066e | |||
| 482b5b7ece | |||
| 19540c9ee8 | |||
| cf0561d31a | |||
| 161c6b025e | |||
| b966adf103 | |||
| c2a68708ef | |||
| 34178205fc | |||
| 5bb766e826 | |||
| 96eefc4af6 | |||
| 8751b18cf0 | |||
| 2608b9249d | |||
| 43f84efa15 | |||
| ea5616785e | |||
| 6a48325c49 | |||
| 50edb7cd73 | |||
| 4aadd1e401 | |||
| ec5b9994b5 | |||
| 3441e0075d | |||
| 821e1c7233 | |||
| 6088ac2108 | |||
| d8349f9d0f | |||
| fd35d92c1e | |||
| 3b906ffc27 | |||
| 7b4b65d7a9 | |||
| 099b5e45e6 | |||
| b1768c115c | |||
| 86e159997c | |||
| 576f0f6985 | |||
| b46bf2950f | |||
| 0347339970 | |||
| 40e939421f | |||
| b1cf1acb93 | |||
| c94cfebb7e | |||
| 57e942145c | |||
| 51e8efdab5 | |||
| df31398bb9 | |||
| a94fd3bbec | |||
| 1a1742ac4f | |||
| a492a9dd07 | |||
| 875a8079bc | |||
| b76c04c097 | |||
| f7b4983137 | |||
| eeef654cd7 | |||
| 7fb6fd2f55 | |||
| a189a5f0c5 | |||
| 24b25b4827 | |||
| 830ff985db | |||
| 3d937e1e90 | |||
| 04ff9c2548 | |||
| 28bf56e725 | |||
| 662d1859bd | |||
| 97e0b0a01e | |||
| 04ac1bcabe | |||
| ec9b037e5f | |||
| 6f6be95bad | |||
| b96db269a8 | |||
| dcbb05ef39 | |||
| e25de55fac | |||
| 28892666bd | |||
| 6058e7cf60 | |||
| 2a21543c88 | |||
| 007613cb5e | |||
| 1b69ef8e6c | |||
| 972dec454c | |||
| b6b8c62ba5 | |||
| db57b5f8f4 | |||
| 4a4513d126 | |||
| 2b1324eddb | |||
| dfd030b67a | |||
| 20621ed3e3 | |||
| 2aec8fb956 | |||
| 3ec94abcdb | |||
| e1907e349f | |||
| f237e8b8ea | |||
| 103b368ab7 | |||
| a29dd88f75 | |||
| a1076cc68a | |||
| 78908b7aed | |||
| d98150dffc | |||
| c549f71f64 | |||
| c19ea4b000 | |||
| bede30e7a6 | |||
| b05fbb3733 | |||
| 9b43fd7937 | |||
| 87fc9dcaa3 | |||
| 83f3ea7ab4 | |||
| 9c8c4ff46f | |||
| d655147e8c | |||
| 3c675db3d0 | |||
| cf247e7e30 | |||
| 0026c88b3a | |||
| 6482ce2bb2 | |||
| 867a5a8cd2 | |||
| 78e6b361c5 | |||
| aa392c366e | |||
| f80c50bcdd | |||
| d282cf6964 | |||
| b1fcfe4c5d | |||
| 30418a3cfc | |||
| cb1709ef5e | |||
| 67338e6f32 | |||
| 8300ab149c | |||
| c00443b19e | |||
| 9db9e4f7d3 | |||
| 22e40c8c10 | |||
| e9296d694c | |||
| fb4b4f772e | |||
| f4dadee5e2 | |||
| 808a312e1c | |||
| 93e539d909 | |||
| 9d7a36121a | |||
| 8307da0de7 | |||
| ad43ce1436 | |||
| 0a6532a39d | |||
| 20a6f99cdb | |||
| 4554d8b2ac | |||
| 9cb187762a | |||
| 4a8c1b2470 | |||
| 0759d8f430 | |||
| ae65ab25d5 | |||
| 24417a6cd9 | |||
| ad4739a6d4 | |||
| a695ed65a8 | |||
| 750ac9ac50 | |||
| 07f3f0384a | |||
| 87b483f999 | |||
| c2d42ea833 | |||
| b5f6c2241b | |||
| e89a8e0913 | |||
| d543a64cc7 | |||
| 939b621e5c | |||
| a77a3b723f | |||
| 976270916b | |||
| 87f7e99bc4 | |||
| 72d8d27234 | |||
| 1ae6ae9b60 | |||
| af4fadebda | |||
| 0af3af5d25 | |||
| 852d45a600 | |||
| 96213689e4 | |||
| 4e59c5c274 | |||
| 7d97ebfe7f | |||
| 377c406c74 | |||
| 91601d7f95 | |||
| f3728e66f8 | |||
| 3f14ed6602 | |||
| 14df99130f | |||
| 47bcb892af | |||
| 6e05055f06 | |||
| da6e53a436 | |||
| 56774fff20 | |||
| 3527a42063 | |||
| 98352a5e84 | |||
| 11a7980976 | |||
| 5b8ca1eee7 | |||
| 81cd417b45 | |||
| a44c5cf4f7 | |||
| 5c5af4fa65 | |||
| efd2167998 | |||
| 348f824104 | |||
| 0f7cbaca75 | |||
| e870afa5d5 | |||
| 9bacd921fa | |||
| bb3427ca85 | |||
| 6809b57cfc | |||
| ffa75215cc | |||
| c4517c013c | |||
| ed04c010eb | |||
| e9dc2e9e1e | |||
| 9c7d72739c | |||
| 3fc08f8ab6 | |||
| c56a7ee803 | |||
| 35fa4fc71f | |||
| b56a098cfb | |||
| 4cc272cb94 | |||
| c4fc82c6b7 | |||
| a40ded2884 | |||
| 44c78fdb7a | |||
| ecb98a3330 | |||
| 9b6b510ca8 | |||
| c2600a73cf | |||
| 43204d9ac2 | |||
| 369789b426 | |||
| 8fa53a5b92 | |||
| d58176bfea | |||
| 0095f423f2 | |||
| 2617aa415e | |||
| 22b9307aba | |||
| ac7339877b | |||
| 90890844ad | |||
| 8a89b12641 | |||
| 4a3b162c8c | |||
| 5c8af7ccb8 | |||
| 7942e6f3bf | |||
| c6f497f09d | |||
| 29be28e1a2 | |||
| e7939f450f | |||
| 81801d395f | |||
| bc76c62c63 | |||
| fd5d6c5340 | |||
| 08abe8b4a3 | |||
| e896368496 | |||
| 2fe4e10b0b | |||
| f2e78d9f84 | |||
| b5bbc1f713 | |||
| 23943208ec | |||
| c555e1aa96 | |||
| 36cc214703 | |||
| 8f7d36a85d | |||
| e7cfe42d3f | |||
| 500fff920b | |||
| 782c3f36cc | |||
| 8272dcb6cd | |||
| fec623d68d | |||
| a3bf09c5c9 | |||
| 325dedc7da | |||
| 09b5949cd2 | |||
| 3141490374 | |||
| 1a8e3f0b2e | |||
| 80dd90f972 | |||
| c2c185423b | |||
| 25b4d0c127 | |||
| 2225e3bbe7 | |||
| a90a990118 | |||
| 83d8fe2d59 | |||
| 63a04134d0 | |||
| 6bc16f3ff1 | |||
| 10b24af98a | |||
| be9aba2fa0 | |||
| 35018fa307 | |||
| b706165527 | |||
| 6963c3802d | |||
| 3b67636f0e | |||
| 48e39c5c8e | |||
| 13524bea9b | |||
| 500c7f44ab | |||
| d156e7a20b | |||
| c386ce0023 | |||
| b69d9ee3f7 | |||
| 7d5b8fcf77 | |||
| bc6a6e04a0 | |||
| e5ffe9959c | |||
| 86b95f2105 | |||
| 1e92df6b20 | |||
| ba85c59d96 | |||
| dafd5b5864 | |||
| eabba1119f | |||
| 06e0d48794 | |||
| 4a71c86270 | |||
| 68583f4d48 | |||
| 5b35c149e8 | |||
| 9a542d9698 | |||
| cd27ed9a74 | |||
| b9f8cb7837 | |||
| ffa150bec3 | |||
| 13bc6ba2c6 | |||
| 30b3edf328 | |||
| 7902d6089e | |||
| b6b0878da8 | |||
| 3a76163aba | |||
| 1e7c6fc761 | |||
| c50ad85c3c | |||
| bb6a6e159a | |||
| 1036cadcec | |||
| c71ae794df | |||
| 409930e98c | |||
| b88f7df387 | |||
| adcfffceeb | |||
| a3c1d64a5f | |||
| ce24a229df | |||
| ce619b3b6c | |||
| 2e2a4b4ea3 | |||
| 7f519a2463 | |||
| ff1ecb5d6c | |||
| dab1cd8af9 | |||
| 5b0c6b9bc0 | |||
| fc290dc30b | |||
| 5f7eb20090 | |||
| 03ad183384 | |||
| 527a2ec541 | |||
| 3185c36a65 | |||
| 3d8140a541 | |||
| a6fc3d6ee5 | |||
| a1f9bf19d9 | |||
| 4ad6a3496b | |||
| 969ad8001c | |||
| 07e0dd27fb | |||
| b8eb699db7 | |||
| ad1f28bc1c | |||
| 67686b7684 | |||
| 69f4954df1 | |||
| 4894231ff7 | |||
| 36bb57a47e | |||
| a042449f5d | |||
| f5e434c2d9 | |||
| 37d551fb39 | |||
| 9c8c0de538 | |||
| fbdabe2975 | |||
| 0cfb30e5be | |||
| c081a81daf | |||
| 155bed18f5 | |||
| 95d9687d95 | |||
| ff41b8df76 | |||
| 53ccba8457 | |||
| 7ac6e3b850 | |||
| d15217b953 | |||
| bc54a44010 | |||
| 3f806df0ca | |||
| f3799aa750 | |||
| 30ca6935a5 | |||
| f25582d4b8 | |||
| fb2fdb21d3 | |||
| 31a0d2200c | |||
| e0a00c4996 | |||
| e5077dc11e | |||
| 01a191936e | |||
| 8094b2add8 | |||
| ffb638995d | |||
| c2a4856f9e | |||
| c9b24c3358 | |||
| 9305983018 | |||
| ae2f5f25cd | |||
| 923b14afaa | |||
| a9782b94e6 | |||
| 351ef5c85b | |||
| be2925b3c5 | |||
| ace27831ee | |||
| 6a1707889c | |||
| 1c42d15340 | |||
| fe26967ea0 | |||
| e7413417ce | |||
| 018022b866 | |||
| 7ea38e980b | |||
| 8173d92dd2 | |||
| 808a4fe817 | |||
| 72760c05c6 | |||
| 15683034a7 | |||
| 4c9d570e43 | |||
| fc519ca74a | |||
| a24c0a736c | |||
| b3a0b389d2 | |||
| 47959c56fd | |||
| aee75ae105 | |||
| 4b8a7f2793 | |||
| 89ec224cb9 | |||
| b21a5e2f06 | |||
| 735cac5d53 | |||
| bc4f3155ae | |||
| a21a110188 | |||
| b414fc0dfd | |||
| e0215f3222 | |||
| 3dfff5bdae | |||
| d632e77058 | |||
| 6d665b7f78 | |||
| b1b0c64046 | |||
| 670cee44f0 | |||
| 3092f0c646 | |||
| 2f6142cb9b | |||
| 3b2bcee0a8 | |||
| 91407f4f74 | |||
| 025d57855a | |||
| 8647fbd6ed | |||
| 811037c845 | |||
| 181cc3f93f | |||
| 91b919fd1d | |||
| 5ff6289afd | |||
| fca0a2dd88 | |||
| 462a39ec49 | |||
| 70125a3be0 | |||
| cff8877a1a | |||
| 8f51f09de7 | |||
| 013dc43d5d | |||
| 853e2a9495 | |||
| 4c3a000211 | |||
| 9884573561 | |||
| 4b232f5ddc | |||
| 45ce92b89c | |||
| bc86668ba4 | |||
| 0783211950 | |||
| 13fe7ee4df | |||
| 21fc66c246 | |||
| ff9e49bac9 | |||
| 90e83fa879 | |||
| 3ef4fdeaa0 | |||
| 13d8af1852 | |||
| 5b7a141065 | |||
| 89a06f6651 | |||
| a2e924039b | |||
| 85d1f9c5ec | |||
| e444e18d2b | |||
| ad0fdf0da6 | |||
| fbbc7e421c | |||
| 1cc42ac9e4 | |||
| 6624105b5b | |||
| de58594b0f | |||
| d5f0b91c06 | |||
| f78488bbdb | |||
| e3b23eb818 | |||
| d494725400 | |||
| 2535dc1340 | |||
| 339bf9b7e1 | |||
| bb86691a0d | |||
| f7fee4c616 |
+73
@@ -0,0 +1,73 @@
|
|||||||
|
language: cpp
|
||||||
|
sudo: required
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
|
packages: ['g++-6', 'g++-6-multilib', 'g++-multilib', 'valgrind', 'expect']
|
||||||
|
env:
|
||||||
|
- COMPILER=g++-6
|
||||||
|
- COMP=gcc
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
|
packages: ['clang', 'g++-multilib', 'valgrind', 'expect']
|
||||||
|
env:
|
||||||
|
- COMPILER=clang++
|
||||||
|
- COMP=clang
|
||||||
|
|
||||||
|
- 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][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++-6 as a proxy for having sanitizers, might need revision as they become available for more recent versions of clang/gcc
|
||||||
|
- if [[ "$COMPILER" == "g++-6" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-undefined; fi
|
||||||
|
- if [[ "$COMPILER" == "g++-6" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
# Generated with 'git shortlog -sn | cut -c8-', which sorts by commits, manually ordered the first four authors, merged duplicates
|
||||||
|
|
||||||
|
Tord Romstad
|
||||||
|
Marco Costalba (mcostalba)
|
||||||
|
Joona Kiiski (zamar)
|
||||||
|
Gary Linscott (glinscott)
|
||||||
|
Lucas Braesch (lucasart)
|
||||||
|
Bill Henry (VoyagerOne)
|
||||||
|
mstembera
|
||||||
|
Stéphane Nicolet (Stephane Nicolet, snicolet)
|
||||||
|
Stefan Geschwentner
|
||||||
|
Alain SAVARD (Rocky640)
|
||||||
|
Jörg Oster (Joerg Oster, joergoster)
|
||||||
|
Reuven Peleg
|
||||||
|
Chris Caino (Chris Cain, ceebo)
|
||||||
|
Jean-Francois Romang
|
||||||
|
homoSapiensSapiens
|
||||||
|
Leonid Pechenik
|
||||||
|
Stefano Cardanobile (Stefano80)
|
||||||
|
Arjun Temurnikar
|
||||||
|
Uri Blass (uriblass)
|
||||||
|
jundery
|
||||||
|
Ajith (ajithcj)
|
||||||
|
hxim
|
||||||
|
Ralph Stößer (Ralph Stoesser)
|
||||||
|
Guenther Demetz
|
||||||
|
Jonathan Calovski (Mysseno)
|
||||||
|
Tom Vijlbrief
|
||||||
|
mbootsector
|
||||||
|
Daylen Yang
|
||||||
|
ElbertoOne
|
||||||
|
Henri Wiechers
|
||||||
|
loco-loco
|
||||||
|
Joost VandeVondele (Joost Vandevondele)
|
||||||
|
Ronald de Man (syzygy)
|
||||||
|
DU-jdto
|
||||||
|
David Zar
|
||||||
|
Eelco de Groot
|
||||||
|
Jerry Donald
|
||||||
|
NicklasPersson
|
||||||
|
Ryan Schmitt
|
||||||
|
Alexander Kure
|
||||||
|
Dan Schmidt
|
||||||
|
H. Felix Wittmann
|
||||||
|
Jacques
|
||||||
|
Joseph R. Prostko
|
||||||
|
Justin Blanchard
|
||||||
|
Linus Arver
|
||||||
|
Luca Brivio
|
||||||
|
Lyudmil Antonov
|
||||||
|
Rodrigo Exterckötter Tjäder
|
||||||
|
Ron Britvich
|
||||||
|
RyanTaker
|
||||||
|
Vince Negri
|
||||||
|
erbsenzaehler
|
||||||
|
Joseph Hellis (jhellis3)
|
||||||
|
shane31
|
||||||
|
Andrew Grant
|
||||||
|
Andy Duplain
|
||||||
|
Auguste Pop
|
||||||
|
Balint Pfliegel
|
||||||
|
Dariusz Orzechowski
|
||||||
|
DiscanX
|
||||||
|
Ernesto Gatti
|
||||||
|
Gregor Cramer
|
||||||
|
Hiraoka Takuya (HiraokaTakuya)
|
||||||
|
Hongzhi Cheng
|
||||||
|
IIvec
|
||||||
|
Kelly Wilson
|
||||||
|
Ken T Takusagawa
|
||||||
|
Kojirion
|
||||||
|
Krgp
|
||||||
|
Matt Sullivan
|
||||||
|
Matthew Lai
|
||||||
|
Matthew Sullivan
|
||||||
|
Michel Van den Bergh
|
||||||
|
Niklas Fiekas
|
||||||
|
Oskar Werkelin Ahlin
|
||||||
|
Pablo Vazquez
|
||||||
|
Pascal Romaret
|
||||||
|
Raminder Singh
|
||||||
|
Richard Lloyd
|
||||||
|
Ryan Takker
|
||||||
|
Thanar2
|
||||||
|
absimaldata
|
||||||
|
atumanian
|
||||||
|
braich
|
||||||
|
fanon
|
||||||
|
gamander
|
||||||
|
gguliash
|
||||||
|
kinderchocolate
|
||||||
|
pellanda
|
||||||
|
ppigazzini
|
||||||
|
renouve
|
||||||
|
sf-x
|
||||||
|
thaspel
|
||||||
|
unknown
|
||||||
|
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
### 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
|
||||||
|
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 512 cores. The engine defaults
|
||||||
|
to one search thread, so it is therefore recommended to inspect the value of
|
||||||
|
the *Threads* UCI parameter, and to make sure it equals the number of CPU
|
||||||
|
cores on your computer.
|
||||||
|
|
||||||
|
This version of Stockfish has support for Syzygybases.
|
||||||
|
|
||||||
|
|
||||||
|
### Files
|
||||||
|
|
||||||
|
This distribution of Stockfish consists of the following files:
|
||||||
|
|
||||||
|
* Readme.md, the file you are currently reading.
|
||||||
|
|
||||||
|
* Copying.txt, a text file containing the GNU General Public License.
|
||||||
|
|
||||||
|
* src, a subdirectory containing the full source code, including a Makefile
|
||||||
|
that can be used to compile Stockfish on Unix-like systems.
|
||||||
|
|
||||||
|
|
||||||
|
### Syzygybases
|
||||||
|
|
||||||
|
**Configuration**
|
||||||
|
|
||||||
|
Syzygybases are configured using the UCI options "SyzygyPath",
|
||||||
|
"SyzygyProbeDepth", "Syzygy50MoveRule" and "SyzygyProbeLimit".
|
||||||
|
|
||||||
|
The option "SyzygyPath" should be set to the directory or directories that
|
||||||
|
contain the .rtbw and .rtbz files. Multiple directories should be
|
||||||
|
separated by ";" on Windows and by ":" on Unix-based operating systems.
|
||||||
|
**Do not use spaces around the ";" or ":".**
|
||||||
|
|
||||||
|
Example: `C:\tablebases\wdl345;C:\tablebases\wdl6;D:\tablebases\dtz345;D:\tablebases\dtz6`
|
||||||
|
|
||||||
|
It is recommended to store .rtbw files on an SSD. There is no loss in
|
||||||
|
storing the .rtbz files on a regular HD.
|
||||||
|
|
||||||
|
Increasing the "SyzygyProbeDepth" option lets the engine probe less
|
||||||
|
aggressively. Set this option to a higher value if you experience too much
|
||||||
|
slowdown (in terms of nps) due to TB probing.
|
||||||
|
|
||||||
|
Set the "Syzygy50MoveRule" option to false if you want tablebase positions
|
||||||
|
that are drawn by the 50-move rule to count as win or loss. This may be useful
|
||||||
|
for correspondence games (because of tablebase adjudication).
|
||||||
|
|
||||||
|
The "SyzygyProbeLimit" option should normally be left at its default value.
|
||||||
|
|
||||||
|
**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.
|
||||||
|
If the engine reports a very large score (typically 123.xx), this means
|
||||||
|
that it has found a winning line into a tablebase position.
|
||||||
|
|
||||||
|
If the engine is given a position to search that is in the tablebases, it
|
||||||
|
will use the tablebases at the beginning of the search to preselect all
|
||||||
|
good moves, i.e. all moves that preserve the win or preserve the draw while
|
||||||
|
taking into account the 50-move rule.
|
||||||
|
It will then perform a search only on those moves. **The engine will not move
|
||||||
|
immediately**, unless there is only a single good move. **The engine likely
|
||||||
|
will not report a mate score even if the position is known to be won.**
|
||||||
|
|
||||||
|
It is therefore clear that behaviour is not identical to what one might
|
||||||
|
be used to with Nalimov tablebases. There are technical reasons for this
|
||||||
|
difference, the main technical reason being that Nalimov tablebases use the
|
||||||
|
DTM metric (distance-to-mate), while Syzygybases use a variation of the
|
||||||
|
DTZ metric (distance-to-zero, zero meaning any move that resets the 50-move
|
||||||
|
counter). This special metric is one of the reasons that Syzygybases are
|
||||||
|
more compact than Nalimov tablebases, while still storing all information
|
||||||
|
needed for optimal play and in addition being able to take into account
|
||||||
|
the 50-move rule.
|
||||||
|
|
||||||
|
|
||||||
|
### Compiling it yourself
|
||||||
|
|
||||||
|
On Unix-like systems, it should be possible to compile Stockfish
|
||||||
|
directly from the source code with the included Makefile.
|
||||||
|
|
||||||
|
Stockfish has support for 32 or 64-bit CPUs, the hardware POPCNT
|
||||||
|
instruction, big-endian machines such as Power PC, and other platforms.
|
||||||
|
|
||||||
|
In general it is recommended to run `make help` to see a list of make
|
||||||
|
targets with corresponding descriptions. When not using the Makefile to
|
||||||
|
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
|
||||||
|
|
||||||
|
* [Chessprogramingwiki](https://chessprogramming.wikispaces.com) has good overall chess engines explanations
|
||||||
|
(techniques used here are well explained like hash maps etc), it was
|
||||||
|
also recommended by the [support at stockfish.](http://support.stockfishchess.org/discussions/questions/1132-how-to-understand-stockfish-sources)
|
||||||
|
|
||||||
|
* [Here](https://chessprogramming.wikispaces.com/Stockfish) you can find a set of features and techniques used by stockfish and each of them is explained at the wiki, however, it's a generic way rather than focusing on stockfish's own implementation, but it will still help you.
|
||||||
|
|
||||||
|
|
||||||
|
### Terms of use
|
||||||
|
|
||||||
|
Stockfish is free, and distributed under the **GNU General Public License**
|
||||||
|
(GPL). Essentially, this means that you are free to do almost exactly
|
||||||
|
what you want with the program, including distributing it among your
|
||||||
|
friends, making it available for download from your web site, selling
|
||||||
|
it (either by itself or as part of some bigger software package), or
|
||||||
|
using it as the starting point for a software project of your own.
|
||||||
|
|
||||||
|
The only real limitation is that whenever you distribute Stockfish in
|
||||||
|
some way, you must always include the full source code, or a pointer
|
||||||
|
to where the source code can be found. If you make any changes to the
|
||||||
|
source code, these changes must also be made available under the GPL.
|
||||||
|
|
||||||
|
For full details, read the copy of the GPL found in the file named
|
||||||
|
*Copying.txt*.
|
||||||
-88
@@ -1,88 +0,0 @@
|
|||||||
1. Introduction
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
|
||||||
not a complete chess program, but requires some UCI compatible GUI
|
|
||||||
(like XBoard with PolyGlot, eboard, Josè, Arena, Sigma Chess, Shredder,
|
|
||||||
Chess Partner, or Fritz) in order to be used comfortably. Read the
|
|
||||||
documentation for your GUI of choice for information about how to use
|
|
||||||
Stockfish with your GUI.
|
|
||||||
|
|
||||||
This version of Stockfish supports up to 32 CPUs, but has not been
|
|
||||||
tested thoroughly with more than 4. The program tries to detect the
|
|
||||||
number of CPUs on your computer and set the number of search threads
|
|
||||||
accordingly, but please be aware that the detection is not always
|
|
||||||
correct. It is therefore recommended to inspect the value of the
|
|
||||||
"Threads" UCI parameter, and to make sure it equals the number of CPU
|
|
||||||
cores on your computer. If you are using more than four threads, it
|
|
||||||
is recommended to raise the value of "Minimum Split Depth" UCI parameter
|
|
||||||
to 6.
|
|
||||||
|
|
||||||
|
|
||||||
2. Files
|
|
||||||
--------
|
|
||||||
|
|
||||||
This distribution of Stockfish consists of the following files:
|
|
||||||
|
|
||||||
* Readme.txt, the file you are currently reading.
|
|
||||||
|
|
||||||
* Copying.txt, a text file containing the GNU General Public
|
|
||||||
License.
|
|
||||||
|
|
||||||
* src/, a subdirectory containing the full source code, including a
|
|
||||||
Makefile that can be used to compile Stockfish on Unix-like
|
|
||||||
systems. For further information about how to compile Stockfish
|
|
||||||
yourself, read section 4 below.
|
|
||||||
|
|
||||||
* polyglot.ini, for using Stockfish with Fabien Letouzey's PolyGlot
|
|
||||||
adapter.
|
|
||||||
|
|
||||||
|
|
||||||
3. Opening books
|
|
||||||
----------------
|
|
||||||
|
|
||||||
This version of Stockfish has support for PolyGlot opening books.
|
|
||||||
For information about how to create such books, consult the PolyGlot
|
|
||||||
documentation. The book file can be selected by setting the UCI
|
|
||||||
parameter "Book File".
|
|
||||||
|
|
||||||
|
|
||||||
4. Compiling it yourself
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
On Unix-like systems, it should usually be possible to compile
|
|
||||||
Stockfish directly from the source code with the included Makefile.
|
|
||||||
|
|
||||||
For big-endian machines like Power PC you need to enable the proper
|
|
||||||
flag changing from -DNBIGENDIAN to -DBIGENDIAN in the Makefile.
|
|
||||||
|
|
||||||
Stockfish has POPCNT instruction runtime detection and support. This can
|
|
||||||
give an extra speed on Core i7 or similar systems. To enable this feature
|
|
||||||
compile with 'make icc-profile-popcnt'
|
|
||||||
|
|
||||||
On 64 bit systems the 'bsfq' assembly instruction will be used for bit
|
|
||||||
counting. Detection is automatic at compile time, but in case you experience
|
|
||||||
compile problems you can comment out #define USE_BSFQ line in types.h
|
|
||||||
|
|
||||||
In general is recommended to run 'make help' to see a list of make targets
|
|
||||||
with corresponding descriptions.
|
|
||||||
|
|
||||||
|
|
||||||
5. Terms of use
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Stockfish is free, and distributed under the GNU General Public License
|
|
||||||
(GPL). Essentially, this means that you are free to do almost exactly
|
|
||||||
what you want with the program, including distributing it among your
|
|
||||||
friends, making it available for download from your web site, selling
|
|
||||||
it (either by itself or as part of some bigger software package), or
|
|
||||||
using it as the starting point for a software project of your own.
|
|
||||||
|
|
||||||
The only real limitation is that whenever you distribute Stockfish in
|
|
||||||
some way, you must always include the full source code, or a pointer
|
|
||||||
to where the source code can be found. If you make any changes to the
|
|
||||||
source code, these changes must also be made available under the GPL.
|
|
||||||
|
|
||||||
For full details, read the copy of the GPL found in the file named
|
|
||||||
Copying.txt.
|
|
||||||
|
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
Contributors with >10,000 CPU hours as of January 23, 2018
|
||||||
|
Thank you!
|
||||||
|
|
||||||
|
Username CPU Hours Games played
|
||||||
|
mibere 518300 41835669
|
||||||
|
crunchy 375564 29121434
|
||||||
|
cw 371664 28748719
|
||||||
|
fastgm 299773 20765374
|
||||||
|
JojoM 220590 15299913
|
||||||
|
glinscott 204517 13932027
|
||||||
|
bking_US 187568 12233168
|
||||||
|
ctoks 169342 13475495
|
||||||
|
spams 149531 10940322
|
||||||
|
Thanar 137015 11714855
|
||||||
|
velislav 127305 10047749
|
||||||
|
vdbergh 121741 9056874
|
||||||
|
malala 117291 8126488
|
||||||
|
vdv 117218 8289983
|
||||||
|
leszek 114825 8331897
|
||||||
|
dsmith 114010 7622414
|
||||||
|
CSU_Dynasty 113516 9582758
|
||||||
|
sqrt2 112407 8782694
|
||||||
|
marrco 111143 8222921
|
||||||
|
drabel 108168 9061580
|
||||||
|
BrunoBanani 104938 7448565
|
||||||
|
Data 94621 8433010
|
||||||
|
CoffeeOne 90394 3964243
|
||||||
|
BRAVONE 80811 5341681
|
||||||
|
psk 77195 6156031
|
||||||
|
brabos 70284 5685893
|
||||||
|
Fisherman 66650 5572406
|
||||||
|
nssy 64587 5369140
|
||||||
|
Pking_cda 64499 5704075
|
||||||
|
sterni1971 63488 5070004
|
||||||
|
mgrabiak 62385 5420812
|
||||||
|
tvijlbrief 58957 4154234
|
||||||
|
jromang 58854 4704502
|
||||||
|
dv8silencer 57421 3961325
|
||||||
|
sunu 56620 4609155
|
||||||
|
tinker 56039 4204914
|
||||||
|
biffhero 55743 4810039
|
||||||
|
teddybaer 52982 4740444
|
||||||
|
bcross 50548 5071599
|
||||||
|
renouve 50318 3544864
|
||||||
|
Freja 50296 3805120
|
||||||
|
robnjr 47504 4131742
|
||||||
|
eva42 46542 4044694
|
||||||
|
davar 46538 4030604
|
||||||
|
finfish 46244 3481661
|
||||||
|
rap 46201 3219490
|
||||||
|
ttruscott 45037 3645430
|
||||||
|
solarlight 44155 4074841
|
||||||
|
TueRens 41372 3891510
|
||||||
|
ElbertoOne 41321 3920894
|
||||||
|
Antihistamine 39218 2792761
|
||||||
|
mhunt 38991 2697512
|
||||||
|
bigpen0r 37820 3149955
|
||||||
|
homyur 35569 3009637
|
||||||
|
VoyagerOne 35137 3302650
|
||||||
|
mhoram 34770 2684128
|
||||||
|
racerschmacer 33022 3231055
|
||||||
|
speedycpu 32043 2531964
|
||||||
|
EthanOConnor 31638 2143255
|
||||||
|
oryx 29574 2767730
|
||||||
|
Pyafue 28885 1986098
|
||||||
|
jkiiski 28014 1923255
|
||||||
|
Garf 27579 2770144
|
||||||
|
slakovv 27017 2031279
|
||||||
|
Bobo1239 27000 2488707
|
||||||
|
pb00067 26817 2306694
|
||||||
|
robal 26337 2316795
|
||||||
|
hyperbolic.tom 26248 2200777
|
||||||
|
rkl 24898 2236013
|
||||||
|
SC 23988 2126825
|
||||||
|
nabildanial 23524 1586321
|
||||||
|
achambord 23495 1942546
|
||||||
|
Sharaf_DG 22975 1790697
|
||||||
|
chriswk 22876 1947731
|
||||||
|
anst 22568 2013953
|
||||||
|
Patrick_G 22435 1682293
|
||||||
|
cuistot 22201 1383031
|
||||||
|
gri 21901 1820968
|
||||||
|
Prcuvu 21182 1890546
|
||||||
|
Zirie 21171 1493227
|
||||||
|
JanErik 20596 1791991
|
||||||
|
Isidor 20560 1730290
|
||||||
|
xor12 20535 1819280
|
||||||
|
team-oh 20364 1653708
|
||||||
|
nesoneg 20264 1493435
|
||||||
|
rstoesser 19802 1335177
|
||||||
|
grandphish2 19402 1834196
|
||||||
|
sg4032 18427 1671742
|
||||||
|
dew 18263 1423326
|
||||||
|
ianh2105 18133 1668562
|
||||||
|
MazeOfGalious 18022 1644593
|
||||||
|
ville 17900 1539130
|
||||||
|
j3corre 17607 975954
|
||||||
|
eudhan 17502 1424648
|
||||||
|
iisiraider 17175 1118788
|
||||||
|
jundery 17172 1115855
|
||||||
|
SFTUser 16635 1363975
|
||||||
|
purplefishies 16621 1106850
|
||||||
|
DragonLord 16599 1252348
|
||||||
|
chris 15274 1575333
|
||||||
|
xoto 14900 1486261
|
||||||
|
dju 14861 901552
|
||||||
|
dex 14647 1228763
|
||||||
|
nordlandia 14551 1369718
|
||||||
|
ronaldjerum 14361 1210607
|
||||||
|
OssumOpossum 14149 1029265
|
||||||
|
IgorLeMasson 13844 1228391
|
||||||
|
enedene 13762 935618
|
||||||
|
ako027ako 13442 1250249
|
||||||
|
AdrianSA 13324 924980
|
||||||
|
bpfliegel 13318 886523
|
||||||
|
ncfish1 13056 932344
|
||||||
|
wei 12863 1369596
|
||||||
|
jpulman 12776 854815
|
||||||
|
horst.prack 12436 1151505
|
||||||
|
joster 12424 986622
|
||||||
|
cisco2015 12265 1205019
|
||||||
|
fatmurphy 12015 901134
|
||||||
|
modolief 11228 926456
|
||||||
|
Dark_wizzie 11214 1017910
|
||||||
|
mschmidt 10973 818594
|
||||||
|
eastorwest 10970 1117836
|
||||||
|
infinity 10762 746397
|
||||||
|
SapphireBrand 10692 1024604
|
||||||
|
Thomas A. 10553 736094
|
||||||
|
pgontarz 10294 878746
|
||||||
|
Andrew Grant 10195 922933
|
||||||
|
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%
|
||||||
|
- ps: |
|
||||||
|
# Verify bench number
|
||||||
|
./stockfish bench 2> out.txt 1> null
|
||||||
|
$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 }
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
[PolyGlot]
|
|
||||||
|
|
||||||
EngineDir = .
|
|
||||||
EngineCommand = ./stockfish
|
|
||||||
|
|
||||||
Book = false
|
|
||||||
BookFile = book.bin
|
|
||||||
|
|
||||||
Log = false
|
|
||||||
LogFile = stockfish.log
|
|
||||||
|
|
||||||
Resign = true
|
|
||||||
ResignScore = 600
|
|
||||||
|
|
||||||
[Engine]
|
|
||||||
|
|
||||||
Hash = 128
|
|
||||||
Threads = 1
|
|
||||||
OwnBook = false
|
|
||||||
Book File = book.bin
|
|
||||||
Best Book Move = false
|
|
||||||
Use Search Log = false
|
|
||||||
Search Log Filename = SearchLog.txt
|
|
||||||
Mobility (Middle Game) = 100
|
|
||||||
Mobility (Endgame) = 100
|
|
||||||
Passed Pawns (Middle Game) = 100
|
|
||||||
Passed Pawns (Endgame) = 100
|
|
||||||
Space = 100
|
|
||||||
Aggressiveness = 100
|
|
||||||
Cowardice = 100
|
|
||||||
Minimum Split Depth = 4
|
|
||||||
Maximum Number of Threads per Split Point = 5
|
|
||||||
Use Sleeping Threads = false
|
|
||||||
Skill Level = 20
|
|
||||||
Emergency Move Horizon = 40
|
|
||||||
Emergency Base Time = 200
|
|
||||||
Emergency Move Time = 70
|
|
||||||
Minimum Thinking Time = 20
|
|
||||||
+336
-301
@@ -1,6 +1,7 @@
|
|||||||
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
# Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
# Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
# Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
#
|
#
|
||||||
# Stockfish is free software: you can redistribute it and/or modify
|
# Stockfish is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -20,6 +21,12 @@
|
|||||||
### Section 1. General Configuration
|
### Section 1. General Configuration
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
|
|
||||||
|
### Establish the operating system name
|
||||||
|
KERNEL = $(shell uname -s)
|
||||||
|
ifeq ($(KERNEL),Linux)
|
||||||
|
OS = $(shell uname -o)
|
||||||
|
endif
|
||||||
|
|
||||||
### Executable name
|
### Executable name
|
||||||
EXE = stockfish
|
EXE = stockfish
|
||||||
|
|
||||||
@@ -28,12 +35,12 @@ PREFIX = /usr/local
|
|||||||
BINDIR = $(PREFIX)/bin
|
BINDIR = $(PREFIX)/bin
|
||||||
|
|
||||||
### Built-in benchmark for pgo-builds
|
### Built-in benchmark for pgo-builds
|
||||||
PGOBENCH = ./$(EXE) bench 32 1 10 default depth
|
PGOBENCH = ./$(EXE) bench
|
||||||
|
|
||||||
### Object files
|
### Object files
|
||||||
OBJS = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
|
OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
||||||
material.o misc.o move.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
|
search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Section 2. High-level Configuration
|
### Section 2. High-level Configuration
|
||||||
@@ -42,148 +49,89 @@ OBJS = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
|
|||||||
# flag --- Comp switch --- Description
|
# flag --- Comp switch --- Description
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# debug = no/yes --- -DNDEBUG --- Enable/Disable debug mode
|
# 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
|
# optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
|
||||||
# arch = (name) --- (-arch) --- Target architecture
|
# arch = (name) --- (-arch) --- Target architecture
|
||||||
# os = (name) --- --- Target operating system
|
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
||||||
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
|
||||||
# bigendian = no/yes --- -DBIGENDIAN --- big/little-endian byte order
|
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
|
||||||
# prefetch = no/yes --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
|
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
||||||
# bsfq = no/yes --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction
|
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
||||||
# --- (Works only with GCC and ICC 64-bit)
|
|
||||||
# popcnt = no/yes --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
|
|
||||||
#
|
#
|
||||||
# Note that Makefile is space sensitive, so when adding new architectures
|
# Note that Makefile is space sensitive, so when adding new architectures
|
||||||
# or modifying existing flags, you have to make sure there are no extra spaces
|
# or modifying existing flags, you have to make sure there are no extra spaces
|
||||||
# at the end of the line for flag values.
|
# at the end of the line for flag values.
|
||||||
|
|
||||||
### 2.1. General
|
### 2.1. General and architecture defaults
|
||||||
debug = no
|
|
||||||
optimize = yes
|
optimize = yes
|
||||||
|
debug = no
|
||||||
|
sanitize = no
|
||||||
|
bits = 32
|
||||||
|
prefetch = no
|
||||||
|
popcnt = no
|
||||||
|
sse = no
|
||||||
|
pext = no
|
||||||
|
|
||||||
### 2.2 Architecture specific
|
### 2.2 Architecture specific
|
||||||
|
|
||||||
# General-section
|
|
||||||
ifeq ($(ARCH),general-64)
|
|
||||||
arch = any
|
|
||||||
os = any
|
|
||||||
bits = 64
|
|
||||||
bigendian = no
|
|
||||||
prefetch = no
|
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),general-32)
|
ifeq ($(ARCH),general-32)
|
||||||
arch = any
|
arch = any
|
||||||
os = any
|
|
||||||
bits = 32
|
|
||||||
bigendian = no
|
|
||||||
prefetch = no
|
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),bigendian-64)
|
|
||||||
arch = any
|
|
||||||
os = any
|
|
||||||
bits = 64
|
|
||||||
bigendian = yes
|
|
||||||
prefetch = no
|
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),bigendian-32)
|
|
||||||
arch = any
|
|
||||||
os = any
|
|
||||||
bits = 32
|
|
||||||
bigendian = yes
|
|
||||||
prefetch = no
|
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
|
||||||
endif
|
|
||||||
|
|
||||||
# x86-section
|
|
||||||
ifeq ($(ARCH),x86-64)
|
|
||||||
arch = x86_64
|
|
||||||
os = any
|
|
||||||
bits = 64
|
|
||||||
bigendian = no
|
|
||||||
prefetch = yes
|
|
||||||
bsfq = yes
|
|
||||||
popcnt = no
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),x86-64-modern)
|
|
||||||
arch = x86_64
|
|
||||||
os = any
|
|
||||||
bits = 64
|
|
||||||
bigendian = no
|
|
||||||
prefetch = yes
|
|
||||||
bsfq = yes
|
|
||||||
popcnt = yes
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),x86-32)
|
|
||||||
arch = i386
|
|
||||||
os = any
|
|
||||||
bits = 32
|
|
||||||
bigendian = no
|
|
||||||
prefetch = yes
|
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),x86-32-old)
|
ifeq ($(ARCH),x86-32-old)
|
||||||
arch = i386
|
arch = i386
|
||||||
os = any
|
|
||||||
bits = 32
|
|
||||||
bigendian = no
|
|
||||||
prefetch = no
|
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# osx-section
|
ifeq ($(ARCH),x86-32)
|
||||||
ifeq ($(ARCH),osx-ppc-64)
|
|
||||||
arch = ppc64
|
|
||||||
os = osx
|
|
||||||
bits = 64
|
|
||||||
bigendian = yes
|
|
||||||
prefetch = no
|
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),osx-ppc-32)
|
|
||||||
arch = ppc
|
|
||||||
os = osx
|
|
||||||
bits = 32
|
|
||||||
bigendian = yes
|
|
||||||
prefetch = no
|
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),osx-x86-64)
|
|
||||||
arch = x86_64
|
|
||||||
os = osx
|
|
||||||
bits = 64
|
|
||||||
bigendian = no
|
|
||||||
prefetch = yes
|
|
||||||
bsfq = yes
|
|
||||||
popcnt = no
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),osx-x86-32)
|
|
||||||
arch = i386
|
arch = i386
|
||||||
os = osx
|
|
||||||
bits = 32
|
|
||||||
bigendian = no
|
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = no
|
sse = yes
|
||||||
popcnt = no
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),general-64)
|
||||||
|
arch = any
|
||||||
|
bits = 64
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),x86-64)
|
||||||
|
arch = x86_64
|
||||||
|
bits = 64
|
||||||
|
prefetch = yes
|
||||||
|
sse = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),x86-64-modern)
|
||||||
|
arch = x86_64
|
||||||
|
bits = 64
|
||||||
|
prefetch = yes
|
||||||
|
popcnt = yes
|
||||||
|
sse = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),x86-64-bmi2)
|
||||||
|
arch = x86_64
|
||||||
|
bits = 64
|
||||||
|
prefetch = yes
|
||||||
|
popcnt = yes
|
||||||
|
sse = yes
|
||||||
|
pext = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),armv7)
|
||||||
|
arch = armv7
|
||||||
|
prefetch = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),ppc-32)
|
||||||
|
arch = ppc
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),ppc-64)
|
||||||
|
arch = ppc64
|
||||||
|
bits = 64
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
@@ -192,75 +140,170 @@ endif
|
|||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
|
|
||||||
### 3.1 Selecting compiler (default = gcc)
|
### 3.1 Selecting compiler (default = gcc)
|
||||||
|
|
||||||
|
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
|
||||||
|
DEPENDFLAGS += -std=c++11
|
||||||
|
LDFLAGS += $(EXTRALDFLAGS)
|
||||||
|
|
||||||
ifeq ($(COMP),)
|
ifeq ($(COMP),)
|
||||||
COMP=gcc
|
COMP=gcc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(COMP),mingw)
|
|
||||||
comp=mingw
|
|
||||||
CXX=g++
|
|
||||||
profile_prepare = gcc-profile-prepare
|
|
||||||
profile_make = gcc-profile-make
|
|
||||||
profile_use = gcc-profile-use
|
|
||||||
profile_clean = gcc-profile-clean
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(COMP),gcc)
|
ifeq ($(COMP),gcc)
|
||||||
comp=gcc
|
comp=gcc
|
||||||
CXX=g++
|
CXX=g++
|
||||||
profile_prepare = gcc-profile-prepare
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||||
profile_make = gcc-profile-make
|
|
||||||
profile_use = gcc-profile-use
|
ifeq ($(ARCH),armv7)
|
||||||
profile_clean = gcc-profile-clean
|
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
|
||||||
|
|
||||||
|
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
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(COMP),icc)
|
ifeq ($(COMP),icc)
|
||||||
comp=icc
|
comp=icc
|
||||||
CXX=icpc
|
CXX=icpc
|
||||||
profile_prepare = icc-profile-prepare
|
CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
|
||||||
profile_make = icc-profile-make
|
|
||||||
profile_use = icc-profile-use
|
|
||||||
profile_clean = icc-profile-clean
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.2 General compiler settings
|
ifeq ($(COMP),clang)
|
||||||
CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
|
comp=clang
|
||||||
|
CXX=clang++
|
||||||
ifeq ($(comp),gcc)
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||||
CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
|
ifneq ($(KERNEL),Darwin)
|
||||||
|
ifneq ($(KERNEL),OpenBSD)
|
||||||
|
LDFLAGS += -latomic
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),mingw)
|
ifeq ($(ARCH),armv7)
|
||||||
CXXFLAGS += -Wextra -Wshadow
|
ifeq ($(OS),Android)
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),icc)
|
ifeq ($(comp),icc)
|
||||||
CXXFLAGS += -wd383,981,1418,1419,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
|
profile_make = icc-profile-make
|
||||||
|
profile_use = icc-profile-use
|
||||||
|
else
|
||||||
|
ifeq ($(comp),clang)
|
||||||
|
profile_make = clang-profile-make
|
||||||
|
profile_use = clang-profile-use
|
||||||
|
else
|
||||||
|
profile_make = gcc-profile-make
|
||||||
|
profile_use = gcc-profile-use
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(os),osx)
|
ifeq ($(KERNEL),Darwin)
|
||||||
CXXFLAGS += -arch $(arch)
|
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
||||||
|
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.3 General linker settings
|
### Travis CI script uses COMPILER to overwrite CXX
|
||||||
LDFLAGS = -lpthread $(EXTRALDFLAGS)
|
ifdef COMPILER
|
||||||
|
COMPCXX=$(COMPILER)
|
||||||
ifeq ($(os),osx)
|
|
||||||
LDFLAGS += -arch $(arch)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.4 Debugging
|
### 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 ($(OS),Android)
|
||||||
|
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
||||||
|
ifneq ($(KERNEL),Haiku)
|
||||||
|
LDFLAGS += -lpthread
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.2.1 Debugging
|
||||||
ifeq ($(debug),no)
|
ifeq ($(debug),no)
|
||||||
CXXFLAGS += -DNDEBUG
|
CXXFLAGS += -DNDEBUG
|
||||||
|
else
|
||||||
|
CXXFLAGS += -g
|
||||||
endif
|
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)
|
ifeq ($(optimize),yes)
|
||||||
|
|
||||||
ifeq ($(comp),gcc)
|
CXXFLAGS += -O3
|
||||||
CXXFLAGS += -O3
|
|
||||||
|
|
||||||
ifeq ($(os),osx)
|
ifeq ($(comp),gcc)
|
||||||
|
|
||||||
|
ifeq ($(KERNEL),Darwin)
|
||||||
|
ifeq ($(arch),i386)
|
||||||
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
|
endif
|
||||||
|
ifeq ($(arch),x86_64)
|
||||||
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(OS), Android)
|
||||||
|
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(comp),icc)
|
||||||
|
ifeq ($(KERNEL),Darwin)
|
||||||
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(comp),clang)
|
||||||
|
ifeq ($(KERNEL),Darwin)
|
||||||
|
CXXFLAGS += -flto
|
||||||
|
LDFLAGS += $(CXXFLAGS)
|
||||||
ifeq ($(arch),i386)
|
ifeq ($(arch),i386)
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
endif
|
endif
|
||||||
@@ -269,153 +312,142 @@ ifeq ($(optimize),yes)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),mingw)
|
|
||||||
CXXFLAGS += -O3
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(comp),icc)
|
|
||||||
ifeq ($(os),osx)
|
|
||||||
CXXFLAGS += -fast -mdynamic-no-pic
|
|
||||||
else
|
|
||||||
CXXFLAGS += -O3
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.6. Bits
|
### 3.4 Bits
|
||||||
ifeq ($(bits),64)
|
ifeq ($(bits),64)
|
||||||
CXXFLAGS += -DIS_64BIT
|
CXXFLAGS += -DIS_64BIT
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.7 Endianess
|
### 3.5 prefetch
|
||||||
ifeq ($(bigendian),yes)
|
|
||||||
CXXFLAGS += -DBIGENDIAN
|
|
||||||
endif
|
|
||||||
|
|
||||||
### 3.8 prefetch
|
|
||||||
ifeq ($(prefetch),yes)
|
ifeq ($(prefetch),yes)
|
||||||
CXXFLAGS += -msse
|
ifeq ($(sse),yes)
|
||||||
DEPENDFLAGS += -msse
|
CXXFLAGS += -msse
|
||||||
|
DEPENDFLAGS += -msse
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
CXXFLAGS += -DNO_PREFETCH
|
CXXFLAGS += -DNO_PREFETCH
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.9 bsfq
|
### 3.6 popcnt
|
||||||
ifeq ($(bsfq),yes)
|
ifeq ($(popcnt),yes)
|
||||||
CXXFLAGS += -DUSE_BSFQ
|
ifeq ($(comp),icc)
|
||||||
|
CXXFLAGS += -msse3 -DUSE_POPCNT
|
||||||
|
else
|
||||||
|
CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.10 popcnt
|
### 3.7 pext
|
||||||
ifeq ($(popcnt),yes)
|
ifeq ($(pext),yes)
|
||||||
CXXFLAGS += -DUSE_POPCNT
|
CXXFLAGS += -DUSE_PEXT
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -mbmi2
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
### 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)
|
||||||
|
CXXFLAGS += -flto
|
||||||
|
LDFLAGS += $(CXXFLAGS)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(comp),mingw)
|
||||||
|
ifeq ($(KERNEL),Linux)
|
||||||
|
ifeq ($(optimize),yes)
|
||||||
|
ifeq ($(debug),no)
|
||||||
|
CXXFLAGS += -flto
|
||||||
|
LDFLAGS += $(CXXFLAGS)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.9 Android 5 can only run position independent executables. Note that this
|
||||||
|
### breaks Android 4.0 and earlier.
|
||||||
|
ifeq ($(OS), Android)
|
||||||
|
CXXFLAGS += -fPIE
|
||||||
|
LDFLAGS += -fPIE -pie
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Section 4. Public targets
|
### Section 4. Public targets
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
|
|
||||||
default:
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) build
|
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "To compile stockfish, type: "
|
@echo "To compile stockfish, type: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make target ARCH=arch [COMP=comp]"
|
@echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Supported targets:"
|
@echo "Supported targets:"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "build > Build unoptimized version"
|
@echo "build > Standard build"
|
||||||
@echo "profile-build > Build PGO-optimized version"
|
@echo "profile-build > PGO build"
|
||||||
@echo "popcnt-profile-build > Build PGO-optimized version with optional popcnt-support"
|
@echo "strip > Strip executable"
|
||||||
@echo "strip > Strip executable"
|
@echo "install > Install executable"
|
||||||
@echo "install > Install executable"
|
@echo "clean > Clean up"
|
||||||
@echo "clean > Clean up"
|
|
||||||
@echo "testrun > Make sample run"
|
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Supported archs:"
|
@echo "Supported archs:"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "x86-64 > x86 64-bit"
|
@echo "x86-64 > x86 64-bit"
|
||||||
@echo "x86-64-modern > x86 64-bit with runtime support for popcnt-instruction"
|
@echo "x86-64-modern > x86 64-bit with popcnt support"
|
||||||
@echo "x86-32 > x86 32-bit excluding very old hardware without SSE-support"
|
@echo "x86-64-bmi2 > x86 64-bit with pext support"
|
||||||
@echo "x86-32-old > x86 32-bit including also very old hardware"
|
@echo "x86-32 > x86 32-bit with SSE support"
|
||||||
@echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
|
@echo "x86-32-old > x86 32-bit fall back for old hardware"
|
||||||
@echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
|
@echo "ppc-64 > PPC 64-bit"
|
||||||
@echo "osx-x86-64 > x86-Mac OS X 64 bit"
|
@echo "ppc-32 > PPC 32-bit"
|
||||||
@echo "osx-x86-32 > x86-Mac OS X 32 bit"
|
@echo "armv7 > ARMv7 32-bit"
|
||||||
@echo "general-64 > unspecified 64-bit"
|
@echo "general-64 > unspecified 64-bit"
|
||||||
@echo "general-32 > unspecified 32-bit"
|
@echo "general-32 > unspecified 32-bit"
|
||||||
@echo "bigendian-64 > unspecified 64-bit with bigendian byte order"
|
|
||||||
@echo "bigendian-32 > unspecified 32-bit with bigendian byte order"
|
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Supported comps:"
|
@echo "Supported compilers:"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "gcc > Gnu compiler (default)"
|
@echo "gcc > Gnu compiler (default)"
|
||||||
@echo "icc > Intel compiler"
|
@echo "mingw > Gnu compiler with MinGW under Windows"
|
||||||
@echo "mingw > Gnu compiler with MinGW under Windows"
|
@echo "clang > LLVM Clang compiler"
|
||||||
|
@echo "icc > Intel compiler"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Non-standard targets:"
|
@echo "Simple examples. If you don't know what to do, you likely want to run: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make hpux > Compile for HP-UX. Compiler = aCC"
|
@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 ""
|
||||||
@echo "Examples. If you don't know what to do, you likely want to run: "
|
@echo "Advanced examples, for experienced users: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
|
@echo "make build ARCH=x86-64 COMP=clang"
|
||||||
@echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
|
@echo "make profile-build ARCH=x86-64-modern COMP=gcc COMPCXX=g++-4.8"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
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
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
||||||
|
|
||||||
profile-build:
|
profile-build: config-sanity objclean profileclean
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 0/4. Preparing for profile build."
|
@echo "Step 1/4. Building instrumented executable ..."
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 1/4. Building executable for benchmark ..."
|
|
||||||
@touch *.cpp *.h
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
||||||
@$(PGOBENCH) > /dev/null
|
$(PGOBENCH) > /dev/null
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 3/4. Building final executable ..."
|
@echo "Step 3/4. Building optimized executable ..."
|
||||||
@touch *.cpp
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 4/4. Deleting profile data ..."
|
@echo "Step 4/4. Deleting profile data ..."
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
|
||||||
|
|
||||||
popcnt-profile-build:
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 0/6. Preparing for profile build."
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 1/6. Building executable for benchmark (popcnt disabled)..."
|
|
||||||
@touch *.cpp *.h
|
|
||||||
$(MAKE) ARCH=x86-64 COMP=$(COMP) $(profile_make)
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 2/6. Running benchmark for pgo-build (popcnt disabled)..."
|
|
||||||
@$(PGOBENCH) > /dev/null
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 3/6. Building executable for benchmark (popcnt enabled)..."
|
|
||||||
@touch *.cpp *.h
|
|
||||||
$(MAKE) ARCH=x86-64-modern COMP=$(COMP) $(profile_make)
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 4/6. Running benchmark for pgo-build (popcnt enabled)..."
|
|
||||||
@$(PGOBENCH) > /dev/null
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 5/6. Building final executable ..."
|
|
||||||
@touch *.cpp *.h
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 6/6. Deleting profile data ..."
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
|
|
||||||
@echo ""
|
|
||||||
|
|
||||||
strip:
|
strip:
|
||||||
strip $(EXE)
|
strip $(EXE)
|
||||||
@@ -425,11 +457,22 @@ install:
|
|||||||
-cp $(EXE) $(BINDIR)
|
-cp $(EXE) $(BINDIR)
|
||||||
-strip $(BINDIR)/$(EXE)
|
-strip $(BINDIR)/$(EXE)
|
||||||
|
|
||||||
clean:
|
#clean all
|
||||||
$(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
|
clean: objclean profileclean
|
||||||
|
@rm -f .depend *~ core
|
||||||
|
|
||||||
testrun:
|
# clean binaries and objects
|
||||||
@$(PGOBENCH)
|
objclean:
|
||||||
|
@rm -f $(EXE) $(EXE).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
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Section 5. Private targets
|
### Section 5. Private targets
|
||||||
@@ -441,14 +484,16 @@ config-sanity:
|
|||||||
@echo ""
|
@echo ""
|
||||||
@echo "Config:"
|
@echo "Config:"
|
||||||
@echo "debug: '$(debug)'"
|
@echo "debug: '$(debug)'"
|
||||||
|
@echo "sanitize: '$(sanitize)'"
|
||||||
@echo "optimize: '$(optimize)'"
|
@echo "optimize: '$(optimize)'"
|
||||||
@echo "arch: '$(arch)'"
|
@echo "arch: '$(arch)'"
|
||||||
@echo "os: '$(os)'"
|
|
||||||
@echo "bits: '$(bits)'"
|
@echo "bits: '$(bits)'"
|
||||||
@echo "bigendian: '$(bigendian)'"
|
@echo "kernel: '$(KERNEL)'"
|
||||||
|
@echo "os: '$(OS)'"
|
||||||
@echo "prefetch: '$(prefetch)'"
|
@echo "prefetch: '$(prefetch)'"
|
||||||
@echo "bsfq: '$(bsfq)'"
|
|
||||||
@echo "popcnt: '$(popcnt)'"
|
@echo "popcnt: '$(popcnt)'"
|
||||||
|
@echo "sse: '$(sse)'"
|
||||||
|
@echo "pext: '$(pext)'"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Flags:"
|
@echo "Flags:"
|
||||||
@echo "CXX: $(CXX)"
|
@echo "CXX: $(CXX)"
|
||||||
@@ -458,22 +503,32 @@ config-sanity:
|
|||||||
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
||||||
@echo ""
|
@echo ""
|
||||||
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
||||||
|
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "no"
|
||||||
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
||||||
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
||||||
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
|
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
||||||
@test "$(os)" = "any" || test "$(os)" = "osx"
|
|
||||||
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
||||||
@test "$(bigendian)" = "yes" || test "$(bigendian)" = "no"
|
|
||||||
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
||||||
@test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
|
|
||||||
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
||||||
@test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw"
|
@test "$(sse)" = "yes" || test "$(sse)" = "no"
|
||||||
|
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
||||||
|
@test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
|
||||||
|
|
||||||
$(EXE): $(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
gcc-profile-prepare:
|
clang-profile-make:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
|
$(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:
|
gcc-profile-make:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
@@ -483,17 +538,12 @@ gcc-profile-make:
|
|||||||
|
|
||||||
gcc-profile-use:
|
gcc-profile-use:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
EXTRACXXFLAGS='-fprofile-use' \
|
EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \
|
||||||
|
EXTRALDFLAGS='-lgcov' \
|
||||||
all
|
all
|
||||||
|
|
||||||
gcc-profile-clean:
|
|
||||||
@rm -rf *.gcda *.gcno bench.txt
|
|
||||||
|
|
||||||
icc-profile-prepare:
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
|
|
||||||
@mkdir profdir
|
|
||||||
|
|
||||||
icc-profile-make:
|
icc-profile-make:
|
||||||
|
@mkdir -p profdir
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
|
EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
|
||||||
all
|
all
|
||||||
@@ -503,23 +553,8 @@ icc-profile-use:
|
|||||||
EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
|
EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
|
||||||
all
|
all
|
||||||
|
|
||||||
icc-profile-clean:
|
|
||||||
@rm -rf profdir bench.txt
|
|
||||||
|
|
||||||
.depend:
|
.depend:
|
||||||
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
||||||
|
|
||||||
-include .depend
|
-include .depend
|
||||||
|
|
||||||
|
|
||||||
### ==========================================================================
|
|
||||||
### Section 6. Non-standard targets
|
|
||||||
### ==========================================================================
|
|
||||||
|
|
||||||
hpux:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG -DNO_PREFETCH' \
|
|
||||||
CXXFLAGS="" \
|
|
||||||
LDFLAGS="" \
|
|
||||||
all
|
|
||||||
|
|
||||||
|
|||||||
+94
-91
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,21 +20,23 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <istream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
|
||||||
#include "ucioption.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static const string Defaults[] = {
|
namespace {
|
||||||
|
|
||||||
|
const vector<string> Defaults = {
|
||||||
|
"setoption name UCI_Chess960 value false",
|
||||||
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
||||||
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -",
|
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
|
||||||
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -",
|
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
|
||||||
"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
|
"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
|
||||||
"rq3rk1/ppp2ppp/1bnpb3/3N2B1/3NP3/7P/PPPQ1PP1/2KR3R w - - 7 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",
|
"r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14 moves g2g4",
|
||||||
"r3r1k1/2p2ppp/p1p1bn2/8/1q2P3/2NPQN2/PPP3PP/R4RK1 b - - 2 15",
|
"r3r1k1/2p2ppp/p1p1bn2/8/1q2P3/2NPQN2/PPP3PP/R4RK1 b - - 2 15",
|
||||||
"r1bbk1nr/pp3p1p/2n5/1N4p1/2Np1B2/8/PPP2PPP/2KR1B1R w kq - 0 13",
|
"r1bbk1nr/pp3p1p/2n5/1N4p1/2Np1B2/8/PPP2PPP/2KR1B1R w kq - 0 13",
|
||||||
"r1bq1rk1/ppp1nppp/4n3/3p3Q/3P4/1BP1B3/PP1N2PP/R4RK1 w - - 1 16",
|
"r1bq1rk1/ppp1nppp/4n3/3p3Q/3P4/1BP1B3/PP1N2PP/R4RK1 w - - 1 16",
|
||||||
@@ -44,110 +47,110 @@ static const string Defaults[] = {
|
|||||||
"r1q2rk1/2p1bppp/2Pp4/p6b/Q1PNp3/4B3/PP1R1PPP/2K4R w - - 2 18",
|
"r1q2rk1/2p1bppp/2Pp4/p6b/Q1PNp3/4B3/PP1R1PPP/2K4R w - - 2 18",
|
||||||
"4k2r/1pb2ppp/1p2p3/1R1p4/3P4/2r1PN2/P4PPP/1R4K1 b - - 3 22",
|
"4k2r/1pb2ppp/1p2p3/1R1p4/3P4/2r1PN2/P4PPP/1R4K1 b - - 3 22",
|
||||||
"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b - - 4 26",
|
"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 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",
|
||||||
|
"8/1p3pp1/7p/5P1P/2k3P1/8/2K2P2/8 w - - 0 1",
|
||||||
|
"8/pp2r1k1/2p1p3/3pP2p/1P1P1P1P/P5KR/8/8 w - - 0 1",
|
||||||
|
"8/3p4/p1bk3p/Pp6/1Kp1PpPp/2P2P1P/2P5/5B2 b - - 0 1",
|
||||||
|
"5k2/7R/4P2p/5K2/p1r2P1p/8/8/8 b - - 0 1",
|
||||||
|
"6k1/6p1/P6p/r1N5/5p2/7P/1b3PP1/4R1K1 w - - 0 1",
|
||||||
|
"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w - - 0 1",
|
||||||
|
"6k1/4pp1p/3p2p1/P1pPb3/R7/1r2P1PP/3B1P2/6K1 w - - 0 1",
|
||||||
|
"8/3p3B/5p2/5P2/p7/PP5b/k7/6K1 w - - 0 1",
|
||||||
|
|
||||||
|
// 5-man positions
|
||||||
|
"8/8/8/8/5kp1/P7/8/1K1N4 w - - 0 1", // Kc2 - mate
|
||||||
|
"8/8/8/5N2/8/p7/8/2NK3k w - - 0 1", // Na2 - mate
|
||||||
|
"8/3k4/8/8/8/4B3/4KB2/2B5 w - - 0 1", // draw
|
||||||
|
|
||||||
|
// 6-man positions
|
||||||
|
"8/8/1P6/5pr1/8/4R3/7k/2K5 w - - 0 1", // Re5 - mate
|
||||||
|
"8/2p4P/8/kr6/6R1/8/8/1K6 w - - 0 1", // Ka2 - mate
|
||||||
|
"8/8/3P3k/8/1p6/8/1P6/1K3n2 b - - 0 1", // Nd2 - draw
|
||||||
|
|
||||||
|
// 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
|
/// setup_bench() builds a list of UCI commands to be run by bench. There
|
||||||
/// of positions for a given limit each. There are five parameters; the
|
/// are five parameters: TT size in MB, number of search threads that
|
||||||
/// transposition table size, the number of search threads that should
|
/// should be used, the limit value spent for each position, a file name
|
||||||
/// be used, the limit value spent for each position (optional, default
|
/// where to look for positions in FEN format and the type of the limit:
|
||||||
/// is ply 12), an optional file name where to look for positions in fen
|
/// depth, perft, nodes and movetime (in millisecs).
|
||||||
/// format (default are the BenchmarkPositions defined above) and the type
|
///
|
||||||
/// of the limit value: depth (default), time in secs or number of nodes.
|
/// bench -> search default positions up to depth 13
|
||||||
/// The analysis is written to a file named bench.txt.
|
/// 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(int argc, char* argv[]) {
|
vector<string> setup_bench(const Position& current, istream& is) {
|
||||||
|
|
||||||
vector<string> fenList;
|
vector<string> fens, list;
|
||||||
SearchLimits limits;
|
string go, token;
|
||||||
int64_t totalNodes;
|
|
||||||
int time;
|
|
||||||
|
|
||||||
// Load default positions
|
|
||||||
for (int i = 0; !Defaults[i].empty(); i++)
|
|
||||||
fenList.push_back(Defaults[i]);
|
|
||||||
|
|
||||||
// Assign default values to missing arguments
|
// Assign default values to missing arguments
|
||||||
string ttSize = argc > 2 ? argv[2] : "128";
|
string ttSize = (is >> token) ? token : "16";
|
||||||
string threads = argc > 3 ? argv[3] : "1";
|
string threads = (is >> token) ? token : "1";
|
||||||
string valStr = argc > 4 ? argv[4] : "12";
|
string limit = (is >> token) ? token : "13";
|
||||||
string fenFile = argc > 5 ? argv[5] : "default";
|
string fenFile = (is >> token) ? token : "default";
|
||||||
string valType = argc > 6 ? argv[6] : "depth";
|
string limitType = (is >> token) ? token : "depth";
|
||||||
|
|
||||||
Options["Hash"].set_value(ttSize);
|
go = "go " + limitType + " " + limit;
|
||||||
Options["Threads"].set_value(threads);
|
|
||||||
Options["OwnBook"].set_value("false");
|
if (fenFile == "default")
|
||||||
|
fens = Defaults;
|
||||||
|
|
||||||
|
else if (fenFile == "current")
|
||||||
|
fens.push_back(current.fen());
|
||||||
|
|
||||||
// Search should be limited by nodes, time or depth ?
|
|
||||||
if (valType == "nodes")
|
|
||||||
limits.maxNodes = atoi(valStr.c_str());
|
|
||||||
else if (valType == "time")
|
|
||||||
limits.maxTime = 1000 * atoi(valStr.c_str()); // maxTime is in ms
|
|
||||||
else
|
else
|
||||||
limits.maxDepth = atoi(valStr.c_str());
|
|
||||||
|
|
||||||
// Do we need to load positions from a given FEN file ?
|
|
||||||
if (fenFile != "default")
|
|
||||||
{
|
{
|
||||||
string fen;
|
string fen;
|
||||||
ifstream f(fenFile.c_str());
|
ifstream file(fenFile);
|
||||||
|
|
||||||
if (f.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
fenList.clear();
|
cerr << "Unable to open file " << fenFile << endl;
|
||||||
|
|
||||||
while (getline(f, fen))
|
|
||||||
if (!fen.empty())
|
|
||||||
fenList.push_back(fen);
|
|
||||||
|
|
||||||
f.close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << "Unable to open FEN file " << fenFile << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (getline(file, fen))
|
||||||
|
if (!fen.empty())
|
||||||
|
fens.push_back(fen);
|
||||||
|
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok, let's start the benchmark !
|
list.emplace_back("ucinewgame");
|
||||||
totalNodes = 0;
|
list.emplace_back("setoption name Threads value " + threads);
|
||||||
time = get_system_time();
|
list.emplace_back("setoption name Hash value " + ttSize);
|
||||||
|
|
||||||
for (size_t i = 0; i < fenList.size(); i++)
|
for (const string& fen : fens)
|
||||||
{
|
if (fen.find("setoption") != string::npos)
|
||||||
Move moves[] = { MOVE_NONE };
|
list.emplace_back(fen);
|
||||||
Position pos(fenList[i], false, 0);
|
|
||||||
|
|
||||||
cerr << "\nBench position: " << i + 1 << '/' << fenList.size() << endl;
|
|
||||||
|
|
||||||
if (valType == "perft")
|
|
||||||
{
|
|
||||||
int64_t cnt = perft(pos, limits.maxDepth * ONE_PLY);
|
|
||||||
totalNodes += cnt;
|
|
||||||
|
|
||||||
cerr << "\nPerft " << limits.maxDepth << " nodes counted: " << cnt << endl;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!think(pos, limits, moves))
|
list.emplace_back("position fen " + fen);
|
||||||
break;
|
list.emplace_back(go);
|
||||||
|
|
||||||
totalNodes += pos.nodes_searched();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
time = get_system_time() - time;
|
return list;
|
||||||
|
|
||||||
cerr << "\n==============================="
|
|
||||||
<< "\nTotal time (ms) : " << time
|
|
||||||
<< "\nNodes searched : " << totalNodes
|
|
||||||
<< "\nNodes/second : " << (int)(totalNodes / (time / 1000.0)) << endl << endl;
|
|
||||||
|
|
||||||
// MS Visual C++ debug window always unconditionally closes when program
|
|
||||||
// exits, this is bad because we want to read results before.
|
|
||||||
#if (defined(WINDOWS) || defined(WIN32) || defined(WIN64))
|
|
||||||
cerr << "Press any key to exit" << endl;
|
|
||||||
cin >> time;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
+122
-226
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,268 +18,163 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <numeric>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum Result {
|
// There are 24 possible pawn squares: the first 4 files and ranks from 2 to 7
|
||||||
RESULT_UNKNOWN,
|
const unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
||||||
RESULT_INVALID,
|
|
||||||
RESULT_WIN,
|
|
||||||
RESULT_LOSS,
|
|
||||||
RESULT_DRAW
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KPKPosition {
|
|
||||||
void from_index(int index);
|
|
||||||
bool is_legal() const;
|
|
||||||
bool is_immediate_draw() const;
|
|
||||||
bool is_immediate_win() const;
|
|
||||||
Bitboard wk_attacks() const { return StepAttacksBB[WK][whiteKingSquare]; }
|
|
||||||
Bitboard bk_attacks() const { return StepAttacksBB[BK][blackKingSquare]; }
|
|
||||||
Bitboard pawn_attacks() const { return StepAttacksBB[WP][pawnSquare]; }
|
|
||||||
|
|
||||||
Square whiteKingSquare, blackKingSquare, pawnSquare;
|
|
||||||
Color sideToMove;
|
|
||||||
};
|
|
||||||
|
|
||||||
// The possible pawns squares are 24, the first 4 files and ranks from 2 to 7
|
|
||||||
const int IndexMax = 2 * 24 * 64 * 64; // color * wp_sq * wk_sq * bk_sq
|
|
||||||
|
|
||||||
// Each uint32_t stores results of 32 positions, one per bit
|
// Each uint32_t stores results of 32 positions, one per bit
|
||||||
uint32_t KPKBitbase[IndexMax / 32];
|
uint32_t KPKBitbase[MAX_INDEX / 32];
|
||||||
|
|
||||||
Result classify_wtm(const KPKPosition& pos, const Result bb[]);
|
// A KPK bitbase index is an integer in [0, IndexMax] range
|
||||||
Result classify_btm(const KPKPosition& pos, const Result bb[]);
|
//
|
||||||
int compute_index(Square wksq, Square bksq, Square wpsq, Color stm);
|
// Information is mapped in a way that minimizes the number of iterations:
|
||||||
}
|
//
|
||||||
|
// bit 0- 5: white king square (from SQ_A1 to SQ_H8)
|
||||||
|
// bit 6-11: black king square (from SQ_A1 to SQ_H8)
|
||||||
uint32_t probe_kpk_bitbase(Square wksq, Square wpsq, Square bksq, Color stm) {
|
// bit 12: side to move (WHITE or BLACK)
|
||||||
|
// bit 13-14: white pawn file (from FILE_A to FILE_D)
|
||||||
int index = compute_index(wksq, bksq, wpsq, stm);
|
// bit 15-17: white pawn RANK_7 - rank (from RANK_7 - RANK_7 to RANK_7 - RANK_2)
|
||||||
|
unsigned index(Color us, Square bksq, Square wksq, Square psq) {
|
||||||
return KPKBitbase[index / 32] & (1 << (index & 31));
|
return wksq | (bksq << 6) | (us << 12) | (file_of(psq) << 13) | ((RANK_7 - rank_of(psq)) << 15);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void init_kpk_bitbase() {
|
|
||||||
|
|
||||||
Result bb[IndexMax];
|
|
||||||
KPKPosition pos;
|
|
||||||
bool repeat;
|
|
||||||
|
|
||||||
// Initialize table
|
|
||||||
for (int i = 0; i < IndexMax; i++)
|
|
||||||
{
|
|
||||||
pos.from_index(i);
|
|
||||||
bb[i] = !pos.is_legal() ? RESULT_INVALID
|
|
||||||
: pos.is_immediate_draw() ? RESULT_DRAW
|
|
||||||
: pos.is_immediate_win() ? RESULT_WIN : RESULT_UNKNOWN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate until all positions are classified (30 cycles needed)
|
enum Result {
|
||||||
do {
|
INVALID = 0,
|
||||||
repeat = false;
|
UNKNOWN = 1,
|
||||||
|
DRAW = 2,
|
||||||
|
WIN = 4
|
||||||
|
};
|
||||||
|
|
||||||
for (int i = 0; i < IndexMax; i++)
|
Result& operator|=(Result& r, Result v) { return r = Result(r | v); }
|
||||||
if (bb[i] == RESULT_UNKNOWN)
|
|
||||||
{
|
|
||||||
pos.from_index(i);
|
|
||||||
|
|
||||||
bb[i] = (pos.sideToMove == WHITE) ? classify_wtm(pos, bb)
|
struct KPKPosition {
|
||||||
: classify_btm(pos, bb);
|
KPKPosition() = default;
|
||||||
if (bb[i] != RESULT_UNKNOWN)
|
explicit KPKPosition(unsigned idx);
|
||||||
repeat = true;
|
operator Result() const { return result; }
|
||||||
}
|
Result classify(const std::vector<KPKPosition>& db)
|
||||||
|
{ return us == WHITE ? classify<WHITE>(db) : classify<BLACK>(db); }
|
||||||
|
|
||||||
} while (repeat);
|
template<Color Us> Result classify(const std::vector<KPKPosition>& db);
|
||||||
|
|
||||||
// Map 32 position results into one KPKBitbase[] entry
|
Color us;
|
||||||
for (int i = 0; i < IndexMax / 32; i++)
|
Square ksq[COLOR_NB], psq;
|
||||||
for (int j = 0; j < 32; j++)
|
Result result;
|
||||||
if (bb[32 * i + j] == RESULT_WIN || bb[32 * i + j] == RESULT_LOSS)
|
};
|
||||||
KPKBitbase[i] |= (1 << j);
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
bool Bitbases::probe(Square wksq, Square wpsq, Square bksq, Color us) {
|
||||||
|
|
||||||
|
assert(file_of(wpsq) <= FILE_D);
|
||||||
|
|
||||||
|
unsigned idx = index(us, bksq, wksq, wpsq);
|
||||||
|
return KPKBitbase[idx / 32] & (1 << (idx & 0x1F));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Bitbases::init() {
|
||||||
|
|
||||||
|
std::vector<KPKPosition> db(MAX_INDEX);
|
||||||
|
unsigned idx, repeat = 1;
|
||||||
|
|
||||||
|
// Initialize db with known win / draw positions
|
||||||
|
for (idx = 0; idx < MAX_INDEX; ++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).
|
||||||
|
while (repeat)
|
||||||
|
for (repeat = idx = 0; idx < MAX_INDEX; ++idx)
|
||||||
|
repeat |= (db[idx] == UNKNOWN && db[idx].classify(db) != UNKNOWN);
|
||||||
|
|
||||||
|
// Map 32 results into one KPKBitbase[] entry
|
||||||
|
for (idx = 0; idx < MAX_INDEX; ++idx)
|
||||||
|
if (db[idx] == WIN)
|
||||||
|
KPKBitbase[idx / 32] |= 1 << (idx & 0x1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// A KPK bitbase index is an integer in [0, IndexMax] range
|
KPKPosition::KPKPosition(unsigned idx) {
|
||||||
//
|
|
||||||
// Information is mapped in this way
|
|
||||||
//
|
|
||||||
// bit 0: side to move (WHITE or BLACK)
|
|
||||||
// bit 1- 6: black king square (from SQ_A1 to SQ_H8)
|
|
||||||
// bit 7-12: white king square (from SQ_A1 to SQ_H8)
|
|
||||||
// bit 13-14: white pawn file (from FILE_A to FILE_D)
|
|
||||||
// bit 15-17: white pawn rank - 1 (from RANK_2 - 1 to RANK_7 - 1)
|
|
||||||
|
|
||||||
int compute_index(Square wksq, Square bksq, Square wpsq, Color stm) {
|
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)));
|
||||||
|
|
||||||
assert(square_file(wpsq) <= FILE_D);
|
// Check if two pieces are on the same square or if a king can be captured
|
||||||
|
if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
|
||||||
|
|| ksq[WHITE] == psq
|
||||||
|
|| ksq[BLACK] == psq
|
||||||
|
|| (us == WHITE && (PawnAttacks[WHITE][psq] & ksq[BLACK])))
|
||||||
|
result = INVALID;
|
||||||
|
|
||||||
int p = int(square_file(wpsq)) + 4 * int(square_rank(wpsq) - 1);
|
// Immediate win if a pawn can be promoted without getting captured
|
||||||
int r = int(stm) + 2 * int(bksq) + 128 * int(wksq) + 8192 * p;
|
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;
|
||||||
|
|
||||||
assert(r >= 0 && r < IndexMax);
|
// Immediate draw if it is a stalemate or a king captures undefended pawn
|
||||||
|
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;
|
||||||
|
|
||||||
return r;
|
// Position will be classified later
|
||||||
}
|
|
||||||
|
|
||||||
void KPKPosition::from_index(int index) {
|
|
||||||
|
|
||||||
int s = (index / 8192) % 24;
|
|
||||||
|
|
||||||
sideToMove = Color(index % 2);
|
|
||||||
blackKingSquare = Square((index / 2) % 64);
|
|
||||||
whiteKingSquare = Square((index / 128) % 64);
|
|
||||||
pawnSquare = make_square(File(s % 4), Rank(s / 4 + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KPKPosition::is_legal() const {
|
|
||||||
|
|
||||||
if ( whiteKingSquare == pawnSquare
|
|
||||||
|| whiteKingSquare == blackKingSquare
|
|
||||||
|| blackKingSquare == pawnSquare)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (sideToMove == WHITE)
|
|
||||||
{
|
|
||||||
if ( bit_is_set(wk_attacks(), blackKingSquare)
|
|
||||||
|| bit_is_set(pawn_attacks(), blackKingSquare))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (bit_is_set(bk_attacks(), whiteKingSquare))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KPKPosition::is_immediate_draw() const {
|
|
||||||
|
|
||||||
if (sideToMove == BLACK)
|
|
||||||
{
|
|
||||||
Bitboard wka = wk_attacks();
|
|
||||||
Bitboard bka = bk_attacks();
|
|
||||||
|
|
||||||
// Case 1: Stalemate
|
|
||||||
if ((bka & ~(wka | pawn_attacks())) == EmptyBoardBB)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Case 2: King can capture pawn
|
|
||||||
if (bit_is_set(bka, pawnSquare) && !bit_is_set(wka, pawnSquare))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
result = UNKNOWN;
|
||||||
// Case 1: Stalemate (possible pawn files are only from A to D)
|
|
||||||
if ( whiteKingSquare == SQ_A8
|
|
||||||
&& pawnSquare == SQ_A7
|
|
||||||
&& (blackKingSquare == SQ_C7 || blackKingSquare == SQ_C8))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KPKPosition::is_immediate_win() const {
|
template<Color Us>
|
||||||
|
Result KPKPosition::classify(const std::vector<KPKPosition>& db) {
|
||||||
|
|
||||||
// The position is an immediate win if it is white to move and the
|
// White to move: If one move leads to a position classified as WIN, the result
|
||||||
// white pawn can be promoted without getting captured.
|
// of the current position is WIN. If all moves lead to positions classified
|
||||||
return sideToMove == WHITE
|
// as DRAW, the current position is classified as DRAW, otherwise the current
|
||||||
&& square_rank(pawnSquare) == RANK_7
|
// position is classified as UNKNOWN.
|
||||||
&& whiteKingSquare != pawnSquare + DELTA_N
|
//
|
||||||
&& ( square_distance(blackKingSquare, pawnSquare + DELTA_N) > 1
|
// Black to move: If one move leads to a position classified as DRAW, the result
|
||||||
|| bit_is_set(wk_attacks(), pawnSquare + DELTA_N));
|
// 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.
|
||||||
|
|
||||||
Result classify_wtm(const KPKPosition& pos, const Result bb[]) {
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
const Result Good = (Us == WHITE ? WIN : DRAW);
|
||||||
|
const Result Bad = (Us == WHITE ? DRAW : WIN);
|
||||||
|
|
||||||
// If one move leads to a position classified as RESULT_LOSS, the result
|
Result r = INVALID;
|
||||||
// of the current position is RESULT_WIN. If all moves lead to positions
|
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
||||||
// classified as RESULT_DRAW, the current position is classified RESULT_DRAW
|
|
||||||
// otherwise the current position is classified as RESULT_UNKNOWN.
|
|
||||||
|
|
||||||
bool unknownFound = false;
|
|
||||||
Bitboard b;
|
|
||||||
Square s;
|
|
||||||
Result r;
|
|
||||||
|
|
||||||
// King moves
|
|
||||||
b = pos.wk_attacks();
|
|
||||||
while (b)
|
while (b)
|
||||||
|
r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)]
|
||||||
|
: db[index(Them, pop_lsb(&b), ksq[Them] , psq)];
|
||||||
|
|
||||||
|
if (Us == WHITE)
|
||||||
{
|
{
|
||||||
s = pop_1st_bit(&b);
|
if (rank_of(psq) < RANK_7) // Single push
|
||||||
r = bb[compute_index(s, pos.blackKingSquare, pos.pawnSquare, BLACK)];
|
r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH)];
|
||||||
|
|
||||||
if (r == RESULT_LOSS)
|
if ( rank_of(psq) == RANK_2 // Double push
|
||||||
return RESULT_WIN;
|
&& psq + NORTH != ksq[Us]
|
||||||
|
&& psq + NORTH != ksq[Them])
|
||||||
if (r == RESULT_UNKNOWN)
|
r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH + NORTH)];
|
||||||
unknownFound = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pawn moves
|
return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad;
|
||||||
if (square_rank(pos.pawnSquare) < RANK_7)
|
|
||||||
{
|
|
||||||
s = pos.pawnSquare + DELTA_N;
|
|
||||||
r = bb[compute_index(pos.whiteKingSquare, pos.blackKingSquare, s, BLACK)];
|
|
||||||
|
|
||||||
if (r == RESULT_LOSS)
|
|
||||||
return RESULT_WIN;
|
|
||||||
|
|
||||||
if (r == RESULT_UNKNOWN)
|
|
||||||
unknownFound = true;
|
|
||||||
|
|
||||||
// Double pawn push
|
|
||||||
if ( square_rank(s) == RANK_3
|
|
||||||
&& s != pos.whiteKingSquare
|
|
||||||
&& s != pos.blackKingSquare)
|
|
||||||
{
|
|
||||||
s += DELTA_N;
|
|
||||||
r = bb[compute_index(pos.whiteKingSquare, pos.blackKingSquare, s, BLACK)];
|
|
||||||
|
|
||||||
if (r == RESULT_LOSS)
|
|
||||||
return RESULT_WIN;
|
|
||||||
|
|
||||||
if (r == RESULT_UNKNOWN)
|
|
||||||
unknownFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return unknownFound ? RESULT_UNKNOWN : RESULT_DRAW;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
Result classify_btm(const KPKPosition& pos, const Result bb[]) {
|
|
||||||
|
|
||||||
// If one move leads to a position classified as RESULT_DRAW, the result
|
|
||||||
// of the current position is RESULT_DRAW. If all moves lead to positions
|
|
||||||
// classified as RESULT_WIN, the current position is classified as
|
|
||||||
// RESULT_LOSS. Otherwise, the current position is classified as
|
|
||||||
// RESULT_UNKNOWN.
|
|
||||||
|
|
||||||
bool unknownFound = false;
|
|
||||||
Bitboard b;
|
|
||||||
Square s;
|
|
||||||
Result r;
|
|
||||||
|
|
||||||
// King moves
|
|
||||||
b = pos.bk_attacks();
|
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
s = pop_1st_bit(&b);
|
|
||||||
r = bb[compute_index(pos.whiteKingSquare, s, pos.pawnSquare, WHITE)];
|
|
||||||
|
|
||||||
if (r == RESULT_DRAW)
|
|
||||||
return RESULT_DRAW;
|
|
||||||
|
|
||||||
if (r == RESULT_UNKNOWN)
|
|
||||||
unknownFound = true;
|
|
||||||
}
|
|
||||||
return unknownFound ? RESULT_UNKNOWN : RESULT_LOSS;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
+260
-420
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,470 +18,309 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "bitcount.h"
|
#include "misc.h"
|
||||||
|
|
||||||
#if defined(IS_64BIT)
|
uint8_t PopCnt16[1 << 16];
|
||||||
|
int SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
|
|
||||||
const uint64_t BMult[64] = {
|
Bitboard SquareBB[SQUARE_NB];
|
||||||
0x0440049104032280ULL, 0x1021023C82008040ULL, 0x0404040082000048ULL,
|
Bitboard FileBB[FILE_NB];
|
||||||
0x48C4440084048090ULL, 0x2801104026490000ULL, 0x4100880442040800ULL,
|
Bitboard RankBB[RANK_NB];
|
||||||
0x0181011002E06040ULL, 0x9101004104200E00ULL, 0x1240848848310401ULL,
|
Bitboard AdjacentFilesBB[FILE_NB];
|
||||||
0x2000142828050024ULL, 0x00001004024D5000ULL, 0x0102044400800200ULL,
|
Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
|
||||||
0x8108108820112000ULL, 0xA880818210C00046ULL, 0x4008008801082000ULL,
|
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
||||||
0x0060882404049400ULL, 0x0104402004240810ULL, 0x000A002084250200ULL,
|
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||||
0x00100B0880801100ULL, 0x0004080201220101ULL, 0x0044008080A00000ULL,
|
Bitboard DistanceRingBB[SQUARE_NB][8];
|
||||||
0x0000202200842000ULL, 0x5006004882D00808ULL, 0x0000200045080802ULL,
|
Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
|
||||||
0x0086100020200601ULL, 0xA802080A20112C02ULL, 0x0080411218080900ULL,
|
Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
||||||
0x000200A0880080A0ULL, 0x9A01010000104000ULL, 0x0028008003100080ULL,
|
Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
||||||
0x0211021004480417ULL, 0x0401004188220806ULL, 0x00825051400C2006ULL,
|
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
||||||
0x00140C0210943000ULL, 0x0000242800300080ULL, 0x00C2208120080200ULL,
|
Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||||
0x2430008200002200ULL, 0x1010100112008040ULL, 0x8141050100020842ULL,
|
|
||||||
0x0000822081014405ULL, 0x800C049E40400804ULL, 0x4A0404028A000820ULL,
|
|
||||||
0x0022060201041200ULL, 0x0360904200840801ULL, 0x0881A08208800400ULL,
|
|
||||||
0x0060202C00400420ULL, 0x1204440086061400ULL, 0x0008184042804040ULL,
|
|
||||||
0x0064040315300400ULL, 0x0C01008801090A00ULL, 0x0808010401140C00ULL,
|
|
||||||
0x04004830C2020040ULL, 0x0080005002020054ULL, 0x40000C14481A0490ULL,
|
|
||||||
0x0010500101042048ULL, 0x1010100200424000ULL, 0x0000640901901040ULL,
|
|
||||||
0x00000A0201014840ULL, 0x00840082AA011002ULL, 0x010010840084240AULL,
|
|
||||||
0x0420400810420608ULL, 0x8D40230408102100ULL, 0x4A00200612222409ULL,
|
|
||||||
0x0A08520292120600ULL
|
|
||||||
};
|
|
||||||
|
|
||||||
const uint64_t RMult[64] = {
|
|
||||||
0x0A8002C000108020ULL, 0x4440200140003000ULL, 0x8080200010011880ULL,
|
|
||||||
0x0380180080141000ULL, 0x1A00060008211044ULL, 0x410001000A0C0008ULL,
|
|
||||||
0x9500060004008100ULL, 0x0100024284A20700ULL, 0x0000802140008000ULL,
|
|
||||||
0x0080C01002A00840ULL, 0x0402004282011020ULL, 0x9862000820420050ULL,
|
|
||||||
0x0001001448011100ULL, 0x6432800200800400ULL, 0x040100010002000CULL,
|
|
||||||
0x0002800D0010C080ULL, 0x90C0008000803042ULL, 0x4010004000200041ULL,
|
|
||||||
0x0003010010200040ULL, 0x0A40828028001000ULL, 0x0123010008000430ULL,
|
|
||||||
0x0024008004020080ULL, 0x0060040001104802ULL, 0x00582200028400D1ULL,
|
|
||||||
0x4000802080044000ULL, 0x0408208200420308ULL, 0x0610038080102000ULL,
|
|
||||||
0x3601000900100020ULL, 0x0000080080040180ULL, 0x00C2020080040080ULL,
|
|
||||||
0x0080084400100102ULL, 0x4022408200014401ULL, 0x0040052040800082ULL,
|
|
||||||
0x0B08200280804000ULL, 0x008A80A008801000ULL, 0x4000480080801000ULL,
|
|
||||||
0x0911808800801401ULL, 0x822A003002001894ULL, 0x401068091400108AULL,
|
|
||||||
0x000004A10A00004CULL, 0x2000800640008024ULL, 0x1486408102020020ULL,
|
|
||||||
0x000100A000D50041ULL, 0x00810050020B0020ULL, 0x0204000800808004ULL,
|
|
||||||
0x00020048100A000CULL, 0x0112000831020004ULL, 0x0009000040810002ULL,
|
|
||||||
0x0440490200208200ULL, 0x8910401000200040ULL, 0x6404200050008480ULL,
|
|
||||||
0x4B824A2010010100ULL, 0x04080801810C0080ULL, 0x00000400802A0080ULL,
|
|
||||||
0x8224080110026400ULL, 0x40002C4104088200ULL, 0x01002100104A0282ULL,
|
|
||||||
0x1208400811048021ULL, 0x3201014A40D02001ULL, 0x0005100019200501ULL,
|
|
||||||
0x0101000208001005ULL, 0x0002008450080702ULL, 0x001002080301D00CULL,
|
|
||||||
0x410201CE5C030092ULL
|
|
||||||
};
|
|
||||||
|
|
||||||
const int BShift[64] = {
|
|
||||||
58, 59, 59, 59, 59, 59, 59, 58, 59, 59, 59, 59, 59, 59, 59, 59,
|
|
||||||
59, 59, 57, 57, 57, 57, 59, 59, 59, 59, 57, 55, 55, 57, 59, 59,
|
|
||||||
59, 59, 57, 55, 55, 57, 59, 59, 59, 59, 57, 57, 57, 57, 59, 59,
|
|
||||||
59, 59, 59, 59, 59, 59, 59, 59, 58, 59, 59, 59, 59, 59, 59, 58
|
|
||||||
};
|
|
||||||
|
|
||||||
const int RShift[64] = {
|
|
||||||
52, 53, 53, 53, 53, 53, 53, 52, 53, 54, 54, 54, 54, 54, 54, 53,
|
|
||||||
53, 54, 54, 54, 54, 54, 54, 53, 53, 54, 54, 54, 54, 54, 54, 53,
|
|
||||||
53, 54, 54, 54, 54, 54, 54, 53, 53, 54, 54, 54, 54, 54, 54, 53,
|
|
||||||
53, 54, 54, 54, 54, 54, 54, 53, 52, 53, 53, 53, 53, 53, 53, 52
|
|
||||||
};
|
|
||||||
|
|
||||||
#else // if !defined(IS_64BIT)
|
|
||||||
|
|
||||||
const uint64_t BMult[64] = {
|
|
||||||
0x54142844C6A22981ULL, 0x710358A6EA25C19EULL, 0x704F746D63A4A8DCULL,
|
|
||||||
0xBFED1A0B80F838C5ULL, 0x90561D5631E62110ULL, 0x2804260376E60944ULL,
|
|
||||||
0x84A656409AA76871ULL, 0xF0267F64C28B6197ULL, 0x70764EBB762F0585ULL,
|
|
||||||
0x92AA09E0CFE161DEULL, 0x41EE1F6BB266F60EULL, 0xDDCBF04F6039C444ULL,
|
|
||||||
0x5A3FAB7BAC0D988AULL, 0xD3727877FA4EAA03ULL, 0xD988402D868DDAAEULL,
|
|
||||||
0x812B291AFA075C7CULL, 0x94FAF987B685A932ULL, 0x3ED867D8470D08DBULL,
|
|
||||||
0x92517660B8901DE8ULL, 0x2D97E43E058814B4ULL, 0x880A10C220B25582ULL,
|
|
||||||
0xC7C6520D1F1A0477ULL, 0xDBFC7FBCD7656AA6ULL, 0x78B1B9BFB1A2B84FULL,
|
|
||||||
0x2F20037F112A0BC1ULL, 0x657171EA2269A916ULL, 0xC08302B07142210EULL,
|
|
||||||
0x0880A4403064080BULL, 0x3602420842208C00ULL, 0x852800DC7E0B6602ULL,
|
|
||||||
0x595A3FBBAA0F03B2ULL, 0x9F01411558159D5EULL, 0x2B4A4A5F88B394F2ULL,
|
|
||||||
0x4AFCBFFC292DD03AULL, 0x4A4094A3B3F10522ULL, 0xB06F00B491F30048ULL,
|
|
||||||
0xD5B3820280D77004ULL, 0x8B2E01E7C8E57A75ULL, 0x2D342794E886C2E6ULL,
|
|
||||||
0xC302C410CDE21461ULL, 0x111F426F1379C274ULL, 0xE0569220ABB31588ULL,
|
|
||||||
0x5026D3064D453324ULL, 0xE2076040C343CD8AULL, 0x93EFD1E1738021EEULL,
|
|
||||||
0xB680804BED143132ULL, 0x44E361B21986944CULL, 0x44C60170EF5C598CULL,
|
|
||||||
0xF4DA475C195C9C94ULL, 0xA3AFBB5F72060B1DULL, 0xBC75F410E41C4FFCULL,
|
|
||||||
0xB51C099390520922ULL, 0x902C011F8F8EC368ULL, 0x950B56B3D6F5490AULL,
|
|
||||||
0x3909E0635BF202D0ULL, 0x5744F90206EC10CCULL, 0xDC59FD76317ABBC1ULL,
|
|
||||||
0x881C7C67FCBFC4F6ULL, 0x47CA41E7E440D423ULL, 0xEB0C88112048D004ULL,
|
|
||||||
0x51C60E04359AEF1AULL, 0x1AA1FE0E957A5554ULL, 0xDD9448DB4F5E3104ULL,
|
|
||||||
0xDC01F6DCA4BEBBDCULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
const uint64_t RMult[64] = {
|
|
||||||
0xD7445CDEC88002C0ULL, 0xD0A505C1F2001722ULL, 0xE065D1C896002182ULL,
|
|
||||||
0x9A8C41E75A000892ULL, 0x8900B10C89002AA8ULL, 0x9B28D1C1D60005A2ULL,
|
|
||||||
0x015D6C88DE002D9AULL, 0xB1DBFC802E8016A9ULL, 0x149A1042D9D60029ULL,
|
|
||||||
0xB9C08050599E002FULL, 0x132208C3AF300403ULL, 0xC1000CE2E9C50070ULL,
|
|
||||||
0x9D9AA13C99020012ULL, 0xB6B078DAF71E0046ULL, 0x9D880182FB6E002EULL,
|
|
||||||
0x52889F467E850037ULL, 0xDA6DC008D19A8480ULL, 0x468286034F902420ULL,
|
|
||||||
0x7140AC09DC54C020ULL, 0xD76FFFFA39548808ULL, 0xEA901C4141500808ULL,
|
|
||||||
0xC91004093F953A02ULL, 0x02882AFA8F6BB402ULL, 0xAEBE335692442C01ULL,
|
|
||||||
0x0E904A22079FB91EULL, 0x13A514851055F606ULL, 0x76C782018C8FE632ULL,
|
|
||||||
0x1DC012A9D116DA06ULL, 0x3C9E0037264FFFA6ULL, 0x2036002853C6E4A2ULL,
|
|
||||||
0xE3FE08500AFB47D4ULL, 0xF38AF25C86B025C2ULL, 0xC0800E2182CF9A40ULL,
|
|
||||||
0x72002480D1F60673ULL, 0x2500200BAE6E9B53ULL, 0xC60018C1EEFCA252ULL,
|
|
||||||
0x0600590473E3608AULL, 0x46002C4AB3FE51B2ULL, 0xA200011486BCC8D2ULL,
|
|
||||||
0xB680078095784C63ULL, 0x2742002639BF11AEULL, 0xC7D60021A5BDB142ULL,
|
|
||||||
0xC8C04016BB83D820ULL, 0xBD520028123B4842ULL, 0x9D1600344AC2A832ULL,
|
|
||||||
0x6A808005631C8A05ULL, 0x604600A148D5389AULL, 0xE2E40103D40DEA65ULL,
|
|
||||||
0x945B5A0087C62A81ULL, 0x012DC200CD82D28EULL, 0x2431C600B5F9EF76ULL,
|
|
||||||
0xFB142A006A9B314AULL, 0x06870E00A1C97D62ULL, 0x2A9DB2004A2689A2ULL,
|
|
||||||
0xD3594600CAF5D1A2ULL, 0xEE0E4900439344A7ULL, 0x89C4D266CA25007AULL,
|
|
||||||
0x3E0013A2743F97E3ULL, 0x0180E31A0431378AULL, 0x3A9E465A4D42A512ULL,
|
|
||||||
0x98D0A11A0C0D9CC2ULL, 0x8E711C1ABA19B01EULL, 0x8DCDC836DD201142ULL,
|
|
||||||
0x5AC08A4735370479ULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
const int BShift[64] = {
|
|
||||||
26, 27, 27, 27, 27, 27, 27, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
|
||||||
27, 27, 25, 25, 25, 25, 27, 27, 27, 27, 25, 23, 23, 25, 27, 27,
|
|
||||||
27, 27, 25, 23, 23, 25, 27, 27, 27, 27, 25, 25, 25, 25, 27, 27,
|
|
||||||
27, 27, 27, 27, 27, 27, 27, 27, 26, 27, 27, 27, 27, 27, 27, 26
|
|
||||||
};
|
|
||||||
|
|
||||||
const int RShift[64] = {
|
|
||||||
20, 21, 21, 21, 21, 21, 21, 20, 21, 22, 22, 22, 22, 22, 22, 21,
|
|
||||||
21, 22, 22, 22, 22, 22, 22, 21, 21, 22, 22, 22, 22, 22, 22, 21,
|
|
||||||
21, 22, 22, 22, 22, 22, 22, 21, 21, 22, 22, 22, 22, 22, 22, 21,
|
|
||||||
21, 22, 22, 22, 22, 22, 22, 21, 20, 21, 21, 21, 21, 21, 21, 20
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // defined(IS_64BIT)
|
|
||||||
|
|
||||||
// Global bitboards definitions with static storage duration are
|
|
||||||
// automatically set to zero before enter main().
|
|
||||||
Bitboard RMask[64];
|
|
||||||
int RAttackIndex[64];
|
|
||||||
Bitboard RAttacks[0x19000];
|
|
||||||
|
|
||||||
Bitboard BMask[64];
|
|
||||||
int BAttackIndex[64];
|
|
||||||
Bitboard BAttacks[0x1480];
|
|
||||||
|
|
||||||
Bitboard SetMaskBB[65];
|
|
||||||
Bitboard ClearMaskBB[65];
|
|
||||||
|
|
||||||
Bitboard SquaresByColorBB[2];
|
|
||||||
Bitboard FileBB[8];
|
|
||||||
Bitboard RankBB[8];
|
|
||||||
Bitboard NeighboringFilesBB[8];
|
|
||||||
Bitboard ThisAndNeighboringFilesBB[8];
|
|
||||||
Bitboard InFrontBB[2][8];
|
|
||||||
Bitboard StepAttacksBB[16][64];
|
|
||||||
Bitboard BetweenBB[64][64];
|
|
||||||
Bitboard SquaresInFrontMask[2][64];
|
|
||||||
Bitboard PassedPawnMask[2][64];
|
|
||||||
Bitboard AttackSpanMask[2][64];
|
|
||||||
|
|
||||||
Bitboard BishopPseudoAttacks[64];
|
|
||||||
Bitboard RookPseudoAttacks[64];
|
|
||||||
Bitboard QueenPseudoAttacks[64];
|
|
||||||
|
|
||||||
uint8_t BitCount8Bit[256];
|
|
||||||
|
|
||||||
|
Magic RookMagics[SQUARE_NB];
|
||||||
|
Magic BishopMagics[SQUARE_NB];
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void init_masks();
|
// De Bruijn sequences. See chessprogramming.wikispaces.com/BitScan
|
||||||
void init_step_attacks();
|
const uint64_t DeBruijn64 = 0x3F79D71B4CB0A89ULL;
|
||||||
void init_pseudo_attacks();
|
const uint32_t DeBruijn32 = 0x783A9B23;
|
||||||
void init_between_bitboards();
|
|
||||||
Bitboard index_to_bitboard(int index, Bitboard mask);
|
int MSBTable[256]; // To implement software msb()
|
||||||
Bitboard sliding_attacks(int sq, Bitboard occupied, int deltas[][2],
|
Square BSFTable[SQUARE_NB]; // To implement software bitscan
|
||||||
int fmin, int fmax, int rmin, int rmax);
|
Bitboard RookTable[0x19000]; // To store rook attacks
|
||||||
void init_sliding_attacks(Bitboard attacks[], int attackIndex[], Bitboard mask[],
|
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
||||||
const int shift[], const Bitboard mult[], int deltas[][2]);
|
|
||||||
|
void init_magics(Bitboard table[], Magic magics[], Direction directions[]);
|
||||||
|
|
||||||
|
// bsf_index() returns the index into BSFTable[] to look up the bitscan. Uses
|
||||||
|
// Matt Taylor's folding for 32 bit case, extended to 64 bit by Kim Walisch.
|
||||||
|
|
||||||
|
unsigned bsf_index(Bitboard b) {
|
||||||
|
b ^= b - 1;
|
||||||
|
return Is64Bit ? (b * DeBruijn64) >> 58
|
||||||
|
: ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn32) >> 26;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// popcount16() counts the non-zero bits using SWAR-Popcount algorithm
|
||||||
|
|
||||||
|
unsigned popcount16(unsigned u) {
|
||||||
|
u -= (u >> 1) & 0x5555U;
|
||||||
|
u = ((u >> 2) & 0x3333U) + (u & 0x3333U);
|
||||||
|
u = ((u >> 4) + u) & 0x0F0FU;
|
||||||
|
return (u * 0x0101U) >> 8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NO_BSF
|
||||||
|
|
||||||
/// print_bitboard() prints a bitboard in an easily readable format to the
|
/// Software fall-back of lsb() and msb() for CPU lacking hardware support
|
||||||
/// standard output. This is sometimes useful for debugging.
|
|
||||||
|
|
||||||
void print_bitboard(Bitboard b) {
|
Square lsb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
return BSFTable[bsf_index(b)];
|
||||||
|
}
|
||||||
|
|
||||||
for (Rank r = RANK_8; r >= RANK_1; r--)
|
Square msb(Bitboard b) {
|
||||||
|
|
||||||
|
assert(b);
|
||||||
|
unsigned b32;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
if (b > 0xFFFFFFFF)
|
||||||
{
|
{
|
||||||
std::cout << "+---+---+---+---+---+---+---+---+" << '\n';
|
b >>= 32;
|
||||||
for (File f = FILE_A; f <= FILE_H; f++)
|
result = 32;
|
||||||
std::cout << "| " << (bit_is_set(b, make_square(f, r)) ? 'X' : ' ') << ' ';
|
|
||||||
|
|
||||||
std::cout << "|\n";
|
|
||||||
}
|
}
|
||||||
std::cout << "+---+---+---+---+---+---+---+---+" << std::endl;
|
|
||||||
|
b32 = unsigned(b);
|
||||||
|
|
||||||
|
if (b32 > 0xFFFF)
|
||||||
|
{
|
||||||
|
b32 >>= 16;
|
||||||
|
result += 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b32 > 0xFF)
|
||||||
|
{
|
||||||
|
b32 >>= 8;
|
||||||
|
result += 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Square(result + MSBTable[b32]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ifdef NO_BSF
|
||||||
|
|
||||||
|
|
||||||
|
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
|
||||||
|
/// to be printed to standard output. Useful for debugging.
|
||||||
|
|
||||||
|
const std::string Bitboards::pretty(Bitboard b) {
|
||||||
|
|
||||||
|
std::string s = "+---+---+---+---+---+---+---+---+\n";
|
||||||
|
|
||||||
|
for (Rank r = RANK_8; r >= RANK_1; --r)
|
||||||
|
{
|
||||||
|
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||||
|
s += b & make_square(f, r) ? "| X " : "| ";
|
||||||
|
|
||||||
|
s += "|\n+---+---+---+---+---+---+---+---+\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
|
/// Bitboards::init() initializes various bitboard tables. It is called at
|
||||||
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
/// startup and relies on global objects to be already zero-initialized.
|
||||||
/// nonzero bitboard.
|
|
||||||
|
|
||||||
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
void Bitboards::init() {
|
||||||
|
|
||||||
static CACHE_LINE_ALIGNMENT
|
for (unsigned i = 0; i < (1 << 16); ++i)
|
||||||
const int BitTable[64] = {
|
PopCnt16[i] = (uint8_t) popcount16(i);
|
||||||
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26,
|
|
||||||
38, 15, 46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27,
|
|
||||||
33, 39, 16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61,
|
|
||||||
22, 43, 51, 60, 42, 59, 58
|
|
||||||
};
|
|
||||||
|
|
||||||
Square first_1(Bitboard b) {
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
return Square(BitTable[((b & -b) * 0x218a392cd3d5dbfULL) >> 58]);
|
{
|
||||||
|
SquareBB[s] = 1ULL << s;
|
||||||
|
BSFTable[bsf_index(SquareBB[s])] = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Bitboard b = 2; b < 256; ++b)
|
||||||
|
MSBTable[b] = MSBTable[b - 1] + !more_than_one(b);
|
||||||
|
|
||||||
|
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||||
|
FileBB[f] = f > FILE_A ? FileBB[f - 1] << 1 : FileABB;
|
||||||
|
|
||||||
|
for (Rank r = RANK_1; r <= RANK_8; ++r)
|
||||||
|
RankBB[r] = r > RANK_1 ? RankBB[r - 1] << 8 : Rank1BB;
|
||||||
|
|
||||||
|
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||||
|
AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0);
|
||||||
|
|
||||||
|
for (Rank r = RANK_1; r < RANK_8; ++r)
|
||||||
|
ForwardRanksBB[WHITE][r] = ~(ForwardRanksBB[BLACK][r + 1] = ForwardRanksBB[BLACK][r] | RankBB[r]);
|
||||||
|
|
||||||
|
for (Color c = WHITE; c <= BLACK; ++c)
|
||||||
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
|
{
|
||||||
|
ForwardFileBB [c][s] = ForwardRanksBB[c][rank_of(s)] & FileBB[file_of(s)];
|
||||||
|
PawnAttackSpan[c][s] = ForwardRanksBB[c][rank_of(s)] & AdjacentFilesBB[file_of(s)];
|
||||||
|
PassedPawnMask[c][s] = ForwardFileBB [c][s] | PawnAttackSpan[c][s];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||||
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||||
|
if (s1 != s2)
|
||||||
|
{
|
||||||
|
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
|
||||||
|
DistanceRingBB[s1][SquareDistance[s1][s2] - 1] |= s2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int steps[][5] = { {}, { 7, 9 }, { 6, 10, 15, 17 }, {}, {}, {}, { 1, 7, 8, 9 } };
|
||||||
|
|
||||||
|
for (Color c = WHITE; c <= BLACK; ++c)
|
||||||
|
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 + Direction(c == WHITE ? steps[pt][i] : -steps[pt][i]);
|
||||||
|
|
||||||
|
if (is_ok(to) && distance(s, to) < 3)
|
||||||
|
{
|
||||||
|
if (pt == PAWN)
|
||||||
|
PawnAttacks[c][s] |= to;
|
||||||
|
else
|
||||||
|
PseudoAttacks[pt][s] |= to;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
|
||||||
|
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
|
||||||
|
|
||||||
|
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 (PieceType pt : { BISHOP, ROOK })
|
||||||
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||||
|
{
|
||||||
|
if (!(PseudoAttacks[pt][s1] & s2))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
LineBB[s1][s2] = (attacks_bb(pt, s1, 0) & attacks_bb(pt, s2, 0)) | s1 | s2;
|
||||||
|
BetweenBB[s1][s2] = attacks_bb(pt, s1, SquareBB[s2]) & attacks_bb(pt, s2, SquareBB[s1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Square pop_1st_bit(Bitboard* b) {
|
|
||||||
Bitboard bb = *b;
|
|
||||||
*b &= (*b - 1);
|
|
||||||
return Square(BitTable[((bb & -bb) * 0x218a392cd3d5dbfULL) >> 58]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif !defined(USE_BSFQ)
|
|
||||||
|
|
||||||
static CACHE_LINE_ALIGNMENT
|
|
||||||
const int BitTable[64] = {
|
|
||||||
63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
|
|
||||||
51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5,
|
|
||||||
52, 26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38,
|
|
||||||
28, 58, 20, 37, 17, 36, 8
|
|
||||||
};
|
|
||||||
|
|
||||||
Square first_1(Bitboard b) {
|
|
||||||
|
|
||||||
b ^= (b - 1);
|
|
||||||
uint32_t fold = int(b) ^ int(b >> 32);
|
|
||||||
return Square(BitTable[(fold * 0x783a9b23) >> 26]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use type-punning
|
|
||||||
union b_union {
|
|
||||||
|
|
||||||
Bitboard b;
|
|
||||||
struct {
|
|
||||||
#if defined (BIGENDIAN)
|
|
||||||
uint32_t h;
|
|
||||||
uint32_t l;
|
|
||||||
#else
|
|
||||||
uint32_t l;
|
|
||||||
uint32_t h;
|
|
||||||
#endif
|
|
||||||
} dw;
|
|
||||||
};
|
|
||||||
|
|
||||||
Square pop_1st_bit(Bitboard* bb) {
|
|
||||||
|
|
||||||
b_union u;
|
|
||||||
Square ret;
|
|
||||||
|
|
||||||
u.b = *bb;
|
|
||||||
|
|
||||||
if (u.dw.l)
|
|
||||||
{
|
|
||||||
ret = Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
|
||||||
u.dw.l &= (u.dw.l - 1);
|
|
||||||
*bb = u.b;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
ret = Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
|
||||||
u.dw.h &= (u.dw.h - 1);
|
|
||||||
*bb = u.b;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(USE_BSFQ)
|
|
||||||
|
|
||||||
|
|
||||||
/// init_bitboards() initializes various bitboard arrays. It is called during
|
|
||||||
/// program initialization.
|
|
||||||
|
|
||||||
void init_bitboards() {
|
|
||||||
|
|
||||||
int rookDeltas[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
|
|
||||||
int bishopDeltas[4][2] = {{1,1},{-1,1},{1,-1},{-1,-1}};
|
|
||||||
|
|
||||||
init_masks();
|
|
||||||
init_step_attacks();
|
|
||||||
init_sliding_attacks(RAttacks, RAttackIndex, RMask, RShift, RMult, rookDeltas);
|
|
||||||
init_sliding_attacks(BAttacks, BAttackIndex, BMask, BShift, BMult, bishopDeltas);
|
|
||||||
init_pseudo_attacks();
|
|
||||||
init_between_bitboards();
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// All functions below are used to precompute various bitboards during
|
Bitboard sliding_attack(Direction directions[], Square sq, Bitboard occupied) {
|
||||||
// program initialization. Some of the functions may be difficult to
|
|
||||||
// understand, but they all seem to work correctly, and it should never
|
|
||||||
// be necessary to touch any of them.
|
|
||||||
|
|
||||||
void init_masks() {
|
Bitboard attack = 0;
|
||||||
|
|
||||||
SquaresByColorBB[DARK] = 0xAA55AA55AA55AA55ULL;
|
for (int i = 0; i < 4; ++i)
|
||||||
SquaresByColorBB[LIGHT] = ~SquaresByColorBB[DARK];
|
for (Square s = sq + directions[i];
|
||||||
|
is_ok(s) && distance(s, s - directions[i]) == 1;
|
||||||
FileBB[FILE_A] = FileABB;
|
s += directions[i])
|
||||||
RankBB[RANK_1] = Rank1BB;
|
|
||||||
|
|
||||||
for (int f = FILE_B; f <= FILE_H; f++)
|
|
||||||
{
|
|
||||||
FileBB[f] = FileBB[f - 1] << 1;
|
|
||||||
RankBB[f] = RankBB[f - 1] << 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int f = FILE_A; f <= FILE_H; f++)
|
|
||||||
{
|
|
||||||
NeighboringFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0);
|
|
||||||
ThisAndNeighboringFilesBB[f] = FileBB[f] | NeighboringFilesBB[f];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int rw = RANK_7, rb = RANK_2; rw >= RANK_1; rw--, rb++)
|
|
||||||
{
|
|
||||||
InFrontBB[WHITE][rw] = InFrontBB[WHITE][rw + 1] | RankBB[rw + 1];
|
|
||||||
InFrontBB[BLACK][rb] = InFrontBB[BLACK][rb - 1] | RankBB[rb - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
SetMaskBB[SQ_NONE] = EmptyBoardBB;
|
|
||||||
ClearMaskBB[SQ_NONE] = ~SetMaskBB[SQ_NONE];
|
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
|
||||||
{
|
|
||||||
SetMaskBB[s] = (1ULL << s);
|
|
||||||
ClearMaskBB[s] = ~SetMaskBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; c++)
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
|
||||||
{
|
{
|
||||||
SquaresInFrontMask[c][s] = in_front_bb(c, s) & file_bb(s);
|
attack |= s;
|
||||||
PassedPawnMask[c][s] = in_front_bb(c, s) & this_and_neighboring_files_bb(s);
|
|
||||||
AttackSpanMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Bitboard b = 0; b < 256; b++)
|
if (occupied & s)
|
||||||
BitCount8Bit[b] = (uint8_t)count_1s<CNT32>(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_step_attacks() {
|
|
||||||
|
|
||||||
const int step[][9] = {
|
|
||||||
{0},
|
|
||||||
{7,9,0}, {17,15,10,6,-6,-10,-15,-17,0}, {0}, {0}, {0},
|
|
||||||
{9,7,-7,-9,8,1,-1,-8,0}, {0}, {0},
|
|
||||||
{-7,-9,0}, {17,15,10,6,-6,-10,-15,-17,0}, {0}, {0}, {0},
|
|
||||||
{9,7,-7,-9,8,1,-1,-8,0}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
|
||||||
for (Piece pc = WP; pc <= BK; pc++)
|
|
||||||
for (int k = 0; step[pc][k] != 0; k++)
|
|
||||||
{
|
|
||||||
Square to = s + Square(step[pc][k]);
|
|
||||||
|
|
||||||
if (square_is_ok(to) && square_distance(s, to) < 3)
|
|
||||||
set_bit(&StepAttacksBB[pc][s], to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Bitboard sliding_attacks(int sq, Bitboard occupied, int deltas[][2],
|
|
||||||
int fmin, int fmax, int rmin, int rmax) {
|
|
||||||
int dx, dy, f, r;
|
|
||||||
int rk = sq / 8;
|
|
||||||
int fl = sq % 8;
|
|
||||||
Bitboard attacks = EmptyBoardBB;
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
dx = deltas[i][0];
|
|
||||||
dy = deltas[i][1];
|
|
||||||
f = fl + dx;
|
|
||||||
r = rk + dy;
|
|
||||||
|
|
||||||
while ( (dx == 0 || (f >= fmin && f <= fmax))
|
|
||||||
&& (dy == 0 || (r >= rmin && r <= rmax)))
|
|
||||||
{
|
|
||||||
attacks |= (1ULL << (f + r * 8));
|
|
||||||
|
|
||||||
if (occupied & (1ULL << (f + r * 8)))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
f += dx;
|
|
||||||
r += dy;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return attacks;
|
return attack;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitboard index_to_bitboard(int index, Bitboard mask) {
|
|
||||||
|
|
||||||
Bitboard result = EmptyBoardBB;
|
// init_magics() computes all rook and bishop attacks at startup. Magic
|
||||||
int sq, cnt = 0;
|
// bitboards are used to look up attacks of sliding pieces. As a reference see
|
||||||
|
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
|
||||||
|
// use the so called "fancy" approach.
|
||||||
|
|
||||||
while (mask)
|
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 epoch[4096] = {}, cnt = 0, size = 0;
|
||||||
|
|
||||||
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
sq = pop_1st_bit(&mask);
|
// Board edges are not considered in the relevant occupancies
|
||||||
|
edges = ((Rank1BB | Rank8BB) & ~rank_bb(s)) | ((FileABB | FileHBB) & ~file_bb(s));
|
||||||
|
|
||||||
if (index & (1 << cnt++))
|
// Given a square 's', the mask is the bitboard of sliding attacks from
|
||||||
result |= (1ULL << sq);
|
// 's' computed on an empty board. The index must be big enough to contain
|
||||||
}
|
// all the attacks for each possible subset of the mask and so is 2 power
|
||||||
return result;
|
// 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.
|
||||||
|
Magic& m = magics[s];
|
||||||
|
m.mask = sliding_attack(directions, s, 0) & ~edges;
|
||||||
|
m.shift = (Is64Bit ? 64 : 32) - popcount(m.mask);
|
||||||
|
|
||||||
void init_sliding_attacks(Bitboard attacks[], int attackIndex[], Bitboard mask[],
|
// Set the offset for the attacks table of the square. We have individual
|
||||||
const int shift[], const Bitboard mult[], int deltas[][2]) {
|
// table sizes for each square with "Fancy Magic Bitboards".
|
||||||
Bitboard b, v;
|
m.attacks = s == SQ_A1 ? table : magics[s - 1].attacks + size;
|
||||||
int i, j, index;
|
|
||||||
|
|
||||||
for (i = index = 0; i < 64; i++)
|
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and
|
||||||
{
|
// store the corresponding sliding attack bitboard in reference[].
|
||||||
attackIndex[i] = index;
|
b = size = 0;
|
||||||
mask[i] = sliding_attacks(i, 0, deltas, 1, 6, 1, 6);
|
do {
|
||||||
j = 1 << ((CpuIs64Bit ? 64 : 32) - shift[i]);
|
occupancy[size] = b;
|
||||||
|
reference[size] = sliding_attack(directions, s, b);
|
||||||
|
|
||||||
for (int k = 0; k < j; k++)
|
if (HasPext)
|
||||||
|
m.attacks[pext(b, m.mask)] = reference[size];
|
||||||
|
|
||||||
|
size++;
|
||||||
|
b = (b - m.mask) & m.mask;
|
||||||
|
} while (b);
|
||||||
|
|
||||||
|
if (HasPext)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PRNG rng(seeds[Is64Bit][rank_of(s)]);
|
||||||
|
|
||||||
|
// Find a magic for square 's' picking up an (almost) random number
|
||||||
|
// until we find the one that passes the verification test.
|
||||||
|
for (int i = 0; i < size; )
|
||||||
{
|
{
|
||||||
b = index_to_bitboard(k, mask[i]);
|
for (m.magic = 0; popcount((m.magic * m.mask) >> 56) < 6; )
|
||||||
v = CpuIs64Bit ? b * mult[i] : unsigned(b * mult[i] ^ (b >> 32) * (mult[i] >> 32));
|
m.magic = rng.sparse_rand<Bitboard>();
|
||||||
attacks[index + (v >> shift[i])] = sliding_attacks(i, b, deltas, 0, 7, 0, 7);
|
|
||||||
}
|
|
||||||
index += j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_pseudo_attacks() {
|
// A good magic must map every possible occupancy to an index that
|
||||||
|
// looks up the correct sliding attack in the attacks[s] database.
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
// Note that we build up the database for square 's' as a side
|
||||||
{
|
// effect of verifying the magic. Keep track of the attempt count
|
||||||
BishopPseudoAttacks[s] = bishop_attacks_bb(s, EmptyBoardBB);
|
// and save it in epoch[], little speed-up trick to avoid resetting
|
||||||
RookPseudoAttacks[s] = rook_attacks_bb(s, EmptyBoardBB);
|
// m.attacks[] after every failed attempt.
|
||||||
QueenPseudoAttacks[s] = queen_attacks_bb(s, EmptyBoardBB);
|
for (++cnt, i = 0; i < size; ++i)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_between_bitboards() {
|
|
||||||
|
|
||||||
Square s1, s2, s3, d;
|
|
||||||
int f, r;
|
|
||||||
|
|
||||||
for (s1 = SQ_A1; s1 <= SQ_H8; s1++)
|
|
||||||
for (s2 = SQ_A1; s2 <= SQ_H8; s2++)
|
|
||||||
if (bit_is_set(QueenPseudoAttacks[s1], s2))
|
|
||||||
{
|
{
|
||||||
f = file_distance(s1, s2);
|
unsigned idx = m.index(occupancy[i]);
|
||||||
r = rank_distance(s1, s2);
|
|
||||||
|
|
||||||
d = (s2 - s1) / Max(f, r);
|
if (epoch[idx] < cnt)
|
||||||
|
{
|
||||||
for (s3 = s1 + d; s3 != s2; s3 += d)
|
epoch[idx] = cnt;
|
||||||
set_bit(&(BetweenBB[s1][s2]), s3);
|
m.attacks[idx] = reference[i];
|
||||||
|
}
|
||||||
|
else if (m.attacks[idx] != reference[i])
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+222
-178
@@ -1,14 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
@@ -18,12 +18,29 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(BITBOARD_H_INCLUDED)
|
#ifndef BITBOARD_H_INCLUDED
|
||||||
#define BITBOARD_H_INCLUDED
|
#define BITBOARD_H_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
const Bitboard EmptyBoardBB = 0;
|
namespace Bitbases {
|
||||||
|
|
||||||
|
void init();
|
||||||
|
bool probe(Square wksq, Square wpsq, Square bksq, Color us);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Bitboards {
|
||||||
|
|
||||||
|
void init();
|
||||||
|
const std::string pretty(Bitboard b);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const Bitboard AllSquares = ~Bitboard(0);
|
||||||
|
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
const Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
const Bitboard FileBBB = FileABB << 1;
|
const Bitboard FileBBB = FileABB << 1;
|
||||||
@@ -43,79 +60,85 @@ const Bitboard Rank6BB = Rank1BB << (8 * 5);
|
|||||||
const Bitboard Rank7BB = Rank1BB << (8 * 6);
|
const Bitboard Rank7BB = Rank1BB << (8 * 6);
|
||||||
const Bitboard Rank8BB = Rank1BB << (8 * 7);
|
const Bitboard Rank8BB = Rank1BB << (8 * 7);
|
||||||
|
|
||||||
extern Bitboard SquaresByColorBB[2];
|
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
extern Bitboard FileBB[8];
|
|
||||||
extern Bitboard NeighboringFilesBB[8];
|
|
||||||
extern Bitboard ThisAndNeighboringFilesBB[8];
|
|
||||||
extern Bitboard RankBB[8];
|
|
||||||
extern Bitboard InFrontBB[2][8];
|
|
||||||
|
|
||||||
extern Bitboard SetMaskBB[65];
|
extern Bitboard SquareBB[SQUARE_NB];
|
||||||
extern Bitboard ClearMaskBB[65];
|
extern Bitboard FileBB[FILE_NB];
|
||||||
|
extern Bitboard RankBB[RANK_NB];
|
||||||
extern Bitboard StepAttacksBB[16][64];
|
extern Bitboard AdjacentFilesBB[FILE_NB];
|
||||||
extern Bitboard BetweenBB[64][64];
|
extern Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
|
||||||
|
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
||||||
extern Bitboard SquaresInFrontMask[2][64];
|
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||||
extern Bitboard PassedPawnMask[2][64];
|
extern Bitboard DistanceRingBB[SQUARE_NB][8];
|
||||||
extern Bitboard AttackSpanMask[2][64];
|
extern Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
|
||||||
|
extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
||||||
extern const uint64_t RMult[64];
|
extern Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
||||||
extern const int RShift[64];
|
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
||||||
extern Bitboard RMask[64];
|
extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||||
extern int RAttackIndex[64];
|
|
||||||
extern Bitboard RAttacks[0x19000];
|
|
||||||
|
|
||||||
extern const uint64_t BMult[64];
|
|
||||||
extern const int BShift[64];
|
|
||||||
extern Bitboard BMask[64];
|
|
||||||
extern int BAttackIndex[64];
|
|
||||||
extern Bitboard BAttacks[0x1480];
|
|
||||||
|
|
||||||
extern Bitboard BishopPseudoAttacks[64];
|
|
||||||
extern Bitboard RookPseudoAttacks[64];
|
|
||||||
extern Bitboard QueenPseudoAttacks[64];
|
|
||||||
|
|
||||||
extern uint8_t BitCount8Bit[256];
|
|
||||||
|
|
||||||
|
|
||||||
/// Functions for testing whether a given bit is set in a bitboard, and for
|
/// Magic holds all magic bitboards relevant data for a single square
|
||||||
/// setting and clearing bits.
|
struct Magic {
|
||||||
|
Bitboard mask;
|
||||||
|
Bitboard magic;
|
||||||
|
Bitboard* attacks;
|
||||||
|
unsigned shift;
|
||||||
|
|
||||||
inline Bitboard bit_is_set(Bitboard b, Square s) {
|
// Compute the attack's index using the 'magic bitboards' approach
|
||||||
return b & SetMaskBB[s];
|
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) {
|
||||||
|
return b & SquareBB[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void set_bit(Bitboard *b, Square s) {
|
inline Bitboard operator|(Bitboard b, Square s) {
|
||||||
*b |= SetMaskBB[s];
|
return b | SquareBB[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void clear_bit(Bitboard *b, Square s) {
|
inline Bitboard operator^(Bitboard b, Square s) {
|
||||||
*b &= ClearMaskBB[s];
|
return b ^ SquareBB[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Bitboard& operator|=(Bitboard& b, Square s) {
|
||||||
/// Functions used to update a bitboard after a move. This is faster
|
return b |= SquareBB[s];
|
||||||
/// then calling a sequence of clear_bit() + set_bit()
|
|
||||||
|
|
||||||
inline Bitboard make_move_bb(Square from, Square to) {
|
|
||||||
return SetMaskBB[from] | SetMaskBB[to];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void do_move_bb(Bitboard *b, Bitboard move_bb) {
|
inline Bitboard& operator^=(Bitboard& b, Square s) {
|
||||||
*b ^= move_bb;
|
return b ^= SquareBB[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr bool more_than_one(Bitboard b) {
|
||||||
|
return b & (b - 1);
|
||||||
|
}
|
||||||
|
|
||||||
/// rank_bb() and file_bb() take a file or a square as input and return
|
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
||||||
/// a bitboard representing all squares on the given file or rank.
|
/// the given file or rank.
|
||||||
|
|
||||||
inline Bitboard rank_bb(Rank r) {
|
inline Bitboard rank_bb(Rank r) {
|
||||||
return RankBB[r];
|
return RankBB[r];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard rank_bb(Square s) {
|
inline Bitboard rank_bb(Square s) {
|
||||||
return RankBB[square_rank(s)];
|
return RankBB[rank_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard file_bb(File f) {
|
inline Bitboard file_bb(File f) {
|
||||||
@@ -123,173 +146,194 @@ inline Bitboard file_bb(File f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard file_bb(Square s) {
|
inline Bitboard file_bb(Square s) {
|
||||||
return FileBB[square_file(s)];
|
return FileBB[file_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// neighboring_files_bb takes a file or a square as input and returns a
|
/// shift() moves a bitboard one step along direction D. Mainly for pawns
|
||||||
/// bitboard representing all squares on the neighboring files.
|
|
||||||
|
|
||||||
inline Bitboard neighboring_files_bb(File f) {
|
template<Direction D>
|
||||||
return NeighboringFilesBB[f];
|
constexpr Bitboard shift(Bitboard b) {
|
||||||
}
|
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
|
||||||
|
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7
|
||||||
inline Bitboard neighboring_files_bb(Square s) {
|
: D == NORTH_WEST ? (b & ~FileABB) << 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
|
||||||
return NeighboringFilesBB[square_file(s)];
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// this_and_neighboring_files_bb takes a file or a square as input and returns
|
/// adjacent_files_bb() returns a bitboard representing all the squares on the
|
||||||
/// a bitboard representing all squares on the given and neighboring files.
|
/// adjacent files of the given one.
|
||||||
|
|
||||||
inline Bitboard this_and_neighboring_files_bb(File f) {
|
inline Bitboard adjacent_files_bb(File f) {
|
||||||
return ThisAndNeighboringFilesBB[f];
|
return AdjacentFilesBB[f];
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard this_and_neighboring_files_bb(Square s) {
|
|
||||||
return ThisAndNeighboringFilesBB[square_file(s)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// in_front_bb() takes a color and a rank or square as input, and returns a
|
/// between_bb() returns a bitboard representing all the squares between the two
|
||||||
/// bitboard representing all the squares on all ranks in front of the rank
|
/// given ones. For instance, between_bb(SQ_C4, SQ_F7) returns a bitboard with
|
||||||
/// (or square), from the given color's point of view. For instance,
|
/// the bits for square d5 and e6 set. If s1 and s2 are not on the same rank, file
|
||||||
/// in_front_bb(WHITE, RANK_5) will give all squares on ranks 6, 7 and 8, while
|
/// or diagonal, 0 is returned.
|
||||||
/// in_front_bb(BLACK, SQ_D3) will give all squares on ranks 1 and 2.
|
|
||||||
|
|
||||||
inline Bitboard in_front_bb(Color c, Rank r) {
|
inline Bitboard between_bb(Square s1, Square s2) {
|
||||||
return InFrontBB[c][r];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard in_front_bb(Color c, Square s) {
|
|
||||||
return InFrontBB[c][square_rank(s)];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Functions for computing sliding attack bitboards. rook_attacks_bb(),
|
|
||||||
/// bishop_attacks_bb() and queen_attacks_bb() all take a square and a
|
|
||||||
/// bitboard of occupied squares as input, and return a bitboard representing
|
|
||||||
/// all squares attacked by a rook, bishop or queen on the given square.
|
|
||||||
|
|
||||||
#if defined(IS_64BIT)
|
|
||||||
|
|
||||||
inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
Bitboard b = blockers & RMask[s];
|
|
||||||
return RAttacks[RAttackIndex[s] + ((b * RMult[s]) >> RShift[s])];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
Bitboard b = blockers & BMask[s];
|
|
||||||
return BAttacks[BAttackIndex[s] + ((b * BMult[s]) >> BShift[s])];
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // if !defined(IS_64BIT)
|
|
||||||
|
|
||||||
inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
Bitboard b = blockers & RMask[s];
|
|
||||||
return RAttacks[RAttackIndex[s] +
|
|
||||||
(unsigned(int(b) * int(RMult[s]) ^ int(b >> 32) * int(RMult[s] >> 32)) >> RShift[s])];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
Bitboard b = blockers & BMask[s];
|
|
||||||
return BAttacks[BAttackIndex[s] +
|
|
||||||
(unsigned(int(b) * int(BMult[s]) ^ int(b >> 32) * int(BMult[s] >> 32)) >> BShift[s])];
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
inline Bitboard queen_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
return rook_attacks_bb(s, blockers) | bishop_attacks_bb(s, blockers);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// squares_between returns a bitboard representing all squares between
|
|
||||||
/// two squares. For instance, squares_between(SQ_C4, SQ_F7) returns a
|
|
||||||
/// bitboard with the bits for square d5 and e6 set. If s1 and s2 are not
|
|
||||||
/// on the same line, file or diagonal, EmptyBoardBB is returned.
|
|
||||||
|
|
||||||
inline Bitboard squares_between(Square s1, Square s2) {
|
|
||||||
return BetweenBB[s1][s2];
|
return BetweenBB[s1][s2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// squares_in_front_of takes a color and a square as input, and returns a
|
/// forward_ranks_bb() returns a bitboard representing all the squares on all the ranks
|
||||||
/// bitboard representing all squares along the line in front of the square,
|
/// in front of the given one, from the point of view of the given color. For
|
||||||
/// from the point of view of the given color. Definition of the table is:
|
/// instance, forward_ranks_bb(BLACK, SQ_D3) will return the 16 squares on ranks 1 and 2.
|
||||||
/// SquaresInFrontOf[c][s] = in_front_bb(c, s) & file_bb(s)
|
|
||||||
|
|
||||||
inline Bitboard squares_in_front_of(Color c, Square s) {
|
inline Bitboard forward_ranks_bb(Color c, Square s) {
|
||||||
return SquaresInFrontMask[c][s];
|
return ForwardRanksBB[c][rank_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// passed_pawn_mask takes a color and a square as input, and returns a
|
/// forward_file_bb() returns a bitboard representing all the squares along the line
|
||||||
/// bitboard mask which can be used to test if a pawn of the given color on
|
/// in front of the given one, from the point of view of the given color:
|
||||||
/// the given square is a passed pawn. Definition of the table is:
|
/// ForwardFileBB[c][s] = forward_ranks_bb(c, s) & file_bb(s)
|
||||||
/// PassedPawnMask[c][s] = in_front_bb(c, s) & this_and_neighboring_files_bb(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] = forward_ranks_bb(c, s) & adjacent_files_bb(file_of(s));
|
||||||
|
|
||||||
|
inline Bitboard pawn_attack_span(Color c, Square s) {
|
||||||
|
return PawnAttackSpan[c][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_file_bb(c, s)
|
||||||
|
|
||||||
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
||||||
return PassedPawnMask[c][s];
|
return PassedPawnMask[c][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// attack_span_mask takes a color and a square as input, and returns a bitboard
|
/// aligned() returns true if the squares s1, s2 and s3 are aligned either on a
|
||||||
/// representing all squares that can be attacked by a pawn of the given color
|
/// straight or on a diagonal line.
|
||||||
/// when it moves along its file starting from the given square. Definition is:
|
|
||||||
/// AttackSpanMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
|
||||||
|
|
||||||
inline Bitboard attack_span_mask(Color c, Square s) {
|
inline bool aligned(Square s1, Square s2, Square s3) {
|
||||||
return AttackSpanMask[c][s];
|
return LineBB[s1][s2] & s3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// squares_aligned returns true if the squares s1, s2 and s3 are aligned
|
/// distance() functions return the distance between x and y, defined as the
|
||||||
/// either on a straight or on a diagonal line.
|
/// number of steps for a king in x to reach y. Works with squares, ranks, files.
|
||||||
|
|
||||||
inline bool squares_aligned(Square s1, Square s2, Square s3) {
|
template<typename T> inline int distance(T x, T y) { return x < y ? y - x : x - y; }
|
||||||
return (BetweenBB[s1][s2] | BetweenBB[s1][s3] | BetweenBB[s2][s3])
|
template<> inline int distance<Square>(Square x, Square y) { return SquareDistance[x][y]; }
|
||||||
& ((1ULL << s1) | (1ULL << s2) | (1ULL << s3));
|
|
||||||
|
template<typename T1, typename T2> inline int distance(T2 x, T2 y);
|
||||||
|
template<> inline int distance<File>(Square x, Square y) { return distance(file_of(x), file_of(y)); }
|
||||||
|
template<> inline int distance<Rank>(Square x, Square y) { return distance(rank_of(x), rank_of(y)); }
|
||||||
|
|
||||||
|
|
||||||
|
/// attacks_bb() returns a bitboard representing all the squares attacked by a
|
||||||
|
/// piece of type Pt (bishop or rook) placed on 's'.
|
||||||
|
|
||||||
|
template<PieceType Pt>
|
||||||
|
inline Bitboard attacks_bb(Square s, Bitboard occupied) {
|
||||||
|
|
||||||
|
const Magic& m = Pt == ROOK ? RookMagics[s] : BishopMagics[s];
|
||||||
|
return m.attacks[m.index(occupied)];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Bitboard attacks_bb(PieceType pt, Square s, Bitboard occupied) {
|
||||||
|
|
||||||
|
assert(pt != PAWN);
|
||||||
|
|
||||||
|
switch (pt)
|
||||||
|
{
|
||||||
|
case BISHOP: return attacks_bb<BISHOP>(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 PseudoAttacks[pt][s];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
|
/// popcount() counts the number of non-zero bits in a bitboard
|
||||||
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
|
||||||
/// nonzero bitboard.
|
|
||||||
|
|
||||||
#if defined(USE_BSFQ)
|
inline int popcount(Bitboard b) {
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
|
#ifndef USE_POPCNT
|
||||||
|
|
||||||
FORCE_INLINE Square first_1(Bitboard b) {
|
extern uint8_t PopCnt16[1 << 16];
|
||||||
unsigned long index;
|
union { Bitboard bb; uint16_t u[4]; } v = { b };
|
||||||
_BitScanForward64(&index, b);
|
return PopCnt16[v.u[0]] + PopCnt16[v.u[1]] + PopCnt16[v.u[2]] + PopCnt16[v.u[3]];
|
||||||
return (Square) index;
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
|
||||||
|
inline Square lsb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
return Square(__builtin_ctzll(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Square msb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
return Square(63 ^ __builtin_clzll(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(_WIN64) && defined(_MSC_VER)
|
||||||
|
|
||||||
|
inline Square lsb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
unsigned long idx;
|
||||||
|
_BitScanForward64(&idx, b);
|
||||||
|
return (Square) idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Square msb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
unsigned long idx;
|
||||||
|
_BitScanReverse64(&idx, b);
|
||||||
|
return (Square) idx;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
FORCE_INLINE Square first_1(Bitboard b) { // Assembly code by Heinz van Saanen
|
#define NO_BSF // Fallback on software implementation for other cases
|
||||||
Bitboard dummy;
|
|
||||||
__asm__("bsfq %1, %0": "=r"(dummy): "rm"(b) );
|
Square lsb(Bitboard b);
|
||||||
return (Square) dummy;
|
Square msb(Bitboard b);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FORCE_INLINE Square pop_1st_bit(Bitboard* b) {
|
|
||||||
const Square s = first_1(*b);
|
/// pop_lsb() finds and clears the least significant bit in a non-zero bitboard
|
||||||
*b &= ~(1ULL<<s);
|
|
||||||
|
inline Square pop_lsb(Bitboard* b) {
|
||||||
|
const Square s = lsb(*b);
|
||||||
|
*b &= *b - 1;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // if !defined(USE_BSFQ)
|
|
||||||
|
|
||||||
extern Square first_1(Bitboard b);
|
/// frontmost_sq() and backmost_sq() return the square corresponding to the
|
||||||
extern Square pop_1st_bit(Bitboard* b);
|
/// most/least advanced bit relative to the given color.
|
||||||
|
|
||||||
#endif
|
inline Square frontmost_sq(Color c, Bitboard b) { return c == WHITE ? msb(b) : lsb(b); }
|
||||||
|
inline Square backmost_sq(Color c, Bitboard b) { return c == WHITE ? lsb(b) : msb(b); }
|
||||||
|
|
||||||
|
#endif // #ifndef BITBOARD_H_INCLUDED
|
||||||
extern void print_bitboard(Bitboard b);
|
|
||||||
extern void init_bitboards();
|
|
||||||
|
|
||||||
#endif // !defined(BITBOARD_H_INCLUDED)
|
|
||||||
|
|||||||
@@ -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-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(BITCOUNT_H_INCLUDED)
|
|
||||||
#define BITCOUNT_H_INCLUDED
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
enum BitCountType {
|
|
||||||
CNT64,
|
|
||||||
CNT64_MAX15,
|
|
||||||
CNT32,
|
|
||||||
CNT32_MAX15,
|
|
||||||
CNT_POPCNT
|
|
||||||
};
|
|
||||||
|
|
||||||
/// count_1s() counts the number of nonzero bits in a bitboard.
|
|
||||||
/// We have different optimized versions according if platform
|
|
||||||
/// is 32 or 64 bits, and to the maximum number of nonzero bits.
|
|
||||||
/// We also support hardware popcnt instruction. See Readme.txt
|
|
||||||
/// on how to pgo compile with popcnt support.
|
|
||||||
template<BitCountType> inline int count_1s(Bitboard);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int count_1s<CNT64>(Bitboard b) {
|
|
||||||
b -= ((b>>1) & 0x5555555555555555ULL);
|
|
||||||
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
|
||||||
b = ((b>>4) + b) & 0x0F0F0F0F0F0F0F0FULL;
|
|
||||||
b *= 0x0101010101010101ULL;
|
|
||||||
return int(b >> 56);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int count_1s<CNT64_MAX15>(Bitboard b) {
|
|
||||||
b -= (b>>1) & 0x5555555555555555ULL;
|
|
||||||
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
|
||||||
b *= 0x1111111111111111ULL;
|
|
||||||
return int(b >> 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int count_1s<CNT32>(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) & 0x0F0F0F0F; // 0-8 in 8 bits
|
|
||||||
v += (((w >> 4) + w) & 0x0F0F0F0F); // 0-16 in 8 bits
|
|
||||||
v *= 0x01010101; // mul is fast on amd procs
|
|
||||||
return int(v >> 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int count_1s<CNT32_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);
|
|
||||||
v += w; // 0-8 in 4 bits
|
|
||||||
v *= 0x11111111;
|
|
||||||
return int(v >> 28);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int count_1s<CNT_POPCNT>(Bitboard b) {
|
|
||||||
#if !defined(USE_POPCNT)
|
|
||||||
return int(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);
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
unsigned long ret;
|
|
||||||
__asm__("popcnt %1, %0" : "=r" (ret) : "r" (b));
|
|
||||||
return ret;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(BITCOUNT_H_INCLUDED)
|
|
||||||
-525
@@ -1,525 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
The code in this file is based on the opening book code in PolyGlot
|
|
||||||
by Fabien Letouzey. PolyGlot is available under the GNU General
|
|
||||||
Public License, and can be downloaded from http://wbec-ridderkerk.nl
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "book.h"
|
|
||||||
#include "movegen.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// Random numbers from PolyGlot, used to compute book hash keys
|
|
||||||
const uint64_t Random64[781] = {
|
|
||||||
0x9D39247E33776D41ULL, 0x2AF7398005AAA5C7ULL, 0x44DB015024623547ULL,
|
|
||||||
0x9C15F73E62A76AE2ULL, 0x75834465489C0C89ULL, 0x3290AC3A203001BFULL,
|
|
||||||
0x0FBBAD1F61042279ULL, 0xE83A908FF2FB60CAULL, 0x0D7E765D58755C10ULL,
|
|
||||||
0x1A083822CEAFE02DULL, 0x9605D5F0E25EC3B0ULL, 0xD021FF5CD13A2ED5ULL,
|
|
||||||
0x40BDF15D4A672E32ULL, 0x011355146FD56395ULL, 0x5DB4832046F3D9E5ULL,
|
|
||||||
0x239F8B2D7FF719CCULL, 0x05D1A1AE85B49AA1ULL, 0x679F848F6E8FC971ULL,
|
|
||||||
0x7449BBFF801FED0BULL, 0x7D11CDB1C3B7ADF0ULL, 0x82C7709E781EB7CCULL,
|
|
||||||
0xF3218F1C9510786CULL, 0x331478F3AF51BBE6ULL, 0x4BB38DE5E7219443ULL,
|
|
||||||
0xAA649C6EBCFD50FCULL, 0x8DBD98A352AFD40BULL, 0x87D2074B81D79217ULL,
|
|
||||||
0x19F3C751D3E92AE1ULL, 0xB4AB30F062B19ABFULL, 0x7B0500AC42047AC4ULL,
|
|
||||||
0xC9452CA81A09D85DULL, 0x24AA6C514DA27500ULL, 0x4C9F34427501B447ULL,
|
|
||||||
0x14A68FD73C910841ULL, 0xA71B9B83461CBD93ULL, 0x03488B95B0F1850FULL,
|
|
||||||
0x637B2B34FF93C040ULL, 0x09D1BC9A3DD90A94ULL, 0x3575668334A1DD3BULL,
|
|
||||||
0x735E2B97A4C45A23ULL, 0x18727070F1BD400BULL, 0x1FCBACD259BF02E7ULL,
|
|
||||||
0xD310A7C2CE9B6555ULL, 0xBF983FE0FE5D8244ULL, 0x9F74D14F7454A824ULL,
|
|
||||||
0x51EBDC4AB9BA3035ULL, 0x5C82C505DB9AB0FAULL, 0xFCF7FE8A3430B241ULL,
|
|
||||||
0x3253A729B9BA3DDEULL, 0x8C74C368081B3075ULL, 0xB9BC6C87167C33E7ULL,
|
|
||||||
0x7EF48F2B83024E20ULL, 0x11D505D4C351BD7FULL, 0x6568FCA92C76A243ULL,
|
|
||||||
0x4DE0B0F40F32A7B8ULL, 0x96D693460CC37E5DULL, 0x42E240CB63689F2FULL,
|
|
||||||
0x6D2BDCDAE2919661ULL, 0x42880B0236E4D951ULL, 0x5F0F4A5898171BB6ULL,
|
|
||||||
0x39F890F579F92F88ULL, 0x93C5B5F47356388BULL, 0x63DC359D8D231B78ULL,
|
|
||||||
0xEC16CA8AEA98AD76ULL, 0x5355F900C2A82DC7ULL, 0x07FB9F855A997142ULL,
|
|
||||||
0x5093417AA8A7ED5EULL, 0x7BCBC38DA25A7F3CULL, 0x19FC8A768CF4B6D4ULL,
|
|
||||||
0x637A7780DECFC0D9ULL, 0x8249A47AEE0E41F7ULL, 0x79AD695501E7D1E8ULL,
|
|
||||||
0x14ACBAF4777D5776ULL, 0xF145B6BECCDEA195ULL, 0xDABF2AC8201752FCULL,
|
|
||||||
0x24C3C94DF9C8D3F6ULL, 0xBB6E2924F03912EAULL, 0x0CE26C0B95C980D9ULL,
|
|
||||||
0xA49CD132BFBF7CC4ULL, 0xE99D662AF4243939ULL, 0x27E6AD7891165C3FULL,
|
|
||||||
0x8535F040B9744FF1ULL, 0x54B3F4FA5F40D873ULL, 0x72B12C32127FED2BULL,
|
|
||||||
0xEE954D3C7B411F47ULL, 0x9A85AC909A24EAA1ULL, 0x70AC4CD9F04F21F5ULL,
|
|
||||||
0xF9B89D3E99A075C2ULL, 0x87B3E2B2B5C907B1ULL, 0xA366E5B8C54F48B8ULL,
|
|
||||||
0xAE4A9346CC3F7CF2ULL, 0x1920C04D47267BBDULL, 0x87BF02C6B49E2AE9ULL,
|
|
||||||
0x092237AC237F3859ULL, 0xFF07F64EF8ED14D0ULL, 0x8DE8DCA9F03CC54EULL,
|
|
||||||
0x9C1633264DB49C89ULL, 0xB3F22C3D0B0B38EDULL, 0x390E5FB44D01144BULL,
|
|
||||||
0x5BFEA5B4712768E9ULL, 0x1E1032911FA78984ULL, 0x9A74ACB964E78CB3ULL,
|
|
||||||
0x4F80F7A035DAFB04ULL, 0x6304D09A0B3738C4ULL, 0x2171E64683023A08ULL,
|
|
||||||
0x5B9B63EB9CEFF80CULL, 0x506AACF489889342ULL, 0x1881AFC9A3A701D6ULL,
|
|
||||||
0x6503080440750644ULL, 0xDFD395339CDBF4A7ULL, 0xEF927DBCF00C20F2ULL,
|
|
||||||
0x7B32F7D1E03680ECULL, 0xB9FD7620E7316243ULL, 0x05A7E8A57DB91B77ULL,
|
|
||||||
0xB5889C6E15630A75ULL, 0x4A750A09CE9573F7ULL, 0xCF464CEC899A2F8AULL,
|
|
||||||
0xF538639CE705B824ULL, 0x3C79A0FF5580EF7FULL, 0xEDE6C87F8477609DULL,
|
|
||||||
0x799E81F05BC93F31ULL, 0x86536B8CF3428A8CULL, 0x97D7374C60087B73ULL,
|
|
||||||
0xA246637CFF328532ULL, 0x043FCAE60CC0EBA0ULL, 0x920E449535DD359EULL,
|
|
||||||
0x70EB093B15B290CCULL, 0x73A1921916591CBDULL, 0x56436C9FE1A1AA8DULL,
|
|
||||||
0xEFAC4B70633B8F81ULL, 0xBB215798D45DF7AFULL, 0x45F20042F24F1768ULL,
|
|
||||||
0x930F80F4E8EB7462ULL, 0xFF6712FFCFD75EA1ULL, 0xAE623FD67468AA70ULL,
|
|
||||||
0xDD2C5BC84BC8D8FCULL, 0x7EED120D54CF2DD9ULL, 0x22FE545401165F1CULL,
|
|
||||||
0xC91800E98FB99929ULL, 0x808BD68E6AC10365ULL, 0xDEC468145B7605F6ULL,
|
|
||||||
0x1BEDE3A3AEF53302ULL, 0x43539603D6C55602ULL, 0xAA969B5C691CCB7AULL,
|
|
||||||
0xA87832D392EFEE56ULL, 0x65942C7B3C7E11AEULL, 0xDED2D633CAD004F6ULL,
|
|
||||||
0x21F08570F420E565ULL, 0xB415938D7DA94E3CULL, 0x91B859E59ECB6350ULL,
|
|
||||||
0x10CFF333E0ED804AULL, 0x28AED140BE0BB7DDULL, 0xC5CC1D89724FA456ULL,
|
|
||||||
0x5648F680F11A2741ULL, 0x2D255069F0B7DAB3ULL, 0x9BC5A38EF729ABD4ULL,
|
|
||||||
0xEF2F054308F6A2BCULL, 0xAF2042F5CC5C2858ULL, 0x480412BAB7F5BE2AULL,
|
|
||||||
0xAEF3AF4A563DFE43ULL, 0x19AFE59AE451497FULL, 0x52593803DFF1E840ULL,
|
|
||||||
0xF4F076E65F2CE6F0ULL, 0x11379625747D5AF3ULL, 0xBCE5D2248682C115ULL,
|
|
||||||
0x9DA4243DE836994FULL, 0x066F70B33FE09017ULL, 0x4DC4DE189B671A1CULL,
|
|
||||||
0x51039AB7712457C3ULL, 0xC07A3F80C31FB4B4ULL, 0xB46EE9C5E64A6E7CULL,
|
|
||||||
0xB3819A42ABE61C87ULL, 0x21A007933A522A20ULL, 0x2DF16F761598AA4FULL,
|
|
||||||
0x763C4A1371B368FDULL, 0xF793C46702E086A0ULL, 0xD7288E012AEB8D31ULL,
|
|
||||||
0xDE336A2A4BC1C44BULL, 0x0BF692B38D079F23ULL, 0x2C604A7A177326B3ULL,
|
|
||||||
0x4850E73E03EB6064ULL, 0xCFC447F1E53C8E1BULL, 0xB05CA3F564268D99ULL,
|
|
||||||
0x9AE182C8BC9474E8ULL, 0xA4FC4BD4FC5558CAULL, 0xE755178D58FC4E76ULL,
|
|
||||||
0x69B97DB1A4C03DFEULL, 0xF9B5B7C4ACC67C96ULL, 0xFC6A82D64B8655FBULL,
|
|
||||||
0x9C684CB6C4D24417ULL, 0x8EC97D2917456ED0ULL, 0x6703DF9D2924E97EULL,
|
|
||||||
0xC547F57E42A7444EULL, 0x78E37644E7CAD29EULL, 0xFE9A44E9362F05FAULL,
|
|
||||||
0x08BD35CC38336615ULL, 0x9315E5EB3A129ACEULL, 0x94061B871E04DF75ULL,
|
|
||||||
0xDF1D9F9D784BA010ULL, 0x3BBA57B68871B59DULL, 0xD2B7ADEEDED1F73FULL,
|
|
||||||
0xF7A255D83BC373F8ULL, 0xD7F4F2448C0CEB81ULL, 0xD95BE88CD210FFA7ULL,
|
|
||||||
0x336F52F8FF4728E7ULL, 0xA74049DAC312AC71ULL, 0xA2F61BB6E437FDB5ULL,
|
|
||||||
0x4F2A5CB07F6A35B3ULL, 0x87D380BDA5BF7859ULL, 0x16B9F7E06C453A21ULL,
|
|
||||||
0x7BA2484C8A0FD54EULL, 0xF3A678CAD9A2E38CULL, 0x39B0BF7DDE437BA2ULL,
|
|
||||||
0xFCAF55C1BF8A4424ULL, 0x18FCF680573FA594ULL, 0x4C0563B89F495AC3ULL,
|
|
||||||
0x40E087931A00930DULL, 0x8CFFA9412EB642C1ULL, 0x68CA39053261169FULL,
|
|
||||||
0x7A1EE967D27579E2ULL, 0x9D1D60E5076F5B6FULL, 0x3810E399B6F65BA2ULL,
|
|
||||||
0x32095B6D4AB5F9B1ULL, 0x35CAB62109DD038AULL, 0xA90B24499FCFAFB1ULL,
|
|
||||||
0x77A225A07CC2C6BDULL, 0x513E5E634C70E331ULL, 0x4361C0CA3F692F12ULL,
|
|
||||||
0xD941ACA44B20A45BULL, 0x528F7C8602C5807BULL, 0x52AB92BEB9613989ULL,
|
|
||||||
0x9D1DFA2EFC557F73ULL, 0x722FF175F572C348ULL, 0x1D1260A51107FE97ULL,
|
|
||||||
0x7A249A57EC0C9BA2ULL, 0x04208FE9E8F7F2D6ULL, 0x5A110C6058B920A0ULL,
|
|
||||||
0x0CD9A497658A5698ULL, 0x56FD23C8F9715A4CULL, 0x284C847B9D887AAEULL,
|
|
||||||
0x04FEABFBBDB619CBULL, 0x742E1E651C60BA83ULL, 0x9A9632E65904AD3CULL,
|
|
||||||
0x881B82A13B51B9E2ULL, 0x506E6744CD974924ULL, 0xB0183DB56FFC6A79ULL,
|
|
||||||
0x0ED9B915C66ED37EULL, 0x5E11E86D5873D484ULL, 0xF678647E3519AC6EULL,
|
|
||||||
0x1B85D488D0F20CC5ULL, 0xDAB9FE6525D89021ULL, 0x0D151D86ADB73615ULL,
|
|
||||||
0xA865A54EDCC0F019ULL, 0x93C42566AEF98FFBULL, 0x99E7AFEABE000731ULL,
|
|
||||||
0x48CBFF086DDF285AULL, 0x7F9B6AF1EBF78BAFULL, 0x58627E1A149BBA21ULL,
|
|
||||||
0x2CD16E2ABD791E33ULL, 0xD363EFF5F0977996ULL, 0x0CE2A38C344A6EEDULL,
|
|
||||||
0x1A804AADB9CFA741ULL, 0x907F30421D78C5DEULL, 0x501F65EDB3034D07ULL,
|
|
||||||
0x37624AE5A48FA6E9ULL, 0x957BAF61700CFF4EULL, 0x3A6C27934E31188AULL,
|
|
||||||
0xD49503536ABCA345ULL, 0x088E049589C432E0ULL, 0xF943AEE7FEBF21B8ULL,
|
|
||||||
0x6C3B8E3E336139D3ULL, 0x364F6FFA464EE52EULL, 0xD60F6DCEDC314222ULL,
|
|
||||||
0x56963B0DCA418FC0ULL, 0x16F50EDF91E513AFULL, 0xEF1955914B609F93ULL,
|
|
||||||
0x565601C0364E3228ULL, 0xECB53939887E8175ULL, 0xBAC7A9A18531294BULL,
|
|
||||||
0xB344C470397BBA52ULL, 0x65D34954DAF3CEBDULL, 0xB4B81B3FA97511E2ULL,
|
|
||||||
0xB422061193D6F6A7ULL, 0x071582401C38434DULL, 0x7A13F18BBEDC4FF5ULL,
|
|
||||||
0xBC4097B116C524D2ULL, 0x59B97885E2F2EA28ULL, 0x99170A5DC3115544ULL,
|
|
||||||
0x6F423357E7C6A9F9ULL, 0x325928EE6E6F8794ULL, 0xD0E4366228B03343ULL,
|
|
||||||
0x565C31F7DE89EA27ULL, 0x30F5611484119414ULL, 0xD873DB391292ED4FULL,
|
|
||||||
0x7BD94E1D8E17DEBCULL, 0xC7D9F16864A76E94ULL, 0x947AE053EE56E63CULL,
|
|
||||||
0xC8C93882F9475F5FULL, 0x3A9BF55BA91F81CAULL, 0xD9A11FBB3D9808E4ULL,
|
|
||||||
0x0FD22063EDC29FCAULL, 0xB3F256D8ACA0B0B9ULL, 0xB03031A8B4516E84ULL,
|
|
||||||
0x35DD37D5871448AFULL, 0xE9F6082B05542E4EULL, 0xEBFAFA33D7254B59ULL,
|
|
||||||
0x9255ABB50D532280ULL, 0xB9AB4CE57F2D34F3ULL, 0x693501D628297551ULL,
|
|
||||||
0xC62C58F97DD949BFULL, 0xCD454F8F19C5126AULL, 0xBBE83F4ECC2BDECBULL,
|
|
||||||
0xDC842B7E2819E230ULL, 0xBA89142E007503B8ULL, 0xA3BC941D0A5061CBULL,
|
|
||||||
0xE9F6760E32CD8021ULL, 0x09C7E552BC76492FULL, 0x852F54934DA55CC9ULL,
|
|
||||||
0x8107FCCF064FCF56ULL, 0x098954D51FFF6580ULL, 0x23B70EDB1955C4BFULL,
|
|
||||||
0xC330DE426430F69DULL, 0x4715ED43E8A45C0AULL, 0xA8D7E4DAB780A08DULL,
|
|
||||||
0x0572B974F03CE0BBULL, 0xB57D2E985E1419C7ULL, 0xE8D9ECBE2CF3D73FULL,
|
|
||||||
0x2FE4B17170E59750ULL, 0x11317BA87905E790ULL, 0x7FBF21EC8A1F45ECULL,
|
|
||||||
0x1725CABFCB045B00ULL, 0x964E915CD5E2B207ULL, 0x3E2B8BCBF016D66DULL,
|
|
||||||
0xBE7444E39328A0ACULL, 0xF85B2B4FBCDE44B7ULL, 0x49353FEA39BA63B1ULL,
|
|
||||||
0x1DD01AAFCD53486AULL, 0x1FCA8A92FD719F85ULL, 0xFC7C95D827357AFAULL,
|
|
||||||
0x18A6A990C8B35EBDULL, 0xCCCB7005C6B9C28DULL, 0x3BDBB92C43B17F26ULL,
|
|
||||||
0xAA70B5B4F89695A2ULL, 0xE94C39A54A98307FULL, 0xB7A0B174CFF6F36EULL,
|
|
||||||
0xD4DBA84729AF48ADULL, 0x2E18BC1AD9704A68ULL, 0x2DE0966DAF2F8B1CULL,
|
|
||||||
0xB9C11D5B1E43A07EULL, 0x64972D68DEE33360ULL, 0x94628D38D0C20584ULL,
|
|
||||||
0xDBC0D2B6AB90A559ULL, 0xD2733C4335C6A72FULL, 0x7E75D99D94A70F4DULL,
|
|
||||||
0x6CED1983376FA72BULL, 0x97FCAACBF030BC24ULL, 0x7B77497B32503B12ULL,
|
|
||||||
0x8547EDDFB81CCB94ULL, 0x79999CDFF70902CBULL, 0xCFFE1939438E9B24ULL,
|
|
||||||
0x829626E3892D95D7ULL, 0x92FAE24291F2B3F1ULL, 0x63E22C147B9C3403ULL,
|
|
||||||
0xC678B6D860284A1CULL, 0x5873888850659AE7ULL, 0x0981DCD296A8736DULL,
|
|
||||||
0x9F65789A6509A440ULL, 0x9FF38FED72E9052FULL, 0xE479EE5B9930578CULL,
|
|
||||||
0xE7F28ECD2D49EECDULL, 0x56C074A581EA17FEULL, 0x5544F7D774B14AEFULL,
|
|
||||||
0x7B3F0195FC6F290FULL, 0x12153635B2C0CF57ULL, 0x7F5126DBBA5E0CA7ULL,
|
|
||||||
0x7A76956C3EAFB413ULL, 0x3D5774A11D31AB39ULL, 0x8A1B083821F40CB4ULL,
|
|
||||||
0x7B4A38E32537DF62ULL, 0x950113646D1D6E03ULL, 0x4DA8979A0041E8A9ULL,
|
|
||||||
0x3BC36E078F7515D7ULL, 0x5D0A12F27AD310D1ULL, 0x7F9D1A2E1EBE1327ULL,
|
|
||||||
0xDA3A361B1C5157B1ULL, 0xDCDD7D20903D0C25ULL, 0x36833336D068F707ULL,
|
|
||||||
0xCE68341F79893389ULL, 0xAB9090168DD05F34ULL, 0x43954B3252DC25E5ULL,
|
|
||||||
0xB438C2B67F98E5E9ULL, 0x10DCD78E3851A492ULL, 0xDBC27AB5447822BFULL,
|
|
||||||
0x9B3CDB65F82CA382ULL, 0xB67B7896167B4C84ULL, 0xBFCED1B0048EAC50ULL,
|
|
||||||
0xA9119B60369FFEBDULL, 0x1FFF7AC80904BF45ULL, 0xAC12FB171817EEE7ULL,
|
|
||||||
0xAF08DA9177DDA93DULL, 0x1B0CAB936E65C744ULL, 0xB559EB1D04E5E932ULL,
|
|
||||||
0xC37B45B3F8D6F2BAULL, 0xC3A9DC228CAAC9E9ULL, 0xF3B8B6675A6507FFULL,
|
|
||||||
0x9FC477DE4ED681DAULL, 0x67378D8ECCEF96CBULL, 0x6DD856D94D259236ULL,
|
|
||||||
0xA319CE15B0B4DB31ULL, 0x073973751F12DD5EULL, 0x8A8E849EB32781A5ULL,
|
|
||||||
0xE1925C71285279F5ULL, 0x74C04BF1790C0EFEULL, 0x4DDA48153C94938AULL,
|
|
||||||
0x9D266D6A1CC0542CULL, 0x7440FB816508C4FEULL, 0x13328503DF48229FULL,
|
|
||||||
0xD6BF7BAEE43CAC40ULL, 0x4838D65F6EF6748FULL, 0x1E152328F3318DEAULL,
|
|
||||||
0x8F8419A348F296BFULL, 0x72C8834A5957B511ULL, 0xD7A023A73260B45CULL,
|
|
||||||
0x94EBC8ABCFB56DAEULL, 0x9FC10D0F989993E0ULL, 0xDE68A2355B93CAE6ULL,
|
|
||||||
0xA44CFE79AE538BBEULL, 0x9D1D84FCCE371425ULL, 0x51D2B1AB2DDFB636ULL,
|
|
||||||
0x2FD7E4B9E72CD38CULL, 0x65CA5B96B7552210ULL, 0xDD69A0D8AB3B546DULL,
|
|
||||||
0x604D51B25FBF70E2ULL, 0x73AA8A564FB7AC9EULL, 0x1A8C1E992B941148ULL,
|
|
||||||
0xAAC40A2703D9BEA0ULL, 0x764DBEAE7FA4F3A6ULL, 0x1E99B96E70A9BE8BULL,
|
|
||||||
0x2C5E9DEB57EF4743ULL, 0x3A938FEE32D29981ULL, 0x26E6DB8FFDF5ADFEULL,
|
|
||||||
0x469356C504EC9F9DULL, 0xC8763C5B08D1908CULL, 0x3F6C6AF859D80055ULL,
|
|
||||||
0x7F7CC39420A3A545ULL, 0x9BFB227EBDF4C5CEULL, 0x89039D79D6FC5C5CULL,
|
|
||||||
0x8FE88B57305E2AB6ULL, 0xA09E8C8C35AB96DEULL, 0xFA7E393983325753ULL,
|
|
||||||
0xD6B6D0ECC617C699ULL, 0xDFEA21EA9E7557E3ULL, 0xB67C1FA481680AF8ULL,
|
|
||||||
0xCA1E3785A9E724E5ULL, 0x1CFC8BED0D681639ULL, 0xD18D8549D140CAEAULL,
|
|
||||||
0x4ED0FE7E9DC91335ULL, 0xE4DBF0634473F5D2ULL, 0x1761F93A44D5AEFEULL,
|
|
||||||
0x53898E4C3910DA55ULL, 0x734DE8181F6EC39AULL, 0x2680B122BAA28D97ULL,
|
|
||||||
0x298AF231C85BAFABULL, 0x7983EED3740847D5ULL, 0x66C1A2A1A60CD889ULL,
|
|
||||||
0x9E17E49642A3E4C1ULL, 0xEDB454E7BADC0805ULL, 0x50B704CAB602C329ULL,
|
|
||||||
0x4CC317FB9CDDD023ULL, 0x66B4835D9EAFEA22ULL, 0x219B97E26FFC81BDULL,
|
|
||||||
0x261E4E4C0A333A9DULL, 0x1FE2CCA76517DB90ULL, 0xD7504DFA8816EDBBULL,
|
|
||||||
0xB9571FA04DC089C8ULL, 0x1DDC0325259B27DEULL, 0xCF3F4688801EB9AAULL,
|
|
||||||
0xF4F5D05C10CAB243ULL, 0x38B6525C21A42B0EULL, 0x36F60E2BA4FA6800ULL,
|
|
||||||
0xEB3593803173E0CEULL, 0x9C4CD6257C5A3603ULL, 0xAF0C317D32ADAA8AULL,
|
|
||||||
0x258E5A80C7204C4BULL, 0x8B889D624D44885DULL, 0xF4D14597E660F855ULL,
|
|
||||||
0xD4347F66EC8941C3ULL, 0xE699ED85B0DFB40DULL, 0x2472F6207C2D0484ULL,
|
|
||||||
0xC2A1E7B5B459AEB5ULL, 0xAB4F6451CC1D45ECULL, 0x63767572AE3D6174ULL,
|
|
||||||
0xA59E0BD101731A28ULL, 0x116D0016CB948F09ULL, 0x2CF9C8CA052F6E9FULL,
|
|
||||||
0x0B090A7560A968E3ULL, 0xABEEDDB2DDE06FF1ULL, 0x58EFC10B06A2068DULL,
|
|
||||||
0xC6E57A78FBD986E0ULL, 0x2EAB8CA63CE802D7ULL, 0x14A195640116F336ULL,
|
|
||||||
0x7C0828DD624EC390ULL, 0xD74BBE77E6116AC7ULL, 0x804456AF10F5FB53ULL,
|
|
||||||
0xEBE9EA2ADF4321C7ULL, 0x03219A39EE587A30ULL, 0x49787FEF17AF9924ULL,
|
|
||||||
0xA1E9300CD8520548ULL, 0x5B45E522E4B1B4EFULL, 0xB49C3B3995091A36ULL,
|
|
||||||
0xD4490AD526F14431ULL, 0x12A8F216AF9418C2ULL, 0x001F837CC7350524ULL,
|
|
||||||
0x1877B51E57A764D5ULL, 0xA2853B80F17F58EEULL, 0x993E1DE72D36D310ULL,
|
|
||||||
0xB3598080CE64A656ULL, 0x252F59CF0D9F04BBULL, 0xD23C8E176D113600ULL,
|
|
||||||
0x1BDA0492E7E4586EULL, 0x21E0BD5026C619BFULL, 0x3B097ADAF088F94EULL,
|
|
||||||
0x8D14DEDB30BE846EULL, 0xF95CFFA23AF5F6F4ULL, 0x3871700761B3F743ULL,
|
|
||||||
0xCA672B91E9E4FA16ULL, 0x64C8E531BFF53B55ULL, 0x241260ED4AD1E87DULL,
|
|
||||||
0x106C09B972D2E822ULL, 0x7FBA195410E5CA30ULL, 0x7884D9BC6CB569D8ULL,
|
|
||||||
0x0647DFEDCD894A29ULL, 0x63573FF03E224774ULL, 0x4FC8E9560F91B123ULL,
|
|
||||||
0x1DB956E450275779ULL, 0xB8D91274B9E9D4FBULL, 0xA2EBEE47E2FBFCE1ULL,
|
|
||||||
0xD9F1F30CCD97FB09ULL, 0xEFED53D75FD64E6BULL, 0x2E6D02C36017F67FULL,
|
|
||||||
0xA9AA4D20DB084E9BULL, 0xB64BE8D8B25396C1ULL, 0x70CB6AF7C2D5BCF0ULL,
|
|
||||||
0x98F076A4F7A2322EULL, 0xBF84470805E69B5FULL, 0x94C3251F06F90CF3ULL,
|
|
||||||
0x3E003E616A6591E9ULL, 0xB925A6CD0421AFF3ULL, 0x61BDD1307C66E300ULL,
|
|
||||||
0xBF8D5108E27E0D48ULL, 0x240AB57A8B888B20ULL, 0xFC87614BAF287E07ULL,
|
|
||||||
0xEF02CDD06FFDB432ULL, 0xA1082C0466DF6C0AULL, 0x8215E577001332C8ULL,
|
|
||||||
0xD39BB9C3A48DB6CFULL, 0x2738259634305C14ULL, 0x61CF4F94C97DF93DULL,
|
|
||||||
0x1B6BACA2AE4E125BULL, 0x758F450C88572E0BULL, 0x959F587D507A8359ULL,
|
|
||||||
0xB063E962E045F54DULL, 0x60E8ED72C0DFF5D1ULL, 0x7B64978555326F9FULL,
|
|
||||||
0xFD080D236DA814BAULL, 0x8C90FD9B083F4558ULL, 0x106F72FE81E2C590ULL,
|
|
||||||
0x7976033A39F7D952ULL, 0xA4EC0132764CA04BULL, 0x733EA705FAE4FA77ULL,
|
|
||||||
0xB4D8F77BC3E56167ULL, 0x9E21F4F903B33FD9ULL, 0x9D765E419FB69F6DULL,
|
|
||||||
0xD30C088BA61EA5EFULL, 0x5D94337FBFAF7F5BULL, 0x1A4E4822EB4D7A59ULL,
|
|
||||||
0x6FFE73E81B637FB3ULL, 0xDDF957BC36D8B9CAULL, 0x64D0E29EEA8838B3ULL,
|
|
||||||
0x08DD9BDFD96B9F63ULL, 0x087E79E5A57D1D13ULL, 0xE328E230E3E2B3FBULL,
|
|
||||||
0x1C2559E30F0946BEULL, 0x720BF5F26F4D2EAAULL, 0xB0774D261CC609DBULL,
|
|
||||||
0x443F64EC5A371195ULL, 0x4112CF68649A260EULL, 0xD813F2FAB7F5C5CAULL,
|
|
||||||
0x660D3257380841EEULL, 0x59AC2C7873F910A3ULL, 0xE846963877671A17ULL,
|
|
||||||
0x93B633ABFA3469F8ULL, 0xC0C0F5A60EF4CDCFULL, 0xCAF21ECD4377B28CULL,
|
|
||||||
0x57277707199B8175ULL, 0x506C11B9D90E8B1DULL, 0xD83CC2687A19255FULL,
|
|
||||||
0x4A29C6465A314CD1ULL, 0xED2DF21216235097ULL, 0xB5635C95FF7296E2ULL,
|
|
||||||
0x22AF003AB672E811ULL, 0x52E762596BF68235ULL, 0x9AEBA33AC6ECC6B0ULL,
|
|
||||||
0x944F6DE09134DFB6ULL, 0x6C47BEC883A7DE39ULL, 0x6AD047C430A12104ULL,
|
|
||||||
0xA5B1CFDBA0AB4067ULL, 0x7C45D833AFF07862ULL, 0x5092EF950A16DA0BULL,
|
|
||||||
0x9338E69C052B8E7BULL, 0x455A4B4CFE30E3F5ULL, 0x6B02E63195AD0CF8ULL,
|
|
||||||
0x6B17B224BAD6BF27ULL, 0xD1E0CCD25BB9C169ULL, 0xDE0C89A556B9AE70ULL,
|
|
||||||
0x50065E535A213CF6ULL, 0x9C1169FA2777B874ULL, 0x78EDEFD694AF1EEDULL,
|
|
||||||
0x6DC93D9526A50E68ULL, 0xEE97F453F06791EDULL, 0x32AB0EDB696703D3ULL,
|
|
||||||
0x3A6853C7E70757A7ULL, 0x31865CED6120F37DULL, 0x67FEF95D92607890ULL,
|
|
||||||
0x1F2B1D1F15F6DC9CULL, 0xB69E38A8965C6B65ULL, 0xAA9119FF184CCCF4ULL,
|
|
||||||
0xF43C732873F24C13ULL, 0xFB4A3D794A9A80D2ULL, 0x3550C2321FD6109CULL,
|
|
||||||
0x371F77E76BB8417EULL, 0x6BFA9AAE5EC05779ULL, 0xCD04F3FF001A4778ULL,
|
|
||||||
0xE3273522064480CAULL, 0x9F91508BFFCFC14AULL, 0x049A7F41061A9E60ULL,
|
|
||||||
0xFCB6BE43A9F2FE9BULL, 0x08DE8A1C7797DA9BULL, 0x8F9887E6078735A1ULL,
|
|
||||||
0xB5B4071DBFC73A66ULL, 0x230E343DFBA08D33ULL, 0x43ED7F5A0FAE657DULL,
|
|
||||||
0x3A88A0FBBCB05C63ULL, 0x21874B8B4D2DBC4FULL, 0x1BDEA12E35F6A8C9ULL,
|
|
||||||
0x53C065C6C8E63528ULL, 0xE34A1D250E7A8D6BULL, 0xD6B04D3B7651DD7EULL,
|
|
||||||
0x5E90277E7CB39E2DULL, 0x2C046F22062DC67DULL, 0xB10BB459132D0A26ULL,
|
|
||||||
0x3FA9DDFB67E2F199ULL, 0x0E09B88E1914F7AFULL, 0x10E8B35AF3EEAB37ULL,
|
|
||||||
0x9EEDECA8E272B933ULL, 0xD4C718BC4AE8AE5FULL, 0x81536D601170FC20ULL,
|
|
||||||
0x91B534F885818A06ULL, 0xEC8177F83F900978ULL, 0x190E714FADA5156EULL,
|
|
||||||
0xB592BF39B0364963ULL, 0x89C350C893AE7DC1ULL, 0xAC042E70F8B383F2ULL,
|
|
||||||
0xB49B52E587A1EE60ULL, 0xFB152FE3FF26DA89ULL, 0x3E666E6F69AE2C15ULL,
|
|
||||||
0x3B544EBE544C19F9ULL, 0xE805A1E290CF2456ULL, 0x24B33C9D7ED25117ULL,
|
|
||||||
0xE74733427B72F0C1ULL, 0x0A804D18B7097475ULL, 0x57E3306D881EDB4FULL,
|
|
||||||
0x4AE7D6A36EB5DBCBULL, 0x2D8D5432157064C8ULL, 0xD1E649DE1E7F268BULL,
|
|
||||||
0x8A328A1CEDFE552CULL, 0x07A3AEC79624C7DAULL, 0x84547DDC3E203C94ULL,
|
|
||||||
0x990A98FD5071D263ULL, 0x1A4FF12616EEFC89ULL, 0xF6F7FD1431714200ULL,
|
|
||||||
0x30C05B1BA332F41CULL, 0x8D2636B81555A786ULL, 0x46C9FEB55D120902ULL,
|
|
||||||
0xCCEC0A73B49C9921ULL, 0x4E9D2827355FC492ULL, 0x19EBB029435DCB0FULL,
|
|
||||||
0x4659D2B743848A2CULL, 0x963EF2C96B33BE31ULL, 0x74F85198B05A2E7DULL,
|
|
||||||
0x5A0F544DD2B1FB18ULL, 0x03727073C2E134B1ULL, 0xC7F6AA2DE59AEA61ULL,
|
|
||||||
0x352787BAA0D7C22FULL, 0x9853EAB63B5E0B35ULL, 0xABBDCDD7ED5C0860ULL,
|
|
||||||
0xCF05DAF5AC8D77B0ULL, 0x49CAD48CEBF4A71EULL, 0x7A4C10EC2158C4A6ULL,
|
|
||||||
0xD9E92AA246BF719EULL, 0x13AE978D09FE5557ULL, 0x730499AF921549FFULL,
|
|
||||||
0x4E4B705B92903BA4ULL, 0xFF577222C14F0A3AULL, 0x55B6344CF97AAFAEULL,
|
|
||||||
0xB862225B055B6960ULL, 0xCAC09AFBDDD2CDB4ULL, 0xDAF8E9829FE96B5FULL,
|
|
||||||
0xB5FDFC5D3132C498ULL, 0x310CB380DB6F7503ULL, 0xE87FBB46217A360EULL,
|
|
||||||
0x2102AE466EBB1148ULL, 0xF8549E1A3AA5E00DULL, 0x07A69AFDCC42261AULL,
|
|
||||||
0xC4C118BFE78FEAAEULL, 0xF9F4892ED96BD438ULL, 0x1AF3DBE25D8F45DAULL,
|
|
||||||
0xF5B4B0B0D2DEEEB4ULL, 0x962ACEEFA82E1C84ULL, 0x046E3ECAAF453CE9ULL,
|
|
||||||
0xF05D129681949A4CULL, 0x964781CE734B3C84ULL, 0x9C2ED44081CE5FBDULL,
|
|
||||||
0x522E23F3925E319EULL, 0x177E00F9FC32F791ULL, 0x2BC60A63A6F3B3F2ULL,
|
|
||||||
0x222BBFAE61725606ULL, 0x486289DDCC3D6780ULL, 0x7DC7785B8EFDFC80ULL,
|
|
||||||
0x8AF38731C02BA980ULL, 0x1FAB64EA29A2DDF7ULL, 0xE4D9429322CD065AULL,
|
|
||||||
0x9DA058C67844F20CULL, 0x24C0E332B70019B0ULL, 0x233003B5A6CFE6ADULL,
|
|
||||||
0xD586BD01C5C217F6ULL, 0x5E5637885F29BC2BULL, 0x7EBA726D8C94094BULL,
|
|
||||||
0x0A56A5F0BFE39272ULL, 0xD79476A84EE20D06ULL, 0x9E4C1269BAA4BF37ULL,
|
|
||||||
0x17EFEE45B0DEE640ULL, 0x1D95B0A5FCF90BC6ULL, 0x93CBE0B699C2585DULL,
|
|
||||||
0x65FA4F227A2B6D79ULL, 0xD5F9E858292504D5ULL, 0xC2B5A03F71471A6FULL,
|
|
||||||
0x59300222B4561E00ULL, 0xCE2F8642CA0712DCULL, 0x7CA9723FBB2E8988ULL,
|
|
||||||
0x2785338347F2BA08ULL, 0xC61BB3A141E50E8CULL, 0x150F361DAB9DEC26ULL,
|
|
||||||
0x9F6A419D382595F4ULL, 0x64A53DC924FE7AC9ULL, 0x142DE49FFF7A7C3DULL,
|
|
||||||
0x0C335248857FA9E7ULL, 0x0A9C32D5EAE45305ULL, 0xE6C42178C4BBB92EULL,
|
|
||||||
0x71F1CE2490D20B07ULL, 0xF1BCC3D275AFE51AULL, 0xE728E8C83C334074ULL,
|
|
||||||
0x96FBF83A12884624ULL, 0x81A1549FD6573DA5ULL, 0x5FA7867CAF35E149ULL,
|
|
||||||
0x56986E2EF3ED091BULL, 0x917F1DD5F8886C61ULL, 0xD20D8C88C8FFE65FULL,
|
|
||||||
0x31D71DCE64B2C310ULL, 0xF165B587DF898190ULL, 0xA57E6339DD2CF3A0ULL,
|
|
||||||
0x1EF6E6DBB1961EC9ULL, 0x70CC73D90BC26E24ULL, 0xE21A6B35DF0C3AD7ULL,
|
|
||||||
0x003A93D8B2806962ULL, 0x1C99DED33CB890A1ULL, 0xCF3145DE0ADD4289ULL,
|
|
||||||
0xD0E4427A5514FB72ULL, 0x77C621CC9FB3A483ULL, 0x67A34DAC4356550BULL,
|
|
||||||
0xF8D626AAAF278509ULL
|
|
||||||
};
|
|
||||||
|
|
||||||
// Indices to the Random64[] array
|
|
||||||
const int PieceIdx = 0;
|
|
||||||
const int CastleIdx = 768;
|
|
||||||
const int EnPassantIdx = 772;
|
|
||||||
const int TurnIdx = 780;
|
|
||||||
|
|
||||||
// book_key() builds up a PolyGlot hash key out of a position
|
|
||||||
uint64_t book_key(const Position& pos) {
|
|
||||||
|
|
||||||
// Piece offset is calculated as (64 * PolyPieceType + square), where
|
|
||||||
// PolyPieceType is: BP = 0, WP = 1, BN = 2, WN = 3 .... BK = 10, WK = 11
|
|
||||||
static const int PieceToPoly[] = { 0, 1, 3, 5, 7, 9, 11, 0, 0, 0, 2, 4, 6, 8, 10 };
|
|
||||||
|
|
||||||
uint64_t result = 0;
|
|
||||||
Bitboard b = pos.occupied_squares();
|
|
||||||
|
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
Square s = pop_1st_bit(&b);
|
|
||||||
int p = PieceToPoly[int(pos.piece_on(s))];
|
|
||||||
result ^= Random64[PieceIdx + 64 * p + int(s)];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos.can_castle_kingside(WHITE))
|
|
||||||
result ^= Random64[CastleIdx + 0];
|
|
||||||
|
|
||||||
if (pos.can_castle_queenside(WHITE))
|
|
||||||
result ^= Random64[CastleIdx + 1];
|
|
||||||
|
|
||||||
if (pos.can_castle_kingside(BLACK))
|
|
||||||
result ^= Random64[CastleIdx + 2];
|
|
||||||
|
|
||||||
if (pos.can_castle_queenside(BLACK))
|
|
||||||
result ^= Random64[CastleIdx + 3];
|
|
||||||
|
|
||||||
if (pos.ep_square() != SQ_NONE)
|
|
||||||
result ^= Random64[EnPassantIdx + square_file(pos.ep_square())];
|
|
||||||
|
|
||||||
if (pos.side_to_move() == WHITE)
|
|
||||||
result ^= Random64[TurnIdx];
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Book c'tor. Make random number generation less deterministic, for book moves
|
|
||||||
Book::Book() {
|
|
||||||
|
|
||||||
for (int i = abs(get_system_time() % 10000); i > 0; i--)
|
|
||||||
RKiss.rand<unsigned>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Book destructor. Be sure file is closed before we leave.
|
|
||||||
|
|
||||||
Book::~Book() {
|
|
||||||
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Book::close() closes the file only if it is open, otherwise
|
|
||||||
/// we can end up in a little mess due to how std::ifstream works.
|
|
||||||
|
|
||||||
void Book::close() {
|
|
||||||
|
|
||||||
if (bookFile.is_open())
|
|
||||||
bookFile.close();
|
|
||||||
|
|
||||||
bookName = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Book::open() opens a book file with a given file name
|
|
||||||
|
|
||||||
void Book::open(const string& fileName) {
|
|
||||||
|
|
||||||
// Close old file before opening the new
|
|
||||||
close();
|
|
||||||
|
|
||||||
bookFile.open(fileName.c_str(), ifstream::in | ifstream::binary);
|
|
||||||
|
|
||||||
// Silently return when asked to open a non-exsistent file
|
|
||||||
if (!bookFile.is_open())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Get the book size in number of entries
|
|
||||||
bookFile.seekg(0, ios::end);
|
|
||||||
bookSize = long(bookFile.tellg()) / sizeof(BookEntry);
|
|
||||||
|
|
||||||
if (!bookFile.good())
|
|
||||||
{
|
|
||||||
cerr << "Failed to open book file " << fileName << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set only if successful
|
|
||||||
bookName = fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Book::get_move() gets a book move for a given position. Returns
|
|
||||||
/// MOVE_NONE if no book move is found. If findBestMove is true then
|
|
||||||
/// return always the highest rated book move.
|
|
||||||
|
|
||||||
Move Book::get_move(const Position& pos, bool findBestMove) {
|
|
||||||
|
|
||||||
if (!bookFile.is_open() || bookSize == 0)
|
|
||||||
return MOVE_NONE;
|
|
||||||
|
|
||||||
BookEntry entry;
|
|
||||||
int bookMove = MOVE_NONE;
|
|
||||||
unsigned score, scoresSum = 0, bestScore = 0;
|
|
||||||
uint64_t key = book_key(pos);
|
|
||||||
|
|
||||||
// Choose a book move among the possible moves for the given position
|
|
||||||
for (int idx = find_entry(key); idx < bookSize; idx++)
|
|
||||||
{
|
|
||||||
entry = read_entry(idx);
|
|
||||||
|
|
||||||
if (entry.key != key)
|
|
||||||
break;
|
|
||||||
|
|
||||||
score = entry.count;
|
|
||||||
|
|
||||||
if (!findBestMove)
|
|
||||||
{
|
|
||||||
// Choose book move according to its score. If a move has a very
|
|
||||||
// high score it has more probability to be choosen then a one with
|
|
||||||
// lower score. Note that first entry is always chosen.
|
|
||||||
scoresSum += score;
|
|
||||||
if (RKiss.rand<unsigned>() % scoresSum < score)
|
|
||||||
bookMove = entry.move;
|
|
||||||
}
|
|
||||||
else if (score > bestScore)
|
|
||||||
{
|
|
||||||
bestScore = score;
|
|
||||||
bookMove = entry.move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A PolyGlot book move is encoded as follows:
|
|
||||||
//
|
|
||||||
// bit 0- 5: destination square (from 0 to 63)
|
|
||||||
// bit 6-11: origin square (from 0 to 63)
|
|
||||||
// bit 12-13-14: promotion piece (from KNIGHT == 1 to QUEEN == 4)
|
|
||||||
//
|
|
||||||
// Castling moves follow "king captures rook" representation. So in case
|
|
||||||
// book move is a promotion we have to convert to our representation, in
|
|
||||||
// all other cases we can directly compare with a Move after having
|
|
||||||
// masked out special Move's flags that are not supported by PolyGlot.
|
|
||||||
int p = (bookMove >> 12) & 7;
|
|
||||||
|
|
||||||
if (p)
|
|
||||||
bookMove = int(make_promotion_move(move_from(Move(bookMove)),
|
|
||||||
move_to(Move(bookMove)), PieceType(p + 1)));
|
|
||||||
|
|
||||||
// Verify the book move (if any) is legal
|
|
||||||
MoveStack mlist[MAX_MOVES];
|
|
||||||
MoveStack* last = generate<MV_LEGAL>(pos, mlist);
|
|
||||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
|
||||||
if ((int(cur->move) & ~(3 << 14)) == bookMove) // Mask out special flags
|
|
||||||
return cur->move;
|
|
||||||
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Book::find_entry() takes a book key as input, and does a binary search
|
|
||||||
/// through the book file for the given key. The index to the first book
|
|
||||||
/// entry with the same key as the input is returned. When the key is not
|
|
||||||
/// found in the book file, bookSize is returned.
|
|
||||||
|
|
||||||
int Book::find_entry(uint64_t key) {
|
|
||||||
|
|
||||||
int left, right, mid;
|
|
||||||
|
|
||||||
// Binary search (finds the leftmost entry)
|
|
||||||
left = 0;
|
|
||||||
right = bookSize - 1;
|
|
||||||
|
|
||||||
assert(left <= right);
|
|
||||||
|
|
||||||
while (left < right)
|
|
||||||
{
|
|
||||||
mid = (left + right) / 2;
|
|
||||||
|
|
||||||
assert(mid >= left && mid < right);
|
|
||||||
|
|
||||||
if (key <= read_entry(mid).key)
|
|
||||||
right = mid;
|
|
||||||
else
|
|
||||||
left = mid + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(left == right);
|
|
||||||
|
|
||||||
return read_entry(left).key == key ? left : bookSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Book::read_entry() takes an integer index, and returns the BookEntry
|
|
||||||
/// at the given index in the book file.
|
|
||||||
|
|
||||||
BookEntry Book::read_entry(int idx) {
|
|
||||||
|
|
||||||
assert(idx >= 0 && idx < bookSize);
|
|
||||||
assert(bookFile.is_open());
|
|
||||||
|
|
||||||
BookEntry e;
|
|
||||||
|
|
||||||
bookFile.seekg(idx * sizeof(BookEntry), ios_base::beg);
|
|
||||||
|
|
||||||
*this >> e.key >> e.move >> e.count >> e.learn;
|
|
||||||
|
|
||||||
if (!bookFile.good())
|
|
||||||
{
|
|
||||||
cerr << "Failed to read book entry at index " << idx << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
-71
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(BOOK_H_INCLUDED)
|
|
||||||
#define BOOK_H_INCLUDED
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "move.h"
|
|
||||||
#include "position.h"
|
|
||||||
#include "rkiss.h"
|
|
||||||
|
|
||||||
|
|
||||||
// A Polyglot book is a series of "entries" of 16 bytes. All integers are
|
|
||||||
// stored highest byte first (regardless of size). The entries are ordered
|
|
||||||
// according to key. Lowest key first.
|
|
||||||
struct BookEntry {
|
|
||||||
uint64_t key;
|
|
||||||
uint16_t move;
|
|
||||||
uint16_t count;
|
|
||||||
uint32_t learn;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Book {
|
|
||||||
public:
|
|
||||||
Book();
|
|
||||||
~Book();
|
|
||||||
void open(const std::string& fileName);
|
|
||||||
void close();
|
|
||||||
Move get_move(const Position& pos, bool findBestMove);
|
|
||||||
const std::string name() const { return bookName; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
// read n chars from the file stream and converts them in an
|
|
||||||
// integer number. Integers are stored with highest byte first.
|
|
||||||
template<int n> uint64_t get_int();
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
Book& operator>>(T& n) { n = (T)get_int<sizeof(T)>(); return *this; }
|
|
||||||
|
|
||||||
BookEntry read_entry(int idx);
|
|
||||||
int find_entry(uint64_t key);
|
|
||||||
|
|
||||||
std::ifstream bookFile;
|
|
||||||
std::string bookName;
|
|
||||||
int bookSize;
|
|
||||||
RKISS RKiss;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Yes, we indulge a bit here ;-)
|
|
||||||
template<int n> inline uint64_t Book::get_int() { return 256 * get_int<n-1>() + bookFile.get(); }
|
|
||||||
template<> inline uint64_t Book::get_int<1>() { return bookFile.get(); }
|
|
||||||
|
|
||||||
#endif // !defined(BOOK_H_INCLUDED)
|
|
||||||
+476
-599
File diff suppressed because it is too large
Load Diff
+57
-44
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,96 +18,108 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(ENDGAME_H_INCLUDED)
|
#ifndef ENDGAME_H_INCLUDED
|
||||||
#define ENDGAME_H_INCLUDED
|
#define ENDGAME_H_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
|
||||||
/// EndgameType lists all supported endgames
|
/// EndgameCode lists all supported endgame functions by corresponding codes
|
||||||
|
|
||||||
enum EndgameType {
|
enum EndgameCode {
|
||||||
|
|
||||||
// Evaluation functions
|
|
||||||
|
|
||||||
|
EVALUATION_FUNCTIONS,
|
||||||
|
KNNK, // KNN vs K
|
||||||
KXK, // Generic "mate lone king" eval
|
KXK, // Generic "mate lone king" eval
|
||||||
KBNK, // KBN vs K
|
KBNK, // KBN vs K
|
||||||
KPK, // KP vs K
|
KPK, // KP vs K
|
||||||
KRKP, // KR vs KP
|
KRKP, // KR vs KP
|
||||||
KRKB, // KR vs KB
|
KRKB, // KR vs KB
|
||||||
KRKN, // KR vs KN
|
KRKN, // KR vs KN
|
||||||
|
KQKP, // KQ vs KP
|
||||||
KQKR, // KQ vs KR
|
KQKR, // KQ vs KR
|
||||||
KBBKN, // KBB vs KN
|
|
||||||
KNNK, // KNN vs K
|
|
||||||
KmmKm, // K and two minors vs K and one or two minors
|
|
||||||
|
|
||||||
|
SCALING_FUNCTIONS,
|
||||||
// Scaling functions
|
KBPsK, // KB and pawns vs K
|
||||||
|
KQKRPs, // KQ vs KR and pawns
|
||||||
KBPsK, // KB+pawns vs K
|
|
||||||
KQKRPs, // KQ vs KR+pawns
|
|
||||||
KRPKR, // KRP vs KR
|
KRPKR, // KRP vs KR
|
||||||
|
KRPKB, // KRP vs KB
|
||||||
KRPPKRP, // KRPP vs KRP
|
KRPPKRP, // KRPP vs KRP
|
||||||
KPsK, // King and pawns vs king
|
KPsK, // K and pawns vs K
|
||||||
KBPKB, // KBP vs KB
|
KBPKB, // KBP vs KB
|
||||||
KBPPKB, // KBPP vs KB
|
KBPPKB, // KBPP vs KB
|
||||||
KBPKN, // KBP vs KN
|
KBPKN, // KBP vs KN
|
||||||
KNPK, // KNP vs K
|
KNPK, // KNP vs K
|
||||||
|
KNPKB, // KNP vs KB
|
||||||
KPKP // KP vs KP
|
KPKP // KP vs KP
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Base and derived templates for endgame evaluation and scaling functions
|
/// Endgame functions can be of two types depending on whether they return a
|
||||||
|
/// Value or a ScaleFactor.
|
||||||
|
template<EndgameCode E> using
|
||||||
|
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
||||||
|
|
||||||
|
|
||||||
|
/// Base and derived functors for endgame evaluation and scaling functions
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct EndgameBase {
|
struct EndgameBase {
|
||||||
|
|
||||||
typedef EndgameBase<T> Base;
|
explicit EndgameBase(Color c) : strongSide(c), weakSide(~c) {}
|
||||||
|
virtual ~EndgameBase() = default;
|
||||||
|
virtual T operator()(const Position&) const = 0;
|
||||||
|
|
||||||
virtual ~EndgameBase() {}
|
const Color strongSide, weakSide;
|
||||||
virtual Color color() const = 0;
|
|
||||||
virtual T apply(const Position&) const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename T, EndgameType>
|
template<EndgameCode E, typename T = eg_type<E>>
|
||||||
struct Endgame : public EndgameBase<T> {
|
struct Endgame : public EndgameBase<T> {
|
||||||
|
|
||||||
explicit Endgame(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
|
explicit Endgame(Color c) : EndgameBase<T>(c) {}
|
||||||
Color color() const { return strongerSide; }
|
T operator()(const Position&) const override;
|
||||||
T apply(const Position&) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Color strongerSide, weakerSide;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Endgames class stores in two std::map the pointers to endgame evaluation
|
/// The Endgames class stores the pointers to endgame evaluation and scaling
|
||||||
/// and scaling base objects. Then we use polymorphism to invoke the actual
|
/// base objects in two std::map. We use polymorphism to invoke the actual
|
||||||
/// endgame function calling its apply() method that is virtual.
|
/// endgame function by calling its virtual operator().
|
||||||
|
|
||||||
class Endgames {
|
class Endgames {
|
||||||
|
|
||||||
typedef std::map<Key, EndgameBase<Value>* > EFMap;
|
template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
|
||||||
typedef std::map<Key, EndgameBase<ScaleFactor>* > SFMap;
|
template<typename T> using Map = std::map<Key, Ptr<T>>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Map<T>& map() {
|
||||||
|
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<EndgameCode E, typename T = eg_type<E>, typename P = Ptr<T>>
|
||||||
|
void add(const std::string& code) {
|
||||||
|
|
||||||
|
StateInfo st;
|
||||||
|
map<T>()[Position().set(code, WHITE, &st).material_key()] = P(new Endgame<E>(WHITE));
|
||||||
|
map<T>()[Position().set(code, BLACK, &st).material_key()] = P(new Endgame<E>(BLACK));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Endgames();
|
Endgames();
|
||||||
~Endgames();
|
|
||||||
template<class T> T* get(Key key) const;
|
|
||||||
|
|
||||||
private:
|
template<typename T>
|
||||||
template<class T> void add(const std::string& keyCode);
|
EndgameBase<T>* probe(Key key) {
|
||||||
|
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
|
||||||
// Here we store two maps, for evaluate and scaling functions...
|
}
|
||||||
std::pair<EFMap, SFMap> maps;
|
|
||||||
|
|
||||||
// ...and here is the accessing template function
|
|
||||||
template<typename T> const std::map<Key, T*>& get() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !defined(ENDGAME_H_INCLUDED)
|
#endif // #ifndef ENDGAME_H_INCLUDED
|
||||||
|
|||||||
+742
-1011
File diff suppressed because it is too large
Load Diff
+16
-6
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,15 +18,24 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(EVALUATE_H_INCLUDED)
|
#ifndef EVALUATE_H_INCLUDED
|
||||||
#define EVALUATE_H_INCLUDED
|
#define EVALUATE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
class Position;
|
class Position;
|
||||||
|
|
||||||
extern Value evaluate(const Position& pos, Value& margin);
|
namespace Eval {
|
||||||
extern std::string trace_evaluate(const Position& pos);
|
|
||||||
extern void read_evaluation_uci_options(Color sideToMove);
|
|
||||||
|
|
||||||
#endif // !defined(EVALUATE_H_INCLUDED)
|
const Value Tempo = Value(20); // Must be visible to search
|
||||||
|
|
||||||
|
extern Score Contempt;
|
||||||
|
|
||||||
|
std::string trace(const Position& pos);
|
||||||
|
|
||||||
|
Value evaluate(const Position& pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #ifndef EVALUATE_H_INCLUDED
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(HISTORY_H_INCLUDED)
|
|
||||||
#define HISTORY_H_INCLUDED
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
/// The History class stores statistics about how often different moves
|
|
||||||
/// have been successful or unsuccessful during the current search. These
|
|
||||||
/// statistics are used for reduction and move ordering decisions. History
|
|
||||||
/// entries are stored according only to moving piece and destination square,
|
|
||||||
/// in particular two moves with different origin but same destination and
|
|
||||||
/// same piece will be considered identical.
|
|
||||||
|
|
||||||
class History {
|
|
||||||
|
|
||||||
public:
|
|
||||||
void clear();
|
|
||||||
Value value(Piece p, Square to) const;
|
|
||||||
void update(Piece p, Square to, Value bonus);
|
|
||||||
Value gain(Piece p, Square to) const;
|
|
||||||
void update_gain(Piece p, Square to, Value g);
|
|
||||||
|
|
||||||
static const Value MaxValue = Value(2000);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Value history[16][64]; // [piece][to_square]
|
|
||||||
Value maxGains[16][64]; // [piece][to_square]
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void History::clear() {
|
|
||||||
memset(history, 0, 16 * 64 * sizeof(Value));
|
|
||||||
memset(maxGains, 0, 16 * 64 * sizeof(Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Value History::value(Piece p, Square to) const {
|
|
||||||
return history[p][to];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void History::update(Piece p, Square to, Value bonus) {
|
|
||||||
if (abs(history[p][to] + bonus) < MaxValue) history[p][to] += bonus;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Value History::gain(Piece p, Square to) const {
|
|
||||||
return maxGains[p][to];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void History::update_gain(Piece p, Square to, Value g) {
|
|
||||||
maxGains[p][to] = Max(g, maxGains[p][to] - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(HISTORY_H_INCLUDED)
|
|
||||||
-79
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(LOCK_H_INCLUDED)
|
|
||||||
#define LOCK_H_INCLUDED
|
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
|
||||||
|
|
||||||
# include <pthread.h>
|
|
||||||
|
|
||||||
typedef pthread_mutex_t Lock;
|
|
||||||
typedef pthread_cond_t WaitCondition;
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#undef WIN32_LEAN_AND_MEAN
|
|
||||||
|
|
||||||
// Default fast and race free locks and condition variables
|
|
||||||
#if !defined(OLD_LOCKS)
|
|
||||||
|
|
||||||
typedef SRWLOCK Lock;
|
|
||||||
typedef CONDITION_VARIABLE WaitCondition;
|
|
||||||
|
|
||||||
# define lock_init(x) InitializeSRWLock(x)
|
|
||||||
# define lock_grab(x) AcquireSRWLockExclusive(x)
|
|
||||||
# define lock_release(x) ReleaseSRWLockExclusive(x)
|
|
||||||
# define lock_destroy(x) (x)
|
|
||||||
# define cond_destroy(x) (x)
|
|
||||||
# define cond_init(x) InitializeConditionVariable(x)
|
|
||||||
# define cond_signal(x) WakeConditionVariable(x)
|
|
||||||
# define cond_wait(x,y) SleepConditionVariableSRW(x, y, INFINITE,0)
|
|
||||||
|
|
||||||
// Fallback solution to build for Windows XP and older versions, note that
|
|
||||||
// cond_wait() is racy between lock_release() and WaitForSingleObject().
|
|
||||||
#else
|
|
||||||
|
|
||||||
typedef CRITICAL_SECTION Lock;
|
|
||||||
typedef HANDLE WaitCondition;
|
|
||||||
|
|
||||||
# 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); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // !defined(LOCK_H_INCLUDED)
|
|
||||||
+23
-55
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,71 +18,38 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// To profile with callgrind uncomment following line
|
|
||||||
//#define USE_CALLGRIND
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "evaluate.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "thread.h"
|
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "ucioption.h"
|
#include "thread.h"
|
||||||
|
#include "tt.h"
|
||||||
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
#ifdef USE_CALLGRIND
|
namespace PSQT {
|
||||||
#include <valgrind/callgrind.h>
|
void init();
|
||||||
#endif
|
}
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
extern bool execute_uci_command(const string& cmd);
|
|
||||||
extern void benchmark(int argc, char* argv[]);
|
|
||||||
extern void init_kpk_bitbase();
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
// Disable IO buffering for C and C++ standard libraries
|
std::cout << engine_info() << std::endl;
|
||||||
setvbuf(stdin, NULL, _IONBF, 0);
|
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
|
||||||
cout.rdbuf()->pubsetbuf(NULL, 0);
|
|
||||||
cin.rdbuf()->pubsetbuf(NULL, 0);
|
|
||||||
|
|
||||||
// Startup initializations
|
UCI::init(Options);
|
||||||
init_bitboards();
|
PSQT::init();
|
||||||
Position::init_zobrist();
|
Bitboards::init();
|
||||||
Position::init_piece_square_tables();
|
Position::init();
|
||||||
init_kpk_bitbase();
|
Bitbases::init();
|
||||||
init_search();
|
Search::init();
|
||||||
Threads.init();
|
Pawns::init();
|
||||||
|
Tablebases::init(Options["SyzygyPath"]);
|
||||||
|
TT.resize(Options["Hash"]);
|
||||||
|
Threads.set(Options["Threads"]);
|
||||||
|
Search::clear(); // After threads are up
|
||||||
|
|
||||||
#ifdef USE_CALLGRIND
|
UCI::loop(argc, argv);
|
||||||
CALLGRIND_START_INSTRUMENTATION;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (argc < 2)
|
Threads.set(0);
|
||||||
{
|
|
||||||
// Print copyright notice
|
|
||||||
cout << engine_name() << " by " << engine_authors() << endl;
|
|
||||||
|
|
||||||
if (CpuHasPOPCNT)
|
|
||||||
cout << "Good! CPU has hardware POPCNT." << endl;
|
|
||||||
|
|
||||||
// Wait for a command from the user, and passes this command to
|
|
||||||
// execute_uci_command() and also intercepts EOF from stdin to
|
|
||||||
// ensure that we exit gracefully if the GUI dies unexpectedly.
|
|
||||||
string cmd;
|
|
||||||
while (getline(cin, cmd) && execute_uci_command(cmd)) {}
|
|
||||||
}
|
|
||||||
else if (string(argv[1]) == "bench" && argc < 8)
|
|
||||||
benchmark(argc, argv);
|
|
||||||
else
|
|
||||||
cout << "Usage: stockfish bench [hash size = 128] [threads = 1] "
|
|
||||||
<< "[limit = 12] [fen positions file = default] "
|
|
||||||
<< "[limited by depth, time, nodes or perft = depth]" << endl;
|
|
||||||
|
|
||||||
Threads.exit();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+159
-216
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,269 +18,211 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm> // For std::min
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring> // For std::memset
|
||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Values modified by Joona Kiiski
|
// Polynomial material imbalance parameters
|
||||||
const Value MidgameLimit = Value(15581);
|
|
||||||
const Value EndgameLimit = Value(3998);
|
|
||||||
|
|
||||||
// Scale factors used when one side has no more pawns
|
const int QuadraticOurs[][PIECE_TYPE_NB] = {
|
||||||
const int NoPawnsSF[4] = { 6, 12, 32 };
|
// OUR PIECES
|
||||||
|
// pair pawn knight bishop rook queen
|
||||||
|
{1667 }, // Bishop pair
|
||||||
|
{ 40, 0 }, // Pawn
|
||||||
|
{ 32, 255, -3 }, // Knight OUR PIECES
|
||||||
|
{ 0, 104, 4, 0 }, // Bishop
|
||||||
|
{ -26, -2, 47, 105, -149 }, // Rook
|
||||||
|
{-189, 24, 117, 133, -134, -10 } // Queen
|
||||||
|
};
|
||||||
|
|
||||||
// Polynomial material balance parameters
|
const int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
||||||
const Value RedundantQueenPenalty = Value(320);
|
// THEIR PIECES
|
||||||
const Value RedundantRookPenalty = Value(554);
|
// pair pawn knight bishop rook queen
|
||||||
|
{ 0 }, // Bishop pair
|
||||||
|
{ 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
|
||||||
|
};
|
||||||
|
|
||||||
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
// Endgame evaluation and scaling functions are accessed directly and not through
|
||||||
|
// the function maps because they correspond to more than one material hash key.
|
||||||
|
Endgame<KXK> EvaluateKXK[] = { Endgame<KXK>(WHITE), Endgame<KXK>(BLACK) };
|
||||||
|
|
||||||
const int QuadraticCoefficientsSameColor[][8] = {
|
Endgame<KBPsK> ScaleKBPsK[] = { Endgame<KBPsK>(WHITE), Endgame<KBPsK>(BLACK) };
|
||||||
{ 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 },
|
Endgame<KQKRPs> ScaleKQKRPs[] = { Endgame<KQKRPs>(WHITE), Endgame<KQKRPs>(BLACK) };
|
||||||
{ 7, 25, 4, 7, 7, 7 }, { -27, -2, 46, 100, 56, 7 }, { 58, 29, 83, 148, -3, -25 } };
|
Endgame<KPsK> ScaleKPsK[] = { Endgame<KPsK>(WHITE), Endgame<KPsK>(BLACK) };
|
||||||
|
Endgame<KPKP> ScaleKPKP[] = { Endgame<KPKP>(WHITE), Endgame<KPKP>(BLACK) };
|
||||||
|
|
||||||
const int QuadraticCoefficientsOppositeColor[][8] = {
|
// Helper used to detect a given material distribution
|
||||||
{ 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 },
|
bool is_KXK(const Position& pos, Color us) {
|
||||||
{ 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } };
|
return !more_than_one(pos.pieces(~us))
|
||||||
|
&& pos.non_pawn_material(us) >= RookValueMg;
|
||||||
// Endgame evaluation and scaling functions accessed direcly and not through
|
|
||||||
// the function maps because correspond to more then one material hash key.
|
|
||||||
Endgame<Value, KmmKm> EvaluateKmmKm[] = { Endgame<Value, KmmKm>(WHITE), Endgame<Value, KmmKm>(BLACK) };
|
|
||||||
Endgame<Value, KXK> EvaluateKXK[] = { Endgame<Value, KXK>(WHITE), Endgame<Value, KXK>(BLACK) };
|
|
||||||
|
|
||||||
Endgame<ScaleFactor, KBPsK> ScaleKBPsK[] = { Endgame<ScaleFactor, KBPsK>(WHITE), Endgame<ScaleFactor, KBPsK>(BLACK) };
|
|
||||||
Endgame<ScaleFactor, KQKRPs> ScaleKQKRPs[] = { Endgame<ScaleFactor, KQKRPs>(WHITE), Endgame<ScaleFactor, KQKRPs>(BLACK) };
|
|
||||||
Endgame<ScaleFactor, KPsK> ScaleKPsK[] = { Endgame<ScaleFactor, KPsK>(WHITE), Endgame<ScaleFactor, KPsK>(BLACK) };
|
|
||||||
Endgame<ScaleFactor, KPKP> ScaleKPKP[] = { Endgame<ScaleFactor, KPKP>(WHITE), Endgame<ScaleFactor, 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 pos.non_pawn_material(Them) == VALUE_ZERO
|
|
||||||
&& pos.piece_count(Them, PAWN) == 0
|
|
||||||
&& pos.non_pawn_material(Us) >= RookValueMidgame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us> bool is_KBPsKs(const Position& pos) {
|
bool is_KBPsKs(const Position& pos, Color us) {
|
||||||
return pos.non_pawn_material(Us) == BishopValueMidgame
|
return pos.non_pawn_material(us) == BishopValueMg
|
||||||
&& pos.piece_count(Us, BISHOP) == 1
|
&& pos.count<BISHOP>(us) == 1
|
||||||
&& pos.piece_count(Us, PAWN) >= 1;
|
&& pos.count<PAWN >(us) >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us> bool is_KQKRPs(const Position& pos) {
|
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);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
return pos.piece_count(Us, PAWN) == 0
|
|
||||||
&& pos.non_pawn_material(Us) == QueenValueMidgame
|
int bonus = 0;
|
||||||
&& pos.piece_count(Us, QUEEN) == 1
|
|
||||||
&& pos.piece_count(Them, ROOK) == 1
|
// Second-degree polynomial material imbalance, by Tord Romstad
|
||||||
&& pos.piece_count(Them, PAWN) >= 1;
|
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)
|
||||||
|
{
|
||||||
|
if (!pieceCount[Us][pt1])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int v = 0;
|
||||||
|
|
||||||
|
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; ++pt2)
|
||||||
|
v += QuadraticOurs[pt1][pt2] * pieceCount[Us][pt2]
|
||||||
|
+ QuadraticTheirs[pt1][pt2] * pieceCount[Them][pt2];
|
||||||
|
|
||||||
|
bonus += pieceCount[Us][pt1] * v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
namespace Material {
|
||||||
|
|
||||||
/// MaterialInfoTable c'tor and d'tor allocate and free the space for Endgames
|
/// Material::probe() looks up the current position's material configuration in
|
||||||
|
/// the material hash table. It returns a pointer to the Entry if the position
|
||||||
|
/// is found. Otherwise a new Entry is computed and stored there, so we don't
|
||||||
|
/// have to recompute all when the same material configuration occurs again.
|
||||||
|
|
||||||
void MaterialInfoTable::init() { Base::init(); if (!funcs) funcs = new Endgames(); }
|
Entry* probe(const Position& pos) {
|
||||||
MaterialInfoTable::~MaterialInfoTable() { delete funcs; }
|
|
||||||
|
|
||||||
|
Key key = pos.material_key();
|
||||||
|
Entry* e = pos.this_thread()->materialTable[key];
|
||||||
|
|
||||||
/// MaterialInfoTable::get_material_info() takes a position object as input,
|
if (e->key == key)
|
||||||
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
|
return e;
|
||||||
/// If the material configuration is not already present in the table, it
|
|
||||||
/// is stored there, so we don't have to recompute everything when the
|
|
||||||
/// same material configuration occurs again.
|
|
||||||
|
|
||||||
MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) const {
|
std::memset(e, 0, sizeof(Entry));
|
||||||
|
e->key = key;
|
||||||
Key key = pos.get_material_key();
|
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
|
||||||
MaterialInfo* mi = probe(key);
|
|
||||||
|
|
||||||
// If mi->key matches the position's material hash key, it means that we
|
|
||||||
// have analysed this material configuration before, and we can simply
|
|
||||||
// return the information we found the last time instead of recomputing it.
|
|
||||||
if (mi->key == key)
|
|
||||||
return mi;
|
|
||||||
|
|
||||||
// Initialize MaterialInfo entry
|
|
||||||
memset(mi, 0, sizeof(MaterialInfo));
|
|
||||||
mi->key = key;
|
|
||||||
mi->factor[WHITE] = mi->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
|
|
||||||
|
|
||||||
// Store game phase
|
|
||||||
mi->gamePhase = MaterialInfoTable::game_phase(pos);
|
|
||||||
|
|
||||||
// Let's look if we have a specialized evaluation function for this
|
|
||||||
// particular material configuration. First we look for a fixed
|
|
||||||
// configuration one, then a generic one if previous search failed.
|
|
||||||
if ((mi->evaluationFunction = funcs->get<EndgameBase<Value> >(key)) != NULL)
|
|
||||||
return mi;
|
|
||||||
|
|
||||||
if (is_KXK<WHITE>(pos))
|
|
||||||
{
|
|
||||||
mi->evaluationFunction = &EvaluateKXK[WHITE];
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_KXK<BLACK>(pos))
|
|
||||||
{
|
|
||||||
mi->evaluationFunction = &EvaluateKXK[BLACK];
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pos.pieces(PAWN) && !pos.pieces(ROOK) && !pos.pieces(QUEEN))
|
|
||||||
{
|
|
||||||
// Minor piece endgame with at least one minor piece per side and
|
|
||||||
// no pawns. Note that the case KmmK is already handled by KXK.
|
|
||||||
assert((pos.pieces(KNIGHT, WHITE) | pos.pieces(BISHOP, WHITE)));
|
|
||||||
assert((pos.pieces(KNIGHT, BLACK) | pos.pieces(BISHOP, BLACK)));
|
|
||||||
|
|
||||||
if ( pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
|
|
||||||
&& pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
|
|
||||||
{
|
|
||||||
mi->evaluationFunction = &EvaluateKmmKm[WHITE];
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OK, we didn't find any special evaluation function for the current
|
|
||||||
// material configuration. Is there a suitable scaling function?
|
|
||||||
//
|
|
||||||
// We face problems when there are several conflicting applicable
|
|
||||||
// scaling functions and we need to decide which one to use.
|
|
||||||
EndgameBase<ScaleFactor>* sf;
|
|
||||||
|
|
||||||
if ((sf = funcs->get<EndgameBase<ScaleFactor> >(key)) != NULL)
|
|
||||||
{
|
|
||||||
mi->scalingFunction[sf->color()] = sf;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generic scaling functions that refer to more then one material
|
|
||||||
// distribution. Should be probed after the specialized ones.
|
|
||||||
// Note that these ones don't return after setting the function.
|
|
||||||
if (is_KBPsKs<WHITE>(pos))
|
|
||||||
mi->scalingFunction[WHITE] = &ScaleKBPsK[WHITE];
|
|
||||||
|
|
||||||
if (is_KBPsKs<BLACK>(pos))
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKBPsK[BLACK];
|
|
||||||
|
|
||||||
if (is_KQKRPs<WHITE>(pos))
|
|
||||||
mi->scalingFunction[WHITE] = &ScaleKQKRPs[WHITE];
|
|
||||||
|
|
||||||
else if (is_KQKRPs<BLACK>(pos))
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
|
|
||||||
|
|
||||||
Value npm_w = pos.non_pawn_material(WHITE);
|
Value npm_w = pos.non_pawn_material(WHITE);
|
||||||
Value npm_b = pos.non_pawn_material(BLACK);
|
Value npm_b = pos.non_pawn_material(BLACK);
|
||||||
|
Value npm = std::max(EndgameLimit, std::min(npm_w + npm_b, MidgameLimit));
|
||||||
|
|
||||||
if (npm_w + npm_b == VALUE_ZERO)
|
// 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 ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)
|
||||||
|
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;
|
||||||
|
|
||||||
|
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
|
||||||
{
|
{
|
||||||
if (pos.piece_count(BLACK, PAWN) == 0)
|
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.
|
||||||
|
for (Color c = WHITE; c <= BLACK; ++c)
|
||||||
|
{
|
||||||
|
if (is_KBPsKs(pos, c))
|
||||||
|
e->scalingFunction[c] = &ScaleKBPsK[c];
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
if (!pos.count<PAWN>(BLACK))
|
||||||
{
|
{
|
||||||
assert(pos.piece_count(WHITE, PAWN) >= 2);
|
assert(pos.count<PAWN>(WHITE) >= 2);
|
||||||
mi->scalingFunction[WHITE] = &ScaleKPsK[WHITE];
|
|
||||||
|
e->scalingFunction[WHITE] = &ScaleKPsK[WHITE];
|
||||||
}
|
}
|
||||||
else if (pos.piece_count(WHITE, PAWN) == 0)
|
else if (!pos.count<PAWN>(WHITE))
|
||||||
{
|
{
|
||||||
assert(pos.piece_count(BLACK, PAWN) >= 2);
|
assert(pos.count<PAWN>(BLACK) >= 2);
|
||||||
mi->scalingFunction[BLACK] = &ScaleKPsK[BLACK];
|
|
||||||
|
e->scalingFunction[BLACK] = &ScaleKPsK[BLACK];
|
||||||
}
|
}
|
||||||
else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
|
else if (pos.count<PAWN>(WHITE) == 1 && pos.count<PAWN>(BLACK) == 1)
|
||||||
{
|
{
|
||||||
// This is a special case because we set scaling functions
|
// This is a special case because we set scaling functions
|
||||||
// for both colors instead of only one.
|
// for both colors instead of only one.
|
||||||
mi->scalingFunction[WHITE] = &ScaleKPKP[WHITE];
|
e->scalingFunction[WHITE] = &ScaleKPKP[WHITE];
|
||||||
mi->scalingFunction[BLACK] = &ScaleKPKP[BLACK];
|
e->scalingFunction[BLACK] = &ScaleKPKP[BLACK];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No pawns makes it difficult to win, even with a material advantage
|
// Zero or just one pawn makes it difficult to win, even with a small material
|
||||||
if (pos.piece_count(WHITE, PAWN) == 0 && npm_w - npm_b <= BishopValueMidgame)
|
// advantage. This catches some trivial draws like KK, KBK and KNK and gives a
|
||||||
{
|
// drawish scale factor for cases such as KRKBP and KmmKm (except for KBBKN).
|
||||||
mi->factor[WHITE] = uint8_t
|
if (!pos.count<PAWN>(WHITE) && npm_w - npm_b <= BishopValueMg)
|
||||||
(npm_w == npm_b || npm_w < RookValueMidgame ? 0 : NoPawnsSF[Min(pos.piece_count(WHITE, BISHOP), 2)]);
|
e->factor[WHITE] = uint8_t(npm_w < RookValueMg ? SCALE_FACTOR_DRAW :
|
||||||
}
|
npm_b <= BishopValueMg ? 4 : 14);
|
||||||
|
|
||||||
if (pos.piece_count(BLACK, PAWN) == 0 && npm_b - npm_w <= BishopValueMidgame)
|
if (!pos.count<PAWN>(BLACK) && npm_b - npm_w <= BishopValueMg)
|
||||||
{
|
e->factor[BLACK] = uint8_t(npm_b < RookValueMg ? SCALE_FACTOR_DRAW :
|
||||||
mi->factor[BLACK] = uint8_t
|
npm_w <= BishopValueMg ? 4 : 14);
|
||||||
(npm_w == npm_b || npm_b < RookValueMidgame ? 0 : NoPawnsSF[Min(pos.piece_count(BLACK, BISHOP), 2)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute the space weight
|
if (pos.count<PAWN>(WHITE) == 1 && npm_w - npm_b <= BishopValueMg)
|
||||||
if (npm_w + npm_b >= 2 * QueenValueMidgame + 4 * RookValueMidgame + 2 * KnightValueMidgame)
|
e->factor[WHITE] = (uint8_t) SCALE_FACTOR_ONEPAWN;
|
||||||
{
|
|
||||||
int minorPieceCount = pos.piece_count(WHITE, KNIGHT) + pos.piece_count(WHITE, BISHOP)
|
|
||||||
+ pos.piece_count(BLACK, KNIGHT) + pos.piece_count(BLACK, BISHOP);
|
|
||||||
|
|
||||||
mi->spaceWeight = minorPieceCount * minorPieceCount;
|
if (pos.count<PAWN>(BLACK) == 1 && npm_b - npm_w <= BishopValueMg)
|
||||||
}
|
e->factor[BLACK] = (uint8_t) SCALE_FACTOR_ONEPAWN;
|
||||||
|
|
||||||
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
||||||
// for the bishop pair "extended piece", this allow us to be more flexible
|
// for the bishop pair "extended piece", which allows us to be more flexible
|
||||||
// in defining bishop pair bonuses.
|
// in defining bishop pair bonuses.
|
||||||
const int pieceCount[2][8] = {
|
const int PieceCount[COLOR_NB][PIECE_TYPE_NB] = {
|
||||||
{ pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT),
|
{ pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
|
||||||
pos.piece_count(WHITE, BISHOP) , pos.piece_count(WHITE, ROOK), pos.piece_count(WHITE, QUEEN) },
|
pos.count<BISHOP>(WHITE) , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
|
||||||
{ pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
|
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
|
||||||
pos.piece_count(BLACK, BISHOP) , pos.piece_count(BLACK, ROOK), pos.piece_count(BLACK, QUEEN) } };
|
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
|
||||||
|
|
||||||
mi->value = int16_t((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
|
e->value = int16_t((imbalance<WHITE>(PieceCount) - imbalance<BLACK>(PieceCount)) / 16);
|
||||||
return mi;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Material
|
||||||
/// MaterialInfoTable::imbalance() calculates imbalance comparing piece count of each
|
|
||||||
/// piece type for both colors.
|
|
||||||
|
|
||||||
template<Color Us>
|
|
||||||
int MaterialInfoTable::imbalance(const int pieceCount[][8]) {
|
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
|
||||||
|
|
||||||
int pt1, pt2, pc, v;
|
|
||||||
int value = 0;
|
|
||||||
|
|
||||||
// Redundancy of major pieces, formula based on Kaufman's paper
|
|
||||||
// "The Evaluation of Material Imbalances in Chess"
|
|
||||||
if (pieceCount[Us][ROOK] > 0)
|
|
||||||
value -= RedundantRookPenalty * (pieceCount[Us][ROOK] - 1)
|
|
||||||
+ RedundantQueenPenalty * pieceCount[Us][QUEEN];
|
|
||||||
|
|
||||||
// Second-degree polynomial material imbalance by Tord Romstad
|
|
||||||
for (pt1 = PIECE_TYPE_NONE; pt1 <= QUEEN; pt1++)
|
|
||||||
{
|
|
||||||
pc = pieceCount[Us][pt1];
|
|
||||||
if (!pc)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
v = LinearCoefficients[pt1];
|
|
||||||
|
|
||||||
for (pt2 = PIECE_TYPE_NONE; pt2 <= pt1; pt2++)
|
|
||||||
v += QuadraticCoefficientsSameColor[pt1][pt2] * pieceCount[Us][pt2]
|
|
||||||
+ QuadraticCoefficientsOppositeColor[pt1][pt2] * pieceCount[Them][pt2];
|
|
||||||
|
|
||||||
value += pc * v;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// MaterialInfoTable::game_phase() calculates the phase given the current
|
|
||||||
/// position. Because the phase is strictly a function of the material, it
|
|
||||||
/// is stored in MaterialInfo.
|
|
||||||
|
|
||||||
Phase MaterialInfoTable::game_phase(const Position& pos) {
|
|
||||||
|
|
||||||
Value npm = pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK);
|
|
||||||
|
|
||||||
return npm >= MidgameLimit ? PHASE_MIDGAME
|
|
||||||
: npm <= EndgameLimit ? PHASE_ENDGAME
|
|
||||||
: Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
|
|
||||||
}
|
|
||||||
|
|||||||
+35
-79
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,101 +18,56 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(MATERIAL_H_INCLUDED)
|
#ifndef MATERIAL_H_INCLUDED
|
||||||
#define MATERIAL_H_INCLUDED
|
#define MATERIAL_H_INCLUDED
|
||||||
|
|
||||||
#include "endgame.h"
|
#include "endgame.h"
|
||||||
|
#include "misc.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "tt.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
const int MaterialTableSize = 8192;
|
namespace Material {
|
||||||
|
|
||||||
/// MaterialInfo is a class which contains various information about a
|
/// Material::Entry contains various information about a material configuration.
|
||||||
/// material configuration. It contains a material balance evaluation,
|
/// It contains a material imbalance evaluation, a function pointer to a special
|
||||||
/// a function pointer to a special endgame evaluation function (which in
|
/// endgame evaluation function (which in most cases is NULL, meaning that the
|
||||||
/// most cases is NULL, meaning that the standard evaluation function will
|
/// standard evaluation function will be used), and scale factors.
|
||||||
/// be used), and "scale factors" for black and white.
|
|
||||||
///
|
///
|
||||||
/// The scale factors are used to scale the evaluation score up or down.
|
/// The scale factors are used to scale the evaluation score up or down. For
|
||||||
/// For instance, in KRB vs KR endgames, the score is scaled down by a factor
|
/// instance, in KRB vs KR endgames, the score is scaled down by a factor of 4,
|
||||||
/// of 4, which will result in scores of absolute value less than one pawn.
|
/// which will result in scores of absolute value less than one pawn.
|
||||||
|
|
||||||
class MaterialInfo {
|
struct Entry {
|
||||||
|
|
||||||
friend class MaterialInfoTable;
|
Score imbalance() const { return make_score(value, value); }
|
||||||
|
Phase game_phase() const { return gamePhase; }
|
||||||
|
bool specialized_eval_exists() const { return evaluationFunction != nullptr; }
|
||||||
|
Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
|
||||||
|
|
||||||
public:
|
// scale_factor takes a position and a color as input and returns a scale factor
|
||||||
Score material_value() const;
|
// for the given color. We have to provide the position in addition to the color
|
||||||
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
// because the scale factor may also be a function which should be applied to
|
||||||
int space_weight() const;
|
// the position. For instance, in KBP vs K endgames, the scaling function looks
|
||||||
Phase game_phase() const;
|
// for rook pawns and wrong-colored bishops.
|
||||||
bool specialized_eval_exists() const;
|
ScaleFactor scale_factor(const Position& pos, Color c) const {
|
||||||
Value evaluate(const Position& pos) const;
|
ScaleFactor sf = scalingFunction[c] ? (*scalingFunction[c])(pos)
|
||||||
|
: SCALE_FACTOR_NONE;
|
||||||
|
return sf != SCALE_FACTOR_NONE ? sf : ScaleFactor(factor[c]);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
Key key;
|
Key key;
|
||||||
int16_t value;
|
|
||||||
uint8_t factor[2];
|
|
||||||
EndgameBase<Value>* evaluationFunction;
|
EndgameBase<Value>* evaluationFunction;
|
||||||
EndgameBase<ScaleFactor>* scalingFunction[2];
|
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
||||||
int spaceWeight;
|
// side (e.g. KPKP, KBPsKs)
|
||||||
|
int16_t value;
|
||||||
|
uint8_t factor[COLOR_NB];
|
||||||
Phase gamePhase;
|
Phase gamePhase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef HashTable<Entry, 8192> Table;
|
||||||
|
|
||||||
/// The MaterialInfoTable class represents a pawn hash table. The most important
|
Entry* probe(const Position& pos);
|
||||||
/// method is get_material_info, which returns a pointer to a MaterialInfo object.
|
|
||||||
|
|
||||||
class MaterialInfoTable : public SimpleHash<MaterialInfo, MaterialTableSize> {
|
} // namespace Material
|
||||||
public:
|
|
||||||
~MaterialInfoTable();
|
|
||||||
void init();
|
|
||||||
MaterialInfo* get_material_info(const Position& pos) const;
|
|
||||||
static Phase game_phase(const Position& pos);
|
|
||||||
|
|
||||||
private:
|
#endif // #ifndef MATERIAL_H_INCLUDED
|
||||||
template<Color Us>
|
|
||||||
static int imbalance(const int pieceCount[][8]);
|
|
||||||
|
|
||||||
Endgames* funcs;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// MaterialInfo::scale_factor takes a position and a color as input, and
|
|
||||||
/// returns a scale factor for the given color. We have to provide the
|
|
||||||
/// position in addition to the color, because the scale factor need not
|
|
||||||
/// to be a constant: It can also be a function which should be applied to
|
|
||||||
/// the position. For instance, in KBP vs K endgames, a scaling function
|
|
||||||
/// which checks for draws with rook pawns and wrong-colored bishops.
|
|
||||||
|
|
||||||
inline ScaleFactor MaterialInfo::scale_factor(const Position& pos, Color c) const {
|
|
||||||
|
|
||||||
if (!scalingFunction[c])
|
|
||||||
return ScaleFactor(factor[c]);
|
|
||||||
|
|
||||||
ScaleFactor sf = scalingFunction[c]->apply(pos);
|
|
||||||
return sf == SCALE_FACTOR_NONE ? ScaleFactor(factor[c]) : sf;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Value MaterialInfo::evaluate(const Position& pos) const {
|
|
||||||
return evaluationFunction->apply(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Score MaterialInfo::material_value() const {
|
|
||||||
return make_score(value, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int MaterialInfo::space_weight() const {
|
|
||||||
return spaceWeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Phase MaterialInfo::game_phase() const {
|
|
||||||
return gamePhase;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool MaterialInfo::specialized_eval_exists() const {
|
|
||||||
return evaluationFunction != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(MATERIAL_H_INCLUDED)
|
|
||||||
|
|||||||
+232
-185
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,254 +18,300 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#ifdef _WIN32
|
||||||
|
#if _WIN32_WINNT < 0x0601
|
||||||
# include <sys/time.h>
|
#undef _WIN32_WINNT
|
||||||
# include <sys/types.h>
|
#define _WIN32_WINNT 0x0601 // Force to include needed API prototypes
|
||||||
# include <unistd.h>
|
#endif
|
||||||
# if defined(__hpux)
|
|
||||||
# include <sys/pstat.h>
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define _CRT_SECURE_NO_DEPRECATE
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <sys/timeb.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
|
#endif
|
||||||
|
|
||||||
#if !defined(NO_PREFETCH)
|
#include <fstream>
|
||||||
# include <xmmintrin.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "bitcount.h"
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/// Version number. If EngineVersion is left empty, then AppTag plus
|
namespace {
|
||||||
/// current date (in the format YYMMDD) is used as a version number.
|
|
||||||
|
|
||||||
static const string AppName = "Stockfish";
|
/// Version number. If Version is left empty, then compile date in the format
|
||||||
static const string EngineVersion = "2.1";
|
/// DD-MM-YY and show in engine_info.
|
||||||
static const string AppTag = "";
|
const string Version = "9";
|
||||||
|
|
||||||
|
/// 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!
|
||||||
|
/// Idea from http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81
|
||||||
|
|
||||||
/// engine_name() returns the full name of the current Stockfish version.
|
struct Tie: public streambuf { // MSVC requires split streambuf for cin and cout
|
||||||
/// This will be either "Stockfish YYMMDD" (where YYMMDD is the date when
|
|
||||||
/// the program was compiled) or "Stockfish <version number>", depending
|
|
||||||
/// on whether the constant EngineVersion is empty.
|
|
||||||
|
|
||||||
const string engine_name() {
|
Tie(streambuf* b, streambuf* l) : buf(b), logBuf(l) {}
|
||||||
|
|
||||||
|
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, *logBuf;
|
||||||
|
|
||||||
|
int log(int c, const char* prefix) {
|
||||||
|
|
||||||
|
static int last = '\n'; // Single log file
|
||||||
|
|
||||||
|
if (last == '\n')
|
||||||
|
logBuf->sputn(prefix, 3);
|
||||||
|
|
||||||
|
return last = logBuf->sputc((char)c);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
|
||||||
|
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
|
||||||
|
~Logger() { start(""); }
|
||||||
|
|
||||||
|
ofstream file;
|
||||||
|
Tie in, out;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void start(const std::string& fname) {
|
||||||
|
|
||||||
|
static Logger l;
|
||||||
|
|
||||||
|
if (!fname.empty() && !l.file.is_open())
|
||||||
|
{
|
||||||
|
l.file.open(fname, ifstream::out);
|
||||||
|
cin.rdbuf(&l.in);
|
||||||
|
cout.rdbuf(&l.out);
|
||||||
|
}
|
||||||
|
else if (fname.empty() && l.file.is_open())
|
||||||
|
{
|
||||||
|
cout.rdbuf(l.out.buf);
|
||||||
|
cin.rdbuf(l.in.buf);
|
||||||
|
l.file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
/// engine_info() returns the full name of the current Stockfish version. This
|
||||||
|
/// will be either "Stockfish <Tag> DD-MM-YY" (where DD-MM-YY is the date when
|
||||||
|
/// the program was compiled) or "Stockfish <Version>", depending on whether
|
||||||
|
/// Version is empty.
|
||||||
|
|
||||||
|
const string engine_info(bool to_uci) {
|
||||||
|
|
||||||
const string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
|
const string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
|
||||||
const string cpu64(CpuIs64Bit ? " 64bit" : "");
|
|
||||||
|
|
||||||
if (!EngineVersion.empty())
|
|
||||||
return AppName + " " + EngineVersion + cpu64;
|
|
||||||
|
|
||||||
stringstream s, date(__DATE__); // From compiler, format is "Sep 21 2008"
|
|
||||||
string month, day, year;
|
string month, day, year;
|
||||||
|
stringstream ss, date(__DATE__); // From compiler, format is "Sep 21 2008"
|
||||||
|
|
||||||
date >> month >> day >> year;
|
ss << "Stockfish " << Version << setfill('0');
|
||||||
|
|
||||||
s << setfill('0') << AppName + " " + AppTag + " "
|
if (Version.empty())
|
||||||
<< year.substr(2, 2) << setw(2)
|
{
|
||||||
<< (1 + months.find(month) / 4) << setw(2)
|
date >> month >> day >> year;
|
||||||
<< day << cpu64;
|
ss << setw(2) << day << setw(2) << (1 + months.find(month) / 4) << year.substr(2);
|
||||||
|
}
|
||||||
|
|
||||||
return s.str();
|
ss << (Is64Bit ? " 64" : "")
|
||||||
|
<< (HasPext ? " BMI2" : (HasPopCnt ? " POPCNT" : ""))
|
||||||
|
<< (to_uci ? "\nid author ": " by ")
|
||||||
|
<< "T. Romstad, M. Costalba, J. Kiiski, G. Linscott";
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Our brave developers! Required by UCI
|
/// Debug functions used mainly to collect run-time statistics
|
||||||
|
static int64_t hits[2], means[2];
|
||||||
|
|
||||||
const string engine_authors() {
|
void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; }
|
||||||
|
void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); }
|
||||||
|
void dbg_mean_of(int v) { ++means[0]; means[1] += v; }
|
||||||
|
|
||||||
return "Tord Romstad, Marco Costalba and Joona Kiiski";
|
void dbg_print() {
|
||||||
|
|
||||||
|
if (hits[0])
|
||||||
|
cerr << "Total " << hits[0] << " Hits " << hits[1]
|
||||||
|
<< " hit rate (%) " << 100 * hits[1] / hits[0] << endl;
|
||||||
|
|
||||||
|
if (means[0])
|
||||||
|
cerr << "Total " << means[0] << " Mean "
|
||||||
|
<< (double)means[1] / means[0] << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Debug stuff. Helper functions used mainly for debugging purposes
|
/// Used to serialize access to std::cout to avoid multiple threads writing at
|
||||||
|
/// the same time.
|
||||||
|
|
||||||
static uint64_t dbg_hit_cnt0;
|
std::ostream& operator<<(std::ostream& os, SyncCout sc) {
|
||||||
static uint64_t dbg_hit_cnt1;
|
|
||||||
static uint64_t dbg_mean_cnt0;
|
|
||||||
static uint64_t dbg_mean_cnt1;
|
|
||||||
|
|
||||||
void dbg_print_hit_rate() {
|
static Mutex m;
|
||||||
|
|
||||||
if (dbg_hit_cnt0)
|
if (sc == IO_LOCK)
|
||||||
cout << "Total " << dbg_hit_cnt0 << " Hit " << dbg_hit_cnt1
|
m.lock();
|
||||||
<< " hit rate (%) " << 100 * dbg_hit_cnt1 / dbg_hit_cnt0 << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbg_print_mean() {
|
if (sc == IO_UNLOCK)
|
||||||
|
m.unlock();
|
||||||
|
|
||||||
if (dbg_mean_cnt0)
|
return os;
|
||||||
cout << "Total " << dbg_mean_cnt0 << " Mean "
|
|
||||||
<< (float)dbg_mean_cnt1 / dbg_mean_cnt0 << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbg_mean_of(int v) {
|
|
||||||
|
|
||||||
dbg_mean_cnt0++;
|
|
||||||
dbg_mean_cnt1 += v;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbg_hit_on(bool b) {
|
|
||||||
|
|
||||||
dbg_hit_cnt0++;
|
|
||||||
if (b)
|
|
||||||
dbg_hit_cnt1++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); }
|
|
||||||
void dbg_before() { dbg_hit_on(false); }
|
|
||||||
void dbg_after() { dbg_hit_on(true); dbg_hit_cnt0--; }
|
|
||||||
|
|
||||||
|
|
||||||
/// get_system_time() returns the current system time, measured in milliseconds
|
|
||||||
|
|
||||||
int get_system_time() {
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
struct _timeb t;
|
|
||||||
_ftime(&t);
|
|
||||||
return int(t.time * 1000 + t.millitm);
|
|
||||||
#else
|
|
||||||
struct timeval t;
|
|
||||||
gettimeofday(&t, NULL);
|
|
||||||
return t.tv_sec * 1000 + t.tv_usec / 1000;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// cpu_count() tries to detect the number of CPU cores
|
/// Trampoline helper to avoid moving Logger to misc.h
|
||||||
|
void start_logger(const std::string& fname) { Logger::start(fname); }
|
||||||
|
|
||||||
int cpu_count() {
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
/// prefetch() preloads the given address in L1/L2 cache. This is a non-blocking
|
||||||
SYSTEM_INFO s;
|
/// function that doesn't stall the CPU waiting for data to be loaded from memory,
|
||||||
GetSystemInfo(&s);
|
/// which can be quite slow.
|
||||||
return Min(s.dwNumberOfProcessors, MAX_THREADS);
|
#ifdef NO_PREFETCH
|
||||||
|
|
||||||
|
void prefetch(void*) {}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# if defined(_SC_NPROCESSORS_ONLN)
|
void prefetch(void* addr) {
|
||||||
return Min(sysconf(_SC_NPROCESSORS_ONLN), MAX_THREADS);
|
|
||||||
# elif defined(__hpux)
|
# if defined(__INTEL_COMPILER)
|
||||||
struct pst_dynamic psd;
|
// This hack prevents prefetches from being optimized away by
|
||||||
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) == -1)
|
// Intel compiler. Both MSVC and gcc seem not be affected by this.
|
||||||
return 1;
|
__asm__ ("");
|
||||||
return Min(psd.psd_proc_cnt, MAX_THREADS);
|
|
||||||
# else
|
|
||||||
return 1;
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#endif
|
# if defined(__INTEL_COMPILER) || defined(_MSC_VER)
|
||||||
|
_mm_prefetch((char*)addr, _MM_HINT_T0);
|
||||||
|
# else
|
||||||
|
__builtin_prefetch(addr);
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Check for console input. Original code from Beowulf, Olithink and Greko
|
void prefetch2(void* addr) {
|
||||||
|
|
||||||
|
prefetch(addr);
|
||||||
|
prefetch((uint8_t*)addr + 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace WinProcGroup {
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
|
||||||
int input_available() {
|
void bindThisThread(size_t) {}
|
||||||
|
|
||||||
fd_set readfds;
|
|
||||||
struct timeval timeout;
|
|
||||||
|
|
||||||
FD_ZERO(&readfds);
|
|
||||||
FD_SET(fileno(stdin), &readfds);
|
|
||||||
timeout.tv_sec = 0; // Set to timeout immediately
|
|
||||||
timeout.tv_usec = 0;
|
|
||||||
select(16, &readfds, 0, 0, &timeout);
|
|
||||||
|
|
||||||
return (FD_ISSET(fileno(stdin), &readfds));
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int input_available() {
|
/// get_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.
|
||||||
|
|
||||||
static HANDLE inh = NULL;
|
int get_group(size_t idx) {
|
||||||
static bool usePipe = false;
|
|
||||||
INPUT_RECORD rec[256];
|
|
||||||
DWORD nchars, recCnt;
|
|
||||||
|
|
||||||
if (!inh)
|
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)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))
|
||||||
{
|
{
|
||||||
inh = GetStdHandle(STD_INPUT_HANDLE);
|
free(buffer);
|
||||||
if (GetConsoleMode(inh, &nchars))
|
return -1;
|
||||||
{
|
|
||||||
SetConsoleMode(inh, nchars & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT));
|
|
||||||
FlushConsoleInputBuffer(inh);
|
|
||||||
} else
|
|
||||||
usePipe = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// When using Standard C input functions, also check if there
|
while (ptr->Size > 0 && byteOffset + ptr->Size <= returnLength)
|
||||||
// is anything in the buffer. After a call to such functions,
|
{
|
||||||
// the input waiting in the pipe will be copied to the buffer,
|
if (ptr->Relationship == RelationNumaNode)
|
||||||
// and the call to PeekNamedPipe can indicate no input available.
|
nodes++;
|
||||||
// Setting stdin to unbuffered was not enough. [from Greko]
|
|
||||||
if (stdin->_cnt > 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// When running under a GUI the input commands are sent to us
|
else if (ptr->Relationship == RelationProcessorCore)
|
||||||
// directly over the internal pipe. If PeekNamedPipe() returns 0
|
{
|
||||||
// then something went wrong. Probably the parent program exited.
|
cores++;
|
||||||
// Returning 1 will make the next call to the input function
|
threads += (ptr->Processor.Flags == LTP_PC_SMT) ? 2 : 1;
|
||||||
// return EOF, where this should be catched then.
|
}
|
||||||
if (usePipe)
|
|
||||||
return PeekNamedPipe(inh, NULL, 0, NULL, &nchars, NULL) ? nchars : 1;
|
|
||||||
|
|
||||||
// Count the number of unread input records, including keyboard,
|
byteOffset += ptr->Size;
|
||||||
// mouse, and window-resizing input records.
|
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((char*)ptr) + ptr->Size);
|
||||||
GetNumberOfConsoleInputEvents(inh, &nchars);
|
}
|
||||||
|
|
||||||
// Read data from console without removing it from the buffer
|
free(buffer);
|
||||||
if (nchars <= 0 || !PeekConsoleInput(inh, rec, Min(nchars, 256), &recCnt))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Search for at least one keyboard event
|
std::vector<int> groups;
|
||||||
for (DWORD i = 0; i < recCnt; i++)
|
|
||||||
if (rec[i].EventType == KEY_EVENT)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
// 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 = get_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)GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
|
||||||
|
auto fun3 = (fun3_t)GetProcAddress(k32, "SetThreadGroupAffinity");
|
||||||
|
|
||||||
|
if (!fun2 || !fun3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GROUP_AFFINITY affinity;
|
||||||
|
if (fun2(group, &affinity))
|
||||||
|
fun3(GetCurrentThread(), &affinity, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
} // namespace WinProcGroup
|
||||||
/// prefetch() preloads the given address in L1/L2 cache. This is a non
|
|
||||||
/// blocking function and do not stalls the CPU waiting for data to be
|
|
||||||
/// loaded from memory, that can be quite slow.
|
|
||||||
#if defined(NO_PREFETCH)
|
|
||||||
|
|
||||||
void prefetch(char*) {}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
void prefetch(char* addr) {
|
|
||||||
|
|
||||||
#if defined(__INTEL_COMPILER) || defined(__ICL)
|
|
||||||
// This hack prevents prefetches to be optimized away by
|
|
||||||
// Intel compiler. Both MSVC and gcc seems not affected.
|
|
||||||
__asm__ ("");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_mm_prefetch(addr, _MM_HINT_T2);
|
|
||||||
_mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
+87
-16
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,25 +18,95 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(MISC_H_INCLUDED)
|
#ifndef MISC_H_INCLUDED
|
||||||
#define MISC_H_INCLUDED
|
#define MISC_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <chrono>
|
||||||
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
extern const std::string engine_name();
|
const std::string engine_info(bool to_uci = false);
|
||||||
extern const std::string engine_authors();
|
void prefetch(void* addr);
|
||||||
extern int get_system_time();
|
void prefetch2(void* addr);
|
||||||
extern int cpu_count();
|
void start_logger(const std::string& fname);
|
||||||
extern int input_available();
|
|
||||||
extern void prefetch(char* addr);
|
|
||||||
|
|
||||||
extern void dbg_hit_on(bool b);
|
void dbg_hit_on(bool b);
|
||||||
extern void dbg_hit_on_c(bool c, bool b);
|
void dbg_hit_on(bool c, bool b);
|
||||||
extern void dbg_before();
|
void dbg_mean_of(int v);
|
||||||
extern void dbg_after();
|
void dbg_print();
|
||||||
extern void dbg_mean_of(int v);
|
|
||||||
extern void dbg_print_hit_rate();
|
|
||||||
extern void dbg_print_mean();
|
|
||||||
|
|
||||||
#endif // !defined(MISC_H_INCLUDED)
|
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
||||||
|
|
||||||
|
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 {
|
||||||
|
Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Entry> table = std::vector<Entry>(Size);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum SyncCout { IO_LOCK, IO_UNLOCK };
|
||||||
|
std::ostream& operator<<(std::ostream&, SyncCout);
|
||||||
|
|
||||||
|
#define sync_cout std::cout << IO_LOCK
|
||||||
|
#define sync_endl std::endl << IO_UNLOCK
|
||||||
|
|
||||||
|
|
||||||
|
/// xorshift64star Pseudo-Random Number Generator
|
||||||
|
/// This class is based on original code written and dedicated
|
||||||
|
/// to the public domain by Sebastiano Vigna (2014).
|
||||||
|
/// It has the following characteristics:
|
||||||
|
///
|
||||||
|
/// - Outputs 64-bit numbers
|
||||||
|
/// - Passes Dieharder and SmallCrush test batteries
|
||||||
|
/// - Does not require warm-up, no zeroland to escape
|
||||||
|
/// - Internal state is a single 64-bit integer
|
||||||
|
/// - Period is 2^64 - 1
|
||||||
|
/// - Speed: 1.60 ns/call (Core i7 @3.40GHz)
|
||||||
|
///
|
||||||
|
/// For further analysis see
|
||||||
|
/// <http://vigna.di.unimi.it/ftp/papers/xorshift.pdf>
|
||||||
|
|
||||||
|
class PRNG {
|
||||||
|
|
||||||
|
uint64_t s;
|
||||||
|
|
||||||
|
uint64_t rand64() {
|
||||||
|
|
||||||
|
s ^= s >> 12, s ^= s << 25, s ^= s >> 27;
|
||||||
|
return s * 2685821657736338717LL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
PRNG(uint64_t seed) : s(seed) { assert(seed); }
|
||||||
|
|
||||||
|
template<typename T> T rand() { return T(rand64()); }
|
||||||
|
|
||||||
|
/// Special generator used to fast init magic numbers.
|
||||||
|
/// Output values only have 1/8th of their bits set on average.
|
||||||
|
template<typename T> T sparse_rand()
|
||||||
|
{ 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
|
||||||
|
|||||||
-258
@@ -1,258 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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 <cassert>
|
|
||||||
#include <cstring>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "move.h"
|
|
||||||
#include "movegen.h"
|
|
||||||
#include "search.h"
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
const string time_string(int milliseconds);
|
|
||||||
const string score_string(Value v);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// move_to_uci() converts a move to a string in coordinate notation
|
|
||||||
/// (g1f3, a7a8q, etc.). The only special case is castling moves, where we
|
|
||||||
/// print in the e1g1 notation in normal chess mode, and in e1h1 notation in
|
|
||||||
/// Chess960 mode.
|
|
||||||
|
|
||||||
const string move_to_uci(Move m, bool chess960) {
|
|
||||||
|
|
||||||
Square from = move_from(m);
|
|
||||||
Square to = move_to(m);
|
|
||||||
string promotion;
|
|
||||||
|
|
||||||
if (m == MOVE_NONE)
|
|
||||||
return "(none)";
|
|
||||||
|
|
||||||
if (m == MOVE_NULL)
|
|
||||||
return "0000";
|
|
||||||
|
|
||||||
if (move_is_short_castle(m) && !chess960)
|
|
||||||
return from == SQ_E1 ? "e1g1" : "e8g8";
|
|
||||||
|
|
||||||
if (move_is_long_castle(m) && !chess960)
|
|
||||||
return from == SQ_E1 ? "e1c1" : "e8c8";
|
|
||||||
|
|
||||||
if (move_is_promotion(m))
|
|
||||||
promotion = char(tolower(piece_type_to_char(move_promotion_piece(m))));
|
|
||||||
|
|
||||||
return square_to_string(from) + square_to_string(to) + promotion;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// move_from_uci() takes a position and a string representing a move in
|
|
||||||
/// simple coordinate notation and returns an equivalent Move if any.
|
|
||||||
/// Moves are guaranteed to be legal.
|
|
||||||
|
|
||||||
Move move_from_uci(const Position& pos, const string& str) {
|
|
||||||
|
|
||||||
MoveStack mlist[MAX_MOVES];
|
|
||||||
MoveStack* last = generate<MV_LEGAL>(pos, mlist);
|
|
||||||
|
|
||||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
|
||||||
if (str == move_to_uci(cur->move, pos.is_chess960()))
|
|
||||||
return cur->move;
|
|
||||||
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// move_to_san() takes a position and a move as input, where it is assumed
|
|
||||||
/// that the move is a legal move from the position. The return value is
|
|
||||||
/// a string containing the move in short algebraic notation.
|
|
||||||
|
|
||||||
const string move_to_san(Position& pos, Move m) {
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
|
||||||
assert(move_is_ok(m));
|
|
||||||
|
|
||||||
MoveStack mlist[MAX_MOVES];
|
|
||||||
Square from = move_from(m);
|
|
||||||
Square to = move_to(m);
|
|
||||||
PieceType pt = pos.type_of_piece_on(from);
|
|
||||||
string san;
|
|
||||||
|
|
||||||
if (m == MOVE_NONE)
|
|
||||||
return "(none)";
|
|
||||||
|
|
||||||
if (m == MOVE_NULL)
|
|
||||||
return "(null)";
|
|
||||||
|
|
||||||
if (move_is_long_castle(m))
|
|
||||||
san = "O-O-O";
|
|
||||||
else if (move_is_short_castle(m))
|
|
||||||
san = "O-O";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (pt != PAWN)
|
|
||||||
{
|
|
||||||
san = piece_type_to_char(pt);
|
|
||||||
|
|
||||||
// Collect all legal moves of piece type 'pt' with destination 'to'
|
|
||||||
MoveStack* last = generate<MV_LEGAL>(pos, mlist);
|
|
||||||
int f = 0, r = 0;
|
|
||||||
|
|
||||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
|
||||||
if ( move_to(cur->move) == to
|
|
||||||
&& pos.type_of_piece_on(move_from(cur->move)) == pt)
|
|
||||||
{
|
|
||||||
if (square_file(move_from(cur->move)) == square_file(from))
|
|
||||||
f++;
|
|
||||||
|
|
||||||
if (square_rank(move_from(cur->move)) == square_rank(from))
|
|
||||||
r++;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(f > 0 && r > 0);
|
|
||||||
|
|
||||||
// Disambiguation if we have more then one piece with destination 'to'
|
|
||||||
if (f == 1 && r > 1)
|
|
||||||
san += file_to_char(square_file(from));
|
|
||||||
else if (f > 1 && r == 1)
|
|
||||||
san += rank_to_char(square_rank(from));
|
|
||||||
else if (f > 1 && r > 1)
|
|
||||||
san += square_to_string(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos.move_is_capture(m))
|
|
||||||
{
|
|
||||||
if (pt == PAWN)
|
|
||||||
san += file_to_char(square_file(from));
|
|
||||||
|
|
||||||
san += 'x';
|
|
||||||
}
|
|
||||||
|
|
||||||
san += square_to_string(to);
|
|
||||||
|
|
||||||
if (move_is_promotion(m))
|
|
||||||
{
|
|
||||||
san += '=';
|
|
||||||
san += piece_type_to_char(move_promotion_piece(m));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The move gives check? We don't use pos.move_gives_check() here
|
|
||||||
// because we need to test for a mate after the move is done.
|
|
||||||
StateInfo st;
|
|
||||||
pos.do_move(m, st);
|
|
||||||
if (pos.in_check())
|
|
||||||
san += pos.is_mate() ? "#" : "+";
|
|
||||||
pos.undo_move(m);
|
|
||||||
|
|
||||||
return san;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// pretty_pv() creates a human-readable string from a position and a PV.
|
|
||||||
/// It is used to write search information to the log file (which is created
|
|
||||||
/// when the UCI parameter "Use Search Log" is "true").
|
|
||||||
|
|
||||||
const string pretty_pv(Position& pos, int depth, Value score, int time, Move pv[]) {
|
|
||||||
|
|
||||||
const int64_t K = 1000;
|
|
||||||
const int64_t M = 1000000;
|
|
||||||
const int startColumn = 28;
|
|
||||||
const size_t maxLength = 80 - startColumn;
|
|
||||||
const string lf = string("\n") + string(startColumn, ' ');
|
|
||||||
|
|
||||||
StateInfo state[PLY_MAX_PLUS_2], *st = state;
|
|
||||||
Move* m = pv;
|
|
||||||
string san;
|
|
||||||
std::stringstream s;
|
|
||||||
size_t length = 0;
|
|
||||||
|
|
||||||
// First print depth, score, time and searched nodes...
|
|
||||||
s << std::setw(2) << depth
|
|
||||||
<< std::setw(8) << score_string(score)
|
|
||||||
<< std::setw(8) << time_string(time);
|
|
||||||
|
|
||||||
if (pos.nodes_searched() < M)
|
|
||||||
s << std::setw(8) << pos.nodes_searched() / 1 << " ";
|
|
||||||
else if (pos.nodes_searched() < K * M)
|
|
||||||
s << std::setw(7) << pos.nodes_searched() / K << "K ";
|
|
||||||
else
|
|
||||||
s << std::setw(7) << pos.nodes_searched() / M << "M ";
|
|
||||||
|
|
||||||
// ...then print the full PV line in short algebraic notation
|
|
||||||
while (*m != MOVE_NONE)
|
|
||||||
{
|
|
||||||
san = move_to_san(pos, *m);
|
|
||||||
length += san.length() + 1;
|
|
||||||
|
|
||||||
if (length > maxLength)
|
|
||||||
{
|
|
||||||
length = san.length() + 1;
|
|
||||||
s << lf;
|
|
||||||
}
|
|
||||||
s << san << ' ';
|
|
||||||
|
|
||||||
pos.do_move(*m++, *st++);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore original position before to leave
|
|
||||||
while (m != pv) pos.undo_move(*--m);
|
|
||||||
|
|
||||||
return s.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
const string time_string(int millisecs) {
|
|
||||||
|
|
||||||
const int MSecMinute = 1000 * 60;
|
|
||||||
const int MSecHour = 1000 * 60 * 60;
|
|
||||||
|
|
||||||
int hours = millisecs / MSecHour;
|
|
||||||
int minutes = (millisecs % MSecHour) / MSecMinute;
|
|
||||||
int seconds = ((millisecs % MSecHour) % MSecMinute) / 1000;
|
|
||||||
|
|
||||||
std::stringstream s;
|
|
||||||
|
|
||||||
if (hours)
|
|
||||||
s << hours << ':';
|
|
||||||
|
|
||||||
s << std::setfill('0') << std::setw(2) << minutes << ':' << std::setw(2) << seconds;
|
|
||||||
return s.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const string score_string(Value v) {
|
|
||||||
|
|
||||||
std::stringstream s;
|
|
||||||
|
|
||||||
if (v >= VALUE_MATE - 200)
|
|
||||||
s << "#" << (VALUE_MATE - v + 1) / 2;
|
|
||||||
else if (v <= -VALUE_MATE + 200)
|
|
||||||
s << "-#" << (VALUE_MATE + v) / 2;
|
|
||||||
else
|
|
||||||
s << std::setprecision(2) << std::fixed << std::showpos << float(v) / PawnValueMidgame;
|
|
||||||
|
|
||||||
return s.str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-195
@@ -1,195 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(MOVE_H_INCLUDED)
|
|
||||||
#define MOVE_H_INCLUDED
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "misc.h"
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
// Maximum number of allowed moves per position
|
|
||||||
const int MAX_MOVES = 256;
|
|
||||||
|
|
||||||
/// A move needs 16 bits to be stored
|
|
||||||
///
|
|
||||||
/// bit 0- 5: destination square (from 0 to 63)
|
|
||||||
/// bit 6-11: origin square (from 0 to 63)
|
|
||||||
/// bit 12-13: promotion piece type - 2 (from KNIGHT-2 to QUEEN-2)
|
|
||||||
/// bit 14-15: special move flag: promotion (1), en passant (2), castle (3)
|
|
||||||
///
|
|
||||||
/// Special cases are MOVE_NONE and MOVE_NULL. We can sneak these in
|
|
||||||
/// because in any normal move destination square is always different
|
|
||||||
/// from origin square while MOVE_NONE and MOVE_NULL have the same
|
|
||||||
/// origin and destination square, 0 and 1 respectively.
|
|
||||||
|
|
||||||
enum Move {
|
|
||||||
MOVE_NONE = 0,
|
|
||||||
MOVE_NULL = 65
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct MoveStack {
|
|
||||||
Move move;
|
|
||||||
int score;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool operator<(const MoveStack& f, const MoveStack& s) { return f.score < s.score; }
|
|
||||||
|
|
||||||
// An helper insertion sort implementation, works with pointers and iterators
|
|
||||||
template<typename T, typename K>
|
|
||||||
inline void insertion_sort(K firstMove, K lastMove)
|
|
||||||
{
|
|
||||||
T value;
|
|
||||||
K cur, p, d;
|
|
||||||
|
|
||||||
if (firstMove != lastMove)
|
|
||||||
for (cur = firstMove + 1; cur != lastMove; cur++)
|
|
||||||
{
|
|
||||||
p = d = cur;
|
|
||||||
value = *p--;
|
|
||||||
if (*p < value)
|
|
||||||
{
|
|
||||||
do *d = *p;
|
|
||||||
while (--d != firstMove && *--p < value);
|
|
||||||
*d = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Our dedicated sort in range [firstMove, lastMove), first splits
|
|
||||||
// positive scores from ramining then order seaprately the two sets.
|
|
||||||
template<typename T>
|
|
||||||
inline void sort_moves(T* firstMove, T* lastMove, T** lastPositive)
|
|
||||||
{
|
|
||||||
T tmp;
|
|
||||||
T *p, *d;
|
|
||||||
|
|
||||||
d = lastMove;
|
|
||||||
p = firstMove - 1;
|
|
||||||
|
|
||||||
d->score = -1; // right guard
|
|
||||||
|
|
||||||
// Split positives vs non-positives
|
|
||||||
do {
|
|
||||||
while ((++p)->score > 0) {}
|
|
||||||
|
|
||||||
if (p != d)
|
|
||||||
{
|
|
||||||
while (--d != p && d->score <= 0) {}
|
|
||||||
|
|
||||||
tmp = *p;
|
|
||||||
*p = *d;
|
|
||||||
*d = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (p != d);
|
|
||||||
|
|
||||||
// Sort just positive scored moves, remaining only when we get there
|
|
||||||
insertion_sort<T, T*>(firstMove, p);
|
|
||||||
*lastPositive = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Picks up the best move in range [curMove, lastMove), one per cycle.
|
|
||||||
// It is faster then sorting all the moves in advance when moves are few,
|
|
||||||
// as normally are the possible captures. Note that is not a stable alghoritm.
|
|
||||||
template<typename T>
|
|
||||||
inline T pick_best(T* curMove, T* lastMove)
|
|
||||||
{
|
|
||||||
T bestMove, tmp;
|
|
||||||
|
|
||||||
bestMove = *curMove;
|
|
||||||
while (++curMove != lastMove)
|
|
||||||
{
|
|
||||||
if (bestMove < *curMove)
|
|
||||||
{
|
|
||||||
tmp = *curMove;
|
|
||||||
*curMove = bestMove;
|
|
||||||
bestMove = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bestMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline Square move_from(Move m) {
|
|
||||||
return Square((int(m) >> 6) & 0x3F);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square move_to(Move m) {
|
|
||||||
return Square(m & 0x3F);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool move_is_special(Move m) {
|
|
||||||
return m & (3 << 14);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool move_is_promotion(Move m) {
|
|
||||||
return (m & (3 << 14)) == (1 << 14);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int move_is_ep(Move m) {
|
|
||||||
return (m & (3 << 14)) == (2 << 14);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int move_is_castle(Move m) {
|
|
||||||
return (m & (3 << 14)) == (3 << 14);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool move_is_short_castle(Move m) {
|
|
||||||
return move_is_castle(m) && (move_to(m) > move_from(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool move_is_long_castle(Move m) {
|
|
||||||
return move_is_castle(m) && (move_to(m) < move_from(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline PieceType move_promotion_piece(Move m) {
|
|
||||||
return move_is_promotion(m) ? PieceType(((int(m) >> 12) & 3) + 2) : PIECE_TYPE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Move make_move(Square from, Square to) {
|
|
||||||
return Move(int(to) | (int(from) << 6));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Move make_promotion_move(Square from, Square to, PieceType promotion) {
|
|
||||||
return Move(int(to) | (int(from) << 6) | ((int(promotion) - 2) << 12) | (1 << 14));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Move make_ep_move(Square from, Square to) {
|
|
||||||
return Move(int(to) | (int(from) << 6) | (2 << 14));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Move make_castle_move(Square from, Square to) {
|
|
||||||
return Move(int(to) | (int(from) << 6) | (3 << 14));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool move_is_ok(Move m) {
|
|
||||||
return move_from(m) != move_to(m); // Catches also MOVE_NONE
|
|
||||||
}
|
|
||||||
|
|
||||||
class Position;
|
|
||||||
|
|
||||||
extern const std::string move_to_uci(Move m, bool chess960);
|
|
||||||
extern Move move_from_uci(const Position& pos, const std::string& str);
|
|
||||||
extern const std::string move_to_san(Position& pos, Move m);
|
|
||||||
extern const std::string pretty_pv(Position& pos, int depth, Value score, int time, Move pv[]);
|
|
||||||
|
|
||||||
#endif // !defined(MOVE_H_INCLUDED)
|
|
||||||
+347
-469
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,524 +20,401 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "bitcount.h"
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
|
#include "position.h"
|
||||||
// Simple macro to wrap a very common while loop, no facny, no flexibility,
|
|
||||||
// hardcoded list name 'mlist' and from square 'from'.
|
|
||||||
#define SERIALIZE_MOVES(b) while (b) (*mlist++).move = make_move(from, pop_1st_bit(&b))
|
|
||||||
|
|
||||||
// Version used for pawns, where the 'from' square is given as a delta from the 'to' square
|
|
||||||
#define SERIALIZE_MOVES_D(b, d) while (b) { to = pop_1st_bit(&b); (*mlist++).move = make_move(to + (d), to); }
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum CastlingSide {
|
template<CastlingRight Cr, bool Checks, bool Chess960>
|
||||||
KING_SIDE,
|
ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us) {
|
||||||
QUEEN_SIDE
|
|
||||||
};
|
|
||||||
|
|
||||||
template<CastlingSide>
|
static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
|
||||||
MoveStack* generate_castle_moves(const Position&, MoveStack*, Color us);
|
|
||||||
|
|
||||||
template<Color, MoveType>
|
if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
|
||||||
MoveStack* generate_pawn_moves(const Position&, MoveStack*, Bitboard, Square);
|
return moveList;
|
||||||
|
|
||||||
template<PieceType Pt>
|
// After castling, the rook and king final positions are the same in Chess960
|
||||||
inline MoveStack* generate_discovered_checks(const Position& pos, MoveStack* mlist, Square from) {
|
// as they would be in standard chess.
|
||||||
|
Square kfrom = pos.square<KING>(us);
|
||||||
|
Square rfrom = pos.castling_rook_square(Cr);
|
||||||
|
Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1);
|
||||||
|
Bitboard enemies = pos.pieces(~us);
|
||||||
|
|
||||||
assert(Pt != QUEEN);
|
assert(!pos.checkers());
|
||||||
|
|
||||||
Bitboard b = pos.attacks_from<Pt>(from) & pos.empty_squares();
|
const Direction K = Chess960 ? kto > kfrom ? WEST : EAST
|
||||||
if (Pt == KING)
|
: KingSide ? WEST : EAST;
|
||||||
|
|
||||||
|
for (Square s = kto; s != kfrom; s += K)
|
||||||
|
if (pos.attackers_to(s) & enemies)
|
||||||
|
return moveList;
|
||||||
|
|
||||||
|
// Because we generate only legal castling moves we need to verify that
|
||||||
|
// when moving the castling rook we do not discover some hidden checker.
|
||||||
|
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
|
||||||
|
if (Chess960 && (attacks_bb<ROOK>(kto, pos.pieces() ^ rfrom) & pos.pieces(~us, ROOK, QUEEN)))
|
||||||
|
return moveList;
|
||||||
|
|
||||||
|
Move m = make<CASTLING>(kfrom, rfrom);
|
||||||
|
|
||||||
|
if (Checks && !pos.gives_check(m))
|
||||||
|
return moveList;
|
||||||
|
|
||||||
|
*moveList++ = m;
|
||||||
|
return moveList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<GenType Type, Direction D>
|
||||||
|
ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) {
|
||||||
|
|
||||||
|
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
|
*moveList++ = make<PROMOTION>(to - D, to, QUEEN);
|
||||||
|
|
||||||
|
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
{
|
{
|
||||||
Square ksq = pos.king_square(opposite_color(pos.side_to_move()));
|
*moveList++ = make<PROMOTION>(to - D, to, ROOK);
|
||||||
b &= ~QueenPseudoAttacks[ksq];
|
*moveList++ = make<PROMOTION>(to - D, to, BISHOP);
|
||||||
|
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
||||||
}
|
}
|
||||||
SERIALIZE_MOVES(b);
|
|
||||||
return mlist;
|
// 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 && (PseudoAttacks[KNIGHT][to] & ksq))
|
||||||
|
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
||||||
|
else
|
||||||
|
(void)ksq; // Silence a warning under MSVC
|
||||||
|
|
||||||
|
return moveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt>
|
|
||||||
inline MoveStack* generate_direct_checks(const Position& pos, MoveStack* mlist, Color us,
|
|
||||||
Bitboard dc, Square ksq) {
|
|
||||||
assert(Pt != KING);
|
|
||||||
|
|
||||||
Bitboard checkSqs, b;
|
template<Color Us, GenType Type>
|
||||||
Square from;
|
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
const Square* ptr = pos.piece_list_begin(us, Pt);
|
|
||||||
|
|
||||||
if ((from = *ptr++) == SQ_NONE)
|
// Compute our parametrized parameters at compile time, named according to
|
||||||
return mlist;
|
// 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 Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
|
const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||||
|
const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||||
|
|
||||||
checkSqs = pos.attacks_from<Pt>(ksq) & pos.empty_squares();
|
Bitboard emptySquares;
|
||||||
|
|
||||||
do
|
Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB;
|
||||||
|
Bitboard pawnsNotOn7 = pos.pieces(Us, PAWN) & ~TRank7BB;
|
||||||
|
|
||||||
|
Bitboard enemies = (Type == EVASIONS ? pos.pieces(Them) & target:
|
||||||
|
Type == CAPTURES ? target : pos.pieces(Them));
|
||||||
|
|
||||||
|
// Single and double pawn pushes, no promotions
|
||||||
|
if (Type != CAPTURES)
|
||||||
{
|
{
|
||||||
if ( (Pt == QUEEN && !(QueenPseudoAttacks[from] & checkSqs))
|
emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces());
|
||||||
|| (Pt == ROOK && !(RookPseudoAttacks[from] & checkSqs))
|
|
||||||
|| (Pt == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (dc && bit_is_set(dc, from))
|
Bitboard b1 = shift<Up>(pawnsNotOn7) & emptySquares;
|
||||||
continue;
|
Bitboard b2 = shift<Up>(b1 & TRank3BB) & emptySquares;
|
||||||
|
|
||||||
b = pos.attacks_from<Pt>(from) & checkSqs;
|
if (Type == EVASIONS) // Consider only blocking squares
|
||||||
SERIALIZE_MOVES(b);
|
|
||||||
|
|
||||||
} while ((from = *ptr++) != SQ_NONE);
|
|
||||||
|
|
||||||
return mlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
FORCE_INLINE MoveStack* generate_direct_checks<PAWN>(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) {
|
|
||||||
|
|
||||||
return (us == WHITE ? generate_pawn_moves<WHITE, MV_CHECK>(p, m, dc, ksq)
|
|
||||||
: generate_pawn_moves<BLACK, MV_CHECK>(p, m, dc, ksq));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<PieceType Pt, MoveType Type>
|
|
||||||
FORCE_INLINE MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) {
|
|
||||||
|
|
||||||
assert(Pt == PAWN);
|
|
||||||
assert(Type == MV_CAPTURE || Type == MV_NON_CAPTURE || Type == MV_EVASION);
|
|
||||||
|
|
||||||
return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m, t, SQ_NONE)
|
|
||||||
: generate_pawn_moves<BLACK, Type>(p, m, t, SQ_NONE));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<PieceType Pt>
|
|
||||||
FORCE_INLINE MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) {
|
|
||||||
|
|
||||||
Bitboard b;
|
|
||||||
Square from;
|
|
||||||
const Square* ptr = pos.piece_list_begin(us, Pt);
|
|
||||||
|
|
||||||
if (*ptr != SQ_NONE)
|
|
||||||
{
|
|
||||||
do {
|
|
||||||
from = *ptr;
|
|
||||||
b = pos.attacks_from<Pt>(from) & target;
|
|
||||||
SERIALIZE_MOVES(b);
|
|
||||||
} while (*++ptr != SQ_NONE);
|
|
||||||
}
|
|
||||||
return mlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
FORCE_INLINE MoveStack* generate_piece_moves<KING>(const Position& pos, MoveStack* mlist, Color us, Bitboard target) {
|
|
||||||
|
|
||||||
Bitboard b;
|
|
||||||
Square from = pos.king_square(us);
|
|
||||||
|
|
||||||
b = pos.attacks_from<KING>(from) & target;
|
|
||||||
SERIALIZE_MOVES(b);
|
|
||||||
return mlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// generate<MV_CAPTURE> generates all pseudo-legal captures and queen
|
|
||||||
/// promotions. Returns a pointer to the end of the move list.
|
|
||||||
///
|
|
||||||
/// generate<MV_NON_CAPTURE> generates all pseudo-legal non-captures and
|
|
||||||
/// underpromotions. Returns a pointer to the end of the move list.
|
|
||||||
///
|
|
||||||
/// generate<MV_NON_EVASION> generates all pseudo-legal captures and
|
|
||||||
/// non-captures. Returns a pointer to the end of the move list.
|
|
||||||
|
|
||||||
template<MoveType Type>
|
|
||||||
MoveStack* generate(const Position& pos, MoveStack* mlist) {
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
|
||||||
assert(!pos.in_check());
|
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
|
||||||
Bitboard target;
|
|
||||||
|
|
||||||
if (Type == MV_CAPTURE || Type == MV_NON_EVASION)
|
|
||||||
target = pos.pieces_of_color(opposite_color(us));
|
|
||||||
else if (Type == MV_NON_CAPTURE)
|
|
||||||
target = pos.empty_squares();
|
|
||||||
else
|
|
||||||
assert(false);
|
|
||||||
|
|
||||||
if (Type == MV_NON_EVASION)
|
|
||||||
{
|
|
||||||
mlist = generate_piece_moves<PAWN, MV_CAPTURE>(pos, mlist, us, target);
|
|
||||||
mlist = generate_piece_moves<PAWN, MV_NON_CAPTURE>(pos, mlist, us, pos.empty_squares());
|
|
||||||
target |= pos.empty_squares();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
mlist = generate_piece_moves<PAWN, Type>(pos, mlist, us, target);
|
|
||||||
|
|
||||||
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
|
||||||
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
|
||||||
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
|
||||||
mlist = generate_piece_moves<QUEEN>(pos, mlist, us, target);
|
|
||||||
mlist = generate_piece_moves<KING>(pos, mlist, us, target);
|
|
||||||
|
|
||||||
if (Type != MV_CAPTURE)
|
|
||||||
{
|
|
||||||
if (pos.can_castle_kingside(us))
|
|
||||||
mlist = generate_castle_moves<KING_SIDE>(pos, mlist, us);
|
|
||||||
|
|
||||||
if (pos.can_castle_queenside(us))
|
|
||||||
mlist = generate_castle_moves<QUEEN_SIDE>(pos, mlist, us);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit template instantiations
|
|
||||||
template MoveStack* generate<MV_CAPTURE>(const Position& pos, MoveStack* mlist);
|
|
||||||
template MoveStack* generate<MV_NON_CAPTURE>(const Position& pos, MoveStack* mlist);
|
|
||||||
template MoveStack* generate<MV_NON_EVASION>(const Position& pos, MoveStack* mlist);
|
|
||||||
|
|
||||||
|
|
||||||
/// generate_non_capture_checks() generates all pseudo-legal non-captures and knight
|
|
||||||
/// underpromotions that give check. Returns a pointer to the end of the move list.
|
|
||||||
template<>
|
|
||||||
MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist) {
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
|
||||||
assert(!pos.in_check());
|
|
||||||
|
|
||||||
Bitboard b, dc;
|
|
||||||
Square from;
|
|
||||||
Color us = pos.side_to_move();
|
|
||||||
Square ksq = pos.king_square(opposite_color(us));
|
|
||||||
|
|
||||||
assert(pos.piece_on(ksq) == make_piece(opposite_color(us), KING));
|
|
||||||
|
|
||||||
// Discovered non-capture checks
|
|
||||||
b = dc = pos.discovered_check_candidates(us);
|
|
||||||
|
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
from = pop_1st_bit(&b);
|
|
||||||
switch (pos.type_of_piece_on(from))
|
|
||||||
{
|
|
||||||
case PAWN: /* Will be generated togheter with pawns direct checks */ break;
|
|
||||||
case KNIGHT: mlist = generate_discovered_checks<KNIGHT>(pos, mlist, from); break;
|
|
||||||
case BISHOP: mlist = generate_discovered_checks<BISHOP>(pos, mlist, from); break;
|
|
||||||
case ROOK: mlist = generate_discovered_checks<ROOK>(pos, mlist, from); break;
|
|
||||||
case KING: mlist = generate_discovered_checks<KING>(pos, mlist, from); break;
|
|
||||||
default: assert(false); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Direct non-capture checks
|
|
||||||
mlist = generate_direct_checks<PAWN>(pos, mlist, us, dc, ksq);
|
|
||||||
mlist = generate_direct_checks<KNIGHT>(pos, mlist, us, dc, ksq);
|
|
||||||
mlist = generate_direct_checks<BISHOP>(pos, mlist, us, dc, ksq);
|
|
||||||
mlist = generate_direct_checks<ROOK>(pos, mlist, us, dc, ksq);
|
|
||||||
return generate_direct_checks<QUEEN>(pos, mlist, us, dc, ksq);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// generate_evasions() generates all pseudo-legal check evasions when
|
|
||||||
/// the side to move is in check. Returns a pointer to the end of the move list.
|
|
||||||
template<>
|
|
||||||
MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
|
||||||
assert(pos.in_check());
|
|
||||||
|
|
||||||
Bitboard b, target;
|
|
||||||
Square from, checksq;
|
|
||||||
int checkersCnt = 0;
|
|
||||||
Color us = pos.side_to_move();
|
|
||||||
Square ksq = pos.king_square(us);
|
|
||||||
Bitboard checkers = pos.checkers();
|
|
||||||
Bitboard sliderAttacks = EmptyBoardBB;
|
|
||||||
|
|
||||||
assert(pos.piece_on(ksq) == make_piece(us, KING));
|
|
||||||
assert(checkers);
|
|
||||||
|
|
||||||
// Find squares attacked by slider checkers, we will remove
|
|
||||||
// them from the king evasions set so to early skip known
|
|
||||||
// illegal moves and avoid an useless legality check later.
|
|
||||||
b = checkers;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
checkersCnt++;
|
|
||||||
checksq = pop_1st_bit(&b);
|
|
||||||
|
|
||||||
assert(pos.color_of_piece_on(checksq) == opposite_color(us));
|
|
||||||
|
|
||||||
switch (pos.type_of_piece_on(checksq))
|
|
||||||
{
|
|
||||||
case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break;
|
|
||||||
case ROOK: sliderAttacks |= RookPseudoAttacks[checksq]; break;
|
|
||||||
case QUEEN:
|
|
||||||
// In case of a queen remove also squares attacked in the other direction to
|
|
||||||
// avoid possible illegal moves when queen and king are on adjacent squares.
|
|
||||||
if (RookPseudoAttacks[checksq] & (1ULL << ksq))
|
|
||||||
sliderAttacks |= RookPseudoAttacks[checksq] | pos.attacks_from<BISHOP>(checksq);
|
|
||||||
else
|
|
||||||
sliderAttacks |= BishopPseudoAttacks[checksq] | pos.attacks_from<ROOK>(checksq);
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (b);
|
|
||||||
|
|
||||||
// Generate evasions for king, capture and non capture moves
|
|
||||||
b = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~sliderAttacks;
|
|
||||||
from = ksq;
|
|
||||||
SERIALIZE_MOVES(b);
|
|
||||||
|
|
||||||
// Generate evasions for other pieces only if not double check
|
|
||||||
if (checkersCnt > 1)
|
|
||||||
return mlist;
|
|
||||||
|
|
||||||
// Find squares where a blocking evasion or a capture of the
|
|
||||||
// checker piece is possible.
|
|
||||||
target = squares_between(checksq, ksq) | checkers;
|
|
||||||
|
|
||||||
mlist = generate_piece_moves<PAWN, MV_EVASION>(pos, mlist, us, target);
|
|
||||||
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
|
||||||
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
|
||||||
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
|
||||||
return generate_piece_moves<QUEEN>(pos, mlist, us, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// generate<MV_LEGAL / MV_PSEUDO_LEGAL> computes a complete list of legal
|
|
||||||
/// or pseudo-legal moves in the current position.
|
|
||||||
template<>
|
|
||||||
MoveStack* generate<MV_PSEUDO_LEGAL>(const Position& pos, MoveStack* mlist) {
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
|
||||||
|
|
||||||
return pos.in_check() ? generate<MV_EVASION>(pos, mlist)
|
|
||||||
: generate<MV_NON_EVASION>(pos, mlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
|
||||||
|
|
||||||
MoveStack *last, *cur = mlist;
|
|
||||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
|
||||||
|
|
||||||
last = generate<MV_PSEUDO_LEGAL>(pos, mlist);
|
|
||||||
|
|
||||||
// Remove illegal moves from the list
|
|
||||||
while (cur != last)
|
|
||||||
if (!pos.pl_move_is_legal(cur->move, pinned))
|
|
||||||
cur->move = (--last)->move;
|
|
||||||
else
|
|
||||||
cur++;
|
|
||||||
|
|
||||||
return last;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
template<Square Delta>
|
|
||||||
inline Bitboard move_pawns(Bitboard p) {
|
|
||||||
|
|
||||||
return Delta == DELTA_N ? p << 8 : Delta == DELTA_S ? p >> 8 :
|
|
||||||
Delta == DELTA_NE ? p << 9 : Delta == DELTA_SE ? p >> 7 :
|
|
||||||
Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<MoveType Type, Square Delta>
|
|
||||||
inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) {
|
|
||||||
|
|
||||||
const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB);
|
|
||||||
|
|
||||||
Bitboard b;
|
|
||||||
Square to;
|
|
||||||
|
|
||||||
// Captures in the a1-h8 (a8-h1 for black) diagonal or in the h1-a8 (h8-a1 for black)
|
|
||||||
b = move_pawns<Delta>(pawns) & target & ~TFileABB;
|
|
||||||
SERIALIZE_MOVES_D(b, -Delta);
|
|
||||||
return mlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Color Us, MoveType Type, Square Delta>
|
|
||||||
inline MoveStack* generate_promotions(const Position& pos, MoveStack* mlist, Bitboard pawnsOn7, Bitboard target) {
|
|
||||||
|
|
||||||
const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB);
|
|
||||||
|
|
||||||
Bitboard b;
|
|
||||||
Square to;
|
|
||||||
|
|
||||||
// Promotions and under-promotions, both captures and non-captures
|
|
||||||
b = move_pawns<Delta>(pawnsOn7) & target;
|
|
||||||
|
|
||||||
if (Delta != DELTA_N && Delta != DELTA_S)
|
|
||||||
b &= ~TFileABB;
|
|
||||||
|
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
to = pop_1st_bit(&b);
|
|
||||||
|
|
||||||
if (Type == MV_CAPTURE || Type == MV_EVASION)
|
|
||||||
(*mlist++).move = make_promotion_move(to - Delta, to, QUEEN);
|
|
||||||
|
|
||||||
if (Type == MV_NON_CAPTURE || Type == MV_EVASION)
|
|
||||||
{
|
{
|
||||||
(*mlist++).move = make_promotion_move(to - Delta, to, ROOK);
|
b1 &= target;
|
||||||
(*mlist++).move = make_promotion_move(to - Delta, to, BISHOP);
|
b2 &= target;
|
||||||
(*mlist++).move = make_promotion_move(to - Delta, to, KNIGHT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the only possible under promotion that can give a check
|
if (Type == QUIET_CHECKS)
|
||||||
// not already included in the queen-promotion.
|
|
||||||
if ( Type == MV_CHECK
|
|
||||||
&& bit_is_set(pos.attacks_from<KNIGHT>(to), pos.king_square(opposite_color(Us))))
|
|
||||||
(*mlist++).move = make_promotion_move(to - Delta, to, KNIGHT);
|
|
||||||
else (void)pos; // Silence a warning under MSVC
|
|
||||||
}
|
|
||||||
return mlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Color Us, MoveType Type>
|
|
||||||
MoveStack* generate_pawn_moves(const Position& pos, MoveStack* mlist, Bitboard target, Square ksq) {
|
|
||||||
|
|
||||||
// Calculate 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 TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
|
||||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
|
||||||
const Square TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S);
|
|
||||||
const Square TDELTA_NE = (Us == WHITE ? DELTA_NE : DELTA_SE);
|
|
||||||
const Square TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW);
|
|
||||||
|
|
||||||
Square to;
|
|
||||||
Bitboard b1, b2, dc1, dc2, pawnPushes, emptySquares;
|
|
||||||
Bitboard pawns = pos.pieces(PAWN, Us);
|
|
||||||
Bitboard pawnsOn7 = pawns & TRank7BB;
|
|
||||||
Bitboard enemyPieces = (Type == MV_CAPTURE ? target : pos.pieces_of_color(Them));
|
|
||||||
|
|
||||||
// Pre-calculate pawn pushes before changing emptySquares definition
|
|
||||||
if (Type != MV_CAPTURE)
|
|
||||||
{
|
|
||||||
emptySquares = (Type == MV_NON_CAPTURE ? target : pos.empty_squares());
|
|
||||||
pawnPushes = move_pawns<TDELTA_N>(pawns & ~TRank7BB) & emptySquares;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Type == MV_EVASION)
|
|
||||||
{
|
|
||||||
emptySquares &= target; // Only blocking squares
|
|
||||||
enemyPieces &= target; // Capture only the checker piece
|
|
||||||
}
|
|
||||||
|
|
||||||
// Promotions and underpromotions
|
|
||||||
if (pawnsOn7)
|
|
||||||
{
|
|
||||||
if (Type == MV_CAPTURE)
|
|
||||||
emptySquares = pos.empty_squares();
|
|
||||||
|
|
||||||
pawns &= ~TRank7BB;
|
|
||||||
mlist = generate_promotions<Us, Type, TDELTA_NE>(pos, mlist, pawnsOn7, enemyPieces);
|
|
||||||
mlist = generate_promotions<Us, Type, TDELTA_NW>(pos, mlist, pawnsOn7, enemyPieces);
|
|
||||||
mlist = generate_promotions<Us, Type, TDELTA_N >(pos, mlist, pawnsOn7, emptySquares);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Standard captures
|
|
||||||
if (Type == MV_CAPTURE || Type == MV_EVASION)
|
|
||||||
{
|
|
||||||
mlist = generate_pawn_captures<Type, TDELTA_NE>(mlist, pawns, enemyPieces);
|
|
||||||
mlist = generate_pawn_captures<Type, TDELTA_NW>(mlist, pawns, enemyPieces);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single and double pawn pushes
|
|
||||||
if (Type != MV_CAPTURE)
|
|
||||||
{
|
|
||||||
b1 = pawnPushes & emptySquares;
|
|
||||||
b2 = move_pawns<TDELTA_N>(pawnPushes & TRank3BB) & emptySquares;
|
|
||||||
|
|
||||||
if (Type == MV_CHECK)
|
|
||||||
{
|
{
|
||||||
// Consider only pawn moves which give direct checks
|
Square ksq = pos.square<KING>(Them);
|
||||||
|
|
||||||
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
|
|
||||||
// Add pawn moves which gives discovered check. This is possible only
|
// 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
|
// if the pawn is not on the same file as the enemy king, because we
|
||||||
// don't generate captures.
|
// don't generate captures. Note that a possible discovery check
|
||||||
if (pawns & target) // For CHECK type target is dc bitboard
|
// promotion has been already generated amongst the captures.
|
||||||
|
Bitboard dcCandidates = pos.discovered_check_candidates();
|
||||||
|
if (pawnsNotOn7 & dcCandidates)
|
||||||
{
|
{
|
||||||
dc1 = move_pawns<TDELTA_N>(pawns & target & ~file_bb(ksq)) & emptySquares;
|
Bitboard dc1 = shift<Up>(pawnsNotOn7 & dcCandidates) & emptySquares & ~file_bb(ksq);
|
||||||
dc2 = move_pawns<TDELTA_N>(dc1 & TRank3BB) & emptySquares;
|
Bitboard dc2 = shift<Up>(dc1 & TRank3BB) & emptySquares;
|
||||||
|
|
||||||
b1 |= dc1;
|
b1 |= dc1;
|
||||||
b2 |= dc2;
|
b2 |= dc2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SERIALIZE_MOVES_D(b1, -TDELTA_N);
|
|
||||||
SERIALIZE_MOVES_D(b2, -TDELTA_N -TDELTA_N);
|
|
||||||
}
|
|
||||||
|
|
||||||
// En passant captures
|
|
||||||
if ((Type == MV_CAPTURE || Type == MV_EVASION) && pos.ep_square() != SQ_NONE)
|
|
||||||
{
|
|
||||||
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
|
|
||||||
assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
|
|
||||||
|
|
||||||
// An en passant capture can be an evasion only if the checking piece
|
|
||||||
// is the double pushed pawn and so is in the target. Otherwise this
|
|
||||||
// is a discovery check and we are forced to do otherwise.
|
|
||||||
if (Type == MV_EVASION && !bit_is_set(target, pos.ep_square() - TDELTA_N))
|
|
||||||
return mlist;
|
|
||||||
|
|
||||||
b1 = pawns & pos.attacks_from<PAWN>(pos.ep_square(), Them);
|
|
||||||
|
|
||||||
assert(b1 != EmptyBoardBB);
|
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
to = pop_1st_bit(&b1);
|
Square to = pop_lsb(&b1);
|
||||||
(*mlist++).move = make_ep_move(to, pos.ep_square());
|
*moveList++ = make_move(to - Up, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (b2)
|
||||||
|
{
|
||||||
|
Square to = pop_lsb(&b2);
|
||||||
|
*moveList++ = make_move(to - Up - Up, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mlist;
|
|
||||||
|
// Promotions and underpromotions
|
||||||
|
if (pawnsOn7 && (Type != EVASIONS || (target & TRank8BB)))
|
||||||
|
{
|
||||||
|
if (Type == CAPTURES)
|
||||||
|
emptySquares = ~pos.pieces();
|
||||||
|
|
||||||
|
if (Type == EVASIONS)
|
||||||
|
emptySquares &= target;
|
||||||
|
|
||||||
|
Bitboard b1 = shift<Right>(pawnsOn7) & enemies;
|
||||||
|
Bitboard b2 = shift<Left >(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), ksq);
|
||||||
|
|
||||||
|
while (b2)
|
||||||
|
moveList = make_promotions<Type, Left >(moveList, pop_lsb(&b2), ksq);
|
||||||
|
|
||||||
|
while (b3)
|
||||||
|
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<Right>(pawnsNotOn7) & enemies;
|
||||||
|
Bitboard b2 = shift<Left >(pawnsNotOn7) & enemies;
|
||||||
|
|
||||||
|
while (b1)
|
||||||
|
{
|
||||||
|
Square to = pop_lsb(&b1);
|
||||||
|
*moveList++ = make_move(to - Right, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (b2)
|
||||||
|
{
|
||||||
|
Square to = pop_lsb(&b2);
|
||||||
|
*moveList++ = make_move(to - Left, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos.ep_square() != SQ_NONE)
|
||||||
|
{
|
||||||
|
assert(rank_of(pos.ep_square()) == relative_rank(Us, RANK_6));
|
||||||
|
|
||||||
|
// An en passant capture can be an evasion only if the checking piece
|
||||||
|
// is the double pushed pawn and so is in the target. Otherwise this
|
||||||
|
// is a discovery check and we are forced to do otherwise.
|
||||||
|
if (Type == EVASIONS && !(target & (pos.ep_square() - Up)))
|
||||||
|
return moveList;
|
||||||
|
|
||||||
|
b1 = pawnsNotOn7 & pos.attacks_from<PAWN>(pos.ep_square(), Them);
|
||||||
|
|
||||||
|
assert(b1);
|
||||||
|
|
||||||
|
while (b1)
|
||||||
|
*moveList++ = make<ENPASSANT>(pop_lsb(&b1), pos.ep_square());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return moveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<CastlingSide Side>
|
|
||||||
MoveStack* generate_castle_moves(const Position& pos, MoveStack* mlist, Color us) {
|
|
||||||
|
|
||||||
Color them = opposite_color(us);
|
template<PieceType Pt, bool Checks>
|
||||||
Square ksq = pos.king_square(us);
|
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
||||||
|
Bitboard target) {
|
||||||
|
|
||||||
assert(pos.piece_on(ksq) == make_piece(us, KING));
|
assert(Pt != KING && Pt != PAWN);
|
||||||
|
|
||||||
Square rsq = (Side == KING_SIDE ? pos.initial_kr_square(us) : pos.initial_qr_square(us));
|
const Square* pl = pos.squares<Pt>(us);
|
||||||
Square s1 = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1);
|
|
||||||
Square s2 = relative_square(us, Side == KING_SIDE ? SQ_F1 : SQ_D1);
|
|
||||||
Square s;
|
|
||||||
bool illegal = false;
|
|
||||||
|
|
||||||
assert(pos.piece_on(rsq) == make_piece(us, ROOK));
|
for (Square from = *pl; from != SQ_NONE; from = *++pl)
|
||||||
|
{
|
||||||
|
if (Checks)
|
||||||
|
{
|
||||||
|
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
|
||||||
|
&& !(PseudoAttacks[Pt][from] & target & pos.check_squares(Pt)))
|
||||||
|
continue;
|
||||||
|
|
||||||
// It is a bit complicated to correctly handle Chess960
|
if (pos.discovered_check_candidates() & from)
|
||||||
for (s = Min(ksq, s1); s <= Max(ksq, s1); s++)
|
continue;
|
||||||
if ( (s != ksq && s != rsq && pos.square_is_occupied(s))
|
}
|
||||||
||(pos.attackers_to(s) & pos.pieces_of_color(them)))
|
|
||||||
illegal = true;
|
|
||||||
|
|
||||||
for (s = Min(rsq, s2); s <= Max(rsq, s2); s++)
|
Bitboard b = pos.attacks_from<Pt>(from) & target;
|
||||||
if (s != ksq && s != rsq && pos.square_is_occupied(s))
|
|
||||||
illegal = true;
|
|
||||||
|
|
||||||
if ( Side == QUEEN_SIDE
|
if (Checks)
|
||||||
&& square_file(rsq) == FILE_B
|
b &= pos.check_squares(Pt);
|
||||||
&& ( pos.piece_on(relative_square(us, SQ_A1)) == make_piece(them, ROOK)
|
|
||||||
|| pos.piece_on(relative_square(us, SQ_A1)) == make_piece(them, QUEEN)))
|
|
||||||
illegal = true;
|
|
||||||
|
|
||||||
if (!illegal)
|
while (b)
|
||||||
(*mlist++).move = make_castle_move(ksq, rsq);
|
*moveList++ = make_move(from, pop_lsb(&b));
|
||||||
|
}
|
||||||
|
|
||||||
return mlist;
|
return moveList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<Color Us, GenType Type>
|
||||||
|
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
|
|
||||||
|
const bool Checks = Type == QUIET_CHECKS;
|
||||||
|
|
||||||
|
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.square<KING>(Us);
|
||||||
|
Bitboard b = pos.attacks_from<KING>(ksq) & target;
|
||||||
|
while (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);
|
||||||
|
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us);
|
||||||
|
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return moveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
/// generate<CAPTURES> generates all pseudo-legal captures and queen
|
||||||
|
/// promotions. Returns a pointer to the end of the move list.
|
||||||
|
///
|
||||||
|
/// generate<QUIETS> generates all pseudo-legal non-captures and
|
||||||
|
/// underpromotions. Returns a pointer to the end of the move list.
|
||||||
|
///
|
||||||
|
/// generate<NON_EVASIONS> generates all pseudo-legal captures and
|
||||||
|
/// non-captures. Returns a pointer to the end of the move list.
|
||||||
|
|
||||||
|
template<GenType Type>
|
||||||
|
ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
|
assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS);
|
||||||
|
assert(!pos.checkers());
|
||||||
|
|
||||||
|
Color us = pos.side_to_move();
|
||||||
|
|
||||||
|
Bitboard target = Type == CAPTURES ? pos.pieces(~us)
|
||||||
|
: Type == QUIETS ? ~pos.pieces()
|
||||||
|
: Type == NON_EVASIONS ? ~pos.pieces(us) : 0;
|
||||||
|
|
||||||
|
return us == WHITE ? generate_all<WHITE, Type>(pos, moveList, target)
|
||||||
|
: generate_all<BLACK, Type>(pos, moveList, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explicit template instantiations
|
||||||
|
template ExtMove* generate<CAPTURES>(const Position&, ExtMove*);
|
||||||
|
template ExtMove* generate<QUIETS>(const Position&, ExtMove*);
|
||||||
|
template ExtMove* generate<NON_EVASIONS>(const Position&, ExtMove*);
|
||||||
|
|
||||||
|
|
||||||
|
/// generate<QUIET_CHECKS> generates all pseudo-legal non-captures and knight
|
||||||
|
/// underpromotions that give check. Returns a pointer to the end of the move list.
|
||||||
|
template<>
|
||||||
|
ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
|
assert(!pos.checkers());
|
||||||
|
|
||||||
|
Color us = pos.side_to_move();
|
||||||
|
Bitboard dc = pos.discovered_check_candidates();
|
||||||
|
|
||||||
|
while (dc)
|
||||||
|
{
|
||||||
|
Square from = pop_lsb(&dc);
|
||||||
|
PieceType pt = type_of(pos.piece_on(from));
|
||||||
|
|
||||||
|
if (pt == PAWN)
|
||||||
|
continue; // Will be generated together with direct checks
|
||||||
|
|
||||||
|
Bitboard b = pos.attacks_from(pt, from) & ~pos.pieces();
|
||||||
|
|
||||||
|
if (pt == KING)
|
||||||
|
b &= ~PseudoAttacks[QUEEN][pos.square<KING>(~us)];
|
||||||
|
|
||||||
|
while (b)
|
||||||
|
*moveList++ = make_move(from, pop_lsb(&b));
|
||||||
|
}
|
||||||
|
|
||||||
|
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces())
|
||||||
|
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// generate<EVASIONS> generates all pseudo-legal check evasions when the side
|
||||||
|
/// to move is in check. Returns a pointer to the end of the move list.
|
||||||
|
template<>
|
||||||
|
ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
|
assert(pos.checkers());
|
||||||
|
|
||||||
|
Color us = pos.side_to_move();
|
||||||
|
Square ksq = pos.square<KING>(us);
|
||||||
|
Bitboard sliderAttacks = 0;
|
||||||
|
Bitboard sliders = pos.checkers() & ~pos.pieces(KNIGHT, PAWN);
|
||||||
|
|
||||||
|
// Find all the squares attacked by slider checkers. We will remove them from
|
||||||
|
// the king evasions in order to skip known illegal moves, which avoids any
|
||||||
|
// useless legality checks later on.
|
||||||
|
while (sliders)
|
||||||
|
{
|
||||||
|
Square checksq = pop_lsb(&sliders);
|
||||||
|
sliderAttacks |= LineBB[checksq][ksq] ^ checksq;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate evasions for king, capture and non capture moves
|
||||||
|
Bitboard b = pos.attacks_from<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;
|
||||||
|
while (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
|
||||||
|
|
||||||
|
// Generate blocking evasions or captures of the checking piece
|
||||||
|
Square checksq = lsb(pos.checkers());
|
||||||
|
Bitboard target = between_bb(checksq, ksq) | checksq;
|
||||||
|
|
||||||
|
return us == WHITE ? generate_all<WHITE, EVASIONS>(pos, moveList, target)
|
||||||
|
: generate_all<BLACK, EVASIONS>(pos, moveList, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// generate<LEGAL> generates all the legal moves in the given position
|
||||||
|
|
||||||
|
template<>
|
||||||
|
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
|
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||||
|
Square ksq = pos.square<KING>(pos.side_to_move());
|
||||||
|
ExtMove* cur = moveList;
|
||||||
|
|
||||||
|
moveList = pos.checkers() ? generate<EVASIONS >(pos, moveList)
|
||||||
|
: generate<NON_EVASIONS>(pos, moveList);
|
||||||
|
while (cur != moveList)
|
||||||
|
if ( (pinned || from_sq(*cur) == ksq || type_of(*cur) == ENPASSANT)
|
||||||
|
&& !pos.legal(*cur))
|
||||||
|
*cur = (--moveList)->move;
|
||||||
|
else
|
||||||
|
++cur;
|
||||||
|
|
||||||
|
return moveList;
|
||||||
|
}
|
||||||
|
|||||||
+51
-16
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,24 +18,58 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(MOVEGEN_H_INCLUDED)
|
#ifndef MOVEGEN_H_INCLUDED
|
||||||
#define MOVEGEN_H_INCLUDED
|
#define MOVEGEN_H_INCLUDED
|
||||||
|
|
||||||
#include "move.h"
|
#include <algorithm>
|
||||||
#include "position.h"
|
|
||||||
|
|
||||||
enum MoveType {
|
#include "types.h"
|
||||||
MV_CAPTURE,
|
|
||||||
MV_NON_CAPTURE,
|
class Position;
|
||||||
MV_CHECK,
|
|
||||||
MV_NON_CAPTURE_CHECK,
|
enum GenType {
|
||||||
MV_EVASION,
|
CAPTURES,
|
||||||
MV_NON_EVASION,
|
QUIETS,
|
||||||
MV_LEGAL,
|
QUIET_CHECKS,
|
||||||
MV_PSEUDO_LEGAL
|
EVASIONS,
|
||||||
|
NON_EVASIONS,
|
||||||
|
LEGAL
|
||||||
};
|
};
|
||||||
|
|
||||||
template<MoveType>
|
struct ExtMove {
|
||||||
MoveStack* generate(const Position& pos, MoveStack* mlist);
|
Move move;
|
||||||
|
int value;
|
||||||
|
|
||||||
#endif // !defined(MOVEGEN_H_INCLUDED)
|
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) {
|
||||||
|
return f.value < s.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<GenType>
|
||||||
|
ExtMove* generate(const Position& pos, ExtMove* moveList);
|
||||||
|
|
||||||
|
/// The MoveList struct is a simple wrapper around generate(). It sometimes comes
|
||||||
|
/// in handy to use this class instead of the low level generate() function.
|
||||||
|
template<GenType T>
|
||||||
|
struct MoveList {
|
||||||
|
|
||||||
|
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 move) const {
|
||||||
|
return std::find(begin(), end(), move) != end();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ExtMove moveList[MAX_MOVES], *last;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // #ifndef MOVEGEN_H_INCLUDED
|
||||||
|
|||||||
+266
-282
@@ -1,14 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
@@ -20,331 +20,315 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "movegen.h"
|
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "search.h"
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum MovegenPhase {
|
enum Stages {
|
||||||
PH_TT_MOVES, // Transposition table move and mate killer
|
MAIN_SEARCH, CAPTURES_INIT, GOOD_CAPTURES, KILLERS, COUNTERMOVE, QUIET_INIT, QUIET, BAD_CAPTURES,
|
||||||
PH_GOOD_CAPTURES, // Queen promotions and captures with SEE values >= 0
|
EVASION, EVASIONS_INIT, ALL_EVASIONS,
|
||||||
PH_KILLERS, // Killer moves from the current ply
|
PROBCUT, PROBCUT_INIT, PROBCUT_CAPTURES,
|
||||||
PH_NONCAPTURES, // Non-captures and underpromotions
|
QSEARCH_WITH_CHECKS, QCAPTURES_1_INIT, QCAPTURES_1, QCHECKS,
|
||||||
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < 0
|
QSEARCH_NO_CHECKS, QCAPTURES_2_INIT, QCAPTURES_2,
|
||||||
PH_EVASIONS, // Check evasions
|
QSEARCH_RECAPTURES, QRECAPTURES
|
||||||
PH_QCAPTURES, // Captures in quiescence search
|
|
||||||
PH_QCHECKS, // Non-capture checks in quiescence search
|
|
||||||
PH_STOP
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CACHE_LINE_ALIGNMENT
|
// partial_insertion_sort() sorts moves in descending order up to and including
|
||||||
const uint8_t MainSearchTable[] = { PH_TT_MOVES, PH_GOOD_CAPTURES, PH_KILLERS, PH_NONCAPTURES, PH_BAD_CAPTURES, PH_STOP };
|
// a given limit. The order of moves smaller than the limit is left unspecified.
|
||||||
const uint8_t EvasionTable[] = { PH_TT_MOVES, PH_EVASIONS, PH_STOP };
|
void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit) {
|
||||||
const uint8_t QsearchWithChecksTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_QCHECKS, PH_STOP };
|
|
||||||
const uint8_t QsearchWithoutChecksTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_STOP };
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pick_best() finds the best move in the range (begin, end) and moves it to
|
||||||
|
// the front. It's faster than sorting all the moves in advance when there
|
||||||
|
// are few moves, e.g., the possible captures.
|
||||||
|
Move pick_best(ExtMove* begin, ExtMove* end) {
|
||||||
|
|
||||||
|
std::swap(*begin, *std::max_element(begin, end));
|
||||||
|
return *begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
/// Constructor for the MovePicker class. Apart from the position for which
|
/// Constructors of the MovePicker class. As arguments we pass information
|
||||||
/// it is asked to pick legal moves, MovePicker also wants some information
|
/// to help it to return the (presumably) good moves first, to decide which
|
||||||
/// to help it to return the presumably good moves first, to decide which
|
|
||||||
/// moves to return (in the quiescence search, for instance, we only want to
|
/// moves to return (in the quiescence search, for instance, we only want to
|
||||||
/// search captures, promotions and some checks) and about how important good
|
/// search captures, promotions, and some checks) and how important good move
|
||||||
/// move ordering is at the current node.
|
/// ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
/// MovePicker constructor for the main search
|
||||||
SearchStack* ss, Value beta) : pos(p), H(h) {
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||||
int searchTT = ttm;
|
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers_p)
|
||||||
ttMoves[0].move = ttm;
|
: pos(p), mainHistory(mh), captureHistory(cph), contHistory(ch), countermove(cm),
|
||||||
badCaptureThreshold = 0;
|
killers{killers_p[0], killers_p[1]}, depth(d){
|
||||||
badCaptures = moves + MAX_MOVES;
|
|
||||||
|
|
||||||
assert(d > DEPTH_ZERO);
|
assert(d > DEPTH_ZERO);
|
||||||
|
|
||||||
pinned = p.pinned_pieces(pos.side_to_move());
|
stage = pos.checkers() ? EVASION : MAIN_SEARCH;
|
||||||
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
if (p.in_check())
|
stage += (ttMove == MOVE_NONE);
|
||||||
{
|
|
||||||
ttMoves[1].move = killers[0].move = killers[1].move = MOVE_NONE;
|
|
||||||
phasePtr = EvasionTable;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ttMoves[1].move = (ss->mateKiller == ttm) ? MOVE_NONE : ss->mateKiller;
|
|
||||||
searchTT |= ttMoves[1].move;
|
|
||||||
killers[0].move = ss->killers[0];
|
|
||||||
killers[1].move = ss->killers[1];
|
|
||||||
|
|
||||||
// Consider sligtly negative captures as good if at low
|
|
||||||
// depth and far from beta.
|
|
||||||
if (ss && ss->eval < beta - PawnValueMidgame && d < 3 * ONE_PLY)
|
|
||||||
badCaptureThreshold = -PawnValueMidgame;
|
|
||||||
|
|
||||||
phasePtr = MainSearchTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
phasePtr += int(!searchTT) - 1;
|
|
||||||
go_next_phase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h)
|
/// MovePicker constructor for quiescence search
|
||||||
: pos(p), H(h) {
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const CapturePieceToHistory* cph, Square s)
|
||||||
int searchTT = ttm;
|
: pos(p), mainHistory(mh), captureHistory(cph) {
|
||||||
ttMoves[0].move = ttm;
|
|
||||||
ttMoves[1].move = MOVE_NONE;
|
|
||||||
|
|
||||||
assert(d <= DEPTH_ZERO);
|
assert(d <= DEPTH_ZERO);
|
||||||
|
|
||||||
pinned = p.pinned_pieces(pos.side_to_move());
|
if (pos.checkers())
|
||||||
|
stage = EVASION;
|
||||||
|
|
||||||
|
else if (d > DEPTH_QS_NO_CHECKS)
|
||||||
|
stage = QSEARCH_WITH_CHECKS;
|
||||||
|
|
||||||
|
else if (d > DEPTH_QS_RECAPTURES)
|
||||||
|
stage = QSEARCH_NO_CHECKS;
|
||||||
|
|
||||||
if (p.in_check())
|
|
||||||
phasePtr = EvasionTable;
|
|
||||||
else if (d >= DEPTH_QS_CHECKS)
|
|
||||||
phasePtr = QsearchWithChecksTable;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
phasePtr = QsearchWithoutChecksTable;
|
stage = QSEARCH_RECAPTURES;
|
||||||
|
recaptureSquare = s;
|
||||||
// Skip TT move if is not a capture or a promotion, this avoids
|
|
||||||
// qsearch tree explosion due to a possible perpetual check or
|
|
||||||
// similar rare cases when TT table is full.
|
|
||||||
if (ttm != MOVE_NONE && !pos.move_is_capture_or_promotion(ttm))
|
|
||||||
searchTT = ttMoves[0].move = MOVE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
phasePtr += int(!searchTT) - 1;
|
|
||||||
go_next_phase();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::go_next_phase() generates, scores and sorts the next bunch
|
|
||||||
/// of moves when there are no more moves to try for the current phase.
|
|
||||||
|
|
||||||
void MovePicker::go_next_phase() {
|
|
||||||
|
|
||||||
curMove = moves;
|
|
||||||
phase = *(++phasePtr);
|
|
||||||
switch (phase) {
|
|
||||||
|
|
||||||
case PH_TT_MOVES:
|
|
||||||
curMove = ttMoves;
|
|
||||||
lastMove = curMove + 2;
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PH_GOOD_CAPTURES:
|
|
||||||
lastMove = generate<MV_CAPTURE>(pos, moves);
|
|
||||||
score_captures();
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PH_KILLERS:
|
|
||||||
curMove = killers;
|
|
||||||
lastMove = curMove + 2;
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
|
||||||
lastMove = generate<MV_NON_CAPTURE>(pos, moves);
|
|
||||||
score_noncaptures();
|
|
||||||
sort_moves(moves, lastMove, &lastGoodNonCapture);
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
|
||||||
// Bad captures SEE value is already calculated so just pick
|
|
||||||
// them in order to get SEE move ordering.
|
|
||||||
curMove = badCaptures;
|
|
||||||
lastMove = moves + MAX_MOVES;
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PH_EVASIONS:
|
|
||||||
assert(pos.in_check());
|
|
||||||
lastMove = generate<MV_EVASION>(pos, moves);
|
|
||||||
score_evasions();
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
|
||||||
lastMove = generate<MV_CAPTURE>(pos, moves);
|
|
||||||
score_captures();
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PH_QCHECKS:
|
|
||||||
lastMove = generate<MV_NON_CAPTURE_CHECK>(pos, moves);
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PH_STOP:
|
|
||||||
lastMove = curMove + 1; // Avoid another go_next_phase() call
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// MovePicker constructor for ProbCut: we generate captures with SEE higher
|
||||||
|
/// 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) {
|
||||||
|
|
||||||
/// MovePicker::score_captures(), MovePicker::score_noncaptures() and
|
assert(!pos.checkers());
|
||||||
/// MovePicker::score_evasions() assign a numerical move ordering score
|
|
||||||
/// to each move in a move list. The moves with highest scores will be
|
|
||||||
/// picked first by get_next_move().
|
|
||||||
|
|
||||||
void MovePicker::score_captures() {
|
stage = PROBCUT;
|
||||||
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
ttMove = ttm
|
||||||
// Suprisingly, this appears to perform slightly better than SEE based
|
&& pos.pseudo_legal(ttm)
|
||||||
// move ordering. The reason is probably that in a position with a winning
|
&& pos.capture(ttm)
|
||||||
// capture, capturing a more valuable (but sufficiently defended) piece
|
&& pos.see_ge(ttm, threshold) ? ttm : MOVE_NONE;
|
||||||
// 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
|
|
||||||
// badCaptures[] array, but instead of doing it now we delay till when
|
|
||||||
// the move has been picked up in pick_move_from_list(), this way we save
|
|
||||||
// some SEE calls in case we get a cutoff (idea from Pablo Vazquez).
|
|
||||||
Move m;
|
|
||||||
|
|
||||||
// Use MVV/LVA ordering
|
stage += (ttMove == MOVE_NONE);
|
||||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
|
||||||
{
|
|
||||||
m = cur->move;
|
|
||||||
if (move_is_promotion(m))
|
|
||||||
cur->score = QueenValueMidgame;
|
|
||||||
else
|
|
||||||
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
|
||||||
- pos.type_of_piece_on(move_from(m));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovePicker::score_noncaptures() {
|
/// 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 are ordered using the histories.
|
||||||
|
template<GenType Type>
|
||||||
|
void MovePicker::score() {
|
||||||
|
|
||||||
Move m;
|
static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
|
||||||
Square from;
|
|
||||||
|
|
||||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
for (auto& m : *this)
|
||||||
{
|
if (Type == CAPTURES)
|
||||||
m = cur->move;
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||||
from = move_from(m);
|
+ Value((*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))]);
|
||||||
cur->score = H.value(pos.piece_on(from), move_to(m));
|
|
||||||
}
|
else if (Type == QUIETS)
|
||||||
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||||
|
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
+ (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
+ (*contHistory[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)] - (1 << 28);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovePicker::score_evasions() {
|
/// next_move() is the most important method of the MovePicker class. It returns
|
||||||
// Try good captures ordered by MVV/LVA, then non-captures if
|
/// a new pseudo legal move every time it is called, until there are no more moves
|
||||||
// destination square is not under attack, ordered by history
|
/// left. It picks the move with the biggest value from a list of generated moves
|
||||||
// value, and at the end bad-captures and non-captures with a
|
/// taking care not to return the ttMove if it has already been searched.
|
||||||
// negative SEE. This last group is ordered by the SEE score.
|
|
||||||
Move m;
|
|
||||||
int seeScore;
|
|
||||||
|
|
||||||
// Skip if we don't have at least two moves to order
|
Move MovePicker::next_move(bool skipQuiets) {
|
||||||
if (lastMove < moves + 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
|
||||||
{
|
|
||||||
m = cur->move;
|
|
||||||
if ((seeScore = pos.see_sign(m)) < 0)
|
|
||||||
cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
|
|
||||||
else if (pos.move_is_capture(m))
|
|
||||||
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
|
||||||
- pos.type_of_piece_on(move_from(m)) + History::MaxValue;
|
|
||||||
else
|
|
||||||
cur->score = H.value(pos.piece_on(move_from(m)), move_to(m));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// MovePicker::get_next_move() is the most important method of the MovePicker
|
|
||||||
/// class. It returns a new legal move every time it is called, until there
|
|
||||||
/// are no more moves left. It picks the move with the biggest score from a list
|
|
||||||
/// of generated moves taking care not to return the tt move if has already been
|
|
||||||
/// searched previously. Note that this function is not thread safe so should be
|
|
||||||
/// lock protected by caller when accessed through a shared MovePicker object.
|
|
||||||
|
|
||||||
Move MovePicker::get_next_move() {
|
|
||||||
|
|
||||||
Move move;
|
Move move;
|
||||||
|
|
||||||
while (true)
|
switch (stage) {
|
||||||
{
|
|
||||||
while (curMove == lastMove)
|
|
||||||
go_next_phase();
|
|
||||||
|
|
||||||
switch (phase) {
|
case MAIN_SEARCH: case EVASION: case QSEARCH_WITH_CHECKS:
|
||||||
|
case QSEARCH_NO_CHECKS: case PROBCUT:
|
||||||
|
++stage;
|
||||||
|
return ttMove;
|
||||||
|
|
||||||
case PH_TT_MOVES:
|
case CAPTURES_INIT:
|
||||||
move = (curMove++)->move;
|
endBadCaptures = cur = moves;
|
||||||
if ( move != MOVE_NONE
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
&& pos.move_is_legal(move, pinned))
|
score<CAPTURES>();
|
||||||
return move;
|
++stage;
|
||||||
break;
|
/* fallthrough */
|
||||||
|
|
||||||
case PH_GOOD_CAPTURES:
|
case GOOD_CAPTURES:
|
||||||
move = pick_best(curMove++, lastMove).move;
|
while (cur < endMoves)
|
||||||
if ( move != ttMoves[0].move
|
{
|
||||||
&& move != ttMoves[1].move
|
move = pick_best(cur++, endMoves);
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
if (move != ttMove)
|
||||||
{
|
{
|
||||||
// Check for a non negative SEE now
|
if (pos.see_ge(move, Value(-55 * (cur-1)->value / 1024)))
|
||||||
int seeValue = pos.see_sign(move);
|
|
||||||
if (seeValue >= badCaptureThreshold)
|
|
||||||
return move;
|
return move;
|
||||||
|
|
||||||
// Losing capture, move it to the tail of the array, note
|
// Losing capture, move it to the beginning of the array
|
||||||
// that move has now been already checked for legality.
|
*endBadCaptures++ = move;
|
||||||
(--badCaptures)->move = move;
|
|
||||||
badCaptures->score = seeValue;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_KILLERS:
|
|
||||||
move = (curMove++)->move;
|
|
||||||
if ( move != MOVE_NONE
|
|
||||||
&& pos.move_is_legal(move, pinned)
|
|
||||||
&& move != ttMoves[0].move
|
|
||||||
&& move != ttMoves[1].move
|
|
||||||
&& !pos.move_is_capture(move))
|
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
|
||||||
// Sort negative scored moves only when we get there
|
|
||||||
if (curMove == lastGoodNonCapture)
|
|
||||||
insertion_sort<MoveStack>(lastGoodNonCapture, lastMove);
|
|
||||||
|
|
||||||
move = (curMove++)->move;
|
|
||||||
if ( move != ttMoves[0].move
|
|
||||||
&& move != ttMoves[1].move
|
|
||||||
&& move != killers[0].move
|
|
||||||
&& move != killers[1].move
|
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
|
||||||
move = pick_best(curMove++, lastMove).move;
|
|
||||||
return move;
|
|
||||||
|
|
||||||
case PH_EVASIONS:
|
|
||||||
case PH_QCAPTURES:
|
|
||||||
move = pick_best(curMove++, lastMove).move;
|
|
||||||
if ( move != ttMoves[0].move
|
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_QCHECKS:
|
|
||||||
move = (curMove++)->move;
|
|
||||||
if ( move != ttMoves[0].move
|
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_STOP:
|
|
||||||
return MOVE_NONE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++stage;
|
||||||
|
move = killers[0]; // First killer move
|
||||||
|
if ( move != MOVE_NONE
|
||||||
|
&& move != ttMove
|
||||||
|
&& pos.pseudo_legal(move)
|
||||||
|
&& !pos.capture(move))
|
||||||
|
return move;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case KILLERS:
|
||||||
|
++stage;
|
||||||
|
move = killers[1]; // Second killer move
|
||||||
|
if ( move != MOVE_NONE
|
||||||
|
&& move != ttMove
|
||||||
|
&& pos.pseudo_legal(move)
|
||||||
|
&& !pos.capture(move))
|
||||||
|
return move;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case COUNTERMOVE:
|
||||||
|
++stage;
|
||||||
|
move = countermove;
|
||||||
|
if ( move != MOVE_NONE
|
||||||
|
&& move != ttMove
|
||||||
|
&& move != killers[0]
|
||||||
|
&& move != killers[1]
|
||||||
|
&& pos.pseudo_legal(move)
|
||||||
|
&& !pos.capture(move))
|
||||||
|
return move;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QUIET_INIT:
|
||||||
|
cur = endBadCaptures;
|
||||||
|
endMoves = generate<QUIETS>(pos, cur);
|
||||||
|
score<QUIETS>();
|
||||||
|
partial_insertion_sort(cur, endMoves, -4000 * depth / ONE_PLY);
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QUIET:
|
||||||
|
while ( cur < endMoves
|
||||||
|
&& (!skipQuiets || cur->value >= VALUE_ZERO))
|
||||||
|
{
|
||||||
|
move = *cur++;
|
||||||
|
|
||||||
|
if ( move != ttMove
|
||||||
|
&& move != killers[0]
|
||||||
|
&& move != killers[1]
|
||||||
|
&& move != countermove)
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
++stage;
|
||||||
|
cur = moves; // Point to beginning of bad captures
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case BAD_CAPTURES:
|
||||||
|
if (cur < endBadCaptures)
|
||||||
|
return *cur++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EVASIONS_INIT:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<EVASIONS>(pos, cur);
|
||||||
|
score<EVASIONS>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case ALL_EVASIONS:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
|
move = pick_best(cur++, endMoves);
|
||||||
|
if (move != ttMove)
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROBCUT_INIT:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
|
score<CAPTURES>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case PROBCUT_CAPTURES:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
|
move = pick_best(cur++, endMoves);
|
||||||
|
if ( move != ttMove
|
||||||
|
&& pos.see_ge(move, threshold))
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QCAPTURES_1_INIT: case QCAPTURES_2_INIT:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
|
score<CAPTURES>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QCAPTURES_1: case QCAPTURES_2:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
|
move = pick_best(cur++, endMoves);
|
||||||
|
if (move != ttMove)
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
if (stage == QCAPTURES_2)
|
||||||
|
break;
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QCHECKS:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
|
move = cur++->move;
|
||||||
|
if (move != ttMove)
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QSEARCH_RECAPTURES:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
|
score<CAPTURES>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QRECAPTURES:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
|
move = pick_best(cur++, endMoves);
|
||||||
|
if (to_sq(move) == recaptureSquare)
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
+121
-33
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,47 +18,134 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined MOVEPICK_H_INCLUDED
|
#ifndef MOVEPICK_H_INCLUDED
|
||||||
#define MOVEPICK_H_INCLUDED
|
#define MOVEPICK_H_INCLUDED
|
||||||
|
|
||||||
#include "history.h"
|
#include <array>
|
||||||
#include "move.h"
|
#include <limits>
|
||||||
|
|
||||||
|
#include "movegen.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
struct SearchStack;
|
/// StatBoards is a generic 2-dimensional array used to store various statistics
|
||||||
|
template<int Size1, int Size2, typename T = int16_t>
|
||||||
|
struct StatBoards : public std::array<std::array<T, Size2>, Size1> {
|
||||||
|
|
||||||
/// MovePicker is a class which is used to pick one legal move at a time from
|
void fill(const T& v) {
|
||||||
/// the current position. It is initialized with a Position object and a few
|
T* p = &(*this)[0][0];
|
||||||
/// moves we have reason to believe are good. The most important method is
|
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
|
||||||
/// MovePicker::get_next_move(), which returns a new legal move each time it
|
}
|
||||||
/// is called, until there are no legal moves left, 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 {
|
void update(T& entry, int bonus, const int D) {
|
||||||
|
|
||||||
MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
|
assert(abs(bonus) <= D); // Ensure range is [-32 * D, 32 * D]
|
||||||
|
assert(abs(32 * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
|
||||||
|
|
||||||
public:
|
entry += bonus * 32 - entry * abs(bonus) / D;
|
||||||
MovePicker(const Position&, Move, Depth, const History&, SearchStack*, Value);
|
|
||||||
MovePicker(const Position&, Move, Depth, const History&);
|
|
||||||
Move get_next_move();
|
|
||||||
|
|
||||||
private:
|
assert(abs(entry) <= 32 * D);
|
||||||
void score_captures();
|
}
|
||||||
void score_noncaptures();
|
|
||||||
void score_evasions();
|
|
||||||
void go_next_phase();
|
|
||||||
|
|
||||||
const Position& pos;
|
|
||||||
const History& H;
|
|
||||||
Bitboard pinned;
|
|
||||||
MoveStack ttMoves[2], killers[2];
|
|
||||||
int badCaptureThreshold, phase;
|
|
||||||
const uint8_t* phasePtr;
|
|
||||||
MoveStack *curMove, *lastMove, *lastGoodNonCapture, *badCaptures;
|
|
||||||
MoveStack moves[MAX_MOVES];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !defined(MOVEPICK_H_INCLUDED)
|
/// StatCubes is a generic 3-dimensional array used to store various statistics
|
||||||
|
template<int Size1, int Size2, int Size3, typename T = int16_t>
|
||||||
|
struct StatCubes : public std::array<std::array<std::array<T, Size3>, Size2>, Size1> {
|
||||||
|
|
||||||
|
void fill(const T& v) {
|
||||||
|
T* p = &(*this)[0][0][0];
|
||||||
|
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(T& entry, int bonus, const int D, const int W) {
|
||||||
|
|
||||||
|
assert(abs(bonus) <= D); // Ensure range is [-W * D, W * D]
|
||||||
|
assert(abs(W * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
|
||||||
|
|
||||||
|
entry += bonus * W - entry * abs(bonus) / D;
|
||||||
|
|
||||||
|
assert(abs(entry) <= W * D);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// ButterflyBoards are 2 tables (one for each color) indexed by the move's from
|
||||||
|
/// and to squares, see chessprogramming.wikispaces.com/Butterfly+Boards
|
||||||
|
typedef StatBoards<COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyBoards;
|
||||||
|
|
||||||
|
/// PieceToBoards are addressed by a move's [piece][to] information
|
||||||
|
typedef StatBoards<PIECE_NB, SQUARE_NB> PieceToBoards;
|
||||||
|
|
||||||
|
/// CapturePieceToBoards are addressed by a move's [piece][to][captured piece type] information
|
||||||
|
typedef StatCubes<PIECE_NB, SQUARE_NB, PIECE_TYPE_NB> CapturePieceToBoards;
|
||||||
|
|
||||||
|
/// ButterflyHistory records how often quiet moves have been successful or
|
||||||
|
/// unsuccessful during the current search, and is used for reduction and move
|
||||||
|
/// ordering decisions. It uses ButterflyBoards as backing store.
|
||||||
|
struct ButterflyHistory : public ButterflyBoards {
|
||||||
|
|
||||||
|
void update(Color c, Move m, int bonus) {
|
||||||
|
StatBoards::update((*this)[c][from_to(m)], bonus, 324);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// PieceToHistory is like ButterflyHistory, but is based on PieceToBoards
|
||||||
|
struct PieceToHistory : public PieceToBoards {
|
||||||
|
|
||||||
|
void update(Piece pc, Square to, int bonus) {
|
||||||
|
StatBoards::update((*this)[pc][to], bonus, 936);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// CapturePieceToHistory is like PieceToHistory, but is based on CapturePieceToBoards
|
||||||
|
struct CapturePieceToHistory : public CapturePieceToBoards {
|
||||||
|
|
||||||
|
void update(Piece pc, Square to, PieceType captured, int bonus) {
|
||||||
|
StatCubes::update((*this)[pc][to][captured], bonus, 324, 2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous
|
||||||
|
/// move, see chessprogramming.wikispaces.com/Countermove+Heuristic
|
||||||
|
typedef StatBoards<PIECE_NB, SQUARE_NB, Move> CounterMoveHistory;
|
||||||
|
|
||||||
|
/// ContinuationHistory is the history of a given pair of moves, usually the
|
||||||
|
/// current one given a previous one. History table is based on PieceToBoards
|
||||||
|
/// instead of ButterflyBoards.
|
||||||
|
typedef StatBoards<PIECE_NB, SQUARE_NB, PieceToHistory> ContinuationHistory;
|
||||||
|
|
||||||
|
|
||||||
|
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
||||||
|
/// current position. The most important method is next_move(), which returns a
|
||||||
|
/// new pseudo legal move each time it is called, until there are no moves left,
|
||||||
|
/// 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 {
|
||||||
|
public:
|
||||||
|
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*, Square);
|
||||||
|
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const CapturePieceToHistory*, const PieceToHistory**, Move, Move*);
|
||||||
|
Move next_move(bool skipQuiets = false);
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<GenType> void score();
|
||||||
|
ExtMove* begin() { return cur; }
|
||||||
|
ExtMove* end() { return endMoves; }
|
||||||
|
|
||||||
|
const Position& pos;
|
||||||
|
const ButterflyHistory* mainHistory;
|
||||||
|
const CapturePieceToHistory* captureHistory;
|
||||||
|
const PieceToHistory** contHistory;
|
||||||
|
Move ttMove, countermove, killers[2];
|
||||||
|
ExtMove *cur, *endMoves, *endBadCaptures;
|
||||||
|
int stage;
|
||||||
|
Square recaptureSquare;
|
||||||
|
Value threshold;
|
||||||
|
Depth depth;
|
||||||
|
ExtMove moves[MAX_MOVES];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // #ifndef MOVEPICK_H_INCLUDED
|
||||||
|
|||||||
+231
-175
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,227 +18,282 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "bitcount.h"
|
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#define V Value
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
|
|
||||||
// Doubled pawn penalty by opposed flag and file
|
// Isolated pawn penalty
|
||||||
const Score DoubledPawnPenalty[2][8] = {
|
const Score Isolated = S(13, 18);
|
||||||
{ S(13, 43), S(20, 48), S(23, 48), S(23, 48),
|
|
||||||
S(23, 48), S(23, 48), S(20, 48), S(13, 43) },
|
|
||||||
{ S(13, 43), S(20, 48), S(23, 48), S(23, 48),
|
|
||||||
S(23, 48), S(23, 48), S(20, 48), S(13, 43) }};
|
|
||||||
|
|
||||||
// Isolated pawn penalty by opposed flag and file
|
// Backward pawn penalty
|
||||||
const Score IsolatedPawnPenalty[2][8] = {
|
const Score Backward = S(24, 12);
|
||||||
{ 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) }};
|
|
||||||
|
|
||||||
// Backward pawn penalty by opposed flag and file
|
// Connected pawn bonus by opposed, phalanx, #support and rank
|
||||||
const Score BackwardPawnPenalty[2][8] = {
|
Score Connected[2][2][3][RANK_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) }};
|
|
||||||
|
|
||||||
// Pawn chain membership bonus by file
|
// Doubled pawn penalty
|
||||||
const Score ChainBonus[8] = {
|
const Score Doubled = S(18, 38);
|
||||||
S(11,-1), S(13,-1), S(13,-1), S(14,-1),
|
|
||||||
S(14,-1), S(13,-1), S(13,-1), S(11,-1)
|
// Weakness of our pawn shelter in front of the king by [isKingFile][distance from edge][rank].
|
||||||
|
// RANK_1 = 0 is used for files where we have no pawns or our pawn is behind our king.
|
||||||
|
const Value ShelterWeakness[][int(FILE_NB) / 2][RANK_NB] = {
|
||||||
|
{ { V( 97), V(17), V( 9), V(44), V( 84), V( 87), V( 99) }, // Not On King file
|
||||||
|
{ V(106), V( 6), V(33), V(86), V( 87), V(104), V(112) },
|
||||||
|
{ V(101), V( 2), V(65), V(98), V( 58), V( 89), V(115) },
|
||||||
|
{ V( 73), V( 7), V(54), V(73), V( 84), V( 83), V(111) } },
|
||||||
|
{ { V(104), V(20), V( 6), V(27), V( 86), V( 93), V( 82) }, // On King file
|
||||||
|
{ V(123), V( 9), V(34), V(96), V(112), V( 88), V( 75) },
|
||||||
|
{ V(120), V(25), V(65), V(91), V( 66), V( 78), V(117) },
|
||||||
|
{ V( 81), V( 2), V(47), V(63), V( 94), V( 93), V(104) } }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Candidate passed pawn bonus by rank
|
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank].
|
||||||
const Score CandidateBonus[8] = {
|
// For the unopposed and unblocked cases, RANK_1 = 0 is used when opponent has
|
||||||
S( 0, 0), S( 6, 13), S(6,13), S(14,29),
|
// no pawn on the given file, or their pawn is behind our king.
|
||||||
S(34,68), S(83,166), S(0, 0), S( 0, 0)
|
const Value StormDanger[][4][RANK_NB] = {
|
||||||
|
{ { V( 0), V(-290), V(-274), V(57), V(41) }, // BlockedByKing
|
||||||
|
{ V( 0), V( 60), V( 144), V(39), V(13) },
|
||||||
|
{ V( 0), V( 65), V( 141), V(41), V(34) },
|
||||||
|
{ V( 0), V( 53), V( 127), V(56), V(14) } },
|
||||||
|
{ { V( 4), V( 73), V( 132), V(46), V(31) }, // Unopposed
|
||||||
|
{ V( 1), V( 64), V( 143), V(26), V(13) },
|
||||||
|
{ V( 1), V( 47), V( 110), V(44), V(24) },
|
||||||
|
{ V( 0), V( 72), V( 127), V(50), V(31) } },
|
||||||
|
{ { V( 0), V( 0), V( 79), V(23), V( 1) }, // BlockedByPawn
|
||||||
|
{ V( 0), V( 0), V( 148), V(27), V( 2) },
|
||||||
|
{ V( 0), V( 0), V( 161), V(16), V( 1) },
|
||||||
|
{ V( 0), V( 0), V( 171), V(22), V(15) } },
|
||||||
|
{ { V(22), V( 45), V( 104), V(62), V( 6) }, // Unblocked
|
||||||
|
{ V(31), V( 30), V( 99), V(39), V(19) },
|
||||||
|
{ V(23), V( 29), V( 96), V(41), V(15) },
|
||||||
|
{ V(21), V( 23), V( 116), V(41), V(15) } }
|
||||||
};
|
};
|
||||||
|
|
||||||
const Score PawnStructureWeight = S(233, 201);
|
// Max bonus for king safety. Corresponds to start position with all the pawns
|
||||||
|
// in front of the king and no enemy pawn on the horizon.
|
||||||
|
const Value MaxSafetyBonus = V(258);
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
|
#undef V
|
||||||
|
|
||||||
inline Score apply_weight(Score v, Score w) {
|
template<Color Us>
|
||||||
return make_score((int(mg_value(v)) * mg_value(w)) / 0x100,
|
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
||||||
(int(eg_value(v)) * eg_value(w)) / 0x100);
|
|
||||||
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
|
const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||||
|
const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||||
|
|
||||||
|
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
|
||||||
|
Bitboard lever, leverPush;
|
||||||
|
Square s;
|
||||||
|
bool opposed, backward;
|
||||||
|
Score score = SCORE_ZERO;
|
||||||
|
const Square* pl = pos.squares<PAWN>(Us);
|
||||||
|
|
||||||
|
Bitboard ourPawns = pos.pieces( Us, PAWN);
|
||||||
|
Bitboard theirPawns = pos.pieces(Them, PAWN);
|
||||||
|
|
||||||
|
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = e->weakUnopposed[Us] = 0;
|
||||||
|
e->semiopenFiles[Us] = 0xFF;
|
||||||
|
e->kingSquares[Us] = SQ_NONE;
|
||||||
|
e->pawnAttacks[Us] = shift<Right>(ourPawns) | shift<Left>(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
|
||||||
|
while ((s = *pl++) != SQ_NONE)
|
||||||
|
{
|
||||||
|
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
||||||
|
|
||||||
|
File f = file_of(s);
|
||||||
|
|
||||||
|
e->semiopenFiles[Us] &= ~(1 << f);
|
||||||
|
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// A pawn is backward when it is behind all pawns of the same color on the
|
||||||
|
// adjacent files and cannot be safely advanced.
|
||||||
|
if (!neighbours || lever || relative_rank(Us, s) >= RANK_5)
|
||||||
|
backward = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Find the backmost rank with neighbours or stoppers
|
||||||
|
b = rank_bb(backmost_sq(Us, neighbours | stoppers));
|
||||||
|
|
||||||
|
// The pawn is backward when it cannot safely progress to that rank:
|
||||||
|
// either there is a stopper in the way on this rank, or there is a
|
||||||
|
// stopper on adjacent file which controls the way to that rank.
|
||||||
|
backward = (b | shift<Up>(b & adjacent_files_bb(f))) & stoppers;
|
||||||
|
|
||||||
|
assert(!(backward && (forward_ranks_bb(Them, s + Up) & neighbours)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passed pawns will be properly scored in evaluation because we need
|
||||||
|
// 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)
|
||||||
|
&& !(ourPawns & forward_file_bb(Us, s))
|
||||||
|
&& popcount(supported) >= popcount(lever)
|
||||||
|
&& 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 (supported | phalanx)
|
||||||
|
score += Connected[opposed][bool(phalanx)][popcount(supported)][relative_rank(Us, s)];
|
||||||
|
|
||||||
|
else if (!neighbours)
|
||||||
|
score -= Isolated, e->weakUnopposed[Us] += !opposed;
|
||||||
|
|
||||||
|
else if (backward)
|
||||||
|
score -= Backward, e->weakUnopposed[Us] += !opposed;
|
||||||
|
|
||||||
|
if (doubled && !supported)
|
||||||
|
score -= Doubled;
|
||||||
|
}
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace Pawns {
|
||||||
|
|
||||||
|
/// Pawns::init() initializes some tables needed by evaluation. Instead of using
|
||||||
|
/// hard-coded tables, when makes sense, we prefer to calculate them with a formula
|
||||||
|
/// to reduce independent parameters and to allow easier tuning and better insight.
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
|
||||||
|
static const int Seed[RANK_NB] = { 0, 13, 24, 18, 76, 100, 175, 330 };
|
||||||
|
|
||||||
|
for (int opposed = 0; opposed <= 1; ++opposed)
|
||||||
|
for (int phalanx = 0; phalanx <= 1; ++phalanx)
|
||||||
|
for (int support = 0; support <= 2; ++support)
|
||||||
|
for (Rank r = RANK_2; r < RANK_8; ++r)
|
||||||
|
{
|
||||||
|
int v = 17 * support;
|
||||||
|
v += (Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0)) >> opposed;
|
||||||
|
|
||||||
|
Connected[opposed][phalanx][support][r] = make_score(v, v * (r - 2) / 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// PawnInfoTable::get_pawn_info() takes a position object as input, computes
|
/// Pawns::probe() looks up the current position's pawns configuration in
|
||||||
/// a PawnInfo object, and returns a pointer to it. The result is also stored
|
/// the pawns hash table. It returns a pointer to the Entry if the position
|
||||||
/// in an hash table, so we don't have to recompute everything when the same
|
/// is found. Otherwise a new Entry is computed and stored there, so we don't
|
||||||
/// pawn structure occurs again.
|
/// have to recompute all when the same pawns configuration occurs again.
|
||||||
|
|
||||||
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const {
|
Entry* probe(const Position& pos) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
Key key = pos.pawn_key();
|
||||||
|
Entry* e = pos.this_thread()->pawnsTable[key];
|
||||||
|
|
||||||
Key key = pos.get_pawn_key();
|
if (e->key == key)
|
||||||
PawnInfo* pi = probe(key);
|
return e;
|
||||||
|
|
||||||
// If pi->key matches the position's pawn hash key, it means that we
|
e->key = key;
|
||||||
// have analysed this pawn structure before, and we can simply return
|
e->score = evaluate<WHITE>(pos, e) - evaluate<BLACK>(pos, e);
|
||||||
// the information we found the last time instead of recomputing it.
|
e->asymmetry = popcount(e->semiopenFiles[WHITE] ^ e->semiopenFiles[BLACK]);
|
||||||
if (pi->key == key)
|
e->openFiles = popcount(e->semiopenFiles[WHITE] & e->semiopenFiles[BLACK]);
|
||||||
return pi;
|
return e;
|
||||||
|
|
||||||
// Initialize PawnInfo entry
|
|
||||||
pi->key = key;
|
|
||||||
pi->passedPawns[WHITE] = pi->passedPawns[BLACK] = 0;
|
|
||||||
pi->kingSquares[WHITE] = pi->kingSquares[BLACK] = SQ_NONE;
|
|
||||||
pi->halfOpenFiles[WHITE] = pi->halfOpenFiles[BLACK] = 0xFF;
|
|
||||||
|
|
||||||
// Calculate pawn attacks
|
|
||||||
Bitboard wPawns = pos.pieces(PAWN, WHITE);
|
|
||||||
Bitboard bPawns = pos.pieces(PAWN, BLACK);
|
|
||||||
pi->pawnAttacks[WHITE] = ((wPawns << 9) & ~FileABB) | ((wPawns << 7) & ~FileHBB);
|
|
||||||
pi->pawnAttacks[BLACK] = ((bPawns >> 7) & ~FileABB) | ((bPawns >> 9) & ~FileHBB);
|
|
||||||
|
|
||||||
// Evaluate pawns for both colors and weight the result
|
|
||||||
pi->value = evaluate_pawns<WHITE>(pos, wPawns, bPawns, pi)
|
|
||||||
- evaluate_pawns<BLACK>(pos, bPawns, wPawns, pi);
|
|
||||||
|
|
||||||
pi->value = apply_weight(pi->value, PawnStructureWeight);
|
|
||||||
|
|
||||||
return pi;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// PawnInfoTable::evaluate_pawns() evaluates each pawn of the given color
|
/// Entry::shelter_storm() calculates shelter and storm penalties for the file
|
||||||
|
/// the king is on, as well as the two closest files.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
|
Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
||||||
Bitboard theirPawns, PawnInfo* pi) {
|
|
||||||
|
|
||||||
const BitCountType Max15 = CpuIs64Bit ? CNT64_MAX15 : CNT32_MAX15;
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
Bitboard b;
|
enum { BlockedByKing, Unopposed, BlockedByPawn, Unblocked };
|
||||||
Square s;
|
|
||||||
File f;
|
|
||||||
Rank r;
|
|
||||||
bool passed, isolated, doubled, opposed, chain, backward, candidate;
|
|
||||||
Score value = SCORE_ZERO;
|
|
||||||
const Square* ptr = pos.piece_list_begin(Us, PAWN);
|
|
||||||
|
|
||||||
// Loop through all pawns of the current color and score each pawn
|
Bitboard b = pos.pieces(PAWN) & (forward_ranks_bb(Us, ksq) | rank_bb(ksq));
|
||||||
while ((s = *ptr++) != SQ_NONE)
|
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 = File(center - 1); f <= File(center + 1); ++f)
|
||||||
{
|
{
|
||||||
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
b = ourPawns & file_bb(f);
|
||||||
|
Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
|
||||||
|
|
||||||
f = square_file(s);
|
b = theirPawns & file_bb(f);
|
||||||
r = square_rank(s);
|
Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
|
||||||
|
|
||||||
// This file cannot be half open
|
int d = std::min(f, ~f);
|
||||||
pi->halfOpenFiles[Us] &= ~(1 << f);
|
safety -= ShelterWeakness[f == file_of(ksq)][d][rkUs]
|
||||||
|
+ StormDanger
|
||||||
// Our rank plus previous one. Used for chain detection
|
[f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing :
|
||||||
b = rank_bb(r) | rank_bb(Us == WHITE ? r - Rank(1) : r + Rank(1));
|
rkUs == RANK_1 ? Unopposed :
|
||||||
|
rkThem == rkUs + 1 ? BlockedByPawn : Unblocked]
|
||||||
// Flag the pawn as passed, isolated, doubled or member of a pawn
|
[d][rkThem];
|
||||||
// chain (but not the backward one).
|
|
||||||
passed = !(theirPawns & passed_pawn_mask(Us, s));
|
|
||||||
doubled = ourPawns & squares_in_front_of(Us, s);
|
|
||||||
opposed = theirPawns & squares_in_front_of(Us, s);
|
|
||||||
isolated = !(ourPawns & neighboring_files_bb(f));
|
|
||||||
chain = ourPawns & neighboring_files_bb(f) & b;
|
|
||||||
|
|
||||||
// Test for backward pawn
|
|
||||||
backward = false;
|
|
||||||
|
|
||||||
// If the pawn is passed, isolated, or member of a pawn chain it cannot
|
|
||||||
// be backward. If there are friendly pawns behind on neighboring files
|
|
||||||
// or if can capture an enemy pawn it cannot be backward either.
|
|
||||||
if ( !(passed | isolated | chain)
|
|
||||||
&& !(ourPawns & attack_span_mask(Them, s))
|
|
||||||
&& !(pos.attacks_from<PAWN>(s, Us) & theirPawns))
|
|
||||||
{
|
|
||||||
// We now know that there are no friendly pawns beside or behind this
|
|
||||||
// pawn on neighboring files. We now check whether the pawn is
|
|
||||||
// backward by looking in the forward direction on the neighboring
|
|
||||||
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
|
||||||
b = pos.attacks_from<PAWN>(s, Us);
|
|
||||||
|
|
||||||
// Note that we are sure to find something because pawn is not passed
|
|
||||||
// nor isolated, so loop is potentially infinite, but it isn't.
|
|
||||||
while (!(b & (ourPawns | theirPawns)))
|
|
||||||
Us == WHITE ? b <<= 8 : b >>= 8;
|
|
||||||
|
|
||||||
// The friendly pawn needs to be at least two ranks closer than the
|
|
||||||
// enemy pawn in order to help the potentially backward pawn advance.
|
|
||||||
backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(opposed | passed | (attack_span_mask(Us, s) & theirPawns));
|
|
||||||
|
|
||||||
// A not passed pawn is a candidate to become passed if it is free to
|
|
||||||
// advance and if the number of friendly pawns beside or behind this
|
|
||||||
// pawn on neighboring files is higher or equal than the number of
|
|
||||||
// enemy pawns in the forward direction on the neighboring files.
|
|
||||||
candidate = !(opposed | passed | backward | isolated)
|
|
||||||
&& (b = attack_span_mask(Them, s + pawn_push(Us)) & ourPawns) != EmptyBoardBB
|
|
||||||
&& count_1s<Max15>(b) >= count_1s<Max15>(attack_span_mask(Us, s) & theirPawns);
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
set_bit(&(pi->passedPawns[Us]), s);
|
|
||||||
|
|
||||||
// Score this pawn
|
|
||||||
if (isolated)
|
|
||||||
value -= IsolatedPawnPenalty[opposed][f];
|
|
||||||
|
|
||||||
if (doubled)
|
|
||||||
value -= DoubledPawnPenalty[opposed][f];
|
|
||||||
|
|
||||||
if (backward)
|
|
||||||
value -= BackwardPawnPenalty[opposed][f];
|
|
||||||
|
|
||||||
if (chain)
|
|
||||||
value += ChainBonus[f];
|
|
||||||
|
|
||||||
if (candidate)
|
|
||||||
value += CandidateBonus[relative_rank(Us, s)];
|
|
||||||
}
|
}
|
||||||
return value;
|
|
||||||
|
return safety;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// PawnInfo::updateShelter() calculates and caches king shelter. It is called
|
/// Entry::do_king_safety() calculates a bonus for king safety. It is called only
|
||||||
/// only when king square changes, about 20% of total king_shelter() calls.
|
/// when king square changes, which is about 20% of total king_safety() calls.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score PawnInfo::updateShelter(const Position& pos, Square ksq) {
|
Score Entry::do_king_safety(const Position& pos, Square ksq) {
|
||||||
|
|
||||||
const int Shift = (Us == WHITE ? 8 : -8);
|
|
||||||
|
|
||||||
Bitboard pawns;
|
|
||||||
int r, shelter = 0;
|
|
||||||
|
|
||||||
if (relative_rank(Us, ksq) <= RANK_4)
|
|
||||||
{
|
|
||||||
pawns = pos.pieces(PAWN, Us) & this_and_neighboring_files_bb(ksq);
|
|
||||||
r = ksq & (7 << 3);
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
r += Shift;
|
|
||||||
shelter += BitCount8Bit[(pawns >> r) & 0xFF] * (64 >> i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
kingSquares[Us] = ksq;
|
kingSquares[Us] = ksq;
|
||||||
kingShelters[Us] = make_score(shelter, 0);
|
castlingRights[Us] = pos.can_castle(Us);
|
||||||
return kingShelters[Us];
|
int minKingPawnDistance = 0;
|
||||||
|
|
||||||
|
Bitboard pawns = pos.pieces(Us, PAWN);
|
||||||
|
if (pawns)
|
||||||
|
while (!(DistanceRingBB[ksq][minKingPawnDistance++] & pawns)) {}
|
||||||
|
|
||||||
|
Value bonus = shelter_storm<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(MakeCastling<Us, QUEEN_SIDE>::right))
|
||||||
|
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1)));
|
||||||
|
|
||||||
|
return make_score(bonus, -16 * minKingPawnDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit template instantiation
|
// Explicit template instantiation
|
||||||
template Score PawnInfo::updateShelter<WHITE>(const Position& pos, Square ksq);
|
template Score Entry::do_king_safety<WHITE>(const Position& pos, Square ksq);
|
||||||
template Score PawnInfo::updateShelter<BLACK>(const Position& pos, Square ksq);
|
template Score Entry::do_king_safety<BLACK>(const Position& pos, Square ksq);
|
||||||
|
|
||||||
|
} // namespace Pawns
|
||||||
|
|||||||
+52
-69
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,91 +18,73 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(PAWNS_H_INCLUDED)
|
#ifndef PAWNS_H_INCLUDED
|
||||||
#define PAWNS_H_INCLUDED
|
#define PAWNS_H_INCLUDED
|
||||||
|
|
||||||
|
#include "misc.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "tt.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
const int PawnTableSize = 16384;
|
namespace Pawns {
|
||||||
|
|
||||||
/// PawnInfo is a class which contains various information about a pawn
|
/// Pawns::Entry contains various information about a pawn structure. A lookup
|
||||||
/// structure. Currently, it only includes a middle game and an end game
|
/// to the pawn hash table (performed by calling the probe function) returns a
|
||||||
/// pawn structure evaluation, and a bitboard of passed pawns. We may want
|
/// pointer to an Entry object.
|
||||||
/// to add further information in the future. A lookup to the pawn hash table
|
|
||||||
/// (performed by calling the get_pawn_info method in a PawnInfoTable object)
|
|
||||||
/// returns a pointer to a PawnInfo object.
|
|
||||||
|
|
||||||
class PawnInfo {
|
struct Entry {
|
||||||
|
|
||||||
friend class PawnInfoTable;
|
Score pawns_score() const { return score; }
|
||||||
|
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
|
||||||
|
Bitboard passed_pawns(Color c) const { return passedPawns[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; }
|
||||||
|
|
||||||
public:
|
int semiopen_file(Color c, File f) const {
|
||||||
Score pawns_value() const;
|
return semiopenFiles[c] & (1 << f);
|
||||||
Bitboard pawn_attacks(Color c) const;
|
}
|
||||||
Bitboard passed_pawns(Color c) const;
|
|
||||||
int file_is_half_open(Color c, File f) const;
|
int semiopen_side(Color c, File f, bool leftSide) const {
|
||||||
int has_open_file_to_left(Color c, File f) const;
|
return semiopenFiles[c] & (leftSide ? (1 << f) - 1 : ~((1 << (f + 1)) - 1));
|
||||||
int has_open_file_to_right(Color c, File f) const;
|
}
|
||||||
|
|
||||||
|
int pawns_on_same_color_squares(Color c, Square s) const {
|
||||||
|
return pawnsOnSquares[c][bool(DarkSquares & s)];
|
||||||
|
}
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score king_shelter(const Position& pos, Square ksq);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score updateShelter(const Position& pos, Square ksq);
|
Score do_king_safety(const Position& pos, Square ksq);
|
||||||
|
|
||||||
|
template<Color Us>
|
||||||
|
Value shelter_storm(const Position& pos, Square ksq);
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
Bitboard passedPawns[2];
|
Score score;
|
||||||
Bitboard pawnAttacks[2];
|
Bitboard passedPawns[COLOR_NB];
|
||||||
Square kingSquares[2];
|
Bitboard pawnAttacks[COLOR_NB];
|
||||||
Score value;
|
Bitboard pawnAttacksSpan[COLOR_NB];
|
||||||
int halfOpenFiles[2];
|
Square kingSquares[COLOR_NB];
|
||||||
Score kingShelters[2];
|
Score kingSafety[COLOR_NB];
|
||||||
|
int weakUnopposed[COLOR_NB];
|
||||||
|
int castlingRights[COLOR_NB];
|
||||||
|
int semiopenFiles[COLOR_NB];
|
||||||
|
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
||||||
|
int asymmetry;
|
||||||
|
int openFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef HashTable<Entry, 16384> Table;
|
||||||
|
|
||||||
/// The PawnInfoTable class represents a pawn hash table. The most important
|
void init();
|
||||||
/// method is get_pawn_info, which returns a pointer to a PawnInfo object.
|
Entry* probe(const Position& pos);
|
||||||
|
|
||||||
class PawnInfoTable : public SimpleHash<PawnInfo, PawnTableSize> {
|
} // namespace Pawns
|
||||||
public:
|
|
||||||
PawnInfo* get_pawn_info(const Position& pos) const;
|
|
||||||
|
|
||||||
private:
|
#endif // #ifndef PAWNS_H_INCLUDED
|
||||||
template<Color Us>
|
|
||||||
static Score evaluate_pawns(const Position& pos, Bitboard ourPawns, Bitboard theirPawns, PawnInfo* pi);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
inline Score PawnInfo::pawns_value() const {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard PawnInfo::pawn_attacks(Color c) const {
|
|
||||||
return pawnAttacks[c];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard PawnInfo::passed_pawns(Color c) const {
|
|
||||||
return passedPawns[c];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int PawnInfo::file_is_half_open(Color c, File f) const {
|
|
||||||
return halfOpenFiles[c] & (1 << int(f));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int PawnInfo::has_open_file_to_left(Color c, File f) const {
|
|
||||||
return halfOpenFiles[c] & ((1 << int(f)) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int PawnInfo::has_open_file_to_right(Color c, File f) const {
|
|
||||||
return halfOpenFiles[c] & ~((1 << int(f+1)) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Color Us>
|
|
||||||
inline Score PawnInfo::king_shelter(const Position& pos, Square ksq) {
|
|
||||||
return kingSquares[Us] == ksq ? kingShelters[Us] : updateShelter<Us>(pos, ksq);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(PAWNS_H_INCLUDED)
|
|
||||||
|
|||||||
+833
-1704
File diff suppressed because it is too large
Load Diff
+259
-386
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,538 +18,410 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(POSITION_H_INCLUDED)
|
#ifndef POSITION_H_INCLUDED
|
||||||
#define POSITION_H_INCLUDED
|
#define POSITION_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <deque>
|
||||||
|
#include <memory> // For std::unique_ptr
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "move.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
/// Maximum number of plies per game (220 should be enough, because the
|
|
||||||
/// maximum search depth is 100, and during position setup we reset the
|
|
||||||
/// move counter for every non-reversible move).
|
|
||||||
const int MaxGameLength = 220;
|
|
||||||
|
|
||||||
class Position;
|
/// 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
|
||||||
/// struct checkInfo is initialized at c'tor time and keeps
|
/// board (by calling Position::do_move), a StateInfo object must be passed.
|
||||||
/// info used to detect if a move gives check.
|
|
||||||
|
|
||||||
struct CheckInfo {
|
|
||||||
|
|
||||||
explicit CheckInfo(const Position&);
|
|
||||||
|
|
||||||
Bitboard dcCandidates;
|
|
||||||
Bitboard checkSq[8];
|
|
||||||
Square ksq;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Castle rights, encoded as bit fields
|
|
||||||
|
|
||||||
enum CastleRights {
|
|
||||||
CASTLES_NONE = 0,
|
|
||||||
WHITE_OO = 1,
|
|
||||||
BLACK_OO = 2,
|
|
||||||
WHITE_OOO = 4,
|
|
||||||
BLACK_OOO = 8,
|
|
||||||
ALL_CASTLES = 15
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Game phase
|
|
||||||
enum Phase {
|
|
||||||
PHASE_ENDGAME = 0,
|
|
||||||
PHASE_MIDGAME = 128
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// The StateInfo struct stores information we need to restore a Position
|
|
||||||
/// object to its previous state when we retract a move. Whenever a move
|
|
||||||
/// is made on the board (by calling Position::do_move), an StateInfo object
|
|
||||||
/// must be passed as a parameter.
|
|
||||||
|
|
||||||
struct StateInfo {
|
struct StateInfo {
|
||||||
Key pawnKey, materialKey;
|
|
||||||
int castleRights, rule50, gamePly, pliesFromNull;
|
|
||||||
Square epSquare;
|
|
||||||
Score value;
|
|
||||||
Value npMaterial[2];
|
|
||||||
|
|
||||||
PieceType capturedType;
|
// Copied when making a move
|
||||||
Key key;
|
Key pawnKey;
|
||||||
Bitboard checkersBB;
|
Key materialKey;
|
||||||
|
Value nonPawnMaterial[COLOR_NB];
|
||||||
|
int castlingRights;
|
||||||
|
int rule50;
|
||||||
|
int pliesFromNull;
|
||||||
|
Score psq;
|
||||||
|
Square epSquare;
|
||||||
|
|
||||||
|
// Not copied when making a move (will be recomputed anyhow)
|
||||||
|
Key key;
|
||||||
|
Bitboard checkersBB;
|
||||||
|
Piece capturedPiece;
|
||||||
StateInfo* previous;
|
StateInfo* previous;
|
||||||
|
Bitboard blockersForKing[COLOR_NB];
|
||||||
|
Bitboard pinnersForKing[COLOR_NB];
|
||||||
|
Bitboard checkSquares[PIECE_TYPE_NB];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
|
||||||
/// The position data structure. A position consists of the following data:
|
|
||||||
///
|
/// Position class stores information regarding the board representation as
|
||||||
/// * For each piece type, a bitboard representing the squares occupied
|
/// pieces, side to move, hash keys, castling info, etc. Important methods are
|
||||||
/// by pieces of that type.
|
/// do_move() and undo_move(), used by the search to update node info when
|
||||||
/// * For each color, a bitboard representing the squares occupied by
|
/// traversing the search tree.
|
||||||
/// pieces of that color.
|
class Thread;
|
||||||
/// * A bitboard of all occupied squares.
|
|
||||||
/// * A bitboard of all checking pieces.
|
|
||||||
/// * A 64-entry array of pieces, indexed by the squares of the board.
|
|
||||||
/// * The current side to move.
|
|
||||||
/// * Information about the castling rights for both sides.
|
|
||||||
/// * The initial files of the kings and both pairs of rooks. This is
|
|
||||||
/// used to implement the Chess960 castling rules.
|
|
||||||
/// * The en passant square (which is SQ_NONE if no en passant capture is
|
|
||||||
/// possible).
|
|
||||||
/// * The squares of the kings for both sides.
|
|
||||||
/// * Hash keys for the position itself, the current pawn structure, and
|
|
||||||
/// the current material situation.
|
|
||||||
/// * Hash keys for all previous positions in the game for detecting
|
|
||||||
/// repetition draws.
|
|
||||||
/// * A counter for detecting 50 move rule draws.
|
|
||||||
|
|
||||||
class Position {
|
class Position {
|
||||||
|
|
||||||
Position(); // No default or copy c'tor allowed
|
|
||||||
Position(const Position& pos);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum GamePhase {
|
static void init();
|
||||||
MidGame,
|
|
||||||
EndGame
|
|
||||||
};
|
|
||||||
|
|
||||||
// Constructors
|
Position() = default;
|
||||||
Position(const Position& pos, int threadID);
|
Position(const Position&) = delete;
|
||||||
Position(const std::string& fen, bool isChess960, int threadID);
|
Position& operator=(const Position&) = delete;
|
||||||
|
|
||||||
// Text input/output
|
// FEN string input/output
|
||||||
void from_fen(const std::string& fen, bool isChess960);
|
Position& set(const std::string& fenStr, bool isChess960, StateInfo* si, Thread* th);
|
||||||
const std::string to_fen() const;
|
Position& set(const std::string& code, Color c, StateInfo* si);
|
||||||
void print(Move m = MOVE_NONE) const;
|
const std::string fen() const;
|
||||||
|
|
||||||
// Copying
|
// Position representation
|
||||||
void flip();
|
Bitboard pieces() const;
|
||||||
|
|
||||||
// The piece on a given square
|
|
||||||
Piece piece_on(Square s) const;
|
|
||||||
PieceType type_of_piece_on(Square s) const;
|
|
||||||
Color color_of_piece_on(Square s) const;
|
|
||||||
bool square_is_empty(Square s) const;
|
|
||||||
bool square_is_occupied(Square s) const;
|
|
||||||
Value midgame_value_of_piece_on(Square s) const;
|
|
||||||
Value endgame_value_of_piece_on(Square s) const;
|
|
||||||
|
|
||||||
// Side to move
|
|
||||||
Color side_to_move() const;
|
|
||||||
|
|
||||||
// Bitboard representation of the position
|
|
||||||
Bitboard empty_squares() const;
|
|
||||||
Bitboard occupied_squares() const;
|
|
||||||
Bitboard pieces_of_color(Color c) const;
|
|
||||||
Bitboard pieces(PieceType pt) const;
|
Bitboard pieces(PieceType pt) const;
|
||||||
Bitboard pieces(PieceType pt, Color c) const;
|
|
||||||
Bitboard pieces(PieceType pt1, PieceType pt2) const;
|
Bitboard pieces(PieceType pt1, PieceType pt2) const;
|
||||||
Bitboard pieces(PieceType pt1, PieceType pt2, Color c) const;
|
Bitboard pieces(Color c) const;
|
||||||
|
Bitboard pieces(Color c, PieceType pt) const;
|
||||||
// Number of pieces of each color and type
|
Bitboard pieces(Color c, PieceType pt1, PieceType pt2) const;
|
||||||
int piece_count(Color c, PieceType pt) const;
|
Piece piece_on(Square s) const;
|
||||||
|
|
||||||
// The en passant square
|
|
||||||
Square ep_square() const;
|
Square ep_square() const;
|
||||||
|
bool empty(Square s) const;
|
||||||
|
template<PieceType Pt> int count(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;
|
||||||
|
|
||||||
// Current king position for each color
|
// Castling
|
||||||
Square king_square(Color c) const;
|
int can_castle(Color c) const;
|
||||||
|
int can_castle(CastlingRight cr) const;
|
||||||
|
bool castling_impeded(CastlingRight cr) const;
|
||||||
|
Square castling_rook_square(CastlingRight cr) const;
|
||||||
|
|
||||||
// Castling rights
|
// Checking
|
||||||
bool can_castle_kingside(Color c) const;
|
|
||||||
bool can_castle_queenside(Color c) const;
|
|
||||||
bool can_castle(Color c) const;
|
|
||||||
Square initial_kr_square(Color c) const;
|
|
||||||
Square initial_qr_square(Color c) const;
|
|
||||||
|
|
||||||
// Bitboards for pinned pieces and discovered check candidates
|
|
||||||
Bitboard discovered_check_candidates(Color c) const;
|
|
||||||
Bitboard pinned_pieces(Color c) const;
|
|
||||||
|
|
||||||
// Checking pieces and under check information
|
|
||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
bool in_check() const;
|
Bitboard discovered_check_candidates() const;
|
||||||
|
Bitboard pinned_pieces(Color c) const;
|
||||||
|
Bitboard check_squares(PieceType pt) const;
|
||||||
|
|
||||||
// Piece lists
|
// Attacks to/from a given square
|
||||||
Square piece_list(Color c, PieceType pt, int index) const;
|
|
||||||
const Square* piece_list_begin(Color c, PieceType pt) const;
|
|
||||||
|
|
||||||
// Information about attacks to or from a given square
|
|
||||||
Bitboard attackers_to(Square s) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
Bitboard attacks_from(Piece p, Square s) const;
|
Bitboard attackers_to(Square s, Bitboard occupied) const;
|
||||||
static Bitboard attacks_from(Piece p, Square s, Bitboard occ);
|
Bitboard attacks_from(PieceType pt, Square s) const;
|
||||||
template<PieceType> Bitboard attacks_from(Square s) const;
|
template<PieceType> Bitboard attacks_from(Square s) const;
|
||||||
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||||
|
Bitboard slider_blockers(Bitboard sliders, Square s, Bitboard& pinners) const;
|
||||||
|
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
bool legal(Move m) const;
|
||||||
bool pl_move_is_evasion(Move m, Bitboard pinned) const;
|
bool pseudo_legal(const Move m) const;
|
||||||
bool move_is_legal(const Move m) const;
|
bool capture(Move m) const;
|
||||||
bool move_is_legal(const Move m, Bitboard pinned) const;
|
bool capture_or_promotion(Move m) const;
|
||||||
bool move_gives_check(Move m) const;
|
bool gives_check(Move m) const;
|
||||||
bool move_gives_check(Move m, const CheckInfo& ci) const;
|
bool advanced_pawn_push(Move m) const;
|
||||||
bool move_is_capture(Move m) const;
|
Piece moved_piece(Move m) const;
|
||||||
bool move_is_capture_or_promotion(Move m) const;
|
Piece captured_piece() const;
|
||||||
bool move_is_passed_pawn_push(Move m) const;
|
|
||||||
bool move_attacks_square(Move m, Square s) const;
|
|
||||||
|
|
||||||
// Piece captured with previous moves
|
// Piece specific
|
||||||
PieceType captured_piece_type() const;
|
bool pawn_passed(Color c, Square s) const;
|
||||||
|
bool opposite_bishops() const;
|
||||||
// Information about pawns
|
|
||||||
bool pawn_is_passed(Color c, Square s) const;
|
|
||||||
|
|
||||||
// Weak squares
|
|
||||||
bool square_is_weak(Square s, Color c) const;
|
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void do_setup_move(Move m);
|
void do_move(Move m, StateInfo& newSt);
|
||||||
void do_move(Move m, StateInfo& st);
|
void do_move(Move m, StateInfo& newSt, bool givesCheck);
|
||||||
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
void do_null_move(StateInfo& st);
|
void do_null_move(StateInfo& newSt);
|
||||||
void undo_null_move();
|
void undo_null_move();
|
||||||
|
|
||||||
// Static exchange evaluation
|
// Static Exchange Evaluation
|
||||||
int see(Square from, Square to) const;
|
bool see_ge(Move m, Value threshold = VALUE_ZERO) const;
|
||||||
int see(Move m) const;
|
|
||||||
int see_sign(Move m) const;
|
|
||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key get_key() const;
|
Key key() const;
|
||||||
Key get_exclusion_key() const;
|
Key key_after(Move m) const;
|
||||||
Key get_pawn_key() const;
|
Key material_key() const;
|
||||||
Key get_material_key() const;
|
Key pawn_key() const;
|
||||||
|
|
||||||
// Incremental evaluation
|
|
||||||
Score value() const;
|
|
||||||
Value non_pawn_material(Color c) const;
|
|
||||||
static Score pst_delta(Piece piece, Square from, Square to);
|
|
||||||
|
|
||||||
// Game termination checks
|
|
||||||
bool is_mate() const;
|
|
||||||
bool is_draw() const;
|
|
||||||
|
|
||||||
// Number of plies from starting position
|
|
||||||
int startpos_ply_counter() const;
|
|
||||||
|
|
||||||
// Other properties of the position
|
// Other properties of the position
|
||||||
bool opposite_colored_bishops() const;
|
Color side_to_move() const;
|
||||||
bool has_pawn_on_7th(Color c) const;
|
int game_ply() const;
|
||||||
bool is_chess960() const;
|
bool is_chess960() const;
|
||||||
|
Thread* this_thread() const;
|
||||||
// Current thread ID searching on the position
|
bool is_draw(int ply) const;
|
||||||
int thread() const;
|
int rule50_count() const;
|
||||||
|
Score psq_score() const;
|
||||||
int64_t nodes_searched() const;
|
Value non_pawn_material(Color c) const;
|
||||||
void set_nodes_searched(int64_t n);
|
Value non_pawn_material() const;
|
||||||
|
|
||||||
// Position consistency check, for debugging
|
// Position consistency check, for debugging
|
||||||
bool is_ok(int* failedStep = NULL) const;
|
bool pos_is_ok() const;
|
||||||
|
void flip();
|
||||||
// Static member functions
|
|
||||||
static void init_zobrist();
|
|
||||||
static void init_piece_square_tables();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Initialization helpers (used while setting up a position)
|
||||||
|
void set_castling_right(Color c, Square rfrom);
|
||||||
|
void set_state(StateInfo* si) const;
|
||||||
|
void set_check_info(StateInfo* si) const;
|
||||||
|
|
||||||
// Initialization helper functions (used while setting up a position)
|
// Other helpers
|
||||||
void clear();
|
void put_piece(Piece pc, Square s);
|
||||||
void detach();
|
void remove_piece(Piece pc, Square s);
|
||||||
void put_piece(Piece p, Square s);
|
void move_piece(Piece pc, Square from, Square to);
|
||||||
void do_allow_oo(Color c);
|
template<bool Do>
|
||||||
void do_allow_ooo(Color c);
|
void do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto);
|
||||||
bool set_castling_rights(char token);
|
|
||||||
|
|
||||||
// Helper functions for doing and undoing moves
|
// Data members
|
||||||
void do_capture_move(Key& key, PieceType capture, Color them, Square to, bool ep);
|
Piece board[SQUARE_NB];
|
||||||
void do_castle_move(Move m);
|
Bitboard byTypeBB[PIECE_TYPE_NB];
|
||||||
void undo_castle_move(Move m);
|
Bitboard byColorBB[COLOR_NB];
|
||||||
void find_checkers();
|
int pieceCount[PIECE_NB];
|
||||||
|
Square pieceList[PIECE_NB][16];
|
||||||
template<bool FindPinned>
|
int index[SQUARE_NB];
|
||||||
Bitboard hidden_checkers(Color c) const;
|
int castlingRightsMask[SQUARE_NB];
|
||||||
|
Square castlingRookSquare[CASTLING_RIGHT_NB];
|
||||||
// Computing hash keys from scratch (for initialization and debugging)
|
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
||||||
Key compute_key() const;
|
int gamePly;
|
||||||
Key compute_pawn_key() const;
|
|
||||||
Key compute_material_key() const;
|
|
||||||
|
|
||||||
// Computing incremental evaluation scores and material counts
|
|
||||||
static Score pst(Color c, PieceType pt, Square s);
|
|
||||||
Score compute_value() const;
|
|
||||||
Value compute_non_pawn_material(Color c) const;
|
|
||||||
|
|
||||||
// Board
|
|
||||||
Piece board[64];
|
|
||||||
|
|
||||||
// Bitboards
|
|
||||||
Bitboard byTypeBB[8], byColorBB[2];
|
|
||||||
|
|
||||||
// Piece counts
|
|
||||||
int pieceCount[2][8]; // [color][pieceType]
|
|
||||||
|
|
||||||
// Piece lists
|
|
||||||
Square pieceList[2][8][16]; // [color][pieceType][index]
|
|
||||||
int index[64]; // [square]
|
|
||||||
|
|
||||||
// Other info
|
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
Key history[MaxGameLength];
|
Thread* thisThread;
|
||||||
int castleRightsMask[64];
|
|
||||||
StateInfo startState;
|
|
||||||
File initialKFile, initialKRFile, initialQRFile;
|
|
||||||
bool chess960;
|
|
||||||
int startPosPlyCounter;
|
|
||||||
int threadID;
|
|
||||||
int64_t nodes;
|
|
||||||
StateInfo* st;
|
StateInfo* st;
|
||||||
|
bool chess960;
|
||||||
// Static variables
|
|
||||||
static Key zobrist[2][8][64];
|
|
||||||
static Key zobEp[64];
|
|
||||||
static Key zobCastle[16];
|
|
||||||
static Key zobSideToMove;
|
|
||||||
static Score PieceSquareTable[16][64];
|
|
||||||
static Key zobExclusion;
|
|
||||||
static const Value seeValues[8];
|
|
||||||
static const Value PieceValueMidgame[17];
|
|
||||||
static const Value PieceValueEndgame[17];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline int64_t Position::nodes_searched() const {
|
extern std::ostream& operator<<(std::ostream& os, const Position& pos);
|
||||||
return nodes;
|
|
||||||
|
inline Color Position::side_to_move() const {
|
||||||
|
return sideToMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::set_nodes_searched(int64_t n) {
|
inline bool Position::empty(Square s) const {
|
||||||
nodes = n;
|
return board[s] == NO_PIECE;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Piece Position::piece_on(Square s) const {
|
inline Piece Position::piece_on(Square s) const {
|
||||||
return board[s];
|
return board[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color Position::color_of_piece_on(Square s) const {
|
inline Piece Position::moved_piece(Move m) const {
|
||||||
return color_of_piece(piece_on(s));
|
return board[from_sq(m)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType Position::type_of_piece_on(Square s) const {
|
inline Bitboard Position::pieces() const {
|
||||||
return type_of_piece(piece_on(s));
|
return byTypeBB[ALL_PIECES];
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::square_is_empty(Square s) const {
|
|
||||||
return piece_on(s) == PIECE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::square_is_occupied(Square s) const {
|
|
||||||
return !square_is_empty(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Value Position::midgame_value_of_piece_on(Square s) const {
|
|
||||||
return PieceValueMidgame[piece_on(s)];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Value Position::endgame_value_of_piece_on(Square s) const {
|
|
||||||
return PieceValueEndgame[piece_on(s)];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Color Position::side_to_move() const {
|
|
||||||
return sideToMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::occupied_squares() const {
|
|
||||||
return byTypeBB[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::empty_squares() const {
|
|
||||||
return ~occupied_squares();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::pieces_of_color(Color c) const {
|
|
||||||
return byColorBB[c];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces(PieceType pt) const {
|
inline Bitboard Position::pieces(PieceType pt) const {
|
||||||
return byTypeBB[pt];
|
return byTypeBB[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces(PieceType pt, Color c) const {
|
|
||||||
return byTypeBB[pt] & byColorBB[c];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2) const {
|
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2) const {
|
||||||
return byTypeBB[pt1] | byTypeBB[pt2];
|
return byTypeBB[pt1] | byTypeBB[pt2];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2, Color c) const {
|
inline Bitboard Position::pieces(Color c) const {
|
||||||
return (byTypeBB[pt1] | byTypeBB[pt2]) & byColorBB[c];
|
return byColorBB[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::piece_count(Color c, PieceType pt) const {
|
inline Bitboard Position::pieces(Color c, PieceType pt) const {
|
||||||
return pieceCount[c][pt];
|
return byColorBB[c] & byTypeBB[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::piece_list(Color c, PieceType pt, int idx) const {
|
inline Bitboard Position::pieces(Color c, PieceType pt1, PieceType pt2) const {
|
||||||
return pieceList[c][pt][idx];
|
return byColorBB[c] & (byTypeBB[pt1] | byTypeBB[pt2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Square* Position::piece_list_begin(Color c, PieceType pt) const {
|
template<PieceType Pt> inline int Position::count(Color c) const {
|
||||||
return pieceList[c][pt];
|
return pieceCount[make_piece(c, Pt)];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<PieceType Pt> inline int Position::count() const {
|
||||||
|
return pieceCount[make_piece(WHITE, Pt)] + pieceCount[make_piece(BLACK, Pt)];
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
inline Square Position::ep_square() const {
|
||||||
return st->epSquare;
|
return st->epSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::king_square(Color c) const {
|
inline int Position::can_castle(CastlingRight cr) const {
|
||||||
return pieceList[c][KING][0];
|
return st->castlingRights & cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::can_castle_kingside(Color side) const {
|
inline int Position::can_castle(Color c) const {
|
||||||
return st->castleRights & (1+int(side));
|
return st->castlingRights & ((WHITE_OO | WHITE_OOO) << (2 * c));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::can_castle_queenside(Color side) const {
|
inline bool Position::castling_impeded(CastlingRight cr) const {
|
||||||
return st->castleRights & (4+4*int(side));
|
return byTypeBB[ALL_PIECES] & castlingPath[cr];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::can_castle(Color side) const {
|
inline Square Position::castling_rook_square(CastlingRight cr) const {
|
||||||
return can_castle_kingside(side) || can_castle_queenside(side);
|
return castlingRookSquare[cr];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::initial_kr_square(Color c) const {
|
template<PieceType Pt>
|
||||||
return relative_square(c, make_square(initialKRFile, RANK_1));
|
inline Bitboard Position::attacks_from(Square s) const {
|
||||||
}
|
assert(Pt != PAWN);
|
||||||
|
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
||||||
inline Square Position::initial_qr_square(Color c) const {
|
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
||||||
return relative_square(c, make_square(initialQRFile, RANK_1));
|
: PseudoAttacks[Pt][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
||||||
return StepAttacksBB[make_piece(c, PAWN)][s];
|
return PawnAttacks[c][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Piece> // Knight and King and white pawns
|
inline Bitboard Position::attacks_from(PieceType pt, Square s) const {
|
||||||
inline Bitboard Position::attacks_from(Square s) const {
|
return attacks_bb(pt, s, byTypeBB[ALL_PIECES]);
|
||||||
return StepAttacksBB[Piece][s];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
inline Bitboard Position::attackers_to(Square s) const {
|
||||||
inline Bitboard Position::attacks_from<BISHOP>(Square s) const {
|
return attackers_to(s, byTypeBB[ALL_PIECES]);
|
||||||
return bishop_attacks_bb(s, occupied_squares());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline Bitboard Position::attacks_from<ROOK>(Square s) const {
|
|
||||||
return rook_attacks_bb(s, occupied_squares());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline Bitboard Position::attacks_from<QUEEN>(Square s) const {
|
|
||||||
return attacks_from<ROOK>(s) | attacks_from<BISHOP>(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::checkers() const {
|
inline Bitboard Position::checkers() const {
|
||||||
return st->checkersBB;
|
return st->checkersBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::in_check() const {
|
inline Bitboard Position::discovered_check_candidates() const {
|
||||||
return st->checkersBB != EmptyBoardBB;
|
return st->blockersForKing[~sideToMove] & pieces(sideToMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
inline Bitboard Position::pinned_pieces(Color c) const {
|
||||||
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
|
return st->blockersForKing[c] & pieces(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::square_is_weak(Square s, Color c) const {
|
inline Bitboard Position::check_squares(PieceType pt) const {
|
||||||
return !(pieces(PAWN, opposite_color(c)) & attack_span_mask(c, s));
|
return st->checkSquares[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_key() const {
|
inline bool Position::pawn_passed(Color c, Square s) const {
|
||||||
|
return !(pieces(~c, PAWN) & passed_pawn_mask(c, s));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Position::advanced_pawn_push(Move m) const {
|
||||||
|
return type_of(moved_piece(m)) == PAWN
|
||||||
|
&& relative_rank(sideToMove, from_sq(m)) > RANK_4;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Key Position::key() const {
|
||||||
return st->key;
|
return st->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_exclusion_key() const {
|
inline Key Position::pawn_key() const {
|
||||||
return st->key ^ zobExclusion;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Key Position::get_pawn_key() const {
|
|
||||||
return st->pawnKey;
|
return st->pawnKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_material_key() const {
|
inline Key Position::material_key() const {
|
||||||
return st->materialKey;
|
return st->materialKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Score Position::pst(Color c, PieceType pt, Square s) {
|
inline Score Position::psq_score() const {
|
||||||
return PieceSquareTable[make_piece(c, pt)][s];
|
return st->psq;
|
||||||
}
|
|
||||||
|
|
||||||
inline Score Position::pst_delta(Piece piece, Square from, Square to) {
|
|
||||||
return PieceSquareTable[piece][to] - PieceSquareTable[piece][from];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Score Position::value() const {
|
|
||||||
return st->value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::non_pawn_material(Color c) const {
|
inline Value Position::non_pawn_material(Color c) const {
|
||||||
return st->npMaterial[c];
|
return st->nonPawnMaterial[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
inline Value Position::non_pawn_material() const {
|
||||||
|
return st->nonPawnMaterial[WHITE] + st->nonPawnMaterial[BLACK];
|
||||||
Color c = side_to_move();
|
|
||||||
return piece_on(move_from(m)) == make_piece(c, PAWN)
|
|
||||||
&& pawn_is_passed(c, move_to(m));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::startpos_ply_counter() const {
|
inline int Position::game_ply() const {
|
||||||
return startPosPlyCounter;
|
return gamePly;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::opposite_colored_bishops() const {
|
inline int Position::rule50_count() const {
|
||||||
|
return st->rule50;
|
||||||
return piece_count(WHITE, BISHOP) == 1 && piece_count(BLACK, BISHOP) == 1
|
|
||||||
&& opposite_color_squares(piece_list(WHITE, BISHOP, 0), piece_list(BLACK, BISHOP, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::has_pawn_on_7th(Color c) const {
|
inline bool Position::opposite_bishops() const {
|
||||||
return pieces(PAWN, c) & 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 {
|
inline bool Position::is_chess960() const {
|
||||||
return chess960;
|
return chess960;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::move_is_capture(Move m) const {
|
inline bool Position::capture_or_promotion(Move m) const {
|
||||||
|
assert(is_ok(m));
|
||||||
// Move must not be MOVE_NONE !
|
return type_of(m) != NORMAL ? type_of(m) != CASTLING : !empty(to_sq(m));
|
||||||
return (m & (3 << 15)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::move_is_capture_or_promotion(Move m) const {
|
inline bool Position::capture(Move m) const {
|
||||||
|
assert(is_ok(m));
|
||||||
// Move must not be MOVE_NONE !
|
// Castling is encoded as "king captures rook"
|
||||||
return (m & (0x1F << 12)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
|
return (!empty(to_sq(m)) && type_of(m) != CASTLING) || type_of(m) == ENPASSANT;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType Position::captured_piece_type() const {
|
inline Piece Position::captured_piece() const {
|
||||||
return st->capturedType;
|
return st->capturedPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::thread() const {
|
inline Thread* Position::this_thread() const {
|
||||||
return threadID;
|
return thisThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::do_allow_oo(Color c) {
|
inline void Position::put_piece(Piece pc, Square s) {
|
||||||
st->castleRights |= (1 + int(c));
|
|
||||||
|
board[s] = pc;
|
||||||
|
byTypeBB[ALL_PIECES] |= s;
|
||||||
|
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)]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::do_allow_ooo(Color c) {
|
inline void Position::remove_piece(Piece pc, Square s) {
|
||||||
st->castleRights |= (4 + 4*int(c));
|
|
||||||
|
// 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 invariant to a do_move() + undo_move() sequence.
|
||||||
|
byTypeBB[ALL_PIECES] ^= 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[pc][--pieceCount[pc]];
|
||||||
|
index[lastSquare] = index[s];
|
||||||
|
pieceList[pc][index[lastSquare]] = lastSquare;
|
||||||
|
pieceList[pc][pieceCount[pc]] = SQ_NONE;
|
||||||
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !defined(POSITION_H_INCLUDED)
|
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 from_to_bb = SquareBB[from] ^ SquareBB[to];
|
||||||
|
byTypeBB[ALL_PIECES] ^= from_to_bb;
|
||||||
|
byTypeBB[type_of(pc)] ^= from_to_bb;
|
||||||
|
byColorBB[color_of(pc)] ^= from_to_bb;
|
||||||
|
board[from] = NO_PIECE;
|
||||||
|
board[to] = pc;
|
||||||
|
index[to] = index[from];
|
||||||
|
pieceList[pc][index[to]] = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
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-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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.
|
||||||
|
const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
||||||
|
{ },
|
||||||
|
{ // Pawn
|
||||||
|
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
||||||
|
{ S(-11, 7), S( 6,-4), S( 7, 8), S( 3,-2) },
|
||||||
|
{ S(-18,-4), S( -2,-5), S( 19, 5), S(24, 4) },
|
||||||
|
{ S(-17, 3), S( -9, 3), S( 20,-8), S(35,-3) },
|
||||||
|
{ S( -6, 8), S( 5, 9), S( 3, 7), S(21,-6) },
|
||||||
|
{ S( -6, 8), S( -8,-5), S( -6, 2), S(-2, 4) },
|
||||||
|
{ S( -4, 3), S( 20,-9), S( -8, 1), S(-4,18) }
|
||||||
|
},
|
||||||
|
{ // Knight
|
||||||
|
{ S(-161,-105), S(-96,-82), S(-80,-46), S(-73,-14) },
|
||||||
|
{ S( -83, -69), S(-43,-54), S(-21,-17), S(-10, 9) },
|
||||||
|
{ S( -71, -50), S(-22,-39), S( 0, -7), S( 9, 28) },
|
||||||
|
{ S( -25, -41), S( 18,-25), S( 43, 6), S( 47, 38) },
|
||||||
|
{ S( -26, -46), S( 16,-25), S( 38, 3), S( 50, 40) },
|
||||||
|
{ S( -11, -54), S( 37,-38), S( 56, -7), S( 65, 27) },
|
||||||
|
{ S( -63, -65), S(-19,-50), S( 5,-24), S( 14, 13) },
|
||||||
|
{ S(-195,-109), S(-67,-89), S(-42,-50), S(-29,-13) }
|
||||||
|
},
|
||||||
|
{ // Bishop
|
||||||
|
{ S(-44,-58), S(-13,-31), S(-25,-37), S(-34,-19) },
|
||||||
|
{ S(-20,-34), S( 20, -9), S( 12,-14), S( 1, 4) },
|
||||||
|
{ S( -9,-23), S( 27, 0), S( 21, -3), S( 11, 16) },
|
||||||
|
{ S(-11,-26), S( 28, -3), S( 21, -5), S( 10, 16) },
|
||||||
|
{ S(-11,-26), S( 27, -4), S( 16, -7), S( 9, 14) },
|
||||||
|
{ S(-17,-24), S( 16, -2), S( 12, 0), S( 2, 13) },
|
||||||
|
{ S(-23,-34), S( 17,-10), S( 6,-12), S( -2, 6) },
|
||||||
|
{ S(-35,-55), S(-11,-32), S(-19,-36), S(-29,-17) }
|
||||||
|
},
|
||||||
|
{ // Rook
|
||||||
|
{ S(-25, 0), S(-16, 0), S(-16, 0), S(-9, 0) },
|
||||||
|
{ S(-21, 0), S( -8, 0), S( -3, 0), S( 0, 0) },
|
||||||
|
{ S(-21, 0), S( -9, 0), S( -4, 0), S( 2, 0) },
|
||||||
|
{ S(-22, 0), S( -6, 0), S( -1, 0), S( 2, 0) },
|
||||||
|
{ S(-22, 0), S( -7, 0), S( 0, 0), S( 1, 0) },
|
||||||
|
{ S(-21, 0), S( -7, 0), S( 0, 0), S( 2, 0) },
|
||||||
|
{ S(-12, 0), S( 4, 0), S( 8, 0), S(12, 0) },
|
||||||
|
{ S(-23, 0), S(-15, 0), S(-11, 0), S(-5, 0) }
|
||||||
|
},
|
||||||
|
{ // Queen
|
||||||
|
{ S( 0,-71), S(-4,-56), S(-3,-42), S(-1,-29) },
|
||||||
|
{ S(-4,-56), S( 6,-30), S( 9,-21), S( 8, -5) },
|
||||||
|
{ S(-2,-39), S( 6,-17), S( 9, -8), S( 9, 5) },
|
||||||
|
{ S(-1,-29), S( 8, -5), S(10, 9), S( 7, 19) },
|
||||||
|
{ S(-3,-27), S( 9, -5), S( 8, 10), S( 7, 21) },
|
||||||
|
{ S(-2,-40), S( 6,-16), S( 8,-10), S(10, 3) },
|
||||||
|
{ S(-2,-55), S( 7,-30), S( 7,-21), S( 6, -6) },
|
||||||
|
{ S(-1,-74), S(-4,-55), S(-1,-43), S( 0,-30) }
|
||||||
|
},
|
||||||
|
{ // King
|
||||||
|
{ S(267, 0), S(320, 48), S(270, 75), S(195, 84) },
|
||||||
|
{ S(264, 43), S(304, 92), S(238,143), S(180,132) },
|
||||||
|
{ S(200, 83), S(245,138), S(176,167), S(110,165) },
|
||||||
|
{ S(177,106), S(185,169), S(148,169), S(110,179) },
|
||||||
|
{ S(149,108), S(177,163), S(115,200), S( 66,203) },
|
||||||
|
{ S(118, 95), S(159,155), S( 84,176), S( 41,174) },
|
||||||
|
{ S( 87, 50), S(128, 99), S( 63,122), S( 20,139) },
|
||||||
|
{ S( 63, 9), S( 88, 55), S( 47, 80), S( 0, 90) }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#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 v = 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] = v + Bonus[pc][rank_of(s)][f];
|
||||||
|
psq[~pc][~s] = -psq[pc][s];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace PSQT
|
||||||
-185
@@ -1,185 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(PSQTAB_H_INCLUDED)
|
|
||||||
#define PSQTAB_H_INCLUDED
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Constants modified by Joona Kiiski
|
|
||||||
////
|
|
||||||
|
|
||||||
const Value MP = PawnValueMidgame;
|
|
||||||
const Value MK = KnightValueMidgame;
|
|
||||||
const Value MB = BishopValueMidgame;
|
|
||||||
const Value MR = RookValueMidgame;
|
|
||||||
const Value MQ = QueenValueMidgame;
|
|
||||||
|
|
||||||
const Value EP = PawnValueEndgame;
|
|
||||||
const Value EK = KnightValueEndgame;
|
|
||||||
const Value EB = BishopValueEndgame;
|
|
||||||
const Value ER = RookValueEndgame;
|
|
||||||
const Value EQ = QueenValueEndgame;
|
|
||||||
|
|
||||||
const int MgPST[][64] = {
|
|
||||||
{ },
|
|
||||||
{// Pawn
|
|
||||||
// A B C D E F G H
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
MP-28, MP-6, MP+ 4, MP+14, MP+14, MP+ 4, MP-6, MP-28,
|
|
||||||
MP-28, MP-6, MP+ 9, MP+36, MP+36, MP+ 9, MP-6, MP-28,
|
|
||||||
MP-28, MP-6, MP+17, MP+58, MP+58, MP+17, MP-6, MP-28,
|
|
||||||
MP-28, MP-6, MP+17, MP+36, MP+36, MP+17, MP-6, MP-28,
|
|
||||||
MP-28, MP-6, MP+ 9, MP+14, MP+14, MP+ 9, MP-6, MP-28,
|
|
||||||
MP-28, MP-6, MP+ 4, MP+14, MP+14, MP+ 4, MP-6, MP-28,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
},
|
|
||||||
{// Knight
|
|
||||||
// A B C D E F G H
|
|
||||||
MK-135, MK-107, MK-80, MK-67, MK-67, MK-80, MK-107, MK-135,
|
|
||||||
MK- 93, MK- 67, MK-39, MK-25, MK-25, MK-39, MK- 67, MK- 93,
|
|
||||||
MK- 53, MK- 25, MK+ 1, MK+13, MK+13, MK+ 1, MK- 25, MK- 53,
|
|
||||||
MK- 25, MK+ 1, MK+27, MK+41, MK+41, MK+27, MK+ 1, MK- 25,
|
|
||||||
MK- 11, MK+ 13, MK+41, MK+55, MK+55, MK+41, MK+ 13, MK- 11,
|
|
||||||
MK- 11, MK+ 13, MK+41, MK+55, MK+55, MK+41, MK+ 13, MK- 11,
|
|
||||||
MK- 53, MK- 25, MK+ 1, MK+13, MK+13, MK+ 1, MK- 25, MK- 53,
|
|
||||||
MK-193, MK- 67, MK-39, MK-25, MK-25, MK-39, MK- 67, MK-193
|
|
||||||
},
|
|
||||||
{// Bishop
|
|
||||||
// A B C D E F G H
|
|
||||||
MB-40, MB-40, MB-35, MB-30, MB-30, MB-35, MB-40, MB-40,
|
|
||||||
MB-17, MB+ 0, MB- 4, MB+ 0, MB+ 0, MB- 4, MB+ 0, MB-17,
|
|
||||||
MB-13, MB- 4, MB+ 8, MB+ 4, MB+ 4, MB+ 8, MB- 4, MB-13,
|
|
||||||
MB- 8, MB+ 0, MB+ 4, MB+17, MB+17, MB+ 4, MB+ 0, MB- 8,
|
|
||||||
MB- 8, MB+ 0, MB+ 4, MB+17, MB+17, MB+ 4, MB+ 0, MB- 8,
|
|
||||||
MB-13, MB- 4, MB+ 8, MB+ 4, MB+ 4, MB+ 8, MB- 4, MB-13,
|
|
||||||
MB-17, MB+ 0, MB- 4, MB+ 0, MB+ 0, MB- 4, MB+ 0, MB-17,
|
|
||||||
MB-17, MB-17, MB-13, MB- 8, MB- 8, MB-13, MB-17, MB-17
|
|
||||||
},
|
|
||||||
{// Rook
|
|
||||||
// A B C D E F G H
|
|
||||||
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
|
||||||
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
|
||||||
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
|
||||||
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
|
||||||
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
|
||||||
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
|
||||||
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
|
||||||
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12
|
|
||||||
},
|
|
||||||
{// Queen
|
|
||||||
// A B C D E F G H
|
|
||||||
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
|
||||||
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
|
||||||
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
|
||||||
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
|
||||||
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
|
||||||
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
|
||||||
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
|
||||||
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8
|
|
||||||
},
|
|
||||||
{// King
|
|
||||||
//A B C D E F G H
|
|
||||||
287, 311, 262, 214, 214, 262, 311, 287,
|
|
||||||
262, 287, 238, 190, 190, 238, 287, 262,
|
|
||||||
214, 238, 190, 142, 142, 190, 238, 214,
|
|
||||||
190, 214, 167, 119, 119, 167, 214, 190,
|
|
||||||
167, 190, 142, 94, 94, 142, 190, 167,
|
|
||||||
142, 167, 119, 69, 69, 119, 167, 142,
|
|
||||||
119, 142, 94, 46, 46, 94, 142, 119,
|
|
||||||
94, 119, 69, 21, 21, 69, 119, 94
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const int EgPST[][64] = {
|
|
||||||
{ },
|
|
||||||
{// Pawn
|
|
||||||
// A B C D E F G H
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
|
||||||
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
|
||||||
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
|
||||||
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
|
||||||
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
|
||||||
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
},
|
|
||||||
{// Knight
|
|
||||||
// A B C D E F G H
|
|
||||||
EK-104, EK-79, EK-55, EK-42, EK-42, EK-55, EK-79, EK-104,
|
|
||||||
EK- 79, EK-55, EK-30, EK-17, EK-17, EK-30, EK-55, EK- 79,
|
|
||||||
EK- 55, EK-30, EK- 6, EK+ 5, EK+ 5, EK- 6, EK-30, EK- 55,
|
|
||||||
EK- 42, EK-17, EK+ 5, EK+18, EK+18, EK+ 5, EK-17, EK- 42,
|
|
||||||
EK- 42, EK-17, EK+ 5, EK+18, EK+18, EK+ 5, EK-17, EK- 42,
|
|
||||||
EK- 55, EK-30, EK- 6, EK+ 5, EK+ 5, EK- 6, EK-30, EK- 55,
|
|
||||||
EK- 79, EK-55, EK-30, EK-17, EK-17, EK-30, EK-55, EK- 79,
|
|
||||||
EK-104, EK-79, EK-55, EK-42, EK-42, EK-55, EK-79, EK-104
|
|
||||||
},
|
|
||||||
{// Bishop
|
|
||||||
// A B C D E F G H
|
|
||||||
EB-59, EB-42, EB-35, EB-26, EB-26, EB-35, EB-42, EB-59,
|
|
||||||
EB-42, EB-26, EB-18, EB-11, EB-11, EB-18, EB-26, EB-42,
|
|
||||||
EB-35, EB-18, EB-11, EB- 4, EB- 4, EB-11, EB-18, EB-35,
|
|
||||||
EB-26, EB-11, EB- 4, EB+ 4, EB+ 4, EB- 4, EB-11, EB-26,
|
|
||||||
EB-26, EB-11, EB- 4, EB+ 4, EB+ 4, EB- 4, EB-11, EB-26,
|
|
||||||
EB-35, EB-18, EB-11, EB- 4, EB- 4, EB-11, EB-18, EB-35,
|
|
||||||
EB-42, EB-26, EB-18, EB-11, EB-11, EB-18, EB-26, EB-42,
|
|
||||||
EB-59, EB-42, EB-35, EB-26, EB-26, EB-35, EB-42, EB-59
|
|
||||||
},
|
|
||||||
{// Rook
|
|
||||||
// A B C D E F G H
|
|
||||||
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
|
||||||
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
|
||||||
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
|
||||||
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
|
||||||
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
|
||||||
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
|
||||||
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
|
||||||
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3
|
|
||||||
},
|
|
||||||
{// Queen
|
|
||||||
// A B C D E F G H
|
|
||||||
EQ-80, EQ-54, EQ-42, EQ-30, EQ-30, EQ-42, EQ-54, EQ-80,
|
|
||||||
EQ-54, EQ-30, EQ-18, EQ- 6, EQ- 6, EQ-18, EQ-30, EQ-54,
|
|
||||||
EQ-42, EQ-18, EQ- 6, EQ+ 6, EQ+ 6, EQ- 6, EQ-18, EQ-42,
|
|
||||||
EQ-30, EQ- 6, EQ+ 6, EQ+18, EQ+18, EQ+ 6, EQ- 6, EQ-30,
|
|
||||||
EQ-30, EQ- 6, EQ+ 6, EQ+18, EQ+18, EQ+ 6, EQ- 6, EQ-30,
|
|
||||||
EQ-42, EQ-18, EQ- 6, EQ+ 6, EQ+ 6, EQ- 6, EQ-18, EQ-42,
|
|
||||||
EQ-54, EQ-30, EQ-18, EQ- 6, EQ- 6, EQ-18, EQ-30, EQ-54,
|
|
||||||
EQ-80, EQ-54, EQ-42, EQ-30, EQ-30, EQ-42, EQ-54, EQ-80
|
|
||||||
},
|
|
||||||
{// King
|
|
||||||
//A B C D E F G H
|
|
||||||
18, 77, 105, 135, 135, 105, 77, 18,
|
|
||||||
77, 135, 165, 193, 193, 165, 135, 77,
|
|
||||||
105, 165, 193, 222, 222, 193, 165, 105,
|
|
||||||
135, 193, 222, 251, 251, 222, 193, 135,
|
|
||||||
135, 193, 222, 251, 251, 222, 193, 135,
|
|
||||||
105, 165, 193, 222, 222, 193, 165, 105,
|
|
||||||
77, 135, 165, 193, 193, 165, 135, 77,
|
|
||||||
18, 77, 105, 135, 135, 105, 77, 18
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
#endif // !defined(PSQTAB_H_INCLUDED)
|
|
||||||
-77
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
|
|
||||||
This file is based on original code by Heinz van Saanen and is
|
|
||||||
available under 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.
|
|
||||||
|
|
||||||
** George Marsaglia invented the RNG-Kiss-family in the early 90's.
|
|
||||||
** This is a specific version that Heinz van Saanen derived and
|
|
||||||
** tested from some public domain code by Bob Jenkins:
|
|
||||||
**
|
|
||||||
** Quite platform independent
|
|
||||||
** Passes ALL dieharder tests! Here *nix sys-rand() e.g. fails miserably:-)
|
|
||||||
** ~12 times faster than my *nix sys-rand()
|
|
||||||
** ~4 times faster than SSE2-version of Mersenne twister
|
|
||||||
** Average cycle length: ~2^126
|
|
||||||
** 64 bit seed
|
|
||||||
** Return doubles with a full 53 bit mantissa
|
|
||||||
** Thread safe
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(RKISS_H_INCLUDED)
|
|
||||||
#define RKISS_H_INCLUDED
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
class RKISS {
|
|
||||||
|
|
||||||
// Keep variables always together
|
|
||||||
struct S { uint64_t a, b, c, d; } s;
|
|
||||||
|
|
||||||
uint64_t rotate(uint64_t x, uint64_t k) const {
|
|
||||||
return (x << k) | (x >> (64 - k));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return 64 bit unsigned integer in between [0, 2^64 - 1]
|
|
||||||
uint64_t rand64() {
|
|
||||||
|
|
||||||
const uint64_t
|
|
||||||
e = s.a - rotate(s.b, 7);
|
|
||||||
s.a = s.b ^ rotate(s.c, 13);
|
|
||||||
s.b = s.c + rotate(s.d, 37);
|
|
||||||
s.c = s.d + e;
|
|
||||||
return s.d = e + s.a;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init seed and scramble a few rounds
|
|
||||||
void raninit() {
|
|
||||||
|
|
||||||
s.a = 0xf1ea5eed;
|
|
||||||
s.b = s.c = s.d = 0xd4e12c77;
|
|
||||||
for (int i = 0; i < 73; i++)
|
|
||||||
rand64();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
RKISS() { raninit(); }
|
|
||||||
template<typename T> T rand() { return T(rand64()); }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // !defined(RKISS_H_INCLUDED)
|
|
||||||
+1301
-1847
File diff suppressed because it is too large
Load Diff
+67
-34
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,57 +18,89 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(SEARCH_H_INCLUDED)
|
#ifndef SEARCH_H_INCLUDED
|
||||||
#define SEARCH_H_INCLUDED
|
#define SEARCH_H_INCLUDED
|
||||||
|
|
||||||
#include <cstring>
|
#include <vector>
|
||||||
|
|
||||||
#include "move.h"
|
#include "misc.h"
|
||||||
|
#include "movepick.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
class Position;
|
class Position;
|
||||||
struct SplitPoint;
|
|
||||||
|
|
||||||
/// The SearchStack struct keeps track of the information we need to remember
|
namespace Search {
|
||||||
/// from nodes shallower and deeper in the tree during the search. Each
|
|
||||||
/// search thread has its own array of SearchStack objects, indexed by the
|
|
||||||
/// current ply.
|
|
||||||
|
|
||||||
struct SearchStack {
|
/// Threshold used for countermoves based pruning
|
||||||
|
const 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 {
|
||||||
|
Move* pv;
|
||||||
|
PieceToHistory* contHistory;
|
||||||
int ply;
|
int ply;
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Move mateKiller;
|
|
||||||
Move excludedMove;
|
Move excludedMove;
|
||||||
Move bestMove;
|
|
||||||
Move killers[2];
|
Move killers[2];
|
||||||
Depth reduction;
|
Value staticEval;
|
||||||
Value eval;
|
int statScore;
|
||||||
Value evalMargin;
|
int moveCount;
|
||||||
bool skipNullMove;
|
|
||||||
SplitPoint* sp;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// The SearchLimits struct stores information sent by GUI about available time
|
/// RootMove struct is used for moves at the root of the tree. For each root move
|
||||||
/// to search the current move, maximum depth/time, if we are in analysis mode
|
/// we store a score and a PV (really a refutation in the case of moves which
|
||||||
/// or if we have to ponder while is our opponent's side to move.
|
/// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves.
|
||||||
|
|
||||||
struct SearchLimits {
|
struct RootMove {
|
||||||
|
|
||||||
SearchLimits() { memset(this, 0, sizeof(SearchLimits)); }
|
explicit RootMove(Move m) : pv(1, m) {}
|
||||||
|
bool extract_ponder_from_tt(Position& pos);
|
||||||
|
bool operator==(const Move& m) const { return pv[0] == m; }
|
||||||
|
bool operator<(const RootMove& m) const { // Sort in descending order
|
||||||
|
return m.score != score ? m.score < score
|
||||||
|
: m.previousScore < previousScore;
|
||||||
|
}
|
||||||
|
|
||||||
SearchLimits(int t, int i, int mtg, int mt, int md, int mn, bool inf, bool pon)
|
Value score = -VALUE_INFINITE;
|
||||||
: time(t), increment(i), movesToGo(mtg), maxTime(mt), maxDepth(md),
|
Value previousScore = -VALUE_INFINITE;
|
||||||
maxNodes(mn), infinite(inf), ponder(pon) {}
|
int selDepth = 0;
|
||||||
|
std::vector<Move> pv;
|
||||||
bool useTimeManagement() const { return !(maxTime | maxDepth | maxNodes | int(infinite)); }
|
|
||||||
|
|
||||||
int time, increment, movesToGo, maxTime, maxDepth, maxNodes;
|
|
||||||
bool infinite, ponder;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void init_search();
|
typedef std::vector<RootMove> RootMoves;
|
||||||
extern int64_t perft(Position& pos, Depth depth);
|
|
||||||
extern bool think(Position& pos, const SearchLimits& limits, Move searchMoves[]);
|
|
||||||
|
|
||||||
#endif // !defined(SEARCH_H_INCLUDED)
|
|
||||||
|
/// LimitsType struct stores information sent by GUI about available time to
|
||||||
|
/// 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] =
|
||||||
|
npmsec = movestogo = depth = movetime = mate = perft = infinite = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool use_time_management() const {
|
||||||
|
return !(mate | movetime | depth | nodes | perft | infinite);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Move> searchmoves;
|
||||||
|
int time[COLOR_NB], inc[COLOR_NB], npmsec, movestogo, depth,
|
||||||
|
movetime, mate, perft, infinite;
|
||||||
|
int64_t nodes;
|
||||||
|
TimePoint startTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern LimitsType Limits;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
} // namespace Search
|
||||||
|
|
||||||
|
#endif // #ifndef SEARCH_H_INCLUDED
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
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& paths);
|
||||||
|
WDLScore probe_wdl(Position& pos, ProbeState* result);
|
||||||
|
int probe_dtz(Position& pos, ProbeState* result);
|
||||||
|
bool root_probe(Position& pos, Search::RootMoves& rootMoves, Value& score);
|
||||||
|
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves, Value& score);
|
||||||
|
void filter_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+142
-288
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,329 +18,182 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <algorithm> // For std::count
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "movegen.h"
|
||||||
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "ucioption.h"
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
ThreadsManager Threads; // Global object definition
|
ThreadPool Threads; // Global object
|
||||||
|
|
||||||
namespace { extern "C" {
|
|
||||||
|
|
||||||
// start_routine() is the C function which is called when a new thread
|
|
||||||
// is launched. It simply calls idle_loop() with the supplied threadID.
|
|
||||||
// There are two versions of this function; one for POSIX threads and
|
|
||||||
// one for Windows threads.
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
|
|
||||||
DWORD WINAPI start_routine(LPVOID threadID) {
|
|
||||||
|
|
||||||
Threads.idle_loop(*(int*)threadID, NULL);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
void* start_routine(void* threadID) {
|
|
||||||
|
|
||||||
Threads.idle_loop(*(int*)threadID, NULL);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} }
|
|
||||||
|
|
||||||
|
|
||||||
// wake_up() wakes up the thread, normally at the beginning of the search or,
|
/// Thread constructor launches the thread and waits until it goes to sleep
|
||||||
// if "sleeping threads" is used, when there is some work to do.
|
/// in idle_loop(). Note that 'searching' and 'exit' should be alredy set.
|
||||||
|
|
||||||
void Thread::wake_up() {
|
Thread::Thread(size_t n) : idx(n), stdThread(&Thread::idle_loop, this) {
|
||||||
|
|
||||||
lock_grab(&sleepLock);
|
wait_for_search_finished();
|
||||||
cond_signal(&sleepCond);
|
|
||||||
lock_release(&sleepLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// cutoff_occurred() checks whether a beta cutoff has occurred in
|
/// Thread destructor wakes up the thread in idle_loop() and waits
|
||||||
// the thread's currently active split point, or in some ancestor of
|
/// for its termination. Thread should be already waiting.
|
||||||
// the current split point.
|
|
||||||
|
|
||||||
bool Thread::cutoff_occurred() const {
|
Thread::~Thread() {
|
||||||
|
|
||||||
for (SplitPoint* sp = splitPoint; sp; sp = sp->parent)
|
assert(!searching);
|
||||||
if (sp->is_betaCutoff)
|
|
||||||
return true;
|
exit = true;
|
||||||
return false;
|
start_searching();
|
||||||
|
stdThread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// is_available_to() checks whether the thread is available to help the thread with
|
/// Thread::clear() reset histories, usually before a new game
|
||||||
// threadID "master" at a split point. An obvious requirement is that thread must be
|
|
||||||
// idle. With more than two threads, this is not by itself sufficient: If the thread
|
|
||||||
// is the master of some active split point, it is only available as a slave to the
|
|
||||||
// threads 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::is_available_to(int master) const {
|
void Thread::clear() {
|
||||||
|
|
||||||
if (state != AVAILABLE)
|
counterMoves.fill(MOVE_NONE);
|
||||||
return false;
|
mainHistory.fill(0);
|
||||||
|
captureHistory.fill(0);
|
||||||
|
|
||||||
// Make a local copy to be sure doesn't become zero under our feet while
|
for (auto& to : contHistory)
|
||||||
// testing next condition and so leading to an out of bound access.
|
for (auto& h : to)
|
||||||
int localActiveSplitPoints = activeSplitPoints;
|
h.fill(0);
|
||||||
|
|
||||||
// No active split points means that the thread is available as a slave for any
|
contHistory[NO_PIECE][0].fill(Search::CounterMovePruneThreshold - 1);
|
||||||
// other thread otherwise apply the "helpful master" concept if possible.
|
}
|
||||||
if ( !localActiveSplitPoints
|
|
||||||
|| splitPoints[localActiveSplitPoints - 1].is_slave[master])
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
/// Thread::start_searching() wakes up the thread that will start the search
|
||||||
|
|
||||||
|
void Thread::start_searching() {
|
||||||
|
|
||||||
|
std::lock_guard<Mutex> lk(mutex);
|
||||||
|
searching = true;
|
||||||
|
cv.notify_one(); // Wake up the thread in idle_loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// read_uci_options() updates number of active threads and other internal
|
/// Thread::wait_for_search_finished() blocks on the condition variable
|
||||||
// parameters according to the UCI options values. It is called before
|
/// until the thread has finished searching.
|
||||||
// to start a new search.
|
|
||||||
|
|
||||||
void ThreadsManager::read_uci_options() {
|
void Thread::wait_for_search_finished() {
|
||||||
|
|
||||||
maxThreadsPerSplitPoint = Options["Maximum Number of Threads per Split Point"].value<int>();
|
std::unique_lock<Mutex> lk(mutex);
|
||||||
minimumSplitDepth = Options["Minimum Split Depth"].value<int>() * ONE_PLY;
|
cv.wait(lk, [&]{ return !searching; });
|
||||||
useSleepingThreads = Options["Use Sleeping Threads"].value<bool>();
|
|
||||||
activeThreads = Options["Threads"].value<int>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// init() is called during startup. Initializes locks and condition variables
|
/// Thread::idle_loop() is where the thread is parked, blocked on the
|
||||||
// and launches all threads sending them immediately to sleep.
|
/// condition variable, when it has no work to do.
|
||||||
|
|
||||||
void ThreadsManager::init() {
|
void Thread::idle_loop() {
|
||||||
|
|
||||||
int threadID[MAX_THREADS];
|
// 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);
|
||||||
|
|
||||||
// This flag is needed to properly end the threads when program exits
|
while (true)
|
||||||
allThreadsShouldExit = false;
|
|
||||||
|
|
||||||
// Threads will sent to sleep as soon as created, only main thread is kept alive
|
|
||||||
activeThreads = 1;
|
|
||||||
threads[0].state = Thread::SEARCHING;
|
|
||||||
|
|
||||||
// Allocate pawn and material hash tables for main thread
|
|
||||||
init_hash_tables();
|
|
||||||
|
|
||||||
lock_init(&mpLock);
|
|
||||||
|
|
||||||
// Initialize thread and split point locks
|
|
||||||
for (int i = 0; i < MAX_THREADS; i++)
|
|
||||||
{
|
{
|
||||||
lock_init(&threads[i].sleepLock);
|
std::unique_lock<Mutex> lk(mutex);
|
||||||
cond_init(&threads[i].sleepCond);
|
searching = false;
|
||||||
|
cv.notify_one(); // Wake up anyone waiting for search finished
|
||||||
|
cv.wait(lk, [&]{ return searching; });
|
||||||
|
|
||||||
for (int j = 0; j < MAX_ACTIVE_SPLIT_POINTS; j++)
|
if (exit)
|
||||||
lock_init(&(threads[i].splitPoints[j].lock));
|
return;
|
||||||
|
|
||||||
|
lk.unlock();
|
||||||
|
|
||||||
|
search();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ThreadPool::set() creates/destroys threads to match the requested number.
|
||||||
|
/// Created and launced threads wil go immediately to sleep in idle_loop.
|
||||||
|
/// Upon resizing, threads are recreated to allow for binding if necessary.
|
||||||
|
|
||||||
|
void ThreadPool::set(size_t requested) {
|
||||||
|
|
||||||
|
if (size() > 0) { // destroy any existing thread(s)
|
||||||
|
main()->wait_for_search_finished();
|
||||||
|
|
||||||
|
while (size() > 0)
|
||||||
|
delete back(), pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and startup all the threads but the main that is already running
|
if (requested > 0) { // create new thread(s)
|
||||||
for (int i = 1; i < MAX_THREADS; i++)
|
push_back(new MainThread(0));
|
||||||
|
|
||||||
|
while (size() < requested)
|
||||||
|
push_back(new Thread(size()));
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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(), m))
|
||||||
|
rootMoves.emplace_back(m);
|
||||||
|
|
||||||
|
if (!rootMoves.empty())
|
||||||
|
Tablebases::filter_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)
|
||||||
{
|
{
|
||||||
threads[i].state = Thread::INITIALIZING;
|
th->nodes = th->tbHits = th->nmp_ply = th->nmp_odd = 0;
|
||||||
threadID[i] = i;
|
th->rootDepth = th->completedDepth = DEPTH_ZERO;
|
||||||
|
th->rootMoves = rootMoves;
|
||||||
#if defined(_MSC_VER)
|
th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th);
|
||||||
bool ok = (CreateThread(NULL, 0, start_routine, (LPVOID)&threadID[i], 0, NULL) != NULL);
|
|
||||||
#else
|
|
||||||
pthread_t pthreadID;
|
|
||||||
bool ok = (pthread_create(&pthreadID, NULL, start_routine, (void*)&threadID[i]) == 0);
|
|
||||||
pthread_detach(pthreadID);
|
|
||||||
#endif
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
std::cout << "Failed to create thread number " << i << std::endl;
|
|
||||||
::exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait until the thread has finished launching and is gone to sleep
|
|
||||||
while (threads[i].state == Thread::INITIALIZING) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// exit() is called to cleanly exit the threads when the program finishes
|
|
||||||
|
|
||||||
void ThreadsManager::exit() {
|
|
||||||
|
|
||||||
// Force the woken up threads to exit idle_loop() and hence terminate
|
|
||||||
allThreadsShouldExit = true;
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_THREADS; i++)
|
|
||||||
{
|
|
||||||
// Wake up all the threads and waits for termination
|
|
||||||
if (i != 0)
|
|
||||||
{
|
|
||||||
threads[i].wake_up();
|
|
||||||
while (threads[i].state != Thread::TERMINATED) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can safely destroy the locks and wait conditions
|
|
||||||
lock_destroy(&threads[i].sleepLock);
|
|
||||||
cond_destroy(&threads[i].sleepCond);
|
|
||||||
|
|
||||||
for (int j = 0; j < MAX_ACTIVE_SPLIT_POINTS; j++)
|
|
||||||
lock_destroy(&(threads[i].splitPoints[j].lock));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lock_destroy(&mpLock);
|
setupStates->back() = tmp;
|
||||||
|
|
||||||
|
main()->start_searching();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// init_hash_tables() dynamically allocates pawn and material hash tables
|
|
||||||
// according to the number of active threads. This avoids preallocating
|
|
||||||
// memory for all possible threads if only few are used as, for instance,
|
|
||||||
// on mobile devices where memory is scarce and allocating for MAX_THREADS
|
|
||||||
// threads could even result in a crash.
|
|
||||||
|
|
||||||
void ThreadsManager::init_hash_tables() {
|
|
||||||
|
|
||||||
for (int i = 0; i < activeThreads; i++)
|
|
||||||
{
|
|
||||||
threads[i].pawnTable.init();
|
|
||||||
threads[i].materialTable.init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// available_slave_exists() tries to find an idle thread which is available as
|
|
||||||
// a slave for the thread with threadID "master".
|
|
||||||
|
|
||||||
bool ThreadsManager::available_slave_exists(int master) const {
|
|
||||||
|
|
||||||
assert(master >= 0 && master < activeThreads);
|
|
||||||
|
|
||||||
for (int i = 0; i < activeThreads; i++)
|
|
||||||
if (i != master && threads[i].is_available_to(master))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 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, or because we have no unused
|
|
||||||
// split point objects), 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 we tell our helper threads 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.
|
|
||||||
|
|
||||||
template <bool Fake>
|
|
||||||
void ThreadsManager::split(Position& pos, SearchStack* ss, Value* alpha, const Value beta,
|
|
||||||
Value* bestValue, Depth depth, Move threatMove,
|
|
||||||
int moveCount, MovePicker* mp, bool pvNode) {
|
|
||||||
assert(pos.is_ok());
|
|
||||||
assert(*bestValue >= -VALUE_INFINITE);
|
|
||||||
assert(*bestValue <= *alpha);
|
|
||||||
assert(*alpha < beta);
|
|
||||||
assert(beta <= VALUE_INFINITE);
|
|
||||||
assert(depth > DEPTH_ZERO);
|
|
||||||
assert(pos.thread() >= 0 && pos.thread() < activeThreads);
|
|
||||||
assert(activeThreads > 1);
|
|
||||||
|
|
||||||
int i, master = pos.thread();
|
|
||||||
Thread& masterThread = threads[master];
|
|
||||||
|
|
||||||
lock_grab(&mpLock);
|
|
||||||
|
|
||||||
// If no other thread is available to help us, or if we have too many
|
|
||||||
// active split points, don't split.
|
|
||||||
if ( !available_slave_exists(master)
|
|
||||||
|| masterThread.activeSplitPoints >= MAX_ACTIVE_SPLIT_POINTS)
|
|
||||||
{
|
|
||||||
lock_release(&mpLock);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pick the next available split point object from the split point stack
|
|
||||||
SplitPoint& splitPoint = masterThread.splitPoints[masterThread.activeSplitPoints++];
|
|
||||||
|
|
||||||
// Initialize the split point object
|
|
||||||
splitPoint.parent = masterThread.splitPoint;
|
|
||||||
splitPoint.master = master;
|
|
||||||
splitPoint.is_betaCutoff = false;
|
|
||||||
splitPoint.depth = depth;
|
|
||||||
splitPoint.threatMove = threatMove;
|
|
||||||
splitPoint.alpha = *alpha;
|
|
||||||
splitPoint.beta = beta;
|
|
||||||
splitPoint.pvNode = pvNode;
|
|
||||||
splitPoint.bestValue = *bestValue;
|
|
||||||
splitPoint.mp = mp;
|
|
||||||
splitPoint.moveCount = moveCount;
|
|
||||||
splitPoint.pos = &pos;
|
|
||||||
splitPoint.nodes = 0;
|
|
||||||
splitPoint.ss = ss;
|
|
||||||
for (i = 0; i < activeThreads; i++)
|
|
||||||
splitPoint.is_slave[i] = false;
|
|
||||||
|
|
||||||
masterThread.splitPoint = &splitPoint;
|
|
||||||
|
|
||||||
// If we are here it means we are not available
|
|
||||||
assert(masterThread.state != Thread::AVAILABLE);
|
|
||||||
|
|
||||||
int workersCnt = 1; // At least the master is included
|
|
||||||
|
|
||||||
// Allocate available threads setting state to THREAD_BOOKED
|
|
||||||
for (i = 0; !Fake && i < activeThreads && workersCnt < maxThreadsPerSplitPoint; i++)
|
|
||||||
if (i != master && threads[i].is_available_to(master))
|
|
||||||
{
|
|
||||||
threads[i].state = Thread::BOOKED;
|
|
||||||
threads[i].splitPoint = &splitPoint;
|
|
||||||
splitPoint.is_slave[i] = true;
|
|
||||||
workersCnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(Fake || workersCnt > 1);
|
|
||||||
|
|
||||||
// We can release the lock because slave threads are already booked and master is not available
|
|
||||||
lock_release(&mpLock);
|
|
||||||
|
|
||||||
// Tell the threads that they have work to do. This will make them leave
|
|
||||||
// their idle loop.
|
|
||||||
for (i = 0; i < activeThreads; i++)
|
|
||||||
if (i == master || splitPoint.is_slave[i])
|
|
||||||
{
|
|
||||||
assert(i == master || threads[i].state == Thread::BOOKED);
|
|
||||||
|
|
||||||
threads[i].state = Thread::WORKISWAITING; // This makes the slave to exit from idle_loop()
|
|
||||||
|
|
||||||
if (useSleepingThreads && i != master)
|
|
||||||
threads[i].wake_up();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Everything is set up. The master thread enters the idle loop, from
|
|
||||||
// which it will instantly launch a search, because its state is
|
|
||||||
// THREAD_WORKISWAITING. We send the split point as a second parameter to the
|
|
||||||
// idle loop, which means that the main thread will return from the idle
|
|
||||||
// loop when all threads have finished their work at this split point.
|
|
||||||
idle_loop(master, &splitPoint);
|
|
||||||
|
|
||||||
// We have returned from the idle loop, which means that all threads are
|
|
||||||
// finished. Update alpha and bestValue, and return.
|
|
||||||
lock_grab(&mpLock);
|
|
||||||
|
|
||||||
*alpha = splitPoint.alpha;
|
|
||||||
*bestValue = splitPoint.bestValue;
|
|
||||||
masterThread.activeSplitPoints--;
|
|
||||||
masterThread.splitPoint = splitPoint.parent;
|
|
||||||
pos.set_nodes_searched(pos.nodes_searched() + splitPoint.nodes);
|
|
||||||
|
|
||||||
lock_release(&mpLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit template instantiations
|
|
||||||
template void ThreadsManager::split<false>(Position&, SearchStack*, Value*, const Value, Value*, Depth, Move, int, MovePicker*, bool);
|
|
||||||
template void ThreadsManager::split<true>(Position&, SearchStack*, Value*, const Value, Value*, Depth, Move, int, MovePicker*, bool);
|
|
||||||
|
|||||||
+87
-96
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,116 +18,106 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(THREAD_H_INCLUDED)
|
#ifndef THREAD_H_INCLUDED
|
||||||
#define THREAD_H_INCLUDED
|
#define THREAD_H_INCLUDED
|
||||||
|
|
||||||
#include <cstring>
|
#include <atomic>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "lock.h"
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
#include "search.h"
|
||||||
const int MAX_THREADS = 32;
|
#include "thread_win32.h"
|
||||||
const int MAX_ACTIVE_SPLIT_POINTS = 8;
|
|
||||||
|
|
||||||
struct SplitPoint {
|
|
||||||
|
|
||||||
// Const data after splitPoint has been setup
|
|
||||||
SplitPoint* parent;
|
|
||||||
const Position* pos;
|
|
||||||
Depth depth;
|
|
||||||
bool pvNode;
|
|
||||||
Value beta;
|
|
||||||
int ply;
|
|
||||||
int master;
|
|
||||||
Move threatMove;
|
|
||||||
|
|
||||||
// Const pointers to shared data
|
|
||||||
MovePicker* mp;
|
|
||||||
SearchStack* ss;
|
|
||||||
|
|
||||||
// Shared data
|
|
||||||
Lock lock;
|
|
||||||
volatile int64_t nodes;
|
|
||||||
volatile Value alpha;
|
|
||||||
volatile Value bestValue;
|
|
||||||
volatile int moveCount;
|
|
||||||
volatile bool is_betaCutoff;
|
|
||||||
volatile bool is_slave[MAX_THREADS];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Thread struct is used to keep together all the thread related stuff like locks,
|
/// Thread class keeps together all the thread-related stuff. We use
|
||||||
/// state and especially split points. We also use per-thread pawn and material hash
|
/// per-thread pawn and material hash tables so that once we get a
|
||||||
/// tables so that once we get a pointer to an entry its life time is unlimited and
|
/// pointer to an entry its life time is unlimited and we don't have
|
||||||
/// we don't have to care about someone changing the entry under our feet.
|
/// to care about someone changing the entry under our feet.
|
||||||
|
|
||||||
struct Thread {
|
class Thread {
|
||||||
|
|
||||||
enum ThreadState
|
Mutex mutex;
|
||||||
{
|
ConditionVariable cv;
|
||||||
INITIALIZING, // Thread is initializing itself
|
size_t idx;
|
||||||
SEARCHING, // Thread is performing work
|
bool exit = false, searching = true; // Set before starting std::thread
|
||||||
AVAILABLE, // Thread is waiting for work
|
std::thread stdThread;
|
||||||
BOOKED, // Other thread (master) has booked us as a slave
|
|
||||||
WORKISWAITING, // Master has ordered us to start
|
|
||||||
TERMINATED // We are quitting and thread is terminated
|
|
||||||
};
|
|
||||||
|
|
||||||
void wake_up();
|
|
||||||
bool cutoff_occurred() const;
|
|
||||||
bool is_available_to(int master) const;
|
|
||||||
|
|
||||||
MaterialInfoTable materialTable;
|
|
||||||
PawnInfoTable pawnTable;
|
|
||||||
int maxPly;
|
|
||||||
Lock sleepLock;
|
|
||||||
WaitCondition sleepCond;
|
|
||||||
volatile ThreadState state;
|
|
||||||
SplitPoint* volatile splitPoint;
|
|
||||||
volatile int activeSplitPoints;
|
|
||||||
SplitPoint splitPoints[MAX_ACTIVE_SPLIT_POINTS];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// ThreadsManager class is used to handle all the threads related stuff like init,
|
|
||||||
/// starting, parking and, the most important, launching a slave thread at a split
|
|
||||||
/// point. All the access to shared thread data is done through this class.
|
|
||||||
|
|
||||||
class ThreadsManager {
|
|
||||||
/* As long as the single ThreadsManager object is defined as a global we don't
|
|
||||||
need to explicitly initialize to zero its data members because variables with
|
|
||||||
static storage duration are automatically set to zero before enter main()
|
|
||||||
*/
|
|
||||||
public:
|
public:
|
||||||
Thread& operator[](int threadID) { return threads[threadID]; }
|
explicit Thread(size_t);
|
||||||
void init();
|
virtual ~Thread();
|
||||||
void exit();
|
virtual void search();
|
||||||
void init_hash_tables();
|
void clear();
|
||||||
|
void idle_loop();
|
||||||
|
void start_searching();
|
||||||
|
void wait_for_search_finished();
|
||||||
|
|
||||||
int min_split_depth() const { return minimumSplitDepth; }
|
Pawns::Table pawnsTable;
|
||||||
int size() const { return activeThreads; }
|
Material::Table materialTable;
|
||||||
void set_size(int cnt) { activeThreads = cnt; }
|
Endgames endgames;
|
||||||
|
size_t PVIdx;
|
||||||
|
int selDepth, nmp_ply, nmp_odd;
|
||||||
|
std::atomic<uint64_t> nodes, tbHits;
|
||||||
|
|
||||||
void read_uci_options();
|
Position rootPos;
|
||||||
bool available_slave_exists(int master) const;
|
Search::RootMoves rootMoves;
|
||||||
void idle_loop(int threadID, SplitPoint* sp);
|
Depth rootDepth, completedDepth;
|
||||||
|
CounterMoveHistory counterMoves;
|
||||||
template <bool Fake>
|
ButterflyHistory mainHistory;
|
||||||
void split(Position& pos, SearchStack* ss, Value* alpha, const Value beta, Value* bestValue,
|
CapturePieceToHistory captureHistory;
|
||||||
Depth depth, Move threatMove, int moveCount, MovePicker* mp, bool pvNode);
|
ContinuationHistory contHistory;
|
||||||
private:
|
|
||||||
Lock mpLock;
|
|
||||||
Depth minimumSplitDepth;
|
|
||||||
int maxThreadsPerSplitPoint;
|
|
||||||
bool useSleepingThreads;
|
|
||||||
int activeThreads;
|
|
||||||
volatile bool allThreadsShouldExit;
|
|
||||||
Thread threads[MAX_THREADS];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ThreadsManager Threads;
|
|
||||||
|
|
||||||
#endif // !defined(THREAD_H_INCLUDED)
|
/// MainThread is a derived class specific for main thread
|
||||||
|
|
||||||
|
struct MainThread : public Thread {
|
||||||
|
|
||||||
|
using Thread::Thread;
|
||||||
|
|
||||||
|
void search() override;
|
||||||
|
void check_time();
|
||||||
|
|
||||||
|
bool failedLow;
|
||||||
|
double bestMoveChanges, previousTimeReduction;
|
||||||
|
Value previousScore;
|
||||||
|
int callsCnt;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// 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 start_thinking(Position&, StateListPtr&, const Search::LimitsType&, bool = false);
|
||||||
|
void clear();
|
||||||
|
void set(size_t);
|
||||||
|
|
||||||
|
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); }
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
#endif // #ifndef THREAD_H_INCLUDED
|
||||||
|
|||||||
@@ -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-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef THREAD_WIN32_H_INCLUDED
|
||||||
|
#define THREAD_WIN32_H_INCLUDED
|
||||||
|
|
||||||
|
/// STL thread library used by mingw and gcc when cross compiling for Windows
|
||||||
|
/// relies on libwinpthread. Currently libwinpthread implements mutexes directly
|
||||||
|
/// on top of Windows semaphores. Semaphores, being kernel objects, require kernel
|
||||||
|
/// mode transition in order to lock or unlock, which is very slow compared to
|
||||||
|
/// interlocked operations (about 30% slower on bench test). To work around this
|
||||||
|
/// issue, we define our wrappers to the low level Win32 calls. We use critical
|
||||||
|
/// sections to support Windows XP and older versions. Unfortunately, cond_wait()
|
||||||
|
/// is racy between unlock() and WaitForSingleObject() but they have the same
|
||||||
|
/// speed performance as the SRW locks.
|
||||||
|
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#if defined(_WIN32) && !defined(_MSC_VER)
|
||||||
|
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
# define NOMINMAX // Disable macros min() and max()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
|
#undef NOMINMAX
|
||||||
|
|
||||||
|
/// Mutex and ConditionVariable struct are wrappers of the low level locking
|
||||||
|
/// machinery and are modeled after the corresponding C++11 classes.
|
||||||
|
|
||||||
|
struct Mutex {
|
||||||
|
Mutex() { InitializeCriticalSection(&cs); }
|
||||||
|
~Mutex() { DeleteCriticalSection(&cs); }
|
||||||
|
void lock() { EnterCriticalSection(&cs); }
|
||||||
|
void unlock() { LeaveCriticalSection(&cs); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CRITICAL_SECTION cs;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::condition_variable_any ConditionVariable;
|
||||||
|
|
||||||
|
#else // Default case: use STL classes
|
||||||
|
|
||||||
|
typedef std::mutex Mutex;
|
||||||
|
typedef std::condition_variable ConditionVariable;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef THREAD_WIN32_H_INCLUDED
|
||||||
+91
-120
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,145 +18,115 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cfloat>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "misc.h"
|
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "timeman.h"
|
#include "timeman.h"
|
||||||
#include "ucioption.h"
|
#include "uci.h"
|
||||||
|
|
||||||
|
TimeManagement Time; // Our global time management object
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Constants
|
|
||||||
|
|
||||||
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
|
||||||
const float MaxRatio = 3.0f; // When in trouble, we can step over reserved time with this ratio
|
|
||||||
const float StealRatio = 0.33f; // However we must not steal time from remaining moves over this ratio
|
|
||||||
|
|
||||||
|
|
||||||
// MoveImportance[] is 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.
|
|
||||||
const int MoveImportance[512] = {
|
|
||||||
7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780, 7780,
|
|
||||||
7780, 7780, 7780, 7780, 7778, 7778, 7776, 7776, 7776, 7773, 7770, 7768, 7766, 7763, 7757, 7751,
|
|
||||||
7743, 7735, 7724, 7713, 7696, 7689, 7670, 7656, 7627, 7605, 7571, 7549, 7522, 7493, 7462, 7425,
|
|
||||||
7385, 7350, 7308, 7272, 7230, 7180, 7139, 7094, 7055, 7010, 6959, 6902, 6841, 6778, 6705, 6651,
|
|
||||||
6569, 6508, 6435, 6378, 6323, 6253, 6152, 6085, 5995, 5931, 5859, 5794, 5717, 5646, 5544, 5462,
|
|
||||||
5364, 5282, 5172, 5078, 4988, 4901, 4831, 4764, 4688, 4609, 4536, 4443, 4365, 4293, 4225, 4155,
|
|
||||||
4085, 4005, 3927, 3844, 3765, 3693, 3634, 3560, 3479, 3404, 3331, 3268, 3207, 3146, 3077, 3011,
|
|
||||||
2947, 2894, 2828, 2776, 2727, 2676, 2626, 2589, 2538, 2490, 2442, 2394, 2345, 2302, 2243, 2192,
|
|
||||||
2156, 2115, 2078, 2043, 2004, 1967, 1922, 1893, 1845, 1809, 1772, 1736, 1702, 1674, 1640, 1605,
|
|
||||||
1566, 1536, 1509, 1479, 1452, 1423, 1388, 1362, 1332, 1304, 1289, 1266, 1250, 1228, 1206, 1180,
|
|
||||||
1160, 1134, 1118, 1100, 1080, 1068, 1051, 1034, 1012, 1001, 980, 960, 945, 934, 916, 900, 888,
|
|
||||||
878, 865, 852, 828, 807, 787, 770, 753, 744, 731, 722, 706, 700, 683, 676, 671, 664, 652, 641,
|
|
||||||
634, 627, 613, 604, 591, 582, 568, 560, 552, 540, 534, 529, 519, 509, 495, 484, 474, 467, 460,
|
|
||||||
450, 438, 427, 419, 410, 406, 399, 394, 387, 382, 377, 372, 366, 359, 353, 348, 343, 337, 333,
|
|
||||||
328, 321, 315, 309, 303, 298, 293, 287, 284, 281, 277, 273, 265, 261, 255, 251, 247, 241, 240,
|
|
||||||
235, 229, 218, 217, 213, 212, 208, 206, 197, 193, 191, 189, 185, 184, 180, 177, 172, 170, 170,
|
|
||||||
170, 166, 163, 159, 158, 156, 155, 151, 146, 141, 138, 136, 132, 130, 128, 125, 123, 122, 118,
|
|
||||||
118, 118, 117, 115, 114, 108, 107, 105, 105, 105, 102, 97, 97, 95, 94, 93, 91, 88, 86, 83, 80,
|
|
||||||
80, 79, 79, 79, 78, 76, 75, 72, 72, 71, 70, 68, 65, 63, 61, 61, 59, 59, 59, 58, 56, 55, 54, 54,
|
|
||||||
52, 49, 48, 48, 48, 48, 45, 45, 45, 44, 43, 41, 41, 41, 41, 40, 40, 38, 37, 36, 34, 34, 34, 33,
|
|
||||||
31, 29, 29, 29, 28, 28, 28, 28, 28, 28, 28, 27, 27, 27, 27, 27, 24, 24, 23, 23, 22, 21, 20, 20,
|
|
||||||
19, 19, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17, 17, 17, 16, 16, 15, 15, 14, 14, 14, 12, 12, 11,
|
|
||||||
9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
||||||
8, 8, 8, 8, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 2, 2, 2,
|
|
||||||
2, 1, 1, 1, 1, 1, 1, 1 };
|
|
||||||
|
|
||||||
int move_importance(int ply) { return MoveImportance[Min(ply, 511)]; }
|
|
||||||
|
|
||||||
|
|
||||||
/// Function Prototypes
|
|
||||||
|
|
||||||
enum TimeType { OptimumTime, MaxTime };
|
enum TimeType { OptimumTime, MaxTime };
|
||||||
|
|
||||||
template<TimeType>
|
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||||
int remaining(int myTime, int movesToGo, int currentPly);
|
const double MaxRatio = 7.09; // When in trouble, we can step over reserved time with this ratio
|
||||||
}
|
const double StealRatio = 0.35; // However we must not steal time from remaining moves over this ratio
|
||||||
|
|
||||||
|
|
||||||
void TimeManager::pv_instability(int curChanges, int prevChanges) {
|
// 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 the CCRL game database with some simple filtering criteria.
|
||||||
|
|
||||||
unstablePVExtraTime = curChanges * (optimumSearchTime / 2)
|
double move_importance(int ply) {
|
||||||
+ prevChanges * (optimumSearchTime / 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const double XScale = 7.64;
|
||||||
|
const double XShift = 58.4;
|
||||||
|
const double Skew = 0.183;
|
||||||
|
|
||||||
void TimeManager::init(const SearchLimits& limits, int currentPly)
|
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
||||||
{
|
|
||||||
/* We support four different kind of time controls:
|
|
||||||
|
|
||||||
increment == 0 && movesToGo == 0 means: x basetime [sudden death!]
|
|
||||||
increment == 0 && movesToGo != 0 means: x moves in y minutes
|
|
||||||
increment > 0 && movesToGo == 0 means: x basetime + z increment
|
|
||||||
increment > 0 && movesToGo != 0 means: x moves in y minutes + z increment
|
|
||||||
|
|
||||||
Time management is adjusted by following UCI parameters:
|
|
||||||
|
|
||||||
emergencyMoveHorizon: Be prepared to always play at least this many moves
|
|
||||||
emergencyBaseTime : Always attempt to keep at least this much time (in ms) at clock
|
|
||||||
emergencyMoveTime : Plus attempt to keep at least this much time for each remaining emergency move
|
|
||||||
minThinkingTime : No matter what, use at least this much thinking before doing the move
|
|
||||||
*/
|
|
||||||
|
|
||||||
int hypMTG, hypMyTime, t1, t2;
|
|
||||||
|
|
||||||
// Read uci parameters
|
|
||||||
int emergencyMoveHorizon = Options["Emergency Move Horizon"].value<int>();
|
|
||||||
int emergencyBaseTime = Options["Emergency Base Time"].value<int>();
|
|
||||||
int emergencyMoveTime = Options["Emergency Move Time"].value<int>();
|
|
||||||
int minThinkingTime = Options["Minimum Thinking Time"].value<int>();
|
|
||||||
|
|
||||||
// Initialize to maximum values but unstablePVExtraTime that is reset
|
|
||||||
unstablePVExtraTime = 0;
|
|
||||||
optimumSearchTime = maximumSearchTime = limits.time;
|
|
||||||
|
|
||||||
// We calculate optimum time usage for different hypothetic "moves to go"-values and choose the
|
|
||||||
// minimum of calculated search time values. Usually the greatest hypMTG gives the minimum values.
|
|
||||||
for (hypMTG = 1; hypMTG <= (limits.movesToGo ? Min(limits.movesToGo, MoveHorizon) : MoveHorizon); hypMTG++)
|
|
||||||
{
|
|
||||||
// Calculate thinking time for hypothetic "moves to go"-value
|
|
||||||
hypMyTime = limits.time
|
|
||||||
+ limits.increment * (hypMTG - 1)
|
|
||||||
- emergencyBaseTime
|
|
||||||
- emergencyMoveTime * Min(hypMTG, emergencyMoveHorizon);
|
|
||||||
|
|
||||||
hypMyTime = Max(hypMyTime, 0);
|
|
||||||
|
|
||||||
t1 = minThinkingTime + remaining<OptimumTime>(hypMyTime, hypMTG, currentPly);
|
|
||||||
t2 = minThinkingTime + remaining<MaxTime>(hypMyTime, hypMTG, currentPly);
|
|
||||||
|
|
||||||
optimumSearchTime = Min(optimumSearchTime, t1);
|
|
||||||
maximumSearchTime = Min(maximumSearchTime, t2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Options["Ponder"].value<bool>())
|
|
||||||
optimumSearchTime += optimumSearchTime / 4;
|
|
||||||
|
|
||||||
// Make sure that maxSearchTime is not over absoluteMaxSearchTime
|
|
||||||
optimumSearchTime = Min(optimumSearchTime, maximumSearchTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
template<TimeType T>
|
template<TimeType T>
|
||||||
int remaining(int myTime, int movesToGo, int currentPly)
|
int remaining(int myTime, int movesToGo, int ply, int slowMover) {
|
||||||
{
|
|
||||||
const float TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
|
||||||
const float TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
|
||||||
|
|
||||||
int thisMoveImportance = move_importance(currentPly);
|
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
||||||
int otherMovesImportance = 0;
|
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
||||||
|
|
||||||
for (int i = 1; i < movesToGo; i++)
|
double moveImportance = (move_importance(ply) * slowMover) / 100;
|
||||||
otherMovesImportance += move_importance(currentPly + 2 * i);
|
double otherMovesImportance = 0;
|
||||||
|
|
||||||
float ratio1 = (TMaxRatio * thisMoveImportance) / float(TMaxRatio * thisMoveImportance + otherMovesImportance);
|
for (int i = 1; i < movesToGo; ++i)
|
||||||
float ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / float(thisMoveImportance + otherMovesImportance);
|
otherMovesImportance += move_importance(ply + 2 * i);
|
||||||
|
|
||||||
return int(floor(myTime * Min(ratio1, ratio2)));
|
double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance);
|
||||||
|
double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance);
|
||||||
|
|
||||||
|
return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
/// init() is called at the beginning of the search and calculates the allowed
|
||||||
|
/// thinking time out of the time control and current game ply. We support four
|
||||||
|
/// different kinds of time controls, passed in 'limits':
|
||||||
|
///
|
||||||
|
/// inc == 0 && movestogo == 0 means: x basetime [sudden death!]
|
||||||
|
/// inc == 0 && movestogo != 0 means: x moves in y minutes
|
||||||
|
/// inc > 0 && movestogo == 0 means: x basetime + z increment
|
||||||
|
/// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment
|
||||||
|
|
||||||
|
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
||||||
|
|
||||||
|
int minThinkingTime = Options["Minimum Thinking Time"];
|
||||||
|
int moveOverhead = Options["Move Overhead"];
|
||||||
|
int slowMover = Options["Slow Mover"];
|
||||||
|
int npmsec = Options["nodestime"];
|
||||||
|
|
||||||
|
// 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: Given npms (nodes per millisecond) must be much lower then
|
||||||
|
// the real engine speed to avoid time losses.
|
||||||
|
if (npmsec)
|
||||||
|
{
|
||||||
|
if (!availableNodes) // Only once at game start
|
||||||
|
availableNodes = npmsec * limits.time[us]; // Time is in msec
|
||||||
|
|
||||||
|
// Convert from millisecs to nodes
|
||||||
|
limits.time[us] = (int)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)
|
||||||
|
{
|
||||||
|
// 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 = std::max(hypMyTime, 0);
|
||||||
|
|
||||||
|
int t1 = minThinkingTime + remaining<OptimumTime>(hypMyTime, hypMTG, ply, slowMover);
|
||||||
|
int t2 = minThinkingTime + remaining<MaxTime >(hypMyTime, hypMTG, ply, slowMover);
|
||||||
|
|
||||||
|
optimumTime = std::min(t1, optimumTime);
|
||||||
|
maximumTime = std::min(t2, maximumTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Options["Ponder"])
|
||||||
|
optimumTime += optimumTime / 4;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-12
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,23 +18,31 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(TIMEMAN_H_INCLUDED)
|
#ifndef TIMEMAN_H_INCLUDED
|
||||||
#define TIMEMAN_H_INCLUDED
|
#define TIMEMAN_H_INCLUDED
|
||||||
|
|
||||||
struct SearchLimits;
|
#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:
|
public:
|
||||||
|
void init(Search::LimitsType& limits, Color us, int ply);
|
||||||
|
int optimum() const { return optimumTime; }
|
||||||
|
int maximum() const { return maximumTime; }
|
||||||
|
int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - startTime); }
|
||||||
|
|
||||||
void init(const SearchLimits& limits, int currentPly);
|
int64_t availableNodes; // When in 'nodes as time' mode
|
||||||
void pv_instability(int curChanges, int prevChanges);
|
|
||||||
int available_time() const { return optimumSearchTime + unstablePVExtraTime; }
|
|
||||||
int maximum_time() const { return maximumSearchTime; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int optimumSearchTime;
|
TimePoint startTime;
|
||||||
int maximumSearchTime;
|
int optimumTime;
|
||||||
int unstablePVExtraTime;
|
int maximumTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !defined(TIMEMAN_H_INCLUDED)
|
extern TimeManagement Time;
|
||||||
|
|
||||||
|
#endif // #ifndef TIMEMAN_H_INCLUDED
|
||||||
|
|||||||
+62
-88
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,128 +18,101 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cassert>
|
#include <cstring> // For std::memset
|
||||||
#include <cstring>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "bitboard.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
|
|
||||||
TranspositionTable TT; // Our global transposition table
|
TranspositionTable TT; // Our global transposition table
|
||||||
|
|
||||||
TranspositionTable::TranspositionTable() {
|
|
||||||
|
|
||||||
size = generation = 0;
|
/// TranspositionTable::resize() sets the size of the transposition table,
|
||||||
entries = NULL;
|
/// measured in megabytes. Transposition table consists of a power of 2 number
|
||||||
}
|
/// of clusters and each cluster consists of ClusterSize number of TTEntry.
|
||||||
|
|
||||||
TranspositionTable::~TranspositionTable() {
|
void TranspositionTable::resize(size_t mbSize) {
|
||||||
|
|
||||||
delete [] entries;
|
size_t newClusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
|
||||||
}
|
|
||||||
|
|
||||||
|
if (newClusterCount == clusterCount)
|
||||||
/// TranspositionTable::set_size() sets the size of the transposition table,
|
|
||||||
/// measured in megabytes.
|
|
||||||
|
|
||||||
void TranspositionTable::set_size(size_t mbSize) {
|
|
||||||
|
|
||||||
size_t newSize = 1024;
|
|
||||||
|
|
||||||
// Transposition table consists of clusters and each cluster consists
|
|
||||||
// of ClusterSize number of TTEntries. Each non-empty entry contains
|
|
||||||
// information of exactly one position and newSize is the number of
|
|
||||||
// clusters we are going to allocate.
|
|
||||||
while (2ULL * newSize * sizeof(TTCluster) <= (mbSize << 20))
|
|
||||||
newSize *= 2;
|
|
||||||
|
|
||||||
if (newSize == size)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size = newSize;
|
clusterCount = newClusterCount;
|
||||||
delete [] entries;
|
|
||||||
entries = new (std::nothrow) TTCluster[size];
|
free(mem);
|
||||||
if (!entries)
|
mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);
|
||||||
|
|
||||||
|
if (!mem)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to allocate " << mbSize
|
std::cerr << "Failed to allocate " << mbSize
|
||||||
<< " MB for transposition table." << std::endl;
|
<< "MB for transposition table." << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::clear() overwrites the entire transposition table
|
/// TranspositionTable::clear() overwrites the entire transposition table
|
||||||
/// with zeroes. It is called whenever the table is resized, or when the
|
/// 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).
|
/// user asks the program to clear the table (from the UCI interface).
|
||||||
|
|
||||||
void TranspositionTable::clear() {
|
void TranspositionTable::clear() {
|
||||||
|
|
||||||
memset(entries, 0, size * sizeof(TTCluster));
|
std::memset(table, 0, clusterCount * sizeof(Cluster));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::store() writes a new entry containing position key and
|
/// TranspositionTable::probe() looks up the current position in the transposition
|
||||||
/// valuable information of current position. The lowest order bits of position
|
/// table. It returns true and a pointer to the TTEntry if the position is found.
|
||||||
/// key are used to decide on which cluster the position will be placed.
|
/// Otherwise, it returns false and a pointer to an empty or least valuable TTEntry
|
||||||
/// When a new entry is written and there are no empty entries available in cluster,
|
/// to be replaced later. The replace value of an entry is calculated as its depth
|
||||||
/// it replaces the least valuable of entries. A TTEntry t1 is considered to be
|
/// minus 8 times its relative age. TTEntry t1 is considered more valuable than
|
||||||
/// more valuable than a TTEntry t2 if t1 is from the current search and t2 is from
|
/// TTEntry t2 if its replace value is greater than that of t2.
|
||||||
/// a previous search, or if the depth of t1 is bigger than the depth of t2.
|
|
||||||
|
|
||||||
void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, Move m, Value statV, Value kingD) {
|
TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
||||||
|
|
||||||
int c1, c2, c3;
|
TTEntry* const tte = first_entry(key);
|
||||||
TTEntry *tte, *replace;
|
const uint16_t key16 = key >> 48; // Use the high 16 bits as key inside the cluster
|
||||||
uint32_t posKey32 = posKey >> 32; // Use the high 32 bits as key inside the cluster
|
|
||||||
|
|
||||||
tte = replace = first_entry(posKey);
|
for (int i = 0; i < ClusterSize; ++i)
|
||||||
|
if (!tte[i].key16 || tte[i].key16 == key16)
|
||||||
for (int i = 0; i < ClusterSize; i++, tte++)
|
|
||||||
{
|
|
||||||
if (!tte->key() || tte->key() == posKey32) // Empty or overwrite old
|
|
||||||
{
|
{
|
||||||
// Preserve any existing ttMove
|
if ((tte[i].genBound8 & 0xFC) != generation8 && tte[i].key16)
|
||||||
if (m == MOVE_NONE)
|
tte[i].genBound8 = uint8_t(generation8 | tte[i].bound()); // Refresh
|
||||||
m = tte->move();
|
|
||||||
|
|
||||||
tte->save(posKey32, v, t, d, m, generation, statV, kingD);
|
return found = (bool)tte[i].key16, &tte[i];
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement replace strategy
|
// Find an entry to be replaced according to the replacement strategy
|
||||||
c1 = (replace->generation() == generation ? 2 : 0);
|
TTEntry* replace = tte;
|
||||||
c2 = (tte->generation() == generation || tte->type() == VALUE_TYPE_EXACT ? -2 : 0);
|
for (int i = 1; i < ClusterSize; ++i)
|
||||||
c3 = (tte->depth() < replace->depth() ? 1 : 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];
|
||||||
|
|
||||||
if (c1 + c2 + c3 > 0)
|
return found = false, replace;
|
||||||
replace = tte;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// 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++;
|
||||||
}
|
}
|
||||||
replace->save(posKey32, v, t, d, m, generation, statV, kingD);
|
return cnt;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::probe() looks up the current position in the
|
|
||||||
/// transposition table. Returns a pointer to the TTEntry or NULL if
|
|
||||||
/// position is not found.
|
|
||||||
|
|
||||||
TTEntry* TranspositionTable::probe(const Key posKey) const {
|
|
||||||
|
|
||||||
uint32_t posKey32 = posKey >> 32;
|
|
||||||
TTEntry* tte = first_entry(posKey);
|
|
||||||
|
|
||||||
for (int i = 0; i < ClusterSize; i++, tte++)
|
|
||||||
if (tte->key() == posKey32)
|
|
||||||
return tte;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::new_search() is called at the beginning of every new
|
|
||||||
/// search. It increments the "generation" variable, which is used to
|
|
||||||
/// distinguish transposition table entries from previous searches from
|
|
||||||
/// entries from the current search.
|
|
||||||
|
|
||||||
void TranspositionTable::new_search() {
|
|
||||||
generation++;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,157 +18,104 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(TT_H_INCLUDED)
|
#ifndef TT_H_INCLUDED
|
||||||
#define TT_H_INCLUDED
|
#define TT_H_INCLUDED
|
||||||
|
|
||||||
#include <iostream>
|
#include "misc.h"
|
||||||
|
|
||||||
#include "move.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
/// TTEntry struct is the 10 bytes transposition table entry, defined as below:
|
||||||
/// The TTEntry is the class of transposition table entries
|
|
||||||
///
|
///
|
||||||
/// A TTEntry needs 128 bits to be stored
|
/// key 16 bit
|
||||||
///
|
/// move 16 bit
|
||||||
/// bit 0-31: key
|
/// value 16 bit
|
||||||
/// bit 32-63: data
|
/// eval value 16 bit
|
||||||
/// bit 64-79: value
|
/// generation 6 bit
|
||||||
/// bit 80-95: depth
|
/// bound type 2 bit
|
||||||
/// bit 96-111: static value
|
/// depth 8 bit
|
||||||
/// bit 112-127: margin of static value
|
|
||||||
///
|
|
||||||
/// the 32 bits of the data field are so defined
|
|
||||||
///
|
|
||||||
/// bit 0-15: move
|
|
||||||
/// bit 16-20: not used
|
|
||||||
/// bit 21-22: value type
|
|
||||||
/// bit 23-31: generation
|
|
||||||
|
|
||||||
class TTEntry {
|
struct TTEntry {
|
||||||
|
|
||||||
public:
|
Move move() const { return (Move )move16; }
|
||||||
void save(uint32_t k, Value v, ValueType t, Depth d, Move m, int g, Value statV, Value statM) {
|
Value value() const { return (Value)value16; }
|
||||||
|
Value eval() const { return (Value)eval16; }
|
||||||
|
Depth depth() const { return (Depth)(depth8 * int(ONE_PLY)); }
|
||||||
|
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
||||||
|
|
||||||
key32 = (uint32_t)k;
|
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
|
||||||
move16 = (uint16_t)m;
|
|
||||||
valueType = (uint8_t)t;
|
assert(d / ONE_PLY * ONE_PLY == d);
|
||||||
generation8 = (uint8_t)g;
|
|
||||||
value16 = (int16_t)v;
|
// Preserve any existing move for the same position
|
||||||
depth16 = (int16_t)d;
|
if (m || (k >> 48) != key16)
|
||||||
staticValue = (int16_t)statV;
|
move16 = (uint16_t)m;
|
||||||
staticMargin = (int16_t)statM;
|
|
||||||
|
// Don't overwrite more valuable entries
|
||||||
|
if ( (k >> 48) != key16
|
||||||
|
|| d / ONE_PLY > depth8 - 4
|
||||||
|
/* || g != (genBound8 & 0xFC) // Matching non-zero keys are already refreshed by probe() */
|
||||||
|
|| b == BOUND_EXACT)
|
||||||
|
{
|
||||||
|
key16 = (uint16_t)(k >> 48);
|
||||||
|
value16 = (int16_t)v;
|
||||||
|
eval16 = (int16_t)ev;
|
||||||
|
genBound8 = (uint8_t)(g | b);
|
||||||
|
depth8 = (int8_t)(d / ONE_PLY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void set_generation(int g) { generation8 = (uint8_t)g; }
|
|
||||||
|
|
||||||
uint32_t key() const { return key32; }
|
|
||||||
Depth depth() const { return (Depth)depth16; }
|
|
||||||
Move move() const { return (Move)move16; }
|
|
||||||
Value value() const { return (Value)value16; }
|
|
||||||
ValueType type() const { return (ValueType)valueType; }
|
|
||||||
int generation() const { return (int)generation8; }
|
|
||||||
Value static_value() const { return (Value)staticValue; }
|
|
||||||
Value static_value_margin() const { return (Value)staticMargin; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t key32;
|
friend class TranspositionTable;
|
||||||
|
|
||||||
|
uint16_t key16;
|
||||||
uint16_t move16;
|
uint16_t move16;
|
||||||
uint8_t valueType, generation8;
|
int16_t value16;
|
||||||
int16_t value16, depth16, staticValue, staticMargin;
|
int16_t eval16;
|
||||||
|
uint8_t genBound8;
|
||||||
|
int8_t depth8;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// This is the number of TTEntry slots for each cluster
|
/// A TranspositionTable consists of a power of 2 number of clusters and each
|
||||||
const int ClusterSize = 4;
|
/// cluster consists of ClusterSize number of TTEntry. Each non-empty entry
|
||||||
|
/// contains information of exactly one position. The size of a cluster should
|
||||||
|
/// divide the size of a cache line size, to ensure that clusters never cross
|
||||||
/// TTCluster consists of ClusterSize number of TTEntries. Size of TTCluster
|
/// cache lines. This ensures best cache performance, as the cacheline is
|
||||||
/// must not be bigger than a cache line size. In case it is less, it should
|
/// prefetched, as soon as possible.
|
||||||
/// be padded to guarantee always aligned accesses.
|
|
||||||
|
|
||||||
struct TTCluster {
|
|
||||||
TTEntry data[ClusterSize];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// The transposition table class. This is basically just a huge array containing
|
|
||||||
/// TTCluster objects, and a few methods for writing and reading entries.
|
|
||||||
|
|
||||||
class TranspositionTable {
|
class TranspositionTable {
|
||||||
|
|
||||||
TranspositionTable(const TranspositionTable&);
|
static const int CacheLineSize = 64;
|
||||||
TranspositionTable& operator=(const TranspositionTable&);
|
static const int ClusterSize = 3;
|
||||||
|
|
||||||
|
struct Cluster {
|
||||||
|
TTEntry entry[ClusterSize];
|
||||||
|
char padding[2]; // Align to a divisor of the cache line size
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(CacheLineSize % sizeof(Cluster) == 0, "Cluster size incorrect");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TranspositionTable();
|
~TranspositionTable() { free(mem); }
|
||||||
~TranspositionTable();
|
void new_search() { generation8 += 4; } // Lower 2 bits are used by Bound
|
||||||
void set_size(size_t mbSize);
|
uint8_t generation() const { return generation8; }
|
||||||
|
TTEntry* probe(const Key key, bool& found) const;
|
||||||
|
int hashfull() const;
|
||||||
|
void resize(size_t mbSize);
|
||||||
void clear();
|
void clear();
|
||||||
void store(const Key posKey, Value v, ValueType type, Depth d, Move m, Value statV, Value kingD);
|
|
||||||
TTEntry* probe(const Key posKey) const;
|
// The 32 lowest order bits of the key are used to get the index of the cluster
|
||||||
void new_search();
|
TTEntry* first_entry(const Key key) const {
|
||||||
TTEntry* first_entry(const Key posKey) const;
|
return &table[(uint32_t(key) * uint64_t(clusterCount)) >> 32].entry[0];
|
||||||
void refresh(const TTEntry* tte) const;
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t size;
|
size_t clusterCount;
|
||||||
TTCluster* entries;
|
Cluster* table;
|
||||||
uint8_t generation; // Size must be not bigger then TTEntry::generation8
|
void* mem;
|
||||||
|
uint8_t generation8; // Size must be not bigger than TTEntry::genBound8
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TranspositionTable TT;
|
extern TranspositionTable TT;
|
||||||
|
|
||||||
|
#endif // #ifndef TT_H_INCLUDED
|
||||||
/// TranspositionTable::first_entry() returns a pointer to the first entry of
|
|
||||||
/// a cluster given a position. The lowest order bits of the key are used to
|
|
||||||
/// get the index of the cluster.
|
|
||||||
|
|
||||||
inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
|
|
||||||
|
|
||||||
return entries[((uint32_t)posKey) & (size - 1)].data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::refresh() updates the 'generation' value of the TTEntry
|
|
||||||
/// to avoid aging. Normally called after a TT hit.
|
|
||||||
|
|
||||||
inline void TranspositionTable::refresh(const TTEntry* tte) const {
|
|
||||||
|
|
||||||
const_cast<TTEntry*>(tte)->set_generation(generation);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// A simple fixed size hash table used to store pawns and material
|
|
||||||
/// configurations. It is basically just an array of Entry objects.
|
|
||||||
/// Without cluster concept or overwrite policy.
|
|
||||||
|
|
||||||
template<class Entry, int HashSize>
|
|
||||||
struct SimpleHash {
|
|
||||||
|
|
||||||
typedef SimpleHash<Entry, HashSize> Base;
|
|
||||||
|
|
||||||
void init() {
|
|
||||||
|
|
||||||
if (entries)
|
|
||||||
return;
|
|
||||||
|
|
||||||
entries = new (std::nothrow) Entry[HashSize];
|
|
||||||
if (!entries)
|
|
||||||
{
|
|
||||||
std::cerr << "Failed to allocate " << HashSize * sizeof(Entry)
|
|
||||||
<< " bytes for hash table." << std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
memset(entries, 0, HashSize * sizeof(Entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~SimpleHash() { delete [] entries; }
|
|
||||||
|
|
||||||
Entry* probe(Key key) const { return entries + ((uint32_t)key & (HashSize - 1)); }
|
|
||||||
void prefetch(Key key) const { ::prefetch((char*)probe(key)); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Entry* entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // !defined(TT_H_INCLUDED)
|
|
||||||
|
|||||||
+333
-337
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,198 +18,212 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(TYPES_H_INCLUDED)
|
#ifndef TYPES_H_INCLUDED
|
||||||
#define TYPES_H_INCLUDED
|
#define TYPES_H_INCLUDED
|
||||||
|
|
||||||
|
/// When compiling with provided Makefile (e.g. for Linux and OSX), configuration
|
||||||
|
/// is done automatically. To get started type 'make help'.
|
||||||
|
///
|
||||||
|
/// When Makefile is not used (e.g. with Microsoft Visual Studio) some switches
|
||||||
|
/// need to be set manually:
|
||||||
|
///
|
||||||
|
/// -DNDEBUG | Disable debugging mode. Always use this for release.
|
||||||
|
///
|
||||||
|
/// -DNO_PREFETCH | Disable use of prefetch asm-instruction. You may need this to
|
||||||
|
/// | run on some very old machines.
|
||||||
|
///
|
||||||
|
/// -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 <climits>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
// Disable some silly and noisy warning from MSVC compiler
|
// Disable some silly and noisy warning from MSVC compiler
|
||||||
#pragma warning(disable: 4800) // Forcing value to bool 'true' or 'false'
|
|
||||||
#pragma warning(disable: 4127) // Conditional expression is constant
|
#pragma warning(disable: 4127) // Conditional expression is constant
|
||||||
#pragma warning(disable: 4146) // Unary minus operator applied to unsigned type
|
#pragma warning(disable: 4146) // Unary minus operator applied to unsigned type
|
||||||
|
#pragma warning(disable: 4800) // Forcing value to bool 'true' or 'false'
|
||||||
|
#endif
|
||||||
|
|
||||||
// MSVC does not support <inttypes.h>
|
/// Predefined macros hell:
|
||||||
typedef signed __int8 int8_t;
|
///
|
||||||
typedef unsigned __int8 uint8_t;
|
/// __GNUC__ Compiler is gcc, Clang or Intel on Linux
|
||||||
typedef signed __int16 int16_t;
|
/// __INTEL_COMPILER Compiler is Intel
|
||||||
typedef unsigned __int16 uint16_t;
|
/// _MSC_VER Compiler is MSVC or Intel on Windows
|
||||||
typedef signed __int32 int32_t;
|
/// _WIN32 Building on Windows (any)
|
||||||
typedef unsigned __int32 uint32_t;
|
/// _WIN64 Building on Windows 64 bit
|
||||||
typedef signed __int64 int64_t;
|
|
||||||
typedef unsigned __int64 uint64_t;
|
|
||||||
|
|
||||||
|
#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
|
||||||
|
# include <intrin.h> // Microsoft header for _BitScanForward64()
|
||||||
|
# define IS_64BIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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))
|
||||||
|
# include <xmmintrin.h> // Intel and Microsoft header for _mm_prefetch()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USE_PEXT)
|
||||||
|
# include <immintrin.h> // Header for _pext_u64() intrinsic
|
||||||
|
# define pext(b, m) _pext_u64(b, m)
|
||||||
#else
|
#else
|
||||||
|
# define pext(b, m) 0
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define Min(x, y) (((x) < (y)) ? (x) : (y))
|
#ifdef USE_POPCNT
|
||||||
#define Max(x, y) (((x) < (y)) ? (y) : (x))
|
const bool HasPopCnt = true;
|
||||||
|
|
||||||
////
|
|
||||||
//// Configuration
|
|
||||||
////
|
|
||||||
|
|
||||||
//// For Linux and OSX configuration is done automatically using Makefile.
|
|
||||||
//// To get started type "make help".
|
|
||||||
////
|
|
||||||
//// For windows part of the configuration is detected automatically, but
|
|
||||||
//// some switches need to be set manually:
|
|
||||||
////
|
|
||||||
//// -DNDEBUG | Disable debugging mode. Use always.
|
|
||||||
////
|
|
||||||
//// -DNO_PREFETCH | Disable use of prefetch asm-instruction. A must if you want the
|
|
||||||
//// | executable to run on some very old machines.
|
|
||||||
////
|
|
||||||
//// -DUSE_POPCNT | Add runtime support for use of popcnt asm-instruction.
|
|
||||||
//// | Works only in 64-bit mode. For compiling requires hardware
|
|
||||||
//// | with popcnt support. Around 4% speed-up.
|
|
||||||
////
|
|
||||||
//// -DOLD_LOCKS | By default under Windows are used the fast Slim Reader/Writer (SRW)
|
|
||||||
//// | Locks and Condition Variables: these are not supported by Windows XP
|
|
||||||
//// | and older, to compile for those platforms you should enable OLD_LOCKS.
|
|
||||||
|
|
||||||
// Automatic detection for 64-bit under Windows
|
|
||||||
#if defined(_WIN64)
|
|
||||||
#define IS_64BIT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Automatic detection for use of bsfq asm-instruction under Windows
|
|
||||||
#if defined(_WIN64)
|
|
||||||
#define USE_BSFQ
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Intel header for _mm_popcnt_u64() intrinsic
|
|
||||||
#if defined(USE_POPCNT) && defined(_MSC_VER) && defined(__INTEL_COMPILER)
|
|
||||||
#include <nmmintrin.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Cache line alignment specification
|
|
||||||
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
|
||||||
#define CACHE_LINE_ALIGNMENT __declspec(align(64))
|
|
||||||
#else
|
#else
|
||||||
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
|
const bool HasPopCnt = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Define a __cpuid() function for gcc compilers, for Intel and MSVC
|
#ifdef USE_PEXT
|
||||||
// is already available as an intrinsic.
|
const bool HasPext = true;
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#include <intrin.h>
|
|
||||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
|
||||||
inline void __cpuid(int CPUInfo[4], int InfoType)
|
|
||||||
{
|
|
||||||
int* eax = CPUInfo + 0;
|
|
||||||
int* ebx = CPUInfo + 1;
|
|
||||||
int* ecx = CPUInfo + 2;
|
|
||||||
int* edx = CPUInfo + 3;
|
|
||||||
|
|
||||||
*eax = InfoType;
|
|
||||||
*ecx = 0;
|
|
||||||
__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
|
|
||||||
: "0" (*eax), "2" (*ecx));
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
inline void __cpuid(int CPUInfo[4], int)
|
const bool HasPext = false;
|
||||||
{
|
|
||||||
CPUInfo[0] = CPUInfo[1] = CPUInfo[2] = CPUInfo[3] = 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Define FORCE_INLINE macro to force inlining overriding compiler choice
|
#ifdef IS_64BIT
|
||||||
#if defined(_MSC_VER)
|
const bool Is64Bit = true;
|
||||||
#define FORCE_INLINE __forceinline
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#define FORCE_INLINE inline __attribute__((always_inline))
|
|
||||||
#else
|
#else
|
||||||
#define FORCE_INLINE inline
|
const bool Is64Bit = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// cpu_has_popcnt() detects support for popcnt instruction at runtime
|
|
||||||
inline bool cpu_has_popcnt() {
|
|
||||||
|
|
||||||
int CPUInfo[4] = {-1};
|
|
||||||
__cpuid(CPUInfo, 0x00000001);
|
|
||||||
return (CPUInfo[2] >> 23) & 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// CpuHasPOPCNT is a global constant initialized at startup that
|
|
||||||
/// is set to true if CPU on which application runs supports popcnt
|
|
||||||
/// hardware instruction. Unless USE_POPCNT is not defined.
|
|
||||||
#if defined(USE_POPCNT)
|
|
||||||
const bool CpuHasPOPCNT = cpu_has_popcnt();
|
|
||||||
#else
|
|
||||||
const bool CpuHasPOPCNT = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/// CpuIs64Bit is a global constant initialized at compile time that
|
|
||||||
/// is set to true if CPU on which application runs is a 64 bits.
|
|
||||||
#if defined(IS_64BIT)
|
|
||||||
const bool CpuIs64Bit = true;
|
|
||||||
#else
|
|
||||||
const bool CpuIs64Bit = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
typedef uint64_t Key;
|
typedef uint64_t Key;
|
||||||
typedef uint64_t Bitboard;
|
typedef uint64_t Bitboard;
|
||||||
|
|
||||||
const int PLY_MAX = 100;
|
const int MAX_MOVES = 256;
|
||||||
const int PLY_MAX_PLUS_2 = PLY_MAX + 2;
|
const int MAX_PLY = 128;
|
||||||
|
|
||||||
enum ValueType {
|
/// A move needs 16 bits to be stored
|
||||||
VALUE_TYPE_NONE = 0,
|
///
|
||||||
VALUE_TYPE_UPPER = 1,
|
/// bit 0- 5: destination square (from 0 to 63)
|
||||||
VALUE_TYPE_LOWER = 2,
|
/// bit 6-11: origin square (from 0 to 63)
|
||||||
VALUE_TYPE_EXACT = VALUE_TYPE_UPPER | VALUE_TYPE_LOWER
|
/// bit 12-13: promotion piece type - 2 (from KNIGHT-2 to QUEEN-2)
|
||||||
|
/// bit 14-15: special move flag: promotion (1), en passant (2), castling (3)
|
||||||
|
/// NOTE: EN-PASSANT bit is set only when a pawn can be captured
|
||||||
|
///
|
||||||
|
/// Special cases are MOVE_NONE and MOVE_NULL. We can sneak these in because in
|
||||||
|
/// 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 : int {
|
||||||
|
MOVE_NONE,
|
||||||
|
MOVE_NULL = 65
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Value {
|
enum MoveType {
|
||||||
VALUE_ZERO = 0,
|
NORMAL,
|
||||||
VALUE_DRAW = 0,
|
PROMOTION = 1 << 14,
|
||||||
VALUE_KNOWN_WIN = 15000,
|
ENPASSANT = 2 << 14,
|
||||||
VALUE_MATE = 30000,
|
CASTLING = 3 << 14
|
||||||
VALUE_INFINITE = 30001,
|
|
||||||
VALUE_NONE = 30002,
|
|
||||||
|
|
||||||
VALUE_MATE_IN_PLY_MAX = VALUE_MATE - PLY_MAX,
|
|
||||||
VALUE_MATED_IN_PLY_MAX = -VALUE_MATE + PLY_MAX,
|
|
||||||
|
|
||||||
VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX,
|
|
||||||
VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN
|
|
||||||
};
|
|
||||||
|
|
||||||
enum PieceType {
|
|
||||||
PIECE_TYPE_NONE = 0,
|
|
||||||
PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Piece {
|
|
||||||
PIECE_NONE_DARK_SQ = 0, WP = 1, WN = 2, WB = 3, WR = 4, WQ = 5, WK = 6,
|
|
||||||
BP = 9, BN = 10, BB = 11, BR = 12, BQ = 13, BK = 14, PIECE_NONE = 16
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Color {
|
enum Color {
|
||||||
WHITE, BLACK, COLOR_NONE
|
WHITE, BLACK, COLOR_NB = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Depth {
|
enum CastlingSide {
|
||||||
|
KING_SIDE, QUEEN_SIDE, CASTLING_SIDE_NB = 2
|
||||||
ONE_PLY = 2,
|
|
||||||
|
|
||||||
DEPTH_ZERO = 0 * ONE_PLY,
|
|
||||||
DEPTH_QS_CHECKS = -1 * ONE_PLY,
|
|
||||||
DEPTH_QS_NO_CHECKS = -2 * ONE_PLY,
|
|
||||||
|
|
||||||
DEPTH_NONE = -127 * ONE_PLY
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Square {
|
enum CastlingRight {
|
||||||
|
NO_CASTLING,
|
||||||
|
WHITE_OO,
|
||||||
|
WHITE_OOO = WHITE_OO << 1,
|
||||||
|
BLACK_OO = WHITE_OO << 2,
|
||||||
|
BLACK_OOO = WHITE_OO << 3,
|
||||||
|
ANY_CASTLING = WHITE_OO | WHITE_OOO | BLACK_OO | BLACK_OOO,
|
||||||
|
CASTLING_RIGHT_NB = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
template<Color C, CastlingSide S> struct MakeCastling {
|
||||||
|
static constexpr 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,
|
||||||
|
MG = 0, EG = 1, PHASE_NB = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ScaleFactor {
|
||||||
|
SCALE_FACTOR_DRAW = 0,
|
||||||
|
SCALE_FACTOR_ONEPAWN = 48,
|
||||||
|
SCALE_FACTOR_NORMAL = 64,
|
||||||
|
SCALE_FACTOR_MAX = 128,
|
||||||
|
SCALE_FACTOR_NONE = 255
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Bound {
|
||||||
|
BOUND_NONE,
|
||||||
|
BOUND_UPPER,
|
||||||
|
BOUND_LOWER,
|
||||||
|
BOUND_EXACT = BOUND_UPPER | BOUND_LOWER
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Value : int {
|
||||||
|
VALUE_ZERO = 0,
|
||||||
|
VALUE_DRAW = 0,
|
||||||
|
VALUE_KNOWN_WIN = 10000,
|
||||||
|
VALUE_MATE = 32000,
|
||||||
|
VALUE_INFINITE = 32001,
|
||||||
|
VALUE_NONE = 32002,
|
||||||
|
|
||||||
|
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
||||||
|
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
||||||
|
|
||||||
|
PawnValueMg = 171, PawnValueEg = 240,
|
||||||
|
KnightValueMg = 764, KnightValueEg = 848,
|
||||||
|
BishopValueMg = 826, BishopValueEg = 891,
|
||||||
|
RookValueMg = 1282, RookValueEg = 1373,
|
||||||
|
QueenValueMg = 2526, QueenValueEg = 2646,
|
||||||
|
|
||||||
|
MidgameLimit = 15258, EndgameLimit = 3915
|
||||||
|
};
|
||||||
|
|
||||||
|
enum PieceType {
|
||||||
|
NO_PIECE_TYPE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING,
|
||||||
|
ALL_PIECES = 0,
|
||||||
|
QUEEN_DIAGONAL = 7,
|
||||||
|
PIECE_TYPE_NB = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Piece {
|
||||||
|
NO_PIECE,
|
||||||
|
W_PAWN = 1, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
||||||
|
B_PAWN = 9, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING,
|
||||||
|
PIECE_NB = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
||||||
|
|
||||||
|
enum Depth : int {
|
||||||
|
|
||||||
|
ONE_PLY = 1,
|
||||||
|
|
||||||
|
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 * ONE_PLY,
|
||||||
|
DEPTH_MAX = MAX_PLY * ONE_PLY
|
||||||
|
};
|
||||||
|
|
||||||
|
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_A1, SQ_B1, SQ_C1, SQ_D1, SQ_E1, SQ_F1, SQ_G1, SQ_H1,
|
||||||
SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2,
|
SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2,
|
||||||
SQ_A3, SQ_B3, SQ_C3, SQ_D3, SQ_E3, SQ_F3, SQ_G3, SQ_H3,
|
SQ_A3, SQ_B3, SQ_C3, SQ_D3, SQ_E3, SQ_F3, SQ_G3, SQ_H3,
|
||||||
@@ -219,252 +234,233 @@ enum Square {
|
|||||||
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
||||||
SQ_NONE,
|
SQ_NONE,
|
||||||
|
|
||||||
DELTA_N = 8,
|
SQUARE_NB = 64
|
||||||
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
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum File {
|
enum Direction : int {
|
||||||
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H
|
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 Rank {
|
enum File : int {
|
||||||
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8
|
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SquareColor {
|
enum Rank : int {
|
||||||
DARK, LIGHT
|
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
|
||||||
};
|
|
||||||
|
|
||||||
enum ScaleFactor {
|
|
||||||
SCALE_FACTOR_ZERO = 0,
|
|
||||||
SCALE_FACTOR_NORMAL = 64,
|
|
||||||
SCALE_FACTOR_MAX = 128,
|
|
||||||
SCALE_FACTOR_NONE = 255
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Score enum keeps a midgame and an endgame value in a single
|
/// Score enum stores a middlegame and an endgame value in a single integer
|
||||||
/// integer (enum), first LSB 16 bits are used to store endgame
|
/// (enum). The least significant 16 bits are used to store the endgame value
|
||||||
/// value, while upper bits are used for midgame value. Compiler
|
/// and the upper 16 bits are used to store the middlegame value. Take some
|
||||||
/// is free to choose the enum type as long as can keep its data,
|
/// care to avoid left-shifting a signed int to avoid undefined behavior.
|
||||||
/// so ensure Score to be an integer type.
|
enum Score : int { SCORE_ZERO };
|
||||||
enum Score {
|
|
||||||
SCORE_ZERO = 0,
|
|
||||||
SCORE_ENSURE_INTEGER_SIZE_P = INT_MAX,
|
|
||||||
SCORE_ENSURE_INTEGER_SIZE_N = INT_MIN
|
|
||||||
};
|
|
||||||
|
|
||||||
#define ENABLE_OPERATORS_ON(T) \
|
constexpr Score make_score(int mg, int eg) {
|
||||||
inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); } \
|
return Score((int)((unsigned int)eg << 16) + mg);
|
||||||
inline T operator- (const T d1, const T d2) { return T(int(d1) - int(d2)); } \
|
}
|
||||||
inline T operator* (int i, const T d) { return T(i * int(d)); } \
|
|
||||||
inline T operator* (const T d, int i) { return T(int(d) * i); } \
|
|
||||||
inline T operator/ (const T d, int i) { return T(int(d) / i); } \
|
|
||||||
inline T operator- (const T d) { return T(-int(d)); } \
|
|
||||||
inline T operator++ (T& d, int) {d = T(int(d) + 1); return d; } \
|
|
||||||
inline T operator-- (T& d, int) { d = T(int(d) - 1); return d; } \
|
|
||||||
inline void operator+= (T& d1, const T d2) { d1 = d1 + d2; } \
|
|
||||||
inline void operator-= (T& d1, const T d2) { d1 = d1 - d2; } \
|
|
||||||
inline void operator*= (T& d, int i) { d = T(int(d) * i); } \
|
|
||||||
inline void operator/= (T& d, int i) { d = T(int(d) / i); }
|
|
||||||
|
|
||||||
ENABLE_OPERATORS_ON(Value)
|
/// Extracting the signed lower and upper 16 bits is not so trivial because
|
||||||
ENABLE_OPERATORS_ON(PieceType)
|
/// according to the standard a simple cast to short is implementation defined
|
||||||
ENABLE_OPERATORS_ON(Piece)
|
/// and so is a right shift of a signed integer.
|
||||||
ENABLE_OPERATORS_ON(Color)
|
inline Value eg_value(Score s) {
|
||||||
ENABLE_OPERATORS_ON(Depth)
|
union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s + 0x8000) >> 16) };
|
||||||
ENABLE_OPERATORS_ON(Square)
|
return Value(eg.s);
|
||||||
ENABLE_OPERATORS_ON(File)
|
}
|
||||||
ENABLE_OPERATORS_ON(Rank)
|
|
||||||
|
|
||||||
#undef ENABLE_OPERATORS_ON
|
inline Value mg_value(Score s) {
|
||||||
|
union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s)) };
|
||||||
|
return Value(mg.s);
|
||||||
|
}
|
||||||
|
|
||||||
// Extra operators for adding integers to a Value
|
#define ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
inline Value operator+ (Value v, int i) { return Value(int(v) + i); }
|
constexpr T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
|
||||||
inline Value operator- (Value v, int i) { return Value(int(v) - i); }
|
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; }
|
||||||
|
|
||||||
// Extracting the _signed_ lower and upper 16 bits it not so trivial
|
#define ENABLE_INCR_OPERATORS_ON(T) \
|
||||||
// because according to the standard a simple cast to short is
|
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
||||||
// implementation defined and so is a right shift of a signed integer.
|
inline T& operator--(T& d) { return d = T(int(d) - 1); }
|
||||||
inline Value mg_value(Score s) { return Value(((int(s) + 32768) & ~0xffff) / 0x10000); }
|
|
||||||
|
|
||||||
// Unfortunatly on Intel 64 bit we have a small speed regression, so use a faster code in
|
#define ENABLE_FULL_OPERATORS_ON(T) \
|
||||||
// this case, although not 100% standard compliant it seems to work for Intel and MSVC.
|
ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
#if defined(IS_64BIT) && (!defined(__GNUC__) || defined(__INTEL_COMPILER))
|
ENABLE_INCR_OPERATORS_ON(T) \
|
||||||
inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); }
|
constexpr T operator*(int i, T d) { return T(i * int(d)); } \
|
||||||
#else
|
constexpr T operator*(T d, int i) { return T(int(d) * i); } \
|
||||||
inline Value eg_value(Score s) { return Value((int)(unsigned(s) & 0x7fffu) - (int)(unsigned(s) & 0x8000u)); }
|
constexpr T operator/(T d, int i) { return T(int(d) / i); } \
|
||||||
#endif
|
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); }
|
||||||
|
|
||||||
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
|
ENABLE_FULL_OPERATORS_ON(Value)
|
||||||
|
ENABLE_FULL_OPERATORS_ON(Depth)
|
||||||
|
ENABLE_FULL_OPERATORS_ON(Direction)
|
||||||
|
|
||||||
// Division must be handled separately for each term
|
ENABLE_INCR_OPERATORS_ON(PieceType)
|
||||||
inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); }
|
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)
|
||||||
|
|
||||||
// Only declared but not defined. We don't want to multiply two scores due to
|
ENABLE_BASE_OPERATORS_ON(Score)
|
||||||
// a very high risk of overflow. So user should explicitly convert to integer.
|
|
||||||
inline Score operator*(Score s1, Score s2);
|
|
||||||
|
|
||||||
// Remaining Score operators are standard
|
#undef ENABLE_FULL_OPERATORS_ON
|
||||||
inline Score operator+ (const Score d1, const Score d2) { return Score(int(d1) + int(d2)); }
|
#undef ENABLE_INCR_OPERATORS_ON
|
||||||
inline Score operator- (const Score d1, const Score d2) { return Score(int(d1) - int(d2)); }
|
#undef ENABLE_BASE_OPERATORS_ON
|
||||||
inline Score operator* (int i, const Score d) { return Score(i * int(d)); }
|
|
||||||
inline Score operator* (const Score d, int i) { return Score(int(d) * i); }
|
|
||||||
inline Score operator- (const Score d) { return Score(-int(d)); }
|
|
||||||
inline void operator+= (Score& d1, const Score d2) { d1 = d1 + d2; }
|
|
||||||
inline void operator-= (Score& d1, const Score d2) { d1 = d1 - d2; }
|
|
||||||
inline void operator*= (Score& d, int i) { d = Score(int(d) * i); }
|
|
||||||
inline void operator/= (Score& d, int i) { d = Score(int(d) / i); }
|
|
||||||
|
|
||||||
const Value PawnValueMidgame = Value(0x0C6);
|
/// Additional operators to add integers to a Value
|
||||||
const Value PawnValueEndgame = Value(0x102);
|
constexpr Value operator+(Value v, int i) { return Value(int(v) + i); }
|
||||||
const Value KnightValueMidgame = Value(0x331);
|
constexpr Value operator-(Value v, int i) { return Value(int(v) - i); }
|
||||||
const Value KnightValueEndgame = Value(0x34E);
|
inline Value& operator+=(Value& v, int i) { return v = v + i; }
|
||||||
const Value BishopValueMidgame = Value(0x344);
|
inline Value& operator-=(Value& v, int i) { return v = v - i; }
|
||||||
const Value BishopValueEndgame = Value(0x359);
|
|
||||||
const Value RookValueMidgame = Value(0x4F6);
|
|
||||||
const Value RookValueEndgame = Value(0x4FE);
|
|
||||||
const Value QueenValueMidgame = Value(0x9D9);
|
|
||||||
const Value QueenValueEndgame = Value(0x9FE);
|
|
||||||
|
|
||||||
inline Value value_mate_in(int ply) {
|
/// Additional operators to add a Direction to a Square
|
||||||
|
inline Square operator+(Square s, Direction d) { return Square(int(s) + int(d)); }
|
||||||
|
inline Square operator-(Square s, Direction d) { return Square(int(s) - int(d)); }
|
||||||
|
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.
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Multiplication of a Score by an integer. We check for overflow in debug mode.
|
||||||
|
inline Score operator*(Score s, int i) {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Value mate_in(int ply) {
|
||||||
return VALUE_MATE - ply;
|
return VALUE_MATE - ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value value_mated_in(int ply) {
|
constexpr Value mated_in(int ply) {
|
||||||
return -VALUE_MATE + ply;
|
return -VALUE_MATE + ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Piece make_piece(Color c, PieceType pt) {
|
constexpr Square make_square(File f, Rank r) {
|
||||||
return Piece((int(c) << 3) | int(pt));
|
return Square((r << 3) + f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType type_of_piece(Piece p) {
|
constexpr Piece make_piece(Color c, PieceType pt) {
|
||||||
return PieceType(int(p) & 7);
|
return Piece((c << 3) + pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color color_of_piece(Piece p) {
|
constexpr PieceType type_of(Piece pc) {
|
||||||
return Color(int(p) >> 3);
|
return PieceType(pc & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color opposite_color(Color c) {
|
inline Color color_of(Piece pc) {
|
||||||
return Color(int(c) ^ 1);
|
assert(pc != NO_PIECE);
|
||||||
|
return Color(pc >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool color_is_ok(Color c) {
|
constexpr bool is_ok(Square s) {
|
||||||
return c == WHITE || c == BLACK;
|
return s >= SQ_A1 && s <= SQ_H8;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool piece_type_is_ok(PieceType pt) {
|
constexpr File file_of(Square s) {
|
||||||
return pt >= PAWN && pt <= KING;
|
return File(s & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool piece_is_ok(Piece p) {
|
constexpr Rank rank_of(Square s) {
|
||||||
return piece_type_is_ok(type_of_piece(p)) && color_is_ok(color_of_piece(p));
|
return Rank(s >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char piece_type_to_char(PieceType pt) {
|
constexpr Square relative_square(Color c, Square s) {
|
||||||
static const char ch[] = " PNBRQK";
|
return Square(s ^ (c * 56));
|
||||||
return ch[pt];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square make_square(File f, Rank r) {
|
constexpr Rank relative_rank(Color c, Rank r) {
|
||||||
return Square((int(r) << 3) | int(f));
|
return Rank(r ^ (c * 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline File square_file(Square s) {
|
constexpr Rank relative_rank(Color c, Square s) {
|
||||||
return File(int(s) & 7);
|
return relative_rank(c, rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank square_rank(Square s) {
|
inline bool opposite_colors(Square s1, Square s2) {
|
||||||
return Rank(int(s) >> 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square flip_square(Square s) {
|
|
||||||
return Square(int(s) ^ 56);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square flop_square(Square s) {
|
|
||||||
return Square(int(s) ^ 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square relative_square(Color c, Square s) {
|
|
||||||
return Square(int(s) ^ (int(c) * 56));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Rank relative_rank(Color c, Rank r) {
|
|
||||||
return Rank(int(r) ^ (int(c) * 7));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Rank relative_rank(Color c, Square s) {
|
|
||||||
return relative_rank(c, square_rank(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SquareColor square_color(Square s) {
|
|
||||||
return SquareColor(int(square_rank(s) + s) & 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool opposite_color_squares(Square s1, Square s2) {
|
|
||||||
int s = int(s1) ^ int(s2);
|
int s = int(s1) ^ int(s2);
|
||||||
return ((s >> 3) ^ s) & 1;
|
return ((s >> 3) ^ s) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int file_distance(Square s1, Square s2) {
|
constexpr Direction pawn_push(Color c) {
|
||||||
return abs(square_file(s1) - square_file(s2));
|
return c == WHITE ? NORTH : SOUTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int rank_distance(Square s1, Square s2) {
|
constexpr Square from_sq(Move m) {
|
||||||
return abs(square_rank(s1) - square_rank(s2));
|
return Square((m >> 6) & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int square_distance(Square s1, Square s2) {
|
constexpr Square to_sq(Move m) {
|
||||||
return Max(file_distance(s1, s2), rank_distance(s1, s2));
|
return Square(m & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline File file_from_char(char c) {
|
constexpr int from_to(Move m) {
|
||||||
return File(c - 'a') + FILE_A;
|
return m & 0xFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char file_to_char(File f) {
|
constexpr MoveType type_of(Move m) {
|
||||||
return char(f - FILE_A + int('a'));
|
return MoveType(m & (3 << 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank rank_from_char(char c) {
|
constexpr PieceType promotion_type(Move m) {
|
||||||
return Rank(c - '1') + RANK_1;
|
return PieceType(((m >> 12) & 3) + KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char rank_to_char(Rank r) {
|
inline Move make_move(Square from, Square to) {
|
||||||
return char(r - RANK_1 + int('1'));
|
return Move((from << 6) + to);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string square_to_string(Square s) {
|
template<MoveType T>
|
||||||
char ch[] = { file_to_char(square_file(s)), rank_to_char(square_rank(s)), 0 };
|
constexpr Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
||||||
return std::string(ch);
|
return Move(T + ((pt - KNIGHT) << 12) + (from << 6) + to);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool file_is_ok(File f) {
|
constexpr bool is_ok(Move m) {
|
||||||
return f >= FILE_A && f <= FILE_H;
|
return from_sq(m) != to_sq(m); // Catch MOVE_NULL and MOVE_NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool rank_is_ok(Rank r) {
|
#endif // #ifndef TYPES_H_INCLUDED
|
||||||
return r >= RANK_1 && r <= RANK_8;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool square_is_ok(Square s) {
|
|
||||||
return s >= SQ_A1 && s <= SQ_H8;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square pawn_push(Color c) {
|
|
||||||
return c == WHITE ? DELTA_N : DELTA_S;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(TYPES_H_INCLUDED)
|
|
||||||
|
|||||||
+268
-199
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,225 +24,293 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "evaluate.h"
|
#include "evaluate.h"
|
||||||
#include "misc.h"
|
#include "movegen.h"
|
||||||
#include "move.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "ucioption.h"
|
#include "thread.h"
|
||||||
|
#include "tt.h"
|
||||||
|
#include "timeman.h"
|
||||||
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace {
|
extern vector<string> setup_bench(const Position&, istream&);
|
||||||
|
|
||||||
// FEN string for the initial position
|
|
||||||
const string StartPositionFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
|
||||||
|
|
||||||
// UCIParser is a class for parsing UCI input. The class
|
|
||||||
// is actually a string stream built on a given input string.
|
|
||||||
typedef istringstream UCIParser;
|
|
||||||
|
|
||||||
void set_option(UCIParser& up);
|
|
||||||
void set_position(Position& pos, UCIParser& up);
|
|
||||||
bool go(Position& pos, UCIParser& up);
|
|
||||||
void perft(Position& pos, UCIParser& up);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// execute_uci_command() takes a string as input, uses a UCIParser
|
|
||||||
/// object to parse this text string as a UCI command, and calls
|
|
||||||
/// the appropriate functions. In addition to the UCI commands,
|
|
||||||
/// the function also supports a few debug commands.
|
|
||||||
|
|
||||||
bool execute_uci_command(const string& cmd) {
|
|
||||||
|
|
||||||
static Position pos(StartPositionFEN, false, 0); // The root position
|
|
||||||
|
|
||||||
UCIParser up(cmd);
|
|
||||||
string token;
|
|
||||||
|
|
||||||
up >> token; // operator>>() skips any whitespace
|
|
||||||
|
|
||||||
if (token == "quit")
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (token == "go")
|
|
||||||
return go(pos, up);
|
|
||||||
|
|
||||||
if (token == "ucinewgame")
|
|
||||||
pos.from_fen(StartPositionFEN, false);
|
|
||||||
|
|
||||||
else if (token == "isready")
|
|
||||||
cout << "readyok" << endl;
|
|
||||||
|
|
||||||
else if (token == "position")
|
|
||||||
set_position(pos, up);
|
|
||||||
|
|
||||||
else if (token == "setoption")
|
|
||||||
set_option(up);
|
|
||||||
|
|
||||||
else if (token == "perft")
|
|
||||||
perft(pos, up);
|
|
||||||
|
|
||||||
else if (token == "d")
|
|
||||||
pos.print();
|
|
||||||
|
|
||||||
else if (token == "flip")
|
|
||||||
pos.flip();
|
|
||||||
|
|
||||||
else if (token == "eval")
|
|
||||||
{
|
|
||||||
read_evaluation_uci_options(pos.side_to_move());
|
|
||||||
cout << trace_evaluate(pos) << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (token == "key")
|
|
||||||
cout << "key: " << hex << pos.get_key()
|
|
||||||
<< "\nmaterial key: " << pos.get_material_key()
|
|
||||||
<< "\npawn key: " << pos.get_pawn_key() << endl;
|
|
||||||
|
|
||||||
else if (token == "uci")
|
|
||||||
cout << "id name " << engine_name()
|
|
||||||
<< "\nid author " << engine_authors()
|
|
||||||
<< "\n" << Options.print_all()
|
|
||||||
<< "\nuciok" << endl;
|
|
||||||
else
|
|
||||||
cout << "Unknown command: " << cmd << endl;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// set_position() is called when engine receives the "position" UCI
|
// FEN string of the initial position, normal chess
|
||||||
// command. The function sets up the position described in the given
|
const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
// fen string ("fen") or the starting position ("startpos") and then
|
|
||||||
// makes the moves given in the following move list ("moves").
|
|
||||||
|
|
||||||
void set_position(Position& pos, UCIParser& up) {
|
|
||||||
|
|
||||||
|
// 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, StateListPtr& states) {
|
||||||
|
|
||||||
|
Move m;
|
||||||
string token, fen;
|
string token, fen;
|
||||||
|
|
||||||
up >> token; // operator>>() skips any whitespace
|
is >> token;
|
||||||
|
|
||||||
if (token == "startpos")
|
if (token == "startpos")
|
||||||
{
|
{
|
||||||
pos.from_fen(StartPositionFEN, false);
|
fen = StartFEN;
|
||||||
up >> token; // Consume "moves" token if any
|
is >> token; // Consume "moves" token if any
|
||||||
}
|
}
|
||||||
else if (token == "fen")
|
else if (token == "fen")
|
||||||
{
|
while (is >> token && token != "moves")
|
||||||
while (up >> token && token != "moves")
|
|
||||||
fen += token + " ";
|
fen += token + " ";
|
||||||
|
|
||||||
pos.from_fen(fen, Options["UCI_Chess960"].value<bool>());
|
|
||||||
}
|
|
||||||
else return;
|
|
||||||
|
|
||||||
// Parse move list (if any)
|
|
||||||
while (up >> token)
|
|
||||||
pos.do_setup_move(move_from_uci(pos, token));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// set_option() is called when engine receives the "setoption" UCI
|
|
||||||
// command. The function updates the corresponding UCI option ("name")
|
|
||||||
// to the given value ("value").
|
|
||||||
|
|
||||||
void set_option(UCIParser& up) {
|
|
||||||
|
|
||||||
string token, name;
|
|
||||||
string value = "true"; // UCI buttons don't have a "value" field
|
|
||||||
|
|
||||||
up >> token; // Consume "name" token
|
|
||||||
up >> name; // Read option name
|
|
||||||
|
|
||||||
// Handle names with included spaces
|
|
||||||
while (up >> token && token != "value")
|
|
||||||
name += " " + token;
|
|
||||||
|
|
||||||
up >> value; // Read option value
|
|
||||||
|
|
||||||
// Handle values with included spaces
|
|
||||||
while (up >> token)
|
|
||||||
value += " " + token;
|
|
||||||
|
|
||||||
if (Options.find(name) != Options.end())
|
|
||||||
Options[name].set_value(value);
|
|
||||||
else
|
else
|
||||||
cout << "No such option: " << name << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// go() is called when engine receives the "go" UCI command. The
|
|
||||||
// function sets the thinking time and other parameters from the input
|
|
||||||
// string, and then calls think(). Returns false if a quit command
|
|
||||||
// is received while thinking, true otherwise.
|
|
||||||
|
|
||||||
bool go(Position& pos, UCIParser& up) {
|
|
||||||
|
|
||||||
string token;
|
|
||||||
SearchLimits limits;
|
|
||||||
Move searchMoves[MAX_MOVES], *cur = searchMoves;
|
|
||||||
int time[] = { 0, 0 }, inc[] = { 0, 0 };
|
|
||||||
|
|
||||||
while (up >> token)
|
|
||||||
{
|
|
||||||
if (token == "infinite")
|
|
||||||
limits.infinite = true;
|
|
||||||
else if (token == "ponder")
|
|
||||||
limits.ponder = true;
|
|
||||||
else if (token == "wtime")
|
|
||||||
up >> time[WHITE];
|
|
||||||
else if (token == "btime")
|
|
||||||
up >> time[BLACK];
|
|
||||||
else if (token == "winc")
|
|
||||||
up >> inc[WHITE];
|
|
||||||
else if (token == "binc")
|
|
||||||
up >> inc[BLACK];
|
|
||||||
else if (token == "movestogo")
|
|
||||||
up >> limits.movesToGo;
|
|
||||||
else if (token == "depth")
|
|
||||||
up >> limits.maxDepth;
|
|
||||||
else if (token == "nodes")
|
|
||||||
up >> limits.maxNodes;
|
|
||||||
else if (token == "movetime")
|
|
||||||
up >> limits.maxTime;
|
|
||||||
else if (token == "searchmoves")
|
|
||||||
while (up >> token)
|
|
||||||
*cur++ = move_from_uci(pos, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
*cur = MOVE_NONE;
|
|
||||||
limits.time = time[pos.side_to_move()];
|
|
||||||
limits.increment = inc[pos.side_to_move()];
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
|
||||||
|
|
||||||
return think(pos, limits, searchMoves);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// perft() is called when engine receives the "perft" command.
|
|
||||||
// The function calls perft() passing the required search depth
|
|
||||||
// then prints counted leaf nodes and elapsed time.
|
|
||||||
|
|
||||||
void perft(Position& pos, UCIParser& up) {
|
|
||||||
|
|
||||||
int depth, time;
|
|
||||||
int64_t n;
|
|
||||||
|
|
||||||
if (!(up >> depth))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
time = get_system_time();
|
states = StateListPtr(new std::deque<StateInfo>(1)); // Drop old and create a new one
|
||||||
|
pos.set(fen, Options["UCI_Chess960"], &states->back(), Threads.main());
|
||||||
|
|
||||||
n = perft(pos, depth * ONE_PLY);
|
// Parse move list (if any)
|
||||||
|
while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE)
|
||||||
time = get_system_time() - time;
|
{
|
||||||
|
states->emplace_back();
|
||||||
std::cout << "\nNodes " << n
|
pos.do_move(m, states->back());
|
||||||
<< "\nTime (ms) " << time
|
}
|
||||||
<< "\nNodes/second " << int(n / (time / 1000.0)) << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// setoption() is called when engine receives the "setoption" UCI command. The
|
||||||
|
// function updates the UCI option ("name") to the given value ("value").
|
||||||
|
|
||||||
|
void setoption(istringstream& is) {
|
||||||
|
|
||||||
|
string token, name, value;
|
||||||
|
|
||||||
|
is >> token; // Consume "name" token
|
||||||
|
|
||||||
|
// Read option name (can contain spaces)
|
||||||
|
while (is >> token && token != "value")
|
||||||
|
name += string(" ", name.empty() ? 0 : 1) + token;
|
||||||
|
|
||||||
|
// Read option value (can contain spaces)
|
||||||
|
while (is >> token)
|
||||||
|
value += string(" ", value.empty() ? 0 : 1) + token;
|
||||||
|
|
||||||
|
if (Options.count(name))
|
||||||
|
Options[name] = value;
|
||||||
|
else
|
||||||
|
sync_cout << "No such option: " << name << sync_endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// go() is called when engine receives the "go" UCI command. The function sets
|
||||||
|
// the thinking time and other parameters from the input string, then starts
|
||||||
|
// the search.
|
||||||
|
|
||||||
|
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")
|
||||||
|
while (is >> token)
|
||||||
|
limits.searchmoves.push_back(UCI::to_move(pos, token));
|
||||||
|
|
||||||
|
else if (token == "wtime") is >> limits.time[WHITE];
|
||||||
|
else if (token == "btime") is >> limits.time[BLACK];
|
||||||
|
else if (token == "winc") is >> limits.inc[WHITE];
|
||||||
|
else if (token == "binc") is >> limits.inc[BLACK];
|
||||||
|
else if (token == "movestogo") is >> limits.movestogo;
|
||||||
|
else if (token == "depth") is >> limits.depth;
|
||||||
|
else if (token == "nodes") is >> limits.nodes;
|
||||||
|
else if (token == "movetime") is >> limits.movetime;
|
||||||
|
else if (token == "mate") is >> limits.mate;
|
||||||
|
else if (token == "perft") is >> limits.perft;
|
||||||
|
else if (token == "infinite") limits.infinite = 1;
|
||||||
|
else if (token == "ponder") ponderMode = true;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
/// UCI::loop() waits for a command from stdin, parses it and calls the appropriate
|
||||||
|
/// function. Also intercepts EOF from stdin to ensure gracefully exiting if the
|
||||||
|
/// GUI dies unexpectedly. When called with some command line arguments, e.g. to
|
||||||
|
/// run 'bench', once the command is executed the function returns immediately.
|
||||||
|
/// In addition to the UCI ones, also some additional debug commands are supported.
|
||||||
|
|
||||||
|
void UCI::loop(int argc, char* argv[]) {
|
||||||
|
|
||||||
|
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]) + " ";
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (argc == 1 && !getline(cin, cmd)) // Block here waiting for input or EOF
|
||||||
|
cmd = "quit";
|
||||||
|
|
||||||
|
istringstream is(cmd);
|
||||||
|
|
||||||
|
token.clear(); // Avoid a stale if getline() returns empty or blank line
|
||||||
|
is >> skipws >> token;
|
||||||
|
|
||||||
|
// 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" && Threads.stopOnPonderhit))
|
||||||
|
Threads.stop = true;
|
||||||
|
|
||||||
|
else if (token == "ponderhit")
|
||||||
|
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 == "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, 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); // Command line args are one-shot
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// UCI::value() converts a Value to a string suitable for use with the UCI
|
||||||
|
/// protocol specification:
|
||||||
|
///
|
||||||
|
/// cp <x> The score from the engine's point of view in centipawns.
|
||||||
|
/// mate <y> Mate in y moves, not plies. If the engine is getting mated
|
||||||
|
/// use negative values for y.
|
||||||
|
|
||||||
|
string UCI::value(Value v) {
|
||||||
|
|
||||||
|
assert(-VALUE_INFINITE < v && v < VALUE_INFINITE);
|
||||||
|
|
||||||
|
stringstream ss;
|
||||||
|
|
||||||
|
if (abs(v) < VALUE_MATE - MAX_PLY)
|
||||||
|
ss << "cp " << v * 100 / PawnValueEg;
|
||||||
|
else
|
||||||
|
ss << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2;
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// UCI::square() converts a Square to a string in algebraic notation (g1, a7, etc.)
|
||||||
|
|
||||||
|
std::string UCI::square(Square s) {
|
||||||
|
return std::string{ char('a' + file_of(s)), char('1' + rank_of(s)) };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// UCI::move() converts a Move to a string in coordinate notation (g1f3, a7a8q).
|
||||||
|
/// The only special case is castling, where we print in the e1g1 notation in
|
||||||
|
/// normal chess mode, and in e1h1 notation in chess960 mode. Internally all
|
||||||
|
/// castling moves are always encoded as 'king captures rook'.
|
||||||
|
|
||||||
|
string UCI::move(Move m, bool chess960) {
|
||||||
|
|
||||||
|
Square from = from_sq(m);
|
||||||
|
Square to = to_sq(m);
|
||||||
|
|
||||||
|
if (m == MOVE_NONE)
|
||||||
|
return "(none)";
|
||||||
|
|
||||||
|
if (m == MOVE_NULL)
|
||||||
|
return "0000";
|
||||||
|
|
||||||
|
if (type_of(m) == CASTLING && !chess960)
|
||||||
|
to = make_square(to > from ? FILE_G : FILE_C, rank_of(from));
|
||||||
|
|
||||||
|
string move = UCI::square(from) + UCI::square(to);
|
||||||
|
|
||||||
|
if (type_of(m) == PROMOTION)
|
||||||
|
move += " pnbrqk"[promotion_type(m)];
|
||||||
|
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// UCI::to_move() converts a string representing a move in coordinate notation
|
||||||
|
/// (g1f3, a7a8q) to the corresponding legal Move, if any.
|
||||||
|
|
||||||
|
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 (const auto& m : MoveList<LEGAL>(pos))
|
||||||
|
if (str == UCI::move(m, pos.is_chess960()))
|
||||||
|
return m;
|
||||||
|
|
||||||
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UCI_H_INCLUDED
|
||||||
|
#define UCI_H_INCLUDED
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
class Position;
|
||||||
|
|
||||||
|
namespace UCI {
|
||||||
|
|
||||||
|
class Option;
|
||||||
|
|
||||||
|
/// Custom comparator because UCI options should be case insensitive
|
||||||
|
struct CaseInsensitiveLess {
|
||||||
|
bool operator() (const std::string&, const std::string&) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Our options container is actually a std::map
|
||||||
|
typedef std::map<std::string, Option, CaseInsensitiveLess> OptionsMap;
|
||||||
|
|
||||||
|
/// Option class implements an option as defined by UCI protocol
|
||||||
|
class Option {
|
||||||
|
|
||||||
|
typedef void (*OnChange)(const Option&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
Option(OnChange = nullptr);
|
||||||
|
Option(bool v, OnChange = nullptr);
|
||||||
|
Option(const char* v, OnChange = nullptr);
|
||||||
|
Option(int v, int minv, int maxv, OnChange = nullptr);
|
||||||
|
|
||||||
|
Option& operator=(const std::string&);
|
||||||
|
void operator<<(const Option&);
|
||||||
|
operator int() const;
|
||||||
|
operator std::string() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
|
||||||
|
|
||||||
|
std::string defaultValue, currentValue, type;
|
||||||
|
int min, max;
|
||||||
|
size_t idx;
|
||||||
|
OnChange on_change;
|
||||||
|
};
|
||||||
|
|
||||||
|
void init(OptionsMap&);
|
||||||
|
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 UCI_H_INCLUDED
|
||||||
+102
-108
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,154 +18,147 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cctype>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <cassert>
|
||||||
#include <sstream>
|
#include <ostream>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "ucioption.h"
|
#include "tt.h"
|
||||||
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
OptionsMap Options; // Global object
|
UCI::OptionsMap Options; // Global object
|
||||||
|
|
||||||
|
namespace UCI {
|
||||||
|
|
||||||
|
/// 'On change' actions, triggered by an option's value change
|
||||||
|
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& o) { Threads.set(o); }
|
||||||
|
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
||||||
|
|
||||||
|
|
||||||
// Our case insensitive less() function as required by UCI protocol
|
/// Our case insensitive less() function as required by UCI protocol
|
||||||
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
|
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
|
||||||
|
|
||||||
int c1, c2;
|
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
|
||||||
size_t i = 0;
|
[](char c1, char c2) { return tolower(c1) < tolower(c2); });
|
||||||
|
|
||||||
while (i < s1.size() && i < s2.size())
|
|
||||||
{
|
|
||||||
c1 = tolower(s1[i]);
|
|
||||||
c2 = tolower(s2[i++]);
|
|
||||||
|
|
||||||
if (c1 != c2)
|
|
||||||
return c1 < c2;
|
|
||||||
}
|
|
||||||
return s1.size() < s2.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// stringify() converts a numeric value of type T to a std::string
|
/// init() initializes the UCI options to their hard-coded default values
|
||||||
template<typename T>
|
|
||||||
static string stringify(const T& v) {
|
|
||||||
|
|
||||||
std::ostringstream ss;
|
void init(OptionsMap& o) {
|
||||||
ss << v;
|
|
||||||
return ss.str();
|
// at most 2^32 clusters.
|
||||||
|
const int MaxHashMB = Is64Bit ? 131072 : 2048;
|
||||||
|
|
||||||
|
o["Debug Log File"] << Option("", on_logger);
|
||||||
|
o["Contempt"] << Option(20, -100, 100);
|
||||||
|
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(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(89, 10, 1000);
|
||||||
|
o["nodestime"] << Option(0, 0, 10000);
|
||||||
|
o["UCI_Chess960"] << 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// OptionsMap c'tor initializes the UCI options to their hard coded default
|
/// operator<<() is used to print all the options default values in chronological
|
||||||
/// values and initializes the default value of "Threads" and "Minimum Split Depth"
|
|
||||||
/// parameters according to the number of CPU cores.
|
|
||||||
|
|
||||||
OptionsMap::OptionsMap() {
|
|
||||||
|
|
||||||
OptionsMap& o = *this;
|
|
||||||
|
|
||||||
o["Use Search Log"] = UCIOption(false);
|
|
||||||
o["Search Log Filename"] = UCIOption("SearchLog.txt");
|
|
||||||
o["Book File"] = UCIOption("book.bin");
|
|
||||||
o["Best Book Move"] = UCIOption(false);
|
|
||||||
o["Mobility (Middle Game)"] = UCIOption(100, 0, 200);
|
|
||||||
o["Mobility (Endgame)"] = UCIOption(100, 0, 200);
|
|
||||||
o["Passed Pawns (Middle Game)"] = UCIOption(100, 0, 200);
|
|
||||||
o["Passed Pawns (Endgame)"] = UCIOption(100, 0, 200);
|
|
||||||
o["Space"] = UCIOption(100, 0, 200);
|
|
||||||
o["Aggressiveness"] = UCIOption(100, 0, 200);
|
|
||||||
o["Cowardice"] = UCIOption(100, 0, 200);
|
|
||||||
o["Minimum Split Depth"] = UCIOption(4, 4, 7);
|
|
||||||
o["Maximum Number of Threads per Split Point"] = UCIOption(5, 4, 8);
|
|
||||||
o["Threads"] = UCIOption(1, 1, MAX_THREADS);
|
|
||||||
o["Use Sleeping Threads"] = UCIOption(false);
|
|
||||||
o["Hash"] = UCIOption(32, 4, 8192);
|
|
||||||
o["Clear Hash"] = UCIOption(false, "button");
|
|
||||||
o["Ponder"] = UCIOption(true);
|
|
||||||
o["OwnBook"] = UCIOption(true);
|
|
||||||
o["MultiPV"] = UCIOption(1, 1, 500);
|
|
||||||
o["Skill Level"] = UCIOption(20, 0, 20);
|
|
||||||
o["Emergency Move Horizon"] = UCIOption(40, 0, 50);
|
|
||||||
o["Emergency Base Time"] = UCIOption(200, 0, 30000);
|
|
||||||
o["Emergency Move Time"] = UCIOption(70, 0, 5000);
|
|
||||||
o["Minimum Thinking Time"] = UCIOption(20, 0, 5000);
|
|
||||||
o["UCI_Chess960"] = UCIOption(false);
|
|
||||||
o["UCI_AnalyseMode"] = UCIOption(false);
|
|
||||||
|
|
||||||
// Set some SMP parameters accordingly to the detected CPU count
|
|
||||||
UCIOption& thr = o["Threads"];
|
|
||||||
UCIOption& msd = o["Minimum Split Depth"];
|
|
||||||
|
|
||||||
thr.defaultValue = thr.currentValue = stringify(cpu_count());
|
|
||||||
|
|
||||||
if (cpu_count() >= 8)
|
|
||||||
msd.defaultValue = msd.currentValue = stringify(7);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// OptionsMap::print_all() returns a string with all the UCI options in chronological
|
|
||||||
/// insertion order (the idx field) and in the format defined by the UCI protocol.
|
/// insertion order (the idx field) and in the format defined by the UCI protocol.
|
||||||
|
|
||||||
string OptionsMap::print_all() const {
|
std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
|
||||||
|
|
||||||
std::stringstream s;
|
for (size_t idx = 0; idx < om.size(); ++idx)
|
||||||
|
for (const auto& it : om)
|
||||||
for (size_t i = 0; i <= size(); i++)
|
if (it.second.idx == idx)
|
||||||
for (OptionsMap::const_iterator it = begin(); it != end(); ++it)
|
|
||||||
if (it->second.idx == i)
|
|
||||||
{
|
{
|
||||||
const UCIOption& o = it->second;
|
const Option& o = it.second;
|
||||||
s << "\noption name " << it->first << " type " << o.type;
|
os << "\noption name " << it.first << " type " << o.type;
|
||||||
|
|
||||||
if (o.type != "button")
|
if (o.type != "button")
|
||||||
s << " default " << o.defaultValue;
|
os << " default " << o.defaultValue;
|
||||||
|
|
||||||
if (o.type == "spin")
|
if (o.type == "spin")
|
||||||
s << " min " << o.minValue << " max " << o.maxValue;
|
os << " min " << o.min << " max " << o.max;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return s.str();
|
|
||||||
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Option class c'tors
|
/// Option class constructors and conversion operators
|
||||||
|
|
||||||
UCIOption::UCIOption(const char* def) : type("string"), minValue(0), maxValue(0), idx(Options.size())
|
Option::Option(const char* v, OnChange f) : type("string"), min(0), max(0), on_change(f)
|
||||||
{ defaultValue = currentValue = def; }
|
{ defaultValue = currentValue = v; }
|
||||||
|
|
||||||
UCIOption::UCIOption(bool def, string t) : type(t), minValue(0), maxValue(0), idx(Options.size())
|
Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f)
|
||||||
{ defaultValue = currentValue = (def ? "true" : "false"); }
|
{ defaultValue = currentValue = (v ? "true" : "false"); }
|
||||||
|
|
||||||
UCIOption::UCIOption(int def, int minv, int maxv) : type("spin"), minValue(minv), maxValue(maxv), idx(Options.size())
|
Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
|
||||||
{ defaultValue = currentValue = stringify(def); }
|
{}
|
||||||
|
|
||||||
|
Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
|
||||||
|
{ defaultValue = currentValue = std::to_string(v); }
|
||||||
|
|
||||||
|
Option::operator int() const {
|
||||||
|
assert(type == "check" || type == "spin");
|
||||||
|
return (type == "spin" ? stoi(currentValue) : currentValue == "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
Option::operator std::string() const {
|
||||||
|
assert(type == "string");
|
||||||
|
return currentValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// set_value() updates currentValue of the Option object. Normally it's up to
|
/// operator<<() inits options and assigns idx in the correct printing order
|
||||||
/// the GUI to check for option's limits, but we could receive the new value
|
|
||||||
/// directly from the user by teminal window. So let's check the bounds anyway.
|
|
||||||
|
|
||||||
void UCIOption::set_value(const string& v) {
|
void Option::operator<<(const Option& o) {
|
||||||
|
|
||||||
|
static size_t insert_order = 0;
|
||||||
|
|
||||||
|
*this = o;
|
||||||
|
idx = insert_order++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// operator=() updates currentValue and triggers on_change() action. It's up to
|
||||||
|
/// the GUI to check for option's limits, but we could receive the new value from
|
||||||
|
/// the user by console window, so let's check the bounds anyway.
|
||||||
|
|
||||||
|
Option& Option::operator=(const string& v) {
|
||||||
|
|
||||||
assert(!type.empty());
|
assert(!type.empty());
|
||||||
|
|
||||||
if (v.empty())
|
if ( (type != "button" && v.empty())
|
||||||
return;
|
|| (type == "check" && v != "true" && v != "false")
|
||||||
|
|| (type == "spin" && (stoi(v) < min || stoi(v) > max)))
|
||||||
|
return *this;
|
||||||
|
|
||||||
if ((type == "check" || type == "button") != (v == "true" || v == "false"))
|
if (type != "button")
|
||||||
return;
|
currentValue = v;
|
||||||
|
|
||||||
if (type == "spin")
|
if (on_change)
|
||||||
{
|
on_change(*this);
|
||||||
int val = atoi(v.c_str());
|
|
||||||
if (val < minValue || val > maxValue)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentValue = v;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace UCI
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(UCIOPTION_H_INCLUDED)
|
|
||||||
#define UCIOPTION_H_INCLUDED
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class UCIOption {
|
|
||||||
public:
|
|
||||||
UCIOption() {} // To be used in a std::map
|
|
||||||
UCIOption(const char* defaultValue);
|
|
||||||
UCIOption(bool defaultValue, std::string type = "check");
|
|
||||||
UCIOption(int defaultValue, int minValue, int maxValue);
|
|
||||||
|
|
||||||
void set_value(const std::string& v);
|
|
||||||
template<typename T> T value() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class OptionsMap;
|
|
||||||
|
|
||||||
std::string defaultValue, currentValue, type;
|
|
||||||
int minValue, maxValue;
|
|
||||||
size_t idx;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Custom comparator because UCI options should not be case sensitive
|
|
||||||
struct CaseInsensitiveLess {
|
|
||||||
bool operator() (const std::string&, const std::string&) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Our options container is actually a map with a customized c'tor
|
|
||||||
class OptionsMap : public std::map<std::string, UCIOption, CaseInsensitiveLess> {
|
|
||||||
public:
|
|
||||||
OptionsMap();
|
|
||||||
std::string print_all() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern OptionsMap Options;
|
|
||||||
|
|
||||||
|
|
||||||
/// Option::value() definition and specializations
|
|
||||||
template<typename T>
|
|
||||||
T UCIOption::value() const {
|
|
||||||
|
|
||||||
assert(type == "spin");
|
|
||||||
return T(atoi(currentValue.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline std::string UCIOption::value<std::string>() const {
|
|
||||||
|
|
||||||
assert(type == "string");
|
|
||||||
return currentValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline bool UCIOption::value<bool>() const {
|
|
||||||
|
|
||||||
assert(type == "check" || type == "button");
|
|
||||||
return currentValue == "true";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(UCIOPTION_H_INCLUDED)
|
|
||||||
Executable
+123
@@ -0,0 +1,123 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
for exps in game.exp
|
||||||
|
do
|
||||||
|
|
||||||
|
echo "$prefix expect $exps $postfix"
|
||||||
|
eval "$prefix expect $exps $postfix"
|
||||||
|
|
||||||
|
rm $exps
|
||||||
|
|
||||||
|
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
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/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
|
||||||
|
echo "signature mismatch: reference $1 obtained $signature"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "signature OK: $signature"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# just report signature
|
||||||
|
echo $signature
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user