mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 13:17:44 +00:00
Compare commits
486 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 235df6a887 | |||
| 8d86c87e1e | |||
| c172af1b61 | |||
| b7c36d078b | |||
| db1b0bfa1d | |||
| 6f946f823c | |||
| 2de78ebc7b | |||
| 32934c0c8d | |||
| b4fcfed55b | |||
| dc2302b701 | |||
| 268c12bf31 | |||
| 9f943a132a | |||
| 20390fcb3c | |||
| d95b9189d8 | |||
| 9d5d69e435 | |||
| 08265aef81 | |||
| 9d1e4d041d | |||
| cff3a6d33e | |||
| 20a2ca366f | |||
| c3ba5fb9d3 | |||
| eba8925d81 | |||
| ee9f650242 | |||
| 8a0dd93c56 | |||
| 5a72ff128e | |||
| 3f63dd1023 | |||
| 62ab7e4612 | |||
| 1867785231 | |||
| bac4da70c9 | |||
| 8189ae9e1c | |||
| 1d525bb45f | |||
| da7d872eda | |||
| 49d52b8266 | |||
| 75d001addd | |||
| 7daaf03b39 | |||
| 2e778445d5 | |||
| 93bc05cf69 | |||
| a7227ac26f | |||
| bb0da595a7 | |||
| 20d7197a9b | |||
| f4758ced90 | |||
| 3c05bd70eb | |||
| 7000e100bd | |||
| 2ed22e4fc8 | |||
| 940c53c366 | |||
| 4df8651c82 | |||
| 2d4e2bc62a | |||
| d89a03cc35 | |||
| 34b1d0538b | |||
| cdf1f23bc5 | |||
| e86468cc63 | |||
| e7bad2687a | |||
| 3f610e2b13 | |||
| 6cc11272e2 | |||
| a28c17ecb6 | |||
| ec23692433 | |||
| 787d358554 | |||
| ff0d9dad2b | |||
| 046fd4926f | |||
| c595185b3c | |||
| 1a158c0cf0 | |||
| 8097e99c69 | |||
| 2fa9d25e82 | |||
| 3e275680d5 | |||
| d087b0a34a | |||
| 55b6464d40 | |||
| b5232e2da3 | |||
| 35bd334b30 | |||
| 6e8bd8bf2d | |||
| 899b9455d6 | |||
| 8b57416ace | |||
| 1146fc8d09 | |||
| 6e5cf2f3c5 | |||
| e5ebd4f5d1 | |||
| cf2bafb661 | |||
| 79513e3a43 | |||
| bd3ec6af15 | |||
| b2b86cfd27 | |||
| 7d717df4e4 | |||
| 5e906ea10e | |||
| 73cce873de | |||
| 038235ba35 | |||
| 5e2fc2aa16 | |||
| 74fd57220e | |||
| 74f1efee26 | |||
| 0936a96a0e | |||
| 13d1776a98 | |||
| a56e1c662c | |||
| fcc49561a1 | |||
| 714069e248 | |||
| 88885399f4 | |||
| a5c1b3e8f6 | |||
| 8a85007023 | |||
| 4397e6c03e | |||
| 4f14bd5032 | |||
| f8bc38a006 | |||
| 5dd9159106 | |||
| ad956ef00a | |||
| d155cd88d1 | |||
| 2aebf8eb55 | |||
| 1ac2f50145 | |||
| af59cb1d63 | |||
| 2f8961beef | |||
| af5743837d | |||
| 5e768e4b0a | |||
| 2d867109d9 | |||
| b145e99559 | |||
| 8f2c1c59eb | |||
| c40249e9d2 | |||
| ce93a202b5 | |||
| 279ed7ed48 | |||
| af6571856e | |||
| 0c8659721f | |||
| 5dc2312121 | |||
| aa94f2f4c2 | |||
| d7161c1ce6 | |||
| e2af0e775b | |||
| ad1bb084dd | |||
| 760f77872f | |||
| 257689dec7 | |||
| ff211469ba | |||
| d4f14a8e83 | |||
| 7eb290a509 | |||
| d316b02771 | |||
| d9e54ceaa1 | |||
| 691de79eaa | |||
| 3f38cca072 | |||
| 6b8a07eccc | |||
| 8e85aa3a65 | |||
| 4f18528a1c | |||
| 4a4d62da13 | |||
| d3600c39a7 | |||
| f664ca41ed | |||
| b397426785 | |||
| 68c78400c8 | |||
| 1bd1f5a293 | |||
| d0e51bc0f0 | |||
| 0d19437703 | |||
| 8b5519a009 | |||
| 1eae58523f | |||
| 305b711ca8 | |||
| 2bea93975e | |||
| f036239521 | |||
| 832a8a2719 | |||
| 11910d44e0 | |||
| 00bcc64787 | |||
| f2ead1004a | |||
| 84ce43498a | |||
| 987ff3b4b6 | |||
| 72289fcfab | |||
| 73d0d2c0b2 | |||
| c1257d45b2 | |||
| 34a515f20b | |||
| 5abe8a0816 | |||
| 35fd5ce5bc | |||
| 146bb2dfa7 | |||
| ea16985ea5 | |||
| 3b857d1625 | |||
| aa7121297d | |||
| 94f1b31484 | |||
| c852a94009 | |||
| 8be2c483a1 | |||
| 158911425b | |||
| cf8ee79b76 | |||
| 06d6468ce9 | |||
| 173ecc0acf | |||
| 2943e1ca31 | |||
| 486ec580f9 | |||
| a930aafce0 | |||
| b3744eb4d0 | |||
| a03ab94f44 | |||
| 644db060ae | |||
| cb76e4a814 | |||
| d8268024a9 | |||
| 4fa5dd4db5 | |||
| 58c7a5c477 | |||
| 3901affb1d | |||
| a6017aa728 | |||
| 6a15df1d82 | |||
| bbf7a94d76 | |||
| a3477af2a1 | |||
| 310e07f292 | |||
| ea7bebb604 | |||
| 54071312f3 | |||
| 849809e97e | |||
| e9e51da4b8 | |||
| f1f887b6d7 | |||
| 88bb3c9422 | |||
| 8d76de820f | |||
| b00abed181 | |||
| 2e3faae067 | |||
| 453e815d4b | |||
| 3e0dc9ee84 | |||
| 597ef38c39 | |||
| d6618d7325 | |||
| 3ee3cdc09b | |||
| ca891e9760 | |||
| dfcfed6432 | |||
| 34ca22486a | |||
| f56af8e84d | |||
| 3263ee8557 | |||
| 853ce65f17 | |||
| 7dd0c39714 | |||
| 060eef4f4e | |||
| 67f975e56b | |||
| 1d8994402b | |||
| 2a3ebc884e | |||
| 01dd46a309 | |||
| e5cc6f6b85 | |||
| 29b01b6d82 | |||
| cde7b30b65 | |||
| 2dbc8feae3 | |||
| c034cce27c | |||
| 1373a00187 | |||
| 9ae2b69235 | |||
| 95ce27f926 | |||
| 5c4f6f6226 | |||
| 18860cce40 | |||
| d583176baf | |||
| 4c5eaeb363 | |||
| 925f97f4e7 | |||
| f1e245850f | |||
| 2f5012a3eb | |||
| 94929c36bd | |||
| a0aa8e760a | |||
| 52487c4f04 | |||
| 5080e72ea5 | |||
| 295352d04a | |||
| 421fd9c3bf | |||
| eacb42092b | |||
| a10c9632a5 | |||
| bc4e937f05 | |||
| 6c592955e1 | |||
| d517080ab6 | |||
| b7781e8faa | |||
| a230dc1404 | |||
| c2c0ba875f | |||
| 61f41a057d | |||
| d786822b92 | |||
| 392360e73b | |||
| 7c93b171cb | |||
| dad9a1eca7 | |||
| 731a9f3806 | |||
| bd3fd6501b | |||
| 9ec12da028 | |||
| 973eb543a4 | |||
| e5068c4734 | |||
| 35010b4938 | |||
| 6c64f68ccf | |||
| 6ef44d4c4e | |||
| d22aeb1cc0 | |||
| b8e487ff9c |
+20
-249
@@ -1,21 +1,14 @@
|
|||||||
1. Introduction
|
1. Introduction
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Glaurung is a free UCI chess engine. It is not a complete chess
|
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
||||||
program, but requires some UCI compatible GUI (like XBoard with
|
not a complete chess program, but requires some UCI compatible GUI
|
||||||
PolyGlot, eboard, José, Arena, Sigma Chess, Shredder, Chess Partner,
|
(like XBoard with PolyGlot, eboard, Jos�, Arena, Sigma Chess, Shredder,
|
||||||
or Fritz) in order to be used comfortably. Read the documentation for
|
Chess Partner, or Fritz) in order to be used comfortably. Read the
|
||||||
your GUI of choice for information about how to use Glaurung with your
|
documentation for your GUI of choice for information about how to use
|
||||||
GUI.
|
Stockfish with your GUI.
|
||||||
|
|
||||||
Glaurung 2 is a completely rewritten version of Glaurung. Apart from
|
This version of Stockfish supports up to 8 CPUs, but has not been
|
||||||
the parallel search code, almost no code is shared with Glaurung
|
|
||||||
1.2.1, the previous stable version. The new program is clearly
|
|
||||||
stronger than the old, but has a less attractive style of play,
|
|
||||||
because there are still a few major holes in its evaluation function
|
|
||||||
(most notably space and development).
|
|
||||||
|
|
||||||
This version of Glaurung supports up to 8 CPUs, but has not been
|
|
||||||
tested thoroughly with more than 2. The program tries to detect the
|
tested thoroughly with more than 2. The program tries to detect the
|
||||||
number of CPUs on your computer and set the number of search threads
|
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
|
||||||
@@ -27,7 +20,7 @@ cores on your computer.
|
|||||||
2. Files
|
2. Files
|
||||||
--------
|
--------
|
||||||
|
|
||||||
This distribution of Glaurung consists of the following files:
|
This distribution of Stockfish consists of the following files:
|
||||||
|
|
||||||
* Readme.txt, the file you are currently reading.
|
* Readme.txt, the file you are currently reading.
|
||||||
|
|
||||||
@@ -35,57 +28,43 @@ This distribution of Glaurung consists of the following files:
|
|||||||
License.
|
License.
|
||||||
|
|
||||||
* src/, a subdirectory containing the full source code, including a
|
* src/, a subdirectory containing the full source code, including a
|
||||||
Makefile that can be used to compile Glaurung on Unix-like
|
Makefile that can be used to compile Stockfish on Unix-like
|
||||||
systems. For further information about how to compile Glaurung
|
systems. For further information about how to compile Stockfish
|
||||||
yourself, read section 4 below.
|
yourself, read section 4 below.
|
||||||
|
|
||||||
* MacOSX/, a subdirectory containing excutables for Apple Macintosh
|
* polyglot.ini, for using Stockfish with Fabien Letouzey's PolyGlot
|
||||||
computers running Mac OS X 10.4 (Tiger) and newer. There are two
|
|
||||||
executables, one for OS X 10.4, and one for OS X 10.5. The
|
|
||||||
executable for OS X 10.4 will work in 10.5 as well, but the one
|
|
||||||
for 10.5 is faster.
|
|
||||||
|
|
||||||
* LinuxX86/, a subdirectory containing 32-bit and 64-bit x86 GNU/Linux
|
|
||||||
executables.
|
|
||||||
|
|
||||||
* Windows/, a subdirectory containing 32-bit and 64-bit Windows
|
|
||||||
executables.
|
|
||||||
|
|
||||||
* polyglot.ini, for using Glaurung with Fabien Letouzey's PolyGlot
|
|
||||||
adapter.
|
adapter.
|
||||||
|
|
||||||
|
|
||||||
3. Opening books
|
3. Opening books
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
This version of Glaurung has experimental support for PolyGlot opening
|
This version of Stockfish has experimental support for PolyGlot opening
|
||||||
books. For information about how to create such books, consult the
|
books. For information about how to create such books, consult the
|
||||||
PolyGlot documentation. The book file can be selected by setting the
|
PolyGlot documentation. The book file can be selected by setting the
|
||||||
UCI parameter "Book File".
|
UCI parameter "Book File".
|
||||||
|
|
||||||
A book file contributed by Salvo Spitaleri can be found on the
|
|
||||||
Glaurung web page.
|
|
||||||
|
|
||||||
|
|
||||||
4. Compiling it yourself
|
4. Compiling it yourself
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
On Unix-like systems, it should usually be possible to compile
|
On Unix-like systems, it should usually be possible to compile
|
||||||
Glaurung directly from the source code with the included Makefile.
|
Stockfish directly from the source code with the included Makefile.
|
||||||
The exception is computer with big-endian CPUs, like PowerPC
|
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
|
||||||
Glaurung 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
|
Ensuring that the line with #define USE_32BIT_ATTACKS" near the top
|
||||||
of bitboard.h is commented out should solve this problem.
|
of bitboard.h is commented out should solve this problem.
|
||||||
Commenting out the line with "#define USE_32BIT_ATTACKS" near the
|
Commenting out the line with "#define USE_32BIT_ATTACKS" near the
|
||||||
|
|
||||||
There is also a problem with compiling Glaurung on certain 64-bit
|
There is also a problem with compiling Stockfish on certain 64-bit
|
||||||
systems, regardless of the endianness. If Glaurung segfaults
|
systems, regardless of the endianness. If Stockfish segfaults
|
||||||
immediately after startup, try to comment out the line with
|
immediately after startup, try to comment out the line with
|
||||||
"#define USE_FOLDED_BITSCAN" near the beginning of bitboard.h and
|
"#define USE_FOLDED_BITSCAN" near the beginning of bitboard.h and
|
||||||
recompile.
|
recompile.
|
||||||
|
|
||||||
Finally, even if Glaurung does work without any changes on your
|
Finally, even if Stockfish does work without any changes on your
|
||||||
computer, it might be possible to improve the performance by changing
|
computer, it might be possible to improve the performance by changing
|
||||||
some of the #define directives in bitboard.h. The default settings
|
some of the #define directives in bitboard.h. The default settings
|
||||||
are optimized for 64-bit CPUs. On 32-bit CPUs, it is probably better
|
are optimized for 64-bit CPUs. On 32-bit CPUs, it is probably better
|
||||||
@@ -95,224 +74,17 @@ handheld devices), it is possible to conserve memory by defining
|
|||||||
USE_COMPACT_ROOK_ATTACKS.
|
USE_COMPACT_ROOK_ATTACKS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
5. History
|
|
||||||
----------
|
|
||||||
|
|
||||||
2007-05-06: Glaurung 2 - epsilon
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
The first public release, and the first version of my new program
|
|
||||||
which is able to match the old Glaurung 1.2.1 on a single CPU. Lots
|
|
||||||
of features and chess knowledge is still missing.
|
|
||||||
|
|
||||||
2007-05-10: Glaurung 2 - epsilon/2
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
This version is very close to 2 - epsilon. The major changes are:
|
|
||||||
|
|
||||||
* A number of compatibility problems which appeared when trying to
|
|
||||||
compile Glaurung 2 - epsilon on various operating systems and CPUs
|
|
||||||
have been solved.
|
|
||||||
|
|
||||||
* Fixed a major bug in the detection of rooks trapped inside a
|
|
||||||
friendly king.
|
|
||||||
|
|
||||||
* Added knowledge about several types of drawn endgames.
|
|
||||||
|
|
||||||
* Fixed a few FRC related bugs. FRC now works, but because of
|
|
||||||
serious holes in the evaluation function the program plays very
|
|
||||||
badly.
|
|
||||||
|
|
||||||
* A slightly more sophisticated king safety evaluation.
|
|
||||||
|
|
||||||
2007-06-07: Glaurung 2 - epsilon/3
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
The first public version with support for multiple CPUs. Unless you
|
|
||||||
have a dual-core (or better) computer, use Glaurung with a PolyGlot
|
|
||||||
book, or runs games with ponder on, you may want to skip this version,
|
|
||||||
which is almost certainly no stronger than 2 - epsilon/2 when running
|
|
||||||
on a single CPU. The main changes compared to the previous version
|
|
||||||
are:
|
|
||||||
|
|
||||||
* Parallel search, with support for 1-4 CPUs. The program currently
|
|
||||||
always allocates a separate pawn hash table and material hash
|
|
||||||
table for four threads, which is a pure waste of RAM if your
|
|
||||||
computer has just a single CPU. This will be fixed in a future
|
|
||||||
version.
|
|
||||||
|
|
||||||
* Fixed a bug in book randomization. When using Polyglot books, the
|
|
||||||
previous version would always select exactly the same move in the
|
|
||||||
same position after a restart of the program. Thanks to Pavel
|
|
||||||
Háse for pointing this out.
|
|
||||||
|
|
||||||
* Fixed a UCI pondering bug: Glaurung no longer instantly prints its
|
|
||||||
best move when the maximum depth is reached during a ponder
|
|
||||||
search, as the previous version did. According to the UCI
|
|
||||||
protocol, it is not allowed to print the best move before the
|
|
||||||
engine has received the "stop" or "quit" command.
|
|
||||||
|
|
||||||
* Additional search information: The new version displays hash
|
|
||||||
saturation and the current line(s) of search.
|
|
||||||
|
|
||||||
* Several minor bug fixes and optimizations in the search and
|
|
||||||
evaluation.
|
|
||||||
|
|
||||||
2007-06-08: Glaurung 2 - epsilon/4
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
A bugfix release, with only a single important change:
|
|
||||||
|
|
||||||
* Fixed a very serious pondering bug. As pointed out by Marc
|
|
||||||
Lacrosse, the previous version would lose on time in almost every
|
|
||||||
single game with pondering enabled. The new version handles
|
|
||||||
pondering correctly (or so I hope). When playing with ponder
|
|
||||||
off, the new version is identical to version 2 - epsilon/3.
|
|
||||||
|
|
||||||
2007-06-25: Glaurung 2 - epsilon/5
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Another minor update, including the following improvements and bug
|
|
||||||
fixes:
|
|
||||||
|
|
||||||
* As Werner Schüle discovered, the previous version would sometimes
|
|
||||||
stop thinking and lose on time right before delivering checkmate
|
|
||||||
(which is of course a very unfortunate moment to lose on time).
|
|
||||||
I haven't been able to reproduce Werner's problem on my computer
|
|
||||||
(probably because I run a different OS), but I have fixed the bug
|
|
||||||
which I suspect caused the time losses. I hope the time losses
|
|
||||||
will no longer occur with 2 - epsilon/5.
|
|
||||||
|
|
||||||
* The program is now slightly less resource-hungry on computers
|
|
||||||
with less than 4 CPU cores: The previous version would always
|
|
||||||
allocated separate pawn and material hash tables for four
|
|
||||||
threads, even when running on a single-core CPU. The new version
|
|
||||||
only allocates pawn and material hash tables for the threads
|
|
||||||
which are actually used.
|
|
||||||
|
|
||||||
* A minor reorganization of the memory layout has made the parallel
|
|
||||||
search about 10% more efficient (at least on my computer, but the
|
|
||||||
results are likely to vary considerably on different systems).
|
|
||||||
|
|
||||||
* The Intel Mac OS X binary is much faster than before, thanks to
|
|
||||||
the Intel C++ compiler (previous versions were compiled with
|
|
||||||
GCC).
|
|
||||||
|
|
||||||
* A few other very minor bug fixes and enhancements.
|
|
||||||
|
|
||||||
2007-11-21: Glaurung 2.0
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
The first stable (or so I hope) and feature-complete version of
|
|
||||||
Glaurung 2. The following are the main changes compared to the
|
|
||||||
previous version:
|
|
||||||
|
|
||||||
* The license has been changed from GPL version 2 to GPL version 3.
|
|
||||||
|
|
||||||
* MultiPV mode.
|
|
||||||
|
|
||||||
* Support for the "searchmoves" option in the UCI "go" command.
|
|
||||||
This means that it is possible to ask Glaurung to exclude some
|
|
||||||
moves from its analysis, or to restrict its analysis to just a
|
|
||||||
handful of moves selected by the user. This feature must also be
|
|
||||||
supported by the GUI under which Glaurung is run. Glaurung's own
|
|
||||||
GUI does currently not support this feature.
|
|
||||||
|
|
||||||
* Chess960 support now works. The program still plays this game
|
|
||||||
very badly, because of lack of opening knowledge.
|
|
||||||
|
|
||||||
* Much more aggressive pruning in the last few plies of the main
|
|
||||||
search.
|
|
||||||
|
|
||||||
* Somewhat better scaling on multi-CPU systems, and support for up
|
|
||||||
to 8 CPUs.
|
|
||||||
|
|
||||||
* Lots of new UCI parameters.
|
|
||||||
|
|
||||||
* Improved time managment, especially in games with pondering on
|
|
||||||
(i.e. when the engine is allowed to think when it's the
|
|
||||||
opponent's turn to move).
|
|
||||||
|
|
||||||
* Some evaluation improvements, and some new basic endgame
|
|
||||||
patterns.
|
|
||||||
|
|
||||||
* The program should no longer crash if the game lasts longer than
|
|
||||||
1000 plies.
|
|
||||||
|
|
||||||
* Many minor bug fixes and other tiny improvements throughout the
|
|
||||||
code.
|
|
||||||
|
|
||||||
* More generously commented code, and numerous cosmetic changes in
|
|
||||||
coding style.
|
|
||||||
|
|
||||||
2007-11-22: Glaurung 2.0.1
|
|
||||||
--------------------------
|
|
||||||
|
|
||||||
* Fixed (or so I hope) a bug which would occasionally cause one of
|
|
||||||
the search threads to get stuck forever in its idle loop.
|
|
||||||
|
|
||||||
2008-05-14: Glaurung 2.1
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
This version contains far too many changes to list them all, but most
|
|
||||||
of them are minor and cosmetic. The most important and noticable
|
|
||||||
changes are a lot of new UCI parameters, and many improvements in the
|
|
||||||
evaluation function. The highlights are:
|
|
||||||
|
|
||||||
* Extensive changes in the evaluation function. The addition of
|
|
||||||
king safety is the most important improvement, but there are also
|
|
||||||
numerous little improvements elsewhere in the evaluation. There
|
|
||||||
is still much work left to do in the evaluation function, though.
|
|
||||||
Space and development are still missing, and the tuning is likely
|
|
||||||
to be very poor. Currently, the program is optimized for an
|
|
||||||
entertaining style rather than maximum strength.
|
|
||||||
|
|
||||||
* More accurate forward pruning. The previous version used the
|
|
||||||
null move refutation move to improve the pruning accuracy by
|
|
||||||
means of a very simple trick: It did not allow pruning of any
|
|
||||||
moves with the piece captured by the null move refutation move.
|
|
||||||
In Glaurung 2.1, this has been enhanced: It does not allow
|
|
||||||
pruning of moves which defend the destination square of the null
|
|
||||||
move refutation move, nor of moves which block the ray of the
|
|
||||||
piece in the case that the moving piece in the null move
|
|
||||||
refutation move is a slider.
|
|
||||||
|
|
||||||
* More conservative use of LMR at PV nodes. The previous version
|
|
||||||
searched the first 6 moves with full depth, 2.1 by default
|
|
||||||
searches the first 14 moves with full depth (but there is a new
|
|
||||||
UCI parameter for configuring this). I am not at all sure
|
|
||||||
whether this is an improvement. More thorough testing is
|
|
||||||
required.
|
|
||||||
|
|
||||||
* Feedback from the evaluation to the search. The search passes an
|
|
||||||
object of type 'EvalInfo' to the eval, and the eval fills this
|
|
||||||
struct with various potentially useful information (like the sets
|
|
||||||
of squares attacked by each piece type, the middle game and
|
|
||||||
endgame components of the eval, etc.). At the moment, almost
|
|
||||||
none of this information is actually used by the search. The
|
|
||||||
only exception is that the evaluation function is now used to
|
|
||||||
adjust the futility pruning margin in the quiescence search.
|
|
||||||
|
|
||||||
* Less extensions. This hurts the programs performance a lot in most
|
|
||||||
test suites, but I hope it improves the branching factor in deep
|
|
||||||
searches.
|
|
||||||
|
|
||||||
* A very long list of new UCI parameters, especially for tuning the
|
|
||||||
evaluation.
|
|
||||||
|
|
||||||
|
|
||||||
6. Terms of use
|
6. Terms of use
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Glaurung is free, and distributed under the GNU General Public License
|
Stockfish is free, and distributed under the GNU General Public License
|
||||||
(GPL). Essentially, this means that you are free to do almost exactly
|
(GPL). Essentially, this means that you are free to do almost exactly
|
||||||
what you want with the program, including distributing it among your
|
what you want with the program, including distributing it among your
|
||||||
friends, making it available for download from your web site, selling
|
friends, making it available for download from your web site, selling
|
||||||
it (either by itself or as part of some bigger software package), or
|
it (either by itself or as part of some bigger software package), or
|
||||||
using it as the starting point for a software project of your own.
|
using it as the starting point for a software project of your own.
|
||||||
|
|
||||||
The only real limitation is that whenever you distribute Glaurung in
|
The only real limitation is that whenever you distribute Stockfish in
|
||||||
some way, you must always include the full source code, or a pointer
|
some way, you must always include the full source code, or a pointer
|
||||||
to where the source code can be found. If you make any changes to the
|
to where the source code can be found. If you make any changes to the
|
||||||
source code, these changes must also be made available under the GPL.
|
source code, these changes must also be made available under the GPL.
|
||||||
@@ -324,5 +96,4 @@ Copying.txt.
|
|||||||
7. Feedback
|
7. Feedback
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
The author's e-mail address is tord@glaurungchess.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
|
||||||
|
|||||||
+18
-13
@@ -1,14 +1,15 @@
|
|||||||
# Glaurung, a UCI chess playing engine.
|
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
# Copyright (C) 2004-2007 Tord Romstad
|
# Copyright (C) 2004-2007 Tord Romstad
|
||||||
|
# Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
# This file is part of Glaurung.
|
# This file is part of Stockfish.
|
||||||
#
|
#
|
||||||
# Glaurung 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.
|
||||||
#
|
#
|
||||||
# Glaurung 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.
|
||||||
@@ -21,11 +22,11 @@
|
|||||||
### Files
|
### Files
|
||||||
###
|
###
|
||||||
|
|
||||||
EXE = glaurung
|
EXE = stockfish
|
||||||
|
|
||||||
OBJS = bitboard.o color.o pawns.o material.o endgame.o evaluate.o main.o \
|
OBJS = 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
|
||||||
|
|
||||||
|
|
||||||
@@ -36,16 +37,16 @@ OBJS = bitboard.o color.o pawns.o material.o endgame.o evaluate.o main.o \
|
|||||||
all: $(EXE) .depend
|
all: $(EXE) .depend
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o .depend glaurung
|
$(RM) *.o .depend stockfish
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
### Compiler:
|
### Compiler:
|
||||||
###
|
###
|
||||||
|
|
||||||
CXX = g++
|
# CXX = g++
|
||||||
# CXX = g++-4.2
|
# CXX = g++-4.2
|
||||||
# CXX = icpc
|
CXX = icpc
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
@@ -78,7 +79,11 @@ CXXFLAGS += -Wall -g
|
|||||||
# General optimization flags. Note that -O2 might be faster than -O3 on some
|
# General optimization flags. Note that -O2 might be faster than -O3 on some
|
||||||
# systems; this requires testing.
|
# systems; this requires testing.
|
||||||
|
|
||||||
CXXFLAGS += -O3 -fno-exceptions -fomit-frame-pointer -fno-rtti -fstrict-aliasing
|
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:
|
# Compiler optimization flags for the Intel C++ compiler in Mac OS X:
|
||||||
@@ -89,11 +94,11 @@ CXXFLAGS += -O3 -fno-exceptions -fomit-frame-pointer -fno-rtti -fstrict-aliasing
|
|||||||
# Profiler guided optimization with the Intel C++ compiler. To use it, first
|
# 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
|
# 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
|
# 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
|
# resulting binary for a while (for instance, do ./stockfish bench 128 1, and
|
||||||
# wait 15 minutes for the benchmark to complete). Then do a 'make clean', and
|
# wait 15 minutes for the benchmark to complete). Then do a 'make clean', and
|
||||||
# recompile with -prof_use.
|
# recompile with -prof_use.
|
||||||
|
|
||||||
# CXXFLAGS += -prof_gen -prof_dir ./profdata
|
# CXXFLAGS += -prof_gen -prof_dir profdata
|
||||||
# CXXFLAGS += -prof_use -prof_dir ./profdata
|
# CXXFLAGS += -prof_use -prof_dir ./profdata
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+83
-23
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -20,6 +21,9 @@
|
|||||||
////
|
////
|
||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
@@ -31,7 +35,8 @@
|
|||||||
//// Variables
|
//// Variables
|
||||||
////
|
////
|
||||||
|
|
||||||
const std::string BenchmarkPositions[15] = {
|
const std::string BenchmarkPositions[] = {
|
||||||
|
"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",
|
||||||
"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
|
"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
|
||||||
@@ -54,38 +59,93 @@ const std::string BenchmarkPositions[15] = {
|
|||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// benchmark() runs a simple benchmark by letting Glaurung analyze 15
|
/// benchmark() runs a simple benchmark by letting Stockfish analyze a set
|
||||||
/// positions for 60 seconds each. There are two parameters; the
|
/// of positions for a given time each. There are four parameters; the
|
||||||
/// transposition table size and the number of search threads that should
|
/// transposition table size, the number of search threads that should
|
||||||
/// be used. The analysis is written to a file named bench.txt.
|
/// be used, the time in seconds spent for each position (optional, default
|
||||||
|
/// is 60) and an optional file name where to look for positions in fen
|
||||||
|
/// format (default are the BenchmarkPositions defined above).
|
||||||
|
/// The analysis is written to a file named bench.txt.
|
||||||
|
|
||||||
void benchmark(const std::string &ttSize, const std::string &threads) {
|
void benchmark(const std::string& commandLine) {
|
||||||
Position pos;
|
|
||||||
Move moves[1] = {MOVE_NONE};
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = atoi(ttSize.c_str());
|
std::istringstream csVal(commandLine);
|
||||||
if(i < 4 || i > 1024) {
|
std::istringstream csStr(commandLine);
|
||||||
|
std::string ttSize, threads, fileName, limitType;
|
||||||
|
int val, secsPerPos, maxDepth, maxNodes;
|
||||||
|
|
||||||
|
csStr >> ttSize;
|
||||||
|
csVal >> val;
|
||||||
|
if (val < 4 || val > 1024)
|
||||||
|
{
|
||||||
std::cerr << "The hash table size must be between 4 and 1024" << std::endl;
|
std::cerr << "The hash table size must be between 4 and 1024" << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
csStr >> threads;
|
||||||
i = atoi(threads.c_str());
|
csVal >> val;
|
||||||
if(i < 1 || i > THREAD_MAX) {
|
if (val < 1 || val > THREAD_MAX)
|
||||||
|
{
|
||||||
std::cerr << "The number of threads must be between 1 and " << THREAD_MAX
|
std::cerr << "The number of threads must be between 1 and " << THREAD_MAX
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
exit(EXIT_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");
|
||||||
set_option_value("Use Search Log", "true");
|
set_option_value("Use Search Log", "true");
|
||||||
set_option_value("Search Log Filename", "bench.txt");
|
set_option_value("Search Log Filename", "bench.txt");
|
||||||
|
|
||||||
for(i = 0; i < 15; i++) {
|
csVal >> val;
|
||||||
pos.from_fen(BenchmarkPositions[i]);
|
csVal >> fileName;
|
||||||
think(pos, true, false, 0, 0, 0, 0, 0, 60000, moves);
|
csVal >> limitType;
|
||||||
}
|
|
||||||
|
|
||||||
|
secsPerPos = maxDepth = maxNodes = 0;
|
||||||
|
|
||||||
|
if (limitType == "time")
|
||||||
|
secsPerPos = val * 1000;
|
||||||
|
else if (limitType == "depth")
|
||||||
|
maxDepth = val;
|
||||||
|
else
|
||||||
|
maxNodes = val;
|
||||||
|
|
||||||
|
std::vector<std::string> positions;
|
||||||
|
|
||||||
|
if (fileName != "default")
|
||||||
|
{
|
||||||
|
std::ifstream fenFile(fileName.c_str());
|
||||||
|
if (!fenFile.is_open())
|
||||||
|
{
|
||||||
|
std::cerr << "Unable to open positions file " << fileName
|
||||||
|
<< std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
std::string pos;
|
||||||
|
while (fenFile.good())
|
||||||
|
{
|
||||||
|
std::getline(fenFile, pos);
|
||||||
|
if (!pos.empty())
|
||||||
|
positions.push_back(pos);
|
||||||
|
}
|
||||||
|
fenFile.close();
|
||||||
|
} else
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
positions.push_back(std::string(BenchmarkPositions[i]));
|
||||||
|
|
||||||
|
int startTime = get_system_time();
|
||||||
|
std::vector<std::string>::iterator it;
|
||||||
|
int cnt = 1;
|
||||||
|
int64_t totalNodes = 0;
|
||||||
|
for (it = positions.begin(); it != positions.end(); ++it, ++cnt)
|
||||||
|
{
|
||||||
|
Move moves[1] = {MOVE_NONE};
|
||||||
|
int dummy[2] = {0, 0};
|
||||||
|
Position pos(*it);
|
||||||
|
std::cout << "\nProcessing position " << cnt << '/' << positions.size() << std::endl << std::endl;
|
||||||
|
think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves);
|
||||||
|
totalNodes += nodes_searched();
|
||||||
|
}
|
||||||
|
std::cout << "\nProcessing time (ms) " << get_system_time() - startTime << std::endl
|
||||||
|
<< "Nodes searched " << totalNodes << std::endl
|
||||||
|
<< "Press any key to exit" << std::endl;
|
||||||
|
std::cin >> fileName;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -31,7 +32,6 @@
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern void benchmark(const std::string &ttSize, const std::string &threads);
|
extern void benchmark(const std::string& commandLine);
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(BENCHMARK_H_INCLUDED)
|
#endif // !defined(BENCHMARK_H_INCLUDED)
|
||||||
|
|||||||
+7
-5
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -88,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:
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+68
-66
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -21,70 +22,22 @@
|
|||||||
//// 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 "direction.h"
|
#include "direction.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// 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)
|
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
||||||
|
|
||||||
Bitboard RankAttacks[8][64], FileAttacks[8][64];
|
Bitboard RankAttacks[8][64], FileAttacks[8][64];
|
||||||
@@ -239,8 +192,8 @@ 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];
|
||||||
@@ -259,6 +212,7 @@ Bitboard QueenPseudoAttacks[64];
|
|||||||
////
|
////
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void init_masks();
|
void init_masks();
|
||||||
void init_ray_bitboards();
|
void init_ray_bitboards();
|
||||||
void init_attacks();
|
void init_attacks();
|
||||||
@@ -274,7 +228,7 @@ namespace {
|
|||||||
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
||||||
void init_file_and_rank_attacks();
|
void init_file_and_rank_attacks();
|
||||||
#endif
|
#endif
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -339,6 +293,43 @@ Square first_1(Bitboard b) {
|
|||||||
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
||||||
/// nonzero bitboard.
|
/// nonzero bitboard.
|
||||||
|
|
||||||
|
#if defined(USE_32BIT_ATTACKS)
|
||||||
|
|
||||||
|
// Use type-punning
|
||||||
|
union b_union {
|
||||||
|
|
||||||
|
Bitboard b;
|
||||||
|
struct {
|
||||||
|
uint32_t l;
|
||||||
|
uint32_t h;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// WARNING: Needs -fno-strict-aliasing compiler option
|
||||||
|
Square pop_1st_bit(Bitboard *bb) {
|
||||||
|
|
||||||
|
b_union u;
|
||||||
|
uint32_t b;
|
||||||
|
|
||||||
|
u.b = *bb;
|
||||||
|
|
||||||
|
if (u.l)
|
||||||
|
{
|
||||||
|
b = u.l;
|
||||||
|
*((uint32_t*)bb) = b & (b - 1);
|
||||||
|
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
|
||||||
|
|
||||||
Square pop_1st_bit(Bitboard *b) {
|
Square pop_1st_bit(Bitboard *b) {
|
||||||
Bitboard bb = *b ^ (*b - 1);
|
Bitboard bb = *b ^ (*b - 1);
|
||||||
uint32_t fold = int(bb) ^ int(bb >> 32);
|
uint32_t fold = int(bb) ^ int(bb >> 32);
|
||||||
@@ -346,6 +337,8 @@ Square pop_1st_bit(Bitboard *b) {
|
|||||||
return Square(BitTable[(fold * 0x783a9b23) >> 26]);
|
return Square(BitTable[(fold * 0x783a9b23) >> 26]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static const int BitTable[64] = {
|
static const int BitTable[64] = {
|
||||||
@@ -383,6 +376,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];
|
||||||
@@ -398,7 +393,7 @@ namespace {
|
|||||||
|
|
||||||
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])
|
||||||
@@ -484,8 +479,15 @@ 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(USE_32BIT_ATTACKS)
|
||||||
|
j = (1 << (32 - shift[i]));
|
||||||
|
#else
|
||||||
j = (1 << (64 - shift[i]));
|
j = (1 << (64 - shift[i]));
|
||||||
|
#endif
|
||||||
|
|
||||||
for(k = 0; k < j; k++) {
|
for(k = 0; k < j; k++) {
|
||||||
|
|
||||||
#if defined(USE_32BIT_ATTACKS)
|
#if defined(USE_32BIT_ATTACKS)
|
||||||
b = index_to_bitboard(k, mask[i]);
|
b = index_to_bitboard(k, mask[i]);
|
||||||
attacks[index +
|
attacks[index +
|
||||||
|
|||||||
+110
-41
@@ -1,13 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -25,6 +27,22 @@
|
|||||||
//// Defines
|
//// 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_COMPACT_ROOK_ATTACKS
|
||||||
//#define USE_32BIT_ATTACKS
|
//#define USE_32BIT_ATTACKS
|
||||||
#define USE_FOLDED_BITSCAN
|
#define USE_FOLDED_BITSCAN
|
||||||
@@ -33,7 +51,13 @@
|
|||||||
//#define BITCOUNT_SWAR_32
|
//#define BITCOUNT_SWAR_32
|
||||||
//#define BITCOUNT_LOOP
|
//#define BITCOUNT_LOOP
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define USE_32BIT_ATTACKS
|
||||||
|
#define USE_FOLDED_BITSCAN
|
||||||
|
#define BITCOUNT_SWAR_32
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Includes
|
//// Includes
|
||||||
@@ -60,8 +84,7 @@ const Bitboard EmptyBoardBB = 0ULL;
|
|||||||
|
|
||||||
const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL;
|
const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL;
|
||||||
const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL;
|
const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL;
|
||||||
|
const Bitboard SquaresByColorBB[2] = { BlackSquaresBB, WhiteSquaresBB };
|
||||||
extern const Bitboard SquaresByColorBB[2];
|
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
const Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
const Bitboard FileBBB = 0x0202020202020202ULL;
|
const Bitboard FileBBB = 0x0202020202020202ULL;
|
||||||
@@ -72,9 +95,21 @@ 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];
|
const Bitboard FileBB[8] = {
|
||||||
extern const Bitboard NeighboringFilesBB[8];
|
FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
|
||||||
extern const Bitboard ThisAndNeighboringFilesBB[8];
|
};
|
||||||
|
|
||||||
|
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 Rank1BB = 0xFFULL;
|
const Bitboard Rank1BB = 0xFFULL;
|
||||||
const Bitboard Rank2BB = 0xFF00ULL;
|
const Bitboard Rank2BB = 0xFF00ULL;
|
||||||
@@ -85,12 +120,38 @@ const Bitboard Rank6BB = 0xFF0000000000ULL;
|
|||||||
const Bitboard Rank7BB = 0xFF000000000000ULL;
|
const Bitboard Rank7BB = 0xFF000000000000ULL;
|
||||||
const Bitboard Rank8BB = 0xFF00000000000000ULL;
|
const Bitboard Rank8BB = 0xFF00000000000000ULL;
|
||||||
|
|
||||||
extern const Bitboard RankBB[8];
|
const Bitboard RankBB[8] = {
|
||||||
extern const Bitboard RelativeRankBB[2][8];
|
Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
|
||||||
extern const Bitboard InFrontBB[2][8];
|
};
|
||||||
|
|
||||||
extern Bitboard SetMaskBB[64];
|
const Bitboard RelativeRankBB[2][8] = {
|
||||||
extern Bitboard ClearMaskBB[64];
|
{ 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
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Bitboard SetMaskBB[65];
|
||||||
|
extern Bitboard ClearMaskBB[65];
|
||||||
|
|
||||||
extern Bitboard StepAttackBB[16][64];
|
extern Bitboard StepAttackBB[16][64];
|
||||||
extern Bitboard RayBB[64][8];
|
extern Bitboard RayBB[64][8];
|
||||||
@@ -100,13 +161,17 @@ extern Bitboard PassedPawnMask[2][64];
|
|||||||
extern Bitboard OutpostMask[2][64];
|
extern Bitboard OutpostMask[2][64];
|
||||||
|
|
||||||
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
#if defined(USE_COMPACT_ROOK_ATTACKS)
|
||||||
|
|
||||||
extern Bitboard RankAttacks[8][64], FileAttacks[8][64];
|
extern Bitboard RankAttacks[8][64], FileAttacks[8][64];
|
||||||
|
|
||||||
#else
|
#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)
|
#endif // defined(USE_COMPACT_ROOK_ATTACKS)
|
||||||
|
|
||||||
extern const uint64_t BMult[64];
|
extern const uint64_t BMult[64];
|
||||||
@@ -127,26 +192,16 @@ extern Bitboard QueenPseudoAttacks[64];
|
|||||||
/// Functions for testing whether a given bit is set in a bitboard, and for
|
/// Functions for testing whether a given bit is set in a bitboard, and for
|
||||||
/// setting and clearing bits.
|
/// setting and clearing bits.
|
||||||
|
|
||||||
inline Bitboard set_mask_bb(Square s) {
|
|
||||||
// return 1ULL << s;
|
|
||||||
return SetMaskBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard clear_mask_bb(Square s) {
|
|
||||||
// return ~set_mask_bb(s);
|
|
||||||
return ClearMaskBB[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard bit_is_set(Bitboard b, Square s) {
|
inline Bitboard bit_is_set(Bitboard b, Square s) {
|
||||||
return b & set_mask_bb(s);
|
return b & SetMaskBB[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void set_bit(Bitboard *b, Square s) {
|
inline void set_bit(Bitboard *b, Square s) {
|
||||||
*b |= set_mask_bb(s);
|
*b |= SetMaskBB[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void clear_bit(Bitboard *b, Square s) {
|
inline void clear_bit(Bitboard *b, Square s) {
|
||||||
*b &= clear_mask_bb(s);
|
*b &= ClearMaskBB[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -222,6 +277,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.
|
||||||
|
|
||||||
@@ -368,24 +436,25 @@ inline int count_1s_max_15(Bitboard b) {
|
|||||||
|
|
||||||
inline int count_1s(Bitboard b) {
|
inline int count_1s(Bitboard b) {
|
||||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
||||||
v = v - ((v >> 1) & 0x55555555);
|
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
||||||
w = w - ((w >> 1) & 0x55555555);
|
w -= (w >> 1) & 0x55555555;
|
||||||
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
|
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
||||||
w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
|
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
||||||
v = (v + (v >> 4)) & 0x0F0F0F0F;
|
v = ((v >> 4) + v) & 0x0F0F0F0F; // 0-8 in 8 bits
|
||||||
w = (w + (w >> 4)) & 0x0F0F0F0F;
|
v += (((w >> 4) + w) & 0x0F0F0F0F); // 0-16 in 8 bits
|
||||||
v = ((v+w) * 0x01010101) >> 24; // mul is fast on amd procs
|
v *= 0x01010101; // mul is fast on amd procs
|
||||||
return int(v);
|
return int(v >> 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int count_1s_max_15(Bitboard b) {
|
inline int count_1s_max_15(Bitboard b) {
|
||||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
||||||
v = v - ((v >> 1) & 0x55555555);
|
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
||||||
w = w - ((w >> 1) & 0x55555555);
|
w -= (w >> 1) & 0x55555555;
|
||||||
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
|
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
||||||
w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
|
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
||||||
v = ((v+w) * 0x11111111) >> 28;
|
v += w; // 0-8 in 4 bits
|
||||||
return int(v);
|
v *= 0x11111111;
|
||||||
|
return int(v >> 28);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(BITCOUNT_SWAR_64)
|
#elif defined(BITCOUNT_SWAR_64)
|
||||||
|
|||||||
+62
-48
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -29,7 +30,6 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#include "book.h"
|
#include "book.h"
|
||||||
#include "mersenne.h"
|
#include "mersenne.h"
|
||||||
@@ -339,8 +339,9 @@ namespace {
|
|||||||
uint64_t book_ep_key(const Position &pos);
|
uint64_t book_ep_key(const Position &pos);
|
||||||
uint64_t book_color_key(const Position &pos);
|
uint64_t book_color_key(const Position &pos);
|
||||||
|
|
||||||
uint64_t read_integer(FILE *file, int size);
|
uint16_t read_integer16(std::ifstream& file);
|
||||||
|
uint64_t read_integer64(std::ifstream& file);
|
||||||
|
uint64_t read_integer(std::ifstream& file, int size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -351,45 +352,44 @@ namespace {
|
|||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
|
|
||||||
Book::Book() {
|
Book::Book() : bookSize(0) {}
|
||||||
bookFile = NULL;
|
|
||||||
bookSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// 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 std::string &fName) {
|
||||||
|
|
||||||
fileName = fName;
|
fileName = fName;
|
||||||
bookFile = fopen(fileName.c_str(), "rb");
|
bookFile.open(fileName.c_str(), std::ifstream::in | std::ifstream::binary);
|
||||||
if(bookFile != NULL) {
|
if (!bookFile.is_open())
|
||||||
if(fseek(bookFile, 0, SEEK_END) == -1) {
|
return;
|
||||||
|
|
||||||
|
bookFile.seekg(0, std::ios::end);
|
||||||
|
bookSize = bookFile.tellg() / 16;
|
||||||
|
bookFile.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
|
if (!bookFile.good())
|
||||||
|
{
|
||||||
std::cerr << "Failed to open book file " << fileName << std::endl;
|
std::cerr << "Failed to open book file " << fileName << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
bookSize = ftell(bookFile) / 16;
|
|
||||||
if(bookSize == -1) {
|
|
||||||
std::cerr << "Failed to open book file " << fileName << std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Book::close() closes the currently open book file.
|
/// Book::close() closes the currently open book file.
|
||||||
|
|
||||||
void Book::close() {
|
void Book::close() {
|
||||||
if(bookFile != NULL && fclose(bookFile) == EOF) {
|
|
||||||
std::cerr << "Failed to close book file" << std::endl;
|
if (bookFile.is_open())
|
||||||
exit(EXIT_FAILURE);
|
bookFile.close();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Book::is_open() tests whether a book file has been opened.
|
/// Book::is_open() tests whether a book file has been opened.
|
||||||
|
|
||||||
bool Book::is_open() const {
|
bool Book::is_open() const {
|
||||||
return bookFile != NULL && bookSize != 0;
|
|
||||||
|
return bookFile.is_open() && bookSize != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -397,7 +397,8 @@ bool Book::is_open() const {
|
|||||||
/// 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 std::string Book::file_name() const {
|
||||||
return this->is_open()? fileName : "";
|
|
||||||
|
return bookFile.is_open() ? fileName : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -476,19 +477,21 @@ int Book::find_key(uint64_t key) const {
|
|||||||
/// 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 n) const {
|
||||||
assert(n >= 0 && n < bookSize);
|
|
||||||
assert(bookFile != NULL);
|
|
||||||
|
|
||||||
if(fseek(bookFile, n*16, SEEK_SET) == -1) {
|
assert(n >= 0 && n < bookSize);
|
||||||
|
assert(bookFile.is_open());
|
||||||
|
|
||||||
|
bookFile.seekg(n*16, std::ios_base::beg);
|
||||||
|
if (!bookFile.good())
|
||||||
|
{
|
||||||
std::cerr << "Failed to read book entry at index " << n << std::endl;
|
std::cerr << "Failed to read book entry at index " << n << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
entry.key = read_integer64(bookFile);
|
||||||
entry.key = read_integer(bookFile, 8);
|
entry.move = read_integer16(bookFile);
|
||||||
entry.move = read_integer(bookFile, 2);
|
entry.count = read_integer16(bookFile);
|
||||||
entry.count = read_integer(bookFile, 2);
|
entry.n = read_integer16(bookFile);
|
||||||
entry.n = read_integer(bookFile, 2);
|
entry.sum = read_integer16(bookFile);
|
||||||
entry.sum = read_integer(bookFile, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -554,25 +557,36 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t read_integer(FILE *file, int size) {
|
uint16_t read_integer16(std::ifstream& file) {
|
||||||
uint64_t n = 0ULL;;
|
|
||||||
int i;
|
|
||||||
int b;
|
|
||||||
|
|
||||||
assert(file != NULL);
|
uint64_t n = read_integer(file, 2);
|
||||||
assert(size > 0 && size <= 8);
|
assert(n == (uint16_t)n);
|
||||||
|
return (uint16_t)n;
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0; i < size; i++) {
|
|
||||||
b = fgetc(file);
|
uint64_t read_integer64(std::ifstream& file) {
|
||||||
if(b == EOF) {
|
|
||||||
|
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::cerr << "Failed to read " << size << " bytes from book file"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
assert(b >= 0 && b < 256);
|
// Numbers are stored in little endian format
|
||||||
n = (n << 8) | b;
|
uint64_t n = 0ULL;
|
||||||
}
|
for (int i = 0; i < size; i++)
|
||||||
|
n = (n << 8) + (unsigned char)buf[i];
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-5
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
@@ -74,7 +76,7 @@ private:
|
|||||||
void read_entry(BookEntry &entry, int n) const;
|
void read_entry(BookEntry &entry, int n) const;
|
||||||
|
|
||||||
std::string fileName;
|
std::string fileName;
|
||||||
FILE *bookFile;
|
mutable std::ifstream bookFile;
|
||||||
int bookSize;
|
int bookSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
Glaurung, a UCI chess playing engine.
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
|
||||||
|
|
||||||
Glaurung 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.
|
|
||||||
|
|
||||||
Glaurung 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
-18
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -20,12 +21,6 @@
|
|||||||
#if !defined(COLOR_H_INCLUDED)
|
#if !defined(COLOR_H_INCLUDED)
|
||||||
#define COLOR_H_INCLUDED
|
#define COLOR_H_INCLUDED
|
||||||
|
|
||||||
////
|
|
||||||
//// Includes
|
|
||||||
////
|
|
||||||
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Types
|
//// Types
|
||||||
@@ -43,18 +38,14 @@ enum Color {
|
|||||||
////
|
////
|
||||||
|
|
||||||
inline Color operator+ (Color c, int i) { return Color(int(c) + i); }
|
inline Color operator+ (Color c, int i) { return Color(int(c) + i); }
|
||||||
inline void operator++ (Color &c, int i) { c = Color(int(c) + 1); }
|
inline void operator++ (Color &c, int) { 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)
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+16
-6
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -57,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,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
|
||||||
|
|||||||
+412
-339
File diff suppressed because it is too large
Load Diff
+68
-183
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -33,149 +34,61 @@
|
|||||||
//// 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
|
||||||
|
KmmKm, // K and two minors vs K and one or two minors
|
||||||
|
|
||||||
|
// Scaling functions
|
||||||
|
KBPK, // KBP vs K
|
||||||
|
KQKRP, // KQ vs KRP
|
||||||
|
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(strongerSide); }
|
||||||
virtual ~EndgameEvaluationFunction() { }
|
virtual ~EndgameFunctionBase() {}
|
||||||
|
virtual T apply(const Position&) = 0;
|
||||||
virtual Value apply(const Position &pos) =0;
|
|
||||||
|
|
||||||
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);
|
explicit EvaluationFunction(Color c): EndgameEvaluationFunctionBase(c) {}
|
||||||
|
Value apply(const Position&);
|
||||||
};
|
};
|
||||||
|
|
||||||
// KBN vs K:
|
template<EndgameType>
|
||||||
class KBNKEvaluationFunction : public EndgameEvaluationFunction {
|
struct ScalingFunction : public EndgameScalingFunctionBase {
|
||||||
public:
|
explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
|
||||||
KBNKEvaluationFunction(Color c);
|
ScaleFactor apply(const Position&);
|
||||||
Value apply(const Position &pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -183,54 +96,26 @@ public:
|
|||||||
//// Constants and variables
|
//// Constants and variables
|
||||||
////
|
////
|
||||||
|
|
||||||
// Generic "mate lone king" eval:
|
extern EvaluationFunction<KXK> EvaluateKXK, EvaluateKKX; // Generic "mate lone king" eval
|
||||||
extern KXKEvaluationFunction EvaluateKXK, EvaluateKKX;
|
extern EvaluationFunction<KBNK> EvaluateKBNK, EvaluateKKBN; // KBN vs K
|
||||||
|
extern EvaluationFunction<KPK> EvaluateKPK, EvaluateKKP; // KP vs K
|
||||||
// KBN vs K:
|
extern EvaluationFunction<KRKP> EvaluateKRKP, EvaluateKPKR; // KR vs KP
|
||||||
extern KBNKEvaluationFunction EvaluateKBNK, EvaluateKKBN;
|
extern EvaluationFunction<KRKB> EvaluateKRKB, EvaluateKBKR; // KR vs KB
|
||||||
|
extern EvaluationFunction<KRKN> EvaluateKRKN, EvaluateKNKR; // KR vs KN
|
||||||
// KP vs K:
|
extern EvaluationFunction<KQKR> EvaluateKQKR, EvaluateKRKQ; // KQ vs KR
|
||||||
extern KPKEvaluationFunction EvaluateKPK, EvaluateKKP;
|
extern EvaluationFunction<KBBKN> EvaluateKBBKN, EvaluateKNKBB; // KBB vs KN
|
||||||
|
extern EvaluationFunction<KmmKm> EvaluateKmmKm; // K and two minors vs K and one or two minors:
|
||||||
// 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;
|
|
||||||
|
|
||||||
|
extern ScalingFunction<KBPK> ScaleKBPK, ScaleKKBP; // KBP vs K
|
||||||
|
extern ScalingFunction<KQKRP> ScaleKQKRP, ScaleKRPKQ; // KQ vs KRP
|
||||||
|
extern ScalingFunction<KRPKR> ScaleKRPKR, ScaleKRKRP; // KRP vs KR
|
||||||
|
extern ScalingFunction<KRPPKRP> ScaleKRPPKRP, ScaleKRPKRPP; // KRPP vs KRP
|
||||||
|
extern ScalingFunction<KPsK> ScaleKPsK, ScaleKKPs; // King and pawns vs king
|
||||||
|
extern ScalingFunction<KBPKB> ScaleKBPKB, ScaleKBKBP; // KBP vs KB
|
||||||
|
extern ScalingFunction<KBPPKB> ScaleKBPPKB, ScaleKBKBPP; // KBPP vs KB
|
||||||
|
extern ScalingFunction<KBPKN> ScaleKBPKN, ScaleKNKBP; // KBP vs KN
|
||||||
|
extern ScalingFunction<KNPK> ScaleKNPK, ScaleKKNP; // KNP vs K
|
||||||
|
extern ScalingFunction<KPKP> ScaleKPKPw, ScaleKPKPb; // KP vs KP
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Prototypes
|
//// Prototypes
|
||||||
|
|||||||
+584
-572
File diff suppressed because it is too large
Load Diff
+31
-28
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -26,13 +27,13 @@
|
|||||||
|
|
||||||
#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
|
||||||
@@ -40,15 +41,16 @@
|
|||||||
///
|
///
|
||||||
/// 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
|
||||||
@@ -56,31 +58,32 @@ struct EvalInfo {
|
|||||||
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]; }
|
||||||
// attackZone[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, attackZone[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 attackZone[2];
|
Bitboard kingZone[2];
|
||||||
|
|
||||||
// attackCount[color] is the number of pieces of the given color which
|
// kingAttackersCount[color] is the number of pieces of the given color
|
||||||
// attack a square adjacent to the enemy king.
|
// which attack a square in the kingZone of the enemy king.
|
||||||
int attackCount[2];
|
int kingAttackersCount[2];
|
||||||
|
|
||||||
// attackWeight[color] is the sum of the "weight" of the pieces of the given
|
// kingAttackersWeight[color] is the sum of the "weight" of the pieces of the
|
||||||
// color which attack a square adjacent to the enemy king. The weights of
|
// given color which attack a square in the kingZone of the enemy king. The
|
||||||
// the individual piece types are given by the variables QueenAttackWeight,
|
// weights of the individual piece types are given by the variables
|
||||||
// RookAttackWeight, BishopAttackWeight and KnightAttackWeight in
|
// QueenAttackWeight, RookAttackWeight, BishopAttackWeight and
|
||||||
// evaluate.cpp.
|
// KnightAttackWeight in evaluate.cpp
|
||||||
int attackWeight[2];
|
int kingAttackersWeight[2];
|
||||||
|
|
||||||
// attacked[color] is the number of enemy piece attacks to squares directly
|
// kingAdjacentZoneAttacksCount[color] is the number of attacks to squares
|
||||||
// adjacent to the king of the given color. Pieces which attack more
|
// directly adjacent to the king of the given color. Pieces which attack
|
||||||
// than one square are counted multiple times. For instance, if black's
|
// more than one square are counted multiple times. For instance, if black's
|
||||||
// king is on g8 and there's a white knight on g5, this knight adds
|
// king is on g8 and there's a white knight on g5, this knight adds
|
||||||
// 2 to attacked[BLACK].
|
// 2 to kingAdjacentZoneAttacksCount[BLACK].
|
||||||
int attacked[2];
|
int kingAdjacentZoneAttacksCount[2];
|
||||||
|
|
||||||
// mateThreat[color] is a move for the given side which gives a direct mate.
|
// mateThreat[color] is a move for the given side which gives a direct mate.
|
||||||
Move mateThreat[2];
|
Move mateThreat[2];
|
||||||
@@ -98,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);
|
||||||
|
|||||||
+6
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+6
-5
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -86,7 +87,7 @@ typedef pthread_mutex_t Lock;
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
# include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
typedef CRITICAL_SECTION Lock;
|
typedef CRITICAL_SECTION Lock;
|
||||||
# define lock_init(x, y) InitializeCriticalSection(x)
|
# define lock_init(x, y) InitializeCriticalSection(x)
|
||||||
|
|||||||
+21
-19
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -21,7 +22,6 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
@@ -39,6 +39,7 @@
|
|||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
#include "ucioption.h"
|
#include "ucioption.h"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
@@ -47,45 +48,46 @@
|
|||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// Disable IO buffering
|
// Disable IO buffering
|
||||||
setbuf(stdin, NULL);
|
|
||||||
setbuf(stdout, NULL);
|
|
||||||
std::cout.rdbuf()->pubsetbuf(NULL, 0);
|
std::cout.rdbuf()->pubsetbuf(NULL, 0);
|
||||||
std::cin.rdbuf()->pubsetbuf(NULL, 0);
|
std::cin.rdbuf()->pubsetbuf(NULL, 0);
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
|
|
||||||
init_mersenne();
|
init_mersenne();
|
||||||
init_direction_table();
|
init_direction_table();
|
||||||
init_bitboards();
|
init_bitboards();
|
||||||
init_uci_options();
|
init_uci_options();
|
||||||
Position::init_zobrist();
|
Position::init_zobrist();
|
||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
MaterialInfo::init();
|
|
||||||
MovePicker::init_phase_table();
|
MovePicker::init_phase_table();
|
||||||
init_eval(1);
|
init_eval(1);
|
||||||
init_bitbases();
|
init_bitbases();
|
||||||
init_threads();
|
init_threads();
|
||||||
|
|
||||||
// Make random number generation less deterministic, for book moves
|
// Make random number generation less deterministic, for book moves
|
||||||
int i = abs(get_system_time() % 10000);
|
for (int i = abs(get_system_time() % 10000); i > 0; i--)
|
||||||
for(int j = 0; j < i; j++)
|
|
||||||
genrand_int32();
|
genrand_int32();
|
||||||
|
|
||||||
// Process command line arguments
|
// Process command line arguments
|
||||||
if(argc >= 2) {
|
if (argc >= 2 && string(argv[1]) == "bench")
|
||||||
if(std::string(argv[1]) == "bench") {
|
{
|
||||||
if(argc != 4) {
|
if (argc < 4 || argc > 7)
|
||||||
std::cout << "Usage: glaurung bench <hash> <threads>" << std::endl;
|
{
|
||||||
|
std::cout << "Usage: stockfish bench <hash size> <threads> "
|
||||||
|
<< "[time = 60s] [fen positions file = default] "
|
||||||
|
<< "[time, depth or node limited = time]"
|
||||||
|
<< std::endl;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
benchmark(std::string(argv[2]), std::string(argv[3]));
|
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() << ". "
|
std::cout << engine_name() << ". Copyright (C) "
|
||||||
<< "Copyright (C) 2004-2008 Tord Romstad."
|
<< "2004-2008 Tord Romstad, Marco Costalba. "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
// Enter UCI mode
|
// Enter UCI mode
|
||||||
|
|||||||
+251
-256
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -22,6 +23,9 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
#include <sstream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
|
||||||
@@ -32,23 +36,41 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const Value BishopPairMidgameBonus = Value(100);
|
const Value BishopPairMidgameBonus = Value(109);
|
||||||
const Value BishopPairEndgameBonus = Value(100);
|
const Value BishopPairEndgameBonus = Value(97);
|
||||||
|
|
||||||
Key KPKMaterialKey, KKPMaterialKey;
|
|
||||||
Key KBNKMaterialKey, KKBNMaterialKey;
|
|
||||||
Key KRKPMaterialKey, KPKRMaterialKey;
|
|
||||||
Key KRKBMaterialKey, KBKRMaterialKey;
|
|
||||||
Key KRKNMaterialKey, KNKRMaterialKey;
|
|
||||||
Key KQKRMaterialKey, KRKQMaterialKey;
|
|
||||||
Key KRPKRMaterialKey, KRKRPMaterialKey;
|
|
||||||
Key KRPPKRPMaterialKey, KRPKRPPMaterialKey;
|
|
||||||
Key KNNKMaterialKey, KKNNMaterialKey;
|
Key KNNKMaterialKey, KKNNMaterialKey;
|
||||||
Key KBPKBMaterialKey, KBKBPMaterialKey;
|
|
||||||
Key KBPKNMaterialKey, KNKBPMaterialKey;
|
|
||||||
Key KNPKMaterialKey, KKNPMaterialKey;
|
|
||||||
Key KPKPMaterialKey;
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
////
|
||||||
|
//// Classes
|
||||||
|
////
|
||||||
|
|
||||||
|
|
||||||
|
/// See header for a class description. It is declared here to avoid
|
||||||
|
/// to include <map> in the header file.
|
||||||
|
|
||||||
|
class EndgameFunctions {
|
||||||
|
|
||||||
|
public:
|
||||||
|
EndgameFunctions();
|
||||||
|
EndgameEvaluationFunctionBase* getEEF(Key key) const;
|
||||||
|
EndgameScalingFunctionBase* getESF(Key key, Color* c) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void add(const std::string& keyCode, EndgameEvaluationFunctionBase* f);
|
||||||
|
void add(const std::string& keyCode, Color c, EndgameScalingFunctionBase* f);
|
||||||
|
Key buildKey(const std::string& keyCode);
|
||||||
|
|
||||||
|
struct ScalingInfo
|
||||||
|
{
|
||||||
|
Color col;
|
||||||
|
EndgameScalingFunctionBase* fun;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::map<Key, EndgameEvaluationFunctionBase*> EEFmap;
|
||||||
|
std::map<Key, ScalingInfo> ESFmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -56,115 +78,30 @@ namespace {
|
|||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// MaterialInfo::init() is called during program initialization. It
|
|
||||||
/// precomputes material hash keys for a few basic endgames, in order
|
|
||||||
/// to make it easy to recognize such endgames when they occur.
|
|
||||||
|
|
||||||
void MaterialInfo::init() {
|
/// Constructor for the MaterialInfoTable class
|
||||||
KPKMaterialKey = Position::zobMaterial[WHITE][PAWN][1];
|
|
||||||
KKPMaterialKey = Position::zobMaterial[BLACK][PAWN][1];
|
|
||||||
KBNKMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][BISHOP][1] ^
|
|
||||||
Position::zobMaterial[WHITE][KNIGHT][1];
|
|
||||||
KKBNMaterialKey =
|
|
||||||
Position::zobMaterial[BLACK][BISHOP][1] ^
|
|
||||||
Position::zobMaterial[BLACK][KNIGHT][1];
|
|
||||||
KRKPMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][ROOK][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][1];
|
|
||||||
KPKRMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][PAWN][1] ^
|
|
||||||
Position::zobMaterial[BLACK][ROOK][1];
|
|
||||||
KRKBMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][ROOK][1] ^
|
|
||||||
Position::zobMaterial[BLACK][BISHOP][1];
|
|
||||||
KBKRMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][BISHOP][1] ^
|
|
||||||
Position::zobMaterial[BLACK][ROOK][1];
|
|
||||||
KRKNMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][ROOK][1] ^
|
|
||||||
Position::zobMaterial[BLACK][KNIGHT][1];
|
|
||||||
KNKRMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][KNIGHT][1] ^
|
|
||||||
Position::zobMaterial[BLACK][ROOK][1];
|
|
||||||
KQKRMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][QUEEN][1] ^
|
|
||||||
Position::zobMaterial[BLACK][ROOK][1];
|
|
||||||
KRKQMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][ROOK][1] ^
|
|
||||||
Position::zobMaterial[BLACK][QUEEN][1];
|
|
||||||
KRPKRMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][ROOK][1] ^
|
|
||||||
Position::zobMaterial[WHITE][PAWN][1] ^
|
|
||||||
Position::zobMaterial[BLACK][ROOK][1];
|
|
||||||
KRKRPMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][ROOK][1] ^
|
|
||||||
Position::zobMaterial[BLACK][ROOK][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][1];
|
|
||||||
KRPPKRPMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][ROOK][1] ^
|
|
||||||
Position::zobMaterial[WHITE][PAWN][1] ^
|
|
||||||
Position::zobMaterial[WHITE][PAWN][2] ^
|
|
||||||
Position::zobMaterial[BLACK][ROOK][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][1];
|
|
||||||
KRPKRPPMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][ROOK][1] ^
|
|
||||||
Position::zobMaterial[WHITE][PAWN][1] ^
|
|
||||||
Position::zobMaterial[BLACK][ROOK][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][2];
|
|
||||||
KNNKMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][KNIGHT][1] ^
|
|
||||||
Position::zobMaterial[WHITE][KNIGHT][2];
|
|
||||||
KKNNMaterialKey =
|
|
||||||
Position::zobMaterial[BLACK][KNIGHT][1] ^
|
|
||||||
Position::zobMaterial[BLACK][KNIGHT][2];
|
|
||||||
KBPKBMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][BISHOP][1] ^
|
|
||||||
Position::zobMaterial[WHITE][PAWN][1] ^
|
|
||||||
Position::zobMaterial[BLACK][BISHOP][1];
|
|
||||||
KBKBPMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][BISHOP][1] ^
|
|
||||||
Position::zobMaterial[BLACK][BISHOP][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][1];
|
|
||||||
KBPKNMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][BISHOP][1] ^
|
|
||||||
Position::zobMaterial[WHITE][PAWN][1] ^
|
|
||||||
Position::zobMaterial[BLACK][KNIGHT][1];
|
|
||||||
KNKBPMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][KNIGHT][1] ^
|
|
||||||
Position::zobMaterial[BLACK][BISHOP][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][1];
|
|
||||||
KNPKMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][KNIGHT][1] ^
|
|
||||||
Position::zobMaterial[WHITE][PAWN][1];
|
|
||||||
KKNPMaterialKey =
|
|
||||||
Position::zobMaterial[BLACK][KNIGHT][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][1];
|
|
||||||
KPKPMaterialKey =
|
|
||||||
Position::zobMaterial[WHITE][PAWN][1] ^
|
|
||||||
Position::zobMaterial[BLACK][PAWN][1];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
MaterialInfoTable::MaterialInfoTable(unsigned int numOfEntries) {
|
||||||
|
|
||||||
/// Constructor for the MaterialInfoTable class.
|
|
||||||
|
|
||||||
MaterialInfoTable::MaterialInfoTable(unsigned numOfEntries) {
|
|
||||||
size = numOfEntries;
|
size = numOfEntries;
|
||||||
entries = new MaterialInfo[size];
|
entries = new MaterialInfo[size];
|
||||||
if(entries == NULL) {
|
funcs = new EndgameFunctions();
|
||||||
|
if (!entries || !funcs)
|
||||||
|
{
|
||||||
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(MaterialInfo))
|
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(MaterialInfo))
|
||||||
<< " bytes for material hash table." << std::endl;
|
<< " bytes for material hash table." << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
this->clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Destructor for the MaterialInfoTable class.
|
/// Destructor for the MaterialInfoTable class
|
||||||
|
|
||||||
MaterialInfoTable::~MaterialInfoTable() {
|
MaterialInfoTable::~MaterialInfoTable() {
|
||||||
|
|
||||||
delete [] entries;
|
delete [] entries;
|
||||||
|
delete funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -172,6 +109,7 @@ MaterialInfoTable::~MaterialInfoTable() {
|
|||||||
/// all entries to 0.
|
/// all entries to 0.
|
||||||
|
|
||||||
void MaterialInfoTable::clear() {
|
void MaterialInfoTable::clear() {
|
||||||
|
|
||||||
memset(entries, 0, size * sizeof(MaterialInfo));
|
memset(entries, 0, size * sizeof(MaterialInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,90 +120,66 @@ void MaterialInfoTable::clear() {
|
|||||||
/// is stored there, so we don't have to recompute everything when the
|
/// is stored there, so we don't have to recompute everything when the
|
||||||
/// same material configuration occurs again.
|
/// same material configuration occurs again.
|
||||||
|
|
||||||
MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) {
|
MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||||
|
|
||||||
Key key = pos.get_material_key();
|
Key key = pos.get_material_key();
|
||||||
int index = key & (size - 1);
|
int index = key & (size - 1);
|
||||||
MaterialInfo *mi = entries + index;
|
MaterialInfo* mi = entries + index;
|
||||||
|
|
||||||
// If mi->key matches the position's material hash key, it means that we
|
// If mi->key matches the position's material hash key, it means that we
|
||||||
// have analysed this material configuration before, and we can simply
|
// have analysed this material configuration before, and we can simply
|
||||||
// return the information we found the last time instead of recomputing it:
|
// return the information we found the last time instead of recomputing it.
|
||||||
if(mi->key == key)
|
if (mi->key == key)
|
||||||
return mi;
|
return mi;
|
||||||
|
|
||||||
// Clear the MaterialInfo object, and set its key:
|
// Clear the MaterialInfo object, and set its key
|
||||||
mi->clear();
|
mi->clear();
|
||||||
mi->key = key;
|
mi->key = key;
|
||||||
|
|
||||||
// A special case before looking for a specialized evaluation function:
|
// A special case before looking for a specialized evaluation function
|
||||||
// KNN vs K is a draw:
|
// KNN vs K is a draw.
|
||||||
if(key == KNNKMaterialKey || key == KKNNMaterialKey) {
|
if (key == KNNKMaterialKey || key == KKNNMaterialKey)
|
||||||
|
{
|
||||||
mi->factor[WHITE] = mi->factor[BLACK] = 0;
|
mi->factor[WHITE] = mi->factor[BLACK] = 0;
|
||||||
return mi;
|
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(key == KPKMaterialKey) {
|
// configuration one, then a generic one if previous search failed.
|
||||||
mi->evaluationFunction = &EvaluateKPK;
|
if ((mi->evaluationFunction = funcs->getEEF(key)) != NULL)
|
||||||
return mi;
|
return mi;
|
||||||
}
|
|
||||||
else if(key == KKPMaterialKey) {
|
else if ( pos.non_pawn_material(BLACK) == Value(0)
|
||||||
mi->evaluationFunction = &EvaluateKKP;
|
&& pos.piece_count(BLACK, PAWN) == 0
|
||||||
return mi;
|
&& pos.non_pawn_material(WHITE) >= RookValueEndgame)
|
||||||
}
|
{
|
||||||
else if(key == KBNKMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKBNK;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KKBNMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKKBN;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KRKPMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKRKP;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KPKRMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKPKR;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KRKBMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKRKB;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KBKRMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKBKR;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KRKNMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKRKN;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KNKRMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKNKR;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KQKRMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKQKR;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KRKQMaterialKey) {
|
|
||||||
mi->evaluationFunction = &EvaluateKRKQ;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(pos.non_pawn_material(BLACK) == Value(0) &&
|
|
||||||
pos.pawn_count(BLACK) == 0 &&
|
|
||||||
pos.non_pawn_material(WHITE) >= RookValueEndgame) {
|
|
||||||
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.pawn_count(WHITE) == 0 &&
|
&& pos.piece_count(WHITE, PAWN) == 0
|
||||||
pos.non_pawn_material(BLACK) >= RookValueEndgame) {
|
&& pos.non_pawn_material(BLACK) >= RookValueEndgame)
|
||||||
|
{
|
||||||
mi->evaluationFunction = &EvaluateKKX;
|
mi->evaluationFunction = &EvaluateKKX;
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
else if ( pos.pawns() == EmptyBoardBB
|
||||||
|
&& pos.rooks() == EmptyBoardBB
|
||||||
|
&& pos.queens() == EmptyBoardBB)
|
||||||
|
{
|
||||||
|
// Minor piece endgame with at least one minor piece per side,
|
||||||
|
// and no pawns.
|
||||||
|
assert(pos.knights(WHITE) | pos.bishops(WHITE));
|
||||||
|
assert(pos.knights(BLACK) | pos.bishops(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?
|
||||||
@@ -274,111 +188,104 @@ MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) {
|
|||||||
// 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;
|
||||||
|
EndgameScalingFunctionBase* sf;
|
||||||
|
|
||||||
if(key == KRPKRMaterialKey) {
|
if ((sf = funcs->getESF(key, &c)) != NULL)
|
||||||
mi->scalingFunction[WHITE] = &ScaleKRPKR;
|
{
|
||||||
return mi;
|
mi->scalingFunction[c] = sf;
|
||||||
}
|
|
||||||
if(key == KRKRPMaterialKey) {
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKRKRP;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
if(key == KRPPKRPMaterialKey) {
|
|
||||||
mi->scalingFunction[WHITE] = &ScaleKRPPKRP;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
else if(key == KRPKRPPMaterialKey) {
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKRPKRPP;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
if(key == KBPKBMaterialKey) {
|
|
||||||
mi->scalingFunction[WHITE] = &ScaleKBPKB;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
if(key == KBKBPMaterialKey) {
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKBKBP;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
if(key == KBPKNMaterialKey) {
|
|
||||||
mi->scalingFunction[WHITE] = &ScaleKBPKN;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
if(key == KNKBPMaterialKey) {
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKNKBP;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
if(key == KNPKMaterialKey) {
|
|
||||||
mi->scalingFunction[WHITE] = &ScaleKNPK;
|
|
||||||
return mi;
|
|
||||||
}
|
|
||||||
if(key == KKNPMaterialKey) {
|
|
||||||
mi->scalingFunction[BLACK] = &ScaleKKNP;
|
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pos.non_pawn_material(WHITE) == BishopValueMidgame &&
|
if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
|
||||||
pos.bishop_count(WHITE) == 1 && pos.pawn_count(WHITE) >= 1)
|
&& pos.piece_count(WHITE, BISHOP) == 1
|
||||||
|
&& pos.piece_count(WHITE, PAWN) >= 1)
|
||||||
mi->scalingFunction[WHITE] = &ScaleKBPK;
|
mi->scalingFunction[WHITE] = &ScaleKBPK;
|
||||||
if(pos.non_pawn_material(BLACK) == BishopValueMidgame &&
|
|
||||||
pos.bishop_count(BLACK) == 1 && pos.pawn_count(BLACK) >= 1)
|
if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
|
||||||
|
&& pos.piece_count(BLACK, BISHOP) == 1
|
||||||
|
&& pos.piece_count(BLACK, PAWN) >= 1)
|
||||||
mi->scalingFunction[BLACK] = &ScaleKKBP;
|
mi->scalingFunction[BLACK] = &ScaleKKBP;
|
||||||
|
|
||||||
if(pos.pawn_count(WHITE) == 0 &&
|
if ( pos.piece_count(WHITE, PAWN) == 0
|
||||||
pos.non_pawn_material(WHITE) == QueenValueMidgame &&
|
&& pos.non_pawn_material(WHITE) == QueenValueMidgame
|
||||||
pos.queen_count(WHITE) == 1 &&
|
&& pos.piece_count(WHITE, QUEEN) == 1
|
||||||
pos.rook_count(BLACK) == 1 && pos.pawn_count(BLACK) >= 1)
|
&& pos.piece_count(BLACK, ROOK) == 1
|
||||||
|
&& pos.piece_count(BLACK, PAWN) >= 1)
|
||||||
mi->scalingFunction[WHITE] = &ScaleKQKRP;
|
mi->scalingFunction[WHITE] = &ScaleKQKRP;
|
||||||
else if(pos.pawn_count(BLACK) == 0 &&
|
|
||||||
pos.non_pawn_material(BLACK) == QueenValueMidgame &&
|
else if ( pos.piece_count(BLACK, PAWN) == 0
|
||||||
pos.queen_count(BLACK) == 1 &&
|
&& pos.non_pawn_material(BLACK) == QueenValueMidgame
|
||||||
pos.rook_count(WHITE) == 1 && pos.pawn_count(WHITE) >= 1)
|
&& pos.piece_count(BLACK, QUEEN) == 1
|
||||||
|
&& pos.piece_count(WHITE, ROOK) == 1
|
||||||
|
&& pos.piece_count(WHITE, PAWN) >= 1)
|
||||||
mi->scalingFunction[BLACK] = &ScaleKRPKQ;
|
mi->scalingFunction[BLACK] = &ScaleKRPKQ;
|
||||||
|
|
||||||
if(pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0)) {
|
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
|
||||||
if(pos.pawn_count(BLACK) == 0) {
|
{
|
||||||
assert(pos.pawn_count(WHITE) >= 2);
|
if (pos.piece_count(BLACK, PAWN) == 0)
|
||||||
|
{
|
||||||
|
assert(pos.piece_count(WHITE, PAWN) >= 2);
|
||||||
mi->scalingFunction[WHITE] = &ScaleKPsK;
|
mi->scalingFunction[WHITE] = &ScaleKPsK;
|
||||||
}
|
}
|
||||||
else if(pos.pawn_count(WHITE) == 0) {
|
else if (pos.piece_count(WHITE, PAWN) == 0)
|
||||||
assert(pos.pawn_count(BLACK) >= 2);
|
{
|
||||||
|
assert(pos.piece_count(BLACK, PAWN) >= 2);
|
||||||
mi->scalingFunction[BLACK] = &ScaleKKPs;
|
mi->scalingFunction[BLACK] = &ScaleKKPs;
|
||||||
}
|
}
|
||||||
else if(pos.pawn_count(WHITE) == 1 && pos.pawn_count(BLACK) == 1) {
|
else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
|
||||||
|
{
|
||||||
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
|
||||||
|
|
||||||
Color c;
|
|
||||||
int sign;
|
int sign;
|
||||||
Value egValue = Value(0), mgValue = Value(0);
|
Value egValue = Value(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)
|
||||||
|
{
|
||||||
// No pawns makes it difficult to win, even with a material advantage:
|
// No pawns makes it difficult to win, even with a material advantage
|
||||||
if(pos.pawn_count(c) == 0 &&
|
if ( pos.piece_count(c, PAWN) == 0
|
||||||
pos.non_pawn_material(c) - pos.non_pawn_material(opposite_color(c))
|
&& pos.non_pawn_material(c) - pos.non_pawn_material(opposite_color(c)) <= BishopValueMidgame)
|
||||||
<= BishopValueMidgame) {
|
{
|
||||||
if(pos.non_pawn_material(c) == pos.non_pawn_material(opposite_color(c)))
|
if ( pos.non_pawn_material(c) == pos.non_pawn_material(opposite_color(c))
|
||||||
|
|| pos.non_pawn_material(c) < RookValueMidgame)
|
||||||
mi->factor[c] = 0;
|
mi->factor[c] = 0;
|
||||||
else if(pos.non_pawn_material(c) < RookValueMidgame)
|
else
|
||||||
mi->factor[c] = 0;
|
{
|
||||||
else {
|
switch (pos.piece_count(c, BISHOP)) {
|
||||||
switch(pos.bishop_count(c)) {
|
|
||||||
case 2:
|
case 2:
|
||||||
mi->factor[c] = 32; break;
|
mi->factor[c] = 32;
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
mi->factor[c] = 12; break;
|
mi->factor[c] = 12;
|
||||||
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
mi->factor[c] = 6; break;
|
mi->factor[c] = 6;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bishop pair:
|
// Bishop pair
|
||||||
if(pos.bishop_count(c) >= 2) {
|
if (pos.piece_count(c, BISHOP) >= 2)
|
||||||
|
{
|
||||||
mgValue += sign * BishopPairMidgameBonus;
|
mgValue += sign * BishopPairMidgameBonus;
|
||||||
egValue += sign * BishopPairEndgameBonus;
|
egValue += sign * BishopPairEndgameBonus;
|
||||||
}
|
}
|
||||||
@@ -387,20 +294,108 @@ MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) {
|
|||||||
// formula is taken from Larry Kaufman's paper "The Evaluation of Material
|
// formula is taken from Larry Kaufman's paper "The Evaluation of Material
|
||||||
// Imbalances in Chess":
|
// 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.knight_count(c)*(pos.pawn_count(c)-5)*16);
|
mgValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
|
||||||
egValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16);
|
egValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
|
||||||
|
|
||||||
// Redundancy of major pieces, again based on Kaufman's paper:
|
// Redundancy of major pieces, again based on Kaufman's paper:
|
||||||
if(pos.rook_count(c) >= 1) {
|
if (pos.piece_count(c, ROOK) >= 1)
|
||||||
Value v = Value((pos.rook_count(c) - 1) * 32 + pos.queen_count(c) * 16);
|
{
|
||||||
|
Value v = Value((pos.piece_count(c, ROOK) - 1) * 32 + pos.piece_count(c, QUEEN) * 16);
|
||||||
mgValue -= sign * v;
|
mgValue -= sign * v;
|
||||||
egValue -= sign * v;
|
egValue -= sign * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mi->mgValue = int16_t(mgValue);
|
mi->mgValue = int16_t(mgValue);
|
||||||
mi->egValue = int16_t(egValue);
|
mi->egValue = int16_t(egValue);
|
||||||
|
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// EndgameFunctions member definitions. This class is used to store the maps
|
||||||
|
/// 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() {
|
||||||
|
|
||||||
|
KNNKMaterialKey = buildKey("KNNK");
|
||||||
|
KKNNMaterialKey = buildKey("KKNN");
|
||||||
|
|
||||||
|
add("KPK", &EvaluateKPK);
|
||||||
|
add("KKP", &EvaluateKKP);
|
||||||
|
add("KBNK", &EvaluateKBNK);
|
||||||
|
add("KKBN", &EvaluateKKBN);
|
||||||
|
add("KRKP", &EvaluateKRKP);
|
||||||
|
add("KPKR", &EvaluateKPKR);
|
||||||
|
add("KRKB", &EvaluateKRKB);
|
||||||
|
add("KBKR", &EvaluateKBKR);
|
||||||
|
add("KRKN", &EvaluateKRKN);
|
||||||
|
add("KNKR", &EvaluateKNKR);
|
||||||
|
add("KQKR", &EvaluateKQKR);
|
||||||
|
add("KRKQ", &EvaluateKRKQ);
|
||||||
|
add("KBBKN", &EvaluateKBBKN);
|
||||||
|
add("KNKBB", &EvaluateKNKBB);
|
||||||
|
|
||||||
|
add("KNPK", WHITE, &ScaleKNPK);
|
||||||
|
add("KKNP", BLACK, &ScaleKKNP);
|
||||||
|
add("KRPKR", WHITE, &ScaleKRPKR);
|
||||||
|
add("KRKRP", BLACK, &ScaleKRKRP);
|
||||||
|
add("KBPKB", WHITE, &ScaleKBPKB);
|
||||||
|
add("KBKBP", BLACK, &ScaleKBKBP);
|
||||||
|
add("KBPPKB", WHITE, &ScaleKBPPKB);
|
||||||
|
add("KBKBPP", BLACK, &ScaleKBKBPP);
|
||||||
|
add("KBPKN", WHITE, &ScaleKBPKN);
|
||||||
|
add("KNKBP", BLACK, &ScaleKNKBP);
|
||||||
|
add("KRPPKRP", WHITE, &ScaleKRPPKRP);
|
||||||
|
add("KRPKRPP", BLACK, &ScaleKRPKRPP);
|
||||||
|
add("KRPPKRP", WHITE, &ScaleKRPPKRP);
|
||||||
|
add("KRPKRPP", BLACK, &ScaleKRPKRPP);
|
||||||
|
}
|
||||||
|
|
||||||
|
Key EndgameFunctions::buildKey(const std::string& keyCode) {
|
||||||
|
|
||||||
|
assert(keyCode.length() > 0 && keyCode[0] == 'K');
|
||||||
|
assert(keyCode.length() < 8);
|
||||||
|
|
||||||
|
std::stringstream s;
|
||||||
|
bool upcase = false;
|
||||||
|
|
||||||
|
// Build up a fen substring 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndgameFunctions::add(const std::string& keyCode, EndgameEvaluationFunctionBase* f) {
|
||||||
|
|
||||||
|
EEFmap.insert(std::pair<Key, EndgameEvaluationFunctionBase*>(buildKey(keyCode), f));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndgameFunctions::add(const std::string& keyCode, Color c, EndgameScalingFunctionBase* f) {
|
||||||
|
|
||||||
|
ScalingInfo s = {c, f};
|
||||||
|
ESFmap.insert(std::pair<Key, ScalingInfo>(buildKey(keyCode), s));
|
||||||
|
}
|
||||||
|
|
||||||
|
EndgameEvaluationFunctionBase* EndgameFunctions::getEEF(Key key) const {
|
||||||
|
|
||||||
|
std::map<Key, EndgameEvaluationFunctionBase*>::const_iterator it(EEFmap.find(key));
|
||||||
|
return (it != EEFmap.end() ? it->second : NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndgameScalingFunctionBase* EndgameFunctions::getESF(Key key, Color* c) const {
|
||||||
|
|
||||||
|
std::map<Key, ScalingInfo>::const_iterator it(ESFmap.find(key));
|
||||||
|
if (it == ESFmap.end())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
*c = it->second.col;
|
||||||
|
return it->second.fun;
|
||||||
|
}
|
||||||
|
|||||||
+47
-21
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -50,11 +51,10 @@ class MaterialInfo {
|
|||||||
public:
|
public:
|
||||||
Value mg_value() const;
|
Value mg_value() const;
|
||||||
Value eg_value() const;
|
Value eg_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;
|
||||||
|
|
||||||
static void init();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clear();
|
void clear();
|
||||||
@@ -63,11 +63,20 @@ private:
|
|||||||
int16_t mgValue;
|
int16_t mgValue;
|
||||||
int16_t egValue;
|
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
|
||||||
@@ -79,11 +88,12 @@ public:
|
|||||||
MaterialInfoTable(unsigned numOfEntries);
|
MaterialInfoTable(unsigned numOfEntries);
|
||||||
~MaterialInfoTable();
|
~MaterialInfoTable();
|
||||||
void clear();
|
void clear();
|
||||||
MaterialInfo *get_material_info(const Position &pos);
|
MaterialInfo* get_material_info(const Position& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned size;
|
unsigned size;
|
||||||
MaterialInfo *entries;
|
MaterialInfo* entries;
|
||||||
|
EndgameFunctions* funcs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -95,10 +105,12 @@ private:
|
|||||||
/// material balance evaluation for the middle game and the endgame.
|
/// material balance evaluation for the middle game and the endgame.
|
||||||
|
|
||||||
inline Value MaterialInfo::mg_value() const {
|
inline Value MaterialInfo::mg_value() const {
|
||||||
|
|
||||||
return Value(mgValue);
|
return Value(mgValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value MaterialInfo::eg_value() const {
|
inline Value MaterialInfo::eg_value() const {
|
||||||
|
|
||||||
return Value(egValue);
|
return Value(egValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +119,10 @@ inline Value MaterialInfo::eg_value() const {
|
|||||||
/// with all slots at their default values.
|
/// with all slots at their default values.
|
||||||
|
|
||||||
inline void MaterialInfo::clear() {
|
inline void MaterialInfo::clear() {
|
||||||
|
|
||||||
mgValue = egValue = 0;
|
mgValue = egValue = 0;
|
||||||
factor[WHITE] = factor[BLACK] = uint8_t(SCALE_FACTOR_NORMAL);
|
factor[WHITE] = factor[BLACK] = uint8_t(SCALE_FACTOR_NORMAL);
|
||||||
|
spaceWeight = 0;
|
||||||
evaluationFunction = NULL;
|
evaluationFunction = NULL;
|
||||||
scalingFunction[WHITE] = scalingFunction[BLACK] = NULL;
|
scalingFunction[WHITE] = scalingFunction[BLACK] = NULL;
|
||||||
}
|
}
|
||||||
@@ -117,35 +131,47 @@ inline void MaterialInfo::clear() {
|
|||||||
/// 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
|
||||||
/// 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
|
||||||
/// which checks for draws with rook pawns and wrong-colored bishops.
|
/// which checks for draws with rook pawns and wrong-colored bishops.
|
||||||
|
|
||||||
inline ScaleFactor MaterialInfo::scale_factor(const Position &pos, Color c)
|
inline ScaleFactor MaterialInfo::scale_factor(const Position& pos, Color c) const {
|
||||||
const {
|
|
||||||
if(scalingFunction[c] != NULL) {
|
if (scalingFunction[c] != NULL)
|
||||||
|
{
|
||||||
ScaleFactor sf = scalingFunction[c]->apply(pos);
|
ScaleFactor sf = scalingFunction[c]->apply(pos);
|
||||||
if(sf != SCALE_FACTOR_NONE)
|
if (sf != SCALE_FACTOR_NONE)
|
||||||
return sf;
|
return sf;
|
||||||
}
|
}
|
||||||
return ScaleFactor(factor[c]);
|
return ScaleFactor(factor[c]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
|
||||||
inline bool MaterialInfo::specialized_eval_exists() const {
|
inline bool MaterialInfo::specialized_eval_exists() const {
|
||||||
|
|
||||||
return evaluationFunction != NULL;
|
return evaluationFunction != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MaterialInfo::evaluate applies a specialized evaluation function to a
|
/// MaterialInfo::evaluate applies a specialized evaluation function
|
||||||
/// given position object. It should only be called when
|
/// to a given position object. It should only be called when
|
||||||
/// this->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 {
|
|
||||||
return evaluationFunction->apply(pos);
|
return evaluationFunction->apply(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -42,6 +42,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "mersenne.h"
|
||||||
|
|
||||||
/* Period parameters */
|
/* Period parameters */
|
||||||
#define N 624
|
#define N 624
|
||||||
@@ -54,7 +55,7 @@ static unsigned long mt[N]; /* the array for the state vector */
|
|||||||
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
|
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
|
||||||
|
|
||||||
/* initializes mt[N] with a seed */
|
/* initializes mt[N] with a seed */
|
||||||
void init_genrand(unsigned long s)
|
static void init_genrand(unsigned long s)
|
||||||
{
|
{
|
||||||
mt[0]= s & 0xffffffffUL;
|
mt[0]= s & 0xffffffffUL;
|
||||||
for (mti=1; mti<N; mti++) {
|
for (mti=1; mti<N; mti++) {
|
||||||
@@ -73,7 +74,7 @@ void init_genrand(unsigned long s)
|
|||||||
/* init_key is the array for initializing keys */
|
/* init_key is the array for initializing keys */
|
||||||
/* key_length is its length */
|
/* key_length is its length */
|
||||||
/* slight change for C++, 2004/2/26 */
|
/* slight change for C++, 2004/2/26 */
|
||||||
void init_by_array(unsigned long init_key[], int key_length)
|
static void init_by_array(unsigned long init_key[], int key_length)
|
||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
init_genrand(19650218UL);
|
init_genrand(19650218UL);
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+145
-26
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -28,51 +29,153 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
/*
|
||||||
|
(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 <windows.h>
|
||||||
# include <time.h>
|
# include <time.h>
|
||||||
# include "dos.h"
|
# include "dos.h"
|
||||||
int gettimeofday(struct timeval * tp, struct timezone * tzp);
|
static int gettimeofday(struct timeval* tp, struct timezone*)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#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.3";
|
||||||
|
static const string AppName = "Stockfish";
|
||||||
|
static const string AppTag = "";
|
||||||
|
|
||||||
|
|
||||||
|
////
|
||||||
|
//// Variables
|
||||||
|
////
|
||||||
|
|
||||||
|
long dbg_cnt0 = 0;
|
||||||
|
long dbg_cnt1 = 0;
|
||||||
|
|
||||||
|
bool dbg_show_mean = false;
|
||||||
|
bool dbg_show_hit_rate = false;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// engine_name() returns the full name of the current Glaurung version.
|
void dbg_hit_on(bool b) {
|
||||||
/// This will be either "Glaurung YYMMDD" (where YYMMDD is the date when the
|
|
||||||
/// program was compiled) or "Glaurung <version number>", depending on whether
|
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() {
|
||||||
|
|
||||||
|
cout << "Total " << dbg_cnt0 << " Hit " << dbg_cnt1
|
||||||
|
<< " hit rate (%) " << (dbg_cnt1*100)/(dbg_cnt0 ? dbg_cnt0 : 1) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_print_mean() {
|
||||||
|
|
||||||
|
cout << "Total " << dbg_cnt0 << " Mean "
|
||||||
|
<< (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.
|
||||||
|
/// This will be either "Stockfish YYMMDD" (where YYMMDD is the date when the
|
||||||
|
/// program was compiled) or "Stockfish <version number>", depending on whether
|
||||||
/// the constant EngineVersion (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 == "") {
|
|
||||||
static const char monthNames[12][4] = {
|
|
||||||
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
|
|
||||||
};
|
|
||||||
const char *dateString = __DATE__;
|
|
||||||
std::stringstream s;
|
|
||||||
int month = 0, day = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < 12; i++)
|
if (!EngineVersion.empty())
|
||||||
if(strncmp(dateString, monthNames[i], 3) == 0)
|
return "Stockfish " + EngineVersion;
|
||||||
month = i + 1;
|
|
||||||
day = atoi(dateString+4);
|
|
||||||
|
|
||||||
s << "Glaurung " << (dateString+9) << std::setfill('0') << std::setw(2)
|
string date(__DATE__); // From compiler, format is "Sep 21 2008"
|
||||||
<< month << std::setfill('0') << std::setw(2) << day;
|
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;
|
||||||
|
|
||||||
|
stringstream s;
|
||||||
|
string day = (date[4] == ' ' ? date.substr(5, 1) : date.substr(4, 2));
|
||||||
|
|
||||||
|
string name = AppName + " " + AppTag + " ";
|
||||||
|
|
||||||
|
s << name << date.substr(date.length() - 2) << setfill('0')
|
||||||
|
<< setw(2) << mon << setw(2) << day;
|
||||||
|
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
|
||||||
else
|
|
||||||
return "Glaurung " + EngineVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -162,8 +265,24 @@ int Bioskey()
|
|||||||
return 1;
|
return 1;
|
||||||
return dw;
|
return dw;
|
||||||
} else {
|
} else {
|
||||||
|
// Count the number of unread input records, including keyboard,
|
||||||
|
// mouse, and window-resizing input records.
|
||||||
GetNumberOfConsoleInputEvents(inh, &dw);
|
GetNumberOfConsoleInputEvents(inh, &dw);
|
||||||
return dw <= 1 ? 0 : dw;
|
if (dw <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Read data from console without removing it from the buffer
|
||||||
|
INPUT_RECORD rec[256];
|
||||||
|
DWORD recCnt;
|
||||||
|
if (!PeekConsoleInput(inh, rec, Min(dw, 256), &recCnt))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Search for at least one keyboard event
|
||||||
|
for (DWORD i = 0; i < recCnt; i++)
|
||||||
|
if (rec[i].EventType == KEY_EVENT)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+25
-15
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -25,20 +26,10 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// 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 = "2.1";
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Macros
|
//// Macros
|
||||||
////
|
////
|
||||||
@@ -56,5 +47,24 @@ extern int get_system_time();
|
|||||||
extern int cpu_count();
|
extern int cpu_count();
|
||||||
extern int Bioskey();
|
extern int Bioskey();
|
||||||
|
|
||||||
|
////
|
||||||
|
//// Debug
|
||||||
|
////
|
||||||
|
|
||||||
|
extern bool dbg_show_mean;
|
||||||
|
extern bool dbg_show_hit_rate;
|
||||||
|
|
||||||
|
extern long dbg_cnt0;
|
||||||
|
extern long dbg_cnt1;
|
||||||
|
|
||||||
|
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_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)
|
||||||
|
|||||||
+54
-48
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -39,61 +40,66 @@
|
|||||||
/// moves, we need the position. This function is not robust, and expects that
|
/// moves, we need the position. This function is not robust, and expects that
|
||||||
/// the input move is legal and correctly formatted.
|
/// the input move is legal and correctly formatted.
|
||||||
|
|
||||||
Move move_from_string(const Position &pos, const std::string &str) {
|
Move move_from_string(const Position& pos, const std::string& str) {
|
||||||
|
|
||||||
Square from, to;
|
Square from, to;
|
||||||
Piece piece;
|
Piece piece;
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
|
|
||||||
if(str.length() < 4) return MOVE_NONE;
|
if (str.length() < 4)
|
||||||
|
return MOVE_NONE;
|
||||||
|
|
||||||
// Read the from and to squares:
|
// Read the from and to squares
|
||||||
from = square_from_string(str.substr(0, 2));
|
from = square_from_string(str.substr(0, 2));
|
||||||
to = square_from_string(str.substr(2, 4));
|
to = square_from_string(str.substr(2, 4));
|
||||||
|
|
||||||
// Find the moving piece:
|
// Find the moving piece
|
||||||
piece = pos.piece_on(from);
|
piece = pos.piece_on(from);
|
||||||
|
|
||||||
// If the string has more than 4 characters, try to interpret the 5th
|
// If the string has more than 4 characters, try to interpret the 5th
|
||||||
// character as a promotion:
|
// character as a promotion
|
||||||
if(type_of_piece(piece) == PAWN && str.length() >= 5) {
|
if (type_of_piece(piece) == PAWN && str.length() > 4)
|
||||||
switch(str[4]) {
|
{
|
||||||
case 'n': case 'N':
|
switch (tolower(str[4])) {
|
||||||
|
case 'n':
|
||||||
return make_promotion_move(from, to, KNIGHT);
|
return make_promotion_move(from, to, KNIGHT);
|
||||||
case 'b': case 'B':
|
case 'b':
|
||||||
return make_promotion_move(from, to, BISHOP);
|
return make_promotion_move(from, to, BISHOP);
|
||||||
case 'r': case 'R':
|
case 'r':
|
||||||
return make_promotion_move(from, to, ROOK);
|
return make_promotion_move(from, to, ROOK);
|
||||||
case 'q': case 'Q':
|
case 'q':
|
||||||
return make_promotion_move(from, to, QUEEN);
|
return make_promotion_move(from, to, QUEEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
{
|
||||||
// This is a castling move, but we have to translate it to the
|
// This is a castling move, but we have to translate it to the
|
||||||
// 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;
|
Square s = from + delta;
|
||||||
for(s = from + delta;
|
while (relative_rank(us, s) == RANK_1 && pos.piece_on(s) != piece_of_color_and_type(us, ROOK))
|
||||||
pawn_rank(us, s) == RANK_1 && pos.piece_on(s) != rook_of_color(us);
|
s += delta;
|
||||||
s += delta);
|
|
||||||
if(pawn_rank(us, s) == RANK_1 && pos.piece_on(s) == rook_of_color(us))
|
return (relative_rank(us, s) == RANK_1 ? make_castle_move(from, s) : MOVE_NONE);
|
||||||
return make_castle_move(from, s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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.
|
||||||
if(to == pos.ep_square())
|
if (to == pos.ep_square())
|
||||||
return make_ep_move(from, to);
|
return make_ep_move(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
return make_move(from, to);
|
return make_move(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,29 +110,27 @@ Move move_from_string(const Position &pos, const std::string &str) {
|
|||||||
/// Chess960 mode.
|
/// Chess960 mode.
|
||||||
|
|
||||||
const std::string move_to_string(Move move) {
|
const std::string move_to_string(Move move) {
|
||||||
std::string str;
|
|
||||||
|
|
||||||
if(move == MOVE_NONE)
|
std::string str;
|
||||||
|
Square from = move_from(move);
|
||||||
|
Square to = move_to(move);
|
||||||
|
|
||||||
|
if (move == MOVE_NONE)
|
||||||
str = "(none)";
|
str = "(none)";
|
||||||
else if(move == MOVE_NULL)
|
else if (move == MOVE_NULL)
|
||||||
str = "0000";
|
str = "0000";
|
||||||
else {
|
else
|
||||||
if(!Chess960) {
|
{
|
||||||
if(move_from(move) == SQ_E1 && move_is_short_castle(move)) {
|
if (!Chess960)
|
||||||
str = "e1g1"; return str;
|
{
|
||||||
|
if (move_is_short_castle(move))
|
||||||
|
return (from == SQ_E1 ? "e1g1" : "e8g8");
|
||||||
|
|
||||||
|
if (move_is_long_castle(move))
|
||||||
|
return (from == SQ_E1 ? "e1c1" : "e8c8");
|
||||||
}
|
}
|
||||||
else if(move_from(move) == SQ_E1 && move_is_long_castle(move)) {
|
str = square_to_string(from) + square_to_string(to);
|
||||||
str = "e1c1"; return str;
|
if (move_promotion(move))
|
||||||
}
|
|
||||||
if(move_from(move) == SQ_E8 && move_is_short_castle(move)) {
|
|
||||||
str = "e8g8"; return str;
|
|
||||||
}
|
|
||||||
else if(move_from(move) == SQ_E8 && move_is_long_castle(move)) {
|
|
||||||
str = "e8c8"; return str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
str = square_to_string(move_from(move)) + square_to_string(move_to(move));
|
|
||||||
if(move_promotion(move))
|
|
||||||
str += piece_type_to_char(move_promotion(move), false);
|
str += piece_type_to_char(move_promotion(move), false);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
@@ -135,7 +139,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,5 +148,6 @@ std::ostream &operator << (std::ostream &os, Move m) {
|
|||||||
/// move_is_ok(), for debugging.
|
/// move_is_ok(), for debugging.
|
||||||
|
|
||||||
bool move_is_ok(Move m) {
|
bool move_is_ok(Move m) {
|
||||||
|
|
||||||
return square_is_ok(move_from(m)) && square_is_ok(move_to(m));
|
return square_is_ok(move_from(m)) && square_is_ok(move_to(m));
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-8
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -37,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
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -49,17 +62,20 @@ 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(Move m) {
|
||||||
|
|||||||
+674
-980
File diff suppressed because it is too large
Load Diff
+12
-11
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -31,12 +32,12 @@
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern int generate_captures(const Position &pos, MoveStack *mlist);
|
extern int generate_captures(const Position& pos, MoveStack* mlist);
|
||||||
extern int generate_noncaptures(const Position &pos, MoveStack *mlist);
|
extern int generate_noncaptures(const Position& pos, MoveStack* mlist);
|
||||||
extern int generate_checks(const Position &pos, MoveStack *mlist, Bitboard dc);
|
extern int generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc);
|
||||||
extern int generate_evasions(const Position &pos, MoveStack *mlist);
|
extern int generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
|
||||||
extern int generate_legal_moves(const Position &pos, MoveStack *mlist);
|
extern int generate_legal_moves(const Position& pos, MoveStack* mlist);
|
||||||
extern Move generate_move_if_legal(const Position &pos, Move m,
|
extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned);
|
||||||
Bitboard pinned);
|
|
||||||
|
|
||||||
#endif // !defined(MOVEGEN_H_INCLUDED)
|
#endif // !defined(MOVEGEN_H_INCLUDED)
|
||||||
|
|||||||
+151
-246
@@ -1,13 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -21,9 +23,11 @@
|
|||||||
//// 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"
|
||||||
@@ -36,26 +40,9 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Types
|
|
||||||
|
|
||||||
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 valuse <= 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
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Variables
|
/// Variables
|
||||||
|
|
||||||
MovegenPhase PhaseTable[32];
|
MovePicker::MovegenPhase PhaseTable[32];
|
||||||
int MainSearchPhaseIndex;
|
int MainSearchPhaseIndex;
|
||||||
int EvasionsPhaseIndex;
|
int EvasionsPhaseIndex;
|
||||||
int QsearchWithChecksPhaseIndex;
|
int QsearchWithChecksPhaseIndex;
|
||||||
@@ -76,30 +63,31 @@ namespace {
|
|||||||
/// search captures, promotions and some checks) and about how important good
|
/// search captures, promotions and some checks) and about how important good
|
||||||
/// move ordering is at the current node.
|
/// move ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(Position &p, bool pvnode, Move ttm, Move mk,
|
MovePicker::MovePicker(const Position& p, bool pv, Move ttm,
|
||||||
Move k1, Move k2, Depth dpth) {
|
const SearchStack& ss, Depth d) : pos(p) {
|
||||||
pos = &p;
|
pvNode = pv;
|
||||||
pvNode = pvnode;
|
|
||||||
ttMove = ttm;
|
ttMove = ttm;
|
||||||
mateKiller = (mk == ttm)? MOVE_NONE : mk;
|
mateKiller = (ss.mateKiller == ttm)? MOVE_NONE : ss.mateKiller;
|
||||||
killer1 = k1;
|
killer1 = ss.killers[0];
|
||||||
killer2 = k2;
|
killer2 = ss.killers[1];
|
||||||
depth = dpth;
|
depth = d;
|
||||||
movesPicked = 0;
|
movesPicked = 0;
|
||||||
numOfMoves = 0;
|
numOfMoves = 0;
|
||||||
numOfBadCaptures = 0;
|
numOfBadCaptures = 0;
|
||||||
dc = p.discovered_check_candidates(p.side_to_move());
|
|
||||||
|
|
||||||
if(p.is_check())
|
if (p.is_check())
|
||||||
phaseIndex = EvasionsPhaseIndex;
|
phaseIndex = EvasionsPhaseIndex;
|
||||||
else if(depth > Depth(0))
|
else if (depth > Depth(0))
|
||||||
phaseIndex = MainSearchPhaseIndex;
|
phaseIndex = MainSearchPhaseIndex;
|
||||||
else if(depth == Depth(0))
|
else if (depth == Depth(0))
|
||||||
phaseIndex = QsearchWithChecksPhaseIndex;
|
phaseIndex = QsearchWithChecksPhaseIndex;
|
||||||
else
|
else
|
||||||
phaseIndex = QsearchWithoutChecksPhaseIndex;
|
phaseIndex = QsearchWithoutChecksPhaseIndex;
|
||||||
|
|
||||||
pinned = p.pinned_pieces(p.side_to_move());
|
Color us = pos.side_to_move();
|
||||||
|
|
||||||
|
dc = p.discovered_check_candidates(us);
|
||||||
|
pinned = p.pinned_pieces(us);
|
||||||
|
|
||||||
finished = false;
|
finished = false;
|
||||||
}
|
}
|
||||||
@@ -110,77 +98,79 @@ MovePicker::MovePicker(Position &p, bool pvnode, Move ttm, Move mk,
|
|||||||
/// are no more moves left of the types we are interested in.
|
/// are no more moves left of the types we are interested in.
|
||||||
|
|
||||||
Move MovePicker::get_next_move() {
|
Move MovePicker::get_next_move() {
|
||||||
|
|
||||||
Move move;
|
Move move;
|
||||||
|
|
||||||
while(true) {
|
while (true)
|
||||||
|
{
|
||||||
// If we already have a list of generated moves, pick the best move from
|
// If we already have a list of generated moves, pick the best move from
|
||||||
// the list, and return it:
|
// the list, and return it.
|
||||||
move = this->pick_move_from_list();
|
move = pick_move_from_list();
|
||||||
if(move != MOVE_NONE) {
|
if (move != MOVE_NONE)
|
||||||
|
{
|
||||||
assert(move_is_ok(move));
|
assert(move_is_ok(move));
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next phase:
|
// Next phase
|
||||||
phaseIndex++;
|
phaseIndex++;
|
||||||
switch(PhaseTable[phaseIndex]) {
|
switch (PhaseTable[phaseIndex]) {
|
||||||
|
|
||||||
case PH_TT_MOVE:
|
case PH_TT_MOVE:
|
||||||
if(ttMove != MOVE_NONE) {
|
if (ttMove != MOVE_NONE)
|
||||||
|
{
|
||||||
assert(move_is_ok(ttMove));
|
assert(move_is_ok(ttMove));
|
||||||
Move m = generate_move_if_legal(*pos, ttMove, pinned);
|
if (move_is_legal(pos, ttMove, pinned))
|
||||||
if(m != MOVE_NONE) {
|
return ttMove;
|
||||||
assert(m == ttMove);
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_MATE_KILLER:
|
case PH_MATE_KILLER:
|
||||||
if(mateKiller != MOVE_NONE) {
|
if (mateKiller != MOVE_NONE)
|
||||||
|
{
|
||||||
assert(move_is_ok(mateKiller));
|
assert(move_is_ok(mateKiller));
|
||||||
Move m = generate_move_if_legal(*pos, mateKiller, pinned);
|
if (move_is_legal(pos, mateKiller, pinned))
|
||||||
if(m != MOVE_NONE) {
|
return mateKiller;
|
||||||
assert(m == mateKiller);
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_GOOD_CAPTURES:
|
case PH_GOOD_CAPTURES:
|
||||||
// pinned = pos->pinned_pieces(pos->side_to_move());
|
numOfMoves = generate_captures(pos, moves);
|
||||||
numOfMoves = generate_captures(*pos, moves);
|
score_captures();
|
||||||
this->score_captures();
|
std::sort(moves, moves + numOfMoves);
|
||||||
movesPicked = 0;
|
movesPicked = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
case PH_BAD_CAPTURES:
|
||||||
badCapturesPicked = 0;
|
// It's probably a good idea to use SEE move ordering here. FIXME
|
||||||
|
movesPicked = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
numOfMoves = generate_noncaptures(*pos, moves);
|
numOfMoves = generate_noncaptures(pos, moves);
|
||||||
this->score_noncaptures();
|
score_noncaptures();
|
||||||
|
std::sort(moves, moves + numOfMoves);
|
||||||
movesPicked = 0;
|
movesPicked = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_EVASIONS:
|
case PH_EVASIONS:
|
||||||
assert(pos->is_check());
|
assert(pos.is_check());
|
||||||
// pinned = pos->pinned_pieces(pos->side_to_move());
|
numOfMoves = generate_evasions(pos, moves, pinned);
|
||||||
numOfMoves = generate_evasions(*pos, moves);
|
score_evasions();
|
||||||
this->score_evasions();
|
std::sort(moves, moves + numOfMoves);
|
||||||
movesPicked = 0;
|
movesPicked = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
case PH_QCAPTURES:
|
||||||
// pinned = pos->pinned_pieces(pos->side_to_move());
|
numOfMoves = generate_captures(pos, moves);
|
||||||
numOfMoves = generate_captures(*pos, moves);
|
score_qcaptures();
|
||||||
this->score_qcaptures();
|
std::sort(moves, moves + numOfMoves);
|
||||||
movesPicked = 0;
|
movesPicked = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_QCHECKS:
|
case PH_QCHECKS:
|
||||||
numOfMoves = generate_checks(*pos, moves, dc);
|
// Perhaps we should order moves move here? FIXME
|
||||||
|
numOfMoves = generate_non_capture_checks(pos, moves, dc);
|
||||||
movesPicked = 0;
|
movesPicked = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -192,10 +182,6 @@ Move MovePicker::get_next_move() {
|
|||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false);
|
|
||||||
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -203,37 +189,26 @@ Move MovePicker::get_next_move() {
|
|||||||
/// prevent multiple threads from picking the same move at a split point.
|
/// prevent multiple threads from picking the same move at a split point.
|
||||||
|
|
||||||
Move MovePicker::get_next_move(Lock &lock) {
|
Move MovePicker::get_next_move(Lock &lock) {
|
||||||
Move m;
|
|
||||||
|
|
||||||
lock_grab(&lock);
|
lock_grab(&lock);
|
||||||
if(finished) {
|
if (finished)
|
||||||
|
{
|
||||||
lock_release(&lock);
|
lock_release(&lock);
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
m = this->get_next_move();
|
Move m = get_next_move();
|
||||||
if(m == MOVE_NONE)
|
if (m == MOVE_NONE)
|
||||||
finished = true;
|
finished = true;
|
||||||
|
|
||||||
lock_release(&lock);
|
lock_release(&lock);
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::number_of_moves() simply returns the numOfMoves member
|
|
||||||
/// variable. It is intended to be used in positions where the side to move
|
|
||||||
/// is in check, for detecting checkmates or situations where there is only
|
|
||||||
/// a single reply to check.
|
|
||||||
|
|
||||||
int MovePicker::number_of_moves() const {
|
|
||||||
return numOfMoves;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::score_captures(), MovePicker::score_noncaptures(),
|
/// MovePicker::score_captures(), MovePicker::score_noncaptures(),
|
||||||
/// MovePicker::score_evasions() and MovePicker::score_qcaptures() assign a
|
/// MovePicker::score_evasions() and MovePicker::score_qcaptures() assign a
|
||||||
/// numerical move ordering score to each move in a move list. The moves
|
/// numerical move ordering score to each move in a move list. The moves
|
||||||
/// with highest scores will be picked first by
|
/// with highest scores will be picked first by pick_move_from_list().
|
||||||
/// MovePicker::pick_move_from_list().
|
|
||||||
|
|
||||||
void MovePicker::score_captures() {
|
void MovePicker::score_captures() {
|
||||||
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
||||||
@@ -245,58 +220,88 @@ void MovePicker::score_captures() {
|
|||||||
// where it is possible to recapture with the hanging piece). Exchanging
|
// where it is possible to recapture with the hanging piece). Exchanging
|
||||||
// big pieces before capturing a hanging piece probably helps to reduce
|
// big pieces before capturing a hanging piece probably helps to reduce
|
||||||
// the subtree size.
|
// the subtree size.
|
||||||
for(int i = 0; i < numOfMoves; i++) {
|
// While scoring captures it moves all captures with negative SEE values
|
||||||
int seeValue = pos->see(moves[i].move);
|
// to the badCaptures[] array.
|
||||||
if(seeValue >= 0) {
|
Move m;
|
||||||
if(move_promotion(moves[i].move))
|
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;
|
moves[i].score = QueenValueMidgame;
|
||||||
else
|
else
|
||||||
moves[i].score =
|
moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
||||||
int(pos->midgame_value_of_piece_on(move_to(moves[i].move))) -
|
-int(pos.type_of_piece_on(move_from(m)));
|
||||||
int(pos->type_of_piece_on(move_from(moves[i].move)));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// Losing capture, move it to the badCaptures[] array
|
||||||
|
assert(numOfBadCaptures < 63);
|
||||||
moves[i].score = seeValue;
|
moves[i].score = seeValue;
|
||||||
|
badCaptures[numOfBadCaptures++] = moves[i];
|
||||||
|
moves[i--] = moves[--numOfMoves];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovePicker::score_noncaptures() {
|
void MovePicker::score_noncaptures() {
|
||||||
for(int i = 0; i < numOfMoves; i++) {
|
// First score by history, when no history is available then use
|
||||||
Move m = moves[i].move;
|
// piece/square tables values. This seems to be better then a
|
||||||
if(m == killer1)
|
// random choice when we don't have an history for any move.
|
||||||
moves[i].score = HistoryMax + 2;
|
Move m;
|
||||||
else if(m == killer2)
|
int hs;
|
||||||
moves[i].score = HistoryMax + 1;
|
|
||||||
|
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
|
else
|
||||||
moves[i].score = H.move_ordering_score(pos->piece_on(move_from(m)), m);
|
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() {
|
void MovePicker::score_evasions() {
|
||||||
for(int i = 0; i < numOfMoves; i++) {
|
|
||||||
|
for (int i = 0; i < numOfMoves; i++)
|
||||||
|
{
|
||||||
Move m = moves[i].move;
|
Move m = moves[i].move;
|
||||||
if(m == ttMove)
|
if (m == ttMove)
|
||||||
moves[i].score = 2*HistoryMax;
|
moves[i].score = 2*HistoryMax;
|
||||||
else if(!pos->square_is_empty(move_to(m))) {
|
else if (!pos.square_is_empty(move_to(m)))
|
||||||
int seeScore = pos->see(m);
|
{
|
||||||
|
int seeScore = pos.see(m);
|
||||||
moves[i].score = (seeScore >= 0)? seeScore + HistoryMax : seeScore;
|
moves[i].score = (seeScore >= 0)? seeScore + HistoryMax : seeScore;
|
||||||
}
|
} else
|
||||||
else
|
moves[i].score = H.move_ordering_score(pos.piece_on(move_from(m)), m);
|
||||||
moves[i].score = H.move_ordering_score(pos->piece_on(move_from(m)), m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovePicker::score_qcaptures() {
|
void MovePicker::score_qcaptures() {
|
||||||
// Use MVV/LVA ordering.
|
|
||||||
for(int i = 0; i < numOfMoves; i++) {
|
// Use MVV/LVA ordering
|
||||||
|
for (int i = 0; i < numOfMoves; i++)
|
||||||
|
{
|
||||||
Move m = moves[i].move;
|
Move m = moves[i].move;
|
||||||
if(move_promotion(m))
|
if (move_promotion(m))
|
||||||
moves[i].score = QueenValueMidgame;
|
moves[i].score = QueenValueMidgame;
|
||||||
else
|
else
|
||||||
moves[i].score =
|
moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
||||||
int(pos->midgame_value_of_piece_on(move_to(m))) -
|
-int(pos.type_of_piece_on(move_from(m)));
|
||||||
int(pos->midgame_value_of_piece_on(move_to(m))) / 64;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,154 +310,52 @@ void MovePicker::score_qcaptures() {
|
|||||||
/// from a list of generated moves (moves[] or badCaptures[], depending on
|
/// from a list of generated moves (moves[] or badCaptures[], depending on
|
||||||
/// the current move generation phase). It takes care not to return the
|
/// the current move generation phase). It takes care not to return the
|
||||||
/// transposition table move if that has already been serched previously.
|
/// transposition table move if that has already been serched previously.
|
||||||
/// While picking captures in the PH_GOOD_CAPTURES phase (i.e. while picking
|
|
||||||
/// non-losing captures in the main search), it moves all captures with
|
|
||||||
/// negative SEE values to the badCaptures[] array.
|
|
||||||
|
|
||||||
Move MovePicker::pick_move_from_list() {
|
Move MovePicker::pick_move_from_list() {
|
||||||
int bestScore = -10000000;
|
|
||||||
int bestIndex;
|
|
||||||
Move move;
|
|
||||||
|
|
||||||
switch(PhaseTable[phaseIndex]) {
|
assert(movesPicked >= 0);
|
||||||
|
assert(!pos.is_check() || PhaseTable[phaseIndex] == PH_EVASIONS || PhaseTable[phaseIndex] == PH_STOP);
|
||||||
|
assert( pos.is_check() || PhaseTable[phaseIndex] != PH_EVASIONS);
|
||||||
|
|
||||||
|
switch (PhaseTable[phaseIndex]) {
|
||||||
|
|
||||||
case PH_GOOD_CAPTURES:
|
case PH_GOOD_CAPTURES:
|
||||||
assert(!pos->is_check());
|
|
||||||
assert(movesPicked >= 0);
|
|
||||||
while(movesPicked < numOfMoves) {
|
|
||||||
bestScore = -10000000;
|
|
||||||
bestIndex = -1;
|
|
||||||
for(int i = movesPicked; i < numOfMoves; i++) {
|
|
||||||
if(moves[i].score < 0) {
|
|
||||||
// Losing capture, move it to the badCaptures[] array
|
|
||||||
assert(numOfBadCaptures < 63);
|
|
||||||
badCaptures[numOfBadCaptures++] = moves[i];
|
|
||||||
moves[i--] = moves[--numOfMoves];
|
|
||||||
}
|
|
||||||
else if(moves[i].score > bestScore) {
|
|
||||||
bestIndex = i;
|
|
||||||
bestScore = moves[i].score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(bestIndex != -1) { // Found a good capture
|
|
||||||
MoveStack tmp = moves[movesPicked];
|
|
||||||
moves[movesPicked] = moves[bestIndex];
|
|
||||||
moves[bestIndex] = tmp;
|
|
||||||
move = moves[movesPicked++].move;
|
|
||||||
if(move != ttMove && move != mateKiller &&
|
|
||||||
pos->move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
assert(!pos->is_check());
|
while (movesPicked < numOfMoves)
|
||||||
assert(movesPicked >= 0);
|
{
|
||||||
while(movesPicked < numOfMoves) {
|
Move move = moves[movesPicked++].move;
|
||||||
bestScore = -10000000;
|
if ( move != ttMove
|
||||||
|
&& move != mateKiller
|
||||||
// If this is a PV node or we have only picked a few moves, scan
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
// 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.
|
|
||||||
if(pvNode || movesPicked < 12) {
|
|
||||||
bestIndex = -1;
|
|
||||||
for(int i = movesPicked; i < numOfMoves; i++)
|
|
||||||
if(moves[i].score > bestScore) {
|
|
||||||
bestIndex = i;
|
|
||||||
bestScore = moves[i].score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
bestIndex = movesPicked;
|
|
||||||
|
|
||||||
if(bestIndex != -1) {
|
|
||||||
MoveStack tmp = moves[movesPicked];
|
|
||||||
moves[movesPicked] = moves[bestIndex];
|
|
||||||
moves[bestIndex] = tmp;
|
|
||||||
move = moves[movesPicked++].move;
|
|
||||||
if(move != ttMove && move != mateKiller &&
|
|
||||||
pos->move_is_legal(move, pinned))
|
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_EVASIONS:
|
case PH_EVASIONS:
|
||||||
assert(pos->is_check());
|
if (movesPicked < numOfMoves)
|
||||||
assert(movesPicked >= 0);
|
return moves[movesPicked++].move;
|
||||||
while(movesPicked < numOfMoves) {
|
|
||||||
bestScore = -10000000;
|
|
||||||
bestIndex = -1;
|
|
||||||
for(int i = movesPicked; i < numOfMoves; i++)
|
|
||||||
if(moves[i].score > bestScore) {
|
|
||||||
bestIndex = i;
|
|
||||||
bestScore = moves[i].score;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(bestIndex != -1) {
|
|
||||||
MoveStack tmp = moves[movesPicked];
|
|
||||||
moves[movesPicked] = moves[bestIndex];
|
|
||||||
moves[bestIndex] = tmp;
|
|
||||||
move = moves[movesPicked++].move;
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
case PH_BAD_CAPTURES:
|
||||||
assert(!pos->is_check());
|
while (movesPicked < numOfBadCaptures)
|
||||||
assert(badCapturesPicked >= 0);
|
{
|
||||||
// It's probably a good idea to use SEE move ordering here, instead
|
Move move = badCaptures[movesPicked++].move;
|
||||||
// of just picking the first move. FIXME
|
if ( move != ttMove
|
||||||
while(badCapturesPicked < numOfBadCaptures) {
|
&& move != mateKiller
|
||||||
move = badCaptures[badCapturesPicked++].move;
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
if(move != ttMove && move != mateKiller &&
|
|
||||||
pos->move_is_legal(move, pinned))
|
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
case PH_QCAPTURES:
|
||||||
assert(!pos->is_check());
|
|
||||||
assert(movesPicked >= 0);
|
|
||||||
while(movesPicked < numOfMoves) {
|
|
||||||
bestScore = -10000000;
|
|
||||||
if(movesPicked < 4) {
|
|
||||||
bestIndex = -1;
|
|
||||||
for(int i = movesPicked; i < numOfMoves; i++)
|
|
||||||
if(moves[i].score > bestScore) {
|
|
||||||
bestIndex = i;
|
|
||||||
bestScore = moves[i].score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
bestIndex = movesPicked;
|
|
||||||
|
|
||||||
if(bestIndex != -1) {
|
|
||||||
MoveStack tmp = moves[movesPicked];
|
|
||||||
moves[movesPicked] = moves[bestIndex];
|
|
||||||
moves[bestIndex] = tmp;
|
|
||||||
|
|
||||||
move = moves[movesPicked++].move;
|
|
||||||
// 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->move_is_legal(move, pinned))
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PH_QCHECKS:
|
case PH_QCHECKS:
|
||||||
assert(!pos->is_check());
|
while (movesPicked < numOfMoves)
|
||||||
assert(movesPicked >= 0);
|
{
|
||||||
// Perhaps we should do something better than just picking the first
|
Move move = moves[movesPicked++].move;
|
||||||
// move here? FIXME
|
// Maybe postpone the legality check until after futility pruning?
|
||||||
while(movesPicked < numOfMoves) {
|
if ( move != ttMove
|
||||||
move = moves[movesPicked++].move;
|
&& pos.pl_move_is_legal(move, pinned))
|
||||||
// Remember to change the line below if we decide to hash the qsearch!
|
|
||||||
if(/* move != ttMove && */ pos->move_is_legal(move, pinned))
|
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -460,17 +363,17 @@ Move MovePicker::pick_move_from_list() {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker::init_phase_table() initializes the PhaseTable[],
|
/// MovePicker::init_phase_table() initializes the PhaseTable[],
|
||||||
/// MainSearchPhaseIndex, EvasionPhaseIndex, QsearchWithChecksPhaseIndex
|
/// MainSearchPhaseIndex, EvasionPhaseIndex, QsearchWithChecksPhaseIndex
|
||||||
/// and QsearchWithoutChecksPhaseIndex variables. It is only called once
|
/// and QsearchWithoutChecksPhaseIndex. It is only called once during
|
||||||
/// during program startup, and never again while the program is running.
|
/// program startup, and never again while the program is running.
|
||||||
|
|
||||||
void MovePicker::init_phase_table() {
|
void MovePicker::init_phase_table() {
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// Main search
|
// Main search
|
||||||
@@ -492,12 +395,14 @@ void MovePicker::init_phase_table() {
|
|||||||
|
|
||||||
// Quiescence search with checks
|
// Quiescence search with checks
|
||||||
QsearchWithChecksPhaseIndex = i - 1;
|
QsearchWithChecksPhaseIndex = i - 1;
|
||||||
|
PhaseTable[i++] = PH_TT_MOVE;
|
||||||
PhaseTable[i++] = PH_QCAPTURES;
|
PhaseTable[i++] = PH_QCAPTURES;
|
||||||
PhaseTable[i++] = PH_QCHECKS;
|
PhaseTable[i++] = PH_QCHECKS;
|
||||||
PhaseTable[i++] = PH_STOP;
|
PhaseTable[i++] = PH_STOP;
|
||||||
|
|
||||||
// Quiescence search without checks
|
// Quiescence search without checks
|
||||||
QsearchWithoutChecksPhaseIndex = i - 1;
|
QsearchWithoutChecksPhaseIndex = i - 1;
|
||||||
|
PhaseTable[i++] = PH_TT_MOVE;
|
||||||
PhaseTable[i++] = PH_QCAPTURES;
|
PhaseTable[i++] = PH_QCAPTURES;
|
||||||
PhaseTable[i++] = PH_STOP;
|
PhaseTable[i++] = PH_STOP;
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-10
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -33,6 +34,9 @@
|
|||||||
//// Types
|
//// Types
|
||||||
////
|
////
|
||||||
|
|
||||||
|
struct EvalInfo;
|
||||||
|
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
|
||||||
@@ -43,14 +47,30 @@
|
|||||||
|
|
||||||
class MovePicker {
|
class MovePicker {
|
||||||
|
|
||||||
|
MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MovePicker(Position &p, bool pvnode, Move ttm, Move mk, Move k1, Move k2,
|
|
||||||
Depth dpth);
|
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);
|
||||||
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_moves() const;
|
||||||
int current_move_score() const;
|
int current_move_score() const;
|
||||||
Bitboard discovered_check_candidates();
|
Bitboard discovered_check_candidates() const;
|
||||||
|
|
||||||
static void init_phase_table();
|
static void init_phase_table();
|
||||||
|
|
||||||
@@ -61,7 +81,7 @@ private:
|
|||||||
void score_qcaptures();
|
void score_qcaptures();
|
||||||
Move pick_move_from_list();
|
Move pick_move_from_list();
|
||||||
|
|
||||||
Position *pos;
|
const Position& pos;
|
||||||
Move ttMove, mateKiller, killer1, killer2;
|
Move ttMove, mateKiller, killer1, killer2;
|
||||||
Bitboard pinned, dc;
|
Bitboard pinned, dc;
|
||||||
MoveStack moves[256], badCaptures[64];
|
MoveStack moves[256], badCaptures[64];
|
||||||
@@ -69,7 +89,7 @@ private:
|
|||||||
Depth depth;
|
Depth depth;
|
||||||
int phaseIndex;
|
int phaseIndex;
|
||||||
int numOfMoves, numOfBadCaptures;
|
int numOfMoves, numOfBadCaptures;
|
||||||
int movesPicked, badCapturesPicked;
|
int movesPicked;
|
||||||
bool finished;
|
bool finished;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,11 +98,20 @@ private:
|
|||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
|
/// MovePicker::number_of_moves() simply returns the numOfMoves member
|
||||||
|
/// variable. It is intended to be used in positions where the side to move
|
||||||
|
/// is in check, for detecting checkmates or situations where there is only
|
||||||
|
/// a single reply to check.
|
||||||
|
|
||||||
|
inline int MovePicker::number_of_moves() const {
|
||||||
|
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() {
|
inline Bitboard MovePicker::discovered_check_candidates() const {
|
||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+142
-131
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -22,8 +23,10 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
|
#include "position.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -84,24 +87,21 @@ namespace {
|
|||||||
|
|
||||||
// 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(12), Value(12), Value(20),
|
||||||
Value(40), Value(90), Value(0), Value(0)
|
Value(40), Value(90), 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(24), Value(24), Value(40),
|
||||||
Value(80), Value(180), Value(0), Value(0)
|
Value(80), Value(180), Value(0), Value( 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Evaluate pawn storms?
|
|
||||||
const bool EvaluatePawnStorms = true;
|
|
||||||
|
|
||||||
// Pawn storm tables for positions with opposite castling:
|
// 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,-13,-4, 0, 0, 0,
|
||||||
-4, -9, -9, -9, -4, 0, 0, 0,
|
-4, -9, -9, -9,-4, 0, 0, 0,
|
||||||
9, 18, 22, 18, 9, 0, 0, 0,
|
9, 18, 22, 18, 9, 0, 0, 0,
|
||||||
22, 31, 31, 22, 0, 0, 0, 0,
|
22, 31, 31, 22, 0, 0, 0, 0,
|
||||||
31, 40, 40, 31, 0, 0, 0, 0,
|
31, 40, 40, 31, 0, 0, 0, 0,
|
||||||
@@ -111,8 +111,8 @@ namespace {
|
|||||||
|
|
||||||
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,-4,-13,-22,-27,-27,
|
||||||
0, 0, 0, -4, -9, -13, -18, -18,
|
0, 0, 0,-4, -9,-13,-18,-18,
|
||||||
0, 0, 0, 0, 9, 9, 9, 9,
|
0, 0, 0, 0, 9, 9, 9, 9,
|
||||||
0, 0, 0, 0, 9, 18, 27, 27,
|
0, 0, 0, 0, 9, 18, 27, 27,
|
||||||
0, 0, 0, 0, 9, 27, 40, 36,
|
0, 0, 0, 0, 9, 27, 40, 36,
|
||||||
@@ -120,14 +120,12 @@ namespace {
|
|||||||
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] = { 45, 45, 30, 0, 0, 0, 0, 0 };
|
||||||
45, 45, 30, 0, 0, 0, 0, 0
|
const int16_t QStormOpenFileBonus[8] = { 0, 0, 0, 0, 0, 30, 45, 30 };
|
||||||
};
|
|
||||||
|
|
||||||
const int QStormOpenFileBonus[8] = {
|
// Pawn storm lever bonuses by file
|
||||||
0, 0, 0, 0, 0, 30, 45, 30
|
const int StormLeverBonus[8] = { 20, 20, 10, 0, 0, 10, 20, 20 };
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,14 +137,16 @@ 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 == NULL)
|
||||||
|
{
|
||||||
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(PawnInfo))
|
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(PawnInfo))
|
||||||
<< " bytes for pawn hash table." << std::endl;
|
<< " bytes for pawn hash table." << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
this->clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -171,6 +171,7 @@ void PawnInfoTable::clear() {
|
|||||||
/// 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();
|
||||||
@@ -179,43 +180,45 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
|||||||
|
|
||||||
// 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 the
|
||||||
// information we found the last time instead of recomputing it:
|
// 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:
|
// Loop through the pawns for both colors
|
||||||
for(Color us = WHITE; us <= BLACK; us++) {
|
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.pawns(us);
|
||||||
Bitboard theirPawns = pos.pawns(them);
|
Bitboard theirPawns = pos.pawns(them);
|
||||||
Bitboard pawns = ourPawns;
|
Bitboard pawns = ourPawns;
|
||||||
|
int bonus;
|
||||||
|
|
||||||
// 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 (pos.file_is_half_open(us, 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];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
|
{
|
||||||
|
bool passed, doubled, isolated, backward, chain, candidate;
|
||||||
Square s = pop_1st_bit(&pawns);
|
Square s = pop_1st_bit(&pawns);
|
||||||
File f = square_file(s);
|
File f = square_file(s);
|
||||||
Rank r = square_rank(s);
|
Rank r = square_rank(s);
|
||||||
bool passed, doubled, isolated, backward, chain, candidate;
|
|
||||||
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:
|
// The file containing the pawn is not half open
|
||||||
pi->halfOpenFiles[us] &= ~(1 << f);
|
pi->halfOpenFiles[us] &= ~(1 << f);
|
||||||
|
|
||||||
// Passed, isolated or doubled pawn?
|
// Passed, isolated or doubled pawn?
|
||||||
@@ -223,163 +226,171 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
|||||||
isolated = pos.pawn_is_isolated(us, s);
|
isolated = pos.pawn_is_isolated(us, s);
|
||||||
doubled = pos.pawn_is_doubled(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:
|
// Kingside pawn storms
|
||||||
bonus = KStormTable[relative_square(us, s)];
|
bonus = KStormTable[relative_square(us, s)];
|
||||||
if(bonus > 0 && outpost_mask(us, s) & theirPawns) {
|
if (f >= FILE_F)
|
||||||
switch(f) {
|
{
|
||||||
|
Bitboard b = outpost_mask(us, s) & theirPawns & (FileFBB | FileGBB | FileHBB);
|
||||||
case FILE_F:
|
while (b)
|
||||||
bonus += bonus / 4;
|
{
|
||||||
break;
|
Square s2 = pop_1st_bit(&b);
|
||||||
|
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||||
case FILE_G:
|
{
|
||||||
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_H:
|
if (square_file(s2) == FILE_H)
|
||||||
bonus += bonus / 2;
|
bonus += 4*StormLeverBonus[f] - 8*square_distance(s, s2);
|
||||||
break;
|
else
|
||||||
|
bonus += 2*StormLeverBonus[f] - 4*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] - 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
|
// Member of a pawn chain (but not the backward one)? We could speed up
|
||||||
// introducing an array of masks indexed by color and square for doing
|
// the test a little by introducing an array of masks indexed by color
|
||||||
// the test, but because everything is hashed, it probably won't make
|
// and square for doing the test, but because everything is hashed,
|
||||||
// any noticable difference.
|
// it probably won't make any noticable difference.
|
||||||
chain = (us == WHITE)?
|
chain = ourPawns
|
||||||
(ourPawns & neighboring_files_bb(f) & (rank_bb(r) | rank_bb(r-1))) :
|
& neighboring_files_bb(f)
|
||||||
(ourPawns & neighboring_files_bb(f) & (rank_bb(r) | rank_bb(r+1)));
|
& (rank_bb(r) | rank_bb(r - (us == WHITE ? 1 : -1)));
|
||||||
|
|
||||||
|
// Test for backward pawn
|
||||||
// Test for backward pawn.
|
//
|
||||||
|
// If the pawn is passed, isolated, or member of a pawn chain
|
||||||
// If the pawn is isolated, passed, or member of a pawn chain, it cannot
|
// it cannot be backward. If can capture an enemy pawn or if
|
||||||
// be backward:
|
// there are friendly pawns behind on neighboring files it cannot
|
||||||
if(passed || isolated || chain)
|
// be backward either.
|
||||||
|
if ( passed
|
||||||
|
|| isolated
|
||||||
|
|| chain
|
||||||
|
|| (pos.pawn_attacks(us, s) & theirPawns)
|
||||||
|
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
|
||||||
backward = false;
|
backward = false;
|
||||||
// If the pawn can capture an enemy pawn, it's not backward:
|
else
|
||||||
else if(pos.pawn_attacks(us, s) & theirPawns)
|
{
|
||||||
backward = false;
|
// We now know that there are no friendly pawns beside or behind this
|
||||||
// Check for friendly pawns behind on neighboring files:
|
|
||||||
else if(ourPawns & in_front_bb(them, r) & neighboring_files_bb(f))
|
|
||||||
backward = false;
|
|
||||||
else {
|
|
||||||
// We now know that there is no friendly pawns beside or behind this
|
|
||||||
// pawn on neighboring files. We now check whether the pawn is
|
// pawn on neighboring files. We now check whether the pawn is
|
||||||
// backward by looking in the forward direction on the neighboring
|
// backward by looking in the forward direction on the neighboring
|
||||||
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
if(us == WHITE) {
|
if (us == WHITE)
|
||||||
for(b=pos.pawn_attacks(us, s); !(b&(ourPawns|theirPawns)); b<<=8);
|
{
|
||||||
|
for (b = pos.pawn_attacks(us, s); !(b & (ourPawns | theirPawns)); b <<= 8);
|
||||||
backward = (b | (b << 8)) & theirPawns;
|
backward = (b | (b << 8)) & theirPawns;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
for(b=pos.pawn_attacks(us, s); !(b&(ourPawns|theirPawns)); b>>=8);
|
{
|
||||||
|
for (b = pos.pawn_attacks(us, s); !(b & (ourPawns | theirPawns)); b >>= 8);
|
||||||
backward = (b | (b >> 8)) & theirPawns;
|
backward = (b | (b >> 8)) & theirPawns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test for candidate passed pawn.
|
// Test for candidate passed pawn
|
||||||
candidate =
|
candidate = !passed
|
||||||
(!passed && pos.file_is_half_open(them, f) &&
|
&& pos.file_is_half_open(them, f)
|
||||||
count_1s_max_15(neighboring_files_bb(f)
|
&& ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns)
|
||||||
& (in_front_bb(them, r) | rank_bb(r))
|
- count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns)
|
||||||
& ourPawns)
|
|
||||||
- count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r)
|
|
||||||
& theirPawns)
|
|
||||||
>= 0);
|
>= 0);
|
||||||
|
|
||||||
// In order to prevent doubled passed pawns from receiving a too big
|
// In order to prevent doubled passed pawns from receiving a too big
|
||||||
// bonus, only the frontmost passed pawn on each file is considered as
|
// bonus, only the frontmost passed pawn on each file is considered as
|
||||||
// a true passed pawn.
|
// a true passed pawn.
|
||||||
if(passed && (ourPawns & squares_in_front_of(us, s))) {
|
if (passed && (ourPawns & squares_in_front_of(us, s)))
|
||||||
|
{
|
||||||
// candidate = true;
|
// candidate = true;
|
||||||
passed = false;
|
passed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Score this pawn:
|
// Score this pawn
|
||||||
Value mv = Value(0), ev = Value(0);
|
Value mv = Value(0), ev = Value(0);
|
||||||
if(isolated) {
|
if (isolated)
|
||||||
|
{
|
||||||
mv -= IsolatedPawnMidgamePenalty[f];
|
mv -= IsolatedPawnMidgamePenalty[f];
|
||||||
ev -= IsolatedPawnEndgamePenalty[f];
|
ev -= IsolatedPawnEndgamePenalty[f];
|
||||||
if(pos.file_is_half_open(them, f)) {
|
if (pos.file_is_half_open(them, f))
|
||||||
|
{
|
||||||
mv -= IsolatedPawnMidgamePenalty[f] / 2;
|
mv -= IsolatedPawnMidgamePenalty[f] / 2;
|
||||||
ev -= IsolatedPawnEndgamePenalty[f] / 2;
|
ev -= IsolatedPawnEndgamePenalty[f] / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(doubled) {
|
if (doubled)
|
||||||
|
{
|
||||||
mv -= DoubledPawnMidgamePenalty[f];
|
mv -= DoubledPawnMidgamePenalty[f];
|
||||||
ev -= DoubledPawnEndgamePenalty[f];
|
ev -= DoubledPawnEndgamePenalty[f];
|
||||||
}
|
}
|
||||||
if(backward) {
|
if (backward)
|
||||||
|
{
|
||||||
mv -= BackwardPawnMidgamePenalty[f];
|
mv -= BackwardPawnMidgamePenalty[f];
|
||||||
ev -= BackwardPawnEndgamePenalty[f];
|
ev -= BackwardPawnEndgamePenalty[f];
|
||||||
if(pos.file_is_half_open(them, f)) {
|
if (pos.file_is_half_open(them, f))
|
||||||
|
{
|
||||||
mv -= BackwardPawnMidgamePenalty[f] / 2;
|
mv -= BackwardPawnMidgamePenalty[f] / 2;
|
||||||
ev -= BackwardPawnEndgamePenalty[f] / 2;
|
ev -= BackwardPawnEndgamePenalty[f] / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(chain) {
|
if (chain)
|
||||||
|
{
|
||||||
mv += ChainMidgameBonus[f];
|
mv += ChainMidgameBonus[f];
|
||||||
ev += ChainEndgameBonus[f];
|
ev += ChainEndgameBonus[f];
|
||||||
}
|
}
|
||||||
if(candidate) {
|
if (candidate)
|
||||||
mv += CandidateMidgameBonus[pawn_rank(us, s)];
|
{
|
||||||
ev += CandidateEndgameBonus[pawn_rank(us, s)];
|
mv += CandidateMidgameBonus[relative_rank(us, s)];
|
||||||
|
ev += CandidateEndgameBonus[relative_rank(us, s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
mgValue[us] += mv;
|
mgValue[us] += mv;
|
||||||
egValue[us] += ev;
|
egValue[us] += ev;
|
||||||
|
|
||||||
// If the pawn is passed, set the square of the pawn in the passedPawns
|
// If the pawn is passed, set the square of the pawn in the passedPawns
|
||||||
// bitboard:
|
// bitboard
|
||||||
if(passed)
|
if (passed)
|
||||||
set_bit(&(pi->passedPawns), s);
|
set_bit(&(pi->passedPawns), s);
|
||||||
}
|
} // while(pawns)
|
||||||
}
|
} // for(colors)
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-16
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -24,8 +25,8 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include "position.h"
|
#include "bitboard.h"
|
||||||
|
#include "value.h"
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Types
|
//// Types
|
||||||
@@ -37,6 +38,7 @@
|
|||||||
/// 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 {
|
||||||
|
|
||||||
@@ -48,9 +50,9 @@ public:
|
|||||||
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 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;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clear();
|
void clear();
|
||||||
@@ -58,7 +60,7 @@ private:
|
|||||||
Key key;
|
Key key;
|
||||||
Bitboard passedPawns;
|
Bitboard passedPawns;
|
||||||
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];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,11 +76,11 @@ public:
|
|||||||
PawnInfoTable(unsigned numOfEntries);
|
PawnInfoTable(unsigned numOfEntries);
|
||||||
~PawnInfoTable();
|
~PawnInfoTable();
|
||||||
void clear();
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -106,21 +108,22 @@ 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 void PawnInfo::clear() {
|
||||||
mgValue = egValue = 0;
|
|
||||||
passedPawns = EmptyBoardBB;
|
passedPawns = EmptyBoardBB;
|
||||||
|
mgValue = egValue = 0;
|
||||||
ksStormValue[WHITE] = ksStormValue[BLACK] = 0;
|
ksStormValue[WHITE] = ksStormValue[BLACK] = 0;
|
||||||
qsStormValue[WHITE] = qsStormValue[BLACK] = 0;
|
qsStormValue[WHITE] = qsStormValue[BLACK] = 0;
|
||||||
halfOpenFiles[WHITE] = halfOpenFiles[BLACK] = 0xFF;
|
halfOpenFiles[WHITE] = halfOpenFiles[BLACK] = 0xFF;
|
||||||
|
|||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
Glaurung, a UCI chess playing engine.
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
|
||||||
|
|
||||||
Glaurung 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.
|
|
||||||
|
|
||||||
Glaurung 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(PHASE_H_INCLUDED)
|
|
||||||
#define PHASE_H_INCLUDED
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Types
|
|
||||||
////
|
|
||||||
|
|
||||||
enum Phase {
|
|
||||||
PHASE_ENDGAME = 0,
|
|
||||||
PHASE_MIDGAME = 128
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(PHASE_H_INCLUDED)
|
|
||||||
+16
-61
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -21,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 = false) {
|
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-41
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -25,7 +26,6 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "misc.h"
|
|
||||||
#include "square.h"
|
#include "square.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -46,15 +46,12 @@ 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];
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -82,40 +79,24 @@ 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 int piece_is_slider(PieceType pt) {
|
||||||
return SlidingArray[int(pt)];
|
return SlidingArray[int(pt)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline SquareDelta pawn_push(Color c) {
|
inline SquareDelta pawn_push(Color c) {
|
||||||
return PawnPush[c];
|
return (c == WHITE ? DELTA_N : DELTA_S);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool piece_type_is_ok(PieceType pc) {
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -123,10 +104,8 @@ inline SquareDelta pawn_push(Color c) {
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern char piece_type_to_char(PieceType pt, bool upcase);
|
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)
|
||||||
|
|||||||
+1104
-1127
File diff suppressed because it is too large
Load Diff
+211
-226
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -20,6 +21,18 @@
|
|||||||
#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
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
|
// Forcing value to bool 'true' or 'false' (performance warning)
|
||||||
|
#pragma warning(disable: 4800)
|
||||||
|
|
||||||
|
// Conditional expression is constant
|
||||||
|
#pragma warning(disable: 4127)
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
@@ -29,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"
|
||||||
|
|
||||||
@@ -52,31 +64,39 @@ 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, BLACK_OO = 2,
|
WHITE_OO = 1,
|
||||||
WHITE_OOO = 4, BLACK_OOO = 8,
|
BLACK_OO = 2,
|
||||||
|
WHITE_OOO = 4,
|
||||||
|
BLACK_OOO = 8,
|
||||||
ALL_CASTLES = 15
|
ALL_CASTLES = 15
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Game phase
|
||||||
|
enum Phase {
|
||||||
|
PHASE_ENDGAME = 0,
|
||||||
|
PHASE_MIDGAME = 128
|
||||||
|
};
|
||||||
|
|
||||||
/// The UndoInfo struct stores information we need to restore a Position
|
|
||||||
|
/// The StateInfo struct stores information we need to restore a Position
|
||||||
/// object to its previous state when we retract a move. Whenever a move
|
/// object to its previous state when we retract a move. Whenever a move
|
||||||
/// is made on the board (by calling Position::do_move), an UndoInfo object
|
/// is made on the board (by calling Position::do_move), an StateInfo object
|
||||||
/// must be passed as a parameter. When the move is unmade (by calling
|
/// must be passed as a parameter.
|
||||||
/// Position::undo_move), the same UndoInfo object must be passed again.
|
|
||||||
|
|
||||||
struct UndoInfo {
|
struct StateInfo {
|
||||||
int castleRights;
|
|
||||||
Square epSquare;
|
|
||||||
Bitboard checkersBB;
|
|
||||||
Key key, pawnKey, materialKey;
|
Key key, pawnKey, materialKey;
|
||||||
int rule50;
|
int castleRights, rule50;
|
||||||
Move lastMove;
|
Square epSquare;
|
||||||
PieceType capture;
|
|
||||||
Value mgValue, egValue;
|
Value mgValue, egValue;
|
||||||
|
|
||||||
|
PieceType capture;
|
||||||
|
Bitboard checkersBB;
|
||||||
|
Move lastMove;
|
||||||
|
StateInfo* previous;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -106,17 +126,18 @@ struct UndoInfo {
|
|||||||
class Position {
|
class Position {
|
||||||
|
|
||||||
friend class MaterialInfo;
|
friend class MaterialInfo;
|
||||||
|
friend class EndgameFunctions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 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() const;
|
void print(Move m = MOVE_NONE) const;
|
||||||
|
|
||||||
// Copying
|
// Copying
|
||||||
void copy(const Position &pos);
|
void copy(const Position &pos);
|
||||||
@@ -161,19 +182,14 @@ public:
|
|||||||
|
|
||||||
// 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;
|
||||||
int pawn_count(Color c) const;
|
|
||||||
int knight_count(Color c) const;
|
|
||||||
int bishop_count(Color c) const;
|
|
||||||
int rook_count(Color c) const;
|
|
||||||
int queen_count(Color c) const;
|
|
||||||
|
|
||||||
// The en passant square:
|
// The en passant square
|
||||||
Square ep_square() const;
|
Square ep_square() const;
|
||||||
|
|
||||||
// Current king position for each color
|
// Current king position for each color
|
||||||
Square king_square(Color c) const;
|
Square king_square(Color c) const;
|
||||||
|
|
||||||
// Castling rights.
|
// Castling rights
|
||||||
bool can_castle_kingside(Color c) const;
|
bool can_castle_kingside(Color c) const;
|
||||||
bool can_castle_queenside(Color c) const;
|
bool can_castle_queenside(Color c) const;
|
||||||
bool can_castle(Color c) const;
|
bool can_castle(Color c) const;
|
||||||
@@ -184,49 +200,40 @@ public:
|
|||||||
Bitboard sliding_attacks(Square s, Direction d) const;
|
Bitboard sliding_attacks(Square s, Direction d) const;
|
||||||
Bitboard ray_attacks(Square s, SignedDirection d) const;
|
Bitboard ray_attacks(Square s, SignedDirection d) const;
|
||||||
Bitboard pawn_attacks(Color c, Square s) const;
|
Bitboard pawn_attacks(Color c, Square s) const;
|
||||||
Bitboard white_pawn_attacks(Square s) const;
|
|
||||||
Bitboard black_pawn_attacks(Square s) const;
|
template<PieceType>
|
||||||
Bitboard knight_attacks(Square s) const;
|
Bitboard piece_attacks(Square s) const;
|
||||||
Bitboard bishop_attacks(Square s) const;
|
|
||||||
Bitboard rook_attacks(Square s) const;
|
|
||||||
Bitboard queen_attacks(Square s) const;
|
|
||||||
Bitboard king_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, Bitboard& p) const;
|
||||||
Bitboard pinned_pieces(Color c) const;
|
Bitboard pinned_pieces(Color c) const;
|
||||||
|
|
||||||
// Checking pieces
|
// Checking pieces
|
||||||
Bitboard checkers() const;
|
Bitboard checkers() 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;
|
||||||
Square pawn_list(Color c, int index) const;
|
|
||||||
Square knight_list(Color c, int index) const;
|
|
||||||
Square bishop_list(Color c, int index) const;
|
|
||||||
Square rook_list(Color c, int index) const;
|
|
||||||
Square queen_list(Color c, int index) const;
|
|
||||||
|
|
||||||
// Attack information for a given square
|
// Attack information for a given square
|
||||||
bool square_is_attacked(Square s, Color c) const;
|
bool square_is_attacked(Square s, Color c) const;
|
||||||
Bitboard attacks_to(Square s) const;
|
Bitboard attacks_to(Square s) const;
|
||||||
Bitboard attacks_to(Square s, Color c) const;
|
Bitboard attacks_to(Square s, Color c) const;
|
||||||
bool is_check() const;
|
bool is_check() const;
|
||||||
bool piece_attacks_square(Square f, Square t) const;
|
bool pawn_attacks_square(Color c, Square f, Square t) const;
|
||||||
bool white_pawn_attacks_square(Square f, Square t) const;
|
|
||||||
bool black_pawn_attacks_square(Square f, Square t) const;
|
template<PieceType>
|
||||||
bool knight_attacks_square(Square f, Square t) const;
|
Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
|
||||||
bool bishop_attacks_square(Square f, Square t) const;
|
|
||||||
bool rook_attacks_square(Square f, Square t) const;
|
bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time
|
||||||
bool queen_attacks_square(Square f, Square t) const;
|
|
||||||
bool king_attacks_square(Square f, Square t) const;
|
|
||||||
|
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool move_is_legal(Move m) const;
|
bool pl_move_is_legal(Move m) const;
|
||||||
bool move_is_legal(Move m, Bitboard pinned) const;
|
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
||||||
bool move_is_check(Move m) const;
|
bool move_is_check(Move m) const;
|
||||||
bool move_is_check(Move m, Bitboard dcCandidates) const;
|
bool move_is_check(Move m, 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_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_was_passed_pawn_push(Move m) const;
|
||||||
@@ -245,17 +252,17 @@ public:
|
|||||||
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 setStartState(const StateInfo& st);
|
||||||
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;
|
||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key get_key() const;
|
Key get_key() const;
|
||||||
@@ -267,9 +274,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;
|
||||||
|
|
||||||
// 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,13 +294,14 @@ public:
|
|||||||
void reset_game_ply();
|
void reset_game_ply();
|
||||||
|
|
||||||
// Position consistency check, for debugging
|
// Position consistency check, for debugging
|
||||||
bool is_ok() 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);
|
||||||
@@ -300,29 +309,37 @@ 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(PieceType capture, Color them, Square to);
|
||||||
void do_castle_move(Move m);
|
void do_castle_move(Move m);
|
||||||
void do_promotion_move(Move m, UndoInfo &u);
|
void do_promotion_move(Move m);
|
||||||
void do_ep_move(Move m);
|
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_promotion_move(Move m);
|
||||||
void undo_ep_move(Move m);
|
void undo_ep_move(Move m);
|
||||||
void find_checkers();
|
void find_checkers();
|
||||||
|
|
||||||
|
template<PieceType Piece>
|
||||||
|
void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
|
||||||
|
|
||||||
|
template<bool FindPinned>
|
||||||
|
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;
|
||||||
Key compute_pawn_key() const;
|
Key compute_pawn_key() const;
|
||||||
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;
|
enum GamePhase {
|
||||||
Value eg_pst(Color c, PieceType pt, Square s) const;
|
MidGame,
|
||||||
Value compute_mg_value() const;
|
EndGame
|
||||||
Value compute_eg_value() const;
|
};
|
||||||
|
template<GamePhase> Value pst(Color c, PieceType pt, Square s) const;
|
||||||
|
template<GamePhase> Value compute_value() const;
|
||||||
Value compute_non_pawn_material(Color c) const;
|
Value compute_non_pawn_material(Color c) const;
|
||||||
|
|
||||||
// Bitboards
|
// Bitboards
|
||||||
Bitboard byColorBB[2], byTypeBB[8];
|
Bitboard byColorBB[2], byTypeBB[8];
|
||||||
Bitboard checkersBB;
|
|
||||||
|
|
||||||
// Board
|
// Board
|
||||||
Piece board[64];
|
Piece board[64];
|
||||||
@@ -335,16 +352,14 @@ private:
|
|||||||
int index[64];
|
int index[64];
|
||||||
|
|
||||||
// Other info
|
// Other info
|
||||||
Color sideToMove;
|
|
||||||
int castleRights;
|
|
||||||
File initialKFile, initialKRFile, initialQRFile;
|
|
||||||
Square epSquare;
|
|
||||||
Square kingSquare[2];
|
Square kingSquare[2];
|
||||||
Move lastMove;
|
Color sideToMove;
|
||||||
Key key, pawnKey, materialKey, history[MaxGameLength];
|
int gamePly;
|
||||||
int rule50, gamePly;
|
Key history[MaxGameLength];
|
||||||
Value mgValue, egValue;
|
|
||||||
Value npMaterial[2];
|
Value npMaterial[2];
|
||||||
|
File initialKFile, initialKRFile, initialQRFile;
|
||||||
|
StateInfo startState;
|
||||||
|
StateInfo* st;
|
||||||
|
|
||||||
// Static variables
|
// Static variables
|
||||||
static int castleRightsMask[64];
|
static int castleRightsMask[64];
|
||||||
@@ -367,27 +382,27 @@ inline Piece Position::piece_on(Square s) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Color Position::color_of_piece_on(Square s) const {
|
inline Color Position::color_of_piece_on(Square s) const {
|
||||||
return color_of_piece(this->piece_on(s));
|
return color_of_piece(piece_on(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType Position::type_of_piece_on(Square s) const {
|
inline PieceType Position::type_of_piece_on(Square s) const {
|
||||||
return type_of_piece(this->piece_on(s));
|
return type_of_piece(piece_on(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::square_is_empty(Square s) const {
|
inline bool Position::square_is_empty(Square s) const {
|
||||||
return this->piece_on(s) == EMPTY;
|
return piece_on(s) == EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::square_is_occupied(Square s) const {
|
inline bool Position::square_is_occupied(Square s) const {
|
||||||
return !this->square_is_empty(s);
|
return !square_is_empty(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::midgame_value_of_piece_on(Square s) const {
|
inline Value Position::midgame_value_of_piece_on(Square s) const {
|
||||||
return piece_value_midgame(this->piece_on(s));
|
return piece_value_midgame(piece_on(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::endgame_value_of_piece_on(Square s) const {
|
inline Value Position::endgame_value_of_piece_on(Square s) const {
|
||||||
return piece_value_endgame(this->piece_on(s));
|
return piece_value_endgame(piece_on(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color Position::side_to_move() const {
|
inline Color Position::side_to_move() const {
|
||||||
@@ -399,7 +414,7 @@ inline Bitboard Position::occupied_squares() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::empty_squares() const {
|
inline Bitboard Position::empty_squares() const {
|
||||||
return ~(this->occupied_squares());
|
return ~(occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces_of_color(Color c) const {
|
inline Bitboard Position::pieces_of_color(Color c) const {
|
||||||
@@ -410,133 +425,92 @@ inline Bitboard Position::pieces_of_type(PieceType pt) const {
|
|||||||
return byTypeBB[pt];
|
return byTypeBB[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces_of_color_and_type(Color c, PieceType pt)
|
inline Bitboard Position::pieces_of_color_and_type(Color c, PieceType pt) const {
|
||||||
const {
|
return pieces_of_color(c) & pieces_of_type(pt);
|
||||||
return this->pieces_of_color(c) & this->pieces_of_type(pt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pawns() const {
|
inline Bitboard Position::pawns() const {
|
||||||
return this->pieces_of_type(PAWN);
|
return pieces_of_type(PAWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::knights() const {
|
inline Bitboard Position::knights() const {
|
||||||
return this->pieces_of_type(KNIGHT);
|
return pieces_of_type(KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::bishops() const {
|
inline Bitboard Position::bishops() const {
|
||||||
return this->pieces_of_type(BISHOP);
|
return pieces_of_type(BISHOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::rooks() const {
|
inline Bitboard Position::rooks() const {
|
||||||
return this->pieces_of_type(ROOK);
|
return pieces_of_type(ROOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::queens() const {
|
inline Bitboard Position::queens() const {
|
||||||
return this->pieces_of_type(QUEEN);
|
return pieces_of_type(QUEEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::kings() const {
|
inline Bitboard Position::kings() const {
|
||||||
return this->pieces_of_type(KING);
|
return pieces_of_type(KING);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::rooks_and_queens() const {
|
inline Bitboard Position::rooks_and_queens() const {
|
||||||
return this->rooks() | this->queens();
|
return rooks() | queens();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::bishops_and_queens() const {
|
inline Bitboard Position::bishops_and_queens() const {
|
||||||
return this->bishops() | this->queens();
|
return bishops() | queens();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::sliders() const {
|
inline Bitboard Position::sliders() const {
|
||||||
return this->bishops() | this->queens() | this->rooks();
|
return bishops() | queens() | rooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pawns(Color c) const {
|
inline Bitboard Position::pawns(Color c) const {
|
||||||
return this->pieces_of_color_and_type(c, PAWN);
|
return pieces_of_color_and_type(c, PAWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::knights(Color c) const {
|
inline Bitboard Position::knights(Color c) const {
|
||||||
return this->pieces_of_color_and_type(c, KNIGHT);
|
return pieces_of_color_and_type(c, KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::bishops(Color c) const {
|
inline Bitboard Position::bishops(Color c) const {
|
||||||
return this->pieces_of_color_and_type(c, BISHOP);
|
return pieces_of_color_and_type(c, BISHOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::rooks(Color c) const {
|
inline Bitboard Position::rooks(Color c) const {
|
||||||
return this->pieces_of_color_and_type(c, ROOK);
|
return pieces_of_color_and_type(c, ROOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::queens(Color c) const {
|
inline Bitboard Position::queens(Color c) const {
|
||||||
return this->pieces_of_color_and_type(c, QUEEN);
|
return pieces_of_color_and_type(c, QUEEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::kings(Color c) const {
|
inline Bitboard Position::kings(Color c) const {
|
||||||
return this->pieces_of_color_and_type(c, KING);
|
return pieces_of_color_and_type(c, KING);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::rooks_and_queens(Color c) const {
|
inline Bitboard Position::rooks_and_queens(Color c) const {
|
||||||
return this->rooks_and_queens() & this->pieces_of_color(c);
|
return rooks_and_queens() & pieces_of_color(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::bishops_and_queens(Color c) const {
|
inline Bitboard Position::bishops_and_queens(Color c) const {
|
||||||
return this->bishops_and_queens() & this->pieces_of_color(c);
|
return bishops_and_queens() & pieces_of_color(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::sliders_of_color(Color c) const {
|
inline Bitboard Position::sliders_of_color(Color c) const {
|
||||||
return this->sliders() & this->pieces_of_color(c);
|
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 {
|
||||||
return pieceCount[c][pt];
|
return pieceCount[c][pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::pawn_count(Color c) const {
|
|
||||||
return this->piece_count(c, PAWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Position::knight_count(Color c) const {
|
|
||||||
return this->piece_count(c, KNIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Position::bishop_count(Color c) const {
|
|
||||||
return this->piece_count(c, BISHOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Position::rook_count(Color c) const {
|
|
||||||
return this->piece_count(c, ROOK);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Position::queen_count(Color c) const {
|
|
||||||
return this->piece_count(c, QUEEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square Position::piece_list(Color c, PieceType pt, int index) const {
|
inline Square Position::piece_list(Color c, PieceType pt, int index) const {
|
||||||
return pieceList[c][pt][index];
|
return pieceList[c][pt][index];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::pawn_list(Color c, int index) const {
|
|
||||||
return this->piece_list(c, PAWN, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square Position::knight_list(Color c, int index) const {
|
|
||||||
return this->piece_list(c, KNIGHT, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square Position::bishop_list(Color c, int index) const {
|
|
||||||
return this->piece_list(c, BISHOP, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square Position::rook_list(Color c, int index) const {
|
|
||||||
return this->piece_list(c, ROOK, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square Position::queen_list(Color c, int index) const {
|
|
||||||
return this->piece_list(c, QUEEN, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
||||||
@@ -544,11 +518,11 @@ inline Square Position::king_square(Color c) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@@ -564,123 +538,119 @@ inline Square Position::initial_qr_square(Color c) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pawn_attacks(Color c, Square s) const {
|
inline Bitboard Position::pawn_attacks(Color c, Square s) const {
|
||||||
return StepAttackBB[pawn_of_color(c)][s];
|
return StepAttackBB[piece_of_color_and_type(c, PAWN)][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::white_pawn_attacks(Square s) const {
|
template<>
|
||||||
return this->pawn_attacks(WHITE, s);
|
inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
|
||||||
|
return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::black_pawn_attacks(Square s) const {
|
template<>
|
||||||
return this->pawn_attacks(BLACK, s);
|
inline Bitboard Position::piece_attacks<KNIGHT>(Square s) const {
|
||||||
}
|
|
||||||
|
|
||||||
inline Bitboard Position::knight_attacks(Square s) const {
|
|
||||||
return StepAttackBB[KNIGHT][s];
|
return StepAttackBB[KNIGHT][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::rook_attacks(Square s) const {
|
template<>
|
||||||
return rook_attacks_bb(s, this->occupied_squares());
|
inline Bitboard Position::piece_attacks<BISHOP>(Square s) const {
|
||||||
|
return bishop_attacks_bb(s, occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::bishop_attacks(Square s) const {
|
template<>
|
||||||
return bishop_attacks_bb(s, this->occupied_squares());
|
inline Bitboard Position::piece_attacks<ROOK>(Square s) const {
|
||||||
|
return rook_attacks_bb(s, occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::queen_attacks(Square s) const {
|
template<>
|
||||||
return this->rook_attacks(s) | this->bishop_attacks(s);
|
inline Bitboard Position::piece_attacks<QUEEN>(Square s) const {
|
||||||
|
return piece_attacks<ROOK>(s) | piece_attacks<BISHOP>(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::king_attacks(Square s) const {
|
template<>
|
||||||
|
inline Bitboard Position::piece_attacks<KING>(Square s) const {
|
||||||
return StepAttackBB[KING][s];
|
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 this->checkers() != EmptyBoardBB;
|
return st->checkersBB != EmptyBoardBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::white_pawn_attacks_square(Square f, Square t) const {
|
inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const {
|
||||||
return bit_is_set(this->white_pawn_attacks(f), t);
|
return bit_is_set(pawn_attacks(c, f), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::black_pawn_attacks_square(Square f, Square t) const {
|
template<PieceType Piece>
|
||||||
return bit_is_set(this->black_pawn_attacks(f), t);
|
Bitboard Position::piece_attacks_square(Square f, Square t) const {
|
||||||
|
return bit_is_set(piece_attacks<Piece>(f), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::knight_attacks_square(Square f, Square t) const {
|
inline Bitboard Position::attacks_to(Square s, Color c) const {
|
||||||
return bit_is_set(this->knight_attacks(f), t);
|
|
||||||
|
return attacks_to(s) & pieces_of_color(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::bishop_attacks_square(Square f, Square t) const {
|
inline bool Position::square_is_attacked(Square s, Color c) const {
|
||||||
return bit_is_set(this->bishop_attacks(f), t);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::rook_attacks_square(Square f, Square t) const {
|
return attacks_to(s, c) != EmptyBoardBB;
|
||||||
return bit_is_set(this->rook_attacks(f), t);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::queen_attacks_square(Square f, Square t) const {
|
|
||||||
return bit_is_set(this->queen_attacks(f), t);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::king_attacks_square(Square f, Square t) const {
|
|
||||||
return bit_is_set(this->king_attacks(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 !(this->pawns(opposite_color(c)) & passed_pawn_mask(c, s));
|
return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_isolated(Color c, Square s) const {
|
inline bool Position::pawn_is_isolated(Color c, Square s) const {
|
||||||
return !(this->pawns(c) & neighboring_files_bb(s));
|
return !(pawns(c) & neighboring_files_bb(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_doubled(Color c, Square s) const {
|
inline bool Position::pawn_is_doubled(Color c, Square s) const {
|
||||||
return this->pawns(c) & squares_behind(c, s);
|
return pawns(c) & squares_behind(c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::file_is_open(File f) const {
|
inline bool Position::file_is_open(File f) const {
|
||||||
return !(this->pawns() & file_bb(f));
|
return !(pawns() & file_bb(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::file_is_half_open(Color c, File f) const {
|
inline bool Position::file_is_half_open(Color c, File f) const {
|
||||||
return !(this->pawns(c) & file_bb(f));
|
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 !(this->pawns(c) & outpost_mask(opposite_color(c), s));
|
return !(pawns(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 Phase>
|
||||||
return MgPieceSquareTable[piece_of_color_and_type(c, pt)][s];
|
inline Value Position::pst(Color c, PieceType pt, Square s) const {
|
||||||
|
return (Phase == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
|
||||||
|
: EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::eg_pst(Color c, PieceType pt, Square s) const {
|
inline Value Position::mg_pst_delta(Move m) const {
|
||||||
return EgPieceSquareTable[piece_of_color_and_type(c, pt)][s];
|
return MgPieceSquareTable[piece_on(move_from(m))][move_to(m)]
|
||||||
|
-MgPieceSquareTable[piece_on(move_from(m))][move_from(m)];
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@@ -689,16 +659,13 @@ inline Value Position::non_pawn_material(Color c) const {
|
|||||||
|
|
||||||
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(15713);
|
||||||
// the division at the end of the function a bit faster.
|
static const Value EndgameLimit = Value(4428);
|
||||||
|
|
||||||
static const Value MidgameLimit =
|
Value npm = non_pawn_material(WHITE) + non_pawn_material(BLACK);
|
||||||
2*QueenValueMidgame+2*RookValueMidgame+6*BishopValueMidgame+Value(325);
|
|
||||||
static const Value EndgameLimit = 4*RookValueMidgame-Value(325);
|
|
||||||
Value npm = this->non_pawn_material(WHITE) + this->non_pawn_material(BLACK);
|
|
||||||
|
|
||||||
if(npm >= MidgameLimit)
|
if (npm >= MidgameLimit)
|
||||||
return PHASE_MIDGAME;
|
return PHASE_MIDGAME;
|
||||||
else if(npm <= EndgameLimit)
|
else if(npm <= EndgameLimit)
|
||||||
return PHASE_ENDGAME;
|
return PHASE_ENDGAME;
|
||||||
@@ -706,41 +673,59 @@ 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)) == piece_of_color_and_type(c, PAWN)
|
||||||
|
&& relative_rank(c, move_to(m)) > RANK_4;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool Position::move_is_pawn_push_to_7th(Move m) const {
|
inline bool Position::move_is_pawn_push_to_7th(Move m) const {
|
||||||
Color c = this->side_to_move();
|
|
||||||
return
|
Color c = side_to_move();
|
||||||
this->piece_on(move_from(m)) == pawn_of_color(c) &&
|
return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN)
|
||||||
pawn_rank(c, move_to(m)) == RANK_7;
|
&& 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 = this->side_to_move();
|
|
||||||
return
|
Color c = side_to_move();
|
||||||
this->piece_on(move_from(m)) == pawn_of_color(c) &&
|
return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN)
|
||||||
this->pawn_is_passed(c, move_to(m));
|
&& pawn_is_passed(c, move_to(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::move_was_passed_pawn_push(Move m) const {
|
inline bool Position::move_was_passed_pawn_push(Move m) const {
|
||||||
Color c = opposite_color(this->side_to_move());
|
|
||||||
return
|
Color c = opposite_color(side_to_move());
|
||||||
this->piece_on(move_to(m)) == pawn_of_color(c) &&
|
return piece_on(move_to(m)) == piece_of_color_and_type(c, PAWN)
|
||||||
this->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 {
|
||||||
return
|
|
||||||
this->bishop_count(WHITE) == 1 && this->bishop_count(BLACK) == 1 &&
|
return piece_count(WHITE, BISHOP) == 1
|
||||||
square_color(this->bishop_list(WHITE, 0)) !=
|
&& piece_count(BLACK, BISHOP) == 1
|
||||||
square_color(this->bishop_list(BLACK, 0));
|
&& square_color(piece_list(WHITE, BISHOP, 0)) != square_color(piece_list(BLACK, BISHOP, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::has_pawn_on_7th(Color c) const {
|
inline bool Position::has_pawn_on_7th(Color c) const {
|
||||||
return this->pawns(c) & relative_rank_bb(c, RANK_7);
|
|
||||||
|
return pawns(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))
|
||||||
|
&& (color_of_piece_on(move_to(m)) != color_of_piece_on(move_from(m)))
|
||||||
|
)
|
||||||
|
|| move_is_ep(m);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(POSITION_H_INCLUDED)
|
#endif // !defined(POSITION_H_INCLUDED)
|
||||||
|
|||||||
+118
-94
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -24,66 +25,78 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include "position.h"
|
#include "value.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Variables
|
//// Variables
|
||||||
////
|
////
|
||||||
|
|
||||||
|
static const Value MP = PawnValueMidgame;
|
||||||
|
static const Value MK = KnightValueMidgame;
|
||||||
|
static const Value MB = BishopValueMidgame;
|
||||||
|
static const Value MR = RookValueMidgame;
|
||||||
|
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
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
166, 192, 204, 216, 216, 204, 192, 166,
|
MP-38, MP-12, MP- 0, MP+12, MP+12, MP- 0, MP-12, MP-38,
|
||||||
166, 192, 210, 242, 242, 210, 192, 166,
|
MP-38, MP-12, MP+ 6, MP+38, MP+38, MP+ 6, MP-12, MP-38,
|
||||||
166, 192, 220, 268, 268, 220, 192, 166,
|
MP-38, MP-12, MP+16, MP+64, MP+64, MP+16, MP-12, MP-38,
|
||||||
166, 192, 220, 242, 242, 220, 192, 166,
|
MP-38, MP-12, MP+16, MP+38, MP+38, MP+16, MP-12, MP-38,
|
||||||
166, 192, 210, 216, 216, 210, 192, 166,
|
MP-38, MP-12, MP+ 6, MP+12, MP+12, MP+ 6, MP-12, MP-38,
|
||||||
166, 192, 204, 216, 216, 204, 192, 166,
|
MP-38, MP-12, MP- 0, MP+12, MP+12, MP- 0, MP-12, MP-38,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
},
|
},
|
||||||
{ // Knight
|
{// Knight
|
||||||
704, 730, 756, 768, 768, 756, 730, 704,
|
// A B C D E F G H
|
||||||
743, 768, 794, 807, 807, 794, 768, 743,
|
MK-128, MK-102, MK-76, MK-64, MK-64, MK-76, MK-102, MK-128,
|
||||||
781, 807, 832, 844, 844, 832, 807, 781,
|
MK- 89, MK- 64, MK-38, MK-25, MK-25, MK-38, MK- 64, MK- 89,
|
||||||
807, 832, 857, 870, 870, 857, 832, 807,
|
MK- 51, MK- 25, MK- 0, MK+12, MK+12, MK- 0, MK- 25, MK- 51,
|
||||||
820, 844, 870, 883, 883, 870, 844, 820,
|
MK- 25, MK- 0, MK+25, MK+38, MK+38, MK+25, MK- 0, MK- 25,
|
||||||
820, 844, 870, 883, 883, 870, 844, 820,
|
MK- 12, MK+ 12, MK+38, MK+51, MK+51, MK+38, MK+ 12, MK- 12,
|
||||||
781, 807, 832, 844, 844, 832, 807, 781,
|
MK- 12, MK+ 12, MK+38, MK+51, MK+51, MK+38, MK+ 12, MK- 12,
|
||||||
650, 768, 794, 807, 807, 794, 768, 650
|
MK- 51, MK- 25, MK- 0, MK+12, MK+12, MK- 0, MK- 25, MK- 51,
|
||||||
|
MK-182, MK- 64, MK-38, MK-25, MK-25, MK-38, MK- 64, MK-182
|
||||||
},
|
},
|
||||||
{ // Bishop
|
{// Bishop
|
||||||
786, 786, 792, 797, 797, 792, 786, 786,
|
// A B C D E F G H
|
||||||
812, 832, 827, 832, 832, 827, 832, 812,
|
MB-46, MB-46, MB-40, MB-35, MB-35, MB-40, MB-46, MB-46,
|
||||||
817, 827, 842, 837, 837, 842, 827, 817,
|
MB-20, MB- 0, MB- 5, MB- 0, MB- 0, MB- 5, MB- 0, MB-20,
|
||||||
822, 832, 837, 852, 852, 837, 832, 822,
|
MB-15, MB- 5, MB+10, MB+ 5, MB+ 5, MB+10, MB- 5, MB-15,
|
||||||
822, 832, 837, 852, 852, 837, 832, 822,
|
MB-10, MB- 0, MB+ 5, MB+20, MB+20, MB+ 5, MB- 0, MB-10,
|
||||||
817, 827, 842, 837, 837, 842, 827, 817,
|
MB-10, MB- 0, MB+ 5, MB+20, MB+20, MB+ 5, MB- 0, MB-10,
|
||||||
812, 832, 827, 832, 832, 827, 832, 812,
|
MB-15, MB- 5, MB+10, MB+ 5, MB+ 5, MB+10, MB- 5, MB-15,
|
||||||
812, 812, 817, 822, 822, 817, 812, 812
|
MB-20, MB- 0, MB- 5, MB- 0, MB- 0, MB- 5, MB- 0, MB-20,
|
||||||
|
MB-20, MB-20, MB-15, MB-10, MB-10, MB-15, MB-20, MB-20
|
||||||
},
|
},
|
||||||
{ // Rook
|
{// Rook
|
||||||
1267, 1275, 1282, 1289, 1289, 1282, 1275, 1267,
|
// A B C D E F G H
|
||||||
1267, 1275, 1282, 1289, 1289, 1282, 1275, 1267,
|
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
||||||
1267, 1275, 1282, 1289, 1289, 1282, 1275, 1267,
|
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
||||||
1267, 1275, 1282, 1289, 1289, 1282, 1275, 1267,
|
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
||||||
1267, 1275, 1282, 1289, 1289, 1282, 1275, 1267,
|
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
||||||
1267, 1275, 1282, 1289, 1289, 1282, 1275, 1267,
|
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
||||||
1267, 1275, 1282, 1289, 1289, 1282, 1275, 1267,
|
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
||||||
1267, 1275, 1282, 1289, 1289, 1282, 1275, 1267
|
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18,
|
||||||
|
MR-18, MR-10, MR-3, MR+4, MR+4, MR-3, MR-10, MR-18
|
||||||
},
|
},
|
||||||
{ // Queen
|
{// Queen
|
||||||
2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
|
//A B C D E F G H
|
||||||
2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
|
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
||||||
2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
|
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
||||||
2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
|
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
||||||
2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
|
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
||||||
2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
|
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
||||||
2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
|
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
||||||
2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560
|
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ,
|
||||||
|
MQ, MQ, MQ, MQ, MQ, MQ, MQ, MQ
|
||||||
},
|
},
|
||||||
{ // King
|
{// King
|
||||||
|
//A B C D E F G H
|
||||||
302, 328, 276, 225, 225, 276, 328, 302,
|
302, 328, 276, 225, 225, 276, 328, 302,
|
||||||
276, 302, 251, 200, 200, 251, 302, 276,
|
276, 302, 251, 200, 200, 251, 302, 276,
|
||||||
225, 251, 200, 149, 149, 200, 251, 225,
|
225, 251, 200, 149, 149, 200, 251, 225,
|
||||||
@@ -91,64 +104,75 @@ static const int MgPST[][64] = {
|
|||||||
175, 200, 149, 98, 98, 149, 200, 175,
|
175, 200, 149, 98, 98, 149, 200, 175,
|
||||||
149, 175, 124, 72, 72, 124, 175, 149,
|
149, 175, 124, 72, 72, 124, 175, 149,
|
||||||
124, 149, 98, 47, 47, 98, 149, 124,
|
124, 149, 98, 47, 47, 98, 149, 124,
|
||||||
98, 124, 72, 21, 21, 72, 124, 98,
|
98, 124, 72, 21, 21, 72, 124, 98
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const Value EP = PawnValueEndgame;
|
||||||
|
static const Value EK = KnightValueEndgame;
|
||||||
|
static const Value EB = BishopValueEndgame;
|
||||||
|
static const Value ER = RookValueEndgame;
|
||||||
|
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
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
256, 256, 256, 256, 256, 256, 256, 256,
|
EP, EP, EP, EP, EP, EP, EP, EP,
|
||||||
256, 256, 256, 256, 256, 256, 256, 256,
|
EP, EP, EP, EP, EP, EP, EP, EP,
|
||||||
256, 256, 256, 256, 256, 256, 256, 256,
|
EP, EP, EP, EP, EP, EP, EP, EP,
|
||||||
256, 256, 256, 256, 256, 256, 256, 256,
|
EP, EP, EP, EP, EP, EP, EP, EP,
|
||||||
256, 256, 256, 256, 256, 256, 256, 256,
|
EP, EP, EP, EP, EP, EP, EP, EP,
|
||||||
256, 256, 256, 256, 256, 256, 256, 256,
|
EP, EP, EP, EP, EP, EP, EP, EP,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
},
|
},
|
||||||
{ // Knight
|
{// Knight
|
||||||
730, 756, 781, 794, 794, 781, 756, 730,
|
// A B C D E F G H
|
||||||
756, 781, 807, 820, 820, 807, 781, 756,
|
EK-102, EK-76, EK-51, EK-38, EK-38, EK-51, EK-76, EK-102,
|
||||||
781, 807, 832, 844, 844, 832, 807, 781,
|
EK- 76, EK-51, EK-25, EK-12, EK-12, EK-25, EK-51, EK-76,
|
||||||
794, 820, 844, 857, 857, 844, 820, 794,
|
EK- 51, EK-25, EK- 0, EK+12, EK+12, EK- 0, EK-25, EK-51,
|
||||||
794, 820, 844, 857, 857, 844, 820, 794,
|
EK- 38, EK-12, EK+12, EK+25, EK+25, EK+12, EK-12, EK-38,
|
||||||
781, 807, 832, 844, 844, 832, 807, 781,
|
EK- 38, EK-12, EK+12, EK+25, EK+25, EK+12, EK-12, EK-38,
|
||||||
756, 781, 807, 820, 820, 807, 781, 756,
|
EK- 51, EK-25, EK- 0, EK+12, EK+12, EK- 0, EK-25, EK-51,
|
||||||
730, 756, 781, 794, 794, 781, 756, 730
|
EK- 76, EK-51, EK-25, EK-12, EK-12, EK-25, EK-51, EK-76,
|
||||||
|
EK-102, EK-76, EK-51, EK-38, EK-38, EK-51, EK-76, EK-102
|
||||||
},
|
},
|
||||||
{ // Bishop
|
{// Bishop
|
||||||
786, 802, 809, 817, 817, 809, 802, 786,
|
// A B C D E F G H
|
||||||
802, 817, 825, 832, 832, 825, 817, 802,
|
EB-46, EB-30, EB-23, EB-15, EB-15, EB-23, EB-30, EB-46,
|
||||||
809, 825, 832, 839, 839, 832, 825, 809,
|
EB-30, EB-15, EB- 7, EB- 0, EB- 0, EB- 7, EB-15, EB-30,
|
||||||
817, 832, 839, 847, 847, 839, 832, 817,
|
EB-23, EB- 7, EB- 0, EB+ 7, EB+ 7, EB- 0, EB- 7, EB-23,
|
||||||
817, 832, 839, 847, 847, 839, 832, 817,
|
EB-15, EB- 0, EB+ 7, EB+15, EB+15, EB+ 7, EB- 0, EB-15,
|
||||||
809, 825, 832, 839, 839, 832, 825, 809,
|
EB-15, EB- 0, EB+ 7, EB+15, EB+15, EB+ 7, EB- 0, EB-15,
|
||||||
802, 817, 825, 832, 832, 825, 817, 802,
|
EB-23, EB- 7, EB- 0, EB+ 7, EB+ 7, EB- 0, EB- 7, EB-23,
|
||||||
786, 802, 809, 817, 817, 809, 802, 786
|
EB-30, EB-15, EB- 7, EB- 0, EB- 0, EB- 7, EB-15, EB-30,
|
||||||
|
EB-46, EB-30, EB-23, EB-15, EB-15, EB-23, EB-30, EB-46
|
||||||
},
|
},
|
||||||
{ // Rook
|
{// Rook
|
||||||
1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282,
|
// A B C D E F G H
|
||||||
1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282,
|
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
||||||
1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282,
|
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
||||||
1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282,
|
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
||||||
1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282,
|
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
||||||
1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282,
|
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
||||||
1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282,
|
ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3, ER-3,
|
||||||
1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282
|
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
|
||||||
2499, 2520, 2530, 2540, 2540, 2530, 2520, 2499,
|
// A B C D E F G H
|
||||||
2520, 2540, 2550, 2560, 2560, 2550, 2540, 2520,
|
EQ-61, EQ-40, EQ-30, EQ-20, EQ-20, EQ-30, EQ-40, EQ-61,
|
||||||
2530, 2550, 2560, 2570, 2570, 2560, 2550, 2530,
|
EQ-40, EQ-20, EQ-10, EQ- 0, EQ- 0, EQ-10, EQ-20, EQ-40,
|
||||||
2540, 2560, 2570, 2580, 2580, 2570, 2560, 2540,
|
EQ-30, EQ-10, EQ- 0, EQ+10, EQ+10, EQ- 0, EQ-10, EQ-30,
|
||||||
2540, 2560, 2570, 2580, 2580, 2570, 2560, 2540,
|
EQ-20, EQ- 0, EQ+10, EQ+20, EQ+20, EQ+10, EQ- 0, EQ-20,
|
||||||
2530, 2550, 2560, 2570, 2570, 2560, 2550, 2530,
|
EQ-20, EQ- 0, EQ+10, EQ+20, EQ+20, EQ+10, EQ- 0, EQ-20,
|
||||||
2520, 2540, 2550, 2560, 2560, 2550, 2540, 2520,
|
EQ-30, EQ-10, EQ- 0, EQ+10, EQ+10, EQ- 0, EQ-10, EQ-30,
|
||||||
2499, 2520, 2530, 2540, 2540, 2530, 2520, 2499
|
EQ-40, EQ-20, EQ-10, EQ- 0, EQ- 0, EQ-10, EQ-20, EQ-40,
|
||||||
|
EQ-61, EQ-40, EQ-30, EQ-20, EQ-20, EQ-30, EQ-40, EQ-61
|
||||||
},
|
},
|
||||||
{ // King
|
{// King
|
||||||
|
//A B C D E F G H
|
||||||
16, 78, 108, 139, 139, 108, 78, 16,
|
16, 78, 108, 139, 139, 108, 78, 16,
|
||||||
78, 139, 170, 200, 200, 170, 139, 78,
|
78, 139, 170, 200, 200, 170, 139, 78,
|
||||||
108, 170, 200, 230, 230, 200, 170, 108,
|
108, 170, 200, 230, 230, 200, 170, 108,
|
||||||
|
|||||||
+217
-199
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "san.h"
|
#include "san.h"
|
||||||
|
|
||||||
|
extern SearchStack EmptySearchStack;
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
@@ -49,7 +51,7 @@ namespace {
|
|||||||
|
|
||||||
/// Functions
|
/// Functions
|
||||||
|
|
||||||
Ambiguity move_ambiguity(Position &pos, Move m);
|
Ambiguity move_ambiguity(const Position& pos, Move m);
|
||||||
const std::string time_string(int milliseconds);
|
const std::string time_string(int milliseconds);
|
||||||
const std::string score_string(Value v);
|
const std::string score_string(Value v);
|
||||||
}
|
}
|
||||||
@@ -63,85 +65,72 @@ 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(Position &pos, Move m) {
|
const std::string move_to_san(const Position& pos, Move m) {
|
||||||
std::string str;
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
|
|
||||||
if(m == MOVE_NONE) {
|
|
||||||
str = "(none)";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
else if(m == MOVE_NULL) {
|
|
||||||
str = "(null)";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
else if(move_is_long_castle(m))
|
|
||||||
str = "O-O-O";
|
|
||||||
else if(move_is_short_castle(m))
|
|
||||||
str = "O-O";
|
|
||||||
else {
|
|
||||||
Square from, to;
|
Square from, to;
|
||||||
Piece pc;
|
PieceType pt;
|
||||||
|
|
||||||
from = move_from(m);
|
from = move_from(m);
|
||||||
to = move_to(m);
|
to = move_to(m);
|
||||||
pc = pos.piece_on(move_from(m));
|
pt = type_of_piece(pos.piece_on(move_from(m)));
|
||||||
|
|
||||||
str = "";
|
std::string san = "";
|
||||||
|
|
||||||
if(type_of_piece(pc) == PAWN) {
|
|
||||||
if(pos.move_is_capture(m))
|
|
||||||
str += file_to_char(square_file(move_from(m)));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
str += piece_type_to_char(type_of_piece(pc), true);
|
|
||||||
|
|
||||||
Ambiguity amb = move_ambiguity(pos, m);
|
|
||||||
switch(amb) {
|
|
||||||
|
|
||||||
|
if (m == MOVE_NONE)
|
||||||
|
return "(none)";
|
||||||
|
else if (m == MOVE_NULL)
|
||||||
|
return "(null)";
|
||||||
|
else if (move_is_long_castle(m) || (int(to - from) == -2 && pt == KING))
|
||||||
|
san = "O-O-O";
|
||||||
|
else if (move_is_short_castle(m) || (int(to - from) == 2 && pt == KING))
|
||||||
|
san = "O-O";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pt != PAWN)
|
||||||
|
{
|
||||||
|
san += piece_type_to_char(pt, true);
|
||||||
|
switch (move_ambiguity(pos, m)) {
|
||||||
case AMBIGUITY_NONE:
|
case AMBIGUITY_NONE:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AMBIGUITY_FILE:
|
case AMBIGUITY_FILE:
|
||||||
str += file_to_char(square_file(from));
|
san += file_to_char(square_file(from));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AMBIGUITY_RANK:
|
case AMBIGUITY_RANK:
|
||||||
str += rank_to_char(square_rank(from));
|
san += rank_to_char(square_rank(from));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AMBIGUITY_BOTH:
|
case AMBIGUITY_BOTH:
|
||||||
str += square_to_string(from);
|
san += square_to_string(from);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pos.move_is_capture(m))
|
||||||
if(pos.move_is_capture(m))
|
{
|
||||||
str += "x";
|
if (pt == PAWN)
|
||||||
|
san += file_to_char(square_file(move_from(m)));
|
||||||
str += square_to_string(move_to(m));
|
san += "x";
|
||||||
|
}
|
||||||
if(move_promotion(m)) {
|
san += square_to_string(move_to(m));
|
||||||
str += "=";
|
if (move_promotion(m))
|
||||||
str += piece_type_to_char(move_promotion(m), true);
|
{
|
||||||
|
san += '=';
|
||||||
|
san += piece_type_to_char(move_promotion(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;
|
||||||
pos.do_move(m, u);
|
Position p(pos);
|
||||||
if(pos.is_check())
|
p.do_move(m, st);
|
||||||
str += pos.is_mate()? "#" : "+";
|
if (p.is_check())
|
||||||
pos.undo_move(m, u);
|
san += p.is_mate()? "#" : "+";
|
||||||
|
|
||||||
return str;
|
return san;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -150,116 +139,150 @@ const std::string move_to_san(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(Position &pos, const std::string &movestr) {
|
Move move_from_san(const Position& pos, const std::string& movestr) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
MovePicker mp = MovePicker(pos, false, MOVE_NONE, MOVE_NONE, MOVE_NONE,
|
MovePicker mp = MovePicker(pos, false, MOVE_NONE, EmptySearchStack, OnePly);
|
||||||
MOVE_NONE, OnePly);
|
|
||||||
|
|
||||||
// Castling moves
|
// Castling moves
|
||||||
if(movestr == "O-O-O") {
|
if (movestr == "O-O-O" || movestr == "O-O-O+")
|
||||||
|
{
|
||||||
Move m;
|
Move m;
|
||||||
while((m = mp.get_next_move()) != MOVE_NONE)
|
while ((m = mp.get_next_move()) != MOVE_NONE)
|
||||||
if(move_is_long_castle(m) && pos.move_is_legal(m))
|
if (move_is_long_castle(m) && pos.pl_move_is_legal(m))
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
else if(movestr == "O-O") {
|
else if (movestr == "O-O" || movestr == "O-O+")
|
||||||
|
{
|
||||||
Move m;
|
Move m;
|
||||||
while((m = mp.get_next_move()) != MOVE_NONE)
|
while ((m = mp.get_next_move()) != MOVE_NONE)
|
||||||
if(move_is_short_castle(m) && pos.move_is_legal(m))
|
if (move_is_short_castle(m) && pos.pl_move_is_legal(m))
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal moves
|
// Normal moves. We use a simple FSM to parse the san string.
|
||||||
const char *cstr = movestr.c_str();
|
enum { START, TO_FILE, TO_RANK, PROMOTION_OR_CHECK, PROMOTION, CHECK, END };
|
||||||
const char *c;
|
static const std::string pieceLetters = "KQRBN";
|
||||||
char *cc;
|
PieceType pt = NO_PIECE_TYPE, promotion = NO_PIECE_TYPE;
|
||||||
char str[10];
|
File fromFile = FILE_NONE, toFile = FILE_NONE;
|
||||||
int i;
|
Rank fromRank = RANK_NONE, toRank = RANK_NONE;
|
||||||
|
|
||||||
// Initialize str[] by making a copy of movestr with the characters
|
|
||||||
// 'x', '=', '+' and '#' removed.
|
|
||||||
cc = str;
|
|
||||||
for(i=0, c=cstr; i<10 && *c!='\0' && *c!='\n' && *c!=' '; i++, c++)
|
|
||||||
if(!strchr("x=+#", *c)) {
|
|
||||||
*cc = strchr("nrq", *c)? toupper(*c) : *c;
|
|
||||||
cc++;
|
|
||||||
}
|
|
||||||
*cc = '\0';
|
|
||||||
|
|
||||||
int left = 0, right = strlen(str) - 1;
|
|
||||||
PieceType pt = NO_PIECE_TYPE, promotion;
|
|
||||||
Square to;
|
Square to;
|
||||||
File fromFile = FILE_NONE;
|
int state = START;
|
||||||
Rank fromRank = RANK_NONE;
|
|
||||||
|
|
||||||
// Promotion?
|
for (size_t i = 0; i < movestr.length(); i++)
|
||||||
if(strchr("BNRQ", str[right])) {
|
{
|
||||||
promotion = piece_type_from_char(str[right]);
|
char type, c = movestr[i];
|
||||||
right--;
|
if (pieceLetters.find(c) != std::string::npos)
|
||||||
}
|
type = 'P';
|
||||||
else
|
else if (c >= 'a' && c <= 'h')
|
||||||
promotion = NO_PIECE_TYPE;
|
type = 'F';
|
||||||
|
else if (c >= '1' && c <= '8')
|
||||||
// Find the moving piece:
|
type = 'R';
|
||||||
if(left < right) {
|
else
|
||||||
if(strchr("BNRQK", str[left])) {
|
type = c;
|
||||||
pt = piece_type_from_char(str[left]);
|
|
||||||
left++;
|
switch (type) {
|
||||||
|
case 'P':
|
||||||
|
if (state == START)
|
||||||
|
{
|
||||||
|
pt = piece_type_from_char(c);
|
||||||
|
state = TO_FILE;
|
||||||
|
}
|
||||||
|
else if (state == PROMOTION)
|
||||||
|
{
|
||||||
|
promotion = piece_type_from_char(c);
|
||||||
|
state = (i < movestr.length() - 1) ? CHECK : END;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
return MOVE_NONE;
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
if (state == START)
|
||||||
|
{
|
||||||
pt = PAWN;
|
pt = PAWN;
|
||||||
|
fromFile = toFile = file_from_char(c);
|
||||||
|
state = TO_RANK;
|
||||||
}
|
}
|
||||||
|
else if (state == TO_FILE)
|
||||||
// Find the to square:
|
{
|
||||||
if(left < right) {
|
toFile = file_from_char(c);
|
||||||
if(str[right] < '1' || str[right] > '8' ||
|
state = TO_RANK;
|
||||||
str[right-1] < 'a' || str[right-1] > 'h')
|
}
|
||||||
return MOVE_NONE;
|
else if (state == TO_RANK && toFile != FILE_NONE)
|
||||||
to = make_square(file_from_char(str[right-1]), rank_from_char(str[right]));
|
{
|
||||||
right -= 2;
|
// Previous file was for disambiguation
|
||||||
|
fromFile = toFile;
|
||||||
|
toFile = file_from_char(c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
|
break;
|
||||||
// Find the file and/or rank of the from square:
|
case 'R':
|
||||||
if(left <= right) {
|
if (state == TO_RANK)
|
||||||
if(strchr("abcdefgh", str[left])) {
|
{
|
||||||
fromFile = file_from_char(str[left]);
|
toRank = rank_from_char(c);
|
||||||
left++;
|
state = (i < movestr.length() - 1) ? PROMOTION_OR_CHECK : END;
|
||||||
|
}
|
||||||
|
else if (state == TO_FILE && fromRank == RANK_NONE)
|
||||||
|
{
|
||||||
|
// It's a disambiguation rank instead of a file
|
||||||
|
fromRank = rank_from_char(c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return MOVE_NONE;
|
||||||
|
break;
|
||||||
|
case 'x': case 'X':
|
||||||
|
if (state == TO_RANK)
|
||||||
|
{
|
||||||
|
// Previous file was for disambiguation, or it's a pawn capture
|
||||||
|
fromFile = toFile;
|
||||||
|
state = TO_FILE;
|
||||||
|
}
|
||||||
|
else if (state != TO_FILE)
|
||||||
|
return MOVE_NONE;
|
||||||
|
break;
|
||||||
|
case '=':
|
||||||
|
if (state == PROMOTION_OR_CHECK)
|
||||||
|
state = PROMOTION;
|
||||||
|
else
|
||||||
|
return MOVE_NONE;
|
||||||
|
break;
|
||||||
|
case '+': case '#':
|
||||||
|
if (state == PROMOTION_OR_CHECK || state == CHECK)
|
||||||
|
state = END;
|
||||||
|
else
|
||||||
|
return MOVE_NONE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return MOVE_NONE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(strchr("12345678", str[left]))
|
|
||||||
fromRank = rank_from_char(str[left]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for a matching move:
|
if (state != END)
|
||||||
|
return MOVE_NONE;
|
||||||
|
|
||||||
|
// Look for a matching move
|
||||||
Move m, move = MOVE_NONE;
|
Move m, move = MOVE_NONE;
|
||||||
|
to = make_square(toFile, toRank);
|
||||||
int matches = 0;
|
int matches = 0;
|
||||||
|
|
||||||
while((m = mp.get_next_move()) != MOVE_NONE) {
|
while ((m = mp.get_next_move()) != MOVE_NONE)
|
||||||
bool match = true;
|
if ( pos.type_of_piece_on(move_from(m)) == pt
|
||||||
if(pos.type_of_piece_on(move_from(m)) != pt)
|
&& move_to(m) == to
|
||||||
match = false;
|
&& move_promotion(m) == promotion
|
||||||
else if(move_to(m) != to)
|
&& (fromFile == FILE_NONE || fromFile == square_file(move_from(m)))
|
||||||
match = false;
|
&& (fromRank == RANK_NONE || fromRank == square_rank(move_from(m))))
|
||||||
else if(move_promotion(m) != promotion)
|
{
|
||||||
match = false;
|
|
||||||
else if(fromFile != FILE_NONE && fromFile != square_file(move_from(m)))
|
|
||||||
match = false;
|
|
||||||
else if(fromRank != RANK_NONE && fromRank != square_rank(move_from(m)))
|
|
||||||
match = false;
|
|
||||||
if(match) {
|
|
||||||
move = m;
|
move = m;
|
||||||
matches++;
|
matches++;
|
||||||
}
|
}
|
||||||
}
|
return (matches == 1 ? move : MOVE_NONE);
|
||||||
|
|
||||||
if(matches == 1)
|
|
||||||
return move;
|
|
||||||
else
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -270,34 +293,31 @@ Move move_from_san(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,
|
const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines) {
|
||||||
bool breakLines) {
|
|
||||||
Position p = Position(pos);
|
StateInfo st;
|
||||||
UndoInfo u;
|
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
std::string moveStr;
|
std::string moveStr;
|
||||||
int length, maxLength;
|
size_t length = 0;
|
||||||
|
size_t maxLength = 80 - startColumn;
|
||||||
|
Position p(pos);
|
||||||
|
|
||||||
length = 0;
|
for (int i = 0; line[i] != MOVE_NONE; i++)
|
||||||
maxLength = 80 - startColumn;
|
{
|
||||||
|
|
||||||
for(int i = 0; line[i] != MOVE_NONE; i++) {
|
|
||||||
moveStr = move_to_san(p, line[i]);
|
moveStr = move_to_san(p, line[i]);
|
||||||
length += moveStr.length() + 1;
|
length += moveStr.length() + 1;
|
||||||
if(breakLines && length > maxLength) {
|
if (breakLines && length > maxLength)
|
||||||
s << "\n";
|
{
|
||||||
for(int j = 0; j < startColumn; j++)
|
s << '\n' << std::setw(startColumn) << ' ';
|
||||||
s << " ";
|
|
||||||
length = moveStr.length() + 1;
|
length = moveStr.length() + 1;
|
||||||
}
|
}
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,26 +326,26 @@ 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 std::string pretty_pv(const Position& pos, int time, int depth,
|
||||||
uint64_t nodes, Value score, Move pv[]) {
|
uint64_t nodes, Value score, Move pv[]) {
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
|
||||||
// Depth
|
// Depth
|
||||||
s << std::setw(2) << std::setfill(' ') << depth << " ";
|
s << std::setw(2) << depth << " ";
|
||||||
|
|
||||||
// Score
|
// Score
|
||||||
s << std::setw(8) << score_string(score);
|
s << std::setw(8) << score_string(score);
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
s << std::setw(8) << std::setfill(' ') << time_string(time) << " ";
|
s << std::setw(8) << time_string(time) << " ";
|
||||||
|
|
||||||
// Nodes
|
// Nodes
|
||||||
if(nodes < 1000000ULL)
|
if (nodes < 1000000ULL)
|
||||||
s << std::setw(8) << std::setfill(' ') << nodes << " ";
|
s << std::setw(8) << nodes << " ";
|
||||||
else if(nodes < 1000000000ULL)
|
else if (nodes < 1000000000ULL)
|
||||||
s << std::setw(7) << std::setfill(' ') << nodes/1000ULL << 'k' << " ";
|
s << std::setw(7) << nodes/1000ULL << 'k' << " ";
|
||||||
else
|
else
|
||||||
s << std::setw(7) << std::setfill(' ') << nodes/1000000ULL << 'M' << " ";
|
s << std::setw(7) << nodes/1000000ULL << 'M' << " ";
|
||||||
|
|
||||||
// PV
|
// PV
|
||||||
s << line_to_san(pos, pv, 30, true);
|
s << line_to_san(pos, pv, 30, true);
|
||||||
@@ -336,44 +356,41 @@ const std::string pretty_pv(const Position &pos, int time, int depth,
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
Ambiguity move_ambiguity(Position &pos, Move m) {
|
Ambiguity move_ambiguity(const Position& pos, Move m) {
|
||||||
Square from, to;
|
|
||||||
Piece pc;
|
|
||||||
|
|
||||||
from = move_from(m);
|
Square from = move_from(m);
|
||||||
to = move_to(m);
|
Square to = move_to(m);
|
||||||
pc = pos.piece_on(from);
|
Piece pc = pos.piece_on(from);
|
||||||
|
|
||||||
// King moves are never ambiguous, because there is never two kings of
|
// King moves are never ambiguous, because there is never two kings of
|
||||||
// the same color.
|
// the same color.
|
||||||
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, MOVE_NONE, MOVE_NONE,
|
MovePicker mp = MovePicker(pos, false, MOVE_NONE, EmptySearchStack, OnePly);
|
||||||
MOVE_NONE, OnePly);
|
|
||||||
Move mv, moveList[8];
|
Move mv, moveList[8];
|
||||||
int i, j, n;
|
|
||||||
|
|
||||||
n = 0;
|
int n = 0;
|
||||||
while((mv = mp.get_next_move()) != MOVE_NONE)
|
while ((mv = mp.get_next_move()) != MOVE_NONE)
|
||||||
if(move_to(mv) == to && pos.piece_on(move_from(mv)) == pc
|
if (move_to(mv) == to && pos.piece_on(move_from(mv)) == pc && pos.pl_move_is_legal(mv))
|
||||||
&& pos.move_is_legal(mv))
|
|
||||||
moveList[n++] = mv;
|
moveList[n++] = mv;
|
||||||
if(n == 1)
|
|
||||||
|
if (n == 1)
|
||||||
return AMBIGUITY_NONE;
|
return AMBIGUITY_NONE;
|
||||||
|
|
||||||
j = 0;
|
int f = 0, r = 0;
|
||||||
for(i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
if(square_file(move_from(moveList[i])) == square_file(from))
|
{
|
||||||
j++;
|
if (square_file(move_from(moveList[i])) == square_file(from))
|
||||||
if(j == 1)
|
f++;
|
||||||
|
|
||||||
|
if (square_rank(move_from(moveList[i])) == square_rank(from))
|
||||||
|
r++;
|
||||||
|
}
|
||||||
|
if (f == 1)
|
||||||
return AMBIGUITY_FILE;
|
return AMBIGUITY_FILE;
|
||||||
|
|
||||||
j = 0;
|
if (r == 1)
|
||||||
for(i = 0; i < n; i++)
|
|
||||||
if(square_rank(move_from(moveList[i])) == square_rank(from))
|
|
||||||
j++;
|
|
||||||
if(j == 1)
|
|
||||||
return AMBIGUITY_RANK;
|
return AMBIGUITY_RANK;
|
||||||
|
|
||||||
return AMBIGUITY_BOTH;
|
return AMBIGUITY_BOTH;
|
||||||
@@ -381,37 +398,38 @@ namespace {
|
|||||||
|
|
||||||
|
|
||||||
const std::string time_string(int milliseconds) {
|
const std::string time_string(int milliseconds) {
|
||||||
|
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
s << std::setfill('0');
|
||||||
|
|
||||||
int hours = milliseconds / (1000 * 60 * 60);
|
int hours = milliseconds / (1000*60*60);
|
||||||
int minutes = (milliseconds - hours*1000*60*60) / (60*1000);
|
int minutes = (milliseconds - hours*1000*60*60) / (1000*60);
|
||||||
int seconds = (milliseconds - hours*1000*60*60 - minutes*60*1000) / 1000;
|
int seconds = (milliseconds - hours*1000*60*60 - minutes*1000*60) / 1000;
|
||||||
|
|
||||||
if(hours)
|
if (hours)
|
||||||
s << hours << ':';
|
s << hours << ':';
|
||||||
s << std::setw(2) << std::setfill('0') << minutes << ':';
|
|
||||||
s << std::setw(2) << std::setfill('0') << seconds;
|
|
||||||
|
|
||||||
|
s << std::setw(2) << minutes << ':' << std::setw(2) << seconds;
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string score_string(Value v) {
|
const std::string score_string(Value v) {
|
||||||
|
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
|
||||||
if(abs(v) >= VALUE_MATE - 200) {
|
if (v >= VALUE_MATE - 200)
|
||||||
if(v < 0)
|
s << "#" << (VALUE_MATE - v + 1) / 2;
|
||||||
|
else if(v <= -VALUE_MATE + 200)
|
||||||
s << "-#" << (VALUE_MATE + v) / 2;
|
s << "-#" << (VALUE_MATE + v) / 2;
|
||||||
else
|
else
|
||||||
s << "#" << (VALUE_MATE - v + 1) / 2;
|
{
|
||||||
}
|
|
||||||
else {
|
|
||||||
float floatScore = float(v) / float(PawnValueMidgame);
|
float floatScore = float(v) / float(PawnValueMidgame);
|
||||||
if(v >= 0)
|
if (v >= 0)
|
||||||
s << '+';
|
s << '+';
|
||||||
|
|
||||||
s << std::setprecision(2) << std::fixed << floatScore;
|
s << std::setprecision(2) << std::fixed << floatScore;
|
||||||
}
|
}
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -35,12 +36,9 @@
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern const std::string move_to_san(Position &pos, Move m);
|
extern const std::string move_to_san(const Position& pos, Move m);
|
||||||
extern Move move_from_san(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[],
|
extern const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines);
|
||||||
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, Move pv[]);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(SAN_H_INCLUDED)
|
#endif // !defined(SAN_H_INCLUDED)
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+1177
-748
File diff suppressed because it is too large
Load Diff
+15
-12
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -24,7 +25,6 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
const int PLY_MAX = 100;
|
const int PLY_MAX = 100;
|
||||||
const int PLY_MAX_PLUS_2 = 102;
|
const int PLY_MAX_PLUS_2 = 102;
|
||||||
|
const int KILLER_MAX = 2;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -54,10 +55,13 @@ const int PLY_MAX_PLUS_2 = 102;
|
|||||||
struct SearchStack {
|
struct SearchStack {
|
||||||
Move pv[PLY_MAX];
|
Move pv[PLY_MAX];
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Value currentMoveCaptureValue;
|
Move mateKiller;
|
||||||
Move mateKiller, killer1, killer2;
|
|
||||||
Move threatMove;
|
Move threatMove;
|
||||||
|
Move killers[KILLER_MAX];
|
||||||
Depth reduction;
|
Depth reduction;
|
||||||
|
|
||||||
|
void init(int ply);
|
||||||
|
void initKillers();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -65,10 +69,9 @@ struct SearchStack {
|
|||||||
//// Global variables
|
//// Global variables
|
||||||
////
|
////
|
||||||
|
|
||||||
|
extern SearchStack EmptySearchStack;
|
||||||
extern TranspositionTable TT;
|
extern TranspositionTable TT;
|
||||||
|
|
||||||
extern int ActiveThreads;
|
extern int ActiveThreads;
|
||||||
|
|
||||||
extern Lock SMPLock;
|
extern Lock SMPLock;
|
||||||
|
|
||||||
// Perhaps better to make H local, and pass as parameter to MovePicker?
|
// Perhaps better to make H local, and pass as parameter to MovePicker?
|
||||||
@@ -81,9 +84,9 @@ extern History H;
|
|||||||
|
|
||||||
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 time,
|
extern void think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
||||||
int increment, int movesToGo, int maxDepth, int maxNodes,
|
int time[], int increment[], int movesToGo, int maxDepth,
|
||||||
int maxTime, Move searchMoves[]);
|
int maxNodes, int maxTime, Move searchMoves[]);
|
||||||
extern int64_t nodes_searched();
|
extern int64_t nodes_searched();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
Glaurung, a UCI chess playing engine.
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
|
||||||
|
|
||||||
Glaurung 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.
|
|
||||||
|
|
||||||
Glaurung 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 <cstdio>
|
|
||||||
#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));
|
|
||||||
}
|
|
||||||
+41
-17
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <cstdlib> // for abs()
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
@@ -129,7 +131,7 @@ inline Square relative_square(Color c, Square s) {
|
|||||||
return Square(int(s) ^ (int(c) * FlipMask));
|
return Square(int(s) ^ (int(c) * FlipMask));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank pawn_rank(Color c, Square s) {
|
inline Rank relative_rank(Color c, Square s) {
|
||||||
return square_rank(relative_square(c, s));
|
return square_rank(relative_square(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,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,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
+82
-116
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
|
|
||||||
@@ -31,20 +33,15 @@
|
|||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
|
|
||||||
/// Constructor
|
TranspositionTable::TranspositionTable() {
|
||||||
|
|
||||||
TranspositionTable::TranspositionTable(unsigned mbSize) {
|
size = writes = 0;
|
||||||
size = 0;
|
|
||||||
generation = 0;
|
|
||||||
writes = 0;
|
|
||||||
entries = 0;
|
entries = 0;
|
||||||
this->set_size(mbSize);
|
generation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Destructor
|
|
||||||
|
|
||||||
TranspositionTable::~TranspositionTable() {
|
TranspositionTable::~TranspositionTable() {
|
||||||
|
|
||||||
delete [] entries;
|
delete [] entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,25 +50,28 @@ TranspositionTable::~TranspositionTable() {
|
|||||||
/// measured in megabytes.
|
/// measured in megabytes.
|
||||||
|
|
||||||
void TranspositionTable::set_size(unsigned mbSize) {
|
void TranspositionTable::set_size(unsigned mbSize) {
|
||||||
unsigned newSize;
|
|
||||||
|
|
||||||
assert(mbSize >= 4 && mbSize <= 1024);
|
assert(mbSize >= 4 && mbSize <= 4096);
|
||||||
|
|
||||||
for(newSize = 1024; newSize * 4 * (sizeof(TTEntry)) <= (mbSize << 20);
|
unsigned newSize = 1024;
|
||||||
newSize *= 2);
|
|
||||||
newSize /= 2;
|
|
||||||
|
|
||||||
if(newSize != size) {
|
// We store a cluster of 4 TTEntry for each position and newSize is
|
||||||
|
// the maximum number of storable positions
|
||||||
|
while ((2 * newSize) * 4 * (sizeof(TTEntry)) <= (mbSize << 20))
|
||||||
|
newSize *= 2;
|
||||||
|
|
||||||
|
if (newSize != size)
|
||||||
|
{
|
||||||
size = newSize;
|
size = newSize;
|
||||||
delete [] entries;
|
delete [] entries;
|
||||||
entries = new TTEntry[size * 4];
|
entries = new TTEntry[size * 4];
|
||||||
if(entries == NULL) {
|
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;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
this->clear();
|
clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,99 +82,105 @@ void TranspositionTable::set_size(unsigned mbSize) {
|
|||||||
/// 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 * 4 * sizeof(TTEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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 Position& p, 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;
|
||||||
|
|
||||||
tte = replace = entries + int(pos.get_key() & (size - 1)) * 4;
|
tte = replace = first_entry(p);
|
||||||
for(int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++, tte++)
|
||||||
if((tte+i)->key() == pos.get_key()) {
|
{
|
||||||
if(m == MOVE_NONE)
|
if (!tte->key() || tte->key() == p.get_key()) // empty or overwrite old
|
||||||
m = (tte+i)->move();
|
{
|
||||||
*(tte+i) = TTEntry(pos.get_key(), v, type, d, m, generation);
|
// Do not overwrite when new type is VALUE_TYPE_EVAL
|
||||||
|
if (tte->key() && t == VALUE_TYPE_EVAL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m == MOVE_NONE)
|
||||||
|
m = tte->move();
|
||||||
|
|
||||||
|
*tte = TTEntry(p.get_key(), v, t, d, m, generation);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(replace->generation() == generation) {
|
else if (i == 0) // replace would be a no-op in this common case
|
||||||
if((tte+i)->generation() != generation ||
|
continue;
|
||||||
(tte+i)->depth() < replace->depth())
|
|
||||||
replace = tte+i;
|
int c1 = (replace->generation() == generation ? 2 : 0);
|
||||||
|
int c2 = (tte->generation() == generation ? -2 : 0);
|
||||||
|
int c3 = (tte->depth() < replace->depth() ? 1 : 0);
|
||||||
|
|
||||||
|
if (c1 + c2 + c3 > 0)
|
||||||
|
replace = tte;
|
||||||
}
|
}
|
||||||
else if((tte+i)->generation() != generation &&
|
*replace = TTEntry(p.get_key(), v, t, d, m, generation);
|
||||||
(tte+i)->depth() < replace->depth())
|
|
||||||
replace = tte+i;
|
|
||||||
}
|
|
||||||
*replace = TTEntry(pos.get_key(), v, type, d, m, generation);
|
|
||||||
writes++;
|
writes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TranspositionTable::retrieve looks up the current position in the
|
/// TranspositionTable::retrieve looks up the current position in the
|
||||||
/// transposition table, and extracts the value, value type, depth and
|
/// transposition table. Returns a pointer to the TTEntry or NULL
|
||||||
/// best move if the position is found. The return value is true if
|
/// if position is not found.
|
||||||
/// the position is found, and false if it isn't.
|
|
||||||
|
|
||||||
bool TranspositionTable::retrieve(const Position &pos, Value *value,
|
TTEntry* TranspositionTable::retrieve(const Position& pos) const {
|
||||||
Depth *d, Move *move,
|
|
||||||
ValueType *type) const {
|
|
||||||
TTEntry *tte;
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
tte = entries + int(pos.get_key() & (size - 1)) * 4;
|
TTEntry *tte = first_entry(pos);
|
||||||
for(int i = 0; i < 4 && !found ; i++)
|
|
||||||
if((tte+i)->key() == pos.get_key()) {
|
|
||||||
tte = tte + i;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
if(!found) {
|
|
||||||
*move = MOVE_NONE;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*value = tte->value();
|
for (int i = 0; i < 4; i++, tte++)
|
||||||
*type = tte->type();
|
if (tte->key() == pos.get_key())
|
||||||
*d = tte->depth();
|
return tte;
|
||||||
*move = tte->move();
|
|
||||||
|
|
||||||
return true;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// TranspositionTable::first_entry returns a pointer to the first
|
||||||
|
/// entry of a cluster given a position.
|
||||||
|
|
||||||
|
inline TTEntry* TranspositionTable::first_entry(const Position& pos) const {
|
||||||
|
|
||||||
|
return entries + (int(pos.get_key() & (size - 1)) << 2);
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
|
|
||||||
void TranspositionTable::new_search() {
|
void TranspositionTable::new_search() {
|
||||||
|
|
||||||
generation++;
|
generation++;
|
||||||
writes = 0;
|
writes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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++)
|
||||||
this->store(p, VALUE_NONE, Depth(0), pv[i], VALUE_TYPE_NONE);
|
{
|
||||||
p.do_move(pv[i], u);
|
store(p, VALUE_NONE, VALUE_TYPE_NONE, Depth(-127*OnePly), pv[i]);
|
||||||
|
p.do_move(pv[i], st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,48 +189,8 @@ void TranspositionTable::insert_pv(const Position &pos, Move pv[]) {
|
|||||||
/// 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) * 4.0;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Functions for extracting data from TTEntry objects.
|
|
||||||
|
|
||||||
Key TTEntry::key() const {
|
|
||||||
return key_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Depth TTEntry::depth() const {
|
|
||||||
return Depth(depth_);
|
|
||||||
}
|
|
||||||
|
|
||||||
Move TTEntry::move() const {
|
|
||||||
return Move(data & 0x7FFFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
Value TTEntry::value() const {
|
|
||||||
return Value(value_);
|
|
||||||
}
|
|
||||||
|
|
||||||
ValueType TTEntry::type() const {
|
|
||||||
return ValueType((data >> 20) & 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
int TTEntry::generation() const {
|
|
||||||
return (data >> 23);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -33,19 +34,36 @@
|
|||||||
//// 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 128 bits to be stored
|
||||||
|
///
|
||||||
|
/// bit 0-63: key
|
||||||
|
/// bit 64-95: data
|
||||||
|
/// bit 96-111: value
|
||||||
|
/// bit 112-127: 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(Key k, Value v, ValueType t, Depth d, Move m, int generation)
|
||||||
Key key() const;
|
: key_ (k), data((m & 0x1FFFF) | (t << 20) | (generation << 23)),
|
||||||
Depth depth() const;
|
value_(int16_t(v)), depth_(int16_t(d)) {}
|
||||||
Move move() const;
|
|
||||||
Value value() const;
|
Key key() const { return key_; }
|
||||||
ValueType type() const;
|
Depth depth() const { return Depth(depth_); }
|
||||||
int generation() const;
|
Move move() const { return Move(data & 0x1FFFF); }
|
||||||
|
Value value() const { return Value(value_); }
|
||||||
|
ValueType type() const { return ValueType((data >> 20) & 7); }
|
||||||
|
int generation() const { return (data >> 23); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Key key_;
|
Key key_;
|
||||||
@@ -54,7 +72,6 @@ private:
|
|||||||
int16_t depth_;
|
int16_t depth_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// The transposition table class. This is basically just a huge array
|
/// 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.
|
||||||
@@ -62,31 +79,22 @@ private:
|
|||||||
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 Position& pos, Value v, ValueType type, Depth d, Move m);
|
||||||
bool retrieve(const Position &pos, Value *value, Depth *d, Move *move,
|
TTEntry* retrieve(const Position& pos) const;
|
||||||
ValueType *type) 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();
|
int full() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned size;
|
inline TTEntry* first_entry(const Position& pos) const;
|
||||||
int writes;
|
|
||||||
|
unsigned size, writes;
|
||||||
TTEntry* entries;
|
TTEntry* entries;
|
||||||
uint8_t generation;
|
uint8_t generation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Constants and variables
|
|
||||||
////
|
|
||||||
|
|
||||||
// Default transposition table size, in megabytes:
|
|
||||||
const int TTDefaultSize = 32;
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(TT_H_INCLUDED)
|
#endif // !defined(TT_H_INCLUDED)
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+138
-194
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -21,7 +22,9 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "book.h"
|
#include "book.h"
|
||||||
@@ -42,30 +45,10 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// UCIInputParser is a class for parsing UCI input. The class is
|
// UCIInputParser is a class for parsing UCI input. The class
|
||||||
// very simple, and basically just consist of a constant input
|
// is actually a string stream built on a given input string.
|
||||||
// string and a current location in the string. There are methods
|
|
||||||
// for checking if we are at the end of the line, for getting the
|
|
||||||
// next token (defined as any whitespace-delimited sequence of
|
|
||||||
// characters), and for getting the rest of the line as a single
|
|
||||||
// string.
|
|
||||||
|
|
||||||
class UCIInputParser {
|
|
||||||
|
|
||||||
public:
|
|
||||||
UCIInputParser(const std::string &line);
|
|
||||||
std::string get_next_token();
|
|
||||||
std::string get_rest_of_line();
|
|
||||||
bool at_end_of_line();
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::string &inputLine;
|
|
||||||
int length, currentIndex;
|
|
||||||
|
|
||||||
void skip_whitespace();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
typedef std::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()
|
||||||
@@ -73,7 +56,7 @@ namespace {
|
|||||||
Position RootPosition;
|
Position RootPosition;
|
||||||
|
|
||||||
// Local functions
|
// Local functions
|
||||||
void wait_for_command();
|
void get_command();
|
||||||
void handle_command(const std::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);
|
||||||
@@ -91,8 +74,11 @@ namespace {
|
|||||||
/// command.
|
/// command.
|
||||||
|
|
||||||
void uci_main_loop() {
|
void uci_main_loop() {
|
||||||
|
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
while(1) wait_for_command();
|
|
||||||
|
while (1)
|
||||||
|
get_command();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -102,80 +88,19 @@ void uci_main_loop() {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
///
|
// get_command() waits for a command from the user, and passes
|
||||||
/// Implementation of the UCIInputParser class.
|
// this command to handle_command. get_command also intercepts
|
||||||
///
|
|
||||||
|
|
||||||
// Constructor for the UCIInputParser class. The constructor takes a
|
|
||||||
// text string containing a single UCI command as input.
|
|
||||||
|
|
||||||
UCIInputParser::UCIInputParser(const std::string &line) : inputLine(line) {
|
|
||||||
this->currentIndex = 0;
|
|
||||||
this->length = line.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// UCIInputParser::skip_whitspace() skips any number of whitespace
|
|
||||||
// characters from the current location in an input string.
|
|
||||||
|
|
||||||
void UCIInputParser::skip_whitespace() {
|
|
||||||
while(isspace((int)(unsigned char)this->inputLine[this->currentIndex]))
|
|
||||||
this->currentIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// UCIInputParser::get_next_token() gets the next token in an UCI
|
|
||||||
// command. A 'token' in an UCI command is simply any
|
|
||||||
// whitespace-delimited sequence of characters.
|
|
||||||
|
|
||||||
std::string UCIInputParser::get_next_token() {
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
this->skip_whitespace();
|
|
||||||
for(i = j = this->currentIndex;
|
|
||||||
j < this->length && !isspace(this->inputLine[j]);
|
|
||||||
j++);
|
|
||||||
this->currentIndex = j;
|
|
||||||
this->skip_whitespace();
|
|
||||||
|
|
||||||
std::string str = this->inputLine.substr(i, j - i);
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// UCIInputParser::get_rest_of_line() returns the rest of the input
|
|
||||||
// line (from the current location) as a single string.
|
|
||||||
|
|
||||||
std::string UCIInputParser::get_rest_of_line() {
|
|
||||||
this->skip_whitespace();
|
|
||||||
return this->inputLine.substr(this->currentIndex, this->length);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// UCIInputParser::at_end_of_line() tests whether we have reached the
|
|
||||||
// end of the input string, i.e. if any more input remains to be
|
|
||||||
// parsed.
|
|
||||||
|
|
||||||
bool UCIInputParser::at_end_of_line() {
|
|
||||||
return this->currentIndex == this->length;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Other functions
|
|
||||||
///
|
|
||||||
|
|
||||||
|
|
||||||
// wait_for_command() waits for a command from the user, and passes
|
|
||||||
// this command to handle_command. wait_for_command also intercepts
|
|
||||||
// EOF from stdin, by translating EOF to the "quit" command. This
|
// EOF from stdin, by translating EOF to the "quit" command. This
|
||||||
// ensures that Glaurung exits gracefully if the GUI dies
|
// ensures that Stockfish exits gracefully if the GUI dies
|
||||||
// unexpectedly.
|
// unexpectedly.
|
||||||
|
|
||||||
void wait_for_command() {
|
void get_command() {
|
||||||
|
|
||||||
std::string command;
|
std::string command;
|
||||||
if(!std::getline(std::cin, command)) command = "quit";
|
|
||||||
|
if (!std::getline(std::cin, command))
|
||||||
|
command = "quit";
|
||||||
|
|
||||||
handle_command(command);
|
handle_command(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,45 +111,54 @@ namespace {
|
|||||||
// 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) {
|
void handle_command(const std::string &command) {
|
||||||
UCIInputParser uip(command);
|
|
||||||
std::string s = uip.get_next_token();
|
|
||||||
|
|
||||||
if(s == "quit") {
|
UCIInputParser uip(command);
|
||||||
|
std::string token;
|
||||||
|
|
||||||
|
uip >> token; // operator >> skips any whitespace
|
||||||
|
|
||||||
|
if (token == "quit")
|
||||||
|
{
|
||||||
OpeningBook.close();
|
OpeningBook.close();
|
||||||
stop_threads();
|
stop_threads();
|
||||||
quit_eval();
|
quit_eval();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
else if(s == "uci") {
|
else if (token == "uci")
|
||||||
std::cout << "id name " << engine_name() << std::endl;
|
{
|
||||||
std::cout << "id author Tord Romstad" << std::endl;
|
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;
|
std::cout << "uciok" << std::endl;
|
||||||
}
|
}
|
||||||
else if(s == "ucinewgame") {
|
else if (token == "ucinewgame")
|
||||||
|
{
|
||||||
TT.clear();
|
TT.clear();
|
||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
}
|
}
|
||||||
else if(s == "isready")
|
else if (token == "isready")
|
||||||
std::cout << "readyok" << std::endl;
|
std::cout << "readyok" << std::endl;
|
||||||
else if(s == "position")
|
else if (token == "position")
|
||||||
set_position(uip);
|
set_position(uip);
|
||||||
else if(s == "setoption")
|
else if (token == "setoption")
|
||||||
set_option(uip);
|
set_option(uip);
|
||||||
else if(s == "go")
|
else if (token == "go")
|
||||||
go(uip);
|
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
|
||||||
// size of the program binary.
|
// size of the program binary.
|
||||||
else if(s == "d")
|
else if (token == "d")
|
||||||
RootPosition.print();
|
RootPosition.print();
|
||||||
else if(s == "flip") {
|
else if (token == "flip")
|
||||||
|
{
|
||||||
Position p(RootPosition);
|
Position p(RootPosition);
|
||||||
RootPosition.flipped_copy(p);
|
RootPosition.flipped_copy(p);
|
||||||
}
|
}
|
||||||
else if(s == "eval") {
|
else if (token == "eval")
|
||||||
|
{
|
||||||
EvalInfo ei;
|
EvalInfo ei;
|
||||||
std::cout << "Incremental mg: " << RootPosition.mg_value()
|
std::cout << "Incremental mg: " << RootPosition.mg_value()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@@ -234,87 +168,108 @@ namespace {
|
|||||||
<< evaluate(RootPosition, ei, 0)
|
<< evaluate(RootPosition, ei, 0)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
else if(s == "key") {
|
else if (token == "key")
|
||||||
std::cout << "key: " << RootPosition.get_key()
|
{
|
||||||
|
std::cout << "key: " << std::hex << RootPosition.get_key()
|
||||||
<< " material key: " << RootPosition.get_material_key()
|
<< " material key: " << RootPosition.get_material_key()
|
||||||
<< " pawn key: " << RootPosition.get_pawn_key()
|
<< " pawn key: " << RootPosition.get_pawn_key()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
std::cout << "Unknown command: " << command << std::endl;
|
std::cout << "Unknown command: " << command << std::endl;
|
||||||
while(!uip.at_end_of_line()) {
|
while (!uip.eof())
|
||||||
std::cout << uip.get_next_token() << std::endl;
|
{
|
||||||
|
uip >> token;
|
||||||
|
std::cout << token << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// set_position() is called when Glaurung 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;
|
std::string token;
|
||||||
|
|
||||||
token = uip.get_next_token();
|
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;
|
std::string fen;
|
||||||
while(token != "moves" && !uip.at_end_of_line()) {
|
while (token != "moves" && !uip.eof())
|
||||||
token = uip.get_next_token();
|
{
|
||||||
|
uip >> token;
|
||||||
fen += token;
|
fen += token;
|
||||||
fen += ' ';
|
fen += ' ';
|
||||||
}
|
}
|
||||||
RootPosition.from_fen(fen);
|
RootPosition.from_fen(fen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!uip.at_end_of_line()) {
|
if (!uip.eof())
|
||||||
if(token != "moves")
|
{
|
||||||
token = uip.get_next_token();
|
if (token != "moves")
|
||||||
if(token == "moves") {
|
uip >> token;
|
||||||
|
if (token == "moves")
|
||||||
|
{
|
||||||
Move move;
|
Move move;
|
||||||
UndoInfo u;
|
StateInfo st;
|
||||||
while(!uip.at_end_of_line()) {
|
while (!uip.eof())
|
||||||
token = uip.get_next_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 save its content before they disappear.
|
||||||
|
RootPosition.setStartState(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// set_option() is called when Glaurung 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;
|
|
||||||
if(!uip.at_end_of_line()) {
|
std::string token, name;
|
||||||
token = uip.get_next_token();
|
|
||||||
if(token == "name" && !uip.at_end_of_line()) {
|
uip >> token;
|
||||||
std::string name = uip.get_next_token();
|
if (token == "name")
|
||||||
std::string nextToken;
|
{
|
||||||
while(!uip.at_end_of_line()
|
uip >> name;
|
||||||
&& (nextToken = uip.get_next_token()) != "value")
|
while (!uip.eof())
|
||||||
name += (" " + nextToken);
|
{
|
||||||
if(nextToken == "value")
|
uip >> token;
|
||||||
set_option_value(name, uip.get_rest_of_line());
|
if (token == "value")
|
||||||
else
|
break;
|
||||||
|
|
||||||
|
name += (" " + token);
|
||||||
|
}
|
||||||
|
if (token == "value")
|
||||||
|
{
|
||||||
|
std::getline(uip, token); // reads until end of line
|
||||||
|
set_option_value(name, token);
|
||||||
|
} else
|
||||||
push_button(name);
|
push_button(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// go() is called when Glaurung 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
|
||||||
@@ -323,69 +278,58 @@ namespace {
|
|||||||
// parameters.
|
// parameters.
|
||||||
|
|
||||||
void go(UCIInputParser &uip) {
|
void go(UCIInputParser &uip) {
|
||||||
|
|
||||||
std::string token;
|
std::string token;
|
||||||
int time[2] = {0, 0}, inc[2] = {0, 0}, movesToGo = 0, depth = 0, nodes = 0;
|
|
||||||
int moveTime = 0;
|
int time[2] = {0, 0}, inc[2] = {0, 0};
|
||||||
|
int movesToGo = 0, depth = 0, nodes = 0, moveTime = 0;
|
||||||
bool infinite = false, ponder = false;
|
bool infinite = false, ponder = false;
|
||||||
Move searchMoves[500];
|
Move searchMoves[500];
|
||||||
|
|
||||||
searchMoves[0] = MOVE_NONE;
|
searchMoves[0] = MOVE_NONE;
|
||||||
|
|
||||||
while(!uip.at_end_of_line()) {
|
while (!uip.eof())
|
||||||
token = uip.get_next_token();
|
{
|
||||||
|
uip >> token;
|
||||||
|
|
||||||
if(token == "infinite")
|
if (token == "infinite")
|
||||||
infinite = true;
|
infinite = true;
|
||||||
else if(token == "ponder")
|
else if (token == "ponder")
|
||||||
ponder = true;
|
ponder = true;
|
||||||
else if(token == "wtime") {
|
else if (token == "wtime")
|
||||||
if(!uip.at_end_of_line())
|
uip >> time[0];
|
||||||
time[0] = atoi(uip.get_next_token().c_str());
|
else if (token == "btime")
|
||||||
}
|
uip >> time[1];
|
||||||
else if(token == "btime") {
|
else if (token == "winc")
|
||||||
if(!uip.at_end_of_line())
|
uip >> inc[0];
|
||||||
time[1] = atoi(uip.get_next_token().c_str());
|
else if (token == "binc")
|
||||||
}
|
uip >> inc[1];
|
||||||
else if(token == "winc") {
|
else if (token == "movestogo")
|
||||||
if(!uip.at_end_of_line())
|
uip >> movesToGo;
|
||||||
inc[0] = atoi(uip.get_next_token().c_str());
|
else if (token == "depth")
|
||||||
}
|
uip >> depth;
|
||||||
else if(token == "binc") {
|
else if (token == "nodes")
|
||||||
if(!uip.at_end_of_line())
|
uip >> nodes;
|
||||||
inc[1] = atoi(uip.get_next_token().c_str());
|
else if (token == "movetime")
|
||||||
}
|
uip >> moveTime;
|
||||||
else if(token == "movestogo") {
|
else if (token == "searchmoves")
|
||||||
if(!uip.at_end_of_line())
|
{
|
||||||
movesToGo = atoi(uip.get_next_token().c_str());
|
|
||||||
}
|
|
||||||
else if(token == "depth") {
|
|
||||||
if(!uip.at_end_of_line())
|
|
||||||
depth = atoi(uip.get_next_token().c_str());
|
|
||||||
}
|
|
||||||
else if(token == "nodes") {
|
|
||||||
if(!uip.at_end_of_line())
|
|
||||||
nodes = atoi(uip.get_next_token().c_str());
|
|
||||||
}
|
|
||||||
else if(token == "movetime") {
|
|
||||||
if(!uip.at_end_of_line())
|
|
||||||
moveTime = atoi(uip.get_next_token().c_str());
|
|
||||||
}
|
|
||||||
else if(token == "searchmoves" && !uip.at_end_of_line()) {
|
|
||||||
int numOfMoves = 0;
|
int numOfMoves = 0;
|
||||||
while(!uip.at_end_of_line()) {
|
while (!uip.eof())
|
||||||
token = uip.get_next_token();
|
{
|
||||||
|
uip >> token;
|
||||||
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
||||||
}
|
}
|
||||||
searchMoves[numOfMoves] = MOVE_NONE;
|
searchMoves[numOfMoves] = MOVE_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(moveTime)
|
if (moveTime)
|
||||||
infinite = true; // HACK
|
infinite = true; // HACK
|
||||||
|
|
||||||
think(RootPosition, infinite, ponder, time[RootPosition.side_to_move()],
|
assert(RootPosition.is_ok());
|
||||||
inc[RootPosition.side_to_move()], movesToGo, depth, nodes, moveTime,
|
|
||||||
searchMoves);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
think(RootPosition, infinite, ponder, RootPosition.side_to_move(), time,
|
||||||
|
inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+213
-134
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -21,9 +22,12 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdarg>
|
#include <map>
|
||||||
#include <cstdio>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
@@ -34,7 +38,7 @@
|
|||||||
//// Variables
|
//// Variables
|
||||||
////
|
////
|
||||||
|
|
||||||
bool Chess960 = false;
|
bool Chess960;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -47,93 +51,136 @@ namespace {
|
|||||||
/// Types
|
/// Types
|
||||||
///
|
///
|
||||||
|
|
||||||
enum OptionType { SPIN, COMBO, CHECK, STRING, BUTTON, OPTION_TYPE_NONE};
|
enum OptionType { SPIN, COMBO, CHECK, STRING, BUTTON };
|
||||||
|
|
||||||
|
typedef std::vector<std::string> ComboValues;
|
||||||
|
|
||||||
struct Option {
|
struct Option {
|
||||||
char name[50], defaultValue[300], currentValue[300];
|
|
||||||
|
std::string name, defaultValue, currentValue;
|
||||||
OptionType type;
|
OptionType type;
|
||||||
|
size_t idx;
|
||||||
int minValue, maxValue;
|
int minValue, maxValue;
|
||||||
char comboValues[8][64];
|
ComboValues comboValues;
|
||||||
|
|
||||||
|
Option();
|
||||||
|
Option(const char* defaultValue, OptionType = STRING);
|
||||||
|
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::map<std::string, Option> Options;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Constants
|
||||||
|
///
|
||||||
|
|
||||||
|
// load_defaults populates the options map with the hard
|
||||||
|
// coded names and default values.
|
||||||
|
|
||||||
|
void load_defaults(Options& o) {
|
||||||
|
|
||||||
|
o["Use Search Log"] = Option(false);
|
||||||
|
o["Search Log Filename"] = Option("SearchLog.txt");
|
||||||
|
o["Book File"] = Option("book.bin");
|
||||||
|
o["Mobility (Middle Game)"] = Option(100, 0, 200);
|
||||||
|
o["Mobility (Endgame)"] = Option(100, 0, 200);
|
||||||
|
o["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
|
||||||
|
o["Pawn Structure (Endgame)"] = Option(100, 0, 200);
|
||||||
|
o["Passed Pawns (Middle Game)"] = Option(100, 0, 200);
|
||||||
|
o["Passed Pawns (Endgame)"] = Option(100, 0, 200);
|
||||||
|
o["Space"] = Option(100, 0, 200);
|
||||||
|
o["Aggressiveness"] = Option(100, 0, 200);
|
||||||
|
o["Cowardice"] = Option(100, 0, 200);
|
||||||
|
o["King Safety Curve"] = Option("Quadratic", COMBO);
|
||||||
|
|
||||||
|
o["King Safety Curve"].comboValues.push_back("Quadratic");
|
||||||
|
o["King Safety Curve"].comboValues.push_back("Linear"); /*, "From File"*/
|
||||||
|
|
||||||
|
o["King Safety Coefficient"] = Option(40, 1, 100);
|
||||||
|
o["King Safety X Intercept"] = Option(0, 0, 20);
|
||||||
|
o["King Safety Max Slope"] = Option(30, 10, 100);
|
||||||
|
o["King Safety Max Value"] = Option(500, 100, 1000);
|
||||||
|
o["Queen Contact Check Bonus"] = Option(3, 0, 8);
|
||||||
|
o["Queen Check Bonus"] = Option(2, 0, 4);
|
||||||
|
o["Rook Check Bonus"] = Option(1, 0, 4);
|
||||||
|
o["Bishop Check Bonus"] = Option(1, 0, 4);
|
||||||
|
o["Knight Check Bonus"] = Option(1, 0, 4);
|
||||||
|
o["Discovered Check Bonus"] = Option(3, 0, 8);
|
||||||
|
o["Mate Threat Bonus"] = Option(3, 0, 8);
|
||||||
|
o["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
|
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
|
o["Single Reply Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
|
o["Single Reply Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
|
o["Mate Threat Extension (PV nodes)"] = Option(0, 0, 2);
|
||||||
|
o["Mate Threat Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||||
|
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
|
o["Pawn Push to 7th Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
|
o["Passed Pawn Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
|
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||||
|
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
|
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
|
o["Full Depth Moves (PV nodes)"] = Option(14, 1, 100);
|
||||||
|
o["Full Depth Moves (non-PV nodes)"] = Option(3, 1, 100);
|
||||||
|
o["Threat Depth"] = Option(5, 0, 100);
|
||||||
|
o["Futility Pruning (Main Search)"] = Option(true);
|
||||||
|
o["Futility Pruning (Quiescence Search)"] = Option(true);
|
||||||
|
o["LSN filtering"] = Option(false);
|
||||||
|
o["LSN Time Margin (sec)"] = Option(4, 1, 10);
|
||||||
|
o["LSN Value Margin"] = Option(200, 100, 600);
|
||||||
|
o["Randomness"] = Option(0, 0, 10);
|
||||||
|
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||||
|
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
||||||
|
o["Threads"] = Option(1, 1, 8);
|
||||||
|
o["Hash"] = Option(32, 4, 4096);
|
||||||
|
o["Clear Hash"] = Option(false, BUTTON);
|
||||||
|
o["Ponder"] = Option(true);
|
||||||
|
o["OwnBook"] = Option(true);
|
||||||
|
o["MultiPV"] = Option(1, 1, 500);
|
||||||
|
o["UCI_ShowCurrLine"] = Option(false);
|
||||||
|
o["UCI_Chess960"] = Option(false);
|
||||||
|
|
||||||
|
// Any option should know its name so to be easily printed
|
||||||
|
for (Options::iterator it = o.begin(); it != o.end(); ++it)
|
||||||
|
it->second.name = it->first;
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Variables
|
/// Variables
|
||||||
///
|
///
|
||||||
|
|
||||||
Option Options[] = {
|
Options options;
|
||||||
{ "Use Search Log", "false", "false", CHECK, 0, 0, {""} },
|
|
||||||
{ "Search Log Filename", "SearchLog.txt", "SearchLog.txt", STRING, 0, 0, {""} },
|
// stringify converts a value of type T to a std::string
|
||||||
{ "Book File", "book.bin", "book.bin", STRING, 0, 0, {""} },
|
template<typename T>
|
||||||
{ "Mobility (Middle Game)", "100", "100", SPIN, 0, 200, {""} },
|
std::string stringify(const T& v) {
|
||||||
{ "Mobility (Endgame)", "100", "100", SPIN, 0, 200, {""} },
|
|
||||||
{ "Pawn Structure (Middle Game)", "100", "100", SPIN, 0, 200, {""} },
|
std::ostringstream ss;
|
||||||
{ "Pawn Structure (Endgame)", "100", "100", SPIN, 0, 200, {""} },
|
ss << v;
|
||||||
{ "Passed Pawns (Middle Game)", "100", "100", SPIN, 0, 200, {""} },
|
return ss.str();
|
||||||
{ "Passed Pawns (Endgame)", "100", "100", SPIN, 0, 200, {""} },
|
}
|
||||||
{ "Aggressiveness", "100", "100", SPIN, 0, 200, {""} },
|
|
||||||
{ "Cowardice", "100", "100", SPIN, 0, 200, {""} },
|
|
||||||
{ "King Safety Curve", "Quadratic", "Quadratic", COMBO, 0, 0,
|
|
||||||
{ "Quadratic", "Linear" /*, "From File"*/ } },
|
|
||||||
{ "King Safety Coefficient", "40", "40", SPIN, 1, 100 , {""} },
|
|
||||||
{ "King Safety X Intercept", "0", "0", SPIN, 0, 20, {""} },
|
|
||||||
{ "King Safety Max Slope", "30", "30", SPIN, 10, 100, {""} },
|
|
||||||
{ "King Safety Max Value", "500", "500", SPIN, 100, 1000, {""} },
|
|
||||||
{ "Queen Contact Check Bonus", "4", "4", SPIN, 0, 8, {""} },
|
|
||||||
{ "Rook Contact Check Bonus", "2", "2", SPIN, 0, 4, {""} },
|
|
||||||
{ "Queen Check Bonus", "2", "2", SPIN, 0, 4, {""} },
|
|
||||||
{ "Rook Check Bonus", "1", "1", SPIN, 0, 4, {""} },
|
|
||||||
{ "Bishop Check Bonus", "1", "1", SPIN, 0, 4, {""} },
|
|
||||||
{ "Knight Check Bonus", "1", "1", SPIN, 0, 4, {""} },
|
|
||||||
{ "Discovered Check Bonus", "3", "3", SPIN, 0, 8, {""} },
|
|
||||||
{ "Mate Threat Bonus", "3", "3", SPIN, 0, 8, {""} },
|
|
||||||
{ "Check Extension (PV nodes)", "2", "2", SPIN, 0, 2, {""} },
|
|
||||||
{ "Check Extension (non-PV nodes)", "1", "1", SPIN, 0, 2, {""} },
|
|
||||||
{ "Single Reply Extension (PV nodes)", "2", "2", SPIN, 0, 2, {""} },
|
|
||||||
{ "Single Reply Extension (non-PV nodes)", "2", "2", SPIN, 0, 2, {""} },
|
|
||||||
{ "Mate Threat Extension (PV nodes)", "0", "0", SPIN, 0, 2, {""} },
|
|
||||||
{ "Mate Threat Extension (non-PV nodes)", "0", "0", SPIN, 0, 2, {""} },
|
|
||||||
{ "Pawn Push to 7th Extension (PV nodes)", "1", "1", SPIN, 0, 2, {""} },
|
|
||||||
{ "Pawn Push to 7th Extension (non-PV nodes)", "1", "1", SPIN, 0, 2, {""} },
|
|
||||||
{ "Passed Pawn Extension (PV nodes)", "1", "1", SPIN, 0, 2, {""} },
|
|
||||||
{ "Passed Pawn Extension (non-PV nodes)", "0", "0", SPIN, 0, 2, {""} },
|
|
||||||
{ "Pawn Endgame Extension (PV nodes)", "2", "2", SPIN, 0, 2, {""} },
|
|
||||||
{ "Pawn Endgame Extension (non-PV nodes)", "2", "2", SPIN, 0, 2, {""} },
|
|
||||||
{ "Full Depth Moves (PV nodes)", "14", "14", SPIN, 1, 100, {""} },
|
|
||||||
{ "Full Depth Moves (non-PV nodes)", "3", "3", SPIN, 1, 100, {""} },
|
|
||||||
{ "Threat Depth", "5", "5", SPIN, 0, 100, {""} },
|
|
||||||
{ "Selective Plies", "7", "7", SPIN, 0, 10, {""} },
|
|
||||||
{ "Futility Pruning (Main Search)", "true", "true", CHECK, 0, 0, {""} },
|
|
||||||
{ "Futility Pruning (Quiescence Search)", "true", "true", CHECK, 0, 0, {""} },
|
|
||||||
{ "Futility Margin 0", "50", "50", SPIN, 0, 1000, {""} },
|
|
||||||
{ "Futility Margin 1", "100", "100", SPIN, 0, 1000, {""} },
|
|
||||||
{ "Futility Margin 2", "300", "300", SPIN, 0, 1000, {""} },
|
|
||||||
{ "Maximum Razoring Depth", "3", "3", SPIN, 0, 4, {""} },
|
|
||||||
{ "Razoring Margin", "300", "300", SPIN, 150, 600, {""} },
|
|
||||||
{ "Randomness", "0", "0", SPIN, 0, 10, {""} },
|
|
||||||
{ "Minimum Split Depth", "4", "4", SPIN, 4, 7, {""} },
|
|
||||||
{ "Maximum Number of Threads per Split Point", "5", "5", SPIN, 4, 8, {""} },
|
|
||||||
{ "Threads", "1", "1", SPIN, 1, 8, {""} },
|
|
||||||
{ "Hash", "32", "32", SPIN, 4, 4096, {""} },
|
|
||||||
{ "Clear Hash", "false", "false", BUTTON, 0, 0, {""} },
|
|
||||||
{ "Ponder", "true", "true", CHECK, 0, 0, {""} },
|
|
||||||
{ "OwnBook", "true", "true", CHECK, 0, 0, {""} },
|
|
||||||
{ "MultiPV", "1", "1", SPIN, 1, 500, {""} },
|
|
||||||
{ "UCI_ShowCurrLine", "false", "false", CHECK, 0, 0, {""} },
|
|
||||||
{ "UCI_Chess960", "false", "false", CHECK, 0, 0, {""} },
|
|
||||||
{ "", "", "", OPTION_TYPE_NONE, 0, 0, {""}}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
///
|
// get_option_value implements the various get_option_value_<type>
|
||||||
/// Functions
|
// functions defined later, because only the option value
|
||||||
///
|
// type changes a template seems a proper solution.
|
||||||
|
|
||||||
Option *option_with_name(const char *optionName);
|
template<typename T>
|
||||||
|
T get_option_value(const std::string& optionName) {
|
||||||
|
|
||||||
|
T ret = T();
|
||||||
|
if (options.find(optionName) == options.end())
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
std::istringstream ss(options[optionName].currentValue);
|
||||||
|
ss >> ret;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Functions
|
//// Functions
|
||||||
////
|
////
|
||||||
@@ -143,26 +190,26 @@ namespace {
|
|||||||
/// "Threads" parameter to the number of available CPU cores.
|
/// "Threads" parameter to the number of available CPU cores.
|
||||||
|
|
||||||
void init_uci_options() {
|
void init_uci_options() {
|
||||||
Option *o;
|
|
||||||
|
|
||||||
o = option_with_name("Threads");
|
load_defaults(options);
|
||||||
assert(o != NULL);
|
|
||||||
|
|
||||||
// Limit the default value of "Threads" to 7 even if we have 8 CPU cores.
|
// Limit the default value of "Threads" to 7 even if we have 8 CPU cores.
|
||||||
// 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.
|
||||||
sprintf(o->defaultValue, "%d", Min(cpu_count(), 7));
|
assert(options.find("Threads") != options.end());
|
||||||
sprintf(o->currentValue, "%d", Min(cpu_count(), 7));
|
assert(options.find("Minimum Split Depth") != options.end());
|
||||||
|
|
||||||
|
options["Threads"].defaultValue = stringify(Min(cpu_count(), 7));
|
||||||
|
options["Threads"].currentValue = stringify(Min(cpu_count(), 7));
|
||||||
|
|
||||||
// Increase the minimum split depth when the number of CPUs is big.
|
// 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
|
// It would probably be better to let this depend on the number of threads
|
||||||
// instead.
|
// instead.
|
||||||
o = option_with_name("Minimum Split Depth");
|
if (cpu_count() > 4)
|
||||||
assert(o != NULL);
|
{
|
||||||
if(cpu_count() > 4) {
|
options["Minimum Split Depth"].defaultValue = "6";
|
||||||
sprintf(o->defaultValue, "%d", 6);
|
options["Minimum Split Depth"].currentValue = "6";
|
||||||
sprintf(o->defaultValue, "%d", 6);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,30 +218,51 @@ void init_uci_options() {
|
|||||||
/// in the format defined by the UCI protocol.
|
/// in the format defined by the UCI protocol.
|
||||||
|
|
||||||
void print_uci_options() {
|
void print_uci_options() {
|
||||||
|
|
||||||
static const char optionTypeName[][16] = {
|
static const char optionTypeName[][16] = {
|
||||||
"spin", "combo", "check", "string", "button"
|
"spin", "combo", "check", "string", "button"
|
||||||
};
|
};
|
||||||
for(Option *o = Options; o->type != OPTION_TYPE_NONE; o++) {
|
|
||||||
printf("option name %s type %s", o->name, optionTypeName[o->type]);
|
// Build up a vector out of the options map and sort it according to idx
|
||||||
if(o->type != BUTTON) {
|
// field, that is the chronological insertion order in options map.
|
||||||
printf(" default %s", o->defaultValue);
|
std::vector<Option> vec;
|
||||||
if(o->type == SPIN)
|
for (Options::const_iterator it = options.begin(); it != options.end(); ++it)
|
||||||
printf(" min %d max %d", o->minValue, o->maxValue);
|
vec.push_back(it->second);
|
||||||
else if(o->type == COMBO)
|
|
||||||
for(int i = 0; strlen(o->comboValues[i]) > 0; i++)
|
std::sort(vec.begin(), vec.end());
|
||||||
printf(" var %s", o->comboValues[i]);
|
|
||||||
}
|
for (std::vector<Option>::const_iterator it = vec.begin(); it != vec.end(); ++it)
|
||||||
printf("\n");
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (it->type == SPIN)
|
||||||
|
std::cout << " min " << it->minValue
|
||||||
|
<< " max " << it->maxValue;
|
||||||
|
|
||||||
|
else if (it->type == COMBO)
|
||||||
|
for (ComboValues::const_iterator itc = it->comboValues.begin();
|
||||||
|
itc != it->comboValues.end(); ++itc)
|
||||||
|
std::cout << " var " << *itc;
|
||||||
}
|
}
|
||||||
|
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 std::string& optionName) {
|
||||||
Option *o = option_with_name(optionName.c_str());
|
|
||||||
return o != NULL && strcmp(o->currentValue, "true") == 0;
|
return get_option_value<bool>(optionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -203,31 +271,18 @@ 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 std::string& optionName) {
|
||||||
Option *o = option_with_name(optionName.c_str());
|
|
||||||
return atoi(o->currentValue);
|
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) {
|
const std::string get_option_value_string(const std::string& optionName) {
|
||||||
Option *o = option_with_name(optionName.c_str());
|
|
||||||
return o->currentValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return get_option_value<std::string>(optionName);
|
||||||
/// button_was_pressed() tests whether a UCI parameter of type "button" has
|
|
||||||
/// 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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -235,12 +290,19 @@ bool button_was_pressed(const std::string &buttonName) {
|
|||||||
/// 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 std::string& optionName,
|
||||||
const std::string &newValue) {
|
const std::string& newValue) {
|
||||||
Option *o = option_with_name(optionName.c_str());
|
|
||||||
|
|
||||||
if(o != NULL)
|
// UCI protocol uses "true" and "false" instead of "1" and "0", so convert
|
||||||
strcpy(o->currentValue, newValue.c_str());
|
// newValue according to standard C++ convention before to store it.
|
||||||
|
std::string v(newValue);
|
||||||
|
if (v == "true")
|
||||||
|
v = "1";
|
||||||
|
else if (v == "false")
|
||||||
|
v = "0";
|
||||||
|
|
||||||
|
if (options.find(optionName) != options.end())
|
||||||
|
options[optionName].currentValue = v;
|
||||||
else
|
else
|
||||||
std::cout << "No such option: " << optionName << std::endl;
|
std::cout << "No such option: " << optionName << std::endl;
|
||||||
}
|
}
|
||||||
@@ -249,22 +311,39 @@ void set_option_value(const std::string &optionName,
|
|||||||
/// 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 std::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 std::string& buttonName) {
|
||||||
|
|
||||||
|
if (!get_option_value<bool>(buttonName))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
set_option_value(buttonName, "false");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// option_with_name() tries to find a UCI option with a given
|
// Define constructors of Option class.
|
||||||
// name. It returns a pointer to the UCI option or the null pointer,
|
|
||||||
// depending on whether an option with the given name exists.
|
|
||||||
|
|
||||||
Option *option_with_name(const char *optionName) {
|
Option::Option() {} // To allow insertion in a std::map
|
||||||
for(Option *o = Options; o->type != OPTION_TYPE_NONE; o++)
|
|
||||||
if(strcmp(o->name, optionName) == 0)
|
Option::Option(const char* def, OptionType t)
|
||||||
return o;
|
: defaultValue(def), currentValue(def), type(t), idx(options.size()), minValue(0), maxValue(0) {}
|
||||||
return NULL;
|
|
||||||
}
|
Option::Option(bool def, OptionType t)
|
||||||
|
: defaultValue(stringify(def)), currentValue(stringify(def)), type(t), idx(options.size()), minValue(0), maxValue(0) {}
|
||||||
|
|
||||||
|
Option::Option(int def, int minv, int maxv)
|
||||||
|
: defaultValue(stringify(def)), currentValue(stringify(def)), type(SPIN), idx(options.size()), minValue(minv), maxValue(maxv) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|||||||
+7
-6
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -59,7 +60,7 @@ Value value_from_tt(Value v, int ply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// value_to_centipawns() converts a value from Glaurung's somewhat unusual
|
/// value_to_centipawns() converts a value from Stockfish's somewhat unusual
|
||||||
/// scale of pawn = 256 to the more conventional pawn = 100.
|
/// scale of pawn = 256 to the more conventional pawn = 100.
|
||||||
|
|
||||||
int value_to_centipawns(Value v) {
|
int value_to_centipawns(Value v) {
|
||||||
@@ -67,7 +68,7 @@ int value_to_centipawns(Value v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// value_from_centipawns() converts a centipawn value to Glaurung's internal
|
/// value_from_centipawns() converts a centipawn value to Stockfish's internal
|
||||||
/// evaluation scale. It's used when reading the values of UCI options
|
/// evaluation scale. It's used when reading the values of UCI options
|
||||||
/// containing material values (e.g. futility pruning margins).
|
/// containing material values (e.g. futility pruning margins).
|
||||||
|
|
||||||
|
|||||||
+21
-17
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Glaurung, a UCI chess playing engine.
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
|
Copyright (C) 2008 Marco Costalba
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
|
|
||||||
Glaurung 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.
|
||||||
@@ -35,7 +36,8 @@ 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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -57,17 +59,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(0x0CC);
|
||||||
const Value PawnValueEndgame = Value(0x100);
|
const Value PawnValueEndgame = Value(0x101);
|
||||||
const Value KnightValueMidgame = Value(0x340);
|
const Value KnightValueMidgame = Value(0x332);
|
||||||
const Value KnightValueEndgame = Value(0x340);
|
const Value KnightValueEndgame = Value(0x34E);
|
||||||
const Value BishopValueMidgame = Value(0x340);
|
const Value BishopValueMidgame = Value(0x345);
|
||||||
const Value BishopValueEndgame = Value(0x340);
|
const Value BishopValueEndgame = Value(0x356);
|
||||||
const Value RookValueMidgame = Value(0x505);
|
const Value RookValueMidgame = Value(0x4F8);
|
||||||
const Value RookValueEndgame = Value(0x505);
|
const Value RookValueEndgame = Value(0x500);
|
||||||
const Value QueenValueMidgame = Value(0xA00);
|
const Value QueenValueMidgame = Value(0x9D5);
|
||||||
const Value QueenValueEndgame = Value(0xA00);
|
const Value QueenValueEndgame = Value(0x9FB);
|
||||||
|
|
||||||
const Value PieceValueMidgame[17] = {
|
const Value PieceValueMidgame[17] = {
|
||||||
Value(0),
|
Value(0),
|
||||||
@@ -91,8 +95,8 @@ const Value PieceValueEndgame[17] = {
|
|||||||
|
|
||||||
/// Bonus for having the side to move
|
/// Bonus for having the side to move
|
||||||
|
|
||||||
const Value TempoValueMidgame = Value(50);
|
const Value TempoValueMidgame = Value(48);
|
||||||
const Value TempoValueEndgame = Value(20);
|
const Value TempoValueEndgame = Value(21);
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|||||||
Reference in New Issue
Block a user