mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 16:47:37 +00:00
Compare commits
1043 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c3483fa9a7 | |||
| 446a3c2522 | |||
| baf184e8d9 | |||
| 7150183d07 | |||
| 4901218d4c | |||
| 01dfdb95dc | |||
| 69204f0720 | |||
| 9f800a2577 | |||
| 114ddb789b | |||
| 7f623206f4 | |||
| 384bff4264 | |||
| bae019b53e | |||
| 09bef14c76 | |||
| 44f79bdf5a | |||
| de4e1cb88d | |||
| 56d5504f65 | |||
| 83ecfa7c33 | |||
| 44f56e04e2 | |||
| 13f70d0392 | |||
| b6482472a0 | |||
| 443787b0d1 | |||
| 3ef0c3c34a | |||
| 764b9adda6 | |||
| d00b2ec6bd | |||
| 78eeba29a2 | |||
| a6b5ba1b64 | |||
| 20484ccdd5 | |||
| 0256416bb7 | |||
| 6a6fc28551 | |||
| 97a0e4e817 | |||
| f0047ce08e | |||
| 54253bcce6 | |||
| df340a839c | |||
| 53125902e4 | |||
| 87ed9facf1 | |||
| 1fdf1f1ff5 | |||
| 3f4191392c | |||
| 37698b0396 | |||
| e0f42aa956 | |||
| fe124896b2 | |||
| 3468138210 | |||
| a00a336946 | |||
| a131975170 | |||
| 9ab2590963 | |||
| 44b6697f19 | |||
| 9b8b259388 | |||
| 5ae195ee7e | |||
| 9f312c80d9 | |||
| 3804effb34 | |||
| ef38046e73 | |||
| cff9a8672c | |||
| 474d133565 | |||
| e8fca71342 | |||
| 6f3796adaf | |||
| 1725ed39ad | |||
| 648c7ec25d | |||
| 90c0385724 | |||
| 7e89a71624 | |||
| 215cd19108 | |||
| 12d58adc68 | |||
| 472de897cb | |||
| b8e5092d07 | |||
| 80d59eea39 | |||
| 23a022980b | |||
| 0150da5c2b | |||
| 0b0b21c608 | |||
| 7264540107 | |||
| c78f8ddd86 | |||
| 2e96c513ad | |||
| ca7d4e9ac7 | |||
| 328bdd0947 | |||
| 5d1568632c | |||
| e6f4b5f463 | |||
| 005ad170c1 | |||
| abd4400c87 | |||
| 70a38d7264 | |||
| 3a3ca6af03 | |||
| 28dcd700a9 | |||
| d703d2b5e7 | |||
| 8726beba59 | |||
| 0436f01d05 | |||
| 667d24f227 | |||
| d232a4ae68 | |||
| defa1ccaa9 | |||
| 302e0f70c6 | |||
| 7756344d5d | |||
| 770c8d92f3 | |||
| 7e4c3256aa | |||
| 64af5434ed | |||
| a858defd33 | |||
| 7b06475294 | |||
| 843a6c4305 | |||
| e5cfa14f40 | |||
| a83d1a0e80 | |||
| 8a04b3a13c | |||
| db00e1625e | |||
| 8aecf26981 | |||
| 36e4a86c08 | |||
| 270b241ec1 | |||
| 61f44ce578 | |||
| 8fec883471 | |||
| 0e295fee25 | |||
| d799529b48 | |||
| 3984b8f8f0 | |||
| a016626825 | |||
| 10d2ebc6ae | |||
| 18279b24fc | |||
| d4dca9187e | |||
| 7efc39d683 | |||
| 66a3c2968b | |||
| fcee0ce6a3 | |||
| 8152a74ab4 | |||
| d980d7c0d4 | |||
| 9d3a2ecaa2 | |||
| aec918a2b6 | |||
| acdda38b93 | |||
| 33c3a04653 | |||
| dc243a3c88 | |||
| 9dc57b660e | |||
| fd96cba676 | |||
| 19509e5f13 | |||
| 3ec362e4b2 | |||
| 7090d2561a | |||
| 0dbc72d82e | |||
| 650aeaf242 | |||
| 13ba67801f | |||
| 0a8a3b8d9c | |||
| a0360cc2d4 | |||
| ff69d570d7 | |||
| 389e60741f | |||
| 82d66f6b72 | |||
| 4ae5a7b45a | |||
| c83cbe42f3 | |||
| 5a7827d59d | |||
| 93349d0dbd | |||
| fa1a2a0667 | |||
| ca51d1ee63 | |||
| 217840a6a5 | |||
| 79d06d8840 | |||
| c9d73d1aa5 | |||
| d889bb4718 | |||
| dab66631e8 | |||
| 8b4521df83 | |||
| a8de07cc26 | |||
| 4c986b0501 | |||
| 7cb8817ef2 | |||
| 37ffacf209 | |||
| 8bf21a723e | |||
| 297c40291a | |||
| 59f1d0c7dd | |||
| 466daf6fba | |||
| 46ce245763 | |||
| 8cfe27b765 | |||
| f9518de974 | |||
| a9cca5c953 | |||
| d39bc2efa1 | |||
| 2ead74d1e2 | |||
| 53d197b841 | |||
| 14e23d520f | |||
| 5935daf8a5 | |||
| 6ed81f09ff | |||
| 2d06d659c0 | |||
| 09caea5cab | |||
| 434b2c72a4 | |||
| 3edf0e6b37 | |||
| c645587270 | |||
| 190f38a7c2 | |||
| bf6b647a1a | |||
| 2985a6b5d7 | |||
| 272936eaba | |||
| 3d076a0c50 | |||
| 3a572ffb48 | |||
| 02708a4a11 | |||
| 4a7b8180ec | |||
| 44c320a572 | |||
| 4fcd78bd06 | |||
| 2d9fac1e13 | |||
| 66820a2668 | |||
| 9c7dc057d1 | |||
| a8abba0b4d | |||
| 5f4d44fda0 | |||
| 893a08a8c2 | |||
| 7df832fea6 | |||
| 8a0af1004a | |||
| ad8b78ad52 | |||
| 368f976fb6 | |||
| b6d11028bb | |||
| aba906b734 | |||
| 4e72e2a964 | |||
| 5c4002aa82 | |||
| 7ede1ed071 | |||
| e4c1f8759d | |||
| 9a11a29194 | |||
| e89bc30fdc | |||
| 6373fd56e9 | |||
| a858b5a84e | |||
| bdeb01dec0 | |||
| f21b503982 | |||
| c4fc00ec49 | |||
| 3b46df546d | |||
| 76777b663a | |||
| eb07775583 | |||
| 1594d15922 | |||
| 42d271f23c | |||
| a2cdb6e5d2 | |||
| 5928cb2b30 | |||
| 5b5687d76e | |||
| ec49e676a7 | |||
| ab4b94e173 | |||
| f98c77413b | |||
| 8fa6273ff6 | |||
| 49a1fdd3fe | |||
| fdd799bc16 | |||
| 1982fe25f8 | |||
| 0f63b35120 | |||
| aa0166fba6 | |||
| 82ad9ce9cf | |||
| 95ba7f78d5 | |||
| 76f1807baa | |||
| c858990377 | |||
| d1f76ebcd8 | |||
| 796d0ad70e | |||
| 7133598a98 | |||
| 2f11c03bbf | |||
| ea5505821d | |||
| d320de7619 | |||
| 66818f2e85 | |||
| bad18bccb6 | |||
| b8efa0daac | |||
| acc47e8b79 | |||
| 4d0981fef3 | |||
| 1aab5b4b05 | |||
| 714e857c24 | |||
| 58bbbd176b | |||
| 2bceba7f51 | |||
| c2fb0ff720 | |||
| 82ff04b992 | |||
| 7c5f5fbada | |||
| badb2aca44 | |||
| e51244cb27 | |||
| 22ef36803e | |||
| 76d2f5b94a | |||
| 3c92f849ab | |||
| 05f7d59a9a | |||
| 332b90455b | |||
| dd4796fcd5 | |||
| 6514500236 | |||
| 9050eac595 | |||
| ff97a9fdb9 | |||
| 3f7ec977cd | |||
| d1fd1a96bc | |||
| 3302349662 | |||
| 242c566c1a | |||
| 8df1cd10df | |||
| 2d0af36753 | |||
| 58d3ee6175 | |||
| 59b2486bc3 | |||
| 691a287bfe | |||
| 3acacf8471 | |||
| 3300517ecb | |||
| 3732c55c18 | |||
| 230fb6e9ad | |||
| 5446e6f408 | |||
| d07e782e22 | |||
| d2acdac101 | |||
| 70880b8e24 | |||
| f69106f7bb | |||
| bb843a00c1 | |||
| 3c576efa77 | |||
| eb6d7f537d | |||
| 79c97625a4 | |||
| 7accf07c0b | |||
| e2d3c163cb | |||
| 800031c94c | |||
| 69dc5568b3 | |||
| 14c4a40dc7 | |||
| 0194da0d80 | |||
| ade87ff8d3 | |||
| 96ac85b319 | |||
| 2089c414da | |||
| 656aad8b0c | |||
| ae5d2c38e1 | |||
| 59d32f8edd | |||
| b54bcfddaa | |||
| 0f2df4e4af | |||
| 67ae53b020 | |||
| 7240a90bf9 | |||
| 64a6138d37 | |||
| 4e2bb8fa44 | |||
| fda0161e3a | |||
| 4f3804f3f3 | |||
| 31ac538f96 | |||
| 883367d217 | |||
| e917bd59b1 | |||
| e8ffca3eb4 | |||
| 4e2e4759a1 | |||
| a8e903c33a | |||
| 090e49547e | |||
| fefc0c6789 | |||
| 5c2fbcd09b | |||
| 7b4f9c37cb | |||
| b19ad4977c | |||
| 33d9548218 | |||
| 9dc6d270fc | |||
| 982fd9c8bc | |||
| 79e3710fd2 | |||
| 9b276a6596 | |||
| b4c239b625 | |||
| 622360ad66 | |||
| 340e9ea509 | |||
| 7b6fa353a3 | |||
| de7182f4ee | |||
| 6ab92d2e1c | |||
| bb58bc215c | |||
| 6e66e7aae2 | |||
| 4b88bea4fc | |||
| 3925750945 | |||
| cf5d683408 | |||
| 3f2ec5b3d5 | |||
| b92206305f | |||
| d2274e609c | |||
| 4111f36f45 | |||
| 0e508f30bb | |||
| 4350a66ffa | |||
| 8a9c298dee | |||
| 2a7213f720 | |||
| b9f1c9bf3f | |||
| 3cbb05b1b8 | |||
| 68209c9121 | |||
| 30a905c95d | |||
| 05aa34e00e | |||
| cd732c080b | |||
| df50ea5dc6 | |||
| 9315ba60e6 | |||
| a6fe035977 | |||
| 8bb7a73708 | |||
| 3f1eb85a1c | |||
| 4a0db9ea3c | |||
| 7a61368971 | |||
| 081af90805 | |||
| bc3b148d57 | |||
| 9fff272209 | |||
| 542a2b39ed | |||
| 738a6dfd4c | |||
| 97d2cc9a9c | |||
| cb0111d3db | |||
| 0370077c37 | |||
| d615f15fce | |||
| 489357d7b2 | |||
| 8141bdd179 | |||
| bbf9daa175 | |||
| 13d06edb84 | |||
| 49b1591505 | |||
| 33b2f6398c | |||
| 0fa957cf66 | |||
| 4bef7aa5cd | |||
| 767c4ad1fc | |||
| 2bfaf45455 | |||
| f923dc0fe5 | |||
| e846a9306d | |||
| 10bb2e6cdb | |||
| 166bf90e41 | |||
| 4aa091cf44 | |||
| 8a4821923a | |||
| 6307fd08e6 | |||
| 3ac3b68540 | |||
| 28543cddc6 | |||
| f3b8a69919 | |||
| 96c3a1f2ec | |||
| d0f09de2d2 | |||
| 881cab2525 | |||
| 4d22d3e52d | |||
| 41cc4eb953 | |||
| b5581b7779 | |||
| 348cd5ed74 | |||
| f1088c9822 | |||
| 198418ee67 | |||
| bd4d2b0576 | |||
| c569cf263d | |||
| d96c1c32a2 | |||
| 571f54b176 | |||
| fae57273b2 | |||
| 9afa03b80e | |||
| ba2a2c34bb | |||
| c08e05b494 | |||
| 6184d2b2ac | |||
| 9ca014df49 | |||
| e12fc10b5c | |||
| 313f403733 | |||
| c9f80660a6 | |||
| d44701be4b | |||
| 2660a9145e | |||
| a4eda3056e | |||
| ae98927885 | |||
| c4c2e08f0d | |||
| 6e36860554 | |||
| bb56779cb6 | |||
| 38471697b7 | |||
| 50287a55d3 | |||
| 0d5fe2f156 | |||
| af1ddfd83b | |||
| 4bd24da161 | |||
| 53c07c34bb | |||
| 0365b08601 | |||
| 41bc0d5660 | |||
| 12e79be910 | |||
| 3913726d1c | |||
| 2ac35027d5 | |||
| a05793517f | |||
| ee0f5cd303 | |||
| e0f317afaa | |||
| a6fa6a9e92 | |||
| d2d4e85f25 | |||
| d2752fdc15 | |||
| 0f48095759 | |||
| 3279655f12 | |||
| e7cfa5d020 | |||
| 8c4f0ffa1d | |||
| a781535168 | |||
| af6072c8b7 | |||
| 1e9397a2df | |||
| f0a7bed6fb | |||
| efd4ca27c4 | |||
| 34321fcc2d | |||
| 062eb074c8 | |||
| 06a853eb9c | |||
| 745160572f | |||
| 9d219c07e4 | |||
| a834bfe833 | |||
| 6c36e65193 | |||
| fc3af7c4fb | |||
| 88de112b84 | |||
| 86e467520f | |||
| 2af2c67650 | |||
| 528507b303 | |||
| 231103d2cf | |||
| e4f8a4fa7f | |||
| 9597ad8cab | |||
| b939788f9d | |||
| 6b5d671cdc | |||
| f7bae2de82 | |||
| 8ef9bc5a95 | |||
| c5d6ae8c96 | |||
| a0486ecb40 | |||
| 6cc5614124 | |||
| 31b8243272 | |||
| 626d43a329 | |||
| 3d6995eae8 | |||
| d5d23bfd2d | |||
| beaadd6547 | |||
| d702203113 | |||
| 04407e35d6 | |||
| 335dc2d021 | |||
| fd4585ef07 | |||
| e8005ebe56 | |||
| 91a76331ca | |||
| aacee91a5a | |||
| bf01bd0755 | |||
| c163c2fcb0 | |||
| 255df4ffae | |||
| 76d4a80084 | |||
| fc0a1f37cf | |||
| 4d647428d8 | |||
| de0889612f | |||
| 6634f41ac9 | |||
| 8d1625d6df | |||
| 155d5417d9 | |||
| cb4bda0f49 | |||
| d4cb80b210 | |||
| 06e0134cbc | |||
| 12ef8f71a2 | |||
| 5a7cdadfb3 | |||
| 213166ba22 | |||
| d6252ef202 | |||
| 3df8cabb84 | |||
| 11967e89cd | |||
| 45072612d4 | |||
| c794c8c801 | |||
| aef7076c34 | |||
| a64d524d02 | |||
| 82f7d507ea | |||
| f7cc0026e3 | |||
| 73e8daa150 | |||
| 66af80972a | |||
| 0143c6f0c2 | |||
| 108f0da4d7 | |||
| e9aeaad052 | |||
| ae0bb6dc2b | |||
| 6413d9b1f9 | |||
| 62619fa228 | |||
| b88374b14a | |||
| 759d129e47 | |||
| 04a228f9c8 | |||
| 06a8fd2154 | |||
| 0cfb653eec | |||
| e408fd7b10 | |||
| 76f9cd4df1 | |||
| d9cac9a414 | |||
| f2681232e5 | |||
| d5e3e7d207 | |||
| c8ef80f466 | |||
| c959871a59 | |||
| 9953bfff62 | |||
| 5ce630584c | |||
| 29070bd01a | |||
| 367304e930 | |||
| 8ff2fcf299 | |||
| 280022baf7 | |||
| a03e98dcd3 | |||
| f0f6da2d30 | |||
| 62937d1007 | |||
| d40e7ee209 | |||
| ed26d71354 | |||
| bd59560480 | |||
| 1940485030 | |||
| 759b3c79cf | |||
| 350dff4464 | |||
| 96362fe3df | |||
| 8ab12c9012 | |||
| 8db75dd9ec | |||
| edf4c07d25 | |||
| b605103a34 | |||
| c5f6bd517c | |||
| b2961aded6 | |||
| efe702e9f5 | |||
| 840605c14e | |||
| 6e9337b107 | |||
| c3af52c43b | |||
| 5dc381a566 | |||
| 2c5dfb3122 | |||
| 1093047e7d | |||
| 82697f1193 | |||
| 65c3bb8586 | |||
| 6d8f583af2 | |||
| 56a104e2e0 | |||
| d42e6338ea | |||
| 43682d08f7 | |||
| 3192b09fe0 | |||
| 450f04969c | |||
| cad300cfab | |||
| b87308692a | |||
| f35e52f030 | |||
| 94b3cdd908 | |||
| 94abc2a0cf | |||
| 59d10374ca | |||
| ad5d86c771 | |||
| de642f16db | |||
| cccbecb6f8 | |||
| 1463881153 | |||
| 29bc128384 | |||
| ad2a0e356e | |||
| d438720a1c | |||
| 71cc01c2ef | |||
| 7a03450bd9 | |||
| ebb3e7df65 | |||
| 2ec36f8ae8 | |||
| 2e21aba8d9 | |||
| 8dd6875240 | |||
| 16b31bb249 | |||
| 5d57bb467a | |||
| 9246e4a6f9 | |||
| a09eee5798 | |||
| 52f92d05a9 | |||
| 820c5c25b6 | |||
| 6c898a10be | |||
| 67f5f54a29 | |||
| b2b0013d11 | |||
| 80ea80e451 | |||
| 860223c5e6 | |||
| 4c57cf0ead | |||
| baab8be324 | |||
| cb1324312d | |||
| d71adc5bd9 | |||
| 211ebc5c7a | |||
| 917fe69f84 | |||
| 69067e1988 | |||
| 312a248fa9 | |||
| ef61886332 | |||
| 414a3e6ee3 | |||
| e316e432d0 | |||
| d93baae220 | |||
| 44a7db0f9a | |||
| 83c828f31e | |||
| 0f6f42cd83 | |||
| 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 |
+36
-12
@@ -1,4 +1,5 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
|
dist: xenial
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
@@ -7,31 +8,32 @@ matrix:
|
|||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
packages: ['g++-4.8']
|
packages: ['g++-8', 'g++-8-multilib', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
||||||
env:
|
env:
|
||||||
- COMPILER=g++-4.8
|
- COMPILER=g++-8
|
||||||
- COMP=gcc
|
- COMP=gcc
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
|
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-6.0']
|
||||||
packages: ['clang-3.7']
|
packages: ['clang-6.0', 'llvm-6.0-dev', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
||||||
env:
|
env:
|
||||||
- COMPILER=clang++-3.7
|
- COMPILER=clang++-6.0
|
||||||
- COMP=clang
|
- COMP=clang
|
||||||
|
- LDFLAGS=-fuse-ld=lld
|
||||||
|
|
||||||
- os: osx
|
- os: osx
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
env:
|
env:
|
||||||
- COMPILER=g++-4.8
|
- COMPILER=g++
|
||||||
- COMP=gcc
|
- COMP=gcc
|
||||||
|
|
||||||
- os: osx
|
- os: osx
|
||||||
compiler: clang
|
compiler: clang
|
||||||
env:
|
env:
|
||||||
- COMPILER=clang++ V='Apple LLVM 6.0' # Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
|
- COMPILER=clang++ V='Apple LLVM 9.4.1' # Apple LLVM version 9.1.0 (clang-902.0.39.2)
|
||||||
- COMP=clang
|
- COMP=clang
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
@@ -42,8 +44,30 @@ before_script:
|
|||||||
- cd src
|
- cd src
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- make clean && make build ARCH=x86-64 && ./stockfish bench 2>&1 >/dev/null | grep 'Nodes searched' | tee bench1
|
# Obtain bench reference from git log
|
||||||
- make clean && make build ARCH=x86-32 && ./stockfish bench 2>&1 >/dev/null | grep 'Nodes searched' | tee bench2
|
- git log HEAD | grep "\b[Bb]ench[ :]\+[0-9]\{7\}" | head -n 1 | sed "s/[^0-9]*\([0-9]*\).*/\1/g" > git_sig
|
||||||
- echo "Checking for same bench numbers..."
|
- export benchref=$(cat git_sig)
|
||||||
- diff bench1 bench2 > result
|
- echo "Reference bench:" $benchref
|
||||||
- test ! -s result
|
#
|
||||||
|
# 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
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check perft and reproducible search
|
||||||
|
- ../tests/perft.sh
|
||||||
|
- ../tests/reprosearch.sh
|
||||||
|
#
|
||||||
|
# Valgrind
|
||||||
|
#
|
||||||
|
- export CXXFLAGS="-O1 -fno-inline"
|
||||||
|
- if [ -x "$(command -v valgrind )" ]; then make clean && make -j2 ARCH=x86-64 debug=yes optimize=no build > /dev/null && ../tests/instrumented.sh --valgrind; fi
|
||||||
|
- if [ -x "$(command -v valgrind )" ]; then ../tests/instrumented.sh --valgrind-thread; fi
|
||||||
|
#
|
||||||
|
# Sanitizer
|
||||||
|
#
|
||||||
|
# Use g++-8 as a proxy for having sanitizers, might need revision as they become available for more recent versions of clang/gcc
|
||||||
|
- if [[ "$COMPILER" == "g++-8" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-undefined; fi
|
||||||
|
- if [[ "$COMPILER" == "g++-8" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi
|
||||||
|
|||||||
@@ -1,98 +1,163 @@
|
|||||||
# Generated with git shortlog -sn | cut -c8-', which sorts by commits (manually ordered the first four authors)
|
# List of authors for Stockfish, as of January 7, 2020
|
||||||
|
|
||||||
Tord Romstad
|
Tord Romstad (romstad)
|
||||||
Marco Costalba
|
Marco Costalba (mcostalba)
|
||||||
Joona Kiiski
|
Joona Kiiski (zamar)
|
||||||
Gary Linscott
|
Gary Linscott (glinscott)
|
||||||
lucasart
|
|
||||||
mstembera
|
Aditya (absimaldata)
|
||||||
Lucas Braesch
|
Adrian Petrescu (apetresc)
|
||||||
Stefan Geschwentner
|
Ajith Chandy Jose (ajithcj)
|
||||||
Reuven Peleg
|
Alain Savard (Rocky640)
|
||||||
Chris Caino
|
Alayan Feh (Alayan-stk-2)
|
||||||
joergoster
|
|
||||||
VoyagerOne
|
|
||||||
Jean-Francois Romang
|
|
||||||
homoSapiensSapiens
|
|
||||||
Alain SAVARD
|
|
||||||
Arjun Temurnikar
|
|
||||||
Stéphane Nicolet
|
|
||||||
Uri Blass
|
|
||||||
jundery
|
|
||||||
Ralph Stößer
|
|
||||||
Ajith
|
|
||||||
Leonid Pechenik
|
|
||||||
Stefano80
|
|
||||||
Tom Vijlbrief
|
|
||||||
hxim
|
|
||||||
snicolet
|
|
||||||
Daylen Yang
|
|
||||||
Henri Wiechers
|
|
||||||
Jonathan Calovski
|
|
||||||
mbootsector
|
|
||||||
David Zar
|
|
||||||
Eelco de Groot
|
|
||||||
Jerry Donald
|
|
||||||
Joerg Oster
|
|
||||||
Jörg Oster
|
|
||||||
Ryan Schmitt
|
|
||||||
mcostalba
|
|
||||||
Alexander Kure
|
Alexander Kure
|
||||||
Dan Schmidt
|
Alexander Pagel (Lolligerhans)
|
||||||
H. Felix Wittmann
|
Ali AlZhrani (Cooffe)
|
||||||
Joseph R. Prostko
|
Andrew Grant (AndyGrant)
|
||||||
Justin Blanchard
|
Andrey Neporada (nepal)
|
||||||
Linus Arver
|
|
||||||
NicklasPersson
|
|
||||||
Rodrigo Exterckötter Tjäder
|
|
||||||
Ron Britvich
|
|
||||||
Ronald de Man
|
|
||||||
RyanTaker
|
|
||||||
Vince Negri
|
|
||||||
ceebo
|
|
||||||
jhellis3
|
|
||||||
ppigazzini
|
|
||||||
shane31
|
|
||||||
Andy Duplain
|
Andy Duplain
|
||||||
|
Aram Tumanian (atumanian)
|
||||||
|
Arjun Temurnikar
|
||||||
Auguste Pop
|
Auguste Pop
|
||||||
Balint Pfliegel
|
Balint Pfliegel
|
||||||
Chris Cain
|
Ben Koshy (BKSpurgeon)
|
||||||
DU-jdto
|
Bill Henry (VoyagerOne)
|
||||||
|
Bojun Guo (noobpwnftw, Nooby)
|
||||||
|
braich
|
||||||
|
Brian Sheppard (SapphireBrand, briansheppard-toast)
|
||||||
|
Bryan Cross (crossbr)
|
||||||
|
candirufish
|
||||||
|
Chess13234
|
||||||
|
Chris Cain (ceebo)
|
||||||
|
Dan Schmidt (dfannius)
|
||||||
|
Daniel Axtens (daxtens)
|
||||||
|
Daniel Dugovic (ddugovic)
|
||||||
Dariusz Orzechowski
|
Dariusz Orzechowski
|
||||||
|
David Zar
|
||||||
|
Daylen Yang (daylen)
|
||||||
DiscanX
|
DiscanX
|
||||||
|
double-beep
|
||||||
|
Eduardo Cáceres (eduherminio)
|
||||||
|
Eelco de Groot (KingDefender)
|
||||||
|
Elvin Liu (solarlight2)
|
||||||
|
erbsenzaehler
|
||||||
Ernesto Gatti
|
Ernesto Gatti
|
||||||
|
Fabian Beuke (madnight)
|
||||||
|
Fabian Fichter (ianfab)
|
||||||
|
fanon
|
||||||
|
Fauzi Akram Dabat (FauziAkram)
|
||||||
|
Felix Wittmann
|
||||||
|
gamander
|
||||||
|
gguliash
|
||||||
|
Gian-Carlo Pascutto (gcp)
|
||||||
|
Gontran Lemaire (gonlem)
|
||||||
|
Goodkov Vasiliy Aleksandrovich (goodkov)
|
||||||
Gregor Cramer
|
Gregor Cramer
|
||||||
Guenther Demetz
|
GuardianRM
|
||||||
Hiraoka Takuya
|
Günther Demetz (pb00067, pb00068)
|
||||||
|
Guy Vreuls (gvreuls)
|
||||||
|
Henri Wiechers
|
||||||
|
Hiraoka Takuya (HiraokaTakuya)
|
||||||
|
homoSapiensSapiens
|
||||||
Hongzhi Cheng
|
Hongzhi Cheng
|
||||||
Joseph Hellis
|
Ivan Ivec (IIvec)
|
||||||
|
Jacques B. (Timshel)
|
||||||
|
Jan Ondruš (hxim)
|
||||||
|
Jared Kish (Kurtbusch)
|
||||||
|
Jarrod Torriero (DU-jdto)
|
||||||
|
Jean Gauthier (OuaisBla)
|
||||||
|
Jean-Francois Romang (jromang)
|
||||||
|
Jekaa
|
||||||
|
Jerry Donald Watson (jerrydonaldwatson)
|
||||||
|
Jonathan Calovski (Mysseno)
|
||||||
|
Jonathan Dumale (SFisGOD)
|
||||||
|
Joost VandeVondele (vondele)
|
||||||
|
Jörg Oster (joergoster)
|
||||||
|
Joseph Ellis (jhellis3)
|
||||||
|
Joseph R. Prostko
|
||||||
|
jundery
|
||||||
|
Justin Blanchard (UncombedCoconut)
|
||||||
Kelly Wilson
|
Kelly Wilson
|
||||||
Ken T Takusagawa
|
Ken Takusagawa
|
||||||
|
kinderchocolate
|
||||||
|
Kiran Panditrao (Krgp)
|
||||||
Kojirion
|
Kojirion
|
||||||
Luca Brivio
|
Leonardo Ljubičić (ICCF World Champion)
|
||||||
Matt Sullivan
|
Leonid Pechenik (lp--)
|
||||||
Matthew Lai
|
Linus Arver (listx)
|
||||||
Matthew Sullivan
|
loco-loco
|
||||||
Michel Van den Bergh
|
Lub van den Berg (ElbertoOne)
|
||||||
Mysseno
|
Luca Brivio (lucabrivio)
|
||||||
|
Lucas Braesch (lucasart)
|
||||||
|
Lyudmil Antonov (lantonov)
|
||||||
|
Maciej Żenczykowski (zenczykowski)
|
||||||
|
Malcolm Campbell (xoto10)
|
||||||
|
Mark Tenzer (31m059)
|
||||||
|
marotear
|
||||||
|
Matthew Lai (matthewlai)
|
||||||
|
Matthew Sullivan (Matt14916)
|
||||||
|
Michael An (man)
|
||||||
|
Michael Byrne (MichaelB7)
|
||||||
|
Michael Chaly (Vizvezdenec)
|
||||||
|
Michael Stembera (mstembera)
|
||||||
|
Michael Whiteley (protonspring)
|
||||||
|
Michel Van den Bergh (vdbergh)
|
||||||
|
Miguel Lahoz (miguel-l)
|
||||||
|
Mikael Bäckman (mbootsector)
|
||||||
|
Mira
|
||||||
|
Miroslav Fontán (Hexik)
|
||||||
|
Moez Jellouli (MJZ1977)
|
||||||
|
Mohammed Li (tthsqe12)
|
||||||
|
Nathan Rugg (nmrugg)
|
||||||
|
Nick Pelling (nickpelling)
|
||||||
|
Nicklas Persson (NicklasPersson)
|
||||||
|
Niklas Fiekas (niklasf)
|
||||||
|
Nikolay Kostov (NikolayIT)
|
||||||
|
Ondrej Mosnáček (WOnder93)
|
||||||
Oskar Werkelin Ahlin
|
Oskar Werkelin Ahlin
|
||||||
Pablo Vazquez
|
Pablo Vazquez
|
||||||
|
Panthee
|
||||||
Pascal Romaret
|
Pascal Romaret
|
||||||
Ralph Stoesser
|
Pasquale Pigazzini (ppigazzini)
|
||||||
Ralph Stößer
|
Patrick Jansen (mibere)
|
||||||
Raminder Singh
|
|
||||||
Richard Lloyd
|
|
||||||
Ryan Takker
|
|
||||||
Stephane Nicolet
|
|
||||||
Thanar2
|
|
||||||
absimaldata
|
|
||||||
braich
|
|
||||||
gguliash
|
|
||||||
kinderchocolate
|
|
||||||
loco-loco
|
|
||||||
pellanda
|
pellanda
|
||||||
|
Peter Zsifkovits (CoffeeOne)
|
||||||
|
Ralph Stößer (Ralph Stoesser)
|
||||||
|
Raminder Singh
|
||||||
renouve
|
renouve
|
||||||
|
Reuven Peleg
|
||||||
|
Richard Lloyd
|
||||||
|
Rodrigo Exterckötter Tjäder
|
||||||
|
Ron Britvich (Britvich)
|
||||||
|
Ronald de Man (syzygy1, syzygy)
|
||||||
|
Ryan Schmitt
|
||||||
|
Ryan Takker
|
||||||
|
Sami Kiminki (skiminki)
|
||||||
|
Sebastian Buchwald (UniQP)
|
||||||
|
Sergei Antonov (saproj)
|
||||||
|
Sergei Ivanov (svivanov72)
|
||||||
sf-x
|
sf-x
|
||||||
|
Shane Booth (shane31)
|
||||||
|
Stefan Geschwentner (locutus2)
|
||||||
|
Stefano Cardanobile (Stefano80)
|
||||||
|
Steinar Gunderson (sesse)
|
||||||
|
Stéphane Nicolet (snicolet)
|
||||||
|
Thanar2
|
||||||
thaspel
|
thaspel
|
||||||
unknown
|
theo77186
|
||||||
uriblass
|
Tom Truscott
|
||||||
|
Tom Vijlbrief (tomtor)
|
||||||
|
Torsten Franz (torfranz, tfranzer)
|
||||||
|
Tracey Emery (basepr1me)
|
||||||
|
Uri Blass (uriblass)
|
||||||
|
Vince Negri (cuddlestmonkey)
|
||||||
|
|
||||||
|
|
||||||
|
# Additionally, we acknowledge the authors and maintainers of fishtest,
|
||||||
|
# an amazing and essential framework for the development of Stockfish!
|
||||||
|
#
|
||||||
|
# https://github.com/glinscott/fishtest/blob/master/AUTHORS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,65 +1,123 @@
|
|||||||
### Overview
|
## Overview
|
||||||
|
|
||||||
[](https://travis-ci.org/official-stockfish/Stockfish)
|
[](https://travis-ci.org/official-stockfish/Stockfish)
|
||||||
|
[](https://ci.appveyor.com/project/mcostalba/stockfish/branch/master)
|
||||||
|
|
||||||
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
[Stockfish](https://stockfishchess.org) is a free, powerful UCI chess engine
|
||||||
not a complete chess program and requires some UCI-compatible GUI
|
derived from Glaurung 2.1. It is not a complete chess program and requires a
|
||||||
(e.g. XBoard with PolyGlot, eboard, Arena, Sigma Chess, Shredder, Chess
|
UCI-compatible GUI (e.g. XBoard with PolyGlot, Scid, Cute Chess, eboard, Arena,
|
||||||
Partner or Fritz) in order to be used comfortably. Read the
|
Sigma Chess, Shredder, Chess Partner or Fritz) in order to be used comfortably.
|
||||||
documentation for your GUI of choice for information about how to use
|
Read the documentation for your GUI of choice for information about how to use
|
||||||
Stockfish with it.
|
Stockfish with it.
|
||||||
|
|
||||||
This version of Stockfish supports up to 128 cores. The engine defaults
|
|
||||||
to one search thread, so it is therefore recommended to inspect the value of
|
|
||||||
the *Threads* UCI parameter, and to make sure it equals the number of CPU
|
|
||||||
cores on your computer.
|
|
||||||
|
|
||||||
This version of Stockfish has support for Syzygybases.
|
## Files
|
||||||
|
|
||||||
|
|
||||||
### Files
|
|
||||||
|
|
||||||
This distribution of Stockfish consists of the following files:
|
This distribution of Stockfish consists of the following files:
|
||||||
|
|
||||||
* Readme.md, the file you are currently reading.
|
* Readme.md, the file you are currently reading.
|
||||||
|
|
||||||
* Copying.txt, a text file containing the GNU General Public License.
|
* Copying.txt, a text file containing the GNU General Public License version 3.
|
||||||
|
|
||||||
* src, a subdirectory containing the full source code, including a Makefile
|
* src, a subdirectory containing the full source code, including a Makefile
|
||||||
that can be used to compile Stockfish on Unix-like systems.
|
that can be used to compile Stockfish on Unix-like systems.
|
||||||
|
|
||||||
|
|
||||||
### Syzygybases
|
## UCI parameters
|
||||||
|
|
||||||
**Configuration**
|
Currently, Stockfish has the following UCI options:
|
||||||
|
|
||||||
Syzygybases are configured using the UCI options "SyzygyPath",
|
* #### Debug Log File
|
||||||
"SyzygyProbeDepth", "Syzygy50MoveRule" and "SyzygyProbeLimit".
|
Write all communication to and from the engine into a text file.
|
||||||
|
|
||||||
The option "SyzygyPath" should be set to the directory or directories that
|
* #### Contempt
|
||||||
contain the .rtbw and .rtbz files. Multiple directories should be
|
A positive value for contempt favors middle game positions and avoids draws.
|
||||||
separated by ";" on Windows and by ":" on Unix-based operating systems.
|
|
||||||
**Do not use spaces around the ";" or ":".**
|
|
||||||
|
|
||||||
Example: `C:\tablebases\wdl345;C:\tablebases\wdl6;D:\tablebases\dtz345;D:\tablebases\dtz6`
|
* #### Analysis Contempt
|
||||||
|
By default, contempt is set to prefer the side to move. Set this option to "White"
|
||||||
|
or "Black" to analyse with contempt for that side, or "Off" to disable contempt.
|
||||||
|
|
||||||
It is recommended to store .rtbw files on an SSD. There is no loss in
|
* #### Threads
|
||||||
storing the .rtbz files on a regular HD.
|
The number of CPU threads used for searching a position. For best performance, set
|
||||||
|
this equal to the number of CPU cores available.
|
||||||
|
|
||||||
Increasing the "SyzygyProbeDepth" option lets the engine probe less
|
* #### Hash
|
||||||
aggressively. Set this option to a higher value if you experience too much
|
The size of the hash table in MB.
|
||||||
slowdown (in terms of nps) due to TB probing.
|
|
||||||
|
|
||||||
Set the "Syzygy50MoveRule" option to false if you want tablebase positions
|
* #### Clear Hash
|
||||||
that are drawn by the 50-move rule to count as win or loss. This may be useful
|
Clear the hash table.
|
||||||
for correspondence games (because of tablebase adjudication).
|
|
||||||
|
|
||||||
The "SyzygyProbeLimit" option should normally be left at its default value.
|
* #### Ponder
|
||||||
|
Let Stockfish ponder its next move while the opponent is thinking.
|
||||||
|
|
||||||
|
* #### MultiPV
|
||||||
|
Output the N best lines (principal variations, PVs) when searching.
|
||||||
|
Leave at 1 for best performance.
|
||||||
|
|
||||||
|
* #### Skill Level
|
||||||
|
Lower the Skill Level in order to make Stockfish play weaker (see also UCI_LimitStrength).
|
||||||
|
Internally, MultiPV is enabled, and with a certain probability depending on the Skill Level a
|
||||||
|
weaker move will be played.
|
||||||
|
|
||||||
|
* #### UCI_LimitStrength
|
||||||
|
Enable weaker play aiming for an Elo rating as set by UCI_Elo. This option overrides Skill Level.
|
||||||
|
|
||||||
|
* #### UCI_Elo
|
||||||
|
If enabled by UCI_LimitStrength, aim for an engine strength of the given Elo.
|
||||||
|
This Elo rating has been calibrated at a time control of 60s+0.6s and anchored to CCRL 40/4.
|
||||||
|
|
||||||
|
* #### Move Overhead
|
||||||
|
Assume a time delay of x ms due to network and GUI overheads. This is useful to
|
||||||
|
avoid losses on time in those cases.
|
||||||
|
|
||||||
|
* #### Minimum Thinking Time
|
||||||
|
Search for at least x ms per move.
|
||||||
|
|
||||||
|
* #### Slow Mover
|
||||||
|
Lower values will make Stockfish take less time in games, higher values will
|
||||||
|
make it think longer.
|
||||||
|
|
||||||
|
* #### nodestime
|
||||||
|
Tells the engine to use nodes searched instead of wall time to account for
|
||||||
|
elapsed time. Useful for engine testing.
|
||||||
|
|
||||||
|
* #### UCI_Chess960
|
||||||
|
An option handled by your GUI. If true, Stockfish will play Chess960.
|
||||||
|
|
||||||
|
* #### UCI_AnalyseMode
|
||||||
|
An option handled by your GUI.
|
||||||
|
|
||||||
|
* #### SyzygyPath
|
||||||
|
Path to the folders/directories storing the Syzygy tablebase files. Multiple
|
||||||
|
directories are to be separated by ";" on Windows and by ":" on Unix-based
|
||||||
|
operating systems. Do not use spaces around the ";" or ":".
|
||||||
|
|
||||||
|
Example: `C:\tablebases\wdl345;C:\tablebases\wdl6;D:\tablebases\dtz345;D:\tablebases\dtz6`
|
||||||
|
|
||||||
|
It is recommended to store .rtbw files on an SSD. There is no loss in storing
|
||||||
|
the .rtbz files on a regular HD. It is recommended to verify all md5 checksums
|
||||||
|
of the downloaded tablebase files (`md5sum -c checksum.md5`) as corruption will
|
||||||
|
lead to engine crashes.
|
||||||
|
|
||||||
|
* #### SyzygyProbeDepth
|
||||||
|
Minimum remaining search depth for which a position is probed. Set this option
|
||||||
|
to a higher value to probe less agressively if you experience too much slowdown
|
||||||
|
(in terms of nps) due to TB probing.
|
||||||
|
|
||||||
|
* #### Syzygy50MoveRule
|
||||||
|
Disable to let fifty-move rule draws detected by Syzygy tablebase probes count
|
||||||
|
as wins or losses. This is useful for ICCF correspondence games.
|
||||||
|
|
||||||
|
* #### SyzygyProbeLimit
|
||||||
|
Limit Syzygy tablebase probing to positions with at most this many pieces left
|
||||||
|
(including kings and pawns).
|
||||||
|
|
||||||
|
|
||||||
|
## What to expect from Syzygybases?
|
||||||
|
|
||||||
**What to expect**
|
|
||||||
If the engine is searching a position that is not in the tablebases (e.g.
|
If the engine is searching a position that is not in the tablebases (e.g.
|
||||||
a position with 7 pieces), it will access the tablebases during the search.
|
a position with 8 pieces), it will access the tablebases during the search.
|
||||||
If the engine reports a very large score (typically 123.xx), this means
|
If the engine reports a very large score (typically 153.xx), this means
|
||||||
that it has found a winning line into a tablebase position.
|
that it has found a winning line into a tablebase position.
|
||||||
|
|
||||||
If the engine is given a position to search that is in the tablebases, it
|
If the engine is given a position to search that is in the tablebases, it
|
||||||
@@ -70,7 +128,7 @@ It will then perform a search only on those moves. **The engine will not move
|
|||||||
immediately**, unless there is only a single good move. **The engine likely
|
immediately**, unless there is only a single good move. **The engine likely
|
||||||
will not report a mate score even if the position is known to be won.**
|
will not report a mate score even if the position is known to be won.**
|
||||||
|
|
||||||
It is therefore clear that behaviour is not identical to what one might
|
It is therefore clear that this behaviour is not identical to what one might
|
||||||
be used to with Nalimov tablebases. There are technical reasons for this
|
be used to with Nalimov tablebases. There are technical reasons for this
|
||||||
difference, the main technical reason being that Nalimov tablebases use the
|
difference, the main technical reason being that Nalimov tablebases use the
|
||||||
DTM metric (distance-to-mate), while Syzygybases use a variation of the
|
DTM metric (distance-to-mate), while Syzygybases use a variation of the
|
||||||
@@ -81,7 +139,7 @@ needed for optimal play and in addition being able to take into account
|
|||||||
the 50-move rule.
|
the 50-move rule.
|
||||||
|
|
||||||
|
|
||||||
### Compiling it yourself
|
## Compiling Stockfish yourself from the sources
|
||||||
|
|
||||||
On Unix-like systems, it should be possible to compile Stockfish
|
On Unix-like systems, it should be possible to compile Stockfish
|
||||||
directly from the source code with the included Makefile.
|
directly from the source code with the included Makefile.
|
||||||
@@ -95,11 +153,49 @@ compile (for instance with Microsoft MSVC) you need to manually
|
|||||||
set/unset some switches in the compiler command line; see file *types.h*
|
set/unset some switches in the compiler command line; see file *types.h*
|
||||||
for a quick reference.
|
for a quick reference.
|
||||||
|
|
||||||
|
When reporting an issue or a bug, please tell us which version and
|
||||||
|
compiler you used to create your executable. These informations can
|
||||||
|
be found by typing the following commands in a console:
|
||||||
|
|
||||||
### Terms of use
|
```
|
||||||
|
./stockfish
|
||||||
|
compiler
|
||||||
|
```
|
||||||
|
|
||||||
Stockfish is free, and distributed under the **GNU General Public License**
|
## Understanding the code base and participating in the project
|
||||||
(GPL). Essentially, this means that you are free to do almost exactly
|
|
||||||
|
Stockfish's improvement over the last couple of years has been a great
|
||||||
|
community effort. There are a few ways to help contribute to its growth.
|
||||||
|
|
||||||
|
### Donating hardware
|
||||||
|
|
||||||
|
Improving Stockfish requires a massive amount of testing. You can donate
|
||||||
|
your hardware resources by installing the [Fishtest Worker](https://github.com/glinscott/fishtest/wiki/Running-the-worker:-overview)
|
||||||
|
and view the current tests on [Fishtest](https://tests.stockfishchess.org/tests).
|
||||||
|
|
||||||
|
### Improving the code
|
||||||
|
|
||||||
|
If you want to help improve the code, there are several valuable resources:
|
||||||
|
|
||||||
|
* [In this wiki,](https://www.chessprogramming.org) many techniques used in
|
||||||
|
Stockfish are explained with a lot of background information.
|
||||||
|
|
||||||
|
* [The section on Stockfish](https://www.chessprogramming.org/Stockfish)
|
||||||
|
describes many features and techniques used by Stockfish. However, it is
|
||||||
|
generic rather than being focused on Stockfish's precise implementation.
|
||||||
|
Nevertheless, a helpful resource.
|
||||||
|
|
||||||
|
* The latest source can always be found on [GitHub](https://github.com/official-stockfish/Stockfish).
|
||||||
|
Discussions about Stockfish take place in the [FishCooking](https://groups.google.com/forum/#!forum/fishcooking)
|
||||||
|
group and engine testing is done on [Fishtest](https://tests.stockfishchess.org/tests).
|
||||||
|
If you want to help improve Stockfish, please read this [guideline](https://github.com/glinscott/fishtest/wiki/Creating-my-first-test)
|
||||||
|
first, where the basics of Stockfish development are explained.
|
||||||
|
|
||||||
|
|
||||||
|
## Terms of use
|
||||||
|
|
||||||
|
Stockfish is free, and distributed under the **GNU General Public License version 3**
|
||||||
|
(GPL v3). Essentially, this means that you are free to do almost exactly
|
||||||
what you want with the program, including distributing it among your
|
what you want with the program, including distributing it among your
|
||||||
friends, making it available for download from your web site, selling
|
friends, making it available for download from your web site, selling
|
||||||
it (either by itself or as part of some bigger software package), or
|
it (either by itself or as part of some bigger software package), or
|
||||||
@@ -110,5 +206,5 @@ some way, you must always include the full source code, or a pointer
|
|||||||
to where the source code can be found. If you make any changes to the
|
to where the source code can be found. If you make any changes to the
|
||||||
source code, these changes must also be made available under the GPL.
|
source code, these changes must also be made available under the GPL.
|
||||||
|
|
||||||
For full details, read the copy of the GPL found in the file named
|
For full details, read the copy of the GPL v3 found in the file named
|
||||||
*Copying.txt*
|
*Copying.txt*.
|
||||||
|
|||||||
@@ -0,0 +1,154 @@
|
|||||||
|
Contributors with >10,000 CPU hours as of January 7, 2020
|
||||||
|
Thank you!
|
||||||
|
|
||||||
|
Username CPU Hours Games played
|
||||||
|
--------------------------------------------------
|
||||||
|
noobpwnftw 9305707 695548021
|
||||||
|
mlang 780050 61648867
|
||||||
|
dew 621626 43921547
|
||||||
|
mibere 524702 42238645
|
||||||
|
crunchy 354587 27344275
|
||||||
|
cw 354495 27274181
|
||||||
|
fastgm 332801 22804359
|
||||||
|
JojoM 295750 20437451
|
||||||
|
CSU_Dynasty 262015 21828122
|
||||||
|
Fisherman 232181 18939229
|
||||||
|
ctoks 218866 17622052
|
||||||
|
glinscott 201989 13780820
|
||||||
|
tvijlbrief 201204 15337115
|
||||||
|
velislav 188630 14348485
|
||||||
|
gvreuls 187164 15149976
|
||||||
|
bking_US 180289 11876016
|
||||||
|
nordlandia 172076 13467830
|
||||||
|
leszek 157152 11443978
|
||||||
|
Thanar 148021 12365359
|
||||||
|
spams 141975 10319326
|
||||||
|
drabel 138073 11121749
|
||||||
|
vdv 137850 9394330
|
||||||
|
mgrabiak 133578 10454324
|
||||||
|
TueRens 132485 10878471
|
||||||
|
bcross 129683 11557084
|
||||||
|
marrco 126078 9356740
|
||||||
|
sqrt2 125830 9724586
|
||||||
|
robal 122873 9593418
|
||||||
|
vdbergh 120766 8926915
|
||||||
|
malala 115926 8002293
|
||||||
|
CoffeeOne 114241 5004100
|
||||||
|
dsmith 113189 7570238
|
||||||
|
BrunoBanani 104644 7436849
|
||||||
|
Data 92328 8220352
|
||||||
|
mhoram 89333 6695109
|
||||||
|
davar 87924 7009424
|
||||||
|
xoto 81094 6869316
|
||||||
|
ElbertoOne 80899 7023771
|
||||||
|
grandphish2 78067 6160199
|
||||||
|
brabos 77212 6186135
|
||||||
|
psk 75733 5984901
|
||||||
|
BRAVONE 73875 5054681
|
||||||
|
sunu 70771 5597972
|
||||||
|
sterni1971 70605 5590573
|
||||||
|
MaZePallas 66886 5188978
|
||||||
|
Vizvezdenec 63708 4967313
|
||||||
|
nssy 63462 5259388
|
||||||
|
jromang 61634 4940891
|
||||||
|
teddybaer 61231 5407666
|
||||||
|
Pking_cda 60099 5293873
|
||||||
|
solarlight 57469 5028306
|
||||||
|
dv8silencer 56913 3883992
|
||||||
|
tinker 54936 4086118
|
||||||
|
renouve 49732 3501516
|
||||||
|
Freja 49543 3733019
|
||||||
|
robnjr 46972 4053117
|
||||||
|
rap 46563 3219146
|
||||||
|
Bobo1239 46036 3817196
|
||||||
|
ttruscott 45304 3649765
|
||||||
|
racerschmacer 44881 3975413
|
||||||
|
finfish 44764 3370515
|
||||||
|
eva42 41783 3599691
|
||||||
|
biffhero 40263 3111352
|
||||||
|
bigpen0r 39817 3291647
|
||||||
|
mhunt 38871 2691355
|
||||||
|
ronaldjerum 38820 3240695
|
||||||
|
Antihistamine 38785 2761312
|
||||||
|
pb00067 38038 3086320
|
||||||
|
speedycpu 37591 3003273
|
||||||
|
rkl 37207 3289580
|
||||||
|
VoyagerOne 37050 3441673
|
||||||
|
jbwiebe 35320 2805433
|
||||||
|
cuistot 34191 2146279
|
||||||
|
homyur 33927 2850481
|
||||||
|
manap 32873 2327384
|
||||||
|
gri 32538 2515779
|
||||||
|
oryx 31267 2899051
|
||||||
|
EthanOConnor 30959 2090311
|
||||||
|
SC 30832 2730764
|
||||||
|
csnodgrass 29505 2688994
|
||||||
|
jmdana 29458 2205261
|
||||||
|
strelock 28219 2067805
|
||||||
|
jkiiski 27832 1904470
|
||||||
|
Pyafue 27533 1902349
|
||||||
|
Garf 27515 2747562
|
||||||
|
eastorwest 27421 2317535
|
||||||
|
slakovv 26903 2021889
|
||||||
|
Prcuvu 24835 2170122
|
||||||
|
anst 24714 2190091
|
||||||
|
hyperbolic.tom 24319 2017394
|
||||||
|
Patrick_G 23687 1801617
|
||||||
|
Sharaf_DG 22896 1786697
|
||||||
|
nabildanial 22195 1519409
|
||||||
|
chriswk 21931 1868317
|
||||||
|
achambord 21665 1767323
|
||||||
|
Zirie 20887 1472937
|
||||||
|
team-oh 20217 1636708
|
||||||
|
Isidor 20096 1680691
|
||||||
|
ncfish1 19931 1520927
|
||||||
|
nesoneg 19875 1463031
|
||||||
|
Spprtr 19853 1548165
|
||||||
|
JanErik 19849 1703875
|
||||||
|
agg177 19478 1395014
|
||||||
|
SFTUser 19231 1567999
|
||||||
|
xor12 19017 1680165
|
||||||
|
sg4032 18431 1641865
|
||||||
|
rstoesser 18118 1293588
|
||||||
|
MazeOfGalious 17917 1629593
|
||||||
|
j3corre 17743 941444
|
||||||
|
cisco2015 17725 1690126
|
||||||
|
ianh2105 17706 1632562
|
||||||
|
dex 17678 1467203
|
||||||
|
jundery 17194 1115855
|
||||||
|
iisiraider 17019 1101015
|
||||||
|
horst.prack 17012 1465656
|
||||||
|
Adrian.Schmidt123 16563 1281436
|
||||||
|
purplefishies 16342 1092533
|
||||||
|
wei 16274 1745989
|
||||||
|
ville 16144 1384026
|
||||||
|
eudhan 15712 1283717
|
||||||
|
OuaisBla 15581 972000
|
||||||
|
DragonLord 15559 1162790
|
||||||
|
dju 14716 875569
|
||||||
|
chris 14479 1487385
|
||||||
|
0xB00B1ES 14079 1001120
|
||||||
|
OssumOpossum 13776 1007129
|
||||||
|
enedene 13460 905279
|
||||||
|
bpfliegel 13346 884523
|
||||||
|
Ente 13198 1156722
|
||||||
|
IgorLeMasson 13087 1147232
|
||||||
|
jpulman 13000 870599
|
||||||
|
ako027ako 12775 1173203
|
||||||
|
Nikolay.IT 12352 1068349
|
||||||
|
Andrew Grant 12327 895539
|
||||||
|
joster 12008 950160
|
||||||
|
AdrianSA 11996 804972
|
||||||
|
Nesa92 11455 1111993
|
||||||
|
fatmurphy 11345 853210
|
||||||
|
Dark_wizzie 11108 1007152
|
||||||
|
modolief 10869 896470
|
||||||
|
mschmidt 10757 803401
|
||||||
|
infinity 10594 727027
|
||||||
|
mabichito 10524 749391
|
||||||
|
Thomas A. Anderson 10474 732094
|
||||||
|
thijsk 10431 719357
|
||||||
|
Flopzee 10339 894821
|
||||||
|
crocogoat 10104 1013854
|
||||||
|
SapphireBrand 10104 969604
|
||||||
|
stocky 10017 699440
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
version: 1.0.{build}
|
||||||
|
clone_depth: 50
|
||||||
|
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- appveyor
|
||||||
|
|
||||||
|
# Operating system (build VM template)
|
||||||
|
os: Visual Studio 2017
|
||||||
|
|
||||||
|
# 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 15 2017"
|
||||||
|
If (${env:PLATFORM} -eq 'x64') { $g = $g + ' Win64' }
|
||||||
|
cmake -G "${g}" .
|
||||||
|
Write-Host "Generated files for: " $g
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- cmake --build . --config %CONFIGURATION% -- /verbosity:minimal
|
||||||
|
|
||||||
|
before_test:
|
||||||
|
- cd src/%CONFIGURATION%
|
||||||
|
- stockfish bench 2> out.txt >NUL
|
||||||
|
- ps: |
|
||||||
|
# Verify bench number
|
||||||
|
$s = (gc "./out.txt" | out-string)
|
||||||
|
$r = ($s -match 'Nodes searched \D+(\d+)' | % { $matches[1] })
|
||||||
|
Write-Host "Engine bench:" $r
|
||||||
|
Write-Host "Reference bench:" $bench
|
||||||
|
If ($r -ne $bench) { exit 1 }
|
||||||
+149
-130
@@ -1,7 +1,7 @@
|
|||||||
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
# Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
# Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
# Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
# Copyright (C) 2015-2019 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
#
|
#
|
||||||
# Stockfish is free software: you can redistribute it and/or modify
|
# Stockfish is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,24 +21,31 @@
|
|||||||
### Section 1. General Configuration
|
### Section 1. General Configuration
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
|
|
||||||
### Establish the operating system name
|
|
||||||
UNAME = $(shell uname)
|
|
||||||
|
|
||||||
### Executable name
|
### Executable name
|
||||||
|
ifeq ($(COMP),mingw)
|
||||||
|
EXE = stockfish.exe
|
||||||
|
else
|
||||||
EXE = stockfish
|
EXE = stockfish
|
||||||
|
endif
|
||||||
|
|
||||||
### Installation dir definitions
|
### Installation dir definitions
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
BINDIR = $(PREFIX)/bin
|
BINDIR = $(PREFIX)/bin
|
||||||
|
|
||||||
### Built-in benchmark for pgo-builds
|
### Built-in benchmark for pgo-builds
|
||||||
PGOBENCH = ./$(EXE) bench 16 1 1000 default time
|
PGOBENCH = ./$(EXE) bench
|
||||||
|
|
||||||
### Object files
|
### Object files
|
||||||
OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
||||||
material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o \
|
material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o \
|
||||||
search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
|
search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
|
||||||
|
|
||||||
|
### Establish the operating system name
|
||||||
|
KERNEL = $(shell uname -s)
|
||||||
|
ifeq ($(KERNEL),Linux)
|
||||||
|
OS = $(shell uname -o)
|
||||||
|
endif
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Section 2. High-level Configuration
|
### Section 2. High-level Configuration
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
@@ -47,13 +54,14 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
|||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# debug = yes/no --- -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
|
||||||
# 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 x86 asm-instruction
|
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
|
||||||
# bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
|
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
|
||||||
# with GCC and ICC 64-bit)
|
|
||||||
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
|
|
||||||
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
||||||
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
||||||
#
|
#
|
||||||
@@ -64,9 +72,9 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
|||||||
### 2.1. General and architecture defaults
|
### 2.1. General and architecture defaults
|
||||||
optimize = yes
|
optimize = yes
|
||||||
debug = no
|
debug = no
|
||||||
|
sanitize = no
|
||||||
bits = 32
|
bits = 32
|
||||||
prefetch = no
|
prefetch = no
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
popcnt = no
|
||||||
sse = no
|
sse = no
|
||||||
pext = no
|
pext = no
|
||||||
@@ -96,7 +104,6 @@ ifeq ($(ARCH),x86-64)
|
|||||||
arch = x86_64
|
arch = x86_64
|
||||||
bits = 64
|
bits = 64
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = yes
|
|
||||||
sse = yes
|
sse = yes
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -104,7 +111,6 @@ ifeq ($(ARCH),x86-64-modern)
|
|||||||
arch = x86_64
|
arch = x86_64
|
||||||
bits = 64
|
bits = 64
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = yes
|
|
||||||
popcnt = yes
|
popcnt = yes
|
||||||
sse = yes
|
sse = yes
|
||||||
endif
|
endif
|
||||||
@@ -113,7 +119,6 @@ ifeq ($(ARCH),x86-64-bmi2)
|
|||||||
arch = x86_64
|
arch = x86_64
|
||||||
bits = 64
|
bits = 64
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = yes
|
|
||||||
popcnt = yes
|
popcnt = yes
|
||||||
sse = yes
|
sse = yes
|
||||||
pext = yes
|
pext = yes
|
||||||
@@ -122,7 +127,6 @@ endif
|
|||||||
ifeq ($(ARCH),armv7)
|
ifeq ($(ARCH),armv7)
|
||||||
arch = armv7
|
arch = armv7
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = yes
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),ppc-32)
|
ifeq ($(ARCH),ppc-32)
|
||||||
@@ -132,6 +136,8 @@ endif
|
|||||||
ifeq ($(ARCH),ppc-64)
|
ifeq ($(ARCH),ppc-64)
|
||||||
arch = ppc64
|
arch = ppc64
|
||||||
bits = 64
|
bits = 64
|
||||||
|
popcnt = yes
|
||||||
|
prefetch = yes
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
@@ -141,7 +147,7 @@ endif
|
|||||||
|
|
||||||
### 3.1 Selecting compiler (default = gcc)
|
### 3.1 Selecting compiler (default = gcc)
|
||||||
|
|
||||||
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -fno-rtti -std=c++11 $(EXTRACXXFLAGS)
|
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
|
||||||
DEPENDFLAGS += -std=c++11
|
DEPENDFLAGS += -std=c++11
|
||||||
LDFLAGS += $(EXTRALDFLAGS)
|
LDFLAGS += $(EXTRALDFLAGS)
|
||||||
|
|
||||||
@@ -153,7 +159,18 @@ ifeq ($(COMP),gcc)
|
|||||||
comp=gcc
|
comp=gcc
|
||||||
CXX=g++
|
CXX=g++
|
||||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||||
ifneq ($(UNAME),Darwin)
|
|
||||||
|
ifeq ($(ARCH),armv7)
|
||||||
|
ifeq ($(OS),Android)
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(KERNEL),Darwin)
|
||||||
LDFLAGS += -Wl,--no-as-needed
|
LDFLAGS += -Wl,--no-as-needed
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -161,7 +178,7 @@ endif
|
|||||||
ifeq ($(COMP),mingw)
|
ifeq ($(COMP),mingw)
|
||||||
comp=mingw
|
comp=mingw
|
||||||
|
|
||||||
ifeq ($(UNAME),Linux)
|
ifeq ($(KERNEL),Linux)
|
||||||
ifeq ($(bits),64)
|
ifeq ($(bits),64)
|
||||||
ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
|
ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
|
||||||
CXX=x86_64-w64-mingw32-c++
|
CXX=x86_64-w64-mingw32-c++
|
||||||
@@ -193,108 +210,100 @@ ifeq ($(COMP),clang)
|
|||||||
comp=clang
|
comp=clang
|
||||||
CXX=clang++
|
CXX=clang++
|
||||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||||
ifeq ($(UNAME),Darwin)
|
|
||||||
CXXFLAGS += -std=c++0x -stdlib=libc++
|
ifneq ($(KERNEL),Darwin)
|
||||||
DEPENDFLAGS += -std=c++0x -stdlib=libc++
|
ifneq ($(KERNEL),OpenBSD)
|
||||||
|
LDFLAGS += -latomic
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),armv7)
|
||||||
|
ifeq ($(OS),Android)
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),icc)
|
ifeq ($(comp),icc)
|
||||||
profile_prepare = icc-profile-prepare
|
|
||||||
profile_make = icc-profile-make
|
profile_make = icc-profile-make
|
||||||
profile_use = icc-profile-use
|
profile_use = icc-profile-use
|
||||||
profile_clean = icc-profile-clean
|
|
||||||
else
|
else
|
||||||
profile_prepare = gcc-profile-prepare
|
ifeq ($(comp),clang)
|
||||||
|
profile_make = clang-profile-make
|
||||||
|
profile_use = clang-profile-use
|
||||||
|
else
|
||||||
profile_make = gcc-profile-make
|
profile_make = gcc-profile-make
|
||||||
profile_use = gcc-profile-use
|
profile_use = gcc-profile-use
|
||||||
profile_clean = gcc-profile-clean
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(UNAME),Darwin)
|
ifeq ($(KERNEL),Darwin)
|
||||||
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
||||||
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### Travis CI script uses COMPILER to overwrite CXX
|
### Travis CI script uses COMPILER to overwrite CXX
|
||||||
ifdef COMPILER
|
ifdef COMPILER
|
||||||
CXX=$(COMPILER)
|
COMPCXX=$(COMPILER)
|
||||||
|
endif
|
||||||
|
|
||||||
|
### Allow overwriting CXX from command line
|
||||||
|
ifdef COMPCXX
|
||||||
|
CXX=$(COMPCXX)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### On mingw use Windows threads, otherwise POSIX
|
### On mingw use Windows threads, otherwise POSIX
|
||||||
ifneq ($(comp),mingw)
|
ifneq ($(comp),mingw)
|
||||||
# On Android Bionic's C library comes with its own pthread implementation bundled in
|
# On Android Bionic's C library comes with its own pthread implementation bundled in
|
||||||
ifneq ($(arch),armv7)
|
ifneq ($(OS),Android)
|
||||||
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
||||||
ifneq ($(UNAME),Haiku)
|
ifneq ($(KERNEL),Haiku)
|
||||||
LDFLAGS += -lpthread
|
LDFLAGS += -lpthread
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.4 Debugging
|
### 3.2.1 Debugging
|
||||||
ifeq ($(debug),no)
|
ifeq ($(debug),no)
|
||||||
CXXFLAGS += -DNDEBUG
|
CXXFLAGS += -DNDEBUG
|
||||||
else
|
else
|
||||||
CXXFLAGS += -g
|
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)
|
||||||
|
|
||||||
|
CXXFLAGS += -O3
|
||||||
|
|
||||||
ifeq ($(comp),gcc)
|
ifeq ($(comp),gcc)
|
||||||
CXXFLAGS += -O3
|
ifeq ($(OS), Android)
|
||||||
|
|
||||||
ifeq ($(UNAME),Darwin)
|
|
||||||
ifeq ($(arch),i386)
|
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
|
||||||
endif
|
|
||||||
ifeq ($(arch),x86_64)
|
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(arch),armv7)
|
|
||||||
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),mingw)
|
ifeq ($(comp),$(filter $(comp),gcc clang icc))
|
||||||
CXXFLAGS += -O3
|
ifeq ($(KERNEL),Darwin)
|
||||||
endif
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
|
|
||||||
ifeq ($(comp),icc)
|
|
||||||
ifeq ($(UNAME),Darwin)
|
|
||||||
CXXFLAGS += -fast -mdynamic-no-pic
|
|
||||||
else
|
|
||||||
CXXFLAGS += -fast
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(comp),clang)
|
|
||||||
CXXFLAGS += -O3
|
|
||||||
|
|
||||||
ifeq ($(UNAME),Darwin)
|
|
||||||
ifeq ($(pext),no)
|
|
||||||
CXXFLAGS += -flto
|
|
||||||
LDFLAGS += $(CXXFLAGS)
|
|
||||||
endif
|
|
||||||
ifeq ($(arch),i386)
|
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
|
||||||
endif
|
|
||||||
ifeq ($(arch),x86_64)
|
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
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 prefetch
|
### 3.5 prefetch
|
||||||
ifeq ($(prefetch),yes)
|
ifeq ($(prefetch),yes)
|
||||||
ifeq ($(sse),yes)
|
ifeq ($(sse),yes)
|
||||||
CXXFLAGS += -msse
|
CXXFLAGS += -msse
|
||||||
@@ -304,54 +313,47 @@ else
|
|||||||
CXXFLAGS += -DNO_PREFETCH
|
CXXFLAGS += -DNO_PREFETCH
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.8 bsfq
|
### 3.6 popcnt
|
||||||
ifeq ($(bsfq),yes)
|
|
||||||
CXXFLAGS += -DUSE_BSFQ
|
|
||||||
endif
|
|
||||||
|
|
||||||
### 3.9 popcnt
|
|
||||||
ifeq ($(popcnt),yes)
|
ifeq ($(popcnt),yes)
|
||||||
ifeq ($(comp),icc)
|
ifeq ($(arch),ppc64)
|
||||||
|
CXXFLAGS += -DUSE_POPCNT
|
||||||
|
else ifeq ($(comp),icc)
|
||||||
CXXFLAGS += -msse3 -DUSE_POPCNT
|
CXXFLAGS += -msse3 -DUSE_POPCNT
|
||||||
else
|
else
|
||||||
CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
|
CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.10 pext
|
### 3.7 pext
|
||||||
ifeq ($(pext),yes)
|
ifeq ($(pext),yes)
|
||||||
CXXFLAGS += -DUSE_PEXT
|
CXXFLAGS += -DUSE_PEXT
|
||||||
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
CXXFLAGS += -mbmi -mbmi2
|
CXXFLAGS += -msse4 -mbmi2
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.11 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
|
### 3.8 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
|
||||||
### This is a mix of compile and link time options because the lto link phase
|
### This is a mix of compile and link time options because the lto link phase
|
||||||
### needs access to the optimization flags.
|
### needs access to the optimization flags.
|
||||||
ifeq ($(comp),gcc)
|
ifeq ($(optimize),yes)
|
||||||
ifeq ($(optimize),yes)
|
ifeq ($(debug), no)
|
||||||
ifeq ($(debug),no)
|
ifeq ($(comp),$(filter $(comp),gcc clang))
|
||||||
|
CXXFLAGS += -flto
|
||||||
|
LDFLAGS += $(CXXFLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(comp),mingw)
|
||||||
|
ifeq ($(KERNEL),Linux)
|
||||||
CXXFLAGS += -flto
|
CXXFLAGS += -flto
|
||||||
LDFLAGS += $(CXXFLAGS)
|
LDFLAGS += $(CXXFLAGS)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),mingw)
|
|
||||||
ifeq ($(UNAME),Linux)
|
|
||||||
ifeq ($(optimize),yes)
|
|
||||||
ifeq ($(debug),no)
|
|
||||||
CXXFLAGS += -flto
|
|
||||||
LDFLAGS += $(CXXFLAGS)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.12 Android 5 can only run position independent executables. Note that this
|
### 3.9 Android 5 can only run position independent executables. Note that this
|
||||||
### breaks Android 4.0 and earlier.
|
### breaks Android 4.0 and earlier.
|
||||||
ifeq ($(arch),armv7)
|
ifeq ($(OS), Android)
|
||||||
CXXFLAGS += -fPIE
|
CXXFLAGS += -fPIE
|
||||||
LDFLAGS += -fPIE -pie
|
LDFLAGS += -fPIE -pie
|
||||||
endif
|
endif
|
||||||
@@ -365,7 +367,7 @@ 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 ""
|
||||||
@@ -377,10 +379,10 @@ help:
|
|||||||
@echo ""
|
@echo ""
|
||||||
@echo "Supported archs:"
|
@echo "Supported archs:"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "x86-64 > x86 64-bit"
|
@echo "x86-64-bmi2 > x86 64-bit with pext support (also enables SSE4)"
|
||||||
@echo "x86-64-modern > x86 64-bit with popcnt support"
|
@echo "x86-64-modern > x86 64-bit with popcnt support (also enables SSE3)"
|
||||||
@echo "x86-64-bmi2 > x86 64-bit with pext support"
|
@echo "x86-64 > x86 64-bit generic"
|
||||||
@echo "x86-32 > x86 32-bit with SSE support"
|
@echo "x86-32 > x86 32-bit (also enables SSE)"
|
||||||
@echo "x86-32-old > x86 32-bit fall back for old hardware"
|
@echo "x86-32-old > x86 32-bit fall back for old hardware"
|
||||||
@echo "ppc-64 > PPC 64-bit"
|
@echo "ppc-64 > PPC 64-bit"
|
||||||
@echo "ppc-32 > PPC 32-bit"
|
@echo "ppc-32 > PPC 32-bit"
|
||||||
@@ -395,36 +397,39 @@ help:
|
|||||||
@echo "clang > LLVM Clang compiler"
|
@echo "clang > LLVM Clang compiler"
|
||||||
@echo "icc > Intel compiler"
|
@echo "icc > Intel compiler"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Examples. If you don't know what to do, you likely want to run: "
|
@echo "Simple examples. If you don't know what to do, you likely want to run: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make build ARCH=x86-64 (This is for 64-bit systems)"
|
@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 "make build ARCH=x86-32 (This is for 32-bit systems)"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
@echo "Advanced examples, for experienced users: "
|
||||||
|
@echo ""
|
||||||
|
@echo "make build ARCH=x86-64 COMP=clang"
|
||||||
|
@echo "make profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-4.8"
|
||||||
|
@echo ""
|
||||||
|
|
||||||
.PHONY: build profile-build
|
|
||||||
build:
|
.PHONY: help build profile-build strip install clean objclean profileclean help \
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
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 syzygy/*.cpp syzygy/*.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 *.h syzygy/*.cpp syzygy/*.h
|
$(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
|
||||||
|
|
||||||
strip:
|
strip:
|
||||||
strip $(EXE)
|
strip $(EXE)
|
||||||
@@ -434,8 +439,19 @@ 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 ./syzygy/*.o ./syzygy/*.gcda
|
clean: objclean profileclean
|
||||||
|
@rm -f .depend *~ core
|
||||||
|
|
||||||
|
# clean binaries and objects
|
||||||
|
objclean:
|
||||||
|
@rm -f $(EXE) *.o ./syzygy/*.o
|
||||||
|
|
||||||
|
# clean auxiliary profiling files
|
||||||
|
profileclean:
|
||||||
|
@rm -rf profdir
|
||||||
|
@rm -f bench.txt *.gcda ./syzygy/*.gcda *.gcno ./syzygy/*.gcno
|
||||||
|
@rm -f stockfish.profdata *.profraw
|
||||||
|
|
||||||
default:
|
default:
|
||||||
help
|
help
|
||||||
@@ -450,11 +466,13 @@ 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 "bits: '$(bits)'"
|
@echo "bits: '$(bits)'"
|
||||||
|
@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 "sse: '$(sse)'"
|
||||||
@echo "pext: '$(pext)'"
|
@echo "pext: '$(pext)'"
|
||||||
@@ -467,12 +485,12 @@ 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)" = "address" || test "$(sanitize)" = "no"
|
||||||
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
||||||
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
||||||
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
||||||
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
||||||
@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 "$(sse)" = "yes" || test "$(sse)" = "no"
|
@test "$(sse)" = "yes" || test "$(sse)" = "no"
|
||||||
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
||||||
@@ -481,8 +499,18 @@ config-sanity:
|
|||||||
$(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) \
|
||||||
@@ -496,14 +524,8 @@ gcc-profile-use:
|
|||||||
EXTRALDFLAGS='-lgcov' \
|
EXTRALDFLAGS='-lgcov' \
|
||||||
all
|
all
|
||||||
|
|
||||||
gcc-profile-clean:
|
|
||||||
@rm -rf *.gcda *.gcno syzygy/*.gcda syzygy/*.gcno bench.txt
|
|
||||||
|
|
||||||
icc-profile-prepare:
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
|
|
||||||
@mkdir profdir
|
|
||||||
|
|
||||||
icc-profile-make:
|
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
|
||||||
@@ -513,9 +535,6 @@ 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
|
||||||
|
|
||||||
|
|||||||
+46
-61
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,23 +23,20 @@
|
|||||||
#include <istream>
|
#include <istream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "misc.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
|
||||||
#include "thread.h"
|
|
||||||
#include "uci.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const vector<string> Defaults = {
|
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 - 0 10",
|
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
|
||||||
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
|
"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",
|
||||||
@@ -52,7 +49,7 @@ const vector<string> Defaults = {
|
|||||||
"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",
|
"6k1/6p1/6Pp/ppp5/3pn2P/1P3K2/1PP2P2/3N4 b - - 0 1",
|
||||||
"3b4/5kp1/1p1p1p1p/pP1PpP1P/P1P1P3/3KN3/8/8 w - - 0 1",
|
"3b4/5kp1/1p1p1p1p/pP1PpP1P/P1P1P3/3KN3/8/8 w - - 0 1",
|
||||||
"2K5/p7/7P/5pR1/8/5k2/r7/8 w - - 0 1",
|
"2K5/p7/7P/5pR1/8/5k2/r7/8 w - - 0 1 moves g5g6 f3e3 g6g5 e3f3",
|
||||||
"8/6pk/1p6/8/PP3p1p/5P2/4KP1q/3Q4 w - - 0 1",
|
"8/6pk/1p6/8/PP3p1p/5P2/4KP1q/3Q4 w - - 0 1",
|
||||||
"7k/3p2pp/4q3/8/4Q3/5Kp1/P6b/8 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/2p5/8/2kPKp1p/2p4P/2P5/3P4/8 w - - 0 1",
|
||||||
@@ -64,6 +61,10 @@ const vector<string> Defaults = {
|
|||||||
"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w - - 0 1",
|
"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w - - 0 1",
|
||||||
"6k1/4pp1p/3p2p1/P1pPb3/R7/1r2P1PP/3B1P2/6K1 w - - 0 1",
|
"6k1/4pp1p/3p2p1/P1pPb3/R7/1r2P1PP/3B1P2/6K1 w - - 0 1",
|
||||||
"8/3p3B/5p2/5P2/p7/PP5b/k7/6K1 w - - 0 1",
|
"8/3p3B/5p2/5P2/p7/PP5b/k7/6K1 w - - 0 1",
|
||||||
|
"5rk1/q6p/2p3bR/1pPp1rP1/1P1Pp3/P3B1Q1/1K3P2/R7 w - - 93 90",
|
||||||
|
"4rrk1/1p1nq3/p7/2p1P1pp/3P2bp/3Q1Bn1/PPPB4/1K2R1NR w - - 40 21",
|
||||||
|
"r3k2r/3nnpbp/q2pp1p1/p7/Pp1PPPP1/4BNN1/1P5P/R2Q1RK1 w kq - 0 16",
|
||||||
|
"3Qb1k1/1r2ppb1/pN1n2q1/Pp1Pp1Pr/4P2p/4BP2/4B1R1/1R5K b - - 11 40",
|
||||||
|
|
||||||
// 5-man positions
|
// 5-man positions
|
||||||
"8/8/8/8/5kp1/P7/8/1K1N4 w - - 0 1", // Kc2 - mate
|
"8/8/8/8/5kp1/P7/8/1K1N4 w - - 0 1", // Kc2 - mate
|
||||||
@@ -76,24 +77,38 @@ const vector<string> Defaults = {
|
|||||||
"8/8/3P3k/8/1p6/8/1P6/1K3n2 b - - 0 1", // Nd2 - draw
|
"8/8/3P3k/8/1p6/8/1P6/1K3n2 b - - 0 1", // Nd2 - draw
|
||||||
|
|
||||||
// 7-man positions
|
// 7-man positions
|
||||||
"8/R7/2q5/8/6k1/8/1P5p/K6R w - - 0 124" // Draw
|
"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
|
} // 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 is
|
/// where to look for positions in FEN format and the type of the limit:
|
||||||
/// depth 13), an optional file name where to look for positions in FEN
|
/// depth, perft, nodes and movetime (in millisecs).
|
||||||
/// format (defaults are the positions defined above) and the type of the
|
///
|
||||||
/// limit value: depth (default), time in millisecs or number of nodes.
|
/// bench -> search default positions up to depth 13
|
||||||
|
/// bench 64 1 15 -> search default positions up to depth 15 (TT = 64MB)
|
||||||
|
/// bench 64 4 5000 current movetime -> search current position with 4 threads for 5 sec
|
||||||
|
/// bench 64 1 100000 default nodes -> search default positions for 100K nodes each
|
||||||
|
/// bench 16 1 5 default perft -> run a perft 5 on default positions
|
||||||
|
|
||||||
void benchmark(const Position& current, istream& is) {
|
vector<string> setup_bench(const Position& current, istream& is) {
|
||||||
|
|
||||||
string token;
|
vector<string> fens, list;
|
||||||
vector<string> fens;
|
string go, token;
|
||||||
Search::LimitsType limits;
|
|
||||||
|
|
||||||
// Assign default values to missing arguments
|
// Assign default values to missing arguments
|
||||||
string ttSize = (is >> token) ? token : "16";
|
string ttSize = (is >> token) ? token : "16";
|
||||||
@@ -102,21 +117,7 @@ void benchmark(const Position& current, istream& is) {
|
|||||||
string fenFile = (is >> token) ? token : "default";
|
string fenFile = (is >> token) ? token : "default";
|
||||||
string limitType = (is >> token) ? token : "depth";
|
string limitType = (is >> token) ? token : "depth";
|
||||||
|
|
||||||
Options["Hash"] = ttSize;
|
go = limitType == "eval" ? "eval" : "go " + limitType + " " + limit;
|
||||||
Options["Threads"] = threads;
|
|
||||||
Search::clear();
|
|
||||||
|
|
||||||
if (limitType == "time")
|
|
||||||
limits.movetime = stoi(limit); // movetime is in millisecs
|
|
||||||
|
|
||||||
else if (limitType == "nodes")
|
|
||||||
limits.nodes = stoi(limit);
|
|
||||||
|
|
||||||
else if (limitType == "mate")
|
|
||||||
limits.mate = stoi(limit);
|
|
||||||
|
|
||||||
else
|
|
||||||
limits.depth = stoi(limit);
|
|
||||||
|
|
||||||
if (fenFile == "default")
|
if (fenFile == "default")
|
||||||
fens = Defaults;
|
fens = Defaults;
|
||||||
@@ -132,7 +133,7 @@ void benchmark(const Position& current, istream& is) {
|
|||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
cerr << "Unable to open file " << fenFile << endl;
|
cerr << "Unable to open file " << fenFile << endl;
|
||||||
return;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (getline(file, fen))
|
while (getline(file, fen))
|
||||||
@@ -142,34 +143,18 @@ void benchmark(const Position& current, istream& is) {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t nodes = 0;
|
list.emplace_back("setoption name Threads value " + threads);
|
||||||
TimePoint elapsed = now();
|
list.emplace_back("setoption name Hash value " + ttSize);
|
||||||
|
list.emplace_back("ucinewgame");
|
||||||
for (size_t i = 0; i < fens.size(); ++i)
|
|
||||||
{
|
|
||||||
Position pos(fens[i], Options["UCI_Chess960"], Threads.main());
|
|
||||||
|
|
||||||
cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl;
|
|
||||||
|
|
||||||
if (limitType == "perft")
|
|
||||||
nodes += Search::perft(pos, limits.depth * ONE_PLY);
|
|
||||||
|
|
||||||
|
for (const string& fen : fens)
|
||||||
|
if (fen.find("setoption") != string::npos)
|
||||||
|
list.emplace_back(fen);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Search::StateStackPtr st;
|
list.emplace_back("position fen " + fen);
|
||||||
limits.startTime = now();
|
list.emplace_back(go);
|
||||||
Threads.start_thinking(pos, limits, st);
|
|
||||||
Threads.main()->wait_for_search_finished();
|
|
||||||
nodes += Threads.nodes_searched();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
return list;
|
||||||
|
|
||||||
dbg_print(); // Just before to exit
|
|
||||||
|
|
||||||
cerr << "\n==========================="
|
|
||||||
<< "\nTotal time (ms) : " << elapsed
|
|
||||||
<< "\nNodes searched : " << nodes
|
|
||||||
<< "\nNodes/second : " << 1000 * nodes / elapsed << endl;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-20
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -28,8 +27,9 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// There are 24 possible pawn squares: the first 4 files and ranks from 2 to 7
|
// There are 24 possible pawn squares: files A to D and ranks from 2 to 7.
|
||||||
const unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
// Positions with the pawn on files E to H will be mirrored before probing.
|
||||||
|
constexpr unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
||||||
|
|
||||||
// Each uint32_t stores results of 32 positions, one per bit
|
// Each uint32_t stores results of 32 positions, one per bit
|
||||||
uint32_t KPKBitbase[MAX_INDEX / 32];
|
uint32_t KPKBitbase[MAX_INDEX / 32];
|
||||||
@@ -44,7 +44,7 @@ namespace {
|
|||||||
// bit 13-14: white pawn file (from FILE_A to FILE_D)
|
// bit 13-14: white pawn file (from FILE_A to FILE_D)
|
||||||
// bit 15-17: white pawn RANK_7 - rank (from RANK_7 - RANK_7 to RANK_7 - RANK_2)
|
// bit 15-17: white pawn RANK_7 - rank (from RANK_7 - RANK_7 to RANK_7 - RANK_2)
|
||||||
unsigned index(Color us, Square bksq, Square wksq, Square psq) {
|
unsigned index(Color us, Square bksq, Square wksq, Square psq) {
|
||||||
return wksq | (bksq << 6) | (us << 12) | (file_of(psq) << 13) | ((RANK_7 - rank_of(psq)) << 15);
|
return int(wksq) | (bksq << 6) | (us << 12) | (file_of(psq) << 13) | ((RANK_7 - rank_of(psq)) << 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Result {
|
enum Result {
|
||||||
@@ -111,27 +111,27 @@ namespace {
|
|||||||
ksq[WHITE] = Square((idx >> 0) & 0x3F);
|
ksq[WHITE] = Square((idx >> 0) & 0x3F);
|
||||||
ksq[BLACK] = Square((idx >> 6) & 0x3F);
|
ksq[BLACK] = Square((idx >> 6) & 0x3F);
|
||||||
us = Color ((idx >> 12) & 0x01);
|
us = Color ((idx >> 12) & 0x01);
|
||||||
psq = make_square(File((idx >> 13) & 0x3), RANK_7 - Rank((idx >> 15) & 0x7));
|
psq = make_square(File((idx >> 13) & 0x3), Rank(RANK_7 - ((idx >> 15) & 0x7)));
|
||||||
|
|
||||||
// Check if two pieces are on the same square or if a king can be captured
|
// Check if two pieces are on the same square or if a king can be captured
|
||||||
if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
|
if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
|
||||||
|| ksq[WHITE] == psq
|
|| ksq[WHITE] == psq
|
||||||
|| ksq[BLACK] == psq
|
|| ksq[BLACK] == psq
|
||||||
|| (us == WHITE && (StepAttacksBB[PAWN][psq] & ksq[BLACK])))
|
|| (us == WHITE && (PawnAttacks[WHITE][psq] & ksq[BLACK])))
|
||||||
result = INVALID;
|
result = INVALID;
|
||||||
|
|
||||||
// Immediate win if a pawn can be promoted without getting captured
|
// Immediate win if a pawn can be promoted without getting captured
|
||||||
else if ( us == WHITE
|
else if ( us == WHITE
|
||||||
&& rank_of(psq) == RANK_7
|
&& rank_of(psq) == RANK_7
|
||||||
&& ksq[us] != psq + DELTA_N
|
&& ksq[us] != psq + NORTH
|
||||||
&& ( distance(ksq[~us], psq + DELTA_N) > 1
|
&& ( distance(ksq[~us], psq + NORTH) > 1
|
||||||
|| (StepAttacksBB[KING][ksq[us]] & (psq + DELTA_N))))
|
|| (PseudoAttacks[KING][ksq[us]] & (psq + NORTH))))
|
||||||
result = WIN;
|
result = WIN;
|
||||||
|
|
||||||
// Immediate draw if it is a stalemate or a king captures undefended pawn
|
// Immediate draw if it is a stalemate or a king captures undefended pawn
|
||||||
else if ( us == BLACK
|
else if ( us == BLACK
|
||||||
&& ( !(StepAttacksBB[KING][ksq[us]] & ~(StepAttacksBB[KING][ksq[~us]] | StepAttacksBB[PAWN][psq]))
|
&& ( !(PseudoAttacks[KING][ksq[us]] & ~(PseudoAttacks[KING][ksq[~us]] | PawnAttacks[~us][psq]))
|
||||||
|| (StepAttacksBB[KING][ksq[us]] & psq & ~StepAttacksBB[KING][ksq[~us]])))
|
|| (PseudoAttacks[KING][ksq[us]] & psq & ~PseudoAttacks[KING][ksq[~us]])))
|
||||||
result = DRAW;
|
result = DRAW;
|
||||||
|
|
||||||
// Position will be classified later
|
// Position will be classified later
|
||||||
@@ -152,12 +152,12 @@ namespace {
|
|||||||
// as WIN, the position is classified as WIN, otherwise the current position is
|
// as WIN, the position is classified as WIN, otherwise the current position is
|
||||||
// classified as UNKNOWN.
|
// classified as UNKNOWN.
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Result Good = (Us == WHITE ? WIN : DRAW);
|
constexpr Result Good = (Us == WHITE ? WIN : DRAW);
|
||||||
const Result Bad = (Us == WHITE ? DRAW : WIN);
|
constexpr Result Bad = (Us == WHITE ? DRAW : WIN);
|
||||||
|
|
||||||
Result r = INVALID;
|
Result r = INVALID;
|
||||||
Bitboard b = StepAttacksBB[KING][ksq[Us]];
|
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)]
|
r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)]
|
||||||
@@ -166,12 +166,12 @@ namespace {
|
|||||||
if (Us == WHITE)
|
if (Us == WHITE)
|
||||||
{
|
{
|
||||||
if (rank_of(psq) < RANK_7) // Single push
|
if (rank_of(psq) < RANK_7) // Single push
|
||||||
r |= db[index(Them, ksq[Them], ksq[Us], psq + DELTA_N)];
|
r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH)];
|
||||||
|
|
||||||
if ( rank_of(psq) == RANK_2 // Double push
|
if ( rank_of(psq) == RANK_2 // Double push
|
||||||
&& psq + DELTA_N != ksq[Us]
|
&& psq + NORTH != ksq[Us]
|
||||||
&& psq + DELTA_N != ksq[Them])
|
&& psq + NORTH != ksq[Them])
|
||||||
r |= db[index(Them, ksq[Them], ksq[Us], psq + DELTA_N + DELTA_N)];
|
r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH + NORTH)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad;
|
return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad;
|
||||||
|
|||||||
+73
-169
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,101 +19,30 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "bitcount.h"
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
int SquareDistance[SQUARE_NB][SQUARE_NB];
|
uint8_t PopCnt16[1 << 16];
|
||||||
|
uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
Bitboard RookMasks [SQUARE_NB];
|
|
||||||
Bitboard RookMagics [SQUARE_NB];
|
|
||||||
Bitboard* RookAttacks[SQUARE_NB];
|
|
||||||
unsigned RookShifts [SQUARE_NB];
|
|
||||||
|
|
||||||
Bitboard BishopMasks [SQUARE_NB];
|
|
||||||
Bitboard BishopMagics [SQUARE_NB];
|
|
||||||
Bitboard* BishopAttacks[SQUARE_NB];
|
|
||||||
unsigned BishopShifts [SQUARE_NB];
|
|
||||||
|
|
||||||
Bitboard SquareBB[SQUARE_NB];
|
Bitboard SquareBB[SQUARE_NB];
|
||||||
Bitboard FileBB[FILE_NB];
|
|
||||||
Bitboard RankBB[RANK_NB];
|
|
||||||
Bitboard AdjacentFilesBB[FILE_NB];
|
|
||||||
Bitboard InFrontBB[COLOR_NB][RANK_NB];
|
|
||||||
Bitboard StepAttacksBB[PIECE_NB][SQUARE_NB];
|
|
||||||
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
|
||||||
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||||
Bitboard DistanceRingBB[SQUARE_NB][8];
|
|
||||||
Bitboard ForwardBB[COLOR_NB][SQUARE_NB];
|
|
||||||
Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
|
||||||
Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
|
||||||
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
||||||
|
Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||||
|
|
||||||
|
Magic RookMagics[SQUARE_NB];
|
||||||
|
Magic BishopMagics[SQUARE_NB];
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// De Bruijn sequences. See chessprogramming.wikispaces.com/BitScan
|
|
||||||
const uint64_t DeBruijn64 = 0x3F79D71B4CB0A89ULL;
|
|
||||||
const uint32_t DeBruijn32 = 0x783A9B23;
|
|
||||||
|
|
||||||
int MSBTable[256]; // To implement software msb()
|
|
||||||
Square BSFTable[SQUARE_NB]; // To implement software bitscan
|
|
||||||
Bitboard RookTable[0x19000]; // To store rook attacks
|
Bitboard RookTable[0x19000]; // To store rook attacks
|
||||||
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
||||||
|
|
||||||
typedef unsigned (Fn)(Square, Bitboard);
|
void init_magics(Bitboard table[], Magic magics[], Direction directions[]);
|
||||||
|
|
||||||
void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
|
|
||||||
Bitboard masks[], unsigned shifts[], Square deltas[], Fn index);
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef USE_BSFQ
|
|
||||||
|
|
||||||
/// Software fall-back of lsb() and msb() for CPU lacking hardware support
|
|
||||||
|
|
||||||
Square lsb(Bitboard b) {
|
|
||||||
return BSFTable[bsf_index(b)];
|
|
||||||
}
|
|
||||||
|
|
||||||
Square msb(Bitboard b) {
|
|
||||||
|
|
||||||
unsigned b32;
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
if (b > 0xFFFFFFFF)
|
|
||||||
{
|
|
||||||
b >>= 32;
|
|
||||||
result = 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
b32 = unsigned(b);
|
|
||||||
|
|
||||||
if (b32 > 0xFFFF)
|
|
||||||
{
|
|
||||||
b32 >>= 16;
|
|
||||||
result += 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b32 > 0xFF)
|
|
||||||
{
|
|
||||||
b32 >>= 8;
|
|
||||||
result += 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Square(result + MSBTable[b32]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ifndef USE_BSFQ
|
|
||||||
|
|
||||||
|
|
||||||
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
|
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
|
||||||
/// to be printed to standard output. Useful for debugging.
|
/// to be printed to standard output. Useful for debugging.
|
||||||
@@ -139,91 +68,67 @@ const std::string Bitboards::pretty(Bitboard b) {
|
|||||||
|
|
||||||
void Bitboards::init() {
|
void Bitboards::init() {
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < (1 << 16); ++i)
|
||||||
|
PopCnt16[i] = std::bitset<16>(i).count();
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
SquareBB[s] = (1ULL << s);
|
||||||
SquareBB[s] = 1ULL << s;
|
|
||||||
BSFTable[bsf_index(SquareBB[s])] = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Bitboard b = 2; b < 256; ++b)
|
|
||||||
MSBTable[b] = MSBTable[b - 1] + !more_than_one(b);
|
|
||||||
|
|
||||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
|
||||||
FileBB[f] = f > FILE_A ? FileBB[f - 1] << 1 : FileABB;
|
|
||||||
|
|
||||||
for (Rank r = RANK_1; r <= RANK_8; ++r)
|
|
||||||
RankBB[r] = r > RANK_1 ? RankBB[r - 1] << 8 : Rank1BB;
|
|
||||||
|
|
||||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
|
||||||
AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0);
|
|
||||||
|
|
||||||
for (Rank r = RANK_1; r < RANK_8; ++r)
|
|
||||||
InFrontBB[WHITE][r] = ~(InFrontBB[BLACK][r + 1] = InFrontBB[BLACK][r] | RankBB[r]);
|
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
|
||||||
{
|
|
||||||
ForwardBB[c][s] = InFrontBB[c][rank_of(s)] & FileBB[file_of(s)];
|
|
||||||
PawnAttackSpan[c][s] = InFrontBB[c][rank_of(s)] & AdjacentFilesBB[file_of(s)];
|
|
||||||
PassedPawnMask[c][s] = ForwardBB[c][s] | PawnAttackSpan[c][s];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||||
if (s1 != s2)
|
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
|
||||||
{
|
|
||||||
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
|
|
||||||
DistanceRingBB[s1][SquareDistance[s1][s2] - 1] |= s2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int steps[][9] = { {}, { 7, 9 }, { 17, 15, 10, 6, -6, -10, -15, -17 },
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{}, {}, {}, { 9, 7, -7, -9, 8, 1, -1, -8 } };
|
{
|
||||||
|
PawnAttacks[WHITE][s] = pawn_attacks_bb<WHITE>(square_bb(s));
|
||||||
|
PawnAttacks[BLACK][s] = pawn_attacks_bb<BLACK>(square_bb(s));
|
||||||
|
}
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
// Helper returning the target bitboard of a step from a square
|
||||||
for (PieceType pt = PAWN; pt <= KING; ++pt)
|
auto landing_square_bb = [&](Square s, int step)
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
{
|
||||||
for (int i = 0; steps[pt][i]; ++i)
|
Square to = Square(s + step);
|
||||||
{
|
return is_ok(to) && distance(s, to) <= 2 ? square_bb(to) : Bitboard(0);
|
||||||
Square to = s + Square(c == WHITE ? steps[pt][i] : -steps[pt][i]);
|
};
|
||||||
|
|
||||||
if (is_ok(to) && distance(s, to) < 3)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
StepAttacksBB[make_piece(c, pt)][s] |= to;
|
{
|
||||||
}
|
for (int step : {-9, -8, -7, -1, 1, 7, 8, 9} )
|
||||||
|
PseudoAttacks[KING][s] |= landing_square_bb(s, step);
|
||||||
|
|
||||||
Square RookDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
|
for (int step : {-17, -15, -10, -6, 6, 10, 15, 17} )
|
||||||
Square BishopDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW };
|
PseudoAttacks[KNIGHT][s] |= landing_square_bb(s, step);
|
||||||
|
}
|
||||||
|
|
||||||
init_magics(RookTable, RookAttacks, RookMagics, RookMasks, RookShifts, RookDeltas, magic_index<ROOK>);
|
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
|
||||||
init_magics(BishopTable, BishopAttacks, BishopMagics, BishopMasks, BishopShifts, BishopDeltas, magic_index<BISHOP>);
|
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)
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||||
{
|
{
|
||||||
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
||||||
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
||||||
|
|
||||||
for (Piece pc = W_BISHOP; pc <= W_ROOK; ++pc)
|
for (PieceType pt : { BISHOP, ROOK })
|
||||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||||
{
|
if (PseudoAttacks[pt][s1] & s2)
|
||||||
if (!(PseudoAttacks[pc][s1] & s2))
|
LineBB[s1][s2] = (attacks_bb(pt, s1, 0) & attacks_bb(pt, s2, 0)) | s1 | s2;
|
||||||
continue;
|
|
||||||
|
|
||||||
LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
|
|
||||||
BetweenBB[s1][s2] = attacks_bb(pc, s1, SquareBB[s2]) & attacks_bb(pc, s2, SquareBB[s1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
Bitboard sliding_attack(Square deltas[], Square sq, Bitboard occupied) {
|
Bitboard sliding_attack(Direction directions[], Square sq, Bitboard occupied) {
|
||||||
|
|
||||||
Bitboard attack = 0;
|
Bitboard attack = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
for (Square s = sq + deltas[i];
|
for (Square s = sq + directions[i];
|
||||||
is_ok(s) && distance(s, s - deltas[i]) == 1;
|
is_ok(s) && distance(s, s - directions[i]) == 1;
|
||||||
s += deltas[i])
|
s += directions[i])
|
||||||
{
|
{
|
||||||
attack |= s;
|
attack |= s;
|
||||||
|
|
||||||
@@ -237,20 +142,17 @@ namespace {
|
|||||||
|
|
||||||
// init_magics() computes all rook and bishop attacks at startup. Magic
|
// init_magics() computes all rook and bishop attacks at startup. Magic
|
||||||
// bitboards are used to look up attacks of sliding pieces. As a reference see
|
// bitboards are used to look up attacks of sliding pieces. As a reference see
|
||||||
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
|
// www.chessprogramming.org/Magic_Bitboards. In particular, here we use the so
|
||||||
// use the so called "fancy" approach.
|
// called "fancy" approach.
|
||||||
|
|
||||||
void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
|
void init_magics(Bitboard table[], Magic magics[], Direction directions[]) {
|
||||||
Bitboard masks[], unsigned shifts[], Square deltas[], Fn index) {
|
|
||||||
|
|
||||||
|
// Optimal PRNG seeds to pick the correct magics in the shortest time
|
||||||
int seeds[][RANK_NB] = { { 8977, 44560, 54343, 38998, 5731, 95205, 104912, 17020 },
|
int seeds[][RANK_NB] = { { 8977, 44560, 54343, 38998, 5731, 95205, 104912, 17020 },
|
||||||
{ 728, 10316, 55013, 32803, 12281, 15100, 16645, 255 } };
|
{ 728, 10316, 55013, 32803, 12281, 15100, 16645, 255 } };
|
||||||
|
|
||||||
Bitboard occupancy[4096], reference[4096], edges, b;
|
Bitboard occupancy[4096], reference[4096], edges, b;
|
||||||
int age[4096] = {0}, current = 0, i, size;
|
int epoch[4096] = {}, cnt = 0, size = 0;
|
||||||
|
|
||||||
// attacks[s] is a pointer to the beginning of the attacks table for square 's'
|
|
||||||
attacks[SQ_A1] = table;
|
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
@@ -262,28 +164,28 @@ namespace {
|
|||||||
// all the attacks for each possible subset of the mask and so is 2 power
|
// all the attacks for each possible subset of the mask and so is 2 power
|
||||||
// the number of 1s of the mask. Hence we deduce the size of the shift to
|
// 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.
|
// apply to the 64 or 32 bits word to get the index.
|
||||||
masks[s] = sliding_attack(deltas, s, 0) & ~edges;
|
Magic& m = magics[s];
|
||||||
shifts[s] = (Is64Bit ? 64 : 32) - popcount<Max15>(masks[s]);
|
m.mask = sliding_attack(directions, s, 0) & ~edges;
|
||||||
|
m.shift = (Is64Bit ? 64 : 32) - popcount(m.mask);
|
||||||
|
|
||||||
|
// Set the offset for the attacks table of the square. We have individual
|
||||||
|
// table sizes for each square with "Fancy Magic Bitboards".
|
||||||
|
m.attacks = s == SQ_A1 ? table : magics[s - 1].attacks + size;
|
||||||
|
|
||||||
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and
|
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and
|
||||||
// store the corresponding sliding attack bitboard in reference[].
|
// store the corresponding sliding attack bitboard in reference[].
|
||||||
b = size = 0;
|
b = size = 0;
|
||||||
do {
|
do {
|
||||||
occupancy[size] = b;
|
occupancy[size] = b;
|
||||||
reference[size] = sliding_attack(deltas, s, b);
|
reference[size] = sliding_attack(directions, s, b);
|
||||||
|
|
||||||
if (HasPext)
|
if (HasPext)
|
||||||
attacks[s][pext(b, masks[s])] = reference[size];
|
m.attacks[pext(b, m.mask)] = reference[size];
|
||||||
|
|
||||||
size++;
|
size++;
|
||||||
b = (b - masks[s]) & masks[s];
|
b = (b - m.mask) & m.mask;
|
||||||
} while (b);
|
} while (b);
|
||||||
|
|
||||||
// Set the offset for the table of the next square. We have individual
|
|
||||||
// table sizes for each square with "Fancy Magic Bitboards".
|
|
||||||
if (s < SQ_H8)
|
|
||||||
attacks[s + 1] = attacks[s] + size;
|
|
||||||
|
|
||||||
if (HasPext)
|
if (HasPext)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -291,28 +193,30 @@ namespace {
|
|||||||
|
|
||||||
// Find a magic for square 's' picking up an (almost) random number
|
// Find a magic for square 's' picking up an (almost) random number
|
||||||
// until we find the one that passes the verification test.
|
// until we find the one that passes the verification test.
|
||||||
do {
|
for (int i = 0; i < size; )
|
||||||
do
|
{
|
||||||
magics[s] = rng.sparse_rand<Bitboard>();
|
for (m.magic = 0; popcount((m.magic * m.mask) >> 56) < 6; )
|
||||||
while (popcount<Max15>((magics[s] * masks[s]) >> 56) < 6);
|
m.magic = rng.sparse_rand<Bitboard>();
|
||||||
|
|
||||||
// A good magic must map every possible occupancy to an index that
|
// A good magic must map every possible occupancy to an index that
|
||||||
// looks up the correct sliding attack in the attacks[s] database.
|
// looks up the correct sliding attack in the attacks[s] database.
|
||||||
// Note that we build up the database for square 's' as a side
|
// Note that we build up the database for square 's' as a side
|
||||||
// effect of verifying the magic.
|
// effect of verifying the magic. Keep track of the attempt count
|
||||||
for (++current, i = 0; i < size; ++i)
|
// and save it in epoch[], little speed-up trick to avoid resetting
|
||||||
|
// m.attacks[] after every failed attempt.
|
||||||
|
for (++cnt, i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
unsigned idx = index(s, occupancy[i]);
|
unsigned idx = m.index(occupancy[i]);
|
||||||
|
|
||||||
if (age[idx] < current)
|
if (epoch[idx] < cnt)
|
||||||
{
|
{
|
||||||
age[idx] = current;
|
epoch[idx] = cnt;
|
||||||
attacks[s][idx] = reference[i];
|
m.attacks[idx] = reference[i];
|
||||||
}
|
}
|
||||||
else if (attacks[s][idx] != reference[i])
|
else if (m.attacks[idx] != reference[i])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (i < size);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+213
-155
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -39,164 +39,203 @@ const std::string pretty(Bitboard b);
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
constexpr Bitboard AllSquares = ~Bitboard(0);
|
||||||
|
constexpr Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
constexpr Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
const Bitboard FileBBB = FileABB << 1;
|
constexpr Bitboard FileBBB = FileABB << 1;
|
||||||
const Bitboard FileCBB = FileABB << 2;
|
constexpr Bitboard FileCBB = FileABB << 2;
|
||||||
const Bitboard FileDBB = FileABB << 3;
|
constexpr Bitboard FileDBB = FileABB << 3;
|
||||||
const Bitboard FileEBB = FileABB << 4;
|
constexpr Bitboard FileEBB = FileABB << 4;
|
||||||
const Bitboard FileFBB = FileABB << 5;
|
constexpr Bitboard FileFBB = FileABB << 5;
|
||||||
const Bitboard FileGBB = FileABB << 6;
|
constexpr Bitboard FileGBB = FileABB << 6;
|
||||||
const Bitboard FileHBB = FileABB << 7;
|
constexpr Bitboard FileHBB = FileABB << 7;
|
||||||
|
|
||||||
const Bitboard Rank1BB = 0xFF;
|
constexpr Bitboard Rank1BB = 0xFF;
|
||||||
const Bitboard Rank2BB = Rank1BB << (8 * 1);
|
constexpr Bitboard Rank2BB = Rank1BB << (8 * 1);
|
||||||
const Bitboard Rank3BB = Rank1BB << (8 * 2);
|
constexpr Bitboard Rank3BB = Rank1BB << (8 * 2);
|
||||||
const Bitboard Rank4BB = Rank1BB << (8 * 3);
|
constexpr Bitboard Rank4BB = Rank1BB << (8 * 3);
|
||||||
const Bitboard Rank5BB = Rank1BB << (8 * 4);
|
constexpr Bitboard Rank5BB = Rank1BB << (8 * 4);
|
||||||
const Bitboard Rank6BB = Rank1BB << (8 * 5);
|
constexpr Bitboard Rank6BB = Rank1BB << (8 * 5);
|
||||||
const Bitboard Rank7BB = Rank1BB << (8 * 6);
|
constexpr Bitboard Rank7BB = Rank1BB << (8 * 6);
|
||||||
const Bitboard Rank8BB = Rank1BB << (8 * 7);
|
constexpr Bitboard Rank8BB = Rank1BB << (8 * 7);
|
||||||
|
|
||||||
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
|
constexpr Bitboard QueenSide = FileABB | FileBBB | FileCBB | FileDBB;
|
||||||
|
constexpr Bitboard CenterFiles = FileCBB | FileDBB | FileEBB | FileFBB;
|
||||||
|
constexpr Bitboard KingSide = FileEBB | FileFBB | FileGBB | FileHBB;
|
||||||
|
constexpr Bitboard Center = (FileDBB | FileEBB) & (Rank4BB | Rank5BB);
|
||||||
|
|
||||||
extern Bitboard RookMasks [SQUARE_NB];
|
constexpr Bitboard KingFlank[FILE_NB] = {
|
||||||
extern Bitboard RookMagics [SQUARE_NB];
|
QueenSide ^ FileDBB, QueenSide, QueenSide,
|
||||||
extern Bitboard* RookAttacks[SQUARE_NB];
|
CenterFiles, CenterFiles,
|
||||||
extern unsigned RookShifts [SQUARE_NB];
|
KingSide, KingSide, KingSide ^ FileEBB
|
||||||
|
};
|
||||||
|
|
||||||
extern Bitboard BishopMasks [SQUARE_NB];
|
extern uint8_t PopCnt16[1 << 16];
|
||||||
extern Bitboard BishopMagics [SQUARE_NB];
|
extern uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
extern Bitboard* BishopAttacks[SQUARE_NB];
|
|
||||||
extern unsigned BishopShifts [SQUARE_NB];
|
|
||||||
|
|
||||||
extern Bitboard SquareBB[SQUARE_NB];
|
extern Bitboard SquareBB[SQUARE_NB];
|
||||||
extern Bitboard FileBB[FILE_NB];
|
|
||||||
extern Bitboard RankBB[RANK_NB];
|
|
||||||
extern Bitboard AdjacentFilesBB[FILE_NB];
|
|
||||||
extern Bitboard InFrontBB[COLOR_NB][RANK_NB];
|
|
||||||
extern Bitboard StepAttacksBB[PIECE_NB][SQUARE_NB];
|
|
||||||
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
|
||||||
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||||
extern Bitboard DistanceRingBB[SQUARE_NB][8];
|
|
||||||
extern Bitboard ForwardBB[COLOR_NB][SQUARE_NB];
|
|
||||||
extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
|
||||||
extern Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
|
||||||
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
||||||
|
extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||||
|
|
||||||
|
|
||||||
|
/// Magic holds all magic bitboards relevant data for a single square
|
||||||
|
struct Magic {
|
||||||
|
Bitboard mask;
|
||||||
|
Bitboard magic;
|
||||||
|
Bitboard* attacks;
|
||||||
|
unsigned shift;
|
||||||
|
|
||||||
|
// Compute the attack's index using the 'magic bitboards' approach
|
||||||
|
unsigned index(Bitboard occupied) const {
|
||||||
|
|
||||||
|
if (HasPext)
|
||||||
|
return unsigned(pext(occupied, mask));
|
||||||
|
|
||||||
|
if (Is64Bit)
|
||||||
|
return unsigned(((occupied & mask) * magic) >> shift);
|
||||||
|
|
||||||
|
unsigned lo = unsigned(occupied) & unsigned(mask);
|
||||||
|
unsigned hi = unsigned(occupied >> 32) & unsigned(mask >> 32);
|
||||||
|
return (lo * unsigned(magic) ^ hi * unsigned(magic >> 32)) >> shift;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Magic RookMagics[SQUARE_NB];
|
||||||
|
extern Magic BishopMagics[SQUARE_NB];
|
||||||
|
|
||||||
|
inline Bitboard square_bb(Square s) {
|
||||||
|
assert(s >= SQ_A1 && s <= SQ_H8);
|
||||||
|
return SquareBB[s];
|
||||||
|
}
|
||||||
|
|
||||||
/// Overloads of bitwise operators between a Bitboard and a Square for testing
|
/// Overloads of bitwise operators between a Bitboard and a Square for testing
|
||||||
/// whether a given bit is set in a bitboard, and for setting and clearing bits.
|
/// whether a given bit is set in a bitboard, and for setting and clearing bits.
|
||||||
|
|
||||||
inline Bitboard operator&(Bitboard b, Square s) {
|
inline Bitboard operator&( Bitboard b, Square s) { return b & square_bb(s); }
|
||||||
return b & SquareBB[s];
|
inline Bitboard operator|( Bitboard b, Square s) { return b | square_bb(s); }
|
||||||
}
|
inline Bitboard operator^( Bitboard b, Square s) { return b ^ square_bb(s); }
|
||||||
|
inline Bitboard& operator|=(Bitboard& b, Square s) { return b |= square_bb(s); }
|
||||||
|
inline Bitboard& operator^=(Bitboard& b, Square s) { return b ^= square_bb(s); }
|
||||||
|
|
||||||
inline Bitboard operator|(Bitboard b, Square s) {
|
inline Bitboard operator&(Square s, Bitboard b) { return b & s; }
|
||||||
return b | SquareBB[s];
|
inline Bitboard operator|(Square s, Bitboard b) { return b | s; }
|
||||||
}
|
inline Bitboard operator^(Square s, Bitboard b) { return b ^ s; }
|
||||||
|
|
||||||
inline Bitboard operator^(Bitboard b, Square s) {
|
inline Bitboard operator|(Square s, Square s2) { return square_bb(s) | square_bb(s2); }
|
||||||
return b ^ SquareBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard& operator|=(Bitboard& b, Square s) {
|
constexpr bool more_than_one(Bitboard b) {
|
||||||
return b |= SquareBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard& operator^=(Bitboard& b, Square s) {
|
|
||||||
return b ^= SquareBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool more_than_one(Bitboard b) {
|
|
||||||
return b & (b - 1);
|
return b & (b - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool opposite_colors(Square s1, Square s2) {
|
||||||
|
return bool(DarkSquares & s1) != bool(DarkSquares & s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
||||||
/// the given file or rank.
|
/// the given file or rank.
|
||||||
|
|
||||||
inline Bitboard rank_bb(Rank r) {
|
inline Bitboard rank_bb(Rank r) {
|
||||||
return RankBB[r];
|
return Rank1BB << (8 * r);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard rank_bb(Square s) {
|
inline Bitboard rank_bb(Square s) {
|
||||||
return RankBB[rank_of(s)];
|
return rank_bb(rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard file_bb(File f) {
|
inline Bitboard file_bb(File f) {
|
||||||
return FileBB[f];
|
return FileABB << f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard file_bb(Square s) {
|
inline Bitboard file_bb(Square s) {
|
||||||
return FileBB[file_of(s)];
|
return file_bb(file_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// shift_bb() moves a bitboard one step along direction Delta. Mainly for pawns
|
/// shift() moves a bitboard one step along direction D
|
||||||
|
|
||||||
template<Square Delta>
|
template<Direction D>
|
||||||
inline Bitboard shift_bb(Bitboard b) {
|
constexpr Bitboard shift(Bitboard b) {
|
||||||
return Delta == DELTA_N ? b << 8 : Delta == DELTA_S ? b >> 8
|
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
|
||||||
: Delta == DELTA_NE ? (b & ~FileHBB) << 9 : Delta == DELTA_SE ? (b & ~FileHBB) >> 7
|
: D == NORTH+NORTH? b <<16 : D == SOUTH+SOUTH? b >>16
|
||||||
: Delta == DELTA_NW ? (b & ~FileABB) << 7 : Delta == DELTA_SW ? (b & ~FileABB) >> 9
|
: D == EAST ? (b & ~FileHBB) << 1 : D == WEST ? (b & ~FileABB) >> 1
|
||||||
|
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == NORTH_WEST ? (b & ~FileABB) << 7
|
||||||
|
: D == SOUTH_EAST ? (b & ~FileHBB) >> 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// pawn_attacks_bb() returns the squares attacked by pawns of the given color
|
||||||
|
/// from the squares in the given bitboard.
|
||||||
|
|
||||||
|
template<Color C>
|
||||||
|
constexpr Bitboard pawn_attacks_bb(Bitboard b) {
|
||||||
|
return C == WHITE ? shift<NORTH_WEST>(b) | shift<NORTH_EAST>(b)
|
||||||
|
: shift<SOUTH_WEST>(b) | shift<SOUTH_EAST>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// pawn_double_attacks_bb() returns the squares doubly attacked by pawns of the
|
||||||
|
/// given color from the squares in the given bitboard.
|
||||||
|
|
||||||
|
template<Color C>
|
||||||
|
constexpr Bitboard pawn_double_attacks_bb(Bitboard b) {
|
||||||
|
return C == WHITE ? shift<NORTH_WEST>(b) & shift<NORTH_EAST>(b)
|
||||||
|
: shift<SOUTH_WEST>(b) & shift<SOUTH_EAST>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// adjacent_files_bb() returns a bitboard representing all the squares on the
|
/// adjacent_files_bb() returns a bitboard representing all the squares on the
|
||||||
/// adjacent files of the given one.
|
/// adjacent files of the given one.
|
||||||
|
|
||||||
inline Bitboard adjacent_files_bb(File f) {
|
inline Bitboard adjacent_files_bb(Square s) {
|
||||||
return AdjacentFilesBB[f];
|
return shift<EAST>(file_bb(s)) | shift<WEST>(file_bb(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// between_bb() returns a bitboard representing all the squares between the two
|
/// between_bb() returns squares that are linearly between the given squares
|
||||||
/// given ones. For instance, between_bb(SQ_C4, SQ_F7) returns a bitboard with
|
/// If the given squares are not on a same file/rank/diagonal, return 0.
|
||||||
/// the bits for square d5 and e6 set. If s1 and s2 are not on the same rank, file
|
|
||||||
/// or diagonal, 0 is returned.
|
|
||||||
|
|
||||||
inline Bitboard between_bb(Square s1, Square s2) {
|
inline Bitboard between_bb(Square s1, Square s2) {
|
||||||
return BetweenBB[s1][s2];
|
return LineBB[s1][s2] & ( (AllSquares << (s1 + (s1 < s2)))
|
||||||
|
^(AllSquares << (s2 + !(s1 < s2))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// in_front_bb() returns a bitboard representing all the squares on all the ranks
|
/// forward_ranks_bb() returns a bitboard representing the squares on the ranks
|
||||||
/// in front of the given one, from the point of view of the given color. For
|
/// in front of the given one, from the point of view of the given color. For instance,
|
||||||
/// instance, in_front_bb(BLACK, RANK_3) will return the squares on ranks 1 and 2.
|
/// forward_ranks_bb(BLACK, SQ_D3) will return the 16 squares on ranks 1 and 2.
|
||||||
|
|
||||||
inline Bitboard in_front_bb(Color c, Rank r) {
|
inline Bitboard forward_ranks_bb(Color c, Square s) {
|
||||||
return InFrontBB[c][r];
|
return c == WHITE ? ~Rank1BB << 8 * (rank_of(s) - RANK_1)
|
||||||
|
: ~Rank8BB >> 8 * (RANK_8 - rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// forward_bb() returns a bitboard representing all the squares along the line
|
/// forward_file_bb() returns a bitboard representing all the squares along the
|
||||||
/// in front of the given one, from the point of view of the given color:
|
/// line in front of the given one, from the point of view of the given color.
|
||||||
/// ForwardBB[c][s] = in_front_bb(c, s) & file_bb(s)
|
|
||||||
|
|
||||||
inline Bitboard forward_bb(Color c, Square s) {
|
inline Bitboard forward_file_bb(Color c, Square s) {
|
||||||
return ForwardBB[c][s];
|
return forward_ranks_bb(c, s) & file_bb(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// pawn_attack_span() returns a bitboard representing all the squares that can be
|
/// pawn_attack_span() returns a bitboard representing all the squares that can
|
||||||
/// attacked by a pawn of the given color when it moves along its file, starting
|
/// be attacked by a pawn of the given color when it moves along its file,
|
||||||
/// from the given square:
|
/// starting from the given square.
|
||||||
/// PawnAttackSpan[c][s] = in_front_bb(c, s) & adjacent_files_bb(s);
|
|
||||||
|
|
||||||
inline Bitboard pawn_attack_span(Color c, Square s) {
|
inline Bitboard pawn_attack_span(Color c, Square s) {
|
||||||
return PawnAttackSpan[c][s];
|
return forward_ranks_bb(c, s) & adjacent_files_bb(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// passed_pawn_mask() returns a bitboard mask which can be used to test if a
|
/// passed_pawn_span() returns a bitboard which can be used to test if a pawn of
|
||||||
/// pawn of the given color and on the given square is a passed pawn:
|
/// the given color and on the given square is a passed pawn.
|
||||||
/// PassedPawnMask[c][s] = pawn_attack_span(c, s) | forward_bb(c, s)
|
|
||||||
|
|
||||||
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
inline Bitboard passed_pawn_span(Color c, Square s) {
|
||||||
return PassedPawnMask[c][s];
|
return forward_ranks_bb(c, s) & (adjacent_files_bb(s) | file_bb(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -209,107 +248,127 @@ inline bool aligned(Square s1, Square s2, Square s3) {
|
|||||||
|
|
||||||
|
|
||||||
/// distance() functions return the distance between x and y, defined as the
|
/// distance() functions return the distance between x and y, defined as the
|
||||||
/// number of steps for a king in x to reach y. Works with squares, ranks, files.
|
/// number of steps for a king in x to reach y.
|
||||||
|
|
||||||
template<typename T> inline int distance(T x, T y) { return x < y ? y - x : x - y; }
|
template<typename T1 = Square> inline int distance(Square x, Square y);
|
||||||
|
template<> inline int distance<File>(Square x, Square y) { return std::abs(file_of(x) - file_of(y)); }
|
||||||
|
template<> inline int distance<Rank>(Square x, Square y) { return std::abs(rank_of(x) - rank_of(y)); }
|
||||||
template<> inline int distance<Square>(Square x, Square y) { return SquareDistance[x][y]; }
|
template<> inline int distance<Square>(Square x, Square y) { return SquareDistance[x][y]; }
|
||||||
|
|
||||||
template<typename T1, typename T2> inline int distance(T2 x, T2 y);
|
template<class T> constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
|
||||||
template<> inline int distance<File>(Square x, Square y) { return distance(file_of(x), file_of(y)); }
|
return v < lo ? lo : v > hi ? hi : v;
|
||||||
template<> inline int distance<Rank>(Square x, Square y) { return distance(rank_of(x), rank_of(y)); }
|
}
|
||||||
|
|
||||||
|
|
||||||
/// attacks_bb() returns a bitboard representing all the squares attacked by a
|
/// attacks_bb() returns a bitboard representing all the squares attacked by a
|
||||||
/// piece of type Pt (bishop or rook) placed on 's'. The helper magic_index()
|
/// piece of type Pt (bishop or rook) placed on 's'.
|
||||||
/// looks up the index using the 'magic bitboards' approach.
|
|
||||||
template<PieceType Pt>
|
|
||||||
inline unsigned magic_index(Square s, Bitboard occupied) {
|
|
||||||
|
|
||||||
Bitboard* const Masks = Pt == ROOK ? RookMasks : BishopMasks;
|
|
||||||
Bitboard* const Magics = Pt == ROOK ? RookMagics : BishopMagics;
|
|
||||||
unsigned* const Shifts = Pt == ROOK ? RookShifts : BishopShifts;
|
|
||||||
|
|
||||||
if (HasPext)
|
|
||||||
return unsigned(pext(occupied, Masks[s]));
|
|
||||||
|
|
||||||
if (Is64Bit)
|
|
||||||
return unsigned(((occupied & Masks[s]) * Magics[s]) >> Shifts[s]);
|
|
||||||
|
|
||||||
unsigned lo = unsigned(occupied) & unsigned(Masks[s]);
|
|
||||||
unsigned hi = unsigned(occupied >> 32) & unsigned(Masks[s] >> 32);
|
|
||||||
return (lo * unsigned(Magics[s]) ^ hi * unsigned(Magics[s] >> 32)) >> Shifts[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
template<PieceType Pt>
|
template<PieceType Pt>
|
||||||
inline Bitboard attacks_bb(Square s, Bitboard occupied) {
|
inline Bitboard attacks_bb(Square s, Bitboard occupied) {
|
||||||
return (Pt == ROOK ? RookAttacks : BishopAttacks)[s][magic_index<Pt>(s, occupied)];
|
|
||||||
|
const Magic& m = Pt == ROOK ? RookMagics[s] : BishopMagics[s];
|
||||||
|
return m.attacks[m.index(occupied)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occupied) {
|
inline Bitboard attacks_bb(PieceType pt, Square s, Bitboard occupied) {
|
||||||
|
|
||||||
switch (type_of(pc))
|
assert(pt != PAWN);
|
||||||
|
|
||||||
|
switch (pt)
|
||||||
{
|
{
|
||||||
case BISHOP: return attacks_bb<BISHOP>(s, occupied);
|
case BISHOP: return attacks_bb<BISHOP>(s, occupied);
|
||||||
case ROOK : return attacks_bb<ROOK>(s, occupied);
|
case ROOK : return attacks_bb< ROOK>(s, occupied);
|
||||||
case QUEEN : return attacks_bb<BISHOP>(s, occupied) | attacks_bb<ROOK>(s, occupied);
|
case QUEEN : return attacks_bb<BISHOP>(s, occupied) | attacks_bb<ROOK>(s, occupied);
|
||||||
default : return StepAttacksBB[pc][s];
|
default : return PseudoAttacks[pt][s];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// popcount() counts the number of non-zero bits in a bitboard
|
||||||
|
|
||||||
|
inline int popcount(Bitboard b) {
|
||||||
|
|
||||||
|
#ifndef USE_POPCNT
|
||||||
|
|
||||||
|
union { Bitboard bb; uint16_t u[4]; } v = { b };
|
||||||
|
return PopCnt16[v.u[0]] + PopCnt16[v.u[1]] + PopCnt16[v.u[2]] + PopCnt16[v.u[3]];
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||||
|
|
||||||
|
return (int)_mm_popcnt_u64(b);
|
||||||
|
|
||||||
|
#else // Assumed gcc or compatible compiler
|
||||||
|
|
||||||
|
return __builtin_popcountll(b);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
|
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
|
||||||
|
|
||||||
#ifdef USE_BSFQ
|
#if defined(__GNUC__) // GCC, Clang, ICC
|
||||||
|
|
||||||
# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
|
|
||||||
|
|
||||||
inline Square lsb(Bitboard b) {
|
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(_MSC_VER) // MSVC
|
||||||
|
|
||||||
|
#ifdef _WIN64 // MSVC, WIN64
|
||||||
|
|
||||||
|
inline Square lsb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
unsigned long idx;
|
unsigned long idx;
|
||||||
_BitScanForward64(&idx, b);
|
_BitScanForward64(&idx, b);
|
||||||
return (Square) idx;
|
return (Square) idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square msb(Bitboard b) {
|
inline Square msb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
unsigned long idx;
|
unsigned long idx;
|
||||||
_BitScanReverse64(&idx, b);
|
_BitScanReverse64(&idx, b);
|
||||||
return (Square) idx;
|
return (Square) idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
# elif defined(__arm__)
|
#else // MSVC, WIN32
|
||||||
|
|
||||||
inline int lsb32(uint32_t v) {
|
|
||||||
__asm__("rbit %0, %1" : "=r"(v) : "r"(v));
|
|
||||||
return __builtin_clz(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square msb(Bitboard b) {
|
|
||||||
return (Square) (63 - __builtin_clzll(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square lsb(Bitboard b) {
|
inline Square lsb(Bitboard b) {
|
||||||
return (Square) (uint32_t(b) ? lsb32(uint32_t(b)) : 32 + lsb32(uint32_t(b >> 32)));
|
assert(b);
|
||||||
}
|
unsigned long idx;
|
||||||
|
|
||||||
# else // Assumed gcc or compatible compiler
|
if (b & 0xffffffff) {
|
||||||
|
_BitScanForward(&idx, int32_t(b));
|
||||||
inline Square lsb(Bitboard b) { // Assembly code by Heinz van Saanen
|
return Square(idx);
|
||||||
Bitboard idx;
|
} else {
|
||||||
__asm__("bsfq %1, %0": "=r"(idx): "rm"(b) );
|
_BitScanForward(&idx, int32_t(b >> 32));
|
||||||
return (Square) idx;
|
return Square(idx + 32);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square msb(Bitboard b) {
|
inline Square msb(Bitboard b) {
|
||||||
Bitboard idx;
|
assert(b);
|
||||||
__asm__("bsrq %1, %0": "=r"(idx): "rm"(b) );
|
unsigned long idx;
|
||||||
return (Square) idx;
|
|
||||||
|
if (b >> 32) {
|
||||||
|
_BitScanReverse(&idx, int32_t(b >> 32));
|
||||||
|
return Square(idx + 32);
|
||||||
|
} else {
|
||||||
|
_BitScanReverse(&idx, int32_t(b));
|
||||||
|
return Square(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
#else // ifdef(USE_BSFQ)
|
#else // Compiler is neither GCC nor MSVC compatible
|
||||||
|
|
||||||
Square lsb(Bitboard b);
|
#error "Compiler not supported."
|
||||||
Square msb(Bitboard b);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -323,10 +382,9 @@ inline Square pop_lsb(Bitboard* b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// frontmost_sq() and backmost_sq() return the square corresponding to the
|
/// frontmost_sq() returns the most advanced square for the given color
|
||||||
/// most/least advanced bit relative to the given color.
|
inline Square frontmost_sq(Color c, Bitboard b) {
|
||||||
|
return c == WHITE ? msb(b) : lsb(b);
|
||||||
inline Square frontmost_sq(Color c, Bitboard b) { return c == WHITE ? msb(b) : lsb(b); }
|
}
|
||||||
inline Square backmost_sq(Color c, Bitboard b) { return c == WHITE ? lsb(b) : msb(b); }
|
|
||||||
|
|
||||||
#endif // #ifndef BITBOARD_H_INCLUDED
|
#endif // #ifndef BITBOARD_H_INCLUDED
|
||||||
|
|||||||
-105
@@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2016 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 BITCOUNT_H_INCLUDED
|
|
||||||
#define BITCOUNT_H_INCLUDED
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
enum BitCountType {
|
|
||||||
CNT_64,
|
|
||||||
CNT_64_MAX15,
|
|
||||||
CNT_32,
|
|
||||||
CNT_32_MAX15,
|
|
||||||
CNT_HW_POPCNT
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Determine at compile time the best popcount<> specialization according to
|
|
||||||
/// whether the platform is 32 or 64 bit, the maximum number of non-zero
|
|
||||||
/// bits to count and if the hardware popcnt instruction is available.
|
|
||||||
const BitCountType Full = HasPopCnt ? CNT_HW_POPCNT : Is64Bit ? CNT_64 : CNT_32;
|
|
||||||
const BitCountType Max15 = HasPopCnt ? CNT_HW_POPCNT : Is64Bit ? CNT_64_MAX15 : CNT_32_MAX15;
|
|
||||||
|
|
||||||
|
|
||||||
/// popcount() counts the number of non-zero bits in a bitboard
|
|
||||||
template<BitCountType> inline int popcount(Bitboard);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_64>(Bitboard b) {
|
|
||||||
b -= (b >> 1) & 0x5555555555555555ULL;
|
|
||||||
b = ((b >> 2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
|
||||||
b = ((b >> 4) + b) & 0x0F0F0F0F0F0F0F0FULL;
|
|
||||||
return (b * 0x0101010101010101ULL) >> 56;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_64_MAX15>(Bitboard b) {
|
|
||||||
b -= (b >> 1) & 0x5555555555555555ULL;
|
|
||||||
b = ((b >> 2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
|
||||||
return (b * 0x1111111111111111ULL) >> 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_32>(Bitboard b) {
|
|
||||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
|
||||||
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
|
||||||
w -= (w >> 1) & 0x55555555;
|
|
||||||
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
|
||||||
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
|
||||||
v = ((v >> 4) + v + (w >> 4) + w) & 0x0F0F0F0F;
|
|
||||||
return (v * 0x01010101) >> 24;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_32_MAX15>(Bitboard b) {
|
|
||||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
|
||||||
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
|
||||||
w -= (w >> 1) & 0x55555555;
|
|
||||||
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
|
||||||
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
|
||||||
return ((v + w) * 0x11111111) >> 28;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_HW_POPCNT>(Bitboard b) {
|
|
||||||
|
|
||||||
#ifndef USE_POPCNT
|
|
||||||
|
|
||||||
assert(false);
|
|
||||||
return b != 0; // Avoid 'b not used' warning
|
|
||||||
|
|
||||||
#elif defined(_MSC_VER) && defined(__INTEL_COMPILER)
|
|
||||||
|
|
||||||
return _mm_popcnt_u64(b);
|
|
||||||
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
|
|
||||||
return (int)__popcnt64(b);
|
|
||||||
|
|
||||||
#else // Assumed gcc or compatible compiler
|
|
||||||
|
|
||||||
return __builtin_popcountll(b);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // #ifndef BITCOUNT_H_INCLUDED
|
|
||||||
+76
-115
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,11 +18,9 @@
|
|||||||
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 "endgame.h"
|
#include "endgame.h"
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
|
|
||||||
@@ -32,7 +30,7 @@ namespace {
|
|||||||
|
|
||||||
// Table used to drive the king towards the edge of the board
|
// Table used to drive the king towards the edge of the board
|
||||||
// in KX vs K and KQ vs KR endgames.
|
// in KX vs K and KQ vs KR endgames.
|
||||||
const int PushToEdges[SQUARE_NB] = {
|
constexpr int PushToEdges[SQUARE_NB] = {
|
||||||
100, 90, 80, 70, 70, 80, 90, 100,
|
100, 90, 80, 70, 70, 80, 90, 100,
|
||||||
90, 70, 60, 50, 50, 60, 70, 90,
|
90, 70, 60, 50, 50, 60, 70, 90,
|
||||||
80, 60, 40, 30, 30, 40, 60, 80,
|
80, 60, 40, 30, 30, 40, 60, 80,
|
||||||
@@ -45,23 +43,23 @@ namespace {
|
|||||||
|
|
||||||
// Table used to drive the king towards a corner square of the
|
// Table used to drive the king towards a corner square of the
|
||||||
// right color in KBN vs K endgames.
|
// right color in KBN vs K endgames.
|
||||||
const int PushToCorners[SQUARE_NB] = {
|
constexpr int PushToCorners[SQUARE_NB] = {
|
||||||
200, 190, 180, 170, 160, 150, 140, 130,
|
6400, 6080, 5760, 5440, 5120, 4800, 4480, 4160,
|
||||||
190, 180, 170, 160, 150, 140, 130, 140,
|
6080, 5760, 5440, 5120, 4800, 4480, 4160, 4480,
|
||||||
180, 170, 155, 140, 140, 125, 140, 150,
|
5760, 5440, 4960, 4480, 4480, 4000, 4480, 4800,
|
||||||
170, 160, 140, 120, 110, 140, 150, 160,
|
5440, 5120, 4480, 3840, 3520, 4480, 4800, 5120,
|
||||||
160, 150, 140, 110, 120, 140, 160, 170,
|
5120, 4800, 4480, 3520, 3840, 4480, 5120, 5440,
|
||||||
150, 140, 125, 140, 140, 155, 170, 180,
|
4800, 4480, 4000, 4480, 4480, 4960, 5440, 5760,
|
||||||
140, 130, 140, 150, 160, 170, 180, 190,
|
4480, 4160, 4480, 4800, 5120, 5440, 5760, 6080,
|
||||||
130, 140, 150, 160, 170, 180, 190, 200
|
4160, 4480, 4800, 5120, 5440, 5760, 6080, 6400
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tables used to drive a piece towards or away from another piece
|
// Tables used to drive a piece towards or away from another piece
|
||||||
const int PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
|
constexpr int PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
|
||||||
const int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
|
constexpr int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
|
||||||
|
|
||||||
// Pawn Rank based scaling factors used in KRPPKRP endgame
|
// Pawn Rank based scaling factors used in KRPPKRP endgame
|
||||||
const int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
|
constexpr int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
|
bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
|
||||||
@@ -76,64 +74,39 @@ namespace {
|
|||||||
assert(pos.count<PAWN>(strongSide) == 1);
|
assert(pos.count<PAWN>(strongSide) == 1);
|
||||||
|
|
||||||
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
|
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
|
||||||
sq = Square(sq ^ 7); // Mirror SQ_H1 -> SQ_A1
|
sq = Square(int(sq) ^ 7); // Mirror SQ_H1 -> SQ_A1
|
||||||
|
|
||||||
if (strongSide == BLACK)
|
return strongSide == WHITE ? sq : ~sq;
|
||||||
sq = ~sq;
|
|
||||||
|
|
||||||
return sq;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the material key of Position out of the given endgame key code
|
|
||||||
// like "KBPKN". The trick here is to first forge an ad-hoc FEN string
|
|
||||||
// and then let a Position object do the work for us.
|
|
||||||
Key key(const string& code, Color c) {
|
|
||||||
|
|
||||||
assert(code.length() > 0 && code.length() < 8);
|
|
||||||
assert(code[0] == 'K');
|
|
||||||
|
|
||||||
string sides[] = { code.substr(code.find('K', 1)), // Weak
|
|
||||||
code.substr(0, code.find('K', 1)) }; // Strong
|
|
||||||
|
|
||||||
std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
|
|
||||||
|
|
||||||
string fen = sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
|
|
||||||
+ sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";
|
|
||||||
|
|
||||||
return Position(fen, false, nullptr).material_key();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
/// Endgames members definitions
|
namespace Endgames {
|
||||||
|
|
||||||
Endgames::Endgames() {
|
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||||
|
|
||||||
add<KPK>("KPK");
|
void init() {
|
||||||
add<KNNK>("KNNK");
|
|
||||||
add<KBNK>("KBNK");
|
|
||||||
add<KRKP>("KRKP");
|
|
||||||
add<KRKB>("KRKB");
|
|
||||||
add<KRKN>("KRKN");
|
|
||||||
add<KQKP>("KQKP");
|
|
||||||
add<KQKR>("KQKR");
|
|
||||||
|
|
||||||
add<KNPK>("KNPK");
|
add<KPK>("KPK");
|
||||||
add<KNPKB>("KNPKB");
|
add<KNNK>("KNNK");
|
||||||
add<KRPKR>("KRPKR");
|
add<KBNK>("KBNK");
|
||||||
add<KRPKB>("KRPKB");
|
add<KRKP>("KRKP");
|
||||||
add<KBPKB>("KBPKB");
|
add<KRKB>("KRKB");
|
||||||
add<KBPKN>("KBPKN");
|
add<KRKN>("KRKN");
|
||||||
add<KBPPKB>("KBPPKB");
|
add<KQKP>("KQKP");
|
||||||
add<KRPPKRP>("KRPPKRP");
|
add<KQKR>("KQKR");
|
||||||
}
|
add<KNNKP>("KNNKP");
|
||||||
|
|
||||||
|
add<KNPK>("KNPK");
|
||||||
template<EndgameType E, typename T>
|
add<KNPKB>("KNPKB");
|
||||||
void Endgames::add(const string& code) {
|
add<KRPKR>("KRPKR");
|
||||||
map<T>()[key(code, WHITE)] = std::unique_ptr<EndgameBase<T>>(new Endgame<E>(WHITE));
|
add<KRPKB>("KRPKB");
|
||||||
map<T>()[key(code, BLACK)] = std::unique_ptr<EndgameBase<T>>(new Endgame<E>(BLACK));
|
add<KBPKB>("KBPKB");
|
||||||
|
add<KBPKN>("KBPKN");
|
||||||
|
add<KBPPKB>("KBPPKB");
|
||||||
|
add<KRPPKRP>("KRPPKRP");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -162,8 +135,8 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
|
|||||||
if ( pos.count<QUEEN>(strongSide)
|
if ( pos.count<QUEEN>(strongSide)
|
||||||
|| pos.count<ROOK>(strongSide)
|
|| pos.count<ROOK>(strongSide)
|
||||||
||(pos.count<BISHOP>(strongSide) && pos.count<KNIGHT>(strongSide))
|
||(pos.count<BISHOP>(strongSide) && pos.count<KNIGHT>(strongSide))
|
||||||
||(pos.count<BISHOP>(strongSide) > 1 && opposite_colors(pos.squares<BISHOP>(strongSide)[0],
|
|| ( (pos.pieces(strongSide, BISHOP) & ~DarkSquares)
|
||||||
pos.squares<BISHOP>(strongSide)[1])))
|
&& (pos.pieces(strongSide, BISHOP) & DarkSquares)))
|
||||||
result = std::min(result + VALUE_KNOWN_WIN, VALUE_MATE_IN_MAX_PLY - 1);
|
result = std::min(result + VALUE_KNOWN_WIN, VALUE_MATE_IN_MAX_PLY - 1);
|
||||||
|
|
||||||
return strongSide == pos.side_to_move() ? result : -result;
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
@@ -171,7 +144,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
|
|||||||
|
|
||||||
|
|
||||||
/// Mate with KBN vs K. This is similar to KX vs K, but we have to drive the
|
/// Mate with KBN vs K. This is similar to KX vs K, but we have to drive the
|
||||||
/// defending king towards a corner square of the right color.
|
/// defending king towards a corner square that our bishop attacks.
|
||||||
template<>
|
template<>
|
||||||
Value Endgame<KBNK>::operator()(const Position& pos) const {
|
Value Endgame<KBNK>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
@@ -182,24 +155,19 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
|
|||||||
Square loserKSq = pos.square<KING>(weakSide);
|
Square loserKSq = pos.square<KING>(weakSide);
|
||||||
Square bishopSq = pos.square<BISHOP>(strongSide);
|
Square bishopSq = pos.square<BISHOP>(strongSide);
|
||||||
|
|
||||||
// kbnk_mate_table() tries to drive toward corners A1 or H8. If we have a
|
// If our bishop does not attack A1/H8, we flip the enemy king square
|
||||||
// bishop that cannot reach the above squares, we flip the kings in order
|
// to drive to opposite corners (A8/H1).
|
||||||
// to drive the enemy toward corners A8 or H1.
|
|
||||||
if (opposite_colors(bishopSq, SQ_A1))
|
|
||||||
{
|
|
||||||
winnerKSq = ~winnerKSq;
|
|
||||||
loserKSq = ~loserKSq;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value result = VALUE_KNOWN_WIN
|
Value result = VALUE_KNOWN_WIN
|
||||||
+ PushClose[distance(winnerKSq, loserKSq)]
|
+ PushClose[distance(winnerKSq, loserKSq)]
|
||||||
+ PushToCorners[loserKSq];
|
+ PushToCorners[opposite_colors(bishopSq, SQ_A1) ? ~loserKSq : loserKSq];
|
||||||
|
|
||||||
|
assert(abs(result) < VALUE_MATE_IN_MAX_PLY);
|
||||||
return strongSide == pos.side_to_move() ? result : -result;
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// KP vs K. This endgame is evaluated with the help of a bitbase.
|
/// KP vs K. This endgame is evaluated with the help of a bitbase
|
||||||
template<>
|
template<>
|
||||||
Value Endgame<KPK>::operator()(const Position& pos) const {
|
Value Endgame<KPK>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
@@ -241,7 +209,7 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
|||||||
Value result;
|
Value result;
|
||||||
|
|
||||||
// If the stronger side's king is in front of the pawn, it's a win
|
// If the stronger side's king is in front of the pawn, it's a win
|
||||||
if (wksq < psq && file_of(wksq) == file_of(psq))
|
if (forward_file_bb(WHITE, wksq) & psq)
|
||||||
result = RookValueEg - distance(wksq, psq);
|
result = RookValueEg - distance(wksq, psq);
|
||||||
|
|
||||||
// If the weaker side's king is too far from the pawn and the rook,
|
// If the weaker side's king is too far from the pawn and the rook,
|
||||||
@@ -259,15 +227,15 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
|||||||
result = Value(80) - 8 * distance(wksq, psq);
|
result = Value(80) - 8 * distance(wksq, psq);
|
||||||
|
|
||||||
else
|
else
|
||||||
result = Value(200) - 8 * ( distance(wksq, psq + DELTA_S)
|
result = Value(200) - 8 * ( distance(wksq, psq + SOUTH)
|
||||||
- distance(bksq, psq + DELTA_S)
|
- distance(bksq, psq + SOUTH)
|
||||||
- distance(psq, queeningSq));
|
- distance(psq, queeningSq));
|
||||||
|
|
||||||
return strongSide == pos.side_to_move() ? result : -result;
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// KR vs KB. This is very simple, and always returns drawish scores. The
|
/// KR vs KB. This is very simple, and always returns drawish scores. The
|
||||||
/// score is slightly bigger when the defending king is close to the edge.
|
/// score is slightly bigger when the defending king is close to the edge.
|
||||||
template<>
|
template<>
|
||||||
Value Endgame<KRKB>::operator()(const Position& pos) const {
|
Value Endgame<KRKB>::operator()(const Position& pos) const {
|
||||||
@@ -342,6 +310,21 @@ Value Endgame<KQKR>::operator()(const Position& pos) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// KNN vs KP. Simply push the opposing king to the corner
|
||||||
|
template<>
|
||||||
|
Value Endgame<KNNKP>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
|
assert(verify_material(pos, strongSide, 2 * KnightValueMg, 0));
|
||||||
|
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
|
||||||
|
|
||||||
|
Value result = 2 * KnightValueEg
|
||||||
|
- PawnValueEg
|
||||||
|
+ PushToEdges[pos.square<KING>(weakSide)];
|
||||||
|
|
||||||
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Some cases of trivial draws
|
/// Some cases of trivial draws
|
||||||
template<> Value Endgame<KNNK>::operator()(const Position&) const { return VALUE_DRAW; }
|
template<> Value Endgame<KNNK>::operator()(const Position&) const { return VALUE_DRAW; }
|
||||||
|
|
||||||
@@ -382,7 +365,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
|
|||||||
&& pos.count<PAWN>(weakSide) >= 1)
|
&& pos.count<PAWN>(weakSide) >= 1)
|
||||||
{
|
{
|
||||||
// Get weakSide pawn that is closest to the home rank
|
// Get weakSide pawn that is closest to the home rank
|
||||||
Square weakPawnSq = backmost_sq(weakSide, pos.pieces(weakSide, PAWN));
|
Square weakPawnSq = frontmost_sq(strongSide, pos.pieces(weakSide, PAWN));
|
||||||
|
|
||||||
Square strongKingSq = pos.square<KING>(strongSide);
|
Square strongKingSq = pos.square<KING>(strongSide);
|
||||||
Square weakKingSq = pos.square<KING>(weakSide);
|
Square weakKingSq = pos.square<KING>(weakSide);
|
||||||
@@ -496,7 +479,7 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
|
|||||||
// If the defending king blocks the pawn and the attacking king is too far
|
// If the defending king blocks the pawn and the attacking king is too far
|
||||||
// away, it's a draw.
|
// away, it's a draw.
|
||||||
if ( r <= RANK_5
|
if ( r <= RANK_5
|
||||||
&& bksq == wpsq + DELTA_N
|
&& bksq == wpsq + NORTH
|
||||||
&& distance(wksq, wpsq) - tempo >= 2
|
&& distance(wksq, wpsq) - tempo >= 2
|
||||||
&& distance(wksq, brsq) - tempo >= 2)
|
&& distance(wksq, brsq) - tempo >= 2)
|
||||||
return SCALE_FACTOR_DRAW;
|
return SCALE_FACTOR_DRAW;
|
||||||
@@ -517,10 +500,10 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
|
|||||||
&& file_of(wrsq) == f
|
&& file_of(wrsq) == f
|
||||||
&& wrsq < wpsq
|
&& wrsq < wpsq
|
||||||
&& (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo)
|
&& (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo)
|
||||||
&& (distance(wksq, wpsq + DELTA_N) < distance(bksq, wpsq + DELTA_N) - 2 + tempo)
|
&& (distance(wksq, wpsq + NORTH) < distance(bksq, wpsq + NORTH) - 2 + tempo)
|
||||||
&& ( distance(bksq, wrsq) + tempo >= 3
|
&& ( distance(bksq, wrsq) + tempo >= 3
|
||||||
|| ( distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo
|
|| ( distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo
|
||||||
&& (distance(wksq, wpsq + DELTA_N) < distance(bksq, wrsq) + tempo))))
|
&& (distance(wksq, wpsq + NORTH) < distance(bksq, wrsq) + tempo))))
|
||||||
return ScaleFactor( SCALE_FACTOR_MAX
|
return ScaleFactor( SCALE_FACTOR_MAX
|
||||||
- 8 * distance(wpsq, queeningSq)
|
- 8 * distance(wpsq, queeningSq)
|
||||||
- 2 * distance(wksq, queeningSq));
|
- 2 * distance(wksq, queeningSq));
|
||||||
@@ -551,7 +534,7 @@ ScaleFactor Endgame<KRPKB>::operator()(const Position& pos) const {
|
|||||||
Square bsq = pos.square<BISHOP>(weakSide);
|
Square bsq = pos.square<BISHOP>(weakSide);
|
||||||
Square psq = pos.square<PAWN>(strongSide);
|
Square psq = pos.square<PAWN>(strongSide);
|
||||||
Rank rk = relative_rank(strongSide, psq);
|
Rank rk = relative_rank(strongSide, psq);
|
||||||
Square push = pawn_push(strongSide);
|
Direction push = pawn_push(strongSide);
|
||||||
|
|
||||||
// If the pawn is on the 5th rank and the pawn (currently) is on
|
// If the pawn is on the 5th rank and the pawn (currently) is on
|
||||||
// the same color square as the bishop then there is a chance of
|
// the same color square as the bishop then there is a chance of
|
||||||
@@ -625,7 +608,7 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
|
|||||||
|
|
||||||
// If all pawns are ahead of the king, on a single rook file and
|
// If all pawns are ahead of the king, on a single rook file and
|
||||||
// the king is within one file of the pawns, it's a draw.
|
// the king is within one file of the pawns, it's a draw.
|
||||||
if ( !(pawns & ~in_front_bb(weakSide, rank_of(ksq)))
|
if ( !(pawns & ~forward_ranks_bb(weakSide, ksq))
|
||||||
&& !((pawns & ~FileABB) && (pawns & ~FileHBB))
|
&& !((pawns & ~FileABB) && (pawns & ~FileHBB))
|
||||||
&& distance<File>(ksq, lsb(pawns)) <= 1)
|
&& distance<File>(ksq, lsb(pawns)) <= 1)
|
||||||
return SCALE_FACTOR_DRAW;
|
return SCALE_FACTOR_DRAW;
|
||||||
@@ -658,31 +641,8 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
|
|||||||
|
|
||||||
// Case 2: Opposite colored bishops
|
// Case 2: Opposite colored bishops
|
||||||
if (opposite_colors(strongBishopSq, weakBishopSq))
|
if (opposite_colors(strongBishopSq, weakBishopSq))
|
||||||
{
|
return SCALE_FACTOR_DRAW;
|
||||||
// We assume that the position is drawn in the following three situations:
|
|
||||||
//
|
|
||||||
// a. The pawn is on rank 5 or further back.
|
|
||||||
// b. The defending king is somewhere in the pawn's path.
|
|
||||||
// c. The defending bishop attacks some square along the pawn's path,
|
|
||||||
// and is at least three squares away from the pawn.
|
|
||||||
//
|
|
||||||
// These rules are probably not perfect, but in practice they work
|
|
||||||
// reasonably well.
|
|
||||||
|
|
||||||
if (relative_rank(strongSide, pawnSq) <= RANK_5)
|
|
||||||
return SCALE_FACTOR_DRAW;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Bitboard path = forward_bb(strongSide, pawnSq);
|
|
||||||
|
|
||||||
if (path & pos.pieces(weakSide, KING))
|
|
||||||
return SCALE_FACTOR_DRAW;
|
|
||||||
|
|
||||||
if ( (pos.attacks_from<BISHOP>(weakBishopSq) & path)
|
|
||||||
&& distance(weakBishopSq, pawnSq) >= 3)
|
|
||||||
return SCALE_FACTOR_DRAW;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,8 +663,6 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
|
|||||||
Square ksq = pos.square<KING>(weakSide);
|
Square ksq = pos.square<KING>(weakSide);
|
||||||
Square psq1 = pos.squares<PAWN>(strongSide)[0];
|
Square psq1 = pos.squares<PAWN>(strongSide)[0];
|
||||||
Square psq2 = pos.squares<PAWN>(strongSide)[1];
|
Square psq2 = pos.squares<PAWN>(strongSide)[1];
|
||||||
Rank r1 = rank_of(psq1);
|
|
||||||
Rank r2 = rank_of(psq2);
|
|
||||||
Square blockSq1, blockSq2;
|
Square blockSq1, blockSq2;
|
||||||
|
|
||||||
if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2))
|
if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2))
|
||||||
@@ -738,7 +696,7 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
|
|||||||
&& opposite_colors(ksq, wbsq)
|
&& opposite_colors(ksq, wbsq)
|
||||||
&& ( bbsq == blockSq2
|
&& ( bbsq == blockSq2
|
||||||
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(weakSide, BISHOP))
|
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(weakSide, BISHOP))
|
||||||
|| distance(r1, r2) >= 2))
|
|| distance<Rank>(psq1, psq2) >= 2))
|
||||||
return SCALE_FACTOR_DRAW;
|
return SCALE_FACTOR_DRAW;
|
||||||
|
|
||||||
else if ( ksq == blockSq2
|
else if ( ksq == blockSq2
|
||||||
@@ -803,13 +761,16 @@ ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
|
|||||||
template<>
|
template<>
|
||||||
ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
|
ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
|
assert(verify_material(pos, strongSide, KnightValueMg, 1));
|
||||||
|
assert(verify_material(pos, weakSide, BishopValueMg, 0));
|
||||||
|
|
||||||
Square pawnSq = pos.square<PAWN>(strongSide);
|
Square pawnSq = pos.square<PAWN>(strongSide);
|
||||||
Square bishopSq = pos.square<BISHOP>(weakSide);
|
Square bishopSq = pos.square<BISHOP>(weakSide);
|
||||||
Square weakKingSq = pos.square<KING>(weakSide);
|
Square weakKingSq = pos.square<KING>(weakSide);
|
||||||
|
|
||||||
// King needs to get close to promoting pawn to prevent knight from blocking.
|
// King needs to get close to promoting pawn to prevent knight from blocking.
|
||||||
// Rules for this are very tricky, so just approximate.
|
// Rules for this are very tricky, so just approximate.
|
||||||
if (forward_bb(strongSide, pawnSq) & pos.attacks_from<BISHOP>(bishopSq))
|
if (forward_file_bb(strongSide, pawnSq) & pos.attacks_from<BISHOP>(bishopSq))
|
||||||
return ScaleFactor(distance(weakKingSq, pawnSq));
|
return ScaleFactor(distance(weakKingSq, pawnSq));
|
||||||
|
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
|
|||||||
+32
-30
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
#ifndef ENDGAME_H_INCLUDED
|
#ifndef ENDGAME_H_INCLUDED
|
||||||
#define ENDGAME_H_INCLUDED
|
#define ENDGAME_H_INCLUDED
|
||||||
|
|
||||||
#include <map>
|
#include <unordered_map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -31,13 +31,13 @@
|
|||||||
#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
|
KNNK, // KNN vs K
|
||||||
|
KNNKP, // KNN vs KP
|
||||||
KXK, // Generic "mate lone king" eval
|
KXK, // Generic "mate lone king" eval
|
||||||
KBNK, // KBN vs K
|
KBNK, // KBN vs K
|
||||||
KPK, // KP vs K
|
KPK, // KP vs K
|
||||||
@@ -47,10 +47,7 @@ enum EndgameType {
|
|||||||
KQKP, // KQ vs KP
|
KQKP, // KQ vs KP
|
||||||
KQKR, // KQ vs KR
|
KQKR, // KQ vs KR
|
||||||
|
|
||||||
|
|
||||||
// Scaling functions
|
|
||||||
SCALING_FUNCTIONS,
|
SCALING_FUNCTIONS,
|
||||||
|
|
||||||
KBPsK, // KB and pawns vs K
|
KBPsK, // KB and pawns vs K
|
||||||
KQKRPs, // KQ vs KR and pawns
|
KQKRPs, // KQ vs KR and pawns
|
||||||
KRPKR, // KRP vs KR
|
KRPKR, // KRP vs KR
|
||||||
@@ -68,58 +65,63 @@ enum EndgameType {
|
|||||||
|
|
||||||
/// Endgame functions can be of two types depending on whether they return a
|
/// Endgame functions can be of two types depending on whether they return a
|
||||||
/// Value or a ScaleFactor.
|
/// Value or a ScaleFactor.
|
||||||
template<EndgameType E> using
|
|
||||||
|
template<EndgameCode E> using
|
||||||
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
||||||
|
|
||||||
|
|
||||||
/// Base and derived templates for endgame evaluation and scaling functions
|
/// Base and derived functors for endgame evaluation and scaling functions
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct EndgameBase {
|
struct EndgameBase {
|
||||||
|
|
||||||
|
explicit EndgameBase(Color c) : strongSide(c), weakSide(~c) {}
|
||||||
virtual ~EndgameBase() = default;
|
virtual ~EndgameBase() = default;
|
||||||
virtual Color strong_side() const = 0;
|
|
||||||
virtual T operator()(const Position&) const = 0;
|
virtual T operator()(const Position&) const = 0;
|
||||||
|
|
||||||
|
const Color strongSide, weakSide;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<EndgameType E, typename T = eg_type<E>>
|
template<EndgameCode E, typename T = eg_type<E>>
|
||||||
struct Endgame : public EndgameBase<T> {
|
struct Endgame : public EndgameBase<T> {
|
||||||
|
|
||||||
explicit Endgame(Color c) : strongSide(c), weakSide(~c) {}
|
explicit Endgame(Color c) : EndgameBase<T>(c) {}
|
||||||
Color strong_side() const { return strongSide; }
|
T operator()(const Position&) const override;
|
||||||
T operator()(const Position&) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Color strongSide, weakSide;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// The Endgames class stores the pointers to endgame evaluation and scaling
|
/// The Endgames namespace handles the pointers to endgame evaluation and scaling
|
||||||
/// base objects in two std::map. We use polymorphism to invoke the actual
|
/// base objects in two std::map. We use polymorphism to invoke the actual
|
||||||
/// endgame function by calling its virtual operator().
|
/// endgame function by calling its virtual operator().
|
||||||
|
|
||||||
class Endgames {
|
namespace Endgames {
|
||||||
|
|
||||||
template<typename T> using Map = std::map<Key, std::unique_ptr<EndgameBase<T>>>;
|
template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
|
||||||
|
template<typename T> using Map = std::unordered_map<Key, Ptr<T>>;
|
||||||
|
|
||||||
template<EndgameType E, typename T = eg_type<E>>
|
extern std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||||
void add(const std::string& code);
|
|
||||||
|
void init();
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Map<T>& map() {
|
Map<T>& map() {
|
||||||
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
template<EndgameCode E, typename T = eg_type<E>>
|
||||||
|
void add(const std::string& code) {
|
||||||
|
|
||||||
public:
|
StateInfo st;
|
||||||
Endgames();
|
map<T>()[Position().set(code, WHITE, &st).material_key()] = Ptr<T>(new Endgame<E>(WHITE));
|
||||||
|
map<T>()[Position().set(code, BLACK, &st).material_key()] = Ptr<T>(new Endgame<E>(BLACK));
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
EndgameBase<T>* probe(Key key) {
|
const EndgameBase<T>* probe(Key key) {
|
||||||
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
|
auto it = map<T>().find(key);
|
||||||
|
return it != map<T>().end() ? it->second.get() : nullptr;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
#endif // #ifndef ENDGAME_H_INCLUDED
|
#endif // #ifndef ENDGAME_H_INCLUDED
|
||||||
|
|||||||
+641
-662
File diff suppressed because it is too large
Load Diff
+2
-4
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,12 +29,10 @@ class Position;
|
|||||||
|
|
||||||
namespace Eval {
|
namespace Eval {
|
||||||
|
|
||||||
const Value Tempo = Value(20); // Must be visible to search
|
constexpr Value Tempo = Value(28); // Must be visible to search
|
||||||
|
|
||||||
void init();
|
|
||||||
std::string trace(const Position& pos);
|
std::string trace(const Position& pos);
|
||||||
|
|
||||||
template<bool DoTrace = false>
|
|
||||||
Value evaluate(const Position& pos);
|
Value evaluate(const Position& pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-9
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,14 +21,18 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "evaluate.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "endgame.h"
|
||||||
#include "syzygy/tbprobe.h"
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
|
namespace PSQT {
|
||||||
|
void init();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
std::cout << engine_info() << std::endl;
|
std::cout << engine_info() << std::endl;
|
||||||
@@ -38,15 +42,12 @@ int main(int argc, char* argv[]) {
|
|||||||
Bitboards::init();
|
Bitboards::init();
|
||||||
Position::init();
|
Position::init();
|
||||||
Bitbases::init();
|
Bitbases::init();
|
||||||
Search::init();
|
Endgames::init();
|
||||||
Eval::init();
|
Threads.set(Options["Threads"]);
|
||||||
Pawns::init();
|
Search::clear(); // After threads are up
|
||||||
Threads.init();
|
|
||||||
Tablebases::init(Options["SyzygyPath"]);
|
|
||||||
TT.resize(Options["Hash"]);
|
|
||||||
|
|
||||||
UCI::loop(argc, argv);
|
UCI::loop(argc, argv);
|
||||||
|
|
||||||
Threads.exit();
|
Threads.set(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-38
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm> // For std::min
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring> // For std::memset
|
#include <cstring> // For std::memset
|
||||||
|
|
||||||
@@ -31,21 +30,18 @@ namespace {
|
|||||||
|
|
||||||
// Polynomial material imbalance parameters
|
// Polynomial material imbalance parameters
|
||||||
|
|
||||||
// pair pawn knight bishop rook queen
|
constexpr int QuadraticOurs[][PIECE_TYPE_NB] = {
|
||||||
const int Linear[6] = { 1667, -168, -1027, -166, 238, -138 };
|
|
||||||
|
|
||||||
const int QuadraticOurs[][PIECE_TYPE_NB] = {
|
|
||||||
// OUR PIECES
|
// OUR PIECES
|
||||||
// pair pawn knight bishop rook queen
|
// pair pawn knight bishop rook queen
|
||||||
{ 0 }, // Bishop pair
|
{1438 }, // Bishop pair
|
||||||
{ 40, 2 }, // Pawn
|
{ 40, 38 }, // Pawn
|
||||||
{ 32, 255, -3 }, // Knight OUR PIECES
|
{ 32, 255, -62 }, // Knight OUR PIECES
|
||||||
{ 0, 104, 4, 0 }, // Bishop
|
{ 0, 104, 4, 0 }, // Bishop
|
||||||
{ -26, -2, 47, 105, -149 }, // Rook
|
{ -26, -2, 47, 105, -208 }, // Rook
|
||||||
{-185, 24, 122, 137, -134, 0 } // Queen
|
{-189, 24, 117, 133, -134, -6 } // Queen
|
||||||
};
|
};
|
||||||
|
|
||||||
const int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
constexpr int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
||||||
// THEIR PIECES
|
// THEIR PIECES
|
||||||
// pair pawn knight bishop rook queen
|
// pair pawn knight bishop rook queen
|
||||||
{ 0 }, // Bishop pair
|
{ 0 }, // Bishop pair
|
||||||
@@ -53,7 +49,7 @@ namespace {
|
|||||||
{ 9, 63, 0 }, // Knight OUR PIECES
|
{ 9, 63, 0 }, // Knight OUR PIECES
|
||||||
{ 59, 65, 42, 0 }, // Bishop
|
{ 59, 65, 42, 0 }, // Bishop
|
||||||
{ 46, 39, 24, -24, 0 }, // Rook
|
{ 46, 39, 24, -24, 0 }, // Rook
|
||||||
{ 101, 100, -37, 141, 268, 0 } // Queen
|
{ 97, 100, -42, 137, 268, 0 } // Queen
|
||||||
};
|
};
|
||||||
|
|
||||||
// Endgame evaluation and scaling functions are accessed directly and not through
|
// Endgame evaluation and scaling functions are accessed directly and not through
|
||||||
@@ -71,16 +67,14 @@ namespace {
|
|||||||
&& pos.non_pawn_material(us) >= RookValueMg;
|
&& pos.non_pawn_material(us) >= RookValueMg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_KBPsKs(const Position& pos, Color us) {
|
bool is_KBPsK(const Position& pos, Color us) {
|
||||||
return pos.non_pawn_material(us) == BishopValueMg
|
return pos.non_pawn_material(us) == BishopValueMg
|
||||||
&& pos.count<BISHOP>(us) == 1
|
|
||||||
&& pos.count<PAWN >(us) >= 1;
|
&& pos.count<PAWN >(us) >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_KQKRPs(const Position& pos, Color us) {
|
bool is_KQKRPs(const Position& pos, Color us) {
|
||||||
return !pos.count<PAWN>(us)
|
return !pos.count<PAWN>(us)
|
||||||
&& pos.non_pawn_material(us) == QueenValueMg
|
&& pos.non_pawn_material(us) == QueenValueMg
|
||||||
&& pos.count<QUEEN>(us) == 1
|
|
||||||
&& pos.count<ROOK>(~us) == 1
|
&& pos.count<ROOK>(~us) == 1
|
||||||
&& pos.count<PAWN>(~us) >= 1;
|
&& pos.count<PAWN>(~us) >= 1;
|
||||||
}
|
}
|
||||||
@@ -90,17 +84,17 @@ namespace {
|
|||||||
template<Color Us>
|
template<Color Us>
|
||||||
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
int bonus = 0;
|
int bonus = 0;
|
||||||
|
|
||||||
// Second-degree polynomial material imbalance by Tord Romstad
|
// Second-degree polynomial material imbalance, by Tord Romstad
|
||||||
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)
|
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)
|
||||||
{
|
{
|
||||||
if (!pieceCount[Us][pt1])
|
if (!pieceCount[Us][pt1])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int v = Linear[pt1];
|
int v = 0;
|
||||||
|
|
||||||
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; ++pt2)
|
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; ++pt2)
|
||||||
v += QuadraticOurs[pt1][pt2] * pieceCount[Us][pt2]
|
v += QuadraticOurs[pt1][pt2] * pieceCount[Us][pt2]
|
||||||
@@ -132,15 +126,21 @@ Entry* probe(const Position& pos) {
|
|||||||
std::memset(e, 0, sizeof(Entry));
|
std::memset(e, 0, sizeof(Entry));
|
||||||
e->key = key;
|
e->key = key;
|
||||||
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
|
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
|
||||||
e->gamePhase = pos.game_phase();
|
|
||||||
|
Value npm_w = pos.non_pawn_material(WHITE);
|
||||||
|
Value npm_b = pos.non_pawn_material(BLACK);
|
||||||
|
Value npm = clamp(npm_w + npm_b, EndgameLimit, MidgameLimit);
|
||||||
|
|
||||||
|
// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
|
||||||
|
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
|
||||||
|
|
||||||
// Let's look if we have a specialized evaluation function for this particular
|
// Let's look if we have a specialized evaluation function for this particular
|
||||||
// material configuration. Firstly we look for a fixed configuration one, then
|
// material configuration. Firstly we look for a fixed configuration one, then
|
||||||
// for a generic one if the previous search failed.
|
// for a generic one if the previous search failed.
|
||||||
if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)
|
if ((e->evaluationFunction = Endgames::probe<Value>(key)) != nullptr)
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
for (Color c : { WHITE, BLACK })
|
||||||
if (is_KXK(pos, c))
|
if (is_KXK(pos, c))
|
||||||
{
|
{
|
||||||
e->evaluationFunction = &EvaluateKXK[c];
|
e->evaluationFunction = &EvaluateKXK[c];
|
||||||
@@ -149,29 +149,26 @@ Entry* probe(const Position& pos) {
|
|||||||
|
|
||||||
// OK, we didn't find any special evaluation function for the current material
|
// OK, we didn't find any special evaluation function for the current material
|
||||||
// configuration. Is there a suitable specialized scaling function?
|
// configuration. Is there a suitable specialized scaling function?
|
||||||
EndgameBase<ScaleFactor>* sf;
|
const auto* sf = Endgames::probe<ScaleFactor>(key);
|
||||||
|
|
||||||
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
|
if (sf)
|
||||||
{
|
{
|
||||||
e->scalingFunction[sf->strong_side()] = sf; // Only strong color assigned
|
e->scalingFunction[sf->strongSide] = sf; // Only strong color assigned
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We didn't find any specialized scaling function, so fall back on generic
|
// We didn't find any specialized scaling function, so fall back on generic
|
||||||
// ones that refer to more than one material distribution. Note that in this
|
// ones that refer to more than one material distribution. Note that in this
|
||||||
// case we don't return after setting the function.
|
// case we don't return after setting the function.
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
for (Color c : { WHITE, BLACK })
|
||||||
{
|
{
|
||||||
if (is_KBPsKs(pos, c))
|
if (is_KBPsK(pos, c))
|
||||||
e->scalingFunction[c] = &ScaleKBPsK[c];
|
e->scalingFunction[c] = &ScaleKBPsK[c];
|
||||||
|
|
||||||
else if (is_KQKRPs(pos, c))
|
else if (is_KQKRPs(pos, c))
|
||||||
e->scalingFunction[c] = &ScaleKQKRPs[c];
|
e->scalingFunction[c] = &ScaleKQKRPs[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
Value npm_w = pos.non_pawn_material(WHITE);
|
|
||||||
Value npm_b = pos.non_pawn_material(BLACK);
|
|
||||||
|
|
||||||
if (npm_w + npm_b == VALUE_ZERO && pos.pieces(PAWN)) // Only pawns on the board
|
if (npm_w + npm_b == VALUE_ZERO && pos.pieces(PAWN)) // Only pawns on the board
|
||||||
{
|
{
|
||||||
if (!pos.count<PAWN>(BLACK))
|
if (!pos.count<PAWN>(BLACK))
|
||||||
@@ -206,22 +203,16 @@ Entry* probe(const Position& pos) {
|
|||||||
e->factor[BLACK] = uint8_t(npm_b < RookValueMg ? SCALE_FACTOR_DRAW :
|
e->factor[BLACK] = uint8_t(npm_b < RookValueMg ? SCALE_FACTOR_DRAW :
|
||||||
npm_w <= BishopValueMg ? 4 : 14);
|
npm_w <= BishopValueMg ? 4 : 14);
|
||||||
|
|
||||||
if (pos.count<PAWN>(WHITE) == 1 && npm_w - npm_b <= BishopValueMg)
|
|
||||||
e->factor[WHITE] = (uint8_t) SCALE_FACTOR_ONEPAWN;
|
|
||||||
|
|
||||||
if (pos.count<PAWN>(BLACK) == 1 && npm_b - npm_w <= BishopValueMg)
|
|
||||||
e->factor[BLACK] = (uint8_t) SCALE_FACTOR_ONEPAWN;
|
|
||||||
|
|
||||||
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
||||||
// for the bishop pair "extended piece", which allows us to be more flexible
|
// for the bishop pair "extended piece", which allows us to be more flexible
|
||||||
// in defining bishop pair bonuses.
|
// in defining bishop pair bonuses.
|
||||||
const int PieceCount[COLOR_NB][PIECE_TYPE_NB] = {
|
const int pieceCount[COLOR_NB][PIECE_TYPE_NB] = {
|
||||||
{ pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
|
{ pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
|
||||||
pos.count<BISHOP>(WHITE) , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
|
pos.count<BISHOP>(WHITE) , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
|
||||||
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
|
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
|
||||||
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
|
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
|
||||||
|
|
||||||
e->value = int16_t((imbalance<WHITE>(PieceCount) - imbalance<BLACK>(PieceCount)) / 16);
|
e->value = int16_t((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -50,17 +50,17 @@ struct Entry {
|
|||||||
// the position. For instance, in KBP vs K endgames, the scaling function looks
|
// the position. For instance, in KBP vs K endgames, the scaling function looks
|
||||||
// for rook pawns and wrong-colored bishops.
|
// for rook pawns and wrong-colored bishops.
|
||||||
ScaleFactor scale_factor(const Position& pos, Color c) const {
|
ScaleFactor scale_factor(const Position& pos, Color c) const {
|
||||||
return !scalingFunction[c]
|
ScaleFactor sf = scalingFunction[c] ? (*scalingFunction[c])(pos)
|
||||||
|| (*scalingFunction[c])(pos) == SCALE_FACTOR_NONE ? ScaleFactor(factor[c])
|
: SCALE_FACTOR_NONE;
|
||||||
: (*scalingFunction[c])(pos);
|
return sf != SCALE_FACTOR_NONE ? sf : ScaleFactor(factor[c]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
|
const EndgameBase<Value>* evaluationFunction;
|
||||||
|
const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
||||||
|
// side (e.g. KPKP, KBPsK)
|
||||||
int16_t value;
|
int16_t value;
|
||||||
uint8_t factor[COLOR_NB];
|
uint8_t factor[COLOR_NB];
|
||||||
EndgameBase<Value>* evaluationFunction;
|
|
||||||
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
|
||||||
// side (e.g. KPKP, KBPsKs)
|
|
||||||
Phase gamePhase;
|
Phase gamePhase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+222
-14
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,10 +18,34 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#if _WIN32_WINNT < 0x0601
|
||||||
|
#undef _WIN32_WINNT
|
||||||
|
#define _WIN32_WINNT 0x0601 // Force to include needed API prototypes
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
// The needed Windows API for processor groups could be missed from old Windows
|
||||||
|
// versions, so instead of calling them directly (forcing the linker to resolve
|
||||||
|
// the calls at compile time), try to load them at runtime. To do this we need
|
||||||
|
// first to define the corresponding function pointers.
|
||||||
|
extern "C" {
|
||||||
|
typedef bool(*fun1_t)(LOGICAL_PROCESSOR_RELATIONSHIP,
|
||||||
|
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, PDWORD);
|
||||||
|
typedef bool(*fun2_t)(USHORT, PGROUP_AFFINITY);
|
||||||
|
typedef bool(*fun3_t)(HANDLE, CONST GROUP_AFFINITY*, PGROUP_AFFINITY);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
@@ -32,7 +56,7 @@ namespace {
|
|||||||
|
|
||||||
/// Version number. If Version is left empty, then compile date in the format
|
/// Version number. If Version is left empty, then compile date in the format
|
||||||
/// DD-MM-YY and show in engine_info.
|
/// DD-MM-YY and show in engine_info.
|
||||||
const string Version = "7";
|
const string Version = "11";
|
||||||
|
|
||||||
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
||||||
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
||||||
@@ -44,10 +68,10 @@ struct Tie: public streambuf { // MSVC requires split streambuf for cin and cout
|
|||||||
|
|
||||||
Tie(streambuf* b, streambuf* l) : buf(b), logBuf(l) {}
|
Tie(streambuf* b, streambuf* l) : buf(b), logBuf(l) {}
|
||||||
|
|
||||||
int sync() { return logBuf->pubsync(), buf->pubsync(); }
|
int sync() override { return logBuf->pubsync(), buf->pubsync(); }
|
||||||
int overflow(int c) { return log(buf->sputc((char)c), "<< "); }
|
int overflow(int c) override { return log(buf->sputc((char)c), "<< "); }
|
||||||
int underflow() { return buf->sgetc(); }
|
int underflow() override { return buf->sgetc(); }
|
||||||
int uflow() { return log(buf->sbumpc(), ">> "); }
|
int uflow() override { return log(buf->sbumpc(), ">> "); }
|
||||||
|
|
||||||
streambuf *buf, *logBuf;
|
streambuf *buf, *logBuf;
|
||||||
|
|
||||||
@@ -65,23 +89,30 @@ struct Tie: public streambuf { // MSVC requires split streambuf for cin and cout
|
|||||||
class Logger {
|
class Logger {
|
||||||
|
|
||||||
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
|
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
|
||||||
~Logger() { start(false); }
|
~Logger() { start(""); }
|
||||||
|
|
||||||
ofstream file;
|
ofstream file;
|
||||||
Tie in, out;
|
Tie in, out;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void start(bool b) {
|
static void start(const std::string& fname) {
|
||||||
|
|
||||||
static Logger l;
|
static Logger l;
|
||||||
|
|
||||||
if (b && !l.file.is_open())
|
if (!fname.empty() && !l.file.is_open())
|
||||||
{
|
{
|
||||||
l.file.open("io_log.txt", ifstream::out);
|
l.file.open(fname, ifstream::out);
|
||||||
|
|
||||||
|
if (!l.file.is_open())
|
||||||
|
{
|
||||||
|
cerr << "Unable to open debug log file " << fname << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
cin.rdbuf(&l.in);
|
cin.rdbuf(&l.in);
|
||||||
cout.rdbuf(&l.out);
|
cout.rdbuf(&l.out);
|
||||||
}
|
}
|
||||||
else if (!b && l.file.is_open())
|
else if (fname.empty() && l.file.is_open())
|
||||||
{
|
{
|
||||||
cout.rdbuf(l.out.buf);
|
cout.rdbuf(l.out.buf);
|
||||||
cin.rdbuf(l.in.buf);
|
cin.rdbuf(l.in.buf);
|
||||||
@@ -120,8 +151,79 @@ const string engine_info(bool to_uci) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// compiler_info() returns a string trying to describe the compiler we use
|
||||||
|
|
||||||
|
const std::string compiler_info() {
|
||||||
|
|
||||||
|
#define STRINGIFY2(x) #x
|
||||||
|
#define STRINGIFY(x) STRINGIFY2(x)
|
||||||
|
#define VER_STRING(major, minor, patch) STRINGIFY(major) "." STRINGIFY(minor) "." STRINGIFY(patch)
|
||||||
|
|
||||||
|
/// Predefined macros hell:
|
||||||
|
///
|
||||||
|
/// __GNUC__ Compiler is gcc, Clang or Intel on Linux
|
||||||
|
/// __INTEL_COMPILER Compiler is Intel
|
||||||
|
/// _MSC_VER Compiler is MSVC or Intel on Windows
|
||||||
|
/// _WIN32 Building on Windows (any)
|
||||||
|
/// _WIN64 Building on Windows 64 bit
|
||||||
|
|
||||||
|
std::string compiler = "\nCompiled by ";
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
compiler += "clang++ ";
|
||||||
|
compiler += VER_STRING(__clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||||
|
#elif __INTEL_COMPILER
|
||||||
|
compiler += "Intel compiler ";
|
||||||
|
compiler += "(version ";
|
||||||
|
compiler += STRINGIFY(__INTEL_COMPILER) " update " STRINGIFY(__INTEL_COMPILER_UPDATE);
|
||||||
|
compiler += ")";
|
||||||
|
#elif _MSC_VER
|
||||||
|
compiler += "MSVC ";
|
||||||
|
compiler += "(version ";
|
||||||
|
compiler += STRINGIFY(_MSC_FULL_VER) "." STRINGIFY(_MSC_BUILD);
|
||||||
|
compiler += ")";
|
||||||
|
#elif __GNUC__
|
||||||
|
compiler += "g++ (GNUC) ";
|
||||||
|
compiler += VER_STRING(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||||
|
#else
|
||||||
|
compiler += "Unknown compiler ";
|
||||||
|
compiler += "(unknown version)";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
compiler += " on Apple";
|
||||||
|
#elif defined(__CYGWIN__)
|
||||||
|
compiler += " on Cygwin";
|
||||||
|
#elif defined(__MINGW64__)
|
||||||
|
compiler += " on MinGW64";
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
compiler += " on MinGW32";
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
compiler += " on Android";
|
||||||
|
#elif defined(__linux__)
|
||||||
|
compiler += " on Linux";
|
||||||
|
#elif defined(_WIN64)
|
||||||
|
compiler += " on Microsoft Windows 64-bit";
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
compiler += " on Microsoft Windows 32-bit";
|
||||||
|
#else
|
||||||
|
compiler += " on unknown system";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
compiler += "\n __VERSION__ macro expands to: ";
|
||||||
|
#ifdef __VERSION__
|
||||||
|
compiler += __VERSION__;
|
||||||
|
#else
|
||||||
|
compiler += "(undefined macro)";
|
||||||
|
#endif
|
||||||
|
compiler += "\n";
|
||||||
|
|
||||||
|
return compiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Debug functions used mainly to collect run-time statistics
|
/// Debug functions used mainly to collect run-time statistics
|
||||||
static int64_t hits[2], means[2];
|
static std::atomic<int64_t> hits[2], means[2];
|
||||||
|
|
||||||
void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; }
|
void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; }
|
||||||
void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); }
|
void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); }
|
||||||
@@ -144,7 +246,7 @@ void dbg_print() {
|
|||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, SyncCout sc) {
|
std::ostream& operator<<(std::ostream& os, SyncCout sc) {
|
||||||
|
|
||||||
static Mutex m;
|
static std::mutex m;
|
||||||
|
|
||||||
if (sc == IO_LOCK)
|
if (sc == IO_LOCK)
|
||||||
m.lock();
|
m.lock();
|
||||||
@@ -157,7 +259,7 @@ std::ostream& operator<<(std::ostream& os, SyncCout sc) {
|
|||||||
|
|
||||||
|
|
||||||
/// Trampoline helper to avoid moving Logger to misc.h
|
/// Trampoline helper to avoid moving Logger to misc.h
|
||||||
void start_logger(bool b) { Logger::start(b); }
|
void start_logger(const std::string& fname) { Logger::start(fname); }
|
||||||
|
|
||||||
|
|
||||||
/// prefetch() preloads the given address in L1/L2 cache. This is a non-blocking
|
/// prefetch() preloads the given address in L1/L2 cache. This is a non-blocking
|
||||||
@@ -185,3 +287,109 @@ void prefetch(void* addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace WinProcGroup {
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
|
void bindThisThread(size_t) {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/// best_group() retrieves logical processor information using Windows specific
|
||||||
|
/// API and returns the best group id for the thread with index idx. Original
|
||||||
|
/// code from Texel by Peter Österlund.
|
||||||
|
|
||||||
|
int best_group(size_t idx) {
|
||||||
|
|
||||||
|
int threads = 0;
|
||||||
|
int nodes = 0;
|
||||||
|
int cores = 0;
|
||||||
|
DWORD returnLength = 0;
|
||||||
|
DWORD byteOffset = 0;
|
||||||
|
|
||||||
|
// Early exit if the needed API is not available at runtime
|
||||||
|
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
||||||
|
auto fun1 = (fun1_t)(void(*)())GetProcAddress(k32, "GetLogicalProcessorInformationEx");
|
||||||
|
if (!fun1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// First call to get returnLength. We expect it to fail due to null buffer
|
||||||
|
if (fun1(RelationAll, nullptr, &returnLength))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Once we know returnLength, allocate the buffer
|
||||||
|
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buffer, *ptr;
|
||||||
|
ptr = buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(returnLength);
|
||||||
|
|
||||||
|
// Second call, now we expect to succeed
|
||||||
|
if (!fun1(RelationAll, buffer, &returnLength))
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (byteOffset < returnLength)
|
||||||
|
{
|
||||||
|
if (ptr->Relationship == RelationNumaNode)
|
||||||
|
nodes++;
|
||||||
|
|
||||||
|
else if (ptr->Relationship == RelationProcessorCore)
|
||||||
|
{
|
||||||
|
cores++;
|
||||||
|
threads += (ptr->Processor.Flags == LTP_PC_SMT) ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(ptr->Size);
|
||||||
|
byteOffset += ptr->Size;
|
||||||
|
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((char*)ptr) + ptr->Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
std::vector<int> groups;
|
||||||
|
|
||||||
|
// Run as many threads as possible on the same node until core limit is
|
||||||
|
// reached, then move on filling the next node.
|
||||||
|
for (int n = 0; n < nodes; n++)
|
||||||
|
for (int i = 0; i < cores / nodes; i++)
|
||||||
|
groups.push_back(n);
|
||||||
|
|
||||||
|
// In case a core has more than one logical processor (we assume 2) and we
|
||||||
|
// have still threads to allocate, then spread them evenly across available
|
||||||
|
// nodes.
|
||||||
|
for (int t = 0; t < threads - cores; t++)
|
||||||
|
groups.push_back(t % nodes);
|
||||||
|
|
||||||
|
// If we still have more threads than the total number of logical processors
|
||||||
|
// then return -1 and let the OS to decide what to do.
|
||||||
|
return idx < groups.size() ? groups[idx] : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// bindThisThread() set the group affinity of the current thread
|
||||||
|
|
||||||
|
void bindThisThread(size_t idx) {
|
||||||
|
|
||||||
|
// Use only local variables to be thread-safe
|
||||||
|
int group = best_group(idx);
|
||||||
|
|
||||||
|
if (group == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Early exit if the needed API are not available at runtime
|
||||||
|
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
||||||
|
auto fun2 = (fun2_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
|
||||||
|
auto fun3 = (fun3_t)(void(*)())GetProcAddress(k32, "SetThreadGroupAffinity");
|
||||||
|
|
||||||
|
if (!fun2 || !fun3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GROUP_AFFINITY affinity;
|
||||||
|
if (fun2(group, &affinity))
|
||||||
|
fun3(GetCurrentThread(), &affinity, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace WinProcGroup
|
||||||
|
|||||||
+17
-3
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -30,8 +30,9 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
const std::string engine_info(bool to_uci = false);
|
const std::string engine_info(bool to_uci = false);
|
||||||
|
const std::string compiler_info();
|
||||||
void prefetch(void* addr);
|
void prefetch(void* addr);
|
||||||
void start_logger(bool b);
|
void start_logger(const std::string& fname);
|
||||||
|
|
||||||
void dbg_hit_on(bool b);
|
void dbg_hit_on(bool b);
|
||||||
void dbg_hit_on(bool c, bool b);
|
void dbg_hit_on(bool c, bool b);
|
||||||
@@ -40,6 +41,8 @@ void dbg_print();
|
|||||||
|
|
||||||
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
||||||
|
|
||||||
|
static_assert(sizeof(TimePoint) == sizeof(int64_t), "TimePoint should be 64 bits");
|
||||||
|
|
||||||
inline TimePoint now() {
|
inline TimePoint now() {
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>
|
return std::chrono::duration_cast<std::chrono::milliseconds>
|
||||||
(std::chrono::steady_clock::now().time_since_epoch()).count();
|
(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||||
@@ -50,7 +53,7 @@ struct HashTable {
|
|||||||
Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; }
|
Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Entry> table = std::vector<Entry>(Size);
|
std::vector<Entry> table = std::vector<Entry>(Size); // Allocate on the heap
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -97,4 +100,15 @@ public:
|
|||||||
{ return T(rand64() & rand64() & rand64()); }
|
{ 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
|
#endif // #ifndef MISC_H_INCLUDED
|
||||||
|
|||||||
+72
-122
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,86 +25,42 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template<CastlingRight Cr, bool Checks, bool Chess960>
|
template<GenType Type, Direction D>
|
||||||
ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us, const CheckInfo* ci) {
|
ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) {
|
||||||
|
|
||||||
static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
|
|
||||||
|
|
||||||
if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
|
|
||||||
return moveList;
|
|
||||||
|
|
||||||
// After castling, the rook and king final positions are the same in Chess960
|
|
||||||
// as they would be in standard chess.
|
|
||||||
Square kfrom = pos.square<KING>(us);
|
|
||||||
Square rfrom = pos.castling_rook_square(Cr);
|
|
||||||
Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1);
|
|
||||||
Bitboard enemies = pos.pieces(~us);
|
|
||||||
|
|
||||||
assert(!pos.checkers());
|
|
||||||
|
|
||||||
const Square K = Chess960 ? kto > kfrom ? DELTA_W : DELTA_E
|
|
||||||
: KingSide ? DELTA_W : DELTA_E;
|
|
||||||
|
|
||||||
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, *ci))
|
|
||||||
return moveList;
|
|
||||||
else
|
|
||||||
(void)ci; // Silence a warning under MSVC
|
|
||||||
|
|
||||||
*moveList++ = m;
|
|
||||||
return moveList;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<GenType Type, Square Delta>
|
|
||||||
ExtMove* make_promotions(ExtMove* moveList, Square to, const CheckInfo* ci) {
|
|
||||||
|
|
||||||
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, QUEEN);
|
*moveList++ = make<PROMOTION>(to - D, to, QUEEN);
|
||||||
|
|
||||||
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
|
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
{
|
{
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, ROOK);
|
*moveList++ = make<PROMOTION>(to - D, to, ROOK);
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, BISHOP);
|
*moveList++ = make<PROMOTION>(to - D, to, BISHOP);
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, KNIGHT);
|
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Knight promotion is the only promotion that can give a direct check
|
// Knight promotion is the only promotion that can give a direct check
|
||||||
// that's not already included in the queen promotion.
|
// that's not already included in the queen promotion.
|
||||||
if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq))
|
if (Type == QUIET_CHECKS && (PseudoAttacks[KNIGHT][to] & ksq))
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, KNIGHT);
|
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
||||||
else
|
else
|
||||||
(void)ci; // Silence a warning under MSVC
|
(void)ksq; // Silence a warning under MSVC
|
||||||
|
|
||||||
return moveList;
|
return moveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<Color Us, GenType Type>
|
template<Color Us, GenType Type>
|
||||||
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList,
|
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
Bitboard target, const CheckInfo* ci) {
|
|
||||||
|
|
||||||
// Compute our parametrized parameters at compile time, named according to
|
// Compute some compile time parameters relative to the white side
|
||||||
// the point of view of white side.
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||||
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
constexpr Direction Up = pawn_push(Us);
|
||||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
constexpr Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||||
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);
|
constexpr Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||||
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
|
||||||
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
|
||||||
|
|
||||||
|
const Square ksq = pos.square<KING>(Them);
|
||||||
Bitboard emptySquares;
|
Bitboard emptySquares;
|
||||||
|
|
||||||
Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB;
|
Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB;
|
||||||
@@ -118,8 +74,8 @@ namespace {
|
|||||||
{
|
{
|
||||||
emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces());
|
emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces());
|
||||||
|
|
||||||
Bitboard b1 = shift_bb<Up>(pawnsNotOn7) & emptySquares;
|
Bitboard b1 = shift<Up>(pawnsNotOn7) & emptySquares;
|
||||||
Bitboard b2 = shift_bb<Up>(b1 & TRank3BB) & emptySquares;
|
Bitboard b2 = shift<Up>(b1 & TRank3BB) & emptySquares;
|
||||||
|
|
||||||
if (Type == EVASIONS) // Consider only blocking squares
|
if (Type == EVASIONS) // Consider only blocking squares
|
||||||
{
|
{
|
||||||
@@ -129,17 +85,18 @@ namespace {
|
|||||||
|
|
||||||
if (Type == QUIET_CHECKS)
|
if (Type == QUIET_CHECKS)
|
||||||
{
|
{
|
||||||
b1 &= pos.attacks_from<PAWN>(ci->ksq, Them);
|
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
b2 &= pos.attacks_from<PAWN>(ci->ksq, Them);
|
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
|
|
||||||
// Add pawn pushes which give 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. Note that a possible discovery check
|
// don't generate captures. Note that a possible discovery check
|
||||||
// promotion has been already generated amongst the captures.
|
// promotion has been already generated amongst the captures.
|
||||||
if (pawnsNotOn7 & ci->dcCandidates)
|
Bitboard dcCandidateQuiets = pos.blockers_for_king(Them) & pawnsNotOn7;
|
||||||
|
if (dcCandidateQuiets)
|
||||||
{
|
{
|
||||||
Bitboard dc1 = shift_bb<Up>(pawnsNotOn7 & ci->dcCandidates) & emptySquares & ~file_bb(ci->ksq);
|
Bitboard dc1 = shift<Up>(dcCandidateQuiets) & emptySquares & ~file_bb(ksq);
|
||||||
Bitboard dc2 = shift_bb<Up>(dc1 & TRank3BB) & emptySquares;
|
Bitboard dc2 = shift<Up>(dc1 & TRank3BB) & emptySquares;
|
||||||
|
|
||||||
b1 |= dc1;
|
b1 |= dc1;
|
||||||
b2 |= dc2;
|
b2 |= dc2;
|
||||||
@@ -160,7 +117,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Promotions and underpromotions
|
// Promotions and underpromotions
|
||||||
if (pawnsOn7 && (Type != EVASIONS || (target & TRank8BB)))
|
if (pawnsOn7)
|
||||||
{
|
{
|
||||||
if (Type == CAPTURES)
|
if (Type == CAPTURES)
|
||||||
emptySquares = ~pos.pieces();
|
emptySquares = ~pos.pieces();
|
||||||
@@ -168,36 +125,36 @@ namespace {
|
|||||||
if (Type == EVASIONS)
|
if (Type == EVASIONS)
|
||||||
emptySquares &= target;
|
emptySquares &= target;
|
||||||
|
|
||||||
Bitboard b1 = shift_bb<Right>(pawnsOn7) & enemies;
|
Bitboard b1 = shift<UpRight>(pawnsOn7) & enemies;
|
||||||
Bitboard b2 = shift_bb<Left >(pawnsOn7) & enemies;
|
Bitboard b2 = shift<UpLeft >(pawnsOn7) & enemies;
|
||||||
Bitboard b3 = shift_bb<Up >(pawnsOn7) & emptySquares;
|
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
moveList = make_promotions<Type, Right>(moveList, pop_lsb(&b1), ci);
|
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(&b1), ksq);
|
||||||
|
|
||||||
while (b2)
|
while (b2)
|
||||||
moveList = make_promotions<Type, Left >(moveList, pop_lsb(&b2), ci);
|
moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(&b2), ksq);
|
||||||
|
|
||||||
while (b3)
|
while (b3)
|
||||||
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ci);
|
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ksq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard and en-passant captures
|
// Standard and en-passant captures
|
||||||
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
{
|
{
|
||||||
Bitboard b1 = shift_bb<Right>(pawnsNotOn7) & enemies;
|
Bitboard b1 = shift<UpRight>(pawnsNotOn7) & enemies;
|
||||||
Bitboard b2 = shift_bb<Left >(pawnsNotOn7) & enemies;
|
Bitboard b2 = shift<UpLeft >(pawnsNotOn7) & enemies;
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
Square to = pop_lsb(&b1);
|
Square to = pop_lsb(&b1);
|
||||||
*moveList++ = make_move(to - Right, to);
|
*moveList++ = make_move(to - UpRight, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (b2)
|
while (b2)
|
||||||
{
|
{
|
||||||
Square to = pop_lsb(&b2);
|
Square to = pop_lsb(&b2);
|
||||||
*moveList++ = make_move(to - Left, to);
|
*moveList++ = make_move(to - UpLeft, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos.ep_square() != SQ_NONE)
|
if (pos.ep_square() != SQ_NONE)
|
||||||
@@ -225,9 +182,9 @@ namespace {
|
|||||||
|
|
||||||
template<PieceType Pt, bool Checks>
|
template<PieceType Pt, bool Checks>
|
||||||
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
||||||
Bitboard target, const CheckInfo* ci) {
|
Bitboard target) {
|
||||||
|
|
||||||
assert(Pt != KING && Pt != PAWN);
|
static_assert(Pt != KING && Pt != PAWN, "Unsupported piece type in generate_moves()");
|
||||||
|
|
||||||
const Square* pl = pos.squares<Pt>(us);
|
const Square* pl = pos.squares<Pt>(us);
|
||||||
|
|
||||||
@@ -236,17 +193,17 @@ namespace {
|
|||||||
if (Checks)
|
if (Checks)
|
||||||
{
|
{
|
||||||
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
|
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
|
||||||
&& !(PseudoAttacks[Pt][from] & target & ci->checkSquares[Pt]))
|
&& !(PseudoAttacks[Pt][from] & target & pos.check_squares(Pt)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ci->dcCandidates && (ci->dcCandidates & from))
|
if (pos.blockers_for_king(~us) & from)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitboard b = pos.attacks_from<Pt>(from) & target;
|
Bitboard b = pos.attacks_from<Pt>(from) & target;
|
||||||
|
|
||||||
if (Checks)
|
if (Checks)
|
||||||
b &= ci->checkSquares[Pt];
|
b &= pos.check_squares(Pt);
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(from, pop_lsb(&b));
|
*moveList++ = make_move(from, pop_lsb(&b));
|
||||||
@@ -257,16 +214,17 @@ namespace {
|
|||||||
|
|
||||||
|
|
||||||
template<Color Us, GenType Type>
|
template<Color Us, GenType Type>
|
||||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target,
|
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
const CheckInfo* ci = nullptr) {
|
|
||||||
|
|
||||||
const bool Checks = Type == QUIET_CHECKS;
|
constexpr CastlingRights OO = Us & KING_SIDE;
|
||||||
|
constexpr CastlingRights OOO = Us & QUEEN_SIDE;
|
||||||
|
constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
|
||||||
|
|
||||||
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target, ci);
|
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
||||||
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target, ci);
|
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
|
||||||
moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target, ci);
|
moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target);
|
||||||
moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target, ci);
|
moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target);
|
||||||
moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target, ci);
|
moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target);
|
||||||
|
|
||||||
if (Type != QUIET_CHECKS && Type != EVASIONS)
|
if (Type != QUIET_CHECKS && Type != EVASIONS)
|
||||||
{
|
{
|
||||||
@@ -274,19 +232,14 @@ namespace {
|
|||||||
Bitboard b = pos.attacks_from<KING>(ksq) & target;
|
Bitboard b = pos.attacks_from<KING>(ksq) & target;
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(ksq, pop_lsb(&b));
|
*moveList++ = make_move(ksq, pop_lsb(&b));
|
||||||
}
|
|
||||||
|
|
||||||
if (Type != CAPTURES && Type != EVASIONS && pos.can_castle(Us))
|
if (Type != CAPTURES && pos.can_castle(CastlingRights(OO | OOO)))
|
||||||
{
|
|
||||||
if (pos.is_chess960())
|
|
||||||
{
|
{
|
||||||
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
|
if (!pos.castling_impeded(OO) && pos.can_castle(OO))
|
||||||
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
|
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OO));
|
||||||
}
|
|
||||||
else
|
if (!pos.castling_impeded(OOO) && pos.can_castle(OOO))
|
||||||
{
|
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OOO));
|
||||||
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
|
|
||||||
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,19 +249,16 @@ namespace {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
/// generate<CAPTURES> generates all pseudo-legal captures and queen
|
/// <CAPTURES> Generates all pseudo-legal captures and queen promotions
|
||||||
/// promotions. Returns a pointer to the end of the move list.
|
/// <QUIETS> Generates all pseudo-legal non-captures and underpromotions
|
||||||
|
/// <NON_EVASIONS> Generates all pseudo-legal captures and non-captures
|
||||||
///
|
///
|
||||||
/// generate<QUIETS> generates all pseudo-legal non-captures and
|
/// Returns a pointer to the end of the move list.
|
||||||
/// underpromotions. Returns a pointer to the end of the move list.
|
|
||||||
///
|
|
||||||
/// generate<NON_EVASIONS> generates all pseudo-legal captures and
|
|
||||||
/// non-captures. Returns a pointer to the end of the move list.
|
|
||||||
|
|
||||||
template<GenType Type>
|
template<GenType Type>
|
||||||
ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS);
|
static_assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS, "Unsupported type in generate()");
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
@@ -335,8 +285,7 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
|||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
CheckInfo ci(pos);
|
Bitboard dc = pos.blockers_for_king(~us) & pos.pieces(us);
|
||||||
Bitboard dc = ci.dcCandidates;
|
|
||||||
|
|
||||||
while (dc)
|
while (dc)
|
||||||
{
|
{
|
||||||
@@ -346,17 +295,17 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
|||||||
if (pt == PAWN)
|
if (pt == PAWN)
|
||||||
continue; // Will be generated together with direct checks
|
continue; // Will be generated together with direct checks
|
||||||
|
|
||||||
Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.pieces();
|
Bitboard b = pos.attacks_from(pt, from) & ~pos.pieces();
|
||||||
|
|
||||||
if (pt == KING)
|
if (pt == KING)
|
||||||
b &= ~PseudoAttacks[QUEEN][ci.ksq];
|
b &= ~PseudoAttacks[QUEEN][pos.square<KING>(~us)];
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(from, pop_lsb(&b));
|
*moveList++ = make_move(from, pop_lsb(&b));
|
||||||
}
|
}
|
||||||
|
|
||||||
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci)
|
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces())
|
||||||
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci);
|
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -403,15 +352,16 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
|||||||
template<>
|
template<>
|
||||||
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
|
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
Color us = pos.side_to_move();
|
||||||
Square ksq = pos.square<KING>(pos.side_to_move());
|
Bitboard pinned = pos.blockers_for_king(us) & pos.pieces(us);
|
||||||
|
Square ksq = pos.square<KING>(us);
|
||||||
ExtMove* cur = moveList;
|
ExtMove* cur = moveList;
|
||||||
|
|
||||||
moveList = pos.checkers() ? generate<EVASIONS >(pos, moveList)
|
moveList = pos.checkers() ? generate<EVASIONS >(pos, moveList)
|
||||||
: generate<NON_EVASIONS>(pos, moveList);
|
: generate<NON_EVASIONS>(pos, moveList);
|
||||||
while (cur != moveList)
|
while (cur != moveList)
|
||||||
if ( (pinned || from_sq(*cur) == ksq || type_of(*cur) == ENPASSANT)
|
if ( (pinned || from_sq(*cur) == ksq || type_of(*cur) == ENPASSANT)
|
||||||
&& !pos.legal(*cur, pinned))
|
&& !pos.legal(*cur))
|
||||||
*cur = (--moveList)->move;
|
*cur = (--moveList)->move;
|
||||||
else
|
else
|
||||||
++cur;
|
++cur;
|
||||||
|
|||||||
+9
-4
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
#ifndef MOVEGEN_H_INCLUDED
|
#ifndef MOVEGEN_H_INCLUDED
|
||||||
#define MOVEGEN_H_INCLUDED
|
#define MOVEGEN_H_INCLUDED
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
class Position;
|
class Position;
|
||||||
@@ -36,10 +38,14 @@ enum GenType {
|
|||||||
|
|
||||||
struct ExtMove {
|
struct ExtMove {
|
||||||
Move move;
|
Move move;
|
||||||
Value value;
|
int value;
|
||||||
|
|
||||||
operator Move() const { return move; }
|
operator Move() const { return move; }
|
||||||
void operator=(Move m) { move = m; }
|
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) {
|
inline bool operator<(const ExtMove& f, const ExtMove& s) {
|
||||||
@@ -59,8 +65,7 @@ struct MoveList {
|
|||||||
const ExtMove* end() const { return last; }
|
const ExtMove* end() const { return last; }
|
||||||
size_t size() const { return last - moveList; }
|
size_t size() const { return last - moveList; }
|
||||||
bool contains(Move move) const {
|
bool contains(Move move) const {
|
||||||
for (const auto& m : *this) if (m == move) return true;
|
return std::find(begin(), end(), move) != end();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+193
-240
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,41 +21,29 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "thread.h"
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum Stages {
|
enum Stages {
|
||||||
MAIN_SEARCH, GOOD_CAPTURES, KILLERS, GOOD_QUIETS, BAD_QUIETS, BAD_CAPTURES,
|
MAIN_TT, CAPTURE_INIT, GOOD_CAPTURE, REFUTATION, QUIET_INIT, QUIET, BAD_CAPTURE,
|
||||||
EVASION, ALL_EVASIONS,
|
EVASION_TT, EVASION_INIT, EVASION,
|
||||||
QSEARCH_WITH_CHECKS, QCAPTURES_1, CHECKS,
|
PROBCUT_TT, PROBCUT_INIT, PROBCUT,
|
||||||
QSEARCH_WITHOUT_CHECKS, QCAPTURES_2,
|
QSEARCH_TT, QCAPTURE_INIT, QCAPTURE, QCHECK_INIT, QCHECK
|
||||||
PROBCUT, PROBCUT_CAPTURES,
|
|
||||||
RECAPTURE, RECAPTURES,
|
|
||||||
STOP
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Our insertion sort, which is guaranteed to be stable, as it should be
|
// partial_insertion_sort() sorts moves in descending order up to and including
|
||||||
void insertion_sort(ExtMove* begin, ExtMove* end)
|
// a given limit. The order of moves smaller than the limit is left unspecified.
|
||||||
{
|
void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit) {
|
||||||
ExtMove tmp, *p, *q;
|
|
||||||
|
|
||||||
for (p = begin + 1; p < end; ++p)
|
for (ExtMove *sortedEnd = begin, *p = begin + 1; p < end; ++p)
|
||||||
{
|
if (p->value >= limit)
|
||||||
tmp = *p;
|
{
|
||||||
for (q = p; q != begin && *(q-1) < tmp; --q)
|
ExtMove tmp = *p, *q;
|
||||||
*q = *(q-1);
|
*p = *++sortedEnd;
|
||||||
*q = tmp;
|
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
|
} // namespace
|
||||||
@@ -64,255 +52,220 @@ namespace {
|
|||||||
/// Constructors of the MovePicker class. As arguments we pass information
|
/// Constructors of the MovePicker class. As arguments we pass 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 how important good move
|
/// search captures, promotions, and some checks) and how important good move
|
||||||
/// ordering is at the current node.
|
/// ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
|
/// MovePicker constructor for the main search
|
||||||
const CounterMovesStats& cmh, Move cm, Search::Stack* s)
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||||
: pos(p), history(h), counterMovesHistory(&cmh), ss(s), countermove(cm), depth(d) {
|
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers)
|
||||||
|
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch),
|
||||||
|
refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d) {
|
||||||
|
|
||||||
assert(d > DEPTH_ZERO);
|
assert(d > 0);
|
||||||
|
|
||||||
stage = pos.checkers() ? EVASION : MAIN_SEARCH;
|
stage = pos.checkers() ? EVASION_TT : MAIN_TT;
|
||||||
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
/// MovePicker constructor for quiescence search
|
||||||
const HistoryStats& h, Square s)
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||||
: pos(p), history(h), counterMovesHistory(nullptr) {
|
const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
|
||||||
|
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch), recaptureSquare(rs), depth(d) {
|
||||||
|
|
||||||
assert(d <= DEPTH_ZERO);
|
assert(d <= 0);
|
||||||
|
|
||||||
if (pos.checkers())
|
stage = pos.checkers() ? EVASION_TT : QSEARCH_TT;
|
||||||
stage = EVASION;
|
ttMove = ttm
|
||||||
|
&& (depth > DEPTH_QS_RECAPTURES || to_sq(ttm) == recaptureSquare)
|
||||||
else if (d > DEPTH_QS_NO_CHECKS)
|
&& pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
stage = QSEARCH_WITH_CHECKS;
|
stage += (ttMove == MOVE_NONE);
|
||||||
|
|
||||||
else if (d > DEPTH_QS_RECAPTURES)
|
|
||||||
stage = QSEARCH_WITHOUT_CHECKS;
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stage = RECAPTURE;
|
|
||||||
recaptureSquare = s;
|
|
||||||
ttm = MOVE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, Value th)
|
/// MovePicker constructor for ProbCut: we generate captures with SEE greater
|
||||||
: pos(p), history(h), counterMovesHistory(nullptr), threshold(th) {
|
/// than or equal to the given threshold.
|
||||||
|
MovePicker::MovePicker(const Position& p, Move ttm, Value th, const CapturePieceToHistory* cph)
|
||||||
|
: pos(p), captureHistory(cph), threshold(th) {
|
||||||
|
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
stage = PROBCUT;
|
stage = PROBCUT_TT;
|
||||||
|
|
||||||
// In ProbCut we generate captures with SEE higher than the given threshold
|
|
||||||
ttMove = ttm
|
ttMove = ttm
|
||||||
&& pos.pseudo_legal(ttm)
|
|
||||||
&& pos.capture(ttm)
|
&& pos.capture(ttm)
|
||||||
&& pos.see(ttm) > threshold ? ttm : MOVE_NONE;
|
&& pos.pseudo_legal(ttm)
|
||||||
|
&& pos.see_ge(ttm, threshold) ? ttm : MOVE_NONE;
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// MovePicker::score() assigns a numerical value to each move in a list, used
|
||||||
|
/// for sorting. Captures are ordered by Most Valuable Victim (MVV), preferring
|
||||||
|
/// captures with a good history. Quiets moves are ordered using the histories.
|
||||||
|
template<GenType Type>
|
||||||
|
void MovePicker::score() {
|
||||||
|
|
||||||
/// score() assigns a numerical value to each move in a move list. The moves with
|
static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
|
||||||
/// highest values will be picked first.
|
|
||||||
template<>
|
|
||||||
void MovePicker::score<CAPTURES>() {
|
|
||||||
// Winning and equal captures in the main search are ordered by MVV, preferring
|
|
||||||
// captures near our home rank. Surprisingly, this appears to perform slightly
|
|
||||||
// better than SEE based move ordering: exchanging big pieces before capturing
|
|
||||||
// a hanging piece probably helps to reduce the subtree size.
|
|
||||||
// In main search we want to push captures with negative SEE values to the
|
|
||||||
// badCaptures[] array, but instead of doing it now we delay until the move
|
|
||||||
// has been picked up, saving some SEE calls in case we get a cutoff.
|
|
||||||
for (auto& m : *this)
|
|
||||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
|
||||||
- Value(200 * relative_rank(pos.side_to_move(), to_sq(m)));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void MovePicker::score<QUIETS>() {
|
|
||||||
|
|
||||||
for (auto& m : *this)
|
for (auto& m : *this)
|
||||||
m.value = history[pos.moved_piece(m)][to_sq(m)]
|
if (Type == CAPTURES)
|
||||||
+ (*counterMovesHistory)[pos.moved_piece(m)][to_sq(m)];
|
m.value = int(PieceValue[MG][pos.piece_on(to_sq(m))]) * 6
|
||||||
|
+ (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))];
|
||||||
|
|
||||||
|
else if (Type == QUIETS)
|
||||||
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||||
|
+ 2 * (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
+ 2 * (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
+ 2 * (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
+ (*continuationHistory[5])[pos.moved_piece(m)][to_sq(m)];
|
||||||
|
|
||||||
|
else // Type == EVASIONS
|
||||||
|
{
|
||||||
|
if (pos.capture(m))
|
||||||
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||||
|
- Value(type_of(pos.moved_piece(m)));
|
||||||
|
else
|
||||||
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||||
|
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
- (1 << 28);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
/// MovePicker::select() returns the next move satisfying a predicate function.
|
||||||
void MovePicker::score<EVASIONS>() {
|
/// It never returns the TT move.
|
||||||
// Try winning and equal captures captures ordered by MVV/LVA, then non-captures
|
template<MovePicker::PickType T, typename Pred>
|
||||||
// ordered by history value, then bad-captures and quiet moves with a negative
|
Move MovePicker::select(Pred filter) {
|
||||||
// SEE ordered by SEE value.
|
|
||||||
Value see;
|
|
||||||
|
|
||||||
for (auto& m : *this)
|
while (cur < endMoves)
|
||||||
if ((see = pos.see_sign(m)) < VALUE_ZERO)
|
|
||||||
m.value = see - HistoryStats::Max; // At the bottom
|
|
||||||
|
|
||||||
else if (pos.capture(m))
|
|
||||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
|
||||||
- Value(type_of(pos.moved_piece(m))) + HistoryStats::Max;
|
|
||||||
else
|
|
||||||
m.value = history[pos.moved_piece(m)][to_sq(m)];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// generate_next_stage() generates, scores and sorts the next bunch of moves,
|
|
||||||
/// when there are no more moves to try for the current stage.
|
|
||||||
|
|
||||||
void MovePicker::generate_next_stage() {
|
|
||||||
|
|
||||||
assert(stage != STOP);
|
|
||||||
|
|
||||||
cur = moves;
|
|
||||||
|
|
||||||
switch (++stage) {
|
|
||||||
|
|
||||||
case GOOD_CAPTURES: case QCAPTURES_1: case QCAPTURES_2:
|
|
||||||
case PROBCUT_CAPTURES: case RECAPTURES:
|
|
||||||
endMoves = generate<CAPTURES>(pos, moves);
|
|
||||||
score<CAPTURES>();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KILLERS:
|
|
||||||
killers[0] = ss->killers[0];
|
|
||||||
killers[1] = ss->killers[1];
|
|
||||||
killers[2] = countermove;
|
|
||||||
cur = killers;
|
|
||||||
endMoves = cur + 2 + (countermove != killers[0] && countermove != killers[1]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GOOD_QUIETS:
|
|
||||||
endQuiets = endMoves = generate<QUIETS>(pos, moves);
|
|
||||||
score<QUIETS>();
|
|
||||||
endMoves = std::partition(cur, endMoves, [](const ExtMove& m) { return m.value > VALUE_ZERO; });
|
|
||||||
insertion_sort(cur, endMoves);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BAD_QUIETS:
|
|
||||||
cur = endMoves;
|
|
||||||
endMoves = endQuiets;
|
|
||||||
if (depth >= 3 * ONE_PLY)
|
|
||||||
insertion_sort(cur, endMoves);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BAD_CAPTURES:
|
|
||||||
// Just pick them in reverse order to get correct ordering
|
|
||||||
cur = moves + MAX_MOVES - 1;
|
|
||||||
endMoves = endBadCaptures;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ALL_EVASIONS:
|
|
||||||
endMoves = generate<EVASIONS>(pos, moves);
|
|
||||||
if (endMoves - moves > 1)
|
|
||||||
score<EVASIONS>();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CHECKS:
|
|
||||||
endMoves = generate<QUIET_CHECKS>(pos, moves);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVASION: case QSEARCH_WITH_CHECKS: case QSEARCH_WITHOUT_CHECKS:
|
|
||||||
case PROBCUT: case RECAPTURE: case STOP:
|
|
||||||
stage = STOP;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// next_move() is the most important method of the MovePicker class. It returns
|
|
||||||
/// a new pseudo legal move every time it is called, until there are no more moves
|
|
||||||
/// left. It picks the move with the biggest value from a list of generated moves
|
|
||||||
/// taking care not to return the ttMove if it has already been searched.
|
|
||||||
|
|
||||||
Move MovePicker::next_move() {
|
|
||||||
|
|
||||||
Move move;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
while (cur == endMoves && stage != STOP)
|
if (T == Best)
|
||||||
generate_next_stage();
|
std::swap(*cur, *std::max_element(cur, endMoves));
|
||||||
|
|
||||||
switch (stage) {
|
if (*cur != ttMove && filter())
|
||||||
|
return *cur++;
|
||||||
|
|
||||||
case MAIN_SEARCH: case EVASION: case QSEARCH_WITH_CHECKS:
|
cur++;
|
||||||
case QSEARCH_WITHOUT_CHECKS: case PROBCUT:
|
}
|
||||||
++cur;
|
return MOVE_NONE;
|
||||||
return ttMove;
|
}
|
||||||
|
|
||||||
case GOOD_CAPTURES:
|
/// MovePicker::next_move() is the most important method of the MovePicker class. It
|
||||||
move = pick_best(cur++, endMoves);
|
/// returns a new pseudo legal move every time it is called until there are no more
|
||||||
if (move != ttMove)
|
/// moves left, picking the move with the highest score from a list of generated moves.
|
||||||
{
|
Move MovePicker::next_move(bool skipQuiets) {
|
||||||
if (pos.see_sign(move) >= VALUE_ZERO)
|
|
||||||
return move;
|
|
||||||
|
|
||||||
// Losing capture, move it to the tail of the array
|
top:
|
||||||
*endBadCaptures-- = move;
|
switch (stage) {
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KILLERS:
|
case MAIN_TT:
|
||||||
move = *cur++;
|
case EVASION_TT:
|
||||||
if ( move != MOVE_NONE
|
case QSEARCH_TT:
|
||||||
&& move != ttMove
|
case PROBCUT_TT:
|
||||||
&& pos.pseudo_legal(move)
|
++stage;
|
||||||
&& !pos.capture(move))
|
return ttMove;
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GOOD_QUIETS: case BAD_QUIETS:
|
case CAPTURE_INIT:
|
||||||
move = *cur++;
|
case PROBCUT_INIT:
|
||||||
if ( move != ttMove
|
case QCAPTURE_INIT:
|
||||||
&& move != killers[0]
|
cur = endBadCaptures = moves;
|
||||||
&& move != killers[1]
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
&& move != killers[2])
|
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BAD_CAPTURES:
|
score<CAPTURES>();
|
||||||
return *cur--;
|
++stage;
|
||||||
|
goto top;
|
||||||
|
|
||||||
case ALL_EVASIONS: case QCAPTURES_1: case QCAPTURES_2:
|
case GOOD_CAPTURE:
|
||||||
move = pick_best(cur++, endMoves);
|
if (select<Best>([&](){
|
||||||
if (move != ttMove)
|
return pos.see_ge(*cur, Value(-55 * cur->value / 1024)) ?
|
||||||
return move;
|
// Move losing capture to endBadCaptures to be tried later
|
||||||
break;
|
true : (*endBadCaptures++ = *cur, false); }))
|
||||||
|
return *(cur - 1);
|
||||||
|
|
||||||
case PROBCUT_CAPTURES:
|
// Prepare the pointers to loop over the refutations array
|
||||||
move = pick_best(cur++, endMoves);
|
cur = std::begin(refutations);
|
||||||
if (move != ttMove && pos.see(move) > threshold)
|
endMoves = std::end(refutations);
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RECAPTURES:
|
// If the countermove is the same as a killer, skip it
|
||||||
move = pick_best(cur++, endMoves);
|
if ( refutations[0].move == refutations[2].move
|
||||||
if (to_sq(move) == recaptureSquare)
|
|| refutations[1].move == refutations[2].move)
|
||||||
return move;
|
--endMoves;
|
||||||
break;
|
|
||||||
|
|
||||||
case CHECKS:
|
++stage;
|
||||||
move = *cur++;
|
/* fallthrough */
|
||||||
if (move != ttMove)
|
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STOP:
|
case REFUTATION:
|
||||||
|
if (select<Next>([&](){ return *cur != MOVE_NONE
|
||||||
|
&& !pos.capture(*cur)
|
||||||
|
&& pos.pseudo_legal(*cur); }))
|
||||||
|
return *(cur - 1);
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QUIET_INIT:
|
||||||
|
if (!skipQuiets)
|
||||||
|
{
|
||||||
|
cur = endBadCaptures;
|
||||||
|
endMoves = generate<QUIETS>(pos, cur);
|
||||||
|
|
||||||
|
score<QUIETS>();
|
||||||
|
partial_insertion_sort(cur, endMoves, -3000 * depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QUIET:
|
||||||
|
if ( !skipQuiets
|
||||||
|
&& select<Next>([&](){return *cur != refutations[0].move
|
||||||
|
&& *cur != refutations[1].move
|
||||||
|
&& *cur != refutations[2].move;}))
|
||||||
|
return *(cur - 1);
|
||||||
|
|
||||||
|
// Prepare the pointers to loop over the bad captures
|
||||||
|
cur = moves;
|
||||||
|
endMoves = endBadCaptures;
|
||||||
|
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case BAD_CAPTURE:
|
||||||
|
return select<Next>([](){ return true; });
|
||||||
|
|
||||||
|
case EVASION_INIT:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<EVASIONS>(pos, cur);
|
||||||
|
|
||||||
|
score<EVASIONS>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case EVASION:
|
||||||
|
return select<Best>([](){ return true; });
|
||||||
|
|
||||||
|
case PROBCUT:
|
||||||
|
return select<Best>([&](){ return pos.see_ge(*cur, threshold); });
|
||||||
|
|
||||||
|
case QCAPTURE:
|
||||||
|
if (select<Best>([&](){ return depth > DEPTH_QS_RECAPTURES
|
||||||
|
|| to_sq(*cur) == recaptureSquare; }))
|
||||||
|
return *(cur - 1);
|
||||||
|
|
||||||
|
// If we did not find any move and we do not try checks, we have finished
|
||||||
|
if (depth != DEPTH_QS_CHECKS)
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
|
|
||||||
default:
|
++stage;
|
||||||
assert(false);
|
/* fallthrough */
|
||||||
}
|
|
||||||
|
case QCHECK_INIT:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
||||||
|
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QCHECK:
|
||||||
|
return select<Next>([](){ return true; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(false);
|
||||||
|
return MOVE_NONE; // Silence warning
|
||||||
}
|
}
|
||||||
|
|||||||
+92
-54
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,54 +21,87 @@
|
|||||||
#ifndef MOVEPICK_H_INCLUDED
|
#ifndef MOVEPICK_H_INCLUDED
|
||||||
#define MOVEPICK_H_INCLUDED
|
#define MOVEPICK_H_INCLUDED
|
||||||
|
|
||||||
#include <algorithm> // For std::max
|
#include <array>
|
||||||
#include <cstring> // For std::memset
|
#include <limits>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
/// StatsEntry stores the stat table value. It is usually a number but could
|
||||||
|
/// be a move or even a nested history. We use a class instead of naked value
|
||||||
|
/// to directly call history update operator<<() on the entry so to use stats
|
||||||
|
/// tables at caller sites as simple multi-dim arrays.
|
||||||
|
template<typename T, int D>
|
||||||
|
class StatsEntry {
|
||||||
|
|
||||||
/// The Stats struct stores moves statistics. According to the template parameter
|
T entry;
|
||||||
/// the class can store History and Countermoves. History records how often
|
|
||||||
/// different moves have been successful or unsuccessful during the current search
|
|
||||||
/// and is used for reduction and move ordering decisions.
|
|
||||||
/// Countermoves store the move that refute a previous one. Entries are stored
|
|
||||||
/// using only the moving piece and destination square, hence two moves with
|
|
||||||
/// different origin but same destination and piece will be considered identical.
|
|
||||||
template<typename T, bool CM = false>
|
|
||||||
struct Stats {
|
|
||||||
|
|
||||||
static const Value Max = Value(1 << 28);
|
public:
|
||||||
|
void operator=(const T& v) { entry = v; }
|
||||||
|
T* operator&() { return &entry; }
|
||||||
|
T* operator->() { return &entry; }
|
||||||
|
operator const T&() const { return entry; }
|
||||||
|
|
||||||
const T* operator[](Piece pc) const { return table[pc]; }
|
void operator<<(int bonus) {
|
||||||
T* operator[](Piece pc) { return table[pc]; }
|
assert(abs(bonus) <= D); // Ensure range is [-D, D]
|
||||||
void clear() { std::memset(table, 0, sizeof(table)); }
|
static_assert(D <= std::numeric_limits<T>::max(), "D overflows T");
|
||||||
|
|
||||||
void update(Piece pc, Square to, Move m) {
|
entry += bonus - entry * abs(bonus) / D;
|
||||||
|
|
||||||
if (m != table[pc][to])
|
assert(abs(entry) <= D);
|
||||||
table[pc][to] = m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(Piece pc, Square to, Value v) {
|
|
||||||
|
|
||||||
if (abs(int(v)) >= 324)
|
|
||||||
return;
|
|
||||||
|
|
||||||
table[pc][to] -= table[pc][to] * abs(int(v)) / (CM ? 512 : 324);
|
|
||||||
table[pc][to] += int(v) * (CM ? 64 : 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
T table[PIECE_NB][SQUARE_NB];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Stats<Move> MovesStats;
|
/// Stats is a generic N-dimensional array used to store various statistics.
|
||||||
typedef Stats<Value, false> HistoryStats;
|
/// The first template parameter T is the base type of the array, the second
|
||||||
typedef Stats<Value, true> CounterMovesStats;
|
/// template parameter D limits the range of updates in [-D, D] when we update
|
||||||
typedef Stats<CounterMovesStats> CounterMovesHistoryStats;
|
/// values with the << operator, while the last parameters (Size and Sizes)
|
||||||
|
/// encode the dimensions of the array.
|
||||||
|
template <typename T, int D, int Size, int... Sizes>
|
||||||
|
struct Stats : public std::array<Stats<T, D, Sizes...>, Size>
|
||||||
|
{
|
||||||
|
typedef Stats<T, D, Size, Sizes...> stats;
|
||||||
|
|
||||||
|
void fill(const T& v) {
|
||||||
|
|
||||||
|
// For standard-layout 'this' points to first struct member
|
||||||
|
assert(std::is_standard_layout<stats>::value);
|
||||||
|
|
||||||
|
typedef StatsEntry<T, D> entry;
|
||||||
|
entry* p = reinterpret_cast<entry*>(this);
|
||||||
|
std::fill(p, p + sizeof(*this) / sizeof(entry), v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, int D, int Size>
|
||||||
|
struct Stats<T, D, Size> : public std::array<StatsEntry<T, D>, Size> {};
|
||||||
|
|
||||||
|
/// In stats table, D=0 means that the template parameter is not used
|
||||||
|
enum StatsParams { NOT_USED = 0 };
|
||||||
|
enum StatsType { NoCaptures, Captures };
|
||||||
|
|
||||||
|
/// ButterflyHistory records how often quiet moves have been successful or
|
||||||
|
/// unsuccessful during the current search, and is used for reduction and move
|
||||||
|
/// ordering decisions. It uses 2 tables (one for each color) indexed by
|
||||||
|
/// the move's from and to squares, see www.chessprogramming.org/Butterfly_Boards
|
||||||
|
typedef Stats<int16_t, 10692, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyHistory;
|
||||||
|
|
||||||
|
/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous
|
||||||
|
/// move, see www.chessprogramming.org/Countermove_Heuristic
|
||||||
|
typedef Stats<Move, NOT_USED, PIECE_NB, SQUARE_NB> CounterMoveHistory;
|
||||||
|
|
||||||
|
/// CapturePieceToHistory is addressed by a move's [piece][to][captured piece type]
|
||||||
|
typedef Stats<int16_t, 10692, PIECE_NB, SQUARE_NB, PIECE_TYPE_NB> CapturePieceToHistory;
|
||||||
|
|
||||||
|
/// PieceToHistory is like ButterflyHistory but is addressed by a move's [piece][to]
|
||||||
|
typedef Stats<int16_t, 29952, PIECE_NB, SQUARE_NB> PieceToHistory;
|
||||||
|
|
||||||
|
/// ContinuationHistory is the combined history of a given pair of moves, usually
|
||||||
|
/// the current one given a previous one. The nested history table is based on
|
||||||
|
/// PieceToHistory instead of ButterflyBoards.
|
||||||
|
typedef Stats<PieceToHistory, NOT_USED, PIECE_NB, SQUARE_NB> ContinuationHistory;
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
||||||
@@ -77,37 +110,42 @@ typedef Stats<CounterMovesStats> CounterMovesHistoryStats;
|
|||||||
/// when MOVE_NONE is returned. In order to improve the efficiency of the alpha
|
/// when MOVE_NONE is returned. In order to improve the efficiency of the alpha
|
||||||
/// beta algorithm, MovePicker attempts to return the moves which are most likely
|
/// beta algorithm, MovePicker attempts to return the moves which are most likely
|
||||||
/// to get a cut-off first.
|
/// to get a cut-off first.
|
||||||
|
|
||||||
class MovePicker {
|
class MovePicker {
|
||||||
|
|
||||||
|
enum PickType { Next, Best };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MovePicker(const MovePicker&) = delete;
|
MovePicker(const MovePicker&) = delete;
|
||||||
MovePicker& operator=(const MovePicker&) = delete;
|
MovePicker& operator=(const MovePicker&) = delete;
|
||||||
|
MovePicker(const Position&, Move, Value, const CapturePieceToHistory*);
|
||||||
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
|
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
|
||||||
MovePicker(const Position&, Move, const HistoryStats&, Value);
|
const CapturePieceToHistory*,
|
||||||
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMovesStats&, Move, Search::Stack*);
|
const PieceToHistory**,
|
||||||
|
Square);
|
||||||
Move next_move();
|
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
|
||||||
|
const CapturePieceToHistory*,
|
||||||
|
const PieceToHistory**,
|
||||||
|
Move,
|
||||||
|
Move*);
|
||||||
|
Move next_move(bool skipQuiets = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template<PickType T, typename Pred> Move select(Pred);
|
||||||
template<GenType> void score();
|
template<GenType> void score();
|
||||||
void generate_next_stage();
|
ExtMove* begin() { return cur; }
|
||||||
ExtMove* begin() { return moves; }
|
|
||||||
ExtMove* end() { return endMoves; }
|
ExtMove* end() { return endMoves; }
|
||||||
|
|
||||||
const Position& pos;
|
const Position& pos;
|
||||||
const HistoryStats& history;
|
const ButterflyHistory* mainHistory;
|
||||||
const CounterMovesStats* counterMovesHistory;
|
const CapturePieceToHistory* captureHistory;
|
||||||
Search::Stack* ss;
|
const PieceToHistory** continuationHistory;
|
||||||
Move countermove;
|
|
||||||
Depth depth;
|
|
||||||
Move ttMove;
|
Move ttMove;
|
||||||
ExtMove killers[3];
|
ExtMove refutations[3], *cur, *endMoves, *endBadCaptures;
|
||||||
|
int stage;
|
||||||
Square recaptureSquare;
|
Square recaptureSquare;
|
||||||
Value threshold;
|
Value threshold;
|
||||||
int stage;
|
Depth depth;
|
||||||
ExtMove *endQuiets, *endBadCaptures = moves + MAX_MOVES - 1;
|
ExtMove moves[MAX_MOVES];
|
||||||
ExtMove moves[MAX_MOVES], *cur = moves, *endMoves = moves;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #ifndef MOVEPICK_H_INCLUDED
|
#endif // #ifndef MOVEPICK_H_INCLUDED
|
||||||
|
|||||||
+129
-193
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#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"
|
#include "thread.h"
|
||||||
@@ -32,64 +31,36 @@ namespace {
|
|||||||
#define V Value
|
#define V Value
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
|
|
||||||
// Isolated pawn penalty by opposed flag and file
|
// Pawn penalties
|
||||||
const Score Isolated[2][FILE_NB] = {
|
constexpr Score Backward = S( 9, 24);
|
||||||
{ S(37, 45), S(54, 52), S(60, 52), S(60, 52),
|
constexpr Score BlockedStorm = S(82, 82);
|
||||||
S(60, 52), S(60, 52), S(54, 52), S(37, 45) },
|
constexpr Score Doubled = S(11, 56);
|
||||||
{ S(25, 30), S(36, 35), S(40, 35), S(40, 35),
|
constexpr Score Isolated = S( 5, 15);
|
||||||
S(40, 35), S(40, 35), S(36, 35), S(25, 30) } };
|
constexpr Score WeakLever = S( 0, 56);
|
||||||
|
constexpr Score WeakUnopposed = S(13, 27);
|
||||||
|
|
||||||
// Backward pawn penalty by opposed flag
|
// Connected pawn bonus
|
||||||
const Score Backward[2] = { S(67, 42), S(49, 24) };
|
constexpr int Connected[RANK_NB] = { 0, 7, 8, 12, 29, 48, 86 };
|
||||||
|
|
||||||
// Unsupported pawn penalty, for pawns which are neither isolated or backward
|
|
||||||
const Score Unsupported = S(20, 10);
|
|
||||||
|
|
||||||
// Connected pawn bonus by opposed, phalanx, twice supported and rank
|
// Strength of pawn shelter for our king by [distance from edge][rank].
|
||||||
Score Connected[2][2][2][RANK_NB];
|
// RANK_1 = 0 is used for files where we have no pawn, or pawn is behind our king.
|
||||||
|
constexpr Value ShelterStrength[int(FILE_NB) / 2][RANK_NB] = {
|
||||||
// Doubled pawn penalty by file
|
{ V( -6), V( 81), V( 93), V( 58), V( 39), V( 18), V( 25) },
|
||||||
const Score Doubled[FILE_NB] = {
|
{ V(-43), V( 61), V( 35), V(-49), V(-29), V(-11), V( -63) },
|
||||||
S(13, 43), S(20, 48), S(23, 48), S(23, 48),
|
{ V(-10), V( 75), V( 23), V( -2), V( 32), V( 3), V( -45) },
|
||||||
S(23, 48), S(23, 48), S(20, 48), S(13, 43) };
|
{ V(-39), V(-13), V(-29), V(-52), V(-48), V(-67), V(-166) }
|
||||||
|
};
|
||||||
|
|
||||||
// Lever bonus by rank
|
// Danger of enemy pawns moving toward our king by [distance from edge][rank].
|
||||||
const Score Lever[RANK_NB] = {
|
// RANK_1 = 0 is used for files where the enemy has no pawn, or their pawn
|
||||||
S( 0, 0), S( 0, 0), S(0, 0), S(0, 0),
|
// is behind our king. Note that UnblockedStorm[0][1-2] accommodate opponent pawn
|
||||||
S(20, 20), S(40, 40), S(0, 0), S(0, 0) };
|
// on edge, likely blocked by our king.
|
||||||
|
constexpr Value UnblockedStorm[int(FILE_NB) / 2][RANK_NB] = {
|
||||||
// Center bind bonus, when two pawns controls the same central square
|
{ V( 85), V(-289), V(-166), V(97), V(50), V( 45), V( 50) },
|
||||||
const Score CenterBind = S(16, 0);
|
{ V( 46), V( -25), V( 122), V(45), V(37), V(-10), V( 20) },
|
||||||
|
{ V( -6), V( 51), V( 168), V(34), V(-2), V(-22), V(-14) },
|
||||||
// Weakness of our pawn shelter in front of the king by [distance from edge][rank]
|
{ V(-15), V( -11), V( 101), V( 4), V(11), V(-15), V(-29) }
|
||||||
const Value ShelterWeakness[][RANK_NB] = {
|
};
|
||||||
{ V( 97), V(21), V(26), V(51), V(87), V( 89), V( 99) },
|
|
||||||
{ V(120), V( 0), V(28), V(76), V(88), V(103), V(104) },
|
|
||||||
{ V(101), V( 7), V(54), V(78), V(77), V( 92), V(101) },
|
|
||||||
{ V( 80), V(11), V(44), V(68), V(87), V( 90), V(119) } };
|
|
||||||
|
|
||||||
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank]
|
|
||||||
const Value StormDanger[][4][RANK_NB] = {
|
|
||||||
{ { V( 0), V( 67), V( 134), V(38), V(32) },
|
|
||||||
{ V( 0), V( 57), V( 139), V(37), V(22) },
|
|
||||||
{ V( 0), V( 43), V( 115), V(43), V(27) },
|
|
||||||
{ V( 0), V( 68), V( 124), V(57), V(32) } },
|
|
||||||
{ { V(20), V( 43), V( 100), V(56), V(20) },
|
|
||||||
{ V(23), V( 20), V( 98), V(40), V(15) },
|
|
||||||
{ V(23), V( 39), V( 103), V(36), V(18) },
|
|
||||||
{ V(28), V( 19), V( 108), V(42), V(26) } },
|
|
||||||
{ { V( 0), V( 0), V( 75), V(14), V( 2) },
|
|
||||||
{ V( 0), V( 0), V( 150), V(30), V( 4) },
|
|
||||||
{ V( 0), V( 0), V( 160), V(22), V( 5) },
|
|
||||||
{ V( 0), V( 0), V( 166), V(24), V(13) } },
|
|
||||||
{ { V( 0), V(-283), V(-281), V(57), V(31) },
|
|
||||||
{ V( 0), V( 58), V( 141), V(39), V(18) },
|
|
||||||
{ V( 0), V( 65), V( 142), V(48), V(32) },
|
|
||||||
{ V( 0), V( 60), V( 126), V(51), V(19) } } };
|
|
||||||
|
|
||||||
// Max bonus for king safety. Corresponds to start position with all the pawns
|
|
||||||
// in front of the king and no enemy pawn on the horizon.
|
|
||||||
const Value MaxSafetyBonus = V(258);
|
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
#undef V
|
#undef V
|
||||||
@@ -97,109 +68,89 @@ namespace {
|
|||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);
|
constexpr Direction Up = pawn_push(Us);
|
||||||
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
|
||||||
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
|
||||||
|
|
||||||
const Bitboard CenterBindMask =
|
Bitboard neighbours, stoppers, support, phalanx, opposed;
|
||||||
Us == WHITE ? (FileDBB | FileEBB) & (Rank5BB | Rank6BB | Rank7BB)
|
Bitboard lever, leverPush, blocked;
|
||||||
: (FileDBB | FileEBB) & (Rank4BB | Rank3BB | Rank2BB);
|
|
||||||
|
|
||||||
Bitboard b, neighbours, doubled, supported, phalanx;
|
|
||||||
Square s;
|
Square s;
|
||||||
bool passed, isolated, opposed, backward, lever, connected;
|
bool backward, passed, doubled;
|
||||||
Score score = SCORE_ZERO;
|
Score score = SCORE_ZERO;
|
||||||
const Square* pl = pos.squares<PAWN>(Us);
|
const Square* pl = pos.squares<PAWN>(Us);
|
||||||
const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)];
|
|
||||||
|
|
||||||
Bitboard ourPawns = pos.pieces(Us , PAWN);
|
Bitboard ourPawns = pos.pieces( Us, PAWN);
|
||||||
Bitboard theirPawns = pos.pieces(Them, PAWN);
|
Bitboard theirPawns = pos.pieces(Them, PAWN);
|
||||||
|
|
||||||
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = 0;
|
Bitboard doubleAttackThem = pawn_double_attacks_bb<Them>(theirPawns);
|
||||||
|
|
||||||
|
e->passedPawns[Us] = 0;
|
||||||
e->kingSquares[Us] = SQ_NONE;
|
e->kingSquares[Us] = SQ_NONE;
|
||||||
e->semiopenFiles[Us] = 0xFF;
|
e->pawnAttacks[Us] = e->pawnAttacksSpan[Us] = pawn_attacks_bb<Us>(ourPawns);
|
||||||
e->pawnAttacks[Us] = shift_bb<Right>(ourPawns) | shift_bb<Left>(ourPawns);
|
|
||||||
e->pawnsOnSquares[Us][BLACK] = popcount<Max15>(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
|
// Loop through all pawns of the current color and score each pawn
|
||||||
while ((s = *pl++) != SQ_NONE)
|
while ((s = *pl++) != SQ_NONE)
|
||||||
{
|
{
|
||||||
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
||||||
|
|
||||||
File f = file_of(s);
|
Rank r = relative_rank(Us, s);
|
||||||
|
|
||||||
e->semiopenFiles[Us] &= ~(1 << f);
|
|
||||||
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
|
|
||||||
|
|
||||||
// Flag the pawn
|
// Flag the pawn
|
||||||
neighbours = ourPawns & adjacent_files_bb(f);
|
opposed = theirPawns & forward_file_bb(Us, s);
|
||||||
doubled = ourPawns & forward_bb(Us, s);
|
blocked = theirPawns & (s + Up);
|
||||||
opposed = theirPawns & forward_bb(Us, s);
|
stoppers = theirPawns & passed_pawn_span(Us, s);
|
||||||
passed = !(theirPawns & passed_pawn_mask(Us, s));
|
lever = theirPawns & PawnAttacks[Us][s];
|
||||||
lever = theirPawns & pawnAttacksBB[s];
|
leverPush = theirPawns & PawnAttacks[Us][s + Up];
|
||||||
phalanx = neighbours & rank_bb(s);
|
doubled = ourPawns & (s - Up);
|
||||||
supported = neighbours & rank_bb(s - Up);
|
neighbours = ourPawns & adjacent_files_bb(s);
|
||||||
connected = supported | phalanx;
|
phalanx = neighbours & rank_bb(s);
|
||||||
isolated = !neighbours;
|
support = neighbours & rank_bb(s - Up);
|
||||||
|
|
||||||
// Test for backward pawn.
|
// A pawn is backward when it is behind all pawns of the same color on
|
||||||
// If the pawn is passed, isolated, lever or connected it cannot be
|
// the adjacent files and cannot safely advance.
|
||||||
// backward. If there are friendly pawns behind on adjacent files
|
backward = !(neighbours & forward_ranks_bb(Them, s + Up))
|
||||||
// or if it is sufficiently advanced, it cannot be backward either.
|
&& (leverPush | blocked);
|
||||||
if ( (passed | isolated | lever | connected)
|
|
||||||
|| (ourPawns & pawn_attack_span(Them, s))
|
|
||||||
|| (relative_rank(Us, s) >= RANK_5))
|
|
||||||
backward = false;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// We now know there are no friendly pawns beside or behind this
|
|
||||||
// pawn on adjacent files. We now check whether the pawn is
|
|
||||||
// backward by looking in the forward direction on the adjacent
|
|
||||||
// files, and picking the closest pawn there.
|
|
||||||
b = pawn_attack_span(Us, s) & (ourPawns | theirPawns);
|
|
||||||
b = pawn_attack_span(Us, s) & rank_bb(backmost_sq(Us, b));
|
|
||||||
|
|
||||||
// If we have an enemy pawn in the same or next rank, the pawn is
|
// Compute additional span if pawn is not backward nor blocked
|
||||||
// backward because it cannot advance without being captured.
|
if (!backward && !blocked)
|
||||||
backward = (b | shift_bb<Up>(b)) & theirPawns;
|
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
|
||||||
}
|
|
||||||
|
|
||||||
assert(opposed | passed | (pawn_attack_span(Us, s) & theirPawns));
|
// A pawn is passed if one of the three following conditions is true:
|
||||||
|
// (a) there is no stoppers except some levers
|
||||||
|
// (b) the only stoppers are the leverPush, but we outnumber them
|
||||||
|
// (c) there is only one front stopper which can be levered.
|
||||||
|
passed = !(stoppers ^ lever)
|
||||||
|
|| ( !(stoppers ^ leverPush)
|
||||||
|
&& popcount(phalanx) >= popcount(leverPush))
|
||||||
|
|| ( stoppers == blocked && r >= RANK_5
|
||||||
|
&& (shift<Up>(support) & ~(theirPawns | doubleAttackThem)));
|
||||||
|
|
||||||
// Passed pawns will be properly scored in evaluation because we need
|
// Passed pawns will be properly scored later in evaluation when we have
|
||||||
// full attack info to evaluate them. Only the frontmost passed
|
// full attack info.
|
||||||
// pawn on each file is considered a true passed pawn.
|
if (passed)
|
||||||
if (passed && !doubled)
|
|
||||||
e->passedPawns[Us] |= s;
|
e->passedPawns[Us] |= s;
|
||||||
|
|
||||||
// Score this pawn
|
// Score this pawn
|
||||||
if (isolated)
|
if (support | phalanx)
|
||||||
score -= Isolated[opposed][f];
|
{
|
||||||
|
int v = Connected[r] * (2 + bool(phalanx) - bool(opposed))
|
||||||
|
+ 21 * popcount(support);
|
||||||
|
|
||||||
|
score += make_score(v, v * (r - 2) / 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!neighbours)
|
||||||
|
score -= Isolated
|
||||||
|
+ WeakUnopposed * !opposed;
|
||||||
|
|
||||||
else if (backward)
|
else if (backward)
|
||||||
score -= Backward[opposed];
|
score -= Backward
|
||||||
|
+ WeakUnopposed * !opposed;
|
||||||
|
|
||||||
else if (!supported)
|
if (!support)
|
||||||
score -= Unsupported;
|
score -= Doubled * doubled
|
||||||
|
+ WeakLever * more_than_one(lever);
|
||||||
if (connected)
|
|
||||||
score += Connected[opposed][!!phalanx][more_than_one(supported)][relative_rank(Us, s)];
|
|
||||||
|
|
||||||
if (doubled)
|
|
||||||
score -= Doubled[f] / distance<Rank>(s, frontmost_sq(Us, doubled));
|
|
||||||
|
|
||||||
if (lever)
|
|
||||||
score += Lever[relative_rank(Us, s)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b = e->semiopenFiles[Us] ^ 0xFF;
|
|
||||||
e->pawnSpan[Us] = b ? int(msb(b) - lsb(b)) : 0;
|
|
||||||
|
|
||||||
b = shift_bb<Right>(ourPawns) & shift_bb<Left>(ourPawns) & CenterBindMask;
|
|
||||||
score += CenterBind * popcount<Max15>(b);
|
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,26 +158,6 @@ namespace {
|
|||||||
|
|
||||||
namespace Pawns {
|
namespace Pawns {
|
||||||
|
|
||||||
/// Pawns::init() initializes some tables needed by evaluation. Instead of using
|
|
||||||
/// hard-coded tables, when makes sense, we prefer to calculate them with a formula
|
|
||||||
/// to reduce independent parameters and to allow easier tuning and better insight.
|
|
||||||
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
static const int Seed[RANK_NB] = { 0, 6, 15, 10, 57, 75, 135, 258 };
|
|
||||||
|
|
||||||
for (int opposed = 0; opposed <= 1; ++opposed)
|
|
||||||
for (int phalanx = 0; phalanx <= 1; ++phalanx)
|
|
||||||
for (int apex = 0; apex <= 1; ++apex)
|
|
||||||
for (Rank r = RANK_2; r < RANK_8; ++r)
|
|
||||||
{
|
|
||||||
int v = (Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0)) >> opposed;
|
|
||||||
v += (apex ? v / 2 : 0);
|
|
||||||
Connected[opposed][phalanx][apex][r] = make_score(3 * v / 2, v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Pawns::probe() looks up the current position's pawns configuration in
|
/// Pawns::probe() looks up the current position's pawns configuration in
|
||||||
/// the pawns hash table. It returns a pointer to the Entry if the position
|
/// the pawns hash table. It returns a pointer to the Entry if the position
|
||||||
/// is found. Otherwise a new Entry is computed and stored there, so we don't
|
/// is found. Otherwise a new Entry is computed and stored there, so we don't
|
||||||
@@ -241,45 +172,46 @@ Entry* probe(const Position& pos) {
|
|||||||
return e;
|
return e;
|
||||||
|
|
||||||
e->key = key;
|
e->key = key;
|
||||||
e->score = evaluate<WHITE>(pos, e) - evaluate<BLACK>(pos, e);
|
e->scores[WHITE] = evaluate<WHITE>(pos, e);
|
||||||
e->asymmetry = popcount<Max15>(e->semiopenFiles[WHITE] ^ e->semiopenFiles[BLACK]);
|
e->scores[BLACK] = evaluate<BLACK>(pos, e);
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Entry::shelter_storm() calculates shelter and storm penalties for the file
|
/// Entry::evaluate_shelter() calculates the shelter bonus and the storm
|
||||||
/// the king is on, as well as the two adjacent files.
|
/// penalty for a king, looking at the king file and the two closest files.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
enum { NoFriendlyPawn, Unblocked, BlockedByPawn, BlockedByKing };
|
Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
|
||||||
|
|
||||||
Bitboard b = pos.pieces(PAWN) & (in_front_bb(Us, rank_of(ksq)) | rank_bb(ksq));
|
|
||||||
Bitboard ourPawns = b & pos.pieces(Us);
|
Bitboard ourPawns = b & pos.pieces(Us);
|
||||||
Bitboard theirPawns = b & pos.pieces(Them);
|
Bitboard theirPawns = b & pos.pieces(Them);
|
||||||
Value safety = MaxSafetyBonus;
|
|
||||||
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
|
|
||||||
|
|
||||||
for (File f = center - File(1); f <= center + File(1); ++f)
|
Score bonus = make_score(5, 5);
|
||||||
|
|
||||||
|
File center = clamp(file_of(ksq), FILE_B, FILE_G);
|
||||||
|
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
||||||
{
|
{
|
||||||
b = ourPawns & file_bb(f);
|
b = ourPawns & file_bb(f);
|
||||||
Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
|
int ourRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
|
||||||
|
|
||||||
b = theirPawns & file_bb(f);
|
b = theirPawns & file_bb(f);
|
||||||
Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
|
int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
|
||||||
|
|
||||||
safety -= ShelterWeakness[std::min(f, FILE_H - f)][rkUs]
|
File d = map_to_queenside(f);
|
||||||
+ StormDanger
|
bonus += make_score(ShelterStrength[d][ourRank], 0);
|
||||||
[f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing :
|
|
||||||
rkUs == RANK_1 ? NoFriendlyPawn :
|
if (ourRank && (ourRank == theirRank - 1))
|
||||||
rkThem == rkUs + 1 ? BlockedByPawn : Unblocked]
|
bonus -= BlockedStorm * int(theirRank == RANK_3);
|
||||||
[std::min(f, FILE_H - f)][rkThem];
|
else
|
||||||
|
bonus -= make_score(UnblockedStorm[d][theirRank], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return safety;
|
return bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -287,33 +219,37 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
|||||||
/// when king square changes, which is about 20% of total king_safety() calls.
|
/// when king square changes, which is about 20% of total king_safety() calls.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score Entry::do_king_safety(const Position& pos, Square ksq) {
|
Score Entry::do_king_safety(const Position& pos) {
|
||||||
|
|
||||||
|
Square ksq = pos.square<KING>(Us);
|
||||||
kingSquares[Us] = ksq;
|
kingSquares[Us] = ksq;
|
||||||
castlingRights[Us] = pos.can_castle(Us);
|
castlingRights[Us] = pos.castling_rights(Us);
|
||||||
int minKingPawnDistance = 0;
|
auto compare = [](Score a, Score b) { return mg_value(a) < mg_value(b); };
|
||||||
|
|
||||||
|
Score shelter = evaluate_shelter<Us>(pos, ksq);
|
||||||
|
|
||||||
|
// If we can castle use the bonus after castling if it is bigger
|
||||||
|
|
||||||
|
if (pos.can_castle(Us & KING_SIDE))
|
||||||
|
shelter = std::max(shelter, evaluate_shelter<Us>(pos, relative_square(Us, SQ_G1)), compare);
|
||||||
|
|
||||||
|
if (pos.can_castle(Us & QUEEN_SIDE))
|
||||||
|
shelter = std::max(shelter, evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1)), compare);
|
||||||
|
|
||||||
|
// In endgame we like to bring our king near our closest pawn
|
||||||
Bitboard pawns = pos.pieces(Us, PAWN);
|
Bitboard pawns = pos.pieces(Us, PAWN);
|
||||||
if (pawns)
|
int minPawnDist = pawns ? 8 : 0;
|
||||||
while (!(DistanceRingBB[ksq][minKingPawnDistance++] & pawns)) {}
|
|
||||||
|
|
||||||
if (relative_rank(Us, ksq) > RANK_4)
|
if (pawns & PseudoAttacks[KING][ksq])
|
||||||
return make_score(0, -16 * minKingPawnDistance);
|
minPawnDist = 1;
|
||||||
|
else while (pawns)
|
||||||
|
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns)));
|
||||||
|
|
||||||
Value bonus = shelter_storm<Us>(pos, ksq);
|
return shelter - make_score(0, 16 * minPawnDist);
|
||||||
|
|
||||||
// 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 Entry::do_king_safety<WHITE>(const Position& pos, Square ksq);
|
template Score Entry::do_king_safety<WHITE>(const Position& pos);
|
||||||
template Score Entry::do_king_safety<BLACK>(const Position& pos, Square ksq);
|
template Score Entry::do_king_safety<BLACK>(const Position& pos);
|
||||||
|
|
||||||
} // namespace Pawns
|
} // namespace Pawns
|
||||||
|
|||||||
+11
-29
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,54 +33,36 @@ namespace Pawns {
|
|||||||
|
|
||||||
struct Entry {
|
struct Entry {
|
||||||
|
|
||||||
Score pawns_score() const { return score; }
|
Score pawn_score(Color c) const { return scores[c]; }
|
||||||
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
|
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
|
||||||
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
|
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
|
||||||
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
|
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
|
||||||
int pawn_span(Color c) const { return pawnSpan[c]; }
|
int passed_count() const { return popcount(passedPawns[WHITE] | passedPawns[BLACK]); }
|
||||||
int pawn_asymmetry() const { return asymmetry; }
|
|
||||||
|
|
||||||
int semiopen_file(Color c, File f) const {
|
template<Color Us>
|
||||||
return semiopenFiles[c] & (1 << f);
|
Score king_safety(const Position& pos) {
|
||||||
}
|
return kingSquares[Us] == pos.square<KING>(Us) && castlingRights[Us] == pos.castling_rights(Us)
|
||||||
|
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos));
|
||||||
int semiopen_side(Color c, File f, bool leftSide) const {
|
|
||||||
return semiopenFiles[c] & (leftSide ? (1 << f) - 1 : ~((1 << (f + 1)) - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
int pawns_on_same_color_squares(Color c, Square s) const {
|
|
||||||
return pawnsOnSquares[c][!!(DarkSquares & s)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score king_safety(const Position& pos, Square ksq) {
|
Score do_king_safety(const Position& pos);
|
||||||
return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
|
|
||||||
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos, ksq));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score do_king_safety(const Position& pos, Square ksq);
|
Score evaluate_shelter(const Position& pos, Square ksq);
|
||||||
|
|
||||||
template<Color Us>
|
|
||||||
Value shelter_storm(const Position& pos, Square ksq);
|
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
Score score;
|
Score scores[COLOR_NB];
|
||||||
Bitboard passedPawns[COLOR_NB];
|
Bitboard passedPawns[COLOR_NB];
|
||||||
Bitboard pawnAttacks[COLOR_NB];
|
Bitboard pawnAttacks[COLOR_NB];
|
||||||
Bitboard pawnAttacksSpan[COLOR_NB];
|
Bitboard pawnAttacksSpan[COLOR_NB];
|
||||||
Square kingSquares[COLOR_NB];
|
Square kingSquares[COLOR_NB];
|
||||||
Score kingSafety[COLOR_NB];
|
Score kingSafety[COLOR_NB];
|
||||||
int castlingRights[COLOR_NB];
|
int castlingRights[COLOR_NB];
|
||||||
int semiopenFiles[COLOR_NB];
|
|
||||||
int pawnSpan[COLOR_NB];
|
|
||||||
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
|
||||||
int asymmetry;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef HashTable<Entry, 16384> Table;
|
typedef HashTable<Entry, 131072> Table;
|
||||||
|
|
||||||
void init();
|
|
||||||
Entry* probe(const Position& pos);
|
Entry* probe(const Position& pos);
|
||||||
|
|
||||||
} // namespace Pawns
|
} // namespace Pawns
|
||||||
|
|||||||
+501
-400
File diff suppressed because it is too large
Load Diff
+136
-121
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,35 +22,13 @@
|
|||||||
#define POSITION_H_INCLUDED
|
#define POSITION_H_INCLUDED
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstddef> // For offsetof()
|
#include <deque>
|
||||||
|
#include <memory> // For std::unique_ptr
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
class Position;
|
|
||||||
class Thread;
|
|
||||||
|
|
||||||
namespace PSQT {
|
|
||||||
|
|
||||||
extern Score psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
|
|
||||||
|
|
||||||
void init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// CheckInfo struct is initialized at constructor time and keeps info used to
|
|
||||||
/// detect if a move gives check.
|
|
||||||
|
|
||||||
struct CheckInfo {
|
|
||||||
|
|
||||||
explicit CheckInfo(const Position&);
|
|
||||||
|
|
||||||
Bitboard dcCandidates;
|
|
||||||
Bitboard pinned;
|
|
||||||
Bitboard checkSquares[PIECE_TYPE_NB];
|
|
||||||
Square ksq;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// StateInfo struct stores information needed to restore a Position object to
|
/// 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
|
/// its previous state when we retract a move. Whenever a move is made on the
|
||||||
@@ -65,35 +43,43 @@ struct StateInfo {
|
|||||||
int castlingRights;
|
int castlingRights;
|
||||||
int rule50;
|
int rule50;
|
||||||
int pliesFromNull;
|
int pliesFromNull;
|
||||||
Score psq;
|
|
||||||
Square epSquare;
|
Square epSquare;
|
||||||
|
|
||||||
// Not copied when making a move
|
// Not copied when making a move (will be recomputed anyhow)
|
||||||
Key key;
|
Key key;
|
||||||
Bitboard checkersBB;
|
Bitboard checkersBB;
|
||||||
PieceType capturedType;
|
Piece capturedPiece;
|
||||||
StateInfo* previous;
|
StateInfo* previous;
|
||||||
|
Bitboard blockersForKing[COLOR_NB];
|
||||||
|
Bitboard pinners[COLOR_NB];
|
||||||
|
Bitboard checkSquares[PIECE_TYPE_NB];
|
||||||
|
int repetition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A list to keep track of the position states along the setup moves (from the
|
||||||
|
/// start position to the position just before the search starts). Needed by
|
||||||
|
/// 'draw by repetition' detection. Use a std::deque because pointers to
|
||||||
|
/// elements are not invalidated upon list resizing.
|
||||||
|
typedef std::unique_ptr<std::deque<StateInfo>> StateListPtr;
|
||||||
|
|
||||||
|
|
||||||
/// Position class stores information regarding the board representation as
|
/// Position class stores information regarding the board representation as
|
||||||
/// pieces, side to move, hash keys, castling info, etc. Important methods are
|
/// pieces, side to move, hash keys, castling info, etc. Important methods are
|
||||||
/// do_move() and undo_move(), used by the search to update node info when
|
/// do_move() and undo_move(), used by the search to update node info when
|
||||||
/// traversing the search tree.
|
/// traversing the search tree.
|
||||||
|
class Thread;
|
||||||
|
|
||||||
class Position {
|
class Position {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
Position() = default; // To define the global object RootPos
|
Position() = default;
|
||||||
Position(const Position&) = delete;
|
Position(const Position&) = delete;
|
||||||
Position(const Position& pos, Thread* th) { *this = pos; thisThread = th; }
|
Position& operator=(const Position&) = delete;
|
||||||
Position(const std::string& f, bool c960, Thread* th) { set(f, c960, th); }
|
|
||||||
Position& operator=(const Position&); // To assign RootPos from UCI
|
|
||||||
|
|
||||||
// FEN string input/output
|
// FEN string input/output
|
||||||
void set(const std::string& fenStr, bool isChess960, Thread* th);
|
Position& set(const std::string& fenStr, bool isChess960, StateInfo* si, Thread* th);
|
||||||
|
Position& set(const std::string& code, Color c, StateInfo* si);
|
||||||
const std::string fen() const;
|
const std::string fen() const;
|
||||||
|
|
||||||
// Position representation
|
// Position representation
|
||||||
@@ -107,86 +93,89 @@ public:
|
|||||||
Square ep_square() const;
|
Square ep_square() const;
|
||||||
bool empty(Square s) const;
|
bool empty(Square s) const;
|
||||||
template<PieceType Pt> int count(Color c) 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> const Square* squares(Color c) const;
|
||||||
template<PieceType Pt> Square square(Color c) const;
|
template<PieceType Pt> Square square(Color c) const;
|
||||||
|
bool is_on_semiopen_file(Color c, Square s) const;
|
||||||
|
|
||||||
// Castling
|
// Castling
|
||||||
int can_castle(Color c) const;
|
int castling_rights(Color c) const;
|
||||||
int can_castle(CastlingRight cr) const;
|
bool can_castle(CastlingRights cr) const;
|
||||||
bool castling_impeded(CastlingRight cr) const;
|
bool castling_impeded(CastlingRights cr) const;
|
||||||
Square castling_rook_square(CastlingRight cr) const;
|
Square castling_rook_square(CastlingRights cr) const;
|
||||||
|
|
||||||
// Checking
|
// Checking
|
||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
Bitboard discovered_check_candidates() const;
|
Bitboard blockers_for_king(Color c) const;
|
||||||
Bitboard pinned_pieces(Color c) const;
|
Bitboard check_squares(PieceType pt) const;
|
||||||
|
bool is_discovery_check_on_king(Color c, Move m) const;
|
||||||
|
|
||||||
// Attacks to/from a given square
|
// Attacks to/from a given square
|
||||||
Bitboard attackers_to(Square s) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
Bitboard attackers_to(Square s, Bitboard occupied) const;
|
Bitboard attackers_to(Square s, Bitboard occupied) const;
|
||||||
Bitboard attacks_from(Piece pc, Square s) const;
|
Bitboard attacks_from(PieceType pt, Square s) const;
|
||||||
template<PieceType> Bitboard attacks_from(Square s) const;
|
template<PieceType> Bitboard attacks_from(Square s) 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 legal(Move m, Bitboard pinned) const;
|
bool legal(Move m) const;
|
||||||
bool pseudo_legal(const Move m) const;
|
bool pseudo_legal(const Move m) const;
|
||||||
bool capture(Move m) const;
|
bool capture(Move m) const;
|
||||||
bool capture_or_promotion(Move m) const;
|
bool capture_or_promotion(Move m) const;
|
||||||
bool gives_check(Move m, const CheckInfo& ci) const;
|
bool gives_check(Move m) const;
|
||||||
bool advanced_pawn_push(Move m) const;
|
bool advanced_pawn_push(Move m) const;
|
||||||
Piece moved_piece(Move m) const;
|
Piece moved_piece(Move m) const;
|
||||||
PieceType captured_piece_type() const;
|
Piece captured_piece() const;
|
||||||
|
|
||||||
// Piece specific
|
// Piece specific
|
||||||
bool pawn_passed(Color c, Square s) const;
|
bool pawn_passed(Color c, Square s) const;
|
||||||
bool opposite_bishops() const;
|
bool opposite_bishops() const;
|
||||||
|
int pawns_on_same_color_squares(Color c, Square s) const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void do_move(Move m, StateInfo& st, bool givesCheck);
|
void do_move(Move m, StateInfo& newSt);
|
||||||
|
void do_move(Move m, StateInfo& newSt, bool givesCheck);
|
||||||
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
|
||||||
Value see(Move m) const;
|
bool see_ge(Move m, Value threshold = VALUE_ZERO) const;
|
||||||
Value see_sign(Move m) const;
|
|
||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key key() const;
|
Key key() const;
|
||||||
Key key_after(Move m) const;
|
Key key_after(Move m) const;
|
||||||
Key exclusion_key() const;
|
|
||||||
Key material_key() const;
|
Key material_key() const;
|
||||||
Key pawn_key() const;
|
Key pawn_key() const;
|
||||||
|
|
||||||
// Other properties of the position
|
// Other properties of the position
|
||||||
Color side_to_move() const;
|
Color side_to_move() const;
|
||||||
Phase game_phase() const;
|
|
||||||
int game_ply() const;
|
int game_ply() const;
|
||||||
bool is_chess960() const;
|
bool is_chess960() const;
|
||||||
Thread* this_thread() const;
|
Thread* this_thread() const;
|
||||||
uint64_t nodes_searched() const;
|
bool is_draw(int ply) const;
|
||||||
void set_nodes_searched(uint64_t n);
|
bool has_game_cycle(int ply) const;
|
||||||
bool is_draw() const;
|
bool has_repeated() const;
|
||||||
int rule50_count() const;
|
int rule50_count() const;
|
||||||
Score psq_score() const;
|
Score psq_score() const;
|
||||||
Value non_pawn_material(Color c) const;
|
Value non_pawn_material(Color c) const;
|
||||||
|
Value non_pawn_material() const;
|
||||||
|
|
||||||
// Position consistency check, for debugging
|
// Position consistency check, for debugging
|
||||||
bool pos_is_ok(int* failedStep = nullptr) const;
|
bool pos_is_ok() const;
|
||||||
void flip();
|
void flip();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Initialization helpers (used while setting up a position)
|
// Initialization helpers (used while setting up a position)
|
||||||
void clear();
|
|
||||||
void set_castling_right(Color c, Square rfrom);
|
void set_castling_right(Color c, Square rfrom);
|
||||||
void set_state(StateInfo* si) const;
|
void set_state(StateInfo* si) const;
|
||||||
|
void set_check_info(StateInfo* si) const;
|
||||||
|
|
||||||
// Other helpers
|
// Other helpers
|
||||||
Bitboard check_blockers(Color c, Color kingColor) const;
|
void put_piece(Piece pc, Square s);
|
||||||
void put_piece(Color c, PieceType pt, Square s);
|
void remove_piece(Piece pc, Square s);
|
||||||
void remove_piece(Color c, PieceType pt, Square s);
|
void move_piece(Piece pc, Square from, Square to);
|
||||||
void move_piece(Color c, PieceType pt, Square from, Square to);
|
|
||||||
template<bool Do>
|
template<bool Do>
|
||||||
void do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto);
|
void do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto);
|
||||||
|
|
||||||
@@ -194,21 +183,24 @@ private:
|
|||||||
Piece board[SQUARE_NB];
|
Piece board[SQUARE_NB];
|
||||||
Bitboard byTypeBB[PIECE_TYPE_NB];
|
Bitboard byTypeBB[PIECE_TYPE_NB];
|
||||||
Bitboard byColorBB[COLOR_NB];
|
Bitboard byColorBB[COLOR_NB];
|
||||||
int pieceCount[COLOR_NB][PIECE_TYPE_NB];
|
int pieceCount[PIECE_NB];
|
||||||
Square pieceList[COLOR_NB][PIECE_TYPE_NB][16];
|
Square pieceList[PIECE_NB][16];
|
||||||
int index[SQUARE_NB];
|
int index[SQUARE_NB];
|
||||||
int castlingRightsMask[SQUARE_NB];
|
int castlingRightsMask[SQUARE_NB];
|
||||||
Square castlingRookSquare[CASTLING_RIGHT_NB];
|
Square castlingRookSquare[CASTLING_RIGHT_NB];
|
||||||
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
||||||
StateInfo startState;
|
|
||||||
uint64_t nodes;
|
|
||||||
int gamePly;
|
int gamePly;
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
|
Score psq;
|
||||||
Thread* thisThread;
|
Thread* thisThread;
|
||||||
StateInfo* st;
|
StateInfo* st;
|
||||||
bool chess960;
|
bool chess960;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace PSQT {
|
||||||
|
extern Score psq[PIECE_NB][SQUARE_NB];
|
||||||
|
}
|
||||||
|
|
||||||
extern std::ostream& operator<<(std::ostream& os, const Position& pos);
|
extern std::ostream& operator<<(std::ostream& os, const Position& pos);
|
||||||
|
|
||||||
inline Color Position::side_to_move() const {
|
inline Color Position::side_to_move() const {
|
||||||
@@ -252,52 +244,66 @@ inline Bitboard Position::pieces(Color c, PieceType pt1, PieceType pt2) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt> inline int Position::count(Color c) const {
|
template<PieceType Pt> inline int Position::count(Color c) const {
|
||||||
return pieceCount[c][Pt];
|
return pieceCount[make_piece(c, Pt)];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<PieceType Pt> inline 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 {
|
template<PieceType Pt> inline const Square* Position::squares(Color c) const {
|
||||||
return pieceList[c][Pt];
|
return pieceList[make_piece(c, Pt)];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt> inline Square Position::square(Color c) const {
|
template<PieceType Pt> inline Square Position::square(Color c) const {
|
||||||
assert(pieceCount[c][Pt] == 1);
|
assert(pieceCount[make_piece(c, Pt)] == 1);
|
||||||
return pieceList[c][Pt][0];
|
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 int Position::can_castle(CastlingRight cr) const {
|
inline bool Position::is_on_semiopen_file(Color c, Square s) const {
|
||||||
|
return !(pieces(c, PAWN) & file_bb(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Position::can_castle(CastlingRights cr) const {
|
||||||
return st->castlingRights & cr;
|
return st->castlingRights & cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::can_castle(Color c) const {
|
inline int Position::castling_rights(Color c) const {
|
||||||
return st->castlingRights & ((WHITE_OO | WHITE_OOO) << (2 * c));
|
return st->castlingRights & (c == WHITE ? WHITE_CASTLING : BLACK_CASTLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::castling_impeded(CastlingRight cr) const {
|
inline bool Position::castling_impeded(CastlingRights cr) const {
|
||||||
|
assert(cr == WHITE_OO || cr == WHITE_OOO || cr == BLACK_OO || cr == BLACK_OOO);
|
||||||
|
|
||||||
return byTypeBB[ALL_PIECES] & castlingPath[cr];
|
return byTypeBB[ALL_PIECES] & castlingPath[cr];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::castling_rook_square(CastlingRight cr) const {
|
inline Square Position::castling_rook_square(CastlingRights cr) const {
|
||||||
|
assert(cr == WHITE_OO || cr == WHITE_OOO || cr == BLACK_OO || cr == BLACK_OOO);
|
||||||
|
|
||||||
return castlingRookSquare[cr];
|
return castlingRookSquare[cr];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt>
|
template<PieceType Pt>
|
||||||
inline Bitboard Position::attacks_from(Square s) const {
|
inline Bitboard Position::attacks_from(Square s) const {
|
||||||
|
static_assert(Pt != PAWN, "Pawn attacks need color");
|
||||||
|
|
||||||
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
||||||
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
||||||
: StepAttacksBB[Pt][s];
|
: 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];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::attacks_from(Piece pc, Square s) const {
|
inline Bitboard Position::attacks_from(PieceType pt, Square s) const {
|
||||||
return attacks_bb(pc, s, byTypeBB[ALL_PIECES]);
|
return attacks_bb(pt, s, byTypeBB[ALL_PIECES]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::attackers_to(Square s) const {
|
inline Bitboard Position::attackers_to(Square s) const {
|
||||||
@@ -308,21 +314,29 @@ inline Bitboard Position::checkers() const {
|
|||||||
return st->checkersBB;
|
return st->checkersBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::discovered_check_candidates() const {
|
inline Bitboard Position::blockers_for_king(Color c) const {
|
||||||
return check_blockers(sideToMove, ~sideToMove);
|
return st->blockersForKing[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pinned_pieces(Color c) const {
|
inline Bitboard Position::check_squares(PieceType pt) const {
|
||||||
return check_blockers(c, c);
|
return st->checkSquares[pt];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Position::is_discovery_check_on_king(Color c, Move m) const {
|
||||||
|
return st->blockersForKing[c] & from_sq(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_passed(Color c, Square s) const {
|
inline bool Position::pawn_passed(Color c, Square s) const {
|
||||||
return !(pieces(~c, PAWN) & passed_pawn_mask(c, s));
|
return !(pieces(~c, PAWN) & passed_pawn_span(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::advanced_pawn_push(Move m) const {
|
inline bool Position::advanced_pawn_push(Move m) const {
|
||||||
return type_of(moved_piece(m)) == PAWN
|
return type_of(moved_piece(m)) == PAWN
|
||||||
&& relative_rank(sideToMove, from_sq(m)) > RANK_4;
|
&& relative_rank(sideToMove, to_sq(m)) > RANK_5;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int Position::pawns_on_same_color_squares(Color c, Square s) const {
|
||||||
|
return popcount(pieces(c, PAWN) & ((DarkSquares & s) ? DarkSquares : ~DarkSquares));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::key() const {
|
inline Key Position::key() const {
|
||||||
@@ -338,13 +352,17 @@ inline Key Position::material_key() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Score Position::psq_score() const {
|
inline Score Position::psq_score() const {
|
||||||
return st->psq;
|
return psq;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::non_pawn_material(Color c) const {
|
inline Value Position::non_pawn_material(Color c) const {
|
||||||
return st->nonPawnMaterial[c];
|
return st->nonPawnMaterial[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Value Position::non_pawn_material() const {
|
||||||
|
return st->nonPawnMaterial[WHITE] + st->nonPawnMaterial[BLACK];
|
||||||
|
}
|
||||||
|
|
||||||
inline int Position::game_ply() const {
|
inline int Position::game_ply() const {
|
||||||
return gamePly;
|
return gamePly;
|
||||||
}
|
}
|
||||||
@@ -353,17 +371,9 @@ inline int Position::rule50_count() const {
|
|||||||
return st->rule50;
|
return st->rule50;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t Position::nodes_searched() const {
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Position::set_nodes_searched(uint64_t n) {
|
|
||||||
nodes = n;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::opposite_bishops() const {
|
inline bool Position::opposite_bishops() const {
|
||||||
return pieceCount[WHITE][BISHOP] == 1
|
return pieceCount[W_BISHOP] == 1
|
||||||
&& pieceCount[BLACK][BISHOP] == 1
|
&& pieceCount[B_BISHOP] == 1
|
||||||
&& opposite_colors(square<BISHOP>(WHITE), square<BISHOP>(BLACK));
|
&& opposite_colors(square<BISHOP>(WHITE), square<BISHOP>(BLACK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,66 +382,71 @@ inline bool Position::is_chess960() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::capture_or_promotion(Move m) const {
|
inline bool Position::capture_or_promotion(Move m) const {
|
||||||
|
|
||||||
assert(is_ok(m));
|
assert(is_ok(m));
|
||||||
return type_of(m) != NORMAL ? type_of(m) != CASTLING : !empty(to_sq(m));
|
return type_of(m) != NORMAL ? type_of(m) != CASTLING : !empty(to_sq(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::capture(Move m) const {
|
inline bool Position::capture(Move m) const {
|
||||||
|
|
||||||
// Castling is encoded as "king captures the rook"
|
|
||||||
assert(is_ok(m));
|
assert(is_ok(m));
|
||||||
|
// Castling is encoded as "king captures rook"
|
||||||
return (!empty(to_sq(m)) && type_of(m) != CASTLING) || type_of(m) == ENPASSANT;
|
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 Thread* Position::this_thread() const {
|
inline Thread* Position::this_thread() const {
|
||||||
return thisThread;
|
return thisThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::put_piece(Color c, PieceType pt, Square s) {
|
inline void Position::put_piece(Piece pc, Square s) {
|
||||||
|
|
||||||
board[s] = make_piece(c, pt);
|
board[s] = pc;
|
||||||
byTypeBB[ALL_PIECES] |= s;
|
byTypeBB[ALL_PIECES] |= s;
|
||||||
byTypeBB[pt] |= s;
|
byTypeBB[type_of(pc)] |= s;
|
||||||
byColorBB[c] |= s;
|
byColorBB[color_of(pc)] |= s;
|
||||||
index[s] = pieceCount[c][pt]++;
|
index[s] = pieceCount[pc]++;
|
||||||
pieceList[c][pt][index[s]] = s;
|
pieceList[pc][index[s]] = s;
|
||||||
pieceCount[c][ALL_PIECES]++;
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]++;
|
||||||
|
psq += PSQT::psq[pc][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::remove_piece(Color c, PieceType pt, Square s) {
|
inline void Position::remove_piece(Piece pc, Square s) {
|
||||||
|
|
||||||
// WARNING: This is not a reversible operation. If we remove a piece in
|
// 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
|
// 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[]
|
// the list and not in its original place, it means index[] and pieceList[]
|
||||||
// are not guaranteed to be invariant to a do_move() + undo_move() sequence.
|
// are not invariant to a do_move() + undo_move() sequence.
|
||||||
byTypeBB[ALL_PIECES] ^= s;
|
byTypeBB[ALL_PIECES] ^= s;
|
||||||
byTypeBB[pt] ^= s;
|
byTypeBB[type_of(pc)] ^= s;
|
||||||
byColorBB[c] ^= s;
|
byColorBB[color_of(pc)] ^= s;
|
||||||
/* board[s] = NO_PIECE; Not needed, overwritten by the capturing one */
|
/* board[s] = NO_PIECE; Not needed, overwritten by the capturing one */
|
||||||
Square lastSquare = pieceList[c][pt][--pieceCount[c][pt]];
|
Square lastSquare = pieceList[pc][--pieceCount[pc]];
|
||||||
index[lastSquare] = index[s];
|
index[lastSquare] = index[s];
|
||||||
pieceList[c][pt][index[lastSquare]] = lastSquare;
|
pieceList[pc][index[lastSquare]] = lastSquare;
|
||||||
pieceList[c][pt][pieceCount[c][pt]] = SQ_NONE;
|
pieceList[pc][pieceCount[pc]] = SQ_NONE;
|
||||||
pieceCount[c][ALL_PIECES]--;
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
|
||||||
|
psq -= PSQT::psq[pc][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::move_piece(Color c, PieceType pt, Square from, Square to) {
|
inline void Position::move_piece(Piece pc, Square from, Square to) {
|
||||||
|
|
||||||
// index[from] is not updated and becomes stale. This works as long as index[]
|
// index[from] is not updated and becomes stale. This works as long as index[]
|
||||||
// is accessed just by known occupied squares.
|
// is accessed just by known occupied squares.
|
||||||
Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to];
|
Bitboard fromTo = from | to;
|
||||||
byTypeBB[ALL_PIECES] ^= from_to_bb;
|
byTypeBB[ALL_PIECES] ^= fromTo;
|
||||||
byTypeBB[pt] ^= from_to_bb;
|
byTypeBB[type_of(pc)] ^= fromTo;
|
||||||
byColorBB[c] ^= from_to_bb;
|
byColorBB[color_of(pc)] ^= fromTo;
|
||||||
board[from] = NO_PIECE;
|
board[from] = NO_PIECE;
|
||||||
board[to] = make_piece(c, pt);
|
board[to] = pc;
|
||||||
index[to] = index[from];
|
index[to] = index[from];
|
||||||
pieceList[c][pt][index[to]] = to;
|
pieceList[pc][index[to]] = to;
|
||||||
|
psq += PSQT::psq[pc][to] - PSQT::psq[pc][from];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Position::do_move(Move m, StateInfo& newSt) {
|
||||||
|
do_move(m, newSt, gives_check(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #ifndef POSITION_H_INCLUDED
|
#endif // #ifndef POSITION_H_INCLUDED
|
||||||
|
|||||||
+71
-60
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,8 +18,15 @@
|
|||||||
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 "types.h"
|
#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 {
|
namespace PSQT {
|
||||||
|
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
@@ -28,90 +35,94 @@ namespace PSQT {
|
|||||||
// type on a given square a (middlegame, endgame) score pair is assigned. Table
|
// type on a given square a (middlegame, endgame) score pair is assigned. Table
|
||||||
// is defined for files A..D and white side: it is symmetric for black side and
|
// is defined for files A..D and white side: it is symmetric for black side and
|
||||||
// second half of the files.
|
// second half of the files.
|
||||||
const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
constexpr Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
||||||
|
{ },
|
||||||
{ },
|
{ },
|
||||||
{ // Pawn
|
|
||||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
|
||||||
{ S(-19, 5), S( 1,-4), S( 7, 8), S( 3,-2) },
|
|
||||||
{ S(-26,-6), S( -7,-5), S( 19, 5), S(24, 4) },
|
|
||||||
{ S(-25, 1), S(-14, 3), S( 16,-8), S(31,-3) },
|
|
||||||
{ S(-14, 6), S( 0, 9), S( -1, 7), S(17,-6) },
|
|
||||||
{ S(-14, 6), S(-13,-5), S(-10, 2), S(-6, 4) },
|
|
||||||
{ S(-12, 1), S( 15,-9), S( -8, 1), S(-4,18) },
|
|
||||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) }
|
|
||||||
},
|
|
||||||
{ // Knight
|
{ // Knight
|
||||||
{ S(-143, -97), S(-96,-82), S(-80,-46), S(-73,-14) },
|
{ S(-175, -96), S(-92,-65), S(-74,-49), S(-73,-21) },
|
||||||
{ S( -83, -69), S(-43,-55), S(-21,-17), S(-10, 9) },
|
{ S( -77, -67), S(-41,-54), S(-27,-18), S(-15, 8) },
|
||||||
{ S( -71, -50), S(-22,-39), S( 0, -8), S( 9, 28) },
|
{ S( -61, -40), S(-17,-27), S( 6, -8), S( 12, 29) },
|
||||||
{ S( -25, -41), S( 18,-25), S( 43, 7), S( 47, 38) },
|
{ S( -35, -35), S( 8, -2), S( 40, 13), S( 49, 28) },
|
||||||
{ S( -26, -46), S( 16,-25), S( 38, 2), S( 50, 41) },
|
{ S( -34, -45), S( 13,-16), S( 44, 9), S( 51, 39) },
|
||||||
{ S( -11, -55), S( 37,-38), S( 56, -8), S( 71, 27) },
|
{ S( -9, -51), S( 22,-44), S( 58,-16), S( 53, 17) },
|
||||||
{ S( -62, -64), S(-17,-50), S( 5,-24), S( 14, 13) },
|
{ S( -67, -69), S(-27,-50), S( 4,-51), S( 37, 12) },
|
||||||
{ S(-195,-110), S(-66,-90), S(-42,-50), S(-29,-13) }
|
{ S(-201,-100), S(-83,-88), S(-56,-56), S(-26,-17) }
|
||||||
},
|
},
|
||||||
{ // Bishop
|
{ // Bishop
|
||||||
{ S(-54,-68), S(-23,-40), S(-35,-46), S(-44,-28) },
|
{ S(-53,-57), S( -5,-30), S( -8,-37), S(-23,-12) },
|
||||||
{ S(-30,-43), S( 10,-17), S( 2,-23), S( -9, -5) },
|
{ S(-15,-37), S( 8,-13), S( 19,-17), S( 4, 1) },
|
||||||
{ S(-19,-32), S( 17, -9), S( 11,-13), S( 1, 8) },
|
{ S( -7,-16), S( 21, -1), S( -5, -2), S( 17, 10) },
|
||||||
{ S(-21,-36), S( 18,-13), S( 11,-15), S( 0, 7) },
|
{ S( -5,-20), S( 11, -6), S( 25, 0), S( 39, 17) },
|
||||||
{ S(-21,-36), S( 14,-14), S( 6,-17), S( -1, 3) },
|
{ S(-12,-17), S( 29, -1), S( 22,-14), S( 31, 15) },
|
||||||
{ S(-27,-35), S( 6,-13), S( 2,-10), S( -8, 1) },
|
{ S(-16,-30), S( 6, 6), S( 1, 4), S( 11, 6) },
|
||||||
{ S(-33,-44), S( 7,-21), S( -4,-22), S(-12, -4) },
|
{ S(-17,-31), S(-14,-20), S( 5, -1), S( 0, 1) },
|
||||||
{ S(-45,-65), S(-21,-42), S(-29,-46), S(-39,-27) }
|
{ S(-48,-46), S( 1,-42), S(-14,-37), S(-23,-24) }
|
||||||
},
|
},
|
||||||
{ // Rook
|
{ // Rook
|
||||||
{ S(-25, 0), S(-16, 0), S(-16, 0), S(-9, 0) },
|
{ S(-31, -9), S(-20,-13), S(-14,-10), S(-5, -9) },
|
||||||
{ S(-21, 0), S( -8, 0), S( -3, 0), S( 0, 0) },
|
{ S(-21,-12), S(-13, -9), S( -8, -1), S( 6, -2) },
|
||||||
{ S(-21, 0), S( -9, 0), S( -4, 0), S( 2, 0) },
|
{ S(-25, 6), S(-11, -8), S( -1, -2), S( 3, -6) },
|
||||||
{ S(-22, 0), S( -6, 0), S( -1, 0), S( 2, 0) },
|
{ S(-13, -6), S( -5, 1), S( -4, -9), S(-6, 7) },
|
||||||
{ S(-22, 0), S( -7, 0), S( 0, 0), S( 1, 0) },
|
{ S(-27, -5), S(-15, 8), S( -4, 7), S( 3, -6) },
|
||||||
{ S(-21, 0), S( -7, 0), S( 0, 0), S( 2, 0) },
|
{ S(-22, 6), S( -2, 1), S( 6, -7), S(12, 10) },
|
||||||
{ S(-12, 0), S( 4, 0), S( 8, 0), S(12, 0) },
|
{ S( -2, 4), S( 12, 5), S( 16, 20), S(18, -5) },
|
||||||
{ S(-23, 0), S(-15, 0), S(-11, 0), S(-5, 0) }
|
{ S(-17, 18), S(-19, 0), S( -1, 19), S( 9, 13) }
|
||||||
},
|
},
|
||||||
{ // Queen
|
{ // Queen
|
||||||
{ S( 0,-70), S(-3,-57), S(-4,-41), S(-1,-29) },
|
{ S( 3,-69), S(-5,-57), S(-5,-47), S( 4,-26) },
|
||||||
{ S(-4,-58), S( 6,-30), S( 9,-21), S( 8, -4) },
|
{ S(-3,-55), S( 5,-31), S( 8,-22), S(12, -4) },
|
||||||
{ S(-2,-39), S( 6,-17), S( 9, -7), S( 9, 5) },
|
{ S(-3,-39), S( 6,-18), S(13, -9), S( 7, 3) },
|
||||||
{ S(-1,-29), S( 8, -5), S(10, 9), S( 7, 17) },
|
{ S( 4,-23), S( 5, -3), S( 9, 13), S( 8, 24) },
|
||||||
{ S(-3,-27), S( 9, -5), S( 8, 10), S( 7, 23) },
|
{ S( 0,-29), S(14, -6), S(12, 9), S( 5, 21) },
|
||||||
{ S(-2,-40), S( 6,-16), S( 8,-11), S(10, 3) },
|
{ S(-4,-38), S(10,-18), S( 6,-12), S( 8, 1) },
|
||||||
{ S(-2,-54), S( 7,-30), S( 7,-21), S( 6, -7) },
|
{ S(-5,-50), S( 6,-27), S(10,-24), S( 8, -8) },
|
||||||
{ S(-1,-75), S(-4,-54), S(-1,-44), S( 0,-30) }
|
{ S(-2,-75), S(-2,-52), S( 1,-43), S(-2,-36) }
|
||||||
},
|
},
|
||||||
{ // King
|
{ // King
|
||||||
{ S(291, 28), S(344, 76), S(294,103), S(219,112) },
|
{ S(271, 1), S(327, 45), S(271, 85), S(198, 76) },
|
||||||
{ S(289, 70), S(329,119), S(263,170), S(205,159) },
|
{ S(278, 53), S(303,100), S(234,133), S(179,135) },
|
||||||
{ S(226,109), S(271,164), S(202,195), S(136,191) },
|
{ S(195, 88), S(258,130), S(169,169), S(120,175) },
|
||||||
{ S(204,131), S(212,194), S(175,194), S(137,204) },
|
{ S(164,103), S(190,156), S(138,172), S( 98,172) },
|
||||||
{ S(177,132), S(205,187), S(143,224), S( 94,227) },
|
{ S(154, 96), S(179,166), S(105,199), S( 70,199) },
|
||||||
{ S(147,118), S(188,178), S(113,199), S( 70,197) },
|
{ S(123, 92), S(145,172), S( 81,184), S( 31,191) },
|
||||||
{ S(116, 72), S(158,121), S( 93,142), S( 48,161) },
|
{ S( 88, 47), S(120,121), S( 65,116), S( 33,131) },
|
||||||
{ S( 94, 30), S(120, 76), S( 78,101), S( 31,111) }
|
{ S( 59, 11), S( 89, 59), S( 45, 73), S( -1, 78) }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr Score PBonus[RANK_NB][FILE_NB] =
|
||||||
|
{ // Pawn (asymmetric distribution)
|
||||||
|
{ },
|
||||||
|
{ S( 3,-10), S( 3, -6), S( 10, 10), S( 19, 0), S( 16, 14), S( 19, 7), S( 7, -5), S( -5,-19) },
|
||||||
|
{ S( -9,-10), S(-15,-10), S( 11,-10), S( 15, 4), S( 32, 4), S( 22, 3), S( 5, -6), S(-22, -4) },
|
||||||
|
{ S( -8, 6), S(-23, -2), S( 6, -8), S( 20, -4), S( 40,-13), S( 17,-12), S( 4,-10), S(-12, -9) },
|
||||||
|
{ S( 13, 9), S( 0, 4), S(-13, 3), S( 1,-12), S( 11,-12), S( -2, -6), S(-13, 13), S( 5, 8) },
|
||||||
|
{ S( -5, 28), S(-12, 20), S( -7, 21), S( 22, 28), S( -8, 30), S( -5, 7), S(-15, 6), S(-18, 13) },
|
||||||
|
{ S( -7, 0), S( 7,-11), S( -3, 12), S(-13, 21), S( 5, 25), S(-16, 19), S( 10, 4), S( -8, 7) }
|
||||||
|
};
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
|
|
||||||
Score psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
|
Score psq[PIECE_NB][SQUARE_NB];
|
||||||
|
|
||||||
// init() initializes piece square tables: the white halves of the tables are
|
// 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
|
// 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.
|
// tables are initialized by flipping and changing the sign of the white scores.
|
||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
for (PieceType pt = PAWN; pt <= KING; ++pt)
|
for (Piece pc = W_PAWN; pc <= W_KING; ++pc)
|
||||||
{
|
{
|
||||||
PieceValue[MG][make_piece(BLACK, pt)] = PieceValue[MG][pt];
|
PieceValue[MG][~pc] = PieceValue[MG][pc];
|
||||||
PieceValue[EG][make_piece(BLACK, pt)] = PieceValue[EG][pt];
|
PieceValue[EG][~pc] = PieceValue[EG][pc];
|
||||||
|
|
||||||
Score v = make_score(PieceValue[MG][pt], PieceValue[EG][pt]);
|
Score score = make_score(PieceValue[MG][pc], PieceValue[EG][pc]);
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
int edgeDistance = file_of(s) < FILE_E ? file_of(s) : FILE_H - file_of(s);
|
File f = map_to_queenside(file_of(s));
|
||||||
psq[BLACK][pt][~s] = -(psq[WHITE][pt][s] = v + Bonus[pt][rank_of(s)][edgeDistance]);
|
psq[ pc][ s] = score + (type_of(pc) == PAWN ? PBonus[rank_of(s)][file_of(s)]
|
||||||
|
: Bonus[pc][rank_of(s)][f]);
|
||||||
|
psq[~pc][~s] = -psq[pc][s];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1046
-789
File diff suppressed because it is too large
Load Diff
+29
-30
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,32 +21,37 @@
|
|||||||
#ifndef SEARCH_H_INCLUDED
|
#ifndef SEARCH_H_INCLUDED
|
||||||
#define SEARCH_H_INCLUDED
|
#define SEARCH_H_INCLUDED
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <memory> // For std::unique_ptr
|
|
||||||
#include <stack>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "position.h"
|
#include "movepick.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
class Position;
|
||||||
|
|
||||||
namespace Search {
|
namespace Search {
|
||||||
|
|
||||||
|
/// Threshold used for countermoves based pruning
|
||||||
|
constexpr int CounterMovePruneThreshold = 0;
|
||||||
|
|
||||||
|
|
||||||
/// Stack struct keeps track of the information we need to remember from nodes
|
/// 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
|
/// shallower and deeper in the tree during the search. Each search thread has
|
||||||
/// its own array of Stack objects, indexed by the current ply.
|
/// its own array of Stack objects, indexed by the current ply.
|
||||||
|
|
||||||
struct Stack {
|
struct Stack {
|
||||||
Move* pv;
|
Move* pv;
|
||||||
|
PieceToHistory* continuationHistory;
|
||||||
int ply;
|
int ply;
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Move excludedMove;
|
Move excludedMove;
|
||||||
Move killers[2];
|
Move killers[2];
|
||||||
Value staticEval;
|
Value staticEval;
|
||||||
bool skipEarlyPruning;
|
int statScore;
|
||||||
int moveCount;
|
int moveCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// RootMove struct is used for moves at the root of the tree. For each root move
|
/// RootMove struct is used for moves at the root of the tree. For each root move
|
||||||
/// we store a score and a PV (really a refutation in the case of moves which
|
/// we store a score and a PV (really a refutation in the case of moves which
|
||||||
/// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves.
|
/// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves.
|
||||||
@@ -54,56 +59,50 @@ struct Stack {
|
|||||||
struct RootMove {
|
struct RootMove {
|
||||||
|
|
||||||
explicit RootMove(Move m) : pv(1, m) {}
|
explicit RootMove(Move m) : pv(1, m) {}
|
||||||
|
|
||||||
bool operator<(const RootMove& m) const { return m.score < score; } // Descending sort
|
|
||||||
bool operator==(const Move& m) const { return pv[0] == m; }
|
|
||||||
void insert_pv_in_tt(Position& pos);
|
|
||||||
bool extract_ponder_from_tt(Position& pos);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
Value score = -VALUE_INFINITE;
|
Value score = -VALUE_INFINITE;
|
||||||
Value previousScore = -VALUE_INFINITE;
|
Value previousScore = -VALUE_INFINITE;
|
||||||
|
int selDepth = 0;
|
||||||
|
int tbRank = 0;
|
||||||
|
int bestMoveCount = 0;
|
||||||
|
Value tbScore;
|
||||||
std::vector<Move> pv;
|
std::vector<Move> pv;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<RootMove> RootMoveVector;
|
typedef std::vector<RootMove> RootMoves;
|
||||||
|
|
||||||
|
|
||||||
/// LimitsType struct stores information sent by GUI about available time to
|
/// LimitsType struct stores information sent by GUI about available time to
|
||||||
/// search the current move, maximum depth/time, if we are in analysis mode or
|
/// search the current move, maximum depth/time, or if we are in analysis mode.
|
||||||
/// if we have to ponder while it's our opponent's turn to move.
|
|
||||||
|
|
||||||
struct LimitsType {
|
struct LimitsType {
|
||||||
|
|
||||||
LimitsType() { // Init explicitly due to broken value-initialization of non POD in MSVC
|
LimitsType() { // Init explicitly due to broken value-initialization of non POD in MSVC
|
||||||
nodes = time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movestogo =
|
time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0);
|
||||||
depth = movetime = mate = infinite = ponder = 0;
|
movestogo = depth = mate = perft = infinite = 0;
|
||||||
|
nodes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_time_management() const {
|
bool use_time_management() const {
|
||||||
return !(mate | movetime | depth | nodes | infinite);
|
return !(mate | movetime | depth | nodes | perft | infinite);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Move> searchmoves;
|
std::vector<Move> searchmoves;
|
||||||
int time[COLOR_NB], inc[COLOR_NB], npmsec, movestogo, depth, movetime, mate, infinite, ponder;
|
TimePoint time[COLOR_NB], inc[COLOR_NB], npmsec, movetime, startTime;
|
||||||
|
int movestogo, depth, mate, perft, infinite;
|
||||||
int64_t nodes;
|
int64_t nodes;
|
||||||
TimePoint startTime;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The SignalsType struct stores atomic flags updated during the search
|
|
||||||
/// typically in an async fashion e.g. to stop the search by the GUI.
|
|
||||||
|
|
||||||
struct SignalsType {
|
|
||||||
std::atomic_bool stop, stopOnPonderhit;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::unique_ptr<std::stack<StateInfo>> StateStackPtr;
|
|
||||||
|
|
||||||
extern SignalsType Signals;
|
|
||||||
extern LimitsType Limits;
|
extern LimitsType Limits;
|
||||||
extern StateStackPtr SetupStates;
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void clear();
|
void clear();
|
||||||
template<bool Root = true> uint64_t perft(Position& pos, Depth depth);
|
|
||||||
|
|
||||||
} // namespace Search
|
} // namespace Search
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,169 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2011-2013 Ronald de Man
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TBCORE_H
|
|
||||||
#define TBCORE_H
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <pthread.h>
|
|
||||||
#define SEP_CHAR ':'
|
|
||||||
#define FD int
|
|
||||||
#define FD_ERR -1
|
|
||||||
#else
|
|
||||||
#include <windows.h>
|
|
||||||
#define SEP_CHAR ';'
|
|
||||||
#define FD HANDLE
|
|
||||||
#define FD_ERR INVALID_HANDLE_VALUE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#define LOCK_T pthread_mutex_t
|
|
||||||
#define LOCK_INIT(x) pthread_mutex_init(&(x), NULL)
|
|
||||||
#define LOCK(x) pthread_mutex_lock(&(x))
|
|
||||||
#define UNLOCK(x) pthread_mutex_unlock(&(x))
|
|
||||||
#else
|
|
||||||
#define LOCK_T HANDLE
|
|
||||||
#define LOCK_INIT(x) do { x = CreateMutex(NULL, FALSE, NULL); } while (0)
|
|
||||||
#define LOCK(x) WaitForSingleObject(x, INFINITE)
|
|
||||||
#define UNLOCK(x) ReleaseMutex(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
|
||||||
#define BSWAP32(v) __builtin_bswap32(v)
|
|
||||||
#define BSWAP64(v) __builtin_bswap64(v)
|
|
||||||
#else
|
|
||||||
#define BSWAP32(v) _byteswap_ulong(v)
|
|
||||||
#define BSWAP64(v) _byteswap_uint64(v)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WDLSUFFIX ".rtbw"
|
|
||||||
#define DTZSUFFIX ".rtbz"
|
|
||||||
#define WDLDIR "RTBWDIR"
|
|
||||||
#define DTZDIR "RTBZDIR"
|
|
||||||
#define TBPIECES 6
|
|
||||||
|
|
||||||
typedef unsigned long long uint64;
|
|
||||||
typedef unsigned int uint32;
|
|
||||||
typedef unsigned char ubyte;
|
|
||||||
typedef unsigned short ushort;
|
|
||||||
|
|
||||||
const ubyte WDL_MAGIC[4] = { 0x71, 0xe8, 0x23, 0x5d };
|
|
||||||
const ubyte DTZ_MAGIC[4] = { 0xd7, 0x66, 0x0c, 0xa5 };
|
|
||||||
|
|
||||||
#define TBHASHBITS 10
|
|
||||||
|
|
||||||
struct TBHashEntry;
|
|
||||||
|
|
||||||
typedef uint64 base_t;
|
|
||||||
|
|
||||||
struct PairsData {
|
|
||||||
char *indextable;
|
|
||||||
ushort *sizetable;
|
|
||||||
ubyte *data;
|
|
||||||
ushort *offset;
|
|
||||||
ubyte *symlen;
|
|
||||||
ubyte *sympat;
|
|
||||||
int blocksize;
|
|
||||||
int idxbits;
|
|
||||||
int min_len;
|
|
||||||
base_t base[1]; // C++ complains about base[]...
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TBEntry {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
}
|
|
||||||
#ifndef _WIN32
|
|
||||||
__attribute__((__may_alias__))
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
|
|
||||||
struct TBEntry_piece {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
ubyte enc_type;
|
|
||||||
struct PairsData *precomp[2];
|
|
||||||
int factor[2][TBPIECES];
|
|
||||||
ubyte pieces[2][TBPIECES];
|
|
||||||
ubyte norm[2][TBPIECES];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TBEntry_pawn {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
ubyte pawns[2];
|
|
||||||
struct {
|
|
||||||
struct PairsData *precomp[2];
|
|
||||||
int factor[2][TBPIECES];
|
|
||||||
ubyte pieces[2][TBPIECES];
|
|
||||||
ubyte norm[2][TBPIECES];
|
|
||||||
} file[4];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DTZEntry_piece {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
ubyte enc_type;
|
|
||||||
struct PairsData *precomp;
|
|
||||||
int factor[TBPIECES];
|
|
||||||
ubyte pieces[TBPIECES];
|
|
||||||
ubyte norm[TBPIECES];
|
|
||||||
ubyte flags; // accurate, mapped, side
|
|
||||||
ushort map_idx[4];
|
|
||||||
ubyte *map;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DTZEntry_pawn {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
ubyte pawns[2];
|
|
||||||
struct {
|
|
||||||
struct PairsData *precomp;
|
|
||||||
int factor[TBPIECES];
|
|
||||||
ubyte pieces[TBPIECES];
|
|
||||||
ubyte norm[TBPIECES];
|
|
||||||
} file[4];
|
|
||||||
ubyte flags[4];
|
|
||||||
ushort map_idx[4][4];
|
|
||||||
ubyte *map;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TBHashEntry {
|
|
||||||
uint64 key;
|
|
||||||
struct TBEntry *ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DTZTableEntry {
|
|
||||||
uint64 key1;
|
|
||||||
uint64 key2;
|
|
||||||
struct TBEntry *entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+1519
-750
File diff suppressed because it is too large
Load Diff
+66
-5
@@ -1,17 +1,78 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (c) 2013 Ronald de Man
|
||||||
|
Copyright (C) 2016-2020 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
|
#ifndef TBPROBE_H
|
||||||
#define TBPROBE_H
|
#define TBPROBE_H
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
#include "../search.h"
|
#include "../search.h"
|
||||||
|
|
||||||
namespace Tablebases {
|
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;
|
extern int MaxCardinality;
|
||||||
|
|
||||||
void init(const std::string& path);
|
void init(const std::string& paths);
|
||||||
int probe_wdl(Position& pos, int *success);
|
WDLScore probe_wdl(Position& pos, ProbeState* result);
|
||||||
int probe_dtz(Position& pos, int *success);
|
int probe_dtz(Position& pos, ProbeState* result);
|
||||||
bool root_probe(Position& pos, Search::RootMoveVector& rootMoves, Value& score);
|
bool root_probe(Position& pos, Search::RootMoves& rootMoves);
|
||||||
bool root_probe_wdl(Position& pos, Search::RootMoveVector& rootMoves, Value& score);
|
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves);
|
||||||
|
void rank_root_moves(Position& pos, Search::RootMoves& rootMoves);
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& os, const WDLScore v) {
|
||||||
|
|
||||||
|
os << (v == WDLLoss ? "Loss" :
|
||||||
|
v == WDLBlessedLoss ? "Blessed loss" :
|
||||||
|
v == WDLDraw ? "Draw" :
|
||||||
|
v == WDLCursedWin ? "Cursed win" :
|
||||||
|
v == WDLWin ? "Win" : "None");
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& os, const ProbeState v) {
|
||||||
|
|
||||||
|
os << (v == FAIL ? "Failed" :
|
||||||
|
v == OK ? "Success" :
|
||||||
|
v == CHANGE_STM ? "Probed opponent side" :
|
||||||
|
v == ZEROING_BEST_MOVE ? "Best move zeroes DTZ" : "None");
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+140
-115
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,178 +18,203 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm> // For std::count
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <algorithm> // For std::count
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
using namespace Search;
|
#include "tt.h"
|
||||||
|
|
||||||
ThreadPool Threads; // Global object
|
ThreadPool Threads; // Global object
|
||||||
|
|
||||||
/// Thread constructor launch the thread and then wait until it goes to sleep
|
|
||||||
/// in idle_loop().
|
|
||||||
|
|
||||||
Thread::Thread() {
|
/// Thread constructor launches the thread and waits until it goes to sleep
|
||||||
|
/// in idle_loop(). Note that 'searching' and 'exit' should be already set.
|
||||||
|
|
||||||
resetCalls = exit = false;
|
Thread::Thread(size_t n) : idx(n), stdThread(&Thread::idle_loop, this) {
|
||||||
maxPly = callsCnt = 0;
|
|
||||||
history.clear();
|
|
||||||
counterMoves.clear();
|
|
||||||
idx = Threads.size(); // Start from 0
|
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
wait_for_search_finished();
|
||||||
searching = true;
|
|
||||||
nativeThread = std::thread(&Thread::idle_loop, this);
|
|
||||||
sleepCondition.wait(lk, [&]{ return !searching; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Thread destructor wait for thread termination before returning
|
/// Thread destructor wakes up the thread in idle_loop() and waits
|
||||||
|
/// for its termination. Thread should be already waiting.
|
||||||
|
|
||||||
Thread::~Thread() {
|
Thread::~Thread() {
|
||||||
|
|
||||||
mutex.lock();
|
assert(!searching);
|
||||||
|
|
||||||
exit = true;
|
exit = true;
|
||||||
sleepCondition.notify_one();
|
start_searching();
|
||||||
mutex.unlock();
|
stdThread.join();
|
||||||
nativeThread.join();
|
}
|
||||||
|
|
||||||
|
/// Thread::bestMoveCount(Move move) return best move counter for the given root move
|
||||||
|
|
||||||
|
int Thread::best_move_count(Move move) {
|
||||||
|
|
||||||
|
auto rm = std::find(rootMoves.begin() + pvIdx,
|
||||||
|
rootMoves.begin() + pvLast, move);
|
||||||
|
|
||||||
|
return rm != rootMoves.begin() + pvLast ? rm->bestMoveCount : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Thread::clear() reset histories, usually before a new game
|
||||||
|
|
||||||
|
void Thread::clear() {
|
||||||
|
|
||||||
|
counterMoves.fill(MOVE_NONE);
|
||||||
|
mainHistory.fill(0);
|
||||||
|
captureHistory.fill(0);
|
||||||
|
|
||||||
|
for (bool inCheck : { false, true })
|
||||||
|
for (StatsType c : { NoCaptures, Captures })
|
||||||
|
for (auto& to : continuationHistory[inCheck][c])
|
||||||
|
for (auto& h : to)
|
||||||
|
h->fill(0);
|
||||||
|
|
||||||
|
for (bool inCheck : { false, true })
|
||||||
|
for (StatsType c : { NoCaptures, Captures })
|
||||||
|
continuationHistory[inCheck][c][NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Thread::start_searching() wakes up the thread that will start the search
|
||||||
|
|
||||||
|
void Thread::start_searching() {
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
|
searching = true;
|
||||||
|
cv.notify_one(); // Wake up the thread in idle_loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Thread::wait_for_search_finished() wait on sleep condition until not searching
|
/// Thread::wait_for_search_finished() blocks on the condition variable
|
||||||
|
/// until the thread has finished searching.
|
||||||
|
|
||||||
void Thread::wait_for_search_finished() {
|
void Thread::wait_for_search_finished() {
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
sleepCondition.wait(lk, [&]{ return !searching; });
|
cv.wait(lk, [&]{ return !searching; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Thread::wait() wait on sleep condition until condition is true
|
/// Thread::idle_loop() is where the thread is parked, blocked on the
|
||||||
|
/// condition variable, when it has no work to do.
|
||||||
void Thread::wait(std::atomic_bool& condition) {
|
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
|
||||||
sleepCondition.wait(lk, [&]{ return bool(condition); });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Thread::start_searching() wake up the thread that will start the search
|
|
||||||
|
|
||||||
void Thread::start_searching(bool resume) {
|
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
|
||||||
|
|
||||||
if (!resume)
|
|
||||||
searching = true;
|
|
||||||
|
|
||||||
sleepCondition.notify_one();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Thread::idle_loop() is where the thread is parked when it has no work to do
|
|
||||||
|
|
||||||
void Thread::idle_loop() {
|
void Thread::idle_loop() {
|
||||||
|
|
||||||
while (!exit)
|
// If OS already scheduled us on a different group than 0 then don't overwrite
|
||||||
|
// the choice, eventually we are one of many one-threaded processes running on
|
||||||
|
// some Windows NUMA hardware, for instance in fishtest. To make it simple,
|
||||||
|
// just check if running threads are below a threshold, in this case all this
|
||||||
|
// NUMA machinery is not needed.
|
||||||
|
if (Options["Threads"] > 8)
|
||||||
|
WinProcGroup::bindThisThread(idx);
|
||||||
|
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
|
|
||||||
searching = false;
|
searching = false;
|
||||||
|
cv.notify_one(); // Wake up anyone waiting for search finished
|
||||||
|
cv.wait(lk, [&]{ return searching; });
|
||||||
|
|
||||||
while (!searching && !exit)
|
if (exit)
|
||||||
{
|
return;
|
||||||
sleepCondition.notify_one(); // Wake up any waiting thread
|
|
||||||
sleepCondition.wait(lk);
|
|
||||||
}
|
|
||||||
|
|
||||||
lk.unlock();
|
lk.unlock();
|
||||||
|
|
||||||
if (!exit)
|
search();
|
||||||
search();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ThreadPool::set() creates/destroys threads to match the requested number.
|
||||||
|
/// Created and launched threads will immediately go to sleep in idle_loop.
|
||||||
|
/// Upon resizing, threads are recreated to allow for binding if necessary.
|
||||||
|
|
||||||
/// ThreadPool::init() create and launch requested threads, that will go
|
void ThreadPool::set(size_t requested) {
|
||||||
/// immediately to sleep. We cannot use a constructor because Threads is a
|
|
||||||
/// static object and we need a fully initialized engine at this point due to
|
|
||||||
/// allocation of Endgames in the Thread constructor.
|
|
||||||
|
|
||||||
void ThreadPool::init() {
|
if (size() > 0) { // destroy any existing thread(s)
|
||||||
|
main()->wait_for_search_finished();
|
||||||
|
|
||||||
push_back(new MainThread);
|
while (size() > 0)
|
||||||
read_uci_options();
|
delete back(), pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requested > 0) { // create new thread(s)
|
||||||
|
push_back(new MainThread(0));
|
||||||
|
|
||||||
|
while (size() < requested)
|
||||||
|
push_back(new Thread(size()));
|
||||||
|
clear();
|
||||||
|
|
||||||
|
// Reallocate the hash with the new threadpool size
|
||||||
|
TT.resize(Options["Hash"]);
|
||||||
|
|
||||||
|
// Init thread number dependent search params.
|
||||||
|
Search::init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ThreadPool::clear() sets threadPool data to initial values.
|
||||||
|
|
||||||
/// ThreadPool::exit() terminate threads before the program exits. Cannot be
|
void ThreadPool::clear() {
|
||||||
/// done in destructor because threads must be terminated before deleting any
|
|
||||||
/// static objects, so while still in main().
|
|
||||||
|
|
||||||
void ThreadPool::exit() {
|
|
||||||
|
|
||||||
while (size())
|
|
||||||
delete back(), pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// ThreadPool::read_uci_options() updates internal threads parameters from the
|
|
||||||
/// corresponding UCI options and creates/destroys threads to match requested
|
|
||||||
/// number. Thread objects are dynamically allocated.
|
|
||||||
|
|
||||||
void ThreadPool::read_uci_options() {
|
|
||||||
|
|
||||||
size_t requested = Options["Threads"];
|
|
||||||
|
|
||||||
assert(requested > 0);
|
|
||||||
|
|
||||||
while (size() < requested)
|
|
||||||
push_back(new Thread);
|
|
||||||
|
|
||||||
while (size() > requested)
|
|
||||||
delete back(), pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// ThreadPool::nodes_searched() return the number of nodes searched
|
|
||||||
|
|
||||||
int64_t ThreadPool::nodes_searched() {
|
|
||||||
|
|
||||||
int64_t nodes = 0;
|
|
||||||
for (Thread* th : *this)
|
for (Thread* th : *this)
|
||||||
nodes += th->rootPos.nodes_searched();
|
th->clear();
|
||||||
return nodes;
|
|
||||||
|
main()->callsCnt = 0;
|
||||||
|
main()->previousScore = VALUE_INFINITE;
|
||||||
|
main()->previousTimeReduction = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and
|
||||||
|
/// returns immediately. Main thread will wake up other threads and start the search.
|
||||||
|
|
||||||
/// ThreadPool::start_thinking() wake up the main thread sleeping in idle_loop()
|
void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
|
||||||
/// and start a new search, then return immediately.
|
const Search::LimitsType& limits, bool ponderMode) {
|
||||||
|
|
||||||
void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
|
|
||||||
StateStackPtr& states) {
|
|
||||||
|
|
||||||
main()->wait_for_search_finished();
|
main()->wait_for_search_finished();
|
||||||
|
|
||||||
Signals.stopOnPonderhit = Signals.stop = false;
|
main()->stopOnPonderhit = stop = false;
|
||||||
|
increaseDepth = true;
|
||||||
main()->rootMoves.clear();
|
main()->ponder = ponderMode;
|
||||||
main()->rootPos = pos;
|
Search::Limits = limits;
|
||||||
Limits = limits;
|
Search::RootMoves rootMoves;
|
||||||
if (states.get()) // If we don't set a new position, preserve current state
|
|
||||||
{
|
|
||||||
SetupStates = std::move(states); // Ownership transfer here
|
|
||||||
assert(!states.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& m : MoveList<LEGAL>(pos))
|
for (const auto& m : MoveList<LEGAL>(pos))
|
||||||
if ( limits.searchmoves.empty()
|
if ( limits.searchmoves.empty()
|
||||||
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m))
|
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m))
|
||||||
main()->rootMoves.push_back(RootMove(m));
|
rootMoves.emplace_back(m);
|
||||||
|
|
||||||
|
if (!rootMoves.empty())
|
||||||
|
Tablebases::rank_root_moves(pos, rootMoves);
|
||||||
|
|
||||||
|
// After ownership transfer 'states' becomes empty, so if we stop the search
|
||||||
|
// and call 'go' again without setting a new position states.get() == NULL.
|
||||||
|
assert(states.get() || setupStates.get());
|
||||||
|
|
||||||
|
if (states.get())
|
||||||
|
setupStates = std::move(states); // Ownership transfer, states is now empty
|
||||||
|
|
||||||
|
// We use Position::set() to set root position across threads. But there are
|
||||||
|
// some StateInfo fields (previous, pliesFromNull, capturedPiece) that cannot
|
||||||
|
// be deduced from a fen string, so set() clears them and to not lose the info
|
||||||
|
// we need to backup and later restore setupStates->back(). Note that setupStates
|
||||||
|
// is shared by threads but is accessed in read-only mode.
|
||||||
|
StateInfo tmp = setupStates->back();
|
||||||
|
|
||||||
|
for (Thread* th : *this)
|
||||||
|
{
|
||||||
|
th->nodes = th->tbHits = th->nmpMinPly = 0;
|
||||||
|
th->rootDepth = th->completedDepth = 0;
|
||||||
|
th->rootMoves = rootMoves;
|
||||||
|
th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th);
|
||||||
|
}
|
||||||
|
|
||||||
|
setupStates->back() = tmp;
|
||||||
|
|
||||||
main()->start_searching();
|
main()->start_searching();
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-35
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#define THREAD_H_INCLUDED
|
#define THREAD_H_INCLUDED
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <bitset>
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -33,69 +32,95 @@
|
|||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread_win32.h"
|
#include "thread_win32_osx.h"
|
||||||
|
|
||||||
|
|
||||||
/// Thread struct keeps together all the thread related stuff. We also use
|
/// Thread class keeps together all the thread-related stuff. We use
|
||||||
/// per-thread pawn and material hash tables so that once we get a pointer to an
|
/// per-thread pawn and material hash tables so that once we get a
|
||||||
/// entry its life time is unlimited and we don't have to care about someone
|
/// pointer to an entry its life time is unlimited and we don't have
|
||||||
/// changing the entry under our feet.
|
/// to care about someone changing the entry under our feet.
|
||||||
|
|
||||||
class Thread {
|
class Thread {
|
||||||
|
|
||||||
std::thread nativeThread;
|
std::mutex mutex;
|
||||||
Mutex mutex;
|
std::condition_variable cv;
|
||||||
ConditionVariable sleepCondition;
|
size_t idx;
|
||||||
bool exit, searching;
|
bool exit = false, searching = true; // Set before starting std::thread
|
||||||
|
NativeThread stdThread;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Thread();
|
explicit Thread(size_t);
|
||||||
virtual ~Thread();
|
virtual ~Thread();
|
||||||
virtual void search();
|
virtual void search();
|
||||||
|
void clear();
|
||||||
void idle_loop();
|
void idle_loop();
|
||||||
void start_searching(bool resume = false);
|
void start_searching();
|
||||||
void wait_for_search_finished();
|
void wait_for_search_finished();
|
||||||
void wait(std::atomic_bool& b);
|
int best_move_count(Move move);
|
||||||
|
|
||||||
Pawns::Table pawnsTable;
|
Pawns::Table pawnsTable;
|
||||||
Material::Table materialTable;
|
Material::Table materialTable;
|
||||||
Endgames endgames;
|
size_t pvIdx, pvLast;
|
||||||
size_t idx, PVIdx;
|
uint64_t ttHitAverage;
|
||||||
int maxPly, callsCnt;
|
int selDepth, nmpMinPly;
|
||||||
|
Color nmpColor;
|
||||||
|
std::atomic<uint64_t> nodes, tbHits, bestMoveChanges;
|
||||||
|
|
||||||
Position rootPos;
|
Position rootPos;
|
||||||
Search::RootMoveVector rootMoves;
|
Search::RootMoves rootMoves;
|
||||||
Depth rootDepth;
|
Depth rootDepth, completedDepth;
|
||||||
HistoryStats history;
|
CounterMoveHistory counterMoves;
|
||||||
MovesStats counterMoves;
|
ButterflyHistory mainHistory;
|
||||||
Depth completedDepth;
|
CapturePieceToHistory captureHistory;
|
||||||
std::atomic_bool resetCalls;
|
ContinuationHistory continuationHistory[2][2];
|
||||||
|
Score contempt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// MainThread is a derived class with a specific overload for the main thread
|
/// MainThread is a derived class specific for main thread
|
||||||
|
|
||||||
struct MainThread : public Thread {
|
struct MainThread : public Thread {
|
||||||
virtual void search();
|
|
||||||
|
|
||||||
bool easyMovePlayed, failedLow;
|
using Thread::Thread;
|
||||||
double bestMoveChanges;
|
|
||||||
|
void search() override;
|
||||||
|
void check_time();
|
||||||
|
|
||||||
|
double previousTimeReduction;
|
||||||
|
Value previousScore;
|
||||||
|
Value iterValue[4];
|
||||||
|
int callsCnt;
|
||||||
|
bool stopOnPonderhit;
|
||||||
|
std::atomic_bool ponder;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// ThreadPool struct handles all the threads related stuff like init, starting,
|
/// ThreadPool struct handles all the threads-related stuff like init, starting,
|
||||||
/// parking and, most importantly, launching a thread. All the access to threads
|
/// parking and, most importantly, launching a thread. All the access to threads
|
||||||
/// data is done through this class.
|
/// is done through this class.
|
||||||
|
|
||||||
struct ThreadPool : public std::vector<Thread*> {
|
struct ThreadPool : public std::vector<Thread*> {
|
||||||
|
|
||||||
void init(); // No constructor and destructor, threads rely on globals that should
|
void start_thinking(Position&, StateListPtr&, const Search::LimitsType&, bool = false);
|
||||||
void exit(); // be initialized and valid during the whole thread lifetime.
|
void clear();
|
||||||
|
void set(size_t);
|
||||||
|
|
||||||
MainThread* main() { return static_cast<MainThread*>(at(0)); }
|
MainThread* main() const { return static_cast<MainThread*>(front()); }
|
||||||
void start_thinking(const Position&, const Search::LimitsType&, Search::StateStackPtr&);
|
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
|
||||||
void read_uci_options();
|
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
|
||||||
int64_t nodes_searched();
|
|
||||||
|
std::atomic_bool stop, increaseDepth;
|
||||||
|
|
||||||
|
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;
|
extern ThreadPool Threads;
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2016 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 workaround 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 of SRW locks.
|
|
||||||
|
|
||||||
#include <condition_variable>
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(_MSC_VER)
|
|
||||||
|
|
||||||
#ifndef NOMINMAX
|
|
||||||
# define NOMINMAX // Disable macros min() and max()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#undef WIN32_LEAN_AND_MEAN
|
|
||||||
#undef NOMINMAX
|
|
||||||
|
|
||||||
/// Mutex and ConditionVariable struct are wrappers of the low level locking
|
|
||||||
/// machinery and are modeled after the corresponding C++11 classes.
|
|
||||||
|
|
||||||
struct Mutex {
|
|
||||||
Mutex() { InitializeCriticalSection(&cs); }
|
|
||||||
~Mutex() { DeleteCriticalSection(&cs); }
|
|
||||||
void lock() { EnterCriticalSection(&cs); }
|
|
||||||
void unlock() { LeaveCriticalSection(&cs); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CRITICAL_SECTION cs;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::condition_variable_any ConditionVariable;
|
|
||||||
|
|
||||||
#else // Default case: use STL classes
|
|
||||||
|
|
||||||
typedef std::mutex Mutex;
|
|
||||||
typedef std::condition_variable ConditionVariable;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef THREAD_WIN32_H_INCLUDED
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef THREAD_WIN32_OSX_H_INCLUDED
|
||||||
|
#define THREAD_WIN32_OSX_H_INCLUDED
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
/// On OSX threads other than the main thread are created with a reduced stack
|
||||||
|
/// size of 512KB by default, this is too low for deep searches, which require
|
||||||
|
/// somewhat more than 1MB stack, so adjust it to TH_STACK_SIZE.
|
||||||
|
/// The implementation calls pthread_create() with the stack size parameter
|
||||||
|
/// equal to the linux 8MB default, on platforms that support it.
|
||||||
|
|
||||||
|
#if defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__)
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
static const size_t TH_STACK_SIZE = 8 * 1024 * 1024;
|
||||||
|
|
||||||
|
template <class T, class P = std::pair<T*, void(T::*)()>>
|
||||||
|
void* start_routine(void* ptr)
|
||||||
|
{
|
||||||
|
P* p = reinterpret_cast<P*>(ptr);
|
||||||
|
(p->first->*(p->second))(); // Call member function pointer
|
||||||
|
delete p;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
class NativeThread {
|
||||||
|
|
||||||
|
pthread_t thread;
|
||||||
|
|
||||||
|
public:
|
||||||
|
template<class T, class P = std::pair<T*, void(T::*)()>>
|
||||||
|
explicit NativeThread(void(T::*fun)(), T* obj) {
|
||||||
|
pthread_attr_t attr_storage, *attr = &attr_storage;
|
||||||
|
pthread_attr_init(attr);
|
||||||
|
pthread_attr_setstacksize(attr, TH_STACK_SIZE);
|
||||||
|
pthread_create(&thread, attr, start_routine<T>, new P(obj, fun));
|
||||||
|
}
|
||||||
|
void join() { pthread_join(thread, NULL); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#else // Default case: use STL classes
|
||||||
|
|
||||||
|
typedef std::thread NativeThread;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef THREAD_WIN32_OSX_H_INCLUDED
|
||||||
+35
-35
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -32,33 +32,33 @@ namespace {
|
|||||||
|
|
||||||
enum TimeType { OptimumTime, MaxTime };
|
enum TimeType { OptimumTime, MaxTime };
|
||||||
|
|
||||||
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
constexpr int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||||
const double MaxRatio = 6.93; // When in trouble, we can step over reserved time with this ratio
|
constexpr double MaxRatio = 7.3; // When in trouble, we can step over reserved time with this ratio
|
||||||
const double StealRatio = 0.36; // However we must not steal time from remaining moves over this ratio
|
constexpr double StealRatio = 0.34; // However we must not steal time from remaining moves over this ratio
|
||||||
|
|
||||||
|
|
||||||
// move_importance() is a skew-logistic function based on naive statistical
|
// move_importance() is a skew-logistic function based on naive statistical
|
||||||
// analysis of "how many games are still undecided after n half-moves". Game
|
// analysis of "how many games are still undecided after n half-moves". Game
|
||||||
// is considered "undecided" as long as neither side has >275cp advantage.
|
// is considered "undecided" as long as neither side has >275cp advantage.
|
||||||
// Data was extracted from CCRL game database with some simple filtering criteria.
|
// Data was extracted from the CCRL game database with some simple filtering criteria.
|
||||||
|
|
||||||
double move_importance(int ply) {
|
double move_importance(int ply) {
|
||||||
|
|
||||||
const double XScale = 8.27;
|
constexpr double XScale = 6.85;
|
||||||
const double XShift = 59.;
|
constexpr double XShift = 64.5;
|
||||||
const double Skew = 0.179;
|
constexpr double Skew = 0.171;
|
||||||
|
|
||||||
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
||||||
}
|
}
|
||||||
|
|
||||||
template<TimeType T>
|
template<TimeType T>
|
||||||
int remaining(int myTime, int movesToGo, int ply, int slowMover)
|
TimePoint remaining(TimePoint myTime, int movesToGo, int ply, TimePoint slowMover) {
|
||||||
{
|
|
||||||
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
|
||||||
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
|
||||||
|
|
||||||
double moveImportance = (move_importance(ply) * slowMover) / 100;
|
constexpr double TMaxRatio = (T == OptimumTime ? 1.0 : MaxRatio);
|
||||||
double otherMovesImportance = 0;
|
constexpr double TStealRatio = (T == OptimumTime ? 0.0 : StealRatio);
|
||||||
|
|
||||||
|
double moveImportance = (move_importance(ply) * slowMover) / 100.0;
|
||||||
|
double otherMovesImportance = 0.0;
|
||||||
|
|
||||||
for (int i = 1; i < movesToGo; ++i)
|
for (int i = 1; i < movesToGo; ++i)
|
||||||
otherMovesImportance += move_importance(ply + 2 * i);
|
otherMovesImportance += move_importance(ply + 2 * i);
|
||||||
@@ -66,7 +66,7 @@ namespace {
|
|||||||
double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance);
|
double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance);
|
||||||
double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance);
|
double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance);
|
||||||
|
|
||||||
return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks an explicit cast
|
return TimePoint(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -81,48 +81,48 @@ namespace {
|
|||||||
/// inc > 0 && movestogo == 0 means: x basetime + z increment
|
/// inc > 0 && movestogo == 0 means: x basetime + z increment
|
||||||
/// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment
|
/// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment
|
||||||
|
|
||||||
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply)
|
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
||||||
{
|
|
||||||
int minThinkingTime = Options["Minimum Thinking Time"];
|
TimePoint minThinkingTime = Options["Minimum Thinking Time"];
|
||||||
int moveOverhead = Options["Move Overhead"];
|
TimePoint moveOverhead = Options["Move Overhead"];
|
||||||
int slowMover = Options["Slow Mover"];
|
TimePoint slowMover = Options["Slow Mover"];
|
||||||
int npmsec = Options["nodestime"];
|
TimePoint npmsec = Options["nodestime"];
|
||||||
|
TimePoint hypMyTime;
|
||||||
|
|
||||||
// If we have to play in 'nodes as time' mode, then convert from time
|
// If we have to play in 'nodes as time' mode, then convert from time
|
||||||
// to nodes, and use resulting values in time management formulas.
|
// to nodes, and use resulting values in time management formulas.
|
||||||
// WARNING: Given npms (nodes per millisecond) must be much lower then
|
// WARNING: to avoid time losses, the given npmsec (nodes per millisecond)
|
||||||
// real engine speed to avoid time losses.
|
// must be much lower than the real engine speed.
|
||||||
if (npmsec)
|
if (npmsec)
|
||||||
{
|
{
|
||||||
if (!availableNodes) // Only once at game start
|
if (!availableNodes) // Only once at game start
|
||||||
availableNodes = npmsec * limits.time[us]; // Time is in msec
|
availableNodes = npmsec * limits.time[us]; // Time is in msec
|
||||||
|
|
||||||
// Convert from millisecs to nodes
|
// Convert from milliseconds to nodes
|
||||||
limits.time[us] = (int)availableNodes;
|
limits.time[us] = TimePoint(availableNodes);
|
||||||
limits.inc[us] *= npmsec;
|
limits.inc[us] *= npmsec;
|
||||||
limits.npmsec = npmsec;
|
limits.npmsec = npmsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime = limits.startTime;
|
startTime = limits.startTime;
|
||||||
unstablePvFactor = 1;
|
|
||||||
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
||||||
|
|
||||||
const int MaxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
const int maxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
||||||
|
|
||||||
// We calculate optimum time usage for different hypothetical "moves to go"-values
|
// We calculate optimum time usage for different hypothetical "moves to go" values
|
||||||
// and choose the minimum of calculated search time values. Usually the greatest
|
// and choose the minimum of calculated search time values. Usually the greatest
|
||||||
// hypMTG gives the minimum values.
|
// hypMTG gives the minimum values.
|
||||||
for (int hypMTG = 1; hypMTG <= MaxMTG; ++hypMTG)
|
for (int hypMTG = 1; hypMTG <= maxMTG; ++hypMTG)
|
||||||
{
|
{
|
||||||
// Calculate thinking time for hypothetical "moves to go"-value
|
// Calculate thinking time for hypothetical "moves to go"-value
|
||||||
int hypMyTime = limits.time[us]
|
hypMyTime = limits.time[us]
|
||||||
+ limits.inc[us] * (hypMTG - 1)
|
+ limits.inc[us] * (hypMTG - 1)
|
||||||
- moveOverhead * (2 + std::min(hypMTG, 40));
|
- moveOverhead * (2 + std::min(hypMTG, 40));
|
||||||
|
|
||||||
hypMyTime = std::max(hypMyTime, 0);
|
hypMyTime = std::max(hypMyTime, TimePoint(0));
|
||||||
|
|
||||||
int t1 = minThinkingTime + remaining<OptimumTime>(hypMyTime, hypMTG, ply, slowMover);
|
TimePoint t1 = minThinkingTime + remaining<OptimumTime>(hypMyTime, hypMTG, ply, slowMover);
|
||||||
int t2 = minThinkingTime + remaining<MaxTime >(hypMyTime, hypMTG, ply, slowMover);
|
TimePoint t2 = minThinkingTime + remaining<MaxTime >(hypMyTime, hypMTG, ply, slowMover);
|
||||||
|
|
||||||
optimumTime = std::min(t1, optimumTime);
|
optimumTime = std::min(t1, optimumTime);
|
||||||
maximumTime = std::min(t2, maximumTime);
|
maximumTime = std::min(t2, maximumTime);
|
||||||
|
|||||||
+7
-8
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,18 +31,17 @@
|
|||||||
class TimeManagement {
|
class TimeManagement {
|
||||||
public:
|
public:
|
||||||
void init(Search::LimitsType& limits, Color us, int ply);
|
void init(Search::LimitsType& limits, Color us, int ply);
|
||||||
void pv_instability(double bestMoveChanges) { unstablePvFactor = 1 + bestMoveChanges; }
|
TimePoint optimum() const { return optimumTime; }
|
||||||
int available() const { return int(optimumTime * unstablePvFactor * 1.016); }
|
TimePoint maximum() const { return maximumTime; }
|
||||||
int maximum() const { return maximumTime; }
|
TimePoint elapsed() const { return Search::Limits.npmsec ?
|
||||||
int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - startTime); }
|
TimePoint(Threads.nodes_searched()) : now() - startTime; }
|
||||||
|
|
||||||
int64_t availableNodes; // When in 'nodes as time' mode
|
int64_t availableNodes; // When in 'nodes as time' mode
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimePoint startTime;
|
TimePoint startTime;
|
||||||
int optimumTime;
|
TimePoint optimumTime;
|
||||||
int maximumTime;
|
TimePoint maximumTime;
|
||||||
double unstablePvFactor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TimeManagement Time;
|
extern TimeManagement Time;
|
||||||
|
|||||||
+71
-30
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -20,12 +20,40 @@
|
|||||||
|
|
||||||
#include <cstring> // For std::memset
|
#include <cstring> // For std::memset
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "thread.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
|
#include "uci.h"
|
||||||
|
|
||||||
TranspositionTable TT; // Our global transposition table
|
TranspositionTable TT; // Our global transposition table
|
||||||
|
|
||||||
|
/// TTEntry::save populates the TTEntry with a new node's data, possibly
|
||||||
|
/// overwriting an old position. Update is not atomic and can be racy.
|
||||||
|
|
||||||
|
void TTEntry::save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev) {
|
||||||
|
|
||||||
|
// Preserve any existing move for the same position
|
||||||
|
if (m || (k >> 48) != key16)
|
||||||
|
move16 = (uint16_t)m;
|
||||||
|
|
||||||
|
// Overwrite less valuable entries
|
||||||
|
if ( (k >> 48) != key16
|
||||||
|
|| d - DEPTH_OFFSET > depth8 - 4
|
||||||
|
|| b == BOUND_EXACT)
|
||||||
|
{
|
||||||
|
assert(d >= DEPTH_OFFSET);
|
||||||
|
|
||||||
|
key16 = (uint16_t)(k >> 48);
|
||||||
|
value16 = (int16_t)v;
|
||||||
|
eval16 = (int16_t)ev;
|
||||||
|
genBound8 = (uint8_t)(TT.generation8 | uint8_t(pv) << 2 | b);
|
||||||
|
depth8 = (uint8_t)(d - DEPTH_OFFSET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::resize() sets the size of the transposition table,
|
/// TranspositionTable::resize() sets the size of the transposition table,
|
||||||
/// measured in megabytes. Transposition table consists of a power of 2 number
|
/// measured in megabytes. Transposition table consists of a power of 2 number
|
||||||
@@ -33,15 +61,12 @@ TranspositionTable TT; // Our global transposition table
|
|||||||
|
|
||||||
void TranspositionTable::resize(size_t mbSize) {
|
void TranspositionTable::resize(size_t mbSize) {
|
||||||
|
|
||||||
size_t newClusterCount = size_t(1) << msb((mbSize * 1024 * 1024) / sizeof(Cluster));
|
Threads.main()->wait_for_search_finished();
|
||||||
|
|
||||||
if (newClusterCount == clusterCount)
|
clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
|
||||||
return;
|
|
||||||
|
|
||||||
clusterCount = newClusterCount;
|
|
||||||
|
|
||||||
free(mem);
|
free(mem);
|
||||||
mem = calloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1, 1);
|
mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);
|
||||||
|
|
||||||
if (!mem)
|
if (!mem)
|
||||||
{
|
{
|
||||||
@@ -51,18 +76,38 @@ void TranspositionTable::resize(size_t mbSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
|
table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::clear() overwrites the entire transposition table
|
/// TranspositionTable::clear() initializes the entire transposition table to zero,
|
||||||
/// with zeros. It is called whenever the table is resized, or when the
|
// in a multi-threaded way.
|
||||||
/// user asks the program to clear the table (from the UCI interface).
|
|
||||||
|
|
||||||
void TranspositionTable::clear() {
|
void TranspositionTable::clear() {
|
||||||
|
|
||||||
std::memset(table, 0, clusterCount * sizeof(Cluster));
|
std::vector<std::thread> threads;
|
||||||
}
|
|
||||||
|
|
||||||
|
for (size_t idx = 0; idx < Options["Threads"]; ++idx)
|
||||||
|
{
|
||||||
|
threads.emplace_back([this, idx]() {
|
||||||
|
|
||||||
|
// Thread binding gives faster search on systems with a first-touch policy
|
||||||
|
if (Options["Threads"] > 8)
|
||||||
|
WinProcGroup::bindThisThread(idx);
|
||||||
|
|
||||||
|
// Each thread will zero its part of the hash table
|
||||||
|
const size_t stride = clusterCount / Options["Threads"],
|
||||||
|
start = stride * idx,
|
||||||
|
len = idx != Options["Threads"] - 1 ?
|
||||||
|
stride : clusterCount - start;
|
||||||
|
|
||||||
|
std::memset(&table[start], 0, len * sizeof(Cluster));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::thread& th: threads)
|
||||||
|
th.join();
|
||||||
|
}
|
||||||
|
|
||||||
/// TranspositionTable::probe() looks up the current position in the transposition
|
/// TranspositionTable::probe() looks up the current position in the transposition
|
||||||
/// table. It returns true and a pointer to the TTEntry if the position is found.
|
/// table. It returns true and a pointer to the TTEntry if the position is found.
|
||||||
@@ -79,8 +124,7 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
|||||||
for (int i = 0; i < ClusterSize; ++i)
|
for (int i = 0; i < ClusterSize; ++i)
|
||||||
if (!tte[i].key16 || tte[i].key16 == key16)
|
if (!tte[i].key16 || tte[i].key16 == key16)
|
||||||
{
|
{
|
||||||
if ((tte[i].genBound8 & 0xFC) != generation8 && tte[i].key16)
|
tte[i].genBound8 = uint8_t(generation8 | (tte[i].genBound8 & 0x7)); // Refresh
|
||||||
tte[i].genBound8 = uint8_t(generation8 | tte[i].bound()); // Refresh
|
|
||||||
|
|
||||||
return found = (bool)tte[i].key16, &tte[i];
|
return found = (bool)tte[i].key16, &tte[i];
|
||||||
}
|
}
|
||||||
@@ -89,29 +133,26 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
|||||||
TTEntry* replace = tte;
|
TTEntry* replace = tte;
|
||||||
for (int i = 1; i < ClusterSize; ++i)
|
for (int i = 1; i < ClusterSize; ++i)
|
||||||
// Due to our packed storage format for generation and its cyclic
|
// Due to our packed storage format for generation and its cyclic
|
||||||
// nature we add 259 (256 is the modulus plus 3 to keep the lowest
|
// nature we add 263 (256 is the modulus plus 7 to keep the unrelated
|
||||||
// two bound bits from affecting the result) to calculate the entry
|
// lowest three bits from affecting the result) to calculate the entry
|
||||||
// age correctly even after generation8 overflows into the next cycle.
|
// age correctly even after generation8 overflows into the next cycle.
|
||||||
if ( replace->depth8 - ((259 + generation8 - replace->genBound8) & 0xFC) * 2 * ONE_PLY
|
if ( replace->depth8 - ((263 + generation8 - replace->genBound8) & 0xF8)
|
||||||
> tte[i].depth8 - ((259 + generation8 - tte[i].genBound8) & 0xFC) * 2 * ONE_PLY)
|
> tte[i].depth8 - ((263 + generation8 - tte[i].genBound8) & 0xF8))
|
||||||
replace = &tte[i];
|
replace = &tte[i];
|
||||||
|
|
||||||
return found = false, replace;
|
return found = false, replace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns an approximation of the hashtable occupation during a search. The
|
/// TranspositionTable::hashfull() returns an approximation of the hashtable
|
||||||
/// hash is x permill full, as per UCI protocol.
|
/// occupation during a search. The hash is x permill full, as per UCI protocol.
|
||||||
|
|
||||||
|
int TranspositionTable::hashfull() const {
|
||||||
|
|
||||||
int TranspositionTable::hashfull() const
|
|
||||||
{
|
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for (int i = 0; i < 1000 / ClusterSize; i++)
|
for (int i = 0; i < 1000 / ClusterSize; ++i)
|
||||||
{
|
for (int j = 0; j < ClusterSize; ++j)
|
||||||
const TTEntry* tte = &table[i].entry[0];
|
cnt += (table[i].entry[j].genBound8 & 0xF8) == generation8;
|
||||||
for (int j = 0; j < ClusterSize; j++)
|
|
||||||
if ((tte[j].genBound8 & 0xFC) == generation8)
|
return cnt * 1000 / (ClusterSize * (1000 / ClusterSize));
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
return cnt;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -30,7 +30,8 @@
|
|||||||
/// move 16 bit
|
/// move 16 bit
|
||||||
/// value 16 bit
|
/// value 16 bit
|
||||||
/// eval value 16 bit
|
/// eval value 16 bit
|
||||||
/// generation 6 bit
|
/// generation 5 bit
|
||||||
|
/// pv node 1 bit
|
||||||
/// bound type 2 bit
|
/// bound type 2 bit
|
||||||
/// depth 8 bit
|
/// depth 8 bit
|
||||||
|
|
||||||
@@ -39,28 +40,10 @@ struct TTEntry {
|
|||||||
Move move() const { return (Move )move16; }
|
Move move() const { return (Move )move16; }
|
||||||
Value value() const { return (Value)value16; }
|
Value value() const { return (Value)value16; }
|
||||||
Value eval() const { return (Value)eval16; }
|
Value eval() const { return (Value)eval16; }
|
||||||
Depth depth() const { return (Depth)depth8; }
|
Depth depth() const { return (Depth)depth8 + DEPTH_OFFSET; }
|
||||||
|
bool is_pv() const { return (bool)(genBound8 & 0x4); }
|
||||||
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
||||||
|
void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev);
|
||||||
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
|
|
||||||
|
|
||||||
// Preserve any existing move for the same position
|
|
||||||
if (m || (k >> 48) != key16)
|
|
||||||
move16 = (uint16_t)m;
|
|
||||||
|
|
||||||
// Don't overwrite more valuable entries
|
|
||||||
if ( (k >> 48) != key16
|
|
||||||
|| d > depth8 - 2
|
|
||||||
/* || 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class TranspositionTable;
|
friend class TranspositionTable;
|
||||||
@@ -70,7 +53,7 @@ private:
|
|||||||
int16_t value16;
|
int16_t value16;
|
||||||
int16_t eval16;
|
int16_t eval16;
|
||||||
uint8_t genBound8;
|
uint8_t genBound8;
|
||||||
int8_t depth8;
|
uint8_t depth8;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -83,8 +66,8 @@ private:
|
|||||||
|
|
||||||
class TranspositionTable {
|
class TranspositionTable {
|
||||||
|
|
||||||
static const int CacheLineSize = 64;
|
static constexpr int CacheLineSize = 64;
|
||||||
static const int ClusterSize = 3;
|
static constexpr int ClusterSize = 3;
|
||||||
|
|
||||||
struct Cluster {
|
struct Cluster {
|
||||||
TTEntry entry[ClusterSize];
|
TTEntry entry[ClusterSize];
|
||||||
@@ -95,19 +78,20 @@ class TranspositionTable {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
~TranspositionTable() { free(mem); }
|
~TranspositionTable() { free(mem); }
|
||||||
void new_search() { generation8 += 4; } // Lower 2 bits are used by Bound
|
void new_search() { generation8 += 8; } // Lower 3 bits are used by PV flag and Bound
|
||||||
uint8_t generation() const { return generation8; }
|
|
||||||
TTEntry* probe(const Key key, bool& found) const;
|
TTEntry* probe(const Key key, bool& found) const;
|
||||||
int hashfull() const;
|
int hashfull() const;
|
||||||
void resize(size_t mbSize);
|
void resize(size_t mbSize);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// The lowest order bits of the key are used to get the index of the cluster
|
// The 32 lowest order bits of the key are used to get the index of the cluster
|
||||||
TTEntry* first_entry(const Key key) const {
|
TTEntry* first_entry(const Key key) const {
|
||||||
return &table[(size_t)key & (clusterCount - 1)].entry[0];
|
return &table[(uint32_t(key) * uint64_t(clusterCount)) >> 32].entry[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend struct TTEntry;
|
||||||
|
|
||||||
size_t clusterCount;
|
size_t clusterCount;
|
||||||
Cluster* table;
|
Cluster* table;
|
||||||
void* mem;
|
void* mem;
|
||||||
|
|||||||
+159
-129
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
// Disable some silly and noisy warning from MSVC compiler
|
// Disable some silly and noisy warning from MSVC compiler
|
||||||
@@ -60,13 +61,12 @@
|
|||||||
/// _WIN64 Building on Windows 64 bit
|
/// _WIN64 Building on Windows 64 bit
|
||||||
|
|
||||||
#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
|
#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
|
||||||
# include <intrin.h> // MSVC popcnt and bsfq instrinsics
|
# include <intrin.h> // Microsoft header for _BitScanForward64()
|
||||||
# define IS_64BIT
|
# define IS_64BIT
|
||||||
# define USE_BSFQ
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_POPCNT) && defined(__INTEL_COMPILER) && defined(_MSC_VER)
|
#if defined(USE_POPCNT) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
||||||
# include <nmmintrin.h> // Intel header for _mm_popcnt_u64() intrinsic
|
# include <nmmintrin.h> // Intel and Microsoft header for _mm_popcnt_u64()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
||||||
@@ -77,32 +77,32 @@
|
|||||||
# include <immintrin.h> // Header for _pext_u64() intrinsic
|
# include <immintrin.h> // Header for _pext_u64() intrinsic
|
||||||
# define pext(b, m) _pext_u64(b, m)
|
# define pext(b, m) _pext_u64(b, m)
|
||||||
#else
|
#else
|
||||||
# define pext(b, m) (0)
|
# define pext(b, m) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_POPCNT
|
#ifdef USE_POPCNT
|
||||||
const bool HasPopCnt = true;
|
constexpr bool HasPopCnt = true;
|
||||||
#else
|
#else
|
||||||
const bool HasPopCnt = false;
|
constexpr bool HasPopCnt = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_PEXT
|
#ifdef USE_PEXT
|
||||||
const bool HasPext = true;
|
constexpr bool HasPext = true;
|
||||||
#else
|
#else
|
||||||
const bool HasPext = false;
|
constexpr bool HasPext = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef IS_64BIT
|
#ifdef IS_64BIT
|
||||||
const bool Is64Bit = true;
|
constexpr bool Is64Bit = true;
|
||||||
#else
|
#else
|
||||||
const bool Is64Bit = false;
|
constexpr bool Is64Bit = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef uint64_t Key;
|
typedef uint64_t Key;
|
||||||
typedef uint64_t Bitboard;
|
typedef uint64_t Bitboard;
|
||||||
|
|
||||||
const int MAX_MOVES = 256;
|
constexpr int MAX_MOVES = 256;
|
||||||
const int MAX_PLY = 128;
|
constexpr int MAX_PLY = 246;
|
||||||
|
|
||||||
/// A move needs 16 bits to be stored
|
/// A move needs 16 bits to be stored
|
||||||
///
|
///
|
||||||
@@ -116,7 +116,7 @@ const int MAX_PLY = 128;
|
|||||||
/// any normal move destination square is always different from origin square
|
/// any normal move destination square is always different from origin square
|
||||||
/// while MOVE_NONE and MOVE_NULL have the same origin and destination square.
|
/// while MOVE_NONE and MOVE_NULL have the same origin and destination square.
|
||||||
|
|
||||||
enum Move {
|
enum Move : int {
|
||||||
MOVE_NONE,
|
MOVE_NONE,
|
||||||
MOVE_NULL = 65
|
MOVE_NULL = 65
|
||||||
};
|
};
|
||||||
@@ -129,27 +129,23 @@ enum MoveType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum Color {
|
enum Color {
|
||||||
WHITE, BLACK, NO_COLOR, COLOR_NB = 2
|
WHITE, BLACK, COLOR_NB = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CastlingSide {
|
enum CastlingRights {
|
||||||
KING_SIDE, QUEEN_SIDE, CASTLING_SIDE_NB = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum CastlingRight {
|
|
||||||
NO_CASTLING,
|
NO_CASTLING,
|
||||||
WHITE_OO,
|
WHITE_OO,
|
||||||
WHITE_OOO = WHITE_OO << 1,
|
WHITE_OOO = WHITE_OO << 1,
|
||||||
BLACK_OO = WHITE_OO << 2,
|
BLACK_OO = WHITE_OO << 2,
|
||||||
BLACK_OOO = WHITE_OO << 3,
|
BLACK_OOO = WHITE_OO << 3,
|
||||||
ANY_CASTLING = WHITE_OO | WHITE_OOO | BLACK_OO | BLACK_OOO,
|
|
||||||
CASTLING_RIGHT_NB = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
template<Color C, CastlingSide S> struct MakeCastling {
|
KING_SIDE = WHITE_OO | BLACK_OO,
|
||||||
static const CastlingRight
|
QUEEN_SIDE = WHITE_OOO | BLACK_OOO,
|
||||||
right = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO
|
WHITE_CASTLING = WHITE_OO | WHITE_OOO,
|
||||||
: S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO;
|
BLACK_CASTLING = BLACK_OO | BLACK_OOO,
|
||||||
|
ANY_CASTLING = WHITE_CASTLING | BLACK_CASTLING,
|
||||||
|
|
||||||
|
CASTLING_RIGHT_NB = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Phase {
|
enum Phase {
|
||||||
@@ -160,7 +156,6 @@ enum Phase {
|
|||||||
|
|
||||||
enum ScaleFactor {
|
enum ScaleFactor {
|
||||||
SCALE_FACTOR_DRAW = 0,
|
SCALE_FACTOR_DRAW = 0,
|
||||||
SCALE_FACTOR_ONEPAWN = 48,
|
|
||||||
SCALE_FACTOR_NORMAL = 64,
|
SCALE_FACTOR_NORMAL = 64,
|
||||||
SCALE_FACTOR_MAX = 128,
|
SCALE_FACTOR_MAX = 128,
|
||||||
SCALE_FACTOR_NONE = 255
|
SCALE_FACTOR_NONE = 255
|
||||||
@@ -184,13 +179,13 @@ enum Value : int {
|
|||||||
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
||||||
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
||||||
|
|
||||||
PawnValueMg = 198, PawnValueEg = 258,
|
PawnValueMg = 128, PawnValueEg = 213,
|
||||||
KnightValueMg = 817, KnightValueEg = 846,
|
KnightValueMg = 781, KnightValueEg = 854,
|
||||||
BishopValueMg = 836, BishopValueEg = 857,
|
BishopValueMg = 825, BishopValueEg = 915,
|
||||||
RookValueMg = 1270, RookValueEg = 1281,
|
RookValueMg = 1276, RookValueEg = 1380,
|
||||||
QueenValueMg = 2521, QueenValueEg = 2558,
|
QueenValueMg = 2538, QueenValueEg = 2682,
|
||||||
|
|
||||||
MidgameLimit = 15581, EndgameLimit = 3998
|
MidgameLimit = 15258, EndgameLimit = 3915
|
||||||
};
|
};
|
||||||
|
|
||||||
enum PieceType {
|
enum PieceType {
|
||||||
@@ -206,20 +201,21 @@ enum Piece {
|
|||||||
PIECE_NB = 16
|
PIECE_NB = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Depth {
|
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
||||||
|
|
||||||
ONE_PLY = 1,
|
typedef int Depth;
|
||||||
|
|
||||||
|
enum : int {
|
||||||
|
|
||||||
DEPTH_ZERO = 0,
|
|
||||||
DEPTH_QS_CHECKS = 0,
|
DEPTH_QS_CHECKS = 0,
|
||||||
DEPTH_QS_NO_CHECKS = -1,
|
DEPTH_QS_NO_CHECKS = -1,
|
||||||
DEPTH_QS_RECAPTURES = -5,
|
DEPTH_QS_RECAPTURES = -5,
|
||||||
|
|
||||||
DEPTH_NONE = -6,
|
DEPTH_NONE = -6,
|
||||||
DEPTH_MAX = MAX_PLY
|
DEPTH_OFFSET = DEPTH_NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Square {
|
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,
|
||||||
@@ -230,132 +226,163 @@ 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,
|
||||||
|
|
||||||
SQUARE_NB = 64,
|
SQUARE_NB = 64
|
||||||
|
|
||||||
DELTA_N = 8,
|
|
||||||
DELTA_E = 1,
|
|
||||||
DELTA_S = -8,
|
|
||||||
DELTA_W = -1,
|
|
||||||
|
|
||||||
DELTA_NN = DELTA_N + DELTA_N,
|
|
||||||
DELTA_NE = DELTA_N + DELTA_E,
|
|
||||||
DELTA_SE = DELTA_S + DELTA_E,
|
|
||||||
DELTA_SS = DELTA_S + DELTA_S,
|
|
||||||
DELTA_SW = DELTA_S + DELTA_W,
|
|
||||||
DELTA_NW = DELTA_N + DELTA_W
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum File {
|
enum Direction : int {
|
||||||
|
NORTH = 8,
|
||||||
|
EAST = 1,
|
||||||
|
SOUTH = -NORTH,
|
||||||
|
WEST = -EAST,
|
||||||
|
|
||||||
|
NORTH_EAST = NORTH + EAST,
|
||||||
|
SOUTH_EAST = SOUTH + EAST,
|
||||||
|
SOUTH_WEST = SOUTH + WEST,
|
||||||
|
NORTH_WEST = NORTH + WEST
|
||||||
|
};
|
||||||
|
|
||||||
|
enum File : int {
|
||||||
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB
|
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Rank {
|
enum Rank : int {
|
||||||
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
|
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Score enum stores a middlegame and an endgame value in a single integer
|
/// Score enum stores a middlegame and an endgame value in a single integer (enum).
|
||||||
/// (enum). The least significant 16 bits are used to store the endgame value
|
/// The least significant 16 bits are used to store the middlegame value and the
|
||||||
/// and the upper 16 bits are used to store the middlegame value.
|
/// upper 16 bits are used to store the endgame value. We have to take care to
|
||||||
|
/// avoid left-shifting a signed int to avoid undefined behavior.
|
||||||
enum Score : int { SCORE_ZERO };
|
enum Score : int { SCORE_ZERO };
|
||||||
|
|
||||||
inline Score make_score(int mg, int eg) {
|
constexpr Score make_score(int mg, int eg) {
|
||||||
return Score((mg << 16) + eg);
|
return Score((int)((unsigned int)eg << 16) + mg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracting the signed lower and upper 16 bits is not so trivial because
|
/// Extracting the signed lower and upper 16 bits is not so trivial because
|
||||||
/// according to the standard a simple cast to short is implementation defined
|
/// according to the standard a simple cast to short is implementation defined
|
||||||
/// and so is a right shift of a signed integer.
|
/// and so is a right shift of a signed integer.
|
||||||
inline Value mg_value(Score s) {
|
|
||||||
|
|
||||||
union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s + 0x8000) >> 16) };
|
|
||||||
return Value(mg.s);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Value eg_value(Score s) {
|
inline Value eg_value(Score s) {
|
||||||
|
union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s + 0x8000) >> 16) };
|
||||||
union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s)) };
|
|
||||||
return Value(eg.s);
|
return Value(eg.s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ENABLE_BASE_OPERATORS_ON(T) \
|
inline Value mg_value(Score s) {
|
||||||
inline T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
|
union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s)) };
|
||||||
inline T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \
|
return Value(mg.s);
|
||||||
inline T operator*(int i, T d) { return T(i * int(d)); } \
|
}
|
||||||
inline T operator*(T d, int i) { return T(int(d) * i); } \
|
|
||||||
inline T operator-(T d) { return T(-int(d)); } \
|
|
||||||
inline T& operator+=(T& d1, T d2) { return d1 = d1 + d2; } \
|
|
||||||
inline T& operator-=(T& d1, T d2) { return d1 = d1 - d2; } \
|
|
||||||
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); }
|
|
||||||
|
|
||||||
#define ENABLE_FULL_OPERATORS_ON(T) \
|
#define ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
ENABLE_BASE_OPERATORS_ON(T) \
|
constexpr T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
|
||||||
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
constexpr T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \
|
||||||
inline T& operator--(T& d) { return d = T(int(d) - 1); } \
|
constexpr T operator-(T d) { return T(-int(d)); } \
|
||||||
inline T operator/(T d, int i) { return T(int(d) / i); } \
|
inline T& operator+=(T& d1, T d2) { return d1 = d1 + d2; } \
|
||||||
inline int operator/(T d1, T d2) { return int(d1) / int(d2); } \
|
inline T& operator-=(T& d1, T d2) { return d1 = d1 - d2; }
|
||||||
|
|
||||||
|
#define ENABLE_INCR_OPERATORS_ON(T) \
|
||||||
|
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
||||||
|
inline T& operator--(T& d) { return d = T(int(d) - 1); }
|
||||||
|
|
||||||
|
#define ENABLE_FULL_OPERATORS_ON(T) \
|
||||||
|
ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
|
constexpr T operator*(int i, T d) { return T(i * int(d)); } \
|
||||||
|
constexpr T operator*(T d, int i) { return T(int(d) * i); } \
|
||||||
|
constexpr T operator/(T d, int i) { return T(int(d) / i); } \
|
||||||
|
constexpr int operator/(T d1, T d2) { return int(d1) / int(d2); } \
|
||||||
|
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); } \
|
||||||
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
||||||
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Value)
|
ENABLE_FULL_OPERATORS_ON(Value)
|
||||||
ENABLE_FULL_OPERATORS_ON(PieceType)
|
ENABLE_FULL_OPERATORS_ON(Direction)
|
||||||
ENABLE_FULL_OPERATORS_ON(Piece)
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Color)
|
ENABLE_INCR_OPERATORS_ON(PieceType)
|
||||||
ENABLE_FULL_OPERATORS_ON(Depth)
|
ENABLE_INCR_OPERATORS_ON(Piece)
|
||||||
ENABLE_FULL_OPERATORS_ON(Square)
|
ENABLE_INCR_OPERATORS_ON(Square)
|
||||||
ENABLE_FULL_OPERATORS_ON(File)
|
ENABLE_INCR_OPERATORS_ON(File)
|
||||||
ENABLE_FULL_OPERATORS_ON(Rank)
|
ENABLE_INCR_OPERATORS_ON(Rank)
|
||||||
|
|
||||||
ENABLE_BASE_OPERATORS_ON(Score)
|
ENABLE_BASE_OPERATORS_ON(Score)
|
||||||
|
|
||||||
#undef ENABLE_FULL_OPERATORS_ON
|
#undef ENABLE_FULL_OPERATORS_ON
|
||||||
|
#undef ENABLE_INCR_OPERATORS_ON
|
||||||
#undef ENABLE_BASE_OPERATORS_ON
|
#undef ENABLE_BASE_OPERATORS_ON
|
||||||
|
|
||||||
/// Additional operators to add integers to a Value
|
/// Additional operators to add integers to a Value
|
||||||
inline Value operator+(Value v, int i) { return Value(int(v) + i); }
|
constexpr Value operator+(Value v, int i) { return Value(int(v) + i); }
|
||||||
inline Value operator-(Value v, int i) { return Value(int(v) - i); }
|
constexpr Value operator-(Value v, int i) { return Value(int(v) - i); }
|
||||||
inline Value& operator+=(Value& v, int i) { return v = v + i; }
|
inline Value& operator+=(Value& v, int i) { return v = v + i; }
|
||||||
inline Value& operator-=(Value& v, int i) { return v = v - i; }
|
inline Value& operator-=(Value& v, int i) { return v = v - i; }
|
||||||
|
|
||||||
|
/// Additional operators to add a Direction to a Square
|
||||||
|
constexpr Square operator+(Square s, Direction d) { return Square(int(s) + int(d)); }
|
||||||
|
constexpr Square operator-(Square s, Direction d) { return Square(int(s) - int(d)); }
|
||||||
|
inline Square& operator+=(Square& s, Direction d) { return s = s + d; }
|
||||||
|
inline Square& operator-=(Square& s, Direction d) { return s = s - d; }
|
||||||
|
|
||||||
/// Only declared but not defined. We don't want to multiply two scores due to
|
/// Only declared but not defined. We don't want to multiply two scores due to
|
||||||
/// a very high risk of overflow. So user should explicitly convert to integer.
|
/// a very high risk of overflow. So user should explicitly convert to integer.
|
||||||
inline Score operator*(Score s1, Score s2);
|
Score operator*(Score, Score) = delete;
|
||||||
|
|
||||||
/// Division of a Score must be handled separately for each term
|
/// Division of a Score must be handled separately for each term
|
||||||
inline Score operator/(Score s, int i) {
|
inline Score operator/(Score s, int i) {
|
||||||
return make_score(mg_value(s) / i, eg_value(s) / i);
|
return make_score(mg_value(s) / i, eg_value(s) / i);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
/// Multiplication of a Score by an integer. We check for overflow in debug mode.
|
||||||
|
inline Score operator*(Score s, int i) {
|
||||||
|
|
||||||
inline Color operator~(Color c) {
|
Score result = Score(int(s) * i);
|
||||||
return Color(c ^ BLACK);
|
|
||||||
|
assert(eg_value(result) == (i * eg_value(s)));
|
||||||
|
assert(mg_value(result) == (i * mg_value(s)));
|
||||||
|
assert((i == 0) || (result / i) == s);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square operator~(Square s) {
|
/// Multiplication of a Score by a boolean
|
||||||
|
inline Score operator*(Score s, bool b) {
|
||||||
|
return Score(int(s) * int(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Color operator~(Color c) {
|
||||||
|
return Color(c ^ BLACK); // Toggle color
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Square operator~(Square s) {
|
||||||
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
|
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CastlingRight operator|(Color c, CastlingSide s) {
|
constexpr Piece operator~(Piece pc) {
|
||||||
return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
|
return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value mate_in(int ply) {
|
inline File map_to_queenside(File f) {
|
||||||
|
return std::min(f, File(FILE_H - f)); // Map files ABCDEFGH to files ABCDDCBA
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr CastlingRights operator&(Color c, CastlingRights cr) {
|
||||||
|
return CastlingRights((c == WHITE ? WHITE_CASTLING : BLACK_CASTLING) & cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Value mate_in(int ply) {
|
||||||
return VALUE_MATE - ply;
|
return VALUE_MATE - ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value mated_in(int ply) {
|
constexpr Value mated_in(int ply) {
|
||||||
return -VALUE_MATE + ply;
|
return -VALUE_MATE + ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square make_square(File f, Rank r) {
|
constexpr Square make_square(File f, Rank r) {
|
||||||
return Square((r << 3) | f);
|
return Square((r << 3) + f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Piece make_piece(Color c, PieceType pt) {
|
constexpr Piece make_piece(Color c, PieceType pt) {
|
||||||
return Piece((c << 3) | pt);
|
return Piece((c << 3) + pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType type_of(Piece pc) {
|
constexpr PieceType type_of(Piece pc) {
|
||||||
return PieceType(pc & 7);
|
return PieceType(pc & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,65 +391,68 @@ inline Color color_of(Piece pc) {
|
|||||||
return Color(pc >> 3);
|
return Color(pc >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_ok(Square s) {
|
constexpr bool is_ok(Square s) {
|
||||||
return s >= SQ_A1 && s <= SQ_H8;
|
return s >= SQ_A1 && s <= SQ_H8;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline File file_of(Square s) {
|
constexpr File file_of(Square s) {
|
||||||
return File(s & 7);
|
return File(s & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank rank_of(Square s) {
|
constexpr Rank rank_of(Square s) {
|
||||||
return Rank(s >> 3);
|
return Rank(s >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square relative_square(Color c, Square s) {
|
constexpr Square relative_square(Color c, Square s) {
|
||||||
return Square(s ^ (c * 56));
|
return Square(s ^ (c * 56));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank relative_rank(Color c, Rank r) {
|
constexpr Rank relative_rank(Color c, Rank r) {
|
||||||
return Rank(r ^ (c * 7));
|
return Rank(r ^ (c * 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank relative_rank(Color c, Square s) {
|
constexpr Rank relative_rank(Color c, Square s) {
|
||||||
return relative_rank(c, rank_of(s));
|
return relative_rank(c, rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool opposite_colors(Square s1, Square s2) {
|
constexpr Direction pawn_push(Color c) {
|
||||||
int s = int(s1) ^ int(s2);
|
return c == WHITE ? NORTH : SOUTH;
|
||||||
return ((s >> 3) ^ s) & 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square pawn_push(Color c) {
|
constexpr Square from_sq(Move m) {
|
||||||
return c == WHITE ? DELTA_N : DELTA_S;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square from_sq(Move m) {
|
|
||||||
return Square((m >> 6) & 0x3F);
|
return Square((m >> 6) & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square to_sq(Move m) {
|
constexpr Square to_sq(Move m) {
|
||||||
return Square(m & 0x3F);
|
return Square(m & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline MoveType type_of(Move m) {
|
constexpr int from_to(Move m) {
|
||||||
|
return m & 0xFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MoveType type_of(Move m) {
|
||||||
return MoveType(m & (3 << 14));
|
return MoveType(m & (3 << 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType promotion_type(Move m) {
|
constexpr PieceType promotion_type(Move m) {
|
||||||
return PieceType(((m >> 12) & 3) + KNIGHT);
|
return PieceType(((m >> 12) & 3) + KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Move make_move(Square from, Square to) {
|
constexpr Move make_move(Square from, Square to) {
|
||||||
return Move(to | (from << 6));
|
return Move((from << 6) + to);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Move reverse_move(Move m) {
|
||||||
|
return make_move(to_sq(m), from_sq(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<MoveType T>
|
template<MoveType T>
|
||||||
inline Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
constexpr Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
||||||
return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12));
|
return Move(T + ((pt - KNIGHT) << 12) + (from << 6) + to);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_ok(Move m) {
|
constexpr bool is_ok(Move m) {
|
||||||
return from_sq(m) != to_sq(m); // Catch MOVE_NULL and MOVE_NONE
|
return from_sq(m) != to_sq(m); // Catch MOVE_NULL and MOVE_NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+91
-58
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
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 <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -28,29 +29,26 @@
|
|||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "timeman.h"
|
#include "timeman.h"
|
||||||
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
extern void benchmark(const Position& pos, istream& is);
|
extern vector<string> setup_bench(const Position&, istream&);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// FEN string of the initial position, normal chess
|
// FEN string of the initial position, normal chess
|
||||||
const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
|
|
||||||
// Stack to keep track of the position states along the setup moves (from the
|
|
||||||
// start position to the position just before the search starts). Needed by
|
|
||||||
// 'draw by repetition' detection.
|
|
||||||
Search::StateStackPtr SetupStates;
|
|
||||||
|
|
||||||
|
|
||||||
// position() is called when engine receives the "position" UCI command.
|
// position() is called when engine receives the "position" UCI command.
|
||||||
// The function sets up the position described in the given FEN string ("fen")
|
// 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
|
// or the starting position ("startpos") and then makes the moves given in the
|
||||||
// following move list ("moves").
|
// following move list ("moves").
|
||||||
|
|
||||||
void position(Position& pos, istringstream& is) {
|
void position(Position& pos, istringstream& is, StateListPtr& states) {
|
||||||
|
|
||||||
Move m;
|
Move m;
|
||||||
string token, fen;
|
string token, fen;
|
||||||
@@ -68,14 +66,14 @@ namespace {
|
|||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pos.set(fen, Options["UCI_Chess960"], Threads.main());
|
states = StateListPtr(new std::deque<StateInfo>(1)); // Drop old and create a new one
|
||||||
SetupStates = Search::StateStackPtr(new std::stack<StateInfo>);
|
pos.set(fen, Options["UCI_Chess960"], &states->back(), Threads.main());
|
||||||
|
|
||||||
// Parse move list (if any)
|
// Parse move list (if any)
|
||||||
while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE)
|
while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE)
|
||||||
{
|
{
|
||||||
SetupStates->push(StateInfo());
|
states->emplace_back();
|
||||||
pos.do_move(m, SetupStates->top(), pos.gives_check(m, CheckInfo(pos)));
|
pos.do_move(m, states->back());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,11 +89,11 @@ namespace {
|
|||||||
|
|
||||||
// Read option name (can contain spaces)
|
// Read option name (can contain spaces)
|
||||||
while (is >> token && token != "value")
|
while (is >> token && token != "value")
|
||||||
name += string(" ", name.empty() ? 0 : 1) + token;
|
name += (name.empty() ? "" : " ") + token;
|
||||||
|
|
||||||
// Read option value (can contain spaces)
|
// Read option value (can contain spaces)
|
||||||
while (is >> token)
|
while (is >> token)
|
||||||
value += string(" ", value.empty() ? 0 : 1) + token;
|
value += (value.empty() ? "" : " ") + token;
|
||||||
|
|
||||||
if (Options.count(name))
|
if (Options.count(name))
|
||||||
Options[name] = value;
|
Options[name] = value;
|
||||||
@@ -108,10 +106,11 @@ namespace {
|
|||||||
// the thinking time and other parameters from the input string, then starts
|
// the thinking time and other parameters from the input string, then starts
|
||||||
// the search.
|
// the search.
|
||||||
|
|
||||||
void go(const Position& pos, istringstream& is) {
|
void go(Position& pos, istringstream& is, StateListPtr& states) {
|
||||||
|
|
||||||
Search::LimitsType limits;
|
Search::LimitsType limits;
|
||||||
string token;
|
string token;
|
||||||
|
bool ponderMode = false;
|
||||||
|
|
||||||
limits.startTime = now(); // As early as possible!
|
limits.startTime = now(); // As early as possible!
|
||||||
|
|
||||||
@@ -129,10 +128,58 @@ namespace {
|
|||||||
else if (token == "nodes") is >> limits.nodes;
|
else if (token == "nodes") is >> limits.nodes;
|
||||||
else if (token == "movetime") is >> limits.movetime;
|
else if (token == "movetime") is >> limits.movetime;
|
||||||
else if (token == "mate") is >> limits.mate;
|
else if (token == "mate") is >> limits.mate;
|
||||||
|
else if (token == "perft") is >> limits.perft;
|
||||||
else if (token == "infinite") limits.infinite = 1;
|
else if (token == "infinite") limits.infinite = 1;
|
||||||
else if (token == "ponder") limits.ponder = 1;
|
else if (token == "ponder") ponderMode = true;
|
||||||
|
|
||||||
Threads.start_thinking(pos, limits, SetupStates);
|
Threads.start_thinking(pos, states, limits, ponderMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// bench() is called when engine receives the "bench" command. Firstly
|
||||||
|
// a list of UCI commands is setup according to bench parameters, then
|
||||||
|
// it is run one by one printing a summary at the end.
|
||||||
|
|
||||||
|
void bench(Position& pos, istream& args, StateListPtr& states) {
|
||||||
|
|
||||||
|
string token;
|
||||||
|
uint64_t num, nodes = 0, cnt = 1;
|
||||||
|
|
||||||
|
vector<string> list = setup_bench(pos, args);
|
||||||
|
num = count_if(list.begin(), list.end(), [](string s) { return s.find("go ") == 0 || s.find("eval") == 0; });
|
||||||
|
|
||||||
|
TimePoint elapsed = now();
|
||||||
|
|
||||||
|
for (const auto& cmd : list)
|
||||||
|
{
|
||||||
|
istringstream is(cmd);
|
||||||
|
is >> skipws >> token;
|
||||||
|
|
||||||
|
if (token == "go" || token == "eval")
|
||||||
|
{
|
||||||
|
cerr << "\nPosition: " << cnt++ << '/' << num << endl;
|
||||||
|
if (token == "go")
|
||||||
|
{
|
||||||
|
go(pos, is, states);
|
||||||
|
Threads.main()->wait_for_search_finished();
|
||||||
|
nodes += Threads.nodes_searched();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sync_cout << "\n" << Eval::trace(pos) << sync_endl;
|
||||||
|
}
|
||||||
|
else if (token == "setoption") setoption(is);
|
||||||
|
else if (token == "position") position(pos, is, states);
|
||||||
|
else if (token == "ucinewgame") { Search::clear(); elapsed = now(); } // Search::clear() may take some while
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
||||||
|
|
||||||
|
dbg_print(); // Just before exiting
|
||||||
|
|
||||||
|
cerr << "\n==========================="
|
||||||
|
<< "\nTotal time (ms) : " << elapsed
|
||||||
|
<< "\nNodes searched : " << nodes
|
||||||
|
<< "\nNodes/second : " << 1000 * nodes / elapsed << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -146,8 +193,11 @@ namespace {
|
|||||||
|
|
||||||
void UCI::loop(int argc, char* argv[]) {
|
void UCI::loop(int argc, char* argv[]) {
|
||||||
|
|
||||||
Position pos(StartFEN, false, Threads.main()); // The root position
|
Position pos;
|
||||||
string token, cmd;
|
string token, cmd;
|
||||||
|
StateListPtr states(new std::deque<StateInfo>(1));
|
||||||
|
|
||||||
|
pos.set(StartFEN, false, &states->back(), Threads.main());
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
cmd += std::string(argv[i]) + " ";
|
cmd += std::string(argv[i]) + " ";
|
||||||
@@ -158,61 +208,42 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
|
|
||||||
istringstream is(cmd);
|
istringstream is(cmd);
|
||||||
|
|
||||||
token.clear(); // getline() could return empty or blank line
|
token.clear(); // Avoid a stale if getline() returns empty or blank line
|
||||||
is >> skipws >> token;
|
is >> skipws >> token;
|
||||||
|
|
||||||
// The GUI sends 'ponderhit' to tell us to ponder on the same move the
|
|
||||||
// opponent has played. In case Signals.stopOnPonderhit is set we are
|
|
||||||
// waiting for 'ponderhit' to stop the search (for instance because we
|
|
||||||
// already ran out of time), otherwise we should continue searching but
|
|
||||||
// switching from pondering to normal search.
|
|
||||||
if ( token == "quit"
|
if ( token == "quit"
|
||||||
|| token == "stop"
|
|| token == "stop")
|
||||||
|| (token == "ponderhit" && Search::Signals.stopOnPonderhit))
|
Threads.stop = true;
|
||||||
{
|
|
||||||
Search::Signals.stop = true;
|
// The GUI sends 'ponderhit' to tell us the user has played the expected move.
|
||||||
Threads.main()->start_searching(true); // Could be sleeping
|
// 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.
|
||||||
else if (token == "ponderhit")
|
else if (token == "ponderhit")
|
||||||
Search::Limits.ponder = 0; // Switch to normal search
|
Threads.main()->ponder = false; // Switch to normal search
|
||||||
|
|
||||||
else if (token == "uci")
|
else if (token == "uci")
|
||||||
sync_cout << "id name " << engine_info(true)
|
sync_cout << "id name " << engine_info(true)
|
||||||
<< "\n" << Options
|
<< "\n" << Options
|
||||||
<< "\nuciok" << sync_endl;
|
<< "\nuciok" << sync_endl;
|
||||||
|
|
||||||
else if (token == "ucinewgame")
|
|
||||||
{
|
|
||||||
Search::clear();
|
|
||||||
Time.availableNodes = 0;
|
|
||||||
}
|
|
||||||
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
|
||||||
else if (token == "go") go(pos, is);
|
|
||||||
else if (token == "position") position(pos, is);
|
|
||||||
else if (token == "setoption") setoption(is);
|
else if (token == "setoption") setoption(is);
|
||||||
|
else if (token == "go") go(pos, is, states);
|
||||||
|
else if (token == "position") position(pos, is, states);
|
||||||
|
else if (token == "ucinewgame") Search::clear();
|
||||||
|
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
||||||
|
|
||||||
// Additional custom non-UCI commands, useful for debugging
|
// Additional custom non-UCI commands, mainly for debugging.
|
||||||
else if (token == "flip") pos.flip();
|
// Do not use these commands during a search!
|
||||||
else if (token == "bench") benchmark(pos, is);
|
else if (token == "flip") pos.flip();
|
||||||
else if (token == "d") sync_cout << pos << sync_endl;
|
else if (token == "bench") bench(pos, is, states);
|
||||||
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
else if (token == "d") sync_cout << pos << sync_endl;
|
||||||
else if (token == "perft")
|
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
||||||
{
|
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
||||||
int depth;
|
|
||||||
stringstream ss;
|
|
||||||
|
|
||||||
is >> depth;
|
|
||||||
ss << Options["Hash"] << " "
|
|
||||||
<< Options["Threads"] << " " << depth << " current perft";
|
|
||||||
|
|
||||||
benchmark(pos, ss);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
sync_cout << "Unknown command: " << cmd << sync_endl;
|
sync_cout << "Unknown command: " << cmd << sync_endl;
|
||||||
|
|
||||||
} while (token != "quit" && argc == 1); // Passed args have one-shot behaviour
|
} while (token != "quit" && argc == 1); // Command line args are one-shot
|
||||||
|
|
||||||
Threads.main()->wait_for_search_finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -225,6 +256,8 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
|
|
||||||
string UCI::value(Value v) {
|
string UCI::value(Value v) {
|
||||||
|
|
||||||
|
assert(-VALUE_INFINITE < v && v < VALUE_INFINITE);
|
||||||
|
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
|
||||||
if (abs(v) < VALUE_MATE - MAX_PLY)
|
if (abs(v) < VALUE_MATE - MAX_PLY)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -49,12 +49,14 @@ public:
|
|||||||
Option(OnChange = nullptr);
|
Option(OnChange = nullptr);
|
||||||
Option(bool v, OnChange = nullptr);
|
Option(bool v, OnChange = nullptr);
|
||||||
Option(const char* v, OnChange = nullptr);
|
Option(const char* v, OnChange = nullptr);
|
||||||
Option(int v, int min, int max, OnChange = nullptr);
|
Option(double v, int minv, int maxv, OnChange = nullptr);
|
||||||
|
Option(const char* v, const char* cur, OnChange = nullptr);
|
||||||
|
|
||||||
Option& operator=(const std::string&);
|
Option& operator=(const std::string&);
|
||||||
void operator<<(const Option&);
|
void operator<<(const Option&);
|
||||||
operator int() const;
|
operator double() const;
|
||||||
operator std::string() const;
|
operator std::string() const;
|
||||||
|
bool operator==(const char*) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
|
friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
|
||||||
|
|||||||
+43
-15
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
@@ -39,7 +40,7 @@ namespace UCI {
|
|||||||
void on_clear_hash(const Option&) { Search::clear(); }
|
void on_clear_hash(const Option&) { Search::clear(); }
|
||||||
void on_hash_size(const Option& o) { TT.resize(o); }
|
void on_hash_size(const Option& o) { TT.resize(o); }
|
||||||
void on_logger(const Option& o) { start_logger(o); }
|
void on_logger(const Option& o) { start_logger(o); }
|
||||||
void on_threads(const Option&) { Threads.read_uci_options(); }
|
void on_threads(const Option& o) { Threads.set(o); }
|
||||||
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
||||||
|
|
||||||
|
|
||||||
@@ -55,11 +56,13 @@ bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const
|
|||||||
|
|
||||||
void init(OptionsMap& o) {
|
void init(OptionsMap& o) {
|
||||||
|
|
||||||
const int MaxHashMB = Is64Bit ? 1024 * 1024 : 2048;
|
// at most 2^32 clusters.
|
||||||
|
constexpr int MaxHashMB = Is64Bit ? 131072 : 2048;
|
||||||
|
|
||||||
o["Write Debug Log"] << Option(false, on_logger);
|
o["Debug Log File"] << Option("", on_logger);
|
||||||
o["Contempt"] << Option(0, -100, 100);
|
o["Contempt"] << Option(24, -100, 100);
|
||||||
o["Threads"] << Option(1, 1, 128, on_threads);
|
o["Analysis Contempt"] << Option("Both var Off var White var Black var Both", "Both");
|
||||||
|
o["Threads"] << Option(1, 1, 512, on_threads);
|
||||||
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
|
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
|
||||||
o["Clear Hash"] << Option(on_clear_hash);
|
o["Clear Hash"] << Option(on_clear_hash);
|
||||||
o["Ponder"] << Option(false);
|
o["Ponder"] << Option(false);
|
||||||
@@ -70,10 +73,13 @@ void init(OptionsMap& o) {
|
|||||||
o["Slow Mover"] << Option(84, 10, 1000);
|
o["Slow Mover"] << Option(84, 10, 1000);
|
||||||
o["nodestime"] << Option(0, 0, 10000);
|
o["nodestime"] << Option(0, 0, 10000);
|
||||||
o["UCI_Chess960"] << Option(false);
|
o["UCI_Chess960"] << Option(false);
|
||||||
|
o["UCI_AnalyseMode"] << Option(false);
|
||||||
|
o["UCI_LimitStrength"] << Option(false);
|
||||||
|
o["UCI_Elo"] << Option(1350, 1350, 2850);
|
||||||
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
||||||
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
||||||
o["Syzygy50MoveRule"] << Option(true);
|
o["Syzygy50MoveRule"] << Option(true);
|
||||||
o["SyzygyProbeLimit"] << Option(6, 0, 6);
|
o["SyzygyProbeLimit"] << Option(7, 0, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -89,11 +95,13 @@ std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
|
|||||||
const Option& o = it.second;
|
const Option& o = it.second;
|
||||||
os << "\noption name " << it.first << " type " << o.type;
|
os << "\noption name " << it.first << " type " << o.type;
|
||||||
|
|
||||||
if (o.type != "button")
|
if (o.type == "string" || o.type == "check" || o.type == "combo")
|
||||||
os << " default " << o.defaultValue;
|
os << " default " << o.defaultValue;
|
||||||
|
|
||||||
if (o.type == "spin")
|
if (o.type == "spin")
|
||||||
os << " min " << o.min << " max " << o.max;
|
os << " default " << int(stof(o.defaultValue))
|
||||||
|
<< " min " << o.min
|
||||||
|
<< " max " << o.max;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -113,12 +121,15 @@ Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f)
|
|||||||
Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
|
Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
|
Option::Option(double v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
|
||||||
{ defaultValue = currentValue = std::to_string(v); }
|
{ defaultValue = currentValue = std::to_string(v); }
|
||||||
|
|
||||||
Option::operator int() const {
|
Option::Option(const char* v, const char* cur, OnChange f) : type("combo"), min(0), max(0), on_change(f)
|
||||||
|
{ defaultValue = v; currentValue = cur; }
|
||||||
|
|
||||||
|
Option::operator double() const {
|
||||||
assert(type == "check" || type == "spin");
|
assert(type == "check" || type == "spin");
|
||||||
return (type == "spin" ? stoi(currentValue) : currentValue == "true");
|
return (type == "spin" ? stof(currentValue) : currentValue == "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
Option::operator std::string() const {
|
Option::operator std::string() const {
|
||||||
@@ -126,6 +137,12 @@ Option::operator std::string() const {
|
|||||||
return currentValue;
|
return currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Option::operator==(const char* s) const {
|
||||||
|
assert(type == "combo");
|
||||||
|
return !CaseInsensitiveLess()(currentValue, s)
|
||||||
|
&& !CaseInsensitiveLess()(s, currentValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// operator<<() inits options and assigns idx in the correct printing order
|
/// operator<<() inits options and assigns idx in the correct printing order
|
||||||
|
|
||||||
@@ -139,8 +156,8 @@ void Option::operator<<(const Option& o) {
|
|||||||
|
|
||||||
|
|
||||||
/// operator=() updates currentValue and triggers on_change() action. It's up to
|
/// operator=() updates currentValue and triggers on_change() action. It's up to
|
||||||
/// the GUI to check for option's limits, but we could receive the new value from
|
/// the GUI to check for option's limits, but we could receive the new value
|
||||||
/// the user by console window, so let's check the bounds anyway.
|
/// from the user by console window, so let's check the bounds anyway.
|
||||||
|
|
||||||
Option& Option::operator=(const string& v) {
|
Option& Option::operator=(const string& v) {
|
||||||
|
|
||||||
@@ -148,9 +165,20 @@ Option& Option::operator=(const string& v) {
|
|||||||
|
|
||||||
if ( (type != "button" && v.empty())
|
if ( (type != "button" && v.empty())
|
||||||
|| (type == "check" && v != "true" && v != "false")
|
|| (type == "check" && v != "true" && v != "false")
|
||||||
|| (type == "spin" && (stoi(v) < min || stoi(v) > max)))
|
|| (type == "spin" && (stof(v) < min || stof(v) > max)))
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
|
if (type == "combo")
|
||||||
|
{
|
||||||
|
OptionsMap comboMap; // To have case insensitive compare
|
||||||
|
string token;
|
||||||
|
std::istringstream ss(defaultValue);
|
||||||
|
while (ss >> token)
|
||||||
|
comboMap[token] << Option();
|
||||||
|
if (!comboMap.count(v) || v == "var")
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
if (type != "button")
|
if (type != "button")
|
||||||
currentValue = v;
|
currentValue = v;
|
||||||
|
|
||||||
|
|||||||
Executable
+145
@@ -0,0 +1,145 @@
|
|||||||
|
#!/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 -A50 "runtime error:"'
|
||||||
|
threads="1"
|
||||||
|
;;
|
||||||
|
--sanitizer-thread)
|
||||||
|
echo "sanitizer-thread testing started"
|
||||||
|
prefix='!'
|
||||||
|
exeprefix=''
|
||||||
|
postfix='2>&1 | grep -A50 "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:TTEntry::is_pv
|
||||||
|
|
||||||
|
race:TranspositionTable::probe
|
||||||
|
race:TranspositionTable::hashfull
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
export TSAN_OPTIONS="suppressions=./tsan.supp"
|
||||||
|
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "unknown testing started"
|
||||||
|
prefix=''
|
||||||
|
exeprefix=''
|
||||||
|
postfix=''
|
||||||
|
threads="1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# simple command line testing
|
||||||
|
for args in "eval" \
|
||||||
|
"go nodes 1000" \
|
||||||
|
"go depth 10" \
|
||||||
|
"go movetime 1000" \
|
||||||
|
"go wtime 8000 btime 8000 winc 500 binc 500" \
|
||||||
|
"bench 128 $threads 10 default depth"
|
||||||
|
do
|
||||||
|
|
||||||
|
echo "$prefix $exeprefix ./stockfish $args $postfix"
|
||||||
|
eval "$prefix $exeprefix ./stockfish $args $postfix"
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
# more general testing, following an uci protocol exchange
|
||||||
|
cat << EOF > game.exp
|
||||||
|
set timeout 10
|
||||||
|
spawn $exeprefix ./stockfish
|
||||||
|
|
||||||
|
send "uci\n"
|
||||||
|
expect "uciok"
|
||||||
|
|
||||||
|
send "setoption name Threads value $threads\n"
|
||||||
|
|
||||||
|
send "ucinewgame\n"
|
||||||
|
send "position startpos\n"
|
||||||
|
send "go nodes 1000\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "position startpos moves e2e4 e7e6\n"
|
||||||
|
send "go nodes 1000\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
|
||||||
|
send "go depth 30\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "quit\n"
|
||||||
|
expect eof
|
||||||
|
|
||||||
|
# return error code of the spawned program, useful for valgrind
|
||||||
|
lassign [wait] pid spawnid os_error_flag value
|
||||||
|
exit \$value
|
||||||
|
EOF
|
||||||
|
|
||||||
|
#download TB as needed
|
||||||
|
if [ ! -d ../tests/syzygy ]; then
|
||||||
|
curl -sL https://api.github.com/repos/niklasf/python-chess/tarball/9b9aa13f9f36d08aadfabff872882f4ab1494e95 | tar -xzf -
|
||||||
|
mv niklasf-python-chess-9b9aa13 ../tests/syzygy
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat << EOF > syzygy.exp
|
||||||
|
set timeout 240
|
||||||
|
spawn $exeprefix ./stockfish
|
||||||
|
send "uci\n"
|
||||||
|
send "setoption name SyzygyPath value ../tests/syzygy/\n"
|
||||||
|
expect "info string Found 35 tablebases" {} timeout {exit 1}
|
||||||
|
send "bench 128 1 10 default depth\n"
|
||||||
|
send "quit\n"
|
||||||
|
expect eof
|
||||||
|
|
||||||
|
# return error code of the spawned program, useful for valgrind
|
||||||
|
lassign [wait] pid spawnid os_error_flag value
|
||||||
|
exit \$value
|
||||||
|
EOF
|
||||||
|
|
||||||
|
for exp in game.exp syzygy.exp
|
||||||
|
do
|
||||||
|
|
||||||
|
echo "$prefix expect $exp $postfix"
|
||||||
|
eval "$prefix expect $exp $postfix"
|
||||||
|
|
||||||
|
rm $exp
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -f tsan.supp
|
||||||
|
|
||||||
|
echo "instrumented testing OK"
|
||||||
Executable
+32
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# verify perft numbers (positions from www.chessprogramming.org/Perft_Results)
|
||||||
|
|
||||||
|
error()
|
||||||
|
{
|
||||||
|
echo "perft testing failed on line $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
trap 'error ${LINENO}' ERR
|
||||||
|
|
||||||
|
echo "perft testing started"
|
||||||
|
|
||||||
|
cat << EOF > perft.exp
|
||||||
|
set timeout 10
|
||||||
|
lassign \$argv pos depth result
|
||||||
|
spawn ./stockfish
|
||||||
|
send "position \$pos\\ngo perft \$depth\\n"
|
||||||
|
expect "Nodes searched? \$result" {} timeout {exit 1}
|
||||||
|
send "quit\\n"
|
||||||
|
expect eof
|
||||||
|
EOF
|
||||||
|
|
||||||
|
expect perft.exp startpos 5 4865609 > /dev/null
|
||||||
|
expect perft.exp "fen r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -" 5 193690690 > /dev/null
|
||||||
|
expect perft.exp "fen 8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -" 6 11030083 > /dev/null
|
||||||
|
expect perft.exp "fen r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1" 5 15833292 > /dev/null
|
||||||
|
expect perft.exp "fen rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8" 5 89941194 > /dev/null
|
||||||
|
expect perft.exp "fen r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10" 5 164075551 > /dev/null
|
||||||
|
|
||||||
|
rm perft.exp
|
||||||
|
|
||||||
|
echo "perft testing OK"
|
||||||
Executable
+61
@@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# verify reproducible search
|
||||||
|
|
||||||
|
error()
|
||||||
|
{
|
||||||
|
echo "reprosearch testing failed on line $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
trap 'error ${LINENO}' ERR
|
||||||
|
|
||||||
|
echo "reprosearch testing started"
|
||||||
|
|
||||||
|
# repeat two short games, separated by ucinewgame.
|
||||||
|
# with go nodes $nodes they should result in exactly
|
||||||
|
# the same node count for each iteration.
|
||||||
|
cat << EOF > repeat.exp
|
||||||
|
set timeout 10
|
||||||
|
spawn ./stockfish
|
||||||
|
lassign \$argv nodes
|
||||||
|
|
||||||
|
send "uci\n"
|
||||||
|
expect "uciok"
|
||||||
|
|
||||||
|
send "ucinewgame\n"
|
||||||
|
send "position startpos\n"
|
||||||
|
send "go nodes \$nodes\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "position startpos moves e2e4 e7e6\n"
|
||||||
|
send "go nodes \$nodes\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "ucinewgame\n"
|
||||||
|
send "position startpos\n"
|
||||||
|
send "go nodes \$nodes\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "position startpos moves e2e4 e7e6\n"
|
||||||
|
send "go nodes \$nodes\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "quit\n"
|
||||||
|
expect eof
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# to increase the likelyhood of finding a non-reproducible case,
|
||||||
|
# the allowed number of nodes are varied systematically
|
||||||
|
for i in `seq 1 20`
|
||||||
|
do
|
||||||
|
|
||||||
|
nodes=$((100*3**i/2**i))
|
||||||
|
echo "reprosearch testing with $nodes nodes"
|
||||||
|
|
||||||
|
# each line should appear exactly an even number of times
|
||||||
|
expect repeat.exp $nodes 2>&1 | grep -o "nodes [0-9]*" | sort | uniq -c | awk '{if ($1%2!=0) exit(1)}'
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
rm repeat.exp
|
||||||
|
|
||||||
|
echo "reprosearch testing OK"
|
||||||
Executable
+31
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# obtain and optionally verify Bench / signature
|
||||||
|
# if no reference is given, the output is deliberately limited to just the signature
|
||||||
|
|
||||||
|
error()
|
||||||
|
{
|
||||||
|
echo "running bench for signature failed on line $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
trap 'error ${LINENO}' ERR
|
||||||
|
|
||||||
|
# obtain
|
||||||
|
|
||||||
|
signature=`./stockfish bench 2>&1 | grep "Nodes searched : " | awk '{print $4}'`
|
||||||
|
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
# compare to given reference
|
||||||
|
if [ "$1" != "$signature" ]; then
|
||||||
|
if [ -z "$signature" ]; then
|
||||||
|
echo "No signature obtained from bench. Code crashed or assert triggered ?"
|
||||||
|
else
|
||||||
|
echo "signature mismatch: reference $1 obtained: $signature ."
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "signature OK: $signature"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# just report signature
|
||||||
|
echo $signature
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user