mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 14:27:45 +00:00
Compare commits
541 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ac44b40c9 | |||
| b839ea6c0c | |||
| 726df58131 | |||
| d9a8dd0f7a | |||
| 6776f76d20 | |||
| 74db0f0f40 | |||
| a010d438a2 | |||
| a4988fecee | |||
| dc5caff638 | |||
| 4e7a898d7e | |||
| 47ee6d9fa4 | |||
| 221f41c2df | |||
| a8b9c11f56 | |||
| e9eea87341 | |||
| a128faf0b0 | |||
| ed2754227a | |||
| 287b46aa63 | |||
| a04dcce628 | |||
| 452f0d1696 | |||
| 9337c6da46 | |||
| 5f3c660d5d | |||
| ab127028ed | |||
| 2f6927ac08 | |||
| f148a8f6cc | |||
| c51e12200a | |||
| 5804bef824 | |||
| 2572055c87 | |||
| c6ba14b7c9 | |||
| 5212995563 | |||
| 50e094ef8d | |||
| 7903495b0a | |||
| a3819188de | |||
| c0136fb728 | |||
| 9b17083912 | |||
| 05c5f08372 | |||
| 6716337f40 | |||
| ee8ccac622 | |||
| e4e12ed595 | |||
| d81def4fa9 | |||
| 9446dd6da3 | |||
| b7bc0d4c57 | |||
| c35c18a705 | |||
| 2ea323aec6 | |||
| ec0f0eba6b | |||
| 0719470e50 | |||
| 3ccdb57d6f | |||
| 03cfd94414 | |||
| 8c32878701 | |||
| 0c5e89e3e1 | |||
| 4a081280ed | |||
| ee9e162dd5 | |||
| 7e82f793b8 | |||
| a7bfaede91 | |||
| 1afbe1a1d7 | |||
| 226bd54064 | |||
| de0c9e84ca | |||
| 66b751713e | |||
| ecc100d1bb | |||
| 85559cc597 | |||
| 187451294f | |||
| ac4c971e06 | |||
| cab8b78846 | |||
| efdd1e697a | |||
| 09884756d8 | |||
| 32590884df | |||
| 977cd9520a | |||
| 471e745a91 | |||
| 8dc4396477 | |||
| 6181e01c2a | |||
| 0d207ec2c6 | |||
| 93f64577c3 | |||
| 8b6bcd9731 | |||
| 6c0b2f5003 | |||
| 52fd1a3d37 | |||
| 0c9c5032e8 | |||
| 9079bab84c | |||
| ea5af9b8c0 | |||
| 0b49ec9822 | |||
| 6c27bf1880 | |||
| da1165ae5d | |||
| 6e5bb3279f | |||
| e63ab4bd03 | |||
| d72e862a5b | |||
| 02fe05cd0d | |||
| 16d6faf479 | |||
| 2cec7347db | |||
| 1288a5a10a | |||
| 7f095b0a36 | |||
| 2aa455ce95 | |||
| c053f0b838 | |||
| 7abe5f12ef | |||
| 253428bb3f | |||
| 36f4fe52f0 | |||
| e4ad6a38ee | |||
| 6c6b6cd1a4 | |||
| c20a41c9cf | |||
| e0e4bdc991 | |||
| 35e39a196d | |||
| 276513c19f | |||
| 9643d7524e | |||
| b763b40101 | |||
| b4870595a5 | |||
| f010685136 | |||
| 91ce930b28 | |||
| b075d8ca53 | |||
| c0334c7bac | |||
| 0f712ad4fd | |||
| 7488d216fd | |||
| b95b1a9705 | |||
| b14846b6d7 | |||
| 921bd87280 | |||
| 569bc75eb8 | |||
| 0544d6c8f7 | |||
| fe76787a77 | |||
| 8e269d781a | |||
| df7cd94aee | |||
| f16c231bc9 | |||
| b89733b46c | |||
| 67f611f3eb | |||
| 80f5ca88f6 | |||
| 8425b2b499 | |||
| a086f34f36 | |||
| 83631c89ce | |||
| bedf80a4c0 | |||
| cb9399445f | |||
| fe7e0a425e | |||
| fb0e19dc8b | |||
| e6b5d03cc4 | |||
| b2c1e15698 | |||
| 11207f7c1f | |||
| 97f5d19bdc | |||
| fc89dbcab2 | |||
| 6b7efa0cd1 | |||
| c23cd4d90a | |||
| a9fa1fc7f7 | |||
| 1f1ef0897c | |||
| a49e4fac98 | |||
| 87379c2929 | |||
| 53b522d95d | |||
| ef0bbe6e18 | |||
| 65c2715d9a | |||
| ec0a650dff | |||
| abae3c5678 | |||
| f3809f2a18 | |||
| 81ae7cad2d | |||
| 94bb1964f6 | |||
| 13431922a3 | |||
| 9a3fc4d3fb | |||
| a4a0ffce71 | |||
| e81108a855 | |||
| f967f1a25e | |||
| 86c2d2fc3b | |||
| f9d3b48ad0 | |||
| d720778b2b | |||
| e2880f9b8e | |||
| 909e3adede | |||
| 626b1f8c6a | |||
| 06a350f1ae | |||
| a9e9746495 | |||
| a7fcdfd6bf | |||
| 41816b7ced | |||
| 13224e1d9d | |||
| 10c1ae8da0 | |||
| 3a62738174 | |||
| 84451191f3 | |||
| 2ed3358faf | |||
| 08634b06a3 | |||
| 0e33fc6fd4 | |||
| a5a8830e97 | |||
| 2a14123550 | |||
| 8fabd69d4a | |||
| 1fc88071d1 | |||
| 7dca461927 | |||
| 7618ee2df1 | |||
| 661d48c27b | |||
| 42de93ac15 | |||
| 426f55b78d | |||
| b638f6b035 | |||
| 3de0bc43a2 | |||
| 9fc602bae7 | |||
| 49c50399fe | |||
| a4551c59e0 | |||
| c853b87c08 | |||
| 92bada1a32 | |||
| eaed535c5f | |||
| 49dfc50b12 | |||
| c835ee8853 | |||
| 7ff9678651 | |||
| 4ef068a506 | |||
| f23a9e8f88 | |||
| cc2a249952 | |||
| 55f0d6377f | |||
| aeb664e0ea | |||
| 8abdb131c8 | |||
| 43c93cb151 | |||
| 8d1d9f7181 | |||
| a303bde26c | |||
| 0f50f10327 | |||
| 8286e6ded2 | |||
| 3a558a3d8b | |||
| 14dbeb22dd | |||
| 68eb7e77f1 | |||
| 57340c109b | |||
| 111aa44662 | |||
| 29fb389760 | |||
| 0d292d1a2d | |||
| 5bb9da9287 | |||
| 34c7f1387d | |||
| fc23466236 | |||
| 01b228b5e1 | |||
| 2142be7d7f | |||
| 3888d14bd4 | |||
| 7bcd97933a | |||
| 9d4abbc6eb | |||
| c3b3dcc31a | |||
| e6f2d43b8a | |||
| 1a03f0b0d3 | |||
| 62f6d39204 | |||
| 936cd5b83d | |||
| 3c31776a20 | |||
| 0980f43ab0 | |||
| 9eedc0a463 | |||
| 195b54c312 | |||
| 89b4ad6433 | |||
| 77bb9a94ae | |||
| 8a78ac84f3 | |||
| 5c944fb3b4 | |||
| c974d9ef33 | |||
| 12feb5866f | |||
| 80810e4951 | |||
| c67b9916f1 | |||
| 78c6bb1079 | |||
| 85e60bfc8e | |||
| 79b57dd4ca | |||
| b9537edbb0 | |||
| d38f4f61e7 | |||
| 27c74c5245 | |||
| 2f2e8a68d8 | |||
| 1ea70dd9dd | |||
| 13c096f839 | |||
| 2de2b76896 | |||
| 8b99e94562 | |||
| 512a4e4ff0 | |||
| 2da290d72b | |||
| b39a24ecca | |||
| 189a005a0b | |||
| 7c61b8ad2a | |||
| a093f33154 | |||
| 0895f1ac71 | |||
| b29198354c | |||
| 40a7ffd53f | |||
| 8eae6a95fb | |||
| 2b740f5495 | |||
| fb5ba1d329 | |||
| 78e494fcbc | |||
| a16415f44d | |||
| 8a504d36f9 | |||
| 093dd8fe88 | |||
| 6382324afd | |||
| cb08413dc4 | |||
| 711ef615c7 | |||
| 74203e181d | |||
| 97fe0ac777 | |||
| 7ae16a193b | |||
| 8261f61964 | |||
| 6e1cb6e45b | |||
| 4bfa0c429e | |||
| 2e70a2873f | |||
| 9429d2d028 | |||
| d44fa46082 | |||
| c7866a4215 | |||
| 69644d3f73 | |||
| b0858877ae | |||
| 321f6d1d19 | |||
| e738fa7d10 | |||
| c5d546e18e | |||
| 8d65fcc0f3 | |||
| d8e5b8c133 | |||
| 6fe36d13de | |||
| 337ec0f3d0 | |||
| 5b1043ee11 | |||
| 439aea9ab7 | |||
| 770db27164 | |||
| 21d32aa7fe | |||
| 95d33aef9f | |||
| b5a4edd86f | |||
| 35ada63174 | |||
| 06a695d5b8 | |||
| 4b55d3d883 | |||
| 8008f78415 | |||
| 3941e4bdb3 | |||
| d7d2c1b7e3 | |||
| 17502a5659 | |||
| e84488ed6b | |||
| 252844e899 | |||
| b651e5334b | |||
| bd358533a4 | |||
| e4d3a15656 | |||
| 1d7a3f26e0 | |||
| a0005ba45f | |||
| bdd61b1744 | |||
| 973e574e1f | |||
| 27393ebae2 | |||
| 3c7eebb48d | |||
| 548bae80bd | |||
| 2360c8aa2f | |||
| 32bd6e44f0 | |||
| c83fd08fd4 | |||
| 62b43130e2 | |||
| cd112ee8eb | |||
| bb968fd42a | |||
| 307909bed8 | |||
| b95ba7b37e | |||
| f37741cc83 | |||
| 54b3d44194 | |||
| ea53006a9d | |||
| 6247f27a05 | |||
| 5b2fc1e1c0 | |||
| 05a8c318b8 | |||
| 22b8dc8c98 | |||
| cfe59de27d | |||
| c43c5fe9e0 | |||
| d0daa16769 | |||
| 87303d7ed3 | |||
| cf9bf4e58f | |||
| 5ca4284027 | |||
| dac1bcab90 | |||
| 81cfd81366 | |||
| d844a75d2c | |||
| c5e71f5150 | |||
| c5858ff9ae | |||
| 0ff91e16da | |||
| c2df60048e | |||
| 84ec1f7331 | |||
| b1ac6c69a0 | |||
| 56e09b4cc8 | |||
| 5ed0a60203 | |||
| 1588a4e846 | |||
| 5894c759cd | |||
| 3975a2b94f | |||
| eb6ddd54f1 | |||
| 01ebb3d996 | |||
| 285df57a9a | |||
| 806c1d8723 | |||
| a1b8c8109b | |||
| c01af56769 | |||
| 66d5c13a88 | |||
| 0edad63b44 | |||
| b833c8247a | |||
| 419c5b69ca | |||
| 72e1e9b986 | |||
| 1062459029 | |||
| b5d38ad1e5 | |||
| 000a975eaf | |||
| d457594197 | |||
| 942c18ef66 | |||
| 007285be2d | |||
| e817a55bc6 | |||
| 638f3d31cc | |||
| 55745f4105 | |||
| 968c3de8e0 | |||
| 6a6facc058 | |||
| 5b21c10afb | |||
| dba072c449 | |||
| e2e360fcbc | |||
| 49b1c5dccd | |||
| c99d963fa5 | |||
| 7c0679ad61 | |||
| cc974fa7a4 | |||
| 807844eab1 | |||
| 860260c3b1 | |||
| d11af1de11 | |||
| 721d557681 | |||
| 0e15b0f1d3 | |||
| 9e6d38d224 | |||
| c8af7a867e | |||
| 5c8f571459 | |||
| 0256db2a11 | |||
| 12d8f74242 | |||
| 7824603549 | |||
| 0f39e5c4ff | |||
| 990d83a72d | |||
| cf486cf229 | |||
| e0a8b36436 | |||
| 8d724220a7 | |||
| 0973cc2ef6 | |||
| 3f14f9a478 | |||
| aa86d81f79 | |||
| b884351cc7 | |||
| 4d9e9ac3d4 | |||
| 3dc9f95225 | |||
| bc0871acbc | |||
| 2643f1552f | |||
| ba07b95ee0 | |||
| ef58551a2d | |||
| 7d34e7bf84 | |||
| 12aeac5e14 | |||
| 734fb9a13b | |||
| c12364bb67 | |||
| ad5b5cef4a | |||
| 0d88b832e3 | |||
| 14c3da5cad | |||
| 0b9b34655f | |||
| a66f31f129 | |||
| 2161d8b0b3 | |||
| 7bc72d092f | |||
| b056e5d40a | |||
| d0b8bc5fdf | |||
| 9a46ac6b2c | |||
| 0fc9d9ef61 | |||
| bd618941ce | |||
| 403db5a6e9 | |||
| 3f3365221b | |||
| ae0b965711 | |||
| 455993b289 | |||
| c7a77dd3c0 | |||
| af3dd21e90 | |||
| 1a7047f544 | |||
| 25c22ffe7a | |||
| ae6157fcf3 | |||
| 5bec768d42 | |||
| 6ae30e7cb1 | |||
| 5ea8167921 | |||
| 55b5b03273 | |||
| 850c021f86 | |||
| cd0c7373cd | |||
| 9a59535962 | |||
| 48246468f2 | |||
| 2b6bc70f7b | |||
| 8b3fdec7ec | |||
| 58452de86d | |||
| 93c9f342ca | |||
| 16acf57773 | |||
| 77eec9f9cb | |||
| bc35f4c42d | |||
| 889c8538a8 | |||
| c52da3b806 | |||
| b599da01fa | |||
| 52bca81dcb | |||
| 0eedf47661 | |||
| 989833205f | |||
| 87507121d5 | |||
| 89fe8bc0a6 | |||
| 4c58db0dab | |||
| 71e852ea81 | |||
| 314faa905a | |||
| a530fc2b60 | |||
| 7d0e0ff95e | |||
| 764229a2e2 | |||
| 5e340346db | |||
| bf395c6be1 | |||
| ad44ff2bca | |||
| 8e96149c8c | |||
| 3c085775d7 | |||
| dd5a3ae4a6 | |||
| f7f09b91ea | |||
| 8a116ce691 | |||
| 16626dd655 | |||
| 2f01d67a92 | |||
| 975d5e9c64 | |||
| 30075e4abc | |||
| 37398d9456 | |||
| e05039156c | |||
| f35ddb04af | |||
| ef6fca98a0 | |||
| fea46a8212 | |||
| 776c7df30c | |||
| 5e112f16da | |||
| 15ec3e911e | |||
| 1ecd8e13ee | |||
| 444c7c5183 | |||
| e9757f7610 | |||
| 1ab01f1c14 | |||
| 4626ec2890 | |||
| dda7e4639a | |||
| 1ae8c59c0b | |||
| 06f06a9be8 | |||
| 2f5ee9e4e8 | |||
| dd884b65b7 | |||
| 0fdc75c0bd | |||
| dae7cacd3b | |||
| 7c0cb8e73d | |||
| 53ce6ce49c | |||
| 7a68916ff9 | |||
| 82a1e2d5fc | |||
| dc286d2673 | |||
| a9e536a7eb | |||
| e59d053984 | |||
| 1c73c1c150 | |||
| 423b8b9ded | |||
| 94dcac1fee | |||
| 0855d93de8 | |||
| deecb3757c | |||
| 53c2bf0697 | |||
| 483a257618 | |||
| 12461996a5 | |||
| 70b7404a63 | |||
| dddaeff7d8 | |||
| 941d923bf8 | |||
| 23de3e16f1 | |||
| 8ebe5075eb | |||
| fa49311b36 | |||
| d9b920acfb | |||
| 12b0517d1b | |||
| b38685625a | |||
| 73da3a431c | |||
| b50921fd5c | |||
| a72c55283d | |||
| cf4df0327a | |||
| 51c3af9dd0 | |||
| f0b0a3b135 | |||
| 4dd7fccfd1 | |||
| c1ea5ed6f7 | |||
| 53f882ff1a | |||
| d8e7ce1863 | |||
| 181d34e5a0 | |||
| 2655f93c32 | |||
| ab4d26f9bd | |||
| d6b04c2798 | |||
| e2e249eabd | |||
| ed19a9f909 | |||
| eddfd46a10 | |||
| a806d7c3d6 | |||
| ccdb634b77 | |||
| 564ed5b38c | |||
| f05d059b17 | |||
| 06a5b602dc | |||
| d892063cd3 | |||
| 64d6ba2e98 | |||
| 5a5dc6fa10 | |||
| 8ee0842c81 | |||
| e59ff49a55 | |||
| 225dcfeeb7 | |||
| 8dd01fda12 | |||
| 18cd83a380 | |||
| fd2b3df770 | |||
| da948cc94e | |||
| e49b21eacb | |||
| 60bc30275d | |||
| 32dfaa56b0 | |||
| 3701a8e57d |
+4
-5
@@ -52,14 +52,13 @@ UCI parameter "Book File".
|
|||||||
|
|
||||||
On Unix-like systems, it should usually be possible to compile
|
On Unix-like systems, it should usually be possible to compile
|
||||||
Stockfish directly from the source code with the included Makefile.
|
Stockfish directly from the source code with the included Makefile.
|
||||||
The exception is computer with big-endian CPUs, like PowerPC
|
|
||||||
Macintoshes. Some of the bitboard routines in the current version of
|
For big-endian machines like Power PC you need to enable the proper
|
||||||
Stockfish are endianness-sensitive, and won't work on a big-endian CPU.
|
flag changing from -DNBIGENDIAN to -DBIGENDIAN in the Makefile.
|
||||||
|
|
||||||
Stockfish has POPCNT instruction runtime detection and support. This can
|
Stockfish has POPCNT instruction runtime detection and support. This can
|
||||||
give an extra speed on Core i7 or similar systems. To enable this feature
|
give an extra speed on Core i7 or similar systems. To enable this feature
|
||||||
(disabled by default) simply uncomment #define USE_POPCNT in bitcount.h
|
compile with 'make icc-profile-popcnt'
|
||||||
before to compile.
|
|
||||||
|
|
||||||
On 64 bit Unix-like systems the 'bsfq' assembly instruction will be used
|
On 64 bit Unix-like systems the 'bsfq' assembly instruction will be used
|
||||||
for bit counting. Detection is automatic at compile time, but in case you
|
for bit counting. Detection is automatic at compile time, but in case you
|
||||||
|
|||||||
+4
-19
@@ -7,7 +7,7 @@ EngineCommand = ./stockfish
|
|||||||
Book = false
|
Book = false
|
||||||
BookFile = book.bin
|
BookFile = book.bin
|
||||||
|
|
||||||
Log = true
|
Log = false
|
||||||
LogFile = stockfish.log
|
LogFile = stockfish.log
|
||||||
|
|
||||||
Resign = true
|
Resign = true
|
||||||
@@ -19,28 +19,18 @@ Hash = 128
|
|||||||
Threads = 1
|
Threads = 1
|
||||||
OwnBook = false
|
OwnBook = false
|
||||||
Book File = book.bin
|
Book File = book.bin
|
||||||
|
Best Book Move = false
|
||||||
Use Search Log = false
|
Use Search Log = false
|
||||||
|
Search Log Filename = SearchLog.txt
|
||||||
Mobility (Middle Game) = 100
|
Mobility (Middle Game) = 100
|
||||||
Mobility (Endgame) = 100
|
Mobility (Endgame) = 100
|
||||||
Pawn Structure (Middle Game) = 100
|
Pawn Structure (Middle Game) = 100
|
||||||
Pawn Structure (Endgame) = 100
|
Pawn Structure (Endgame) = 100
|
||||||
Passed Pawns (Middle Game) = 100
|
Passed Pawns (Middle Game) = 100
|
||||||
Passed Pawns (Endgame) = 100
|
Passed Pawns (Endgame) = 100
|
||||||
|
Space = 100
|
||||||
Aggressiveness = 100
|
Aggressiveness = 100
|
||||||
Cowardice = 100
|
Cowardice = 100
|
||||||
King Safety Curve = Quadratic
|
|
||||||
Quadratic = Linear
|
|
||||||
King Safety Coefficient = 40
|
|
||||||
King Safety X Intercept = 0
|
|
||||||
King Safety Max Slope = 30
|
|
||||||
King Safety Max Value = 500
|
|
||||||
Queen Contact Check Bonus = 3
|
|
||||||
Queen Check Bonus = 2
|
|
||||||
Rook Check Bonus = 1
|
|
||||||
Bishop Check Bonus = 1
|
|
||||||
Knight Check Bonus = 1
|
|
||||||
Discovered Check Bonus = 3
|
|
||||||
Mate Threat Bonus = 3
|
|
||||||
Check Extension (PV nodes) = 2
|
Check Extension (PV nodes) = 2
|
||||||
Check Extension (non-PV nodes) = 1
|
Check Extension (non-PV nodes) = 1
|
||||||
Single Reply Extension (PV nodes) = 2
|
Single Reply Extension (PV nodes) = 2
|
||||||
@@ -53,11 +43,6 @@ Passed Pawn Extension (PV nodes) = 1
|
|||||||
Passed Pawn Extension (non-PV nodes) = 0
|
Passed Pawn Extension (non-PV nodes) = 0
|
||||||
Pawn Endgame Extension (PV nodes) = 2
|
Pawn Endgame Extension (PV nodes) = 2
|
||||||
Pawn Endgame Extension (non-PV nodes) = 2
|
Pawn Endgame Extension (non-PV nodes) = 2
|
||||||
Full Depth Moves (PV nodes) = 14
|
|
||||||
Full Depth Moves (non-PV nodes) = 3
|
|
||||||
Threat Depth = 5
|
|
||||||
Futility Pruning (Main Search) = true
|
|
||||||
Futility Pruning (Quiescence Search) = true
|
|
||||||
Randomness = 0
|
Randomness = 0
|
||||||
Minimum Split Depth = 4
|
Minimum Split Depth = 4
|
||||||
Maximum Number of Threads per Split Point = 5
|
Maximum Number of Threads per Split Point = 5
|
||||||
|
|||||||
+449
-205
@@ -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-2007 Tord Romstad
|
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
# Copyright (C) 2008 Marco Costalba
|
# Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
#
|
||||||
# This file is part of Stockfish.
|
# This file is part of Stockfish.
|
||||||
#
|
#
|
||||||
# Stockfish is free software: you can redistribute it and/or modify
|
# Stockfish is free software: you can redistribute it and/or modify
|
||||||
@@ -18,246 +18,490 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
### Executable name. Do not change
|
### ==========================================================================
|
||||||
|
### Section 1. General Configuration
|
||||||
|
### ==========================================================================
|
||||||
|
|
||||||
|
### Executable name
|
||||||
EXE = stockfish
|
EXE = stockfish
|
||||||
|
|
||||||
|
### Installation dir definitions
|
||||||
|
PREFIX = /usr/local
|
||||||
|
BINDIR = $(PREFIX)/bin
|
||||||
|
|
||||||
### ==========================================================================
|
### Built-in benchmark for pgo-builds
|
||||||
### Compiler speed switches for both GCC and ICC. These settings are generally
|
|
||||||
### fast on a broad range of systems, but may be changed experimentally
|
|
||||||
### ==========================================================================
|
|
||||||
GCCFLAGS = -O3 -msse
|
|
||||||
ICCFLAGS = -fast -msse
|
|
||||||
ICCFLAGS-OSX = -fast -mdynamic-no-pic
|
|
||||||
|
|
||||||
|
|
||||||
### ==========================================================================
|
|
||||||
### Enable/disable debugging, disabled by default
|
|
||||||
### ==========================================================================
|
|
||||||
GCCFLAGS += -DNDEBUG
|
|
||||||
ICCFLAGS += -DNDEBUG
|
|
||||||
ICCFLAGS-OSX += -DNDEBUG
|
|
||||||
|
|
||||||
|
|
||||||
### ==========================================================================
|
|
||||||
### Run built-in benchmark for pgo-builds with: 32MB hash 1 thread 10 depth
|
|
||||||
### These settings are generally fast, but may be changed experimentally
|
|
||||||
### ==========================================================================
|
|
||||||
PGOBENCH = ./$(EXE) bench 32 1 10 default depth
|
PGOBENCH = ./$(EXE) bench 32 1 10 default depth
|
||||||
|
|
||||||
|
### Object files
|
||||||
### General compiler settings. Do not change
|
|
||||||
GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing
|
|
||||||
ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -wd383,869,981,10187,10188,11505,11503
|
|
||||||
ICCFLAGS-OSX += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -wd383,869,981,10187,10188,11505,11503
|
|
||||||
|
|
||||||
|
|
||||||
### General linker settings. Do not change
|
|
||||||
LDFLAGS = -lpthread
|
|
||||||
|
|
||||||
|
|
||||||
### Object files. Do not change
|
|
||||||
OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
|
OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
|
||||||
misc.o move.o movegen.o history.o movepick.o search.o piece.o \
|
misc.o move.o movegen.o history.o movepick.o search.o piece.o \
|
||||||
position.o direction.o tt.o value.o uci.o ucioption.o \
|
position.o direction.o tt.o value.o uci.o ucioption.o \
|
||||||
mersenne.o book.o bitbase.o san.o benchmark.o
|
mersenne.o book.o bitbase.o san.o benchmark.o
|
||||||
|
|
||||||
|
|
||||||
### General rules. Do not change
|
### ==========================================================================
|
||||||
|
### Section 2. High-level Configuration
|
||||||
|
### ==========================================================================
|
||||||
|
#
|
||||||
|
# flag --- Comp switch --- Description
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# debug = no/yes --- -DNDEBUG --- Enable/Disable debug mode
|
||||||
|
# optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
|
||||||
|
# arch = (name) --- (-arch) --- Target architecture
|
||||||
|
# os = (name) --- --- Target operating system
|
||||||
|
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
||||||
|
# bigendian = no/yes --- -DBIGENDIAN --- big/little-endian byte order
|
||||||
|
# prefetch = no/yes --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
|
||||||
|
# bsfq = no/yes --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction
|
||||||
|
# --- (Works only with GCC and ICC 64-bit)
|
||||||
|
# popcnt = no/yes --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
|
||||||
|
#
|
||||||
|
# Note that Makefile is space sensitive, so when adding new architectures
|
||||||
|
# or modifying existing flags, you have to make sure there are no extra spaces
|
||||||
|
# at the end of the line for flag values.
|
||||||
|
|
||||||
|
### 2.1. General
|
||||||
|
debug = no
|
||||||
|
optimize = yes
|
||||||
|
|
||||||
|
### 2.2 Architecture specific
|
||||||
|
|
||||||
|
# General-section
|
||||||
|
ifeq ($(ARCH),general-64)
|
||||||
|
arch = any
|
||||||
|
os = any
|
||||||
|
bits = 64
|
||||||
|
bigendian = no
|
||||||
|
prefetch = no
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),general-32)
|
||||||
|
arch = any
|
||||||
|
os = any
|
||||||
|
bits = 32
|
||||||
|
bigendian = no
|
||||||
|
prefetch = no
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),bigendian-64)
|
||||||
|
arch = any
|
||||||
|
os = any
|
||||||
|
bits = 64
|
||||||
|
bigendian = yes
|
||||||
|
prefetch = no
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),bigendian-32)
|
||||||
|
arch = any
|
||||||
|
os = any
|
||||||
|
bits = 32
|
||||||
|
bigendian = yes
|
||||||
|
prefetch = no
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
# x86-section
|
||||||
|
ifeq ($(ARCH),x86-64)
|
||||||
|
arch = x86_64
|
||||||
|
os = any
|
||||||
|
bits = 64
|
||||||
|
bigendian = no
|
||||||
|
prefetch = yes
|
||||||
|
bsfq = yes
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),x86-64-modern)
|
||||||
|
arch = x86_64
|
||||||
|
os = any
|
||||||
|
bits = 64
|
||||||
|
bigendian = no
|
||||||
|
prefetch = yes
|
||||||
|
bsfq = yes
|
||||||
|
popcnt = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),x86-32)
|
||||||
|
arch = i386
|
||||||
|
os = any
|
||||||
|
bits = 32
|
||||||
|
bigendian = no
|
||||||
|
prefetch = yes
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),x86-32-old)
|
||||||
|
arch = i386
|
||||||
|
os = any
|
||||||
|
bits = 32
|
||||||
|
bigendian = no
|
||||||
|
prefetch = no
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
# osx-section
|
||||||
|
ifeq ($(ARCH),osx-ppc-64)
|
||||||
|
arch = ppc64
|
||||||
|
os = osx
|
||||||
|
bits = 64
|
||||||
|
bigendian = yes
|
||||||
|
prefetch = no
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),osx-ppc-32)
|
||||||
|
arch = ppc
|
||||||
|
os = osx
|
||||||
|
bits = 32
|
||||||
|
bigendian = yes
|
||||||
|
prefetch = no
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),osx-x86-64)
|
||||||
|
arch = x86_64
|
||||||
|
os = osx
|
||||||
|
bits = 64
|
||||||
|
bigendian = no
|
||||||
|
prefetch = yes
|
||||||
|
bsfq = yes
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),osx-x86-32)
|
||||||
|
arch = i386
|
||||||
|
os = osx
|
||||||
|
bits = 32
|
||||||
|
bigendian = no
|
||||||
|
prefetch = yes
|
||||||
|
bsfq = no
|
||||||
|
popcnt = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
### ==========================================================================
|
||||||
|
### Section 3. Low-level configuration
|
||||||
|
### ==========================================================================
|
||||||
|
|
||||||
|
### 3.1 Selecting compiler (default = gcc)
|
||||||
|
ifeq ($(COMP),)
|
||||||
|
COMP=gcc
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(COMP),gcc)
|
||||||
|
comp=gcc
|
||||||
|
CXX=g++
|
||||||
|
profile_prepare = gcc-profile-prepare
|
||||||
|
profile_make = gcc-profile-make
|
||||||
|
profile_use = gcc-profile-use
|
||||||
|
profile_clean = gcc-profile-clean
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(COMP),icc)
|
||||||
|
comp=icc
|
||||||
|
CXX=icpc
|
||||||
|
profile_prepare = icc-profile-prepare
|
||||||
|
profile_make = icc-profile-make
|
||||||
|
profile_use = icc-profile-use
|
||||||
|
profile_clean = icc-profile-clean
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.2 General compiler settings
|
||||||
|
CXXFLAGS += -g -Wall -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
|
||||||
|
|
||||||
|
ifeq ($(comp),icc)
|
||||||
|
CXXFLAGS += -wd383,869,981,10187,10188,11505,11503
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(os),osx)
|
||||||
|
CXXFLAGS += -arch $(arch)
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.3 General linker settings
|
||||||
|
LDFLAGS += -lpthread $(EXTRALDFLAGS)
|
||||||
|
|
||||||
|
ifeq ($(os),osx)
|
||||||
|
LDFLAGS += -arch $(arch)
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.4 Debugging
|
||||||
|
ifeq ($(debug),no)
|
||||||
|
CXXFLAGS += -DNDEBUG
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.5 Optimization
|
||||||
|
ifeq ($(optimize),yes)
|
||||||
|
|
||||||
|
ifeq ($(comp),gcc)
|
||||||
|
CXXFLAGS += -O3
|
||||||
|
|
||||||
|
ifeq ($(os),osx)
|
||||||
|
ifeq ($(arch),i386)
|
||||||
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
|
endif
|
||||||
|
ifeq ($(arch),x86_64)
|
||||||
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(comp),icc)
|
||||||
|
CXXFLAGS += -fast
|
||||||
|
|
||||||
|
ifeq ($(os),osx)
|
||||||
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.6. Bits
|
||||||
|
ifeq ($(bits),64)
|
||||||
|
CXXFLAGS += -DIS_64BIT
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.7 Endianess
|
||||||
|
ifeq ($(bigendian),yes)
|
||||||
|
CXXFLAGS += -DBIGENDIAN
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.8 prefetch
|
||||||
|
ifeq ($(prefetch),yes)
|
||||||
|
CXXFLAGS += -msse
|
||||||
|
DEPENDFLAGS += -msse
|
||||||
|
else
|
||||||
|
CXXFLAGS += -DNO_PREFETCH
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.9 bsfq
|
||||||
|
ifeq ($(bsfq),yes)
|
||||||
|
CXXFLAGS += -DUSE_BSFQ
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.10 popcnt
|
||||||
|
ifeq ($(popcnt),yes)
|
||||||
|
CXXFLAGS += -DUSE_POPCNT
|
||||||
|
endif
|
||||||
|
|
||||||
|
### ==========================================================================
|
||||||
|
### Section 4. Public targets
|
||||||
|
### ==========================================================================
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$(MAKE) gcc
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) build
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Makefile options:"
|
@echo "To compile stockfish, type: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make > Default: Compiler = g++"
|
@echo "make target ARCH=arch [COMP=comp]"
|
||||||
@echo "make icc > Compiler = icpc"
|
@echo ""
|
||||||
@echo "make icc-profile > Compiler = icpc + automatic pgo-build"
|
@echo "Supported targets:"
|
||||||
@echo "make osx-ppc32 > PPC-Mac OS X 32 bit. Compiler = g++"
|
@echo ""
|
||||||
@echo "make osx-ppc64 > PPC-Mac OS X 64 bit. Compiler = g++"
|
@echo "build > Build unoptimized version"
|
||||||
@echo "make osx-x86 > x86-Mac OS X 32 bit. Compiler = g++"
|
@echo "profile-build > Build PGO-optimized version"
|
||||||
@echo "make osx-x86_64 > x86-Mac OS X 64 bit. Compiler = g++"
|
@echo "popcnt-profile-build > Build PGO-optimized version with optional popcnt-support"
|
||||||
@echo "make osx-icc32 > x86-Mac OS X 32 bit. Compiler = icpc"
|
@echo "strip > Strip executable"
|
||||||
@echo "make osx-icc64 > x86-Mac OS X 64 bit. Compiler = icpc"
|
@echo "install > Install executable"
|
||||||
@echo "make osx-icc32-profile > OSX 32 bit. Compiler = icpc + automatic pgo-build"
|
@echo "clean > Clean up"
|
||||||
@echo "make osx-icc64-profile > OSX 64 bit. Compiler = icpc + automatic pgo-build"
|
@echo "testrun > Make sample run"
|
||||||
@echo "make strip > Strip executable"
|
@echo ""
|
||||||
@echo "make clean > Clean up"
|
@echo "Supported archs:"
|
||||||
|
@echo ""
|
||||||
|
@echo "x86-64 > x86 64-bit"
|
||||||
|
@echo "x86-64-modern > x86 64-bit with runtime support for popcnt-instruction"
|
||||||
|
@echo "x86-32 > x86 32-bit excluding very old hardware without SSE-support"
|
||||||
|
@echo "x86-32-old > x86 32-bit including also very old hardware"
|
||||||
|
@echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
|
||||||
|
@echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
|
||||||
|
@echo "osx-x86-64 > x86-Mac OS X 64 bit"
|
||||||
|
@echo "osx-x86-32 > x86-Mac OS X 32 bit"
|
||||||
|
@echo "general-64 > unspecified 64-bit"
|
||||||
|
@echo "general-32 > unspecified 32-bit"
|
||||||
|
@echo "bigendian-64 > unspecified 64-bit with bigendian byte order"
|
||||||
|
@echo "bigendian-32 > unspecified 32-bit with bigendian byte order"
|
||||||
|
@echo ""
|
||||||
|
@echo "Supported comps:"
|
||||||
|
@echo ""
|
||||||
|
@echo "gcc > Gnu compiler (default)"
|
||||||
|
@echo "icc > Intel compiler"
|
||||||
|
@echo ""
|
||||||
|
@echo "Non-standard targets:"
|
||||||
|
@echo ""
|
||||||
|
@echo "make hpux > Compile for HP-UX. Compiler = aCC"
|
||||||
|
@echo ""
|
||||||
|
@echo "Examples. If you don't know what to do, you likely want to run: "
|
||||||
|
@echo ""
|
||||||
|
@echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
|
||||||
|
@echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
all: $(EXE) .depend
|
build:
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
||||||
|
|
||||||
clean:
|
profile-build:
|
||||||
$(RM) *.o .depend *~ $(EXE)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
||||||
|
@echo ""
|
||||||
|
@echo "Step 0/4. Preparing for profile build."
|
||||||
### Possible targets. You may add your own ones here
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
|
||||||
gcc:
|
@echo ""
|
||||||
$(MAKE) \
|
@echo "Step 1/4. Building executable for benchmark ..."
|
||||||
CXX='g++' \
|
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
|
||||||
all
|
|
||||||
|
|
||||||
icc:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS)" \
|
|
||||||
all
|
|
||||||
|
|
||||||
icc-profile-make:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS)" \
|
|
||||||
CXXFLAGS+='-prof-gen=srcpos -prof_dir ./profdir' \
|
|
||||||
all
|
|
||||||
|
|
||||||
icc-profile-use:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS)" \
|
|
||||||
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
|
||||||
all
|
|
||||||
|
|
||||||
icc-profile:
|
|
||||||
@rm -rf profdir
|
|
||||||
@mkdir profdir
|
|
||||||
@touch *.cpp *.h
|
@touch *.cpp *.h
|
||||||
$(MAKE) icc-profile-make
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Running benchmark for pgo-build ..."
|
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
||||||
@$(PGOBENCH) > /dev/null
|
@$(PGOBENCH) > /dev/null
|
||||||
@echo "Benchmark finished. Build final executable now ..."
|
|
||||||
@echo ""
|
@echo ""
|
||||||
@touch *.cpp *.h
|
@echo "Step 3/4. Building final executable ..."
|
||||||
$(MAKE) icc-profile-use
|
@touch *.cpp
|
||||||
@rm -rf profdir bench.txt
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
||||||
|
|
||||||
osx-ppc32:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='g++' \
|
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
|
||||||
CXXFLAGS+='-arch ppc' \
|
|
||||||
LDFLAGS+='-arch ppc' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-ppc64:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='g++' \
|
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
|
||||||
CXXFLAGS+='-arch ppc64' \
|
|
||||||
LDFLAGS+='-arch ppc64' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-x86:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='g++' \
|
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
|
||||||
CXXFLAGS+='-arch i386' \
|
|
||||||
LDFLAGS+='-arch i386' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-x86_64:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='g++' \
|
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
|
||||||
CXXFLAGS+='-arch x86_64' \
|
|
||||||
LDFLAGS+='-arch x86_64' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-icc32:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
|
||||||
CXXFLAGS+='-arch i386' \
|
|
||||||
LDFLAGS+='-arch i386' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-icc64:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
|
||||||
CXXFLAGS+='-arch x86_64' \
|
|
||||||
LDFLAGS+='-arch x86_64' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-icc32-profile-make:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
|
||||||
CXXFLAGS+='-arch i386' \
|
|
||||||
CXXFLAGS+='-prof_gen -prof_dir ./profdir' \
|
|
||||||
LDFLAGS+='-arch i386' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-icc32-profile-use:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
|
||||||
CXXFLAGS+='-arch i386' \
|
|
||||||
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
|
||||||
LDFLAGS+='-arch i386' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-icc32-profile:
|
|
||||||
@rm -rf profdir
|
|
||||||
@mkdir profdir
|
|
||||||
@touch *.cpp *.h
|
|
||||||
$(MAKE) osx-icc32-profile-make
|
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Running benchmark for pgo-build ..."
|
@echo "Step 4/4. Deleting profile data ..."
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
|
||||||
|
|
||||||
|
popcnt-profile-build:
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
||||||
|
@echo ""
|
||||||
|
@echo "Step 0/6. Preparing for profile build."
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
|
||||||
|
@echo ""
|
||||||
|
@echo "Step 1/6. Building executable for benchmark (popcnt disabled)..."
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(MAKE) ARCH=x86-64 COMP=$(COMP) $(profile_make)
|
||||||
|
@echo ""
|
||||||
|
@echo "Step 2/6. Running benchmark for pgo-build (popcnt disabled)..."
|
||||||
@$(PGOBENCH) > /dev/null
|
@$(PGOBENCH) > /dev/null
|
||||||
@echo "Benchmark finished. Build final executable now ..."
|
|
||||||
@echo ""
|
@echo ""
|
||||||
|
@echo "Step 3/6. Building executable for benchmark (popcnt enabled)..."
|
||||||
@touch *.cpp *.h
|
@touch *.cpp *.h
|
||||||
$(MAKE) osx-icc32-profile-use
|
$(MAKE) ARCH=x86-64-modern COMP=$(COMP) $(profile_make)
|
||||||
@rm -rf profdir bench.txt
|
|
||||||
|
|
||||||
osx-icc64-profile-make:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
|
||||||
CXXFLAGS+='-arch x86_64' \
|
|
||||||
CXXFLAGS+='-prof_gen -prof_dir ./profdir' \
|
|
||||||
LDFLAGS+='-arch x86_64' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-icc64-profile-use:
|
|
||||||
$(MAKE) \
|
|
||||||
CXX='icpc' \
|
|
||||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
|
||||||
CXXFLAGS+='-arch x86_64' \
|
|
||||||
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
|
||||||
LDFLAGS+='-arch x86_64' \
|
|
||||||
all
|
|
||||||
|
|
||||||
osx-icc64-profile:
|
|
||||||
@rm -rf profdir
|
|
||||||
@mkdir profdir
|
|
||||||
@touch *.cpp *.h
|
|
||||||
$(MAKE) osx-icc64-profile-make
|
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Running benchmark for pgo-build ..."
|
@echo "Step 4/6. Running benchmark for pgo-build (popcnt enabled)..."
|
||||||
@$(PGOBENCH) > /dev/null
|
@$(PGOBENCH) > /dev/null
|
||||||
@echo "Benchmark finished. Build final executable now ..."
|
|
||||||
@echo ""
|
@echo ""
|
||||||
|
@echo "Step 5/6. Building final executable ..."
|
||||||
@touch *.cpp *.h
|
@touch *.cpp *.h
|
||||||
$(MAKE) osx-icc64-profile-use
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
||||||
@rm -rf profdir bench.txt
|
@echo ""
|
||||||
|
@echo "Step 6/6. Deleting profile data ..."
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
|
||||||
|
@echo ""
|
||||||
|
|
||||||
strip:
|
strip:
|
||||||
strip $(EXE)
|
strip $(EXE)
|
||||||
|
|
||||||
|
install:
|
||||||
|
-mkdir -p -m 755 $(BINDIR)
|
||||||
|
-cp $(EXE) $(BINDIR)
|
||||||
|
-strip $(BINDIR)/$(EXE)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(EXE) *.o .depend *~ core bench.txt
|
||||||
|
|
||||||
|
testrun:
|
||||||
|
@$(PGOBENCH)
|
||||||
|
|
||||||
|
### ==========================================================================
|
||||||
|
### Section 5. Private targets
|
||||||
|
### ==========================================================================
|
||||||
|
|
||||||
|
all: $(EXE) .depend
|
||||||
|
|
||||||
|
config-sanity:
|
||||||
|
@echo ""
|
||||||
|
@echo "Config:"
|
||||||
|
@echo "debug: '$(debug)'"
|
||||||
|
@echo "optimize: '$(optimize)'"
|
||||||
|
@echo "arch: '$(arch)'"
|
||||||
|
@echo "os: '$(os)'"
|
||||||
|
@echo "bits: '$(bits)'"
|
||||||
|
@echo "bigendian: '$(bigendian)'"
|
||||||
|
@echo "prefetch: '$(prefetch)'"
|
||||||
|
@echo "bsfq: '$(bsfq)'"
|
||||||
|
@echo "popcnt: '$(popcnt)'"
|
||||||
|
@echo ""
|
||||||
|
@echo "Flags:"
|
||||||
|
@echo "CXX: $(CXX)"
|
||||||
|
@echo "CXXFLAGS: $(CXXFLAGS)"
|
||||||
|
@echo "LDFLAGS: $(LDFLAGS)"
|
||||||
|
@echo ""
|
||||||
|
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
||||||
|
@echo ""
|
||||||
|
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
||||||
|
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
||||||
|
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
||||||
|
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
|
||||||
|
@test "$(os)" = "any" || test "$(os)" = "osx"
|
||||||
|
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
||||||
|
@test "$(bigendian)" = "yes" || test "$(bigendian)" = "no"
|
||||||
|
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
||||||
|
@test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
|
||||||
|
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
||||||
|
@test "$(comp)" = "gcc" || test "$(comp)" = "icc"
|
||||||
|
|
||||||
### Compilation. Do not change
|
|
||||||
$(EXE): $(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
|
gcc-profile-prepare:
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
|
||||||
|
|
||||||
|
gcc-profile-make:
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
|
EXTRACXXFLAGS='-fprofile-generate' \
|
||||||
|
EXTRALDFLAGS='-lgcov' \
|
||||||
|
all
|
||||||
|
|
||||||
|
gcc-profile-use:
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
|
EXTRACXXFLAGS='-fprofile-use' \
|
||||||
|
all
|
||||||
|
|
||||||
|
gcc-profile-clean:
|
||||||
|
@rm -rf *.gcda *.gcno bench.txt
|
||||||
|
|
||||||
|
icc-profile-prepare:
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
|
||||||
|
@mkdir profdir
|
||||||
|
|
||||||
|
icc-profile-make:
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
|
EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
|
||||||
|
all
|
||||||
|
|
||||||
|
icc-profile-use:
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
|
EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
|
||||||
|
all
|
||||||
|
|
||||||
|
icc-profile-clean:
|
||||||
|
@rm -rf profdir bench.txt
|
||||||
|
|
||||||
### Dependencies. Do not change
|
|
||||||
.depend:
|
.depend:
|
||||||
$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@
|
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
||||||
|
|
||||||
|
-include .depend
|
||||||
|
|
||||||
|
|
||||||
|
### ==========================================================================
|
||||||
|
### Section 6. Non-standard targets
|
||||||
|
### ==========================================================================
|
||||||
|
|
||||||
|
hpux:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG' \
|
||||||
|
CXXFLAGS="" \
|
||||||
|
LDFLAGS="" \
|
||||||
|
all
|
||||||
|
|
||||||
include .depend
|
|
||||||
|
|||||||
+11
-8
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -49,6 +49,7 @@ Application::Application() {
|
|||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
init_eval(1);
|
init_eval(1);
|
||||||
init_bitbases();
|
init_bitbases();
|
||||||
|
init_search();
|
||||||
init_threads();
|
init_threads();
|
||||||
|
|
||||||
// Make random number generation less deterministic, for book moves
|
// Make random number generation less deterministic, for book moves
|
||||||
@@ -56,12 +57,6 @@ Application::Application() {
|
|||||||
genrand_int32();
|
genrand_int32();
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
|
||||||
|
|
||||||
stop_threads();
|
|
||||||
quit_eval();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::initialize() {
|
void Application::initialize() {
|
||||||
|
|
||||||
// A static Application object is allocated
|
// A static Application object is allocated
|
||||||
@@ -69,7 +64,15 @@ void Application::initialize() {
|
|||||||
static Application singleton;
|
static Application singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::free_resources() {
|
||||||
|
|
||||||
|
// Warning, following functions reference global objects that
|
||||||
|
// must be still alive when free_resources() is called.
|
||||||
|
exit_threads();
|
||||||
|
quit_eval();
|
||||||
|
}
|
||||||
|
|
||||||
void Application::exit_with_failure() {
|
void Application::exit_with_failure() {
|
||||||
|
|
||||||
exit(EXIT_FAILURE); // d'tor will be called automatically
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,10 +29,10 @@ class Application {
|
|||||||
|
|
||||||
Application();
|
Application();
|
||||||
Application(const Application&);
|
Application(const Application&);
|
||||||
~Application();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void initialize();
|
static void initialize();
|
||||||
|
static void free_resources();
|
||||||
static void exit_with_failure();
|
static void exit_with_failure();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+15
-8
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -38,8 +38,8 @@ using namespace std;
|
|||||||
|
|
||||||
const string BenchmarkPositions[] = {
|
const string BenchmarkPositions[] = {
|
||||||
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
||||||
"r4rk1/1b2qppp/p1n1p3/1p6/1b1PN3/3BRN2/PP3PPP/R2Q2K1 b - - 7 16",
|
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -",
|
||||||
"4r1k1/ppq3pp/3b4/2pP4/2Q1p3/4B1P1/PP5P/R5K1 b - - 0 20",
|
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -",
|
||||||
"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",
|
||||||
"r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14",
|
"r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14",
|
||||||
@@ -84,9 +84,9 @@ void benchmark(const string& commandLine) {
|
|||||||
}
|
}
|
||||||
csStr >> threads;
|
csStr >> threads;
|
||||||
csVal >> val;
|
csVal >> val;
|
||||||
if (val < 1 || val > THREAD_MAX)
|
if (val < 1 || val > MAX_THREADS)
|
||||||
{
|
{
|
||||||
cerr << "The number of threads must be between 1 and " << THREAD_MAX << endl;
|
cerr << "The number of threads must be between 1 and " << MAX_THREADS << endl;
|
||||||
Application::exit_with_failure();
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
set_option_value("Hash", ttSize);
|
set_option_value("Hash", ttSize);
|
||||||
@@ -104,7 +104,7 @@ void benchmark(const string& commandLine) {
|
|||||||
|
|
||||||
if (limitType == "time")
|
if (limitType == "time")
|
||||||
secsPerPos = val * 1000;
|
secsPerPos = val * 1000;
|
||||||
else if (limitType == "depth")
|
else if (limitType == "depth" || limitType == "perft")
|
||||||
maxDepth = val;
|
maxDepth = val;
|
||||||
else
|
else
|
||||||
maxNodes = val;
|
maxNodes = val;
|
||||||
@@ -151,12 +151,19 @@ void benchmark(const string& commandLine) {
|
|||||||
{
|
{
|
||||||
Move moves[1] = {MOVE_NONE};
|
Move moves[1] = {MOVE_NONE};
|
||||||
int dummy[2] = {0, 0};
|
int dummy[2] = {0, 0};
|
||||||
Position pos(*it);
|
Position pos(*it, 0);
|
||||||
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
|
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
|
||||||
if (!think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
|
if (limitType == "perft")
|
||||||
|
{
|
||||||
|
int64_t perftCnt = perft(pos, maxDepth * OnePly);
|
||||||
|
cerr << "\nPerft " << maxDepth << " result (nodes searched): " << perftCnt << endl << endl;
|
||||||
|
totalNodes += perftCnt;
|
||||||
|
} else {
|
||||||
|
if (!think(pos, false, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
|
||||||
break;
|
break;
|
||||||
totalNodes += nodes_searched();
|
totalNodes += nodes_searched();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cnt = get_system_time() - startTime;
|
cnt = get_system_time() - startTime;
|
||||||
cerr << "==============================="
|
cerr << "==============================="
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+120
-89
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -226,8 +226,9 @@ Bitboard StepAttackBB[16][64];
|
|||||||
Bitboard RayBB[64][8];
|
Bitboard RayBB[64][8];
|
||||||
Bitboard BetweenBB[64][64];
|
Bitboard BetweenBB[64][64];
|
||||||
|
|
||||||
|
Bitboard SquaresInFrontMask[2][64];
|
||||||
Bitboard PassedPawnMask[2][64];
|
Bitboard PassedPawnMask[2][64];
|
||||||
Bitboard OutpostMask[2][64];
|
Bitboard AttackSpanMask[2][64];
|
||||||
|
|
||||||
Bitboard BishopPseudoAttacks[64];
|
Bitboard BishopPseudoAttacks[64];
|
||||||
Bitboard RookPseudoAttacks[64];
|
Bitboard RookPseudoAttacks[64];
|
||||||
@@ -246,14 +247,12 @@ namespace {
|
|||||||
void init_ray_bitboards();
|
void init_ray_bitboards();
|
||||||
void init_attacks();
|
void init_attacks();
|
||||||
void init_between_bitboards();
|
void init_between_bitboards();
|
||||||
|
void init_pseudo_attacks();
|
||||||
|
Bitboard index_to_bitboard(int index, Bitboard mask);
|
||||||
Bitboard sliding_attacks(int sq, Bitboard block, int dirs, int deltas[][2],
|
Bitboard sliding_attacks(int sq, Bitboard block, int dirs, int deltas[][2],
|
||||||
int fmin, int fmax, int rmin, int rmax);
|
int fmin, int fmax, int rmin, int rmax);
|
||||||
Bitboard index_to_bitboard(int index, Bitboard mask);
|
void init_sliding_attacks(Bitboard attacks[], int attackIndex[], Bitboard mask[],
|
||||||
void init_sliding_attacks(Bitboard attacks[],
|
const int shift[], const Bitboard mult[], int deltas[][2]);
|
||||||
int attackIndex[], Bitboard mask[],
|
|
||||||
const int shift[2], const Bitboard mult[],
|
|
||||||
int deltas[][2]);
|
|
||||||
void init_pseudo_attacks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -265,10 +264,13 @@ namespace {
|
|||||||
/// standard output. This is sometimes useful for debugging.
|
/// standard output. This is sometimes useful for debugging.
|
||||||
|
|
||||||
void print_bitboard(Bitboard b) {
|
void print_bitboard(Bitboard b) {
|
||||||
for(Rank r = RANK_8; r >= RANK_1; r--) {
|
|
||||||
|
for (Rank r = RANK_8; r >= RANK_1; r--)
|
||||||
|
{
|
||||||
std::cout << "+---+---+---+---+---+---+---+---+" << std::endl;
|
std::cout << "+---+---+---+---+---+---+---+---+" << std::endl;
|
||||||
for(File f = FILE_A; f <= FILE_H; f++)
|
for (File f = FILE_A; f <= FILE_H; f++)
|
||||||
std::cout << "| " << (bit_is_set(b, make_square(f, r))? 'X' : ' ') << ' ';
|
std::cout << "| " << (bit_is_set(b, make_square(f, r))? 'X' : ' ') << ' ';
|
||||||
|
|
||||||
std::cout << "|" << std::endl;
|
std::cout << "|" << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << "+---+---+---+---+---+---+---+---+" << std::endl;
|
std::cout << "+---+---+---+---+---+---+---+---+" << std::endl;
|
||||||
@@ -279,8 +281,10 @@ void print_bitboard(Bitboard b) {
|
|||||||
/// program initialization.
|
/// program initialization.
|
||||||
|
|
||||||
void init_bitboards() {
|
void init_bitboards() {
|
||||||
|
|
||||||
int rookDeltas[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
|
int rookDeltas[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
|
||||||
int bishopDeltas[4][2] = {{1,1},{-1,1},{1,-1},{-1,-1}};
|
int bishopDeltas[4][2] = {{1,1},{-1,1},{1,-1},{-1,-1}};
|
||||||
|
|
||||||
init_masks();
|
init_masks();
|
||||||
init_ray_bitboards();
|
init_ray_bitboards();
|
||||||
init_attacks();
|
init_attacks();
|
||||||
@@ -297,8 +301,8 @@ void init_bitboards() {
|
|||||||
|
|
||||||
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
||||||
|
|
||||||
CACHE_LINE_ALIGNMENT
|
static CACHE_LINE_ALIGNMENT
|
||||||
static const int BitTable[64] = {
|
const int BitTable[64] = {
|
||||||
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15,
|
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15,
|
||||||
46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39,
|
46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39,
|
||||||
16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43,
|
16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43,
|
||||||
@@ -317,8 +321,8 @@ Square pop_1st_bit(Bitboard* b) {
|
|||||||
|
|
||||||
#elif !defined(USE_BSFQ)
|
#elif !defined(USE_BSFQ)
|
||||||
|
|
||||||
CACHE_LINE_ALIGNMENT
|
static CACHE_LINE_ALIGNMENT
|
||||||
static const int BitTable[64] = {
|
const int BitTable[64] = {
|
||||||
63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
|
63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
|
||||||
51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52,
|
51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52,
|
||||||
26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28,
|
26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28,
|
||||||
@@ -326,6 +330,7 @@ static const int BitTable[64] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Square first_1(Bitboard b) {
|
Square first_1(Bitboard b) {
|
||||||
|
|
||||||
b ^= (b - 1);
|
b ^= (b - 1);
|
||||||
uint32_t fold = int(b) ^ int(b >> 32);
|
uint32_t fold = int(b) ^ int(b >> 32);
|
||||||
return Square(BitTable[(fold * 0x783a9b23) >> 26]);
|
return Square(BitTable[(fold * 0x783a9b23) >> 26]);
|
||||||
@@ -336,30 +341,39 @@ union b_union {
|
|||||||
|
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
struct {
|
struct {
|
||||||
|
#if defined (BIGENDIAN)
|
||||||
|
uint32_t h;
|
||||||
|
uint32_t l;
|
||||||
|
#else
|
||||||
uint32_t l;
|
uint32_t l;
|
||||||
uint32_t h;
|
uint32_t h;
|
||||||
|
#endif
|
||||||
} dw;
|
} dw;
|
||||||
};
|
};
|
||||||
|
|
||||||
// WARNING: Needs -fno-strict-aliasing compiler option
|
|
||||||
Square pop_1st_bit(Bitboard* bb) {
|
Square pop_1st_bit(Bitboard* bb) {
|
||||||
|
|
||||||
b_union u;
|
b_union u;
|
||||||
|
Square ret;
|
||||||
|
|
||||||
u.b = *bb;
|
u.b = *bb;
|
||||||
|
|
||||||
if (u.dw.l)
|
if (u.dw.l)
|
||||||
{
|
{
|
||||||
*((uint32_t*)bb) = u.dw.l & (u.dw.l - 1);
|
ret = Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||||
return Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
u.dw.l &= (u.dw.l - 1);
|
||||||
|
*bb = u.b;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
ret = Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
||||||
*((uint32_t*)bb+1) = u.dw.h & (u.dw.h - 1); // Little endian only?
|
u.dw.h &= (u.dw.h - 1);
|
||||||
return Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
*bb = u.b;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// All functions below are used to precompute various bitboards during
|
// All functions below are used to precompute various bitboards during
|
||||||
@@ -368,39 +382,46 @@ namespace {
|
|||||||
// be necessary to touch any of them.
|
// be necessary to touch any of them.
|
||||||
|
|
||||||
void init_masks() {
|
void init_masks() {
|
||||||
|
|
||||||
SetMaskBB[SQ_NONE] = 0ULL;
|
SetMaskBB[SQ_NONE] = 0ULL;
|
||||||
ClearMaskBB[SQ_NONE] = ~SetMaskBB[SQ_NONE];
|
ClearMaskBB[SQ_NONE] = ~SetMaskBB[SQ_NONE];
|
||||||
for(Square s = SQ_A1; s <= SQ_H8; s++) {
|
|
||||||
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
|
{
|
||||||
SetMaskBB[s] = (1ULL << s);
|
SetMaskBB[s] = (1ULL << s);
|
||||||
ClearMaskBB[s] = ~SetMaskBB[s];
|
ClearMaskBB[s] = ~SetMaskBB[s];
|
||||||
}
|
}
|
||||||
for(Color c = WHITE; c <= BLACK; c++)
|
|
||||||
for(Square s = SQ_A1; s <= SQ_H8; s++) {
|
for (Color c = WHITE; c <= BLACK; c++)
|
||||||
PassedPawnMask[c][s] =
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
in_front_bb(c, s) & this_and_neighboring_files_bb(s);
|
{
|
||||||
OutpostMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
SquaresInFrontMask[c][s] = in_front_bb(c, s) & file_bb(s);
|
||||||
|
PassedPawnMask[c][s] = in_front_bb(c, s) & this_and_neighboring_files_bb(s);
|
||||||
|
AttackSpanMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Bitboard b = 0ULL; b < 256ULL; b++)
|
for (Bitboard b = 0ULL; b < 256ULL; b++)
|
||||||
BitCount8Bit[b] = (uint8_t)count_1s(b);
|
BitCount8Bit[b] = (uint8_t)count_1s(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int remove_bit_8(int i) { return ((i & ~15) >> 1) | (i & 7); }
|
||||||
|
|
||||||
void init_ray_bitboards() {
|
void init_ray_bitboards() {
|
||||||
int d[8] = {1, -1, 16, -16, 17, -17, 15, -15};
|
|
||||||
for(int i = 0; i < 128; i = (i + 9) & ~8) {
|
|
||||||
for(int j = 0; j < 8; j++) {
|
|
||||||
RayBB[(i&7)|((i>>4)<<3)][j] = EmptyBoardBB;
|
|
||||||
for(int k = i + d[j]; (k & 0x88) == 0; k += d[j])
|
|
||||||
set_bit(&(RayBB[(i&7)|((i>>4)<<3)][j]), Square((k&7)|((k>>4)<<3)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int d[8] = {1, -1, 16, -16, 17, -17, 15, -15};
|
||||||
|
|
||||||
|
for (int i = 0; i < 128; i = (i + 9) & ~8)
|
||||||
|
for (int j = 0; j < 8; j++)
|
||||||
|
{
|
||||||
|
RayBB[remove_bit_8(i)][j] = EmptyBoardBB;
|
||||||
|
for (int k = i + d[j]; (k & 0x88) == 0; k += d[j])
|
||||||
|
set_bit(&(RayBB[remove_bit_8(i)][j]), Square(remove_bit_8(k)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void init_attacks() {
|
void init_attacks() {
|
||||||
int i, j, k, l;
|
|
||||||
int step[16][8] = {
|
const int step[16][8] = {
|
||||||
{0},
|
{0},
|
||||||
{7,9,0}, {17,15,10,6,-6,-10,-15,-17}, {9,7,-7,-9,0}, {8,1,-1,-8,0},
|
{7,9,0}, {17,15,10,6,-6,-10,-15,-17}, {9,7,-7,-9,0}, {8,1,-1,-8,0},
|
||||||
{9,7,-7,-9,8,1,-1,-8}, {9,7,-7,-9,8,1,-1,-8}, {0}, {0},
|
{9,7,-7,-9,8,1,-1,-8}, {9,7,-7,-9,8,1,-1,-8}, {0}, {0},
|
||||||
@@ -408,102 +429,112 @@ namespace {
|
|||||||
{9,7,-7,-9,8,1,-1,-8}, {9,7,-7,-9,8,1,-1,-8}
|
{9,7,-7,-9,8,1,-1,-8}, {9,7,-7,-9,8,1,-1,-8}
|
||||||
};
|
};
|
||||||
|
|
||||||
for(i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++)
|
||||||
for(j = 0; j <= int(BK); j++) {
|
for (int j = 0; j <= int(BK); j++)
|
||||||
|
{
|
||||||
StepAttackBB[j][i] = EmptyBoardBB;
|
StepAttackBB[j][i] = EmptyBoardBB;
|
||||||
for(k = 0; k < 8 && step[j][k] != 0; k++) {
|
for (int k = 0; k < 8 && step[j][k] != 0; k++)
|
||||||
l = i + step[j][k];
|
{
|
||||||
if(l >= 0 && l < 64 && abs((i&7) - (l&7)) < 3)
|
int l = i + step[j][k];
|
||||||
|
if (l >= 0 && l < 64 && abs((i & 7) - (l & 7)) < 3)
|
||||||
StepAttackBB[j][i] |= (1ULL << l);
|
StepAttackBB[j][i] |= (1ULL << l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Bitboard sliding_attacks(int sq, Bitboard block, int dirs, int deltas[][2],
|
Bitboard sliding_attacks(int sq, Bitboard block, int dirs, int deltas[][2],
|
||||||
int fmin=0, int fmax=7, int rmin=0, int rmax=7) {
|
int fmin=0, int fmax=7, int rmin=0, int rmax=7) {
|
||||||
Bitboard result = 0ULL;
|
Bitboard result = 0ULL;
|
||||||
int rk = sq / 8, fl = sq % 8, r, f, i;
|
int rk = sq / 8;
|
||||||
for(i = 0; i < dirs; i++) {
|
int fl = sq % 8;
|
||||||
int dx = deltas[i][0], dy = deltas[i][1];
|
|
||||||
for(f = fl+dx, r = rk+dy;
|
for (int i = 0; i < dirs; i++)
|
||||||
(dx==0 || (f>=fmin && f<=fmax)) && (dy==0 || (r>=rmin && r<=rmax));
|
{
|
||||||
f += dx, r += dy) {
|
int dx = deltas[i][0];
|
||||||
|
int dy = deltas[i][1];
|
||||||
|
int f = fl + dx;
|
||||||
|
int r = rk + dy;
|
||||||
|
|
||||||
|
while ( (dx == 0 || (f >= fmin && f <= fmax))
|
||||||
|
&& (dy == 0 || (r >= rmin && r <= rmax)))
|
||||||
|
{
|
||||||
result |= (1ULL << (f + r*8));
|
result |= (1ULL << (f + r*8));
|
||||||
if(block & (1ULL << (f + r*8))) break;
|
if (block & (1ULL << (f + r*8)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
f += dx;
|
||||||
|
r += dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void init_between_bitboards() {
|
void init_between_bitboards() {
|
||||||
SquareDelta step[8] = {
|
|
||||||
DELTA_E, DELTA_W, DELTA_N, DELTA_S, DELTA_NE, DELTA_SW, DELTA_NW, DELTA_SE
|
const SquareDelta step[8] = { DELTA_E, DELTA_W, DELTA_N, DELTA_S,
|
||||||
};
|
DELTA_NE, DELTA_SW, DELTA_NW, DELTA_SE };
|
||||||
SignedDirection d;
|
|
||||||
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++)
|
||||||
|
{
|
||||||
BetweenBB[s1][s2] = EmptyBoardBB;
|
BetweenBB[s1][s2] = EmptyBoardBB;
|
||||||
d = signed_direction_between_squares(s1, s2);
|
SignedDirection d = signed_direction_between_squares(s1, s2);
|
||||||
if(d != SIGNED_DIR_NONE)
|
|
||||||
for(Square s3 = s1 + step[d]; s3 != s2; s3 += step[d])
|
if (d != SIGNED_DIR_NONE)
|
||||||
|
{
|
||||||
|
for (Square s3 = s1 + step[d]; s3 != s2; s3 += step[d])
|
||||||
set_bit(&(BetweenBB[s1][s2]), s3);
|
set_bit(&(BetweenBB[s1][s2]), s3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Bitboard index_to_bitboard(int index, Bitboard mask) {
|
Bitboard index_to_bitboard(int index, Bitboard mask) {
|
||||||
int i, j, bits = count_1s(mask);
|
|
||||||
Bitboard result = 0ULL;
|
Bitboard result = 0ULL;
|
||||||
for(i = 0; i < bits; i++) {
|
int bits = count_1s(mask);
|
||||||
j = pop_1st_bit(&mask);
|
|
||||||
if(index & (1 << i)) result |= (1ULL << j);
|
for (int i = 0; i < bits; i++)
|
||||||
|
{
|
||||||
|
int j = pop_1st_bit(&mask);
|
||||||
|
if (index & (1 << i))
|
||||||
|
result |= (1ULL << j);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_sliding_attacks(Bitboard attacks[], int attackIndex[], Bitboard mask[],
|
||||||
|
const int shift[], const Bitboard mult[], int deltas[][2]) {
|
||||||
|
|
||||||
void init_sliding_attacks(Bitboard attacks[],
|
for (int i = 0, index = 0; i < 64; i++)
|
||||||
int attackIndex[], Bitboard mask[],
|
{
|
||||||
const int shift[2], const Bitboard mult[],
|
|
||||||
int deltas[][2]) {
|
|
||||||
int i, j, k, index = 0;
|
|
||||||
Bitboard b;
|
|
||||||
for(i = 0; i < 64; i++) {
|
|
||||||
attackIndex[i] = index;
|
attackIndex[i] = index;
|
||||||
mask[i] = sliding_attacks(i, 0ULL, 4, deltas, 1, 6, 1, 6);
|
mask[i] = sliding_attacks(i, 0ULL, 4, deltas, 1, 6, 1, 6);
|
||||||
|
|
||||||
#if defined(IS_64BIT)
|
#if defined(IS_64BIT)
|
||||||
j = (1 << (64 - shift[i]));
|
int j = (1 << (64 - shift[i]));
|
||||||
#else
|
#else
|
||||||
j = (1 << (32 - shift[i]));
|
int j = (1 << (32 - shift[i]));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(k = 0; k < j; k++) {
|
for (int k = 0; k < j; k++)
|
||||||
|
{
|
||||||
#if defined(IS_64BIT)
|
#if defined(IS_64BIT)
|
||||||
b = index_to_bitboard(k, mask[i]);
|
Bitboard b = index_to_bitboard(k, mask[i]);
|
||||||
attacks[index + ((b * mult[i]) >> shift[i])] =
|
attacks[index + ((b * mult[i]) >> shift[i])] = sliding_attacks(i, b, 4, deltas);
|
||||||
sliding_attacks(i, b, 4, deltas);
|
|
||||||
#else
|
#else
|
||||||
b = index_to_bitboard(k, mask[i]);
|
Bitboard b = index_to_bitboard(k, mask[i]);
|
||||||
attacks[index +
|
unsigned v = int(b) * int(mult[i]) ^ int(b >> 32) * int(mult[i] >> 32);
|
||||||
(unsigned(int(b) * int(mult[i]) ^
|
attacks[index + (v >> shift[i])] = sliding_attacks(i, b, 4, deltas);
|
||||||
int(b >> 32) * int(mult[i] >> 32))
|
|
||||||
>> shift[i])] =
|
|
||||||
sliding_attacks(i, b, 4, deltas);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
index += j;
|
index += j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void init_pseudo_attacks() {
|
void init_pseudo_attacks() {
|
||||||
Square s;
|
|
||||||
for(s = SQ_A1; s <= SQ_H8; s++) {
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
|
{
|
||||||
BishopPseudoAttacks[s] = bishop_attacks_bb(s, EmptyBoardBB);
|
BishopPseudoAttacks[s] = bishop_attacks_bb(s, EmptyBoardBB);
|
||||||
RookPseudoAttacks[s] = rook_attacks_bb(s, EmptyBoardBB);
|
RookPseudoAttacks[s] = rook_attacks_bb(s, EmptyBoardBB);
|
||||||
QueenPseudoAttacks[s] = queen_attacks_bb(s, EmptyBoardBB);
|
QueenPseudoAttacks[s] = queen_attacks_bb(s, EmptyBoardBB);
|
||||||
|
|||||||
+21
-28
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -74,8 +74,9 @@ extern Bitboard StepAttackBB[16][64];
|
|||||||
extern Bitboard RayBB[64][8];
|
extern Bitboard RayBB[64][8];
|
||||||
extern Bitboard BetweenBB[64][64];
|
extern Bitboard BetweenBB[64][64];
|
||||||
|
|
||||||
|
extern Bitboard SquaresInFrontMask[2][64];
|
||||||
extern Bitboard PassedPawnMask[2][64];
|
extern Bitboard PassedPawnMask[2][64];
|
||||||
extern Bitboard OutpostMask[2][64];
|
extern Bitboard AttackSpanMask[2][64];
|
||||||
|
|
||||||
extern const uint64_t RMult[64];
|
extern const uint64_t RMult[64];
|
||||||
extern const int RShift[64];
|
extern const int RShift[64];
|
||||||
@@ -127,9 +128,8 @@ inline void do_move_bb(Bitboard *b, Bitboard move_bb) {
|
|||||||
*b ^= move_bb;
|
*b ^= move_bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// rank_bb() and file_bb() gives a bitboard containing all squares on a given
|
/// rank_bb() and file_bb() take a file or a square as input, and return
|
||||||
/// file or rank. It is also possible to pass a square as input to these
|
/// a bitboard representing all squares on the given file or rank.
|
||||||
/// functions.
|
|
||||||
|
|
||||||
inline Bitboard rank_bb(Rank r) {
|
inline Bitboard rank_bb(Rank r) {
|
||||||
return RankBB[r];
|
return RankBB[r];
|
||||||
@@ -156,7 +156,7 @@ inline Bitboard neighboring_files_bb(File f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard neighboring_files_bb(Square s) {
|
inline Bitboard neighboring_files_bb(Square s) {
|
||||||
return neighboring_files_bb(square_file(s));
|
return NeighboringFilesBB[square_file(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ inline Bitboard this_and_neighboring_files_bb(File f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard this_and_neighboring_files_bb(Square s) {
|
inline Bitboard this_and_neighboring_files_bb(Square s) {
|
||||||
return this_and_neighboring_files_bb(square_file(s));
|
return ThisAndNeighboringFilesBB[square_file(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ inline Bitboard in_front_bb(Color c, Rank r) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard in_front_bb(Color c, Square s) {
|
inline Bitboard in_front_bb(Color c, Square s) {
|
||||||
return in_front_bb(c, square_rank(s));
|
return InFrontBB[c][square_rank(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ inline Bitboard behind_bb(Color c, Rank r) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard behind_bb(Color c, Square s) {
|
inline Bitboard behind_bb(Color c, Square s) {
|
||||||
return in_front_bb(opposite_color(c), square_rank(s));
|
return InFrontBB[opposite_color(c)][square_rank(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -274,12 +274,11 @@ inline Bitboard squares_between(Square s1, Square s2) {
|
|||||||
|
|
||||||
/// squares_in_front_of takes a color and a square as input, and returns a
|
/// squares_in_front_of takes a color and a square as input, and returns a
|
||||||
/// bitboard representing all squares along the line in front of the square,
|
/// bitboard representing all squares along the line in front of the square,
|
||||||
/// from the point of view of the given color. For instance,
|
/// from the point of view of the given color. Definition of the table is:
|
||||||
/// squares_in_front_of(BLACK, SQ_E4) returns a bitboard with the squares
|
/// SquaresInFrontOf[c][s] = in_front_bb(c, s) & file_bb(s)
|
||||||
/// e3, e2 and e1 set.
|
|
||||||
|
|
||||||
inline Bitboard squares_in_front_of(Color c, Square s) {
|
inline Bitboard squares_in_front_of(Color c, Square s) {
|
||||||
return in_front_bb(c, s) & file_bb(s);
|
return SquaresInFrontMask[c][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -287,33 +286,27 @@ inline Bitboard squares_in_front_of(Color c, Square s) {
|
|||||||
/// behind the square instead of in front of the square.
|
/// behind the square instead of in front of the square.
|
||||||
|
|
||||||
inline Bitboard squares_behind(Color c, Square s) {
|
inline Bitboard squares_behind(Color c, Square s) {
|
||||||
return in_front_bb(opposite_color(c), s) & file_bb(s);
|
return SquaresInFrontMask[opposite_color(c)][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// passed_pawn_mask takes a color and a square as input, and returns a
|
/// passed_pawn_mask takes a color and a square as input, and returns a
|
||||||
/// bitboard mask which can be used to test if a pawn of the given color on
|
/// bitboard mask which can be used to test if a pawn of the given color on
|
||||||
/// the given square is a passed pawn.
|
/// the given square is a passed pawn. Definition of the table is:
|
||||||
|
/// PassedPawnMask[c][s] = in_front_bb(c, s) & this_and_neighboring_files_bb(s)
|
||||||
|
|
||||||
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
||||||
return PassedPawnMask[c][s];
|
return PassedPawnMask[c][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// outpost_mask takes a color and a square as input, and returns a bitboard
|
/// attack_span_mask takes a color and a square as input, and returns a bitboard
|
||||||
/// mask which can be used to test whether a piece on the square can possibly
|
/// representing all squares that can be attacked by a pawn of the given color
|
||||||
/// be driven away by an enemy pawn.
|
/// when it moves along its file starting from the given square. Definition is:
|
||||||
|
/// AttackSpanMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
||||||
|
|
||||||
inline Bitboard outpost_mask(Color c, Square s) {
|
inline Bitboard attack_span_mask(Color c, Square s) {
|
||||||
return OutpostMask[c][s];
|
return AttackSpanMask[c][s];
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// isolated_pawn_mask takes a square as input, and returns a bitboard mask
|
|
||||||
/// which can be used to test whether a pawn on the given square is isolated.
|
|
||||||
|
|
||||||
inline Bitboard isolated_pawn_mask(Square s) {
|
|
||||||
return neighboring_files_bb(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+26
-53
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,62 +22,22 @@
|
|||||||
#if !defined(BITCOUNT_H_INCLUDED)
|
#if !defined(BITCOUNT_H_INCLUDED)
|
||||||
#define BITCOUNT_H_INCLUDED
|
#define BITCOUNT_H_INCLUDED
|
||||||
|
|
||||||
// To enable POPCNT support uncomment USE_POPCNT define. For PGO compile on a Core i7
|
|
||||||
// you may want to collect profile data first with USE_POPCNT disabled and then, in a
|
|
||||||
// second profiling session, with USE_POPCNT enabled so to exercise both paths. Don't
|
|
||||||
// forget to leave USE_POPCNT enabled for the final optimized compile though ;-)
|
|
||||||
|
|
||||||
//#define USE_POPCNT
|
|
||||||
|
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
// Select type of intrinsic bit count instruction to use
|
// Select type of intrinsic bit count instruction to use, see
|
||||||
|
// README.txt on how to pgo compile with POPCNT support.
|
||||||
#if defined(__INTEL_COMPILER) && defined(IS_64BIT) && defined(USE_POPCNT) // Intel compiler
|
#if !defined(USE_POPCNT)
|
||||||
|
|
||||||
#include <nmmintrin.h>
|
|
||||||
|
|
||||||
inline bool cpu_has_popcnt() {
|
|
||||||
|
|
||||||
int CPUInfo[4] = {-1};
|
|
||||||
__cpuid(CPUInfo, 0x00000001);
|
|
||||||
return (CPUInfo[2] >> 23) & 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define a dummy template to workaround a compile error if _mm_popcnt_u64() is not defined.
|
|
||||||
//
|
|
||||||
// If _mm_popcnt_u64() is defined in <nmmintrin.h> it will be choosen first due to
|
|
||||||
// C++ overload rules that always prefer a function to a template with the same name.
|
|
||||||
// If not, we avoid a compile error and because cpu_has_popcnt() should return false,
|
|
||||||
// our templetized _mm_popcnt_u64() is never called anyway.
|
|
||||||
template<typename T> inline unsigned _mm_popcnt_u64(T) { return 0; } // Is never called
|
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) _mm_popcnt_u64(x)
|
|
||||||
|
|
||||||
#elif defined(_MSC_VER) && defined(IS_64BIT) && defined(USE_POPCNT) // Microsoft compiler
|
|
||||||
|
|
||||||
#include <intrin.h>
|
|
||||||
|
|
||||||
inline bool cpu_has_popcnt() {
|
|
||||||
|
|
||||||
int CPUInfo[4] = {-1};
|
|
||||||
__cpuid(CPUInfo, 0x00000001);
|
|
||||||
return (CPUInfo[2] >> 23) & 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// See comment of _mm_popcnt_u64<>() few lines above for an explanation.
|
|
||||||
template<typename T> inline unsigned __popcnt64(T) { return 0; } // Is never called
|
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) __popcnt64(x)
|
|
||||||
|
|
||||||
#else // Safe fallback for unsupported compilers or when USE_POPCNT is disabled
|
|
||||||
|
|
||||||
inline bool cpu_has_popcnt() { return false; }
|
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) 0
|
#define POPCNT_INTRINSIC(x) 0
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define POPCNT_INTRINSIC(x) (int)__popcnt64(x)
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
|
||||||
#endif // cpu_has_popcnt() and POPCNT_INTRINSIC() definitions
|
#define POPCNT_INTRINSIC(x) ({ \
|
||||||
|
unsigned long __ret; \
|
||||||
|
__asm__("popcnt %1, %0" : "=r" (__ret) : "r" (x)); \
|
||||||
|
__ret; })
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// Software implementation of bit count functions
|
/// Software implementation of bit count functions
|
||||||
@@ -144,10 +104,23 @@ inline int count_1s_max_15(Bitboard b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Detect hardware POPCNT support
|
||||||
|
inline bool cpu_has_popcnt() {
|
||||||
|
|
||||||
|
int CPUInfo[4] = {-1};
|
||||||
|
__cpuid(CPUInfo, 0x00000001);
|
||||||
|
return (CPUInfo[2] >> 23) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Global constant initialized at startup that is set to true if
|
// Global constant initialized at startup that is set to true if
|
||||||
// CPU on which application runs supports POPCNT intrinsic. Unless
|
// CPU on which application runs supports POPCNT intrinsic. Unless
|
||||||
// USE_POPCNT is not defined.
|
// USE_POPCNT is not defined.
|
||||||
|
#if defined(USE_POPCNT)
|
||||||
const bool CpuHasPOPCNT = cpu_has_popcnt();
|
const bool CpuHasPOPCNT = cpu_has_popcnt();
|
||||||
|
#else
|
||||||
|
const bool CpuHasPOPCNT = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Global constant used to print info about the use of 64 optimized
|
// Global constant used to print info about the use of 64 optimized
|
||||||
|
|||||||
+17
-5
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -390,7 +390,7 @@ void Book::close() {
|
|||||||
/// Book::file_name() returns the file name of the currently active book,
|
/// Book::file_name() returns the file name of the currently active book,
|
||||||
/// or the empty string if no book is open.
|
/// or the empty string if no book is open.
|
||||||
|
|
||||||
const string Book::file_name() const {
|
const string Book::file_name() { // Not const to compile on HP-UX 11.X
|
||||||
|
|
||||||
return is_open() ? fileName : "";
|
return is_open() ? fileName : "";
|
||||||
}
|
}
|
||||||
@@ -399,14 +399,15 @@ const string Book::file_name() const {
|
|||||||
/// Book::get_move() gets a book move for a given position. Returns
|
/// Book::get_move() gets a book move for a given position. Returns
|
||||||
/// MOVE_NONE if no book move is found.
|
/// MOVE_NONE if no book move is found.
|
||||||
|
|
||||||
Move Book::get_move(const Position& pos) {
|
Move Book::get_move(const Position& pos, bool findBestMove) {
|
||||||
|
|
||||||
if (!is_open() || bookSize == 0)
|
if (!is_open() || bookSize == 0)
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
|
|
||||||
int bookMove = 0, scoresSum = 0;
|
|
||||||
uint64_t key = book_key(pos);
|
|
||||||
BookEntry entry;
|
BookEntry entry;
|
||||||
|
int bookMove = MOVE_NONE;
|
||||||
|
int scoresSum = 0, bestScore = 0;
|
||||||
|
uint64_t key = book_key(pos);
|
||||||
|
|
||||||
// Choose a book move among the possible moves for the given position
|
// Choose a book move among the possible moves for the given position
|
||||||
for (int idx = find_key(key); idx < bookSize; idx++)
|
for (int idx = find_key(key); idx < bookSize; idx++)
|
||||||
@@ -419,6 +420,17 @@ Move Book::get_move(const Position& pos) {
|
|||||||
|
|
||||||
assert(score > 0);
|
assert(score > 0);
|
||||||
|
|
||||||
|
// If findBestMove is true choose highest rated book move
|
||||||
|
if (findBestMove)
|
||||||
|
{
|
||||||
|
if (score > bestScore)
|
||||||
|
{
|
||||||
|
bestScore = score;
|
||||||
|
bookMove = entry.move;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Choose book move according to its score. If a move has a very
|
// Choose book move according to its score. If a move has a very
|
||||||
// high score it has more probability to be choosen then a one with
|
// high score it has more probability to be choosen then a one with
|
||||||
// lower score. Note that first entry is always chosen.
|
// lower score. Note that first entry is always chosen.
|
||||||
|
|||||||
+6
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -53,12 +53,15 @@ struct BookEntry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Book : private std::ifstream {
|
class Book : private std::ifstream {
|
||||||
|
Book(const Book&); // just decleared..
|
||||||
|
Book& operator=(const Book&); // ..to avoid a warning
|
||||||
public:
|
public:
|
||||||
|
Book() {}
|
||||||
~Book();
|
~Book();
|
||||||
void open(const std::string& fName);
|
void open(const std::string& fName);
|
||||||
void close();
|
void close();
|
||||||
const std::string file_name() const;
|
const std::string file_name();
|
||||||
Move get_move(const Position& pos);
|
Move get_move(const Position& pos, bool findBestMove);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Book& operator>>(uint64_t& n) { n = read_integer(8); return *this; }
|
Book& operator>>(uint64_t& n) { n = read_integer(8); return *this; }
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+5
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,7 +27,8 @@
|
|||||||
|
|
||||||
enum Depth {
|
enum Depth {
|
||||||
DEPTH_ZERO = 0,
|
DEPTH_ZERO = 0,
|
||||||
DEPTH_MAX = 200 // 100 * OnePly;
|
DEPTH_MAX = 200, // 100 * OnePly;
|
||||||
|
DEPTH_ENSURE_SIGNED = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -48,7 +49,8 @@ inline void operator+= (Depth &d, int i) { d = Depth(int(d) + i); }
|
|||||||
inline void operator+= (Depth &d1, Depth d2) { d1 += int(d2); }
|
inline void operator+= (Depth &d1, Depth d2) { d1 += int(d2); }
|
||||||
inline Depth operator- (Depth d, int i) { return Depth(int(d) - i); }
|
inline Depth operator- (Depth d, int i) { return Depth(int(d) - i); }
|
||||||
inline Depth operator- (Depth d1, Depth d2) { return Depth(int(d1) - int(d2)); }
|
inline Depth operator- (Depth d1, Depth d2) { return Depth(int(d1) - int(d2)); }
|
||||||
inline void operator-= (Depth & d, int i) { d = Depth(int(d) - i); }
|
inline void operator-= (Depth &d, int i) { d = Depth(int(d) - i); }
|
||||||
|
inline void operator-= (Depth &d1, Depth d2) { d1 -= int(d2); }
|
||||||
inline Depth operator* (Depth d, int i) { return Depth(int(d) * i); }
|
inline Depth operator* (Depth d, int i) { return Depth(int(d) * i); }
|
||||||
inline Depth operator* (int i, Depth d) { return Depth(int(d) * i); }
|
inline Depth operator* (int i, Depth d) { return Depth(int(d) * i); }
|
||||||
inline void operator*= (Depth &d, int i) { d = Depth(int(d) * i); }
|
inline void operator*= (Depth &d, int i) { d = Depth(int(d) * i); }
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+21
-21
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -104,7 +104,7 @@ namespace {
|
|||||||
/// attacking side a bonus for driving the defending king towards the edge
|
/// attacking side a bonus for driving the defending king towards the edge
|
||||||
/// of the board, and for keeping the distance between the two kings small.
|
/// of the board, and for keeping the distance between the two kings small.
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KXK>::apply(const Position& pos) {
|
Value EvaluationFunction<KXK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
||||||
assert(pos.piece_count(weakerSide, PAWN) == Value(0));
|
assert(pos.piece_count(weakerSide, PAWN) == Value(0));
|
||||||
@@ -130,7 +130,7 @@ Value EvaluationFunction<KXK>::apply(const Position& pos) {
|
|||||||
/// 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 of the right color.
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KBNK>::apply(const Position& pos) {
|
Value EvaluationFunction<KBNK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
||||||
assert(pos.piece_count(weakerSide, PAWN) == Value(0));
|
assert(pos.piece_count(weakerSide, PAWN) == Value(0));
|
||||||
@@ -159,7 +159,7 @@ Value EvaluationFunction<KBNK>::apply(const Position& pos) {
|
|||||||
|
|
||||||
/// 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 EvaluationFunction<KPK>::apply(const Position& pos) {
|
Value EvaluationFunction<KPK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == Value(0));
|
assert(pos.non_pawn_material(strongerSide) == Value(0));
|
||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
||||||
@@ -207,7 +207,7 @@ Value EvaluationFunction<KPK>::apply(const Position& pos) {
|
|||||||
/// far advanced with support of the king, while the attacking king is far
|
/// far advanced with support of the king, while the attacking king is far
|
||||||
/// away.
|
/// away.
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KRKP>::apply(const Position& pos) {
|
Value EvaluationFunction<KRKP>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, PAWN) == 0);
|
assert(pos.piece_count(strongerSide, PAWN) == 0);
|
||||||
@@ -264,7 +264,7 @@ Value EvaluationFunction<KRKP>::apply(const Position& pos) {
|
|||||||
/// 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 EvaluationFunction<KRKB>::apply(const Position& pos) {
|
Value EvaluationFunction<KRKB>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, PAWN) == 0);
|
assert(pos.piece_count(strongerSide, PAWN) == 0);
|
||||||
@@ -280,7 +280,7 @@ Value EvaluationFunction<KRKB>::apply(const Position& pos) {
|
|||||||
/// KR vs KN. The attacking side has slightly better winning chances than
|
/// KR vs KN. The attacking side has slightly better winning chances than
|
||||||
/// in KR vs KB, particularly if the king and the knight are far apart.
|
/// in KR vs KB, particularly if the king and the knight are far apart.
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KRKN>::apply(const Position& pos) {
|
Value EvaluationFunction<KRKN>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, PAWN) == 0);
|
assert(pos.piece_count(strongerSide, PAWN) == 0);
|
||||||
@@ -304,7 +304,7 @@ Value EvaluationFunction<KRKN>::apply(const Position& pos) {
|
|||||||
/// for the defending side in the search, this is usually sufficient to be
|
/// for the defending side in the search, this is usually sufficient to be
|
||||||
/// able to win KQ vs KR.
|
/// able to win KQ vs KR.
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KQKR>::apply(const Position& pos) {
|
Value EvaluationFunction<KQKR>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, PAWN) == 0);
|
assert(pos.piece_count(strongerSide, PAWN) == 0);
|
||||||
@@ -323,7 +323,7 @@ Value EvaluationFunction<KQKR>::apply(const Position& pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
|
Value EvaluationFunction<KBBKN>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.piece_count(strongerSide, BISHOP) == 2);
|
assert(pos.piece_count(strongerSide, BISHOP) == 2);
|
||||||
assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
|
||||||
@@ -352,12 +352,12 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
|
|||||||
/// K and two minors vs K and one or two minors or K and two knights against
|
/// K and two minors vs K and one or two minors or K and two knights against
|
||||||
/// king alone are always draw.
|
/// king alone are always draw.
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KmmKm>::apply(const Position&) {
|
Value EvaluationFunction<KmmKm>::apply(const Position&) const {
|
||||||
return Value(0);
|
return Value(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KNNK>::apply(const Position&) {
|
Value EvaluationFunction<KNNK>::apply(const Position&) const {
|
||||||
return Value(0);
|
return Value(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ Value EvaluationFunction<KNNK>::apply(const Position&) {
|
|||||||
/// returned. If not, the return value is SCALE_FACTOR_NONE, i.e. no scaling
|
/// returned. If not, the return value is SCALE_FACTOR_NONE, i.e. no scaling
|
||||||
/// will be used.
|
/// will be used.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KBPsK>::apply(const Position& pos) {
|
ScaleFactor ScalingFunction<KBPsK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
||||||
@@ -421,7 +421,7 @@ ScaleFactor ScalingFunction<KBPsK>::apply(const Position& pos) {
|
|||||||
/// It tests for fortress draws with a rook on the third rank defended by
|
/// It tests for fortress draws with a rook on the third rank defended by
|
||||||
/// a pawn.
|
/// a pawn.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) {
|
ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, QUEEN) == 1);
|
assert(pos.piece_count(strongerSide, QUEEN) == 1);
|
||||||
@@ -452,7 +452,7 @@ ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) {
|
|||||||
/// It would also be nice to rewrite the actual code for this function,
|
/// It would also be nice to rewrite the actual code for this function,
|
||||||
/// which is mostly copied from Glaurung 1.x, and not very pretty.
|
/// which is mostly copied from Glaurung 1.x, and not very pretty.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KRPKR>::apply(const Position &pos) {
|
ScaleFactor ScalingFunction<KRPKR>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, PAWN) == 1);
|
assert(pos.piece_count(strongerSide, PAWN) == 1);
|
||||||
@@ -570,7 +570,7 @@ ScaleFactor ScalingFunction<KRPKR>::apply(const Position &pos) {
|
|||||||
/// single pattern: If the stronger side has no pawns and the defending king
|
/// single pattern: If the stronger side has no pawns and the defending king
|
||||||
/// is actively placed, the position is drawish.
|
/// is actively placed, the position is drawish.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KRPPKRP>::apply(const Position &pos) {
|
ScaleFactor ScalingFunction<KRPPKRP>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, PAWN) == 2);
|
assert(pos.piece_count(strongerSide, PAWN) == 2);
|
||||||
@@ -609,7 +609,7 @@ ScaleFactor ScalingFunction<KRPPKRP>::apply(const Position &pos) {
|
|||||||
/// against king. There is just a single rule here: If all pawns are on
|
/// against king. There is just a single rule here: If all pawns are on
|
||||||
/// the same rook file and are blocked by the defending king, it's a draw.
|
/// the same rook file and are blocked by the defending king, it's a draw.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KPsK>::apply(const Position &pos) {
|
ScaleFactor ScalingFunction<KPsK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == Value(0));
|
assert(pos.non_pawn_material(strongerSide) == Value(0));
|
||||||
assert(pos.piece_count(strongerSide, PAWN) >= 2);
|
assert(pos.piece_count(strongerSide, PAWN) >= 2);
|
||||||
@@ -655,7 +655,7 @@ ScaleFactor ScalingFunction<KPsK>::apply(const Position &pos) {
|
|||||||
/// it's a draw. If the two bishops have opposite color, it's almost always
|
/// it's a draw. If the two bishops have opposite color, it's almost always
|
||||||
/// a draw.
|
/// a draw.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KBPKB>::apply(const Position &pos) {
|
ScaleFactor ScalingFunction<KBPKB>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
||||||
@@ -708,7 +708,7 @@ ScaleFactor ScalingFunction<KBPKB>::apply(const Position &pos) {
|
|||||||
/// KBPPKBScalingFunction scales KBPP vs KB endgames. It detects a few basic
|
/// KBPPKBScalingFunction scales KBPP vs KB endgames. It detects a few basic
|
||||||
/// draws with opposite-colored bishops.
|
/// draws with opposite-colored bishops.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KBPPKB>::apply(const Position& pos) {
|
ScaleFactor ScalingFunction<KBPPKB>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
||||||
@@ -784,7 +784,7 @@ ScaleFactor ScalingFunction<KBPPKB>::apply(const Position& pos) {
|
|||||||
/// square of the king is not of the same color as the stronger side's bishop,
|
/// square of the king is not of the same color as the stronger side's bishop,
|
||||||
/// it's a draw.
|
/// it's a draw.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KBPKN>::apply(const Position &pos) {
|
ScaleFactor ScalingFunction<KBPKN>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
||||||
@@ -811,7 +811,7 @@ ScaleFactor ScalingFunction<KBPKN>::apply(const Position &pos) {
|
|||||||
/// If the pawn is a rook pawn on the 7th rank and the defending king prevents
|
/// If the pawn is a rook pawn on the 7th rank and the defending king prevents
|
||||||
/// the pawn from advancing, the position is drawn.
|
/// the pawn from advancing, the position is drawn.
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KNPK>::apply(const Position &pos) {
|
ScaleFactor ScalingFunction<KNPK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, KNIGHT) == 1);
|
assert(pos.piece_count(strongerSide, KNIGHT) == 1);
|
||||||
@@ -841,7 +841,7 @@ ScaleFactor ScalingFunction<KNPK>::apply(const Position &pos) {
|
|||||||
/// advanced and not on a rook file; in this case it is often possible to win
|
/// advanced and not on a rook file; in this case it is often possible to win
|
||||||
/// (e.g. 8/4k3/3p4/3P4/6K1/8/8/8 w - - 0 1).
|
/// (e.g. 8/4k3/3p4/3P4/6K1/8/8/8 w - - 0 1).
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KPKP>::apply(const Position &pos) {
|
ScaleFactor ScalingFunction<KPKP>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == Value(0));
|
assert(pos.non_pawn_material(strongerSide) == Value(0));
|
||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
||||||
|
|||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -68,7 +68,7 @@ class EndgameFunctionBase {
|
|||||||
public:
|
public:
|
||||||
EndgameFunctionBase(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
|
EndgameFunctionBase(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
|
||||||
virtual ~EndgameFunctionBase() {}
|
virtual ~EndgameFunctionBase() {}
|
||||||
virtual T apply(const Position&) = 0;
|
virtual T apply(const Position&) const = 0;
|
||||||
Color color() const { return strongerSide; }
|
Color color() const { return strongerSide; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -85,14 +85,14 @@ template<EndgameType>
|
|||||||
struct EvaluationFunction : public EndgameEvaluationFunctionBase {
|
struct EvaluationFunction : public EndgameEvaluationFunctionBase {
|
||||||
typedef EndgameEvaluationFunctionBase Base;
|
typedef EndgameEvaluationFunctionBase Base;
|
||||||
explicit EvaluationFunction(Color c): EndgameEvaluationFunctionBase(c) {}
|
explicit EvaluationFunction(Color c): EndgameEvaluationFunctionBase(c) {}
|
||||||
Value apply(const Position&);
|
Value apply(const Position&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<EndgameType>
|
template<EndgameType>
|
||||||
struct ScalingFunction : public EndgameScalingFunctionBase {
|
struct ScalingFunction : public EndgameScalingFunctionBase {
|
||||||
typedef EndgameScalingFunctionBase Base;
|
typedef EndgameScalingFunctionBase Base;
|
||||||
explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
|
explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
|
||||||
ScaleFactor apply(const Position&);
|
ScaleFactor apply(const Position&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+452
-550
File diff suppressed because it is too large
Load Diff
+11
-12
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
|
|
||||||
@@ -45,8 +47,10 @@ class Position;
|
|||||||
|
|
||||||
struct EvalInfo {
|
struct EvalInfo {
|
||||||
|
|
||||||
|
EvalInfo() { kingDanger[0] = kingDanger[1] = Value(0); }
|
||||||
|
|
||||||
// Middle game and endgame evaluations
|
// Middle game and endgame evaluations
|
||||||
Value mgValue, egValue;
|
Score value;
|
||||||
|
|
||||||
// Pointers to material and pawn hash table entries
|
// Pointers to material and pawn hash table entries
|
||||||
MaterialInfo* mi;
|
MaterialInfo* mi;
|
||||||
@@ -85,15 +89,11 @@ struct EvalInfo {
|
|||||||
// 2 to kingAdjacentZoneAttacksCount[BLACK].
|
// 2 to kingAdjacentZoneAttacksCount[BLACK].
|
||||||
int kingAdjacentZoneAttacksCount[2];
|
int kingAdjacentZoneAttacksCount[2];
|
||||||
|
|
||||||
// mateThreat[color] is a move for the given side which gives a direct mate.
|
// Middle game and endgame mobility scores
|
||||||
Move mateThreat[2];
|
Score mobility;
|
||||||
|
|
||||||
// Middle game and endgame mobility scores.
|
// Value of the danger for the king of the given color
|
||||||
Value mgMobility, egMobility;
|
Value kingDanger[2];
|
||||||
|
|
||||||
// Extra futility margin. This is added to the standard futility margin
|
|
||||||
// in the quiescence search.
|
|
||||||
Value futilityMargin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -101,8 +101,7 @@ struct EvalInfo {
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern Value evaluate(const Position& pos, EvalInfo& ei, int threadID);
|
extern Value evaluate(const Position& pos, EvalInfo& ei);
|
||||||
extern Value quick_evaluate(const Position& pos);
|
|
||||||
extern void init_eval(int threads);
|
extern void init_eval(int threads);
|
||||||
extern void quit_eval();
|
extern void quit_eval();
|
||||||
extern void read_weights(Color sideToMove);
|
extern void read_weights(Color sideToMove);
|
||||||
|
|||||||
+25
-15
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -42,8 +42,7 @@ History::History() { clear(); }
|
|||||||
|
|
||||||
void History::clear() {
|
void History::clear() {
|
||||||
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
||||||
memset(successCount, 0, 2 * 8 * 64 * sizeof(int));
|
memset(maxStaticValueDelta, 0, 2 * 8 * 64 * sizeof(int));
|
||||||
memset(failureCount, 0, 2 * 8 * 64 * sizeof(int));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,13 +57,12 @@ void History::success(Piece p, Square to, Depth d) {
|
|||||||
assert(square_is_ok(to));
|
assert(square_is_ok(to));
|
||||||
|
|
||||||
history[p][to] += int(d) * int(d);
|
history[p][to] += int(d) * int(d);
|
||||||
successCount[p][to]++;
|
|
||||||
|
|
||||||
// Prevent history overflow
|
// Prevent history overflow
|
||||||
if (history[p][to] >= HistoryMax)
|
if (history[p][to] >= HistoryMax)
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
for (int j = 0; j < 64; j++)
|
for (int j = 0; j < 64; j++)
|
||||||
history[i][j] /= 4;
|
history[i][j] /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,12 +70,18 @@ void History::success(Piece p, Square to, Depth d) {
|
|||||||
/// called for each non-capturing move which failed to produce a beta cutoff
|
/// called for each non-capturing move which failed to produce a beta cutoff
|
||||||
/// at a node where a beta cutoff was finally found.
|
/// at a node where a beta cutoff was finally found.
|
||||||
|
|
||||||
void History::failure(Piece p, Square to) {
|
void History::failure(Piece p, Square to, Depth d) {
|
||||||
|
|
||||||
assert(piece_is_ok(p));
|
assert(piece_is_ok(p));
|
||||||
assert(square_is_ok(to));
|
assert(square_is_ok(to));
|
||||||
|
|
||||||
failureCount[p][to]++;
|
history[p][to] -= int(d) * int(d);
|
||||||
|
|
||||||
|
// Prevent history underflow
|
||||||
|
if (history[p][to] <= -HistoryMax)
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
for (int j = 0; j < 64; j++)
|
||||||
|
history[i][j] /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,13 +97,19 @@ int History::move_ordering_score(Piece p, Square to) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// History::ok_to_prune() decides whether a move has been sufficiently
|
/// History::set_gain() and History::gain() store and retrieve the
|
||||||
/// unsuccessful that it makes sense to prune it entirely.
|
/// gain of a move given the delta of the static position evaluations
|
||||||
|
/// before and after the move.
|
||||||
|
|
||||||
bool History::ok_to_prune(Piece p, Square to, Depth d) const {
|
void History::set_gain(Piece p, Square to, Value delta)
|
||||||
|
{
|
||||||
assert(piece_is_ok(p));
|
if (delta >= maxStaticValueDelta[p][to])
|
||||||
assert(square_is_ok(to));
|
maxStaticValueDelta[p][to] = delta;
|
||||||
|
else
|
||||||
return (int(d) * successCount[p][to] < failureCount[p][to]);
|
maxStaticValueDelta[p][to]--;
|
||||||
|
}
|
||||||
|
|
||||||
|
Value History::gain(Piece p, Square to) const
|
||||||
|
{
|
||||||
|
return Value(maxStaticValueDelta[p][to]);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-6
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
|
#include "value.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -47,14 +48,14 @@ public:
|
|||||||
History();
|
History();
|
||||||
void clear();
|
void clear();
|
||||||
void success(Piece p, Square to, Depth d);
|
void success(Piece p, Square to, Depth d);
|
||||||
void failure(Piece p, Square to);
|
void failure(Piece p, Square to, Depth d);
|
||||||
int move_ordering_score(Piece p, Square to) const;
|
int move_ordering_score(Piece p, Square to) const;
|
||||||
bool ok_to_prune(Piece p, Square to, Depth d) const;
|
void set_gain(Piece p, Square to, Value delta);
|
||||||
|
Value gain(Piece p, Square to) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int history[16][64]; // [piece][square]
|
int history[16][64]; // [piece][square]
|
||||||
int successCount[16][64];
|
int maxStaticValueDelta[16][64]; // [piece][from_square][to_square]
|
||||||
int failureCount[16][64];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ private:
|
|||||||
/// recently have a bigger importance for move ordering than the moves which
|
/// recently have a bigger importance for move ordering than the moves which
|
||||||
/// have been searched a long time ago.
|
/// have been searched a long time ago.
|
||||||
|
|
||||||
const int HistoryMax = 25000 * OnePly;
|
const int HistoryMax = 50000 * OnePly;
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(HISTORY_H_INCLUDED)
|
#endif // !defined(HISTORY_H_INCLUDED)
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -99,5 +99,4 @@ typedef CRITICAL_SECTION Lock;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(LOCK_H_INCLUDED)
|
#endif // !defined(LOCK_H_INCLUDED)
|
||||||
|
|||||||
+16
-14
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -57,13 +57,24 @@ int main(int argc, char *argv[]) {
|
|||||||
CALLGRIND_START_INSTRUMENTATION;
|
CALLGRIND_START_INSTRUMENTATION;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Process command line arguments if any
|
if (argc <= 1)
|
||||||
if (argc > 1)
|
{
|
||||||
|
// Print copyright notice
|
||||||
|
cout << engine_name()
|
||||||
|
<< " by Tord Romstad, Marco Costalba, Joona Kiiski" << endl;
|
||||||
|
|
||||||
|
if (CpuHasPOPCNT)
|
||||||
|
cout << "Good! CPU has hardware POPCNT." << endl;
|
||||||
|
|
||||||
|
// Enter UCI mode
|
||||||
|
uci_main_loop();
|
||||||
|
}
|
||||||
|
else // Process command line arguments
|
||||||
{
|
{
|
||||||
if (string(argv[1]) != "bench" || argc < 4 || argc > 8)
|
if (string(argv[1]) != "bench" || argc < 4 || argc > 8)
|
||||||
cout << "Usage: stockfish bench <hash size> <threads> "
|
cout << "Usage: stockfish bench <hash size> <threads> "
|
||||||
<< "[time = 60s] [fen positions file = default] "
|
<< "[time = 60s] [fen positions file = default] "
|
||||||
<< "[time, depth or node limited = time] "
|
<< "[time, depth, perft or node limited = time] "
|
||||||
<< "[timing file name = none]" << endl;
|
<< "[timing file name = none]" << endl;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -73,17 +84,8 @@ int main(int argc, char *argv[]) {
|
|||||||
string tim = argc > 7 ? argv[7] : "";
|
string tim = argc > 7 ? argv[7] : "";
|
||||||
benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen + " " + lim + " " + tim);
|
benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen + " " + lim + " " + tim);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print copyright notice
|
Application::free_resources();
|
||||||
cout << engine_name()
|
|
||||||
<< ". By Tord Romstad, Marco Costalba, Joona Kiiski." << endl;
|
|
||||||
|
|
||||||
if (CpuHasPOPCNT)
|
|
||||||
cout << "Good! CPU has hardware POPCNT. We will use it." << endl;
|
|
||||||
|
|
||||||
// Enter UCI mode
|
|
||||||
uci_main_loop();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+88
-63
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -37,9 +37,14 @@ using namespace std;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// Values modified by Joona Kiiski
|
||||||
|
const Value MidgameLimit = Value(15581);
|
||||||
|
const Value EndgameLimit = Value(3998);
|
||||||
|
|
||||||
// Polynomial material balance parameters
|
// Polynomial material balance parameters
|
||||||
const Value RedundantQueenPenalty = Value(320);
|
const Value RedundantQueenPenalty = Value(320);
|
||||||
const Value RedundantRookPenalty = Value(554);
|
const Value RedundantRookPenalty = Value(554);
|
||||||
|
|
||||||
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
||||||
|
|
||||||
const int QuadraticCoefficientsSameColor[][6] = {
|
const int QuadraticCoefficientsSameColor[][6] = {
|
||||||
@@ -50,17 +55,40 @@ namespace {
|
|||||||
{ 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 },
|
{ 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 },
|
||||||
{ 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } };
|
{ 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } };
|
||||||
|
|
||||||
// Named endgame evaluation and scaling functions, these
|
|
||||||
// are accessed direcly and not through the function maps.
|
|
||||||
EvaluationFunction<KmmKm> EvaluateKmmKm(WHITE);
|
|
||||||
EvaluationFunction<KXK> EvaluateKXK(WHITE), EvaluateKKX(BLACK);
|
|
||||||
ScalingFunction<KBPsK> ScaleKBPsK(WHITE), ScaleKKBPs(BLACK);
|
|
||||||
ScalingFunction<KQKRPs> ScaleKQKRPs(WHITE), ScaleKRPsKQ(BLACK);
|
|
||||||
ScalingFunction<KPsK> ScaleKPsK(WHITE), ScaleKKPs(BLACK);
|
|
||||||
ScalingFunction<KPKP> ScaleKPKPw(WHITE), ScaleKPKPb(BLACK);
|
|
||||||
|
|
||||||
typedef EndgameEvaluationFunctionBase EF;
|
typedef EndgameEvaluationFunctionBase EF;
|
||||||
typedef EndgameScalingFunctionBase SF;
|
typedef EndgameScalingFunctionBase SF;
|
||||||
|
|
||||||
|
// Endgame evaluation and scaling functions accessed direcly and not through
|
||||||
|
// the function maps because correspond to more then one material hash key.
|
||||||
|
EvaluationFunction<KmmKm> EvaluateKmmKm[] = { EvaluationFunction<KmmKm>(WHITE), EvaluationFunction<KmmKm>(BLACK) };
|
||||||
|
EvaluationFunction<KXK> EvaluateKXK[] = { EvaluationFunction<KXK>(WHITE), EvaluationFunction<KXK>(BLACK) };
|
||||||
|
ScalingFunction<KBPsK> ScaleKBPsK[] = { ScalingFunction<KBPsK>(WHITE), ScalingFunction<KBPsK>(BLACK) };
|
||||||
|
ScalingFunction<KQKRPs> ScaleKQKRPs[] = { ScalingFunction<KQKRPs>(WHITE), ScalingFunction<KQKRPs>(BLACK) };
|
||||||
|
ScalingFunction<KPsK> ScaleKPsK[] = { ScalingFunction<KPsK>(WHITE), ScalingFunction<KPsK>(BLACK) };
|
||||||
|
ScalingFunction<KPKP> ScaleKPKP[] = { ScalingFunction<KPKP>(WHITE), ScalingFunction<KPKP>(BLACK) };
|
||||||
|
|
||||||
|
// Helper templates used to detect a given material distribution
|
||||||
|
template<Color Us> bool is_KXK(const Position& pos) {
|
||||||
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
return pos.non_pawn_material(Them) == Value(0)
|
||||||
|
&& pos.piece_count(Them, PAWN) == 0
|
||||||
|
&& pos.non_pawn_material(Us) >= RookValueMidgame;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<Color Us> bool is_KBPsK(const Position& pos) {
|
||||||
|
return pos.non_pawn_material(Us) == BishopValueMidgame
|
||||||
|
&& pos.piece_count(Us, BISHOP) == 1
|
||||||
|
&& pos.piece_count(Us, PAWN) >= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<Color Us> bool is_KQKRPs(const Position& pos) {
|
||||||
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
return pos.piece_count(Us, PAWN) == 0
|
||||||
|
&& pos.non_pawn_material(Us) == QueenValueMidgame
|
||||||
|
&& pos.piece_count(Us, QUEEN) == 1
|
||||||
|
&& pos.piece_count(Them, ROOK) == 1
|
||||||
|
&& pos.piece_count(Them, PAWN) >= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,6 +157,22 @@ MaterialInfoTable::~MaterialInfoTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// MaterialInfoTable::game_phase() calculates the phase given the current
|
||||||
|
/// position. Because the phase is strictly a function of the material, it
|
||||||
|
/// is stored in MaterialInfo.
|
||||||
|
|
||||||
|
Phase MaterialInfoTable::game_phase(const Position& pos) {
|
||||||
|
|
||||||
|
Value npm = pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK);
|
||||||
|
|
||||||
|
if (npm >= MidgameLimit)
|
||||||
|
return PHASE_MIDGAME;
|
||||||
|
else if (npm <= EndgameLimit)
|
||||||
|
return PHASE_ENDGAME;
|
||||||
|
|
||||||
|
return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
|
||||||
|
}
|
||||||
|
|
||||||
/// MaterialInfoTable::get_material_info() takes a position object as input,
|
/// MaterialInfoTable::get_material_info() takes a position object as input,
|
||||||
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
|
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
|
||||||
/// If the material configuration is not already present in the table, it
|
/// If the material configuration is not already present in the table, it
|
||||||
@@ -151,24 +195,18 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
mi->clear();
|
mi->clear();
|
||||||
mi->key = key;
|
mi->key = key;
|
||||||
|
|
||||||
|
// Store game phase
|
||||||
|
mi->gamePhase = MaterialInfoTable::game_phase(pos);
|
||||||
|
|
||||||
// Let's look if we have a specialized evaluation function for this
|
// Let's look if we have a specialized evaluation function for this
|
||||||
// particular material configuration. First we look for a fixed
|
// particular material configuration. First we look for a fixed
|
||||||
// configuration one, then a generic one if previous search failed.
|
// configuration one, then a generic one if previous search failed.
|
||||||
if ((mi->evaluationFunction = funcs->get<EF>(key)) != NULL)
|
if ((mi->evaluationFunction = funcs->get<EF>(key)) != NULL)
|
||||||
return mi;
|
return mi;
|
||||||
|
|
||||||
else if ( pos.non_pawn_material(BLACK) == Value(0)
|
else if (is_KXK<WHITE>(pos) || is_KXK<BLACK>(pos))
|
||||||
&& pos.piece_count(BLACK, PAWN) == 0
|
|
||||||
&& pos.non_pawn_material(WHITE) >= RookValueMidgame)
|
|
||||||
{
|
{
|
||||||
mi->evaluationFunction = &EvaluateKXK;
|
mi->evaluationFunction = is_KXK<WHITE>(pos) ? &EvaluateKXK[WHITE] : &EvaluateKXK[BLACK];
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if ( pos.non_pawn_material(WHITE) == Value(0)
|
|
||||||
&& pos.piece_count(WHITE, PAWN) == 0
|
|
||||||
&& pos.non_pawn_material(BLACK) >= RookValueMidgame)
|
|
||||||
{
|
|
||||||
mi->evaluationFunction = &EvaluateKKX;
|
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
else if ( pos.pieces(PAWN) == EmptyBoardBB
|
else if ( pos.pieces(PAWN) == EmptyBoardBB
|
||||||
@@ -183,7 +221,7 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
if ( pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
|
if ( pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
|
||||||
&& pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
|
&& pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
|
||||||
{
|
{
|
||||||
mi->evaluationFunction = &EvaluateKmmKm;
|
mi->evaluationFunction = &EvaluateKmmKm[WHITE];
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,10 +229,8 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
// OK, we didn't find any special evaluation function for the current
|
// OK, we didn't find any special evaluation function for the current
|
||||||
// material configuration. Is there a suitable scaling function?
|
// material configuration. Is there a suitable scaling function?
|
||||||
//
|
//
|
||||||
// The code below is rather messy, and it could easily get worse later,
|
// We face problems when there are several conflicting applicable
|
||||||
// if we decide to add more special cases. We face problems when there
|
// scaling functions and we need to decide which one to use.
|
||||||
// are several conflicting applicable scaling functions and we need to
|
|
||||||
// decide which one to use.
|
|
||||||
SF* sf;
|
SF* sf;
|
||||||
|
|
||||||
if ((sf = funcs->get<SF>(key)) != NULL)
|
if ((sf = funcs->get<SF>(key)) != NULL)
|
||||||
@@ -206,48 +242,36 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
// Generic scaling functions that refer to more then one material
|
// Generic scaling functions that refer to more then one material
|
||||||
// distribution. Should be probed after the specialized ones.
|
// distribution. Should be probed after the specialized ones.
|
||||||
// Note that these ones don't return after setting the function.
|
// Note that these ones don't return after setting the function.
|
||||||
if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
|
if (is_KBPsK<WHITE>(pos))
|
||||||
&& pos.piece_count(WHITE, BISHOP) == 1
|
mi->scalingFunction[WHITE] = &ScaleKBPsK[WHITE];
|
||||||
&& pos.piece_count(WHITE, PAWN) >= 1)
|
|
||||||
mi->scalingFunction[WHITE] = &ScaleKBPsK;
|
|
||||||
|
|
||||||
if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
|
if (is_KBPsK<BLACK>(pos))
|
||||||
&& pos.piece_count(BLACK, BISHOP) == 1
|
mi->scalingFunction[BLACK] = &ScaleKBPsK[BLACK];
|
||||||
&& pos.piece_count(BLACK, PAWN) >= 1)
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKKBPs;
|
|
||||||
|
|
||||||
if ( pos.piece_count(WHITE, PAWN) == 0
|
if (is_KQKRPs<WHITE>(pos))
|
||||||
&& pos.non_pawn_material(WHITE) == QueenValueMidgame
|
mi->scalingFunction[WHITE] = &ScaleKQKRPs[WHITE];
|
||||||
&& pos.piece_count(WHITE, QUEEN) == 1
|
|
||||||
&& pos.piece_count(BLACK, ROOK) == 1
|
|
||||||
&& pos.piece_count(BLACK, PAWN) >= 1)
|
|
||||||
mi->scalingFunction[WHITE] = &ScaleKQKRPs;
|
|
||||||
|
|
||||||
else if ( pos.piece_count(BLACK, PAWN) == 0
|
else if (is_KQKRPs<BLACK>(pos))
|
||||||
&& pos.non_pawn_material(BLACK) == QueenValueMidgame
|
mi->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
|
||||||
&& pos.piece_count(BLACK, QUEEN) == 1
|
|
||||||
&& pos.piece_count(WHITE, ROOK) == 1
|
|
||||||
&& pos.piece_count(WHITE, PAWN) >= 1)
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKRPsKQ;
|
|
||||||
|
|
||||||
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
|
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
|
||||||
{
|
{
|
||||||
if (pos.piece_count(BLACK, PAWN) == 0)
|
if (pos.piece_count(BLACK, PAWN) == 0)
|
||||||
{
|
{
|
||||||
assert(pos.piece_count(WHITE, PAWN) >= 2);
|
assert(pos.piece_count(WHITE, PAWN) >= 2);
|
||||||
mi->scalingFunction[WHITE] = &ScaleKPsK;
|
mi->scalingFunction[WHITE] = &ScaleKPsK[WHITE];
|
||||||
}
|
}
|
||||||
else if (pos.piece_count(WHITE, PAWN) == 0)
|
else if (pos.piece_count(WHITE, PAWN) == 0)
|
||||||
{
|
{
|
||||||
assert(pos.piece_count(BLACK, PAWN) >= 2);
|
assert(pos.piece_count(BLACK, PAWN) >= 2);
|
||||||
mi->scalingFunction[BLACK] = &ScaleKKPs;
|
mi->scalingFunction[BLACK] = &ScaleKPsK[BLACK];
|
||||||
}
|
}
|
||||||
else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
|
else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
|
||||||
{
|
{
|
||||||
// This is a special case because we set scaling functions
|
// This is a special case because we set scaling functions
|
||||||
// for both colors instead of only one.
|
// for both colors instead of only one.
|
||||||
mi->scalingFunction[WHITE] = &ScaleKPKPw;
|
mi->scalingFunction[WHITE] = &ScaleKPKP[WHITE];
|
||||||
mi->scalingFunction[BLACK] = &ScaleKPKPb;
|
mi->scalingFunction[BLACK] = &ScaleKPKP[BLACK];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,8 +293,8 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
{ pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
|
{ pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
|
||||||
pos.piece_count(BLACK, BISHOP), pos.piece_count(BLACK, ROOK), pos.piece_count(BLACK, QUEEN) } };
|
pos.piece_count(BLACK, BISHOP), pos.piece_count(BLACK, ROOK), pos.piece_count(BLACK, QUEEN) } };
|
||||||
Color c, them;
|
Color c, them;
|
||||||
int sign;
|
int sign, pt1, pt2, pc;
|
||||||
int matValue = 0;
|
int v, vv, matValue = 0;
|
||||||
|
|
||||||
for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
|
for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
|
||||||
{
|
{
|
||||||
@@ -304,25 +328,27 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);
|
matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);
|
||||||
|
|
||||||
them = opposite_color(c);
|
them = opposite_color(c);
|
||||||
|
v = 0;
|
||||||
|
|
||||||
// Second-degree polynomial material imbalance by Tord Romstad
|
// Second-degree polynomial material imbalance by Tord Romstad
|
||||||
//
|
//
|
||||||
// We use NO_PIECE_TYPE as a place holder for the bishop pair "extended piece",
|
// We use NO_PIECE_TYPE as a place holder for the bishop pair "extended piece",
|
||||||
// this allow us to be more flexible in defining bishop pair bonuses.
|
// this allow us to be more flexible in defining bishop pair bonuses.
|
||||||
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
for (pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
||||||
{
|
{
|
||||||
int c1 = sign * pieceCount[c][pt1];
|
pc = pieceCount[c][pt1];
|
||||||
if (!c1)
|
if (!pc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
matValue += c1 * LinearCoefficients[pt1];
|
vv = LinearCoefficients[pt1];
|
||||||
|
|
||||||
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
|
for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
|
||||||
{
|
vv += pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2]
|
||||||
matValue += c1 * pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2];
|
+ pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];
|
||||||
matValue += c1 * pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];
|
|
||||||
}
|
v += pc * vv;
|
||||||
}
|
}
|
||||||
|
matValue += sign * v;
|
||||||
}
|
}
|
||||||
mi->value = int16_t(matValue / 16);
|
mi->value = int16_t(matValue / 16);
|
||||||
return mi;
|
return mi;
|
||||||
@@ -348,7 +374,6 @@ EndgameFunctions::EndgameFunctions() {
|
|||||||
add<ScalingFunction<KBPPKB> >("KBPPKB");
|
add<ScalingFunction<KBPPKB> >("KBPPKB");
|
||||||
add<ScalingFunction<KBPKN> >("KBPKN");
|
add<ScalingFunction<KBPKN> >("KBPKN");
|
||||||
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||||
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EndgameFunctions::~EndgameFunctions() {
|
EndgameFunctions::~EndgameFunctions() {
|
||||||
@@ -378,7 +403,7 @@ Key EndgameFunctions::buildKey(const string& keyCode) {
|
|||||||
s << char(upcase? toupper(keyCode[i]) : tolower(keyCode[i]));
|
s << char(upcase? toupper(keyCode[i]) : tolower(keyCode[i]));
|
||||||
}
|
}
|
||||||
s << 8 - keyCode.length() << "/8/8/8/8/8/8/8 w -";
|
s << 8 - keyCode.length() << "/8/8/8/8/8/8/8 w -";
|
||||||
return Position(s.str()).get_material_key();
|
return Position(s.str(), 0).get_material_key();
|
||||||
}
|
}
|
||||||
|
|
||||||
const string EndgameFunctions::swapColors(const string& keyCode) {
|
const string EndgameFunctions::swapColors(const string& keyCode) {
|
||||||
|
|||||||
+17
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -51,9 +51,10 @@ class MaterialInfo {
|
|||||||
public:
|
public:
|
||||||
MaterialInfo() : key(0) { clear(); }
|
MaterialInfo() : key(0) { clear(); }
|
||||||
|
|
||||||
Value material_value() const;
|
Score material_value() const;
|
||||||
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
||||||
int space_weight() const;
|
int space_weight() const;
|
||||||
|
Phase game_phase() const;
|
||||||
bool specialized_eval_exists() const;
|
bool specialized_eval_exists() const;
|
||||||
Value evaluate(const Position& pos) const;
|
Value evaluate(const Position& pos) const;
|
||||||
|
|
||||||
@@ -66,6 +67,7 @@ private:
|
|||||||
EndgameEvaluationFunctionBase* evaluationFunction;
|
EndgameEvaluationFunctionBase* evaluationFunction;
|
||||||
EndgameScalingFunctionBase* scalingFunction[2];
|
EndgameScalingFunctionBase* scalingFunction[2];
|
||||||
int spaceWeight;
|
int spaceWeight;
|
||||||
|
Phase gamePhase;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
||||||
@@ -81,6 +83,8 @@ public:
|
|||||||
~MaterialInfoTable();
|
~MaterialInfoTable();
|
||||||
MaterialInfo* get_material_info(const Position& pos);
|
MaterialInfo* get_material_info(const Position& pos);
|
||||||
|
|
||||||
|
static Phase game_phase(const Position& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned size;
|
unsigned size;
|
||||||
MaterialInfo* entries;
|
MaterialInfo* entries;
|
||||||
@@ -92,12 +96,13 @@ private:
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
||||||
/// MaterialInfo::material_value simply returns the material balance
|
/// MaterialInfo::material_value simply returns the material balance
|
||||||
/// evaluation that is independent from game phase.
|
/// evaluation that is independent from game phase.
|
||||||
|
|
||||||
inline Value MaterialInfo::material_value() const {
|
inline Score MaterialInfo::material_value() const {
|
||||||
|
|
||||||
return Value(value);
|
return make_score(value, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,6 +146,14 @@ inline int MaterialInfo::space_weight() const {
|
|||||||
return spaceWeight;
|
return spaceWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// MaterialInfo::game_phase() returns the game phase according
|
||||||
|
/// to this material configuration.
|
||||||
|
|
||||||
|
inline Phase MaterialInfo::game_phase() const {
|
||||||
|
|
||||||
|
return gamePhase;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MaterialInfo::specialized_eval_exists decides whether there is a
|
/// MaterialInfo::specialized_eval_exists decides whether there is a
|
||||||
/// specialized evaluation function for the current material configuration,
|
/// specialized evaluation function for the current material configuration,
|
||||||
|
|||||||
+84
-62
@@ -41,93 +41,110 @@
|
|||||||
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "mersenne.h"
|
#include "mersenne.h"
|
||||||
|
|
||||||
/* Period parameters */
|
namespace {
|
||||||
#define N 624
|
|
||||||
#define M 397
|
|
||||||
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
|
|
||||||
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
|
|
||||||
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
|
|
||||||
|
|
||||||
static unsigned long mt[N]; /* the array for the state vector */
|
// Period parameters
|
||||||
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
|
const int N = 624;
|
||||||
|
const int M = 397;
|
||||||
|
const unsigned long MATRIX_A = 0x9908b0dfUL; // Constant vector a
|
||||||
|
const unsigned long UPPER_MASK = 0x80000000UL; // Most significant w-r bits
|
||||||
|
const unsigned long LOWER_MASK = 0x7fffffffUL; // Least significant r bits
|
||||||
|
|
||||||
|
unsigned long mt[N]; // The array for the state vector
|
||||||
|
int mti = N + 1; // mti == N+1 means mt[N] is not initialized
|
||||||
|
|
||||||
|
// Initializes mt[N] with a seed
|
||||||
|
void init_genrand(unsigned long s) {
|
||||||
|
|
||||||
/* initializes mt[N] with a seed */
|
|
||||||
static void init_genrand(unsigned long s)
|
|
||||||
{
|
|
||||||
mt[0]= s & 0xffffffffUL;
|
mt[0]= s & 0xffffffffUL;
|
||||||
for (mti=1; mti<N; mti++) {
|
for (mti = 1; mti < N; mti++)
|
||||||
mt[mti] =
|
{
|
||||||
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
|
// See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier.
|
||||||
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
// In the previous versions, MSBs of the seed affect
|
||||||
/* In the previous versions, MSBs of the seed affect */
|
// only MSBs of the array mt[].
|
||||||
/* only MSBs of the array mt[]. */
|
// 2002/01/09 modified by Makoto Matsumoto
|
||||||
/* 2002/01/09 modified by Makoto Matsumoto */
|
mt[mti] = 1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti;
|
||||||
mt[mti] &= 0xffffffffUL;
|
mt[mti] &= 0xffffffffUL; // For > 32 bit machines
|
||||||
/* for >32 bit machines */
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize by an array with array-length */
|
// Initialize by an array with array-length
|
||||||
/* init_key is the array for initializing keys */
|
// init_key is the array for initializing keys
|
||||||
/* key_length is its length */
|
// key_length is its length
|
||||||
/* slight change for C++, 2004/2/26 */
|
// slight change for C++, 2004/2/26
|
||||||
static void init_by_array(unsigned long init_key[], int key_length)
|
void init_by_array(unsigned long init_key[], int key_length) {
|
||||||
{
|
|
||||||
int i, j, k;
|
int i = 1;
|
||||||
|
int j = 0;
|
||||||
|
int k = (N > key_length ? N : key_length);
|
||||||
|
|
||||||
init_genrand(19650218UL);
|
init_genrand(19650218UL);
|
||||||
i=1; j=0;
|
|
||||||
k = (N>key_length ? N : key_length);
|
for ( ; k; k--)
|
||||||
for (; k; k--) {
|
{
|
||||||
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
|
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL)) + init_key[j] + j; // Non linear
|
||||||
+ init_key[j] + j; /* non linear */
|
mt[i] &= 0xffffffffUL; // For WORDSIZE > 32 machines
|
||||||
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
|
||||||
i++; j++;
|
i++; j++;
|
||||||
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
if (i >= N)
|
||||||
if (j>=key_length) j=0;
|
{
|
||||||
|
mt[0] = mt[N-1];
|
||||||
|
i = 1;
|
||||||
}
|
}
|
||||||
for (k=N-1; k; k--) {
|
if (j >= key_length)
|
||||||
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
|
j = 0;
|
||||||
- i; /* non linear */
|
}
|
||||||
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
for (k = N-1; k; k--)
|
||||||
|
{
|
||||||
|
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) - i; // Non linear
|
||||||
|
mt[i] &= 0xffffffffUL; // For WORDSIZE > 32 machines
|
||||||
i++;
|
i++;
|
||||||
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
if (i >= N)
|
||||||
|
{
|
||||||
|
mt[0] = mt[N-1];
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mt[0] = 0x80000000UL; // MSB is 1; assuring non-zero initial array
|
||||||
}
|
}
|
||||||
|
|
||||||
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
|
} // namespace
|
||||||
}
|
|
||||||
|
|
||||||
|
// Generates a random number on [0,0xffffffff]-interval
|
||||||
|
uint32_t genrand_int32() {
|
||||||
|
|
||||||
/* generates a random number on [0,0xffffffff]-interval */
|
|
||||||
uint32_t genrand_int32(void) {
|
|
||||||
unsigned long y;
|
unsigned long y;
|
||||||
static unsigned long mag01[2]={0x0UL, MATRIX_A};
|
static unsigned long mag01[2] = {0x0UL, MATRIX_A};
|
||||||
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
||||||
|
|
||||||
if (mti >= N) { /* generate N words at one time */
|
// Generate N words at one time
|
||||||
|
if (mti >= N)
|
||||||
|
{
|
||||||
int kk;
|
int kk;
|
||||||
|
|
||||||
if (mti == N+1) /* if init_genrand() has not been called, */
|
if (mti == N+1) // If init_genrand() has not been called,
|
||||||
init_genrand(5489UL); /* a default initial seed is used */
|
init_genrand(5489UL); // a default initial seed is used.
|
||||||
|
|
||||||
for (kk=0;kk<N-M;kk++) {
|
for (kk = 0; kk < N-M; kk++)
|
||||||
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
{
|
||||||
|
y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
|
||||||
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||||
}
|
}
|
||||||
for (;kk<N-1;kk++) {
|
for ( ; kk < N-1; kk++)
|
||||||
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
{
|
||||||
|
y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
|
||||||
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||||
}
|
}
|
||||||
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
|
y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
|
||||||
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||||
|
|
||||||
mti = 0;
|
mti = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
y = mt[mti++];
|
y = mt[mti++];
|
||||||
|
|
||||||
/* Tempering */
|
// Tempering
|
||||||
y ^= (y >> 11);
|
y ^= (y >> 11);
|
||||||
y ^= (y << 7) & 0x9d2c5680UL;
|
y ^= (y << 7) & 0x9d2c5680UL;
|
||||||
y ^= (y << 15) & 0xefc60000UL;
|
y ^= (y << 15) & 0xefc60000UL;
|
||||||
@@ -136,14 +153,19 @@ uint32_t genrand_int32(void) {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t genrand_int64(void) {
|
uint64_t genrand_int64() {
|
||||||
|
|
||||||
uint64_t x, y;
|
uint64_t x, y;
|
||||||
|
|
||||||
x = genrand_int32(); y = genrand_int32();
|
x = genrand_int32();
|
||||||
return (x<<32)|y;
|
y = genrand_int32();
|
||||||
|
return (x << 32) | y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_mersenne(void) {
|
void init_mersenne() {
|
||||||
unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4;
|
|
||||||
|
unsigned long init[4] = {0x123, 0x234, 0x345, 0x456};
|
||||||
|
unsigned long length = 4;
|
||||||
|
|
||||||
init_by_array(init, length);
|
init_by_array(init, length);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -32,9 +32,9 @@
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern uint32_t genrand_int32(void);
|
extern uint32_t genrand_int32();
|
||||||
extern uint64_t genrand_int64(void);
|
extern uint64_t genrand_int64();
|
||||||
extern void init_mersenne(void);
|
extern void init_mersenne();
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(MERSENNE_H_INCLUDED)
|
#endif // !defined(MERSENNE_H_INCLUDED)
|
||||||
|
|||||||
+44
-5
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,6 +27,9 @@
|
|||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
# if defined(__hpux)
|
||||||
|
# include <sys/pstat.h>
|
||||||
|
# endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -36,6 +39,10 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(NO_PREFETCH)
|
||||||
|
# include <xmmintrin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -44,13 +51,14 @@
|
|||||||
|
|
||||||
#include "bitcount.h"
|
#include "bitcount.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/// Version number. If this is left empty, the current date (in the format
|
/// Version number. If this is left empty, the current date (in the format
|
||||||
/// YYMMDD) is used as a version number.
|
/// YYMMDD) is used as a version number.
|
||||||
|
|
||||||
static const string EngineVersion = "1.5";
|
static const string EngineVersion = "1.8 beta 2";
|
||||||
static const string AppName = "Stockfish";
|
static const string AppName = "Stockfish";
|
||||||
static const string AppTag = "";
|
static const string AppTag = "";
|
||||||
|
|
||||||
@@ -143,7 +151,7 @@ const string engine_name() {
|
|||||||
const string cpu64(CpuHas64BitPath ? " 64bit" : "");
|
const string cpu64(CpuHas64BitPath ? " 64bit" : "");
|
||||||
|
|
||||||
if (!EngineVersion.empty())
|
if (!EngineVersion.empty())
|
||||||
return AppName+ " " + EngineVersion + cpu64;
|
return AppName + " " + EngineVersion + cpu64;
|
||||||
|
|
||||||
string date(__DATE__); // From compiler, format is "Sep 21 2008"
|
string date(__DATE__); // From compiler, format is "Sep 21 2008"
|
||||||
string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
|
string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
|
||||||
@@ -185,7 +193,15 @@ int get_system_time() {
|
|||||||
|
|
||||||
# if defined(_SC_NPROCESSORS_ONLN)
|
# if defined(_SC_NPROCESSORS_ONLN)
|
||||||
int cpu_count() {
|
int cpu_count() {
|
||||||
return Min(sysconf(_SC_NPROCESSORS_ONLN), 8);
|
return Min(sysconf(_SC_NPROCESSORS_ONLN), MAX_THREADS);
|
||||||
|
}
|
||||||
|
# elif defined(__hpux)
|
||||||
|
int cpu_count() {
|
||||||
|
struct pst_dynamic psd;
|
||||||
|
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) == -1)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return Min(psd.psd_proc_cnt, MAX_THREADS);
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
int cpu_count() {
|
int cpu_count() {
|
||||||
@@ -198,7 +214,7 @@ int cpu_count() {
|
|||||||
int cpu_count() {
|
int cpu_count() {
|
||||||
SYSTEM_INFO s;
|
SYSTEM_INFO s;
|
||||||
GetSystemInfo(&s);
|
GetSystemInfo(&s);
|
||||||
return Min(s.dwNumberOfProcessors, 8);
|
return Min(s.dwNumberOfProcessors, MAX_THREADS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -275,4 +291,27 @@ int Bioskey()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// prefetch() preloads the given address in L1/L2 cache. This is a non
|
||||||
|
/// blocking function and do not stalls the CPU waiting for data to be
|
||||||
|
/// loaded from RAM, that can be very slow.
|
||||||
|
#if defined(NO_PREFETCH)
|
||||||
|
void prefetch(char*) {}
|
||||||
|
#else
|
||||||
|
|
||||||
|
void prefetch(char* addr) {
|
||||||
|
|
||||||
|
#if defined(__INTEL_COMPILER) || defined(__ICL)
|
||||||
|
// This hack prevents prefetches to be optimized away by
|
||||||
|
// Intel compiler. Both MSVC and gcc seems not affected.
|
||||||
|
__asm__ ("");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_mm_prefetch(addr, _MM_HINT_T2);
|
||||||
|
_mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -55,6 +55,7 @@ extern const std::string engine_name();
|
|||||||
extern int get_system_time();
|
extern int get_system_time();
|
||||||
extern int cpu_count();
|
extern int cpu_count();
|
||||||
extern int Bioskey();
|
extern int Bioskey();
|
||||||
|
extern void prefetch(char* addr);
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+80
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -62,9 +62,83 @@ struct MoveStack {
|
|||||||
int score;
|
int score;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note that operator< is set up such that std::sort() will sort in descending order
|
// Note that operator< is set up such that sorting will be in descending order
|
||||||
inline bool operator<(const MoveStack& f, const MoveStack& s) { return s.score < f.score; }
|
inline bool operator<(const MoveStack& f, const MoveStack& s) { return s.score < f.score; }
|
||||||
|
|
||||||
|
// An helper insertion sort implementation
|
||||||
|
template<typename T>
|
||||||
|
inline void insertion_sort(T* firstMove, T* lastMove)
|
||||||
|
{
|
||||||
|
T value;
|
||||||
|
T *cur, *p, *d;
|
||||||
|
|
||||||
|
if (firstMove != lastMove)
|
||||||
|
for (cur = firstMove + 1; cur != lastMove; cur++)
|
||||||
|
{
|
||||||
|
p = d = cur;
|
||||||
|
value = *p--;
|
||||||
|
if (value < *p)
|
||||||
|
{
|
||||||
|
do *d = *p;
|
||||||
|
while (--d != firstMove && value < *--p);
|
||||||
|
*d = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Our dedicated sort in range [firstMove, lastMove), first splits
|
||||||
|
// positive scores from ramining then order seaprately the two sets.
|
||||||
|
template<typename T>
|
||||||
|
inline void sort_moves(T* firstMove, T* lastMove, T** lastPositive)
|
||||||
|
{
|
||||||
|
T tmp;
|
||||||
|
T *p, *d;
|
||||||
|
|
||||||
|
d = lastMove;
|
||||||
|
p = firstMove - 1;
|
||||||
|
|
||||||
|
d->score = -1; // right guard
|
||||||
|
|
||||||
|
// Split positives vs non-positives
|
||||||
|
do {
|
||||||
|
while ((++p)->score > 0) {}
|
||||||
|
|
||||||
|
if (p != d)
|
||||||
|
{
|
||||||
|
while (--d != p && d->score <= 0) {}
|
||||||
|
|
||||||
|
tmp = *p;
|
||||||
|
*p = *d;
|
||||||
|
*d = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (p != d);
|
||||||
|
|
||||||
|
// Sort just positive scored moves, remaining only when we get there
|
||||||
|
insertion_sort<T>(firstMove, p);
|
||||||
|
*lastPositive = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Picks up the best move in range [curMove, lastMove), one per cycle.
|
||||||
|
// It is faster then sorting all the moves in advance when moves are few,
|
||||||
|
// as normally are the possible captures. Note that is not a stable alghoritm.
|
||||||
|
template<typename T>
|
||||||
|
inline T pick_best(T* curMove, T* lastMove)
|
||||||
|
{
|
||||||
|
T bestMove, tmp;
|
||||||
|
|
||||||
|
bestMove = *curMove;
|
||||||
|
while (++curMove != lastMove)
|
||||||
|
{
|
||||||
|
if (*curMove < bestMove)
|
||||||
|
{
|
||||||
|
tmp = *curMove;
|
||||||
|
*curMove = bestMove;
|
||||||
|
bestMove = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestMove;
|
||||||
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Inline functions
|
//// Inline functions
|
||||||
@@ -82,6 +156,10 @@ inline PieceType move_promotion_piece(Move m) {
|
|||||||
return PieceType((int(m) >> 12) & 7);
|
return PieceType((int(m) >> 12) & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int move_is_special(Move m) {
|
||||||
|
return m & (0x1F << 12);
|
||||||
|
}
|
||||||
|
|
||||||
inline int move_is_promotion(Move m) {
|
inline int move_is_promotion(Move m) {
|
||||||
return m & (7 << 12);
|
return m & (7 << 12);
|
||||||
}
|
}
|
||||||
|
|||||||
+233
-314
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -52,16 +52,12 @@ namespace {
|
|||||||
EVASION
|
EVASION
|
||||||
};
|
};
|
||||||
|
|
||||||
// Functions
|
|
||||||
bool castling_is_check(const Position&, CastlingSide);
|
|
||||||
|
|
||||||
// Helper templates
|
// Helper templates
|
||||||
template<CastlingSide Side>
|
template<CastlingSide Side>
|
||||||
MoveStack* generate_castle_moves(const Position&, MoveStack*);
|
MoveStack* generate_castle_moves(const Position&, MoveStack*);
|
||||||
|
|
||||||
template<Color Us, MoveType Type>
|
template<Color Us, MoveType Type>
|
||||||
MoveStack* generate_pawn_moves(const Position&, MoveStack*, Bitboard = EmptyBoardBB,
|
MoveStack* generate_pawn_moves(const Position&, MoveStack*, Bitboard, Square);
|
||||||
Square = SQ_NONE, Bitboard = EmptyBoardBB);
|
|
||||||
|
|
||||||
// Template generate_piece_moves (captures and non-captures) with specializations and overloads
|
// Template generate_piece_moves (captures and non-captures) with specializations and overloads
|
||||||
template<PieceType>
|
template<PieceType>
|
||||||
@@ -71,37 +67,29 @@ namespace {
|
|||||||
MoveStack* generate_piece_moves<KING>(const Position&, MoveStack*, Color, Bitboard);
|
MoveStack* generate_piece_moves<KING>(const Position&, MoveStack*, Color, Bitboard);
|
||||||
|
|
||||||
template<PieceType Piece, MoveType Type>
|
template<PieceType Piece, MoveType Type>
|
||||||
inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us) {
|
inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) {
|
||||||
|
|
||||||
assert(Piece == PAWN);
|
assert(Piece == PAWN);
|
||||||
assert(Type == CAPTURE || Type == NON_CAPTURE);
|
assert(Type == CAPTURE || Type == NON_CAPTURE || Type == EVASION);
|
||||||
|
|
||||||
return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m)
|
return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m, t, SQ_NONE)
|
||||||
: generate_pawn_moves<BLACK, Type>(p, m));
|
: generate_pawn_moves<BLACK, Type>(p, m, t, SQ_NONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template generate_piece_checks with specializations
|
// Templates for non-capture checks generation
|
||||||
|
|
||||||
|
template<PieceType Piece>
|
||||||
|
MoveStack* generate_discovered_checks(const Position&, MoveStack*, Square);
|
||||||
|
|
||||||
template<PieceType>
|
template<PieceType>
|
||||||
MoveStack* generate_piece_checks(const Position&, MoveStack*, Color, Bitboard, Square);
|
MoveStack* generate_direct_checks(const Position&, MoveStack*, Color, Bitboard, Square);
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline MoveStack* generate_piece_checks<PAWN>(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) {
|
inline MoveStack* generate_direct_checks<PAWN>(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) {
|
||||||
|
|
||||||
return (us == WHITE ? generate_pawn_moves<WHITE, CHECK>(p, m, dc, ksq)
|
return (us == WHITE ? generate_pawn_moves<WHITE, CHECK>(p, m, dc, ksq)
|
||||||
: generate_pawn_moves<BLACK, CHECK>(p, m, dc, ksq));
|
: generate_pawn_moves<BLACK, CHECK>(p, m, dc, ksq));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template generate_piece_evasions with specializations
|
|
||||||
template<PieceType>
|
|
||||||
MoveStack* generate_piece_evasions(const Position&, MoveStack*, Color, Bitboard, Bitboard);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline MoveStack* generate_piece_evasions<PAWN>(const Position& p, MoveStack* m,
|
|
||||||
Color us, Bitboard t, Bitboard pnd) {
|
|
||||||
|
|
||||||
return (us == WHITE ? generate_pawn_moves<WHITE, EVASION>(p, m, pnd, SQ_NONE, t)
|
|
||||||
: generate_pawn_moves<BLACK, EVASION>(p, m, pnd, SQ_NONE, t));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,7 +113,7 @@ MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
|
|||||||
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
||||||
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
||||||
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
||||||
mlist = generate_piece_moves<PAWN, CAPTURE>(pos, mlist, us);
|
mlist = generate_piece_moves<PAWN, CAPTURE>(pos, mlist, us, target);
|
||||||
return generate_piece_moves<KING>(pos, mlist, us, target);
|
return generate_piece_moves<KING>(pos, mlist, us, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +129,7 @@ MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
|
|||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Bitboard target = pos.empty_squares();
|
Bitboard target = pos.empty_squares();
|
||||||
|
|
||||||
mlist = generate_piece_moves<PAWN, NON_CAPTURE>(pos, mlist, us);
|
mlist = generate_piece_moves<PAWN, NON_CAPTURE>(pos, mlist, us, target);
|
||||||
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
||||||
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
||||||
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
||||||
@@ -152,175 +140,111 @@ MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// generate_non_capture_checks() generates all pseudo-legal non-captures and
|
/// generate_non_capture_checks() generates all pseudo-legal non-captures and knight
|
||||||
/// underpromotions that give check. Returns a pointer to the end of the move list.
|
/// underpromotions that give check. Returns a pointer to the end of the move list.
|
||||||
|
|
||||||
MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
|
MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(!pos.is_check());
|
assert(!pos.is_check());
|
||||||
|
|
||||||
|
Bitboard b, dc;
|
||||||
|
Square from;
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Square ksq = pos.king_square(opposite_color(us));
|
Square ksq = pos.king_square(opposite_color(us));
|
||||||
|
|
||||||
assert(pos.piece_on(ksq) == piece_of_color_and_type(opposite_color(us), KING));
|
assert(pos.piece_on(ksq) == piece_of_color_and_type(opposite_color(us), KING));
|
||||||
|
|
||||||
// Pieces moves
|
// Discovered non-capture checks
|
||||||
mlist = generate_piece_checks<PAWN>(pos, mlist, us, dc, ksq);
|
b = dc = pos.discovered_check_candidates(us);
|
||||||
mlist = generate_piece_checks<KNIGHT>(pos, mlist, us, dc, ksq);
|
|
||||||
mlist = generate_piece_checks<BISHOP>(pos, mlist, us, dc, ksq);
|
|
||||||
mlist = generate_piece_checks<ROOK>(pos, mlist, us, dc, ksq);
|
|
||||||
mlist = generate_piece_checks<QUEEN>(pos, mlist, us, dc, ksq);
|
|
||||||
mlist = generate_piece_checks<KING>(pos, mlist, us, dc, ksq);
|
|
||||||
|
|
||||||
// Castling moves that give check. Very rare but nice to have!
|
while (b)
|
||||||
if ( pos.can_castle_queenside(us)
|
{
|
||||||
&& (square_rank(ksq) == square_rank(pos.king_square(us)) || square_file(ksq) == FILE_D)
|
from = pop_1st_bit(&b);
|
||||||
&& castling_is_check(pos, QUEEN_SIDE))
|
switch (pos.type_of_piece_on(from))
|
||||||
mlist = generate_castle_moves<QUEEN_SIDE>(pos, mlist);
|
{
|
||||||
|
case PAWN: /* Will be generated togheter with pawns direct checks */ break;
|
||||||
|
case KNIGHT: mlist = generate_discovered_checks<KNIGHT>(pos, mlist, from); break;
|
||||||
|
case BISHOP: mlist = generate_discovered_checks<BISHOP>(pos, mlist, from); break;
|
||||||
|
case ROOK: mlist = generate_discovered_checks<ROOK>(pos, mlist, from); break;
|
||||||
|
case KING: mlist = generate_discovered_checks<KING>(pos, mlist, from); break;
|
||||||
|
default: assert(false); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( pos.can_castle_kingside(us)
|
// Direct non-capture checks
|
||||||
&& (square_rank(ksq) == square_rank(pos.king_square(us)) || square_file(ksq) == FILE_F)
|
mlist = generate_direct_checks<PAWN>(pos, mlist, us, dc, ksq);
|
||||||
&& castling_is_check(pos, KING_SIDE))
|
mlist = generate_direct_checks<KNIGHT>(pos, mlist, us, dc, ksq);
|
||||||
mlist = generate_castle_moves<KING_SIDE>(pos, mlist);
|
mlist = generate_direct_checks<BISHOP>(pos, mlist, us, dc, ksq);
|
||||||
|
mlist = generate_direct_checks<ROOK>(pos, mlist, us, dc, ksq);
|
||||||
return mlist;
|
return generate_direct_checks<QUEEN>(pos, mlist, us, dc, ksq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// generate_evasions() generates all check evasions when the side to move is
|
/// generate_evasions() generates all pseudo-legal check evasions when
|
||||||
/// in check. Unlike the other move generation functions, this one generates
|
/// the side to move is in check. Returns a pointer to the end of the move list.
|
||||||
/// only legal moves. Returns a pointer to the end of the move list.
|
|
||||||
|
|
||||||
MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned) {
|
MoveStack* generate_evasions(const Position& pos, MoveStack* mlist) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(pos.is_check());
|
assert(pos.is_check());
|
||||||
|
|
||||||
Square from, to;
|
Bitboard b, target;
|
||||||
|
Square from, checksq;
|
||||||
|
int checkersCnt = 0;
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Color them = opposite_color(us);
|
|
||||||
Square ksq = pos.king_square(us);
|
Square ksq = pos.king_square(us);
|
||||||
Bitboard sliderAttacks = EmptyBoardBB;
|
|
||||||
Bitboard checkers = pos.checkers();
|
Bitboard checkers = pos.checkers();
|
||||||
|
Bitboard sliderAttacks = EmptyBoardBB;
|
||||||
|
|
||||||
assert(pos.piece_on(ksq) == piece_of_color_and_type(us, KING));
|
assert(pos.piece_on(ksq) == piece_of_color_and_type(us, KING));
|
||||||
|
assert(checkers);
|
||||||
// The bitboard of occupied pieces without our king
|
|
||||||
Bitboard b_noKing = pos.occupied_squares();
|
|
||||||
clear_bit(&b_noKing, ksq);
|
|
||||||
|
|
||||||
// Find squares attacked by slider checkers, we will remove
|
// Find squares attacked by slider checkers, we will remove
|
||||||
// them from the king evasions set so to avoid a couple
|
// them from the king evasions set so to early skip known
|
||||||
// of cycles in the slow king evasions legality check loop
|
// illegal moves and avoid an useless legality check later.
|
||||||
// and to be able to use attackers_to().
|
b = checkers;
|
||||||
Bitboard b = checkers & pos.pieces(BISHOP, QUEEN);
|
do
|
||||||
while (b)
|
|
||||||
{
|
{
|
||||||
from = pop_1st_bit(&b);
|
checkersCnt++;
|
||||||
sliderAttacks |= bishop_attacks_bb(from, b_noKing);
|
checksq = pop_1st_bit(&b);
|
||||||
}
|
|
||||||
|
|
||||||
b = checkers & pos.pieces(ROOK, QUEEN);
|
assert(pos.color_of_piece_on(checksq) == opposite_color(us));
|
||||||
while (b)
|
|
||||||
|
switch (pos.type_of_piece_on(checksq))
|
||||||
{
|
{
|
||||||
from = pop_1st_bit(&b);
|
case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break;
|
||||||
sliderAttacks |= rook_attacks_bb(from, b_noKing);
|
case ROOK: sliderAttacks |= RookPseudoAttacks[checksq]; break;
|
||||||
|
case QUEEN:
|
||||||
|
// In case of a queen remove also squares attacked in the other direction to
|
||||||
|
// avoid possible illegal moves when queen and king are on adjacent squares.
|
||||||
|
if (direction_is_straight(checksq, ksq))
|
||||||
|
sliderAttacks |= RookPseudoAttacks[checksq] | pos.attacks_from<BISHOP>(checksq);
|
||||||
|
else
|
||||||
|
sliderAttacks |= BishopPseudoAttacks[checksq] | pos.attacks_from<ROOK>(checksq);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
} while (b);
|
||||||
|
|
||||||
// Generate evasions for king, capture and non capture moves
|
// Generate evasions for king, capture and non capture moves
|
||||||
Bitboard enemy = pos.pieces_of_color(them);
|
b = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~sliderAttacks;
|
||||||
Bitboard b1 = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~sliderAttacks;
|
from = ksq;
|
||||||
while (b1)
|
SERIALIZE_MOVES(b);
|
||||||
{
|
|
||||||
// Note that we can use attackers_to() only because we have already
|
|
||||||
// removed from b1 the squares attacked by slider checkers.
|
|
||||||
to = pop_1st_bit(&b1);
|
|
||||||
if (!(pos.attackers_to(to) & enemy))
|
|
||||||
(*mlist++).move = make_move(ksq, to);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate evasions for other pieces only if not double check. We use a
|
// Generate evasions for other pieces only if not double check
|
||||||
// simple bit twiddling hack here rather than calling count_1s in order to
|
if (checkersCnt > 1)
|
||||||
// save some time (we know that pos.checkers() has at most two nonzero bits).
|
|
||||||
if (!(checkers & (checkers - 1))) // Only one bit set?
|
|
||||||
{
|
|
||||||
Square checksq = first_1(checkers);
|
|
||||||
|
|
||||||
assert(pos.color_of_piece_on(checksq) == them);
|
|
||||||
|
|
||||||
// Generate captures of the checking piece
|
|
||||||
|
|
||||||
// Pawn captures
|
|
||||||
b1 = pos.attacks_from<PAWN>(checksq, them) & pos.pieces(PAWN, us) & ~pinned;
|
|
||||||
while (b1)
|
|
||||||
{
|
|
||||||
from = pop_1st_bit(&b1);
|
|
||||||
if (relative_rank(us, checksq) == RANK_8)
|
|
||||||
{
|
|
||||||
(*mlist++).move = make_promotion_move(from, checksq, QUEEN);
|
|
||||||
(*mlist++).move = make_promotion_move(from, checksq, ROOK);
|
|
||||||
(*mlist++).move = make_promotion_move(from, checksq, BISHOP);
|
|
||||||
(*mlist++).move = make_promotion_move(from, checksq, KNIGHT);
|
|
||||||
} else
|
|
||||||
(*mlist++).move = make_move(from, checksq);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pieces captures
|
|
||||||
b1 = ( (pos.attacks_from<KNIGHT>(checksq) & pos.pieces(KNIGHT, us))
|
|
||||||
| (pos.attacks_from<BISHOP>(checksq) & pos.pieces(BISHOP, QUEEN, us))
|
|
||||||
| (pos.attacks_from<ROOK>(checksq) & pos.pieces(ROOK, QUEEN, us)) ) & ~pinned;
|
|
||||||
|
|
||||||
while (b1)
|
|
||||||
{
|
|
||||||
from = pop_1st_bit(&b1);
|
|
||||||
(*mlist++).move = make_move(from, checksq);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Blocking check evasions are possible only if the checking piece is a slider
|
|
||||||
if (sliderAttacks)
|
|
||||||
{
|
|
||||||
Bitboard blockSquares = squares_between(checksq, ksq);
|
|
||||||
|
|
||||||
assert((pos.occupied_squares() & blockSquares) == EmptyBoardBB);
|
|
||||||
|
|
||||||
if (blockSquares)
|
|
||||||
{
|
|
||||||
mlist = generate_piece_evasions<PAWN>(pos, mlist, us, blockSquares, pinned);
|
|
||||||
mlist = generate_piece_evasions<KNIGHT>(pos, mlist, us, blockSquares, pinned);
|
|
||||||
mlist = generate_piece_evasions<BISHOP>(pos, mlist, us, blockSquares, pinned);
|
|
||||||
mlist = generate_piece_evasions<ROOK>(pos, mlist, us, blockSquares, pinned);
|
|
||||||
mlist = generate_piece_evasions<QUEEN>(pos, mlist, us, blockSquares, pinned);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, the special case of en passant captures. An en passant
|
|
||||||
// capture can only be a check evasion if the check is not a discovered
|
|
||||||
// check. If pos.ep_square() is set, the last move made must have been
|
|
||||||
// a double pawn push. If, furthermore, the checking piece is a pawn,
|
|
||||||
// an en passant check evasion may be possible.
|
|
||||||
if (pos.ep_square() != SQ_NONE && (checkers & pos.pieces(PAWN, them)))
|
|
||||||
{
|
|
||||||
to = pos.ep_square();
|
|
||||||
b1 = pos.attacks_from<PAWN>(to, them) & pos.pieces(PAWN, us);
|
|
||||||
|
|
||||||
// The checking pawn cannot be a discovered (bishop) check candidate
|
|
||||||
// otherwise we were in check also before last double push move.
|
|
||||||
assert(!bit_is_set(pos.discovered_check_candidates(them), checksq));
|
|
||||||
assert(count_1s(b1) == 1 || count_1s(b1) == 2);
|
|
||||||
|
|
||||||
b1 &= ~pinned;
|
|
||||||
while (b1)
|
|
||||||
{
|
|
||||||
from = pop_1st_bit(&b1);
|
|
||||||
// Move is always legal because checking pawn is not a discovered
|
|
||||||
// check candidate and our capturing pawn has been already tested
|
|
||||||
// against pinned pieces.
|
|
||||||
(*mlist++).move = make_ep_move(from, to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mlist;
|
return mlist;
|
||||||
|
|
||||||
|
// Find squares where a blocking evasion or a capture of the
|
||||||
|
// checker piece is possible.
|
||||||
|
target = squares_between(checksq, ksq) | checkers;
|
||||||
|
|
||||||
|
mlist = generate_piece_moves<PAWN, EVASION>(pos, mlist, us, target);
|
||||||
|
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
|
||||||
|
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
|
||||||
|
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
|
||||||
|
return generate_piece_moves<QUEEN>(pos, mlist, us, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -332,24 +256,25 @@ MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLega
|
|||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
|
MoveStack *last, *cur = mlist;
|
||||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||||
|
|
||||||
if (pos.is_check())
|
|
||||||
return generate_evasions(pos, mlist, pinned);
|
|
||||||
|
|
||||||
// Generate pseudo-legal moves
|
// Generate pseudo-legal moves
|
||||||
MoveStack* last = generate_captures(pos, mlist);
|
if (pos.is_check())
|
||||||
last = generate_noncaptures(pos, last);
|
last = generate_evasions(pos, mlist);
|
||||||
|
else
|
||||||
|
last = generate_noncaptures(pos, generate_captures(pos, mlist));
|
||||||
|
|
||||||
if (pseudoLegal)
|
if (pseudoLegal)
|
||||||
return last;
|
return last;
|
||||||
|
|
||||||
// Remove illegal moves from the list
|
// Remove illegal moves from the list
|
||||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
while (cur != last)
|
||||||
if (!pos.pl_move_is_legal(cur->move, pinned))
|
if (pos.pl_move_is_legal(cur->move, pinned))
|
||||||
{
|
cur++;
|
||||||
|
else
|
||||||
cur->move = (--last)->move;
|
cur->move = (--last)->move;
|
||||||
cur--;
|
|
||||||
}
|
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,10 +286,11 @@ MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLega
|
|||||||
bool move_is_legal(const Position& pos, const Move m) {
|
bool move_is_legal(const Position& pos, const Move m) {
|
||||||
|
|
||||||
MoveStack mlist[256];
|
MoveStack mlist[256];
|
||||||
MoveStack* last = generate_moves(pos, mlist, true);
|
MoveStack *cur, *last = generate_moves(pos, mlist, true);
|
||||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
|
||||||
|
for (cur = mlist; cur != last; cur++)
|
||||||
if (cur->move == m)
|
if (cur->move == m)
|
||||||
return pos.pl_move_is_legal(m);
|
return pos.pl_move_is_legal(m, pos.pinned_pieces(pos.side_to_move()));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -372,25 +298,23 @@ bool move_is_legal(const Position& pos, const Move m) {
|
|||||||
|
|
||||||
/// Fast version of move_is_legal() that takes a position a move and a
|
/// Fast version of move_is_legal() that takes a position a move and a
|
||||||
/// bitboard of pinned pieces as input, and tests whether the move is legal.
|
/// bitboard of pinned pieces as input, and tests whether the move is legal.
|
||||||
/// This version must only be used when the side to move is not in check.
|
|
||||||
|
|
||||||
bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(!pos.is_check());
|
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
assert(pinned == pos.pinned_pieces(pos.side_to_move()));
|
assert(pinned == pos.pinned_pieces(pos.side_to_move()));
|
||||||
|
|
||||||
// Use a slower but simpler function for uncommon cases
|
|
||||||
if (move_is_ep(m) || move_is_castle(m))
|
|
||||||
return move_is_legal(pos, m);
|
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Color them = opposite_color(us);
|
Color them = opposite_color(us);
|
||||||
Square from = move_from(m);
|
Square from = move_from(m);
|
||||||
Square to = move_to(m);
|
Square to = move_to(m);
|
||||||
Piece pc = pos.piece_on(from);
|
Piece pc = pos.piece_on(from);
|
||||||
|
|
||||||
|
// Use a slower but simpler function for uncommon cases
|
||||||
|
if (move_is_ep(m) || move_is_castle(m))
|
||||||
|
return move_is_legal(pos, m);
|
||||||
|
|
||||||
// If the from square is not occupied by a piece belonging to the side to
|
// If the from square is not occupied by a piece belonging to the side to
|
||||||
// move, the move is obviously not legal.
|
// move, the move is obviously not legal.
|
||||||
if (color_of_piece(pc) != us)
|
if (color_of_piece(pc) != us)
|
||||||
@@ -414,6 +338,10 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
|||||||
||(square_rank(to) == RANK_1 && us != WHITE)) != bool(move_is_promotion(m)))
|
||(square_rank(to) == RANK_1 && us != WHITE)) != bool(move_is_promotion(m)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// The promotion piece, if any, must be valid
|
||||||
|
if (move_promotion_piece(m) > QUEEN || move_promotion_piece(m) == PAWN)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Proceed according to the square delta between the origin and
|
// Proceed according to the square delta between the origin and
|
||||||
// destination squares.
|
// destination squares.
|
||||||
switch (direction)
|
switch (direction)
|
||||||
@@ -459,13 +387,13 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// The move is pseudo-legal, check if it is also legal
|
// The move is pseudo-legal, check if it is also legal
|
||||||
return pos.pl_move_is_legal(m, pinned);
|
return pos.is_check() ? pos.pl_move_is_evasion(m, pinned) : pos.pl_move_is_legal(m, pinned);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Luckly we can handle all the other pieces in one go
|
// Luckly we can handle all the other pieces in one go
|
||||||
return ( bit_is_set(pos.attacks_from(pc, from), to)
|
return bit_is_set(pos.attacks_from(pc, from), to)
|
||||||
&& pos.pl_move_is_legal(m, pinned)
|
&& (pos.is_check() ? pos.pl_move_is_evasion(m, pinned) : pos.pl_move_is_legal(m, pinned))
|
||||||
&& !move_is_promotion(m));
|
&& !move_is_promotion(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -474,8 +402,8 @@ namespace {
|
|||||||
template<PieceType Piece>
|
template<PieceType Piece>
|
||||||
MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) {
|
MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) {
|
||||||
|
|
||||||
Square from;
|
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
|
Square from;
|
||||||
const Square* ptr = pos.piece_list_begin(us, Piece);
|
const Square* ptr = pos.piece_list_begin(us, Piece);
|
||||||
|
|
||||||
while ((from = *ptr++) != SQ_NONE)
|
while ((from = *ptr++) != SQ_NONE)
|
||||||
@@ -497,24 +425,6 @@ namespace {
|
|||||||
return mlist;
|
return mlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Piece>
|
|
||||||
MoveStack* generate_piece_evasions(const Position& pos, MoveStack* mlist,
|
|
||||||
Color us, Bitboard target, Bitboard pinned) {
|
|
||||||
Square from;
|
|
||||||
Bitboard b;
|
|
||||||
const Square* ptr = pos.piece_list_begin(us, Piece);
|
|
||||||
|
|
||||||
while ((from = *ptr++) != SQ_NONE)
|
|
||||||
{
|
|
||||||
if (pinned && bit_is_set(pinned, from))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
b = pos.attacks_from<Piece>(from) & target;
|
|
||||||
SERIALIZE_MOVES(b);
|
|
||||||
}
|
|
||||||
return mlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Color Us, SquareDelta Direction>
|
template<Color Us, SquareDelta Direction>
|
||||||
inline Bitboard move_pawns(Bitboard p) {
|
inline Bitboard move_pawns(Bitboard p) {
|
||||||
|
|
||||||
@@ -528,8 +438,8 @@ namespace {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us, SquareDelta Diagonal>
|
template<Color Us, MoveType Type, SquareDelta Diagonal>
|
||||||
MoveStack* generate_pawn_diagonal_captures(MoveStack* mlist, Bitboard pawns, Bitboard enemyPieces, bool promotion) {
|
inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard enemyPieces) {
|
||||||
|
|
||||||
// Calculate our parametrized parameters at compile time
|
// Calculate our parametrized parameters at compile time
|
||||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||||
@@ -538,136 +448,152 @@ namespace {
|
|||||||
const SquareDelta TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW);
|
const SquareDelta TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW);
|
||||||
const SquareDelta TTDELTA_NE = (Diagonal == DELTA_NE ? TDELTA_NE : TDELTA_NW);
|
const SquareDelta TTDELTA_NE = (Diagonal == DELTA_NE ? TDELTA_NE : TDELTA_NW);
|
||||||
|
|
||||||
|
Bitboard b1, b2;
|
||||||
Square to;
|
Square to;
|
||||||
|
|
||||||
// Captures in the a1-h8 (a8-h1 for black) diagonal or in the h1-a8 (h8-a1 for black)
|
// Captures in the a1-h8 (a8-h1 for black) diagonal or in the h1-a8 (h8-a1 for black)
|
||||||
Bitboard b1 = move_pawns<Us, Diagonal>(pawns) & ~TFileABB & enemyPieces;
|
b1 = move_pawns<Us, Diagonal>(pawns) & ~TFileABB & enemyPieces;
|
||||||
|
|
||||||
// Capturing promotions
|
// Capturing promotions and under-promotions
|
||||||
if (promotion)
|
if (b1 & TRank8BB)
|
||||||
{
|
{
|
||||||
Bitboard b2 = b1 & TRank8BB;
|
b2 = b1 & TRank8BB;
|
||||||
b1 &= ~TRank8BB;
|
b1 &= ~TRank8BB;
|
||||||
while (b2)
|
while (b2)
|
||||||
{
|
{
|
||||||
to = pop_1st_bit(&b2);
|
to = pop_1st_bit(&b2);
|
||||||
|
|
||||||
|
if (Type == CAPTURE || Type == EVASION)
|
||||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, QUEEN);
|
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, QUEEN);
|
||||||
|
|
||||||
|
if (Type == NON_CAPTURE || Type == EVASION)
|
||||||
|
{
|
||||||
|
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, ROOK);
|
||||||
|
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, BISHOP);
|
||||||
|
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, KNIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the only possible under promotion that can give a check
|
||||||
|
// not already included in the queen-promotion. It is not sure that
|
||||||
|
// the promoted knight will give check, but it doesn't worth to verify.
|
||||||
|
if (Type == CHECK)
|
||||||
|
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, KNIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Capturing non-promotions
|
// Serialize standard captures
|
||||||
|
if (Type == CAPTURE || Type == EVASION)
|
||||||
SERIALIZE_MOVES_D(b1, -TTDELTA_NE);
|
SERIALIZE_MOVES_D(b1, -TTDELTA_NE);
|
||||||
|
|
||||||
return mlist;
|
return mlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us, MoveType Type>
|
template<Color Us, MoveType Type>
|
||||||
MoveStack* generate_pawn_moves(const Position& pos, MoveStack* mlist, Bitboard dcp,
|
MoveStack* generate_pawn_moves(const Position& pos, MoveStack* mlist, Bitboard target, Square ksq) {
|
||||||
Square ksq, Bitboard blockSquares) {
|
|
||||||
|
|
||||||
// Calculate our parametrized parameters at compile time
|
// Calculate our parametrized parameters at compile time
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||||
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||||
const SquareDelta TDELTA_NE = (Us == WHITE ? DELTA_NE : DELTA_SE);
|
|
||||||
const SquareDelta TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW);
|
|
||||||
const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S);
|
const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S);
|
||||||
|
|
||||||
Bitboard b1, b2, dcPawns1, dcPawns2;
|
|
||||||
Square to;
|
Square to;
|
||||||
Bitboard pawns = (Type == EVASION ? pos.pieces(PAWN, Us) & ~dcp : pos.pieces(PAWN, Us));
|
Bitboard b1, b2, enemyPieces, emptySquares;
|
||||||
bool possiblePromotion = pawns & TRank7BB;
|
Bitboard pawns = pos.pieces(PAWN, Us);
|
||||||
|
|
||||||
if (Type == CAPTURE)
|
// Standard captures and capturing promotions and underpromotions
|
||||||
|
if (Type == CAPTURE || Type == EVASION || (pawns & TRank7BB))
|
||||||
{
|
{
|
||||||
// Standard captures and capturing promotions in both directions
|
enemyPieces = (Type == CAPTURE ? target : pos.pieces_of_color(opposite_color(Us)));
|
||||||
Bitboard enemyPieces = pos.pieces_of_color(opposite_color(Us));
|
|
||||||
mlist = generate_pawn_diagonal_captures<Us, DELTA_NE>(mlist, pawns, enemyPieces, possiblePromotion);
|
if (Type == EVASION)
|
||||||
mlist = generate_pawn_diagonal_captures<Us, DELTA_NW>(mlist, pawns, enemyPieces, possiblePromotion);
|
enemyPieces &= target; // Capture only the checker piece
|
||||||
|
|
||||||
|
mlist = generate_pawn_captures<Us, Type, DELTA_NE>(mlist, pawns, enemyPieces);
|
||||||
|
mlist = generate_pawn_captures<Us, Type, DELTA_NW>(mlist, pawns, enemyPieces);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (possiblePromotion)
|
// Non-capturing promotions and underpromotions
|
||||||
|
if (pawns & TRank7BB)
|
||||||
{
|
{
|
||||||
// When generating checks consider under-promotion moves (both captures
|
b1 = move_pawns<Us, DELTA_N>(pawns) & TRank8BB & pos.empty_squares();
|
||||||
// and non captures) only if can give a discovery check. Note that dcp
|
|
||||||
// is dc bitboard or pinned bitboard when Type == EVASION.
|
|
||||||
Bitboard pp = (Type == CHECK ? pawns & dcp : pawns);
|
|
||||||
|
|
||||||
if (Type != EVASION && Type != CAPTURE)
|
if (Type == EVASION)
|
||||||
{
|
b1 &= target; // Only blocking promotion pushes
|
||||||
Bitboard enemyPieces = pos.pieces_of_color(opposite_color(Us));
|
|
||||||
|
|
||||||
// Underpromotion captures in the a1-h8 (a8-h1 for black) direction
|
|
||||||
b1 = move_pawns<Us, DELTA_NE>(pp) & ~FileABB & enemyPieces & TRank8BB;
|
|
||||||
while (b1)
|
|
||||||
{
|
|
||||||
to = pop_1st_bit(&b1);
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_NE, to, ROOK);
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_NE, to, BISHOP);
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_NE, to, KNIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Underpromotion captures in the h1-a8 (h8-a1 for black) direction
|
|
||||||
b1 = move_pawns<Us, DELTA_NW>(pp) & ~FileHBB & enemyPieces & TRank8BB;
|
|
||||||
while (b1)
|
|
||||||
{
|
|
||||||
to = pop_1st_bit(&b1);
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_NW, to, ROOK);
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_NW, to, BISHOP);
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_NW, to, KNIGHT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Underpromotion pawn pushes. Also queen promotions for evasions and captures.
|
|
||||||
b1 = move_pawns<Us, DELTA_N>(pp) & TRank8BB;
|
|
||||||
b1 &= (Type == EVASION ? blockSquares : pos.empty_squares());
|
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
to = pop_1st_bit(&b1);
|
to = pop_1st_bit(&b1);
|
||||||
if (Type == EVASION || Type == CAPTURE)
|
|
||||||
|
if (Type == CAPTURE || Type == EVASION)
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, QUEEN);
|
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, QUEEN);
|
||||||
|
|
||||||
if (Type != CAPTURE)
|
if (Type == NON_CAPTURE || Type == EVASION)
|
||||||
{
|
{
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, ROOK);
|
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, ROOK);
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, BISHOP);
|
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, BISHOP);
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT);
|
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the only possible under promotion that can give a check
|
||||||
|
// not already included in the queen-promotion.
|
||||||
|
if (Type == CHECK && bit_is_set(pos.attacks_from<KNIGHT>(to), pos.king_square(Them)))
|
||||||
|
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Standard pawn pushes and double pushes
|
||||||
if (Type != CAPTURE)
|
if (Type != CAPTURE)
|
||||||
{
|
{
|
||||||
Bitboard emptySquares = pos.empty_squares();
|
emptySquares = (Type == NON_CAPTURE ? target : pos.empty_squares());
|
||||||
dcPawns1 = dcPawns2 = EmptyBoardBB;
|
|
||||||
if (Type == CHECK && (pawns & dcp))
|
|
||||||
{
|
|
||||||
// Pawn moves which gives discovered check. This is possible only if the
|
|
||||||
// pawn is not on the same file as the enemy king, because we don't
|
|
||||||
// generate captures.
|
|
||||||
dcPawns1 = move_pawns<Us, DELTA_N>(pawns & dcp & ~file_bb(ksq)) & emptySquares & ~TRank8BB;
|
|
||||||
dcPawns2 = move_pawns<Us, DELTA_N>(dcPawns1 & TRank3BB) & emptySquares;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single pawn pushes
|
// Single and double pawn pushes
|
||||||
b1 = move_pawns<Us, DELTA_N>(pawns) & emptySquares & ~TRank8BB;
|
b1 = move_pawns<Us, DELTA_N>(pawns) & emptySquares & ~TRank8BB;
|
||||||
b2 = (Type == CHECK ? (b1 & pos.attacks_from<PAWN>(ksq, Them)) | dcPawns1 :
|
b2 = move_pawns<Us, DELTA_N>(b1 & TRank3BB) & emptySquares;
|
||||||
(Type == EVASION ? b1 & blockSquares : b1));
|
|
||||||
SERIALIZE_MOVES_D(b2, -TDELTA_N);
|
|
||||||
|
|
||||||
// Double pawn pushes
|
// Filter out unwanted pushes according to the move type
|
||||||
b1 = move_pawns<Us, DELTA_N>(b1 & TRank3BB) & emptySquares;
|
if (Type == EVASION)
|
||||||
b2 = (Type == CHECK ? (b1 & pos.attacks_from<PAWN>(ksq, Them)) | dcPawns2 :
|
{
|
||||||
(Type == EVASION ? b1 & blockSquares : b1));
|
b1 &= target;
|
||||||
|
b2 &= target;
|
||||||
|
}
|
||||||
|
else if (Type == CHECK)
|
||||||
|
{
|
||||||
|
// Pawn moves which give direct cheks
|
||||||
|
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
|
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
|
|
||||||
|
// Pawn moves which gives discovered check. This is possible only if
|
||||||
|
// the pawn is not on the same file as the enemy king, because we
|
||||||
|
// don't generate captures.
|
||||||
|
if (pawns & target) // For CHECK type target is dc bitboard
|
||||||
|
{
|
||||||
|
Bitboard dc1 = move_pawns<Us, DELTA_N>(pawns & target & ~file_bb(ksq)) & emptySquares & ~TRank8BB;
|
||||||
|
Bitboard dc2 = move_pawns<Us, DELTA_N>(dc1 & TRank3BB) & emptySquares;
|
||||||
|
|
||||||
|
b1 |= dc1;
|
||||||
|
b2 |= dc2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SERIALIZE_MOVES_D(b1, -TDELTA_N);
|
||||||
SERIALIZE_MOVES_D(b2, -TDELTA_N -TDELTA_N);
|
SERIALIZE_MOVES_D(b2, -TDELTA_N -TDELTA_N);
|
||||||
}
|
}
|
||||||
else if (pos.ep_square() != SQ_NONE) // En passant captures
|
|
||||||
|
// En passant captures
|
||||||
|
if ((Type == CAPTURE || Type == EVASION) && pos.ep_square() != SQ_NONE)
|
||||||
{
|
{
|
||||||
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
|
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
|
||||||
assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
|
assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
|
||||||
|
|
||||||
|
// An en passant capture can be an evasion only if the checking piece
|
||||||
|
// is the double pushed pawn and so is in the target. Otherwise this
|
||||||
|
// is a discovery check and we are forced to do otherwise.
|
||||||
|
if (Type == EVASION && !bit_is_set(target, pos.ep_square() - TDELTA_N))
|
||||||
|
return mlist;
|
||||||
|
|
||||||
b1 = pawns & pos.attacks_from<PAWN>(pos.ep_square(), Them);
|
b1 = pawns & pos.attacks_from<PAWN>(pos.ep_square(), Them);
|
||||||
|
|
||||||
assert(b1 != EmptyBoardBB);
|
assert(b1 != EmptyBoardBB);
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
@@ -680,43 +606,49 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Piece>
|
template<PieceType Piece>
|
||||||
MoveStack* generate_piece_checks(const Position& pos, MoveStack* mlist, Color us,
|
MoveStack* generate_discovered_checks(const Position& pos, MoveStack* mlist, Square from) {
|
||||||
Bitboard dc, Square ksq) {
|
|
||||||
|
|
||||||
Bitboard target = pos.pieces(Piece, us);
|
assert(Piece != QUEEN);
|
||||||
|
|
||||||
// Discovered non-capture checks
|
Bitboard b = pos.attacks_from<Piece>(from) & pos.empty_squares();
|
||||||
Bitboard b = target & dc;
|
|
||||||
|
|
||||||
assert(Piece != QUEEN || !b);
|
|
||||||
|
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
Square from = pop_1st_bit(&b);
|
|
||||||
Bitboard bb = pos.attacks_from<Piece>(from) & pos.empty_squares();
|
|
||||||
if (Piece == KING)
|
if (Piece == KING)
|
||||||
bb &= ~QueenPseudoAttacks[ksq];
|
{
|
||||||
|
Square ksq = pos.king_square(opposite_color(pos.side_to_move()));
|
||||||
SERIALIZE_MOVES(bb);
|
b &= ~QueenPseudoAttacks[ksq];
|
||||||
|
}
|
||||||
|
SERIALIZE_MOVES(b);
|
||||||
|
return mlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direct non-capture checks
|
template<PieceType Piece>
|
||||||
b = target & ~dc;
|
MoveStack* generate_direct_checks(const Position& pos, MoveStack* mlist, Color us,
|
||||||
Bitboard checkSqs = pos.attacks_from<Piece>(ksq) & pos.empty_squares();
|
Bitboard dc, Square ksq) {
|
||||||
if (Piece != KING && checkSqs)
|
assert(Piece != KING);
|
||||||
|
|
||||||
|
Bitboard checkSqs, b;
|
||||||
|
Square from;
|
||||||
|
const Square* ptr = pos.piece_list_begin(us, Piece);
|
||||||
|
|
||||||
|
if ((from = *ptr++) == SQ_NONE)
|
||||||
|
return mlist;
|
||||||
|
|
||||||
|
checkSqs = pos.attacks_from<Piece>(ksq) & pos.empty_squares();
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
Square from = pop_1st_bit(&b);
|
|
||||||
if ( (Piece == QUEEN && !(QueenPseudoAttacks[from] & checkSqs))
|
if ( (Piece == QUEEN && !(QueenPseudoAttacks[from] & checkSqs))
|
||||||
|| (Piece == ROOK && !(RookPseudoAttacks[from] & checkSqs))
|
|| (Piece == ROOK && !(RookPseudoAttacks[from] & checkSqs))
|
||||||
|| (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
|
|| (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Bitboard bb = pos.attacks_from<Piece>(from) & checkSqs;
|
if (dc && bit_is_set(dc, from))
|
||||||
SERIALIZE_MOVES(bb);
|
continue;
|
||||||
}
|
|
||||||
}
|
b = pos.attacks_from<Piece>(from) & checkSqs;
|
||||||
|
SERIALIZE_MOVES(b);
|
||||||
|
|
||||||
|
} while ((from = *ptr++) != SQ_NONE);
|
||||||
|
|
||||||
return mlist;
|
return mlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,17 +694,4 @@ namespace {
|
|||||||
}
|
}
|
||||||
return mlist;
|
return mlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool castling_is_check(const Position& pos, CastlingSide side) {
|
|
||||||
|
|
||||||
// After castling opponent king is attacked by the castled rook?
|
|
||||||
File rookFile = (side == QUEEN_SIDE ? FILE_D : FILE_F);
|
|
||||||
Color us = pos.side_to_move();
|
|
||||||
Square ksq = pos.king_square(us);
|
|
||||||
Bitboard occ = pos.occupied_squares();
|
|
||||||
|
|
||||||
clear_bit(&occ, ksq); // Remove our king from the board
|
|
||||||
Square rsq = make_square(rookFile, square_rank(ksq));
|
|
||||||
return bit_is_set(rook_attacks_bb(rsq, occ), pos.king_square(opposite_color(us)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -34,8 +34,8 @@
|
|||||||
|
|
||||||
extern MoveStack* generate_captures(const Position& pos, MoveStack* mlist);
|
extern MoveStack* generate_captures(const Position& pos, MoveStack* mlist);
|
||||||
extern MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist);
|
extern MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist);
|
||||||
extern MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc);
|
extern MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist);
|
||||||
extern MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
|
extern MoveStack* generate_evasions(const Position& pos, MoveStack* mlist);
|
||||||
extern MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLegal = false);
|
extern MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLegal = false);
|
||||||
extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned);
|
extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned);
|
||||||
extern bool move_is_legal(const Position& pos, const Move m);
|
extern bool move_is_legal(const Position& pos, const Move m);
|
||||||
|
|||||||
+80
-71
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
@@ -53,7 +52,7 @@ namespace {
|
|||||||
|
|
||||||
CACHE_LINE_ALIGNMENT
|
CACHE_LINE_ALIGNMENT
|
||||||
const uint8_t MainSearchPhaseTable[] = { PH_TT_MOVES, PH_GOOD_CAPTURES, PH_KILLERS, PH_NONCAPTURES, PH_BAD_CAPTURES, PH_STOP};
|
const uint8_t MainSearchPhaseTable[] = { PH_TT_MOVES, PH_GOOD_CAPTURES, PH_KILLERS, PH_NONCAPTURES, PH_BAD_CAPTURES, PH_STOP};
|
||||||
const uint8_t EvasionsPhaseTable[] = { PH_EVASIONS, PH_STOP};
|
const uint8_t EvasionsPhaseTable[] = { PH_TT_MOVES, PH_EVASIONS, PH_STOP};
|
||||||
const uint8_t QsearchWithChecksPhaseTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_QCHECKS, PH_STOP};
|
const uint8_t QsearchWithChecksPhaseTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_QCHECKS, PH_STOP};
|
||||||
const uint8_t QsearchWithoutChecksPhaseTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_STOP};
|
const uint8_t QsearchWithoutChecksPhaseTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_STOP};
|
||||||
}
|
}
|
||||||
@@ -71,37 +70,49 @@ namespace {
|
|||||||
/// search captures, promotions and some checks) and about how important good
|
/// search captures, promotions and some checks) and about how important good
|
||||||
/// move ordering is at the current node.
|
/// move ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
||||||
const History& h, SearchStack* ss) : pos(p), H(h) {
|
SearchStack* ss, Value beta) : pos(p), H(h) {
|
||||||
int searchTT = ttm;
|
int searchTT = ttm;
|
||||||
ttMoves[0].move = ttm;
|
ttMoves[0].move = ttm;
|
||||||
finished = false;
|
badCaptureThreshold = 0;
|
||||||
lastBadCapture = badCaptures;
|
lastBadCapture = badCaptures;
|
||||||
|
|
||||||
if (ss)
|
pinned = p.pinned_pieces(pos.side_to_move());
|
||||||
|
|
||||||
|
if (ss && !p.is_check())
|
||||||
{
|
{
|
||||||
ttMoves[1].move = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller;
|
ttMoves[1].move = (ss->mateKiller == ttm) ? MOVE_NONE : ss->mateKiller;
|
||||||
searchTT |= ttMoves[1].move;
|
searchTT |= ttMoves[1].move;
|
||||||
killers[0].move = ss->killers[0];
|
killers[0].move = ss->killers[0];
|
||||||
killers[1].move = ss->killers[1];
|
killers[1].move = ss->killers[1];
|
||||||
} else
|
} else
|
||||||
ttMoves[1].move = killers[0].move = killers[1].move = MOVE_NONE;
|
ttMoves[1].move = killers[0].move = killers[1].move = MOVE_NONE;
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
|
||||||
|
|
||||||
dc = p.discovered_check_candidates(us);
|
|
||||||
pinned = p.pinned_pieces(us);
|
|
||||||
|
|
||||||
if (p.is_check())
|
if (p.is_check())
|
||||||
phasePtr = EvasionsPhaseTable;
|
phasePtr = EvasionsPhaseTable;
|
||||||
else if (d > Depth(0))
|
else if (d > Depth(0))
|
||||||
phasePtr = MainSearchPhaseTable + !searchTT;
|
{
|
||||||
else if (d == Depth(0))
|
// Consider sligtly negative captures as good if at low
|
||||||
phasePtr = QsearchWithChecksPhaseTable + !searchTT;
|
// depth and far from beta.
|
||||||
else
|
if (ss && ss->eval < beta - PawnValueMidgame && d < 3 * OnePly)
|
||||||
phasePtr = QsearchWithoutChecksPhaseTable + !searchTT;
|
badCaptureThreshold = -PawnValueMidgame;
|
||||||
|
|
||||||
phasePtr--;
|
phasePtr = MainSearchPhaseTable;
|
||||||
|
}
|
||||||
|
else if (d == Depth(0))
|
||||||
|
phasePtr = QsearchWithChecksPhaseTable;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
phasePtr = QsearchWithoutChecksPhaseTable;
|
||||||
|
|
||||||
|
// Skip TT move if is not a capture or a promotion, this avoids
|
||||||
|
// qsearch tree explosion due to a possible perpetual check or
|
||||||
|
// similar rare cases when TT table is full.
|
||||||
|
if (ttm != MOVE_NONE && !pos.move_is_capture_or_promotion(ttm))
|
||||||
|
searchTT = ttMoves[0].move = MOVE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
phasePtr += int(!searchTT) - 1;
|
||||||
go_next_phase();
|
go_next_phase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +134,6 @@ void MovePicker::go_next_phase() {
|
|||||||
case PH_GOOD_CAPTURES:
|
case PH_GOOD_CAPTURES:
|
||||||
lastMove = generate_captures(pos, moves);
|
lastMove = generate_captures(pos, moves);
|
||||||
score_captures();
|
score_captures();
|
||||||
std::sort(moves, lastMove);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_KILLERS:
|
case PH_KILLERS:
|
||||||
@@ -134,7 +144,7 @@ void MovePicker::go_next_phase() {
|
|||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
lastMove = generate_noncaptures(pos, moves);
|
lastMove = generate_noncaptures(pos, moves);
|
||||||
score_noncaptures();
|
score_noncaptures();
|
||||||
std::sort(moves, lastMove);
|
sort_moves(moves, lastMove, &lastGoodNonCapture);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
case PH_BAD_CAPTURES:
|
||||||
@@ -142,29 +152,26 @@ void MovePicker::go_next_phase() {
|
|||||||
// to get SEE move ordering.
|
// to get SEE move ordering.
|
||||||
curMove = badCaptures;
|
curMove = badCaptures;
|
||||||
lastMove = lastBadCapture;
|
lastMove = lastBadCapture;
|
||||||
std::sort(badCaptures, lastMove);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_EVASIONS:
|
case PH_EVASIONS:
|
||||||
assert(pos.is_check());
|
assert(pos.is_check());
|
||||||
lastMove = generate_evasions(pos, moves, pinned);
|
lastMove = generate_evasions(pos, moves);
|
||||||
score_evasions();
|
score_evasions_or_checks();
|
||||||
std::sort(moves, lastMove);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
case PH_QCAPTURES:
|
||||||
lastMove = generate_captures(pos, moves);
|
lastMove = generate_captures(pos, moves);
|
||||||
score_captures();
|
score_captures();
|
||||||
std::sort(moves, lastMove);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_QCHECKS:
|
case PH_QCHECKS:
|
||||||
// Perhaps we should order moves move here? FIXME
|
lastMove = generate_non_capture_checks(pos, moves);
|
||||||
lastMove = generate_non_capture_checks(pos, moves, dc);
|
score_evasions_or_checks();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_STOP:
|
case PH_STOP:
|
||||||
lastMove = curMove + 1; // hack to be friendly for get_next_move()
|
lastMove = curMove + 1; // Avoids another go_next_phase() call
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -202,8 +209,8 @@ void MovePicker::score_captures() {
|
|||||||
if (move_is_promotion(m))
|
if (move_is_promotion(m))
|
||||||
cur->score = QueenValueMidgame;
|
cur->score = QueenValueMidgame;
|
||||||
else
|
else
|
||||||
cur->score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
||||||
-int(pos.type_of_piece_on(move_from(m)));
|
- pos.type_of_piece_on(move_from(m));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,29 +231,36 @@ void MovePicker::score_noncaptures() {
|
|||||||
piece = pos.piece_on(from);
|
piece = pos.piece_on(from);
|
||||||
hs = H.move_ordering_score(piece, to);
|
hs = H.move_ordering_score(piece, to);
|
||||||
|
|
||||||
// Ensure history is always preferred to pst
|
// Ensure history has always highest priority
|
||||||
if (hs > 0)
|
if (hs > 0)
|
||||||
hs += 1000;
|
hs += 10000;
|
||||||
|
|
||||||
// pst based scoring
|
// Gain table based scoring
|
||||||
cur->score = hs + pos.pst_delta<Position::MidGame>(piece, from, to);
|
cur->score = hs + 16 * H.gain(piece, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovePicker::score_evasions() {
|
void MovePicker::score_evasions_or_checks() {
|
||||||
|
// Try good captures ordered by MVV/LVA, then non-captures if
|
||||||
|
// destination square is not under attack, ordered by history
|
||||||
|
// value, and at the end bad-captures and non-captures with a
|
||||||
|
// negative SEE. This last group is ordered by the SEE score.
|
||||||
Move m;
|
Move m;
|
||||||
|
int seeScore;
|
||||||
|
|
||||||
|
// Skip if we don't have at least two moves to order
|
||||||
|
if (lastMove < moves + 2)
|
||||||
|
return;
|
||||||
|
|
||||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
{
|
{
|
||||||
m = cur->move;
|
m = cur->move;
|
||||||
if (m == ttMoves[0].move)
|
if ((seeScore = pos.see_sign(m)) < 0)
|
||||||
cur->score = 2 * HistoryMax;
|
cur->score = seeScore - HistoryMax; // Be sure are at the bottom
|
||||||
else if (!pos.square_is_empty(move_to(m)))
|
else if (pos.move_is_capture(m))
|
||||||
{
|
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
||||||
int seeScore = pos.see(m);
|
- pos.type_of_piece_on(move_from(m)) + HistoryMax;
|
||||||
cur->score = seeScore + (seeScore >= 0 ? HistoryMax : 0);
|
else
|
||||||
} else
|
|
||||||
cur->score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
|
cur->score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,36 +270,35 @@ void MovePicker::score_evasions() {
|
|||||||
/// are no more moves left.
|
/// are no more moves left.
|
||||||
/// It picks the move with the biggest score from a list of generated moves taking
|
/// It picks the move with the biggest score from a list of generated moves taking
|
||||||
/// care not to return the tt move if has already been searched previously.
|
/// care not to return the tt move if has already been searched previously.
|
||||||
|
/// Note that this function is not thread safe so should be lock protected by
|
||||||
|
/// caller when accessed through a shared MovePicker object.
|
||||||
|
|
||||||
Move MovePicker::get_next_move() {
|
Move MovePicker::get_next_move() {
|
||||||
|
|
||||||
assert(!pos.is_check() || *phasePtr == PH_EVASIONS || *phasePtr == PH_STOP);
|
|
||||||
assert( pos.is_check() || *phasePtr != PH_EVASIONS);
|
|
||||||
|
|
||||||
Move move;
|
Move move;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
while (curMove != lastMove)
|
while (curMove != lastMove)
|
||||||
{
|
{
|
||||||
move = (curMove++)->move;
|
|
||||||
|
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
|
|
||||||
case PH_TT_MOVES:
|
case PH_TT_MOVES:
|
||||||
|
move = (curMove++)->move;
|
||||||
if ( move != MOVE_NONE
|
if ( move != MOVE_NONE
|
||||||
&& move_is_legal(pos, move, pinned))
|
&& move_is_legal(pos, move, pinned))
|
||||||
return move;
|
return move;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_GOOD_CAPTURES:
|
case PH_GOOD_CAPTURES:
|
||||||
|
move = pick_best(curMove++, lastMove).move;
|
||||||
if ( move != ttMoves[0].move
|
if ( move != ttMoves[0].move
|
||||||
&& move != ttMoves[1].move
|
&& move != ttMoves[1].move
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
{
|
{
|
||||||
// Check for a non negative SEE now
|
// Check for a non negative SEE now
|
||||||
int seeValue = pos.see_sign(move);
|
int seeValue = pos.see_sign(move);
|
||||||
if (seeValue >= 0)
|
if (seeValue >= badCaptureThreshold)
|
||||||
return move;
|
return move;
|
||||||
|
|
||||||
// Losing capture, move it to the badCaptures[] array, note
|
// Losing capture, move it to the badCaptures[] array, note
|
||||||
@@ -298,15 +311,22 @@ Move MovePicker::get_next_move() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_KILLERS:
|
case PH_KILLERS:
|
||||||
|
move = (curMove++)->move;
|
||||||
if ( move != MOVE_NONE
|
if ( move != MOVE_NONE
|
||||||
|
&& move_is_legal(pos, move, pinned)
|
||||||
&& move != ttMoves[0].move
|
&& move != ttMoves[0].move
|
||||||
&& move != ttMoves[1].move
|
&& move != ttMoves[1].move
|
||||||
&& move_is_legal(pos, move, pinned)
|
|
||||||
&& !pos.move_is_capture(move))
|
&& !pos.move_is_capture(move))
|
||||||
return move;
|
return move;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
|
|
||||||
|
// Sort negative scored moves only when we get there
|
||||||
|
if (curMove == lastGoodNonCapture)
|
||||||
|
insertion_sort(lastGoodNonCapture, lastMove);
|
||||||
|
|
||||||
|
move = (curMove++)->move;
|
||||||
if ( move != ttMoves[0].move
|
if ( move != ttMoves[0].move
|
||||||
&& move != ttMoves[1].move
|
&& move != ttMoves[1].move
|
||||||
&& move != killers[0].move
|
&& move != killers[0].move
|
||||||
@@ -315,13 +335,20 @@ Move MovePicker::get_next_move() {
|
|||||||
return move;
|
return move;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_EVASIONS:
|
|
||||||
case PH_BAD_CAPTURES:
|
case PH_BAD_CAPTURES:
|
||||||
|
move = pick_best(curMove++, lastMove).move;
|
||||||
return move;
|
return move;
|
||||||
|
|
||||||
|
case PH_EVASIONS:
|
||||||
case PH_QCAPTURES:
|
case PH_QCAPTURES:
|
||||||
|
move = pick_best(curMove++, lastMove).move;
|
||||||
|
if ( move != ttMoves[0].move
|
||||||
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
|
return move;
|
||||||
|
break;
|
||||||
|
|
||||||
case PH_QCHECKS:
|
case PH_QCHECKS:
|
||||||
// Maybe postpone the legality check until after futility pruning?
|
move = (curMove++)->move;
|
||||||
if ( move != ttMoves[0].move
|
if ( move != ttMoves[0].move
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
return move;
|
return move;
|
||||||
@@ -339,21 +366,3 @@ Move MovePicker::get_next_move() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A variant of get_next_move() which takes a lock as a parameter, used to
|
|
||||||
/// prevent multiple threads from picking the same move at a split point.
|
|
||||||
|
|
||||||
Move MovePicker::get_next_move(Lock &lock) {
|
|
||||||
|
|
||||||
lock_grab(&lock);
|
|
||||||
if (finished)
|
|
||||||
{
|
|
||||||
lock_release(&lock);
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
|
||||||
Move m = get_next_move();
|
|
||||||
if (m == MOVE_NONE)
|
|
||||||
finished = true;
|
|
||||||
|
|
||||||
lock_release(&lock);
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|||||||
+6
-18
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -50,26 +49,23 @@ class MovePicker {
|
|||||||
MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
|
MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL);
|
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL, Value beta = -VALUE_INFINITE);
|
||||||
Move get_next_move();
|
Move get_next_move();
|
||||||
Move get_next_move(Lock& lock);
|
|
||||||
int number_of_evasions() const;
|
int number_of_evasions() const;
|
||||||
Bitboard discovered_check_candidates() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void score_captures();
|
void score_captures();
|
||||||
void score_noncaptures();
|
void score_noncaptures();
|
||||||
void score_evasions();
|
void score_evasions_or_checks();
|
||||||
void go_next_phase();
|
void go_next_phase();
|
||||||
|
|
||||||
const Position& pos;
|
const Position& pos;
|
||||||
const History& H;
|
const History& H;
|
||||||
|
Bitboard pinned;
|
||||||
MoveStack ttMoves[2], killers[2];
|
MoveStack ttMoves[2], killers[2];
|
||||||
bool finished;
|
int badCaptureThreshold, phase;
|
||||||
int phase;
|
|
||||||
const uint8_t* phasePtr;
|
const uint8_t* phasePtr;
|
||||||
MoveStack *curMove, *lastMove, *lastBadCapture;
|
MoveStack *curMove, *lastMove, *lastGoodNonCapture, *lastBadCapture;
|
||||||
Bitboard dc, pinned;
|
|
||||||
MoveStack moves[256], badCaptures[64];
|
MoveStack moves[256], badCaptures[64];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,12 +84,4 @@ inline int MovePicker::number_of_evasions() const {
|
|||||||
return int(lastMove - moves);
|
return int(lastMove - moves);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// MovePicker::discovered_check_candidates() returns a bitboard containing
|
|
||||||
/// all pieces which can possibly give discovered check. This bitboard is
|
|
||||||
/// computed by the constructor function.
|
|
||||||
|
|
||||||
inline Bitboard MovePicker::discovered_check_candidates() const {
|
|
||||||
return dc;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(MOVEPICK_H_INCLUDED)
|
#endif // !defined(MOVEPICK_H_INCLUDED)
|
||||||
|
|||||||
+150
-210
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -38,64 +38,36 @@ namespace {
|
|||||||
|
|
||||||
/// Constants and variables
|
/// Constants and variables
|
||||||
|
|
||||||
// Doubled pawn penalty by file, middle game
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
const Value DoubledPawnMidgamePenalty[8] = {
|
|
||||||
Value(13), Value(20), Value(23), Value(23),
|
// Doubled pawn penalty by file
|
||||||
Value(23), Value(23), Value(20), Value(13)
|
const Score DoubledPawnPenalty[8] = {
|
||||||
|
S(13, 43), S(20, 48), S(23, 48), S(23, 48),
|
||||||
|
S(23, 48), S(23, 48), S(20, 48), S(13, 43)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Doubled pawn penalty by file, endgame
|
// Isolated pawn penalty by file
|
||||||
const Value DoubledPawnEndgamePenalty[8] = {
|
const Score IsolatedPawnPenalty[8] = {
|
||||||
Value(43), Value(48), Value(48), Value(48),
|
S(25, 30), S(36, 35), S(40, 35), S(40, 35),
|
||||||
Value(48), Value(48), Value(48), Value(43)
|
S(40, 35), S(40, 35), S(36, 35), S(25, 30)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Isolated pawn penalty by file, middle game
|
// Backward pawn penalty by file
|
||||||
const Value IsolatedPawnMidgamePenalty[8] = {
|
const Score BackwardPawnPenalty[8] = {
|
||||||
Value(25), Value(36), Value(40), Value(40),
|
S(20, 28), S(29, 31), S(33, 31), S(33, 31),
|
||||||
Value(40), Value(40), Value(36), Value(25)
|
S(33, 31), S(33, 31), S(29, 31), S(20, 28)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Isolated pawn penalty by file, endgame
|
// Pawn chain membership bonus by file
|
||||||
const Value IsolatedPawnEndgamePenalty[8] = {
|
const Score ChainBonus[8] = {
|
||||||
Value(30), Value(35), Value(35), Value(35),
|
S(11,-1), S(13,-1), S(13,-1), S(14,-1),
|
||||||
Value(35), Value(35), Value(35), Value(30)
|
S(14,-1), S(13,-1), S(13,-1), S(11,-1)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Backward pawn penalty by file, middle game
|
// Candidate passed pawn bonus by rank
|
||||||
const Value BackwardPawnMidgamePenalty[8] = {
|
const Score CandidateBonus[8] = {
|
||||||
Value(20), Value(29), Value(33), Value(33),
|
S( 0, 0), S( 6, 13), S(6,13), S(14,29),
|
||||||
Value(33), Value(33), Value(29), Value(20)
|
S(34,68), S(83,166), S(0, 0), S( 0, 0)
|
||||||
};
|
|
||||||
|
|
||||||
// Backward pawn penalty by file, endgame
|
|
||||||
const Value BackwardPawnEndgamePenalty[8] = {
|
|
||||||
Value(28), Value(31), Value(31), Value(31),
|
|
||||||
Value(31), Value(31), Value(31), Value(28)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Pawn chain membership bonus by file, middle game
|
|
||||||
const Value ChainMidgameBonus[8] = {
|
|
||||||
Value(11), Value(13), Value(13), Value(14),
|
|
||||||
Value(14), Value(13), Value(13), Value(11)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Pawn chain membership bonus by file, endgame
|
|
||||||
const Value ChainEndgameBonus[8] = {
|
|
||||||
Value(-1), Value(-1), Value(-1), Value(-1),
|
|
||||||
Value(-1), Value(-1), Value(-1), Value(-1)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Candidate passed pawn bonus by rank, middle game
|
|
||||||
const Value CandidateMidgameBonus[8] = {
|
|
||||||
Value( 0), Value( 6), Value(6), Value(14),
|
|
||||||
Value(34), Value(83), Value(0), Value( 0)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Candidate passed pawn bonus by rank, endgame
|
|
||||||
const Value CandidateEndgameBonus[8] = {
|
|
||||||
Value( 0), Value( 13), Value(13), Value(29),
|
|
||||||
Value(68), Value(166), Value( 0), Value( 0)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pawn storm tables for positions with opposite castling
|
// Pawn storm tables for positions with opposite castling
|
||||||
@@ -122,12 +94,13 @@ namespace {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Pawn storm open file bonuses by file
|
// Pawn storm open file bonuses by file
|
||||||
const int16_t KStormOpenFileBonus[8] = { 31, 31, 18, 0, 0, 0, 0, 0 };
|
const int16_t QStormOpenFileBonus[8] = { 31, 31, 18, 0, 0, 0, 0, 0 };
|
||||||
const int16_t QStormOpenFileBonus[8] = { 0, 0, 0, 0, 0, 26, 42, 26 };
|
const int16_t KStormOpenFileBonus[8] = { 0, 0, 0, 0, 0, 26, 42, 26 };
|
||||||
|
|
||||||
// Pawn storm lever bonuses by file
|
// Pawn storm lever bonuses by file
|
||||||
const int StormLeverBonus[8] = { -8, -8, -13, 0, 0, -13, -8, -8 };
|
const int StormLeverBonus[8] = { -8, -8, -13, 0, 0, -13, -8, -8 };
|
||||||
|
|
||||||
|
#undef S
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,11 +108,10 @@ namespace {
|
|||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// Constructor
|
/// PawnInfoTable c'tor and d'tor instantiated one each thread
|
||||||
|
|
||||||
PawnInfoTable::PawnInfoTable(unsigned numOfEntries) {
|
PawnInfoTable::PawnInfoTable(unsigned numOfEntries) : size(numOfEntries) {
|
||||||
|
|
||||||
size = numOfEntries;
|
|
||||||
entries = new PawnInfo[size];
|
entries = new PawnInfo[size];
|
||||||
if (!entries)
|
if (!entries)
|
||||||
{
|
{
|
||||||
@@ -150,9 +122,8 @@ PawnInfoTable::PawnInfoTable(unsigned numOfEntries) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Destructor
|
|
||||||
|
|
||||||
PawnInfoTable::~PawnInfoTable() {
|
PawnInfoTable::~PawnInfoTable() {
|
||||||
|
|
||||||
delete [] entries;
|
delete [] entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,11 +139,11 @@ void PawnInfo::clear() {
|
|||||||
|
|
||||||
|
|
||||||
/// PawnInfoTable::get_pawn_info() takes a position object as input, computes
|
/// PawnInfoTable::get_pawn_info() takes a position object as input, computes
|
||||||
/// a PawnInfo object, and returns a pointer to it. The result is also
|
/// a PawnInfo object, and returns a pointer to it. The result is also stored
|
||||||
/// stored in a hash table, so we don't have to recompute everything when
|
/// in a hash table, so we don't have to recompute everything when the same
|
||||||
/// the same pawn structure occurs again.
|
/// pawn structure occurs again.
|
||||||
|
|
||||||
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
@@ -190,112 +161,68 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
|||||||
pi->clear();
|
pi->clear();
|
||||||
pi->key = key;
|
pi->key = key;
|
||||||
|
|
||||||
Value mgValue[2] = {Value(0), Value(0)};
|
|
||||||
Value egValue[2] = {Value(0), Value(0)};
|
|
||||||
|
|
||||||
// Calculate pawn attacks
|
// Calculate pawn attacks
|
||||||
pi->pawnAttacks[WHITE] = ((pos.pieces(PAWN, WHITE) << 9) & ~FileABB) | ((pos.pieces(PAWN, WHITE) << 7) & ~FileHBB);
|
Bitboard whitePawns = pos.pieces(PAWN, WHITE);
|
||||||
pi->pawnAttacks[BLACK] = ((pos.pieces(PAWN, BLACK) >> 7) & ~FileABB) | ((pos.pieces(PAWN, BLACK) >> 9) & ~FileHBB);
|
Bitboard blackPawns = pos.pieces(PAWN, BLACK);
|
||||||
|
pi->pawnAttacks[WHITE] = ((whitePawns << 9) & ~FileABB) | ((whitePawns << 7) & ~FileHBB);
|
||||||
|
pi->pawnAttacks[BLACK] = ((blackPawns >> 7) & ~FileABB) | ((blackPawns >> 9) & ~FileHBB);
|
||||||
|
|
||||||
// Loop through the pawns for both colors
|
// Evaluate pawns for both colors
|
||||||
for (Color us = WHITE; us <= BLACK; us++)
|
pi->value = evaluate_pawns<WHITE>(pos, whitePawns, blackPawns, pi)
|
||||||
{
|
- evaluate_pawns<BLACK>(pos, blackPawns, whitePawns, pi);
|
||||||
Color them = opposite_color(us);
|
return pi;
|
||||||
Bitboard ourPawns = pos.pieces(PAWN, us);
|
}
|
||||||
Bitboard theirPawns = pos.pieces(PAWN, them);
|
|
||||||
Bitboard pawns = ourPawns;
|
|
||||||
|
/// PawnInfoTable::evaluate_pawns() evaluates each pawn of the given color
|
||||||
|
|
||||||
|
template<Color Us>
|
||||||
|
Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
|
||||||
|
Bitboard theirPawns, PawnInfo* pi) const {
|
||||||
|
Bitboard b;
|
||||||
|
Square s;
|
||||||
|
File f;
|
||||||
|
Rank r;
|
||||||
|
int bonus;
|
||||||
|
bool passed, isolated, doubled, opposed, chain, backward, candidate;
|
||||||
|
Score value = make_score(0, 0);
|
||||||
|
const Square* ptr = pos.piece_list_begin(Us, PAWN);
|
||||||
|
|
||||||
// Initialize pawn storm scores by giving bonuses for open files
|
// Initialize pawn storm scores by giving bonuses for open files
|
||||||
for (File f = FILE_A; f <= FILE_H; f++)
|
for (f = FILE_A; f <= FILE_H; f++)
|
||||||
if (!(pawns & file_bb(f)))
|
if (!(ourPawns & file_bb(f)))
|
||||||
{
|
{
|
||||||
pi->ksStormValue[us] += KStormOpenFileBonus[f];
|
pi->ksStormValue[Us] += KStormOpenFileBonus[f];
|
||||||
pi->qsStormValue[us] += QStormOpenFileBonus[f];
|
pi->qsStormValue[Us] += QStormOpenFileBonus[f];
|
||||||
pi->halfOpenFiles[us] |= (1 << f);
|
pi->halfOpenFiles[Us] |= (1 << f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 (pawns)
|
while ((s = *ptr++) != SQ_NONE)
|
||||||
{
|
{
|
||||||
Square s = pop_1st_bit(&pawns);
|
f = square_file(s);
|
||||||
File f = square_file(s);
|
r = square_rank(s);
|
||||||
Rank r = square_rank(s);
|
|
||||||
|
|
||||||
assert(pos.piece_on(s) == piece_of_color_and_type(us, PAWN));
|
assert(pos.piece_on(s) == piece_of_color_and_type(Us, PAWN));
|
||||||
|
|
||||||
// Passed, isolated or doubled pawn?
|
// Calculate kingside and queenside pawn storm scores for both colors to be
|
||||||
bool passed = Position::pawn_is_passed(theirPawns, us, s);
|
// used when evaluating middle game positions with opposite side castling.
|
||||||
bool isolated = Position::pawn_is_isolated(ourPawns, s);
|
bonus = (f >= FILE_F ? evaluate_pawn_storm<Us, KingSide>(s, r, f, theirPawns) : 0);
|
||||||
bool doubled = Position::pawn_is_doubled(ourPawns, us, s);
|
pi->ksStormValue[Us] += KStormTable[relative_square(Us, s)] + bonus;
|
||||||
|
|
||||||
// We calculate kingside and queenside pawn storm
|
bonus = (f <= FILE_C ? evaluate_pawn_storm<Us, QueenSide>(s, r, f, theirPawns) : 0);
|
||||||
// scores for both colors. These are used when evaluating
|
pi->qsStormValue[Us] += QStormTable[relative_square(Us, s)] + bonus;
|
||||||
// middle game positions with opposite side castling.
|
|
||||||
//
|
|
||||||
// Each pawn is given a base score given by a piece square table
|
|
||||||
// (KStormTable[] or QStormTable[]). Pawns which seem to have good
|
|
||||||
// chances of creating an open file by exchanging itself against an
|
|
||||||
// enemy pawn on an adjacent file gets an additional bonus.
|
|
||||||
|
|
||||||
// Kingside pawn storms
|
// Our rank plus previous one. Used for chain detection.
|
||||||
int bonus = KStormTable[relative_square(us, s)];
|
b = rank_bb(r) | rank_bb(r + (Us == WHITE ? -1 : 1));
|
||||||
if (f >= FILE_F)
|
|
||||||
{
|
|
||||||
Bitboard b = outpost_mask(us, s) & theirPawns & (FileFBB | FileGBB | FileHBB);
|
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
Square s2 = pop_1st_bit(&b);
|
|
||||||
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
|
||||||
{
|
|
||||||
// The enemy pawn has no pawn beside itself, which makes it
|
|
||||||
// particularly vulnerable. Big bonus, especially against a
|
|
||||||
// weakness on the rook file.
|
|
||||||
if (square_file(s2) == FILE_H)
|
|
||||||
bonus += 4*StormLeverBonus[f] - 8*square_distance(s, s2);
|
|
||||||
else
|
|
||||||
bonus += 2*StormLeverBonus[f] - 4*square_distance(s, s2);
|
|
||||||
} else
|
|
||||||
// There is at least one enemy pawn beside the enemy pawn we look
|
|
||||||
// at, which means that the pawn has somewhat better chances of
|
|
||||||
// defending itself by advancing. Smaller bonus.
|
|
||||||
bonus += StormLeverBonus[f] - 2*square_distance(s, s2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pi->ksStormValue[us] += bonus;
|
|
||||||
|
|
||||||
// Queenside pawn storms
|
// Passed, isolated, doubled or member of a pawn
|
||||||
bonus = QStormTable[relative_square(us, s)];
|
// chain (but not the backward one) ?
|
||||||
if (f <= FILE_C)
|
passed = !(theirPawns & passed_pawn_mask(Us, s));
|
||||||
{
|
doubled = ourPawns & squares_behind(Us, s);
|
||||||
Bitboard b = outpost_mask(us, s) & theirPawns & (FileABB | FileBBB | FileCBB);
|
opposed = theirPawns & squares_in_front_of(Us, s);
|
||||||
while (b)
|
isolated = !(ourPawns & neighboring_files_bb(f));
|
||||||
{
|
chain = ourPawns & neighboring_files_bb(f) & b;
|
||||||
Square s2 = pop_1st_bit(&b);
|
|
||||||
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
|
||||||
{
|
|
||||||
// The enemy pawn has no pawn beside itself, which makes it
|
|
||||||
// particularly vulnerable. Big bonus, especially against a
|
|
||||||
// weakness on the rook file.
|
|
||||||
if (square_file(s2) == FILE_A)
|
|
||||||
bonus += 4*StormLeverBonus[f] - 16*square_distance(s, s2);
|
|
||||||
else
|
|
||||||
bonus += 2*StormLeverBonus[f] - 8*square_distance(s, s2);
|
|
||||||
} else
|
|
||||||
// There is at least one enemy pawn beside the enemy pawn we look
|
|
||||||
// at, which means that the pawn has somewhat better chances of
|
|
||||||
// defending itself by advancing. Smaller bonus.
|
|
||||||
bonus += StormLeverBonus[f] - 4*square_distance(s, s2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pi->qsStormValue[us] += bonus;
|
|
||||||
|
|
||||||
// Member of a pawn chain (but not the backward one)? We could speed up
|
|
||||||
// the test a little by introducing an array of masks indexed by color
|
|
||||||
// and square for doing the test, but because everything is hashed,
|
|
||||||
// it probably won't make any noticable difference.
|
|
||||||
bool chain = ourPawns
|
|
||||||
& neighboring_files_bb(f)
|
|
||||||
& (rank_bb(r) | rank_bb(r - (us == WHITE ? 1 : -1)));
|
|
||||||
|
|
||||||
// Test for backward pawn
|
// Test for backward pawn
|
||||||
//
|
//
|
||||||
@@ -303,12 +230,9 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
|||||||
// it cannot be backward. If can capture an enemy pawn or if
|
// it cannot be backward. If can capture an enemy pawn or if
|
||||||
// there are friendly pawns behind on neighboring files it cannot
|
// there are friendly pawns behind on neighboring files it cannot
|
||||||
// be backward either.
|
// be backward either.
|
||||||
bool backward;
|
if ( (passed | isolated | chain)
|
||||||
if ( passed
|
|| (ourPawns & attack_span_mask(opposite_color(Us), s))
|
||||||
|| isolated
|
|| (pos.attacks_from<PAWN>(s, Us) & theirPawns))
|
||||||
|| chain
|
|
||||||
|| (pos.attacks_from<PAWN>(s, us) & theirPawns)
|
|
||||||
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
|
|
||||||
backward = false;
|
backward = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -316,78 +240,93 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
|||||||
// pawn on neighboring files. We now check whether the pawn is
|
// pawn on neighboring files. We now check whether the pawn is
|
||||||
// backward by looking in the forward direction on the neighboring
|
// backward by looking in the forward direction on the neighboring
|
||||||
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
||||||
Bitboard b = pos.attacks_from<PAWN>(s, us);
|
b = pos.attacks_from<PAWN>(s, Us);
|
||||||
if (us == WHITE)
|
|
||||||
{
|
// Note that we are sure to find something because pawn is not passed
|
||||||
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
|
// nor isolated, so loop is potentially infinite, but it isn't.
|
||||||
backward = (b | (b << 8)) & theirPawns;
|
while (!(b & (ourPawns | theirPawns)))
|
||||||
}
|
Us == WHITE ? b <<= 8 : b >>= 8;
|
||||||
else
|
|
||||||
{
|
// The friendly pawn needs to be at least two ranks closer than the enemy
|
||||||
for ( ; !(b & (ourPawns | theirPawns)); b >>= 8);
|
// pawn in order to help the potentially backward pawn advance.
|
||||||
backward = (b | (b >> 8)) & theirPawns;
|
backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(passed | opposed | (attack_span_mask(Us, s) & theirPawns));
|
||||||
|
|
||||||
// Test for candidate passed pawn
|
// Test for candidate passed pawn
|
||||||
bool candidate;
|
candidate = !(opposed | passed)
|
||||||
candidate = !passed
|
&& (b = attack_span_mask(opposite_color(Us), s + pawn_push(Us)) & ourPawns) != EmptyBoardBB
|
||||||
&& !(theirPawns & file_bb(f))
|
&& count_1s_max_15(b) >= count_1s_max_15(attack_span_mask(Us, s) & theirPawns);
|
||||||
&& ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns)
|
|
||||||
- count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns)
|
|
||||||
>= 0);
|
|
||||||
|
|
||||||
// In order to prevent doubled passed pawns from receiving a too big
|
// In order to prevent doubled passed pawns from receiving a too big
|
||||||
// bonus, only the frontmost passed pawn on each file is considered as
|
// bonus, only the frontmost passed pawn on each file is considered as
|
||||||
// a true passed pawn.
|
// a true passed pawn.
|
||||||
if (passed && (ourPawns & squares_in_front_of(us, s)))
|
if (passed && (ourPawns & squares_in_front_of(Us, s)))
|
||||||
passed = false;
|
passed = false;
|
||||||
|
|
||||||
// Score this pawn
|
// Mark the pawn as passed. Pawn will be properly scored in evaluation
|
||||||
|
// because we need full attack info to evaluate passed pawns.
|
||||||
if (passed)
|
if (passed)
|
||||||
set_bit(&(pi->passedPawns), s);
|
set_bit(&(pi->passedPawns), s);
|
||||||
|
|
||||||
|
// Score this pawn
|
||||||
if (isolated)
|
if (isolated)
|
||||||
{
|
{
|
||||||
mgValue[us] -= IsolatedPawnMidgamePenalty[f];
|
value -= IsolatedPawnPenalty[f];
|
||||||
egValue[us] -= IsolatedPawnEndgamePenalty[f];
|
|
||||||
if (!(theirPawns & file_bb(f)))
|
if (!(theirPawns & file_bb(f)))
|
||||||
{
|
value -= IsolatedPawnPenalty[f] / 2;
|
||||||
mgValue[us] -= IsolatedPawnMidgamePenalty[f] / 2;
|
|
||||||
egValue[us] -= IsolatedPawnEndgamePenalty[f] / 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (doubled)
|
if (doubled)
|
||||||
{
|
value -= DoubledPawnPenalty[f];
|
||||||
mgValue[us] -= DoubledPawnMidgamePenalty[f];
|
|
||||||
egValue[us] -= DoubledPawnEndgamePenalty[f];
|
|
||||||
}
|
|
||||||
if (backward)
|
if (backward)
|
||||||
{
|
{
|
||||||
mgValue[us] -= BackwardPawnMidgamePenalty[f];
|
value -= BackwardPawnPenalty[f];
|
||||||
egValue[us] -= BackwardPawnEndgamePenalty[f];
|
|
||||||
if (!(theirPawns & file_bb(f)))
|
if (!(theirPawns & file_bb(f)))
|
||||||
{
|
value -= BackwardPawnPenalty[f] / 2;
|
||||||
mgValue[us] -= BackwardPawnMidgamePenalty[f] / 2;
|
|
||||||
egValue[us] -= BackwardPawnEndgamePenalty[f] / 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (chain)
|
if (chain)
|
||||||
{
|
value += ChainBonus[f];
|
||||||
mgValue[us] += ChainMidgameBonus[f];
|
|
||||||
egValue[us] += ChainEndgameBonus[f];
|
|
||||||
}
|
|
||||||
if (candidate)
|
|
||||||
{
|
|
||||||
mgValue[us] += CandidateMidgameBonus[relative_rank(us, s)];
|
|
||||||
egValue[us] += CandidateEndgameBonus[relative_rank(us, s)];
|
|
||||||
}
|
|
||||||
} // while(pawns)
|
|
||||||
} // for(colors)
|
|
||||||
|
|
||||||
pi->mgValue = int16_t(mgValue[WHITE] - mgValue[BLACK]);
|
if (candidate)
|
||||||
pi->egValue = int16_t(egValue[WHITE] - egValue[BLACK]);
|
value += CandidateBonus[relative_rank(Us, s)];
|
||||||
return pi;
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// PawnInfoTable::evaluate_pawn_storm() evaluates each pawn which seems
|
||||||
|
/// to have good chances of creating an open file by exchanging itself
|
||||||
|
/// against an enemy pawn on an adjacent file.
|
||||||
|
|
||||||
|
template<Color Us, PawnInfoTable::SideType Side>
|
||||||
|
int PawnInfoTable::evaluate_pawn_storm(Square s, Rank r, File f, Bitboard theirPawns) const {
|
||||||
|
|
||||||
|
const Bitboard StormFilesBB = (Side == KingSide ? FileFBB | FileGBB | FileHBB
|
||||||
|
: FileABB | FileBBB | FileCBB);
|
||||||
|
const int K = (Side == KingSide ? 2 : 4);
|
||||||
|
const File RookFile = (Side == KingSide ? FILE_H : FILE_A);
|
||||||
|
|
||||||
|
Bitboard b = attack_span_mask(Us, s) & theirPawns & StormFilesBB;
|
||||||
|
int bonus = 0;
|
||||||
|
|
||||||
|
while (b)
|
||||||
|
{
|
||||||
|
// Give a bonus according to the distance of the nearest enemy pawn
|
||||||
|
Square s2 = pop_1st_bit(&b);
|
||||||
|
Rank r2 = square_rank(s2);
|
||||||
|
int v = StormLeverBonus[f] - K * rank_distance(r, r2);
|
||||||
|
|
||||||
|
// If enemy pawn has no pawn beside itself is particularly vulnerable.
|
||||||
|
// Big bonus, especially against a weakness on the rook file
|
||||||
|
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||||
|
v *= (square_file(s2) == RookFile ? 4 : 2);
|
||||||
|
|
||||||
|
bonus += v;
|
||||||
|
}
|
||||||
|
return bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -395,9 +334,10 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
|||||||
/// only when king square changes, about 20% of total get_king_shelter() calls.
|
/// only when king square changes, about 20% of total get_king_shelter() calls.
|
||||||
int PawnInfo::updateShelter(const Position& pos, Color c, Square ksq) {
|
int PawnInfo::updateShelter(const Position& pos, Color c, Square ksq) {
|
||||||
|
|
||||||
unsigned shelter = 0;
|
|
||||||
Bitboard pawns = pos.pieces(PAWN, c) & this_and_neighboring_files_bb(ksq);
|
Bitboard pawns = pos.pieces(PAWN, c) & this_and_neighboring_files_bb(ksq);
|
||||||
|
unsigned shelter = 0;
|
||||||
unsigned r = ksq & (7 << 3);
|
unsigned r = ksq & (7 << 3);
|
||||||
|
|
||||||
for (int i = 1, k = (c ? -8 : 8); i < 4; i++)
|
for (int i = 1, k = (c ? -8 : 8); i < 4; i++)
|
||||||
{
|
{
|
||||||
r += k;
|
r += k;
|
||||||
|
|||||||
+16
-13
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -45,10 +45,9 @@ class PawnInfo {
|
|||||||
friend class PawnInfoTable;
|
friend class PawnInfoTable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PawnInfo() : key(0) { clear(); }
|
PawnInfo() { clear(); }
|
||||||
|
|
||||||
Value mg_value() const;
|
Score pawns_value() const;
|
||||||
Value eg_value() const;
|
|
||||||
Value kingside_storm_value(Color c) const;
|
Value kingside_storm_value(Color c) const;
|
||||||
Value queenside_storm_value(Color c) const;
|
Value queenside_storm_value(Color c) const;
|
||||||
Bitboard pawn_attacks(Color c) const;
|
Bitboard pawn_attacks(Color c) const;
|
||||||
@@ -65,10 +64,10 @@ private:
|
|||||||
Key key;
|
Key key;
|
||||||
Bitboard passedPawns;
|
Bitboard passedPawns;
|
||||||
Bitboard pawnAttacks[2];
|
Bitboard pawnAttacks[2];
|
||||||
int16_t mgValue, egValue;
|
Square kingSquares[2];
|
||||||
|
Score value;
|
||||||
int16_t ksStormValue[2], qsStormValue[2];
|
int16_t ksStormValue[2], qsStormValue[2];
|
||||||
uint8_t halfOpenFiles[2];
|
uint8_t halfOpenFiles[2];
|
||||||
Square kingSquares[2];
|
|
||||||
uint8_t kingShelters[2];
|
uint8_t kingShelters[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -79,12 +78,20 @@ private:
|
|||||||
|
|
||||||
class PawnInfoTable {
|
class PawnInfoTable {
|
||||||
|
|
||||||
|
enum SideType { KingSide, QueenSide };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PawnInfoTable(unsigned numOfEntries);
|
PawnInfoTable(unsigned numOfEntries);
|
||||||
~PawnInfoTable();
|
~PawnInfoTable();
|
||||||
PawnInfo* get_pawn_info(const Position& pos);
|
PawnInfo* get_pawn_info(const Position& pos) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template<Color Us>
|
||||||
|
Score evaluate_pawns(const Position& pos, Bitboard ourPawns, Bitboard theirPawns, PawnInfo* pi) const;
|
||||||
|
|
||||||
|
template<Color Us, SideType Side>
|
||||||
|
int evaluate_pawn_storm(Square s, Rank r, File f, Bitboard theirPawns) const;
|
||||||
|
|
||||||
unsigned size;
|
unsigned size;
|
||||||
PawnInfo* entries;
|
PawnInfo* entries;
|
||||||
};
|
};
|
||||||
@@ -94,12 +101,8 @@ private:
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
inline Value PawnInfo::mg_value() const {
|
inline Score PawnInfo::pawns_value() const {
|
||||||
return Value(mgValue);
|
return value;
|
||||||
}
|
|
||||||
|
|
||||||
inline Value PawnInfo::eg_value() const {
|
|
||||||
return Value(egValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard PawnInfo::passed_pawns() const {
|
inline Bitboard PawnInfo::passed_pawns() const {
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -38,7 +38,7 @@ static const string PieceChars(" pnbrqk PNBRQK");
|
|||||||
|
|
||||||
char piece_type_to_char(PieceType pt, bool upcase) {
|
char piece_type_to_char(PieceType pt, bool upcase) {
|
||||||
|
|
||||||
return PieceChars[pt + upcase * 7];
|
return PieceChars[pt + int(upcase) * 7];
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceType piece_type_from_char(char c) {
|
PieceType piece_type_from_char(char c) {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+306
-310
File diff suppressed because it is too large
Load Diff
+72
-77
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -63,6 +63,18 @@ const int MaxGameLength = 220;
|
|||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
|
/// struct checkInfo is initialized at c'tor time and keeps
|
||||||
|
/// info used to detect if a move gives check.
|
||||||
|
|
||||||
|
struct CheckInfo {
|
||||||
|
|
||||||
|
CheckInfo(const Position&);
|
||||||
|
|
||||||
|
Bitboard dcCandidates;
|
||||||
|
Bitboard checkSq[8];
|
||||||
|
Square ksq;
|
||||||
|
};
|
||||||
|
|
||||||
/// Castle rights, encoded as bit fields
|
/// Castle rights, encoded as bit fields
|
||||||
|
|
||||||
enum CastleRights {
|
enum CastleRights {
|
||||||
@@ -87,13 +99,14 @@ enum Phase {
|
|||||||
/// must be passed as a parameter.
|
/// must be passed as a parameter.
|
||||||
|
|
||||||
struct StateInfo {
|
struct StateInfo {
|
||||||
Key key, pawnKey, materialKey;
|
Key pawnKey, materialKey;
|
||||||
int castleRights, rule50;
|
int castleRights, rule50, gamePly, pliesFromNull;
|
||||||
Square epSquare;
|
Square epSquare;
|
||||||
Value mgValue, egValue;
|
Score value;
|
||||||
Value npMaterial[2];
|
Value npMaterial[2];
|
||||||
|
|
||||||
PieceType capture;
|
PieceType capture;
|
||||||
|
Key key;
|
||||||
Bitboard checkersBB;
|
Bitboard checkersBB;
|
||||||
StateInfo* previous;
|
StateInfo* previous;
|
||||||
};
|
};
|
||||||
@@ -126,6 +139,9 @@ class Position {
|
|||||||
friend class MaterialInfo;
|
friend class MaterialInfo;
|
||||||
friend class EndgameFunctions;
|
friend class EndgameFunctions;
|
||||||
|
|
||||||
|
Position(); // No default or copy c'tor allowed
|
||||||
|
Position(const Position& pos);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum GamePhase {
|
enum GamePhase {
|
||||||
MidGame,
|
MidGame,
|
||||||
@@ -133,9 +149,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
Position() {}
|
explicit Position(int threadID);
|
||||||
Position(const Position& pos);
|
Position(const Position& pos, int threadID);
|
||||||
Position(const std::string& fen);
|
Position(const std::string& fen, int threadID);
|
||||||
|
|
||||||
// Text input/output
|
// Text input/output
|
||||||
void from_fen(const std::string& fen);
|
void from_fen(const std::string& fen);
|
||||||
@@ -143,7 +159,6 @@ public:
|
|||||||
void print(Move m = MOVE_NONE) const;
|
void print(Move m = MOVE_NONE) const;
|
||||||
|
|
||||||
// Copying
|
// Copying
|
||||||
void copy(const Position& pos);
|
|
||||||
void flipped_copy(const Position& pos);
|
void flipped_copy(const Position& pos);
|
||||||
|
|
||||||
// The piece on a given square
|
// The piece on a given square
|
||||||
@@ -202,27 +217,28 @@ public:
|
|||||||
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||||
|
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool pl_move_is_legal(Move m) const;
|
|
||||||
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
||||||
|
bool pl_move_is_evasion(Move m, Bitboard pinned) const;
|
||||||
bool move_is_check(Move m) const;
|
bool move_is_check(Move m) const;
|
||||||
bool move_is_check(Move m, Bitboard dcCandidates) const;
|
bool move_is_check(Move m, const CheckInfo& ci) const;
|
||||||
bool move_is_capture(Move m) const;
|
bool move_is_capture(Move m) const;
|
||||||
|
bool move_is_capture_or_promotion(Move m) const;
|
||||||
bool move_is_passed_pawn_push(Move m) const;
|
bool move_is_passed_pawn_push(Move m) const;
|
||||||
bool move_attacks_square(Move m, Square s) const;
|
bool move_attacks_square(Move m, Square s) const;
|
||||||
|
|
||||||
|
// Piece captured with previous moves
|
||||||
|
PieceType captured_piece() const;
|
||||||
|
|
||||||
// Information about pawns
|
// Information about pawns
|
||||||
bool pawn_is_passed(Color c, Square s) const;
|
bool pawn_is_passed(Color c, Square s) const;
|
||||||
static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
|
|
||||||
static bool pawn_is_isolated(Bitboard ourPawns, Square s);
|
|
||||||
static bool pawn_is_doubled(Bitboard ourPawns, Color c, Square s);
|
|
||||||
|
|
||||||
// Weak squares
|
// Weak squares
|
||||||
bool square_is_weak(Square s, Color c) const;
|
bool square_is_weak(Square s, Color c) const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void saveState();
|
void detach();
|
||||||
void do_move(Move m, StateInfo& st);
|
void do_move(Move m, StateInfo& st);
|
||||||
void do_move(Move m, StateInfo& st, Bitboard dcCandidates);
|
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
void do_null_move(StateInfo& st);
|
void do_null_move(StateInfo& st);
|
||||||
void undo_null_move();
|
void undo_null_move();
|
||||||
@@ -235,15 +251,14 @@ public:
|
|||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key get_key() const;
|
Key get_key() const;
|
||||||
|
Key get_exclusion_key() const;
|
||||||
Key get_pawn_key() const;
|
Key get_pawn_key() const;
|
||||||
Key get_material_key() const;
|
Key get_material_key() const;
|
||||||
|
|
||||||
// Incremental evaluation
|
// Incremental evaluation
|
||||||
Value mg_value() const;
|
Score value() const;
|
||||||
Value eg_value() const;
|
|
||||||
Value non_pawn_material(Color c) const;
|
Value non_pawn_material(Color c) const;
|
||||||
Phase game_phase() const;
|
Score pst_delta(Piece piece, Square from, Square to) const;
|
||||||
template<GamePhase> Value pst_delta(Piece piece, Square from, Square to) const;
|
|
||||||
|
|
||||||
// Game termination checks
|
// Game termination checks
|
||||||
bool is_mate() const;
|
bool is_mate() const;
|
||||||
@@ -259,6 +274,9 @@ public:
|
|||||||
bool opposite_colored_bishops() const;
|
bool opposite_colored_bishops() const;
|
||||||
bool has_pawn_on_7th(Color c) const;
|
bool has_pawn_on_7th(Color c) const;
|
||||||
|
|
||||||
|
// Current thread ID searching on the position
|
||||||
|
int thread() const;
|
||||||
|
|
||||||
// Reset the gamePly variable to 0
|
// Reset the gamePly variable to 0
|
||||||
void reset_game_ply();
|
void reset_game_ply();
|
||||||
|
|
||||||
@@ -278,14 +296,11 @@ private:
|
|||||||
void allow_ooo(Color c);
|
void allow_ooo(Color c);
|
||||||
|
|
||||||
// Helper functions for doing and undoing moves
|
// Helper functions for doing and undoing moves
|
||||||
void do_capture_move(Bitboard& key, PieceType capture, Color them, Square to, bool ep);
|
void do_capture_move(Key& key, PieceType capture, Color them, Square to, bool ep);
|
||||||
void do_castle_move(Move m);
|
void do_castle_move(Move m);
|
||||||
void undo_castle_move(Move m);
|
void undo_castle_move(Move m);
|
||||||
void find_checkers();
|
void find_checkers();
|
||||||
|
|
||||||
template<PieceType Piece>
|
|
||||||
void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
|
|
||||||
|
|
||||||
template<bool FindPinned>
|
template<bool FindPinned>
|
||||||
Bitboard hidden_checkers(Color c) const;
|
Bitboard hidden_checkers(Color c) const;
|
||||||
|
|
||||||
@@ -295,8 +310,8 @@ private:
|
|||||||
Key compute_material_key() const;
|
Key compute_material_key() const;
|
||||||
|
|
||||||
// Computing incremental evaluation scores and material counts
|
// Computing incremental evaluation scores and material counts
|
||||||
template<GamePhase> Value pst(Color c, PieceType pt, Square s) const;
|
Score pst(Color c, PieceType pt, Square s) const;
|
||||||
template<GamePhase> Value compute_value() const;
|
Score compute_value() const;
|
||||||
Value compute_non_pawn_material(Color c) const;
|
Value compute_non_pawn_material(Color c) const;
|
||||||
|
|
||||||
// Board
|
// Board
|
||||||
@@ -314,21 +329,20 @@ private:
|
|||||||
|
|
||||||
// Other info
|
// Other info
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
int gamePly;
|
|
||||||
Key history[MaxGameLength];
|
Key history[MaxGameLength];
|
||||||
File initialKFile, initialKRFile, initialQRFile;
|
int castleRightsMask[64];
|
||||||
StateInfo startState;
|
StateInfo startState;
|
||||||
|
File initialKFile, initialKRFile, initialQRFile;
|
||||||
|
int threadID;
|
||||||
StateInfo* st;
|
StateInfo* st;
|
||||||
|
|
||||||
// Static variables
|
// Static variables
|
||||||
static int castleRightsMask[64];
|
|
||||||
static Key zobrist[2][8][64];
|
static Key zobrist[2][8][64];
|
||||||
static Key zobEp[64];
|
static Key zobEp[64];
|
||||||
static Key zobCastle[16];
|
static Key zobCastle[16];
|
||||||
static Key zobMaterial[2][8][16];
|
|
||||||
static Key zobSideToMove;
|
static Key zobSideToMove;
|
||||||
static Value MgPieceSquareTable[16][64];
|
static Score PieceSquareTable[16][64];
|
||||||
static Value EgPieceSquareTable[16][64];
|
static Key zobExclusion;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -400,8 +414,8 @@ inline int Position::piece_count(Color c, PieceType pt) const {
|
|||||||
return pieceCount[c][pt];
|
return pieceCount[c][pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::piece_list(Color c, PieceType pt, int index) const {
|
inline Square Position::piece_list(Color c, PieceType pt, int idx) const {
|
||||||
return pieceList[c][pt][index];
|
return pieceList[c][pt][idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Square* Position::piece_list_begin(Color c, PieceType pt) const {
|
inline const Square* Position::piece_list_begin(Color c, PieceType pt) const {
|
||||||
@@ -473,26 +487,18 @@ inline bool Position::pawn_is_passed(Color c, Square s) const {
|
|||||||
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
|
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) {
|
|
||||||
return !(theirPawns & passed_pawn_mask(c, s));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::pawn_is_isolated(Bitboard ourPawns, Square s) {
|
|
||||||
return !(ourPawns & neighboring_files_bb(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::pawn_is_doubled(Bitboard ourPawns, Color c, Square s) {
|
|
||||||
return ourPawns & squares_behind(c, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::square_is_weak(Square s, Color c) const {
|
inline bool Position::square_is_weak(Square s, Color c) const {
|
||||||
return !(pieces(PAWN, c) & outpost_mask(opposite_color(c), s));
|
return !(pieces(PAWN, opposite_color(c)) & attack_span_mask(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_key() const {
|
inline Key Position::get_key() const {
|
||||||
return st->key;
|
return st->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Key Position::get_exclusion_key() const {
|
||||||
|
return st->key ^ zobExclusion;
|
||||||
|
}
|
||||||
|
|
||||||
inline Key Position::get_pawn_key() const {
|
inline Key Position::get_pawn_key() const {
|
||||||
return st->pawnKey;
|
return st->pawnKey;
|
||||||
}
|
}
|
||||||
@@ -501,46 +507,22 @@ inline Key Position::get_material_key() const {
|
|||||||
return st->materialKey;
|
return st->materialKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Position::GamePhase Ph>
|
inline Score Position::pst(Color c, PieceType pt, Square s) const {
|
||||||
inline Value Position::pst(Color c, PieceType pt, Square s) const {
|
return PieceSquareTable[piece_of_color_and_type(c, pt)][s];
|
||||||
return (Ph == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
|
|
||||||
: EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Position::GamePhase Ph>
|
inline Score Position::pst_delta(Piece piece, Square from, Square to) const {
|
||||||
inline Value Position::pst_delta(Piece piece, Square from, Square to) const {
|
return PieceSquareTable[piece][to] - PieceSquareTable[piece][from];
|
||||||
return (Ph == MidGame ? MgPieceSquareTable[piece][to] - MgPieceSquareTable[piece][from]
|
|
||||||
: EgPieceSquareTable[piece][to] - EgPieceSquareTable[piece][from]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::mg_value() const {
|
inline Score Position::value() const {
|
||||||
return st->mgValue;
|
return st->value;
|
||||||
}
|
|
||||||
|
|
||||||
inline Value Position::eg_value() const {
|
|
||||||
return st->egValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::non_pawn_material(Color c) const {
|
inline Value Position::non_pawn_material(Color c) const {
|
||||||
return st->npMaterial[c];
|
return st->npMaterial[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Phase Position::game_phase() const {
|
|
||||||
|
|
||||||
// Values modified by Joona Kiiski
|
|
||||||
static const Value MidgameLimit = Value(15581);
|
|
||||||
static const Value EndgameLimit = Value(3998);
|
|
||||||
|
|
||||||
Value npm = non_pawn_material(WHITE) + non_pawn_material(BLACK);
|
|
||||||
|
|
||||||
if (npm >= MidgameLimit)
|
|
||||||
return PHASE_MIDGAME;
|
|
||||||
else if(npm <= EndgameLimit)
|
|
||||||
return PHASE_ENDGAME;
|
|
||||||
else
|
|
||||||
return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
||||||
|
|
||||||
Color c = side_to_move();
|
Color c = side_to_move();
|
||||||
@@ -568,8 +550,21 @@ inline bool Position::has_pawn_on_7th(Color c) const {
|
|||||||
inline bool Position::move_is_capture(Move m) const {
|
inline bool Position::move_is_capture(Move m) const {
|
||||||
|
|
||||||
// Move must not be MOVE_NONE !
|
// Move must not be MOVE_NONE !
|
||||||
|
return (m & (3 << 15)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
|
||||||
|
}
|
||||||
|
|
||||||
return (!square_is_empty(move_to(m)) && !move_is_castle(m)) || move_is_ep(m);
|
inline bool Position::move_is_capture_or_promotion(Move m) const {
|
||||||
|
|
||||||
|
// Move must not be MOVE_NONE !
|
||||||
|
return (m & (0x1F << 12)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline PieceType Position::captured_piece() const {
|
||||||
|
return st->capture;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int Position::thread() const {
|
||||||
|
return threadID;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !defined(POSITION_H_INCLUDED)
|
#endif // !defined(POSITION_H_INCLUDED)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+15
-12
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -63,7 +63,7 @@ namespace {
|
|||||||
/// that the move is a legal move from the position. The return value is
|
/// that the move is a legal move from the position. The return value is
|
||||||
/// a string containing the move in short algebraic notation.
|
/// a string containing the move in short algebraic notation.
|
||||||
|
|
||||||
const string move_to_san(const Position& pos, Move m) {
|
const string move_to_san(Position& pos, Move m) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
@@ -123,10 +123,10 @@ const string move_to_san(const Position& pos, Move m) {
|
|||||||
// Position::move_is_check doesn't detect all checks (not castling moves,
|
// Position::move_is_check doesn't detect all checks (not castling moves,
|
||||||
// promotions and en passant captures).
|
// promotions and en passant captures).
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
Position p(pos);
|
pos.do_move(m, st);
|
||||||
p.do_move(m, st);
|
if (pos.is_check())
|
||||||
if (p.is_check())
|
san += pos.is_mate() ? "#" : "+";
|
||||||
san += p.is_mate()? "#" : "+";
|
pos.undo_move(m);
|
||||||
|
|
||||||
return san;
|
return san;
|
||||||
}
|
}
|
||||||
@@ -142,13 +142,14 @@ Move move_from_san(const Position& pos, const string& movestr) {
|
|||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
||||||
|
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||||
|
|
||||||
// Castling moves
|
// Castling moves
|
||||||
if (movestr == "O-O-O" || movestr == "O-O-O+")
|
if (movestr == "O-O-O" || movestr == "O-O-O+")
|
||||||
{
|
{
|
||||||
Move m;
|
Move m;
|
||||||
while ((m = mp.get_next_move()) != MOVE_NONE)
|
while ((m = mp.get_next_move()) != MOVE_NONE)
|
||||||
if (move_is_long_castle(m) && pos.pl_move_is_legal(m))
|
if (move_is_long_castle(m) && pos.pl_move_is_legal(m, pinned))
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
@@ -157,7 +158,7 @@ Move move_from_san(const Position& pos, const string& movestr) {
|
|||||||
{
|
{
|
||||||
Move m;
|
Move m;
|
||||||
while ((m = mp.get_next_move()) != MOVE_NONE)
|
while ((m = mp.get_next_move()) != MOVE_NONE)
|
||||||
if (move_is_short_castle(m) && pos.pl_move_is_legal(m))
|
if (move_is_short_castle(m) && pos.pl_move_is_legal(m, pinned))
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
@@ -298,7 +299,7 @@ const string line_to_san(const Position& pos, Move line[], int startColumn, bool
|
|||||||
string moveStr;
|
string moveStr;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
size_t maxLength = 80 - startColumn;
|
size_t maxLength = 80 - startColumn;
|
||||||
Position p(pos);
|
Position p(pos, pos.thread());
|
||||||
|
|
||||||
for (int i = 0; line[i] != MOVE_NONE; i++)
|
for (int i = 0; line[i] != MOVE_NONE; i++)
|
||||||
{
|
{
|
||||||
@@ -325,14 +326,15 @@ const string line_to_san(const Position& pos, Move line[], int startColumn, bool
|
|||||||
/// when the UCI parameter "Use Search Log" is "true").
|
/// when the UCI parameter "Use Search Log" is "true").
|
||||||
|
|
||||||
const string pretty_pv(const Position& pos, int time, int depth,
|
const string pretty_pv(const Position& pos, int time, int depth,
|
||||||
uint64_t nodes, Value score, Move pv[]) {
|
uint64_t nodes, Value score, ValueType type, Move pv[]) {
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
|
||||||
// Depth
|
// Depth
|
||||||
s << std::setw(2) << depth << " ";
|
s << std::setw(2) << depth << " ";
|
||||||
|
|
||||||
// Score
|
// Score
|
||||||
s << std::setw(8) << score_string(score);
|
s << ((type == VALUE_TYPE_LOWER)? ">" : ((type == VALUE_TYPE_UPPER)? "<" : " "));
|
||||||
|
s << std::setw(7) << score_string(score);
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
s << std::setw(8) << time_string(time) << " ";
|
s << std::setw(8) << time_string(time) << " ";
|
||||||
@@ -366,11 +368,12 @@ namespace {
|
|||||||
return AMBIGUITY_NONE;
|
return AMBIGUITY_NONE;
|
||||||
|
|
||||||
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
||||||
|
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||||
Move mv, moveList[8];
|
Move mv, moveList[8];
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while ((mv = mp.get_next_move()) != MOVE_NONE)
|
while ((mv = mp.get_next_move()) != MOVE_NONE)
|
||||||
if (move_to(mv) == to && pos.piece_on(move_from(mv)) == pc && pos.pl_move_is_legal(mv))
|
if (move_to(mv) == to && pos.piece_on(move_from(mv)) == pc && pos.pl_move_is_legal(mv, pinned))
|
||||||
moveList[n++] = mv;
|
moveList[n++] = mv;
|
||||||
|
|
||||||
if (n == 1)
|
if (n == 1)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -36,9 +36,9 @@
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern const std::string move_to_san(const Position& pos, Move m);
|
extern const std::string move_to_san(Position& pos, Move m);
|
||||||
extern Move move_from_san(const Position& pos, const std::string& str);
|
extern Move move_from_san(const Position& pos, const std::string& str);
|
||||||
extern const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines);
|
extern const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines);
|
||||||
extern const std::string pretty_pv(const Position& pos, int time, int depth, uint64_t nodes, Value score, Move pv[]);
|
extern const std::string pretty_pv(const Position& pos, int time, int depth, uint64_t nodes, Value score, ValueType type, Move pv[]);
|
||||||
|
|
||||||
#endif // !defined(SAN_H_INCLUDED)
|
#endif // !defined(SAN_H_INCLUDED)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1698
-1722
File diff suppressed because it is too large
Load Diff
+11
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
#include "value.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -46,16 +47,20 @@ const int KILLER_MAX = 2;
|
|||||||
/// from nodes shallower and deeper in the tree during the search. Each
|
/// from nodes shallower and deeper in the tree during the search. Each
|
||||||
/// search thread has its own array of SearchStack objects, indexed by the
|
/// search thread has its own array of SearchStack objects, indexed by the
|
||||||
/// current ply.
|
/// current ply.
|
||||||
|
struct EvalInfo;
|
||||||
|
|
||||||
struct SearchStack {
|
struct SearchStack {
|
||||||
Move pv[PLY_MAX];
|
Move pv[PLY_MAX_PLUS_2];
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Move mateKiller;
|
Move mateKiller;
|
||||||
Move threatMove;
|
Move threatMove;
|
||||||
|
Move excludedMove;
|
||||||
Move killers[KILLER_MAX];
|
Move killers[KILLER_MAX];
|
||||||
Depth reduction;
|
Depth reduction;
|
||||||
|
Value eval;
|
||||||
|
bool skipNullMove;
|
||||||
|
|
||||||
void init(int ply);
|
void init();
|
||||||
void initKillers();
|
void initKillers();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -64,11 +69,13 @@ struct SearchStack {
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
extern void init_search();
|
||||||
extern void init_threads();
|
extern void init_threads();
|
||||||
extern void stop_threads();
|
extern void exit_threads();
|
||||||
extern bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
extern bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
||||||
int time[], int increment[], int movesToGo, int maxDepth,
|
int time[], int increment[], int movesToGo, int maxDepth,
|
||||||
int maxNodes, int maxTime, Move searchMoves[]);
|
int maxNodes, int maxTime, Move searchMoves[]);
|
||||||
|
extern int perft(Position &pos, Depth depth);
|
||||||
extern int64_t nodes_searched();
|
extern int64_t nodes_searched();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+38
-23
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,6 +26,8 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
@@ -36,7 +38,8 @@
|
|||||||
//// Constants and variables
|
//// Constants and variables
|
||||||
////
|
////
|
||||||
|
|
||||||
const int THREAD_MAX = 8;
|
const int MAX_THREADS = 8;
|
||||||
|
const int ACTIVE_SPLIT_POINTS_MAX = 8;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -44,35 +47,47 @@ const int THREAD_MAX = 8;
|
|||||||
////
|
////
|
||||||
|
|
||||||
struct SplitPoint {
|
struct SplitPoint {
|
||||||
SplitPoint *parent;
|
|
||||||
Position pos;
|
// Const data after splitPoint has been setup
|
||||||
SearchStack sstack[THREAD_MAX][PLY_MAX];
|
SplitPoint* parent;
|
||||||
SearchStack *parentSstack;
|
const Position* pos;
|
||||||
int ply;
|
|
||||||
Depth depth;
|
Depth depth;
|
||||||
volatile Value alpha, beta, bestValue;
|
bool pvNode, mateThreat;
|
||||||
bool pvNode;
|
Value beta;
|
||||||
Bitboard dcCandidates;
|
int ply;
|
||||||
int master, slaves[THREAD_MAX];
|
SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
|
||||||
|
|
||||||
|
// Const pointers to shared data
|
||||||
|
MovePicker* mp;
|
||||||
|
SearchStack* parentSstack;
|
||||||
|
|
||||||
|
// Shared data
|
||||||
Lock lock;
|
Lock lock;
|
||||||
MovePicker *mp;
|
volatile Value alpha;
|
||||||
volatile int moves;
|
volatile Value bestValue;
|
||||||
volatile int cpus;
|
volatile int moveCount;
|
||||||
bool finished;
|
volatile bool stopRequest;
|
||||||
|
volatile int slaves[MAX_THREADS];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ThreadState type is used to represent thread's current state
|
||||||
|
|
||||||
|
enum ThreadState
|
||||||
|
{
|
||||||
|
THREAD_SEARCHING, // thread is performing work
|
||||||
|
THREAD_AVAILABLE, // thread is polling for work
|
||||||
|
THREAD_SLEEPING, // we are not thinking, so thread is sleeping
|
||||||
|
THREAD_BOOKED, // other thread (master) has booked us as a slave
|
||||||
|
THREAD_WORKISWAITING, // master has ordered us to start
|
||||||
|
THREAD_TERMINATED // we are quitting and thread is terminated
|
||||||
|
};
|
||||||
|
|
||||||
struct Thread {
|
struct Thread {
|
||||||
SplitPoint *splitPoint;
|
SplitPoint* volatile splitPoint;
|
||||||
int activeSplitPoints;
|
volatile int activeSplitPoints;
|
||||||
uint64_t nodes;
|
uint64_t nodes;
|
||||||
uint64_t betaCutOffs[2];
|
uint64_t betaCutOffs[2];
|
||||||
bool failHighPly1;
|
volatile ThreadState state;
|
||||||
volatile bool stop;
|
|
||||||
volatile bool running;
|
|
||||||
volatile bool idle;
|
|
||||||
volatile bool workIsWaiting;
|
|
||||||
volatile bool printCurrentLine;
|
|
||||||
unsigned char pad[64]; // set some distance among local data for each thread
|
unsigned char pad[64]; // set some distance among local data for each thread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+27
-63
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <xmmintrin.h>
|
|
||||||
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
@@ -53,11 +52,9 @@ TranspositionTable::~TranspositionTable() {
|
|||||||
/// TranspositionTable::set_size sets the size of the transposition table,
|
/// TranspositionTable::set_size sets the size of the transposition table,
|
||||||
/// measured in megabytes.
|
/// measured in megabytes.
|
||||||
|
|
||||||
void TranspositionTable::set_size(unsigned mbSize) {
|
void TranspositionTable::set_size(size_t mbSize) {
|
||||||
|
|
||||||
assert(mbSize >= 4 && mbSize <= 4096);
|
size_t newSize = 1024;
|
||||||
|
|
||||||
unsigned newSize = 1024;
|
|
||||||
|
|
||||||
// We store a cluster of ClusterSize number of TTEntry for each position
|
// We store a cluster of ClusterSize number of TTEntry for each position
|
||||||
// and newSize is the maximum number of storable positions.
|
// and newSize is the maximum number of storable positions.
|
||||||
@@ -91,16 +88,6 @@ void TranspositionTable::clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::first_entry returns a pointer to the first
|
|
||||||
/// entry of a cluster given a position. The low 32 bits of the key
|
|
||||||
/// are used to get the index in the table.
|
|
||||||
|
|
||||||
inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
|
|
||||||
|
|
||||||
return entries[uint32_t(posKey) & (size - 1)].data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::store writes a new entry containing a position,
|
/// TranspositionTable::store writes a new entry containing a position,
|
||||||
/// a value, a value type, a search depth, and a best move to the
|
/// a value, a value type, a search depth, and a best move to the
|
||||||
/// transposition table. Transposition table is organized in clusters of
|
/// transposition table. Transposition table is organized in clusters of
|
||||||
@@ -111,7 +98,7 @@ inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
|
|||||||
/// is bigger than the depth of t2. A TTEntry of type VALUE_TYPE_EVAL
|
/// is bigger than the depth of t2. A TTEntry of type VALUE_TYPE_EVAL
|
||||||
/// never replaces another entry for the same position.
|
/// never replaces another entry for the same position.
|
||||||
|
|
||||||
void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, Move m) {
|
void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, Move m, Value statV, Value kingD) {
|
||||||
|
|
||||||
TTEntry *tte, *replace;
|
TTEntry *tte, *replace;
|
||||||
uint32_t posKey32 = posKey >> 32; // Use the high 32 bits as key
|
uint32_t posKey32 = posKey >> 32; // Use the high 32 bits as key
|
||||||
@@ -121,14 +108,11 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
|
|||||||
{
|
{
|
||||||
if (!tte->key() || tte->key() == posKey32) // empty or overwrite old
|
if (!tte->key() || tte->key() == posKey32) // empty or overwrite old
|
||||||
{
|
{
|
||||||
// Do not overwrite when new type is VALUE_TYPE_EV_LO
|
// Preserve any exsisting ttMove
|
||||||
if (tte->key() && t == VALUE_TYPE_EV_LO)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (m == MOVE_NONE)
|
if (m == MOVE_NONE)
|
||||||
m = tte->move();
|
m = tte->move();
|
||||||
|
|
||||||
*tte = TTEntry(posKey32, v, t, d, m, generation);
|
tte->save(posKey32, v, t, d, m, generation, statV, kingD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (i == 0) // replace would be a no-op in this common case
|
else if (i == 0) // replace would be a no-op in this common case
|
||||||
@@ -141,7 +125,7 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
|
|||||||
if (c1 + c2 + c3 > 0)
|
if (c1 + c2 + c3 > 0)
|
||||||
replace = tte;
|
replace = tte;
|
||||||
}
|
}
|
||||||
*replace = TTEntry(posKey32, v, t, d, m, generation);
|
replace->save(posKey32, v, t, d, m, generation, statV, kingD);
|
||||||
writes++;
|
writes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,27 +147,6 @@ TTEntry* TranspositionTable::retrieve(const Key posKey) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::prefetch looks up the current position in the
|
|
||||||
/// transposition table and load it in L1/L2 cache. This is a non
|
|
||||||
/// blocking function and do not stalls the CPU waiting for data
|
|
||||||
/// to be loaded from RAM, that can be very slow. When we will
|
|
||||||
/// subsequently call retrieve() the TT data will be already
|
|
||||||
/// quickly accessible in L1/L2 CPU cache.
|
|
||||||
|
|
||||||
void TranspositionTable::prefetch(const Key posKey) const {
|
|
||||||
|
|
||||||
#if defined(__INTEL_COMPILER) || defined(__ICL)
|
|
||||||
// This hack prevents prefetches to be optimized away by the
|
|
||||||
// Intel compiler. Both MSVC and gcc seems not affected.
|
|
||||||
__asm__ ("");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char const* addr = (char*)first_entry(posKey);
|
|
||||||
_mm_prefetch(addr, _MM_HINT_T2);
|
|
||||||
_mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::new_search() is called at the beginning of every new
|
/// TranspositionTable::new_search() is called at the beginning of every new
|
||||||
/// search. It increments the "generation" variable, which is used to
|
/// search. It increments the "generation" variable, which is used to
|
||||||
/// distinguish transposition table entries from previous searches from
|
/// distinguish transposition table entries from previous searches from
|
||||||
@@ -204,11 +167,13 @@ void TranspositionTable::new_search() {
|
|||||||
void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
||||||
|
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
Position p(pos);
|
Position p(pos, pos.thread());
|
||||||
|
|
||||||
for (int i = 0; pv[i] != MOVE_NONE; i++)
|
for (int i = 0; pv[i] != MOVE_NONE; i++)
|
||||||
{
|
{
|
||||||
store(p.get_key(), VALUE_NONE, VALUE_TYPE_NONE, Depth(-127*OnePly), pv[i]);
|
TTEntry *tte = retrieve(p.get_key());
|
||||||
|
if (!tte || tte->move() != pv[i])
|
||||||
|
store(p.get_key(), VALUE_NONE, VALUE_TYPE_NONE, Depth(-127*OnePly), pv[i], VALUE_NONE, VALUE_NONE);
|
||||||
p.do_move(pv[i], st);
|
p.do_move(pv[i], st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,27 +185,26 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
|||||||
/// will often get single-move PVs when the search stops while failing high,
|
/// will often get single-move PVs when the search stops while failing high,
|
||||||
/// and a single-move PV means that we don't have a ponder move.
|
/// and a single-move PV means that we don't have a ponder move.
|
||||||
|
|
||||||
void TranspositionTable::extract_pv(const Position& pos, Move pv[]) {
|
void TranspositionTable::extract_pv(const Position& pos, Move pv[], const int PLY_MAX) {
|
||||||
|
|
||||||
int ply;
|
|
||||||
Position p(pos);
|
|
||||||
StateInfo st[100];
|
|
||||||
|
|
||||||
for (ply = 0; pv[ply] != MOVE_NONE; ply++)
|
|
||||||
p.do_move(pv[ply], st[ply]);
|
|
||||||
|
|
||||||
bool stop;
|
|
||||||
const TTEntry* tte;
|
const TTEntry* tte;
|
||||||
for (stop = false, tte = retrieve(p.get_key());
|
StateInfo st;
|
||||||
tte && tte->move() != MOVE_NONE && !stop;
|
Position p(pos, pos.thread());
|
||||||
tte = retrieve(p.get_key()), ply++)
|
int ply = 0;
|
||||||
|
|
||||||
|
// Update position to the end of current PV
|
||||||
|
while (pv[ply] != MOVE_NONE)
|
||||||
|
p.do_move(pv[ply++], st);
|
||||||
|
|
||||||
|
// Try to add moves from TT while possible
|
||||||
|
while ( (tte = retrieve(p.get_key())) != NULL
|
||||||
|
&& tte->move() != MOVE_NONE
|
||||||
|
&& move_is_legal(p, tte->move())
|
||||||
|
&& (!p.is_draw() || ply < 2)
|
||||||
|
&& ply < PLY_MAX)
|
||||||
{
|
{
|
||||||
if (!move_is_legal(p, tte->move()))
|
|
||||||
break;
|
|
||||||
pv[ply] = tte->move();
|
pv[ply] = tte->move();
|
||||||
p.do_move(pv[ply], st[ply]);
|
p.do_move(pv[ply++], st);
|
||||||
for (int j = 0; j < ply; j++)
|
|
||||||
if (st[j].key == p.get_key()) stop = true;
|
|
||||||
}
|
}
|
||||||
pv[ply] = MOVE_NONE;
|
pv[ply] = MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -53,36 +53,45 @@
|
|||||||
class TTEntry {
|
class TTEntry {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TTEntry() {}
|
void save(uint32_t k, Value v, ValueType t, Depth d, Move m, int g, Value statV, Value kd) {
|
||||||
TTEntry(uint32_t k, Value v, ValueType t, Depth d, Move m, int generation)
|
|
||||||
: key_ (k), data((m & 0x1FFFF) | (t << 20) | (generation << 23)),
|
|
||||||
value_(int16_t(v)), depth_(int16_t(d)) {}
|
|
||||||
|
|
||||||
uint32_t key() const { return key_; }
|
key32 = k;
|
||||||
Depth depth() const { return Depth(depth_); }
|
data = (m & 0x1FFFF) | (t << 20) | (g << 23);
|
||||||
|
value16 = int16_t(v);
|
||||||
|
depth16 = int16_t(d);
|
||||||
|
staticValue = int16_t(statV);
|
||||||
|
kingDanger = int16_t(kd);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t key() const { return key32; }
|
||||||
|
Depth depth() const { return Depth(depth16); }
|
||||||
Move move() const { return Move(data & 0x1FFFF); }
|
Move move() const { return Move(data & 0x1FFFF); }
|
||||||
Value value() const { return Value(value_); }
|
Value value() const { return Value(value16); }
|
||||||
ValueType type() const { return ValueType((data >> 20) & 7); }
|
ValueType type() const { return ValueType((data >> 20) & 7); }
|
||||||
int generation() const { return (data >> 23); }
|
int generation() const { return data >> 23; }
|
||||||
|
Value static_value() const { return Value(staticValue); }
|
||||||
|
Value king_danger() const { return Value(kingDanger); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t key_;
|
uint32_t key32;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
int16_t value_;
|
int16_t value16;
|
||||||
int16_t depth_;
|
int16_t depth16;
|
||||||
|
int16_t staticValue;
|
||||||
|
int16_t kingDanger;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// This is the number of TTEntry slots for each position
|
/// This is the number of TTEntry slots for each position
|
||||||
const int ClusterSize = 5;
|
const int ClusterSize = 4;
|
||||||
|
|
||||||
/// Each group of ClusterSize number of TTEntry form a TTCluster
|
/// Each group of ClusterSize number of TTEntry form a TTCluster
|
||||||
/// that is indexed by a single position key. Cluster is padded
|
/// that is indexed by a single position key. TTCluster size must
|
||||||
/// to a cache line size so to guarantee always aligned accesses.
|
/// be not bigger then a cache line size, in case it is less then
|
||||||
|
/// it should be padded to guarantee always aligned accesses.
|
||||||
|
|
||||||
struct TTCluster {
|
struct TTCluster {
|
||||||
TTEntry data[ClusterSize];
|
TTEntry data[ClusterSize];
|
||||||
char cache_line_padding[64 - sizeof(TTEntry[ClusterSize])];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -95,30 +104,38 @@ class TranspositionTable {
|
|||||||
public:
|
public:
|
||||||
TranspositionTable();
|
TranspositionTable();
|
||||||
~TranspositionTable();
|
~TranspositionTable();
|
||||||
void set_size(unsigned mbSize);
|
void set_size(size_t mbSize);
|
||||||
void clear();
|
void clear();
|
||||||
void store(const Key posKey, Value v, ValueType type, Depth d, Move m);
|
void store(const Key posKey, Value v, ValueType type, Depth d, Move m, Value statV, Value kingD);
|
||||||
TTEntry* retrieve(const Key posKey) const;
|
TTEntry* retrieve(const Key posKey) const;
|
||||||
void prefetch(const Key posKey) const;
|
|
||||||
void new_search();
|
void new_search();
|
||||||
void insert_pv(const Position& pos, Move pv[]);
|
void insert_pv(const Position& pos, Move pv[]);
|
||||||
void extract_pv(const Position& pos, Move pv[]);
|
void extract_pv(const Position& pos, Move pv[], const int PLY_MAX);
|
||||||
int full() const;
|
int full() const;
|
||||||
|
TTEntry* first_entry(const Key posKey) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline TTEntry* first_entry(const Key posKey) const;
|
|
||||||
|
|
||||||
// Be sure 'writes' is at least one cache line away
|
// Be sure 'writes' is at least one cache line away
|
||||||
// from read only variables.
|
// from read only variables.
|
||||||
unsigned char pad_before[64 - sizeof(unsigned)];
|
unsigned char pad_before[64 - sizeof(unsigned)];
|
||||||
unsigned writes; // heavy SMP read/write access here
|
unsigned writes; // heavy SMP read/write access here
|
||||||
unsigned char pad_after[64];
|
unsigned char pad_after[64];
|
||||||
|
|
||||||
unsigned size;
|
size_t size;
|
||||||
TTCluster* entries;
|
TTCluster* entries;
|
||||||
uint8_t generation;
|
uint8_t generation;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TranspositionTable TT;
|
extern TranspositionTable TT;
|
||||||
|
|
||||||
|
|
||||||
|
/// TranspositionTable::first_entry returns a pointer to the first
|
||||||
|
/// entry of a cluster given a position. The low 32 bits of the key
|
||||||
|
/// are used to get the index in the table.
|
||||||
|
|
||||||
|
inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
|
||||||
|
|
||||||
|
return entries[uint32_t(posKey) & (size - 1)].data;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(TT_H_INCLUDED)
|
#endif // !defined(TT_H_INCLUDED)
|
||||||
|
|||||||
+46
-10
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,7 +33,7 @@ typedef __int16 int16;
|
|||||||
typedef unsigned __int16 uint16_t;
|
typedef unsigned __int16 uint16_t;
|
||||||
typedef __int32 int32_t;
|
typedef __int32 int32_t;
|
||||||
typedef unsigned __int32 uint32_t;
|
typedef unsigned __int32 uint32_t;
|
||||||
typedef __int64 int64;
|
typedef __int64 int64_t;
|
||||||
typedef unsigned __int64 uint64_t;
|
typedef unsigned __int64 uint64_t;
|
||||||
|
|
||||||
typedef __int16 int16_t;
|
typedef __int16 int16_t;
|
||||||
@@ -49,20 +49,32 @@ typedef uint64_t Bitboard;
|
|||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Compiler specific defines
|
//// Configuration
|
||||||
////
|
////
|
||||||
|
|
||||||
// Quiet a warning on Intel compiler
|
//// For Linux and OSX configuration is done automatically using Makefile.
|
||||||
#if !defined(__SIZEOF_INT__ )
|
//// To get started type "make help".
|
||||||
#define __SIZEOF_INT__ 0
|
////
|
||||||
#endif
|
//// For windows part of the configuration is detected automatically, but
|
||||||
|
//// some switches need to be set manually:
|
||||||
|
////
|
||||||
|
//// -DNDEBUG | Disable debugging mode. Use always.
|
||||||
|
////
|
||||||
|
//// -DNO_PREFETCH | Disable use of prefetch asm-instruction. A must if you want the
|
||||||
|
//// | executable to run on some very old machines.
|
||||||
|
////
|
||||||
|
//// -DUSE_POPCNT | Add runtime support for use of popcnt asm-instruction.
|
||||||
|
//// | Works only in 64-bit mode. For compiling requires hardware
|
||||||
|
//// | with popcnt support. Around 4% speed-up.
|
||||||
|
|
||||||
// Check for 64 bits for different compilers: Intel, MSVC and gcc
|
// Automatic detection for 64-bit under Windows
|
||||||
#if defined(__x86_64) || defined(_M_X64) || defined(_WIN64) || (__SIZEOF_INT__ > 4)
|
#if defined(_WIN64)
|
||||||
#define IS_64BIT
|
#define IS_64BIT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IS_64BIT) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
|
// Automatic detection for use of bsfq asm-instruction under Windows.
|
||||||
|
// Works only in 64-bit mode. Does not work with MSVC.
|
||||||
|
#if defined(_WIN64) && defined(__INTEL_COMPILER)
|
||||||
#define USE_BSFQ
|
#define USE_BSFQ
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -73,4 +85,28 @@ typedef uint64_t Bitboard;
|
|||||||
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
|
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Define a __cpuid() function for gcc compilers, for Intel and MSVC
|
||||||
|
// is already available as an intrinsic.
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include <intrin.h>
|
||||||
|
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||||
|
inline void __cpuid(int CPUInfo[4], int InfoType)
|
||||||
|
{
|
||||||
|
int* eax = CPUInfo + 0;
|
||||||
|
int* ebx = CPUInfo + 1;
|
||||||
|
int* ecx = CPUInfo + 2;
|
||||||
|
int* edx = CPUInfo + 3;
|
||||||
|
|
||||||
|
*eax = InfoType;
|
||||||
|
*ecx = 0;
|
||||||
|
__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
|
||||||
|
: "0" (*eax), "2" (*ecx));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
inline void __cpuid(int CPUInfo[4], int)
|
||||||
|
{
|
||||||
|
CPUInfo[0] = CPUInfo[1] = CPUInfo[2] = CPUInfo[3] = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // !defined(TYPES_H_INCLUDED)
|
#endif // !defined(TYPES_H_INCLUDED)
|
||||||
|
|||||||
+53
-49
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -54,13 +54,14 @@ namespace {
|
|||||||
// The root position. This is set up when the user (or in practice, the GUI)
|
// The root position. This is set up when the user (or in practice, the GUI)
|
||||||
// sends the "position" UCI command. The root position is sent to the think()
|
// sends the "position" UCI command. The root position is sent to the think()
|
||||||
// function when the program receives the "go" command.
|
// function when the program receives the "go" command.
|
||||||
Position RootPosition;
|
Position RootPosition(0);
|
||||||
|
|
||||||
// Local functions
|
// Local functions
|
||||||
bool handle_command(const string& command);
|
bool handle_command(const string& command);
|
||||||
void set_option(UCIInputParser& uip);
|
void set_option(UCIInputParser& uip);
|
||||||
void set_position(UCIInputParser& uip);
|
void set_position(UCIInputParser& uip);
|
||||||
bool go(UCIInputParser& uip);
|
bool go(UCIInputParser& uip);
|
||||||
|
void perft(UCIInputParser& uip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,7 +107,8 @@ namespace {
|
|||||||
UCIInputParser uip(command);
|
UCIInputParser uip(command);
|
||||||
string token;
|
string token;
|
||||||
|
|
||||||
uip >> token; // operator>>() skips any whitespace
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
|
return true;
|
||||||
|
|
||||||
if (token == "quit")
|
if (token == "quit")
|
||||||
return false;
|
return false;
|
||||||
@@ -123,7 +125,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
else if (token == "ucinewgame")
|
else if (token == "ucinewgame")
|
||||||
{
|
{
|
||||||
push_button("Clear Hash");
|
push_button("New Game");
|
||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
}
|
}
|
||||||
@@ -141,29 +143,25 @@ namespace {
|
|||||||
RootPosition.print();
|
RootPosition.print();
|
||||||
else if (token == "flip")
|
else if (token == "flip")
|
||||||
{
|
{
|
||||||
Position p(RootPosition);
|
Position p(RootPosition, RootPosition.thread());
|
||||||
RootPosition.flipped_copy(p);
|
RootPosition.flipped_copy(p);
|
||||||
}
|
}
|
||||||
else if (token == "eval")
|
else if (token == "eval")
|
||||||
{
|
{
|
||||||
EvalInfo ei;
|
EvalInfo ei;
|
||||||
cout << "Incremental mg: " << RootPosition.mg_value()
|
cout << "Incremental mg: " << mg_value(RootPosition.value())
|
||||||
<< "\nIncremental eg: " << RootPosition.eg_value()
|
<< "\nIncremental eg: " << eg_value(RootPosition.value())
|
||||||
<< "\nFull eval: " << evaluate(RootPosition, ei, 0) << endl;
|
<< "\nFull eval: " << evaluate(RootPosition, ei) << endl;
|
||||||
}
|
}
|
||||||
else if (token == "key")
|
else if (token == "key")
|
||||||
cout << "key: " << hex << RootPosition.get_key()
|
cout << "key: " << hex << RootPosition.get_key()
|
||||||
<< "\nmaterial key: " << RootPosition.get_material_key()
|
<< "\nmaterial key: " << RootPosition.get_material_key()
|
||||||
<< "\npawn key: " << RootPosition.get_pawn_key() << endl;
|
<< "\npawn key: " << RootPosition.get_pawn_key() << endl;
|
||||||
|
else if (token == "perft")
|
||||||
|
perft(uip);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
cout << "Unknown command: " << command << endl;
|
cout << "Unknown command: " << command << endl;
|
||||||
while (!uip.eof())
|
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
cout << token << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,33 +176,33 @@ namespace {
|
|||||||
|
|
||||||
string token;
|
string token;
|
||||||
|
|
||||||
uip >> token; // operator>>() skips any whitespace
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
|
return;
|
||||||
|
|
||||||
if (token == "startpos")
|
if (token == "startpos")
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
else if (token == "fen")
|
else if (token == "fen")
|
||||||
{
|
{
|
||||||
string fen;
|
string fen;
|
||||||
while (token != "moves" && !uip.eof())
|
while (uip >> token && token != "moves")
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
fen += token;
|
fen += token;
|
||||||
fen += ' ';
|
fen += ' ';
|
||||||
}
|
}
|
||||||
RootPosition.from_fen(fen);
|
RootPosition.from_fen(fen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uip.eof())
|
if (uip.good())
|
||||||
{
|
{
|
||||||
if (token != "moves")
|
if (token != "moves")
|
||||||
uip >> token;
|
uip >> token;
|
||||||
|
|
||||||
if (token == "moves")
|
if (token == "moves")
|
||||||
{
|
{
|
||||||
Move move;
|
Move move;
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
move = move_from_string(RootPosition, token);
|
move = move_from_string(RootPosition, token);
|
||||||
RootPosition.do_move(move, st);
|
RootPosition.do_move(move, st);
|
||||||
if (RootPosition.rule_50_counter() == 0)
|
if (RootPosition.rule_50_counter() == 0)
|
||||||
@@ -212,7 +210,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
// Our StateInfo st is about going out of scope so copy
|
// Our StateInfo st is about going out of scope so copy
|
||||||
// its content inside RootPosition before they disappear.
|
// its content inside RootPosition before they disappear.
|
||||||
RootPosition.saveState();
|
RootPosition.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,27 +224,22 @@ namespace {
|
|||||||
|
|
||||||
void set_option(UCIInputParser& uip) {
|
void set_option(UCIInputParser& uip) {
|
||||||
|
|
||||||
string token, name;
|
string token, name, value;
|
||||||
|
|
||||||
uip >> token;
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
if (token == "name")
|
return;
|
||||||
{
|
|
||||||
uip >> name;
|
|
||||||
while (!uip.eof())
|
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
if (token == "value")
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
if (token == "name" && uip >> name)
|
||||||
|
{
|
||||||
|
while (uip >> token && token != "value")
|
||||||
name += (" " + token);
|
name += (" " + token);
|
||||||
}
|
|
||||||
if (token == "value")
|
|
||||||
{
|
|
||||||
// Reads until end of line and left trim white space
|
|
||||||
getline(uip, token);
|
|
||||||
token.erase(0, token.find_first_not_of(" \n\r\t"));
|
|
||||||
|
|
||||||
set_option_value(name, token);
|
if (token == "value" && uip >> value)
|
||||||
|
{
|
||||||
|
while (uip >> token)
|
||||||
|
value += (" " + token);
|
||||||
|
|
||||||
|
set_option_value(name, value);
|
||||||
} else
|
} else
|
||||||
push_button(name);
|
push_button(name);
|
||||||
}
|
}
|
||||||
@@ -273,10 +266,8 @@ namespace {
|
|||||||
|
|
||||||
searchMoves[0] = MOVE_NONE;
|
searchMoves[0] = MOVE_NONE;
|
||||||
|
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
|
|
||||||
if (token == "infinite")
|
if (token == "infinite")
|
||||||
infinite = true;
|
infinite = true;
|
||||||
else if (token == "ponder")
|
else if (token == "ponder")
|
||||||
@@ -300,22 +291,35 @@ namespace {
|
|||||||
else if (token == "searchmoves")
|
else if (token == "searchmoves")
|
||||||
{
|
{
|
||||||
int numOfMoves = 0;
|
int numOfMoves = 0;
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
||||||
}
|
|
||||||
searchMoves[numOfMoves] = MOVE_NONE;
|
searchMoves[numOfMoves] = MOVE_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moveTime)
|
|
||||||
infinite = true; // HACK
|
|
||||||
|
|
||||||
assert(RootPosition.is_ok());
|
assert(RootPosition.is_ok());
|
||||||
|
|
||||||
return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
|
return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
|
||||||
time, inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
time, inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void perft(UCIInputParser& uip) {
|
||||||
|
|
||||||
|
string token;
|
||||||
|
int depth, tm, n;
|
||||||
|
Position pos(RootPosition, RootPosition.thread());
|
||||||
|
|
||||||
|
if (!(uip >> depth))
|
||||||
|
return;
|
||||||
|
|
||||||
|
tm = get_system_time();
|
||||||
|
|
||||||
|
n = perft(pos, depth * OnePly);
|
||||||
|
|
||||||
|
tm = get_system_time() - tm;
|
||||||
|
std::cout << "\nNodes " << n
|
||||||
|
<< "\nTime (ms) " << tm
|
||||||
|
<< "\nNodes/second " << (int)(n/(tm/1000.0)) << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+51
-36
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -79,6 +79,7 @@ namespace {
|
|||||||
o["Use Search Log"] = Option(false);
|
o["Use Search Log"] = Option(false);
|
||||||
o["Search Log Filename"] = Option("SearchLog.txt");
|
o["Search Log Filename"] = Option("SearchLog.txt");
|
||||||
o["Book File"] = Option("book.bin");
|
o["Book File"] = Option("book.bin");
|
||||||
|
o["Best Book Move"] = Option(false);
|
||||||
o["Mobility (Middle Game)"] = Option(100, 0, 200);
|
o["Mobility (Middle Game)"] = Option(100, 0, 200);
|
||||||
o["Mobility (Endgame)"] = Option(100, 0, 200);
|
o["Mobility (Endgame)"] = Option(100, 0, 200);
|
||||||
o["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
|
o["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
|
||||||
@@ -88,47 +89,28 @@ namespace {
|
|||||||
o["Space"] = Option(100, 0, 200);
|
o["Space"] = Option(100, 0, 200);
|
||||||
o["Aggressiveness"] = Option(100, 0, 200);
|
o["Aggressiveness"] = Option(100, 0, 200);
|
||||||
o["Cowardice"] = Option(100, 0, 200);
|
o["Cowardice"] = Option(100, 0, 200);
|
||||||
o["King Safety Curve"] = Option("Quadratic", COMBO);
|
|
||||||
|
|
||||||
o["King Safety Curve"].comboValues.push_back("Quadratic");
|
|
||||||
o["King Safety Curve"].comboValues.push_back("Linear"); /*, "From File"*/
|
|
||||||
|
|
||||||
o["King Safety Coefficient"] = Option(40, 1, 100);
|
|
||||||
o["King Safety X Intercept"] = Option(0, 0, 20);
|
|
||||||
o["King Safety Max Slope"] = Option(30, 10, 100);
|
|
||||||
o["King Safety Max Value"] = Option(500, 100, 1000);
|
|
||||||
o["Queen Contact Check Bonus"] = Option(3, 0, 8);
|
|
||||||
o["Queen Check Bonus"] = Option(2, 0, 4);
|
|
||||||
o["Rook Check Bonus"] = Option(1, 0, 4);
|
|
||||||
o["Bishop Check Bonus"] = Option(1, 0, 4);
|
|
||||||
o["Knight Check Bonus"] = Option(1, 0, 4);
|
|
||||||
o["Discovered Check Bonus"] = Option(3, 0, 8);
|
|
||||||
o["Mate Threat Bonus"] = Option(3, 0, 8);
|
|
||||||
o["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
o["Single Reply Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Single Evasion Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Single Reply Extension (non-PV nodes)"] = Option(2, 0, 2);
|
o["Single Evasion Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Mate Threat Extension (PV nodes)"] = Option(0, 0, 2);
|
o["Mate Threat Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Mate Threat Extension (non-PV nodes)"] = Option(0, 0, 2);
|
o["Mate Threat Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
o["Pawn Push to 7th Extension (non-PV nodes)"] = Option(1, 0, 2);
|
o["Pawn Push to 7th Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
o["Passed Pawn Extension (PV nodes)"] = Option(1, 0, 2);
|
o["Passed Pawn Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||||
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Full Depth Moves (PV nodes)"] = Option(10, 1, 100);
|
|
||||||
o["Full Depth Moves (non-PV nodes)"] = Option(3, 1, 100);
|
|
||||||
o["Threat Depth"] = Option(5, 0, 100);
|
|
||||||
o["Randomness"] = Option(0, 0, 10);
|
o["Randomness"] = Option(0, 0, 10);
|
||||||
o["Minimum Split Depth"] = Option(4, 4, 7);
|
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||||
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
||||||
o["Threads"] = Option(1, 1, 8);
|
o["Threads"] = Option(1, 1, MAX_THREADS);
|
||||||
o["Hash"] = Option(32, 4, 4096);
|
o["Hash"] = Option(32, 4, 8192);
|
||||||
o["Clear Hash"] = Option(false, BUTTON);
|
o["Clear Hash"] = Option(false, BUTTON);
|
||||||
|
o["New Game"] = Option(false, BUTTON);
|
||||||
o["Ponder"] = Option(true);
|
o["Ponder"] = Option(true);
|
||||||
o["OwnBook"] = Option(true);
|
o["OwnBook"] = Option(true);
|
||||||
o["MultiPV"] = Option(1, 1, 500);
|
o["MultiPV"] = Option(1, 1, 500);
|
||||||
o["UCI_ShowCurrLine"] = Option(false);
|
|
||||||
o["UCI_Chess960"] = Option(false);
|
o["UCI_Chess960"] = Option(false);
|
||||||
o["UCI_AnalyseMode"] = Option(false);
|
o["UCI_AnalyseMode"] = Option(false);
|
||||||
|
|
||||||
@@ -169,6 +151,18 @@ namespace {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Specialization for std::string where instruction 'ss >> ret;'
|
||||||
|
// would erroneusly tokenize a string with spaces.
|
||||||
|
|
||||||
|
template<>
|
||||||
|
string get_option_value<string>(const string& optionName) {
|
||||||
|
|
||||||
|
if (options.find(optionName) == options.end())
|
||||||
|
return string();
|
||||||
|
|
||||||
|
return options[optionName].currentValue;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -183,15 +177,18 @@ void init_uci_options() {
|
|||||||
|
|
||||||
load_defaults(options);
|
load_defaults(options);
|
||||||
|
|
||||||
// Limit the default value of "Threads" to 7 even if we have 8 CPU cores.
|
// Set optimal value for parameter "Minimum Split Depth"
|
||||||
// According to Ken Dail's tests, Glaurung plays much better with 7 than
|
// according to number of available cores.
|
||||||
// with 8 threads. This is weird, but it is probably difficult to find out
|
|
||||||
// why before I have a 8-core computer to experiment with myself.
|
|
||||||
assert(options.find("Threads") != options.end());
|
assert(options.find("Threads") != options.end());
|
||||||
assert(options.find("Minimum Split Depth") != options.end());
|
assert(options.find("Minimum Split Depth") != options.end());
|
||||||
|
|
||||||
options["Threads"].defaultValue = stringify(Min(cpu_count(), 7));
|
Option& thr = options["Threads"];
|
||||||
options["Threads"].currentValue = stringify(Min(cpu_count(), 7));
|
Option& msd = options["Minimum Split Depth"];
|
||||||
|
|
||||||
|
thr.defaultValue = thr.currentValue = stringify(cpu_count());
|
||||||
|
|
||||||
|
if (cpu_count() >= 8)
|
||||||
|
msd.defaultValue = msd.currentValue = stringify(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -279,10 +276,28 @@ void set_option_value(const string& name, const string& value) {
|
|||||||
else if (v == "false")
|
else if (v == "false")
|
||||||
v = "0";
|
v = "0";
|
||||||
|
|
||||||
if (options.find(name) != options.end())
|
if (options.find(name) == options.end())
|
||||||
options[name].currentValue = v;
|
{
|
||||||
else
|
|
||||||
std::cout << "No such option: " << name << std::endl;
|
std::cout << "No such option: " << name << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normally it's up to the GUI to check for option's limits,
|
||||||
|
// but we could receive the new value directly from the user
|
||||||
|
// by teminal window. So let's check the bounds anyway.
|
||||||
|
Option& opt = options[name];
|
||||||
|
|
||||||
|
if (opt.type == CHECK && v != "0" && v != "1")
|
||||||
|
return;
|
||||||
|
|
||||||
|
else if (opt.type == SPIN)
|
||||||
|
{
|
||||||
|
int val = atoi(v.c_str());
|
||||||
|
if (val < opt.minValue || val > opt.maxValue)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.currentValue = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+43
-8
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -36,10 +36,7 @@ enum ValueType {
|
|||||||
VALUE_TYPE_NONE = 0,
|
VALUE_TYPE_NONE = 0,
|
||||||
VALUE_TYPE_UPPER = 1, // Upper bound
|
VALUE_TYPE_UPPER = 1, // Upper bound
|
||||||
VALUE_TYPE_LOWER = 2, // Lower bound
|
VALUE_TYPE_LOWER = 2, // Lower bound
|
||||||
VALUE_TYPE_EXACT = 3, // Exact score
|
VALUE_TYPE_EXACT = VALUE_TYPE_UPPER | VALUE_TYPE_LOWER
|
||||||
VALUE_TYPE_EVAL = 4, // Evaluation cache
|
|
||||||
VALUE_TYPE_EV_UP = 5, // Evaluation cache for upper bound
|
|
||||||
VALUE_TYPE_EV_LO = 6 // Evaluation cache for lower bound
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -48,10 +45,49 @@ enum Value {
|
|||||||
VALUE_KNOWN_WIN = 15000,
|
VALUE_KNOWN_WIN = 15000,
|
||||||
VALUE_MATE = 30000,
|
VALUE_MATE = 30000,
|
||||||
VALUE_INFINITE = 30001,
|
VALUE_INFINITE = 30001,
|
||||||
VALUE_NONE = 30002
|
VALUE_NONE = 30002,
|
||||||
|
VALUE_ENSURE_SIGNED = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// Score enum keeps a midgame and an endgame value in a single
|
||||||
|
/// integer (enum), first LSB 16 bits are used to store endgame
|
||||||
|
/// value, while upper bits are used for midgame value.
|
||||||
|
|
||||||
|
// Compiler is free to choose the enum type as long as can keep
|
||||||
|
// its data, so ensure Score to be an integer type.
|
||||||
|
enum Score { ENSURE_32_BITS_SIZE_P = (1 << 16), ENSURE_32_BITS_SIZE_N = -(1 << 16)};
|
||||||
|
|
||||||
|
// Extracting the _signed_ lower and upper 16 bits it not so trivial
|
||||||
|
// because according to the standard a simple cast to short is
|
||||||
|
// implementation defined and so is a right shift of a signed integer.
|
||||||
|
inline Value mg_value(Score s) { return Value(((int(s) + 32768) & ~0xffff) / 0x10000); }
|
||||||
|
|
||||||
|
// Unfortunatly on Intel 64 bit we have a small speed regression, so use a faster code in
|
||||||
|
// this case, although not 100% standard compliant it seems to work for Intel and MSVC.
|
||||||
|
#if defined(IS_64BIT) && (!defined(__GNUC__) || defined(__INTEL_COMPILER))
|
||||||
|
inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); }
|
||||||
|
#else
|
||||||
|
inline Value eg_value(Score s) { return Value((int)(unsigned(s) & 0x7fffu) - (int)(unsigned(s) & 0x8000u)); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
|
||||||
|
|
||||||
|
inline Score operator-(Score s) { return Score(-int(s)); }
|
||||||
|
inline Score operator+(Score s1, Score s2) { return Score(int(s1) + int(s2)); }
|
||||||
|
inline Score operator-(Score s1, Score s2) { return Score(int(s1) - int(s2)); }
|
||||||
|
inline void operator+=(Score& s1, Score s2) { s1 = Score(int(s1) + int(s2)); }
|
||||||
|
inline void operator-=(Score& s1, Score s2) { s1 = Score(int(s1) - int(s2)); }
|
||||||
|
inline Score operator*(int i, Score s) { return Score(i * int(s)); }
|
||||||
|
|
||||||
|
// Division must be handled separately for each term
|
||||||
|
inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); }
|
||||||
|
|
||||||
|
// Only declared but not defined. We don't want to multiply two scores due to
|
||||||
|
// a very high risk of overflow. So user should explicitly convert to integer.
|
||||||
|
inline Score operator*(Score s1, Score s2);
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Constants and variables
|
//// Constants and variables
|
||||||
////
|
////
|
||||||
@@ -97,8 +133,7 @@ const Value PieceValueEndgame[17] = {
|
|||||||
|
|
||||||
/// Bonus for having the side to move (modified by Joona Kiiski)
|
/// Bonus for having the side to move (modified by Joona Kiiski)
|
||||||
|
|
||||||
const Value TempoValueMidgame = Value(48);
|
const Score TempoValue = make_score(48, 22);
|
||||||
const Value TempoValueEndgame = Value(22);
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|||||||
Reference in New Issue
Block a user