mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 08:37:44 +00:00
Compare commits
503 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ee0842c81 | |||
| e59ff49a55 | |||
| 225dcfeeb7 | |||
| 8dd01fda12 | |||
| 18cd83a380 | |||
| fd2b3df770 | |||
| da948cc94e | |||
| e49b21eacb | |||
| 60bc30275d | |||
| 32dfaa56b0 | |||
| 3701a8e57d | |||
| aaa07fb161 | |||
| 1361ba75cb | |||
| da9c423989 | |||
| 3713bb26ef | |||
| cff9ff2198 | |||
| a6c6037813 | |||
| e677185567 | |||
| 237dd331d5 | |||
| 98c8a83bb8 | |||
| 73be819426 | |||
| 2940abdac8 | |||
| fa0bffeafa | |||
| d56345c9ae | |||
| 60e23693f0 | |||
| 91f0c08789 | |||
| 6bf22f354f | |||
| 48b74142ef | |||
| dcb323bf0d | |||
| 44cb792c76 | |||
| e68e135771 | |||
| 46141b078c | |||
| 02fd34a5e8 | |||
| 20cac227bb | |||
| 4346445be3 | |||
| 21850536d5 | |||
| 0179a32cf5 | |||
| 8487069058 | |||
| 43ca5c926d | |||
| aed542d74c | |||
| aaffcf973e | |||
| 746bcb348f | |||
| a7cb05b1eb | |||
| 9741694fca | |||
| e145c0d3e2 | |||
| 24cc3a97a4 | |||
| e4277c06bf | |||
| dd80b9abaf | |||
| 84d6fe0f31 | |||
| 6845397c5c | |||
| f74f42b298 | |||
| 0e0adfe2e1 | |||
| 049139d025 | |||
| 62a8f393f1 | |||
| c5f44ef45b | |||
| 7c55b0e880 | |||
| 77ac1e7953 | |||
| cddda7cd19 | |||
| c81010a878 | |||
| 6709b01903 | |||
| 3863cd191c | |||
| f205fe1fe5 | |||
| 9f28d8a854 | |||
| 76bed11f7b | |||
| e33c94883f | |||
| 46ffea46ea | |||
| 03d6a86900 | |||
| 17c5119222 | |||
| cf71efc34b | |||
| c9d364f9ca | |||
| 97dd7568ed | |||
| af220cfd52 | |||
| 1130c8d815 | |||
| 607ac0687a | |||
| e9de96f0e4 | |||
| 9ab84a8165 | |||
| ac65b14d30 | |||
| 9e4befe3f1 | |||
| 6cf28d4aa7 | |||
| 129cde008c | |||
| b088f0aefd | |||
| a5d699d62f | |||
| f6d2452916 | |||
| 268c53ac51 | |||
| 595a90dfd0 | |||
| e217407450 | |||
| 2078878376 | |||
| d1d4437699 | |||
| ba04eb0446 | |||
| ed347e7cbd | |||
| 95af1e28be | |||
| e9aa20ad13 | |||
| e01fefbbaf | |||
| e4fc957898 | |||
| 693b38a5e7 | |||
| fbec55e52e | |||
| 05e70d6740 | |||
| b4cb1a3a9e | |||
| ec14fb1b33 | |||
| cb506d3b16 | |||
| e0c47a6ceb | |||
| f3d0b76feb | |||
| bfd4421f49 | |||
| fd12e8cb23 | |||
| 166c09a7a0 | |||
| 8d369600ec | |||
| f4140ecc0c | |||
| 60b5da4cc8 | |||
| 55c46b2399 | |||
| 76ae0e36be | |||
| 4251eac860 | |||
| cd4604b05c | |||
| e6863f46de | |||
| 6f1475b6fc | |||
| 4a777954e1 | |||
| 54382f8b07 | |||
| 339bb8a524 | |||
| aa925a0e29 | |||
| 23ceb66950 | |||
| 565d12bf42 | |||
| 00eab73399 | |||
| 5be3d98d17 | |||
| 5b3fcab1ad | |||
| 977ca40d6d | |||
| ae49677446 | |||
| 2fff532f4e | |||
| da854fe83a | |||
| a1096e55cf | |||
| dad632ce5b | |||
| 2f7723fd44 | |||
| 152f3b13b7 | |||
| bb1b049b83 | |||
| 50f92bed06 | |||
| bdb586ac2b | |||
| 1b0303b6e9 | |||
| 5f232e0667 | |||
| 080a4995a3 | |||
| 20224a5bbf | |||
| 8654fee18c | |||
| 8b45b60327 | |||
| 044ad593b3 | |||
| 5600d91cff | |||
| 1cc44bcaae | |||
| 15eb59683e | |||
| 620cfbb676 | |||
| fe523b2d18 | |||
| 2a203d8d6f | |||
| b8326edea3 | |||
| 20e8738901 | |||
| b3b1d3aaa7 | |||
| 0d69ac33ff | |||
| 342c8c883c | |||
| 297c12e595 | |||
| 5c20f59788 | |||
| ea06200423 | |||
| 3849beb979 | |||
| 20ed03fc0b | |||
| 2a461b4b74 | |||
| 6f39a3fc80 | |||
| 7eefc1f6cc | |||
| 7622793080 | |||
| 174b40c28d | |||
| 03f524c591 | |||
| 3444b94735 | |||
| 2693db616d | |||
| a5fce1958b | |||
| 67ac358ef2 | |||
| 341f42be8c | |||
| 72ab2cd3e9 | |||
| 92b625d04f | |||
| 2b32571de8 | |||
| 36437f14e8 | |||
| 08f3aac97c | |||
| 48b0d41220 | |||
| 5d79af9e0d | |||
| a87ea9846d | |||
| 063e2441b1 | |||
| b45936a8c7 | |||
| d39ddb9077 | |||
| bbb2462576 | |||
| d9e3be4790 | |||
| 36c0ab3a50 | |||
| ad4eac376f | |||
| 657286b0e5 | |||
| 3a4d6e2034 | |||
| b1e79fed99 | |||
| 190f88e532 | |||
| 8acb1d7e4d | |||
| 46c0bdb74f | |||
| 8225fdd5bb | |||
| e3c02d231a | |||
| 9847adf19f | |||
| 630fda2e2c | |||
| 8bec65029d | |||
| b5685fc564 | |||
| d2c2af9e1c | |||
| 3e0753bef3 | |||
| c7843f2f79 | |||
| 9005ea6339 | |||
| 6d117e4a23 | |||
| b8ab5d533b | |||
| bbd3e30b4e | |||
| e41602b721 | |||
| 48c95706c8 | |||
| 2f760cdf8d | |||
| b58ecb85c7 | |||
| b4a04d8038 | |||
| c1b60269a2 | |||
| e1ed67aacb | |||
| 5b1316f7bb | |||
| bafb9f1a25 | |||
| 738bf66a2d | |||
| 3d0b60b065 | |||
| bdb1bfecfb | |||
| f1591447cf | |||
| d63ff85a43 | |||
| 76024ac40e | |||
| 6c9a64124a | |||
| f90f810ac4 | |||
| ce5d9eb19d | |||
| 628f844c11 | |||
| c729e4e1ab | |||
| 0228ff9ca0 | |||
| e7d3a006cd | |||
| 3376c68f4b | |||
| 1b0888708d | |||
| 229274546f | |||
| 3e40bd0648 | |||
| 595c7d75a2 | |||
| 5603e25a7f | |||
| 20c2a31464 | |||
| d3c4618b3a | |||
| b98bcf858b | |||
| 3b1e64ab72 | |||
| 72ecd9e20d | |||
| 25286e9932 | |||
| 4f7ec4128f | |||
| 1e4472b651 | |||
| da579e46b7 | |||
| f83b899f39 | |||
| a75aa6035b | |||
| 436fa5c8fa | |||
| 8df816f869 | |||
| 9c428afb6d | |||
| 27619830d4 | |||
| 78eecbf6d7 | |||
| 980124c609 | |||
| 5f7d37273c | |||
| be4ee0729d | |||
| 9fbe9af0a0 | |||
| 1d15b38cd8 | |||
| 5c81602d14 | |||
| a88e762b4e | |||
| 2155fb7825 | |||
| a03b8074c8 | |||
| afadc33fb4 | |||
| 92ca97d121 | |||
| da91fab8cb | |||
| 6176357ac1 | |||
| 46bb6c6dc3 | |||
| 5c703b7526 | |||
| 412d68fe4f | |||
| 9144e48eb6 | |||
| aabd526f7c | |||
| fdb2242d34 | |||
| 991ab2bea8 | |||
| f032ba54c5 | |||
| 5a7876d0d0 | |||
| e87931bbfc | |||
| aa5c375ca9 | |||
| cd1cc39b04 | |||
| 4e151f7e0d | |||
| d13e4c16c2 | |||
| 1906df4494 | |||
| 39f2eda285 | |||
| 00a3380885 | |||
| f1d982e2c0 | |||
| fbca16da57 | |||
| 1e97cdd9f3 | |||
| ab69f50c64 | |||
| b35e593551 | |||
| 20d88dbf98 | |||
| ef60043725 | |||
| 2f2e48fad2 | |||
| 2550c6383b | |||
| fb560fa5d7 | |||
| 11491e71ee | |||
| bd26374f21 | |||
| d20e0cf048 | |||
| 342ceb1c91 | |||
| f010b6db71 | |||
| 7c267587fc | |||
| 24485c96ec | |||
| f98385e129 | |||
| 2acc89c6e8 | |||
| a52ab2afbf | |||
| de050db2b0 | |||
| e68ebe618c | |||
| 4634be8ba6 | |||
| e7f03913ea | |||
| e30720b0bf | |||
| 7af1b40b4e | |||
| ecec7dbf89 | |||
| 8da2153ee8 | |||
| 22f9f0cabe | |||
| 3e7e1a7c53 | |||
| 0ea716463b | |||
| 6c4e36aab6 | |||
| 6f28bcd483 | |||
| acef5d6a59 | |||
| 44b497a972 | |||
| b893583bb6 | |||
| e81d0d08c3 | |||
| 72c7595f8a | |||
| e38ad4d42b | |||
| fad772f387 | |||
| ebb0f31928 | |||
| f0701e2b0f | |||
| 95aadb5e53 | |||
| 17ef886fc3 | |||
| 8590a6f3b7 | |||
| 7b05b83bf2 | |||
| d7ef09727a | |||
| 683595fee1 | |||
| 659c54582d | |||
| 2c0cd95ecf | |||
| 6a8e46d53e | |||
| c6c4713ab2 | |||
| 9e44a6dba9 | |||
| 941f4e1643 | |||
| dcdac83187 | |||
| 5a0581498c | |||
| 1c087dd806 | |||
| 095a96b461 | |||
| 72af519e7f | |||
| db46602b1f | |||
| d3f99aea6b | |||
| 0e835bd334 | |||
| 43276cbec5 | |||
| a9e55d4326 | |||
| 4d70e3aeac | |||
| 24b7ad54c7 | |||
| 0ff3bf34cd | |||
| 66d165921d | |||
| b82c3021fa | |||
| 320630ca1a | |||
| ef8acdc73b | |||
| cc8e915ed5 | |||
| 16abc165d8 | |||
| 74160ac602 | |||
| feb5342b39 | |||
| 6cddf9183c | |||
| b870f5a091 | |||
| fcecc5212e | |||
| 8de91be61e | |||
| ca4e78db8d | |||
| bfcfaf7101 | |||
| c8773c720a | |||
| 3ed603cd64 | |||
| f637ddc1e8 | |||
| 964bd86272 | |||
| 72b88e09e1 | |||
| 3e663d8c50 | |||
| 8c9c51c721 | |||
| 7fe1632a49 | |||
| 7c84b39a42 | |||
| 68e711aac6 | |||
| 02cd96e4c2 | |||
| 772a37cd54 | |||
| c02613860a | |||
| 9b6b9e67fe | |||
| 6a8cfe79da | |||
| 1f97b48a31 | |||
| a96cba0ec8 | |||
| f9f30412e7 | |||
| 55f9afee2a | |||
| 962216440c | |||
| 243fa483d7 | |||
| da7a62852a | |||
| 0bf45823da | |||
| 4324276419 | |||
| 43bc5479c2 | |||
| 8f59de48f5 | |||
| 2f6c5f00e6 | |||
| 2f21ec39ad | |||
| 9b257ba29d | |||
| 1b0fee9b17 | |||
| b7cb6180cf | |||
| f30aa83f8a | |||
| 1dc27f3232 | |||
| 95cfc0e306 | |||
| 9e1d142fdd | |||
| 683e6dc656 | |||
| c6630abe0d | |||
| 734941672e | |||
| 0a0ea36e25 | |||
| 5f142ec209 | |||
| 7f4f18f959 | |||
| c45818e9f8 | |||
| 7013efce4e | |||
| 9f5b709db7 | |||
| 2c955f25de | |||
| f32992f88c | |||
| e71d520758 | |||
| 52ed0e9563 | |||
| 30e8f0c9ad | |||
| 67375f4693 | |||
| 039badfda8 | |||
| 088ecc242f | |||
| a188a047ab | |||
| 1d2247aea3 | |||
| 8365f8ac1e | |||
| 68d36b6f59 | |||
| 33c608e140 | |||
| ff60dafe8d | |||
| 214f9dcc27 | |||
| 1dc1cecf01 | |||
| 67535711e8 | |||
| 56f607fe0f | |||
| 9d044cf4ee | |||
| 769f2fdecb | |||
| 9bffe811c4 | |||
| 3e20c6c07d | |||
| 4f5f97107e | |||
| 151d47dc85 | |||
| 33ddeec5e0 | |||
| 4573d618e4 | |||
| 1156eb865b | |||
| 76381cbd69 | |||
| fa322b3768 | |||
| 2ea7449f2a | |||
| ee6e8851be | |||
| 03211296f1 | |||
| cc76951483 | |||
| f0858cd229 | |||
| 225d89c51b | |||
| 8bef9e59a0 | |||
| 82bf08e4f2 | |||
| c32904f0a0 | |||
| 6cfb661ca5 | |||
| be43219136 | |||
| d5b77ad45e | |||
| c6d62b7da5 | |||
| 3e6e57231e | |||
| 14c1fd4d27 | |||
| 4b53bb02f6 | |||
| ec2927286a | |||
| bdbbc4e06b | |||
| 539051b1e0 | |||
| c97104e854 | |||
| 5cacefe7c6 | |||
| 9b87d151bc | |||
| cbfbf25d1b | |||
| 90585a8a36 | |||
| e236a0c652 | |||
| d0804341c5 | |||
| dc4e2d8184 | |||
| e828753a3a | |||
| 33bb8305a9 | |||
| cc3c1dc25a | |||
| 11763d2b7f | |||
| d99a95df29 | |||
| 0da1d6a846 | |||
| 5d94305af3 | |||
| e4fd9a2df7 | |||
| aedc6c6f1f | |||
| dae4e7df07 | |||
| 96a32eec69 | |||
| e46d3670fd | |||
| 8cd5cb930d | |||
| 2feb9d5100 | |||
| d11426c777 | |||
| e96f56adfa | |||
| e3b03f13b3 | |||
| 54b7da120f | |||
| 3fafc9768a | |||
| 23490bd825 | |||
| 61c6a3d5a0 | |||
| 31d4f0b734 | |||
| f178f0a291 | |||
| 72ca727b38 | |||
| 2d0146fe1d | |||
| 96d0501735 | |||
| b58ad355ca | |||
| 17000d1ea0 | |||
| b09cbaebb9 | |||
| 725c504a5f | |||
| bfbfc24d07 | |||
| a55b06d3c9 | |||
| ecc19381b4 | |||
| dae2f600d6 | |||
| 4c294932e7 | |||
| c831b00544 | |||
| 5b853c9be6 | |||
| 5f8f83bc05 | |||
| 8ee3124487 | |||
| 07b45151d2 | |||
| 9e3ab9099f | |||
| f09884d72f | |||
| ab29d8df67 | |||
| 389dc0e83b | |||
| 67aac4889e | |||
| aaad48464b |
+12
-20
@@ -14,7 +14,9 @@ number of CPUs on your computer and set the number of search threads
|
|||||||
accordingly, but please be aware that the detection is not always
|
accordingly, but please be aware that the detection is not always
|
||||||
correct. It is therefore recommended to inspect the value of the
|
correct. It is therefore recommended to inspect the value of the
|
||||||
"Threads" UCI parameter, and to make sure it equals the number of CPU
|
"Threads" UCI parameter, and to make sure it equals the number of CPU
|
||||||
cores on your computer.
|
cores on your computer. If you are using more than four threads, it
|
||||||
|
is recommended to raise the value of "Minimum Split Depth" UCI parameter
|
||||||
|
to 6.
|
||||||
|
|
||||||
|
|
||||||
2. Files
|
2. Files
|
||||||
@@ -45,7 +47,6 @@ PolyGlot documentation. The book file can be selected by setting the
|
|||||||
UCI parameter "Book File".
|
UCI parameter "Book File".
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
4. Compiling it yourself
|
4. Compiling it yourself
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
@@ -54,27 +55,18 @@ Stockfish directly from the source code with the included Makefile.
|
|||||||
The exception is computer with big-endian CPUs, like PowerPC
|
The exception is computer with big-endian CPUs, like PowerPC
|
||||||
Macintoshes. Some of the bitboard routines in the current version of
|
Macintoshes. Some of the bitboard routines in the current version of
|
||||||
Stockfish are endianness-sensitive, and won't work on a big-endian CPU.
|
Stockfish are endianness-sensitive, and won't work on a big-endian CPU.
|
||||||
Ensuring that the line with #define USE_32BIT_ATTACKS" near the top
|
|
||||||
of bitboard.h is commented out should solve this problem.
|
|
||||||
Commenting out the line with "#define USE_32BIT_ATTACKS" near the
|
|
||||||
|
|
||||||
There is also a problem with compiling Stockfish on certain 64-bit
|
Stockfish has POPCNT instruction runtime detection and support. This can
|
||||||
systems, regardless of the endianness. If Stockfish segfaults
|
give an extra speed on Core i7 or similar systems. To enable this feature
|
||||||
immediately after startup, try to comment out the line with
|
(disabled by default) simply uncomment #define USE_POPCNT in bitcount.h
|
||||||
"#define USE_FOLDED_BITSCAN" near the beginning of bitboard.h and
|
before to compile.
|
||||||
recompile.
|
|
||||||
|
|
||||||
Finally, even if Stockfish does work without any changes on your
|
On 64 bit Unix-like systems the 'bsfq' assembly instruction will be used
|
||||||
computer, it might be possible to improve the performance by changing
|
for bit counting. Detection is automatic at compile time, but in case you
|
||||||
some of the #define directives in bitboard.h. The default settings
|
experience compile problems you can comment out #define USE_BSFQ line in types.h
|
||||||
are optimized for 64-bit CPUs. On 32-bit CPUs, it is probably better
|
|
||||||
to switch on USE_32BIT_ATTACKS, and to use BITCOUNT_SWAR_32 instead of
|
|
||||||
BITCOUNT_SWAR_64. For computers with very little memory (like
|
|
||||||
handheld devices), it is possible to conserve memory by defining
|
|
||||||
USE_COMPACT_ROOK_ATTACKS.
|
|
||||||
|
|
||||||
|
|
||||||
6. Terms of use
|
5. Terms of use
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Stockfish is free, and distributed under the GNU General Public License
|
Stockfish is free, and distributed under the GNU General Public License
|
||||||
@@ -93,7 +85,7 @@ For full details, read the copy of the GPL found in the file named
|
|||||||
Copying.txt.
|
Copying.txt.
|
||||||
|
|
||||||
|
|
||||||
7. Feedback
|
6. Feedback
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
The author's e-mail address is mcostalba@gmail.com
|
The author's e-mail address is mcostalba@gmail.com
|
||||||
|
|||||||
+3
-10
@@ -2,13 +2,13 @@
|
|||||||
[PolyGlot]
|
[PolyGlot]
|
||||||
|
|
||||||
EngineDir = .
|
EngineDir = .
|
||||||
EngineCommand = ./glaurung
|
EngineCommand = ./stockfish
|
||||||
|
|
||||||
Book = false
|
Book = false
|
||||||
BookFile = book.bin
|
BookFile = book.bin
|
||||||
|
|
||||||
Log = true
|
Log = true
|
||||||
LogFile = glaurung.log
|
LogFile = stockfish.log
|
||||||
|
|
||||||
Resign = true
|
Resign = true
|
||||||
ResignScore = 600
|
ResignScore = 600
|
||||||
@@ -34,8 +34,7 @@ King Safety Coefficient = 40
|
|||||||
King Safety X Intercept = 0
|
King Safety X Intercept = 0
|
||||||
King Safety Max Slope = 30
|
King Safety Max Slope = 30
|
||||||
King Safety Max Value = 500
|
King Safety Max Value = 500
|
||||||
Queen Contact Check Bonus = 4
|
Queen Contact Check Bonus = 3
|
||||||
Rook Contact Check Bonus = 2
|
|
||||||
Queen Check Bonus = 2
|
Queen Check Bonus = 2
|
||||||
Rook Check Bonus = 1
|
Rook Check Bonus = 1
|
||||||
Bishop Check Bonus = 1
|
Bishop Check Bonus = 1
|
||||||
@@ -57,14 +56,8 @@ Pawn Endgame Extension (non-PV nodes) = 2
|
|||||||
Full Depth Moves (PV nodes) = 14
|
Full Depth Moves (PV nodes) = 14
|
||||||
Full Depth Moves (non-PV nodes) = 3
|
Full Depth Moves (non-PV nodes) = 3
|
||||||
Threat Depth = 5
|
Threat Depth = 5
|
||||||
Selective Plies = 7
|
|
||||||
Futility Pruning (Main Search) = true
|
Futility Pruning (Main Search) = true
|
||||||
Futility Pruning (Quiescence Search) = true
|
Futility Pruning (Quiescence Search) = true
|
||||||
Futility Margin 0 = 50
|
|
||||||
Futility Margin 1 = 100
|
|
||||||
Futility Margin 2 = 300
|
|
||||||
Maximum Razoring Depth = 3
|
|
||||||
Razoring Margin = 300
|
|
||||||
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
|
||||||
|
|||||||
+221
-108
@@ -18,133 +18,246 @@
|
|||||||
# 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
|
||||||
### Files
|
|
||||||
###
|
|
||||||
|
|
||||||
EXE = stockfish
|
EXE = stockfish
|
||||||
|
|
||||||
OBJS = bitboard.o color.o pawns.o material.o endgame.o evaluate.o main.o \
|
|
||||||
|
### ==========================================================================
|
||||||
|
### 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
|
||||||
|
|
||||||
|
|
||||||
|
### 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 \
|
||||||
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 square.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
|
||||||
### Rules
|
default:
|
||||||
###
|
$(MAKE) gcc
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo ""
|
||||||
|
@echo "Makefile options:"
|
||||||
|
@echo ""
|
||||||
|
@echo "make > Default: Compiler = g++"
|
||||||
|
@echo "make icc > Compiler = icpc"
|
||||||
|
@echo "make icc-profile > Compiler = icpc + automatic pgo-build"
|
||||||
|
@echo "make osx-ppc32 > PPC-Mac OS X 32 bit. Compiler = g++"
|
||||||
|
@echo "make osx-ppc64 > PPC-Mac OS X 64 bit. Compiler = g++"
|
||||||
|
@echo "make osx-x86 > x86-Mac OS X 32 bit. Compiler = g++"
|
||||||
|
@echo "make osx-x86_64 > x86-Mac OS X 64 bit. Compiler = g++"
|
||||||
|
@echo "make osx-icc32 > x86-Mac OS X 32 bit. Compiler = icpc"
|
||||||
|
@echo "make osx-icc64 > x86-Mac OS X 64 bit. Compiler = icpc"
|
||||||
|
@echo "make osx-icc32-profile > OSX 32 bit. Compiler = icpc + automatic pgo-build"
|
||||||
|
@echo "make osx-icc64-profile > OSX 64 bit. Compiler = icpc + automatic pgo-build"
|
||||||
|
@echo "make strip > Strip executable"
|
||||||
|
@echo "make clean > Clean up"
|
||||||
|
@echo ""
|
||||||
|
|
||||||
all: $(EXE) .depend
|
all: $(EXE) .depend
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o .depend glaurung
|
$(RM) *.o .depend *~ $(EXE)
|
||||||
|
|
||||||
|
|
||||||
###
|
### Possible targets. You may add your own ones here
|
||||||
### Compiler:
|
gcc:
|
||||||
###
|
$(MAKE) \
|
||||||
|
CXX='g++' \
|
||||||
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
|
all
|
||||||
|
|
||||||
# CXX = g++
|
icc:
|
||||||
# CXX = g++-4.2
|
$(MAKE) \
|
||||||
CXX = icpc
|
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
|
||||||
|
$(MAKE) icc-profile-make
|
||||||
|
@echo ""
|
||||||
|
@echo "Running benchmark for pgo-build ..."
|
||||||
|
@$(PGOBENCH) > /dev/null
|
||||||
|
@echo "Benchmark finished. Build final executable now ..."
|
||||||
|
@echo ""
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(MAKE) icc-profile-use
|
||||||
|
@rm -rf profdir bench.txt
|
||||||
|
|
||||||
|
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 "Running benchmark for pgo-build ..."
|
||||||
|
@$(PGOBENCH) > /dev/null
|
||||||
|
@echo "Benchmark finished. Build final executable now ..."
|
||||||
|
@echo ""
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(MAKE) osx-icc32-profile-use
|
||||||
|
@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 "Running benchmark for pgo-build ..."
|
||||||
|
@$(PGOBENCH) > /dev/null
|
||||||
|
@echo "Benchmark finished. Build final executable now ..."
|
||||||
|
@echo ""
|
||||||
|
@touch *.cpp *.h
|
||||||
|
$(MAKE) osx-icc64-profile-use
|
||||||
|
@rm -rf profdir bench.txt
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Dependencies
|
|
||||||
###
|
|
||||||
|
|
||||||
|
strip:
|
||||||
|
strip $(EXE)
|
||||||
|
|
||||||
|
|
||||||
|
### Compilation. Do not change
|
||||||
$(EXE): $(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
||||||
|
|
||||||
|
|
||||||
|
### Dependencies. Do not change
|
||||||
.depend:
|
.depend:
|
||||||
$(CXX) -MM $(OBJS:.o=.cpp) > $@
|
$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@
|
||||||
|
|
||||||
include .depend
|
include .depend
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Compiler and linker switches
|
|
||||||
###
|
|
||||||
|
|
||||||
# Enable/disable debugging:
|
|
||||||
|
|
||||||
CXXFLAGS += -DNDEBUG
|
|
||||||
|
|
||||||
|
|
||||||
# Compile with full warnings, and symbol names
|
|
||||||
|
|
||||||
CXXFLAGS += -Wall -g
|
|
||||||
|
|
||||||
|
|
||||||
# General optimization flags. Note that -O2 might be faster than -O3 on some
|
|
||||||
# systems; this requires testing.
|
|
||||||
|
|
||||||
CXXFLAGS += -O3 -fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
|
|
||||||
|
|
||||||
# Disable most annoying warnings for the Intel C++ compiler
|
|
||||||
|
|
||||||
CXXFLAGS += -wd383,869,981
|
|
||||||
|
|
||||||
|
|
||||||
# Compiler optimization flags for the Intel C++ compiler in Mac OS X:
|
|
||||||
|
|
||||||
# CXXFLAGS += -mdynamic-no-pic -no-prec-div -ipo -static -xP
|
|
||||||
|
|
||||||
|
|
||||||
# Profiler guided optimization with the Intel C++ compiler. To use it, first
|
|
||||||
# create the directory ./profdata if it does not already exist, and delete its
|
|
||||||
# contents if it does exist. Then compile with -prof_gen, and run the
|
|
||||||
# resulting binary for a while (for instance, do ./glaurung bench 128 1, and
|
|
||||||
# wait 15 minutes for the benchmark to complete). Then do a 'make clean', and
|
|
||||||
# recompile with -prof_use.
|
|
||||||
|
|
||||||
# CXXFLAGS += -prof_gen -prof_dir profdata
|
|
||||||
# CXXFLAGS += -prof_use -prof_dir ./profdata
|
|
||||||
|
|
||||||
|
|
||||||
# Profiler guided optimization with GCC. I've never been able to make this
|
|
||||||
# work.
|
|
||||||
|
|
||||||
# CXXFLAGS += -fprofile-generate
|
|
||||||
# LDFLAGS += -fprofile-generate
|
|
||||||
# CXXFLAGS += -fprofile-use
|
|
||||||
# CXXFLAGS += -fprofile-use
|
|
||||||
|
|
||||||
|
|
||||||
# General linker flags
|
|
||||||
|
|
||||||
LDFLAGS += -lm -lpthread
|
|
||||||
|
|
||||||
|
|
||||||
# Compiler switches for generating binaries for various CPUs in Mac OS X.
|
|
||||||
# Note that 'arch ppc' and 'arch ppc64' only works with g++, and not with
|
|
||||||
# the intel compiler.
|
|
||||||
|
|
||||||
# CXXFLAGS += -arch ppc
|
|
||||||
# CXXFLAGS += -arch ppc64
|
|
||||||
# CXXFLAGS += -arch i386
|
|
||||||
# CXXFLAGS += -arch x86_64
|
|
||||||
# LDFLAGS += -arch ppc
|
|
||||||
# LDFLAGS += -arch ppc64
|
|
||||||
# LDFLAGS += -arch i386
|
|
||||||
# LDFLAGS += -arch x86_64
|
|
||||||
|
|
||||||
|
|
||||||
# Backwards compatibility with Mac OS X 10.4 when compiling under 10.5 with
|
|
||||||
# GCC 4.0. I haven't found a way to make it work with GCC 4.2.
|
|
||||||
|
|
||||||
# CXXFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
|
|
||||||
# CXXFLAGS += -mmacosx-version-min=10.4
|
|
||||||
# LDFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
|
|
||||||
# LDFLAGS += -Wl,-syslibroot /Developer/SDKs/MacOSX10.4u.sdk
|
|
||||||
# LDFLAGS += -mmacosx-version-min=10.4
|
|
||||||
|
|
||||||
|
|
||||||
# Backwards compatibility with Mac OS X 10.4 when compiling with ICC. Doesn't
|
|
||||||
# work yet. :-(
|
|
||||||
|
|
||||||
# CXXFLAGS += -DMAC_OS_X_VERSION_MIN_REQUIRED=1040
|
|
||||||
# CXXFLAGS += -DMAC_OS_X_VERSION_MAX_ALLOWED=1040
|
|
||||||
# CXXFLAGS += -D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1040
|
|
||||||
# CXXFLAGS += -F/Developer/SDKs/MacOSX10.4u.sdk/
|
|
||||||
# LDFLAGS += -Wl,-syslibroot -Wl,/Developer/SDKs/MacOSX10.4u.sdk
|
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
////
|
||||||
|
//// Includes
|
||||||
|
////
|
||||||
|
|
||||||
|
#include "bitboard.h"
|
||||||
|
#include "direction.h"
|
||||||
|
#include "endgame.h"
|
||||||
|
#include "evaluate.h"
|
||||||
|
#include "material.h"
|
||||||
|
#include "mersenne.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "movepick.h"
|
||||||
|
#include "position.h"
|
||||||
|
#include "search.h"
|
||||||
|
#include "thread.h"
|
||||||
|
#include "ucioption.h"
|
||||||
|
|
||||||
|
|
||||||
|
/// Application class is in charge of initializing global resources
|
||||||
|
/// at startup and cleanly releases them when program terminates.
|
||||||
|
|
||||||
|
Application::Application() {
|
||||||
|
|
||||||
|
init_mersenne();
|
||||||
|
init_direction_table();
|
||||||
|
init_bitboards();
|
||||||
|
init_uci_options();
|
||||||
|
Position::init_zobrist();
|
||||||
|
Position::init_piece_square_tables();
|
||||||
|
init_eval(1);
|
||||||
|
init_bitbases();
|
||||||
|
init_threads();
|
||||||
|
|
||||||
|
// Make random number generation less deterministic, for book moves
|
||||||
|
for (int i = abs(get_system_time() % 10000); i > 0; i--)
|
||||||
|
genrand_int32();
|
||||||
|
}
|
||||||
|
|
||||||
|
Application::~Application() {
|
||||||
|
|
||||||
|
stop_threads();
|
||||||
|
quit_eval();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::initialize() {
|
||||||
|
|
||||||
|
// A static Application object is allocated
|
||||||
|
// once only when this function is called.
|
||||||
|
static Application singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::exit_with_failure() {
|
||||||
|
|
||||||
|
exit(EXIT_FAILURE); // d'tor will be called automatically
|
||||||
|
}
|
||||||
@@ -1,34 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#if !defined(PHASE_H_INCLUDED)
|
#if !defined(APPLICATION_H_INCLUDED)
|
||||||
#define PHASE_H_INCLUDED
|
#define APPLICATION_H_INCLUDED
|
||||||
|
|
||||||
////
|
|
||||||
//// Types
|
|
||||||
////
|
|
||||||
|
|
||||||
enum Phase {
|
/// Singleton class used to housekeep memory and global resources
|
||||||
PHASE_ENDGAME = 0,
|
/// so to be sure we always leave in a clean state.
|
||||||
PHASE_MIDGAME = 128
|
|
||||||
|
class Application {
|
||||||
|
|
||||||
|
Application();
|
||||||
|
Application(const Application&);
|
||||||
|
~Application();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void initialize();
|
||||||
|
static void exit_with_failure();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // !defined(APPLICATION_H_INCLUDED)
|
||||||
#endif // !defined(PHASE_H_INCLUDED)
|
|
||||||
+61
-33
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -30,12 +30,13 @@
|
|||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "ucioption.h"
|
#include "ucioption.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Variables
|
//// Variables
|
||||||
////
|
////
|
||||||
|
|
||||||
const std::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",
|
"r4rk1/1b2qppp/p1n1p3/1p6/1b1PN3/3BRN2/PP3PPP/R2Q2K1 b - - 7 16",
|
||||||
"4r1k1/ppq3pp/3b4/2pP4/2Q1p3/4B1P1/PP5P/R5K1 b - - 0 20",
|
"4r1k1/ppq3pp/3b4/2pP4/2Q1p3/4B1P1/PP5P/R5K1 b - - 0 20",
|
||||||
@@ -53,7 +54,7 @@ const std::string BenchmarkPositions[] = {
|
|||||||
"4k2r/1pb2ppp/1p2p3/1R1p4/3P4/2r1PN2/P4PPP/1R4K1 b - 3 22",
|
"4k2r/1pb2ppp/1p2p3/1R1p4/3P4/2r1PN2/P4PPP/1R4K1 b - 3 22",
|
||||||
"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b - - 4 26"
|
"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b - - 4 26"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
@@ -67,28 +68,27 @@ const std::string BenchmarkPositions[] = {
|
|||||||
/// format (default are the BenchmarkPositions defined above).
|
/// format (default are the BenchmarkPositions defined above).
|
||||||
/// The analysis is written to a file named bench.txt.
|
/// The analysis is written to a file named bench.txt.
|
||||||
|
|
||||||
void benchmark(const std::string& commandLine) {
|
void benchmark(const string& commandLine) {
|
||||||
|
|
||||||
std::istringstream csVal(commandLine);
|
istringstream csVal(commandLine);
|
||||||
std::istringstream csStr(commandLine);
|
istringstream csStr(commandLine);
|
||||||
std::string ttSize, threads, fileName, limitType;
|
string ttSize, threads, fileName, limitType, timFile;
|
||||||
int val, secsPerPos, maxDepth, maxNodes;
|
int val, secsPerPos, maxDepth, maxNodes;
|
||||||
|
|
||||||
csStr >> ttSize;
|
csStr >> ttSize;
|
||||||
csVal >> val;
|
csVal >> val;
|
||||||
if (val < 4 || val > 1024)
|
if (val < 4 || val > 1024)
|
||||||
{
|
{
|
||||||
std::cerr << "The hash table size must be between 4 and 1024" << std::endl;
|
cerr << "The hash table size must be between 4 and 1024" << endl;
|
||||||
exit(EXIT_FAILURE);
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
csStr >> threads;
|
csStr >> threads;
|
||||||
csVal >> val;
|
csVal >> val;
|
||||||
if (val < 1 || val > THREAD_MAX)
|
if (val < 1 || val > THREAD_MAX)
|
||||||
{
|
{
|
||||||
std::cerr << "The number of threads must be between 1 and " << THREAD_MAX
|
cerr << "The number of threads must be between 1 and " << THREAD_MAX << endl;
|
||||||
<< std::endl;
|
Application::exit_with_failure();
|
||||||
exit(EXIT_FAILURE);
|
}
|
||||||
}
|
|
||||||
set_option_value("Hash", ttSize);
|
set_option_value("Hash", ttSize);
|
||||||
set_option_value("Threads", threads);
|
set_option_value("Threads", threads);
|
||||||
set_option_value("OwnBook", "false");
|
set_option_value("OwnBook", "false");
|
||||||
@@ -98,6 +98,7 @@ void benchmark(const std::string& commandLine) {
|
|||||||
csVal >> val;
|
csVal >> val;
|
||||||
csVal >> fileName;
|
csVal >> fileName;
|
||||||
csVal >> limitType;
|
csVal >> limitType;
|
||||||
|
csVal >> timFile;
|
||||||
|
|
||||||
secsPerPos = maxDepth = maxNodes = 0;
|
secsPerPos = maxDepth = maxNodes = 0;
|
||||||
|
|
||||||
@@ -108,44 +109,71 @@ void benchmark(const std::string& commandLine) {
|
|||||||
else
|
else
|
||||||
maxNodes = val;
|
maxNodes = val;
|
||||||
|
|
||||||
std::vector<std::string> positions;
|
vector<string> positions;
|
||||||
|
|
||||||
if (fileName != "default")
|
if (fileName != "default")
|
||||||
{
|
{
|
||||||
std::ifstream fenFile(fileName.c_str());
|
ifstream fenFile(fileName.c_str());
|
||||||
if (!fenFile.is_open())
|
if (!fenFile.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "Unable to open positions file " << fileName
|
cerr << "Unable to open positions file " << fileName << endl;
|
||||||
<< std::endl;
|
Application::exit_with_failure();
|
||||||
exit(EXIT_FAILURE);
|
}
|
||||||
}
|
string pos;
|
||||||
std::string pos;
|
|
||||||
while (fenFile.good())
|
while (fenFile.good())
|
||||||
{
|
{
|
||||||
std::getline(fenFile, pos);
|
getline(fenFile, pos);
|
||||||
if (!pos.empty())
|
if (!pos.empty())
|
||||||
positions.push_back(pos);
|
positions.push_back(pos);
|
||||||
}
|
}
|
||||||
fenFile.close();
|
fenFile.close();
|
||||||
} else
|
} else
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
positions.push_back(std::string(BenchmarkPositions[i]));
|
positions.push_back(string(BenchmarkPositions[i]));
|
||||||
|
|
||||||
int startTime = get_system_time();
|
ofstream timingFile;
|
||||||
std::vector<std::string>::iterator it;
|
if (!timFile.empty())
|
||||||
|
{
|
||||||
|
timingFile.open(timFile.c_str(), ios::out | ios::app);
|
||||||
|
if (!timingFile.is_open())
|
||||||
|
{
|
||||||
|
cerr << "Unable to open timing file " << timFile << endl;
|
||||||
|
Application::exit_with_failure();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string>::iterator it;
|
||||||
int cnt = 1;
|
int cnt = 1;
|
||||||
int64_t totalNodes = 0;
|
int64_t totalNodes = 0;
|
||||||
|
int startTime = get_system_time();
|
||||||
|
|
||||||
for (it = positions.begin(); it != positions.end(); ++it, ++cnt)
|
for (it = positions.begin(); it != positions.end(); ++it, ++cnt)
|
||||||
{
|
{
|
||||||
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);
|
||||||
std::cout << "\nProcessing position " << cnt << '/' << positions.size() << std::endl << std::endl;
|
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
|
||||||
think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves);
|
if (!think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
|
||||||
|
break;
|
||||||
totalNodes += nodes_searched();
|
totalNodes += nodes_searched();
|
||||||
}
|
}
|
||||||
std::cout << "\nProcessing time (ms) " << get_system_time() - startTime << std::endl
|
|
||||||
<< "Nodes searched " << totalNodes << std::endl
|
cnt = get_system_time() - startTime;
|
||||||
<< "Press any key to exit" << std::endl;
|
cerr << "==============================="
|
||||||
std::cin >> fileName;
|
<< "\nTotal time (ms) : " << cnt
|
||||||
|
<< "\nNodes searched : " << totalNodes
|
||||||
|
<< "\nNodes/second : " << (int)(totalNodes/(cnt/1000.0)) << endl << endl;
|
||||||
|
|
||||||
|
if (!timFile.empty())
|
||||||
|
{
|
||||||
|
timingFile << cnt << endl << endl;
|
||||||
|
timingFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Under MS Visual C++ debug window always unconditionally closes
|
||||||
|
// when program exits, this is bad because we want to read results before.
|
||||||
|
#if (defined(WINDOWS) || defined(WIN32) || defined(WIN64))
|
||||||
|
cerr << "Press any key to exit" << endl;
|
||||||
|
cin >> fileName;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+22
-21
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -53,11 +53,11 @@ namespace {
|
|||||||
Bitboard wk_attacks() const;
|
Bitboard wk_attacks() const;
|
||||||
Bitboard bk_attacks() const;
|
Bitboard bk_attacks() const;
|
||||||
Bitboard pawn_attacks() const;
|
Bitboard pawn_attacks() const;
|
||||||
|
|
||||||
Square whiteKingSquare, blackKingSquare, pawnSquare;
|
Square whiteKingSquare, blackKingSquare, pawnSquare;
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Result *Bitbase;
|
Result *Bitbase;
|
||||||
const int IndexMax = 2*24*64*64;
|
const int IndexMax = 2*24*64*64;
|
||||||
@@ -69,7 +69,7 @@ namespace {
|
|||||||
Result classify_btm(const KPKPosition &p);
|
Result classify_btm(const KPKPosition &p);
|
||||||
int compute_index(Square wksq, Square bksq, Square psq, Color stm);
|
int compute_index(Square wksq, Square bksq, Square psq, Color stm);
|
||||||
int compress_result(Result r);
|
int compress_result(Result r);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -89,7 +89,8 @@ void generate_kpk_bitbase(uint8_t bitbase[]) {
|
|||||||
int i, j, b;
|
int i, j, b;
|
||||||
for(i = 0; i < 24576; i++) {
|
for(i = 0; i < 24576; i++) {
|
||||||
for(b = 0, j = 0; j < 8; b |= (compress_result(Bitbase[8*i+j]) << j), j++);
|
for(b = 0, j = 0; j < 8; b |= (compress_result(Bitbase[8*i+j]) << j), j++);
|
||||||
bitbase[i] = b;
|
assert(b == int(uint8_t(b)));
|
||||||
|
bitbase[i] = (uint8_t)b;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release allocated memory:
|
// Release allocated memory:
|
||||||
@@ -113,7 +114,7 @@ namespace {
|
|||||||
return compute_index(whiteKingSquare, blackKingSquare, pawnSquare,
|
return compute_index(whiteKingSquare, blackKingSquare, pawnSquare,
|
||||||
sideToMove);
|
sideToMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KPKPosition::is_legal() const {
|
bool KPKPosition::is_legal() const {
|
||||||
if(whiteKingSquare == pawnSquare || whiteKingSquare == blackKingSquare ||
|
if(whiteKingSquare == pawnSquare || whiteKingSquare == blackKingSquare ||
|
||||||
@@ -137,7 +138,7 @@ namespace {
|
|||||||
if(sideToMove == BLACK) {
|
if(sideToMove == BLACK) {
|
||||||
Bitboard wka = this->wk_attacks();
|
Bitboard wka = this->wk_attacks();
|
||||||
Bitboard bka = this->bk_attacks();
|
Bitboard bka = this->bk_attacks();
|
||||||
|
|
||||||
// Case 1: Stalemate
|
// Case 1: Stalemate
|
||||||
if((bka & ~(wka | this->pawn_attacks())) == EmptyBoardBB)
|
if((bka & ~(wka | this->pawn_attacks())) == EmptyBoardBB)
|
||||||
return true;
|
return true;
|
||||||
@@ -166,7 +167,7 @@ namespace {
|
|||||||
(square_distance(blackKingSquare, pawnSquare+DELTA_N) > 1 ||
|
(square_distance(blackKingSquare, pawnSquare+DELTA_N) > 1 ||
|
||||||
bit_is_set(this->wk_attacks(), pawnSquare+DELTA_N));
|
bit_is_set(this->wk_attacks(), pawnSquare+DELTA_N));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Bitboard KPKPosition::wk_attacks() const {
|
Bitboard KPKPosition::wk_attacks() const {
|
||||||
return StepAttackBB[WK][whiteKingSquare];
|
return StepAttackBB[WK][whiteKingSquare];
|
||||||
@@ -204,7 +205,7 @@ namespace {
|
|||||||
bool next_iteration() {
|
bool next_iteration() {
|
||||||
KPKPosition p;
|
KPKPosition p;
|
||||||
int previousUnknownCount = UnknownCount;
|
int previousUnknownCount = UnknownCount;
|
||||||
|
|
||||||
for(int i = 0; i < IndexMax; i++)
|
for(int i = 0; i < IndexMax; i++)
|
||||||
if(Bitbase[i] == RESULT_UNKNOWN) {
|
if(Bitbase[i] == RESULT_UNKNOWN) {
|
||||||
p.from_index(i);
|
p.from_index(i);
|
||||||
@@ -231,7 +232,7 @@ namespace {
|
|||||||
bool unknownFound = false;
|
bool unknownFound = false;
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
Square s;
|
Square s;
|
||||||
|
|
||||||
// King moves
|
// King moves
|
||||||
b = p.wk_attacks();
|
b = p.wk_attacks();
|
||||||
while(b) {
|
while(b) {
|
||||||
@@ -260,14 +261,14 @@ namespace {
|
|||||||
BLACK)]) {
|
BLACK)]) {
|
||||||
case RESULT_LOSS:
|
case RESULT_LOSS:
|
||||||
return RESULT_WIN;
|
return RESULT_WIN;
|
||||||
|
|
||||||
case RESULT_UNKNOWN:
|
case RESULT_UNKNOWN:
|
||||||
unknownFound = true;
|
unknownFound = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESULT_DRAW: case RESULT_INVALID:
|
case RESULT_DRAW: case RESULT_INVALID:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
@@ -279,20 +280,20 @@ namespace {
|
|||||||
BLACK)]) {
|
BLACK)]) {
|
||||||
case RESULT_LOSS:
|
case RESULT_LOSS:
|
||||||
return RESULT_WIN;
|
return RESULT_WIN;
|
||||||
|
|
||||||
case RESULT_UNKNOWN:
|
case RESULT_UNKNOWN:
|
||||||
unknownFound = true;
|
unknownFound = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESULT_DRAW: case RESULT_INVALID:
|
case RESULT_DRAW: case RESULT_INVALID:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return unknownFound? RESULT_UNKNOWN : RESULT_DRAW;
|
return unknownFound? RESULT_UNKNOWN : RESULT_DRAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,5 +346,5 @@ namespace {
|
|||||||
int compress_result(Result r) {
|
int compress_result(Result r) {
|
||||||
return (r == RESULT_WIN || r == RESULT_LOSS)? 1 : 0;
|
return (r == RESULT_WIN || r == RESULT_LOSS)? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+212
-290
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,195 +22,14 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <intrin.h>
|
|
||||||
#ifdef _WIN64
|
|
||||||
#pragma intrinsic(_BitScanForward64)
|
|
||||||
#else
|
|
||||||
#pragma intrinsic(_BitScanForward)
|
|
||||||
#endif
|
|
||||||
#define USING_INTRINSICS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
|
#include "bitcount.h"
|
||||||
#include "direction.h"
|
#include "direction.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
#if defined(IS_64BIT)
|
||||||
//// Constants and variables
|
|
||||||
////
|
|
||||||
|
|
||||||
const Bitboard SquaresByColorBB[2] = {BlackSquaresBB, WhiteSquaresBB};
|
|
||||||
|
|
||||||
const Bitboard FileBB[8] = {
|
|
||||||
FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard NeighboringFilesBB[8] = {
|
|
||||||
FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB,
|
|
||||||
FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard ThisAndNeighboringFilesBB[8] = {
|
|
||||||
FileABB|FileBBB, FileABB|FileBBB|FileCBB,
|
|
||||||
FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB,
|
|
||||||
FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB,
|
|
||||||
FileFBB|FileGBB|FileHBB, FileGBB|FileHBB
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard RankBB[8] = {
|
|
||||||
Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard RelativeRankBB[2][8] = {
|
|
||||||
{
|
|
||||||
Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bitboard InFrontBB[2][8] = {
|
|
||||||
{
|
|
||||||
Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank6BB | Rank7BB | Rank8BB,
|
|
||||||
Rank7BB | Rank8BB,
|
|
||||||
Rank8BB,
|
|
||||||
EmptyBoardBB
|
|
||||||
},
|
|
||||||
{
|
|
||||||
EmptyBoardBB,
|
|
||||||
Rank1BB,
|
|
||||||
Rank2BB | Rank1BB,
|
|
||||||
Rank3BB | Rank2BB | Rank1BB,
|
|
||||||
Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
|
||||||
Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
|
||||||
Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
|
||||||
Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
|
||||||
|
|
||||||
Bitboard RankAttacks[8][64], FileAttacks[8][64];
|
|
||||||
|
|
||||||
#elif defined(USE_32BIT_ATTACKS)
|
|
||||||
|
|
||||||
const uint64_t RMult[64] = {
|
|
||||||
0xd7445cdec88002c0ULL, 0xd0a505c1f2001722ULL, 0xe065d1c896002182ULL,
|
|
||||||
0x9a8c41e75a000892ULL, 0x8900b10c89002aa8ULL, 0x9b28d1c1d60005a2ULL,
|
|
||||||
0x15d6c88de002d9aULL, 0xb1dbfc802e8016a9ULL, 0x149a1042d9d60029ULL,
|
|
||||||
0xb9c08050599e002fULL, 0x132208c3af300403ULL, 0xc1000ce2e9c50070ULL,
|
|
||||||
0x9d9aa13c99020012ULL, 0xb6b078daf71e0046ULL, 0x9d880182fb6e002eULL,
|
|
||||||
0x52889f467e850037ULL, 0xda6dc008d19a8480ULL, 0x468286034f902420ULL,
|
|
||||||
0x7140ac09dc54c020ULL, 0xd76ffffa39548808ULL, 0xea901c4141500808ULL,
|
|
||||||
0xc91004093f953a02ULL, 0x2882afa8f6bb402ULL, 0xaebe335692442c01ULL,
|
|
||||||
0xe904a22079fb91eULL, 0x13a514851055f606ULL, 0x76c782018c8fe632ULL,
|
|
||||||
0x1dc012a9d116da06ULL, 0x3c9e0037264fffa6ULL, 0x2036002853c6e4a2ULL,
|
|
||||||
0xe3fe08500afb47d4ULL, 0xf38af25c86b025c2ULL, 0xc0800e2182cf9a40ULL,
|
|
||||||
0x72002480d1f60673ULL, 0x2500200bae6e9b53ULL, 0xc60018c1eefca252ULL,
|
|
||||||
0x600590473e3608aULL, 0x46002c4ab3fe51b2ULL, 0xa200011486bcc8d2ULL,
|
|
||||||
0xb680078095784c63ULL, 0x2742002639bf11aeULL, 0xc7d60021a5bdb142ULL,
|
|
||||||
0xc8c04016bb83d820ULL, 0xbd520028123b4842ULL, 0x9d1600344ac2a832ULL,
|
|
||||||
0x6a808005631c8a05ULL, 0x604600a148d5389aULL, 0xe2e40103d40dea65ULL,
|
|
||||||
0x945b5a0087c62a81ULL, 0x12dc200cd82d28eULL, 0x2431c600b5f9ef76ULL,
|
|
||||||
0xfb142a006a9b314aULL, 0x6870e00a1c97d62ULL, 0x2a9db2004a2689a2ULL,
|
|
||||||
0xd3594600caf5d1a2ULL, 0xee0e4900439344a7ULL, 0x89c4d266ca25007aULL,
|
|
||||||
0x3e0013a2743f97e3ULL, 0x180e31a0431378aULL, 0x3a9e465a4d42a512ULL,
|
|
||||||
0x98d0a11a0c0d9cc2ULL, 0x8e711c1aba19b01eULL, 0x8dcdc836dd201142ULL,
|
|
||||||
0x5ac08a4735370479ULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
const int RShift[64] = {
|
|
||||||
20, 21, 21, 21, 21, 21, 21, 20, 21, 22, 22, 22, 22, 22, 22, 21,
|
|
||||||
21, 22, 22, 22, 22, 22, 22, 21, 21, 22, 22, 22, 22, 22, 22, 21,
|
|
||||||
21, 22, 22, 22, 22, 22, 22, 21, 21, 22, 22, 22, 22, 22, 22, 21,
|
|
||||||
21, 22, 22, 22, 22, 22, 22, 21, 20, 21, 21, 21, 21, 21, 21, 20
|
|
||||||
};
|
|
||||||
|
|
||||||
#else // if defined(USE_32BIT_ATTACKS)
|
|
||||||
|
|
||||||
const uint64_t RMult[64] = {
|
|
||||||
0xa8002c000108020ULL, 0x4440200140003000ULL, 0x8080200010011880ULL,
|
|
||||||
0x380180080141000ULL, 0x1a00060008211044ULL, 0x410001000a0c0008ULL,
|
|
||||||
0x9500060004008100ULL, 0x100024284a20700ULL, 0x802140008000ULL,
|
|
||||||
0x80c01002a00840ULL, 0x402004282011020ULL, 0x9862000820420050ULL,
|
|
||||||
0x1001448011100ULL, 0x6432800200800400ULL, 0x40100010002000cULL,
|
|
||||||
0x2800d0010c080ULL, 0x90c0008000803042ULL, 0x4010004000200041ULL,
|
|
||||||
0x3010010200040ULL, 0xa40828028001000ULL, 0x123010008000430ULL,
|
|
||||||
0x24008004020080ULL, 0x60040001104802ULL, 0x582200028400d1ULL,
|
|
||||||
0x4000802080044000ULL, 0x408208200420308ULL, 0x610038080102000ULL,
|
|
||||||
0x3601000900100020ULL, 0x80080040180ULL, 0xc2020080040080ULL,
|
|
||||||
0x80084400100102ULL, 0x4022408200014401ULL, 0x40052040800082ULL,
|
|
||||||
0xb08200280804000ULL, 0x8a80a008801000ULL, 0x4000480080801000ULL,
|
|
||||||
0x911808800801401ULL, 0x822a003002001894ULL, 0x401068091400108aULL,
|
|
||||||
0x4a10a00004cULL, 0x2000800640008024ULL, 0x1486408102020020ULL,
|
|
||||||
0x100a000d50041ULL, 0x810050020b0020ULL, 0x204000800808004ULL,
|
|
||||||
0x20048100a000cULL, 0x112000831020004ULL, 0x9000040810002ULL,
|
|
||||||
0x440490200208200ULL, 0x8910401000200040ULL, 0x6404200050008480ULL,
|
|
||||||
0x4b824a2010010100ULL, 0x4080801810c0080ULL, 0x400802a0080ULL,
|
|
||||||
0x8224080110026400ULL, 0x40002c4104088200ULL, 0x1002100104a0282ULL,
|
|
||||||
0x1208400811048021ULL, 0x3201014a40d02001ULL, 0x5100019200501ULL,
|
|
||||||
0x101000208001005ULL, 0x2008450080702ULL, 0x1002080301d00cULL,
|
|
||||||
0x410201ce5c030092ULL
|
|
||||||
};
|
|
||||||
|
|
||||||
const int RShift[64] = {
|
|
||||||
52, 53, 53, 53, 53, 53, 53, 52, 53, 54, 54, 54, 54, 54, 54, 53,
|
|
||||||
53, 54, 54, 54, 54, 54, 54, 53, 53, 54, 54, 54, 54, 54, 54, 53,
|
|
||||||
53, 54, 54, 54, 54, 54, 54, 53, 53, 54, 54, 54, 54, 54, 54, 53,
|
|
||||||
53, 54, 54, 54, 54, 54, 54, 53, 52, 53, 53, 53, 53, 53, 53, 52
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // defined(USE_32BIT_ATTACKS)
|
|
||||||
|
|
||||||
#if !defined(USE_COMPACT_ROOK_ATTACKS)
|
|
||||||
Bitboard RMask[64];
|
|
||||||
int RAttackIndex[64];
|
|
||||||
Bitboard RAttacks[0x19000];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(USE_32BIT_ATTACKS)
|
|
||||||
|
|
||||||
const uint64_t BMult[64] = {
|
|
||||||
0x54142844c6a22981ULL, 0x710358a6ea25c19eULL, 0x704f746d63a4a8dcULL,
|
|
||||||
0xbfed1a0b80f838c5ULL, 0x90561d5631e62110ULL, 0x2804260376e60944ULL,
|
|
||||||
0x84a656409aa76871ULL, 0xf0267f64c28b6197ULL, 0x70764ebb762f0585ULL,
|
|
||||||
0x92aa09e0cfe161deULL, 0x41ee1f6bb266f60eULL, 0xddcbf04f6039c444ULL,
|
|
||||||
0x5a3fab7bac0d988aULL, 0xd3727877fa4eaa03ULL, 0xd988402d868ddaaeULL,
|
|
||||||
0x812b291afa075c7cULL, 0x94faf987b685a932ULL, 0x3ed867d8470d08dbULL,
|
|
||||||
0x92517660b8901de8ULL, 0x2d97e43e058814b4ULL, 0x880a10c220b25582ULL,
|
|
||||||
0xc7c6520d1f1a0477ULL, 0xdbfc7fbcd7656aa6ULL, 0x78b1b9bfb1a2b84fULL,
|
|
||||||
0x2f20037f112a0bc1ULL, 0x657171ea2269a916ULL, 0xc08302b07142210eULL,
|
|
||||||
0x880a4403064080bULL, 0x3602420842208c00ULL, 0x852800dc7e0b6602ULL,
|
|
||||||
0x595a3fbbaa0f03b2ULL, 0x9f01411558159d5eULL, 0x2b4a4a5f88b394f2ULL,
|
|
||||||
0x4afcbffc292dd03aULL, 0x4a4094a3b3f10522ULL, 0xb06f00b491f30048ULL,
|
|
||||||
0xd5b3820280d77004ULL, 0x8b2e01e7c8e57a75ULL, 0x2d342794e886c2e6ULL,
|
|
||||||
0xc302c410cde21461ULL, 0x111f426f1379c274ULL, 0xe0569220abb31588ULL,
|
|
||||||
0x5026d3064d453324ULL, 0xe2076040c343cd8aULL, 0x93efd1e1738021eeULL,
|
|
||||||
0xb680804bed143132ULL, 0x44e361b21986944cULL, 0x44c60170ef5c598cULL,
|
|
||||||
0xf4da475c195c9c94ULL, 0xa3afbb5f72060b1dULL, 0xbc75f410e41c4ffcULL,
|
|
||||||
0xb51c099390520922ULL, 0x902c011f8f8ec368ULL, 0x950b56b3d6f5490aULL,
|
|
||||||
0x3909e0635bf202d0ULL, 0x5744f90206ec10ccULL, 0xdc59fd76317abbc1ULL,
|
|
||||||
0x881c7c67fcbfc4f6ULL, 0x47ca41e7e440d423ULL, 0xeb0c88112048d004ULL,
|
|
||||||
0x51c60e04359aef1aULL, 0x1aa1fe0e957a5554ULL, 0xdd9448db4f5e3104ULL,
|
|
||||||
0xdc01f6dca4bebbdcULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
const int BShift[64] = {
|
|
||||||
26, 27, 27, 27, 27, 27, 27, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
|
||||||
27, 27, 25, 25, 25, 25, 27, 27, 27, 27, 25, 23, 23, 25, 27, 27,
|
|
||||||
27, 27, 25, 23, 23, 25, 27, 27, 27, 27, 25, 25, 25, 25, 27, 27,
|
|
||||||
27, 27, 27, 27, 27, 27, 27, 27, 26, 27, 27, 27, 27, 27, 27, 26
|
|
||||||
};
|
|
||||||
|
|
||||||
#else // if defined(USE_32BIT_ATTACKS)
|
|
||||||
|
|
||||||
const uint64_t BMult[64] = {
|
const uint64_t BMult[64] = {
|
||||||
0x440049104032280ULL, 0x1021023c82008040ULL, 0x404040082000048ULL,
|
0x440049104032280ULL, 0x1021023c82008040ULL, 0x404040082000048ULL,
|
||||||
@@ -237,6 +56,31 @@ const uint64_t BMult[64] = {
|
|||||||
0xa08520292120600ULL
|
0xa08520292120600ULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint64_t RMult[64] = {
|
||||||
|
0xa8002c000108020ULL, 0x4440200140003000ULL, 0x8080200010011880ULL,
|
||||||
|
0x380180080141000ULL, 0x1a00060008211044ULL, 0x410001000a0c0008ULL,
|
||||||
|
0x9500060004008100ULL, 0x100024284a20700ULL, 0x802140008000ULL,
|
||||||
|
0x80c01002a00840ULL, 0x402004282011020ULL, 0x9862000820420050ULL,
|
||||||
|
0x1001448011100ULL, 0x6432800200800400ULL, 0x40100010002000cULL,
|
||||||
|
0x2800d0010c080ULL, 0x90c0008000803042ULL, 0x4010004000200041ULL,
|
||||||
|
0x3010010200040ULL, 0xa40828028001000ULL, 0x123010008000430ULL,
|
||||||
|
0x24008004020080ULL, 0x60040001104802ULL, 0x582200028400d1ULL,
|
||||||
|
0x4000802080044000ULL, 0x408208200420308ULL, 0x610038080102000ULL,
|
||||||
|
0x3601000900100020ULL, 0x80080040180ULL, 0xc2020080040080ULL,
|
||||||
|
0x80084400100102ULL, 0x4022408200014401ULL, 0x40052040800082ULL,
|
||||||
|
0xb08200280804000ULL, 0x8a80a008801000ULL, 0x4000480080801000ULL,
|
||||||
|
0x911808800801401ULL, 0x822a003002001894ULL, 0x401068091400108aULL,
|
||||||
|
0x4a10a00004cULL, 0x2000800640008024ULL, 0x1486408102020020ULL,
|
||||||
|
0x100a000d50041ULL, 0x810050020b0020ULL, 0x204000800808004ULL,
|
||||||
|
0x20048100a000cULL, 0x112000831020004ULL, 0x9000040810002ULL,
|
||||||
|
0x440490200208200ULL, 0x8910401000200040ULL, 0x6404200050008480ULL,
|
||||||
|
0x4b824a2010010100ULL, 0x4080801810c0080ULL, 0x400802a0080ULL,
|
||||||
|
0x8224080110026400ULL, 0x40002c4104088200ULL, 0x1002100104a0282ULL,
|
||||||
|
0x1208400811048021ULL, 0x3201014a40d02001ULL, 0x5100019200501ULL,
|
||||||
|
0x101000208001005ULL, 0x2008450080702ULL, 0x1002080301d00cULL,
|
||||||
|
0x410201ce5c030092ULL
|
||||||
|
};
|
||||||
|
|
||||||
const int BShift[64] = {
|
const int BShift[64] = {
|
||||||
58, 59, 59, 59, 59, 59, 59, 58, 59, 59, 59, 59, 59, 59, 59, 59,
|
58, 59, 59, 59, 59, 59, 59, 58, 59, 59, 59, 59, 59, 59, 59, 59,
|
||||||
59, 59, 57, 57, 57, 57, 59, 59, 59, 59, 57, 55, 55, 57, 59, 59,
|
59, 59, 57, 57, 57, 57, 59, 59, 59, 59, 57, 55, 55, 57, 59, 59,
|
||||||
@@ -244,14 +88,139 @@ const int BShift[64] = {
|
|||||||
59, 59, 59, 59, 59, 59, 59, 59, 58, 59, 59, 59, 59, 59, 59, 58
|
59, 59, 59, 59, 59, 59, 59, 59, 58, 59, 59, 59, 59, 59, 59, 58
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // defined(USE_32BIT_ATTACKS)
|
const int RShift[64] = {
|
||||||
|
52, 53, 53, 53, 53, 53, 53, 52, 53, 54, 54, 54, 54, 54, 54, 53,
|
||||||
|
53, 54, 54, 54, 54, 54, 54, 53, 53, 54, 54, 54, 54, 54, 54, 53,
|
||||||
|
53, 54, 54, 54, 54, 54, 54, 53, 53, 54, 54, 54, 54, 54, 54, 53,
|
||||||
|
53, 54, 54, 54, 54, 54, 54, 53, 52, 53, 53, 53, 53, 53, 53, 52
|
||||||
|
};
|
||||||
|
|
||||||
|
#else // if !defined(IS_64BIT)
|
||||||
|
|
||||||
|
const uint64_t BMult[64] = {
|
||||||
|
0x54142844c6a22981ULL, 0x710358a6ea25c19eULL, 0x704f746d63a4a8dcULL,
|
||||||
|
0xbfed1a0b80f838c5ULL, 0x90561d5631e62110ULL, 0x2804260376e60944ULL,
|
||||||
|
0x84a656409aa76871ULL, 0xf0267f64c28b6197ULL, 0x70764ebb762f0585ULL,
|
||||||
|
0x92aa09e0cfe161deULL, 0x41ee1f6bb266f60eULL, 0xddcbf04f6039c444ULL,
|
||||||
|
0x5a3fab7bac0d988aULL, 0xd3727877fa4eaa03ULL, 0xd988402d868ddaaeULL,
|
||||||
|
0x812b291afa075c7cULL, 0x94faf987b685a932ULL, 0x3ed867d8470d08dbULL,
|
||||||
|
0x92517660b8901de8ULL, 0x2d97e43e058814b4ULL, 0x880a10c220b25582ULL,
|
||||||
|
0xc7c6520d1f1a0477ULL, 0xdbfc7fbcd7656aa6ULL, 0x78b1b9bfb1a2b84fULL,
|
||||||
|
0x2f20037f112a0bc1ULL, 0x657171ea2269a916ULL, 0xc08302b07142210eULL,
|
||||||
|
0x880a4403064080bULL, 0x3602420842208c00ULL, 0x852800dc7e0b6602ULL,
|
||||||
|
0x595a3fbbaa0f03b2ULL, 0x9f01411558159d5eULL, 0x2b4a4a5f88b394f2ULL,
|
||||||
|
0x4afcbffc292dd03aULL, 0x4a4094a3b3f10522ULL, 0xb06f00b491f30048ULL,
|
||||||
|
0xd5b3820280d77004ULL, 0x8b2e01e7c8e57a75ULL, 0x2d342794e886c2e6ULL,
|
||||||
|
0xc302c410cde21461ULL, 0x111f426f1379c274ULL, 0xe0569220abb31588ULL,
|
||||||
|
0x5026d3064d453324ULL, 0xe2076040c343cd8aULL, 0x93efd1e1738021eeULL,
|
||||||
|
0xb680804bed143132ULL, 0x44e361b21986944cULL, 0x44c60170ef5c598cULL,
|
||||||
|
0xf4da475c195c9c94ULL, 0xa3afbb5f72060b1dULL, 0xbc75f410e41c4ffcULL,
|
||||||
|
0xb51c099390520922ULL, 0x902c011f8f8ec368ULL, 0x950b56b3d6f5490aULL,
|
||||||
|
0x3909e0635bf202d0ULL, 0x5744f90206ec10ccULL, 0xdc59fd76317abbc1ULL,
|
||||||
|
0x881c7c67fcbfc4f6ULL, 0x47ca41e7e440d423ULL, 0xeb0c88112048d004ULL,
|
||||||
|
0x51c60e04359aef1aULL, 0x1aa1fe0e957a5554ULL, 0xdd9448db4f5e3104ULL,
|
||||||
|
0xdc01f6dca4bebbdcULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint64_t RMult[64] = {
|
||||||
|
0xd7445cdec88002c0ULL, 0xd0a505c1f2001722ULL, 0xe065d1c896002182ULL,
|
||||||
|
0x9a8c41e75a000892ULL, 0x8900b10c89002aa8ULL, 0x9b28d1c1d60005a2ULL,
|
||||||
|
0x15d6c88de002d9aULL, 0xb1dbfc802e8016a9ULL, 0x149a1042d9d60029ULL,
|
||||||
|
0xb9c08050599e002fULL, 0x132208c3af300403ULL, 0xc1000ce2e9c50070ULL,
|
||||||
|
0x9d9aa13c99020012ULL, 0xb6b078daf71e0046ULL, 0x9d880182fb6e002eULL,
|
||||||
|
0x52889f467e850037ULL, 0xda6dc008d19a8480ULL, 0x468286034f902420ULL,
|
||||||
|
0x7140ac09dc54c020ULL, 0xd76ffffa39548808ULL, 0xea901c4141500808ULL,
|
||||||
|
0xc91004093f953a02ULL, 0x2882afa8f6bb402ULL, 0xaebe335692442c01ULL,
|
||||||
|
0xe904a22079fb91eULL, 0x13a514851055f606ULL, 0x76c782018c8fe632ULL,
|
||||||
|
0x1dc012a9d116da06ULL, 0x3c9e0037264fffa6ULL, 0x2036002853c6e4a2ULL,
|
||||||
|
0xe3fe08500afb47d4ULL, 0xf38af25c86b025c2ULL, 0xc0800e2182cf9a40ULL,
|
||||||
|
0x72002480d1f60673ULL, 0x2500200bae6e9b53ULL, 0xc60018c1eefca252ULL,
|
||||||
|
0x600590473e3608aULL, 0x46002c4ab3fe51b2ULL, 0xa200011486bcc8d2ULL,
|
||||||
|
0xb680078095784c63ULL, 0x2742002639bf11aeULL, 0xc7d60021a5bdb142ULL,
|
||||||
|
0xc8c04016bb83d820ULL, 0xbd520028123b4842ULL, 0x9d1600344ac2a832ULL,
|
||||||
|
0x6a808005631c8a05ULL, 0x604600a148d5389aULL, 0xe2e40103d40dea65ULL,
|
||||||
|
0x945b5a0087c62a81ULL, 0x12dc200cd82d28eULL, 0x2431c600b5f9ef76ULL,
|
||||||
|
0xfb142a006a9b314aULL, 0x6870e00a1c97d62ULL, 0x2a9db2004a2689a2ULL,
|
||||||
|
0xd3594600caf5d1a2ULL, 0xee0e4900439344a7ULL, 0x89c4d266ca25007aULL,
|
||||||
|
0x3e0013a2743f97e3ULL, 0x180e31a0431378aULL, 0x3a9e465a4d42a512ULL,
|
||||||
|
0x98d0a11a0c0d9cc2ULL, 0x8e711c1aba19b01eULL, 0x8dcdc836dd201142ULL,
|
||||||
|
0x5ac08a4735370479ULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
const int BShift[64] = {
|
||||||
|
26, 27, 27, 27, 27, 27, 27, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||||
|
27, 27, 25, 25, 25, 25, 27, 27, 27, 27, 25, 23, 23, 25, 27, 27,
|
||||||
|
27, 27, 25, 23, 23, 25, 27, 27, 27, 27, 25, 25, 25, 25, 27, 27,
|
||||||
|
27, 27, 27, 27, 27, 27, 27, 27, 26, 27, 27, 27, 27, 27, 27, 26
|
||||||
|
};
|
||||||
|
|
||||||
|
const int RShift[64] = {
|
||||||
|
20, 21, 21, 21, 21, 21, 21, 20, 21, 22, 22, 22, 22, 22, 22, 21,
|
||||||
|
21, 22, 22, 22, 22, 22, 22, 21, 21, 22, 22, 22, 22, 22, 22, 21,
|
||||||
|
21, 22, 22, 22, 22, 22, 22, 21, 21, 22, 22, 22, 22, 22, 22, 21,
|
||||||
|
21, 22, 22, 22, 22, 22, 22, 21, 20, 21, 21, 21, 21, 21, 21, 20
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // defined(IS_64BIT)
|
||||||
|
|
||||||
|
const Bitboard SquaresByColorBB[2] = { BlackSquaresBB, WhiteSquaresBB };
|
||||||
|
|
||||||
|
const Bitboard FileBB[8] = {
|
||||||
|
FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard NeighboringFilesBB[8] = {
|
||||||
|
FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB,
|
||||||
|
FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard ThisAndNeighboringFilesBB[8] = {
|
||||||
|
FileABB|FileBBB, FileABB|FileBBB|FileCBB,
|
||||||
|
FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB,
|
||||||
|
FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB,
|
||||||
|
FileFBB|FileGBB|FileHBB, FileGBB|FileHBB
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard RankBB[8] = {
|
||||||
|
Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard RelativeRankBB[2][8] = {
|
||||||
|
{ Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB },
|
||||||
|
{ Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Bitboard InFrontBB[2][8] = {
|
||||||
|
{ Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank6BB | Rank7BB | Rank8BB,
|
||||||
|
Rank7BB | Rank8BB,
|
||||||
|
Rank8BB,
|
||||||
|
EmptyBoardBB
|
||||||
|
},
|
||||||
|
{ EmptyBoardBB,
|
||||||
|
Rank1BB,
|
||||||
|
Rank2BB | Rank1BB,
|
||||||
|
Rank3BB | Rank2BB | Rank1BB,
|
||||||
|
Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||||
|
Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||||
|
Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||||
|
Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Bitboard RMask[64];
|
||||||
|
int RAttackIndex[64];
|
||||||
|
Bitboard RAttacks[0x19000];
|
||||||
|
|
||||||
Bitboard BMask[64];
|
Bitboard BMask[64];
|
||||||
int BAttackIndex[64];
|
int BAttackIndex[64];
|
||||||
Bitboard BAttacks[0x1480];
|
Bitboard BAttacks[0x1480];
|
||||||
|
|
||||||
Bitboard SetMaskBB[64];
|
Bitboard SetMaskBB[65];
|
||||||
Bitboard ClearMaskBB[64];
|
Bitboard ClearMaskBB[65];
|
||||||
|
|
||||||
Bitboard StepAttackBB[16][64];
|
Bitboard StepAttackBB[16][64];
|
||||||
Bitboard RayBB[64][8];
|
Bitboard RayBB[64][8];
|
||||||
@@ -264,12 +233,15 @@ Bitboard BishopPseudoAttacks[64];
|
|||||||
Bitboard RookPseudoAttacks[64];
|
Bitboard RookPseudoAttacks[64];
|
||||||
Bitboard QueenPseudoAttacks[64];
|
Bitboard QueenPseudoAttacks[64];
|
||||||
|
|
||||||
|
uint8_t BitCount8Bit[256];
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
////
|
////
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void init_masks();
|
void init_masks();
|
||||||
void init_ray_bitboards();
|
void init_ray_bitboards();
|
||||||
void init_attacks();
|
void init_attacks();
|
||||||
@@ -282,9 +254,6 @@ namespace {
|
|||||||
const int shift[2], const Bitboard mult[],
|
const int shift[2], const Bitboard mult[],
|
||||||
int deltas[][2]);
|
int deltas[][2]);
|
||||||
void init_pseudo_attacks();
|
void init_pseudo_attacks();
|
||||||
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
|
||||||
void init_file_and_rank_attacks();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -316,20 +285,39 @@ void init_bitboards() {
|
|||||||
init_ray_bitboards();
|
init_ray_bitboards();
|
||||||
init_attacks();
|
init_attacks();
|
||||||
init_between_bitboards();
|
init_between_bitboards();
|
||||||
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
init_sliding_attacks(RAttacks, RAttackIndex, RMask, RShift, RMult, rookDeltas);
|
||||||
init_file_and_rank_attacks();
|
init_sliding_attacks(BAttacks, BAttackIndex, BMask, BShift, BMult, bishopDeltas);
|
||||||
#else
|
|
||||||
init_sliding_attacks(RAttacks, RAttackIndex, RMask, RShift,
|
|
||||||
RMult, rookDeltas);
|
|
||||||
#endif
|
|
||||||
init_sliding_attacks(BAttacks, BAttackIndex, BMask, BShift,
|
|
||||||
BMult, bishopDeltas);
|
|
||||||
init_pseudo_attacks();
|
init_pseudo_attacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(USE_FOLDED_BITSCAN)
|
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
|
||||||
|
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
||||||
|
/// nonzero bitboard.
|
||||||
|
|
||||||
|
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
||||||
|
|
||||||
|
CACHE_LINE_ALIGNMENT
|
||||||
|
static 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,
|
||||||
|
46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39,
|
||||||
|
16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43,
|
||||||
|
51, 60, 42, 59, 58
|
||||||
|
};
|
||||||
|
|
||||||
|
Square first_1(Bitboard b) {
|
||||||
|
return Square(BitTable[((b & -b) * 0x218a392cd3d5dbfULL) >> 58]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Square pop_1st_bit(Bitboard* b) {
|
||||||
|
Bitboard bb = *b;
|
||||||
|
*b &= (*b - 1);
|
||||||
|
return Square(BitTable[((bb & -bb) * 0x218a392cd3d5dbfULL) >> 58]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif !defined(USE_BSFQ)
|
||||||
|
|
||||||
|
CACHE_LINE_ALIGNMENT
|
||||||
static const int BitTable[64] = {
|
static 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,
|
||||||
@@ -337,21 +325,12 @@ static const int BitTable[64] = {
|
|||||||
58, 20, 37, 17, 36, 8
|
58, 20, 37, 17, 36, 8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
|
|
||||||
|
|
||||||
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
|
||||||
/// nonzero bitboard.
|
|
||||||
|
|
||||||
#if defined(USE_32BIT_ATTACKS)
|
|
||||||
|
|
||||||
// Use type-punning
|
// Use type-punning
|
||||||
union b_union {
|
union b_union {
|
||||||
|
|
||||||
@@ -359,72 +338,28 @@ union b_union {
|
|||||||
struct {
|
struct {
|
||||||
uint32_t l;
|
uint32_t l;
|
||||||
uint32_t h;
|
uint32_t h;
|
||||||
};
|
} dw;
|
||||||
};
|
};
|
||||||
|
|
||||||
// WARNING: Needs -fno-strict-aliasing compiler option
|
// 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;
|
||||||
uint32_t b;
|
|
||||||
|
|
||||||
u.b = *bb;
|
u.b = *bb;
|
||||||
|
|
||||||
if (u.l)
|
if (u.dw.l)
|
||||||
{
|
{
|
||||||
b = u.l;
|
*((uint32_t*)bb) = u.dw.l & (u.dw.l - 1);
|
||||||
*((uint32_t*)bb) = b & (b - 1);
|
return Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||||
b ^= (b - 1);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
b = u.h;
|
|
||||||
*((uint32_t*)bb+1) = b & (b - 1); // Little endian only?
|
|
||||||
b = ~(b ^ (b - 1));
|
|
||||||
}
|
|
||||||
return Square(BitTable[(b * 0x783a9b23) >> 26]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
*((uint32_t*)bb+1) = u.dw.h & (u.dw.h - 1); // Little endian only?
|
||||||
|
return Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
||||||
Square pop_1st_bit(Bitboard *b) {
|
|
||||||
Bitboard bb = *b ^ (*b - 1);
|
|
||||||
uint32_t fold = int(bb) ^ int(bb >> 32);
|
|
||||||
*b &= (*b - 1);
|
|
||||||
return Square(BitTable[(fold * 0x783a9b23) >> 26]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static 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,
|
|
||||||
46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39,
|
|
||||||
16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43,
|
|
||||||
51, 60, 42, 59, 58
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
|
|
||||||
|
|
||||||
Square first_1(Bitboard b) {
|
|
||||||
return Square(BitTable[((b & -b) * 0x218a392cd3d5dbfULL) >> 58]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
|
||||||
/// nonzero bitboard.
|
|
||||||
|
|
||||||
Square pop_1st_bit(Bitboard *b) {
|
|
||||||
Bitboard bb = *b;
|
|
||||||
*b &= (*b - 1);
|
|
||||||
return Square(BitTable[((bb & -bb) * 0x218a392cd3d5dbfULL) >> 58]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // defined(USE_FOLDED_BITSCAN)
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// All functions below are used to precompute various bitboards during
|
// All functions below are used to precompute various bitboards during
|
||||||
@@ -433,6 +368,8 @@ 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;
|
||||||
|
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];
|
||||||
@@ -443,12 +380,15 @@ namespace {
|
|||||||
in_front_bb(c, s) & this_and_neighboring_files_bb(s);
|
in_front_bb(c, s) & this_and_neighboring_files_bb(s);
|
||||||
OutpostMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
OutpostMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Bitboard b = 0ULL; b < 256ULL; b++)
|
||||||
|
BitCount8Bit[b] = (uint8_t)count_1s(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void init_ray_bitboards() {
|
void init_ray_bitboards() {
|
||||||
int d[8] = {1, -1, 16, -16, 17, -17, 15, -15};
|
int d[8] = {1, -1, 16, -16, 17, -17, 15, -15};
|
||||||
for(int i = 0; i < 128; i = i + 9 & ~8) {
|
for(int i = 0; i < 128; i = (i + 9) & ~8) {
|
||||||
for(int j = 0; j < 8; j++) {
|
for(int j = 0; j < 8; j++) {
|
||||||
RayBB[(i&7)|((i>>4)<<3)][j] = EmptyBoardBB;
|
RayBB[(i&7)|((i>>4)<<3)][j] = EmptyBoardBB;
|
||||||
for(int k = i + d[j]; (k & 0x88) == 0; k += d[j])
|
for(int k = i + d[j]; (k & 0x88) == 0; k += d[j])
|
||||||
@@ -534,19 +474,26 @@ namespace {
|
|||||||
for(i = 0; i < 64; i++) {
|
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)
|
||||||
j = (1 << (64 - shift[i]));
|
j = (1 << (64 - shift[i]));
|
||||||
|
#else
|
||||||
|
j = (1 << (32 - shift[i]));
|
||||||
|
#endif
|
||||||
|
|
||||||
for(k = 0; k < j; k++) {
|
for(k = 0; k < j; k++) {
|
||||||
#if defined(USE_32BIT_ATTACKS)
|
|
||||||
|
#if defined(IS_64BIT)
|
||||||
|
b = index_to_bitboard(k, mask[i]);
|
||||||
|
attacks[index + ((b * mult[i]) >> shift[i])] =
|
||||||
|
sliding_attacks(i, b, 4, deltas);
|
||||||
|
#else
|
||||||
b = index_to_bitboard(k, mask[i]);
|
b = index_to_bitboard(k, mask[i]);
|
||||||
attacks[index +
|
attacks[index +
|
||||||
(unsigned(int(b) * int(mult[i]) ^
|
(unsigned(int(b) * int(mult[i]) ^
|
||||||
int(b >> 32) * int(mult[i] >> 32))
|
int(b >> 32) * int(mult[i] >> 32))
|
||||||
>> shift[i])] =
|
>> shift[i])] =
|
||||||
sliding_attacks(i, b, 4, deltas);
|
sliding_attacks(i, b, 4, deltas);
|
||||||
#else
|
|
||||||
b = index_to_bitboard(k, mask[i]);
|
|
||||||
attacks[index + ((b * mult[i]) >> shift[i])] =
|
|
||||||
sliding_attacks(i, b, 4, deltas);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
index += j;
|
index += j;
|
||||||
@@ -563,29 +510,4 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
|
||||||
void init_file_and_rank_attacks() {
|
|
||||||
int i, j, k, l, m, s;
|
|
||||||
Bitboard b1, b2;
|
|
||||||
for(i = 0; i < 64; i++) {
|
|
||||||
|
|
||||||
for(m = 0; m <= 1; m++) {
|
|
||||||
b1 = 0ULL;
|
|
||||||
for(j = 0; j < 6; j++) if(i & (1<<j)) b1 |= (1ULL << ((j+1)*(1+m*7)));
|
|
||||||
for(j = 0; j < 8; j++) {
|
|
||||||
b2 = 0ULL;
|
|
||||||
for(k = 0, s = 1; k < 2; k++, s *= -1) {
|
|
||||||
for(l = j+s; l >= 0 && l <= 7; l += s) {
|
|
||||||
b2 |= (m? RankBB[l] : FileBB[l]);
|
|
||||||
if(b1 & (1ULL << (l*(1+m*7)))) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(m) FileAttacks[j][(b1*0xd6e8802041d0c441ULL) >> 58] = b2;
|
|
||||||
else RankAttacks[j][i] = b2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // defined(USE_COMPACT_ROOK_ATTACKS)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+61
-142
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,43 +22,6 @@
|
|||||||
#if !defined(BITBOARD_H_INCLUDED)
|
#if !defined(BITBOARD_H_INCLUDED)
|
||||||
#define BITBOARD_H_INCLUDED
|
#define BITBOARD_H_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Defines
|
|
||||||
////
|
|
||||||
|
|
||||||
// Comment following define if you prefer manually adjust
|
|
||||||
// platform macros defined below
|
|
||||||
#define AUTO_CONFIGURATION
|
|
||||||
|
|
||||||
// Quiet a warning on Intel compiler
|
|
||||||
#if !defined(__SIZEOF_INT__ )
|
|
||||||
#define __SIZEOF_INT__ 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Check for 64 bits for different compilers: Intel, MSVC and gcc
|
|
||||||
#if defined(__x86_64) || defined(_WIN64) || (__SIZEOF_INT__ > 4)
|
|
||||||
#define IS_64BIT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(AUTO_CONFIGURATION) || defined(IS_64BIT)
|
|
||||||
|
|
||||||
//#define USE_COMPACT_ROOK_ATTACKS
|
|
||||||
//#define USE_32BIT_ATTACKS
|
|
||||||
#define USE_FOLDED_BITSCAN
|
|
||||||
|
|
||||||
#define BITCOUNT_SWAR_64
|
|
||||||
//#define BITCOUNT_SWAR_32
|
|
||||||
//#define BITCOUNT_LOOP
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define USE_32BIT_ATTACKS
|
|
||||||
#define USE_FOLDED_BITSCAN
|
|
||||||
#define BITCOUNT_SWAR_32
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
@@ -69,13 +32,6 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Types
|
|
||||||
////
|
|
||||||
|
|
||||||
typedef uint64_t Bitboard;
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Constants and variables
|
//// Constants and variables
|
||||||
////
|
////
|
||||||
@@ -85,8 +41,6 @@ const Bitboard EmptyBoardBB = 0ULL;
|
|||||||
const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL;
|
const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL;
|
||||||
const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL;
|
const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL;
|
||||||
|
|
||||||
extern const Bitboard SquaresByColorBB[2];
|
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
const Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
const Bitboard FileBBB = 0x0202020202020202ULL;
|
const Bitboard FileBBB = 0x0202020202020202ULL;
|
||||||
const Bitboard FileCBB = 0x0404040404040404ULL;
|
const Bitboard FileCBB = 0x0404040404040404ULL;
|
||||||
@@ -96,10 +50,6 @@ const Bitboard FileFBB = 0x2020202020202020ULL;
|
|||||||
const Bitboard FileGBB = 0x4040404040404040ULL;
|
const Bitboard FileGBB = 0x4040404040404040ULL;
|
||||||
const Bitboard FileHBB = 0x8080808080808080ULL;
|
const Bitboard FileHBB = 0x8080808080808080ULL;
|
||||||
|
|
||||||
extern const Bitboard FileBB[8];
|
|
||||||
extern const Bitboard NeighboringFilesBB[8];
|
|
||||||
extern const Bitboard ThisAndNeighboringFilesBB[8];
|
|
||||||
|
|
||||||
const Bitboard Rank1BB = 0xFFULL;
|
const Bitboard Rank1BB = 0xFFULL;
|
||||||
const Bitboard Rank2BB = 0xFF00ULL;
|
const Bitboard Rank2BB = 0xFF00ULL;
|
||||||
const Bitboard Rank3BB = 0xFF0000ULL;
|
const Bitboard Rank3BB = 0xFF0000ULL;
|
||||||
@@ -109,12 +59,16 @@ const Bitboard Rank6BB = 0xFF0000000000ULL;
|
|||||||
const Bitboard Rank7BB = 0xFF000000000000ULL;
|
const Bitboard Rank7BB = 0xFF000000000000ULL;
|
||||||
const Bitboard Rank8BB = 0xFF00000000000000ULL;
|
const Bitboard Rank8BB = 0xFF00000000000000ULL;
|
||||||
|
|
||||||
|
extern const Bitboard SquaresByColorBB[2];
|
||||||
|
extern const Bitboard FileBB[8];
|
||||||
|
extern const Bitboard NeighboringFilesBB[8];
|
||||||
|
extern const Bitboard ThisAndNeighboringFilesBB[8];
|
||||||
extern const Bitboard RankBB[8];
|
extern const Bitboard RankBB[8];
|
||||||
extern const Bitboard RelativeRankBB[2][8];
|
extern const Bitboard RelativeRankBB[2][8];
|
||||||
extern const Bitboard InFrontBB[2][8];
|
extern const Bitboard InFrontBB[2][8];
|
||||||
|
|
||||||
extern Bitboard SetMaskBB[64];
|
extern Bitboard SetMaskBB[65];
|
||||||
extern Bitboard ClearMaskBB[64];
|
extern Bitboard ClearMaskBB[65];
|
||||||
|
|
||||||
extern Bitboard StepAttackBB[16][64];
|
extern Bitboard StepAttackBB[16][64];
|
||||||
extern Bitboard RayBB[64][8];
|
extern Bitboard RayBB[64][8];
|
||||||
@@ -123,15 +77,11 @@ extern Bitboard BetweenBB[64][64];
|
|||||||
extern Bitboard PassedPawnMask[2][64];
|
extern Bitboard PassedPawnMask[2][64];
|
||||||
extern Bitboard OutpostMask[2][64];
|
extern Bitboard OutpostMask[2][64];
|
||||||
|
|
||||||
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
|
||||||
extern Bitboard RankAttacks[8][64], FileAttacks[8][64];
|
|
||||||
#else
|
|
||||||
extern const uint64_t RMult[64];
|
extern const uint64_t RMult[64];
|
||||||
extern const int RShift[64];
|
extern const int RShift[64];
|
||||||
extern Bitboard RMask[64];
|
extern Bitboard RMask[64];
|
||||||
extern int RAttackIndex[64];
|
extern int RAttackIndex[64];
|
||||||
extern Bitboard RAttacks[0x19000];
|
extern Bitboard RAttacks[0x19000];
|
||||||
#endif // defined(USE_COMPACT_ROOK_ATTACKS)
|
|
||||||
|
|
||||||
extern const uint64_t BMult[64];
|
extern const uint64_t BMult[64];
|
||||||
extern const int BShift[64];
|
extern const int BShift[64];
|
||||||
@@ -143,6 +93,8 @@ extern Bitboard BishopPseudoAttacks[64];
|
|||||||
extern Bitboard RookPseudoAttacks[64];
|
extern Bitboard RookPseudoAttacks[64];
|
||||||
extern Bitboard QueenPseudoAttacks[64];
|
extern Bitboard QueenPseudoAttacks[64];
|
||||||
|
|
||||||
|
extern uint8_t BitCount8Bit[256];
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Inline functions
|
//// Inline functions
|
||||||
@@ -164,6 +116,17 @@ inline void clear_bit(Bitboard *b, Square s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Functions used to update a bitboard after a move. This is faster
|
||||||
|
/// then calling a sequence of clear_bit() + set_bit()
|
||||||
|
|
||||||
|
inline Bitboard make_move_bb(Square from, Square to) {
|
||||||
|
return SetMaskBB[from] | SetMaskBB[to];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void do_move_bb(Bitboard *b, Bitboard move_bb) {
|
||||||
|
*b ^= move_bb;
|
||||||
|
}
|
||||||
|
|
||||||
/// rank_bb() and file_bb() gives a bitboard containing all squares on a given
|
/// rank_bb() and file_bb() gives a bitboard containing all squares on a given
|
||||||
/// file or rank. It is also possible to pass a square as input to these
|
/// file or rank. It is also possible to pass a square as input to these
|
||||||
/// functions.
|
/// functions.
|
||||||
@@ -212,7 +175,7 @@ inline Bitboard this_and_neighboring_files_bb(Square s) {
|
|||||||
|
|
||||||
/// relative_rank_bb() takes a color and a rank as input, and returns a bitboard
|
/// relative_rank_bb() takes a color and a rank as input, and returns a bitboard
|
||||||
/// representing all squares on the given rank from the given color's point of
|
/// representing all squares on the given rank from the given color's point of
|
||||||
/// view. For instance, relative_rank_bb(WHITE, 7) gives all squares on the
|
/// view. For instance, relative_rank_bb(WHITE, 7) gives all squares on the
|
||||||
/// 7th rank, while relative_rank_bb(BLACK, 7) gives all squares on the 2nd
|
/// 7th rank, while relative_rank_bb(BLACK, 7) gives all squares on the 2nd
|
||||||
/// rank.
|
/// rank.
|
||||||
|
|
||||||
@@ -236,6 +199,19 @@ inline Bitboard in_front_bb(Color c, Square s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// behind_bb() takes a color and a rank or square as input, and returns a
|
||||||
|
/// bitboard representing all the squares on all ranks behind of the rank
|
||||||
|
/// (or square), from the given color's point of view.
|
||||||
|
|
||||||
|
inline Bitboard behind_bb(Color c, Rank r) {
|
||||||
|
return InFrontBB[opposite_color(c)][r];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Bitboard behind_bb(Color c, Square s) {
|
||||||
|
return in_front_bb(opposite_color(c), square_rank(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// ray_bb() gives a bitboard representing all squares along the ray in a
|
/// ray_bb() gives a bitboard representing all squares along the ray in a
|
||||||
/// given direction from a given square.
|
/// given direction from a given square.
|
||||||
|
|
||||||
@@ -244,29 +220,24 @@ inline Bitboard ray_bb(Square s, SignedDirection d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Functions for computing sliding attack bitboards. rook_attacks_bb(),
|
/// Functions for computing sliding attack bitboards. rook_attacks_bb(),
|
||||||
/// bishop_attacks_bb() and queen_attacks_bb() all take a square and a
|
/// bishop_attacks_bb() and queen_attacks_bb() all take a square and a
|
||||||
/// bitboard of occupied squares as input, and return a bitboard representing
|
/// bitboard of occupied squares as input, and return a bitboard representing
|
||||||
/// all squares attacked by a rook, bishop or queen on the given square.
|
/// all squares attacked by a rook, bishop or queen on the given square.
|
||||||
|
|
||||||
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
#if defined(IS_64BIT)
|
||||||
|
|
||||||
inline Bitboard file_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
Bitboard b = (blockers >> square_file(s)) & 0x01010101010100ULL;
|
|
||||||
return
|
|
||||||
FileAttacks[square_rank(s)][(b*0xd6e8802041d0c441ULL)>>58] & file_bb(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard rank_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
Bitboard b = (blockers >> ((s & 56) + 1)) & 63;
|
|
||||||
return RankAttacks[square_file(s)][b] & rank_bb(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) {
|
inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) {
|
||||||
return file_attacks_bb(s, blockers) | rank_attacks_bb(s, blockers);
|
Bitboard b = blockers & RMask[s];
|
||||||
|
return RAttacks[RAttackIndex[s] + ((b * RMult[s]) >> RShift[s])];
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(USE_32BIT_ATTACKS)
|
inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) {
|
||||||
|
Bitboard b = blockers & BMask[s];
|
||||||
|
return BAttacks[BAttackIndex[s] + ((b * BMult[s]) >> BShift[s])];
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // if !defined(IS_64BIT)
|
||||||
|
|
||||||
inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) {
|
inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) {
|
||||||
Bitboard b = blockers & RMask[s];
|
Bitboard b = blockers & RMask[s];
|
||||||
@@ -276,17 +247,6 @@ inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) {
|
|||||||
>> RShift[s])];
|
>> RShift[s])];
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
Bitboard b = blockers & RMask[s];
|
|
||||||
return RAttacks[RAttackIndex[s] + ((b * RMult[s]) >> RShift[s])];
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(USE_32BIT_ATTACKS)
|
|
||||||
|
|
||||||
inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) {
|
inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) {
|
||||||
Bitboard b = blockers & BMask[s];
|
Bitboard b = blockers & BMask[s];
|
||||||
return BAttacks[BAttackIndex[s] +
|
return BAttacks[BAttackIndex[s] +
|
||||||
@@ -295,14 +255,7 @@ inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) {
|
|||||||
>> BShift[s])];
|
>> BShift[s])];
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // defined(USE_32BIT_ATTACKS)
|
#endif
|
||||||
|
|
||||||
inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) {
|
|
||||||
Bitboard b = blockers & BMask[s];
|
|
||||||
return BAttacks[BAttackIndex[s] + ((b * BMult[s]) >> BShift[s])];
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // defined(USE_32BIT_ATTACKS)
|
|
||||||
|
|
||||||
inline Bitboard queen_attacks_bb(Square s, Bitboard blockers) {
|
inline Bitboard queen_attacks_bb(Square s, Bitboard blockers) {
|
||||||
return rook_attacks_bb(s, blockers) | bishop_attacks_bb(s, blockers);
|
return rook_attacks_bb(s, blockers) | bishop_attacks_bb(s, blockers);
|
||||||
@@ -364,62 +317,30 @@ inline Bitboard isolated_pawn_mask(Square s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// count_1s() counts the number of nonzero bits in a bitboard.
|
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
|
||||||
|
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
||||||
|
/// nonzero bitboard.
|
||||||
|
|
||||||
#if defined(BITCOUNT_LOOP)
|
#if defined(USE_BSFQ) // Assembly code by Heinz van Saanen
|
||||||
|
|
||||||
inline int count_1s(Bitboard b) {
|
inline Square first_1(Bitboard b) {
|
||||||
int r;
|
Bitboard dummy;
|
||||||
for(r = 0; b; r++, b &= b - 1);
|
__asm__("bsfq %1, %0": "=r"(dummy): "rm"(b) );
|
||||||
return r;
|
return (Square)(dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int count_1s_max_15(Bitboard b) {
|
inline Square pop_1st_bit(Bitboard* b) {
|
||||||
return count_1s(b);
|
const Square s = first_1(*b);
|
||||||
|
*b &= ~(1ULL<<s);
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(BITCOUNT_SWAR_32)
|
#else // if !defined(USE_BSFQ)
|
||||||
|
|
||||||
inline int count_1s(Bitboard b) {
|
extern Square first_1(Bitboard b);
|
||||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
extern Square pop_1st_bit(Bitboard* b);
|
||||||
v = v - ((v >> 1) & 0x55555555);
|
|
||||||
w = w - ((w >> 1) & 0x55555555);
|
|
||||||
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
|
|
||||||
w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
|
|
||||||
v = (v + (v >> 4)) & 0x0F0F0F0F;
|
|
||||||
w = (w + (w >> 4)) & 0x0F0F0F0F;
|
|
||||||
v = ((v+w) * 0x01010101) >> 24; // mul is fast on amd procs
|
|
||||||
return int(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int count_1s_max_15(Bitboard b) {
|
#endif
|
||||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
|
||||||
v = v - ((v >> 1) & 0x55555555);
|
|
||||||
w = w - ((w >> 1) & 0x55555555);
|
|
||||||
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
|
|
||||||
w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
|
|
||||||
v = ((v+w) * 0x11111111) >> 28;
|
|
||||||
return int(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(BITCOUNT_SWAR_64)
|
|
||||||
|
|
||||||
inline int count_1s(Bitboard b) {
|
|
||||||
b -= ((b>>1) & 0x5555555555555555ULL);
|
|
||||||
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
|
||||||
b = ((b>>4) + b) & 0x0F0F0F0F0F0F0F0FULL;
|
|
||||||
b *= 0x0101010101010101ULL;
|
|
||||||
return int(b >> 56);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int count_1s_max_15(Bitboard b) {
|
|
||||||
b -= (b>>1) & 0x5555555555555555ULL;
|
|
||||||
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
|
||||||
b *= 0x1111111111111111ULL;
|
|
||||||
return int(b >> 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BITCOUNT
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -428,8 +349,6 @@ inline int count_1s_max_15(Bitboard b) {
|
|||||||
|
|
||||||
extern void print_bitboard(Bitboard b);
|
extern void print_bitboard(Bitboard b);
|
||||||
extern void init_bitboards();
|
extern void init_bitboards();
|
||||||
extern Square first_1(Bitboard b);
|
|
||||||
extern Square pop_1st_bit(Bitboard *b);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(BITBOARD_H_INCLUDED)
|
#endif // !defined(BITBOARD_H_INCLUDED)
|
||||||
|
|||||||
+161
@@ -0,0 +1,161 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(BITCOUNT_H_INCLUDED)
|
||||||
|
#define BITCOUNT_H_INCLUDED
|
||||||
|
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
// Select type of intrinsic bit count instruction to use
|
||||||
|
|
||||||
|
#if defined(__INTEL_COMPILER) && defined(IS_64BIT) && defined(USE_POPCNT) // Intel compiler
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#endif // cpu_has_popcnt() and POPCNT_INTRINSIC() definitions
|
||||||
|
|
||||||
|
|
||||||
|
/// Software implementation of bit count functions
|
||||||
|
|
||||||
|
#if defined(IS_64BIT)
|
||||||
|
|
||||||
|
inline int count_1s(Bitboard b) {
|
||||||
|
b -= ((b>>1) & 0x5555555555555555ULL);
|
||||||
|
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
||||||
|
b = ((b>>4) + b) & 0x0F0F0F0F0F0F0F0FULL;
|
||||||
|
b *= 0x0101010101010101ULL;
|
||||||
|
return int(b >> 56);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int count_1s_max_15(Bitboard b) {
|
||||||
|
b -= (b>>1) & 0x5555555555555555ULL;
|
||||||
|
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
||||||
|
b *= 0x1111111111111111ULL;
|
||||||
|
return int(b >> 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // if !defined(IS_64BIT)
|
||||||
|
|
||||||
|
inline int count_1s(Bitboard b) {
|
||||||
|
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
||||||
|
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
||||||
|
w -= (w >> 1) & 0x55555555;
|
||||||
|
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
||||||
|
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
||||||
|
v = ((v >> 4) + v) & 0x0F0F0F0F; // 0-8 in 8 bits
|
||||||
|
v += (((w >> 4) + w) & 0x0F0F0F0F); // 0-16 in 8 bits
|
||||||
|
v *= 0x01010101; // mul is fast on amd procs
|
||||||
|
return int(v >> 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int count_1s_max_15(Bitboard b) {
|
||||||
|
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
||||||
|
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
||||||
|
w -= (w >> 1) & 0x55555555;
|
||||||
|
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
||||||
|
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
||||||
|
v += w; // 0-8 in 4 bits
|
||||||
|
v *= 0x11111111;
|
||||||
|
return int(v >> 28);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BITCOUNT
|
||||||
|
|
||||||
|
|
||||||
|
/// count_1s() counts the number of nonzero bits in a bitboard.
|
||||||
|
/// If template parameter is true an intrinsic is called, otherwise
|
||||||
|
/// we fallback on a software implementation.
|
||||||
|
|
||||||
|
template<bool UseIntrinsic>
|
||||||
|
inline int count_1s(Bitboard b) {
|
||||||
|
|
||||||
|
return UseIntrinsic ? POPCNT_INTRINSIC(b) : count_1s(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<bool UseIntrinsic>
|
||||||
|
inline int count_1s_max_15(Bitboard b) {
|
||||||
|
|
||||||
|
return UseIntrinsic ? POPCNT_INTRINSIC(b) : count_1s_max_15(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Global constant initialized at startup that is set to true if
|
||||||
|
// CPU on which application runs supports POPCNT intrinsic. Unless
|
||||||
|
// USE_POPCNT is not defined.
|
||||||
|
const bool CpuHasPOPCNT = cpu_has_popcnt();
|
||||||
|
|
||||||
|
|
||||||
|
// Global constant used to print info about the use of 64 optimized
|
||||||
|
// functions to verify that a 64 bit compile has been correctly built.
|
||||||
|
#if defined(IS_64BIT)
|
||||||
|
const bool CpuHas64BitPath = true;
|
||||||
|
#else
|
||||||
|
const bool CpuHas64BitPath = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // !defined(BITCOUNT_H_INCLUDED)
|
||||||
+156
-165
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
#include "mersenne.h"
|
#include "mersenne.h"
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Global variables
|
//// Global variables
|
||||||
@@ -49,7 +50,11 @@ Book OpeningBook;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Random numbers from PolyGlot, used to compute book hash keys.
|
/// Book entry size in bytes
|
||||||
|
const int EntrySize = 16;
|
||||||
|
|
||||||
|
|
||||||
|
/// Random numbers from PolyGlot, used to compute book hash keys
|
||||||
|
|
||||||
const uint64_t Random64[781] = {
|
const uint64_t Random64[781] = {
|
||||||
0x9D39247E33776D41ULL, 0x2AF7398005AAA5C7ULL, 0x44DB015024623547ULL,
|
0x9D39247E33776D41ULL, 0x2AF7398005AAA5C7ULL, 0x44DB015024623547ULL,
|
||||||
@@ -317,31 +322,20 @@ namespace {
|
|||||||
|
|
||||||
|
|
||||||
/// Indices to the Random64[] array
|
/// Indices to the Random64[] array
|
||||||
|
|
||||||
const int RandomPiece = 0;
|
|
||||||
const int RandomCastle = 768;
|
|
||||||
const int RandomEnPassant = 772;
|
|
||||||
const int RandomTurn = 780;
|
|
||||||
|
|
||||||
|
const int RandomPiece = 0;
|
||||||
/// Convert pieces to the range 0..1
|
const int RandomCastle = 768;
|
||||||
|
const int RandomEnPassant = 772;
|
||||||
const int PieceTo12[] = {
|
const int RandomTurn = 780;
|
||||||
0, 0, 2, 4, 6, 8, 10, 0, 0, 1, 3, 5, 7, 9, 11
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Prototypes
|
/// Prototypes
|
||||||
|
|
||||||
uint64_t book_key(const Position &pos);
|
|
||||||
uint64_t book_piece_key(Piece p, Square s);
|
|
||||||
uint64_t book_castle_key(const Position &pos);
|
|
||||||
uint64_t book_ep_key(const Position &pos);
|
|
||||||
uint64_t book_color_key(const Position &pos);
|
|
||||||
|
|
||||||
uint16_t read_integer16(std::ifstream& file);
|
uint64_t book_key(const Position& pos);
|
||||||
uint64_t read_integer64(std::ifstream& file);
|
uint64_t book_piece_key(Piece p, Square s);
|
||||||
uint64_t read_integer(std::ifstream& file, int size);
|
uint64_t book_castle_key(const Position& pos);
|
||||||
|
uint64_t book_ep_key(const Position& pos);
|
||||||
|
uint64_t book_color_key(const Position& pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -350,99 +344,108 @@ namespace {
|
|||||||
////
|
////
|
||||||
|
|
||||||
|
|
||||||
/// Constructor
|
/// Destructor. Be sure file is closed before we leave.
|
||||||
|
|
||||||
Book::Book() : bookSize(0) {}
|
Book::~Book() {
|
||||||
|
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Book::open() opens a book file with a given file name.
|
/// Book::open() opens a book file with a given file name
|
||||||
|
|
||||||
void Book::open(const std::string &fName) {
|
void Book::open(const string& fName) {
|
||||||
|
|
||||||
|
// Close old file before opening the new
|
||||||
|
close();
|
||||||
|
|
||||||
fileName = fName;
|
fileName = fName;
|
||||||
bookFile.open(fileName.c_str(), std::ifstream::in | std::ifstream::binary);
|
ifstream::open(fileName.c_str(), ifstream::in | ifstream::binary);
|
||||||
if (!bookFile.is_open())
|
if (!is_open())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bookFile.seekg(0, std::ios::end);
|
// Get the book size in number of entries
|
||||||
bookSize = bookFile.tellg() / 16;
|
seekg(0, ios::end);
|
||||||
bookFile.seekg(0, std::ios::beg);
|
bookSize = tellg() / EntrySize;
|
||||||
|
seekg(0, ios::beg);
|
||||||
|
|
||||||
if (!bookFile.good())
|
if (!good())
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open book file " << fileName << std::endl;
|
cerr << "Failed to open book file " << fileName << endl;
|
||||||
exit(EXIT_FAILURE);
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Book::close() closes the currently open book file.
|
/// Book::close() closes the file only if it is open, otherwise
|
||||||
|
/// we can end up in a little mess due to how std::ifstream works.
|
||||||
|
|
||||||
void Book::close() {
|
void Book::close() {
|
||||||
|
|
||||||
if (bookFile.is_open())
|
if (is_open())
|
||||||
bookFile.close();
|
ifstream::close();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Book::is_open() tests whether a book file has been opened.
|
|
||||||
|
|
||||||
bool Book::is_open() const {
|
|
||||||
|
|
||||||
return bookFile.is_open() && bookSize != 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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 std::string Book::file_name() const {
|
const string Book::file_name() const {
|
||||||
|
|
||||||
return bookFile.is_open() ? fileName : "";
|
return is_open() ? fileName : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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) const {
|
Move Book::get_move(const Position& pos) {
|
||||||
if(this->is_open()) {
|
|
||||||
int bestMove = 0, bestScore = 0, move, score;
|
if (!is_open() || bookSize == 0)
|
||||||
uint64_t key = book_key(pos);
|
return MOVE_NONE;
|
||||||
BookEntry entry;
|
|
||||||
|
int bookMove = 0, scoresSum = 0;
|
||||||
|
uint64_t key = book_key(pos);
|
||||||
|
BookEntry entry;
|
||||||
|
|
||||||
|
// Choose a book move among the possible moves for the given position
|
||||||
|
for (int idx = find_key(key); idx < bookSize; idx++)
|
||||||
|
{
|
||||||
|
read_entry(entry, idx);
|
||||||
|
if (entry.key != key)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int score = entry.count;
|
||||||
|
|
||||||
for(int i = this->find_key(key); i < bookSize; i++) {
|
|
||||||
this->read_entry(entry, i);
|
|
||||||
if(entry.key != key)
|
|
||||||
break;
|
|
||||||
move = entry.move;
|
|
||||||
score = entry.count;
|
|
||||||
assert(score > 0);
|
assert(score > 0);
|
||||||
|
|
||||||
bestScore += score;
|
// Choose book move according to its score. If a move has a very
|
||||||
if(int(genrand_int32() % bestScore) < score)
|
// high score it has more probability to be choosen then a one with
|
||||||
bestMove = move;
|
// lower score. Note that first entry is always chosen.
|
||||||
}
|
scoresSum += score;
|
||||||
|
if (int(genrand_int32() % scoresSum) < score)
|
||||||
if(bestMove != 0) {
|
bookMove = entry.move;
|
||||||
MoveStack moves[256];
|
|
||||||
int n, j;
|
|
||||||
n = generate_legal_moves(pos, moves);
|
|
||||||
for(j = 0; j < n; j++)
|
|
||||||
if((int(moves[j].move) & 07777) == bestMove)
|
|
||||||
return moves[j].move;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (!bookMove)
|
||||||
|
return MOVE_NONE;
|
||||||
|
|
||||||
|
MoveStack mlist[256];
|
||||||
|
MoveStack* last = generate_moves(pos, mlist);
|
||||||
|
for (MoveStack* cur = mlist; cur != last; cur++)
|
||||||
|
if ((int(cur->move) & 07777) == bookMove)
|
||||||
|
return cur->move;
|
||||||
|
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Book::find_key() takes a book key as input, and does a binary search
|
/// Book::find_key() takes a book key as input, and does a binary search
|
||||||
/// through the book file for the given key. The index to the first book
|
/// through the book file for the given key. The index to the first book
|
||||||
/// entry with the same key as the input is returned. When the key is not
|
/// entry with the same key as the input is returned. When the key is not
|
||||||
/// found in the book file, bookSize is returned.
|
/// found in the book file, bookSize is returned.
|
||||||
|
|
||||||
int Book::find_key(uint64_t key) const {
|
int Book::find_key(uint64_t key) {
|
||||||
|
|
||||||
int left, right, mid;
|
int left, right, mid;
|
||||||
BookEntry entry;
|
BookEntry entry;
|
||||||
|
|
||||||
@@ -452,46 +455,59 @@ int Book::find_key(uint64_t key) const {
|
|||||||
|
|
||||||
assert(left <= right);
|
assert(left <= right);
|
||||||
|
|
||||||
while(left < right) {
|
while (left < right)
|
||||||
mid = (left + right) / 2;
|
{
|
||||||
assert(mid >= left && mid < right);
|
mid = (left + right) / 2;
|
||||||
|
|
||||||
this->read_entry(entry, mid);
|
assert(mid >= left && mid < right);
|
||||||
|
|
||||||
if(key <= entry.key)
|
read_entry(entry, mid);
|
||||||
right = mid;
|
if (key <= entry.key)
|
||||||
else
|
right = mid;
|
||||||
left = mid + 1;
|
else
|
||||||
|
left = mid + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(left == right);
|
assert(left == right);
|
||||||
|
|
||||||
this->read_entry(entry, left);
|
read_entry(entry, left);
|
||||||
|
|
||||||
return (entry.key == key)? left : bookSize;
|
return (entry.key == key)? left : bookSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Book::read_entry() takes a BookEntry reference and an integer index as
|
/// Book::read_entry() takes a BookEntry reference and an integer index as
|
||||||
/// input, and looks up the opening book entry at the given index in the book
|
/// input, and looks up the opening book entry at the given index in the book
|
||||||
/// file. The book entry is copied to the first input parameter.
|
/// file. The book entry is copied to the first input parameter.
|
||||||
|
|
||||||
void Book::read_entry(BookEntry& entry, int n) const {
|
void Book::read_entry(BookEntry& entry, int idx) {
|
||||||
|
|
||||||
assert(n >= 0 && n < bookSize);
|
assert(idx >= 0 && idx < bookSize);
|
||||||
assert(bookFile.is_open());
|
assert(is_open());
|
||||||
|
|
||||||
bookFile.seekg(n*16, std::ios_base::beg);
|
seekg(idx * EntrySize, ios_base::beg);
|
||||||
if (!bookFile.good())
|
*this >> entry;
|
||||||
|
if (!good())
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to read book entry at index " << n << std::endl;
|
cerr << "Failed to read book entry at index " << idx << endl;
|
||||||
exit(EXIT_FAILURE);
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
entry.key = read_integer64(bookFile);
|
}
|
||||||
entry.move = read_integer16(bookFile);
|
|
||||||
entry.count = read_integer16(bookFile);
|
|
||||||
entry.n = read_integer16(bookFile);
|
/// Book::read_integer() reads size chars from the file stream
|
||||||
entry.sum = read_integer16(bookFile);
|
/// and converts them in an integer number.
|
||||||
|
|
||||||
|
uint64_t Book::read_integer(int size) {
|
||||||
|
|
||||||
|
char buf[8];
|
||||||
|
read(buf, size);
|
||||||
|
|
||||||
|
// Numbers are stored on disk as a binary byte stream
|
||||||
|
uint64_t n = 0ULL;
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
n = (n << 8) + (unsigned char)buf[i];
|
||||||
|
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -501,92 +517,67 @@ void Book::read_entry(BookEntry& entry, int n) const {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
uint64_t book_key(const Position &pos) {
|
uint64_t book_key(const Position& pos) {
|
||||||
|
|
||||||
uint64_t result = 0ULL;
|
uint64_t result = 0ULL;
|
||||||
|
|
||||||
for(Color c = WHITE; c <= BLACK; c++) {
|
for (Color c = WHITE; c <= BLACK; c++)
|
||||||
Bitboard b = pos.pieces_of_color(c);
|
{
|
||||||
Square s;
|
Bitboard b = pos.pieces_of_color(c);
|
||||||
Piece p;
|
|
||||||
while(b != EmptyBoardBB) {
|
|
||||||
s = pop_1st_bit(&b);
|
|
||||||
p = pos.piece_on(s);
|
|
||||||
assert(piece_is_ok(p));
|
|
||||||
assert(color_of_piece(p) == c);
|
|
||||||
|
|
||||||
result ^= book_piece_key(p, s);
|
while (b)
|
||||||
}
|
{
|
||||||
|
Square s = pop_1st_bit(&b);
|
||||||
|
Piece p = pos.piece_on(s);
|
||||||
|
|
||||||
|
assert(piece_is_ok(p));
|
||||||
|
assert(color_of_piece(p) == c);
|
||||||
|
|
||||||
|
result ^= book_piece_key(p, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result ^= book_castle_key(pos);
|
result ^= book_castle_key(pos);
|
||||||
result ^= book_ep_key(pos);
|
result ^= book_ep_key(pos);
|
||||||
result ^= book_color_key(pos);
|
result ^= book_color_key(pos);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t book_piece_key(Piece p, Square s) {
|
uint64_t book_piece_key(Piece p, Square s) {
|
||||||
return Random64[RandomPiece + (PieceTo12[int(p)]^1)*64 + int(s)];
|
|
||||||
|
/// Convert pieces to the range 0..11
|
||||||
|
static const int PieceTo12[] = { 0, 0, 2, 4, 6, 8, 10, 0, 0, 1, 3, 5, 7, 9, 11 };
|
||||||
|
|
||||||
|
return Random64[RandomPiece + (PieceTo12[int(p)]^1) * 64 + int(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t book_castle_key(const Position &pos) {
|
uint64_t book_castle_key(const Position& pos) {
|
||||||
|
|
||||||
uint64_t result = 0ULL;
|
uint64_t result = 0ULL;
|
||||||
|
|
||||||
if(pos.can_castle_kingside(WHITE))
|
if (pos.can_castle_kingside(WHITE))
|
||||||
result ^= Random64[RandomCastle+0];
|
result ^= Random64[RandomCastle+0];
|
||||||
if(pos.can_castle_queenside(WHITE))
|
|
||||||
result ^= Random64[RandomCastle+1];
|
if (pos.can_castle_queenside(WHITE))
|
||||||
if(pos.can_castle_kingside(BLACK))
|
result ^= Random64[RandomCastle+1];
|
||||||
result ^= Random64[RandomCastle+2];
|
|
||||||
if(pos.can_castle_queenside(BLACK))
|
if (pos.can_castle_kingside(BLACK))
|
||||||
result ^= Random64[RandomCastle+3];
|
result ^= Random64[RandomCastle+2];
|
||||||
|
|
||||||
|
if (pos.can_castle_queenside(BLACK))
|
||||||
|
result ^= Random64[RandomCastle+3];
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t book_ep_key(const Position &pos) {
|
|
||||||
return (pos.ep_square() == SQ_NONE)?
|
|
||||||
0ULL : Random64[RandomEnPassant + square_file(pos.ep_square())];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
uint64_t book_ep_key(const Position& pos) {
|
||||||
uint64_t book_color_key(const Position &pos) {
|
return (pos.ep_square() == SQ_NONE ? 0ULL : Random64[RandomEnPassant + square_file(pos.ep_square())]);
|
||||||
return (pos.side_to_move() == WHITE)? Random64[RandomTurn] : 0ULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t read_integer16(std::ifstream& file) {
|
|
||||||
|
|
||||||
uint64_t n = read_integer(file, 2);
|
|
||||||
assert(n == (uint16_t)n);
|
|
||||||
return (uint16_t)n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t read_integer64(std::ifstream& file) {
|
uint64_t book_color_key(const Position& pos) {
|
||||||
|
return (pos.side_to_move() == WHITE ? Random64[RandomTurn] : 0ULL);
|
||||||
return read_integer(file, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t read_integer(std::ifstream& file, int size) {
|
|
||||||
|
|
||||||
char buf[8];
|
|
||||||
file.read(buf, size);
|
|
||||||
|
|
||||||
if (!file.good())
|
|
||||||
{
|
|
||||||
std::cerr << "Failed to read " << size << " bytes from book file"
|
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
// Numbers are stored in little endian format
|
|
||||||
uint64_t n = 0ULL;
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
n = (n << 8) + (unsigned char)buf[i];
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-21
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -52,31 +52,24 @@ struct BookEntry {
|
|||||||
uint16_t sum;
|
uint16_t sum;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Book {
|
class Book : private std::ifstream {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructors
|
~Book();
|
||||||
Book();
|
void open(const std::string& fName);
|
||||||
|
|
||||||
// Open and close book files
|
|
||||||
void open(const std::string &fName);
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
// Testing if a book is opened
|
|
||||||
bool is_open() const;
|
|
||||||
|
|
||||||
// The file name of the currently active book
|
|
||||||
const std::string file_name() const;
|
const std::string file_name() const;
|
||||||
|
Move get_move(const Position& pos);
|
||||||
// Get a book move for a given position
|
|
||||||
Move get_move(const Position &pos) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int find_key(uint64_t key) const;
|
Book& operator>>(uint64_t& n) { n = read_integer(8); return *this; }
|
||||||
void read_entry(BookEntry &entry, int n) const;
|
Book& operator>>(uint16_t& n) { n = (uint16_t)read_integer(2); return *this; }
|
||||||
|
void operator>>(BookEntry& e) { *this >> e.key >> e.move >> e.count >> e.n >> e.sum; }
|
||||||
|
|
||||||
|
uint64_t read_integer(int size);
|
||||||
|
void read_entry(BookEntry& e, int n);
|
||||||
|
int find_key(uint64_t key);
|
||||||
|
|
||||||
std::string fileName;
|
std::string fileName;
|
||||||
mutable std::ifstream bookFile;
|
|
||||||
int bookSize;
|
int bookSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008 Marco Costalba
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Includes
|
|
||||||
////
|
|
||||||
|
|
||||||
#include "color.h"
|
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Functions
|
|
||||||
////
|
|
||||||
|
|
||||||
/// color_is_ok(), for debugging:
|
|
||||||
|
|
||||||
bool color_is_ok(Color c) {
|
|
||||||
return c == WHITE || c == BLACK;
|
|
||||||
}
|
|
||||||
+9
-20
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -21,20 +21,14 @@
|
|||||||
#if !defined(COLOR_H_INCLUDED)
|
#if !defined(COLOR_H_INCLUDED)
|
||||||
#define COLOR_H_INCLUDED
|
#define COLOR_H_INCLUDED
|
||||||
|
|
||||||
////
|
|
||||||
//// Includes
|
|
||||||
////
|
|
||||||
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
enum Color {
|
enum Color {
|
||||||
WHITE,
|
WHITE,
|
||||||
BLACK,
|
BLACK,
|
||||||
COLOR_NONE
|
COLOR_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,19 +37,14 @@ enum Color {
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
inline Color operator+ (Color c, int i) { return Color(int(c) + i); }
|
inline void operator++ (Color &c, int) { c = Color(int(c) + 1); }
|
||||||
inline void operator++ (Color &c, int i) { c = Color(int(c) + 1); }
|
|
||||||
|
|
||||||
inline Color opposite_color(Color c) {
|
inline Color opposite_color(Color c) {
|
||||||
return Color(int(c) ^ 1);
|
return Color(int(c) ^ 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool color_is_ok(Color c) {
|
||||||
////
|
return c == WHITE || c == BLACK;
|
||||||
//// Prototypes
|
}
|
||||||
////
|
|
||||||
|
|
||||||
extern bool color_is_ok(Color c);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(COLOR_H_INCLUDED)
|
#endif // !defined(COLOR_H_INCLUDED)
|
||||||
|
|||||||
+3
-6
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -35,9 +35,6 @@ enum Depth {
|
|||||||
//// Constants
|
//// Constants
|
||||||
////
|
////
|
||||||
|
|
||||||
/// Note: If OnePly is changed, the constant HistoryMax in history.h should
|
|
||||||
/// probably also be changed.
|
|
||||||
|
|
||||||
const Depth OnePly = Depth(2);
|
const Depth OnePly = Depth(2);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+47
-23
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -26,6 +26,32 @@
|
|||||||
#include "square.h"
|
#include "square.h"
|
||||||
|
|
||||||
|
|
||||||
|
////
|
||||||
|
//// Local definitions
|
||||||
|
////
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const SquareDelta directionToDelta[] = {
|
||||||
|
DELTA_E, DELTA_W, DELTA_N, DELTA_S, DELTA_NE, DELTA_SW, DELTA_NW, DELTA_SE
|
||||||
|
};
|
||||||
|
|
||||||
|
bool reachable(Square orig, Square dest, SignedDirection dir) {
|
||||||
|
|
||||||
|
SquareDelta delta = directionToDelta[dir];
|
||||||
|
Square from = orig;
|
||||||
|
Square to = from + delta;
|
||||||
|
while (to != dest && square_distance(to, from) == 1 && square_is_ok(to))
|
||||||
|
{
|
||||||
|
from = to;
|
||||||
|
to += delta;
|
||||||
|
}
|
||||||
|
return (to == dest && square_distance(from, to) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Variables
|
//// Variables
|
||||||
////
|
////
|
||||||
@@ -39,25 +65,23 @@ uint8_t SignedDirectionTable[64][64];
|
|||||||
////
|
////
|
||||||
|
|
||||||
void init_direction_table() {
|
void init_direction_table() {
|
||||||
SquareDelta deltas[8] = {
|
|
||||||
DELTA_E, DELTA_W, DELTA_N, DELTA_S, DELTA_NE, DELTA_SW, DELTA_NW, DELTA_SE
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
|
||||||
};
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; s2++)
|
||||||
for(Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
|
{
|
||||||
for(Square s2 = SQ_A1; s2 <= SQ_H8; s2++) {
|
DirectionTable[s1][s2] = uint8_t(DIR_NONE);
|
||||||
DirectionTable[s1][s2] = uint8_t(DIR_NONE);
|
SignedDirectionTable[s1][s2] = uint8_t(SIGNED_DIR_NONE);
|
||||||
SignedDirectionTable[s1][s2] = uint8_t(SIGNED_DIR_NONE);
|
if (s1 == s2)
|
||||||
if(s1 == s2) continue;
|
continue;
|
||||||
for(SignedDirection d = SIGNED_DIR_E; d <= SIGNED_DIR_SE; d++) {
|
|
||||||
SquareDelta delta = deltas[d];
|
for (SignedDirection d = SIGNED_DIR_E; d != SIGNED_DIR_NONE; d++)
|
||||||
Square s3, s4;
|
{
|
||||||
for(s4 = s1 + delta, s3 = s1;
|
if (reachable(s1, s2, d))
|
||||||
square_distance(s4, s3) == 1 && s4 != s2 && square_is_ok(s4);
|
{
|
||||||
s3 = s4, s4 += delta);
|
SignedDirectionTable[s1][s2] = uint8_t(d);
|
||||||
if(s4 == s2 && square_distance(s4, s3) == 1) {
|
DirectionTable[s1][s2] = uint8_t(d / 2);
|
||||||
SignedDirectionTable[s1][s2] = uint8_t(d);
|
break;
|
||||||
DirectionTable[s1][s2] = uint8_t(d/2);
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-7
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -38,8 +38,8 @@ enum Direction {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum SignedDirection {
|
enum SignedDirection {
|
||||||
SIGNED_DIR_E = 0, SIGNED_DIR_W = 1,
|
SIGNED_DIR_E = 0, SIGNED_DIR_W = 1,
|
||||||
SIGNED_DIR_N = 2, SIGNED_DIR_S = 3,
|
SIGNED_DIR_N = 2, SIGNED_DIR_S = 3,
|
||||||
SIGNED_DIR_NE = 4, SIGNED_DIR_SW = 5,
|
SIGNED_DIR_NE = 4, SIGNED_DIR_SW = 5,
|
||||||
SIGNED_DIR_NW = 6, SIGNED_DIR_SE = 7,
|
SIGNED_DIR_NW = 6, SIGNED_DIR_SE = 7,
|
||||||
SIGNED_DIR_NONE = 8
|
SIGNED_DIR_NONE = 8
|
||||||
@@ -58,9 +58,11 @@ extern uint8_t SignedDirectionTable[64][64];
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
inline void operator++ (Direction &d, int) { d = Direction(int(d) + 1); }
|
inline void operator++ (Direction& d, int) {
|
||||||
|
d = Direction(int(d) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator++ (SignedDirection &d, int) {
|
inline void operator++ (SignedDirection& d, int) {
|
||||||
d = SignedDirection(int(d) + 1);
|
d = SignedDirection(int(d) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +74,13 @@ inline SignedDirection signed_direction_between_squares(Square s1, Square s2) {
|
|||||||
return SignedDirection(SignedDirectionTable[s1][s2]);
|
return SignedDirection(SignedDirectionTable[s1][s2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int direction_is_diagonal(Square s1, Square s2) {
|
||||||
|
return DirectionTable[s1][s2] & 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool direction_is_straight(Square s1, Square s2) {
|
||||||
|
return DirectionTable[s1][s2] < 2;
|
||||||
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Prototypes
|
//// Prototypes
|
||||||
|
|||||||
+472
-428
File diff suppressed because it is too large
Load Diff
+51
-188
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -34,204 +34,67 @@
|
|||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
/// Abstract base class for all special endgame evaluation functions:
|
enum EndgameType {
|
||||||
|
|
||||||
class EndgameEvaluationFunction {
|
// Evaluation functions
|
||||||
|
KXK, // Generic "mate lone king" eval
|
||||||
|
KBNK, // KBN vs K
|
||||||
|
KPK, // KP vs K
|
||||||
|
KRKP, // KR vs KP
|
||||||
|
KRKB, // KR vs KB
|
||||||
|
KRKN, // KR vs KN
|
||||||
|
KQKR, // KQ vs KR
|
||||||
|
KBBKN, // KBB vs KN
|
||||||
|
KNNK, // KNN vs K
|
||||||
|
KmmKm, // K and two minors vs K and one or two minors
|
||||||
|
|
||||||
|
// Scaling functions
|
||||||
|
KBPsK, // KB+pawns vs K
|
||||||
|
KQKRPs, // KQ vs KR+pawns
|
||||||
|
KRPKR, // KRP vs KR
|
||||||
|
KRPPKRP, // KRPP vs KRP
|
||||||
|
KPsK, // King and pawns vs king
|
||||||
|
KBPKB, // KBP vs KB
|
||||||
|
KBPPKB, // KBPP vs KB
|
||||||
|
KBPKN, // KBP vs KN
|
||||||
|
KNPK, // KNP vs K
|
||||||
|
KPKP // KP vs KP
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Template abstract base class for all special endgame functions
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class EndgameFunctionBase {
|
||||||
public:
|
public:
|
||||||
EndgameEvaluationFunction(Color c);
|
EndgameFunctionBase(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
|
||||||
virtual ~EndgameEvaluationFunction() { }
|
virtual ~EndgameFunctionBase() {}
|
||||||
|
virtual T apply(const Position&) = 0;
|
||||||
virtual Value apply(const Position &pos) =0;
|
Color color() const { return strongerSide; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Color strongerSide, weakerSide;
|
Color strongerSide, weakerSide;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef EndgameFunctionBase<Value> EndgameEvaluationFunctionBase;
|
||||||
|
typedef EndgameFunctionBase<ScaleFactor> EndgameScalingFunctionBase;
|
||||||
|
|
||||||
/// Subclasses for various concrete endgames:
|
|
||||||
|
|
||||||
// Generic "mate lone king" eval:
|
/// Templates subclass for various concrete endgames
|
||||||
class KXKEvaluationFunction : public EndgameEvaluationFunction {
|
|
||||||
public:
|
template<EndgameType>
|
||||||
KXKEvaluationFunction(Color c);
|
struct EvaluationFunction : public EndgameEvaluationFunctionBase {
|
||||||
Value apply(const Position &pos);
|
typedef EndgameEvaluationFunctionBase Base;
|
||||||
|
explicit EvaluationFunction(Color c): EndgameEvaluationFunctionBase(c) {}
|
||||||
|
Value apply(const Position&);
|
||||||
};
|
};
|
||||||
|
|
||||||
// KBN vs K:
|
template<EndgameType>
|
||||||
class KBNKEvaluationFunction : public EndgameEvaluationFunction {
|
struct ScalingFunction : public EndgameScalingFunctionBase {
|
||||||
public:
|
typedef EndgameScalingFunctionBase Base;
|
||||||
KBNKEvaluationFunction(Color c);
|
explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
|
||||||
Value apply(const Position &pos);
|
ScaleFactor apply(const Position&);
|
||||||
};
|
};
|
||||||
|
|
||||||
// KP vs K:
|
|
||||||
class KPKEvaluationFunction : public EndgameEvaluationFunction {
|
|
||||||
public:
|
|
||||||
KPKEvaluationFunction(Color c);
|
|
||||||
Value apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KR vs KP:
|
|
||||||
class KRKPEvaluationFunction : public EndgameEvaluationFunction {
|
|
||||||
public:
|
|
||||||
KRKPEvaluationFunction(Color c);
|
|
||||||
Value apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KR vs KB:
|
|
||||||
class KRKBEvaluationFunction : public EndgameEvaluationFunction {
|
|
||||||
public:
|
|
||||||
KRKBEvaluationFunction(Color c);
|
|
||||||
Value apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KR vs KN:
|
|
||||||
class KRKNEvaluationFunction : public EndgameEvaluationFunction {
|
|
||||||
public:
|
|
||||||
KRKNEvaluationFunction(Color c);
|
|
||||||
Value apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KQ vs KR:
|
|
||||||
class KQKREvaluationFunction : public EndgameEvaluationFunction {
|
|
||||||
public:
|
|
||||||
KQKREvaluationFunction(Color c);
|
|
||||||
Value apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Abstract base class for all evaluation scaling functions:
|
|
||||||
|
|
||||||
class ScalingFunction {
|
|
||||||
public:
|
|
||||||
ScalingFunction(Color c);
|
|
||||||
virtual ~ScalingFunction() { }
|
|
||||||
|
|
||||||
virtual ScaleFactor apply(const Position &pos) =0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Color strongerSide, weakerSide;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Subclasses for various concrete endgames:
|
|
||||||
|
|
||||||
// KBP vs K:
|
|
||||||
class KBPKScalingFunction : public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KBPKScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KQ vs KRP:
|
|
||||||
class KQKRPScalingFunction: public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KQKRPScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KRP vs KR:
|
|
||||||
class KRPKRScalingFunction : public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KRPKRScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KRPP vs KRP:
|
|
||||||
class KRPPKRPScalingFunction : public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KRPPKRPScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// King and pawns vs king:
|
|
||||||
class KPsKScalingFunction : public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KPsKScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KBP vs KB:
|
|
||||||
class KBPKBScalingFunction : public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KBPKBScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KBP vs KN:
|
|
||||||
class KBPKNScalingFunction : public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KBPKNScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KNP vs K:
|
|
||||||
class KNPKScalingFunction : public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KNPKScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// KP vs KP:
|
|
||||||
class KPKPScalingFunction : public ScalingFunction {
|
|
||||||
public:
|
|
||||||
KPKPScalingFunction(Color c);
|
|
||||||
ScaleFactor apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Constants and variables
|
|
||||||
////
|
|
||||||
|
|
||||||
// Generic "mate lone king" eval:
|
|
||||||
extern KXKEvaluationFunction EvaluateKXK, EvaluateKKX;
|
|
||||||
|
|
||||||
// KBN vs K:
|
|
||||||
extern KBNKEvaluationFunction EvaluateKBNK, EvaluateKKBN;
|
|
||||||
|
|
||||||
// KP vs K:
|
|
||||||
extern KPKEvaluationFunction EvaluateKPK, EvaluateKKP;
|
|
||||||
|
|
||||||
// KR vs KP:
|
|
||||||
extern KRKPEvaluationFunction EvaluateKRKP, EvaluateKPKR;
|
|
||||||
|
|
||||||
// KR vs KB:
|
|
||||||
extern KRKBEvaluationFunction EvaluateKRKB, EvaluateKBKR;
|
|
||||||
|
|
||||||
// KR vs KN:
|
|
||||||
extern KRKNEvaluationFunction EvaluateKRKN, EvaluateKNKR;
|
|
||||||
|
|
||||||
// KQ vs KR:
|
|
||||||
extern KQKREvaluationFunction EvaluateKQKR, EvaluateKRKQ;
|
|
||||||
|
|
||||||
// KBP vs K:
|
|
||||||
extern KBPKScalingFunction ScaleKBPK, ScaleKKBP;
|
|
||||||
|
|
||||||
// KQ vs KRP:
|
|
||||||
extern KQKRPScalingFunction ScaleKQKRP, ScaleKRPKQ;
|
|
||||||
|
|
||||||
// KRP vs KR:
|
|
||||||
extern KRPKRScalingFunction ScaleKRPKR, ScaleKRKRP;
|
|
||||||
|
|
||||||
// KRPP vs KRP:
|
|
||||||
extern KRPPKRPScalingFunction ScaleKRPPKRP, ScaleKRPKRPP;
|
|
||||||
|
|
||||||
// King and pawns vs king:
|
|
||||||
extern KPsKScalingFunction ScaleKPsK, ScaleKKPs;
|
|
||||||
|
|
||||||
// KBP vs KB:
|
|
||||||
extern KBPKBScalingFunction ScaleKBPKB, ScaleKBKBP;
|
|
||||||
|
|
||||||
// KBP vs KN:
|
|
||||||
extern KBPKNScalingFunction ScaleKBPKN, ScaleKNKBP;
|
|
||||||
|
|
||||||
// KNP vs K:
|
|
||||||
extern KNPKScalingFunction ScaleKNPK, ScaleKKNP;
|
|
||||||
|
|
||||||
// KP vs KP:
|
|
||||||
extern KPKPScalingFunction ScaleKPKPw, ScaleKPKPb;
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Prototypes
|
//// Prototypes
|
||||||
|
|||||||
+584
-557
File diff suppressed because it is too large
Load Diff
+19
-18
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -27,41 +27,42 @@
|
|||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
#include "position.h"
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
||||||
/// The EvalInfo struct contains various information computed and collected
|
/// The EvalInfo struct contains various information computed and collected
|
||||||
/// by the evaluation function. An EvalInfo object is passed as one of the
|
/// by the evaluation function. An EvalInfo object is passed as one of the
|
||||||
/// arguments to the evaluation function, and the search can make use of its
|
/// arguments to the evaluation function, and the search can make use of its
|
||||||
/// contents to make intelligent search decisions.
|
/// contents to make intelligent search decisions.
|
||||||
///
|
///
|
||||||
/// At the moment, this is not utilized very much: The only part of the
|
/// At the moment, this is not utilized very much: The only part of the
|
||||||
/// EvalInfo object which is used by the search is futilityMargin.
|
/// EvalInfo object which is used by the search is futilityMargin.
|
||||||
|
class Position;
|
||||||
|
|
||||||
struct EvalInfo {
|
struct EvalInfo {
|
||||||
|
|
||||||
// Middle game and endgame evaluations:
|
// Middle game and endgame evaluations
|
||||||
Value mgValue, egValue;
|
Value mgValue, egValue;
|
||||||
|
|
||||||
// Pointers to material and pawn hash table entries:
|
// Pointers to material and pawn hash table entries
|
||||||
MaterialInfo *mi;
|
MaterialInfo* mi;
|
||||||
PawnInfo *pi;
|
PawnInfo* pi;
|
||||||
|
|
||||||
// attackedBy[color][piece type] is a bitboard representing all squares
|
// attackedBy[color][piece type] is a bitboard representing all squares
|
||||||
// attacked by a given color and piece type. attackedBy[color][0] contains
|
// attacked by a given color and piece type, attackedBy[color][0] contains
|
||||||
// all squares attacked by the given color.
|
// all squares attacked by the given color.
|
||||||
Bitboard attackedBy[2][8];
|
Bitboard attackedBy[2][8];
|
||||||
Bitboard attacked_by(Color c) const { return attackedBy[c][0]; }
|
Bitboard attacked_by(Color c) const { return attackedBy[c][0]; }
|
||||||
Bitboard attacked_by(Color c, PieceType pt) const { return attackedBy[c][pt]; }
|
Bitboard attacked_by(Color c, PieceType pt) const { return attackedBy[c][pt]; }
|
||||||
|
|
||||||
// kingZone[color] is the zone around the enemy king which is considered
|
// kingZone[color] is the zone around the enemy king which is considered
|
||||||
// by the king safety evaluation. This consists of the squares directly
|
// by the king safety evaluation. This consists of the squares directly
|
||||||
// adjacent to the king, and the three (or two, for a king on an edge file)
|
// adjacent to the king, and the three (or two, for a king on an edge file)
|
||||||
// squares two ranks in front of the king. For instance, if black's king
|
// squares two ranks in front of the king. For instance, if black's king
|
||||||
// is on g8, kingZone[WHITE] is a bitboard containing the squares f8, h8,
|
// is on g8, kingZone[WHITE] is a bitboard containing the squares f8, h8,
|
||||||
// f7, g7, h7, f6, g6 and h6.
|
// f7, g7, h7, f6, g6 and h6.
|
||||||
Bitboard kingZone[2];
|
Bitboard kingZone[2];
|
||||||
@@ -90,8 +91,8 @@ struct EvalInfo {
|
|||||||
// Middle game and endgame mobility scores.
|
// Middle game and endgame mobility scores.
|
||||||
Value mgMobility, egMobility;
|
Value mgMobility, egMobility;
|
||||||
|
|
||||||
// Extra futility margin. This is added to the standard futility margin
|
// Extra futility margin. This is added to the standard futility margin
|
||||||
// in the quiescence search.
|
// in the quiescence search.
|
||||||
Value futilityMargin;
|
Value futilityMargin;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,8 +101,8 @@ struct EvalInfo {
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern Value evaluate(const Position &pos, EvalInfo &ei, int threadID);
|
extern Value evaluate(const Position& pos, EvalInfo& ei, int threadID);
|
||||||
extern Value quick_evaluate(const Position &pos);
|
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);
|
||||||
|
|||||||
+35
-32
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -32,14 +32,13 @@
|
|||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
|
|
||||||
History::History() {
|
History::History() { clear(); }
|
||||||
this->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// History::clear() clears the history tables.
|
/// History::clear() clears the history tables
|
||||||
|
|
||||||
void History::clear() {
|
void History::clear() {
|
||||||
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
||||||
@@ -48,55 +47,59 @@ void History::clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// History::success() registers a move as being successful. This is done
|
/// History::success() registers a move as being successful. This is done
|
||||||
/// whenever a non-capturing move causes a beta cutoff in the main search.
|
/// whenever a non-capturing move causes a beta cutoff in the main search.
|
||||||
/// The three parameters are the moving piece, the move itself, and the
|
/// The three parameters are the moving piece, the destination square, and
|
||||||
/// search depth.
|
/// the search depth.
|
||||||
|
|
||||||
|
void History::success(Piece p, Square to, Depth d) {
|
||||||
|
|
||||||
void History::success(Piece p, Move m, Depth d) {
|
|
||||||
assert(piece_is_ok(p));
|
assert(piece_is_ok(p));
|
||||||
assert(move_is_ok(m));
|
assert(square_is_ok(to));
|
||||||
|
|
||||||
history[p][move_to(m)] += int(d) * int(d);
|
history[p][to] += int(d) * int(d);
|
||||||
successCount[p][move_to(m)]++;
|
successCount[p][to]++;
|
||||||
|
|
||||||
// Prevent history overflow:
|
// Prevent history overflow
|
||||||
if(history[p][move_to(m)] >= 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] /= 2;
|
history[i][j] /= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// History::failure() registers a move as being unsuccessful. The function is
|
/// History::failure() registers a move as being unsuccessful. The function is
|
||||||
/// 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, Move m) {
|
void History::failure(Piece p, Square to) {
|
||||||
assert(piece_is_ok(p));
|
|
||||||
assert(move_is_ok(m));
|
|
||||||
|
|
||||||
failureCount[p][move_to(m)]++;
|
assert(piece_is_ok(p));
|
||||||
|
assert(square_is_ok(to));
|
||||||
|
|
||||||
|
failureCount[p][to]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// History::move_ordering_score() returns an integer value used to order the
|
/// History::move_ordering_score() returns an integer value used to order the
|
||||||
/// non-capturing moves in the MovePicker class.
|
/// non-capturing moves in the MovePicker class.
|
||||||
|
|
||||||
int History::move_ordering_score(Piece p, Move m) const {
|
int History::move_ordering_score(Piece p, Square to) const {
|
||||||
assert(piece_is_ok(p));
|
|
||||||
assert(move_is_ok(m));
|
|
||||||
|
|
||||||
return history[p][move_to(m)];
|
assert(piece_is_ok(p));
|
||||||
|
assert(square_is_ok(to));
|
||||||
|
|
||||||
|
return history[p][to];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// History::ok_to_prune() decides whether a move has been sufficiently
|
/// History::ok_to_prune() decides whether a move has been sufficiently
|
||||||
/// unsuccessful that it makes sense to prune it entirely.
|
/// unsuccessful that it makes sense to prune it entirely.
|
||||||
|
|
||||||
|
bool History::ok_to_prune(Piece p, Square to, Depth d) const {
|
||||||
|
|
||||||
bool History::ok_to_prune(Piece p, Move m, Depth d) const {
|
|
||||||
assert(piece_is_ok(p));
|
assert(piece_is_ok(p));
|
||||||
assert(move_is_ok(m));
|
assert(square_is_ok(to));
|
||||||
|
|
||||||
return (int(d) * successCount[p][move_to(m)] < failureCount[p][move_to(m)]);
|
return (int(d) * successCount[p][to] < failureCount[p][to]);
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-17
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -34,19 +34,22 @@
|
|||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
/// The History class stores statistics about how often different moves have
|
/// The History class stores statistics about how often different moves
|
||||||
/// been successful or unsuccessful during the current search. These
|
/// have been successful or unsuccessful during the current search. These
|
||||||
/// statistics are used for reduction and move ordering decisions.
|
/// statistics are used for reduction and move ordering decisions. History
|
||||||
|
/// entries are stored according only to moving piece and destination square,
|
||||||
|
/// in particular two moves with different origin but same destination and
|
||||||
|
/// same piece will be considered identical.
|
||||||
|
|
||||||
class History {
|
class History {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
History();
|
History();
|
||||||
void clear();
|
void clear();
|
||||||
void success(Piece p, Move m, Depth d);
|
void success(Piece p, Square to, Depth d);
|
||||||
void failure(Piece p, Move m);
|
void failure(Piece p, Square to);
|
||||||
int move_ordering_score(Piece p, Move m) const;
|
int move_ordering_score(Piece p, Square to) const;
|
||||||
bool ok_to_prune(Piece p, Move m, Depth d) const;
|
bool ok_to_prune(Piece p, Square to, Depth d) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int history[16][64]; // [piece][square]
|
int history[16][64]; // [piece][square]
|
||||||
@@ -61,17 +64,13 @@ private:
|
|||||||
|
|
||||||
/// HistoryMax controls how often the history counters will be scaled down:
|
/// HistoryMax controls how often the history counters will be scaled down:
|
||||||
/// When the history score for a move gets bigger than HistoryMax, all
|
/// When the history score for a move gets bigger than HistoryMax, all
|
||||||
/// entries in the table are divided by 2. It is difficult to guess what
|
/// entries in the table are divided by 2. It is difficult to guess what
|
||||||
/// the ideal value of this constant is. Scaling down the scores often has
|
/// the ideal value of this constant is. Scaling down the scores often has
|
||||||
/// the effect that parts of the search tree which have been searched
|
/// the effect that parts of the search tree which have been searched
|
||||||
/// 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.
|
||||||
///
|
|
||||||
/// Note that HistoryMax should probably be changed whenever the constant
|
|
||||||
/// OnePly in depth.h is changed. This is somewhat annoying. Perhaps it
|
|
||||||
/// would be better to scale down the history table at regular intervals?
|
|
||||||
|
|
||||||
const int HistoryMax = 50000;
|
const int HistoryMax = 25000 * OnePly;
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(HISTORY_H_INCLUDED)
|
#endif // !defined(HISTORY_H_INCLUDED)
|
||||||
|
|||||||
+7
-6
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// x86 assembly language locks or OS spin locks may perform faster than
|
// x86 assembly language locks or OS spin locks may perform faster than
|
||||||
// mutex locks on some platforms. On my machine, mutexes seem to be the
|
// mutex locks on some platforms. On my machine, mutexes seem to be the
|
||||||
// best.
|
// best.
|
||||||
|
|
||||||
//#define ASM_LOCK
|
//#define ASM_LOCK
|
||||||
@@ -86,8 +86,9 @@ typedef pthread_mutex_t Lock;
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
# include <windows.h>
|
#include <windows.h>
|
||||||
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
typedef CRITICAL_SECTION Lock;
|
typedef CRITICAL_SECTION Lock;
|
||||||
# define lock_init(x, y) InitializeCriticalSection(x)
|
# define lock_init(x, y) InitializeCriticalSection(x)
|
||||||
|
|||||||
+40
-49
@@ -1,98 +1,89 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// To profile with callgrind uncomment following line
|
||||||
|
//#define USE_CALLGRIND
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
#include "bitboard.h"
|
#include "bitcount.h"
|
||||||
#include "direction.h"
|
|
||||||
#include "endgame.h"
|
|
||||||
#include "evaluate.h"
|
|
||||||
#include "material.h"
|
|
||||||
#include "mersenne.h"
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "movepick.h"
|
|
||||||
#include "position.h"
|
|
||||||
#include "search.h"
|
|
||||||
#include "thread.h"
|
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
#include "ucioption.h"
|
|
||||||
|
|
||||||
using std::string;
|
#ifdef USE_CALLGRIND
|
||||||
|
#include <valgrind/callgrind.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
////
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// Disable IO buffering
|
// Disable IO buffering
|
||||||
std::cout.rdbuf()->pubsetbuf(NULL, 0);
|
cout.rdbuf()->pubsetbuf(NULL, 0);
|
||||||
std::cin.rdbuf()->pubsetbuf(NULL, 0);
|
cin.rdbuf()->pubsetbuf(NULL, 0);
|
||||||
|
|
||||||
// Initialization
|
// Initialization through global resources manager
|
||||||
|
Application::initialize();
|
||||||
|
|
||||||
init_mersenne();
|
#ifdef USE_CALLGRIND
|
||||||
init_direction_table();
|
CALLGRIND_START_INSTRUMENTATION;
|
||||||
init_bitboards();
|
#endif
|
||||||
init_uci_options();
|
|
||||||
Position::init_zobrist();
|
|
||||||
Position::init_piece_square_tables();
|
|
||||||
MovePicker::init_phase_table();
|
|
||||||
init_eval(1);
|
|
||||||
init_bitbases();
|
|
||||||
init_threads();
|
|
||||||
|
|
||||||
// Make random number generation less deterministic, for book moves
|
// Process command line arguments if any
|
||||||
for (int i = abs(get_system_time() % 10000); i > 0; i--)
|
if (argc > 1)
|
||||||
genrand_int32();
|
|
||||||
|
|
||||||
// Process command line arguments
|
|
||||||
if (argc >= 2 && string(argv[1]) == "bench")
|
|
||||||
{
|
{
|
||||||
if (argc < 4 || argc > 7)
|
if (string(argv[1]) != "bench" || argc < 4 || argc > 8)
|
||||||
|
cout << "Usage: stockfish bench <hash size> <threads> "
|
||||||
|
<< "[time = 60s] [fen positions file = default] "
|
||||||
|
<< "[time, depth or node limited = time] "
|
||||||
|
<< "[timing file name = none]" << endl;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Usage: glaurung bench <hash size> <threads> "
|
string time = argc > 4 ? argv[4] : "60";
|
||||||
<< "[time = 60s] [fen positions file = default] "
|
string fen = argc > 5 ? argv[5] : "default";
|
||||||
<< "[time, depth or node limited = time]"
|
string lim = argc > 6 ? argv[6] : "time";
|
||||||
<< std::endl;
|
string tim = argc > 7 ? argv[7] : "";
|
||||||
exit(0);
|
benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen + " " + lim + " " + tim);
|
||||||
}
|
}
|
||||||
string time = argc > 4 ? argv[4] : "60";
|
|
||||||
string fen = argc > 5 ? argv[5] : "default";
|
|
||||||
string lim = argc > 6 ? argv[6] : "time";
|
|
||||||
benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen + " " + lim);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print copyright notice
|
// Print copyright notice
|
||||||
std::cout << engine_name() << ". Copyright (C) "
|
cout << engine_name()
|
||||||
<< "2004-2008 Tord Romstad, Marco Costalba. "
|
<< ". By Tord Romstad, Marco Costalba, Joona Kiiski." << endl;
|
||||||
<< std::endl;
|
|
||||||
|
if (CpuHasPOPCNT)
|
||||||
|
cout << "Good! CPU has hardware POPCNT. We will use it." << endl;
|
||||||
|
|
||||||
// Enter UCI mode
|
// Enter UCI mode
|
||||||
uci_main_loop();
|
uci_main_loop();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+187
-134
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,11 +23,13 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <sstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
@@ -35,80 +37,95 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const Value BishopPairMidgameBonus = Value(100);
|
// Polynomial material balance parameters
|
||||||
const Value BishopPairEndgameBonus = Value(100);
|
const Value RedundantQueenPenalty = Value(320);
|
||||||
|
const Value RedundantRookPenalty = Value(554);
|
||||||
|
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
||||||
|
|
||||||
Key KNNKMaterialKey, KKNNMaterialKey;
|
const int QuadraticCoefficientsSameColor[][6] = {
|
||||||
|
{ 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 },
|
||||||
|
{ 7, 25, 4, 7, 7, 7 }, { -27, -2, 46, 100, 56, 7 }, { 58, 29, 83, 148, -3, -25 } };
|
||||||
|
|
||||||
|
const int QuadraticCoefficientsOppositeColor[][6] = {
|
||||||
|
{ 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 } };
|
||||||
|
|
||||||
|
// 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 EndgameScalingFunctionBase SF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Classes
|
//// Classes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
/// EndgameFunctions class stores endgame evaluation and scaling functions
|
||||||
/// See header for a class description. It is declared here to avoid
|
/// in two std::map. Because STL library is not guaranteed to be thread
|
||||||
/// to include <map> in the header file.
|
/// safe even for read access, the maps, although with identical content,
|
||||||
|
/// are replicated for each thread. This is faster then using locks.
|
||||||
|
|
||||||
class EndgameFunctions {
|
class EndgameFunctions {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EndgameFunctions();
|
EndgameFunctions();
|
||||||
EndgameEvaluationFunction* getEEF(Key key) const;
|
~EndgameFunctions();
|
||||||
ScalingFunction* getESF(Key key, Color* c) const;
|
template<class T> T* get(Key key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void add(Key k, EndgameEvaluationFunction* f);
|
template<class T> void add(const string& keyCode);
|
||||||
void add(Key k, Color c, ScalingFunction* f);
|
|
||||||
|
|
||||||
struct ScalingInfo
|
static Key buildKey(const string& keyCode);
|
||||||
{
|
static const string swapColors(const string& keyCode);
|
||||||
Color col;
|
|
||||||
ScalingFunction* fun;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::map<Key, EndgameEvaluationFunction*> EEFmap;
|
// Here we store two maps, for evaluate and scaling functions
|
||||||
std::map<Key, ScalingInfo> ESFmap;
|
pair<map<Key, EF*>, map<Key, SF*> > maps;
|
||||||
|
|
||||||
|
// Maps accessing functions returning const and non-const references
|
||||||
|
template<typename T> const map<Key, T*>& get() const { return maps.first; }
|
||||||
|
template<typename T> map<Key, T*>& get() { return maps.first; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Explicit specializations of a member function shall be declared in
|
||||||
|
// the namespace of which the class template is a member.
|
||||||
|
template<> const map<Key, SF*>&
|
||||||
|
EndgameFunctions::get<SF>() const { return maps.second; }
|
||||||
|
|
||||||
|
template<> map<Key, SF*>&
|
||||||
|
EndgameFunctions::get<SF>() { return maps.second; }
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
|
/// MaterialInfoTable c'tor and d'tor, called once by each thread
|
||||||
/// Constructor for the MaterialInfoTable class
|
|
||||||
|
|
||||||
MaterialInfoTable::MaterialInfoTable(unsigned int numOfEntries) {
|
MaterialInfoTable::MaterialInfoTable(unsigned int numOfEntries) {
|
||||||
|
|
||||||
size = numOfEntries;
|
size = numOfEntries;
|
||||||
entries = new MaterialInfo[size];
|
entries = new MaterialInfo[size];
|
||||||
funcs = new EndgameFunctions();
|
funcs = new EndgameFunctions();
|
||||||
|
|
||||||
if (!entries || !funcs)
|
if (!entries || !funcs)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(MaterialInfo))
|
cerr << "Failed to allocate " << numOfEntries * sizeof(MaterialInfo)
|
||||||
<< " bytes for material hash table." << std::endl;
|
<< " bytes for material hash table." << endl;
|
||||||
exit(EXIT_FAILURE);
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Destructor for the MaterialInfoTable class
|
|
||||||
|
|
||||||
MaterialInfoTable::~MaterialInfoTable() {
|
MaterialInfoTable::~MaterialInfoTable() {
|
||||||
|
|
||||||
delete [] entries;
|
|
||||||
delete funcs;
|
delete funcs;
|
||||||
}
|
delete [] entries;
|
||||||
|
|
||||||
|
|
||||||
/// MaterialInfoTable::clear() clears a material hash table by setting
|
|
||||||
/// all entries to 0.
|
|
||||||
|
|
||||||
void MaterialInfoTable::clear() {
|
|
||||||
|
|
||||||
memset(entries, 0, size * sizeof(MaterialInfo));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -134,73 +151,84 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
mi->clear();
|
mi->clear();
|
||||||
mi->key = key;
|
mi->key = key;
|
||||||
|
|
||||||
// A special case before looking for a specialized evaluation function
|
|
||||||
// KNN vs K is a draw.
|
|
||||||
if (key == KNNKMaterialKey || key == KKNNMaterialKey)
|
|
||||||
{
|
|
||||||
mi->factor[WHITE] = mi->factor[BLACK] = 0;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
// particular material configuration. First we look for a fixed
|
||||||
if ((mi->evaluationFunction = funcs->getEEF(key)) != NULL)
|
// configuration one, then a generic one if previous search failed.
|
||||||
|
if ((mi->evaluationFunction = funcs->get<EF>(key)) != NULL)
|
||||||
return mi;
|
return mi;
|
||||||
|
|
||||||
else if ( pos.non_pawn_material(BLACK) == Value(0)
|
else if ( pos.non_pawn_material(BLACK) == Value(0)
|
||||||
&& pos.piece_count(BLACK, PAWN) == 0
|
&& pos.piece_count(BLACK, PAWN) == 0
|
||||||
&& pos.non_pawn_material(WHITE) >= RookValueEndgame)
|
&& pos.non_pawn_material(WHITE) >= RookValueMidgame)
|
||||||
{
|
{
|
||||||
mi->evaluationFunction = &EvaluateKXK;
|
mi->evaluationFunction = &EvaluateKXK;
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
else if ( pos.non_pawn_material(WHITE) == Value(0)
|
else if ( pos.non_pawn_material(WHITE) == Value(0)
|
||||||
&& pos.piece_count(WHITE, PAWN) == 0
|
&& pos.piece_count(WHITE, PAWN) == 0
|
||||||
&& pos.non_pawn_material(BLACK) >= RookValueEndgame)
|
&& pos.non_pawn_material(BLACK) >= RookValueMidgame)
|
||||||
{
|
{
|
||||||
mi->evaluationFunction = &EvaluateKKX;
|
mi->evaluationFunction = &EvaluateKKX;
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
else if ( pos.pieces(PAWN) == EmptyBoardBB
|
||||||
|
&& pos.pieces(ROOK) == EmptyBoardBB
|
||||||
|
&& pos.pieces(QUEEN) == EmptyBoardBB)
|
||||||
|
{
|
||||||
|
// Minor piece endgame with at least one minor piece per side and
|
||||||
|
// no pawns. Note that the case KmmK is already handled by KXK.
|
||||||
|
assert((pos.pieces(KNIGHT, WHITE) | pos.pieces(BISHOP, WHITE)));
|
||||||
|
assert((pos.pieces(KNIGHT, BLACK) | pos.pieces(BISHOP, BLACK)));
|
||||||
|
|
||||||
|
if ( pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
|
||||||
|
&& pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
|
||||||
|
{
|
||||||
|
mi->evaluationFunction = &EvaluateKmmKm;
|
||||||
|
return mi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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,
|
// The code below is rather messy, and it could easily get worse later,
|
||||||
// if we decide to add more special cases. We face problems when there
|
// if we decide to add more special cases. We face problems when there
|
||||||
// are several conflicting applicable scaling functions and we need to
|
// are several conflicting applicable scaling functions and we need to
|
||||||
// decide which one to use.
|
// decide which one to use.
|
||||||
Color c;
|
SF* sf;
|
||||||
ScalingFunction* sf;
|
|
||||||
|
|
||||||
if ((sf = funcs->getESF(key, &c)) != NULL)
|
if ((sf = funcs->get<SF>(key)) != NULL)
|
||||||
{
|
{
|
||||||
mi->scalingFunction[c] = sf;
|
mi->scalingFunction[sf->color()] = sf;
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generic scaling functions that refer to more then one material
|
||||||
|
// distribution. Should be probed after the specialized ones.
|
||||||
|
// Note that these ones don't return after setting the function.
|
||||||
if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
|
if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
|
||||||
&& pos.piece_count(WHITE, BISHOP) == 1
|
&& pos.piece_count(WHITE, BISHOP) == 1
|
||||||
&& pos.piece_count(WHITE, PAWN) >= 1)
|
&& pos.piece_count(WHITE, PAWN) >= 1)
|
||||||
mi->scalingFunction[WHITE] = &ScaleKBPK;
|
mi->scalingFunction[WHITE] = &ScaleKBPsK;
|
||||||
|
|
||||||
if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
|
if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
|
||||||
&& pos.piece_count(BLACK, BISHOP) == 1
|
&& pos.piece_count(BLACK, BISHOP) == 1
|
||||||
&& pos.piece_count(BLACK, PAWN) >= 1)
|
&& pos.piece_count(BLACK, PAWN) >= 1)
|
||||||
mi->scalingFunction[BLACK] = &ScaleKKBP;
|
mi->scalingFunction[BLACK] = &ScaleKKBPs;
|
||||||
|
|
||||||
if ( pos.piece_count(WHITE, PAWN) == 0
|
if ( pos.piece_count(WHITE, PAWN) == 0
|
||||||
&& pos.non_pawn_material(WHITE) == QueenValueMidgame
|
&& pos.non_pawn_material(WHITE) == QueenValueMidgame
|
||||||
&& pos.piece_count(WHITE, QUEEN) == 1
|
&& pos.piece_count(WHITE, QUEEN) == 1
|
||||||
&& pos.piece_count(BLACK, ROOK) == 1
|
&& pos.piece_count(BLACK, ROOK) == 1
|
||||||
&& pos.piece_count(BLACK, PAWN) >= 1)
|
&& pos.piece_count(BLACK, PAWN) >= 1)
|
||||||
mi->scalingFunction[WHITE] = &ScaleKQKRP;
|
mi->scalingFunction[WHITE] = &ScaleKQKRPs;
|
||||||
|
|
||||||
else if ( pos.piece_count(BLACK, PAWN) == 0
|
else if ( pos.piece_count(BLACK, PAWN) == 0
|
||||||
&& pos.non_pawn_material(BLACK) == QueenValueMidgame
|
&& pos.non_pawn_material(BLACK) == QueenValueMidgame
|
||||||
&& pos.piece_count(BLACK, QUEEN) == 1
|
&& pos.piece_count(BLACK, QUEEN) == 1
|
||||||
&& pos.piece_count(WHITE, ROOK) == 1
|
&& pos.piece_count(WHITE, ROOK) == 1
|
||||||
&& pos.piece_count(WHITE, PAWN) >= 1)
|
&& pos.piece_count(WHITE, PAWN) >= 1)
|
||||||
mi->scalingFunction[BLACK] = &ScaleKRPKQ;
|
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))
|
||||||
{
|
{
|
||||||
@@ -216,16 +244,33 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
}
|
}
|
||||||
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
|
||||||
|
// for both colors instead of only one.
|
||||||
mi->scalingFunction[WHITE] = &ScaleKPKPw;
|
mi->scalingFunction[WHITE] = &ScaleKPKPw;
|
||||||
mi->scalingFunction[BLACK] = &ScaleKPKPb;
|
mi->scalingFunction[BLACK] = &ScaleKPKPb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate the material balance
|
// Compute the space weight
|
||||||
|
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >=
|
||||||
|
2*QueenValueMidgame + 4*RookValueMidgame + 2*KnightValueMidgame)
|
||||||
|
{
|
||||||
|
int minorPieceCount = pos.piece_count(WHITE, KNIGHT)
|
||||||
|
+ pos.piece_count(BLACK, KNIGHT)
|
||||||
|
+ pos.piece_count(WHITE, BISHOP)
|
||||||
|
+ pos.piece_count(BLACK, BISHOP);
|
||||||
|
|
||||||
|
mi->spaceWeight = minorPieceCount * minorPieceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Evaluate the material balance
|
||||||
|
const int pieceCount[2][6] = { { pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT),
|
||||||
|
pos.piece_count(WHITE, BISHOP), pos.piece_count(WHITE, ROOK), pos.piece_count(WHITE, QUEEN) },
|
||||||
|
{ 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) } };
|
||||||
|
Color c, them;
|
||||||
int sign;
|
int sign;
|
||||||
Value egValue = Value(0);
|
int matValue = 0;
|
||||||
Value mgValue = Value(0);
|
|
||||||
|
|
||||||
for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
|
for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
|
||||||
{
|
{
|
||||||
@@ -252,101 +297,109 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bishop pair
|
// Redundancy of major pieces, formula based on Kaufman's paper
|
||||||
if (pos.piece_count(c, BISHOP) >= 2)
|
// "The Evaluation of Material Imbalances in Chess"
|
||||||
{
|
|
||||||
mgValue += sign * BishopPairMidgameBonus;
|
|
||||||
egValue += sign * BishopPairEndgameBonus;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Knights are stronger when there are many pawns on the board. The
|
|
||||||
// formula is taken from Larry Kaufman's paper "The Evaluation of Material
|
|
||||||
// Imbalances in Chess":
|
|
||||||
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
|
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
|
||||||
mgValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
|
if (pieceCount[c][ROOK] >= 1)
|
||||||
egValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
|
matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);
|
||||||
|
|
||||||
// Redundancy of major pieces, again based on Kaufman's paper:
|
them = opposite_color(c);
|
||||||
if (pos.piece_count(c, ROOK) >= 1)
|
|
||||||
|
// Second-degree polynomial material imbalance by Tord Romstad
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
||||||
{
|
{
|
||||||
Value v = Value((pos.piece_count(c, ROOK) - 1) * 32 + pos.piece_count(c, QUEEN) * 16);
|
int c1 = sign * pieceCount[c][pt1];
|
||||||
mgValue -= sign * v;
|
if (!c1)
|
||||||
egValue -= sign * v;
|
continue;
|
||||||
|
|
||||||
|
matValue += c1 * LinearCoefficients[pt1];
|
||||||
|
|
||||||
|
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
|
||||||
|
{
|
||||||
|
matValue += c1 * pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2];
|
||||||
|
matValue += c1 * pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mi->mgValue = int16_t(mgValue);
|
mi->value = int16_t(matValue / 16);
|
||||||
mi->egValue = int16_t(egValue);
|
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// EndgameFunctions member definitions. This class is used to store the maps
|
/// EndgameFunctions member definitions.
|
||||||
/// of end game and scaling functions that MaterialInfoTable will query for
|
|
||||||
/// each key. The maps are constant and are populated only at construction,
|
|
||||||
/// but are per-thread instead of globals to avoid expensive locks.
|
|
||||||
|
|
||||||
EndgameFunctions::EndgameFunctions() {
|
EndgameFunctions::EndgameFunctions() {
|
||||||
|
|
||||||
typedef Key ZM[2][8][16];
|
add<EvaluationFunction<KNNK> >("KNNK");
|
||||||
const ZM& z = Position::zobMaterial;
|
add<EvaluationFunction<KPK> >("KPK");
|
||||||
|
add<EvaluationFunction<KBNK> >("KBNK");
|
||||||
|
add<EvaluationFunction<KRKP> >("KRKP");
|
||||||
|
add<EvaluationFunction<KRKB> >("KRKB");
|
||||||
|
add<EvaluationFunction<KRKN> >("KRKN");
|
||||||
|
add<EvaluationFunction<KQKR> >("KQKR");
|
||||||
|
add<EvaluationFunction<KBBKN> >("KBBKN");
|
||||||
|
|
||||||
static const Color W = WHITE;
|
add<ScalingFunction<KNPK> >("KNPK");
|
||||||
static const Color B = BLACK;
|
add<ScalingFunction<KRPKR> >("KRPKR");
|
||||||
|
add<ScalingFunction<KBPKB> >("KBPKB");
|
||||||
KNNKMaterialKey = z[W][KNIGHT][1] ^ z[W][KNIGHT][2];
|
add<ScalingFunction<KBPPKB> >("KBPPKB");
|
||||||
KKNNMaterialKey = z[B][KNIGHT][1] ^ z[B][KNIGHT][2];
|
add<ScalingFunction<KBPKN> >("KBPKN");
|
||||||
|
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||||
add(z[W][PAWN][1], &EvaluateKPK);
|
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||||
add(z[B][PAWN][1], &EvaluateKKP);
|
|
||||||
|
|
||||||
add(z[W][BISHOP][1] ^ z[W][KNIGHT][1], &EvaluateKBNK);
|
|
||||||
add(z[B][BISHOP][1] ^ z[B][KNIGHT][1], &EvaluateKKBN);
|
|
||||||
add(z[W][ROOK][1] ^ z[B][PAWN][1], &EvaluateKRKP);
|
|
||||||
add(z[W][PAWN][1] ^ z[B][ROOK][1], &EvaluateKPKR);
|
|
||||||
add(z[W][ROOK][1] ^ z[B][BISHOP][1], &EvaluateKRKB);
|
|
||||||
add(z[W][BISHOP][1] ^ z[B][ROOK][1], &EvaluateKBKR);
|
|
||||||
add(z[W][ROOK][1] ^ z[B][KNIGHT][1], &EvaluateKRKN);
|
|
||||||
add(z[W][KNIGHT][1] ^ z[B][ROOK][1], &EvaluateKNKR);
|
|
||||||
add(z[W][QUEEN][1] ^ z[B][ROOK][1], &EvaluateKQKR);
|
|
||||||
add(z[W][ROOK][1] ^ z[B][QUEEN][1], &EvaluateKRKQ);
|
|
||||||
|
|
||||||
add(z[W][KNIGHT][1] ^ z[W][PAWN][1], W, &ScaleKNPK);
|
|
||||||
add(z[B][KNIGHT][1] ^ z[B][PAWN][1], B, &ScaleKKNP);
|
|
||||||
|
|
||||||
add(z[W][ROOK][1] ^ z[W][PAWN][1] ^ z[B][ROOK][1] , W, &ScaleKRPKR);
|
|
||||||
add(z[W][ROOK][1] ^ z[B][ROOK][1] ^ z[B][PAWN][1] , B, &ScaleKRKRP);
|
|
||||||
add(z[W][BISHOP][1] ^ z[W][PAWN][1] ^ z[B][BISHOP][1], W, &ScaleKBPKB);
|
|
||||||
add(z[W][BISHOP][1] ^ z[B][BISHOP][1] ^ z[B][PAWN][1] , B, &ScaleKBKBP);
|
|
||||||
add(z[W][BISHOP][1] ^ z[W][PAWN][1] ^ z[B][KNIGHT][1], W, &ScaleKBPKN);
|
|
||||||
add(z[W][KNIGHT][1] ^ z[B][BISHOP][1] ^ z[B][PAWN][1] , B, &ScaleKNKBP);
|
|
||||||
|
|
||||||
add(z[W][ROOK][1] ^ z[W][PAWN][1] ^ z[W][PAWN][2] ^ z[B][ROOK][1] ^ z[B][PAWN][1], W, &ScaleKRPPKRP);
|
|
||||||
add(z[W][ROOK][1] ^ z[W][PAWN][1] ^ z[B][ROOK][1] ^ z[B][PAWN][1] ^ z[B][PAWN][2], B, &ScaleKRPKRPP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndgameFunctions::add(Key k, EndgameEvaluationFunction* f) {
|
EndgameFunctions::~EndgameFunctions() {
|
||||||
|
|
||||||
EEFmap.insert(std::pair<Key, EndgameEvaluationFunction*>(k, f));
|
for (map<Key, EF*>::iterator it = maps.first.begin(); it != maps.first.end(); ++it)
|
||||||
|
delete (*it).second;
|
||||||
|
|
||||||
|
for (map<Key, SF*>::iterator it = maps.second.begin(); it != maps.second.end(); ++it)
|
||||||
|
delete (*it).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndgameFunctions::add(Key k, Color c, ScalingFunction* f) {
|
Key EndgameFunctions::buildKey(const string& keyCode) {
|
||||||
|
|
||||||
ScalingInfo s = {c, f};
|
assert(keyCode.length() > 0 && keyCode[0] == 'K');
|
||||||
ESFmap.insert(std::pair<Key, ScalingInfo>(k, s));
|
assert(keyCode.length() < 8);
|
||||||
|
|
||||||
|
stringstream s;
|
||||||
|
bool upcase = false;
|
||||||
|
|
||||||
|
// Build up a fen string with the given pieces, note that
|
||||||
|
// the fen string could be of an illegal position.
|
||||||
|
for (size_t i = 0; i < keyCode.length(); i++)
|
||||||
|
{
|
||||||
|
if (keyCode[i] == 'K')
|
||||||
|
upcase = !upcase;
|
||||||
|
|
||||||
|
s << char(upcase? toupper(keyCode[i]) : tolower(keyCode[i]));
|
||||||
|
}
|
||||||
|
s << 8 - keyCode.length() << "/8/8/8/8/8/8/8 w -";
|
||||||
|
return Position(s.str()).get_material_key();
|
||||||
}
|
}
|
||||||
|
|
||||||
EndgameEvaluationFunction* EndgameFunctions::getEEF(Key key) const {
|
const string EndgameFunctions::swapColors(const string& keyCode) {
|
||||||
|
|
||||||
std::map<Key, EndgameEvaluationFunction*>::const_iterator it(EEFmap.find(key));
|
// Build corresponding key for the opposite color: "KBPKN" -> "KNKBP"
|
||||||
return (it != EEFmap.end() ? it->second : NULL);
|
size_t idx = keyCode.find("K", 1);
|
||||||
|
return keyCode.substr(idx) + keyCode.substr(0, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScalingFunction* EndgameFunctions::getESF(Key key, Color* c) const {
|
template<class T>
|
||||||
|
void EndgameFunctions::add(const string& keyCode) {
|
||||||
|
|
||||||
std::map<Key, ScalingInfo>::const_iterator it(ESFmap.find(key));
|
typedef typename T::Base F;
|
||||||
if (it == ESFmap.end())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
*c = it->second.col;
|
get<F>().insert(pair<Key, F*>(buildKey(keyCode), new T(WHITE)));
|
||||||
return it->second.fun;
|
get<F>().insert(pair<Key, F*>(buildKey(swapColors(keyCode)), new T(BLACK)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T* EndgameFunctions::get(Key key) const {
|
||||||
|
|
||||||
|
typename map<Key, T*>::const_iterator it(get<T>().find(key));
|
||||||
|
return (it != get<T>().end() ? it->second : NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-34
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -49,43 +49,36 @@ class MaterialInfo {
|
|||||||
friend class MaterialInfoTable;
|
friend class MaterialInfoTable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Value mg_value() const;
|
MaterialInfo() : key(0) { clear(); }
|
||||||
Value eg_value() const;
|
|
||||||
|
Value 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;
|
||||||
bool specialized_eval_exists() const;
|
bool specialized_eval_exists() const;
|
||||||
Value evaluate(const Position& pos) const;
|
Value evaluate(const Position& pos) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clear();
|
inline void clear();
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
int16_t mgValue;
|
int16_t value;
|
||||||
int16_t egValue;
|
|
||||||
uint8_t factor[2];
|
uint8_t factor[2];
|
||||||
EndgameEvaluationFunction* evaluationFunction;
|
EndgameEvaluationFunctionBase* evaluationFunction;
|
||||||
ScalingFunction* scalingFunction[2];
|
EndgameScalingFunctionBase* scalingFunction[2];
|
||||||
|
int spaceWeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// EndgameFunctions class stores the endgame evaluation functions std::map.
|
|
||||||
/// Because STL library is not thread safe even for read access, the maps,
|
|
||||||
/// although with identical content, are replicated for each thread. This
|
|
||||||
/// is faster then using locks with an unique set of global maps.
|
|
||||||
|
|
||||||
class EndgameFunctions;
|
|
||||||
|
|
||||||
|
|
||||||
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
||||||
/// just an array of MaterialInfo objects and a few methods for accessing these
|
/// just an array of MaterialInfo objects and a few methods for accessing these
|
||||||
/// objects. The most important method is get_material_info, which looks up a
|
/// objects. The most important method is get_material_info, which looks up a
|
||||||
/// position in the table and returns a pointer to a MaterialInfo object.
|
/// position in the table and returns a pointer to a MaterialInfo object.
|
||||||
|
class EndgameFunctions;
|
||||||
|
|
||||||
class MaterialInfoTable {
|
class MaterialInfoTable {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MaterialInfoTable(unsigned numOfEntries);
|
MaterialInfoTable(unsigned numOfEntries);
|
||||||
~MaterialInfoTable();
|
~MaterialInfoTable();
|
||||||
void clear();
|
|
||||||
MaterialInfo* get_material_info(const Position& pos);
|
MaterialInfo* get_material_info(const Position& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -99,34 +92,30 @@ private:
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// MaterialInfo::mg_value and MaterialInfo::eg_value simply returns the
|
/// MaterialInfo::material_value simply returns the material balance
|
||||||
/// material balance evaluation for the middle game and the endgame.
|
/// evaluation that is independent from game phase.
|
||||||
|
|
||||||
inline Value MaterialInfo::mg_value() const {
|
inline Value MaterialInfo::material_value() const {
|
||||||
|
|
||||||
return Value(mgValue);
|
return Value(value);
|
||||||
}
|
|
||||||
|
|
||||||
inline Value MaterialInfo::eg_value() const {
|
|
||||||
|
|
||||||
return Value(egValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MaterialInfo::clear() resets a MaterialInfo object to an empty state,
|
/// MaterialInfo::clear() resets a MaterialInfo object to an empty state,
|
||||||
/// with all slots at their default values.
|
/// with all slots at their default values but the key.
|
||||||
|
|
||||||
inline void MaterialInfo::clear() {
|
inline void MaterialInfo::clear() {
|
||||||
|
|
||||||
mgValue = egValue = 0;
|
value = 0;
|
||||||
factor[WHITE] = factor[BLACK] = uint8_t(SCALE_FACTOR_NORMAL);
|
factor[WHITE] = factor[BLACK] = uint8_t(SCALE_FACTOR_NORMAL);
|
||||||
evaluationFunction = NULL;
|
evaluationFunction = NULL;
|
||||||
scalingFunction[WHITE] = scalingFunction[BLACK] = NULL;
|
scalingFunction[WHITE] = scalingFunction[BLACK] = NULL;
|
||||||
|
spaceWeight = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MaterialInfo::scale_factor takes a position and a color as input, and
|
/// MaterialInfo::scale_factor takes a position and a color as input, and
|
||||||
/// returns a scale factor for the given color. We have to provide the
|
/// returns a scale factor for the given color. We have to provide the
|
||||||
/// position in addition to the color, because the scale factor need not
|
/// position in addition to the color, because the scale factor need not
|
||||||
/// to be a constant: It can also be a function which should be applied to
|
/// to be a constant: It can also be a function which should be applied to
|
||||||
/// the position. For instance, in KBP vs K endgames, a scaling function
|
/// the position. For instance, in KBP vs K endgames, a scaling function
|
||||||
@@ -144,6 +133,15 @@ inline ScaleFactor MaterialInfo::scale_factor(const Position& pos, Color c) cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// MaterialInfo::space_weight() simply returns the weight for the space
|
||||||
|
/// evaluation for this material configuration.
|
||||||
|
|
||||||
|
inline int MaterialInfo::space_weight() const {
|
||||||
|
|
||||||
|
return spaceWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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,
|
||||||
/// or if the normal evaluation function should be used.
|
/// or if the normal evaluation function should be used.
|
||||||
@@ -155,7 +153,7 @@ inline bool MaterialInfo::specialized_eval_exists() const {
|
|||||||
|
|
||||||
|
|
||||||
/// MaterialInfo::evaluate applies a specialized evaluation function
|
/// MaterialInfo::evaluate applies a specialized evaluation function
|
||||||
/// to a given position object. It should only be called when
|
/// to a given position object. It should only be called when
|
||||||
/// specialized_eval_exists() returns 'true'.
|
/// specialized_eval_exists() returns 'true'.
|
||||||
|
|
||||||
inline Value MaterialInfo::evaluate(const Position& pos) const {
|
inline Value MaterialInfo::evaluate(const Position& pos) const {
|
||||||
|
|||||||
+3
-3
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+98
-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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -30,27 +30,39 @@
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# include <windows.h>
|
#define _CRT_SECURE_NO_DEPRECATE
|
||||||
# include <time.h>
|
#include <windows.h>
|
||||||
# include "dos.h"
|
#include <sys/timeb.h>
|
||||||
int gettimeofday(struct timeval * tp, struct timezone * tzp);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "bitcount.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/// Version number. If this is left empty, the current date (in the format
|
||||||
|
/// YYMMDD) is used as a version number.
|
||||||
|
|
||||||
|
static const string EngineVersion = "1.5.1";
|
||||||
|
static const string AppName = "Stockfish";
|
||||||
|
static const string AppTag = "";
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Variables
|
//// Variables
|
||||||
////
|
////
|
||||||
|
|
||||||
long dbg_cnt0 = 0;
|
bool Chess960;
|
||||||
long dbg_cnt1 = 0;
|
|
||||||
|
uint64_t dbg_cnt0 = 0;
|
||||||
|
uint64_t dbg_cnt1 = 0;
|
||||||
|
|
||||||
bool dbg_show_mean = false;
|
bool dbg_show_mean = false;
|
||||||
bool dbg_show_hit_rate = false;
|
bool dbg_show_hit_rate = false;
|
||||||
@@ -60,17 +72,65 @@ bool dbg_show_hit_rate = false;
|
|||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
|
void dbg_hit_on(bool b) {
|
||||||
|
|
||||||
|
assert(!dbg_show_mean);
|
||||||
|
dbg_show_hit_rate = true;
|
||||||
|
dbg_cnt0++;
|
||||||
|
if (b)
|
||||||
|
dbg_cnt1++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_hit_on_c(bool c, bool b) {
|
||||||
|
|
||||||
|
if (c)
|
||||||
|
dbg_hit_on(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_before() {
|
||||||
|
|
||||||
|
assert(!dbg_show_mean);
|
||||||
|
dbg_show_hit_rate = true;
|
||||||
|
dbg_cnt0++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_after() {
|
||||||
|
|
||||||
|
assert(!dbg_show_mean);
|
||||||
|
dbg_show_hit_rate = true;
|
||||||
|
dbg_cnt1++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_mean_of(int v) {
|
||||||
|
|
||||||
|
assert(!dbg_show_hit_rate);
|
||||||
|
dbg_show_mean = true;
|
||||||
|
dbg_cnt0++;
|
||||||
|
dbg_cnt1 += v;
|
||||||
|
}
|
||||||
|
|
||||||
void dbg_print_hit_rate() {
|
void dbg_print_hit_rate() {
|
||||||
|
|
||||||
std::cout << "Total " << dbg_cnt0 << " Hit " << dbg_cnt1
|
cout << "Total " << dbg_cnt0 << " Hit " << dbg_cnt1
|
||||||
<< " hit rate (%) " << (dbg_cnt1*100)/(dbg_cnt0 ? dbg_cnt0 : 1)
|
<< " hit rate (%) " << (dbg_cnt1*100)/(dbg_cnt0 ? dbg_cnt0 : 1) << endl;
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dbg_print_mean() {
|
void dbg_print_mean() {
|
||||||
|
|
||||||
std::cout << "Total " << dbg_cnt0 << " Mean "
|
cout << "Total " << dbg_cnt0 << " Mean "
|
||||||
<< (float)dbg_cnt1 / (dbg_cnt0 ? dbg_cnt0 : 1) << std::endl;
|
<< (float)dbg_cnt1 / (dbg_cnt0 ? dbg_cnt0 : 1) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_print_hit_rate(ofstream& logFile) {
|
||||||
|
|
||||||
|
logFile << "Total " << dbg_cnt0 << " Hit " << dbg_cnt1
|
||||||
|
<< " hit rate (%) " << (dbg_cnt1*100)/(dbg_cnt0 ? dbg_cnt0 : 1) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_print_mean(ofstream& logFile) {
|
||||||
|
|
||||||
|
logFile << "Total " << dbg_cnt0 << " Mean "
|
||||||
|
<< (float)dbg_cnt1 / (dbg_cnt0 ? dbg_cnt0 : 1) << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// engine_name() returns the full name of the current Stockfish version.
|
/// engine_name() returns the full name of the current Stockfish version.
|
||||||
@@ -78,24 +138,27 @@ void dbg_print_mean() {
|
|||||||
/// program was compiled) or "Stockfish <version number>", depending on whether
|
/// program was compiled) or "Stockfish <version number>", depending on whether
|
||||||
/// the constant EngineVersion (defined in misc.h) is empty.
|
/// the constant EngineVersion (defined in misc.h) is empty.
|
||||||
|
|
||||||
const std::string engine_name() {
|
const string engine_name() {
|
||||||
|
|
||||||
if (EngineVersion.empty())
|
const string cpu64(CpuHas64BitPath ? " 64bit" : "");
|
||||||
{
|
|
||||||
std::string date(__DATE__); // From compiler, format is "Sep 21 2008"
|
|
||||||
std::string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
|
|
||||||
|
|
||||||
size_t mon = 1 + months.find(date.substr(0, 3)) / 4;
|
if (!EngineVersion.empty())
|
||||||
|
return AppName+ " " + EngineVersion + cpu64;
|
||||||
|
|
||||||
std::stringstream s;
|
string date(__DATE__); // From compiler, format is "Sep 21 2008"
|
||||||
std::string day = (date[4] == ' ' ? date.substr(5, 1) : date.substr(4, 2));
|
string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
|
||||||
|
|
||||||
s << "Stockfish " << date.substr(date.length() - 2) << std::setfill('0')
|
size_t mon = 1 + months.find(date.substr(0, 3)) / 4;
|
||||||
<< std::setw(2) << mon << std::setw(2) << day;
|
|
||||||
|
|
||||||
return s.str();
|
stringstream s;
|
||||||
} else
|
string day = (date[4] == ' ' ? date.substr(5, 1) : date.substr(4, 2));
|
||||||
return "Stockfish " + EngineVersion;
|
|
||||||
|
string name = AppName + " " + AppTag + " ";
|
||||||
|
|
||||||
|
s << name << date.substr(date.length() - 2) << setfill('0')
|
||||||
|
<< setw(2) << mon << setw(2) << day << cpu64;
|
||||||
|
|
||||||
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -103,9 +166,16 @@ const std::string engine_name() {
|
|||||||
/// milliseconds.
|
/// milliseconds.
|
||||||
|
|
||||||
int get_system_time() {
|
int get_system_time() {
|
||||||
struct timeval t;
|
|
||||||
gettimeofday(&t, NULL);
|
#if defined(_MSC_VER)
|
||||||
return t.tv_sec*1000 + t.tv_usec/1000;
|
struct _timeb t;
|
||||||
|
_ftime(&t);
|
||||||
|
return int(t.time*1000 + t.millitm);
|
||||||
|
#else
|
||||||
|
struct timeval t;
|
||||||
|
gettimeofday(&t, NULL);
|
||||||
|
return t.tv_sec*1000 + t.tv_usec/1000;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+22
-22
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,19 +26,11 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "application.h"
|
||||||
////
|
#include "types.h"
|
||||||
//// Constants
|
|
||||||
////
|
|
||||||
|
|
||||||
|
|
||||||
/// Version number. If this is left empty, the current date (in the format
|
|
||||||
/// YYMMDD) is used as a version number.
|
|
||||||
|
|
||||||
const std::string EngineVersion = "1.1a";
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Macros
|
//// Macros
|
||||||
@@ -48,6 +40,13 @@ const std::string EngineVersion = "1.1a";
|
|||||||
#define Max(x, y) (((x) < (y))? (y) : (x))
|
#define Max(x, y) (((x) < (y))? (y) : (x))
|
||||||
|
|
||||||
|
|
||||||
|
////
|
||||||
|
//// Variables
|
||||||
|
////
|
||||||
|
|
||||||
|
extern bool Chess960;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
@@ -57,24 +56,25 @@ extern int get_system_time();
|
|||||||
extern int cpu_count();
|
extern int cpu_count();
|
||||||
extern int Bioskey();
|
extern int Bioskey();
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Debug
|
//// Debug
|
||||||
////
|
////
|
||||||
|
|
||||||
extern bool dbg_show_mean;
|
extern bool dbg_show_mean;
|
||||||
extern bool dbg_show_hit_rate;
|
extern bool dbg_show_hit_rate;
|
||||||
|
|
||||||
extern long dbg_cnt0;
|
extern uint64_t dbg_cnt0;
|
||||||
extern long dbg_cnt1;
|
extern uint64_t dbg_cnt1;
|
||||||
|
|
||||||
inline void dbg_hit_on(bool b) { dbg_show_hit_rate = true; dbg_cnt0++; if (b) dbg_cnt1++; }
|
|
||||||
inline void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); }
|
|
||||||
|
|
||||||
inline void dbg_before() { dbg_show_hit_rate = true; dbg_cnt0++; }
|
|
||||||
inline void dbg_after() { dbg_show_hit_rate = true; dbg_cnt1++; }
|
|
||||||
|
|
||||||
inline void dbg_mean_of(int v) { dbg_cnt0++; dbg_cnt1 += v; }
|
|
||||||
|
|
||||||
|
extern void dbg_hit_on(bool b);
|
||||||
|
extern void dbg_hit_on_c(bool c, bool b);
|
||||||
|
extern void dbg_before();
|
||||||
|
extern void dbg_after();
|
||||||
|
extern void dbg_mean_of(int v);
|
||||||
extern void dbg_print_hit_rate();
|
extern void dbg_print_hit_rate();
|
||||||
extern void dbg_print_mean();
|
extern void dbg_print_mean();
|
||||||
|
extern void dbg_print_hit_rate(std::ofstream& logFile);
|
||||||
|
extern void dbg_print_mean(std::ofstream& logFile);
|
||||||
|
|
||||||
#endif // !defined(MISC_H_INCLUDED)
|
#endif // !defined(MISC_H_INCLUDED)
|
||||||
|
|||||||
+10
-11
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "ucioption.h"
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -72,13 +71,13 @@ Move move_from_string(const Position& pos, const std::string& str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (piece == king_of_color(us))
|
if (piece == piece_of_color_and_type(us, KING))
|
||||||
{
|
{
|
||||||
// Is this a castling move? A king move is assumed to be a castling
|
// Is this a castling move? A king move is assumed to be a castling
|
||||||
// move if the destination square is occupied by a friendly rook, or
|
// move if the destination square is occupied by a friendly rook, or
|
||||||
// if the distance between the source and destination squares is more
|
// if the distance between the source and destination squares is more
|
||||||
// than 1.
|
// than 1.
|
||||||
if (pos.piece_on(to) == rook_of_color(us))
|
if (pos.piece_on(to) == piece_of_color_and_type(us, ROOK))
|
||||||
return make_castle_move(from, to);
|
return make_castle_move(from, to);
|
||||||
|
|
||||||
else if (square_distance(from, to) > 1)
|
else if (square_distance(from, to) > 1)
|
||||||
@@ -87,13 +86,13 @@ Move move_from_string(const Position& pos, const std::string& str) {
|
|||||||
// internal "king captures rook" representation.
|
// internal "king captures rook" representation.
|
||||||
SquareDelta delta = (to > from ? DELTA_E : DELTA_W);
|
SquareDelta delta = (to > from ? DELTA_E : DELTA_W);
|
||||||
Square s = from + delta;
|
Square s = from + delta;
|
||||||
while (relative_rank(us, s) == RANK_1 && pos.piece_on(s) != rook_of_color(us))
|
while (relative_rank(us, s) == RANK_1 && pos.piece_on(s) != piece_of_color_and_type(us, ROOK))
|
||||||
s += delta;
|
s += delta;
|
||||||
|
|
||||||
return (relative_rank(us, s) == RANK_1 ? make_castle_move(from, s) : MOVE_NONE);
|
return (relative_rank(us, s) == RANK_1 ? make_castle_move(from, s) : MOVE_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (piece == pawn_of_color(us))
|
else if (piece == piece_of_color_and_type(us, PAWN))
|
||||||
{
|
{
|
||||||
// En passant move? We assume that a pawn move is an en passant move
|
// En passant move? We assume that a pawn move is an en passant move
|
||||||
// without further testing if the destination square is epSquare.
|
// without further testing if the destination square is epSquare.
|
||||||
@@ -130,8 +129,8 @@ const std::string move_to_string(Move move) {
|
|||||||
return (from == SQ_E1 ? "e1c1" : "e8c8");
|
return (from == SQ_E1 ? "e1c1" : "e8c8");
|
||||||
}
|
}
|
||||||
str = square_to_string(from) + square_to_string(to);
|
str = square_to_string(from) + square_to_string(to);
|
||||||
if (move_promotion(move))
|
if (move_is_promotion(move))
|
||||||
str += piece_type_to_char(move_promotion(move), false);
|
str += piece_type_to_char(move_promotion_piece(move), false);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -139,7 +138,7 @@ const std::string move_to_string(Move move) {
|
|||||||
|
|
||||||
/// Overload the << operator, to make it easier to print moves.
|
/// Overload the << operator, to make it easier to print moves.
|
||||||
|
|
||||||
std::ostream &operator << (std::ostream &os, Move m) {
|
std::ostream &operator << (std::ostream& os, Move m) {
|
||||||
|
|
||||||
return os << move_to_string(m);
|
return os << move_to_string(m);
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-13
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -38,10 +38,22 @@
|
|||||||
|
|
||||||
class Position;
|
class Position;
|
||||||
|
|
||||||
|
/// A move needs 17 bits to be stored
|
||||||
|
///
|
||||||
|
/// bit 0- 5: destination square (from 0 to 63)
|
||||||
|
/// bit 6-11: origin square (from 0 to 63)
|
||||||
|
/// bit 12-14: promotion piece type
|
||||||
|
/// bit 15: en passant flag
|
||||||
|
/// bit 16: castle flag
|
||||||
|
///
|
||||||
|
/// Special cases are MOVE_NONE and MOVE_NULL. We can sneak these in
|
||||||
|
/// because in any normal move destination square is always different
|
||||||
|
/// from origin square while MOVE_NONE and MOVE_NULL have the same
|
||||||
|
/// origin and destination square, 0 and 1 respectively.
|
||||||
|
|
||||||
enum Move {
|
enum Move {
|
||||||
MOVE_NONE = 0,
|
MOVE_NONE = 0,
|
||||||
MOVE_NULL = 65,
|
MOVE_NULL = 65
|
||||||
MOVE_MAX = 0xFFFFFF
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -50,29 +62,36 @@ struct MoveStack {
|
|||||||
int score;
|
int score;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Note that operator< is set up such that std::sort() will sort in descending order
|
||||||
|
inline bool operator<(const MoveStack& f, const MoveStack& s) { return s.score < f.score; }
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
inline Square move_from(Move m) {
|
inline Square move_from(Move m) {
|
||||||
return Square((int(m) >> 6) & 077);
|
return Square((int(m) >> 6) & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square move_to(Move m) {
|
inline Square move_to(Move m) {
|
||||||
return Square(m & 077);
|
return Square(m & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType move_promotion(Move m) {
|
inline PieceType move_promotion_piece(Move m) {
|
||||||
return PieceType((int(m) >> 12) & 7);
|
return PieceType((int(m) >> 12) & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool move_is_ep(Move m) {
|
inline int move_is_promotion(Move m) {
|
||||||
return bool((int(m) >> 15) & 1);
|
return m & (7 << 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool move_is_castle(Move m) {
|
inline int move_is_ep(Move m) {
|
||||||
return bool((int(m) >> 16) & 1);
|
return m & (1 << 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int move_is_castle(Move m) {
|
||||||
|
return m & (1 << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool move_is_short_castle(Move m) {
|
inline bool move_is_short_castle(Move m) {
|
||||||
@@ -104,7 +123,7 @@ inline Move make_ep_move(Square from, Square to) {
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern std::ostream &operator << (std::ostream &os, Move m);
|
extern std::ostream& operator<<(std::ostream &os, Move m);
|
||||||
extern Move move_from_string(const Position &pos, const std::string &str);
|
extern Move move_from_string(const Position &pos, const std::string &str);
|
||||||
extern const std::string move_to_string(Move m);
|
extern const std::string move_to_string(Move m);
|
||||||
extern bool move_is_ok(Move m);
|
extern bool move_is_ok(Move m);
|
||||||
|
|||||||
+428
-598
File diff suppressed because it is too large
Load Diff
+8
-7
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,12 +32,13 @@
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern int generate_captures(const Position &pos, MoveStack *mlist);
|
extern MoveStack* generate_captures(const Position& pos, MoveStack* mlist);
|
||||||
extern int generate_noncaptures(const Position &pos, MoveStack *mlist);
|
extern MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist);
|
||||||
extern int generate_checks(const Position &pos, MoveStack *mlist, Bitboard dc);
|
extern MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc);
|
||||||
extern int generate_evasions(const Position &pos, MoveStack *mlist);
|
extern MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
|
||||||
extern int generate_legal_moves(const Position &pos, MoveStack *mlist);
|
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);
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(MOVEGEN_H_INCLUDED)
|
#endif // !defined(MOVEGEN_H_INCLUDED)
|
||||||
|
|||||||
+258
-451
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,10 +23,10 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "evaluate.h"
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
@@ -39,156 +39,306 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Variables
|
enum MovegenPhase {
|
||||||
|
PH_TT_MOVES, // Transposition table move and mate killer
|
||||||
MovePicker::MovegenPhase PhaseTable[32];
|
PH_GOOD_CAPTURES, // Queen promotions and captures with SEE values >= 0
|
||||||
int MainSearchPhaseIndex;
|
PH_KILLERS, // Killer moves from the current ply
|
||||||
int EvasionsPhaseIndex;
|
PH_NONCAPTURES, // Non-captures and underpromotions
|
||||||
int QsearchWithChecksPhaseIndex;
|
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < 0
|
||||||
int QsearchNoCapturesPhaseIndex;
|
PH_EVASIONS, // Check evasions
|
||||||
int QsearchWithoutChecksPhaseIndex;
|
PH_QCAPTURES, // Captures in quiescence search
|
||||||
int NoMovesPhaseIndex;
|
PH_QCHECKS, // Non-capture checks in quiescence search
|
||||||
|
PH_STOP
|
||||||
|
};
|
||||||
|
|
||||||
|
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 EvasionsPhaseTable[] = { PH_EVASIONS, 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};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
||||||
/// Constructor for the MovePicker class. Apart from the position for which
|
/// Constructor for the MovePicker class. Apart from the position for which
|
||||||
/// it is asked to pick legal moves, MovePicker also wants some information
|
/// it is asked to pick legal moves, MovePicker also wants some information
|
||||||
/// to help it to return the presumably good moves first, to decide which
|
/// to help it to return the presumably good moves first, to decide which
|
||||||
/// moves to return (in the quiescence search, for instance, we only want to
|
/// moves to return (in the quiescence search, for instance, we only want to
|
||||||
/// search captures, promotions and some checks) and about how important good
|
/// search captures, promotions and some checks) and about how important good
|
||||||
/// move ordering is at the current node.
|
/// move ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, bool pv, Move ttm,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
||||||
const SearchStack& ss, Depth d, EvalInfo* ei) : pos(p) {
|
const History& h, SearchStack* ss) : pos(p), H(h) {
|
||||||
pvNode = pv;
|
int searchTT = ttm;
|
||||||
ttMove = ttm;
|
ttMoves[0].move = ttm;
|
||||||
mateKiller = (ss.mateKiller == ttm)? MOVE_NONE : ss.mateKiller;
|
finished = false;
|
||||||
killer1 = ss.killers[0];
|
lastBadCapture = badCaptures;
|
||||||
killer2 = ss.killers[1];
|
|
||||||
depth = d;
|
if (ss)
|
||||||
movesPicked = 0;
|
{
|
||||||
numOfMoves = 0;
|
ttMoves[1].move = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller;
|
||||||
numOfBadCaptures = 0;
|
searchTT |= ttMoves[1].move;
|
||||||
|
killers[0].move = ss->killers[0];
|
||||||
|
killers[1].move = ss->killers[1];
|
||||||
|
} else
|
||||||
|
ttMoves[1].move = killers[0].move = killers[1].move = MOVE_NONE;
|
||||||
|
|
||||||
// With EvalInfo we are able to know how many captures are possible before
|
|
||||||
// generating them. So avoid generating in case we know are zero.
|
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Color them = opposite_color(us);
|
|
||||||
bool noCaptures = ei
|
|
||||||
&& (ei->attackedBy[us][0] & pos.pieces_of_color(them)) == 0
|
|
||||||
&& !ei->mi->specialized_eval_exists()
|
|
||||||
&& (pos.ep_square() == SQ_NONE)
|
|
||||||
&& !pos.has_pawn_on_7th(us);
|
|
||||||
|
|
||||||
if (p.is_check())
|
|
||||||
phaseIndex = EvasionsPhaseIndex;
|
|
||||||
else if (depth > Depth(0))
|
|
||||||
phaseIndex = MainSearchPhaseIndex;
|
|
||||||
else if (depth == Depth(0))
|
|
||||||
phaseIndex = (noCaptures ? QsearchNoCapturesPhaseIndex : QsearchWithChecksPhaseIndex);
|
|
||||||
else
|
|
||||||
phaseIndex = (noCaptures ? NoMovesPhaseIndex : QsearchWithoutChecksPhaseIndex);
|
|
||||||
|
|
||||||
dc = p.discovered_check_candidates(us);
|
dc = p.discovered_check_candidates(us);
|
||||||
pinned = p.pinned_pieces(p.side_to_move());
|
pinned = p.pinned_pieces(us);
|
||||||
|
|
||||||
finished = false;
|
if (p.is_check())
|
||||||
|
phasePtr = EvasionsPhaseTable;
|
||||||
|
else if (d > Depth(0))
|
||||||
|
phasePtr = MainSearchPhaseTable + !searchTT;
|
||||||
|
else if (d == Depth(0))
|
||||||
|
phasePtr = QsearchWithChecksPhaseTable + !searchTT;
|
||||||
|
else
|
||||||
|
phasePtr = QsearchWithoutChecksPhaseTable + !searchTT;
|
||||||
|
|
||||||
|
phasePtr--;
|
||||||
|
go_next_phase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// MovePicker::go_next_phase() generates, scores and sorts the next bunch
|
||||||
|
/// of moves when there are no more moves to try for the current phase.
|
||||||
|
|
||||||
|
void MovePicker::go_next_phase() {
|
||||||
|
|
||||||
|
curMove = moves;
|
||||||
|
phase = *(++phasePtr);
|
||||||
|
switch (phase) {
|
||||||
|
|
||||||
|
case PH_TT_MOVES:
|
||||||
|
curMove = ttMoves;
|
||||||
|
lastMove = curMove + 2;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case PH_GOOD_CAPTURES:
|
||||||
|
lastMove = generate_captures(pos, moves);
|
||||||
|
score_captures();
|
||||||
|
std::sort(moves, lastMove);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case PH_KILLERS:
|
||||||
|
curMove = killers;
|
||||||
|
lastMove = curMove + 2;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case PH_NONCAPTURES:
|
||||||
|
lastMove = generate_noncaptures(pos, moves);
|
||||||
|
score_noncaptures();
|
||||||
|
std::sort(moves, lastMove);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case PH_BAD_CAPTURES:
|
||||||
|
// Bad captures SEE value is already calculated so just sort them
|
||||||
|
// to get SEE move ordering.
|
||||||
|
curMove = badCaptures;
|
||||||
|
lastMove = lastBadCapture;
|
||||||
|
std::sort(badCaptures, lastMove);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case PH_EVASIONS:
|
||||||
|
assert(pos.is_check());
|
||||||
|
lastMove = generate_evasions(pos, moves, pinned);
|
||||||
|
score_evasions();
|
||||||
|
std::sort(moves, lastMove);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case PH_QCAPTURES:
|
||||||
|
lastMove = generate_captures(pos, moves);
|
||||||
|
score_captures();
|
||||||
|
std::sort(moves, lastMove);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case PH_QCHECKS:
|
||||||
|
// Perhaps we should order moves move here? FIXME
|
||||||
|
lastMove = generate_non_capture_checks(pos, moves, dc);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case PH_STOP:
|
||||||
|
lastMove = curMove + 1; // hack to be friendly for get_next_move()
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// MovePicker::score_captures(), MovePicker::score_noncaptures() and
|
||||||
|
/// MovePicker::score_evasions() assign a numerical move ordering score
|
||||||
|
/// to each move in a move list. The moves with highest scores will be
|
||||||
|
/// picked first by get_next_move().
|
||||||
|
|
||||||
|
void MovePicker::score_captures() {
|
||||||
|
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
||||||
|
// Suprisingly, this appears to perform slightly better than SEE based
|
||||||
|
// move ordering. The reason is probably that in a position with a winning
|
||||||
|
// capture, capturing a more valuable (but sufficiently defended) piece
|
||||||
|
// first usually doesn't hurt. The opponent will have to recapture, and
|
||||||
|
// the hanging piece will still be hanging (except in the unusual cases
|
||||||
|
// where it is possible to recapture with the hanging piece). Exchanging
|
||||||
|
// big pieces before capturing a hanging piece probably helps to reduce
|
||||||
|
// the subtree size.
|
||||||
|
// In main search we want to push captures with negative SEE values to
|
||||||
|
// badCaptures[] array, but instead of doing it now we delay till when
|
||||||
|
// the move has been picked up in pick_move_from_list(), this way we save
|
||||||
|
// some SEE calls in case we get a cutoff (idea from Pablo Vazquez).
|
||||||
|
Move m;
|
||||||
|
|
||||||
|
// Use MVV/LVA ordering
|
||||||
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
|
{
|
||||||
|
m = cur->move;
|
||||||
|
if (move_is_promotion(m))
|
||||||
|
cur->score = QueenValueMidgame;
|
||||||
|
else
|
||||||
|
cur->score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
||||||
|
-int(pos.type_of_piece_on(move_from(m)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovePicker::score_noncaptures() {
|
||||||
|
// First score by history, when no history is available then use
|
||||||
|
// piece/square tables values. This seems to be better then a
|
||||||
|
// random choice when we don't have an history for any move.
|
||||||
|
Move m;
|
||||||
|
Piece piece;
|
||||||
|
Square from, to;
|
||||||
|
int hs;
|
||||||
|
|
||||||
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
|
{
|
||||||
|
m = cur->move;
|
||||||
|
from = move_from(m);
|
||||||
|
to = move_to(m);
|
||||||
|
piece = pos.piece_on(from);
|
||||||
|
hs = H.move_ordering_score(piece, to);
|
||||||
|
|
||||||
|
// Ensure history is always preferred to pst
|
||||||
|
if (hs > 0)
|
||||||
|
hs += 1000;
|
||||||
|
|
||||||
|
// pst based scoring
|
||||||
|
cur->score = hs + pos.pst_delta<Position::MidGame>(piece, from, to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovePicker::score_evasions() {
|
||||||
|
|
||||||
|
Move m;
|
||||||
|
|
||||||
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
|
{
|
||||||
|
m = cur->move;
|
||||||
|
if (m == ttMoves[0].move)
|
||||||
|
cur->score = 2 * HistoryMax;
|
||||||
|
else if (!pos.square_is_empty(move_to(m)))
|
||||||
|
{
|
||||||
|
int seeScore = pos.see(m);
|
||||||
|
cur->score = seeScore + (seeScore >= 0 ? HistoryMax : 0);
|
||||||
|
} else
|
||||||
|
cur->score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// MovePicker::get_next_move() is the most important method of the MovePicker
|
/// MovePicker::get_next_move() is the most important method of the MovePicker
|
||||||
/// class. It returns a new legal move every time it is called, until there
|
/// class. It returns a new legal move every time it is called, until there
|
||||||
/// are no more moves left of the types we are interested in.
|
/// are no more moves left.
|
||||||
|
/// It picks the move with the biggest score from a list of generated moves taking
|
||||||
|
/// care not to return the tt move if has already been searched previously.
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
// If we already have a list of generated moves, pick the best move from
|
while (curMove != lastMove)
|
||||||
// the list, and return it.
|
{
|
||||||
move = pick_move_from_list();
|
move = (curMove++)->move;
|
||||||
if (move != MOVE_NONE)
|
|
||||||
{
|
|
||||||
assert(move_is_ok(move));
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next phase
|
switch (phase) {
|
||||||
phaseIndex++;
|
|
||||||
switch (PhaseTable[phaseIndex]) {
|
|
||||||
|
|
||||||
case PH_TT_MOVE:
|
case PH_TT_MOVES:
|
||||||
if (ttMove != MOVE_NONE)
|
if ( move != MOVE_NONE
|
||||||
{
|
&& move_is_legal(pos, move, pinned))
|
||||||
assert(move_is_ok(ttMove));
|
return move;
|
||||||
if (move_is_legal(pos, ttMove, pinned))
|
break;
|
||||||
return ttMove;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_MATE_KILLER:
|
case PH_GOOD_CAPTURES:
|
||||||
if (mateKiller != MOVE_NONE)
|
if ( move != ttMoves[0].move
|
||||||
{
|
&& move != ttMoves[1].move
|
||||||
assert(move_is_ok(mateKiller));
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
if (move_is_legal(pos, mateKiller, pinned))
|
{
|
||||||
return mateKiller;
|
// Check for a non negative SEE now
|
||||||
}
|
int seeValue = pos.see_sign(move);
|
||||||
break;
|
if (seeValue >= 0)
|
||||||
|
return move;
|
||||||
|
|
||||||
case PH_GOOD_CAPTURES:
|
// Losing capture, move it to the badCaptures[] array, note
|
||||||
numOfMoves = generate_captures(pos, moves);
|
// that move has now been already checked for legality.
|
||||||
score_captures();
|
assert(int(lastBadCapture - badCaptures) < 63);
|
||||||
movesPicked = 0;
|
lastBadCapture->move = move;
|
||||||
break;
|
lastBadCapture->score = seeValue;
|
||||||
|
lastBadCapture++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
case PH_KILLERS:
|
||||||
badCapturesPicked = 0;
|
if ( move != MOVE_NONE
|
||||||
break;
|
&& move != ttMoves[0].move
|
||||||
|
&& move != ttMoves[1].move
|
||||||
|
&& move_is_legal(pos, move, pinned)
|
||||||
|
&& !pos.move_is_capture(move))
|
||||||
|
return move;
|
||||||
|
break;
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
numOfMoves = generate_noncaptures(pos, moves);
|
if ( move != ttMoves[0].move
|
||||||
score_noncaptures();
|
&& move != ttMoves[1].move
|
||||||
movesPicked = 0;
|
&& move != killers[0].move
|
||||||
break;
|
&& move != killers[1].move
|
||||||
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
|
return move;
|
||||||
|
break;
|
||||||
|
|
||||||
case PH_EVASIONS:
|
case PH_EVASIONS:
|
||||||
assert(pos.is_check());
|
case PH_BAD_CAPTURES:
|
||||||
numOfMoves = generate_evasions(pos, moves);
|
return move;
|
||||||
score_evasions();
|
|
||||||
movesPicked = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
case PH_QCAPTURES:
|
||||||
numOfMoves = generate_captures(pos, moves);
|
case PH_QCHECKS:
|
||||||
score_qcaptures();
|
// Maybe postpone the legality check until after futility pruning?
|
||||||
movesPicked = 0;
|
if ( move != ttMoves[0].move
|
||||||
break;
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
|
return move;
|
||||||
|
break;
|
||||||
|
|
||||||
case PH_QCHECKS:
|
case PH_STOP:
|
||||||
numOfMoves = generate_checks(pos, moves, dc);
|
return MOVE_NONE;
|
||||||
movesPicked = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_STOP:
|
default:
|
||||||
return MOVE_NONE;
|
assert(false);
|
||||||
|
break;
|
||||||
default:
|
}
|
||||||
assert(false);
|
}
|
||||||
return MOVE_NONE;
|
go_next_phase();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// A variant of get_next_move() which takes a lock as a parameter, used to
|
/// 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.
|
/// prevent multiple threads from picking the same move at a split point.
|
||||||
|
|
||||||
@@ -207,346 +357,3 @@ Move MovePicker::get_next_move(Lock &lock) {
|
|||||||
lock_release(&lock);
|
lock_release(&lock);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::score_captures(), MovePicker::score_noncaptures(),
|
|
||||||
/// MovePicker::score_evasions() and MovePicker::score_qcaptures() assign a
|
|
||||||
/// numerical move ordering score to each move in a move list. The moves
|
|
||||||
/// with highest scores will be picked first by pick_move_from_list().
|
|
||||||
|
|
||||||
void MovePicker::score_captures() {
|
|
||||||
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
|
||||||
// Suprisingly, this appears to perform slightly better than SEE based
|
|
||||||
// move ordering. The reason is probably that in a position with a winning
|
|
||||||
// capture, capturing a more valuable (but sufficiently defended) piece
|
|
||||||
// first usually doesn't hurt. The opponent will have to recapture, and
|
|
||||||
// the hanging piece will still be hanging (except in the unusual cases
|
|
||||||
// where it is possible to recapture with the hanging piece). Exchanging
|
|
||||||
// big pieces before capturing a hanging piece probably helps to reduce
|
|
||||||
// the subtree size.
|
|
||||||
// While scoring captures it moves all captures with negative SEE values
|
|
||||||
// to the badCaptures[] array.
|
|
||||||
Move m;
|
|
||||||
int seeValue;
|
|
||||||
|
|
||||||
for (int i = 0; i < numOfMoves; i++)
|
|
||||||
{
|
|
||||||
m = moves[i].move;
|
|
||||||
seeValue = pos.see(m);
|
|
||||||
if (seeValue >= 0)
|
|
||||||
{
|
|
||||||
if (move_promotion(m))
|
|
||||||
moves[i].score = QueenValueMidgame;
|
|
||||||
else
|
|
||||||
moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
|
||||||
-int(pos.type_of_piece_on(move_from(m)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Losing capture, move it to the badCaptures[] array
|
|
||||||
assert(numOfBadCaptures < 63);
|
|
||||||
moves[i].score = seeValue;
|
|
||||||
badCaptures[numOfBadCaptures++] = moves[i];
|
|
||||||
moves[i--] = moves[--numOfMoves];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MovePicker::score_noncaptures() {
|
|
||||||
// First score by history, when no history is available then use
|
|
||||||
// piece/square tables values. This seems to be better then a
|
|
||||||
// random choice when we don't have an history for any move.
|
|
||||||
Move m;
|
|
||||||
int hs;
|
|
||||||
|
|
||||||
for (int i = 0; i < numOfMoves; i++)
|
|
||||||
{
|
|
||||||
m = moves[i].move;
|
|
||||||
|
|
||||||
if (m == killer1)
|
|
||||||
hs = HistoryMax + 2;
|
|
||||||
else if (m == killer2)
|
|
||||||
hs = HistoryMax + 1;
|
|
||||||
else
|
|
||||||
hs = H.move_ordering_score(pos.piece_on(move_from(m)), m);
|
|
||||||
|
|
||||||
// Ensure history is always preferred to pst
|
|
||||||
if (hs > 0)
|
|
||||||
hs += 1000;
|
|
||||||
|
|
||||||
// pst based scoring
|
|
||||||
moves[i].score = hs + pos.mg_pst_delta(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MovePicker::score_evasions() {
|
|
||||||
|
|
||||||
for (int i = 0; i < numOfMoves; i++)
|
|
||||||
{
|
|
||||||
Move m = moves[i].move;
|
|
||||||
if (m == ttMove)
|
|
||||||
moves[i].score = 2*HistoryMax;
|
|
||||||
else if (!pos.square_is_empty(move_to(m)))
|
|
||||||
{
|
|
||||||
int seeScore = pos.see(m);
|
|
||||||
moves[i].score = (seeScore >= 0)? seeScore + HistoryMax : seeScore;
|
|
||||||
} else
|
|
||||||
moves[i].score = H.move_ordering_score(pos.piece_on(move_from(m)), m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MovePicker::score_qcaptures() {
|
|
||||||
|
|
||||||
// Use MVV/LVA ordering
|
|
||||||
for (int i = 0; i < numOfMoves; i++)
|
|
||||||
{
|
|
||||||
Move m = moves[i].move;
|
|
||||||
if (move_promotion(m))
|
|
||||||
moves[i].score = QueenValueMidgame;
|
|
||||||
else
|
|
||||||
moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
|
||||||
-int(pos.type_of_piece_on(move_from(m)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// find_best_index() loops across the moves and returns index of
|
|
||||||
/// the highest scored one. There is also a second version that
|
|
||||||
/// lowers the priority of moves that attack the same square,
|
|
||||||
/// so that if the best move that attack a square fails the next
|
|
||||||
/// move picked attacks a different square if any, not the same one.
|
|
||||||
|
|
||||||
int MovePicker::find_best_index() {
|
|
||||||
|
|
||||||
int bestScore = -10000000, bestIndex = -1;
|
|
||||||
|
|
||||||
for (int i = movesPicked; i < numOfMoves; i++)
|
|
||||||
if (moves[i].score > bestScore)
|
|
||||||
{
|
|
||||||
bestIndex = i;
|
|
||||||
bestScore = moves[i].score;
|
|
||||||
}
|
|
||||||
return bestIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MovePicker::find_best_index(Bitboard* squares, int values[]) {
|
|
||||||
|
|
||||||
int hs;
|
|
||||||
Move m;
|
|
||||||
Square to;
|
|
||||||
int bestScore = -10000000, bestIndex = -1;
|
|
||||||
|
|
||||||
for (int i = movesPicked; i < numOfMoves; i++)
|
|
||||||
{
|
|
||||||
m = moves[i].move;
|
|
||||||
to = move_to(m);
|
|
||||||
|
|
||||||
if (!bit_is_set(*squares, to))
|
|
||||||
{
|
|
||||||
// Init at first use
|
|
||||||
set_bit(squares, to);
|
|
||||||
values[to] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
hs = moves[i].score - values[to];
|
|
||||||
if (hs > bestScore)
|
|
||||||
{
|
|
||||||
bestIndex = i;
|
|
||||||
bestScore = hs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bestIndex != -1)
|
|
||||||
{
|
|
||||||
// Raise value of the picked square, so next attack
|
|
||||||
// to the same square will get low priority.
|
|
||||||
to = move_to(moves[bestIndex].move);
|
|
||||||
values[to] += 0xB00;
|
|
||||||
}
|
|
||||||
return bestIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::pick_move_from_list() picks the move with the biggest score
|
|
||||||
/// from a list of generated moves (moves[] or badCaptures[], depending on
|
|
||||||
/// the current move generation phase). It takes care not to return the
|
|
||||||
/// transposition table move if that has already been serched previously.
|
|
||||||
|
|
||||||
Move MovePicker::pick_move_from_list() {
|
|
||||||
|
|
||||||
int bestIndex;
|
|
||||||
Move move;
|
|
||||||
|
|
||||||
switch (PhaseTable[phaseIndex]) {
|
|
||||||
case PH_GOOD_CAPTURES:
|
|
||||||
assert(!pos.is_check());
|
|
||||||
assert(movesPicked >= 0);
|
|
||||||
|
|
||||||
while (movesPicked < numOfMoves)
|
|
||||||
{
|
|
||||||
bestIndex = find_best_index();
|
|
||||||
|
|
||||||
if (bestIndex != -1) // Found a good capture
|
|
||||||
{
|
|
||||||
move = moves[bestIndex].move;
|
|
||||||
moves[bestIndex] = moves[movesPicked++];
|
|
||||||
if ( move != ttMove
|
|
||||||
&& move != mateKiller
|
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
|
||||||
assert(!pos.is_check());
|
|
||||||
assert(movesPicked >= 0);
|
|
||||||
|
|
||||||
while (movesPicked < numOfMoves)
|
|
||||||
{
|
|
||||||
// If this is a PV node or we have only picked a few moves, scan
|
|
||||||
// the entire move list for the best move. If many moves have already
|
|
||||||
// been searched and it is not a PV node, we are probably failing low
|
|
||||||
// anyway, so we just pick the first move from the list.
|
|
||||||
bestIndex = (pvNode || movesPicked < 12) ? find_best_index() : movesPicked;
|
|
||||||
|
|
||||||
if (bestIndex != -1)
|
|
||||||
{
|
|
||||||
move = moves[bestIndex].move;
|
|
||||||
moves[bestIndex] = moves[movesPicked++];
|
|
||||||
if ( move != ttMove
|
|
||||||
&& move != mateKiller
|
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_EVASIONS:
|
|
||||||
assert(pos.is_check());
|
|
||||||
assert(movesPicked >= 0);
|
|
||||||
|
|
||||||
while (movesPicked < numOfMoves)
|
|
||||||
{
|
|
||||||
bestIndex = find_best_index();
|
|
||||||
|
|
||||||
if (bestIndex != -1)
|
|
||||||
{
|
|
||||||
move = moves[bestIndex].move;
|
|
||||||
moves[bestIndex] = moves[movesPicked++];
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
|
||||||
assert(!pos.is_check());
|
|
||||||
assert(badCapturesPicked >= 0);
|
|
||||||
// It's probably a good idea to use SEE move ordering here, instead
|
|
||||||
// of just picking the first move. FIXME
|
|
||||||
while (badCapturesPicked < numOfBadCaptures)
|
|
||||||
{
|
|
||||||
move = badCaptures[badCapturesPicked++].move;
|
|
||||||
if ( move != ttMove
|
|
||||||
&& move != mateKiller
|
|
||||||
&& pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
|
||||||
assert(!pos.is_check());
|
|
||||||
assert(movesPicked >= 0);
|
|
||||||
while (movesPicked < numOfMoves)
|
|
||||||
{
|
|
||||||
bestIndex = (movesPicked < 4 ? find_best_index() : movesPicked);
|
|
||||||
|
|
||||||
if (bestIndex != -1)
|
|
||||||
{
|
|
||||||
move = moves[bestIndex].move;
|
|
||||||
moves[bestIndex] = moves[movesPicked++];
|
|
||||||
// Remember to change the line below if we decide to hash the qsearch!
|
|
||||||
// Maybe also postpone the legality check until after futility pruning?
|
|
||||||
if (/* move != ttMove && */ pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_QCHECKS:
|
|
||||||
assert(!pos.is_check());
|
|
||||||
assert(movesPicked >= 0);
|
|
||||||
// Perhaps we should do something better than just picking the first
|
|
||||||
// move here? FIXME
|
|
||||||
while (movesPicked < numOfMoves)
|
|
||||||
{
|
|
||||||
move = moves[movesPicked++].move;
|
|
||||||
// Remember to change the line below if we decide to hash the qsearch!
|
|
||||||
if (/* move != ttMove && */ pos.pl_move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::current_move_type() returns the type of the just
|
|
||||||
/// picked next move. It can be used in search to further differentiate
|
|
||||||
/// according to the current move type: capture, non capture, escape, etc.
|
|
||||||
MovePicker::MovegenPhase MovePicker::current_move_type() const {
|
|
||||||
|
|
||||||
return PhaseTable[phaseIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::init_phase_table() initializes the PhaseTable[],
|
|
||||||
/// MainSearchPhaseIndex, EvasionPhaseIndex, QsearchWithChecksPhaseIndex
|
|
||||||
/// QsearchNoCapturesPhaseIndex, QsearchWithoutChecksPhaseIndex and
|
|
||||||
/// NoMovesPhaseIndex variables. It is only called once during program
|
|
||||||
/// startup, and never again while the program is running.
|
|
||||||
|
|
||||||
void MovePicker::init_phase_table() {
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
// Main search
|
|
||||||
MainSearchPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_TT_MOVE;
|
|
||||||
PhaseTable[i++] = PH_MATE_KILLER;
|
|
||||||
PhaseTable[i++] = PH_GOOD_CAPTURES;
|
|
||||||
// PH_KILLER_1 and PH_KILLER_2 are not yet used.
|
|
||||||
// PhaseTable[i++] = PH_KILLER_1;
|
|
||||||
// PhaseTable[i++] = PH_KILLER_2;
|
|
||||||
PhaseTable[i++] = PH_NONCAPTURES;
|
|
||||||
PhaseTable[i++] = PH_BAD_CAPTURES;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
|
|
||||||
// Check evasions
|
|
||||||
EvasionsPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_EVASIONS;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
|
|
||||||
// Quiescence search with checks
|
|
||||||
QsearchWithChecksPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_QCAPTURES;
|
|
||||||
PhaseTable[i++] = PH_QCHECKS;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
|
|
||||||
// Quiescence search with checks only and no captures
|
|
||||||
QsearchNoCapturesPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_QCHECKS;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
|
|
||||||
// Quiescence search without checks
|
|
||||||
QsearchWithoutChecksPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_QCAPTURES;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
|
|
||||||
// Do not generate any move
|
|
||||||
NoMovesPhaseIndex = i - 1;
|
|
||||||
PhaseTable[i++] = PH_STOP;
|
|
||||||
}
|
|
||||||
|
|||||||
+25
-46
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
|
#include "history.h"
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
|
||||||
@@ -34,12 +35,11 @@
|
|||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
struct EvalInfo;
|
|
||||||
struct SearchStack;
|
struct SearchStack;
|
||||||
|
|
||||||
/// MovePicker is a class which is used to pick one legal move at a time from
|
/// MovePicker is a class which is used to pick one legal move at a time from
|
||||||
/// the current position. It is initialized with a Position object and a few
|
/// the current position. It is initialized with a Position object and a few
|
||||||
/// moves we have reason to believe are good. The most important method is
|
/// moves we have reason to believe are good. The most important method is
|
||||||
/// MovePicker::pick_next_move(), which returns a new legal move each time it
|
/// MovePicker::pick_next_move(), which returns a new legal move each time it
|
||||||
/// is called, until there are no legal moves left, when MOVE_NONE is returned.
|
/// is called, until there are no legal moves left, when MOVE_NONE is returned.
|
||||||
/// In order to improve the efficiency of the alpha beta algorithm, MovePicker
|
/// In order to improve the efficiency of the alpha beta algorithm, MovePicker
|
||||||
@@ -47,51 +47,30 @@ struct SearchStack;
|
|||||||
|
|
||||||
class MovePicker {
|
class MovePicker {
|
||||||
|
|
||||||
|
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);
|
||||||
enum MovegenPhase {
|
|
||||||
PH_TT_MOVE, // Transposition table move
|
|
||||||
PH_MATE_KILLER, // Mate killer from the current ply
|
|
||||||
PH_GOOD_CAPTURES, // Queen promotions and captures with SEE values >= 0
|
|
||||||
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < 0
|
|
||||||
PH_KILLER_1, // Killer move 1 from the current ply (not used yet).
|
|
||||||
PH_KILLER_2, // Killer move 2 from the current ply (not used yet).
|
|
||||||
PH_NONCAPTURES, // Non-captures and underpromotions
|
|
||||||
PH_EVASIONS, // Check evasions
|
|
||||||
PH_QCAPTURES, // Captures in quiescence search
|
|
||||||
PH_QCHECKS, // Checks in quiescence search
|
|
||||||
PH_STOP
|
|
||||||
};
|
|
||||||
|
|
||||||
MovePicker(const Position& p, bool pvnode, Move ttm, const SearchStack& ss, Depth d, EvalInfo* ei = NULL);
|
|
||||||
Move get_next_move();
|
Move get_next_move();
|
||||||
Move get_next_move(Lock &lock);
|
Move get_next_move(Lock& lock);
|
||||||
int number_of_moves() const;
|
int number_of_evasions() const;
|
||||||
int current_move_score() const;
|
|
||||||
MovegenPhase current_move_type() const;
|
|
||||||
Bitboard discovered_check_candidates() const;
|
Bitboard discovered_check_candidates() const;
|
||||||
|
|
||||||
static void init_phase_table();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void score_captures();
|
void score_captures();
|
||||||
void score_noncaptures();
|
void score_noncaptures();
|
||||||
void score_evasions();
|
void score_evasions();
|
||||||
void score_qcaptures();
|
void go_next_phase();
|
||||||
Move pick_move_from_list();
|
|
||||||
int find_best_index();
|
|
||||||
int find_best_index(Bitboard* squares, int values[]);
|
|
||||||
|
|
||||||
const Position& pos;
|
const Position& pos;
|
||||||
Move ttMove, mateKiller, killer1, killer2;
|
const History& H;
|
||||||
Bitboard pinned, dc;
|
MoveStack ttMoves[2], killers[2];
|
||||||
MoveStack moves[256], badCaptures[64];
|
|
||||||
bool pvNode;
|
|
||||||
Depth depth;
|
|
||||||
int phaseIndex;
|
|
||||||
int numOfMoves, numOfBadCaptures;
|
|
||||||
int movesPicked, badCapturesPicked;
|
|
||||||
bool finished;
|
bool finished;
|
||||||
|
int phase;
|
||||||
|
const uint8_t* phasePtr;
|
||||||
|
MoveStack *curMove, *lastMove, *lastBadCapture;
|
||||||
|
Bitboard dc, pinned;
|
||||||
|
MoveStack moves[256], badCaptures[64];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -99,18 +78,18 @@ private:
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// MovePicker::number_of_moves() simply returns the numOfMoves member
|
/// MovePicker::number_of_evasions() simply returns the number of moves in
|
||||||
/// variable. It is intended to be used in positions where the side to move
|
/// evasions phase. It is intended to be used in positions where the side to
|
||||||
/// is in check, for detecting checkmates or situations where there is only
|
/// move is in check, for detecting checkmates or situations where there is
|
||||||
/// a single reply to check.
|
/// only a single reply to check.
|
||||||
|
/// WARNING: It works as long as PH_EVASIONS is the _only_ phase for evasions.
|
||||||
|
|
||||||
inline int MovePicker::number_of_moves() const {
|
inline int MovePicker::number_of_evasions() const {
|
||||||
|
return int(lastMove - moves);
|
||||||
return numOfMoves;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// MovePicker::discovered_check_candidates() returns a bitboard containing
|
/// MovePicker::discovered_check_candidates() returns a bitboard containing
|
||||||
/// all pieces which can possibly give discovered check. This bitboard is
|
/// all pieces which can possibly give discovered check. This bitboard is
|
||||||
/// computed by the constructor function.
|
/// computed by the constructor function.
|
||||||
|
|
||||||
inline Bitboard MovePicker::discovered_check_candidates() const {
|
inline Bitboard MovePicker::discovered_check_candidates() const {
|
||||||
|
|||||||
+264
-242
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -25,7 +25,9 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "bitcount.h"
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
|
#include "position.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -36,100 +38,95 @@ namespace {
|
|||||||
|
|
||||||
/// Constants and variables
|
/// Constants and variables
|
||||||
|
|
||||||
// Doubled pawn penalty by file, middle game.
|
// Doubled pawn penalty by file, middle game
|
||||||
const Value DoubledPawnMidgamePenalty[8] = {
|
const Value DoubledPawnMidgamePenalty[8] = {
|
||||||
Value(20), Value(30), Value(34), Value(34),
|
Value(13), Value(20), Value(23), Value(23),
|
||||||
Value(34), Value(34), Value(30), Value(20)
|
Value(23), Value(23), Value(20), Value(13)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Doubled pawn penalty by file, endgame.
|
// Doubled pawn penalty by file, endgame
|
||||||
const Value DoubledPawnEndgamePenalty[8] = {
|
const Value DoubledPawnEndgamePenalty[8] = {
|
||||||
Value(35), Value(40), Value(40), Value(40),
|
Value(43), Value(48), Value(48), Value(48),
|
||||||
Value(40), Value(40), Value(40), Value(35)
|
Value(48), Value(48), Value(48), Value(43)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Isolated pawn penalty by file, middle game.
|
// Isolated pawn penalty by file, middle game
|
||||||
const Value IsolatedPawnMidgamePenalty[8] = {
|
const Value IsolatedPawnMidgamePenalty[8] = {
|
||||||
Value(20), Value(30), Value(34), Value(34),
|
Value(25), Value(36), Value(40), Value(40),
|
||||||
Value(34), Value(34), Value(30), Value(20)
|
Value(40), Value(40), Value(36), Value(25)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Isolated pawn penalty by file, endgame.
|
// Isolated pawn penalty by file, endgame
|
||||||
const Value IsolatedPawnEndgamePenalty[8] = {
|
const Value IsolatedPawnEndgamePenalty[8] = {
|
||||||
Value(35), Value(40), Value(40), Value(40),
|
Value(30), Value(35), Value(35), Value(35),
|
||||||
Value(40), Value(40), Value(40), Value(35)
|
Value(35), Value(35), Value(35), Value(30)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Backward pawn penalty by file, middle game.
|
// Backward pawn penalty by file, middle game
|
||||||
const Value BackwardPawnMidgamePenalty[8] = {
|
const Value BackwardPawnMidgamePenalty[8] = {
|
||||||
Value(16), Value(24), Value(27), Value(27),
|
Value(20), Value(29), Value(33), Value(33),
|
||||||
Value(27), Value(27), Value(24), Value(16)
|
Value(33), Value(33), Value(29), Value(20)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Backward pawn penalty by file, endgame.
|
// Backward pawn penalty by file, endgame
|
||||||
const Value BackwardPawnEndgamePenalty[8] = {
|
const Value BackwardPawnEndgamePenalty[8] = {
|
||||||
Value(28), Value(32), Value(32), Value(32),
|
Value(28), Value(31), Value(31), Value(31),
|
||||||
Value(32), Value(32), Value(32), Value(28)
|
Value(31), Value(31), Value(31), Value(28)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pawn chain membership bonus by file, middle game.
|
// Pawn chain membership bonus by file, middle game
|
||||||
const Value ChainMidgameBonus[8] = {
|
const Value ChainMidgameBonus[8] = {
|
||||||
Value(14), Value(16), Value(17), Value(18),
|
Value(11), Value(13), Value(13), Value(14),
|
||||||
Value(18), Value(17), Value(16), Value(14)
|
Value(14), Value(13), Value(13), Value(11)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pawn chain membership bonus by file, endgame.
|
// Pawn chain membership bonus by file, endgame
|
||||||
const Value ChainEndgameBonus[8] = {
|
const Value ChainEndgameBonus[8] = {
|
||||||
Value(16), Value(16), Value(16), Value(16),
|
Value(-1), Value(-1), Value(-1), Value(-1),
|
||||||
Value(16), Value(16), Value(16), Value(16)
|
Value(-1), Value(-1), Value(-1), Value(-1)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Candidate passed pawn bonus by rank, middle game.
|
// Candidate passed pawn bonus by rank, middle game
|
||||||
const Value CandidateMidgameBonus[8] = {
|
const Value CandidateMidgameBonus[8] = {
|
||||||
Value(0), Value(12), Value(12), Value(20),
|
Value( 0), Value( 6), Value(6), Value(14),
|
||||||
Value(40), Value(90), Value(0), Value(0)
|
Value(34), Value(83), Value(0), Value( 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Candidate passed pawn bonus by rank, endgame.
|
// Candidate passed pawn bonus by rank, endgame
|
||||||
const Value CandidateEndgameBonus[8] = {
|
const Value CandidateEndgameBonus[8] = {
|
||||||
Value(0), Value(24), Value(24), Value(40),
|
Value( 0), Value( 13), Value(13), Value(29),
|
||||||
Value(80), Value(180), Value(0), Value(0)
|
Value(68), Value(166), Value( 0), Value( 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Evaluate pawn storms?
|
// Pawn storm tables for positions with opposite castling
|
||||||
const bool EvaluatePawnStorms = true;
|
|
||||||
|
|
||||||
// Pawn storm tables for positions with opposite castling:
|
|
||||||
const int QStormTable[64] = {
|
const int QStormTable[64] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
-22, -22, -22, -13, -4, 0, 0, 0,
|
-22,-22,-22,-14,-6, 0, 0, 0,
|
||||||
-4, -9, -9, -9, -4, 0, 0, 0,
|
-6,-10,-10,-10,-6, 0, 0, 0,
|
||||||
9, 18, 22, 18, 9, 0, 0, 0,
|
4, 12, 16, 12, 4, 0, 0, 0,
|
||||||
22, 31, 31, 22, 0, 0, 0, 0,
|
16, 23, 23, 16, 0, 0, 0, 0,
|
||||||
31, 40, 40, 31, 0, 0, 0, 0,
|
23, 31, 31, 23, 0, 0, 0, 0,
|
||||||
31, 40, 40, 31, 0, 0, 0, 0,
|
23, 31, 31, 23, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const int KStormTable[64] = {
|
const int KStormTable[64] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, -4, -13, -22, -27, -27,
|
0, 0, 0,-10,-19,-28,-33,-33,
|
||||||
0, 0, 0, -4, -9, -13, -18, -18,
|
0, 0, 0,-10,-15,-19,-24,-24,
|
||||||
0, 0, 0, 0, 9, 9, 9, 9,
|
0, 0, 0, 0, 1, 1, 1, 1,
|
||||||
0, 0, 0, 0, 9, 18, 27, 27,
|
0, 0, 0, 0, 1, 10, 19, 19,
|
||||||
0, 0, 0, 0, 9, 27, 40, 36,
|
0, 0, 0, 0, 1, 19, 31, 27,
|
||||||
0, 0, 0, 0, 0, 31, 40, 31,
|
0, 0, 0, 0, 0, 22, 31, 22,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pawn storm open file bonuses by file:
|
// Pawn storm open file bonuses by file
|
||||||
const int KStormOpenFileBonus[8] = {
|
const int16_t KStormOpenFileBonus[8] = { 31, 31, 18, 0, 0, 0, 0, 0 };
|
||||||
45, 45, 30, 0, 0, 0, 0, 0
|
const int16_t QStormOpenFileBonus[8] = { 0, 0, 0, 0, 0, 26, 42, 26 };
|
||||||
};
|
|
||||||
|
|
||||||
const int QStormOpenFileBonus[8] = {
|
// Pawn storm lever bonuses by file
|
||||||
0, 0, 0, 0, 0, 30, 45, 30
|
const int StormLeverBonus[8] = { -8, -8, -13, 0, 0, -13, -8, -8 };
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,14 +138,15 @@ namespace {
|
|||||||
/// Constructor
|
/// Constructor
|
||||||
|
|
||||||
PawnInfoTable::PawnInfoTable(unsigned numOfEntries) {
|
PawnInfoTable::PawnInfoTable(unsigned numOfEntries) {
|
||||||
|
|
||||||
size = numOfEntries;
|
size = numOfEntries;
|
||||||
entries = new PawnInfo[size];
|
entries = new PawnInfo[size];
|
||||||
if(entries == NULL) {
|
if (!entries)
|
||||||
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(PawnInfo))
|
{
|
||||||
<< " bytes for pawn hash table." << std::endl;
|
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(PawnInfo))
|
||||||
exit(EXIT_FAILURE);
|
<< " bytes for pawn hash table." << std::endl;
|
||||||
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
this->clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -159,229 +157,253 @@ PawnInfoTable::~PawnInfoTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// PawnInfoTable::clear() clears the pawn hash table by setting all
|
/// PawnInfo::clear() resets to zero the PawnInfo entry. Note that
|
||||||
/// entries to 0.
|
/// kingSquares[] is initialized to SQ_NONE instead.
|
||||||
|
|
||||||
void PawnInfoTable::clear() {
|
void PawnInfo::clear() {
|
||||||
memset(entries, 0, size * sizeof(PawnInfo));
|
|
||||||
|
memset(this, 0, sizeof(PawnInfo));
|
||||||
|
kingSquares[WHITE] = kingSquares[BLACK] = SQ_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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 in a hash table, so we don't have to recompute everything when
|
/// stored in a hash table, so we don't have to recompute everything when
|
||||||
/// the same pawn structure occurs again.
|
/// the same pawn structure occurs again.
|
||||||
|
|
||||||
PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
Key key = pos.get_pawn_key();
|
Key key = pos.get_pawn_key();
|
||||||
int index = int(key & (size - 1));
|
int index = int(key & (size - 1));
|
||||||
PawnInfo *pi = entries + index;
|
PawnInfo* pi = entries + index;
|
||||||
|
|
||||||
// If pi->key matches the position's pawn hash key, it means that we
|
// If pi->key matches the position's pawn hash key, it means that we
|
||||||
// have analysed this pawn structure before, and we can simply return the
|
// have analysed this pawn structure before, and we can simply return
|
||||||
// information we found the last time instead of recomputing it:
|
// the information we found the last time instead of recomputing it.
|
||||||
if(pi->key == key)
|
if (pi->key == key)
|
||||||
return pi;
|
return pi;
|
||||||
|
|
||||||
// Clear the PawnInfo object, and set the key:
|
// Clear the PawnInfo object, and set the key
|
||||||
pi->clear();
|
pi->clear();
|
||||||
pi->key = key;
|
pi->key = key;
|
||||||
|
|
||||||
Value mgValue[2] = {Value(0), Value(0)};
|
Value mgValue[2] = {Value(0), Value(0)};
|
||||||
Value egValue[2] = {Value(0), Value(0)};
|
Value egValue[2] = {Value(0), Value(0)};
|
||||||
|
|
||||||
// Loop through the pawns for both colors:
|
// Calculate pawn attacks
|
||||||
for(Color us = WHITE; us <= BLACK; us++) {
|
pi->pawnAttacks[WHITE] = ((pos.pieces(PAWN, WHITE) << 9) & ~FileABB) | ((pos.pieces(PAWN, WHITE) << 7) & ~FileHBB);
|
||||||
|
pi->pawnAttacks[BLACK] = ((pos.pieces(PAWN, BLACK) >> 7) & ~FileABB) | ((pos.pieces(PAWN, BLACK) >> 9) & ~FileHBB);
|
||||||
|
|
||||||
|
// Loop through the pawns for both colors
|
||||||
|
for (Color us = WHITE; us <= BLACK; us++)
|
||||||
|
{
|
||||||
Color them = opposite_color(us);
|
Color them = opposite_color(us);
|
||||||
Bitboard ourPawns = pos.pawns(us);
|
Bitboard ourPawns = pos.pieces(PAWN, us);
|
||||||
Bitboard theirPawns = pos.pawns(them);
|
Bitboard theirPawns = pos.pieces(PAWN, them);
|
||||||
Bitboard pawns = ourPawns;
|
Bitboard pawns = ourPawns;
|
||||||
|
|
||||||
// Initialize pawn storm scores by giving bonuses for open files:
|
// Initialize pawn storm scores by giving bonuses for open files
|
||||||
if(EvaluatePawnStorms)
|
for (File f = FILE_A; f <= FILE_H; f++)
|
||||||
for(File f = FILE_A; f <= FILE_H; f++)
|
if (!(pawns & file_bb(f)))
|
||||||
if(pos.file_is_half_open(us, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 (pawns)
|
||||||
Square s = pop_1st_bit(&pawns);
|
{
|
||||||
File f = square_file(s);
|
Square s = pop_1st_bit(&pawns);
|
||||||
Rank r = square_rank(s);
|
File f = square_file(s);
|
||||||
bool passed, doubled, isolated, backward, chain, candidate;
|
Rank r = square_rank(s);
|
||||||
int bonus;
|
|
||||||
|
|
||||||
assert(pos.piece_on(s) == pawn_of_color(us));
|
assert(pos.piece_on(s) == piece_of_color_and_type(us, PAWN));
|
||||||
|
|
||||||
// The file containing the pawn is not half open:
|
// Passed, isolated or doubled pawn?
|
||||||
pi->halfOpenFiles[us] &= ~(1 << f);
|
bool passed = Position::pawn_is_passed(theirPawns, us, s);
|
||||||
|
bool isolated = Position::pawn_is_isolated(ourPawns, s);
|
||||||
|
bool doubled = Position::pawn_is_doubled(ourPawns, us, s);
|
||||||
|
|
||||||
// Passed, isolated or doubled pawn?
|
|
||||||
passed = pos.pawn_is_passed(us, s);
|
|
||||||
isolated = pos.pawn_is_isolated(us, s);
|
|
||||||
doubled = pos.pawn_is_doubled(us, s);
|
|
||||||
|
|
||||||
if(EvaluatePawnStorms) {
|
|
||||||
// We calculate kingside and queenside pawn storm
|
// We calculate kingside and queenside pawn storm
|
||||||
// scores for both colors. These are used when evaluating
|
// scores for both colors. These are used when evaluating
|
||||||
// middle game positions with opposite side castling.
|
// middle game positions with opposite side castling.
|
||||||
//
|
//
|
||||||
// Each pawn is given a base score given by a piece square table
|
// Each pawn is given a base score given by a piece square table
|
||||||
// (KStormTable[] or QStormTable[]). This score is increased if
|
// (KStormTable[] or QStormTable[]). Pawns which seem to have good
|
||||||
// there are enemy pawns on adjacent files in front of the pawn.
|
// chances of creating an open file by exchanging itself against an
|
||||||
// This is because we want to be able to open files against the
|
// enemy pawn on an adjacent file gets an additional bonus.
|
||||||
// enemy king, and to avoid blocking the pawn structure (e.g. white
|
|
||||||
// pawns on h6, g5, black pawns on h7, g6, f7).
|
|
||||||
|
|
||||||
// Kingside pawn storms:
|
|
||||||
bonus = KStormTable[relative_square(us, s)];
|
|
||||||
if(bonus > 0 && outpost_mask(us, s) & theirPawns) {
|
|
||||||
switch(f) {
|
|
||||||
|
|
||||||
case FILE_F:
|
// Kingside pawn storms
|
||||||
bonus += bonus / 4;
|
int bonus = KStormTable[relative_square(us, s)];
|
||||||
break;
|
if (f >= FILE_F)
|
||||||
|
{
|
||||||
case FILE_G:
|
Bitboard b = outpost_mask(us, s) & theirPawns & (FileFBB | FileGBB | FileHBB);
|
||||||
bonus += bonus / 2 + bonus / 4;
|
while (b)
|
||||||
break;
|
{
|
||||||
|
Square s2 = pop_1st_bit(&b);
|
||||||
case FILE_H:
|
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||||
bonus += bonus / 2;
|
{
|
||||||
break;
|
// The enemy pawn has no pawn beside itself, which makes it
|
||||||
|
// particularly vulnerable. Big bonus, especially against a
|
||||||
default:
|
// weakness on the rook file.
|
||||||
break;
|
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;
|
pi->ksStormValue[us] += bonus;
|
||||||
|
|
||||||
// Queenside pawn storms:
|
// Queenside pawn storms
|
||||||
bonus = QStormTable[relative_square(us, s)];
|
bonus = QStormTable[relative_square(us, s)];
|
||||||
if(bonus > 0 && passed_pawn_mask(us, s) & theirPawns) {
|
if (f <= FILE_C)
|
||||||
switch(f) {
|
{
|
||||||
|
Bitboard b = outpost_mask(us, s) & theirPawns & (FileABB | FileBBB | FileCBB);
|
||||||
case FILE_A:
|
while (b)
|
||||||
bonus += bonus / 2;
|
{
|
||||||
break;
|
Square s2 = pop_1st_bit(&b);
|
||||||
|
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||||
case FILE_B:
|
{
|
||||||
bonus += bonus / 2 + bonus / 4;
|
// The enemy pawn has no pawn beside itself, which makes it
|
||||||
break;
|
// particularly vulnerable. Big bonus, especially against a
|
||||||
|
// weakness on the rook file.
|
||||||
case FILE_C:
|
if (square_file(s2) == FILE_A)
|
||||||
bonus += bonus / 2;
|
bonus += 4*StormLeverBonus[f] - 16*square_distance(s, s2);
|
||||||
break;
|
else
|
||||||
|
bonus += 2*StormLeverBonus[f] - 8*square_distance(s, s2);
|
||||||
default:
|
} else
|
||||||
break;
|
// 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;
|
pi->qsStormValue[us] += bonus;
|
||||||
}
|
|
||||||
|
|
||||||
// Member of a pawn chain? 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.
|
|
||||||
chain = (us == WHITE)?
|
|
||||||
(ourPawns & neighboring_files_bb(f) & (rank_bb(r) | rank_bb(r-1))) :
|
|
||||||
(ourPawns & neighboring_files_bb(f) & (rank_bb(r) | rank_bb(r+1)));
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
//
|
||||||
// If the pawn is isolated, passed, or member of a pawn chain, it cannot
|
// If the pawn is passed, isolated, or member of a pawn chain
|
||||||
// be backward:
|
// it cannot be backward. If can capture an enemy pawn or if
|
||||||
if(passed || isolated || chain)
|
// there are friendly pawns behind on neighboring files it cannot
|
||||||
backward = false;
|
// be backward either.
|
||||||
// If the pawn can capture an enemy pawn, it's not backward:
|
bool backward;
|
||||||
else if(pos.pawn_attacks(us, s) & theirPawns)
|
if ( passed
|
||||||
backward = false;
|
|| isolated
|
||||||
// Check for friendly pawns behind on neighboring files:
|
|| chain
|
||||||
else if(ourPawns & in_front_bb(them, r) & neighboring_files_bb(f))
|
|| (pos.attacks_from<PAWN>(s, us) & theirPawns)
|
||||||
backward = false;
|
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
|
||||||
else {
|
backward = false;
|
||||||
// We now know that there is no friendly pawns beside or behind this
|
else
|
||||||
// pawn on neighboring files. We now check whether the pawn is
|
{
|
||||||
// backward by looking in the forward direction on the neighboring
|
// We now know that there are no friendly pawns beside or behind this
|
||||||
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
// pawn on neighboring files. We now check whether the pawn is
|
||||||
Bitboard b;
|
// backward by looking in the forward direction on the neighboring
|
||||||
if(us == WHITE) {
|
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
||||||
for(b=pos.pawn_attacks(us, s); !(b&(ourPawns|theirPawns)); b<<=8);
|
Bitboard b = pos.attacks_from<PAWN>(s, us);
|
||||||
backward = (b | (b << 8)) & theirPawns;
|
if (us == WHITE)
|
||||||
|
{
|
||||||
|
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
|
||||||
|
backward = (b | (b << 8)) & theirPawns;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( ; !(b & (ourPawns | theirPawns)); b >>= 8);
|
||||||
|
backward = (b | (b >> 8)) & theirPawns;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
for(b=pos.pawn_attacks(us, s); !(b&(ourPawns|theirPawns)); b>>=8);
|
// Test for candidate passed pawn
|
||||||
backward = (b | (b >> 8)) & theirPawns;
|
bool candidate;
|
||||||
|
candidate = !passed
|
||||||
|
&& !(theirPawns & file_bb(f))
|
||||||
|
&& ( 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
|
||||||
|
// bonus, only the frontmost passed pawn on each file is considered as
|
||||||
|
// a true passed pawn.
|
||||||
|
if (passed && (ourPawns & squares_in_front_of(us, s)))
|
||||||
|
passed = false;
|
||||||
|
|
||||||
|
// Score this pawn
|
||||||
|
if (passed)
|
||||||
|
set_bit(&(pi->passedPawns), s);
|
||||||
|
|
||||||
|
if (isolated)
|
||||||
|
{
|
||||||
|
mgValue[us] -= IsolatedPawnMidgamePenalty[f];
|
||||||
|
egValue[us] -= IsolatedPawnEndgamePenalty[f];
|
||||||
|
if (!(theirPawns & file_bb(f)))
|
||||||
|
{
|
||||||
|
mgValue[us] -= IsolatedPawnMidgamePenalty[f] / 2;
|
||||||
|
egValue[us] -= IsolatedPawnEndgamePenalty[f] / 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (doubled)
|
||||||
|
{
|
||||||
// Test for candidate passed pawn.
|
mgValue[us] -= DoubledPawnMidgamePenalty[f];
|
||||||
candidate =
|
egValue[us] -= DoubledPawnEndgamePenalty[f];
|
||||||
(!passed && pos.file_is_half_open(them, f) &&
|
|
||||||
count_1s_max_15(neighboring_files_bb(f)
|
|
||||||
& (in_front_bb(them, 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
|
|
||||||
// bonus, only the frontmost passed pawn on each file is considered as
|
|
||||||
// a true passed pawn.
|
|
||||||
if(passed && (ourPawns & squares_in_front_of(us, s))) {
|
|
||||||
// candidate = true;
|
|
||||||
passed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Score this pawn:
|
|
||||||
Value mv = Value(0), ev = Value(0);
|
|
||||||
if(isolated) {
|
|
||||||
mv -= IsolatedPawnMidgamePenalty[f];
|
|
||||||
ev -= IsolatedPawnEndgamePenalty[f];
|
|
||||||
if(pos.file_is_half_open(them, f)) {
|
|
||||||
mv -= IsolatedPawnMidgamePenalty[f] / 2;
|
|
||||||
ev -= IsolatedPawnEndgamePenalty[f] / 2;
|
|
||||||
}
|
}
|
||||||
}
|
if (backward)
|
||||||
if(doubled) {
|
{
|
||||||
mv -= DoubledPawnMidgamePenalty[f];
|
mgValue[us] -= BackwardPawnMidgamePenalty[f];
|
||||||
ev -= DoubledPawnEndgamePenalty[f];
|
egValue[us] -= BackwardPawnEndgamePenalty[f];
|
||||||
}
|
if (!(theirPawns & file_bb(f)))
|
||||||
if(backward) {
|
{
|
||||||
mv -= BackwardPawnMidgamePenalty[f];
|
mgValue[us] -= BackwardPawnMidgamePenalty[f] / 2;
|
||||||
ev -= BackwardPawnEndgamePenalty[f];
|
egValue[us] -= BackwardPawnEndgamePenalty[f] / 2;
|
||||||
if(pos.file_is_half_open(them, f)) {
|
}
|
||||||
mv -= BackwardPawnMidgamePenalty[f] / 2;
|
|
||||||
ev -= BackwardPawnEndgamePenalty[f] / 2;
|
|
||||||
}
|
}
|
||||||
}
|
if (chain)
|
||||||
if(chain) {
|
{
|
||||||
mv += ChainMidgameBonus[f];
|
mgValue[us] += ChainMidgameBonus[f];
|
||||||
ev += ChainEndgameBonus[f];
|
egValue[us] += ChainEndgameBonus[f];
|
||||||
}
|
}
|
||||||
if(candidate) {
|
if (candidate)
|
||||||
mv += CandidateMidgameBonus[relative_rank(us, s)];
|
{
|
||||||
ev += CandidateEndgameBonus[relative_rank(us, s)];
|
mgValue[us] += CandidateMidgameBonus[relative_rank(us, s)];
|
||||||
}
|
egValue[us] += CandidateEndgameBonus[relative_rank(us, s)];
|
||||||
|
}
|
||||||
mgValue[us] += mv;
|
} // while(pawns)
|
||||||
egValue[us] += ev;
|
} // for(colors)
|
||||||
|
|
||||||
// If the pawn is passed, set the square of the pawn in the passedPawns
|
|
||||||
// bitboard:
|
|
||||||
if(passed)
|
|
||||||
set_bit(&(pi->passedPawns), s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pi->mgValue = int16_t(mgValue[WHITE] - mgValue[BLACK]);
|
pi->mgValue = int16_t(mgValue[WHITE] - mgValue[BLACK]);
|
||||||
pi->egValue = int16_t(egValue[WHITE] - egValue[BLACK]);
|
pi->egValue = int16_t(egValue[WHITE] - egValue[BLACK]);
|
||||||
|
|
||||||
return pi;
|
return pi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// PawnInfo::updateShelter calculates and caches king shelter. It is called
|
||||||
|
/// only when king square changes, about 20% of total get_king_shelter() calls.
|
||||||
|
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);
|
||||||
|
unsigned r = ksq & (7 << 3);
|
||||||
|
for (int i = 1, k = (c ? -8 : 8); i < 4; i++)
|
||||||
|
{
|
||||||
|
r += k;
|
||||||
|
shelter += BitCount8Bit[(pawns >> r) & 0xFF] * (128 >> i);
|
||||||
|
}
|
||||||
|
kingSquares[c] = ksq;
|
||||||
|
kingShelters[c] = shelter;
|
||||||
|
return shelter;
|
||||||
|
}
|
||||||
|
|||||||
+33
-27
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -25,45 +25,53 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include "position.h"
|
#include "bitboard.h"
|
||||||
|
#include "value.h"
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
/// PawnInfo is a class which contains various information about a pawn
|
/// PawnInfo is a class which contains various information about a pawn
|
||||||
/// structure. Currently, it only includes a middle game and an end game
|
/// structure. Currently, it only includes a middle game and an end game
|
||||||
/// pawn structure evaluation, and a bitboard of passed pawns. We may want
|
/// pawn structure evaluation, and a bitboard of passed pawns. We may want
|
||||||
/// to add further information in the future. A lookup to the pawn hash table
|
/// to add further information in the future. A lookup to the pawn hash table
|
||||||
/// (performed by calling the get_pawn_info method in a PawnInfoTable object)
|
/// (performed by calling the get_pawn_info method in a PawnInfoTable object)
|
||||||
/// returns a pointer to a PawnInfo object.
|
/// returns a pointer to a PawnInfo object.
|
||||||
|
class Position;
|
||||||
|
|
||||||
class PawnInfo {
|
class PawnInfo {
|
||||||
|
|
||||||
friend class PawnInfoTable;
|
friend class PawnInfoTable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
PawnInfo() { clear(); }
|
||||||
|
|
||||||
Value mg_value() const;
|
Value mg_value() const;
|
||||||
Value eg_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 passed_pawns() const;
|
Bitboard passed_pawns() const;
|
||||||
bool file_is_half_open(Color c, File f) const;
|
int file_is_half_open(Color c, File f) const;
|
||||||
bool has_open_file_to_left(Color c, File f) const;
|
int has_open_file_to_left(Color c, File f) const;
|
||||||
bool has_open_file_to_right(Color c, File f) const;
|
int has_open_file_to_right(Color c, File f) const;
|
||||||
|
int get_king_shelter(const Position& pos, Color c, Square ksq);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clear();
|
void clear();
|
||||||
|
int updateShelter(const Position& pos, Color c, Square ksq);
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
Bitboard passedPawns;
|
Bitboard passedPawns;
|
||||||
|
Bitboard pawnAttacks[2];
|
||||||
int16_t mgValue, egValue;
|
int16_t mgValue, egValue;
|
||||||
int8_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];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// The PawnInfoTable class represents a pawn hash table. It is basically
|
/// The PawnInfoTable class represents a pawn hash table. It is basically
|
||||||
/// just an array of PawnInfo objects and a few methods for accessing these
|
/// just an array of PawnInfo objects and a few methods for accessing these
|
||||||
/// objects. The most important method is get_pawn_info, which looks up a
|
/// objects. The most important method is get_pawn_info, which looks up a
|
||||||
@@ -74,12 +82,11 @@ class PawnInfoTable {
|
|||||||
public:
|
public:
|
||||||
PawnInfoTable(unsigned numOfEntries);
|
PawnInfoTable(unsigned numOfEntries);
|
||||||
~PawnInfoTable();
|
~PawnInfoTable();
|
||||||
void clear();
|
PawnInfo* get_pawn_info(const Position& pos);
|
||||||
PawnInfo *get_pawn_info(const Position &pos);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned size;
|
unsigned size;
|
||||||
PawnInfo *entries;
|
PawnInfo* entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -99,6 +106,10 @@ inline Bitboard PawnInfo::passed_pawns() const {
|
|||||||
return passedPawns;
|
return passedPawns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Bitboard PawnInfo::pawn_attacks(Color c) const {
|
||||||
|
return pawnAttacks[c];
|
||||||
|
}
|
||||||
|
|
||||||
inline Value PawnInfo::kingside_storm_value(Color c) const {
|
inline Value PawnInfo::kingside_storm_value(Color c) const {
|
||||||
return Value(ksStormValue[c]);
|
return Value(ksStormValue[c]);
|
||||||
}
|
}
|
||||||
@@ -107,25 +118,20 @@ inline Value PawnInfo::queenside_storm_value(Color c) const {
|
|||||||
return Value(qsStormValue[c]);
|
return Value(qsStormValue[c]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool PawnInfo::file_is_half_open(Color c, File f) const {
|
inline int PawnInfo::file_is_half_open(Color c, File f) const {
|
||||||
return (halfOpenFiles[c] & (1 << int(f)));
|
return (halfOpenFiles[c] & (1 << int(f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool PawnInfo::has_open_file_to_left(Color c, File f) const {
|
inline int PawnInfo::has_open_file_to_left(Color c, File f) const {
|
||||||
return halfOpenFiles[c] & ((1 << int(f)) - 1);
|
return halfOpenFiles[c] & ((1 << int(f)) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool PawnInfo::has_open_file_to_right(Color c, File f) const {
|
inline int PawnInfo::has_open_file_to_right(Color c, File f) const {
|
||||||
return halfOpenFiles[c] & ~((1 << int(f+1)) - 1);
|
return halfOpenFiles[c] & ~((1 << int(f+1)) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PawnInfo::clear() {
|
inline int PawnInfo::get_king_shelter(const Position& pos, Color c, Square ksq) {
|
||||||
mgValue = egValue = 0;
|
return (kingSquares[c] == ksq ? kingShelters[c] : updateShelter(pos, c, ksq));
|
||||||
passedPawns = EmptyBoardBB;
|
|
||||||
ksStormValue[WHITE] = ksStormValue[BLACK] = 0;
|
|
||||||
qsStormValue[WHITE] = qsStormValue[BLACK] = 0;
|
|
||||||
halfOpenFiles[WHITE] = halfOpenFiles[BLACK] = 0xFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(PAWNS_H_INCLUDED)
|
#endif // !defined(PAWNS_H_INCLUDED)
|
||||||
|
|||||||
+13
-59
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -22,74 +22,28 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include <cstring>
|
#include <string>
|
||||||
|
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
////
|
|
||||||
//// Constants and variables
|
|
||||||
////
|
|
||||||
|
|
||||||
const int SlidingArray[18] = {
|
|
||||||
0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
const SquareDelta Directions[16][16] = {
|
|
||||||
{DELTA_ZERO},
|
|
||||||
{DELTA_NW, DELTA_NE, DELTA_ZERO},
|
|
||||||
{DELTA_SSW, DELTA_SSE, DELTA_SWW, DELTA_SEE,
|
|
||||||
DELTA_NWW, DELTA_NEE, DELTA_NNW, DELTA_NNE, DELTA_ZERO},
|
|
||||||
{DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
|
|
||||||
{DELTA_S, DELTA_E, DELTA_W, DELTA_N, DELTA_ZERO},
|
|
||||||
{DELTA_S, DELTA_E, DELTA_W, DELTA_N,
|
|
||||||
DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
|
|
||||||
{DELTA_S, DELTA_E, DELTA_W, DELTA_N,
|
|
||||||
DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
|
|
||||||
{DELTA_ZERO},
|
|
||||||
{DELTA_ZERO},
|
|
||||||
{DELTA_SW, DELTA_SE, DELTA_ZERO},
|
|
||||||
{DELTA_SSW, DELTA_SSE, DELTA_SWW, DELTA_SEE,
|
|
||||||
DELTA_NWW, DELTA_NEE, DELTA_NNW, DELTA_NNE, DELTA_ZERO},
|
|
||||||
{DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
|
|
||||||
{DELTA_S, DELTA_E, DELTA_W, DELTA_N, DELTA_ZERO},
|
|
||||||
{DELTA_S, DELTA_E, DELTA_W, DELTA_N,
|
|
||||||
DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
|
|
||||||
{DELTA_S, DELTA_E, DELTA_W, DELTA_N,
|
|
||||||
DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
|
|
||||||
};
|
|
||||||
|
|
||||||
const SquareDelta PawnPush[2] = {
|
|
||||||
DELTA_N, DELTA_S
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// Translating piece types to/from English piece letters:
|
/// Translating piece types to/from English piece letters
|
||||||
|
|
||||||
static const char PieceChars[] = " pnbrqk";
|
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 upcase? toupper(PieceChars[pt]) : PieceChars[pt];
|
|
||||||
|
return PieceChars[pt + upcase * 7];
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceType piece_type_from_char(char c) {
|
PieceType piece_type_from_char(char c) {
|
||||||
const char *ch = strchr(PieceChars, tolower(c));
|
|
||||||
return ch? PieceType(ch - PieceChars) : NO_PIECE_TYPE;
|
size_t idx = PieceChars.find(c);
|
||||||
}
|
|
||||||
|
return idx != string::npos ? PieceType(idx % 7) : NO_PIECE_TYPE;
|
||||||
|
|
||||||
/// piece_is_ok() and piece_type_is_ok(), for debugging:
|
|
||||||
|
|
||||||
bool piece_is_ok(Piece pc) {
|
|
||||||
return
|
|
||||||
piece_type_is_ok(type_of_piece(pc)) &&
|
|
||||||
color_is_ok(color_of_piece(pc));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool piece_type_is_ok(PieceType pc) {
|
|
||||||
return pc >= PAWN && pc <= KING;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-45
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -21,16 +21,15 @@
|
|||||||
#if !defined(PIECE_H_INCLUDED)
|
#if !defined(PIECE_H_INCLUDED)
|
||||||
#define PIECE_H_INCLUDED
|
#define PIECE_H_INCLUDED
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "misc.h"
|
|
||||||
#include "square.h"
|
#include "square.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
@@ -47,18 +46,15 @@ enum Piece {
|
|||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Constants and variables
|
//// Constants
|
||||||
////
|
////
|
||||||
|
|
||||||
const PieceType PieceTypeMin = PAWN;
|
const int SlidingArray[18] = {
|
||||||
const PieceType PieceTypeMax = KING;
|
0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0
|
||||||
|
};
|
||||||
extern const int SlidingArray[18];
|
|
||||||
extern const SquareDelta Directions[16][16];
|
|
||||||
extern const SquareDelta PawnPush[2];
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
@@ -83,42 +79,22 @@ inline Piece piece_of_color_and_type(Color c, PieceType pt) {
|
|||||||
return Piece((int(c) << 3) | int(pt));
|
return Piece((int(c) << 3) | int(pt));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Piece pawn_of_color(Color c) {
|
|
||||||
return piece_of_color_and_type(c, PAWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Piece knight_of_color(Color c) {
|
|
||||||
return piece_of_color_and_type(c, KNIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Piece bishop_of_color(Color c) {
|
|
||||||
return piece_of_color_and_type(c, BISHOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Piece rook_of_color(Color c) {
|
|
||||||
return piece_of_color_and_type(c, ROOK);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Piece queen_of_color(Color c) {
|
|
||||||
return piece_of_color_and_type(c, QUEEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Piece king_of_color(Color c) {
|
|
||||||
return piece_of_color_and_type(c, KING);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int piece_is_slider(Piece p) {
|
inline int piece_is_slider(Piece p) {
|
||||||
return SlidingArray[int(p)];
|
return SlidingArray[int(p)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int piece_type_is_slider(PieceType pt) {
|
inline SquareDelta pawn_push(Color c) {
|
||||||
return SlidingArray[int(pt)];
|
return (c == WHITE ? DELTA_N : DELTA_S);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline SquareDelta pawn_push(Color c) {
|
inline bool piece_type_is_ok(PieceType pc) {
|
||||||
return PawnPush[c];
|
return pc >= PAWN && pc <= KING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool piece_is_ok(Piece pc) {
|
||||||
|
return piece_type_is_ok(type_of_piece(pc)) && color_is_ok(color_of_piece(pc));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Prototypes
|
//// Prototypes
|
||||||
@@ -126,8 +102,6 @@ inline SquareDelta pawn_push(Color c) {
|
|||||||
|
|
||||||
extern char piece_type_to_char(PieceType pt, bool upcase = false);
|
extern char piece_type_to_char(PieceType pt, bool upcase = false);
|
||||||
extern PieceType piece_type_from_char(char c);
|
extern PieceType piece_type_from_char(char c);
|
||||||
extern bool piece_is_ok(Piece pc);
|
|
||||||
extern bool piece_type_is_ok(PieceType pt);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(PIECE_H_INCLUDED)
|
#endif // !defined(PIECE_H_INCLUDED)
|
||||||
|
|||||||
+745
-1002
File diff suppressed because it is too large
Load Diff
+158
-285
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,12 +21,16 @@
|
|||||||
#if !defined(POSITION_H_INCLUDED)
|
#if !defined(POSITION_H_INCLUDED)
|
||||||
#define POSITION_H_INCLUDED
|
#define POSITION_H_INCLUDED
|
||||||
|
|
||||||
// Disable a silly and noisy warning from MSVC compiler
|
// Disable some silly and noisy warning from MSVC compiler
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
// Forcing value to bool 'true' or 'false' (performance warning)
|
// Forcing value to bool 'true' or 'false' (performance warning)
|
||||||
#pragma warning(disable: 4800)
|
#pragma warning(disable: 4800)
|
||||||
|
|
||||||
|
// Conditional expression is constant
|
||||||
|
#pragma warning(disable: 4127)
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -38,7 +42,6 @@
|
|||||||
#include "direction.h"
|
#include "direction.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
#include "phase.h"
|
|
||||||
#include "square.h"
|
#include "square.h"
|
||||||
#include "value.h"
|
#include "value.h"
|
||||||
|
|
||||||
@@ -47,13 +50,12 @@
|
|||||||
//// Constants
|
//// Constants
|
||||||
////
|
////
|
||||||
|
|
||||||
/// FEN string for the initial position:
|
/// FEN string for the initial position
|
||||||
const std::string StartPosition =
|
const std::string StartPosition = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
|
||||||
|
|
||||||
/// Maximum number of plies per game (220 should be enough, because the
|
/// Maximum number of plies per game (220 should be enough, because the
|
||||||
/// maximum search depth is 100, and during position setup we reset the
|
/// maximum search depth is 100, and during position setup we reset the
|
||||||
/// move counter for every non-reversible move):
|
/// move counter for every non-reversible move).
|
||||||
const int MaxGameLength = 220;
|
const int MaxGameLength = 220;
|
||||||
|
|
||||||
|
|
||||||
@@ -61,56 +63,61 @@ const int MaxGameLength = 220;
|
|||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
/// Castle rights, encoded as bit fields:
|
/// Castle rights, encoded as bit fields
|
||||||
|
|
||||||
enum CastleRights {
|
enum CastleRights {
|
||||||
NO_CASTLES = 0,
|
NO_CASTLES = 0,
|
||||||
WHITE_OO = 1,
|
WHITE_OO = 1,
|
||||||
BLACK_OO = 2,
|
BLACK_OO = 2,
|
||||||
WHITE_OOO = 4,
|
WHITE_OOO = 4,
|
||||||
BLACK_OOO = 8,
|
BLACK_OOO = 8,
|
||||||
ALL_CASTLES = 15
|
ALL_CASTLES = 15
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Game phase
|
||||||
/// The UndoInfo struct stores information we need to restore a Position
|
enum Phase {
|
||||||
/// object to its previous state when we retract a move. Whenever a move
|
PHASE_ENDGAME = 0,
|
||||||
/// is made on the board (by calling Position::do_move), an UndoInfo object
|
PHASE_MIDGAME = 128
|
||||||
/// must be passed as a parameter. When the move is unmade (by calling
|
|
||||||
/// Position::undo_move), the same UndoInfo object must be passed again.
|
|
||||||
|
|
||||||
struct UndoInfo {
|
|
||||||
int castleRights;
|
|
||||||
Square epSquare;
|
|
||||||
Bitboard checkersBB;
|
|
||||||
Key key, pawnKey, materialKey;
|
|
||||||
int rule50;
|
|
||||||
Move lastMove;
|
|
||||||
PieceType capture;
|
|
||||||
Value mgValue, egValue;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// The position data structure. A position consists of the following data:
|
/// The StateInfo struct stores information we need to restore a Position
|
||||||
|
/// object to its previous state when we retract a move. Whenever a move
|
||||||
|
/// is made on the board (by calling Position::do_move), an StateInfo object
|
||||||
|
/// must be passed as a parameter.
|
||||||
|
|
||||||
|
struct StateInfo {
|
||||||
|
Key key, pawnKey, materialKey;
|
||||||
|
int castleRights, rule50;
|
||||||
|
Square epSquare;
|
||||||
|
Value mgValue, egValue;
|
||||||
|
Value npMaterial[2];
|
||||||
|
|
||||||
|
PieceType capture;
|
||||||
|
Bitboard checkersBB;
|
||||||
|
StateInfo* previous;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// The position data structure. A position consists of the following data:
|
||||||
///
|
///
|
||||||
/// * For each piece type, a bitboard representing the squares occupied
|
/// * For each piece type, a bitboard representing the squares occupied
|
||||||
/// by pieces of that type.
|
/// by pieces of that type.
|
||||||
/// * For each color, a bitboard representing the squares occupiecd by
|
/// * For each color, a bitboard representing the squares occupied by
|
||||||
/// pieces of that color.
|
/// pieces of that color.
|
||||||
/// * A bitboard of all occupied squares.
|
/// * A bitboard of all occupied squares.
|
||||||
/// * A bitboard of all checking pieces.
|
/// * A bitboard of all checking pieces.
|
||||||
/// * A 64-entry array of pieces, indexed by the squares of the board.
|
/// * A 64-entry array of pieces, indexed by the squares of the board.
|
||||||
/// * The current side to move.
|
/// * The current side to move.
|
||||||
/// * Information about the castling rights for both sides.
|
/// * Information about the castling rights for both sides.
|
||||||
/// * The initial files of the kings and both pairs of rooks. This is
|
/// * The initial files of the kings and both pairs of rooks. This is
|
||||||
/// used to implement the Chess960 castling rules.
|
/// used to implement the Chess960 castling rules.
|
||||||
/// * The en passant square (which is SQ_NONE if no en passant capture is
|
/// * The en passant square (which is SQ_NONE if no en passant capture is
|
||||||
/// possible).
|
/// possible).
|
||||||
/// * The squares of the kings for both sides.
|
/// * The squares of the kings for both sides.
|
||||||
/// * The last move played.
|
|
||||||
/// * Hash keys for the position itself, the current pawn structure, and
|
/// * Hash keys for the position itself, the current pawn structure, and
|
||||||
/// the current material situation.
|
/// the current material situation.
|
||||||
/// * Hash keys for all previous positions in the game (for detecting
|
/// * Hash keys for all previous positions in the game for detecting
|
||||||
/// repetition draws.
|
/// repetition draws.
|
||||||
/// * A counter for detecting 50 move rule draws.
|
/// * A counter for detecting 50 move rule draws.
|
||||||
|
|
||||||
@@ -120,19 +127,24 @@ class Position {
|
|||||||
friend class EndgameFunctions;
|
friend class EndgameFunctions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum GamePhase {
|
||||||
|
MidGame,
|
||||||
|
EndGame
|
||||||
|
};
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
Position() {};
|
Position() {}
|
||||||
Position(const Position &pos);
|
Position(const Position& pos);
|
||||||
Position(const std::string &fen);
|
Position(const std::string& fen);
|
||||||
|
|
||||||
// Text input/output
|
// Text input/output
|
||||||
void from_fen(const std::string &fen);
|
void from_fen(const std::string& fen);
|
||||||
const std::string to_fen() const;
|
const std::string to_fen() const;
|
||||||
void print(Move m = MOVE_NONE) const;
|
void print(Move m = MOVE_NONE) const;
|
||||||
|
|
||||||
// Copying
|
// Copying
|
||||||
void copy(const Position &pos);
|
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
|
||||||
Piece piece_on(Square s) const;
|
Piece piece_on(Square s) const;
|
||||||
@@ -150,26 +162,10 @@ public:
|
|||||||
Bitboard empty_squares() const;
|
Bitboard empty_squares() const;
|
||||||
Bitboard occupied_squares() const;
|
Bitboard occupied_squares() const;
|
||||||
Bitboard pieces_of_color(Color c) const;
|
Bitboard pieces_of_color(Color c) const;
|
||||||
Bitboard pieces_of_type(PieceType pt) const;
|
Bitboard pieces(PieceType pt) const;
|
||||||
Bitboard pieces_of_color_and_type(Color c, PieceType pt) const;
|
Bitboard pieces(PieceType pt, Color c) const;
|
||||||
Bitboard pawns() const;
|
Bitboard pieces(PieceType pt1, PieceType pt2) const;
|
||||||
Bitboard knights() const;
|
Bitboard pieces(PieceType pt1, PieceType pt2, Color c) const;
|
||||||
Bitboard bishops() const;
|
|
||||||
Bitboard rooks() const;
|
|
||||||
Bitboard queens() const;
|
|
||||||
Bitboard kings() const;
|
|
||||||
Bitboard rooks_and_queens() const;
|
|
||||||
Bitboard bishops_and_queens() const;
|
|
||||||
Bitboard sliders() const;
|
|
||||||
Bitboard pawns(Color c) const;
|
|
||||||
Bitboard knights(Color c) const;
|
|
||||||
Bitboard bishops(Color c) const;
|
|
||||||
Bitboard rooks(Color c) const;
|
|
||||||
Bitboard queens(Color c) const;
|
|
||||||
Bitboard kings(Color c) const;
|
|
||||||
Bitboard rooks_and_queens(Color c) const;
|
|
||||||
Bitboard bishops_and_queens(Color c) const;
|
|
||||||
Bitboard sliders_of_color(Color c) const;
|
|
||||||
|
|
||||||
// Number of pieces of each color and type
|
// Number of pieces of each color and type
|
||||||
int piece_count(Color c, PieceType pt) const;
|
int piece_count(Color c, PieceType pt) const;
|
||||||
@@ -187,35 +183,23 @@ public:
|
|||||||
Square initial_kr_square(Color c) const;
|
Square initial_kr_square(Color c) const;
|
||||||
Square initial_qr_square(Color c) const;
|
Square initial_qr_square(Color c) const;
|
||||||
|
|
||||||
// Attack bitboards
|
|
||||||
Bitboard sliding_attacks(Square s, Direction d) const;
|
|
||||||
Bitboard ray_attacks(Square s, SignedDirection d) const;
|
|
||||||
Bitboard pawn_attacks(Color c, Square s) const;
|
|
||||||
|
|
||||||
template<PieceType>
|
|
||||||
Bitboard piece_attacks(Square s) const;
|
|
||||||
|
|
||||||
// Bitboards for pinned pieces and discovered check candidates
|
// Bitboards for pinned pieces and discovered check candidates
|
||||||
Bitboard discovered_check_candidates(Color c) const;
|
Bitboard discovered_check_candidates(Color c) const;
|
||||||
Bitboard pinned_pieces(Color c) const;
|
Bitboard pinned_pieces(Color c) const;
|
||||||
|
|
||||||
// Checking pieces
|
// Checking pieces and under check information
|
||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
|
bool is_check() const;
|
||||||
|
|
||||||
// Piece lists
|
// Piece lists
|
||||||
Square piece_list(Color c, PieceType pt, int index) const;
|
Square piece_list(Color c, PieceType pt, int index) const;
|
||||||
|
const Square* piece_list_begin(Color c, PieceType pt) const;
|
||||||
|
|
||||||
// Attack information for a given square
|
// Information about attacks to or from a given square
|
||||||
bool square_is_attacked(Square s, Color c) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
Bitboard attacks_to(Square s) const;
|
Bitboard attacks_from(Piece p, Square s) const;
|
||||||
Bitboard attacks_to(Square s, Color c) const;
|
template<PieceType> Bitboard attacks_from(Square s) const;
|
||||||
bool is_check() const;
|
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||||
bool pawn_attacks_square(Color c, Square f, Square t) const;
|
|
||||||
|
|
||||||
template<PieceType>
|
|
||||||
Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
|
|
||||||
|
|
||||||
bool piece_attacks_square(Square f, Square t) const; // Dispatch at run-time
|
|
||||||
|
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool pl_move_is_legal(Move m) const;
|
bool pl_move_is_legal(Move m) const;
|
||||||
@@ -223,36 +207,31 @@ public:
|
|||||||
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, Bitboard dcCandidates) const;
|
||||||
bool move_is_capture(Move m) const;
|
bool move_is_capture(Move m) const;
|
||||||
bool move_is_deep_pawn_push(Move m) const;
|
|
||||||
bool move_is_pawn_push_to_7th(Move m) const;
|
|
||||||
bool move_is_passed_pawn_push(Move m) const;
|
bool move_is_passed_pawn_push(Move m) const;
|
||||||
bool move_was_passed_pawn_push(Move m) const;
|
|
||||||
bool move_attacks_square(Move m, Square s) const;
|
bool move_attacks_square(Move m, Square s) 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;
|
||||||
bool pawn_is_isolated(Color c, Square s) const;
|
static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
|
||||||
bool pawn_is_doubled(Color c, Square s) const;
|
static bool pawn_is_isolated(Bitboard ourPawns, Square s);
|
||||||
|
static bool pawn_is_doubled(Bitboard ourPawns, Color c, Square s);
|
||||||
// Open and half-open files
|
|
||||||
bool file_is_open(File f) const;
|
|
||||||
bool file_is_half_open(Color c, File f) const;
|
|
||||||
|
|
||||||
// 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 backup(UndoInfo &u) const;
|
void saveState();
|
||||||
void restore(const UndoInfo &u);
|
void do_move(Move m, StateInfo& st);
|
||||||
void do_move(Move m, UndoInfo &u);
|
void do_move(Move m, StateInfo& st, Bitboard dcCandidates);
|
||||||
void do_move(Move m, UndoInfo &u, Bitboard dcCandidates);
|
void undo_move(Move m);
|
||||||
void undo_move(Move m, const UndoInfo &u);
|
void do_null_move(StateInfo& st);
|
||||||
void do_null_move(UndoInfo &u);
|
void undo_null_move();
|
||||||
void undo_null_move(const UndoInfo &u);
|
|
||||||
|
|
||||||
// Static exchange evaluation
|
// Static exchange evaluation
|
||||||
int see(Square from, Square to) const;
|
int see(Square from, Square to) const;
|
||||||
int see(Move m) const;
|
int see(Move m) const;
|
||||||
|
int see(Square to) const;
|
||||||
|
int see_sign(Move m) const;
|
||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key get_key() const;
|
Key get_key() const;
|
||||||
@@ -264,10 +243,10 @@ public:
|
|||||||
Value eg_value() const;
|
Value eg_value() const;
|
||||||
Value non_pawn_material(Color c) const;
|
Value non_pawn_material(Color c) const;
|
||||||
Phase game_phase() const;
|
Phase game_phase() const;
|
||||||
Value mg_pst_delta(Move m) const;
|
template<GamePhase> Value pst_delta(Piece piece, Square from, Square to) const;
|
||||||
|
|
||||||
// Game termination checks
|
// Game termination checks
|
||||||
bool is_mate();
|
bool is_mate() const;
|
||||||
bool is_draw() const;
|
bool is_draw() const;
|
||||||
|
|
||||||
// Check if one side threatens a mate in one
|
// Check if one side threatens a mate in one
|
||||||
@@ -286,11 +265,12 @@ public:
|
|||||||
// Position consistency check, for debugging
|
// Position consistency check, for debugging
|
||||||
bool is_ok(int* failedStep = NULL) const;
|
bool is_ok(int* failedStep = NULL) const;
|
||||||
|
|
||||||
// Static member functions:
|
// Static member functions
|
||||||
static void init_zobrist();
|
static void init_zobrist();
|
||||||
static void init_piece_square_tables();
|
static void init_piece_square_tables();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Initialization helper functions (used while setting up a position)
|
// Initialization helper functions (used while setting up a position)
|
||||||
void clear();
|
void clear();
|
||||||
void put_piece(Piece p, Square s);
|
void put_piece(Piece p, Square s);
|
||||||
@@ -298,17 +278,16 @@ 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(Move m, PieceType capture, Color them, Square to);
|
void do_capture_move(Bitboard& key, PieceType capture, Color them, Square to, bool ep);
|
||||||
void do_castle_move(Move m);
|
void do_castle_move(Move m);
|
||||||
void do_promotion_move(Move m, UndoInfo &u);
|
|
||||||
void do_ep_move(Move m);
|
|
||||||
void undo_castle_move(Move m);
|
void undo_castle_move(Move m);
|
||||||
void undo_promotion_move(Move m, const UndoInfo &u);
|
|
||||||
void undo_ep_move(Move m);
|
|
||||||
void find_checkers();
|
void find_checkers();
|
||||||
|
|
||||||
template<PieceType Piece, bool FindPinned>
|
template<PieceType Piece>
|
||||||
Bitboard hidden_checks(Color c, Square ksq) const;
|
void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
|
||||||
|
|
||||||
|
template<bool FindPinned>
|
||||||
|
Bitboard hidden_checkers(Color c) const;
|
||||||
|
|
||||||
// Computing hash keys from scratch (for initialization and debugging)
|
// Computing hash keys from scratch (for initialization and debugging)
|
||||||
Key compute_key() const;
|
Key compute_key() const;
|
||||||
@@ -316,37 +295,30 @@ 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
|
||||||
Value mg_pst(Color c, PieceType pt, Square s) const;
|
template<GamePhase> Value pst(Color c, PieceType pt, Square s) const;
|
||||||
Value eg_pst(Color c, PieceType pt, Square s) const;
|
template<GamePhase> Value compute_value() const;
|
||||||
Value compute_mg_value() const;
|
|
||||||
Value compute_eg_value() const;
|
|
||||||
Value compute_non_pawn_material(Color c) const;
|
Value compute_non_pawn_material(Color c) const;
|
||||||
|
|
||||||
// Bitboards
|
|
||||||
Bitboard byColorBB[2], byTypeBB[8];
|
|
||||||
Bitboard checkersBB;
|
|
||||||
|
|
||||||
// Board
|
// Board
|
||||||
Piece board[64];
|
Piece board[64];
|
||||||
|
|
||||||
|
// Bitboards
|
||||||
|
Bitboard byTypeBB[8], byColorBB[2];
|
||||||
|
|
||||||
// Piece counts
|
// Piece counts
|
||||||
int pieceCount[2][8]; // [color][pieceType]
|
int pieceCount[2][8]; // [color][pieceType]
|
||||||
|
|
||||||
// Piece lists
|
// Piece lists
|
||||||
Square pieceList[2][8][16]; // [color][pieceType][index]
|
Square pieceList[2][8][16]; // [color][pieceType][index]
|
||||||
int index[64];
|
int index[64]; // [square]
|
||||||
|
|
||||||
// Other info
|
// Other info
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
int castleRights;
|
int gamePly;
|
||||||
|
Key history[MaxGameLength];
|
||||||
File initialKFile, initialKRFile, initialQRFile;
|
File initialKFile, initialKRFile, initialQRFile;
|
||||||
Square epSquare;
|
StateInfo startState;
|
||||||
Square kingSquare[2];
|
StateInfo* st;
|
||||||
Move lastMove;
|
|
||||||
Key key, pawnKey, materialKey, history[MaxGameLength];
|
|
||||||
int rule50, gamePly;
|
|
||||||
Value mgValue, egValue;
|
|
||||||
Value npMaterial[2];
|
|
||||||
|
|
||||||
// Static variables
|
// Static variables
|
||||||
static int castleRightsMask[64];
|
static int castleRightsMask[64];
|
||||||
@@ -408,84 +380,20 @@ inline Bitboard Position::pieces_of_color(Color c) const {
|
|||||||
return byColorBB[c];
|
return byColorBB[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces_of_type(PieceType pt) const {
|
inline Bitboard Position::pieces(PieceType pt) const {
|
||||||
return byTypeBB[pt];
|
return byTypeBB[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces_of_color_and_type(Color c, PieceType pt) const {
|
inline Bitboard Position::pieces(PieceType pt, Color c) const {
|
||||||
return pieces_of_color(c) & pieces_of_type(pt);
|
return byTypeBB[pt] & byColorBB[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pawns() const {
|
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2) const {
|
||||||
return pieces_of_type(PAWN);
|
return byTypeBB[pt1] | byTypeBB[pt2];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::knights() const {
|
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2, Color c) const {
|
||||||
return pieces_of_type(KNIGHT);
|
return (byTypeBB[pt1] | byTypeBB[pt2]) & byColorBB[c];
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::bishops() const {
|
|
||||||
return pieces_of_type(BISHOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::rooks() const {
|
|
||||||
return pieces_of_type(ROOK);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::queens() const {
|
|
||||||
return pieces_of_type(QUEEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::kings() const {
|
|
||||||
return pieces_of_type(KING);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::rooks_and_queens() const {
|
|
||||||
return rooks() | queens();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::bishops_and_queens() const {
|
|
||||||
return bishops() | queens();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::sliders() const {
|
|
||||||
return bishops() | queens() | rooks();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::pawns(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, PAWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::knights(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, KNIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::bishops(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, BISHOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::rooks(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, ROOK);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::queens(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, QUEEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::kings(Color c) const {
|
|
||||||
return pieces_of_color_and_type(c, KING);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::rooks_and_queens(Color c) const {
|
|
||||||
return rooks_and_queens() & pieces_of_color(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::bishops_and_queens(Color c) const {
|
|
||||||
return bishops_and_queens() & pieces_of_color(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::sliders_of_color(Color c) const {
|
|
||||||
return sliders() & pieces_of_color(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::piece_count(Color c, PieceType pt) const {
|
inline int Position::piece_count(Color c, PieceType pt) const {
|
||||||
@@ -496,20 +404,24 @@ inline Square Position::piece_list(Color c, PieceType pt, int index) const {
|
|||||||
return pieceList[c][pt][index];
|
return pieceList[c][pt][index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const Square* Position::piece_list_begin(Color c, PieceType pt) const {
|
||||||
|
return pieceList[c][pt];
|
||||||
|
}
|
||||||
|
|
||||||
inline Square Position::ep_square() const {
|
inline Square Position::ep_square() const {
|
||||||
return epSquare;
|
return st->epSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::king_square(Color c) const {
|
inline Square Position::king_square(Color c) const {
|
||||||
return kingSquare[c];
|
return pieceList[c][KING][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::can_castle_kingside(Color side) const {
|
inline bool Position::can_castle_kingside(Color side) const {
|
||||||
return castleRights & (1+int(side));
|
return st->castleRights & (1+int(side));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::can_castle_queenside(Color side) const {
|
inline bool Position::can_castle_queenside(Color side) const {
|
||||||
return castleRights & (4+4*int(side));
|
return st->castleRights & (4+4*int(side));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::can_castle(Color side) const {
|
inline bool Position::can_castle(Color side) const {
|
||||||
@@ -524,124 +436,100 @@ inline Square Position::initial_qr_square(Color c) const {
|
|||||||
return relative_square(c, make_square(initialQRFile, RANK_1));
|
return relative_square(c, make_square(initialQRFile, RANK_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pawn_attacks(Color c, Square s) const {
|
template<>
|
||||||
return StepAttackBB[pawn_of_color(c)][s];
|
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
||||||
|
return StepAttackBB[piece_of_color_and_type(c, PAWN)][s];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<PieceType Piece> // Knight and King and white pawns
|
||||||
|
inline Bitboard Position::attacks_from(Square s) const {
|
||||||
|
return StepAttackBB[Piece][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<KNIGHT>(Square s) const {
|
inline Bitboard Position::attacks_from<BISHOP>(Square s) const {
|
||||||
return StepAttackBB[KNIGHT][s];
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline Bitboard Position::piece_attacks<BISHOP>(Square s) const {
|
|
||||||
return bishop_attacks_bb(s, occupied_squares());
|
return bishop_attacks_bb(s, occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<ROOK>(Square s) const {
|
inline Bitboard Position::attacks_from<ROOK>(Square s) const {
|
||||||
return rook_attacks_bb(s, occupied_squares());
|
return rook_attacks_bb(s, occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<QUEEN>(Square s) const {
|
inline Bitboard Position::attacks_from<QUEEN>(Square s) const {
|
||||||
return piece_attacks<ROOK>(s) | piece_attacks<BISHOP>(s);
|
return attacks_from<ROOK>(s) | attacks_from<BISHOP>(s);
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline Bitboard Position::piece_attacks<KING>(Square s) const {
|
|
||||||
return StepAttackBB[KING][s];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::checkers() const {
|
inline Bitboard Position::checkers() const {
|
||||||
return checkersBB;
|
return st->checkersBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::is_check() const {
|
inline bool Position::is_check() const {
|
||||||
return checkersBB != EmptyBoardBB;
|
return st->checkersBB != EmptyBoardBB;
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const {
|
|
||||||
return bit_is_set(pawn_attacks(c, f), t);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<PieceType Piece>
|
|
||||||
Bitboard Position::piece_attacks_square(Square f, Square t) const {
|
|
||||||
return bit_is_set(piece_attacks<Piece>(f), t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
||||||
return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s));
|
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_isolated(Color c, Square s) const {
|
inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) {
|
||||||
return !(pawns(c) & neighboring_files_bb(s));
|
return !(theirPawns & passed_pawn_mask(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_doubled(Color c, Square s) const {
|
inline bool Position::pawn_is_isolated(Bitboard ourPawns, Square s) {
|
||||||
return pawns(c) & squares_behind(c, s);
|
return !(ourPawns & neighboring_files_bb(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::file_is_open(File f) const {
|
inline bool Position::pawn_is_doubled(Bitboard ourPawns, Color c, Square s) {
|
||||||
return !(pawns() & file_bb(f));
|
return ourPawns & squares_behind(c, s);
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::file_is_half_open(Color c, File f) const {
|
|
||||||
return !(pawns(c) & file_bb(f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::square_is_weak(Square s, Color c) const {
|
inline bool Position::square_is_weak(Square s, Color c) const {
|
||||||
return !(pawns(c) & outpost_mask(opposite_color(c), s));
|
return !(pieces(PAWN, c) & outpost_mask(opposite_color(c), s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_key() const {
|
inline Key Position::get_key() const {
|
||||||
return key;
|
return st->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_pawn_key() const {
|
inline Key Position::get_pawn_key() const {
|
||||||
return pawnKey;
|
return st->pawnKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_material_key() const {
|
inline Key Position::get_material_key() const {
|
||||||
return materialKey;
|
return st->materialKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::mg_pst(Color c, PieceType pt, Square s) const {
|
template<Position::GamePhase Ph>
|
||||||
return MgPieceSquareTable[piece_of_color_and_type(c, pt)][s];
|
inline Value Position::pst(Color c, PieceType pt, Square s) const {
|
||||||
|
return (Ph == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
|
||||||
|
: EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::mg_pst_delta(Move m) const {
|
template<Position::GamePhase Ph>
|
||||||
return MgPieceSquareTable[piece_on(move_from(m))][move_to(m)]
|
inline Value Position::pst_delta(Piece piece, Square from, Square to) const {
|
||||||
-MgPieceSquareTable[piece_on(move_from(m))][move_from(m)];
|
return (Ph == MidGame ? MgPieceSquareTable[piece][to] - MgPieceSquareTable[piece][from]
|
||||||
}
|
: EgPieceSquareTable[piece][to] - EgPieceSquareTable[piece][from]);
|
||||||
|
|
||||||
inline Value Position::eg_pst(Color c, PieceType pt, Square s) const {
|
|
||||||
return EgPieceSquareTable[piece_of_color_and_type(c, pt)][s];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::mg_value() const {
|
inline Value Position::mg_value() const {
|
||||||
return mgValue;
|
return st->mgValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::eg_value() const {
|
inline Value Position::eg_value() const {
|
||||||
return egValue;
|
return st->egValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::non_pawn_material(Color c) const {
|
inline Value Position::non_pawn_material(Color c) const {
|
||||||
return npMaterial[c];
|
return st->npMaterial[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Phase Position::game_phase() const {
|
inline Phase Position::game_phase() const {
|
||||||
|
|
||||||
// The purpose of the Value(325) terms below is to make sure the difference
|
// Values modified by Joona Kiiski
|
||||||
// between MidgameLimit and EndgameLimit is a power of 2, which should make
|
static const Value MidgameLimit = Value(15581);
|
||||||
// the division at the end of the function a bit faster.
|
static const Value EndgameLimit = Value(3998);
|
||||||
static const Value MidgameLimit = 2 * QueenValueMidgame
|
|
||||||
+ 2 * RookValueMidgame
|
|
||||||
+ 6 * BishopValueMidgame
|
|
||||||
+ Value(325);
|
|
||||||
|
|
||||||
static const Value EndgameLimit = 4 * RookValueMidgame - Value(325);
|
|
||||||
|
|
||||||
Value npm = non_pawn_material(WHITE) + non_pawn_material(BLACK);
|
Value npm = non_pawn_material(WHITE) + non_pawn_material(BLACK);
|
||||||
|
|
||||||
@@ -653,37 +541,16 @@ inline Phase Position::game_phase() const {
|
|||||||
return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
|
return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::move_is_deep_pawn_push(Move m) const {
|
|
||||||
|
|
||||||
Color c = side_to_move();
|
|
||||||
return piece_on(move_from(m)) == pawn_of_color(c)
|
|
||||||
&& relative_rank(c, move_to(m)) > RANK_4;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::move_is_pawn_push_to_7th(Move m) const {
|
|
||||||
|
|
||||||
Color c = side_to_move();
|
|
||||||
return piece_on(move_from(m)) == pawn_of_color(c)
|
|
||||||
&& relative_rank(c, move_to(m)) == RANK_7;
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
return piece_on(move_from(m)) == pawn_of_color(c)
|
return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN)
|
||||||
&& pawn_is_passed(c, move_to(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::move_was_passed_pawn_push(Move m) const {
|
|
||||||
|
|
||||||
Color c = opposite_color(side_to_move());
|
|
||||||
return piece_on(move_to(m)) == pawn_of_color(c)
|
|
||||||
&& pawn_is_passed(c, move_to(m));
|
&& pawn_is_passed(c, move_to(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::rule_50_counter() const {
|
inline int Position::rule_50_counter() const {
|
||||||
|
|
||||||
return rule50;
|
return st->rule50;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::opposite_colored_bishops() const {
|
inline bool Position::opposite_colored_bishops() const {
|
||||||
@@ -695,8 +562,14 @@ inline bool Position::opposite_colored_bishops() const {
|
|||||||
|
|
||||||
inline bool Position::has_pawn_on_7th(Color c) const {
|
inline bool Position::has_pawn_on_7th(Color c) const {
|
||||||
|
|
||||||
return pawns(c) & relative_rank_bb(c, RANK_7);
|
return pieces(PAWN, c) & relative_rank_bb(c, RANK_7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Position::move_is_capture(Move m) const {
|
||||||
|
|
||||||
|
// Move must not be MOVE_NONE !
|
||||||
|
|
||||||
|
return (!square_is_empty(move_to(m)) && !move_is_castle(m)) || move_is_ep(m);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(POSITION_H_INCLUDED)
|
#endif // !defined(POSITION_H_INCLUDED)
|
||||||
|
|||||||
+104
-105
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -25,12 +25,11 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include "position.h"
|
|
||||||
#include "value.h"
|
#include "value.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Variables
|
//// Constants modified by Joona Kiiski
|
||||||
////
|
////
|
||||||
|
|
||||||
static const Value MP = PawnValueMidgame;
|
static const Value MP = PawnValueMidgame;
|
||||||
@@ -42,70 +41,70 @@ static const Value MQ = QueenValueMidgame;
|
|||||||
static const int MgPST[][64] = {
|
static const int MgPST[][64] = {
|
||||||
{ },
|
{ },
|
||||||
{// Pawn
|
{// Pawn
|
||||||
// A B C D E F G H
|
// A B C D E F G H
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
MP-38, MP-12, MP- 0, MP+12, MP+12, MP- 0, MP-12, MP-38,
|
MP-28, MP-6, MP+ 4, MP+14, MP+14, MP+ 4, MP-6, MP-28,
|
||||||
MP-38, MP-12, MP+ 6, MP+38, MP+38, MP+ 6, MP-12, MP-38,
|
MP-28, MP-6, MP+ 9, MP+36, MP+36, MP+ 9, MP-6, MP-28,
|
||||||
MP-38, MP-12, MP+16, MP+64, MP+64, MP+16, MP-12, MP-38,
|
MP-28, MP-6, MP+17, MP+58, MP+58, MP+17, MP-6, MP-28,
|
||||||
MP-38, MP-12, MP+16, MP+38, MP+38, MP+16, MP-12, MP-38,
|
MP-28, MP-6, MP+17, MP+36, MP+36, MP+17, MP-6, MP-28,
|
||||||
MP-38, MP-12, MP+ 6, MP+12, MP+12, MP+ 6, MP-12, MP-38,
|
MP-28, MP-6, MP+ 9, MP+14, MP+14, MP+ 9, MP-6, MP-28,
|
||||||
MP-38, MP-12, MP- 0, MP+12, MP+12, MP- 0, MP-12, MP-38,
|
MP-28, MP-6, MP+ 4, MP+14, MP+14, MP+ 4, MP-6, MP-28,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
},
|
},
|
||||||
{// Knight
|
{// Knight
|
||||||
// A B C D E F G H
|
// A B C D E F G H
|
||||||
MK-128, MK-102, MK-76, MK-64, MK-64, MK-76, MK-102, MK-128,
|
MK-135, MK-107, MK-80, MK-67, MK-67, MK-80, MK-107, MK-135,
|
||||||
MK- 89, MK- 64, MK-38, MK-25, MK-25, MK-38, MK- 64, MK- 89,
|
MK- 93, MK- 67, MK-39, MK-25, MK-25, MK-39, MK- 67, MK- 93,
|
||||||
MK- 51, MK- 25, MK- 0, MK+12, MK+12, MK- 0, MK- 25, MK- 51,
|
MK- 53, MK- 25, MK+ 1, MK+13, MK+13, MK+ 1, MK- 25, MK- 53,
|
||||||
MK- 25, MK- 0, MK+25, MK+38, MK+38, MK+25, MK- 0, MK- 25,
|
MK- 25, MK+ 1, MK+27, MK+41, MK+41, MK+27, MK+ 1, MK- 25,
|
||||||
MK- 12, MK+ 12, MK+38, MK+51, MK+51, MK+38, MK+ 12, MK- 12,
|
MK- 11, MK+ 13, MK+41, MK+55, MK+55, MK+41, MK+ 13, MK- 11,
|
||||||
MK- 12, MK+ 12, MK+38, MK+51, MK+51, MK+38, MK+ 12, MK- 12,
|
MK- 11, MK+ 13, MK+41, MK+55, MK+55, MK+41, MK+ 13, MK- 11,
|
||||||
MK- 51, MK- 25, MK- 0, MK+12, MK+12, MK- 0, MK- 25, MK- 51,
|
MK- 53, MK- 25, MK+ 1, MK+13, MK+13, MK+ 1, MK- 25, MK- 53,
|
||||||
MK-182, MK- 64, MK-38, MK-25, MK-25, MK-38, MK- 64, MK-182
|
MK-193, MK- 67, MK-39, MK-25, MK-25, MK-39, MK- 67, MK-193
|
||||||
},
|
},
|
||||||
{// Bishop
|
{// Bishop
|
||||||
// A B C D E F G H
|
// A B C D E F G H
|
||||||
MB-46, MB-46, MB-40, MB-35, MB-35, MB-40, MB-46, MB-46,
|
MB-40, MB-40, MB-35, MB-30, MB-30, MB-35, MB-40, MB-40,
|
||||||
MB-20, MB- 0, MB- 5, MB- 0, MB- 0, MB- 5, MB- 0, MB-20,
|
MB-17, MB+ 0, MB- 4, MB+ 0, MB+ 0, MB- 4, MB+ 0, MB-17,
|
||||||
MB-15, MB- 5, MB+10, MB+ 5, MB+ 5, MB+10, MB- 5, MB-15,
|
MB-13, MB- 4, MB+ 8, MB+ 4, MB+ 4, MB+ 8, MB- 4, MB-13,
|
||||||
MB-10, MB- 0, MB+ 5, MB+20, MB+20, MB+ 5, MB- 0, MB-10,
|
MB- 8, MB+ 0, MB+ 4, MB+17, MB+17, MB+ 4, MB+ 0, MB- 8,
|
||||||
MB-10, MB- 0, MB+ 5, MB+20, MB+20, MB+ 5, MB- 0, MB-10,
|
MB- 8, MB+ 0, MB+ 4, MB+17, MB+17, MB+ 4, MB+ 0, MB- 8,
|
||||||
MB-15, MB- 5, MB+10, MB+ 5, MB+ 5, MB+10, MB- 5, MB-15,
|
MB-13, MB- 4, MB+ 8, MB+ 4, MB+ 4, MB+ 8, MB- 4, MB-13,
|
||||||
MB-20, MB- 0, MB- 5, MB- 0, MB- 0, MB- 5, MB- 0, MB-20,
|
MB-17, MB+ 0, MB- 4, MB+ 0, MB+ 0, MB- 4, MB+ 0, MB-17,
|
||||||
MB-20, MB-20, MB-15, MB-10, MB-10, MB-15, MB-20, MB-20
|
MB-17, MB-17, MB-13, MB- 8, MB- 8, MB-13, MB-17, MB-17
|
||||||
},
|
},
|
||||||
{// Rook
|
{// Rook
|
||||||
// A B C D E F G H
|
// A B C D E F G H
|
||||||
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
||||||
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
||||||
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
||||||
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
||||||
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
||||||
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
||||||
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12,
|
||||||
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18
|
MR-12, MR-7, MR-2, MR+2, MR+2, MR-2, MR-7, MR-12
|
||||||
},
|
},
|
||||||
{// Queen
|
{// Queen
|
||||||
//A B C D E F G H
|
// A B C D E F G H
|
||||||
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
||||||
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
||||||
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
||||||
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
||||||
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
||||||
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
||||||
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8,
|
||||||
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ
|
MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8, MQ+8
|
||||||
},
|
},
|
||||||
{// King
|
{// King
|
||||||
//A B C D E F G H
|
//A B C D E F G H
|
||||||
302, 328, 276, 225, 225, 276, 328, 302,
|
287, 311, 262, 214, 214, 262, 311, 287,
|
||||||
276, 302, 251, 200, 200, 251, 302, 276,
|
262, 287, 238, 190, 190, 238, 287, 262,
|
||||||
225, 251, 200, 149, 149, 200, 251, 225,
|
214, 238, 190, 142, 142, 190, 238, 214,
|
||||||
200, 225, 175, 124, 124, 175, 225, 200,
|
190, 214, 167, 119, 119, 167, 214, 190,
|
||||||
175, 200, 149, 98, 98, 149, 200, 175,
|
167, 190, 142, 94, 94, 142, 190, 167,
|
||||||
149, 175, 124, 72, 72, 124, 175, 149,
|
142, 167, 119, 69, 69, 119, 167, 142,
|
||||||
124, 149, 98, 47, 47, 98, 149, 124,
|
119, 142, 94, 46, 46, 94, 142, 119,
|
||||||
98, 124, 72, 21, 21, 72, 124, 98
|
94, 119, 69, 21, 21, 69, 119, 94
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -118,70 +117,70 @@ static const Value EQ = QueenValueEndgame;
|
|||||||
static const int EgPST[][64] = {
|
static const int EgPST[][64] = {
|
||||||
{ },
|
{ },
|
||||||
{// Pawn
|
{// Pawn
|
||||||
//A B C D E F G H
|
// A B C D E F G H
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
EP, EP, EP, EP, EP, EP, EP, EP,
|
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
||||||
EP, EP, EP, EP, EP, EP, EP, EP,
|
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
||||||
EP, EP, EP, EP, EP, EP, EP, EP,
|
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
||||||
EP, EP, EP, EP, EP, EP, EP, EP,
|
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
||||||
EP, EP, EP, EP, EP, EP, EP, EP,
|
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
||||||
EP, EP, EP, EP, EP, EP, EP, EP,
|
EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8, EP-8,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
},
|
},
|
||||||
{// Knight
|
{// Knight
|
||||||
// A B C D E F G H
|
// A B C D E F G H
|
||||||
EK-102, EK-76, EK-51, EK-38, EK-38, EK-51, EK-76, EK-102,
|
EK-104, EK-79, EK-55, EK-42, EK-42, EK-55, EK-79, EK-104,
|
||||||
EK- 76, EK-51, EK-25, EK-12, EK-12, EK-25, EK-51, EK-76,
|
EK- 79, EK-55, EK-30, EK-17, EK-17, EK-30, EK-55, EK- 79,
|
||||||
EK- 51, EK-25, EK- 0, EK+12, EK+12, EK- 0, EK-25, EK-51,
|
EK- 55, EK-30, EK- 6, EK+ 5, EK+ 5, EK- 6, EK-30, EK- 55,
|
||||||
EK- 38, EK-12, EK+12, EK+25, EK+25, EK+12, EK-12, EK-38,
|
EK- 42, EK-17, EK+ 5, EK+18, EK+18, EK+ 5, EK-17, EK- 42,
|
||||||
EK- 38, EK-12, EK+12, EK+25, EK+25, EK+12, EK-12, EK-38,
|
EK- 42, EK-17, EK+ 5, EK+18, EK+18, EK+ 5, EK-17, EK- 42,
|
||||||
EK- 51, EK-25, EK- 0, EK+12, EK+12, EK- 0, EK-25, EK-51,
|
EK- 55, EK-30, EK- 6, EK+ 5, EK+ 5, EK- 6, EK-30, EK- 55,
|
||||||
EK- 76, EK-51, EK-25, EK-12, EK-12, EK-25, EK-51, EK-76,
|
EK- 79, EK-55, EK-30, EK-17, EK-17, EK-30, EK-55, EK- 79,
|
||||||
EK-102, EK-76, EK-51, EK-38, EK-38, EK-51, EK-76, EK-102
|
EK-104, EK-79, EK-55, EK-42, EK-42, EK-55, EK-79, EK-104
|
||||||
},
|
},
|
||||||
{// Bishop
|
{// Bishop
|
||||||
// A B C D E F G H
|
// A B C D E F G H
|
||||||
EB-46, EB-30, EB-23, EB-15, EB-15, EB-23, EB-30, EB-46,
|
EB-59, EB-42, EB-35, EB-26, EB-26, EB-35, EB-42, EB-59,
|
||||||
EB-30, EB-15, EB- 7, EB- 0, EB- 0, EB- 7, EB-15, EB-30,
|
EB-42, EB-26, EB-18, EB-11, EB-11, EB-18, EB-26, EB-42,
|
||||||
EB-23, EB- 7, EB- 0, EB+ 7, EB+ 7, EB- 0, EB- 7, EB-23,
|
EB-35, EB-18, EB-11, EB- 4, EB- 4, EB-11, EB-18, EB-35,
|
||||||
EB-15, EB- 0, EB+ 7, EB+15, EB+15, EB+ 7, EB- 0, EB-15,
|
EB-26, EB-11, EB- 4, EB+ 4, EB+ 4, EB- 4, EB-11, EB-26,
|
||||||
EB-15, EB- 0, EB+ 7, EB+15, EB+15, EB+ 7, EB- 0, EB-15,
|
EB-26, EB-11, EB- 4, EB+ 4, EB+ 4, EB- 4, EB-11, EB-26,
|
||||||
EB-23, EB- 7, EB- 0, EB+ 7, EB+ 7, EB- 0, EB- 7, EB-23,
|
EB-35, EB-18, EB-11, EB- 4, EB- 4, EB-11, EB-18, EB-35,
|
||||||
EB-30, EB-15, EB- 7, EB- 0, EB- 0, EB- 7, EB-15, EB-30,
|
EB-42, EB-26, EB-18, EB-11, EB-11, EB-18, EB-26, EB-42,
|
||||||
EB-46, EB-30, EB-23, EB-15, EB-15, EB-23, EB-30, EB-46
|
EB-59, EB-42, EB-35, EB-26, EB-26, EB-35, EB-42, EB-59
|
||||||
},
|
},
|
||||||
{// Rook
|
{// Rook
|
||||||
// A B C D E F G H
|
// A B C D E F G H
|
||||||
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
||||||
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
||||||
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
||||||
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
||||||
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
||||||
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
||||||
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3,
|
||||||
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3
|
ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3, ER+3
|
||||||
},
|
},
|
||||||
{// Queen
|
{// Queen
|
||||||
// A B C D E F G H
|
// A B C D E F G H
|
||||||
EQ-61, EQ-40, EQ-30, EQ-20, EQ-20, EQ-30, EQ-40, EQ-61,
|
EQ-80, EQ-54, EQ-42, EQ-30, EQ-30, EQ-42, EQ-54, EQ-80,
|
||||||
EQ-40, EQ-20, EQ-10, EQ- 0, EQ- 0, EQ-10, EQ-20, EQ-40,
|
EQ-54, EQ-30, EQ-18, EQ- 6, EQ- 6, EQ-18, EQ-30, EQ-54,
|
||||||
EQ-30, EQ-10, EQ- 0, EQ+10, EQ+10, EQ- 0, EQ-10, EQ-30,
|
EQ-42, EQ-18, EQ- 6, EQ+ 6, EQ+ 6, EQ- 6, EQ-18, EQ-42,
|
||||||
EQ-20, EQ- 0, EQ+10, EQ+20, EQ+20, EQ+10, EQ- 0, EQ-20,
|
EQ-30, EQ- 6, EQ+ 6, EQ+18, EQ+18, EQ+ 6, EQ- 6, EQ-30,
|
||||||
EQ-20, EQ- 0, EQ+10, EQ+20, EQ+20, EQ+10, EQ- 0, EQ-20,
|
EQ-30, EQ- 6, EQ+ 6, EQ+18, EQ+18, EQ+ 6, EQ- 6, EQ-30,
|
||||||
EQ-30, EQ-10, EQ- 0, EQ+10, EQ+10, EQ- 0, EQ-10, EQ-30,
|
EQ-42, EQ-18, EQ- 6, EQ+ 6, EQ+ 6, EQ- 6, EQ-18, EQ-42,
|
||||||
EQ-40, EQ-20, EQ-10, EQ- 0, EQ- 0, EQ-10, EQ-20, EQ-40,
|
EQ-54, EQ-30, EQ-18, EQ- 6, EQ- 6, EQ-18, EQ-30, EQ-54,
|
||||||
EQ-61, EQ-40, EQ-30, EQ-20, EQ-20, EQ-30, EQ-40, EQ-61
|
EQ-80, EQ-54, EQ-42, EQ-30, EQ-30, EQ-42, EQ-54, EQ-80
|
||||||
},
|
},
|
||||||
{// King
|
{// King
|
||||||
//A B C D E F G H
|
//A B C D E F G H
|
||||||
16, 78, 108, 139, 139, 108, 78, 16,
|
18, 77, 105, 135, 135, 105, 77, 18,
|
||||||
78, 139, 170, 200, 200, 170, 139, 78,
|
77, 135, 165, 193, 193, 165, 135, 77,
|
||||||
108, 170, 200, 230, 230, 200, 170, 108,
|
105, 165, 193, 222, 222, 193, 165, 105,
|
||||||
139, 200, 230, 261, 261, 230, 200, 139,
|
135, 193, 222, 251, 251, 222, 193, 135,
|
||||||
139, 200, 230, 261, 261, 230, 200, 139,
|
135, 193, 222, 251, 251, 222, 193, 135,
|
||||||
108, 170, 200, 230, 230, 200, 170, 108,
|
105, 165, 193, 222, 222, 193, 165, 105,
|
||||||
78, 139, 170, 200, 200, 170, 139, 78,
|
77, 135, 165, 193, 193, 165, 135, 77,
|
||||||
16, 78, 108, 139, 139, 108, 78, 16
|
18, 77, 105, 135, 135, 105, 77, 18
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+41
-37
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,10 +28,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "history.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "san.h"
|
#include "san.h"
|
||||||
|
|
||||||
extern SearchStack EmptySearchStack;
|
using std::string;
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
@@ -39,8 +40,6 @@ extern SearchStack EmptySearchStack;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Types
|
|
||||||
|
|
||||||
enum Ambiguity {
|
enum Ambiguity {
|
||||||
AMBIGUITY_NONE,
|
AMBIGUITY_NONE,
|
||||||
AMBIGUITY_FILE,
|
AMBIGUITY_FILE,
|
||||||
@@ -48,12 +47,11 @@ namespace {
|
|||||||
AMBIGUITY_BOTH
|
AMBIGUITY_BOTH
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const History H; // used as dummy argument for MovePicker c'tor
|
||||||
/// Functions
|
|
||||||
|
|
||||||
Ambiguity move_ambiguity(const Position& pos, Move m);
|
Ambiguity move_ambiguity(const Position& pos, Move m);
|
||||||
const std::string time_string(int milliseconds);
|
const string time_string(int milliseconds);
|
||||||
const std::string score_string(Value v);
|
const string score_string(Value v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,28 +63,33 @@ 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 std::string move_to_san(const Position& pos, Move m) {
|
const string move_to_san(const Position& pos, Move m) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
|
|
||||||
std::string san = "";
|
Square from, to;
|
||||||
|
PieceType pt;
|
||||||
|
|
||||||
|
from = move_from(m);
|
||||||
|
to = move_to(m);
|
||||||
|
pt = type_of_piece(pos.piece_on(move_from(m)));
|
||||||
|
|
||||||
|
string san = "";
|
||||||
|
|
||||||
if (m == MOVE_NONE)
|
if (m == MOVE_NONE)
|
||||||
return "(none)";
|
return "(none)";
|
||||||
else if (m == MOVE_NULL)
|
else if (m == MOVE_NULL)
|
||||||
return "(null)";
|
return "(null)";
|
||||||
else if (move_is_long_castle(m))
|
else if (move_is_long_castle(m) || (int(to - from) == -2 && pt == KING))
|
||||||
san = "O-O-O";
|
san = "O-O-O";
|
||||||
else if (move_is_short_castle(m))
|
else if (move_is_short_castle(m) || (int(to - from) == 2 && pt == KING))
|
||||||
san = "O-O";
|
san = "O-O";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Piece pc = pos.piece_on(move_from(m));
|
if (pt != PAWN)
|
||||||
if (type_of_piece(pc) != PAWN)
|
|
||||||
{
|
{
|
||||||
san += piece_type_to_char(type_of_piece(pc), true);
|
san += piece_type_to_char(pt, true);
|
||||||
Square from = move_from(m);
|
|
||||||
switch (move_ambiguity(pos, m)) {
|
switch (move_ambiguity(pos, m)) {
|
||||||
case AMBIGUITY_NONE:
|
case AMBIGUITY_NONE:
|
||||||
break;
|
break;
|
||||||
@@ -105,23 +108,23 @@ const std::string move_to_san(const Position& pos, Move m) {
|
|||||||
}
|
}
|
||||||
if (pos.move_is_capture(m))
|
if (pos.move_is_capture(m))
|
||||||
{
|
{
|
||||||
if (type_of_piece(pc) == PAWN)
|
if (pt == PAWN)
|
||||||
san += file_to_char(square_file(move_from(m)));
|
san += file_to_char(square_file(move_from(m)));
|
||||||
san += "x";
|
san += "x";
|
||||||
}
|
}
|
||||||
san += square_to_string(move_to(m));
|
san += square_to_string(move_to(m));
|
||||||
if (move_promotion(m))
|
if (move_is_promotion(m))
|
||||||
{
|
{
|
||||||
san += '=';
|
san += '=';
|
||||||
san += piece_type_to_char(move_promotion(m), true);
|
san += piece_type_to_char(move_promotion_piece(m), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Is the move check? We don't use pos.move_is_check(m) here, because
|
// Is the move check? We don't use pos.move_is_check(m) here, because
|
||||||
// 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).
|
||||||
UndoInfo u;
|
StateInfo st;
|
||||||
Position p(pos);
|
Position p(pos);
|
||||||
p.do_move(m, u);
|
p.do_move(m, st);
|
||||||
if (p.is_check())
|
if (p.is_check())
|
||||||
san += p.is_mate()? "#" : "+";
|
san += p.is_mate()? "#" : "+";
|
||||||
|
|
||||||
@@ -134,11 +137,11 @@ const std::string move_to_san(const Position& pos, Move m) {
|
|||||||
/// the move is returned. On failure (i.e. if the string is unparsable, or
|
/// the move is returned. On failure (i.e. if the string is unparsable, or
|
||||||
/// if the move is illegal or ambiguous), MOVE_NONE is returned.
|
/// if the move is illegal or ambiguous), MOVE_NONE is returned.
|
||||||
|
|
||||||
Move move_from_san(const Position& pos, const std::string& movestr) {
|
Move move_from_san(const Position& pos, const string& movestr) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
MovePicker mp = MovePicker(pos, false, MOVE_NONE, EmptySearchStack, OnePly);
|
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
||||||
|
|
||||||
// Castling moves
|
// Castling moves
|
||||||
if (movestr == "O-O-O" || movestr == "O-O-O+")
|
if (movestr == "O-O-O" || movestr == "O-O-O+")
|
||||||
@@ -162,7 +165,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) {
|
|||||||
|
|
||||||
// Normal moves. We use a simple FSM to parse the san string.
|
// Normal moves. We use a simple FSM to parse the san string.
|
||||||
enum { START, TO_FILE, TO_RANK, PROMOTION_OR_CHECK, PROMOTION, CHECK, END };
|
enum { START, TO_FILE, TO_RANK, PROMOTION_OR_CHECK, PROMOTION, CHECK, END };
|
||||||
static const std::string pieceLetters = "KQRBN";
|
static const string pieceLetters = "KQRBN";
|
||||||
PieceType pt = NO_PIECE_TYPE, promotion = NO_PIECE_TYPE;
|
PieceType pt = NO_PIECE_TYPE, promotion = NO_PIECE_TYPE;
|
||||||
File fromFile = FILE_NONE, toFile = FILE_NONE;
|
File fromFile = FILE_NONE, toFile = FILE_NONE;
|
||||||
Rank fromRank = RANK_NONE, toRank = RANK_NONE;
|
Rank fromRank = RANK_NONE, toRank = RANK_NONE;
|
||||||
@@ -172,7 +175,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) {
|
|||||||
for (size_t i = 0; i < movestr.length(); i++)
|
for (size_t i = 0; i < movestr.length(); i++)
|
||||||
{
|
{
|
||||||
char type, c = movestr[i];
|
char type, c = movestr[i];
|
||||||
if (pieceLetters.find(c) != std::string::npos)
|
if (pieceLetters.find(c) != string::npos)
|
||||||
type = 'P';
|
type = 'P';
|
||||||
else if (c >= 'a' && c <= 'h')
|
else if (c >= 'a' && c <= 'h')
|
||||||
type = 'F';
|
type = 'F';
|
||||||
@@ -270,7 +273,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) {
|
|||||||
while ((m = mp.get_next_move()) != MOVE_NONE)
|
while ((m = mp.get_next_move()) != MOVE_NONE)
|
||||||
if ( pos.type_of_piece_on(move_from(m)) == pt
|
if ( pos.type_of_piece_on(move_from(m)) == pt
|
||||||
&& move_to(m) == to
|
&& move_to(m) == to
|
||||||
&& move_promotion(m) == promotion
|
&& move_promotion_piece(m) == promotion
|
||||||
&& (fromFile == FILE_NONE || fromFile == square_file(move_from(m)))
|
&& (fromFile == FILE_NONE || fromFile == square_file(move_from(m)))
|
||||||
&& (fromRank == RANK_NONE || fromRank == square_rank(move_from(m))))
|
&& (fromRank == RANK_NONE || fromRank == square_rank(move_from(m))))
|
||||||
{
|
{
|
||||||
@@ -288,11 +291,11 @@ Move move_from_san(const Position& pos, const std::string& movestr) {
|
|||||||
/// length of 80 characters. After a line break, 'startColumn' spaces are
|
/// length of 80 characters. After a line break, 'startColumn' spaces are
|
||||||
/// inserted at the beginning of the new line.
|
/// inserted at the beginning of the new line.
|
||||||
|
|
||||||
const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines) {
|
const string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines) {
|
||||||
|
|
||||||
UndoInfo u;
|
StateInfo st;
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
std::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);
|
||||||
@@ -309,9 +312,9 @@ const std::string line_to_san(const Position& pos, Move line[], int startColumn,
|
|||||||
s << moveStr << ' ';
|
s << moveStr << ' ';
|
||||||
|
|
||||||
if (line[i] == MOVE_NULL)
|
if (line[i] == MOVE_NULL)
|
||||||
p.do_null_move(u);
|
p.do_null_move(st);
|
||||||
else
|
else
|
||||||
p.do_move(line[i], u);
|
p.do_move(line[i], st);
|
||||||
}
|
}
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
@@ -321,15 +324,16 @@ const std::string line_to_san(const Position& pos, Move line[], int startColumn,
|
|||||||
/// It is used to write search information to the log file (which is created
|
/// It is used to write search information to the log file (which is created
|
||||||
/// when the UCI parameter "Use Search Log" is "true").
|
/// when the UCI parameter "Use Search Log" is "true").
|
||||||
|
|
||||||
const std::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) << " ";
|
||||||
@@ -362,7 +366,7 @@ namespace {
|
|||||||
if (type_of_piece(pc) == KING)
|
if (type_of_piece(pc) == KING)
|
||||||
return AMBIGUITY_NONE;
|
return AMBIGUITY_NONE;
|
||||||
|
|
||||||
MovePicker mp = MovePicker(pos, false, MOVE_NONE, EmptySearchStack, OnePly);
|
MovePicker mp = MovePicker(pos, MOVE_NONE, OnePly, H);
|
||||||
Move mv, moveList[8];
|
Move mv, moveList[8];
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
@@ -392,7 +396,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string time_string(int milliseconds) {
|
const string time_string(int milliseconds) {
|
||||||
|
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << std::setfill('0');
|
s << std::setfill('0');
|
||||||
@@ -409,7 +413,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string score_string(Value v) {
|
const string score_string(Value v) {
|
||||||
|
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -39,6 +39,6 @@
|
|||||||
extern const std::string move_to_san(const Position& pos, Move m);
|
extern const std::string move_to_san(const 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)
|
||||||
|
|||||||
+3
-3
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+777
-579
File diff suppressed because it is too large
Load Diff
+9
-26
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -25,14 +25,8 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "history.h"
|
#include "move.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "movegen.h"
|
|
||||||
#include "position.h"
|
|
||||||
#include "tt.h"
|
|
||||||
#include "value.h"
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -56,35 +50,24 @@ const int KILLER_MAX = 2;
|
|||||||
struct SearchStack {
|
struct SearchStack {
|
||||||
Move pv[PLY_MAX];
|
Move pv[PLY_MAX];
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Value currentMoveCaptureValue;
|
|
||||||
Move mateKiller;
|
Move mateKiller;
|
||||||
Move threatMove;
|
Move threatMove;
|
||||||
Move killers[KILLER_MAX];
|
Move killers[KILLER_MAX];
|
||||||
Depth reduction;
|
Depth reduction;
|
||||||
|
|
||||||
|
void init(int ply);
|
||||||
|
void initKillers();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Global variables
|
|
||||||
////
|
|
||||||
|
|
||||||
extern SearchStack EmptySearchStack;
|
|
||||||
extern TranspositionTable TT;
|
|
||||||
extern int ActiveThreads;
|
|
||||||
extern Lock SMPLock;
|
|
||||||
|
|
||||||
// Perhaps better to make H local, and pass as parameter to MovePicker?
|
|
||||||
extern History H;
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern void init_threads();
|
extern void init_threads();
|
||||||
extern void stop_threads();
|
extern void stop_threads();
|
||||||
extern void 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 int64_t nodes_searched();
|
extern int64_t nodes_searched();
|
||||||
|
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008 Marco Costalba
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Includes
|
|
||||||
////
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "square.h"
|
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Functions
|
|
||||||
////
|
|
||||||
|
|
||||||
|
|
||||||
/// Translating files, ranks and squares to/from characters and strings:
|
|
||||||
|
|
||||||
File file_from_char(char c) {
|
|
||||||
return File(c - 'a') + FILE_A;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char file_to_char(File f) {
|
|
||||||
return char(f - FILE_A) + 'a';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Rank rank_from_char(char c) {
|
|
||||||
return Rank(c - '1') + RANK_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char rank_to_char(Rank r) {
|
|
||||||
return char(r - RANK_1) + '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Square square_from_string(const std::string &str) {
|
|
||||||
return make_square(file_from_char(str[0]), rank_from_char(str[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::string square_to_string(Square s) {
|
|
||||||
std::string str;
|
|
||||||
str += file_to_char(square_file(s));
|
|
||||||
str += rank_to_char(square_rank(s));
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// file_is_ok(), rank_is_ok() and square_is_ok(), for debugging:
|
|
||||||
|
|
||||||
bool file_is_ok(File f) {
|
|
||||||
return f >= FILE_A && f <= FILE_H;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool rank_is_ok(Rank r) {
|
|
||||||
return r >= RANK_1 && r <= RANK_8;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool square_is_ok(Square s) {
|
|
||||||
return file_is_ok(square_file(s)) && rank_is_ok(square_rank(s));
|
|
||||||
}
|
|
||||||
+39
-17
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -46,7 +46,7 @@ enum Square {
|
|||||||
SQ_A7, SQ_B7, SQ_C7, SQ_D7, SQ_E7, SQ_F7, SQ_G7, SQ_H7,
|
SQ_A7, SQ_B7, SQ_C7, SQ_D7, SQ_E7, SQ_F7, SQ_G7, SQ_H7,
|
||||||
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
||||||
SQ_NONE
|
SQ_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum File {
|
enum File {
|
||||||
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NONE
|
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NONE
|
||||||
@@ -73,7 +73,7 @@ const int FlipMask = 070;
|
|||||||
const int FlopMask = 07;
|
const int FlopMask = 07;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
@@ -159,21 +159,43 @@ inline int square_distance(Square s1, Square s2) {
|
|||||||
return Max(file_distance(s1, s2), rank_distance(s1, s2));
|
return Max(file_distance(s1, s2), rank_distance(s1, s2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline File file_from_char(char c) {
|
||||||
|
return File(c - 'a') + FILE_A;
|
||||||
|
}
|
||||||
|
|
||||||
////
|
inline char file_to_char(File f) {
|
||||||
//// Prototypes
|
return char(f - FILE_A + int('a'));
|
||||||
////
|
}
|
||||||
|
|
||||||
extern File file_from_char(char c);
|
inline Rank rank_from_char(char c) {
|
||||||
extern char file_to_char(File f);
|
return Rank(c - '1') + RANK_1;
|
||||||
extern Rank rank_from_char(char c);
|
}
|
||||||
extern char rank_to_char(Rank r);
|
|
||||||
extern Square square_from_string(const std::string &str);
|
|
||||||
extern const std::string square_to_string(Square s);
|
|
||||||
|
|
||||||
extern bool file_is_ok(File f);
|
inline char rank_to_char(Rank r) {
|
||||||
extern bool rank_is_ok(Rank r);
|
return char(r - RANK_1 + int('1'));
|
||||||
extern bool square_is_ok(Square s);
|
}
|
||||||
|
|
||||||
|
inline Square square_from_string(const std::string& str) {
|
||||||
|
return make_square(file_from_char(str[0]), rank_from_char(str[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const std::string square_to_string(Square s) {
|
||||||
|
std::string str;
|
||||||
|
str += file_to_char(square_file(s));
|
||||||
|
str += rank_to_char(square_rank(s));
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool file_is_ok(File f) {
|
||||||
|
return f >= FILE_A && f <= FILE_H;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool rank_is_ok(Rank r) {
|
||||||
|
return r >= RANK_1 && r <= RANK_8;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool square_is_ok(Square s) {
|
||||||
|
return file_is_ok(square_file(s)) && rank_is_ok(square_rank(s));
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(SQUARE_H_INCLUDED)
|
#endif // !defined(SQUARE_H_INCLUDED)
|
||||||
|
|||||||
+5
-4
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -66,13 +66,14 @@ struct Thread {
|
|||||||
SplitPoint *splitPoint;
|
SplitPoint *splitPoint;
|
||||||
int activeSplitPoints;
|
int activeSplitPoints;
|
||||||
uint64_t nodes;
|
uint64_t nodes;
|
||||||
|
uint64_t betaCutOffs[2];
|
||||||
bool failHighPly1;
|
bool failHighPly1;
|
||||||
volatile bool stop;
|
volatile bool stop;
|
||||||
volatile bool running;
|
volatile bool running;
|
||||||
volatile bool idle;
|
volatile bool idle;
|
||||||
volatile bool workIsWaiting;
|
volatile bool workIsWaiting;
|
||||||
volatile bool printCurrentLine;
|
volatile bool printCurrentLine;
|
||||||
unsigned char pad[64];
|
unsigned char pad[64]; // set some distance among local data for each thread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
(c) Copyright 1992 Eric Backus
|
|
||||||
|
|
||||||
This software may be used freely so long as this copyright notice is
|
|
||||||
left intact. There is no warrantee on this software.
|
|
||||||
*/
|
|
||||||
#include <windows.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include "dos.h"
|
|
||||||
|
|
||||||
|
|
||||||
int gettimeofday(struct timeval * tp, struct timezone * tzp)
|
|
||||||
{
|
|
||||||
SYSTEMTIME systime;
|
|
||||||
|
|
||||||
if (tp) {
|
|
||||||
struct tm tmrec;
|
|
||||||
time_t theTime = time(NULL);
|
|
||||||
|
|
||||||
|
|
||||||
tmrec = *localtime(&theTime);
|
|
||||||
tp->tv_sec = mktime(&tmrec);
|
|
||||||
GetLocalTime(&systime); /* system time */
|
|
||||||
|
|
||||||
tp->tv_usec = systime.wMilliseconds * 1000;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
+129
-86
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,28 +25,25 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <xmmintrin.h>
|
||||||
|
|
||||||
|
#include "movegen.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
|
|
||||||
|
// The main transposition table
|
||||||
|
TranspositionTable TT;
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// Constructor
|
TranspositionTable::TranspositionTable() {
|
||||||
|
|
||||||
TranspositionTable::TranspositionTable(unsigned mbSize) {
|
size = writes = 0;
|
||||||
|
|
||||||
size = 0;
|
|
||||||
generation = 0;
|
|
||||||
writes = 0;
|
|
||||||
entries = 0;
|
entries = 0;
|
||||||
set_size(mbSize);
|
generation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Destructor
|
|
||||||
|
|
||||||
TranspositionTable::~TranspositionTable() {
|
TranspositionTable::~TranspositionTable() {
|
||||||
|
|
||||||
delete [] entries;
|
delete [] entries;
|
||||||
@@ -58,77 +55,93 @@ TranspositionTable::~TranspositionTable() {
|
|||||||
|
|
||||||
void TranspositionTable::set_size(unsigned mbSize) {
|
void TranspositionTable::set_size(unsigned mbSize) {
|
||||||
|
|
||||||
assert(mbSize >= 4 && mbSize <= 1024);
|
assert(mbSize >= 4 && mbSize <= 4096);
|
||||||
|
|
||||||
unsigned newSize = 1024;
|
unsigned newSize = 1024;
|
||||||
|
|
||||||
// We store a cluster of 4 TTEntry for each position and newSize is
|
// We store a cluster of ClusterSize number of TTEntry for each position
|
||||||
// the maximum number of storable positions
|
// and newSize is the maximum number of storable positions.
|
||||||
for ( ; newSize * 4 * (sizeof(TTEntry)) <= (mbSize << 20); newSize *= 2);
|
while ((2 * newSize) * sizeof(TTCluster) <= (mbSize << 20))
|
||||||
newSize /= 2;
|
newSize *= 2;
|
||||||
|
|
||||||
if (newSize != size)
|
if (newSize != size)
|
||||||
{
|
{
|
||||||
size = newSize;
|
size = newSize;
|
||||||
delete [] entries;
|
delete [] entries;
|
||||||
entries = new TTEntry[size * 4];
|
entries = new TTCluster[size];
|
||||||
if (!entries)
|
if (!entries)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to allocate " << mbSize
|
std::cerr << "Failed to allocate " << mbSize
|
||||||
<< " MB for transposition table."
|
<< " MB for transposition table." << std::endl;
|
||||||
<< std::endl;
|
Application::exit_with_failure();
|
||||||
exit(EXIT_FAILURE);
|
}
|
||||||
}
|
clear();
|
||||||
clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::clear overwrites the entire transposition table
|
/// TranspositionTable::clear overwrites the entire transposition table
|
||||||
/// with zeroes. It is called whenever the table is resized, or when the
|
/// with zeroes. It is called whenever the table is resized, or when the
|
||||||
/// user asks the program to clear the table (from the UCI interface).
|
/// user asks the program to clear the table (from the UCI interface).
|
||||||
/// Perhaps we should also clear it when the "ucinewgame" command is recieved?
|
/// Perhaps we should also clear it when the "ucinewgame" command is recieved?
|
||||||
|
|
||||||
void TranspositionTable::clear() {
|
void TranspositionTable::clear() {
|
||||||
|
|
||||||
memset(entries, 0, size * 4 * sizeof(TTEntry));
|
memset(entries, 0, size * sizeof(TTCluster));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// 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. The transposition table is organized in clusters
|
/// transposition table. Transposition table is organized in clusters of
|
||||||
/// of four TTEntry objects, and when a new entry is written, it replaces
|
/// four TTEntry objects, and when a new entry is written, it replaces
|
||||||
/// the least valuable of the four entries in a cluster. A TTEntry t1 is
|
/// the least valuable of the four entries in a cluster. A TTEntry t1 is
|
||||||
/// considered to be more valuable than a TTEntry t2 if t1 is from the
|
/// considered to be more valuable than a TTEntry t2 if t1 is from the
|
||||||
/// current search and t2 is from a previous search, or if the depth of t1
|
/// current search and t2 is from a previous search, or if the depth of t1
|
||||||
/// is bigger than the depth of t2.
|
/// is bigger than the depth of t2. A TTEntry of type VALUE_TYPE_EVAL
|
||||||
|
/// 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 Position &pos, Value v, Depth d,
|
|
||||||
Move m, ValueType type) {
|
|
||||||
TTEntry *tte, *replace;
|
TTEntry *tte, *replace;
|
||||||
|
uint32_t posKey32 = posKey >> 32; // Use the high 32 bits as key
|
||||||
|
|
||||||
tte = replace = first_entry(pos);
|
tte = replace = first_entry(posKey);
|
||||||
for (int i = 0; i < 4; i++, tte++)
|
for (int i = 0; i < ClusterSize; i++, tte++)
|
||||||
{
|
{
|
||||||
if (!tte->key() || tte->key() == pos.get_key()) // empty or overwrite old
|
if (!tte->key() || tte->key() == posKey32) // empty or overwrite old
|
||||||
{
|
{
|
||||||
if (m == MOVE_NONE)
|
// Do not overwrite when new type is VALUE_TYPE_EV_LO
|
||||||
m = tte->move();
|
if (tte->key() && t == VALUE_TYPE_EV_LO)
|
||||||
|
return;
|
||||||
|
|
||||||
*tte = TTEntry(pos.get_key(), v, type, d, m, generation);
|
if (m == MOVE_NONE)
|
||||||
return;
|
m = tte->move();
|
||||||
}
|
|
||||||
else if (i == 0) // replace would be a no-op in this common case
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int c1 = (replace->generation() == generation ? 2 : 0);
|
*tte = TTEntry(posKey32, v, t, d, m, generation);
|
||||||
int c2 = (tte->generation() == generation ? -2 : 0);
|
return;
|
||||||
int c3 = (tte->depth() < replace->depth() ? 1 : 0);
|
}
|
||||||
|
else if (i == 0) // replace would be a no-op in this common case
|
||||||
|
continue;
|
||||||
|
|
||||||
if (c1 + c2 + c3 > 0)
|
int c1 = (replace->generation() == generation ? 2 : 0);
|
||||||
replace = tte;
|
int c2 = (tte->generation() == generation ? -2 : 0);
|
||||||
|
int c3 = (tte->depth() < replace->depth() ? 1 : 0);
|
||||||
|
|
||||||
|
if (c1 + c2 + c3 > 0)
|
||||||
|
replace = tte;
|
||||||
}
|
}
|
||||||
*replace = TTEntry(pos.get_key(), v, type, d, m, generation);
|
*replace = TTEntry(posKey32, v, t, d, m, generation);
|
||||||
writes++;
|
writes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,29 +150,42 @@ void TranspositionTable::store(const Position &pos, Value v, Depth d,
|
|||||||
/// transposition table. Returns a pointer to the TTEntry or NULL
|
/// transposition table. Returns a pointer to the TTEntry or NULL
|
||||||
/// if position is not found.
|
/// if position is not found.
|
||||||
|
|
||||||
const TTEntry* TranspositionTable::retrieve(const Position &pos) const {
|
TTEntry* TranspositionTable::retrieve(const Key posKey) const {
|
||||||
|
|
||||||
TTEntry *tte = first_entry(pos);
|
uint32_t posKey32 = posKey >> 32;
|
||||||
|
TTEntry* tte = first_entry(posKey);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++, tte++)
|
for (int i = 0; i < ClusterSize; i++, tte++)
|
||||||
{
|
if (tte->key() == posKey32)
|
||||||
if (tte->key() == pos.get_key())
|
|
||||||
return tte;
|
return tte;
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::first_entry returns a pointer to the first
|
/// TranspositionTable::prefetch looks up the current position in the
|
||||||
/// entry of a cluster given a position.
|
/// 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.
|
||||||
|
|
||||||
inline TTEntry* TranspositionTable::first_entry(const Position &pos) const {
|
void TranspositionTable::prefetch(const Key posKey) const {
|
||||||
|
|
||||||
return entries + (int(pos.get_key() & (size - 1)) << 2);
|
#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
|
||||||
/// entries from the current search.
|
/// entries from the current search.
|
||||||
|
|
||||||
@@ -171,43 +197,60 @@ void TranspositionTable::new_search() {
|
|||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::insert_pv() is called at the end of a search
|
/// TranspositionTable::insert_pv() is called at the end of a search
|
||||||
/// iteration, and inserts the PV back into the PV. This makes sure the
|
/// iteration, and inserts the PV back into the PV. This makes sure
|
||||||
/// old PV moves are searched first, even if the old TT entries have been
|
/// the old PV moves are searched first, even if the old TT entries
|
||||||
/// overwritten.
|
/// have been overwritten.
|
||||||
|
|
||||||
void TranspositionTable::insert_pv(const Position &pos, Move pv[]) {
|
void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
||||||
|
|
||||||
UndoInfo u;
|
StateInfo st;
|
||||||
Position p(pos);
|
Position p(pos);
|
||||||
|
|
||||||
for (int i = 0; pv[i] != MOVE_NONE; i++)
|
for (int i = 0; pv[i] != MOVE_NONE; i++)
|
||||||
{
|
{
|
||||||
store(p, VALUE_NONE, Depth(0), pv[i], VALUE_TYPE_NONE);
|
store(p.get_key(), VALUE_NONE, VALUE_TYPE_NONE, Depth(-127*OnePly), pv[i]);
|
||||||
p.do_move(pv[i], u);
|
p.do_move(pv[i], st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// TranspositionTable::extract_pv() extends a PV by adding moves from the
|
||||||
|
/// transposition table at the end. This should ensure that the PV is almost
|
||||||
|
/// always at least two plies long, which is important, because otherwise we
|
||||||
|
/// 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.
|
||||||
|
|
||||||
|
void TranspositionTable::extract_pv(const Position& pos, Move pv[], int pvSize) {
|
||||||
|
|
||||||
|
const TTEntry* tte;
|
||||||
|
StateInfo st;
|
||||||
|
Position p(pos);
|
||||||
|
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 < pvSize)
|
||||||
|
{
|
||||||
|
pv[ply] = tte->move();
|
||||||
|
p.do_move(pv[ply++], st);
|
||||||
|
}
|
||||||
|
pv[ply] = MOVE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::full() returns the permill of all transposition table
|
/// TranspositionTable::full() returns the permill of all transposition table
|
||||||
/// entries which have received at least one write during the current search.
|
/// entries which have received at least one write during the current search.
|
||||||
/// It is used to display the "info hashfull ..." information in UCI.
|
/// It is used to display the "info hashfull ..." information in UCI.
|
||||||
|
|
||||||
int TranspositionTable::full() {
|
int TranspositionTable::full() const {
|
||||||
|
|
||||||
double N = double(size) * 4.0;
|
double N = double(size) * ClusterSize;
|
||||||
return int(1000 * (1 - exp(writes * log(1.0 - 1.0/N))));
|
return int(1000 * (1 - exp(writes * log(1.0 - 1.0/N))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Constructors
|
|
||||||
|
|
||||||
TTEntry::TTEntry() {
|
|
||||||
}
|
|
||||||
|
|
||||||
TTEntry::TTEntry(Key k, Value v, ValueType t, Depth d, Move m,
|
|
||||||
int generation) :
|
|
||||||
key_ (k), data((m & 0x7FFFF) | (t << 20) | (generation << 23)),
|
|
||||||
value_(v), depth_(int16_t(d)) {}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,60 +34,91 @@
|
|||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
/// The TTEntry class is the class of transposition table entries.
|
/// The TTEntry class is the class of transposition table entries
|
||||||
|
///
|
||||||
|
/// A TTEntry needs 96 bits to be stored
|
||||||
|
///
|
||||||
|
/// bit 0-31: key
|
||||||
|
/// bit 32-63: data
|
||||||
|
/// bit 64-79: value
|
||||||
|
/// bit 80-95: depth
|
||||||
|
///
|
||||||
|
/// the 32 bits of the data field are so defined
|
||||||
|
///
|
||||||
|
/// bit 0-16: move
|
||||||
|
/// bit 17-19: not used
|
||||||
|
/// bit 20-22: value type
|
||||||
|
/// bit 23-31: generation
|
||||||
|
|
||||||
class TTEntry {
|
class TTEntry {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TTEntry();
|
TTEntry() {}
|
||||||
TTEntry(Key k, Value v, ValueType t, Depth d, Move m, int generation);
|
TTEntry(uint32_t k, Value v, ValueType t, Depth d, Move m, int generation)
|
||||||
Key key() const { return key_; }
|
: key_ (k), data((m & 0x1FFFF) | (t << 20) | (generation << 23)),
|
||||||
|
value_(int16_t(v)), depth_(int16_t(d)) {}
|
||||||
|
|
||||||
|
uint32_t key() const { return key_; }
|
||||||
Depth depth() const { return Depth(depth_); }
|
Depth depth() const { return Depth(depth_); }
|
||||||
Move move() const { return Move(data & 0x7FFFF); }
|
Move move() const { return Move(data & 0x1FFFF); }
|
||||||
Value value() const { return Value(value_); }
|
Value value() const { return Value(value_); }
|
||||||
ValueType type() const { return ValueType((data >> 20) & 3); }
|
ValueType type() const { return ValueType((data >> 20) & 7); }
|
||||||
int generation() const { return (data >> 23); }
|
int generation() const { return (data >> 23); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Key key_;
|
uint32_t key_;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
int16_t value_;
|
int16_t value_;
|
||||||
int16_t depth_;
|
int16_t depth_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The transposition table class. This is basically just a huge array
|
|
||||||
|
/// This is the number of TTEntry slots for each position
|
||||||
|
const int ClusterSize = 5;
|
||||||
|
|
||||||
|
/// Each group of ClusterSize number of TTEntry form a TTCluster
|
||||||
|
/// that is indexed by a single position key. Cluster is padded
|
||||||
|
/// to a cache line size so to guarantee always aligned accesses.
|
||||||
|
|
||||||
|
struct TTCluster {
|
||||||
|
TTEntry data[ClusterSize];
|
||||||
|
char cache_line_padding[64 - sizeof(TTEntry[ClusterSize])];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// The transposition table class. This is basically just a huge array
|
||||||
/// containing TTEntry objects, and a few methods for writing new entries
|
/// containing TTEntry objects, and a few methods for writing new entries
|
||||||
/// and reading new ones.
|
/// and reading new ones.
|
||||||
|
|
||||||
class TranspositionTable {
|
class TranspositionTable {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TranspositionTable(unsigned mbSize);
|
TranspositionTable();
|
||||||
~TranspositionTable();
|
~TranspositionTable();
|
||||||
void set_size(unsigned mbSize);
|
void set_size(unsigned mbSize);
|
||||||
void clear();
|
void clear();
|
||||||
void store(const Position &pos, Value v, Depth d, Move m, ValueType type);
|
void store(const Key posKey, Value v, ValueType type, Depth d, Move m);
|
||||||
const TTEntry* retrieve(const Position &pos) 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[]);
|
||||||
int full();
|
void extract_pv(const Position& pos, Move pv[], int pvSize);
|
||||||
|
int full() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline TTEntry* first_entry(const Position &pos) const;
|
inline TTEntry* first_entry(const Key posKey) const;
|
||||||
|
|
||||||
|
// Be sure 'writes' is at least one cache line away
|
||||||
|
// from read only variables.
|
||||||
|
unsigned char pad_before[64 - sizeof(unsigned)];
|
||||||
|
unsigned writes; // heavy SMP read/write access here
|
||||||
|
unsigned char pad_after[64];
|
||||||
|
|
||||||
unsigned size;
|
unsigned size;
|
||||||
int writes;
|
TTCluster* entries;
|
||||||
TTEntry* entries;
|
|
||||||
uint8_t generation;
|
uint8_t generation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern TranspositionTable TT;
|
||||||
////
|
|
||||||
//// Constants and variables
|
|
||||||
////
|
|
||||||
|
|
||||||
// Default transposition table size, in megabytes:
|
|
||||||
const int TTDefaultSize = 32;
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(TT_H_INCLUDED)
|
#endif // !defined(TT_H_INCLUDED)
|
||||||
|
|||||||
+34
-5
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -31,7 +31,7 @@ typedef __int8 int8_t;
|
|||||||
typedef unsigned __int8 uint8_t;
|
typedef unsigned __int8 uint8_t;
|
||||||
typedef __int16 int16;
|
typedef __int16 int16;
|
||||||
typedef unsigned __int16 uint16_t;
|
typedef unsigned __int16 uint16_t;
|
||||||
typedef __int32 int32;
|
typedef __int32 int32_t;
|
||||||
typedef unsigned __int32 uint32_t;
|
typedef unsigned __int32 uint32_t;
|
||||||
typedef __int64 int64;
|
typedef __int64 int64;
|
||||||
typedef unsigned __int64 uint64_t;
|
typedef unsigned __int64 uint64_t;
|
||||||
@@ -41,7 +41,36 @@ typedef __int64 int64_t;
|
|||||||
|
|
||||||
#endif // !defined(_MSC_VER)
|
#endif // !defined(_MSC_VER)
|
||||||
|
|
||||||
// Hash keys:
|
// Hash keys
|
||||||
typedef uint64_t Key;
|
typedef uint64_t Key;
|
||||||
|
|
||||||
|
// Bitboard type
|
||||||
|
typedef uint64_t Bitboard;
|
||||||
|
|
||||||
|
|
||||||
|
////
|
||||||
|
//// Compiler specific defines
|
||||||
|
////
|
||||||
|
|
||||||
|
// Quiet a warning on Intel compiler
|
||||||
|
#if !defined(__SIZEOF_INT__ )
|
||||||
|
#define __SIZEOF_INT__ 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Check for 64 bits for different compilers: Intel, MSVC and gcc
|
||||||
|
#if defined(__x86_64) || defined(_M_X64) || defined(_WIN64) || (__SIZEOF_INT__ > 4)
|
||||||
|
#define IS_64BIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(IS_64BIT) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
|
||||||
|
#define USE_BSFQ
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Cache line alignment specification
|
||||||
|
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||||
|
#define CACHE_LINE_ALIGNMENT __declspec(align(64))
|
||||||
|
#else
|
||||||
|
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // !defined(TYPES_H_INCLUDED)
|
#endif // !defined(TYPES_H_INCLUDED)
|
||||||
|
|||||||
+85
-91
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
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,6 +22,7 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -37,6 +38,7 @@
|
|||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
#include "ucioption.h"
|
#include "ucioption.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions:
|
//// Local definitions:
|
||||||
@@ -44,22 +46,21 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// UCIInputParser is a class for parsing UCI input. The class
|
// UCIInputParser is a class for parsing UCI input. The class
|
||||||
// is actually a string stream built on a given input string.
|
// is actually a string stream built on a given input string.
|
||||||
|
|
||||||
typedef std::istringstream UCIInputParser;
|
typedef istringstream UCIInputParser;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
// Local functions
|
// Local functions
|
||||||
void get_command();
|
bool handle_command(const string& command);
|
||||||
void handle_command(const std::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);
|
||||||
void go(UCIInputParser &uip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -67,17 +68,25 @@ namespace {
|
|||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// uci_main_loop() is the only global function in this file. It is
|
/// uci_main_loop() is the only global function in this file. It is
|
||||||
/// called immediately after the program has finished initializing.
|
/// called immediately after the program has finished initializing.
|
||||||
/// The program remains in this loop until it receives the "quit" UCI
|
/// The program remains in this loop until it receives the "quit" UCI
|
||||||
/// command.
|
/// command. It waits for a command from the user, and passes this
|
||||||
|
/// command to handle_command and also intercepts EOF from stdin,
|
||||||
|
/// by translating EOF to the "quit" command. This ensures that Stockfish
|
||||||
|
/// exits gracefully if the GUI dies unexpectedly.
|
||||||
|
|
||||||
void uci_main_loop() {
|
void uci_main_loop() {
|
||||||
|
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
|
string command;
|
||||||
|
|
||||||
while (1)
|
do {
|
||||||
get_command();
|
// Wait for a command from stdin
|
||||||
|
if (!getline(cin, command))
|
||||||
|
command = "quit";
|
||||||
|
|
||||||
|
} while (handle_command(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,64 +96,43 @@ void uci_main_loop() {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// get_command() waits for a command from the user, and passes
|
|
||||||
// this command to handle_command. get_command also intercepts
|
|
||||||
// EOF from stdin, by translating EOF to the "quit" command. This
|
|
||||||
// ensures that Stockfish exits gracefully if the GUI dies
|
|
||||||
// unexpectedly.
|
|
||||||
|
|
||||||
void get_command() {
|
|
||||||
|
|
||||||
std::string command;
|
|
||||||
|
|
||||||
if (!std::getline(std::cin, command))
|
|
||||||
command = "quit";
|
|
||||||
|
|
||||||
handle_command(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// handle_command() takes a text string as input, uses a
|
// handle_command() takes a text string as input, uses a
|
||||||
// UCIInputParser object to parse this text string as a UCI command,
|
// UCIInputParser object to parse this text string as a UCI command,
|
||||||
// and calls the appropriate functions. In addition to the UCI
|
// and calls the appropriate functions. In addition to the UCI
|
||||||
// commands, the function also supports a few debug commands.
|
// commands, the function also supports a few debug commands.
|
||||||
|
|
||||||
void handle_command(const std::string &command) {
|
bool handle_command(const string& command) {
|
||||||
|
|
||||||
UCIInputParser uip(command);
|
UCIInputParser uip(command);
|
||||||
std::string token;
|
string token;
|
||||||
|
|
||||||
uip >> token; // operator >> skips any whitespace
|
uip >> token; // operator>>() skips any whitespace
|
||||||
|
|
||||||
if (token == "quit")
|
if (token == "quit")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (token == "go")
|
||||||
|
return go(uip);
|
||||||
|
|
||||||
|
if (token == "uci")
|
||||||
{
|
{
|
||||||
OpeningBook.close();
|
cout << "id name " << engine_name()
|
||||||
stop_threads();
|
<< "\nid author Tord Romstad, Marco Costalba, Joona Kiiski\n";
|
||||||
quit_eval();
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
else if (token == "uci")
|
|
||||||
{
|
|
||||||
std::cout << "id name " << engine_name() << std::endl
|
|
||||||
<< "id author Tord Romstad, Marco Costalba"
|
|
||||||
<< std::endl;
|
|
||||||
print_uci_options();
|
print_uci_options();
|
||||||
std::cout << "uciok" << std::endl;
|
cout << "uciok" << endl;
|
||||||
}
|
}
|
||||||
else if (token == "ucinewgame")
|
else if (token == "ucinewgame")
|
||||||
{
|
{
|
||||||
TT.clear();
|
push_button("Clear Hash");
|
||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
}
|
}
|
||||||
else if (token == "isready")
|
else if (token == "isready")
|
||||||
std::cout << "readyok" << std::endl;
|
cout << "readyok" << endl;
|
||||||
else if (token == "position")
|
else if (token == "position")
|
||||||
set_position(uip);
|
set_position(uip);
|
||||||
else if (token == "setoption")
|
else if (token == "setoption")
|
||||||
set_option(uip);
|
set_option(uip);
|
||||||
else if (token == "go")
|
|
||||||
go(uip);
|
|
||||||
|
|
||||||
// The remaining commands are for debugging purposes only.
|
// The remaining commands are for debugging purposes only.
|
||||||
// Perhaps they should be removed later in order to reduce the
|
// Perhaps they should be removed later in order to reduce the
|
||||||
@@ -159,55 +147,49 @@ namespace {
|
|||||||
else if (token == "eval")
|
else if (token == "eval")
|
||||||
{
|
{
|
||||||
EvalInfo ei;
|
EvalInfo ei;
|
||||||
std::cout << "Incremental mg: " << RootPosition.mg_value()
|
cout << "Incremental mg: " << RootPosition.mg_value()
|
||||||
<< std::endl;
|
<< "\nIncremental eg: " << RootPosition.eg_value()
|
||||||
std::cout << "Incremental eg: " << RootPosition.eg_value()
|
<< "\nFull eval: " << evaluate(RootPosition, ei, 0) << endl;
|
||||||
<< std::endl;
|
|
||||||
std::cout << "Full eval: "
|
|
||||||
<< evaluate(RootPosition, ei, 0)
|
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
else if (token == "key")
|
else if (token == "key")
|
||||||
{
|
cout << "key: " << hex << RootPosition.get_key()
|
||||||
std::cout << "key: " << RootPosition.get_key()
|
<< "\nmaterial key: " << RootPosition.get_material_key()
|
||||||
<< " material key: " << RootPosition.get_material_key()
|
<< "\npawn key: " << RootPosition.get_pawn_key() << endl;
|
||||||
<< " pawn key: " << RootPosition.get_pawn_key()
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Unknown command: " << command << std::endl;
|
cout << "Unknown command: " << command << endl;
|
||||||
while (!uip.eof())
|
while (!uip.eof())
|
||||||
{
|
{
|
||||||
uip >> token;
|
uip >> token;
|
||||||
std::cout << token << std::endl;
|
cout << token << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// set_position() is called when Stockfish receives the "position" UCI
|
// set_position() is called when Stockfish receives the "position" UCI
|
||||||
// command. The input parameter is a UCIInputParser. It is assumed
|
// command. The input parameter is a UCIInputParser. It is assumed
|
||||||
// that this parser has consumed the first token of the UCI command
|
// that this parser has consumed the first token of the UCI command
|
||||||
// ("position"), and is ready to read the second token ("startpos"
|
// ("position"), and is ready to read the second token ("startpos"
|
||||||
// or "fen", if the input is well-formed).
|
// or "fen", if the input is well-formed).
|
||||||
|
|
||||||
void set_position(UCIInputParser &uip) {
|
void set_position(UCIInputParser& uip) {
|
||||||
|
|
||||||
std::string token;
|
string token;
|
||||||
|
|
||||||
uip >> token; // operator >> skips any whitespace
|
uip >> token; // operator>>() skips any whitespace
|
||||||
|
|
||||||
if (token == "startpos")
|
if (token == "startpos")
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
else if (token == "fen")
|
else if (token == "fen")
|
||||||
{
|
{
|
||||||
std::string fen;
|
string fen;
|
||||||
while (token != "moves" && !uip.eof())
|
while (token != "moves" && !uip.eof())
|
||||||
{
|
{
|
||||||
uip >> token;
|
uip >> token;
|
||||||
fen += token;
|
fen += token;
|
||||||
fen += ' ';
|
fen += ' ';
|
||||||
}
|
}
|
||||||
RootPosition.from_fen(fen);
|
RootPosition.from_fen(fen);
|
||||||
}
|
}
|
||||||
@@ -219,43 +201,51 @@ namespace {
|
|||||||
if (token == "moves")
|
if (token == "moves")
|
||||||
{
|
{
|
||||||
Move move;
|
Move move;
|
||||||
UndoInfo u;
|
StateInfo st;
|
||||||
while (!uip.eof())
|
while (!uip.eof())
|
||||||
{
|
{
|
||||||
uip >> token;
|
uip >> token;
|
||||||
move = move_from_string(RootPosition, token);
|
move = move_from_string(RootPosition, token);
|
||||||
RootPosition.do_move(move, u);
|
RootPosition.do_move(move, st);
|
||||||
if (RootPosition.rule_50_counter() == 0)
|
if (RootPosition.rule_50_counter() == 0)
|
||||||
RootPosition.reset_game_ply();
|
RootPosition.reset_game_ply();
|
||||||
}
|
}
|
||||||
|
// Our StateInfo st is about going out of scope so copy
|
||||||
|
// its content inside RootPosition before they disappear.
|
||||||
|
RootPosition.saveState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// set_option() is called when Stockfish receives the "setoption" UCI
|
// set_option() is called when Stockfish receives the "setoption" UCI
|
||||||
// command. The input parameter is a UCIInputParser. It is assumed
|
// command. The input parameter is a UCIInputParser. It is assumed
|
||||||
// that this parser has consumed the first token of the UCI command
|
// that this parser has consumed the first token of the UCI command
|
||||||
// ("setoption"), and is ready to read the second token ("name", if
|
// ("setoption"), and is ready to read the second token ("name", if
|
||||||
// the input is well-formed).
|
// the input is well-formed).
|
||||||
|
|
||||||
void set_option(UCIInputParser &uip) {
|
void set_option(UCIInputParser& uip) {
|
||||||
|
|
||||||
std::string token, name;
|
string token, name;
|
||||||
|
|
||||||
uip >> token;
|
uip >> token;
|
||||||
if (token == "name")
|
if (token == "name")
|
||||||
{
|
{
|
||||||
uip >> name;
|
uip >> name;
|
||||||
uip >> token;
|
while (!uip.eof())
|
||||||
while (!uip.eof() && token != "value")
|
|
||||||
{
|
{
|
||||||
name += (" " + token);
|
uip >> token;
|
||||||
uip >> token;
|
if (token == "value")
|
||||||
|
break;
|
||||||
|
|
||||||
|
name += (" " + token);
|
||||||
}
|
}
|
||||||
if (token == "value")
|
if (token == "value")
|
||||||
{
|
{
|
||||||
std::getline(uip, token); // reads until end of line
|
// 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);
|
set_option_value(name, token);
|
||||||
} else
|
} else
|
||||||
push_button(name);
|
push_button(name);
|
||||||
@@ -263,17 +253,18 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// go() is called when Stockfish receives the "go" UCI command. The
|
// go() is called when Stockfish receives the "go" UCI command. The
|
||||||
// input parameter is a UCIInputParser. It is assumed that this
|
// input parameter is a UCIInputParser. It is assumed that this
|
||||||
// parser has consumed the first token of the UCI command ("go"),
|
// parser has consumed the first token of the UCI command ("go"),
|
||||||
// and is ready to read the second token. The function sets the
|
// and is ready to read the second token. The function sets the
|
||||||
// thinking time and other parameters from the input string, and
|
// thinking time and other parameters from the input string, and
|
||||||
// calls think() (defined in search.cpp) with the appropriate
|
// calls think() (defined in search.cpp) with the appropriate
|
||||||
// parameters.
|
// parameters. Returns false if a quit command is received while
|
||||||
|
// thinking, returns true otherwise.
|
||||||
|
|
||||||
void go(UCIInputParser &uip) {
|
bool go(UCIInputParser& uip) {
|
||||||
|
|
||||||
std::string token;
|
string token;
|
||||||
|
|
||||||
int time[2] = {0, 0}, inc[2] = {0, 0};
|
int time[2] = {0, 0}, inc[2] = {0, 0};
|
||||||
int movesToGo = 0, depth = 0, nodes = 0, moveTime = 0;
|
int movesToGo = 0, depth = 0, nodes = 0, moveTime = 0;
|
||||||
@@ -321,7 +312,10 @@ namespace {
|
|||||||
if (moveTime)
|
if (moveTime)
|
||||||
infinite = true; // HACK
|
infinite = true; // HACK
|
||||||
|
|
||||||
think(RootPosition, infinite, ponder, RootPosition.side_to_move(), time,
|
assert(RootPosition.is_ok());
|
||||||
inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
|
||||||
|
return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
|
||||||
|
time, inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+149
-190
@@ -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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,7 +22,9 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -31,13 +33,7 @@
|
|||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "ucioption.h"
|
#include "ucioption.h"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
////
|
|
||||||
//// Variables
|
|
||||||
////
|
|
||||||
|
|
||||||
bool Chess960 = false;
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
@@ -51,97 +47,94 @@ namespace {
|
|||||||
|
|
||||||
enum OptionType { SPIN, COMBO, CHECK, STRING, BUTTON };
|
enum OptionType { SPIN, COMBO, CHECK, STRING, BUTTON };
|
||||||
|
|
||||||
typedef std::vector<std::string> ComboValues;
|
typedef std::vector<string> ComboValues;
|
||||||
|
|
||||||
struct Option {
|
struct Option {
|
||||||
|
|
||||||
std::string name, defaultValue, currentValue;
|
string name, defaultValue, currentValue;
|
||||||
OptionType type;
|
OptionType type;
|
||||||
|
size_t idx;
|
||||||
int minValue, maxValue;
|
int minValue, maxValue;
|
||||||
ComboValues comboValues;
|
ComboValues comboValues;
|
||||||
|
|
||||||
Option(const char* name, const char* defaultValue, OptionType = STRING);
|
Option();
|
||||||
Option(const char* name, bool defaultValue, OptionType = CHECK);
|
Option(const char* defaultValue, OptionType = STRING);
|
||||||
Option(const char* name, int defaultValue, int minValue, int maxValue);
|
Option(bool defaultValue, OptionType = CHECK);
|
||||||
|
Option(int defaultValue, int minValue, int maxValue);
|
||||||
|
|
||||||
|
bool operator<(const Option& o) const { return this->idx < o.idx; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Option> Options;
|
typedef std::map<string, Option> Options;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Constants
|
/// Constants
|
||||||
///
|
///
|
||||||
|
|
||||||
// load_defaults populates the options vector with the hard
|
// load_defaults populates the options map with the hard
|
||||||
// coded names and default values.
|
// coded names and default values.
|
||||||
|
|
||||||
void load_defaults(Options& o) {
|
void load_defaults(Options& o) {
|
||||||
|
|
||||||
o.push_back(Option("Use Search Log", false));
|
o["Use Search Log"] = Option(false);
|
||||||
o.push_back(Option("Search Log Filename", "SearchLog.txt"));
|
o["Search Log Filename"] = Option("SearchLog.txt");
|
||||||
o.push_back(Option("Book File", "book.bin"));
|
o["Book File"] = Option("book.bin");
|
||||||
o.push_back(Option("Mobility (Middle Game)", 100, 0, 200));
|
o["Mobility (Middle Game)"] = Option(100, 0, 200);
|
||||||
o.push_back(Option("Mobility (Endgame)", 100, 0, 200));
|
o["Mobility (Endgame)"] = Option(100, 0, 200);
|
||||||
o.push_back(Option("Pawn Structure (Middle Game)", 100, 0, 200));
|
o["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
|
||||||
o.push_back(Option("Pawn Structure (Endgame)", 100, 0, 200));
|
o["Pawn Structure (Endgame)"] = Option(100, 0, 200);
|
||||||
o.push_back(Option("Passed Pawns (Middle Game)", 100, 0, 200));
|
o["Passed Pawns (Middle Game)"] = Option(100, 0, 200);
|
||||||
o.push_back(Option("Passed Pawns (Endgame)", 100, 0, 200));
|
o["Passed Pawns (Endgame)"] = Option(100, 0, 200);
|
||||||
o.push_back(Option("Aggressiveness", 100, 0, 200));
|
o["Space"] = Option(100, 0, 200);
|
||||||
o.push_back(Option("Cowardice", 100, 0, 200));
|
o["Aggressiveness"] = Option(100, 0, 200);
|
||||||
o.push_back(Option("King Safety Curve", "Quadratic", COMBO));
|
o["Cowardice"] = Option(100, 0, 200);
|
||||||
|
o["King Safety Curve"] = Option("Quadratic", COMBO);
|
||||||
|
|
||||||
o.back().comboValues.push_back("Quadratic");
|
o["King Safety Curve"].comboValues.push_back("Quadratic");
|
||||||
o.back().comboValues.push_back("Linear"); /*, "From File"*/
|
o["King Safety Curve"].comboValues.push_back("Linear"); /*, "From File"*/
|
||||||
|
|
||||||
o.push_back(Option("King Safety Coefficient", 40, 1, 100));
|
o["King Safety Coefficient"] = Option(40, 1, 100);
|
||||||
o.push_back(Option("King Safety X Intercept", 0, 0, 20));
|
o["King Safety X Intercept"] = Option(0, 0, 20);
|
||||||
o.push_back(Option("King Safety Max Slope", 30, 10, 100));
|
o["King Safety Max Slope"] = Option(30, 10, 100);
|
||||||
o.push_back(Option("King Safety Max Value", 500, 100, 1000));
|
o["King Safety Max Value"] = Option(500, 100, 1000);
|
||||||
o.push_back(Option("Queen Contact Check Bonus", 4, 0, 8));
|
o["Queen Contact Check Bonus"] = Option(3, 0, 8);
|
||||||
o.push_back(Option("Rook Contact Check Bonus", 2, 0, 4));
|
o["Queen Check Bonus"] = Option(2, 0, 4);
|
||||||
o.push_back(Option("Queen Check Bonus", 2, 0, 4));
|
o["Rook Check Bonus"] = Option(1, 0, 4);
|
||||||
o.push_back(Option("Rook Check Bonus", 1, 0, 4));
|
o["Bishop Check Bonus"] = Option(1, 0, 4);
|
||||||
o.push_back(Option("Bishop Check Bonus", 1, 0, 4));
|
o["Knight Check Bonus"] = Option(1, 0, 4);
|
||||||
o.push_back(Option("Knight Check Bonus", 1, 0, 4));
|
o["Discovered Check Bonus"] = Option(3, 0, 8);
|
||||||
o.push_back(Option("Discovered Check Bonus", 3, 0, 8));
|
o["Mate Threat Bonus"] = Option(3, 0, 8);
|
||||||
o.push_back(Option("Mate Threat Bonus", 3, 0, 8));
|
o["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o.push_back(Option("Check Extension (PV nodes)", 2, 0, 2));
|
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
o.push_back(Option("Check Extension (non-PV nodes)", 1, 0, 2));
|
o["Single Reply Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o.push_back(Option("Single Reply Extension (PV nodes)", 2, 0, 2));
|
o["Single Reply Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
o.push_back(Option("Single Reply Extension (non-PV nodes)", 2, 0, 2));
|
o["Mate Threat Extension (PV nodes)"] = Option(0, 0, 2);
|
||||||
o.push_back(Option("Mate Threat Extension (PV nodes)", 0, 0, 2));
|
o["Mate Threat Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||||
o.push_back(Option("Mate Threat Extension (non-PV nodes)", 0, 0, 2));
|
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
o.push_back(Option("Pawn Push to 7th Extension (PV nodes)", 1, 0, 2));
|
o["Pawn Push to 7th Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
o.push_back(Option("Pawn Push to 7th Extension (non-PV nodes)", 1, 0, 2));
|
o["Passed Pawn Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
o.push_back(Option("Passed Pawn Extension (PV nodes)", 1, 0, 2));
|
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||||
o.push_back(Option("Passed Pawn Extension (non-PV nodes)", 0, 0, 2));
|
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o.push_back(Option("Pawn Endgame Extension (PV nodes)", 2, 0, 2));
|
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
o.push_back(Option("Pawn Endgame Extension (non-PV nodes)", 2, 0, 2));
|
o["Full Depth Moves (PV nodes)"] = Option(10, 1, 100);
|
||||||
o.push_back(Option("Full Depth Moves (PV nodes)", 14, 1, 100));
|
o["Full Depth Moves (non-PV nodes)"] = Option(3, 1, 100);
|
||||||
o.push_back(Option("Full Depth Moves (non-PV nodes)", 3, 1, 100));
|
o["Threat Depth"] = Option(5, 0, 100);
|
||||||
o.push_back(Option("Threat Depth", 5, 0, 100));
|
o["Randomness"] = Option(0, 0, 10);
|
||||||
o.push_back(Option("Selective Plies", 7, 0, 10));
|
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||||
o.push_back(Option("Null driven IID", true));
|
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
||||||
o.push_back(Option("Futility Pruning (Main Search)", true));
|
o["Threads"] = Option(1, 1, 8);
|
||||||
o.push_back(Option("Futility Pruning (Quiescence Search)", true));
|
o["Hash"] = Option(32, 4, 4096);
|
||||||
o.push_back(Option("Futility Margin 0", 50, 0, 1000));
|
o["Clear Hash"] = Option(false, BUTTON);
|
||||||
o.push_back(Option("Futility Margin 1", 100, 0, 1000));
|
o["Ponder"] = Option(true);
|
||||||
o.push_back(Option("Futility Margin 2", 300, 0, 1000));
|
o["OwnBook"] = Option(true);
|
||||||
o.push_back(Option("Maximum Razoring Depth", 3, 0, 4));
|
o["MultiPV"] = Option(1, 1, 500);
|
||||||
o.push_back(Option("Razoring Margin", 300, 150, 600));
|
o["UCI_ShowCurrLine"] = Option(false);
|
||||||
o.push_back(Option("LSN filtering", false));
|
o["UCI_Chess960"] = Option(false);
|
||||||
o.push_back(Option("LSN Time Margin (sec)", 4, 1, 10));
|
o["UCI_AnalyseMode"] = Option(false);
|
||||||
o.push_back(Option("LSN Value Margin", 200, 100, 600));
|
|
||||||
o.push_back(Option("Randomness", 0, 0, 10));
|
// Any option should know its name so to be easily printed
|
||||||
o.push_back(Option("Minimum Split Depth", 4, 4, 7));
|
for (Options::iterator it = o.begin(); it != o.end(); ++it)
|
||||||
o.push_back(Option("Maximum Number of Threads per Split Point", 5, 4, 8));
|
it->second.name = it->first;
|
||||||
o.push_back(Option("Threads", 1, 1, 8));
|
|
||||||
o.push_back(Option("Hash", 32, 4, 4096));
|
|
||||||
o.push_back(Option("Clear Hash", false, BUTTON));
|
|
||||||
o.push_back(Option("Ponder", true));
|
|
||||||
o.push_back(Option("OwnBook", true));
|
|
||||||
o.push_back(Option("MultiPV", 1, 1, 500));
|
|
||||||
o.push_back(Option("UCI_ShowCurrLine", false));
|
|
||||||
o.push_back(Option("UCI_Chess960", false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -150,56 +143,32 @@ namespace {
|
|||||||
|
|
||||||
Options options;
|
Options options;
|
||||||
|
|
||||||
// Local functions
|
|
||||||
Options::iterator option_with_name(const std::string& optionName);
|
|
||||||
|
|
||||||
// stringify converts a value of type T to a std::string
|
// stringify converts a value of type T to a std::string
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string stringify(const T& v) {
|
string stringify(const T& v) {
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << v;
|
ss << v;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want conversion from a bool value to be "true" or "false",
|
|
||||||
// not "1" or "0", so add a specialization for bool type.
|
|
||||||
template<>
|
|
||||||
std::string stringify<bool>(const bool& v) {
|
|
||||||
|
|
||||||
return v ? "true" : "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
// get_option_value implements the various get_option_value_<type>
|
// get_option_value implements the various get_option_value_<type>
|
||||||
// functions defined later, because only the option value
|
// functions defined later, because only the option value
|
||||||
// type changes a template seems a proper solution.
|
// type changes a template seems a proper solution.
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T get_option_value(const std::string& optionName) {
|
T get_option_value(const string& optionName) {
|
||||||
|
|
||||||
T ret = T();
|
T ret = T();
|
||||||
Options::iterator it = option_with_name(optionName);
|
if (options.find(optionName) == options.end())
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (it != options.end())
|
std::istringstream ss(options[optionName].currentValue);
|
||||||
{
|
ss >> ret;
|
||||||
std::istringstream ss(it->currentValue);
|
|
||||||
ss >> ret;
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unfortunatly we need a specialization to convert "false" and "true"
|
|
||||||
// to proper bool values. The culprit is that we use a non standard way
|
|
||||||
// to store a bool value in a string, in particular we use "false" and
|
|
||||||
// "true" instead of "0" and "1" due to how UCI protocol works.
|
|
||||||
|
|
||||||
template<>
|
|
||||||
bool get_option_value<bool>(const std::string& optionName) {
|
|
||||||
|
|
||||||
Options::iterator it = option_with_name(optionName);
|
|
||||||
|
|
||||||
return it != options.end() && it->currentValue == "true";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -218,25 +187,11 @@ void init_uci_options() {
|
|||||||
// According to Ken Dail's tests, Glaurung plays much better with 7 than
|
// According to Ken Dail's tests, Glaurung plays much better with 7 than
|
||||||
// with 8 threads. This is weird, but it is probably difficult to find out
|
// 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.
|
// why before I have a 8-core computer to experiment with myself.
|
||||||
Options::iterator it = option_with_name("Threads");
|
assert(options.find("Threads") != options.end());
|
||||||
|
assert(options.find("Minimum Split Depth") != options.end());
|
||||||
|
|
||||||
assert(it != options.end());
|
options["Threads"].defaultValue = stringify(Min(cpu_count(), 7));
|
||||||
|
options["Threads"].currentValue = stringify(Min(cpu_count(), 7));
|
||||||
it->defaultValue = stringify(Min(cpu_count(), 7));
|
|
||||||
it->currentValue = stringify(Min(cpu_count(), 7));
|
|
||||||
|
|
||||||
// Increase the minimum split depth when the number of CPUs is big.
|
|
||||||
// It would probably be better to let this depend on the number of threads
|
|
||||||
// instead.
|
|
||||||
if(cpu_count() > 4)
|
|
||||||
{
|
|
||||||
it = option_with_name("Minimum Split Depth");
|
|
||||||
|
|
||||||
assert(it != options.end());
|
|
||||||
|
|
||||||
it->defaultValue = "6";
|
|
||||||
it->currentValue = "6";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,32 +204,42 @@ void print_uci_options() {
|
|||||||
"spin", "combo", "check", "string", "button"
|
"spin", "combo", "check", "string", "button"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (Options::iterator it = options.begin(); it != options.end(); ++it)
|
// Build up a vector out of the options map and sort it according to idx
|
||||||
{
|
// field, that is the chronological insertion order in options map.
|
||||||
std::cout << "option name " << it->name
|
std::vector<Option> vec;
|
||||||
<< " type " << optionTypeName[it->type];
|
for (Options::const_iterator it = options.begin(); it != options.end(); ++it)
|
||||||
|
vec.push_back(it->second);
|
||||||
|
|
||||||
if (it->type != BUTTON)
|
std::sort(vec.begin(), vec.end());
|
||||||
{
|
|
||||||
|
for (std::vector<Option>::const_iterator it = vec.begin(); it != vec.end(); ++it)
|
||||||
|
{
|
||||||
|
std::cout << "\noption name " << it->name
|
||||||
|
<< " type " << optionTypeName[it->type];
|
||||||
|
|
||||||
|
if (it->type == BUTTON)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (it->type == CHECK)
|
||||||
|
std::cout << " default " << (it->defaultValue == "1" ? "true" : "false");
|
||||||
|
else
|
||||||
std::cout << " default " << it->defaultValue;
|
std::cout << " default " << it->defaultValue;
|
||||||
|
|
||||||
if (it->type == SPIN)
|
if (it->type == SPIN)
|
||||||
std::cout << " min " << it->minValue
|
std::cout << " min " << it->minValue << " max " << it->maxValue;
|
||||||
<< " max " << it->maxValue;
|
else if (it->type == COMBO)
|
||||||
|
for (ComboValues::const_iterator itc = it->comboValues.begin();
|
||||||
else if (it->type == COMBO)
|
itc != it->comboValues.end(); ++itc)
|
||||||
for(ComboValues::iterator itc = it->comboValues.begin();
|
std::cout << " var " << *itc;
|
||||||
itc != it->comboValues.end(); ++itc)
|
|
||||||
std::cout << " var " << *itc;
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// get_option_value_bool() returns the current value of a UCI parameter of
|
/// get_option_value_bool() returns the current value of a UCI parameter of
|
||||||
/// type "check".
|
/// type "check".
|
||||||
|
|
||||||
bool get_option_value_bool(const std::string& optionName) {
|
bool get_option_value_bool(const string& optionName) {
|
||||||
|
|
||||||
return get_option_value<bool>(optionName);
|
return get_option_value<bool>(optionName);
|
||||||
}
|
}
|
||||||
@@ -285,84 +250,78 @@ bool get_option_value_bool(const std::string& optionName) {
|
|||||||
/// it could also be used with a "combo" parameter, where all the available
|
/// it could also be used with a "combo" parameter, where all the available
|
||||||
/// values are integers.
|
/// values are integers.
|
||||||
|
|
||||||
int get_option_value_int(const std::string& optionName) {
|
int get_option_value_int(const string& optionName) {
|
||||||
|
|
||||||
return get_option_value<int>(optionName);
|
return get_option_value<int>(optionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// get_option_value_string() returns the current value of a UCI parameter as
|
/// get_option_value_string() returns the current value of a UCI parameter as
|
||||||
/// a string. It is used with parameters of type "combo" and "string".
|
/// a string. It is used with parameters of type "combo" and "string".
|
||||||
|
|
||||||
const std::string get_option_value_string(const std::string& optionName) {
|
string get_option_value_string(const string& optionName) {
|
||||||
|
|
||||||
return get_option_value<std::string>(optionName);
|
return get_option_value<string>(optionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// button_was_pressed() tests whether a UCI parameter of type "button" has
|
/// set_option_value() inserts a new value for a UCI parameter. Note that
|
||||||
/// been selected since the last time the function was called.
|
|
||||||
|
|
||||||
bool button_was_pressed(const std::string& buttonName) {
|
|
||||||
|
|
||||||
if (get_option_value<bool>(buttonName))
|
|
||||||
{
|
|
||||||
set_option_value(buttonName, "false");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// set_option_value() inserts a new value for a UCI parameter. Note that
|
|
||||||
/// the function does not check that the new value is legal for the given
|
/// the function does not check that the new value is legal for the given
|
||||||
/// parameter: This is assumed to be the responsibility of the GUI.
|
/// parameter: This is assumed to be the responsibility of the GUI.
|
||||||
|
|
||||||
void set_option_value(const std::string& optionName,
|
void set_option_value(const string& name, const string& value) {
|
||||||
const std::string& newValue) {
|
|
||||||
|
|
||||||
Options::iterator it = option_with_name(optionName);
|
// UCI protocol uses "true" and "false" instead of "1" and "0", so convert
|
||||||
|
// value according to standard C++ convention before to store it.
|
||||||
|
string v(value);
|
||||||
|
if (v == "true")
|
||||||
|
v = "1";
|
||||||
|
else if (v == "false")
|
||||||
|
v = "0";
|
||||||
|
|
||||||
if (it != options.end())
|
if (options.find(name) != options.end())
|
||||||
it->currentValue = newValue;
|
options[name].currentValue = v;
|
||||||
else
|
else
|
||||||
std::cout << "No such option: " << optionName << std::endl;
|
std::cout << "No such option: " << name << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// push_button() is used to tell the engine that a UCI parameter of type
|
/// push_button() is used to tell the engine that a UCI parameter of type
|
||||||
/// "button" has been selected:
|
/// "button" has been selected:
|
||||||
|
|
||||||
void push_button(const std::string& buttonName) {
|
void push_button(const string& buttonName) {
|
||||||
|
|
||||||
set_option_value(buttonName, "true");
|
set_option_value(buttonName, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// button_was_pressed() tests whether a UCI parameter of type "button" has
|
||||||
|
/// been selected since the last time the function was called, in this case
|
||||||
|
/// it also resets the button.
|
||||||
|
|
||||||
|
bool button_was_pressed(const string& buttonName) {
|
||||||
|
|
||||||
|
if (!get_option_value<bool>(buttonName))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
set_option_value(buttonName, "false");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Define constructors of Option class.
|
// Define constructors of Option class.
|
||||||
|
|
||||||
Option::Option(const char* nm, const char* def, OptionType t)
|
Option::Option() {} // To allow insertion in a std::map
|
||||||
: name(nm), defaultValue(def), currentValue(def), type(t), minValue(0), maxValue(0) {}
|
|
||||||
|
|
||||||
Option::Option(const char* nm, bool def, OptionType t)
|
Option::Option(const char* def, OptionType t)
|
||||||
: name(nm), defaultValue(stringify(def)), currentValue(stringify(def)), type(t), minValue(0), maxValue(0) {}
|
: defaultValue(def), currentValue(def), type(t), idx(options.size()), minValue(0), maxValue(0) {}
|
||||||
|
|
||||||
Option::Option(const char* nm, int def, int minv, int maxv)
|
Option::Option(bool def, OptionType t)
|
||||||
: name(nm), defaultValue(stringify(def)), currentValue(stringify(def)), type(SPIN), minValue(minv), maxValue(maxv) {}
|
: defaultValue(stringify(def)), currentValue(stringify(def)), type(t), idx(options.size()), minValue(0), maxValue(0) {}
|
||||||
|
|
||||||
// option_with_name() tries to find a UCI option with a given
|
Option::Option(int def, int minv, int maxv)
|
||||||
// name. It returns an iterator to the UCI option or to options.end(),
|
: defaultValue(stringify(def)), currentValue(stringify(def)), type(SPIN), idx(options.size()), minValue(minv), maxValue(maxv) {}
|
||||||
// depending on whether an option with the given name exists.
|
|
||||||
|
|
||||||
Options::iterator option_with_name(const std::string& optionName) {
|
|
||||||
|
|
||||||
for (Options::iterator it = options.begin(); it != options.end(); ++it)
|
|
||||||
if (it->name == optionName)
|
|
||||||
return it;
|
|
||||||
|
|
||||||
return options.end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-18
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -27,27 +27,18 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Variables
|
|
||||||
////
|
|
||||||
|
|
||||||
extern bool Chess960;
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern void init_uci_options();
|
extern void init_uci_options();
|
||||||
extern void print_uci_options();
|
extern void print_uci_options();
|
||||||
extern bool get_option_value_bool(const std::string &optionName);
|
extern bool get_option_value_bool(const std::string& optionName);
|
||||||
extern int get_option_value_int(const std::string &optionName);
|
extern int get_option_value_int(const std::string& optionName);
|
||||||
extern const std::string get_option_value_string(const std::string &optionName);
|
extern std::string get_option_value_string(const std::string& optionName);
|
||||||
extern bool button_was_pressed(const std::string &buttonName);
|
extern bool button_was_pressed(const std::string& buttonName);
|
||||||
extern void set_option_value(const std::string &optionName,
|
extern void set_option_value(const std::string& optionName,const std::string& newValue);
|
||||||
const std::string &newValue);
|
extern void push_button(const std::string& buttonName);
|
||||||
extern void push_button(const std::string &buttonName);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(UCIOPTION_H_INCLUDED)
|
#endif // !defined(UCIOPTION_H_INCLUDED)
|
||||||
|
|||||||
+3
-3
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+23
-18
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
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 Marco Costalba
|
Copyright (C) 2008-2009 Marco Costalba
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -36,7 +36,10 @@ 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 = 3, // Exact score
|
||||||
|
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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -58,17 +61,19 @@ enum Value {
|
|||||||
/// Important: If the material values are changed, one must also
|
/// Important: If the material values are changed, one must also
|
||||||
/// adjust the piece square tables, and the method game_phase() in the
|
/// adjust the piece square tables, and the method game_phase() in the
|
||||||
/// Position class!
|
/// Position class!
|
||||||
|
///
|
||||||
|
/// Values modified by Joona Kiiski
|
||||||
|
|
||||||
const Value PawnValueMidgame = Value(0xCC);
|
const Value PawnValueMidgame = Value(0x0C6);
|
||||||
const Value PawnValueEndgame = Value(0x100);
|
const Value PawnValueEndgame = Value(0x102);
|
||||||
const Value KnightValueMidgame = Value(0x340);
|
const Value KnightValueMidgame = Value(0x331);
|
||||||
const Value KnightValueEndgame = Value(0x340);
|
const Value KnightValueEndgame = Value(0x34E);
|
||||||
const Value BishopValueMidgame = Value(0x340);
|
const Value BishopValueMidgame = Value(0x344);
|
||||||
const Value BishopValueEndgame = Value(0x340);
|
const Value BishopValueEndgame = Value(0x359);
|
||||||
const Value RookValueMidgame = Value(0x505);
|
const Value RookValueMidgame = Value(0x4F6);
|
||||||
const Value RookValueEndgame = Value(0x505);
|
const Value RookValueEndgame = Value(0x4FE);
|
||||||
const Value QueenValueMidgame = Value(0xA00);
|
const Value QueenValueMidgame = Value(0x9D9);
|
||||||
const Value QueenValueEndgame = Value(0xA00);
|
const Value QueenValueEndgame = Value(0x9FE);
|
||||||
|
|
||||||
const Value PieceValueMidgame[17] = {
|
const Value PieceValueMidgame[17] = {
|
||||||
Value(0),
|
Value(0),
|
||||||
@@ -90,10 +95,10 @@ const Value PieceValueEndgame[17] = {
|
|||||||
Value(0), Value(0), Value(0)
|
Value(0), Value(0), Value(0)
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Bonus for having the side to move
|
/// Bonus for having the side to move (modified by Joona Kiiski)
|
||||||
|
|
||||||
const Value TempoValueMidgame = Value(50);
|
const Value TempoValueMidgame = Value(48);
|
||||||
const Value TempoValueEndgame = Value(20);
|
const Value TempoValueEndgame = Value(22);
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -121,7 +126,7 @@ inline void operator/= (Value &v, int i) { v = Value(int(v) / i); }
|
|||||||
inline Value value_mate_in(int ply) {
|
inline Value value_mate_in(int ply) {
|
||||||
return Value(VALUE_MATE - Value(ply));
|
return Value(VALUE_MATE - Value(ply));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value value_mated_in(int ply) {
|
inline Value value_mated_in(int ply) {
|
||||||
return Value(-VALUE_MATE + Value(ply));
|
return Value(-VALUE_MATE + Value(ply));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user