mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 08:37:44 +00:00
Compare commits
459 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 378c8bdbb8 | |||
| 2e11388581 | |||
| 0a5b03af3f | |||
| fd4d800c98 | |||
| a5a98d822e | |||
| 254d995e18 | |||
| 5451687efb | |||
| b61759e907 | |||
| b508f9561c | |||
| 1b6459195c | |||
| aa88261a8f | |||
| 33682bfb98 | |||
| 66ce8ad5fd | |||
| 9afa1d7330 | |||
| 2ba47416cb | |||
| 7d4d3a2c3a | |||
| 1c50d8cbf5 | |||
| 2198cd0524 | |||
| b53239d641 | |||
| 83e829c9dc | |||
| f6981b1321 | |||
| be6fafd079 | |||
| 020dd69a35 | |||
| 70262f2027 | |||
| 196ae7c38b | |||
| be382bb0cf | |||
| d193482213 | |||
| 54f6ce70fd | |||
| 822695d4d3 | |||
| 2acda1fde3 | |||
| 28b6a457c2 | |||
| ccd6bad512 | |||
| 8a5a64eac5 | |||
| a87a1005ad | |||
| 7dd1f4a7c0 | |||
| d64ffd9621 | |||
| c769d4df84 | |||
| 03a9b3bd8d | |||
| 53239d7d3d | |||
| 3f44f5303b | |||
| 87452f3a8c | |||
| 8cfcca12d1 | |||
| 0a74c16ffe | |||
| 652199d840 | |||
| 4bc11984fc | |||
| 486c8175c4 | |||
| e0d2fdc843 | |||
| e50af36a00 | |||
| 287e2e2f74 | |||
| 86ac50403d | |||
| 0dc3b0978d | |||
| 9d79138682 | |||
| 43c186c645 | |||
| b36489742b | |||
| 452e5154cf | |||
| 07b5a28a68 | |||
| c33af32dad | |||
| 0e949ac2c9 | |||
| ba4e215493 | |||
| 043a469f83 | |||
| 21926ce2d8 | |||
| ed8286eb1b | |||
| 3ac47c84d3 | |||
| 741523eda8 | |||
| 04eb87fd08 | |||
| 323925b91c | |||
| 5ba4373522 | |||
| 3fd7e37868 | |||
| 9d95d43c57 | |||
| e385f194e9 | |||
| 7b4c9852e1 | |||
| bf485f4aff | |||
| a2b8f91cfa | |||
| d5f883ab29 | |||
| 92c39522b1 | |||
| 5ef94eb970 | |||
| 002bf4d8db | |||
| 5ea327d924 | |||
| fe60caba94 | |||
| 7aa7dfd4df | |||
| fa5b0936ee | |||
| 45e254a0a0 | |||
| 444d99b6d2 | |||
| e10255339f | |||
| daf0fe1f57 | |||
| 4d511512d2 | |||
| 9c35b9365d | |||
| 01d97521fd | |||
| d482e3a890 | |||
| 9001f55147 | |||
| ae6a4ebf1f | |||
| 232c50fed0 | |||
| c3e964f35e | |||
| df6cb446ea | |||
| bdeda52efd | |||
| 5837228aa0 | |||
| 2783203428 | |||
| 66c5eaebd8 | |||
| 44236f4ed9 | |||
| 5410424e3d | |||
| 750dfa0521 | |||
| dbc984d9f8 | |||
| f731bcadb7 | |||
| b40e45c1cc | |||
| 53c2d9df5e | |||
| b24bd762b2 | |||
| 722e1e0da6 | |||
| 973ede008a | |||
| a6ae2d3a31 | |||
| 272e4d1ac7 | |||
| e551afbab7 | |||
| d31f068312 | |||
| 377d77dbe9 | |||
| 36a93d90f7 | |||
| 0371a8f8c4 | |||
| c8e5384c3a | |||
| 802fca6fdd | |||
| 01b6cdb76b | |||
| c0cb713a00 | |||
| 6d24ef8585 | |||
| 69eb391cd7 | |||
| 7e897a64f2 | |||
| 05513a6641 | |||
| fa1e3427bd | |||
| 77342126d8 | |||
| 612d93234b | |||
| 0149a4c3d6 | |||
| 336901fdb0 | |||
| 3cb0200459 | |||
| 2c237da546 | |||
| b73016bb41 | |||
| 27ba611a3d | |||
| f907d5b7d9 | |||
| ebc563059c | |||
| 659990b43f | |||
| 6d89d0b64a | |||
| 1781439fc2 | |||
| ecd3218b6b | |||
| 24df0f72c0 | |||
| 1d31065e1d | |||
| c216dcbe7b | |||
| cf893bcded | |||
| 732aa34e3d | |||
| 862934d7ae | |||
| 7edd1f7ccd | |||
| 0c1f119069 | |||
| 99d914985f | |||
| 6b4959e3e0 | |||
| ae97941628 | |||
| 69ec09bd4b | |||
| 25296547d0 | |||
| 321a27fbe3 | |||
| 8b15961349 | |||
| e9f26cccdd | |||
| a18c2c2c3f | |||
| b948b037a5 | |||
| e06a117d5e | |||
| b1b19343cd | |||
| 49a9d4cf99 | |||
| d06a8d0c18 | |||
| b48439e906 | |||
| 6b9a22b40d | |||
| 0868de705d | |||
| 9da3b44ddc | |||
| ced29248c9 | |||
| 2d96e8fbe9 | |||
| d4b9ee0f1d | |||
| 57a3334322 | |||
| 9d3ed9ed2e | |||
| 06175c6055 | |||
| 1454831220 | |||
| b258b4fee7 | |||
| 72a501c6fe | |||
| 35b77b120e | |||
| ebe021f6a5 | |||
| 06eba14dc9 | |||
| c5de4080db | |||
| 3b7c1a17e4 | |||
| afe75571d8 | |||
| 30c583204f | |||
| 352bd6f5aa | |||
| c80d52c845 | |||
| c076216a32 | |||
| a6d6a2c2fa | |||
| d01b66ae8f | |||
| c3d2e6aba9 | |||
| d490bb9973 | |||
| cc76524c2e | |||
| 3627348e2b | |||
| 728ce2195c | |||
| 1810c4d758 | |||
| 8f7e032b8c | |||
| f1e3dfea74 | |||
| 9f48e1ec15 | |||
| eefbe967c2 | |||
| c243cd5f4a | |||
| 05cf45f2d1 | |||
| faedcf08a8 | |||
| 83fb4547f6 | |||
| 1e814e0ca0 | |||
| e0d91f4c44 | |||
| a753e20bd4 | |||
| 5205d44f87 | |||
| 0553b46829 | |||
| ddecdc97d7 | |||
| fa24cc25a4 | |||
| 5254a6040c | |||
| 471f7a1b5c | |||
| 58c181de9a | |||
| cf4a38e0cb | |||
| 9eed183489 | |||
| 243a9f5484 | |||
| 9f8f093fd6 | |||
| de02768af7 | |||
| 99cd513264 | |||
| d2971f3fca | |||
| d40351243b | |||
| d8f683760c | |||
| 332b5013b5 | |||
| 34e47ca87d | |||
| e0504ab876 | |||
| d9dd520896 | |||
| 394e9cd892 | |||
| ba15781be8 | |||
| d39ffbeea6 | |||
| 3ab3e55bb5 | |||
| 1c316c41bb | |||
| 90b052462c | |||
| 8b2c81d3ea | |||
| fe99de20ff | |||
| 6b16ebc825 | |||
| e3a8b8bcff | |||
| 1052ce74f6 | |||
| e258c5a779 | |||
| b7b9d7c9c7 | |||
| 881a9dfb0a | |||
| 43f6b33e50 | |||
| ab4f498bbc | |||
| 8765f9ce16 | |||
| 3728e833aa | |||
| af7412e58a | |||
| 1ceaea701b | |||
| f72b7dc99a | |||
| ee22b61f5e | |||
| 8c61bbda54 | |||
| 847bc0e80f | |||
| 1b62d413c1 | |||
| 589049a0e5 | |||
| a47bbca0ea | |||
| 0d33466bcd | |||
| 46d066b041 | |||
| bf8b45fe63 | |||
| e70da0d2eb | |||
| 1e76ba7cec | |||
| 535435b7fc | |||
| 7a3844e6ef | |||
| fbb2ffacfd | |||
| 8f30d233f8 | |||
| ec83e8a72c | |||
| e7289465b9 | |||
| 8ceb1ff53b | |||
| 2ec626ddae | |||
| 9eccba7761 | |||
| ca464fc89e | |||
| 0d9a9f5e98 | |||
| 6036303bb6 | |||
| b5d10d17c2 | |||
| 797602938d | |||
| 76d113f5f0 | |||
| 18df1698f4 | |||
| 7f4de0196b | |||
| cddc8d4546 | |||
| a90fc4c877 | |||
| e6c2899020 | |||
| de269ee18e | |||
| dc4655e1f9 | |||
| 0fa80c9ba3 | |||
| 61c727fdcb | |||
| 876f07cbee | |||
| f5d3f0ded6 | |||
| e4659693de | |||
| 52cb348023 | |||
| 0d669be76c | |||
| 23f384cac3 | |||
| b915fdc889 | |||
| 67d19447f4 | |||
| d4abf54247 | |||
| 445aade39c | |||
| f3cd7002aa | |||
| c43146edb7 | |||
| c0bb041539 | |||
| 369eff437c | |||
| 344616e917 | |||
| 40b1b27178 | |||
| bf51b4796a | |||
| e18e557e77 | |||
| 818b4a126d | |||
| e77f38c431 | |||
| e18321f55a | |||
| ca67752645 | |||
| 3686e719a1 | |||
| 9893e7fd53 | |||
| 99f3ad6858 | |||
| e27d3bb884 | |||
| 16e1881126 | |||
| e1f600f186 | |||
| a3fe80c36a | |||
| fdf3a51c68 | |||
| e61f7b1e6d | |||
| f799610d4b | |||
| 073eed590e | |||
| 1e586288ca | |||
| 0162fb83c2 | |||
| ab26c61971 | |||
| eccccba0ce | |||
| b77bae0529 | |||
| 7ae3c05795 | |||
| 351844061e | |||
| 8662bdfa12 | |||
| 28240d375c | |||
| 943ae89be1 | |||
| 4b0043ae7c | |||
| 92f01aa2bd | |||
| ea41f18e6e | |||
| 057d710fc2 | |||
| 01f2466f6e | |||
| 5c58d1f5cb | |||
| b96dd754ed | |||
| 01ee509a5c | |||
| 95ad2b51b7 | |||
| 438805aee8 | |||
| ace8e951d7 | |||
| 90ce24b11e | |||
| 4c95edddbf | |||
| 602d7fbb07 | |||
| d909d10f33 | |||
| 38428ada54 | |||
| e340ce221c | |||
| ca6c9f85a5 | |||
| c5828c4eba | |||
| d37dfe9ae4 | |||
| 13b4444d9e | |||
| 7f2eb10e93 | |||
| 5cffc032da | |||
| 2731bbaf6b | |||
| 6aa9308f08 | |||
| b4f6728e61 | |||
| 2b57b61cb1 | |||
| 1ee2838214 | |||
| 0b944c7186 | |||
| 805afcbf3d | |||
| 4c5cbb1b14 | |||
| 133808851d | |||
| 9bd856e28e | |||
| 3e739f883f | |||
| 0b4f6e562b | |||
| 5596492f6e | |||
| 8493c8c6b8 | |||
| e3af492142 | |||
| 9585f8ef58 | |||
| 7396c08b79 | |||
| 3d10cfcdd2 | |||
| 8abb98455f | |||
| b3525fa9ea | |||
| 85924db496 | |||
| f2f3a06a1a | |||
| 714329dbdc | |||
| 76971d8acb | |||
| f619f1d38c | |||
| 82d02a3133 | |||
| 1d09ee70f7 | |||
| eb20a87c67 | |||
| ade3bb9a4e | |||
| 716a145a6c | |||
| 190d2ea4bc | |||
| c2c0e6b07d | |||
| c94145b65c | |||
| 09efbf915e | |||
| 6d58bf777c | |||
| 1c0c4db677 | |||
| 8e45e70e55 | |||
| 126036abb0 | |||
| ca14345ba2 | |||
| 7d2a79f037 | |||
| 7c5d724724 | |||
| 6fed8ff22a | |||
| 0c076f1136 | |||
| e48c7547c5 | |||
| 6e2ca97d93 | |||
| 5f096e9bef | |||
| 20023ac9b8 | |||
| 3549d98d07 | |||
| 07b247f943 | |||
| abac509ccb | |||
| ab0f4c0353 | |||
| 71bfbb22fc | |||
| 7cb8cbb403 | |||
| 0784bd542b | |||
| 16c603ce9b | |||
| 969982406c | |||
| 4b9ed6566a | |||
| 5e4cd3fc0d | |||
| 5486911e01 | |||
| 3487eb9f9e | |||
| dc0030de4f | |||
| 2dd24dc4e6 | |||
| 8f934dff9a | |||
| 2694ef23c3 | |||
| e082112cfe | |||
| 4048bae47b | |||
| c737062436 | |||
| 94e41274bb | |||
| ec6aab0136 | |||
| 7eaea3848c | |||
| ee7a68ea5f | |||
| d30994ecd5 | |||
| bd04f9a0f1 | |||
| 1cbba8d6fa | |||
| e9e5f72c74 | |||
| 29b5842da8 | |||
| 8fb45caade | |||
| 900279a06f | |||
| d5b24ad77b | |||
| f256388e08 | |||
| db4b0d8b7d | |||
| 24dac5ccd3 | |||
| 8788612828 | |||
| 5d1644ba69 | |||
| 60590577f2 | |||
| 04be84e0e2 | |||
| 647402ff79 | |||
| a273b6ef8c | |||
| e1a7d135b2 | |||
| c1be0c68c7 | |||
| c13052f344 | |||
| 8de29390f2 | |||
| 45a309d92e | |||
| d5ba8e827d | |||
| 77fa960f89 | |||
| bfe9044ad9 | |||
| 744ed85a4d | |||
| 56dd58e6f9 | |||
| 4f6aa15228 | |||
| aedebe35cf | |||
| 9a10313a9d | |||
| 8c3a5bbc52 | |||
| 28933a580e | |||
| 12eb345ebd | |||
| ebec2fa48e | |||
| 552b3ccb66 | |||
| 356147d99a | |||
| 89723339d9 | |||
| 74e2fa97b7 | |||
| dcd8ce7094 | |||
| 4d1220d672 | |||
| aa31f7f096 | |||
| 1de97337c2 | |||
| 9eceb894ac | |||
| 5972c4a678 |
+35
-11
@@ -1,4 +1,6 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
|
sudo: required
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
@@ -7,25 +9,25 @@ matrix:
|
|||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
packages: ['g++-4.8']
|
packages: ['g++-6', 'g++-6-multilib', 'g++-multilib', 'valgrind', 'expect']
|
||||||
env:
|
env:
|
||||||
- COMPILER=g++-4.8
|
- COMPILER=g++-6
|
||||||
- COMP=gcc
|
- COMP=gcc
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
packages: ['clang-3.7']
|
packages: ['clang', 'g++-multilib', 'valgrind', 'expect']
|
||||||
env:
|
env:
|
||||||
- COMPILER=clang++-3.7
|
- COMPILER=clang++
|
||||||
- COMP=clang
|
- COMP=clang
|
||||||
|
|
||||||
- os: osx
|
- os: osx
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
env:
|
env:
|
||||||
- COMPILER=g++-4.8
|
- COMPILER=g++
|
||||||
- COMP=gcc
|
- COMP=gcc
|
||||||
|
|
||||||
- os: osx
|
- os: osx
|
||||||
@@ -42,8 +44,30 @@ before_script:
|
|||||||
- cd src
|
- cd src
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- make clean && make build ARCH=x86-64 && ./stockfish bench 2>&1 >/dev/null | grep 'Nodes searched' | tee bench1
|
# Obtain bench reference from git log
|
||||||
- make clean && make build ARCH=x86-32 && ./stockfish bench 2>&1 >/dev/null | grep 'Nodes searched' | tee bench2
|
- git log HEAD | grep "\b[Bb]ench[ :]\+[0-9]\{7\}" | head -n 1 | sed "s/[^0-9]*\([0-9][0-9]*\)/\1/g" > git_sig
|
||||||
- echo "Checking for same bench numbers..."
|
- export benchref=$(cat git_sig)
|
||||||
- diff bench1 bench2 > result
|
- echo "Reference bench:" $benchref
|
||||||
- test ! -s result
|
#
|
||||||
|
# Verify bench number against various builds
|
||||||
|
- export CXXFLAGS=-Werror
|
||||||
|
- make clean && make -j2 ARCH=x86-64 optimize=no debug=yes build && ../tests/signature.sh $benchref
|
||||||
|
- make clean && make -j2 ARCH=x86-32 optimize=no debug=yes build && ../tests/signature.sh $benchref
|
||||||
|
- make clean && make -j2 ARCH=x86-32 build && ../tests/signature.sh $benchref
|
||||||
|
- make clean && make -j2 ARCH=x86-64 build && ../tests/signature.sh $benchref
|
||||||
|
#
|
||||||
|
# Check perft and reproducible search
|
||||||
|
- ../tests/perft.sh
|
||||||
|
- ../tests/reprosearch.sh
|
||||||
|
#
|
||||||
|
# Valgrind
|
||||||
|
#
|
||||||
|
- export CXXFLAGS=-O1
|
||||||
|
- if [ -x "$(command -v valgrind )" ]; then make clean && make -j2 ARCH=x86-64 debug=yes optimize=no build > /dev/null && ../tests/instrumented.sh --valgrind; fi
|
||||||
|
- if [ -x "$(command -v valgrind )" ]; then ../tests/instrumented.sh --valgrind-thread; fi
|
||||||
|
#
|
||||||
|
# Sanitizer
|
||||||
|
#
|
||||||
|
# Use g++-6 as a proxy for having sanitizers, might need revision as they become available for more recent versions of clang/gcc
|
||||||
|
- if [[ "$COMPILER" == "g++-6" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-undefined; fi
|
||||||
|
- if [[ "$COMPILER" == "g++-6" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi
|
||||||
|
|||||||
@@ -1,98 +1,98 @@
|
|||||||
# Generated with git shortlog -sn | cut -c8-', which sorts by commits (manually ordered the first four authors)
|
# Generated with 'git shortlog -sn | cut -c8-', which sorts by commits, manually ordered the first four authors, merged duplicates
|
||||||
|
|
||||||
Tord Romstad
|
Tord Romstad
|
||||||
Marco Costalba
|
Marco Costalba (mcostalba)
|
||||||
Joona Kiiski
|
Joona Kiiski (zamar)
|
||||||
Gary Linscott
|
Gary Linscott (glinscott)
|
||||||
lucasart
|
Lucas Braesch (lucasart)
|
||||||
|
Bill Henry (VoyagerOne)
|
||||||
mstembera
|
mstembera
|
||||||
Lucas Braesch
|
Stéphane Nicolet (Stephane Nicolet, snicolet)
|
||||||
Stefan Geschwentner
|
Stefan Geschwentner
|
||||||
|
Alain SAVARD (Rocky640)
|
||||||
|
Jörg Oster (Joerg Oster, joergoster)
|
||||||
Reuven Peleg
|
Reuven Peleg
|
||||||
Chris Caino
|
Chris Caino (Chris Cain, ceebo)
|
||||||
joergoster
|
|
||||||
VoyagerOne
|
|
||||||
Jean-Francois Romang
|
Jean-Francois Romang
|
||||||
homoSapiensSapiens
|
homoSapiensSapiens
|
||||||
Alain SAVARD
|
|
||||||
Arjun Temurnikar
|
|
||||||
Stéphane Nicolet
|
|
||||||
Uri Blass
|
|
||||||
jundery
|
|
||||||
Ralph Stößer
|
|
||||||
Ajith
|
|
||||||
Leonid Pechenik
|
Leonid Pechenik
|
||||||
Stefano80
|
Stefano Cardanobile (Stefano80)
|
||||||
Tom Vijlbrief
|
Arjun Temurnikar
|
||||||
|
Uri Blass (uriblass)
|
||||||
|
jundery
|
||||||
|
Ajith (ajithcj)
|
||||||
hxim
|
hxim
|
||||||
snicolet
|
Ralph Stößer (Ralph Stoesser)
|
||||||
Daylen Yang
|
Guenther Demetz
|
||||||
Henri Wiechers
|
Jonathan Calovski (Mysseno)
|
||||||
Jonathan Calovski
|
Tom Vijlbrief
|
||||||
mbootsector
|
mbootsector
|
||||||
|
Daylen Yang
|
||||||
|
ElbertoOne
|
||||||
|
Henri Wiechers
|
||||||
|
loco-loco
|
||||||
|
Joost VandeVondele (Joost Vandevondele)
|
||||||
|
Ronald de Man (syzygy)
|
||||||
|
DU-jdto
|
||||||
David Zar
|
David Zar
|
||||||
Eelco de Groot
|
Eelco de Groot
|
||||||
Jerry Donald
|
Jerry Donald
|
||||||
Joerg Oster
|
NicklasPersson
|
||||||
Jörg Oster
|
|
||||||
Ryan Schmitt
|
Ryan Schmitt
|
||||||
mcostalba
|
|
||||||
Alexander Kure
|
Alexander Kure
|
||||||
Dan Schmidt
|
Dan Schmidt
|
||||||
H. Felix Wittmann
|
H. Felix Wittmann
|
||||||
|
Jacques
|
||||||
Joseph R. Prostko
|
Joseph R. Prostko
|
||||||
Justin Blanchard
|
Justin Blanchard
|
||||||
Linus Arver
|
Linus Arver
|
||||||
NicklasPersson
|
Luca Brivio
|
||||||
|
Lyudmil Antonov
|
||||||
Rodrigo Exterckötter Tjäder
|
Rodrigo Exterckötter Tjäder
|
||||||
Ron Britvich
|
Ron Britvich
|
||||||
Ronald de Man
|
|
||||||
RyanTaker
|
RyanTaker
|
||||||
Vince Negri
|
Vince Negri
|
||||||
ceebo
|
erbsenzaehler
|
||||||
jhellis3
|
Joseph Hellis (jhellis3)
|
||||||
ppigazzini
|
|
||||||
shane31
|
shane31
|
||||||
|
Andrew Grant
|
||||||
Andy Duplain
|
Andy Duplain
|
||||||
Auguste Pop
|
Auguste Pop
|
||||||
Balint Pfliegel
|
Balint Pfliegel
|
||||||
Chris Cain
|
|
||||||
DU-jdto
|
|
||||||
Dariusz Orzechowski
|
Dariusz Orzechowski
|
||||||
DiscanX
|
DiscanX
|
||||||
Ernesto Gatti
|
Ernesto Gatti
|
||||||
Gregor Cramer
|
Gregor Cramer
|
||||||
Guenther Demetz
|
Hiraoka Takuya (HiraokaTakuya)
|
||||||
Hiraoka Takuya
|
|
||||||
Hongzhi Cheng
|
Hongzhi Cheng
|
||||||
Joseph Hellis
|
IIvec
|
||||||
Kelly Wilson
|
Kelly Wilson
|
||||||
Ken T Takusagawa
|
Ken T Takusagawa
|
||||||
Kojirion
|
Kojirion
|
||||||
Luca Brivio
|
Krgp
|
||||||
Matt Sullivan
|
Matt Sullivan
|
||||||
Matthew Lai
|
Matthew Lai
|
||||||
Matthew Sullivan
|
Matthew Sullivan
|
||||||
Michel Van den Bergh
|
Michel Van den Bergh
|
||||||
Mysseno
|
Niklas Fiekas
|
||||||
Oskar Werkelin Ahlin
|
Oskar Werkelin Ahlin
|
||||||
Pablo Vazquez
|
Pablo Vazquez
|
||||||
Pascal Romaret
|
Pascal Romaret
|
||||||
Ralph Stoesser
|
|
||||||
Ralph Stößer
|
|
||||||
Raminder Singh
|
Raminder Singh
|
||||||
Richard Lloyd
|
Richard Lloyd
|
||||||
Ryan Takker
|
Ryan Takker
|
||||||
Stephane Nicolet
|
|
||||||
Thanar2
|
Thanar2
|
||||||
absimaldata
|
absimaldata
|
||||||
|
atumanian
|
||||||
braich
|
braich
|
||||||
|
fanon
|
||||||
|
gamander
|
||||||
gguliash
|
gguliash
|
||||||
kinderchocolate
|
kinderchocolate
|
||||||
loco-loco
|
|
||||||
pellanda
|
pellanda
|
||||||
|
ppigazzini
|
||||||
renouve
|
renouve
|
||||||
sf-x
|
sf-x
|
||||||
thaspel
|
thaspel
|
||||||
unknown
|
unknown
|
||||||
uriblass
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
### Overview
|
### Overview
|
||||||
|
|
||||||
[](https://travis-ci.org/official-stockfish/Stockfish)
|
[](https://travis-ci.org/official-stockfish/Stockfish)
|
||||||
|
[](https://ci.appveyor.com/project/mcostalba/stockfish)
|
||||||
|
|
||||||
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
|
||||||
not a complete chess program and requires some UCI-compatible GUI
|
not a complete chess program and requires some UCI-compatible GUI
|
||||||
@@ -9,7 +10,7 @@ Partner or Fritz) in order to be used comfortably. Read the
|
|||||||
documentation for your GUI of choice for information about how to use
|
documentation for your GUI of choice for information about how to use
|
||||||
Stockfish with it.
|
Stockfish with it.
|
||||||
|
|
||||||
This version of Stockfish supports up to 128 cores. The engine defaults
|
This version of Stockfish supports up to 512 cores. The engine defaults
|
||||||
to one search thread, so it is therefore recommended to inspect the value of
|
to one search thread, so it is therefore recommended to inspect the value of
|
||||||
the *Threads* UCI parameter, and to make sure it equals the number of CPU
|
the *Threads* UCI parameter, and to make sure it equals the number of CPU
|
||||||
cores on your computer.
|
cores on your computer.
|
||||||
@@ -95,6 +96,14 @@ compile (for instance with Microsoft MSVC) you need to manually
|
|||||||
set/unset some switches in the compiler command line; see file *types.h*
|
set/unset some switches in the compiler command line; see file *types.h*
|
||||||
for a quick reference.
|
for a quick reference.
|
||||||
|
|
||||||
|
### Resource For Understanding the Code Base
|
||||||
|
|
||||||
|
* [Chessprogramingwiki](https://chessprogramming.wikispaces.com) has good overall chess engines explanations
|
||||||
|
(techniques used here are well explained like hash maps etc), it was
|
||||||
|
also recommended by the [support at stockfish.](http://support.stockfishchess.org/discussions/questions/1132-how-to-understand-stockfish-sources)
|
||||||
|
|
||||||
|
* [Here](https://chessprogramming.wikispaces.com/Stockfish) you can find a set of features and techniques used by stockfish and each of them is explained at the wiki, however, it's a generic way rather than focusing on stockfish's own implementation, but it will still help you.
|
||||||
|
|
||||||
|
|
||||||
### Terms of use
|
### Terms of use
|
||||||
|
|
||||||
@@ -111,4 +120,4 @@ to where the source code can be found. If you make any changes to the
|
|||||||
source code, these changes must also be made available under the GPL.
|
source code, these changes must also be made available under the GPL.
|
||||||
|
|
||||||
For full details, read the copy of the GPL found in the file named
|
For full details, read the copy of the GPL found in the file named
|
||||||
*Copying.txt*
|
*Copying.txt*.
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
Contributors with >10,000 CPU hours as of January 23, 2018
|
||||||
|
Thank you!
|
||||||
|
|
||||||
|
Username CPU Hours Games played
|
||||||
|
mibere 518300 41835669
|
||||||
|
crunchy 375564 29121434
|
||||||
|
cw 371664 28748719
|
||||||
|
fastgm 299773 20765374
|
||||||
|
JojoM 220590 15299913
|
||||||
|
glinscott 204517 13932027
|
||||||
|
bking_US 187568 12233168
|
||||||
|
ctoks 169342 13475495
|
||||||
|
spams 149531 10940322
|
||||||
|
Thanar 137015 11714855
|
||||||
|
velislav 127305 10047749
|
||||||
|
vdbergh 121741 9056874
|
||||||
|
malala 117291 8126488
|
||||||
|
vdv 117218 8289983
|
||||||
|
leszek 114825 8331897
|
||||||
|
dsmith 114010 7622414
|
||||||
|
CSU_Dynasty 113516 9582758
|
||||||
|
sqrt2 112407 8782694
|
||||||
|
marrco 111143 8222921
|
||||||
|
drabel 108168 9061580
|
||||||
|
BrunoBanani 104938 7448565
|
||||||
|
Data 94621 8433010
|
||||||
|
CoffeeOne 90394 3964243
|
||||||
|
BRAVONE 80811 5341681
|
||||||
|
psk 77195 6156031
|
||||||
|
brabos 70284 5685893
|
||||||
|
Fisherman 66650 5572406
|
||||||
|
nssy 64587 5369140
|
||||||
|
Pking_cda 64499 5704075
|
||||||
|
sterni1971 63488 5070004
|
||||||
|
mgrabiak 62385 5420812
|
||||||
|
tvijlbrief 58957 4154234
|
||||||
|
jromang 58854 4704502
|
||||||
|
dv8silencer 57421 3961325
|
||||||
|
sunu 56620 4609155
|
||||||
|
tinker 56039 4204914
|
||||||
|
biffhero 55743 4810039
|
||||||
|
teddybaer 52982 4740444
|
||||||
|
bcross 50548 5071599
|
||||||
|
renouve 50318 3544864
|
||||||
|
Freja 50296 3805120
|
||||||
|
robnjr 47504 4131742
|
||||||
|
eva42 46542 4044694
|
||||||
|
davar 46538 4030604
|
||||||
|
finfish 46244 3481661
|
||||||
|
rap 46201 3219490
|
||||||
|
ttruscott 45037 3645430
|
||||||
|
solarlight 44155 4074841
|
||||||
|
TueRens 41372 3891510
|
||||||
|
ElbertoOne 41321 3920894
|
||||||
|
Antihistamine 39218 2792761
|
||||||
|
mhunt 38991 2697512
|
||||||
|
bigpen0r 37820 3149955
|
||||||
|
homyur 35569 3009637
|
||||||
|
VoyagerOne 35137 3302650
|
||||||
|
mhoram 34770 2684128
|
||||||
|
racerschmacer 33022 3231055
|
||||||
|
speedycpu 32043 2531964
|
||||||
|
EthanOConnor 31638 2143255
|
||||||
|
oryx 29574 2767730
|
||||||
|
Pyafue 28885 1986098
|
||||||
|
jkiiski 28014 1923255
|
||||||
|
Garf 27579 2770144
|
||||||
|
slakovv 27017 2031279
|
||||||
|
Bobo1239 27000 2488707
|
||||||
|
pb00067 26817 2306694
|
||||||
|
robal 26337 2316795
|
||||||
|
hyperbolic.tom 26248 2200777
|
||||||
|
rkl 24898 2236013
|
||||||
|
SC 23988 2126825
|
||||||
|
nabildanial 23524 1586321
|
||||||
|
achambord 23495 1942546
|
||||||
|
Sharaf_DG 22975 1790697
|
||||||
|
chriswk 22876 1947731
|
||||||
|
anst 22568 2013953
|
||||||
|
Patrick_G 22435 1682293
|
||||||
|
cuistot 22201 1383031
|
||||||
|
gri 21901 1820968
|
||||||
|
Prcuvu 21182 1890546
|
||||||
|
Zirie 21171 1493227
|
||||||
|
JanErik 20596 1791991
|
||||||
|
Isidor 20560 1730290
|
||||||
|
xor12 20535 1819280
|
||||||
|
team-oh 20364 1653708
|
||||||
|
nesoneg 20264 1493435
|
||||||
|
rstoesser 19802 1335177
|
||||||
|
grandphish2 19402 1834196
|
||||||
|
sg4032 18427 1671742
|
||||||
|
dew 18263 1423326
|
||||||
|
ianh2105 18133 1668562
|
||||||
|
MazeOfGalious 18022 1644593
|
||||||
|
ville 17900 1539130
|
||||||
|
j3corre 17607 975954
|
||||||
|
eudhan 17502 1424648
|
||||||
|
iisiraider 17175 1118788
|
||||||
|
jundery 17172 1115855
|
||||||
|
SFTUser 16635 1363975
|
||||||
|
purplefishies 16621 1106850
|
||||||
|
DragonLord 16599 1252348
|
||||||
|
chris 15274 1575333
|
||||||
|
xoto 14900 1486261
|
||||||
|
dju 14861 901552
|
||||||
|
dex 14647 1228763
|
||||||
|
nordlandia 14551 1369718
|
||||||
|
ronaldjerum 14361 1210607
|
||||||
|
OssumOpossum 14149 1029265
|
||||||
|
IgorLeMasson 13844 1228391
|
||||||
|
enedene 13762 935618
|
||||||
|
ako027ako 13442 1250249
|
||||||
|
AdrianSA 13324 924980
|
||||||
|
bpfliegel 13318 886523
|
||||||
|
ncfish1 13056 932344
|
||||||
|
wei 12863 1369596
|
||||||
|
jpulman 12776 854815
|
||||||
|
horst.prack 12436 1151505
|
||||||
|
joster 12424 986622
|
||||||
|
cisco2015 12265 1205019
|
||||||
|
fatmurphy 12015 901134
|
||||||
|
modolief 11228 926456
|
||||||
|
Dark_wizzie 11214 1017910
|
||||||
|
mschmidt 10973 818594
|
||||||
|
eastorwest 10970 1117836
|
||||||
|
infinity 10762 746397
|
||||||
|
SapphireBrand 10692 1024604
|
||||||
|
Thomas A. 10553 736094
|
||||||
|
pgontarz 10294 878746
|
||||||
|
Andrew Grant 10195 922933
|
||||||
|
stocky 10083 718114
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
version: 1.0.{build}
|
||||||
|
clone_depth: 50
|
||||||
|
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- appveyor
|
||||||
|
|
||||||
|
# Operating system (build VM template)
|
||||||
|
os: Visual Studio 2015
|
||||||
|
|
||||||
|
# Build platform, i.e. x86, x64, AnyCPU. This setting is optional.
|
||||||
|
platform:
|
||||||
|
- x86
|
||||||
|
- x64
|
||||||
|
|
||||||
|
# build Configuration, i.e. Debug, Release, etc.
|
||||||
|
configuration:
|
||||||
|
- Debug
|
||||||
|
- Release
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
# The build fail immediately once one of the job fails
|
||||||
|
fast_finish: true
|
||||||
|
|
||||||
|
# Scripts that are called at very beginning, before repo cloning
|
||||||
|
init:
|
||||||
|
- cmake --version
|
||||||
|
- msbuild /version
|
||||||
|
|
||||||
|
before_build:
|
||||||
|
- ps: |
|
||||||
|
# Get sources
|
||||||
|
$src = get-childitem -Path *.cpp -Recurse | select -ExpandProperty FullName
|
||||||
|
$src = $src -join ' '
|
||||||
|
$src = $src.Replace("\", "/")
|
||||||
|
|
||||||
|
# Build CMakeLists.txt
|
||||||
|
$t = 'cmake_minimum_required(VERSION 3.8)',
|
||||||
|
'project(Stockfish)',
|
||||||
|
'set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/src)',
|
||||||
|
'set(source_files', $src, ')',
|
||||||
|
'add_executable(stockfish ${source_files})'
|
||||||
|
|
||||||
|
# Write CMakeLists.txt withouth BOM
|
||||||
|
$MyPath = (Get-Item -Path "." -Verbose).FullName + '\CMakeLists.txt'
|
||||||
|
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
|
||||||
|
[System.IO.File]::WriteAllLines($MyPath, $t, $Utf8NoBomEncoding)
|
||||||
|
|
||||||
|
# Obtain bench reference from git log
|
||||||
|
$b = git log HEAD | sls "\b[Bb]ench[ :]+[0-9]{7}" | select -first 1
|
||||||
|
$bench = $b -match '\D+(\d+)' | % { $matches[1] }
|
||||||
|
Write-Host "Reference bench:" $bench
|
||||||
|
$g = "Visual Studio 14 2015"
|
||||||
|
If (${env:PLATFORM} -eq 'x64') { $g = $g + ' Win64' }
|
||||||
|
cmake -G "${g}" .
|
||||||
|
Write-Host "Generated files for: " $g
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- cmake --build . --config %CONFIGURATION% -- /verbosity:minimal
|
||||||
|
|
||||||
|
before_test:
|
||||||
|
- cd src/%CONFIGURATION%
|
||||||
|
- ps: |
|
||||||
|
# Verify bench number
|
||||||
|
./stockfish bench 2> out.txt 1> null
|
||||||
|
$s = (gc "./out.txt" | out-string)
|
||||||
|
$r = ($s -match 'Nodes searched \D+(\d+)' | % { $matches[1] })
|
||||||
|
Write-Host "Engine bench:" $r
|
||||||
|
Write-Host "Reference bench:" $bench
|
||||||
|
If ($r -ne $bench) { exit 1 }
|
||||||
+127
-90
@@ -1,7 +1,7 @@
|
|||||||
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
# Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
# Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
# Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
# Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
#
|
#
|
||||||
# Stockfish is free software: you can redistribute it and/or modify
|
# Stockfish is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,7 +22,10 @@
|
|||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
|
|
||||||
### Establish the operating system name
|
### Establish the operating system name
|
||||||
UNAME = $(shell uname)
|
KERNEL = $(shell uname -s)
|
||||||
|
ifeq ($(KERNEL),Linux)
|
||||||
|
OS = $(shell uname -o)
|
||||||
|
endif
|
||||||
|
|
||||||
### Executable name
|
### Executable name
|
||||||
EXE = stockfish
|
EXE = stockfish
|
||||||
@@ -32,7 +35,7 @@ PREFIX = /usr/local
|
|||||||
BINDIR = $(PREFIX)/bin
|
BINDIR = $(PREFIX)/bin
|
||||||
|
|
||||||
### Built-in benchmark for pgo-builds
|
### Built-in benchmark for pgo-builds
|
||||||
PGOBENCH = ./$(EXE) bench 16 1 1000 default time
|
PGOBENCH = ./$(EXE) bench
|
||||||
|
|
||||||
### Object files
|
### Object files
|
||||||
OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
||||||
@@ -47,13 +50,14 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
|||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
|
# debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
|
||||||
|
# sanitize = undefined/thread/no (-fsanitize )
|
||||||
|
# --- ( undefined ) --- enable undefined behavior checks
|
||||||
|
# --- ( thread ) --- enable threading error checks
|
||||||
# optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
|
# optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
|
||||||
# arch = (name) --- (-arch) --- Target architecture
|
# arch = (name) --- (-arch) --- Target architecture
|
||||||
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
||||||
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
|
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
|
||||||
# bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
|
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
|
||||||
# with GCC and ICC 64-bit)
|
|
||||||
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
|
|
||||||
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
||||||
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
||||||
#
|
#
|
||||||
@@ -64,9 +68,9 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
|||||||
### 2.1. General and architecture defaults
|
### 2.1. General and architecture defaults
|
||||||
optimize = yes
|
optimize = yes
|
||||||
debug = no
|
debug = no
|
||||||
|
sanitize = no
|
||||||
bits = 32
|
bits = 32
|
||||||
prefetch = no
|
prefetch = no
|
||||||
bsfq = no
|
|
||||||
popcnt = no
|
popcnt = no
|
||||||
sse = no
|
sse = no
|
||||||
pext = no
|
pext = no
|
||||||
@@ -96,7 +100,6 @@ ifeq ($(ARCH),x86-64)
|
|||||||
arch = x86_64
|
arch = x86_64
|
||||||
bits = 64
|
bits = 64
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = yes
|
|
||||||
sse = yes
|
sse = yes
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -104,7 +107,6 @@ ifeq ($(ARCH),x86-64-modern)
|
|||||||
arch = x86_64
|
arch = x86_64
|
||||||
bits = 64
|
bits = 64
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = yes
|
|
||||||
popcnt = yes
|
popcnt = yes
|
||||||
sse = yes
|
sse = yes
|
||||||
endif
|
endif
|
||||||
@@ -113,7 +115,6 @@ ifeq ($(ARCH),x86-64-bmi2)
|
|||||||
arch = x86_64
|
arch = x86_64
|
||||||
bits = 64
|
bits = 64
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = yes
|
|
||||||
popcnt = yes
|
popcnt = yes
|
||||||
sse = yes
|
sse = yes
|
||||||
pext = yes
|
pext = yes
|
||||||
@@ -122,7 +123,6 @@ endif
|
|||||||
ifeq ($(ARCH),armv7)
|
ifeq ($(ARCH),armv7)
|
||||||
arch = armv7
|
arch = armv7
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bsfq = yes
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),ppc-32)
|
ifeq ($(ARCH),ppc-32)
|
||||||
@@ -141,7 +141,7 @@ endif
|
|||||||
|
|
||||||
### 3.1 Selecting compiler (default = gcc)
|
### 3.1 Selecting compiler (default = gcc)
|
||||||
|
|
||||||
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -fno-rtti -std=c++11 $(EXTRACXXFLAGS)
|
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
|
||||||
DEPENDFLAGS += -std=c++11
|
DEPENDFLAGS += -std=c++11
|
||||||
LDFLAGS += $(EXTRALDFLAGS)
|
LDFLAGS += $(EXTRALDFLAGS)
|
||||||
|
|
||||||
@@ -153,7 +153,18 @@ ifeq ($(COMP),gcc)
|
|||||||
comp=gcc
|
comp=gcc
|
||||||
CXX=g++
|
CXX=g++
|
||||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||||
ifneq ($(UNAME),Darwin)
|
|
||||||
|
ifeq ($(ARCH),armv7)
|
||||||
|
ifeq ($(OS),Android)
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(KERNEL),Darwin)
|
||||||
LDFLAGS += -Wl,--no-as-needed
|
LDFLAGS += -Wl,--no-as-needed
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -161,7 +172,7 @@ endif
|
|||||||
ifeq ($(COMP),mingw)
|
ifeq ($(COMP),mingw)
|
||||||
comp=mingw
|
comp=mingw
|
||||||
|
|
||||||
ifeq ($(UNAME),Linux)
|
ifeq ($(KERNEL),Linux)
|
||||||
ifeq ($(bits),64)
|
ifeq ($(bits),64)
|
||||||
ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
|
ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
|
||||||
CXX=x86_64-w64-mingw32-c++
|
CXX=x86_64-w64-mingw32-c++
|
||||||
@@ -193,59 +204,83 @@ ifeq ($(COMP),clang)
|
|||||||
comp=clang
|
comp=clang
|
||||||
CXX=clang++
|
CXX=clang++
|
||||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||||
ifeq ($(UNAME),Darwin)
|
ifneq ($(KERNEL),Darwin)
|
||||||
CXXFLAGS += -std=c++0x -stdlib=libc++
|
ifneq ($(KERNEL),OpenBSD)
|
||||||
DEPENDFLAGS += -std=c++0x -stdlib=libc++
|
LDFLAGS += -latomic
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),armv7)
|
||||||
|
ifeq ($(OS),Android)
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
CXXFLAGS += -m$(bits)
|
||||||
|
LDFLAGS += -m$(bits)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),icc)
|
ifeq ($(comp),icc)
|
||||||
profile_prepare = icc-profile-prepare
|
|
||||||
profile_make = icc-profile-make
|
profile_make = icc-profile-make
|
||||||
profile_use = icc-profile-use
|
profile_use = icc-profile-use
|
||||||
profile_clean = icc-profile-clean
|
|
||||||
else
|
else
|
||||||
profile_prepare = gcc-profile-prepare
|
ifeq ($(comp),clang)
|
||||||
|
profile_make = clang-profile-make
|
||||||
|
profile_use = clang-profile-use
|
||||||
|
else
|
||||||
profile_make = gcc-profile-make
|
profile_make = gcc-profile-make
|
||||||
profile_use = gcc-profile-use
|
profile_use = gcc-profile-use
|
||||||
profile_clean = gcc-profile-clean
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(UNAME),Darwin)
|
ifeq ($(KERNEL),Darwin)
|
||||||
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
||||||
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### Travis CI script uses COMPILER to overwrite CXX
|
### Travis CI script uses COMPILER to overwrite CXX
|
||||||
ifdef COMPILER
|
ifdef COMPILER
|
||||||
CXX=$(COMPILER)
|
COMPCXX=$(COMPILER)
|
||||||
|
endif
|
||||||
|
|
||||||
|
### Allow overwriting CXX from command line
|
||||||
|
ifdef COMPCXX
|
||||||
|
CXX=$(COMPCXX)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### On mingw use Windows threads, otherwise POSIX
|
### On mingw use Windows threads, otherwise POSIX
|
||||||
ifneq ($(comp),mingw)
|
ifneq ($(comp),mingw)
|
||||||
# On Android Bionic's C library comes with its own pthread implementation bundled in
|
# On Android Bionic's C library comes with its own pthread implementation bundled in
|
||||||
ifneq ($(arch),armv7)
|
ifneq ($(OS),Android)
|
||||||
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
||||||
ifneq ($(UNAME),Haiku)
|
ifneq ($(KERNEL),Haiku)
|
||||||
LDFLAGS += -lpthread
|
LDFLAGS += -lpthread
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.4 Debugging
|
### 3.2.1 Debugging
|
||||||
ifeq ($(debug),no)
|
ifeq ($(debug),no)
|
||||||
CXXFLAGS += -DNDEBUG
|
CXXFLAGS += -DNDEBUG
|
||||||
else
|
else
|
||||||
CXXFLAGS += -g
|
CXXFLAGS += -g
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.5 Optimization
|
### 3.2.2 Debugging with undefined behavior sanitizers
|
||||||
|
ifneq ($(sanitize),no)
|
||||||
|
CXXFLAGS += -g3 -fsanitize=$(sanitize) -fuse-ld=gold
|
||||||
|
LDFLAGS += -fsanitize=$(sanitize) -fuse-ld=gold
|
||||||
|
endif
|
||||||
|
|
||||||
|
### 3.3 Optimization
|
||||||
ifeq ($(optimize),yes)
|
ifeq ($(optimize),yes)
|
||||||
|
|
||||||
ifeq ($(comp),gcc)
|
CXXFLAGS += -O3
|
||||||
CXXFLAGS += -O3
|
|
||||||
|
|
||||||
ifeq ($(UNAME),Darwin)
|
ifeq ($(comp),gcc)
|
||||||
|
|
||||||
|
ifeq ($(KERNEL),Darwin)
|
||||||
ifeq ($(arch),i386)
|
ifeq ($(arch),i386)
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
endif
|
endif
|
||||||
@@ -254,31 +289,21 @@ ifeq ($(optimize),yes)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(arch),armv7)
|
ifeq ($(OS), Android)
|
||||||
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),mingw)
|
|
||||||
CXXFLAGS += -O3
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(comp),icc)
|
ifeq ($(comp),icc)
|
||||||
ifeq ($(UNAME),Darwin)
|
ifeq ($(KERNEL),Darwin)
|
||||||
CXXFLAGS += -fast -mdynamic-no-pic
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
else
|
|
||||||
CXXFLAGS += -fast
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),clang)
|
ifeq ($(comp),clang)
|
||||||
CXXFLAGS += -O3
|
ifeq ($(KERNEL),Darwin)
|
||||||
|
|
||||||
ifeq ($(UNAME),Darwin)
|
|
||||||
ifeq ($(pext),no)
|
|
||||||
CXXFLAGS += -flto
|
CXXFLAGS += -flto
|
||||||
LDFLAGS += $(CXXFLAGS)
|
LDFLAGS += $(CXXFLAGS)
|
||||||
endif
|
|
||||||
ifeq ($(arch),i386)
|
ifeq ($(arch),i386)
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
endif
|
endif
|
||||||
@@ -289,12 +314,12 @@ ifeq ($(optimize),yes)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.6. Bits
|
### 3.4 Bits
|
||||||
ifeq ($(bits),64)
|
ifeq ($(bits),64)
|
||||||
CXXFLAGS += -DIS_64BIT
|
CXXFLAGS += -DIS_64BIT
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.7 prefetch
|
### 3.5 prefetch
|
||||||
ifeq ($(prefetch),yes)
|
ifeq ($(prefetch),yes)
|
||||||
ifeq ($(sse),yes)
|
ifeq ($(sse),yes)
|
||||||
CXXFLAGS += -msse
|
CXXFLAGS += -msse
|
||||||
@@ -304,12 +329,7 @@ else
|
|||||||
CXXFLAGS += -DNO_PREFETCH
|
CXXFLAGS += -DNO_PREFETCH
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.8 bsfq
|
### 3.6 popcnt
|
||||||
ifeq ($(bsfq),yes)
|
|
||||||
CXXFLAGS += -DUSE_BSFQ
|
|
||||||
endif
|
|
||||||
|
|
||||||
### 3.9 popcnt
|
|
||||||
ifeq ($(popcnt),yes)
|
ifeq ($(popcnt),yes)
|
||||||
ifeq ($(comp),icc)
|
ifeq ($(comp),icc)
|
||||||
CXXFLAGS += -msse3 -DUSE_POPCNT
|
CXXFLAGS += -msse3 -DUSE_POPCNT
|
||||||
@@ -318,15 +338,15 @@ ifeq ($(popcnt),yes)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.10 pext
|
### 3.7 pext
|
||||||
ifeq ($(pext),yes)
|
ifeq ($(pext),yes)
|
||||||
CXXFLAGS += -DUSE_PEXT
|
CXXFLAGS += -DUSE_PEXT
|
||||||
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
CXXFLAGS += -mbmi -mbmi2
|
CXXFLAGS += -mbmi2
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.11 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
|
### 3.8 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
|
||||||
### This is a mix of compile and link time options because the lto link phase
|
### This is a mix of compile and link time options because the lto link phase
|
||||||
### needs access to the optimization flags.
|
### needs access to the optimization flags.
|
||||||
ifeq ($(comp),gcc)
|
ifeq ($(comp),gcc)
|
||||||
@@ -339,7 +359,7 @@ ifeq ($(comp),gcc)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(comp),mingw)
|
ifeq ($(comp),mingw)
|
||||||
ifeq ($(UNAME),Linux)
|
ifeq ($(KERNEL),Linux)
|
||||||
ifeq ($(optimize),yes)
|
ifeq ($(optimize),yes)
|
||||||
ifeq ($(debug),no)
|
ifeq ($(debug),no)
|
||||||
CXXFLAGS += -flto
|
CXXFLAGS += -flto
|
||||||
@@ -349,9 +369,9 @@ ifeq ($(comp),mingw)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.12 Android 5 can only run position independent executables. Note that this
|
### 3.9 Android 5 can only run position independent executables. Note that this
|
||||||
### breaks Android 4.0 and earlier.
|
### breaks Android 4.0 and earlier.
|
||||||
ifeq ($(arch),armv7)
|
ifeq ($(OS), Android)
|
||||||
CXXFLAGS += -fPIE
|
CXXFLAGS += -fPIE
|
||||||
LDFLAGS += -fPIE -pie
|
LDFLAGS += -fPIE -pie
|
||||||
endif
|
endif
|
||||||
@@ -365,7 +385,7 @@ help:
|
|||||||
@echo ""
|
@echo ""
|
||||||
@echo "To compile stockfish, type: "
|
@echo "To compile stockfish, type: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make target ARCH=arch [COMP=comp]"
|
@echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Supported targets:"
|
@echo "Supported targets:"
|
||||||
@echo ""
|
@echo ""
|
||||||
@@ -395,36 +415,39 @@ help:
|
|||||||
@echo "clang > LLVM Clang compiler"
|
@echo "clang > LLVM Clang compiler"
|
||||||
@echo "icc > Intel compiler"
|
@echo "icc > Intel compiler"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Examples. If you don't know what to do, you likely want to run: "
|
@echo "Simple examples. If you don't know what to do, you likely want to run: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make build ARCH=x86-64 (This is for 64-bit systems)"
|
@echo "make build ARCH=x86-64 (This is for 64-bit systems)"
|
||||||
@echo "make build ARCH=x86-32 (This is for 32-bit systems)"
|
@echo "make build ARCH=x86-32 (This is for 32-bit systems)"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
@echo "Advanced examples, for experienced users: "
|
||||||
|
@echo ""
|
||||||
|
@echo "make build ARCH=x86-64 COMP=clang"
|
||||||
|
@echo "make profile-build ARCH=x86-64-modern COMP=gcc COMPCXX=g++-4.8"
|
||||||
|
@echo ""
|
||||||
|
|
||||||
.PHONY: build profile-build
|
|
||||||
build:
|
.PHONY: help build profile-build strip install clean objclean profileclean help \
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \
|
||||||
|
clang-profile-use clang-profile-make
|
||||||
|
|
||||||
|
build: config-sanity
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
||||||
|
|
||||||
profile-build:
|
profile-build: config-sanity objclean profileclean
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 0/4. Preparing for profile build."
|
@echo "Step 1/4. Building instrumented executable ..."
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
|
|
||||||
@echo ""
|
|
||||||
@echo "Step 1/4. Building executable for benchmark ..."
|
|
||||||
@touch *.cpp *.h syzygy/*.cpp syzygy/*.h
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
||||||
$(PGOBENCH) > /dev/null
|
$(PGOBENCH) > /dev/null
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 3/4. Building final executable ..."
|
@echo "Step 3/4. Building optimized executable ..."
|
||||||
@touch *.cpp *.h syzygy/*.cpp syzygy/*.h
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 4/4. Deleting profile data ..."
|
@echo "Step 4/4. Deleting profile data ..."
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
|
||||||
|
|
||||||
strip:
|
strip:
|
||||||
strip $(EXE)
|
strip $(EXE)
|
||||||
@@ -434,8 +457,19 @@ install:
|
|||||||
-cp $(EXE) $(BINDIR)
|
-cp $(EXE) $(BINDIR)
|
||||||
-strip $(BINDIR)/$(EXE)
|
-strip $(BINDIR)/$(EXE)
|
||||||
|
|
||||||
clean:
|
#clean all
|
||||||
$(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda ./syzygy/*.o ./syzygy/*.gcda
|
clean: objclean profileclean
|
||||||
|
@rm -f .depend *~ core
|
||||||
|
|
||||||
|
# clean binaries and objects
|
||||||
|
objclean:
|
||||||
|
@rm -f $(EXE) $(EXE).exe *.o ./syzygy/*.o
|
||||||
|
|
||||||
|
# clean auxiliary profiling files
|
||||||
|
profileclean:
|
||||||
|
@rm -rf profdir
|
||||||
|
@rm -f bench.txt *.gcda ./syzygy/*.gcda *.gcno ./syzygy/*.gcno
|
||||||
|
@rm -f stockfish.profdata *.profraw
|
||||||
|
|
||||||
default:
|
default:
|
||||||
help
|
help
|
||||||
@@ -450,11 +484,13 @@ config-sanity:
|
|||||||
@echo ""
|
@echo ""
|
||||||
@echo "Config:"
|
@echo "Config:"
|
||||||
@echo "debug: '$(debug)'"
|
@echo "debug: '$(debug)'"
|
||||||
|
@echo "sanitize: '$(sanitize)'"
|
||||||
@echo "optimize: '$(optimize)'"
|
@echo "optimize: '$(optimize)'"
|
||||||
@echo "arch: '$(arch)'"
|
@echo "arch: '$(arch)'"
|
||||||
@echo "bits: '$(bits)'"
|
@echo "bits: '$(bits)'"
|
||||||
|
@echo "kernel: '$(KERNEL)'"
|
||||||
|
@echo "os: '$(OS)'"
|
||||||
@echo "prefetch: '$(prefetch)'"
|
@echo "prefetch: '$(prefetch)'"
|
||||||
@echo "bsfq: '$(bsfq)'"
|
|
||||||
@echo "popcnt: '$(popcnt)'"
|
@echo "popcnt: '$(popcnt)'"
|
||||||
@echo "sse: '$(sse)'"
|
@echo "sse: '$(sse)'"
|
||||||
@echo "pext: '$(pext)'"
|
@echo "pext: '$(pext)'"
|
||||||
@@ -467,12 +503,12 @@ config-sanity:
|
|||||||
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
||||||
@echo ""
|
@echo ""
|
||||||
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
||||||
|
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "no"
|
||||||
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
||||||
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
||||||
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
||||||
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
||||||
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
||||||
@test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
|
|
||||||
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
||||||
@test "$(sse)" = "yes" || test "$(sse)" = "no"
|
@test "$(sse)" = "yes" || test "$(sse)" = "no"
|
||||||
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
||||||
@@ -481,8 +517,18 @@ config-sanity:
|
|||||||
$(EXE): $(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
gcc-profile-prepare:
|
clang-profile-make:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
|
EXTRACXXFLAGS='-fprofile-instr-generate ' \
|
||||||
|
EXTRALDFLAGS=' -fprofile-instr-generate' \
|
||||||
|
all
|
||||||
|
|
||||||
|
clang-profile-use:
|
||||||
|
llvm-profdata merge -output=stockfish.profdata *.profraw
|
||||||
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
|
EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
|
||||||
|
EXTRALDFLAGS='-fprofile-use ' \
|
||||||
|
all
|
||||||
|
|
||||||
gcc-profile-make:
|
gcc-profile-make:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
@@ -496,14 +542,8 @@ gcc-profile-use:
|
|||||||
EXTRALDFLAGS='-lgcov' \
|
EXTRALDFLAGS='-lgcov' \
|
||||||
all
|
all
|
||||||
|
|
||||||
gcc-profile-clean:
|
|
||||||
@rm -rf *.gcda *.gcno syzygy/*.gcda syzygy/*.gcno bench.txt
|
|
||||||
|
|
||||||
icc-profile-prepare:
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
|
|
||||||
@mkdir profdir
|
|
||||||
|
|
||||||
icc-profile-make:
|
icc-profile-make:
|
||||||
|
@mkdir -p profdir
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
|
EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
|
||||||
all
|
all
|
||||||
@@ -513,9 +553,6 @@ icc-profile-use:
|
|||||||
EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
|
EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
|
||||||
all
|
all
|
||||||
|
|
||||||
icc-profile-clean:
|
|
||||||
@rm -rf profdir bench.txt
|
|
||||||
|
|
||||||
.depend:
|
.depend:
|
||||||
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
||||||
|
|
||||||
|
|||||||
+42
-61
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,23 +23,20 @@
|
|||||||
#include <istream>
|
#include <istream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "misc.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
|
||||||
#include "thread.h"
|
|
||||||
#include "uci.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const vector<string> Defaults = {
|
const vector<string> Defaults = {
|
||||||
|
"setoption name UCI_Chess960 value false",
|
||||||
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
||||||
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
|
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
|
||||||
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
|
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
|
||||||
"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
|
"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
|
||||||
"rq3rk1/ppp2ppp/1bnpb3/3N2B1/3NP3/7P/PPPQ1PP1/2KR3R w - - 7 14",
|
"rq3rk1/ppp2ppp/1bnpb3/3N2B1/3NP3/7P/PPPQ1PP1/2KR3R w - - 7 14 moves d4e6",
|
||||||
"r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14",
|
"r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14 moves g2g4",
|
||||||
"r3r1k1/2p2ppp/p1p1bn2/8/1q2P3/2NPQN2/PPP3PP/R4RK1 b - - 2 15",
|
"r3r1k1/2p2ppp/p1p1bn2/8/1q2P3/2NPQN2/PPP3PP/R4RK1 b - - 2 15",
|
||||||
"r1bbk1nr/pp3p1p/2n5/1N4p1/2Np1B2/8/PPP2PPP/2KR1B1R w kq - 0 13",
|
"r1bbk1nr/pp3p1p/2n5/1N4p1/2Np1B2/8/PPP2PPP/2KR1B1R w kq - 0 13",
|
||||||
"r1bq1rk1/ppp1nppp/4n3/3p3Q/3P4/1BP1B3/PP1N2PP/R4RK1 w - - 1 16",
|
"r1bq1rk1/ppp1nppp/4n3/3p3Q/3P4/1BP1B3/PP1N2PP/R4RK1 w - - 1 16",
|
||||||
@@ -52,7 +49,7 @@ const vector<string> Defaults = {
|
|||||||
"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b - - 4 26",
|
"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b - - 4 26",
|
||||||
"6k1/6p1/6Pp/ppp5/3pn2P/1P3K2/1PP2P2/3N4 b - - 0 1",
|
"6k1/6p1/6Pp/ppp5/3pn2P/1P3K2/1PP2P2/3N4 b - - 0 1",
|
||||||
"3b4/5kp1/1p1p1p1p/pP1PpP1P/P1P1P3/3KN3/8/8 w - - 0 1",
|
"3b4/5kp1/1p1p1p1p/pP1PpP1P/P1P1P3/3KN3/8/8 w - - 0 1",
|
||||||
"2K5/p7/7P/5pR1/8/5k2/r7/8 w - - 0 1",
|
"2K5/p7/7P/5pR1/8/5k2/r7/8 w - - 0 1 moves g5g6 f3e3 g6g5 e3f3",
|
||||||
"8/6pk/1p6/8/PP3p1p/5P2/4KP1q/3Q4 w - - 0 1",
|
"8/6pk/1p6/8/PP3p1p/5P2/4KP1q/3Q4 w - - 0 1",
|
||||||
"7k/3p2pp/4q3/8/4Q3/5Kp1/P6b/8 w - - 0 1",
|
"7k/3p2pp/4q3/8/4Q3/5Kp1/P6b/8 w - - 0 1",
|
||||||
"8/2p5/8/2kPKp1p/2p4P/2P5/3P4/8 w - - 0 1",
|
"8/2p5/8/2kPKp1p/2p4P/2P5/3P4/8 w - - 0 1",
|
||||||
@@ -76,24 +73,38 @@ const vector<string> Defaults = {
|
|||||||
"8/8/3P3k/8/1p6/8/1P6/1K3n2 b - - 0 1", // Nd2 - draw
|
"8/8/3P3k/8/1p6/8/1P6/1K3n2 b - - 0 1", // Nd2 - draw
|
||||||
|
|
||||||
// 7-man positions
|
// 7-man positions
|
||||||
"8/R7/2q5/8/6k1/8/1P5p/K6R w - - 0 124" // Draw
|
"8/R7/2q5/8/6k1/8/1P5p/K6R w - - 0 124", // Draw
|
||||||
|
|
||||||
|
// Mate and stalemate positions
|
||||||
|
"6k1/3b3r/1p1p4/p1n2p2/1PPNpP1q/P3Q1p1/1R1RB1P1/5K2 b - - 0 1",
|
||||||
|
"r2r1n2/pp2bk2/2p1p2p/3q4/3PN1QP/2P3R1/P4PP1/5RK1 w - - 0 1",
|
||||||
|
"8/8/8/8/8/6k1/6p1/6K1 w - -",
|
||||||
|
"7k/7P/6K1/8/3B4/8/8/8 b - -",
|
||||||
|
|
||||||
|
// Chess 960
|
||||||
|
"setoption name UCI_Chess960 value true",
|
||||||
|
"bbqnnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w KQkq - 0 1 moves g2g3 d7d5 d2d4 c8h3 c1g5 e8d6 g5e7 f7f6",
|
||||||
|
"setoption name UCI_Chess960 value false"
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
/// benchmark() runs a simple benchmark by letting Stockfish analyze a set
|
/// setup_bench() builds a list of UCI commands to be run by bench. There
|
||||||
/// of positions for a given limit each. There are five parameters: the
|
/// are five parameters: TT size in MB, number of search threads that
|
||||||
/// transposition table size, the number of search threads that should
|
/// should be used, the limit value spent for each position, a file name
|
||||||
/// be used, the limit value spent for each position (optional, default is
|
/// where to look for positions in FEN format and the type of the limit:
|
||||||
/// depth 13), an optional file name where to look for positions in FEN
|
/// depth, perft, nodes and movetime (in millisecs).
|
||||||
/// format (defaults are the positions defined above) and the type of the
|
///
|
||||||
/// limit value: depth (default), time in millisecs or number of nodes.
|
/// bench -> search default positions up to depth 13
|
||||||
|
/// bench 64 1 15 -> search default positions up to depth 15 (TT = 64MB)
|
||||||
|
/// bench 64 4 5000 current movetime -> search current position with 4 threads for 5 sec
|
||||||
|
/// bench 64 1 100000 default nodes -> search default positions for 100K nodes each
|
||||||
|
/// bench 16 1 5 default perft -> run a perft 5 on default positions
|
||||||
|
|
||||||
void benchmark(const Position& current, istream& is) {
|
vector<string> setup_bench(const Position& current, istream& is) {
|
||||||
|
|
||||||
string token;
|
vector<string> fens, list;
|
||||||
vector<string> fens;
|
string go, token;
|
||||||
Search::LimitsType limits;
|
|
||||||
|
|
||||||
// Assign default values to missing arguments
|
// Assign default values to missing arguments
|
||||||
string ttSize = (is >> token) ? token : "16";
|
string ttSize = (is >> token) ? token : "16";
|
||||||
@@ -102,21 +113,7 @@ void benchmark(const Position& current, istream& is) {
|
|||||||
string fenFile = (is >> token) ? token : "default";
|
string fenFile = (is >> token) ? token : "default";
|
||||||
string limitType = (is >> token) ? token : "depth";
|
string limitType = (is >> token) ? token : "depth";
|
||||||
|
|
||||||
Options["Hash"] = ttSize;
|
go = "go " + limitType + " " + limit;
|
||||||
Options["Threads"] = threads;
|
|
||||||
Search::clear();
|
|
||||||
|
|
||||||
if (limitType == "time")
|
|
||||||
limits.movetime = stoi(limit); // movetime is in millisecs
|
|
||||||
|
|
||||||
else if (limitType == "nodes")
|
|
||||||
limits.nodes = stoi(limit);
|
|
||||||
|
|
||||||
else if (limitType == "mate")
|
|
||||||
limits.mate = stoi(limit);
|
|
||||||
|
|
||||||
else
|
|
||||||
limits.depth = stoi(limit);
|
|
||||||
|
|
||||||
if (fenFile == "default")
|
if (fenFile == "default")
|
||||||
fens = Defaults;
|
fens = Defaults;
|
||||||
@@ -132,7 +129,7 @@ void benchmark(const Position& current, istream& is) {
|
|||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
cerr << "Unable to open file " << fenFile << endl;
|
cerr << "Unable to open file " << fenFile << endl;
|
||||||
return;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (getline(file, fen))
|
while (getline(file, fen))
|
||||||
@@ -142,34 +139,18 @@ void benchmark(const Position& current, istream& is) {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t nodes = 0;
|
list.emplace_back("ucinewgame");
|
||||||
TimePoint elapsed = now();
|
list.emplace_back("setoption name Threads value " + threads);
|
||||||
|
list.emplace_back("setoption name Hash value " + ttSize);
|
||||||
for (size_t i = 0; i < fens.size(); ++i)
|
|
||||||
{
|
|
||||||
Position pos(fens[i], Options["UCI_Chess960"], Threads.main());
|
|
||||||
|
|
||||||
cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl;
|
|
||||||
|
|
||||||
if (limitType == "perft")
|
|
||||||
nodes += Search::perft(pos, limits.depth * ONE_PLY);
|
|
||||||
|
|
||||||
|
for (const string& fen : fens)
|
||||||
|
if (fen.find("setoption") != string::npos)
|
||||||
|
list.emplace_back(fen);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Search::StateStackPtr st;
|
list.emplace_back("position fen " + fen);
|
||||||
limits.startTime = now();
|
list.emplace_back(go);
|
||||||
Threads.start_thinking(pos, limits, st);
|
|
||||||
Threads.main()->wait_for_search_finished();
|
|
||||||
nodes += Threads.nodes_searched();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
return list;
|
||||||
|
|
||||||
dbg_print(); // Just before to exit
|
|
||||||
|
|
||||||
cerr << "\n==========================="
|
|
||||||
<< "\nTotal time (ms) : " << elapsed
|
|
||||||
<< "\nNodes searched : " << nodes
|
|
||||||
<< "\nNodes/second : " << 1000 * nodes / elapsed << endl;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -111,27 +111,27 @@ namespace {
|
|||||||
ksq[WHITE] = Square((idx >> 0) & 0x3F);
|
ksq[WHITE] = Square((idx >> 0) & 0x3F);
|
||||||
ksq[BLACK] = Square((idx >> 6) & 0x3F);
|
ksq[BLACK] = Square((idx >> 6) & 0x3F);
|
||||||
us = Color ((idx >> 12) & 0x01);
|
us = Color ((idx >> 12) & 0x01);
|
||||||
psq = make_square(File((idx >> 13) & 0x3), RANK_7 - Rank((idx >> 15) & 0x7));
|
psq = make_square(File((idx >> 13) & 0x3), Rank(RANK_7 - ((idx >> 15) & 0x7)));
|
||||||
|
|
||||||
// Check if two pieces are on the same square or if a king can be captured
|
// Check if two pieces are on the same square or if a king can be captured
|
||||||
if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
|
if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
|
||||||
|| ksq[WHITE] == psq
|
|| ksq[WHITE] == psq
|
||||||
|| ksq[BLACK] == psq
|
|| ksq[BLACK] == psq
|
||||||
|| (us == WHITE && (StepAttacksBB[PAWN][psq] & ksq[BLACK])))
|
|| (us == WHITE && (PawnAttacks[WHITE][psq] & ksq[BLACK])))
|
||||||
result = INVALID;
|
result = INVALID;
|
||||||
|
|
||||||
// Immediate win if a pawn can be promoted without getting captured
|
// Immediate win if a pawn can be promoted without getting captured
|
||||||
else if ( us == WHITE
|
else if ( us == WHITE
|
||||||
&& rank_of(psq) == RANK_7
|
&& rank_of(psq) == RANK_7
|
||||||
&& ksq[us] != psq + DELTA_N
|
&& ksq[us] != psq + NORTH
|
||||||
&& ( distance(ksq[~us], psq + DELTA_N) > 1
|
&& ( distance(ksq[~us], psq + NORTH) > 1
|
||||||
|| (StepAttacksBB[KING][ksq[us]] & (psq + DELTA_N))))
|
|| (PseudoAttacks[KING][ksq[us]] & (psq + NORTH))))
|
||||||
result = WIN;
|
result = WIN;
|
||||||
|
|
||||||
// Immediate draw if it is a stalemate or a king captures undefended pawn
|
// Immediate draw if it is a stalemate or a king captures undefended pawn
|
||||||
else if ( us == BLACK
|
else if ( us == BLACK
|
||||||
&& ( !(StepAttacksBB[KING][ksq[us]] & ~(StepAttacksBB[KING][ksq[~us]] | StepAttacksBB[PAWN][psq]))
|
&& ( !(PseudoAttacks[KING][ksq[us]] & ~(PseudoAttacks[KING][ksq[~us]] | PawnAttacks[~us][psq]))
|
||||||
|| (StepAttacksBB[KING][ksq[us]] & psq & ~StepAttacksBB[KING][ksq[~us]])))
|
|| (PseudoAttacks[KING][ksq[us]] & psq & ~PseudoAttacks[KING][ksq[~us]])))
|
||||||
result = DRAW;
|
result = DRAW;
|
||||||
|
|
||||||
// Position will be classified later
|
// Position will be classified later
|
||||||
@@ -157,7 +157,7 @@ namespace {
|
|||||||
const Result Bad = (Us == WHITE ? DRAW : WIN);
|
const Result Bad = (Us == WHITE ? DRAW : WIN);
|
||||||
|
|
||||||
Result r = INVALID;
|
Result r = INVALID;
|
||||||
Bitboard b = StepAttacksBB[KING][ksq[Us]];
|
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)]
|
r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)]
|
||||||
@@ -166,12 +166,12 @@ namespace {
|
|||||||
if (Us == WHITE)
|
if (Us == WHITE)
|
||||||
{
|
{
|
||||||
if (rank_of(psq) < RANK_7) // Single push
|
if (rank_of(psq) < RANK_7) // Single push
|
||||||
r |= db[index(Them, ksq[Them], ksq[Us], psq + DELTA_N)];
|
r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH)];
|
||||||
|
|
||||||
if ( rank_of(psq) == RANK_2 // Double push
|
if ( rank_of(psq) == RANK_2 // Double push
|
||||||
&& psq + DELTA_N != ksq[Us]
|
&& psq + NORTH != ksq[Us]
|
||||||
&& psq + DELTA_N != ksq[Them])
|
&& psq + NORTH != ksq[Them])
|
||||||
r |= db[index(Them, ksq[Them], ksq[Us], psq + DELTA_N + DELTA_N)];
|
r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH + NORTH)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad;
|
return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad;
|
||||||
|
|||||||
+78
-70
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,34 +21,27 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "bitcount.h"
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
uint8_t PopCnt16[1 << 16];
|
||||||
int SquareDistance[SQUARE_NB][SQUARE_NB];
|
int SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
|
|
||||||
Bitboard RookMasks [SQUARE_NB];
|
|
||||||
Bitboard RookMagics [SQUARE_NB];
|
|
||||||
Bitboard* RookAttacks[SQUARE_NB];
|
|
||||||
unsigned RookShifts [SQUARE_NB];
|
|
||||||
|
|
||||||
Bitboard BishopMasks [SQUARE_NB];
|
|
||||||
Bitboard BishopMagics [SQUARE_NB];
|
|
||||||
Bitboard* BishopAttacks[SQUARE_NB];
|
|
||||||
unsigned BishopShifts [SQUARE_NB];
|
|
||||||
|
|
||||||
Bitboard SquareBB[SQUARE_NB];
|
Bitboard SquareBB[SQUARE_NB];
|
||||||
Bitboard FileBB[FILE_NB];
|
Bitboard FileBB[FILE_NB];
|
||||||
Bitboard RankBB[RANK_NB];
|
Bitboard RankBB[RANK_NB];
|
||||||
Bitboard AdjacentFilesBB[FILE_NB];
|
Bitboard AdjacentFilesBB[FILE_NB];
|
||||||
Bitboard InFrontBB[COLOR_NB][RANK_NB];
|
Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
|
||||||
Bitboard StepAttacksBB[PIECE_NB][SQUARE_NB];
|
|
||||||
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
||||||
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||||
Bitboard DistanceRingBB[SQUARE_NB][8];
|
Bitboard DistanceRingBB[SQUARE_NB][8];
|
||||||
Bitboard ForwardBB[COLOR_NB][SQUARE_NB];
|
Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
|
||||||
Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
||||||
Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
||||||
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
||||||
|
Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||||
|
|
||||||
|
Magic RookMagics[SQUARE_NB];
|
||||||
|
Magic BishopMagics[SQUARE_NB];
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -61,10 +54,7 @@ namespace {
|
|||||||
Bitboard RookTable[0x19000]; // To store rook attacks
|
Bitboard RookTable[0x19000]; // To store rook attacks
|
||||||
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
||||||
|
|
||||||
typedef unsigned (Fn)(Square, Bitboard);
|
void init_magics(Bitboard table[], Magic magics[], Direction directions[]);
|
||||||
|
|
||||||
void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
|
|
||||||
Bitboard masks[], unsigned shifts[], Square deltas[], Fn index);
|
|
||||||
|
|
||||||
// bsf_index() returns the index into BSFTable[] to look up the bitscan. Uses
|
// bsf_index() returns the index into BSFTable[] to look up the bitscan. Uses
|
||||||
// Matt Taylor's folding for 32 bit case, extended to 64 bit by Kim Walisch.
|
// Matt Taylor's folding for 32 bit case, extended to 64 bit by Kim Walisch.
|
||||||
@@ -74,18 +64,30 @@ namespace {
|
|||||||
return Is64Bit ? (b * DeBruijn64) >> 58
|
return Is64Bit ? (b * DeBruijn64) >> 58
|
||||||
: ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn32) >> 26;
|
: ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn32) >> 26;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// popcount16() counts the non-zero bits using SWAR-Popcount algorithm
|
||||||
|
|
||||||
|
unsigned popcount16(unsigned u) {
|
||||||
|
u -= (u >> 1) & 0x5555U;
|
||||||
|
u = ((u >> 2) & 0x3333U) + (u & 0x3333U);
|
||||||
|
u = ((u >> 4) + u) & 0x0F0FU;
|
||||||
|
return (u * 0x0101U) >> 8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef USE_BSFQ
|
#ifdef NO_BSF
|
||||||
|
|
||||||
/// Software fall-back of lsb() and msb() for CPU lacking hardware support
|
/// Software fall-back of lsb() and msb() for CPU lacking hardware support
|
||||||
|
|
||||||
Square lsb(Bitboard b) {
|
Square lsb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
return BSFTable[bsf_index(b)];
|
return BSFTable[bsf_index(b)];
|
||||||
}
|
}
|
||||||
|
|
||||||
Square msb(Bitboard b) {
|
Square msb(Bitboard b) {
|
||||||
|
|
||||||
|
assert(b);
|
||||||
unsigned b32;
|
unsigned b32;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
@@ -112,7 +114,7 @@ Square msb(Bitboard b) {
|
|||||||
return Square(result + MSBTable[b32]);
|
return Square(result + MSBTable[b32]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ifndef USE_BSFQ
|
#endif // ifdef NO_BSF
|
||||||
|
|
||||||
|
|
||||||
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
|
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
|
||||||
@@ -139,6 +141,9 @@ const std::string Bitboards::pretty(Bitboard b) {
|
|||||||
|
|
||||||
void Bitboards::init() {
|
void Bitboards::init() {
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < (1 << 16); ++i)
|
||||||
|
PopCnt16[i] = (uint8_t) popcount16(i);
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
SquareBB[s] = 1ULL << s;
|
SquareBB[s] = 1ULL << s;
|
||||||
@@ -158,14 +163,14 @@ void Bitboards::init() {
|
|||||||
AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0);
|
AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0);
|
||||||
|
|
||||||
for (Rank r = RANK_1; r < RANK_8; ++r)
|
for (Rank r = RANK_1; r < RANK_8; ++r)
|
||||||
InFrontBB[WHITE][r] = ~(InFrontBB[BLACK][r + 1] = InFrontBB[BLACK][r] | RankBB[r]);
|
ForwardRanksBB[WHITE][r] = ~(ForwardRanksBB[BLACK][r + 1] = ForwardRanksBB[BLACK][r] | RankBB[r]);
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
for (Color c = WHITE; c <= BLACK; ++c)
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
ForwardBB[c][s] = InFrontBB[c][rank_of(s)] & FileBB[file_of(s)];
|
ForwardFileBB [c][s] = ForwardRanksBB[c][rank_of(s)] & FileBB[file_of(s)];
|
||||||
PawnAttackSpan[c][s] = InFrontBB[c][rank_of(s)] & AdjacentFilesBB[file_of(s)];
|
PawnAttackSpan[c][s] = ForwardRanksBB[c][rank_of(s)] & AdjacentFilesBB[file_of(s)];
|
||||||
PassedPawnMask[c][s] = ForwardBB[c][s] | PawnAttackSpan[c][s];
|
PassedPawnMask[c][s] = ForwardFileBB [c][s] | PawnAttackSpan[c][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||||
@@ -176,39 +181,43 @@ void Bitboards::init() {
|
|||||||
DistanceRingBB[s1][SquareDistance[s1][s2] - 1] |= s2;
|
DistanceRingBB[s1][SquareDistance[s1][s2] - 1] |= s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int steps[][9] = { {}, { 7, 9 }, { 17, 15, 10, 6, -6, -10, -15, -17 },
|
int steps[][5] = { {}, { 7, 9 }, { 6, 10, 15, 17 }, {}, {}, {}, { 1, 7, 8, 9 } };
|
||||||
{}, {}, {}, { 9, 7, -7, -9, 8, 1, -1, -8 } };
|
|
||||||
|
|
||||||
for (Color c = WHITE; c <= BLACK; ++c)
|
for (Color c = WHITE; c <= BLACK; ++c)
|
||||||
for (PieceType pt = PAWN; pt <= KING; ++pt)
|
for (PieceType pt : { PAWN, KNIGHT, KING })
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
for (int i = 0; steps[pt][i]; ++i)
|
for (int i = 0; steps[pt][i]; ++i)
|
||||||
{
|
{
|
||||||
Square to = s + Square(c == WHITE ? steps[pt][i] : -steps[pt][i]);
|
Square to = s + Direction(c == WHITE ? steps[pt][i] : -steps[pt][i]);
|
||||||
|
|
||||||
if (is_ok(to) && distance(s, to) < 3)
|
if (is_ok(to) && distance(s, to) < 3)
|
||||||
StepAttacksBB[make_piece(c, pt)][s] |= to;
|
{
|
||||||
|
if (pt == PAWN)
|
||||||
|
PawnAttacks[c][s] |= to;
|
||||||
|
else
|
||||||
|
PseudoAttacks[pt][s] |= to;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Square RookDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
|
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
|
||||||
Square BishopDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW };
|
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
|
||||||
|
|
||||||
init_magics(RookTable, RookAttacks, RookMagics, RookMasks, RookShifts, RookDeltas, magic_index<ROOK>);
|
init_magics(RookTable, RookMagics, RookDirections);
|
||||||
init_magics(BishopTable, BishopAttacks, BishopMagics, BishopMasks, BishopShifts, BishopDeltas, magic_index<BISHOP>);
|
init_magics(BishopTable, BishopMagics, BishopDirections);
|
||||||
|
|
||||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||||
{
|
{
|
||||||
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
||||||
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
||||||
|
|
||||||
for (Piece pc = W_BISHOP; pc <= W_ROOK; ++pc)
|
for (PieceType pt : { BISHOP, ROOK })
|
||||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||||
{
|
{
|
||||||
if (!(PseudoAttacks[pc][s1] & s2))
|
if (!(PseudoAttacks[pt][s1] & s2))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
|
LineBB[s1][s2] = (attacks_bb(pt, s1, 0) & attacks_bb(pt, s2, 0)) | s1 | s2;
|
||||||
BetweenBB[s1][s2] = attacks_bb(pc, s1, SquareBB[s2]) & attacks_bb(pc, s2, SquareBB[s1]);
|
BetweenBB[s1][s2] = attacks_bb(pt, s1, SquareBB[s2]) & attacks_bb(pt, s2, SquareBB[s1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,14 +225,14 @@ void Bitboards::init() {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
Bitboard sliding_attack(Square deltas[], Square sq, Bitboard occupied) {
|
Bitboard sliding_attack(Direction directions[], Square sq, Bitboard occupied) {
|
||||||
|
|
||||||
Bitboard attack = 0;
|
Bitboard attack = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
for (Square s = sq + deltas[i];
|
for (Square s = sq + directions[i];
|
||||||
is_ok(s) && distance(s, s - deltas[i]) == 1;
|
is_ok(s) && distance(s, s - directions[i]) == 1;
|
||||||
s += deltas[i])
|
s += directions[i])
|
||||||
{
|
{
|
||||||
attack |= s;
|
attack |= s;
|
||||||
|
|
||||||
@@ -240,17 +249,14 @@ namespace {
|
|||||||
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
|
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
|
||||||
// use the so called "fancy" approach.
|
// use the so called "fancy" approach.
|
||||||
|
|
||||||
void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
|
void init_magics(Bitboard table[], Magic magics[], Direction directions[]) {
|
||||||
Bitboard masks[], unsigned shifts[], Square deltas[], Fn index) {
|
|
||||||
|
|
||||||
|
// Optimal PRNG seeds to pick the correct magics in the shortest time
|
||||||
int seeds[][RANK_NB] = { { 8977, 44560, 54343, 38998, 5731, 95205, 104912, 17020 },
|
int seeds[][RANK_NB] = { { 8977, 44560, 54343, 38998, 5731, 95205, 104912, 17020 },
|
||||||
{ 728, 10316, 55013, 32803, 12281, 15100, 16645, 255 } };
|
{ 728, 10316, 55013, 32803, 12281, 15100, 16645, 255 } };
|
||||||
|
|
||||||
Bitboard occupancy[4096], reference[4096], edges, b;
|
Bitboard occupancy[4096], reference[4096], edges, b;
|
||||||
int age[4096] = {0}, current = 0, i, size;
|
int epoch[4096] = {}, cnt = 0, size = 0;
|
||||||
|
|
||||||
// attacks[s] is a pointer to the beginning of the attacks table for square 's'
|
|
||||||
attacks[SQ_A1] = table;
|
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
@@ -262,28 +268,28 @@ namespace {
|
|||||||
// all the attacks for each possible subset of the mask and so is 2 power
|
// all the attacks for each possible subset of the mask and so is 2 power
|
||||||
// the number of 1s of the mask. Hence we deduce the size of the shift to
|
// the number of 1s of the mask. Hence we deduce the size of the shift to
|
||||||
// apply to the 64 or 32 bits word to get the index.
|
// apply to the 64 or 32 bits word to get the index.
|
||||||
masks[s] = sliding_attack(deltas, s, 0) & ~edges;
|
Magic& m = magics[s];
|
||||||
shifts[s] = (Is64Bit ? 64 : 32) - popcount<Max15>(masks[s]);
|
m.mask = sliding_attack(directions, s, 0) & ~edges;
|
||||||
|
m.shift = (Is64Bit ? 64 : 32) - popcount(m.mask);
|
||||||
|
|
||||||
|
// Set the offset for the attacks table of the square. We have individual
|
||||||
|
// table sizes for each square with "Fancy Magic Bitboards".
|
||||||
|
m.attacks = s == SQ_A1 ? table : magics[s - 1].attacks + size;
|
||||||
|
|
||||||
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and
|
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and
|
||||||
// store the corresponding sliding attack bitboard in reference[].
|
// store the corresponding sliding attack bitboard in reference[].
|
||||||
b = size = 0;
|
b = size = 0;
|
||||||
do {
|
do {
|
||||||
occupancy[size] = b;
|
occupancy[size] = b;
|
||||||
reference[size] = sliding_attack(deltas, s, b);
|
reference[size] = sliding_attack(directions, s, b);
|
||||||
|
|
||||||
if (HasPext)
|
if (HasPext)
|
||||||
attacks[s][pext(b, masks[s])] = reference[size];
|
m.attacks[pext(b, m.mask)] = reference[size];
|
||||||
|
|
||||||
size++;
|
size++;
|
||||||
b = (b - masks[s]) & masks[s];
|
b = (b - m.mask) & m.mask;
|
||||||
} while (b);
|
} while (b);
|
||||||
|
|
||||||
// Set the offset for the table of the next square. We have individual
|
|
||||||
// table sizes for each square with "Fancy Magic Bitboards".
|
|
||||||
if (s < SQ_H8)
|
|
||||||
attacks[s + 1] = attacks[s] + size;
|
|
||||||
|
|
||||||
if (HasPext)
|
if (HasPext)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -291,28 +297,30 @@ namespace {
|
|||||||
|
|
||||||
// Find a magic for square 's' picking up an (almost) random number
|
// Find a magic for square 's' picking up an (almost) random number
|
||||||
// until we find the one that passes the verification test.
|
// until we find the one that passes the verification test.
|
||||||
do {
|
for (int i = 0; i < size; )
|
||||||
do
|
{
|
||||||
magics[s] = rng.sparse_rand<Bitboard>();
|
for (m.magic = 0; popcount((m.magic * m.mask) >> 56) < 6; )
|
||||||
while (popcount<Max15>((magics[s] * masks[s]) >> 56) < 6);
|
m.magic = rng.sparse_rand<Bitboard>();
|
||||||
|
|
||||||
// A good magic must map every possible occupancy to an index that
|
// A good magic must map every possible occupancy to an index that
|
||||||
// looks up the correct sliding attack in the attacks[s] database.
|
// looks up the correct sliding attack in the attacks[s] database.
|
||||||
// Note that we build up the database for square 's' as a side
|
// Note that we build up the database for square 's' as a side
|
||||||
// effect of verifying the magic.
|
// effect of verifying the magic. Keep track of the attempt count
|
||||||
for (++current, i = 0; i < size; ++i)
|
// and save it in epoch[], little speed-up trick to avoid resetting
|
||||||
|
// m.attacks[] after every failed attempt.
|
||||||
|
for (++cnt, i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
unsigned idx = index(s, occupancy[i]);
|
unsigned idx = m.index(occupancy[i]);
|
||||||
|
|
||||||
if (age[idx] < current)
|
if (epoch[idx] < cnt)
|
||||||
{
|
{
|
||||||
age[idx] = current;
|
epoch[idx] = cnt;
|
||||||
attacks[s][idx] = reference[i];
|
m.attacks[idx] = reference[i];
|
||||||
}
|
}
|
||||||
else if (attacks[s][idx] != reference[i])
|
else if (m.attacks[idx] != reference[i])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (i < size);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+97
-90
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -39,6 +39,7 @@ const std::string pretty(Bitboard b);
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Bitboard AllSquares = ~Bitboard(0);
|
||||||
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
const Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
@@ -61,29 +62,45 @@ const Bitboard Rank8BB = Rank1BB << (8 * 7);
|
|||||||
|
|
||||||
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
|
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
|
|
||||||
extern Bitboard RookMasks [SQUARE_NB];
|
|
||||||
extern Bitboard RookMagics [SQUARE_NB];
|
|
||||||
extern Bitboard* RookAttacks[SQUARE_NB];
|
|
||||||
extern unsigned RookShifts [SQUARE_NB];
|
|
||||||
|
|
||||||
extern Bitboard BishopMasks [SQUARE_NB];
|
|
||||||
extern Bitboard BishopMagics [SQUARE_NB];
|
|
||||||
extern Bitboard* BishopAttacks[SQUARE_NB];
|
|
||||||
extern unsigned BishopShifts [SQUARE_NB];
|
|
||||||
|
|
||||||
extern Bitboard SquareBB[SQUARE_NB];
|
extern Bitboard SquareBB[SQUARE_NB];
|
||||||
extern Bitboard FileBB[FILE_NB];
|
extern Bitboard FileBB[FILE_NB];
|
||||||
extern Bitboard RankBB[RANK_NB];
|
extern Bitboard RankBB[RANK_NB];
|
||||||
extern Bitboard AdjacentFilesBB[FILE_NB];
|
extern Bitboard AdjacentFilesBB[FILE_NB];
|
||||||
extern Bitboard InFrontBB[COLOR_NB][RANK_NB];
|
extern Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
|
||||||
extern Bitboard StepAttacksBB[PIECE_NB][SQUARE_NB];
|
|
||||||
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
|
||||||
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
|
||||||
extern Bitboard DistanceRingBB[SQUARE_NB][8];
|
extern Bitboard DistanceRingBB[SQUARE_NB][8];
|
||||||
extern Bitboard ForwardBB[COLOR_NB][SQUARE_NB];
|
extern Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
|
||||||
extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
|
||||||
extern Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
extern Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
|
||||||
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
|
||||||
|
extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
|
||||||
|
|
||||||
|
|
||||||
|
/// Magic holds all magic bitboards relevant data for a single square
|
||||||
|
struct Magic {
|
||||||
|
Bitboard mask;
|
||||||
|
Bitboard magic;
|
||||||
|
Bitboard* attacks;
|
||||||
|
unsigned shift;
|
||||||
|
|
||||||
|
// Compute the attack's index using the 'magic bitboards' approach
|
||||||
|
unsigned index(Bitboard occupied) const {
|
||||||
|
|
||||||
|
if (HasPext)
|
||||||
|
return unsigned(pext(occupied, mask));
|
||||||
|
|
||||||
|
if (Is64Bit)
|
||||||
|
return unsigned(((occupied & mask) * magic) >> shift);
|
||||||
|
|
||||||
|
unsigned lo = unsigned(occupied) & unsigned(mask);
|
||||||
|
unsigned hi = unsigned(occupied >> 32) & unsigned(mask >> 32);
|
||||||
|
return (lo * unsigned(magic) ^ hi * unsigned(magic >> 32)) >> shift;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Magic RookMagics[SQUARE_NB];
|
||||||
|
extern Magic BishopMagics[SQUARE_NB];
|
||||||
|
|
||||||
|
|
||||||
/// Overloads of bitwise operators between a Bitboard and a Square for testing
|
/// Overloads of bitwise operators between a Bitboard and a Square for testing
|
||||||
@@ -109,11 +126,10 @@ inline Bitboard& operator^=(Bitboard& b, Square s) {
|
|||||||
return b ^= SquareBB[s];
|
return b ^= SquareBB[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool more_than_one(Bitboard b) {
|
constexpr bool more_than_one(Bitboard b) {
|
||||||
return b & (b - 1);
|
return b & (b - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
||||||
/// the given file or rank.
|
/// the given file or rank.
|
||||||
|
|
||||||
@@ -134,13 +150,13 @@ inline Bitboard file_bb(Square s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// shift_bb() moves a bitboard one step along direction Delta. Mainly for pawns
|
/// shift() moves a bitboard one step along direction D. Mainly for pawns
|
||||||
|
|
||||||
template<Square Delta>
|
template<Direction D>
|
||||||
inline Bitboard shift_bb(Bitboard b) {
|
constexpr Bitboard shift(Bitboard b) {
|
||||||
return Delta == DELTA_N ? b << 8 : Delta == DELTA_S ? b >> 8
|
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
|
||||||
: Delta == DELTA_NE ? (b & ~FileHBB) << 9 : Delta == DELTA_SE ? (b & ~FileHBB) >> 7
|
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7
|
||||||
: Delta == DELTA_NW ? (b & ~FileABB) << 7 : Delta == DELTA_SW ? (b & ~FileABB) >> 9
|
: D == NORTH_WEST ? (b & ~FileABB) << 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,28 +179,28 @@ inline Bitboard between_bb(Square s1, Square s2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// in_front_bb() returns a bitboard representing all the squares on all the ranks
|
/// forward_ranks_bb() returns a bitboard representing all the squares on all the ranks
|
||||||
/// in front of the given one, from the point of view of the given color. For
|
/// in front of the given one, from the point of view of the given color. For
|
||||||
/// instance, in_front_bb(BLACK, RANK_3) will return the squares on ranks 1 and 2.
|
/// instance, forward_ranks_bb(BLACK, SQ_D3) will return the 16 squares on ranks 1 and 2.
|
||||||
|
|
||||||
inline Bitboard in_front_bb(Color c, Rank r) {
|
inline Bitboard forward_ranks_bb(Color c, Square s) {
|
||||||
return InFrontBB[c][r];
|
return ForwardRanksBB[c][rank_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// forward_bb() returns a bitboard representing all the squares along the line
|
/// forward_file_bb() returns a bitboard representing all the squares along the line
|
||||||
/// in front of the given one, from the point of view of the given color:
|
/// in front of the given one, from the point of view of the given color:
|
||||||
/// ForwardBB[c][s] = in_front_bb(c, s) & file_bb(s)
|
/// ForwardFileBB[c][s] = forward_ranks_bb(c, s) & file_bb(s)
|
||||||
|
|
||||||
inline Bitboard forward_bb(Color c, Square s) {
|
inline Bitboard forward_file_bb(Color c, Square s) {
|
||||||
return ForwardBB[c][s];
|
return ForwardFileBB[c][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// pawn_attack_span() returns a bitboard representing all the squares that can be
|
/// pawn_attack_span() returns a bitboard representing all the squares that can be
|
||||||
/// attacked by a pawn of the given color when it moves along its file, starting
|
/// attacked by a pawn of the given color when it moves along its file, starting
|
||||||
/// from the given square:
|
/// from the given square:
|
||||||
/// PawnAttackSpan[c][s] = in_front_bb(c, s) & adjacent_files_bb(s);
|
/// PawnAttackSpan[c][s] = forward_ranks_bb(c, s) & adjacent_files_bb(file_of(s));
|
||||||
|
|
||||||
inline Bitboard pawn_attack_span(Color c, Square s) {
|
inline Bitboard pawn_attack_span(Color c, Square s) {
|
||||||
return PawnAttackSpan[c][s];
|
return PawnAttackSpan[c][s];
|
||||||
@@ -193,7 +209,7 @@ inline Bitboard pawn_attack_span(Color c, Square s) {
|
|||||||
|
|
||||||
/// passed_pawn_mask() returns a bitboard mask which can be used to test if a
|
/// passed_pawn_mask() returns a bitboard mask which can be used to test if a
|
||||||
/// pawn of the given color and on the given square is a passed pawn:
|
/// pawn of the given color and on the given square is a passed pawn:
|
||||||
/// PassedPawnMask[c][s] = pawn_attack_span(c, s) | forward_bb(c, s)
|
/// PassedPawnMask[c][s] = pawn_attack_span(c, s) | forward_file_bb(c, s)
|
||||||
|
|
||||||
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
inline Bitboard passed_pawn_mask(Color c, Square s) {
|
||||||
return PassedPawnMask[c][s];
|
return PassedPawnMask[c][s];
|
||||||
@@ -220,93 +236,84 @@ template<> inline int distance<Rank>(Square x, Square y) { return distance(rank_
|
|||||||
|
|
||||||
|
|
||||||
/// attacks_bb() returns a bitboard representing all the squares attacked by a
|
/// attacks_bb() returns a bitboard representing all the squares attacked by a
|
||||||
/// piece of type Pt (bishop or rook) placed on 's'. The helper magic_index()
|
/// piece of type Pt (bishop or rook) placed on 's'.
|
||||||
/// looks up the index using the 'magic bitboards' approach.
|
|
||||||
template<PieceType Pt>
|
|
||||||
inline unsigned magic_index(Square s, Bitboard occupied) {
|
|
||||||
|
|
||||||
Bitboard* const Masks = Pt == ROOK ? RookMasks : BishopMasks;
|
|
||||||
Bitboard* const Magics = Pt == ROOK ? RookMagics : BishopMagics;
|
|
||||||
unsigned* const Shifts = Pt == ROOK ? RookShifts : BishopShifts;
|
|
||||||
|
|
||||||
if (HasPext)
|
|
||||||
return unsigned(pext(occupied, Masks[s]));
|
|
||||||
|
|
||||||
if (Is64Bit)
|
|
||||||
return unsigned(((occupied & Masks[s]) * Magics[s]) >> Shifts[s]);
|
|
||||||
|
|
||||||
unsigned lo = unsigned(occupied) & unsigned(Masks[s]);
|
|
||||||
unsigned hi = unsigned(occupied >> 32) & unsigned(Masks[s] >> 32);
|
|
||||||
return (lo * unsigned(Magics[s]) ^ hi * unsigned(Magics[s] >> 32)) >> Shifts[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
template<PieceType Pt>
|
template<PieceType Pt>
|
||||||
inline Bitboard attacks_bb(Square s, Bitboard occupied) {
|
inline Bitboard attacks_bb(Square s, Bitboard occupied) {
|
||||||
return (Pt == ROOK ? RookAttacks : BishopAttacks)[s][magic_index<Pt>(s, occupied)];
|
|
||||||
|
const Magic& m = Pt == ROOK ? RookMagics[s] : BishopMagics[s];
|
||||||
|
return m.attacks[m.index(occupied)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occupied) {
|
inline Bitboard attacks_bb(PieceType pt, Square s, Bitboard occupied) {
|
||||||
|
|
||||||
switch (type_of(pc))
|
assert(pt != PAWN);
|
||||||
|
|
||||||
|
switch (pt)
|
||||||
{
|
{
|
||||||
case BISHOP: return attacks_bb<BISHOP>(s, occupied);
|
case BISHOP: return attacks_bb<BISHOP>(s, occupied);
|
||||||
case ROOK : return attacks_bb<ROOK>(s, occupied);
|
case ROOK : return attacks_bb< ROOK>(s, occupied);
|
||||||
case QUEEN : return attacks_bb<BISHOP>(s, occupied) | attacks_bb<ROOK>(s, occupied);
|
case QUEEN : return attacks_bb<BISHOP>(s, occupied) | attacks_bb<ROOK>(s, occupied);
|
||||||
default : return StepAttacksBB[pc][s];
|
default : return PseudoAttacks[pt][s];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// popcount() counts the number of non-zero bits in a bitboard
|
||||||
|
|
||||||
|
inline int popcount(Bitboard b) {
|
||||||
|
|
||||||
|
#ifndef USE_POPCNT
|
||||||
|
|
||||||
|
extern uint8_t PopCnt16[1 << 16];
|
||||||
|
union { Bitboard bb; uint16_t u[4]; } v = { b };
|
||||||
|
return PopCnt16[v.u[0]] + PopCnt16[v.u[1]] + PopCnt16[v.u[2]] + PopCnt16[v.u[3]];
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||||
|
|
||||||
|
return (int)_mm_popcnt_u64(b);
|
||||||
|
|
||||||
|
#else // Assumed gcc or compatible compiler
|
||||||
|
|
||||||
|
return __builtin_popcountll(b);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
|
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
|
||||||
|
|
||||||
#ifdef USE_BSFQ
|
#if defined(__GNUC__)
|
||||||
|
|
||||||
# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
|
|
||||||
|
|
||||||
inline Square lsb(Bitboard b) {
|
inline Square lsb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
return Square(__builtin_ctzll(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Square msb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
|
return Square(63 ^ __builtin_clzll(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(_WIN64) && defined(_MSC_VER)
|
||||||
|
|
||||||
|
inline Square lsb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
unsigned long idx;
|
unsigned long idx;
|
||||||
_BitScanForward64(&idx, b);
|
_BitScanForward64(&idx, b);
|
||||||
return (Square) idx;
|
return (Square) idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square msb(Bitboard b) {
|
inline Square msb(Bitboard b) {
|
||||||
|
assert(b);
|
||||||
unsigned long idx;
|
unsigned long idx;
|
||||||
_BitScanReverse64(&idx, b);
|
_BitScanReverse64(&idx, b);
|
||||||
return (Square) idx;
|
return (Square) idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
# elif defined(__arm__)
|
#else
|
||||||
|
|
||||||
inline int lsb32(uint32_t v) {
|
#define NO_BSF // Fallback on software implementation for other cases
|
||||||
__asm__("rbit %0, %1" : "=r"(v) : "r"(v));
|
|
||||||
return __builtin_clz(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square msb(Bitboard b) {
|
|
||||||
return (Square) (63 - __builtin_clzll(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square lsb(Bitboard b) {
|
|
||||||
return (Square) (uint32_t(b) ? lsb32(uint32_t(b)) : 32 + lsb32(uint32_t(b >> 32)));
|
|
||||||
}
|
|
||||||
|
|
||||||
# else // Assumed gcc or compatible compiler
|
|
||||||
|
|
||||||
inline Square lsb(Bitboard b) { // Assembly code by Heinz van Saanen
|
|
||||||
Bitboard idx;
|
|
||||||
__asm__("bsfq %1, %0": "=r"(idx): "rm"(b) );
|
|
||||||
return (Square) idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Square msb(Bitboard b) {
|
|
||||||
Bitboard idx;
|
|
||||||
__asm__("bsrq %1, %0": "=r"(idx): "rm"(b) );
|
|
||||||
return (Square) idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#else // ifdef(USE_BSFQ)
|
|
||||||
|
|
||||||
Square lsb(Bitboard b);
|
Square lsb(Bitboard b);
|
||||||
Square msb(Bitboard b);
|
Square msb(Bitboard b);
|
||||||
|
|||||||
-105
@@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BITCOUNT_H_INCLUDED
|
|
||||||
#define BITCOUNT_H_INCLUDED
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
enum BitCountType {
|
|
||||||
CNT_64,
|
|
||||||
CNT_64_MAX15,
|
|
||||||
CNT_32,
|
|
||||||
CNT_32_MAX15,
|
|
||||||
CNT_HW_POPCNT
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Determine at compile time the best popcount<> specialization according to
|
|
||||||
/// whether the platform is 32 or 64 bit, the maximum number of non-zero
|
|
||||||
/// bits to count and if the hardware popcnt instruction is available.
|
|
||||||
const BitCountType Full = HasPopCnt ? CNT_HW_POPCNT : Is64Bit ? CNT_64 : CNT_32;
|
|
||||||
const BitCountType Max15 = HasPopCnt ? CNT_HW_POPCNT : Is64Bit ? CNT_64_MAX15 : CNT_32_MAX15;
|
|
||||||
|
|
||||||
|
|
||||||
/// popcount() counts the number of non-zero bits in a bitboard
|
|
||||||
template<BitCountType> inline int popcount(Bitboard);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_64>(Bitboard b) {
|
|
||||||
b -= (b >> 1) & 0x5555555555555555ULL;
|
|
||||||
b = ((b >> 2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
|
||||||
b = ((b >> 4) + b) & 0x0F0F0F0F0F0F0F0FULL;
|
|
||||||
return (b * 0x0101010101010101ULL) >> 56;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_64_MAX15>(Bitboard b) {
|
|
||||||
b -= (b >> 1) & 0x5555555555555555ULL;
|
|
||||||
b = ((b >> 2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
|
|
||||||
return (b * 0x1111111111111111ULL) >> 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_32>(Bitboard b) {
|
|
||||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
|
||||||
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
|
||||||
w -= (w >> 1) & 0x55555555;
|
|
||||||
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
|
||||||
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
|
||||||
v = ((v >> 4) + v + (w >> 4) + w) & 0x0F0F0F0F;
|
|
||||||
return (v * 0x01010101) >> 24;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_32_MAX15>(Bitboard b) {
|
|
||||||
unsigned w = unsigned(b >> 32), v = unsigned(b);
|
|
||||||
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
|
|
||||||
w -= (w >> 1) & 0x55555555;
|
|
||||||
v = ((v >> 2) & 0x33333333) + (v & 0x33333333); // 0-4 in 4 bits
|
|
||||||
w = ((w >> 2) & 0x33333333) + (w & 0x33333333);
|
|
||||||
return ((v + w) * 0x11111111) >> 28;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline int popcount<CNT_HW_POPCNT>(Bitboard b) {
|
|
||||||
|
|
||||||
#ifndef USE_POPCNT
|
|
||||||
|
|
||||||
assert(false);
|
|
||||||
return b != 0; // Avoid 'b not used' warning
|
|
||||||
|
|
||||||
#elif defined(_MSC_VER) && defined(__INTEL_COMPILER)
|
|
||||||
|
|
||||||
return _mm_popcnt_u64(b);
|
|
||||||
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
|
|
||||||
return (int)__popcnt64(b);
|
|
||||||
|
|
||||||
#else // Assumed gcc or compatible compiler
|
|
||||||
|
|
||||||
return __builtin_popcountll(b);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // #ifndef BITCOUNT_H_INCLUDED
|
|
||||||
+18
-47
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "bitcount.h"
|
|
||||||
#include "endgame.h"
|
#include "endgame.h"
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
|
|
||||||
@@ -84,25 +83,6 @@ namespace {
|
|||||||
return sq;
|
return sq;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the material key of Position out of the given endgame key code
|
|
||||||
// like "KBPKN". The trick here is to first forge an ad-hoc FEN string
|
|
||||||
// and then let a Position object do the work for us.
|
|
||||||
Key key(const string& code, Color c) {
|
|
||||||
|
|
||||||
assert(code.length() > 0 && code.length() < 8);
|
|
||||||
assert(code[0] == 'K');
|
|
||||||
|
|
||||||
string sides[] = { code.substr(code.find('K', 1)), // Weak
|
|
||||||
code.substr(0, code.find('K', 1)) }; // Strong
|
|
||||||
|
|
||||||
std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
|
|
||||||
|
|
||||||
string fen = sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
|
|
||||||
+ sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";
|
|
||||||
|
|
||||||
return Position(fen, false, nullptr).material_key();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
@@ -130,13 +110,6 @@ Endgames::Endgames() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<EndgameType E, typename T>
|
|
||||||
void Endgames::add(const string& code) {
|
|
||||||
map<T>()[key(code, WHITE)] = std::unique_ptr<EndgameBase<T>>(new Endgame<E>(WHITE));
|
|
||||||
map<T>()[key(code, BLACK)] = std::unique_ptr<EndgameBase<T>>(new Endgame<E>(BLACK));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Mate with KX vs K. This function is used to evaluate positions with
|
/// Mate with KX vs K. This function is used to evaluate positions with
|
||||||
/// king and plenty of material vs a lone king. It simply gives the
|
/// king and plenty of material vs a lone king. It simply gives the
|
||||||
/// attacking side a bonus for driving the defending king towards the edge
|
/// attacking side a bonus for driving the defending king towards the edge
|
||||||
@@ -162,8 +135,8 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
|
|||||||
if ( pos.count<QUEEN>(strongSide)
|
if ( pos.count<QUEEN>(strongSide)
|
||||||
|| pos.count<ROOK>(strongSide)
|
|| pos.count<ROOK>(strongSide)
|
||||||
||(pos.count<BISHOP>(strongSide) && pos.count<KNIGHT>(strongSide))
|
||(pos.count<BISHOP>(strongSide) && pos.count<KNIGHT>(strongSide))
|
||||||
||(pos.count<BISHOP>(strongSide) > 1 && opposite_colors(pos.squares<BISHOP>(strongSide)[0],
|
|| ( (pos.pieces(strongSide, BISHOP) & ~DarkSquares)
|
||||||
pos.squares<BISHOP>(strongSide)[1])))
|
&& (pos.pieces(strongSide, BISHOP) & DarkSquares)))
|
||||||
result = std::min(result + VALUE_KNOWN_WIN, VALUE_MATE_IN_MAX_PLY - 1);
|
result = std::min(result + VALUE_KNOWN_WIN, VALUE_MATE_IN_MAX_PLY - 1);
|
||||||
|
|
||||||
return strongSide == pos.side_to_move() ? result : -result;
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
@@ -259,8 +232,8 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
|||||||
result = Value(80) - 8 * distance(wksq, psq);
|
result = Value(80) - 8 * distance(wksq, psq);
|
||||||
|
|
||||||
else
|
else
|
||||||
result = Value(200) - 8 * ( distance(wksq, psq + DELTA_S)
|
result = Value(200) - 8 * ( distance(wksq, psq + SOUTH)
|
||||||
- distance(bksq, psq + DELTA_S)
|
- distance(bksq, psq + SOUTH)
|
||||||
- distance(psq, queeningSq));
|
- distance(psq, queeningSq));
|
||||||
|
|
||||||
return strongSide == pos.side_to_move() ? result : -result;
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
@@ -496,7 +469,7 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
|
|||||||
// If the defending king blocks the pawn and the attacking king is too far
|
// If the defending king blocks the pawn and the attacking king is too far
|
||||||
// away, it's a draw.
|
// away, it's a draw.
|
||||||
if ( r <= RANK_5
|
if ( r <= RANK_5
|
||||||
&& bksq == wpsq + DELTA_N
|
&& bksq == wpsq + NORTH
|
||||||
&& distance(wksq, wpsq) - tempo >= 2
|
&& distance(wksq, wpsq) - tempo >= 2
|
||||||
&& distance(wksq, brsq) - tempo >= 2)
|
&& distance(wksq, brsq) - tempo >= 2)
|
||||||
return SCALE_FACTOR_DRAW;
|
return SCALE_FACTOR_DRAW;
|
||||||
@@ -517,10 +490,10 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
|
|||||||
&& file_of(wrsq) == f
|
&& file_of(wrsq) == f
|
||||||
&& wrsq < wpsq
|
&& wrsq < wpsq
|
||||||
&& (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo)
|
&& (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo)
|
||||||
&& (distance(wksq, wpsq + DELTA_N) < distance(bksq, wpsq + DELTA_N) - 2 + tempo)
|
&& (distance(wksq, wpsq + NORTH) < distance(bksq, wpsq + NORTH) - 2 + tempo)
|
||||||
&& ( distance(bksq, wrsq) + tempo >= 3
|
&& ( distance(bksq, wrsq) + tempo >= 3
|
||||||
|| ( distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo
|
|| ( distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo
|
||||||
&& (distance(wksq, wpsq + DELTA_N) < distance(bksq, wrsq) + tempo))))
|
&& (distance(wksq, wpsq + NORTH) < distance(bksq, wrsq) + tempo))))
|
||||||
return ScaleFactor( SCALE_FACTOR_MAX
|
return ScaleFactor( SCALE_FACTOR_MAX
|
||||||
- 8 * distance(wpsq, queeningSq)
|
- 8 * distance(wpsq, queeningSq)
|
||||||
- 2 * distance(wksq, queeningSq));
|
- 2 * distance(wksq, queeningSq));
|
||||||
@@ -551,7 +524,7 @@ ScaleFactor Endgame<KRPKB>::operator()(const Position& pos) const {
|
|||||||
Square bsq = pos.square<BISHOP>(weakSide);
|
Square bsq = pos.square<BISHOP>(weakSide);
|
||||||
Square psq = pos.square<PAWN>(strongSide);
|
Square psq = pos.square<PAWN>(strongSide);
|
||||||
Rank rk = relative_rank(strongSide, psq);
|
Rank rk = relative_rank(strongSide, psq);
|
||||||
Square push = pawn_push(strongSide);
|
Direction push = pawn_push(strongSide);
|
||||||
|
|
||||||
// If the pawn is on the 5th rank and the pawn (currently) is on
|
// If the pawn is on the 5th rank and the pawn (currently) is on
|
||||||
// the same color square as the bishop then there is a chance of
|
// the same color square as the bishop then there is a chance of
|
||||||
@@ -625,7 +598,7 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
|
|||||||
|
|
||||||
// If all pawns are ahead of the king, on a single rook file and
|
// If all pawns are ahead of the king, on a single rook file and
|
||||||
// the king is within one file of the pawns, it's a draw.
|
// the king is within one file of the pawns, it's a draw.
|
||||||
if ( !(pawns & ~in_front_bb(weakSide, rank_of(ksq)))
|
if ( !(pawns & ~forward_ranks_bb(weakSide, ksq))
|
||||||
&& !((pawns & ~FileABB) && (pawns & ~FileHBB))
|
&& !((pawns & ~FileABB) && (pawns & ~FileHBB))
|
||||||
&& distance<File>(ksq, lsb(pawns)) <= 1)
|
&& distance<File>(ksq, lsb(pawns)) <= 1)
|
||||||
return SCALE_FACTOR_DRAW;
|
return SCALE_FACTOR_DRAW;
|
||||||
@@ -671,17 +644,15 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
|
|||||||
|
|
||||||
if (relative_rank(strongSide, pawnSq) <= RANK_5)
|
if (relative_rank(strongSide, pawnSq) <= RANK_5)
|
||||||
return SCALE_FACTOR_DRAW;
|
return SCALE_FACTOR_DRAW;
|
||||||
else
|
|
||||||
{
|
|
||||||
Bitboard path = forward_bb(strongSide, pawnSq);
|
|
||||||
|
|
||||||
if (path & pos.pieces(weakSide, KING))
|
Bitboard path = forward_file_bb(strongSide, pawnSq);
|
||||||
return SCALE_FACTOR_DRAW;
|
|
||||||
|
|
||||||
if ( (pos.attacks_from<BISHOP>(weakBishopSq) & path)
|
if (path & pos.pieces(weakSide, KING))
|
||||||
&& distance(weakBishopSq, pawnSq) >= 3)
|
return SCALE_FACTOR_DRAW;
|
||||||
return SCALE_FACTOR_DRAW;
|
|
||||||
}
|
if ( (pos.attacks_from<BISHOP>(weakBishopSq) & path)
|
||||||
|
&& distance(weakBishopSq, pawnSq) >= 3)
|
||||||
|
return SCALE_FACTOR_DRAW;
|
||||||
}
|
}
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
}
|
}
|
||||||
@@ -809,7 +780,7 @@ ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
|
|||||||
|
|
||||||
// King needs to get close to promoting pawn to prevent knight from blocking.
|
// King needs to get close to promoting pawn to prevent knight from blocking.
|
||||||
// Rules for this are very tricky, so just approximate.
|
// Rules for this are very tricky, so just approximate.
|
||||||
if (forward_bb(strongSide, pawnSq) & pos.attacks_from<BISHOP>(bishopSq))
|
if (forward_file_bb(strongSide, pawnSq) & pos.attacks_from<BISHOP>(bishopSq))
|
||||||
return ScaleFactor(distance(weakKingSq, pawnSq));
|
return ScaleFactor(distance(weakKingSq, pawnSq));
|
||||||
|
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
|
|||||||
+22
-22
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,12 +31,11 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
|
||||||
/// EndgameType lists all supported endgames
|
/// EndgameCode lists all supported endgame functions by corresponding codes
|
||||||
|
|
||||||
enum EndgameType {
|
enum EndgameCode {
|
||||||
|
|
||||||
// Evaluation functions
|
|
||||||
|
|
||||||
|
EVALUATION_FUNCTIONS,
|
||||||
KNNK, // KNN vs K
|
KNNK, // KNN vs K
|
||||||
KXK, // Generic "mate lone king" eval
|
KXK, // Generic "mate lone king" eval
|
||||||
KBNK, // KBN vs K
|
KBNK, // KBN vs K
|
||||||
@@ -47,10 +46,7 @@ enum EndgameType {
|
|||||||
KQKP, // KQ vs KP
|
KQKP, // KQ vs KP
|
||||||
KQKR, // KQ vs KR
|
KQKR, // KQ vs KR
|
||||||
|
|
||||||
|
|
||||||
// Scaling functions
|
|
||||||
SCALING_FUNCTIONS,
|
SCALING_FUNCTIONS,
|
||||||
|
|
||||||
KBPsK, // KB and pawns vs K
|
KBPsK, // KB and pawns vs K
|
||||||
KQKRPs, // KQ vs KR and pawns
|
KQKRPs, // KQ vs KR and pawns
|
||||||
KRPKR, // KRP vs KR
|
KRPKR, // KRP vs KR
|
||||||
@@ -68,30 +64,28 @@ enum EndgameType {
|
|||||||
|
|
||||||
/// Endgame functions can be of two types depending on whether they return a
|
/// Endgame functions can be of two types depending on whether they return a
|
||||||
/// Value or a ScaleFactor.
|
/// Value or a ScaleFactor.
|
||||||
template<EndgameType E> using
|
template<EndgameCode E> using
|
||||||
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
||||||
|
|
||||||
|
|
||||||
/// Base and derived templates for endgame evaluation and scaling functions
|
/// Base and derived functors for endgame evaluation and scaling functions
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct EndgameBase {
|
struct EndgameBase {
|
||||||
|
|
||||||
|
explicit EndgameBase(Color c) : strongSide(c), weakSide(~c) {}
|
||||||
virtual ~EndgameBase() = default;
|
virtual ~EndgameBase() = default;
|
||||||
virtual Color strong_side() const = 0;
|
|
||||||
virtual T operator()(const Position&) const = 0;
|
virtual T operator()(const Position&) const = 0;
|
||||||
|
|
||||||
|
const Color strongSide, weakSide;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<EndgameType E, typename T = eg_type<E>>
|
template<EndgameCode E, typename T = eg_type<E>>
|
||||||
struct Endgame : public EndgameBase<T> {
|
struct Endgame : public EndgameBase<T> {
|
||||||
|
|
||||||
explicit Endgame(Color c) : strongSide(c), weakSide(~c) {}
|
explicit Endgame(Color c) : EndgameBase<T>(c) {}
|
||||||
Color strong_side() const { return strongSide; }
|
T operator()(const Position&) const override;
|
||||||
T operator()(const Position&) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Color strongSide, weakSide;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -101,16 +95,22 @@ private:
|
|||||||
|
|
||||||
class Endgames {
|
class Endgames {
|
||||||
|
|
||||||
template<typename T> using Map = std::map<Key, std::unique_ptr<EndgameBase<T>>>;
|
template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
|
||||||
|
template<typename T> using Map = std::map<Key, Ptr<T>>;
|
||||||
template<EndgameType E, typename T = eg_type<E>>
|
|
||||||
void add(const std::string& code);
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Map<T>& map() {
|
Map<T>& map() {
|
||||||
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<EndgameCode E, typename T = eg_type<E>, typename P = Ptr<T>>
|
||||||
|
void add(const std::string& code) {
|
||||||
|
|
||||||
|
StateInfo st;
|
||||||
|
map<T>()[Position().set(code, WHITE, &st).material_key()] = P(new Endgame<E>(WHITE));
|
||||||
|
map<T>()[Position().set(code, BLACK, &st).material_key()] = P(new Endgame<E>(BLACK));
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
+512
-469
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,10 +31,10 @@ namespace Eval {
|
|||||||
|
|
||||||
const Value Tempo = Value(20); // Must be visible to search
|
const Value Tempo = Value(20); // Must be visible to search
|
||||||
|
|
||||||
void init();
|
extern Score Contempt;
|
||||||
|
|
||||||
std::string trace(const Position& pos);
|
std::string trace(const Position& pos);
|
||||||
|
|
||||||
template<bool DoTrace = false>
|
|
||||||
Value evaluate(const Position& pos);
|
Value evaluate(const Position& pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-5
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,7 +21,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "evaluate.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
@@ -29,6 +28,10 @@
|
|||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
#include "syzygy/tbprobe.h"
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
|
namespace PSQT {
|
||||||
|
void init();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
std::cout << engine_info() << std::endl;
|
std::cout << engine_info() << std::endl;
|
||||||
@@ -39,14 +42,14 @@ int main(int argc, char* argv[]) {
|
|||||||
Position::init();
|
Position::init();
|
||||||
Bitbases::init();
|
Bitbases::init();
|
||||||
Search::init();
|
Search::init();
|
||||||
Eval::init();
|
|
||||||
Pawns::init();
|
Pawns::init();
|
||||||
Threads.init();
|
|
||||||
Tablebases::init(Options["SyzygyPath"]);
|
Tablebases::init(Options["SyzygyPath"]);
|
||||||
TT.resize(Options["Hash"]);
|
TT.resize(Options["Hash"]);
|
||||||
|
Threads.set(Options["Threads"]);
|
||||||
|
Search::clear(); // After threads are up
|
||||||
|
|
||||||
UCI::loop(argc, argv);
|
UCI::loop(argc, argv);
|
||||||
|
|
||||||
Threads.exit();
|
Threads.set(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,18 +31,15 @@ namespace {
|
|||||||
|
|
||||||
// Polynomial material imbalance parameters
|
// Polynomial material imbalance parameters
|
||||||
|
|
||||||
// pair pawn knight bishop rook queen
|
|
||||||
const int Linear[6] = { 1667, -168, -1027, -166, 238, -138 };
|
|
||||||
|
|
||||||
const int QuadraticOurs[][PIECE_TYPE_NB] = {
|
const int QuadraticOurs[][PIECE_TYPE_NB] = {
|
||||||
// OUR PIECES
|
// OUR PIECES
|
||||||
// pair pawn knight bishop rook queen
|
// pair pawn knight bishop rook queen
|
||||||
{ 0 }, // Bishop pair
|
{1667 }, // Bishop pair
|
||||||
{ 40, 2 }, // Pawn
|
{ 40, 0 }, // Pawn
|
||||||
{ 32, 255, -3 }, // Knight OUR PIECES
|
{ 32, 255, -3 }, // Knight OUR PIECES
|
||||||
{ 0, 104, 4, 0 }, // Bishop
|
{ 0, 104, 4, 0 }, // Bishop
|
||||||
{ -26, -2, 47, 105, -149 }, // Rook
|
{ -26, -2, 47, 105, -149 }, // Rook
|
||||||
{-185, 24, 122, 137, -134, 0 } // Queen
|
{-189, 24, 117, 133, -134, -10 } // Queen
|
||||||
};
|
};
|
||||||
|
|
||||||
const int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
const int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
||||||
@@ -53,7 +50,7 @@ namespace {
|
|||||||
{ 9, 63, 0 }, // Knight OUR PIECES
|
{ 9, 63, 0 }, // Knight OUR PIECES
|
||||||
{ 59, 65, 42, 0 }, // Bishop
|
{ 59, 65, 42, 0 }, // Bishop
|
||||||
{ 46, 39, 24, -24, 0 }, // Rook
|
{ 46, 39, 24, -24, 0 }, // Rook
|
||||||
{ 101, 100, -37, 141, 268, 0 } // Queen
|
{ 97, 100, -42, 137, 268, 0 } // Queen
|
||||||
};
|
};
|
||||||
|
|
||||||
// Endgame evaluation and scaling functions are accessed directly and not through
|
// Endgame evaluation and scaling functions are accessed directly and not through
|
||||||
@@ -94,13 +91,13 @@ namespace {
|
|||||||
|
|
||||||
int bonus = 0;
|
int bonus = 0;
|
||||||
|
|
||||||
// Second-degree polynomial material imbalance by Tord Romstad
|
// Second-degree polynomial material imbalance, by Tord Romstad
|
||||||
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)
|
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)
|
||||||
{
|
{
|
||||||
if (!pieceCount[Us][pt1])
|
if (!pieceCount[Us][pt1])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int v = Linear[pt1];
|
int v = 0;
|
||||||
|
|
||||||
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; ++pt2)
|
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; ++pt2)
|
||||||
v += QuadraticOurs[pt1][pt2] * pieceCount[Us][pt2]
|
v += QuadraticOurs[pt1][pt2] * pieceCount[Us][pt2]
|
||||||
@@ -132,7 +129,13 @@ Entry* probe(const Position& pos) {
|
|||||||
std::memset(e, 0, sizeof(Entry));
|
std::memset(e, 0, sizeof(Entry));
|
||||||
e->key = key;
|
e->key = key;
|
||||||
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
|
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
|
||||||
e->gamePhase = pos.game_phase();
|
|
||||||
|
Value npm_w = pos.non_pawn_material(WHITE);
|
||||||
|
Value npm_b = pos.non_pawn_material(BLACK);
|
||||||
|
Value npm = std::max(EndgameLimit, std::min(npm_w + npm_b, MidgameLimit));
|
||||||
|
|
||||||
|
// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
|
||||||
|
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
|
||||||
|
|
||||||
// Let's look if we have a specialized evaluation function for this particular
|
// Let's look if we have a specialized evaluation function for this particular
|
||||||
// material configuration. Firstly we look for a fixed configuration one, then
|
// material configuration. Firstly we look for a fixed configuration one, then
|
||||||
@@ -153,7 +156,7 @@ Entry* probe(const Position& pos) {
|
|||||||
|
|
||||||
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
|
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
|
||||||
{
|
{
|
||||||
e->scalingFunction[sf->strong_side()] = sf; // Only strong color assigned
|
e->scalingFunction[sf->strongSide] = sf; // Only strong color assigned
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,9 +172,6 @@ Entry* probe(const Position& pos) {
|
|||||||
e->scalingFunction[c] = &ScaleKQKRPs[c];
|
e->scalingFunction[c] = &ScaleKQKRPs[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
Value npm_w = pos.non_pawn_material(WHITE);
|
|
||||||
Value npm_b = pos.non_pawn_material(BLACK);
|
|
||||||
|
|
||||||
if (npm_w + npm_b == VALUE_ZERO && pos.pieces(PAWN)) // Only pawns on the board
|
if (npm_w + npm_b == VALUE_ZERO && pos.pieces(PAWN)) // Only pawns on the board
|
||||||
{
|
{
|
||||||
if (!pos.count<PAWN>(BLACK))
|
if (!pos.count<PAWN>(BLACK))
|
||||||
|
|||||||
+6
-6
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -50,17 +50,17 @@ struct Entry {
|
|||||||
// the position. For instance, in KBP vs K endgames, the scaling function looks
|
// the position. For instance, in KBP vs K endgames, the scaling function looks
|
||||||
// for rook pawns and wrong-colored bishops.
|
// for rook pawns and wrong-colored bishops.
|
||||||
ScaleFactor scale_factor(const Position& pos, Color c) const {
|
ScaleFactor scale_factor(const Position& pos, Color c) const {
|
||||||
return !scalingFunction[c]
|
ScaleFactor sf = scalingFunction[c] ? (*scalingFunction[c])(pos)
|
||||||
|| (*scalingFunction[c])(pos) == SCALE_FACTOR_NONE ? ScaleFactor(factor[c])
|
: SCALE_FACTOR_NONE;
|
||||||
: (*scalingFunction[c])(pos);
|
return sf != SCALE_FACTOR_NONE ? sf : ScaleFactor(factor[c]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
int16_t value;
|
|
||||||
uint8_t factor[COLOR_NB];
|
|
||||||
EndgameBase<Value>* evaluationFunction;
|
EndgameBase<Value>* evaluationFunction;
|
||||||
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
|
||||||
// side (e.g. KPKP, KBPsKs)
|
// side (e.g. KPKP, KBPsKs)
|
||||||
|
int16_t value;
|
||||||
|
uint8_t factor[COLOR_NB];
|
||||||
Phase gamePhase;
|
Phase gamePhase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+142
-12
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,10 +18,29 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#if _WIN32_WINNT < 0x0601
|
||||||
|
#undef _WIN32_WINNT
|
||||||
|
#define _WIN32_WINNT 0x0601 // Force to include needed API prototypes
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
// The needed Windows API for processor groups could be missed from old Windows
|
||||||
|
// versions, so instead of calling them directly (forcing the linker to resolve
|
||||||
|
// the calls at compile time), try to load them at runtime. To do this we need
|
||||||
|
// first to define the corresponding function pointers.
|
||||||
|
extern "C" {
|
||||||
|
typedef bool(*fun1_t)(LOGICAL_PROCESSOR_RELATIONSHIP,
|
||||||
|
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, PDWORD);
|
||||||
|
typedef bool(*fun2_t)(USHORT, PGROUP_AFFINITY);
|
||||||
|
typedef bool(*fun3_t)(HANDLE, CONST GROUP_AFFINITY*, PGROUP_AFFINITY);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
@@ -32,7 +51,7 @@ namespace {
|
|||||||
|
|
||||||
/// Version number. If Version is left empty, then compile date in the format
|
/// Version number. If Version is left empty, then compile date in the format
|
||||||
/// DD-MM-YY and show in engine_info.
|
/// DD-MM-YY and show in engine_info.
|
||||||
const string Version = "7";
|
const string Version = "9";
|
||||||
|
|
||||||
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
||||||
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
||||||
@@ -44,10 +63,10 @@ struct Tie: public streambuf { // MSVC requires split streambuf for cin and cout
|
|||||||
|
|
||||||
Tie(streambuf* b, streambuf* l) : buf(b), logBuf(l) {}
|
Tie(streambuf* b, streambuf* l) : buf(b), logBuf(l) {}
|
||||||
|
|
||||||
int sync() { return logBuf->pubsync(), buf->pubsync(); }
|
int sync() override { return logBuf->pubsync(), buf->pubsync(); }
|
||||||
int overflow(int c) { return log(buf->sputc((char)c), "<< "); }
|
int overflow(int c) override { return log(buf->sputc((char)c), "<< "); }
|
||||||
int underflow() { return buf->sgetc(); }
|
int underflow() override { return buf->sgetc(); }
|
||||||
int uflow() { return log(buf->sbumpc(), ">> "); }
|
int uflow() override { return log(buf->sbumpc(), ">> "); }
|
||||||
|
|
||||||
streambuf *buf, *logBuf;
|
streambuf *buf, *logBuf;
|
||||||
|
|
||||||
@@ -65,23 +84,23 @@ struct Tie: public streambuf { // MSVC requires split streambuf for cin and cout
|
|||||||
class Logger {
|
class Logger {
|
||||||
|
|
||||||
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
|
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
|
||||||
~Logger() { start(false); }
|
~Logger() { start(""); }
|
||||||
|
|
||||||
ofstream file;
|
ofstream file;
|
||||||
Tie in, out;
|
Tie in, out;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void start(bool b) {
|
static void start(const std::string& fname) {
|
||||||
|
|
||||||
static Logger l;
|
static Logger l;
|
||||||
|
|
||||||
if (b && !l.file.is_open())
|
if (!fname.empty() && !l.file.is_open())
|
||||||
{
|
{
|
||||||
l.file.open("io_log.txt", ifstream::out);
|
l.file.open(fname, ifstream::out);
|
||||||
cin.rdbuf(&l.in);
|
cin.rdbuf(&l.in);
|
||||||
cout.rdbuf(&l.out);
|
cout.rdbuf(&l.out);
|
||||||
}
|
}
|
||||||
else if (!b && l.file.is_open())
|
else if (fname.empty() && l.file.is_open())
|
||||||
{
|
{
|
||||||
cout.rdbuf(l.out.buf);
|
cout.rdbuf(l.out.buf);
|
||||||
cin.rdbuf(l.in.buf);
|
cin.rdbuf(l.in.buf);
|
||||||
@@ -157,7 +176,7 @@ std::ostream& operator<<(std::ostream& os, SyncCout sc) {
|
|||||||
|
|
||||||
|
|
||||||
/// Trampoline helper to avoid moving Logger to misc.h
|
/// Trampoline helper to avoid moving Logger to misc.h
|
||||||
void start_logger(bool b) { Logger::start(b); }
|
void start_logger(const std::string& fname) { Logger::start(fname); }
|
||||||
|
|
||||||
|
|
||||||
/// prefetch() preloads the given address in L1/L2 cache. This is a non-blocking
|
/// prefetch() preloads the given address in L1/L2 cache. This is a non-blocking
|
||||||
@@ -185,3 +204,114 @@ void prefetch(void* addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void prefetch2(void* addr) {
|
||||||
|
|
||||||
|
prefetch(addr);
|
||||||
|
prefetch((uint8_t*)addr + 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace WinProcGroup {
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
|
void bindThisThread(size_t) {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/// get_group() retrieves logical processor information using Windows specific
|
||||||
|
/// API and returns the best group id for the thread with index idx. Original
|
||||||
|
/// code from Texel by Peter Österlund.
|
||||||
|
|
||||||
|
int get_group(size_t idx) {
|
||||||
|
|
||||||
|
int threads = 0;
|
||||||
|
int nodes = 0;
|
||||||
|
int cores = 0;
|
||||||
|
DWORD returnLength = 0;
|
||||||
|
DWORD byteOffset = 0;
|
||||||
|
|
||||||
|
// Early exit if the needed API is not available at runtime
|
||||||
|
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
||||||
|
auto fun1 = (fun1_t)GetProcAddress(k32, "GetLogicalProcessorInformationEx");
|
||||||
|
if (!fun1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// First call to get returnLength. We expect it to fail due to null buffer
|
||||||
|
if (fun1(RelationAll, nullptr, &returnLength))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Once we know returnLength, allocate the buffer
|
||||||
|
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buffer, *ptr;
|
||||||
|
ptr = buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(returnLength);
|
||||||
|
|
||||||
|
// Second call, now we expect to succeed
|
||||||
|
if (!fun1(RelationAll, buffer, &returnLength))
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (ptr->Size > 0 && byteOffset + ptr->Size <= returnLength)
|
||||||
|
{
|
||||||
|
if (ptr->Relationship == RelationNumaNode)
|
||||||
|
nodes++;
|
||||||
|
|
||||||
|
else if (ptr->Relationship == RelationProcessorCore)
|
||||||
|
{
|
||||||
|
cores++;
|
||||||
|
threads += (ptr->Processor.Flags == LTP_PC_SMT) ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
byteOffset += ptr->Size;
|
||||||
|
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((char*)ptr) + ptr->Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
std::vector<int> groups;
|
||||||
|
|
||||||
|
// Run as many threads as possible on the same node until core limit is
|
||||||
|
// reached, then move on filling the next node.
|
||||||
|
for (int n = 0; n < nodes; n++)
|
||||||
|
for (int i = 0; i < cores / nodes; i++)
|
||||||
|
groups.push_back(n);
|
||||||
|
|
||||||
|
// In case a core has more than one logical processor (we assume 2) and we
|
||||||
|
// have still threads to allocate, then spread them evenly across available
|
||||||
|
// nodes.
|
||||||
|
for (int t = 0; t < threads - cores; t++)
|
||||||
|
groups.push_back(t % nodes);
|
||||||
|
|
||||||
|
// If we still have more threads than the total number of logical processors
|
||||||
|
// then return -1 and let the OS to decide what to do.
|
||||||
|
return idx < groups.size() ? groups[idx] : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// bindThisThread() set the group affinity of the current thread
|
||||||
|
|
||||||
|
void bindThisThread(size_t idx) {
|
||||||
|
|
||||||
|
// Use only local variables to be thread-safe
|
||||||
|
int group = get_group(idx);
|
||||||
|
|
||||||
|
if (group == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Early exit if the needed API are not available at runtime
|
||||||
|
HMODULE k32 = GetModuleHandle("Kernel32.dll");
|
||||||
|
auto fun2 = (fun2_t)GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
|
||||||
|
auto fun3 = (fun3_t)GetProcAddress(k32, "SetThreadGroupAffinity");
|
||||||
|
|
||||||
|
if (!fun2 || !fun3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GROUP_AFFINITY affinity;
|
||||||
|
if (fun2(group, &affinity))
|
||||||
|
fun3(GetCurrentThread(), &affinity, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace WinProcGroup
|
||||||
|
|||||||
+14
-2
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,7 +31,8 @@
|
|||||||
|
|
||||||
const std::string engine_info(bool to_uci = false);
|
const std::string engine_info(bool to_uci = false);
|
||||||
void prefetch(void* addr);
|
void prefetch(void* addr);
|
||||||
void start_logger(bool b);
|
void prefetch2(void* addr);
|
||||||
|
void start_logger(const std::string& fname);
|
||||||
|
|
||||||
void dbg_hit_on(bool b);
|
void dbg_hit_on(bool b);
|
||||||
void dbg_hit_on(bool c, bool b);
|
void dbg_hit_on(bool c, bool b);
|
||||||
@@ -97,4 +98,15 @@ public:
|
|||||||
{ return T(rand64() & rand64() & rand64()); }
|
{ return T(rand64() & rand64() & rand64()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// Under Windows it is not possible for a process to run on more than one
|
||||||
|
/// logical processor group. This usually means to be limited to use max 64
|
||||||
|
/// cores. To overcome this, some special platform specific API should be
|
||||||
|
/// called to set group affinity for each thread. Original code from Texel by
|
||||||
|
/// Peter Österlund.
|
||||||
|
|
||||||
|
namespace WinProcGroup {
|
||||||
|
void bindThisThread(size_t idx);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // #ifndef MISC_H_INCLUDED
|
#endif // #ifndef MISC_H_INCLUDED
|
||||||
|
|||||||
+62
-62
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template<CastlingRight Cr, bool Checks, bool Chess960>
|
template<CastlingRight Cr, bool Checks, bool Chess960>
|
||||||
ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us, const CheckInfo* ci) {
|
ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us) {
|
||||||
|
|
||||||
static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
|
static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
|
||||||
|
|
||||||
@@ -42,8 +42,8 @@ namespace {
|
|||||||
|
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
const Square K = Chess960 ? kto > kfrom ? DELTA_W : DELTA_E
|
const Direction K = Chess960 ? kto > kfrom ? WEST : EAST
|
||||||
: KingSide ? DELTA_W : DELTA_E;
|
: KingSide ? WEST : EAST;
|
||||||
|
|
||||||
for (Square s = kto; s != kfrom; s += K)
|
for (Square s = kto; s != kfrom; s += K)
|
||||||
if (pos.attackers_to(s) & enemies)
|
if (pos.attackers_to(s) & enemies)
|
||||||
@@ -57,53 +57,50 @@ namespace {
|
|||||||
|
|
||||||
Move m = make<CASTLING>(kfrom, rfrom);
|
Move m = make<CASTLING>(kfrom, rfrom);
|
||||||
|
|
||||||
if (Checks && !pos.gives_check(m, *ci))
|
if (Checks && !pos.gives_check(m))
|
||||||
return moveList;
|
return moveList;
|
||||||
else
|
|
||||||
(void)ci; // Silence a warning under MSVC
|
|
||||||
|
|
||||||
*moveList++ = m;
|
*moveList++ = m;
|
||||||
return moveList;
|
return moveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<GenType Type, Square Delta>
|
template<GenType Type, Direction D>
|
||||||
ExtMove* make_promotions(ExtMove* moveList, Square to, const CheckInfo* ci) {
|
ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) {
|
||||||
|
|
||||||
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, QUEEN);
|
*moveList++ = make<PROMOTION>(to - D, to, QUEEN);
|
||||||
|
|
||||||
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
|
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
{
|
{
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, ROOK);
|
*moveList++ = make<PROMOTION>(to - D, to, ROOK);
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, BISHOP);
|
*moveList++ = make<PROMOTION>(to - D, to, BISHOP);
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, KNIGHT);
|
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Knight promotion is the only promotion that can give a direct check
|
// Knight promotion is the only promotion that can give a direct check
|
||||||
// that's not already included in the queen promotion.
|
// that's not already included in the queen promotion.
|
||||||
if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq))
|
if (Type == QUIET_CHECKS && (PseudoAttacks[KNIGHT][to] & ksq))
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, KNIGHT);
|
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
||||||
else
|
else
|
||||||
(void)ci; // Silence a warning under MSVC
|
(void)ksq; // Silence a warning under MSVC
|
||||||
|
|
||||||
return moveList;
|
return moveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<Color Us, GenType Type>
|
template<Color Us, GenType Type>
|
||||||
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList,
|
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
Bitboard target, const CheckInfo* ci) {
|
|
||||||
|
|
||||||
// Compute our parametrized parameters at compile time, named according to
|
// Compute our parametrized parameters at compile time, named according to
|
||||||
// the point of view of white side.
|
// the point of view of white side.
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||||
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||||
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);
|
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||||
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||||
|
|
||||||
Bitboard emptySquares;
|
Bitboard emptySquares;
|
||||||
|
|
||||||
@@ -118,8 +115,8 @@ namespace {
|
|||||||
{
|
{
|
||||||
emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces());
|
emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces());
|
||||||
|
|
||||||
Bitboard b1 = shift_bb<Up>(pawnsNotOn7) & emptySquares;
|
Bitboard b1 = shift<Up>(pawnsNotOn7) & emptySquares;
|
||||||
Bitboard b2 = shift_bb<Up>(b1 & TRank3BB) & emptySquares;
|
Bitboard b2 = shift<Up>(b1 & TRank3BB) & emptySquares;
|
||||||
|
|
||||||
if (Type == EVASIONS) // Consider only blocking squares
|
if (Type == EVASIONS) // Consider only blocking squares
|
||||||
{
|
{
|
||||||
@@ -129,17 +126,20 @@ namespace {
|
|||||||
|
|
||||||
if (Type == QUIET_CHECKS)
|
if (Type == QUIET_CHECKS)
|
||||||
{
|
{
|
||||||
b1 &= pos.attacks_from<PAWN>(ci->ksq, Them);
|
Square ksq = pos.square<KING>(Them);
|
||||||
b2 &= pos.attacks_from<PAWN>(ci->ksq, Them);
|
|
||||||
|
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
|
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
|
|
||||||
// Add pawn pushes which give discovered check. This is possible only
|
// Add pawn pushes which give discovered check. This is possible only
|
||||||
// if the pawn is not on the same file as the enemy king, because we
|
// if the pawn is not on the same file as the enemy king, because we
|
||||||
// don't generate captures. Note that a possible discovery check
|
// don't generate captures. Note that a possible discovery check
|
||||||
// promotion has been already generated amongst the captures.
|
// promotion has been already generated amongst the captures.
|
||||||
if (pawnsNotOn7 & ci->dcCandidates)
|
Bitboard dcCandidates = pos.discovered_check_candidates();
|
||||||
|
if (pawnsNotOn7 & dcCandidates)
|
||||||
{
|
{
|
||||||
Bitboard dc1 = shift_bb<Up>(pawnsNotOn7 & ci->dcCandidates) & emptySquares & ~file_bb(ci->ksq);
|
Bitboard dc1 = shift<Up>(pawnsNotOn7 & dcCandidates) & emptySquares & ~file_bb(ksq);
|
||||||
Bitboard dc2 = shift_bb<Up>(dc1 & TRank3BB) & emptySquares;
|
Bitboard dc2 = shift<Up>(dc1 & TRank3BB) & emptySquares;
|
||||||
|
|
||||||
b1 |= dc1;
|
b1 |= dc1;
|
||||||
b2 |= dc2;
|
b2 |= dc2;
|
||||||
@@ -168,25 +168,27 @@ namespace {
|
|||||||
if (Type == EVASIONS)
|
if (Type == EVASIONS)
|
||||||
emptySquares &= target;
|
emptySquares &= target;
|
||||||
|
|
||||||
Bitboard b1 = shift_bb<Right>(pawnsOn7) & enemies;
|
Bitboard b1 = shift<Right>(pawnsOn7) & enemies;
|
||||||
Bitboard b2 = shift_bb<Left >(pawnsOn7) & enemies;
|
Bitboard b2 = shift<Left >(pawnsOn7) & enemies;
|
||||||
Bitboard b3 = shift_bb<Up >(pawnsOn7) & emptySquares;
|
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
||||||
|
|
||||||
|
Square ksq = pos.square<KING>(Them);
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
moveList = make_promotions<Type, Right>(moveList, pop_lsb(&b1), ci);
|
moveList = make_promotions<Type, Right>(moveList, pop_lsb(&b1), ksq);
|
||||||
|
|
||||||
while (b2)
|
while (b2)
|
||||||
moveList = make_promotions<Type, Left >(moveList, pop_lsb(&b2), ci);
|
moveList = make_promotions<Type, Left >(moveList, pop_lsb(&b2), ksq);
|
||||||
|
|
||||||
while (b3)
|
while (b3)
|
||||||
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ci);
|
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ksq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard and en-passant captures
|
// Standard and en-passant captures
|
||||||
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
||||||
{
|
{
|
||||||
Bitboard b1 = shift_bb<Right>(pawnsNotOn7) & enemies;
|
Bitboard b1 = shift<Right>(pawnsNotOn7) & enemies;
|
||||||
Bitboard b2 = shift_bb<Left >(pawnsNotOn7) & enemies;
|
Bitboard b2 = shift<Left >(pawnsNotOn7) & enemies;
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
@@ -225,7 +227,7 @@ namespace {
|
|||||||
|
|
||||||
template<PieceType Pt, bool Checks>
|
template<PieceType Pt, bool Checks>
|
||||||
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
||||||
Bitboard target, const CheckInfo* ci) {
|
Bitboard target) {
|
||||||
|
|
||||||
assert(Pt != KING && Pt != PAWN);
|
assert(Pt != KING && Pt != PAWN);
|
||||||
|
|
||||||
@@ -236,17 +238,17 @@ namespace {
|
|||||||
if (Checks)
|
if (Checks)
|
||||||
{
|
{
|
||||||
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
|
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
|
||||||
&& !(PseudoAttacks[Pt][from] & target & ci->checkSquares[Pt]))
|
&& !(PseudoAttacks[Pt][from] & target & pos.check_squares(Pt)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ci->dcCandidates && (ci->dcCandidates & from))
|
if (pos.discovered_check_candidates() & from)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitboard b = pos.attacks_from<Pt>(from) & target;
|
Bitboard b = pos.attacks_from<Pt>(from) & target;
|
||||||
|
|
||||||
if (Checks)
|
if (Checks)
|
||||||
b &= ci->checkSquares[Pt];
|
b &= pos.check_squares(Pt);
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(from, pop_lsb(&b));
|
*moveList++ = make_move(from, pop_lsb(&b));
|
||||||
@@ -257,16 +259,15 @@ namespace {
|
|||||||
|
|
||||||
|
|
||||||
template<Color Us, GenType Type>
|
template<Color Us, GenType Type>
|
||||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target,
|
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
const CheckInfo* ci = nullptr) {
|
|
||||||
|
|
||||||
const bool Checks = Type == QUIET_CHECKS;
|
const bool Checks = Type == QUIET_CHECKS;
|
||||||
|
|
||||||
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target, ci);
|
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
||||||
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target, ci);
|
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
|
||||||
moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target, ci);
|
moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target);
|
||||||
moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target, ci);
|
moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target);
|
||||||
moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target, ci);
|
moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target);
|
||||||
|
|
||||||
if (Type != QUIET_CHECKS && Type != EVASIONS)
|
if (Type != QUIET_CHECKS && Type != EVASIONS)
|
||||||
{
|
{
|
||||||
@@ -280,13 +281,13 @@ namespace {
|
|||||||
{
|
{
|
||||||
if (pos.is_chess960())
|
if (pos.is_chess960())
|
||||||
{
|
{
|
||||||
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
|
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, moveList, Us);
|
||||||
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
|
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
|
moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us);
|
||||||
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
|
moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,8 +336,7 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
|||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
CheckInfo ci(pos);
|
Bitboard dc = pos.discovered_check_candidates();
|
||||||
Bitboard dc = ci.dcCandidates;
|
|
||||||
|
|
||||||
while (dc)
|
while (dc)
|
||||||
{
|
{
|
||||||
@@ -346,17 +346,17 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
|||||||
if (pt == PAWN)
|
if (pt == PAWN)
|
||||||
continue; // Will be generated together with direct checks
|
continue; // Will be generated together with direct checks
|
||||||
|
|
||||||
Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.pieces();
|
Bitboard b = pos.attacks_from(pt, from) & ~pos.pieces();
|
||||||
|
|
||||||
if (pt == KING)
|
if (pt == KING)
|
||||||
b &= ~PseudoAttacks[QUEEN][ci.ksq];
|
b &= ~PseudoAttacks[QUEEN][pos.square<KING>(~us)];
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(from, pop_lsb(&b));
|
*moveList++ = make_move(from, pop_lsb(&b));
|
||||||
}
|
}
|
||||||
|
|
||||||
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci)
|
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces())
|
||||||
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci);
|
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -411,7 +411,7 @@ ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
|
|||||||
: generate<NON_EVASIONS>(pos, moveList);
|
: generate<NON_EVASIONS>(pos, moveList);
|
||||||
while (cur != moveList)
|
while (cur != moveList)
|
||||||
if ( (pinned || from_sq(*cur) == ksq || type_of(*cur) == ENPASSANT)
|
if ( (pinned || from_sq(*cur) == ksq || type_of(*cur) == ENPASSANT)
|
||||||
&& !pos.legal(*cur, pinned))
|
&& !pos.legal(*cur))
|
||||||
*cur = (--moveList)->move;
|
*cur = (--moveList)->move;
|
||||||
else
|
else
|
||||||
++cur;
|
++cur;
|
||||||
|
|||||||
+9
-4
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
#ifndef MOVEGEN_H_INCLUDED
|
#ifndef MOVEGEN_H_INCLUDED
|
||||||
#define MOVEGEN_H_INCLUDED
|
#define MOVEGEN_H_INCLUDED
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
class Position;
|
class Position;
|
||||||
@@ -36,10 +38,14 @@ enum GenType {
|
|||||||
|
|
||||||
struct ExtMove {
|
struct ExtMove {
|
||||||
Move move;
|
Move move;
|
||||||
Value value;
|
int value;
|
||||||
|
|
||||||
operator Move() const { return move; }
|
operator Move() const { return move; }
|
||||||
void operator=(Move m) { move = m; }
|
void operator=(Move m) { move = m; }
|
||||||
|
|
||||||
|
// Inhibit unwanted implicit conversions to Move
|
||||||
|
// with an ambiguity that yields to a compile error.
|
||||||
|
operator float() const = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator<(const ExtMove& f, const ExtMove& s) {
|
inline bool operator<(const ExtMove& f, const ExtMove& s) {
|
||||||
@@ -59,8 +65,7 @@ struct MoveList {
|
|||||||
const ExtMove* end() const { return last; }
|
const ExtMove* end() const { return last; }
|
||||||
size_t size() const { return last - moveList; }
|
size_t size() const { return last - moveList; }
|
||||||
bool contains(Move move) const {
|
bool contains(Move move) const {
|
||||||
for (const auto& m : *this) if (m == move) return true;
|
return std::find(begin(), end(), move) != end();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+211
-195
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,41 +21,40 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "thread.h"
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum Stages {
|
enum Stages {
|
||||||
MAIN_SEARCH, GOOD_CAPTURES, KILLERS, GOOD_QUIETS, BAD_QUIETS, BAD_CAPTURES,
|
MAIN_SEARCH, CAPTURES_INIT, GOOD_CAPTURES, KILLERS, COUNTERMOVE, QUIET_INIT, QUIET, BAD_CAPTURES,
|
||||||
EVASION, ALL_EVASIONS,
|
EVASION, EVASIONS_INIT, ALL_EVASIONS,
|
||||||
QSEARCH_WITH_CHECKS, QCAPTURES_1, CHECKS,
|
PROBCUT, PROBCUT_INIT, PROBCUT_CAPTURES,
|
||||||
QSEARCH_WITHOUT_CHECKS, QCAPTURES_2,
|
QSEARCH_WITH_CHECKS, QCAPTURES_1_INIT, QCAPTURES_1, QCHECKS,
|
||||||
PROBCUT, PROBCUT_CAPTURES,
|
QSEARCH_NO_CHECKS, QCAPTURES_2_INIT, QCAPTURES_2,
|
||||||
RECAPTURE, RECAPTURES,
|
QSEARCH_RECAPTURES, QRECAPTURES
|
||||||
STOP
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Our insertion sort, which is guaranteed to be stable, as it should be
|
// partial_insertion_sort() sorts moves in descending order up to and including
|
||||||
void insertion_sort(ExtMove* begin, ExtMove* end)
|
// a given limit. The order of moves smaller than the limit is left unspecified.
|
||||||
{
|
void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit) {
|
||||||
ExtMove tmp, *p, *q;
|
|
||||||
|
|
||||||
for (p = begin + 1; p < end; ++p)
|
for (ExtMove *sortedEnd = begin, *p = begin + 1; p < end; ++p)
|
||||||
{
|
if (p->value >= limit)
|
||||||
tmp = *p;
|
{
|
||||||
for (q = p; q != begin && *(q-1) < tmp; --q)
|
ExtMove tmp = *p, *q;
|
||||||
*q = *(q-1);
|
*p = *++sortedEnd;
|
||||||
*q = tmp;
|
for (q = sortedEnd; q != begin && *(q - 1) < tmp; --q)
|
||||||
}
|
*q = *(q - 1);
|
||||||
|
*q = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pick_best() finds the best move in the range (begin, end) and moves it to
|
// pick_best() finds the best move in the range (begin, end) and moves it to
|
||||||
// the front. It's faster than sorting all the moves in advance when there
|
// the front. It's faster than sorting all the moves in advance when there
|
||||||
// are few moves e.g. the possible captures.
|
// are few moves, e.g., the possible captures.
|
||||||
Move pick_best(ExtMove* begin, ExtMove* end)
|
Move pick_best(ExtMove* begin, ExtMove* end) {
|
||||||
{
|
|
||||||
std::swap(*begin, *std::max_element(begin, end));
|
std::swap(*begin, *std::max_element(begin, end));
|
||||||
return *begin;
|
return *begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -64,23 +63,25 @@ namespace {
|
|||||||
/// Constructors of the MovePicker class. As arguments we pass information
|
/// Constructors of the MovePicker class. As arguments we pass information
|
||||||
/// to help it to return the (presumably) good moves first, to decide which
|
/// to help it to return the (presumably) good moves first, to decide which
|
||||||
/// moves to return (in the quiescence search, for instance, we only want to
|
/// moves to return (in the quiescence search, for instance, we only want to
|
||||||
/// search captures, promotions and some checks) and how important good move
|
/// search captures, promotions, and some checks) and how important good move
|
||||||
/// ordering is at the current node.
|
/// ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
|
/// MovePicker constructor for the main search
|
||||||
const CounterMovesStats& cmh, Move cm, Search::Stack* s)
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||||
: pos(p), history(h), counterMovesHistory(&cmh), ss(s), countermove(cm), depth(d) {
|
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers_p)
|
||||||
|
: pos(p), mainHistory(mh), captureHistory(cph), contHistory(ch), countermove(cm),
|
||||||
|
killers{killers_p[0], killers_p[1]}, depth(d){
|
||||||
|
|
||||||
assert(d > DEPTH_ZERO);
|
assert(d > DEPTH_ZERO);
|
||||||
|
|
||||||
stage = pos.checkers() ? EVASION : MAIN_SEARCH;
|
stage = pos.checkers() ? EVASION : MAIN_SEARCH;
|
||||||
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
/// MovePicker constructor for quiescence search
|
||||||
const HistoryStats& h, Square s)
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const CapturePieceToHistory* cph, Square s)
|
||||||
: pos(p), history(h), counterMovesHistory(nullptr) {
|
: pos(p), mainHistory(mh), captureHistory(cph) {
|
||||||
|
|
||||||
assert(d <= DEPTH_ZERO);
|
assert(d <= DEPTH_ZERO);
|
||||||
|
|
||||||
@@ -91,228 +92,243 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
|||||||
stage = QSEARCH_WITH_CHECKS;
|
stage = QSEARCH_WITH_CHECKS;
|
||||||
|
|
||||||
else if (d > DEPTH_QS_RECAPTURES)
|
else if (d > DEPTH_QS_RECAPTURES)
|
||||||
stage = QSEARCH_WITHOUT_CHECKS;
|
stage = QSEARCH_NO_CHECKS;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stage = RECAPTURE;
|
stage = QSEARCH_RECAPTURES;
|
||||||
recaptureSquare = s;
|
recaptureSquare = s;
|
||||||
ttm = MOVE_NONE;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, Value th)
|
/// MovePicker constructor for ProbCut: we generate captures with SEE higher
|
||||||
: pos(p), history(h), counterMovesHistory(nullptr), threshold(th) {
|
/// than or equal to the given threshold.
|
||||||
|
MovePicker::MovePicker(const Position& p, Move ttm, Value th, const CapturePieceToHistory* cph)
|
||||||
|
: pos(p), captureHistory(cph), threshold(th) {
|
||||||
|
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
stage = PROBCUT;
|
stage = PROBCUT;
|
||||||
|
|
||||||
// In ProbCut we generate captures with SEE higher than the given threshold
|
|
||||||
ttMove = ttm
|
ttMove = ttm
|
||||||
&& pos.pseudo_legal(ttm)
|
&& pos.pseudo_legal(ttm)
|
||||||
&& pos.capture(ttm)
|
&& pos.capture(ttm)
|
||||||
&& pos.see(ttm) > threshold ? ttm : MOVE_NONE;
|
&& pos.see_ge(ttm, threshold) ? ttm : MOVE_NONE;
|
||||||
|
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// score() assigns a numerical value to each move in a list, used for sorting.
|
||||||
|
/// Captures are ordered by Most Valuable Victim (MVV), preferring captures
|
||||||
|
/// with a good history. Quiets are ordered using the histories.
|
||||||
|
template<GenType Type>
|
||||||
|
void MovePicker::score() {
|
||||||
|
|
||||||
/// score() assigns a numerical value to each move in a move list. The moves with
|
static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
|
||||||
/// highest values will be picked first.
|
|
||||||
template<>
|
|
||||||
void MovePicker::score<CAPTURES>() {
|
|
||||||
// Winning and equal captures in the main search are ordered by MVV, preferring
|
|
||||||
// captures near our home rank. Surprisingly, this appears to perform slightly
|
|
||||||
// better than SEE based move ordering: exchanging big pieces before capturing
|
|
||||||
// a hanging piece probably helps to reduce the subtree size.
|
|
||||||
// In main search we want to push captures with negative SEE values to the
|
|
||||||
// badCaptures[] array, but instead of doing it now we delay until the move
|
|
||||||
// has been picked up, saving some SEE calls in case we get a cutoff.
|
|
||||||
for (auto& m : *this)
|
|
||||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
|
||||||
- Value(200 * relative_rank(pos.side_to_move(), to_sq(m)));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void MovePicker::score<QUIETS>() {
|
|
||||||
|
|
||||||
for (auto& m : *this)
|
for (auto& m : *this)
|
||||||
m.value = history[pos.moved_piece(m)][to_sq(m)]
|
if (Type == CAPTURES)
|
||||||
+ (*counterMovesHistory)[pos.moved_piece(m)][to_sq(m)];
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void MovePicker::score<EVASIONS>() {
|
|
||||||
// Try winning and equal captures captures ordered by MVV/LVA, then non-captures
|
|
||||||
// ordered by history value, then bad-captures and quiet moves with a negative
|
|
||||||
// SEE ordered by SEE value.
|
|
||||||
Value see;
|
|
||||||
|
|
||||||
for (auto& m : *this)
|
|
||||||
if ((see = pos.see_sign(m)) < VALUE_ZERO)
|
|
||||||
m.value = see - HistoryStats::Max; // At the bottom
|
|
||||||
|
|
||||||
else if (pos.capture(m))
|
|
||||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||||
- Value(type_of(pos.moved_piece(m))) + HistoryStats::Max;
|
+ Value((*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))]);
|
||||||
else
|
|
||||||
m.value = history[pos.moved_piece(m)][to_sq(m)];
|
else if (Type == QUIETS)
|
||||||
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||||
|
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
+ (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
|
||||||
|
+ (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
|
||||||
|
|
||||||
|
else // Type == EVASIONS
|
||||||
|
{
|
||||||
|
if (pos.capture(m))
|
||||||
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||||
|
- Value(type_of(pos.moved_piece(m)));
|
||||||
|
else
|
||||||
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - (1 << 28);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// generate_next_stage() generates, scores and sorts the next bunch of moves,
|
|
||||||
/// when there are no more moves to try for the current stage.
|
|
||||||
|
|
||||||
void MovePicker::generate_next_stage() {
|
|
||||||
|
|
||||||
assert(stage != STOP);
|
|
||||||
|
|
||||||
cur = moves;
|
|
||||||
|
|
||||||
switch (++stage) {
|
|
||||||
|
|
||||||
case GOOD_CAPTURES: case QCAPTURES_1: case QCAPTURES_2:
|
|
||||||
case PROBCUT_CAPTURES: case RECAPTURES:
|
|
||||||
endMoves = generate<CAPTURES>(pos, moves);
|
|
||||||
score<CAPTURES>();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KILLERS:
|
|
||||||
killers[0] = ss->killers[0];
|
|
||||||
killers[1] = ss->killers[1];
|
|
||||||
killers[2] = countermove;
|
|
||||||
cur = killers;
|
|
||||||
endMoves = cur + 2 + (countermove != killers[0] && countermove != killers[1]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GOOD_QUIETS:
|
|
||||||
endQuiets = endMoves = generate<QUIETS>(pos, moves);
|
|
||||||
score<QUIETS>();
|
|
||||||
endMoves = std::partition(cur, endMoves, [](const ExtMove& m) { return m.value > VALUE_ZERO; });
|
|
||||||
insertion_sort(cur, endMoves);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BAD_QUIETS:
|
|
||||||
cur = endMoves;
|
|
||||||
endMoves = endQuiets;
|
|
||||||
if (depth >= 3 * ONE_PLY)
|
|
||||||
insertion_sort(cur, endMoves);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BAD_CAPTURES:
|
|
||||||
// Just pick them in reverse order to get correct ordering
|
|
||||||
cur = moves + MAX_MOVES - 1;
|
|
||||||
endMoves = endBadCaptures;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ALL_EVASIONS:
|
|
||||||
endMoves = generate<EVASIONS>(pos, moves);
|
|
||||||
if (endMoves - moves > 1)
|
|
||||||
score<EVASIONS>();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CHECKS:
|
|
||||||
endMoves = generate<QUIET_CHECKS>(pos, moves);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVASION: case QSEARCH_WITH_CHECKS: case QSEARCH_WITHOUT_CHECKS:
|
|
||||||
case PROBCUT: case RECAPTURE: case STOP:
|
|
||||||
stage = STOP;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// next_move() is the most important method of the MovePicker class. It returns
|
/// next_move() is the most important method of the MovePicker class. It returns
|
||||||
/// a new pseudo legal move every time it is called, until there are no more moves
|
/// a new pseudo legal move every time it is called, until there are no more moves
|
||||||
/// left. It picks the move with the biggest value from a list of generated moves
|
/// left. It picks the move with the biggest value from a list of generated moves
|
||||||
/// taking care not to return the ttMove if it has already been searched.
|
/// taking care not to return the ttMove if it has already been searched.
|
||||||
|
|
||||||
Move MovePicker::next_move() {
|
Move MovePicker::next_move(bool skipQuiets) {
|
||||||
|
|
||||||
Move move;
|
Move move;
|
||||||
|
|
||||||
while (true)
|
switch (stage) {
|
||||||
{
|
|
||||||
while (cur == endMoves && stage != STOP)
|
|
||||||
generate_next_stage();
|
|
||||||
|
|
||||||
switch (stage) {
|
case MAIN_SEARCH: case EVASION: case QSEARCH_WITH_CHECKS:
|
||||||
|
case QSEARCH_NO_CHECKS: case PROBCUT:
|
||||||
|
++stage;
|
||||||
|
return ttMove;
|
||||||
|
|
||||||
case MAIN_SEARCH: case EVASION: case QSEARCH_WITH_CHECKS:
|
case CAPTURES_INIT:
|
||||||
case QSEARCH_WITHOUT_CHECKS: case PROBCUT:
|
endBadCaptures = cur = moves;
|
||||||
++cur;
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
return ttMove;
|
score<CAPTURES>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
case GOOD_CAPTURES:
|
case GOOD_CAPTURES:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
move = pick_best(cur++, endMoves);
|
move = pick_best(cur++, endMoves);
|
||||||
if (move != ttMove)
|
if (move != ttMove)
|
||||||
{
|
{
|
||||||
if (pos.see_sign(move) >= VALUE_ZERO)
|
if (pos.see_ge(move, Value(-55 * (cur-1)->value / 1024)))
|
||||||
return move;
|
return move;
|
||||||
|
|
||||||
// Losing capture, move it to the tail of the array
|
// Losing capture, move it to the beginning of the array
|
||||||
*endBadCaptures-- = move;
|
*endBadCaptures++ = move;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
case KILLERS:
|
++stage;
|
||||||
move = *cur++;
|
move = killers[0]; // First killer move
|
||||||
if ( move != MOVE_NONE
|
if ( move != MOVE_NONE
|
||||||
&& move != ttMove
|
&& move != ttMove
|
||||||
&& pos.pseudo_legal(move)
|
&& pos.pseudo_legal(move)
|
||||||
&& !pos.capture(move))
|
&& !pos.capture(move))
|
||||||
return move;
|
return move;
|
||||||
break;
|
/* fallthrough */
|
||||||
|
|
||||||
case GOOD_QUIETS: case BAD_QUIETS:
|
case KILLERS:
|
||||||
|
++stage;
|
||||||
|
move = killers[1]; // Second killer move
|
||||||
|
if ( move != MOVE_NONE
|
||||||
|
&& move != ttMove
|
||||||
|
&& pos.pseudo_legal(move)
|
||||||
|
&& !pos.capture(move))
|
||||||
|
return move;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case COUNTERMOVE:
|
||||||
|
++stage;
|
||||||
|
move = countermove;
|
||||||
|
if ( move != MOVE_NONE
|
||||||
|
&& move != ttMove
|
||||||
|
&& move != killers[0]
|
||||||
|
&& move != killers[1]
|
||||||
|
&& pos.pseudo_legal(move)
|
||||||
|
&& !pos.capture(move))
|
||||||
|
return move;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QUIET_INIT:
|
||||||
|
cur = endBadCaptures;
|
||||||
|
endMoves = generate<QUIETS>(pos, cur);
|
||||||
|
score<QUIETS>();
|
||||||
|
partial_insertion_sort(cur, endMoves, -4000 * depth / ONE_PLY);
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QUIET:
|
||||||
|
while ( cur < endMoves
|
||||||
|
&& (!skipQuiets || cur->value >= VALUE_ZERO))
|
||||||
|
{
|
||||||
move = *cur++;
|
move = *cur++;
|
||||||
|
|
||||||
if ( move != ttMove
|
if ( move != ttMove
|
||||||
&& move != killers[0]
|
&& move != killers[0]
|
||||||
&& move != killers[1]
|
&& move != killers[1]
|
||||||
&& move != killers[2])
|
&& move != countermove)
|
||||||
return move;
|
return move;
|
||||||
break;
|
}
|
||||||
|
++stage;
|
||||||
|
cur = moves; // Point to beginning of bad captures
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
case BAD_CAPTURES:
|
case BAD_CAPTURES:
|
||||||
return *cur--;
|
if (cur < endBadCaptures)
|
||||||
|
return *cur++;
|
||||||
|
break;
|
||||||
|
|
||||||
case ALL_EVASIONS: case QCAPTURES_1: case QCAPTURES_2:
|
case EVASIONS_INIT:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<EVASIONS>(pos, cur);
|
||||||
|
score<EVASIONS>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case ALL_EVASIONS:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
move = pick_best(cur++, endMoves);
|
move = pick_best(cur++, endMoves);
|
||||||
if (move != ttMove)
|
if (move != ttMove)
|
||||||
return move;
|
return move;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROBCUT_INIT:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
|
score<CAPTURES>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case PROBCUT_CAPTURES:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
|
move = pick_best(cur++, endMoves);
|
||||||
|
if ( move != ttMove
|
||||||
|
&& pos.see_ge(move, threshold))
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QCAPTURES_1_INIT: case QCAPTURES_2_INIT:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
|
score<CAPTURES>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QCAPTURES_1: case QCAPTURES_2:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
|
move = pick_best(cur++, endMoves);
|
||||||
|
if (move != ttMove)
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
if (stage == QCAPTURES_2)
|
||||||
break;
|
break;
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
case PROBCUT_CAPTURES:
|
case QCHECKS:
|
||||||
move = pick_best(cur++, endMoves);
|
while (cur < endMoves)
|
||||||
if (move != ttMove && pos.see(move) > threshold)
|
{
|
||||||
return move;
|
move = cur++->move;
|
||||||
break;
|
if (move != ttMove)
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case RECAPTURES:
|
case QSEARCH_RECAPTURES:
|
||||||
|
cur = moves;
|
||||||
|
endMoves = generate<CAPTURES>(pos, cur);
|
||||||
|
score<CAPTURES>();
|
||||||
|
++stage;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
|
case QRECAPTURES:
|
||||||
|
while (cur < endMoves)
|
||||||
|
{
|
||||||
move = pick_best(cur++, endMoves);
|
move = pick_best(cur++, endMoves);
|
||||||
if (to_sq(move) == recaptureSquare)
|
if (to_sq(move) == recaptureSquare)
|
||||||
return move;
|
return move;
|
||||||
break;
|
|
||||||
|
|
||||||
case CHECKS:
|
|
||||||
move = *cur++;
|
|
||||||
if (move != ttMove)
|
|
||||||
return move;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STOP:
|
|
||||||
return MOVE_NONE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
+92
-54
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,54 +21,97 @@
|
|||||||
#ifndef MOVEPICK_H_INCLUDED
|
#ifndef MOVEPICK_H_INCLUDED
|
||||||
#define MOVEPICK_H_INCLUDED
|
#define MOVEPICK_H_INCLUDED
|
||||||
|
|
||||||
#include <algorithm> // For std::max
|
#include <array>
|
||||||
#include <cstring> // For std::memset
|
#include <limits>
|
||||||
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
/// StatBoards is a generic 2-dimensional array used to store various statistics
|
||||||
|
template<int Size1, int Size2, typename T = int16_t>
|
||||||
|
struct StatBoards : public std::array<std::array<T, Size2>, Size1> {
|
||||||
|
|
||||||
/// The Stats struct stores moves statistics. According to the template parameter
|
void fill(const T& v) {
|
||||||
/// the class can store History and Countermoves. History records how often
|
T* p = &(*this)[0][0];
|
||||||
/// different moves have been successful or unsuccessful during the current search
|
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
|
||||||
/// and is used for reduction and move ordering decisions.
|
|
||||||
/// Countermoves store the move that refute a previous one. Entries are stored
|
|
||||||
/// using only the moving piece and destination square, hence two moves with
|
|
||||||
/// different origin but same destination and piece will be considered identical.
|
|
||||||
template<typename T, bool CM = false>
|
|
||||||
struct Stats {
|
|
||||||
|
|
||||||
static const Value Max = Value(1 << 28);
|
|
||||||
|
|
||||||
const T* operator[](Piece pc) const { return table[pc]; }
|
|
||||||
T* operator[](Piece pc) { return table[pc]; }
|
|
||||||
void clear() { std::memset(table, 0, sizeof(table)); }
|
|
||||||
|
|
||||||
void update(Piece pc, Square to, Move m) {
|
|
||||||
|
|
||||||
if (m != table[pc][to])
|
|
||||||
table[pc][to] = m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(Piece pc, Square to, Value v) {
|
void update(T& entry, int bonus, const int D) {
|
||||||
|
|
||||||
if (abs(int(v)) >= 324)
|
assert(abs(bonus) <= D); // Ensure range is [-32 * D, 32 * D]
|
||||||
return;
|
assert(abs(32 * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
|
||||||
|
|
||||||
table[pc][to] -= table[pc][to] * abs(int(v)) / (CM ? 512 : 324);
|
entry += bonus * 32 - entry * abs(bonus) / D;
|
||||||
table[pc][to] += int(v) * (CM ? 64 : 32);
|
|
||||||
|
assert(abs(entry) <= 32 * D);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
T table[PIECE_NB][SQUARE_NB];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Stats<Move> MovesStats;
|
/// StatCubes is a generic 3-dimensional array used to store various statistics
|
||||||
typedef Stats<Value, false> HistoryStats;
|
template<int Size1, int Size2, int Size3, typename T = int16_t>
|
||||||
typedef Stats<Value, true> CounterMovesStats;
|
struct StatCubes : public std::array<std::array<std::array<T, Size3>, Size2>, Size1> {
|
||||||
typedef Stats<CounterMovesStats> CounterMovesHistoryStats;
|
|
||||||
|
void fill(const T& v) {
|
||||||
|
T* p = &(*this)[0][0][0];
|
||||||
|
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(T& entry, int bonus, const int D, const int W) {
|
||||||
|
|
||||||
|
assert(abs(bonus) <= D); // Ensure range is [-W * D, W * D]
|
||||||
|
assert(abs(W * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
|
||||||
|
|
||||||
|
entry += bonus * W - entry * abs(bonus) / D;
|
||||||
|
|
||||||
|
assert(abs(entry) <= W * D);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// ButterflyBoards are 2 tables (one for each color) indexed by the move's from
|
||||||
|
/// and to squares, see chessprogramming.wikispaces.com/Butterfly+Boards
|
||||||
|
typedef StatBoards<COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyBoards;
|
||||||
|
|
||||||
|
/// PieceToBoards are addressed by a move's [piece][to] information
|
||||||
|
typedef StatBoards<PIECE_NB, SQUARE_NB> PieceToBoards;
|
||||||
|
|
||||||
|
/// CapturePieceToBoards are addressed by a move's [piece][to][captured piece type] information
|
||||||
|
typedef StatCubes<PIECE_NB, SQUARE_NB, PIECE_TYPE_NB> CapturePieceToBoards;
|
||||||
|
|
||||||
|
/// ButterflyHistory records how often quiet moves have been successful or
|
||||||
|
/// unsuccessful during the current search, and is used for reduction and move
|
||||||
|
/// ordering decisions. It uses ButterflyBoards as backing store.
|
||||||
|
struct ButterflyHistory : public ButterflyBoards {
|
||||||
|
|
||||||
|
void update(Color c, Move m, int bonus) {
|
||||||
|
StatBoards::update((*this)[c][from_to(m)], bonus, 324);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// PieceToHistory is like ButterflyHistory, but is based on PieceToBoards
|
||||||
|
struct PieceToHistory : public PieceToBoards {
|
||||||
|
|
||||||
|
void update(Piece pc, Square to, int bonus) {
|
||||||
|
StatBoards::update((*this)[pc][to], bonus, 936);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// CapturePieceToHistory is like PieceToHistory, but is based on CapturePieceToBoards
|
||||||
|
struct CapturePieceToHistory : public CapturePieceToBoards {
|
||||||
|
|
||||||
|
void update(Piece pc, Square to, PieceType captured, int bonus) {
|
||||||
|
StatCubes::update((*this)[pc][to][captured], bonus, 324, 2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous
|
||||||
|
/// move, see chessprogramming.wikispaces.com/Countermove+Heuristic
|
||||||
|
typedef StatBoards<PIECE_NB, SQUARE_NB, Move> CounterMoveHistory;
|
||||||
|
|
||||||
|
/// ContinuationHistory is the history of a given pair of moves, usually the
|
||||||
|
/// current one given a previous one. History table is based on PieceToBoards
|
||||||
|
/// instead of ButterflyBoards.
|
||||||
|
typedef StatBoards<PIECE_NB, SQUARE_NB, PieceToHistory> ContinuationHistory;
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
||||||
@@ -82,32 +125,27 @@ class MovePicker {
|
|||||||
public:
|
public:
|
||||||
MovePicker(const MovePicker&) = delete;
|
MovePicker(const MovePicker&) = delete;
|
||||||
MovePicker& operator=(const MovePicker&) = delete;
|
MovePicker& operator=(const MovePicker&) = delete;
|
||||||
|
MovePicker(const Position&, Move, Value, const CapturePieceToHistory*);
|
||||||
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
|
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const CapturePieceToHistory*, Square);
|
||||||
MovePicker(const Position&, Move, const HistoryStats&, Value);
|
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const CapturePieceToHistory*, const PieceToHistory**, Move, Move*);
|
||||||
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMovesStats&, Move, Search::Stack*);
|
Move next_move(bool skipQuiets = false);
|
||||||
|
|
||||||
Move next_move();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<GenType> void score();
|
template<GenType> void score();
|
||||||
void generate_next_stage();
|
ExtMove* begin() { return cur; }
|
||||||
ExtMove* begin() { return moves; }
|
|
||||||
ExtMove* end() { return endMoves; }
|
ExtMove* end() { return endMoves; }
|
||||||
|
|
||||||
const Position& pos;
|
const Position& pos;
|
||||||
const HistoryStats& history;
|
const ButterflyHistory* mainHistory;
|
||||||
const CounterMovesStats* counterMovesHistory;
|
const CapturePieceToHistory* captureHistory;
|
||||||
Search::Stack* ss;
|
const PieceToHistory** contHistory;
|
||||||
Move countermove;
|
Move ttMove, countermove, killers[2];
|
||||||
Depth depth;
|
ExtMove *cur, *endMoves, *endBadCaptures;
|
||||||
Move ttMove;
|
int stage;
|
||||||
ExtMove killers[3];
|
|
||||||
Square recaptureSquare;
|
Square recaptureSquare;
|
||||||
Value threshold;
|
Value threshold;
|
||||||
int stage;
|
Depth depth;
|
||||||
ExtMove *endQuiets, *endBadCaptures = moves + MAX_MOVES - 1;
|
ExtMove moves[MAX_MOVES];
|
||||||
ExtMove moves[MAX_MOVES], *cur = moves, *endMoves = moves;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #ifndef MOVEPICK_H_INCLUDED
|
#endif // #ifndef MOVEPICK_H_INCLUDED
|
||||||
|
|||||||
+116
-136
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "bitcount.h"
|
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
@@ -32,60 +31,52 @@ namespace {
|
|||||||
#define V Value
|
#define V Value
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
|
|
||||||
// Isolated pawn penalty by opposed flag and file
|
// Isolated pawn penalty
|
||||||
const Score Isolated[2][FILE_NB] = {
|
const Score Isolated = S(13, 18);
|
||||||
{ S(37, 45), S(54, 52), S(60, 52), S(60, 52),
|
|
||||||
S(60, 52), S(60, 52), S(54, 52), S(37, 45) },
|
|
||||||
{ S(25, 30), S(36, 35), S(40, 35), S(40, 35),
|
|
||||||
S(40, 35), S(40, 35), S(36, 35), S(25, 30) } };
|
|
||||||
|
|
||||||
// Backward pawn penalty by opposed flag
|
// Backward pawn penalty
|
||||||
const Score Backward[2] = { S(67, 42), S(49, 24) };
|
const Score Backward = S(24, 12);
|
||||||
|
|
||||||
// Unsupported pawn penalty, for pawns which are neither isolated or backward
|
|
||||||
const Score Unsupported = S(20, 10);
|
|
||||||
|
|
||||||
// Connected pawn bonus by opposed, phalanx, twice supported and rank
|
// Connected pawn bonus by opposed, phalanx, #support and rank
|
||||||
Score Connected[2][2][2][RANK_NB];
|
Score Connected[2][2][3][RANK_NB];
|
||||||
|
|
||||||
// Doubled pawn penalty by file
|
|
||||||
const Score Doubled[FILE_NB] = {
|
|
||||||
S(13, 43), S(20, 48), S(23, 48), S(23, 48),
|
|
||||||
S(23, 48), S(23, 48), S(20, 48), S(13, 43) };
|
|
||||||
|
|
||||||
// Lever bonus by rank
|
// Doubled pawn penalty
|
||||||
const Score Lever[RANK_NB] = {
|
const Score Doubled = S(18, 38);
|
||||||
S( 0, 0), S( 0, 0), S(0, 0), S(0, 0),
|
|
||||||
S(20, 20), S(40, 40), S(0, 0), S(0, 0) };
|
|
||||||
|
|
||||||
// Center bind bonus, when two pawns controls the same central square
|
// Weakness of our pawn shelter in front of the king by [isKingFile][distance from edge][rank].
|
||||||
const Score CenterBind = S(16, 0);
|
// RANK_1 = 0 is used for files where we have no pawns or our pawn is behind our king.
|
||||||
|
const Value ShelterWeakness[][int(FILE_NB) / 2][RANK_NB] = {
|
||||||
|
{ { V( 97), V(17), V( 9), V(44), V( 84), V( 87), V( 99) }, // Not On King file
|
||||||
|
{ V(106), V( 6), V(33), V(86), V( 87), V(104), V(112) },
|
||||||
|
{ V(101), V( 2), V(65), V(98), V( 58), V( 89), V(115) },
|
||||||
|
{ V( 73), V( 7), V(54), V(73), V( 84), V( 83), V(111) } },
|
||||||
|
{ { V(104), V(20), V( 6), V(27), V( 86), V( 93), V( 82) }, // On King file
|
||||||
|
{ V(123), V( 9), V(34), V(96), V(112), V( 88), V( 75) },
|
||||||
|
{ V(120), V(25), V(65), V(91), V( 66), V( 78), V(117) },
|
||||||
|
{ V( 81), V( 2), V(47), V(63), V( 94), V( 93), V(104) } }
|
||||||
|
};
|
||||||
|
|
||||||
// Weakness of our pawn shelter in front of the king by [distance from edge][rank]
|
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank].
|
||||||
const Value ShelterWeakness[][RANK_NB] = {
|
// For the unopposed and unblocked cases, RANK_1 = 0 is used when opponent has
|
||||||
{ V( 97), V(21), V(26), V(51), V(87), V( 89), V( 99) },
|
// no pawn on the given file, or their pawn is behind our king.
|
||||||
{ V(120), V( 0), V(28), V(76), V(88), V(103), V(104) },
|
|
||||||
{ V(101), V( 7), V(54), V(78), V(77), V( 92), V(101) },
|
|
||||||
{ V( 80), V(11), V(44), V(68), V(87), V( 90), V(119) } };
|
|
||||||
|
|
||||||
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank]
|
|
||||||
const Value StormDanger[][4][RANK_NB] = {
|
const Value StormDanger[][4][RANK_NB] = {
|
||||||
{ { V( 0), V( 67), V( 134), V(38), V(32) },
|
{ { V( 0), V(-290), V(-274), V(57), V(41) }, // BlockedByKing
|
||||||
{ V( 0), V( 57), V( 139), V(37), V(22) },
|
{ V( 0), V( 60), V( 144), V(39), V(13) },
|
||||||
{ V( 0), V( 43), V( 115), V(43), V(27) },
|
{ V( 0), V( 65), V( 141), V(41), V(34) },
|
||||||
{ V( 0), V( 68), V( 124), V(57), V(32) } },
|
{ V( 0), V( 53), V( 127), V(56), V(14) } },
|
||||||
{ { V(20), V( 43), V( 100), V(56), V(20) },
|
{ { V( 4), V( 73), V( 132), V(46), V(31) }, // Unopposed
|
||||||
{ V(23), V( 20), V( 98), V(40), V(15) },
|
{ V( 1), V( 64), V( 143), V(26), V(13) },
|
||||||
{ V(23), V( 39), V( 103), V(36), V(18) },
|
{ V( 1), V( 47), V( 110), V(44), V(24) },
|
||||||
{ V(28), V( 19), V( 108), V(42), V(26) } },
|
{ V( 0), V( 72), V( 127), V(50), V(31) } },
|
||||||
{ { V( 0), V( 0), V( 75), V(14), V( 2) },
|
{ { V( 0), V( 0), V( 79), V(23), V( 1) }, // BlockedByPawn
|
||||||
{ V( 0), V( 0), V( 150), V(30), V( 4) },
|
{ V( 0), V( 0), V( 148), V(27), V( 2) },
|
||||||
{ V( 0), V( 0), V( 160), V(22), V( 5) },
|
{ V( 0), V( 0), V( 161), V(16), V( 1) },
|
||||||
{ V( 0), V( 0), V( 166), V(24), V(13) } },
|
{ V( 0), V( 0), V( 171), V(22), V(15) } },
|
||||||
{ { V( 0), V(-283), V(-281), V(57), V(31) },
|
{ { V(22), V( 45), V( 104), V(62), V( 6) }, // Unblocked
|
||||||
{ V( 0), V( 58), V( 141), V(39), V(18) },
|
{ V(31), V( 30), V( 99), V(39), V(19) },
|
||||||
{ V( 0), V( 65), V( 142), V(48), V(32) },
|
{ V(23), V( 29), V( 96), V(41), V(15) },
|
||||||
{ V( 0), V( 60), V( 126), V(51), V(19) } } };
|
{ V(21), V( 23), V( 116), V(41), V(15) } }
|
||||||
|
};
|
||||||
|
|
||||||
// Max bonus for king safety. Corresponds to start position with all the pawns
|
// Max bonus for king safety. Corresponds to start position with all the pawns
|
||||||
// in front of the king and no enemy pawn on the horizon.
|
// in front of the king and no enemy pawn on the horizon.
|
||||||
@@ -97,30 +88,26 @@ namespace {
|
|||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);
|
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||||
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||||
|
|
||||||
const Bitboard CenterBindMask =
|
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
|
||||||
Us == WHITE ? (FileDBB | FileEBB) & (Rank5BB | Rank6BB | Rank7BB)
|
Bitboard lever, leverPush;
|
||||||
: (FileDBB | FileEBB) & (Rank4BB | Rank3BB | Rank2BB);
|
|
||||||
|
|
||||||
Bitboard b, neighbours, doubled, supported, phalanx;
|
|
||||||
Square s;
|
Square s;
|
||||||
bool passed, isolated, opposed, backward, lever, connected;
|
bool opposed, backward;
|
||||||
Score score = SCORE_ZERO;
|
Score score = SCORE_ZERO;
|
||||||
const Square* pl = pos.squares<PAWN>(Us);
|
const Square* pl = pos.squares<PAWN>(Us);
|
||||||
const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)];
|
|
||||||
|
|
||||||
Bitboard ourPawns = pos.pieces(Us , PAWN);
|
Bitboard ourPawns = pos.pieces( Us, PAWN);
|
||||||
Bitboard theirPawns = pos.pieces(Them, PAWN);
|
Bitboard theirPawns = pos.pieces(Them, PAWN);
|
||||||
|
|
||||||
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = 0;
|
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = e->weakUnopposed[Us] = 0;
|
||||||
e->kingSquares[Us] = SQ_NONE;
|
|
||||||
e->semiopenFiles[Us] = 0xFF;
|
e->semiopenFiles[Us] = 0xFF;
|
||||||
e->pawnAttacks[Us] = shift_bb<Right>(ourPawns) | shift_bb<Left>(ourPawns);
|
e->kingSquares[Us] = SQ_NONE;
|
||||||
e->pawnsOnSquares[Us][BLACK] = popcount<Max15>(ourPawns & DarkSquares);
|
e->pawnAttacks[Us] = shift<Right>(ourPawns) | shift<Left>(ourPawns);
|
||||||
|
e->pawnsOnSquares[Us][BLACK] = popcount(ourPawns & DarkSquares);
|
||||||
e->pawnsOnSquares[Us][WHITE] = pos.count<PAWN>(Us) - e->pawnsOnSquares[Us][BLACK];
|
e->pawnsOnSquares[Us][WHITE] = pos.count<PAWN>(Us) - e->pawnsOnSquares[Us][BLACK];
|
||||||
|
|
||||||
// Loop through all pawns of the current color and score each pawn
|
// Loop through all pawns of the current color and score each pawn
|
||||||
@@ -130,76 +117,69 @@ namespace {
|
|||||||
|
|
||||||
File f = file_of(s);
|
File f = file_of(s);
|
||||||
|
|
||||||
e->semiopenFiles[Us] &= ~(1 << f);
|
e->semiopenFiles[Us] &= ~(1 << f);
|
||||||
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
|
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
|
||||||
|
|
||||||
// Flag the pawn
|
// Flag the pawn
|
||||||
neighbours = ourPawns & adjacent_files_bb(f);
|
opposed = theirPawns & forward_file_bb(Us, s);
|
||||||
doubled = ourPawns & forward_bb(Us, s);
|
stoppers = theirPawns & passed_pawn_mask(Us, s);
|
||||||
opposed = theirPawns & forward_bb(Us, s);
|
lever = theirPawns & PawnAttacks[Us][s];
|
||||||
passed = !(theirPawns & passed_pawn_mask(Us, s));
|
leverPush = theirPawns & PawnAttacks[Us][s + Up];
|
||||||
lever = theirPawns & pawnAttacksBB[s];
|
doubled = ourPawns & (s - Up);
|
||||||
phalanx = neighbours & rank_bb(s);
|
neighbours = ourPawns & adjacent_files_bb(f);
|
||||||
supported = neighbours & rank_bb(s - Up);
|
phalanx = neighbours & rank_bb(s);
|
||||||
connected = supported | phalanx;
|
supported = neighbours & rank_bb(s - Up);
|
||||||
isolated = !neighbours;
|
|
||||||
|
|
||||||
// Test for backward pawn.
|
// A pawn is backward when it is behind all pawns of the same color on the
|
||||||
// If the pawn is passed, isolated, lever or connected it cannot be
|
// adjacent files and cannot be safely advanced.
|
||||||
// backward. If there are friendly pawns behind on adjacent files
|
if (!neighbours || lever || relative_rank(Us, s) >= RANK_5)
|
||||||
// or if it is sufficiently advanced, it cannot be backward either.
|
|
||||||
if ( (passed | isolated | lever | connected)
|
|
||||||
|| (ourPawns & pawn_attack_span(Them, s))
|
|
||||||
|| (relative_rank(Us, s) >= RANK_5))
|
|
||||||
backward = false;
|
backward = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We now know there are no friendly pawns beside or behind this
|
// Find the backmost rank with neighbours or stoppers
|
||||||
// pawn on adjacent files. We now check whether the pawn is
|
b = rank_bb(backmost_sq(Us, neighbours | stoppers));
|
||||||
// backward by looking in the forward direction on the adjacent
|
|
||||||
// files, and picking the closest pawn there.
|
|
||||||
b = pawn_attack_span(Us, s) & (ourPawns | theirPawns);
|
|
||||||
b = pawn_attack_span(Us, s) & rank_bb(backmost_sq(Us, b));
|
|
||||||
|
|
||||||
// If we have an enemy pawn in the same or next rank, the pawn is
|
// The pawn is backward when it cannot safely progress to that rank:
|
||||||
// backward because it cannot advance without being captured.
|
// either there is a stopper in the way on this rank, or there is a
|
||||||
backward = (b | shift_bb<Up>(b)) & theirPawns;
|
// stopper on adjacent file which controls the way to that rank.
|
||||||
|
backward = (b | shift<Up>(b & adjacent_files_bb(f))) & stoppers;
|
||||||
|
|
||||||
|
assert(!(backward && (forward_ranks_bb(Them, s + Up) & neighbours)));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(opposed | passed | (pawn_attack_span(Us, s) & theirPawns));
|
|
||||||
|
|
||||||
// Passed pawns will be properly scored in evaluation because we need
|
// Passed pawns will be properly scored in evaluation because we need
|
||||||
// full attack info to evaluate them. Only the frontmost passed
|
// full attack info to evaluate them. Include also not passed pawns
|
||||||
// pawn on each file is considered a true passed pawn.
|
// which could become passed after one or two pawn pushes when are
|
||||||
if (passed && !doubled)
|
// not attacked more times than defended.
|
||||||
|
if ( !(stoppers ^ lever ^ leverPush)
|
||||||
|
&& !(ourPawns & forward_file_bb(Us, s))
|
||||||
|
&& popcount(supported) >= popcount(lever)
|
||||||
|
&& popcount(phalanx) >= popcount(leverPush))
|
||||||
e->passedPawns[Us] |= s;
|
e->passedPawns[Us] |= s;
|
||||||
|
|
||||||
|
else if ( stoppers == SquareBB[s + Up]
|
||||||
|
&& relative_rank(Us, s) >= RANK_5)
|
||||||
|
{
|
||||||
|
b = shift<Up>(supported) & ~theirPawns;
|
||||||
|
while (b)
|
||||||
|
if (!more_than_one(theirPawns & PawnAttacks[Us][pop_lsb(&b)]))
|
||||||
|
e->passedPawns[Us] |= s;
|
||||||
|
}
|
||||||
|
|
||||||
// Score this pawn
|
// Score this pawn
|
||||||
if (isolated)
|
if (supported | phalanx)
|
||||||
score -= Isolated[opposed][f];
|
score += Connected[opposed][bool(phalanx)][popcount(supported)][relative_rank(Us, s)];
|
||||||
|
|
||||||
|
else if (!neighbours)
|
||||||
|
score -= Isolated, e->weakUnopposed[Us] += !opposed;
|
||||||
|
|
||||||
else if (backward)
|
else if (backward)
|
||||||
score -= Backward[opposed];
|
score -= Backward, e->weakUnopposed[Us] += !opposed;
|
||||||
|
|
||||||
else if (!supported)
|
if (doubled && !supported)
|
||||||
score -= Unsupported;
|
score -= Doubled;
|
||||||
|
|
||||||
if (connected)
|
|
||||||
score += Connected[opposed][!!phalanx][more_than_one(supported)][relative_rank(Us, s)];
|
|
||||||
|
|
||||||
if (doubled)
|
|
||||||
score -= Doubled[f] / distance<Rank>(s, frontmost_sq(Us, doubled));
|
|
||||||
|
|
||||||
if (lever)
|
|
||||||
score += Lever[relative_rank(Us, s)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b = e->semiopenFiles[Us] ^ 0xFF;
|
|
||||||
e->pawnSpan[Us] = b ? int(msb(b) - lsb(b)) : 0;
|
|
||||||
|
|
||||||
b = shift_bb<Right>(ourPawns) & shift_bb<Left>(ourPawns) & CenterBindMask;
|
|
||||||
score += CenterBind * popcount<Max15>(b);
|
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,18 +191,19 @@ namespace Pawns {
|
|||||||
/// hard-coded tables, when makes sense, we prefer to calculate them with a formula
|
/// hard-coded tables, when makes sense, we prefer to calculate them with a formula
|
||||||
/// to reduce independent parameters and to allow easier tuning and better insight.
|
/// to reduce independent parameters and to allow easier tuning and better insight.
|
||||||
|
|
||||||
void init()
|
void init() {
|
||||||
{
|
|
||||||
static const int Seed[RANK_NB] = { 0, 6, 15, 10, 57, 75, 135, 258 };
|
static const int Seed[RANK_NB] = { 0, 13, 24, 18, 76, 100, 175, 330 };
|
||||||
|
|
||||||
for (int opposed = 0; opposed <= 1; ++opposed)
|
for (int opposed = 0; opposed <= 1; ++opposed)
|
||||||
for (int phalanx = 0; phalanx <= 1; ++phalanx)
|
for (int phalanx = 0; phalanx <= 1; ++phalanx)
|
||||||
for (int apex = 0; apex <= 1; ++apex)
|
for (int support = 0; support <= 2; ++support)
|
||||||
for (Rank r = RANK_2; r < RANK_8; ++r)
|
for (Rank r = RANK_2; r < RANK_8; ++r)
|
||||||
{
|
{
|
||||||
int v = (Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0)) >> opposed;
|
int v = 17 * support;
|
||||||
v += (apex ? v / 2 : 0);
|
v += (Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0)) >> opposed;
|
||||||
Connected[opposed][phalanx][apex][r] = make_score(3 * v / 2, v);
|
|
||||||
|
Connected[opposed][phalanx][support][r] = make_score(v, v * (r - 2) / 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,41 +223,43 @@ Entry* probe(const Position& pos) {
|
|||||||
|
|
||||||
e->key = key;
|
e->key = key;
|
||||||
e->score = evaluate<WHITE>(pos, e) - evaluate<BLACK>(pos, e);
|
e->score = evaluate<WHITE>(pos, e) - evaluate<BLACK>(pos, e);
|
||||||
e->asymmetry = popcount<Max15>(e->semiopenFiles[WHITE] ^ e->semiopenFiles[BLACK]);
|
e->asymmetry = popcount(e->semiopenFiles[WHITE] ^ e->semiopenFiles[BLACK]);
|
||||||
|
e->openFiles = popcount(e->semiopenFiles[WHITE] & e->semiopenFiles[BLACK]);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Entry::shelter_storm() calculates shelter and storm penalties for the file
|
/// Entry::shelter_storm() calculates shelter and storm penalties for the file
|
||||||
/// the king is on, as well as the two adjacent files.
|
/// the king is on, as well as the two closest files.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
enum { NoFriendlyPawn, Unblocked, BlockedByPawn, BlockedByKing };
|
enum { BlockedByKing, Unopposed, BlockedByPawn, Unblocked };
|
||||||
|
|
||||||
Bitboard b = pos.pieces(PAWN) & (in_front_bb(Us, rank_of(ksq)) | rank_bb(ksq));
|
Bitboard b = pos.pieces(PAWN) & (forward_ranks_bb(Us, ksq) | rank_bb(ksq));
|
||||||
Bitboard ourPawns = b & pos.pieces(Us);
|
Bitboard ourPawns = b & pos.pieces(Us);
|
||||||
Bitboard theirPawns = b & pos.pieces(Them);
|
Bitboard theirPawns = b & pos.pieces(Them);
|
||||||
Value safety = MaxSafetyBonus;
|
Value safety = MaxSafetyBonus;
|
||||||
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
|
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
|
||||||
|
|
||||||
for (File f = center - File(1); f <= center + File(1); ++f)
|
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
||||||
{
|
{
|
||||||
b = ourPawns & file_bb(f);
|
b = ourPawns & file_bb(f);
|
||||||
Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
|
Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
|
||||||
|
|
||||||
b = theirPawns & file_bb(f);
|
b = theirPawns & file_bb(f);
|
||||||
Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
|
Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
|
||||||
|
|
||||||
safety -= ShelterWeakness[std::min(f, FILE_H - f)][rkUs]
|
int d = std::min(f, ~f);
|
||||||
|
safety -= ShelterWeakness[f == file_of(ksq)][d][rkUs]
|
||||||
+ StormDanger
|
+ StormDanger
|
||||||
[f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing :
|
[f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing :
|
||||||
rkUs == RANK_1 ? NoFriendlyPawn :
|
rkUs == RANK_1 ? Unopposed :
|
||||||
rkThem == rkUs + 1 ? BlockedByPawn : Unblocked]
|
rkThem == rkUs + 1 ? BlockedByPawn : Unblocked]
|
||||||
[std::min(f, FILE_H - f)][rkThem];
|
[d][rkThem];
|
||||||
}
|
}
|
||||||
|
|
||||||
return safety;
|
return safety;
|
||||||
@@ -297,9 +280,6 @@ Score Entry::do_king_safety(const Position& pos, Square ksq) {
|
|||||||
if (pawns)
|
if (pawns)
|
||||||
while (!(DistanceRingBB[ksq][minKingPawnDistance++] & pawns)) {}
|
while (!(DistanceRingBB[ksq][minKingPawnDistance++] & pawns)) {}
|
||||||
|
|
||||||
if (relative_rank(Us, ksq) > RANK_4)
|
|
||||||
return make_score(0, -16 * minKingPawnDistance);
|
|
||||||
|
|
||||||
Value bonus = shelter_storm<Us>(pos, ksq);
|
Value bonus = shelter_storm<Us>(pos, ksq);
|
||||||
|
|
||||||
// If we can castle use the bonus after the castling if it is bigger
|
// If we can castle use the bonus after the castling if it is bigger
|
||||||
|
|||||||
+7
-5
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -37,8 +37,9 @@ struct Entry {
|
|||||||
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
|
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
|
||||||
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
|
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
|
||||||
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
|
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
|
||||||
int pawn_span(Color c) const { return pawnSpan[c]; }
|
int weak_unopposed(Color c) const { return weakUnopposed[c]; }
|
||||||
int pawn_asymmetry() const { return asymmetry; }
|
int pawn_asymmetry() const { return asymmetry; }
|
||||||
|
int open_files() const { return openFiles; }
|
||||||
|
|
||||||
int semiopen_file(Color c, File f) const {
|
int semiopen_file(Color c, File f) const {
|
||||||
return semiopenFiles[c] & (1 << f);
|
return semiopenFiles[c] & (1 << f);
|
||||||
@@ -49,11 +50,11 @@ struct Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int pawns_on_same_color_squares(Color c, Square s) const {
|
int pawns_on_same_color_squares(Color c, Square s) const {
|
||||||
return pawnsOnSquares[c][!!(DarkSquares & s)];
|
return pawnsOnSquares[c][bool(DarkSquares & s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score king_safety(const Position& pos, Square ksq) {
|
Score king_safety(const Position& pos, Square ksq) {
|
||||||
return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
|
return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
|
||||||
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos, ksq));
|
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos, ksq));
|
||||||
}
|
}
|
||||||
@@ -71,11 +72,12 @@ struct Entry {
|
|||||||
Bitboard pawnAttacksSpan[COLOR_NB];
|
Bitboard pawnAttacksSpan[COLOR_NB];
|
||||||
Square kingSquares[COLOR_NB];
|
Square kingSquares[COLOR_NB];
|
||||||
Score kingSafety[COLOR_NB];
|
Score kingSafety[COLOR_NB];
|
||||||
|
int weakUnopposed[COLOR_NB];
|
||||||
int castlingRights[COLOR_NB];
|
int castlingRights[COLOR_NB];
|
||||||
int semiopenFiles[COLOR_NB];
|
int semiopenFiles[COLOR_NB];
|
||||||
int pawnSpan[COLOR_NB];
|
|
||||||
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
||||||
int asymmetry;
|
int asymmetry;
|
||||||
|
int openFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef HashTable<Entry, 16384> Table;
|
typedef HashTable<Entry, 16384> Table;
|
||||||
|
|||||||
+343
-327
File diff suppressed because it is too large
Load Diff
+92
-102
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,35 +22,13 @@
|
|||||||
#define POSITION_H_INCLUDED
|
#define POSITION_H_INCLUDED
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstddef> // For offsetof()
|
#include <deque>
|
||||||
|
#include <memory> // For std::unique_ptr
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
class Position;
|
|
||||||
class Thread;
|
|
||||||
|
|
||||||
namespace PSQT {
|
|
||||||
|
|
||||||
extern Score psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
|
|
||||||
|
|
||||||
void init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// CheckInfo struct is initialized at constructor time and keeps info used to
|
|
||||||
/// detect if a move gives check.
|
|
||||||
|
|
||||||
struct CheckInfo {
|
|
||||||
|
|
||||||
explicit CheckInfo(const Position&);
|
|
||||||
|
|
||||||
Bitboard dcCandidates;
|
|
||||||
Bitboard pinned;
|
|
||||||
Bitboard checkSquares[PIECE_TYPE_NB];
|
|
||||||
Square ksq;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// StateInfo struct stores information needed to restore a Position object to
|
/// StateInfo struct stores information needed to restore a Position object to
|
||||||
/// its previous state when we retract a move. Whenever a move is made on the
|
/// its previous state when we retract a move. Whenever a move is made on the
|
||||||
@@ -68,32 +46,40 @@ struct StateInfo {
|
|||||||
Score psq;
|
Score psq;
|
||||||
Square epSquare;
|
Square epSquare;
|
||||||
|
|
||||||
// Not copied when making a move
|
// Not copied when making a move (will be recomputed anyhow)
|
||||||
Key key;
|
Key key;
|
||||||
Bitboard checkersBB;
|
Bitboard checkersBB;
|
||||||
PieceType capturedType;
|
Piece capturedPiece;
|
||||||
StateInfo* previous;
|
StateInfo* previous;
|
||||||
|
Bitboard blockersForKing[COLOR_NB];
|
||||||
|
Bitboard pinnersForKing[COLOR_NB];
|
||||||
|
Bitboard checkSquares[PIECE_TYPE_NB];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A list to keep track of the position states along the setup moves (from the
|
||||||
|
/// start position to the position just before the search starts). Needed by
|
||||||
|
/// 'draw by repetition' detection. Use a std::deque because pointers to
|
||||||
|
/// elements are not invalidated upon list resizing.
|
||||||
|
typedef std::unique_ptr<std::deque<StateInfo>> StateListPtr;
|
||||||
|
|
||||||
|
|
||||||
/// Position class stores information regarding the board representation as
|
/// Position class stores information regarding the board representation as
|
||||||
/// pieces, side to move, hash keys, castling info, etc. Important methods are
|
/// pieces, side to move, hash keys, castling info, etc. Important methods are
|
||||||
/// do_move() and undo_move(), used by the search to update node info when
|
/// do_move() and undo_move(), used by the search to update node info when
|
||||||
/// traversing the search tree.
|
/// traversing the search tree.
|
||||||
|
class Thread;
|
||||||
|
|
||||||
class Position {
|
class Position {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
Position() = default; // To define the global object RootPos
|
Position() = default;
|
||||||
Position(const Position&) = delete;
|
Position(const Position&) = delete;
|
||||||
Position(const Position& pos, Thread* th) { *this = pos; thisThread = th; }
|
Position& operator=(const Position&) = delete;
|
||||||
Position(const std::string& f, bool c960, Thread* th) { set(f, c960, th); }
|
|
||||||
Position& operator=(const Position&); // To assign RootPos from UCI
|
|
||||||
|
|
||||||
// FEN string input/output
|
// FEN string input/output
|
||||||
void set(const std::string& fenStr, bool isChess960, Thread* th);
|
Position& set(const std::string& fenStr, bool isChess960, StateInfo* si, Thread* th);
|
||||||
|
Position& set(const std::string& code, Color c, StateInfo* si);
|
||||||
const std::string fen() const;
|
const std::string fen() const;
|
||||||
|
|
||||||
// Position representation
|
// Position representation
|
||||||
@@ -107,6 +93,7 @@ public:
|
|||||||
Square ep_square() const;
|
Square ep_square() const;
|
||||||
bool empty(Square s) const;
|
bool empty(Square s) const;
|
||||||
template<PieceType Pt> int count(Color c) const;
|
template<PieceType Pt> int count(Color c) const;
|
||||||
|
template<PieceType Pt> int count() const;
|
||||||
template<PieceType Pt> const Square* squares(Color c) const;
|
template<PieceType Pt> const Square* squares(Color c) const;
|
||||||
template<PieceType Pt> Square square(Color c) const;
|
template<PieceType Pt> Square square(Color c) const;
|
||||||
|
|
||||||
@@ -120,73 +107,71 @@ public:
|
|||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
Bitboard discovered_check_candidates() const;
|
Bitboard discovered_check_candidates() const;
|
||||||
Bitboard pinned_pieces(Color c) const;
|
Bitboard pinned_pieces(Color c) const;
|
||||||
|
Bitboard check_squares(PieceType pt) const;
|
||||||
|
|
||||||
// Attacks to/from a given square
|
// Attacks to/from a given square
|
||||||
Bitboard attackers_to(Square s) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
Bitboard attackers_to(Square s, Bitboard occupied) const;
|
Bitboard attackers_to(Square s, Bitboard occupied) const;
|
||||||
Bitboard attacks_from(Piece pc, Square s) const;
|
Bitboard attacks_from(PieceType pt, Square s) const;
|
||||||
template<PieceType> Bitboard attacks_from(Square s) const;
|
template<PieceType> Bitboard attacks_from(Square s) const;
|
||||||
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||||
|
Bitboard slider_blockers(Bitboard sliders, Square s, Bitboard& pinners) const;
|
||||||
|
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool legal(Move m, Bitboard pinned) const;
|
bool legal(Move m) const;
|
||||||
bool pseudo_legal(const Move m) const;
|
bool pseudo_legal(const Move m) const;
|
||||||
bool capture(Move m) const;
|
bool capture(Move m) const;
|
||||||
bool capture_or_promotion(Move m) const;
|
bool capture_or_promotion(Move m) const;
|
||||||
bool gives_check(Move m, const CheckInfo& ci) const;
|
bool gives_check(Move m) const;
|
||||||
bool advanced_pawn_push(Move m) const;
|
bool advanced_pawn_push(Move m) const;
|
||||||
Piece moved_piece(Move m) const;
|
Piece moved_piece(Move m) const;
|
||||||
PieceType captured_piece_type() const;
|
Piece captured_piece() const;
|
||||||
|
|
||||||
// Piece specific
|
// Piece specific
|
||||||
bool pawn_passed(Color c, Square s) const;
|
bool pawn_passed(Color c, Square s) const;
|
||||||
bool opposite_bishops() const;
|
bool opposite_bishops() const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void do_move(Move m, StateInfo& st, bool givesCheck);
|
void do_move(Move m, StateInfo& newSt);
|
||||||
|
void do_move(Move m, StateInfo& newSt, bool givesCheck);
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
void do_null_move(StateInfo& st);
|
void do_null_move(StateInfo& newSt);
|
||||||
void undo_null_move();
|
void undo_null_move();
|
||||||
|
|
||||||
// Static exchange evaluation
|
// Static Exchange Evaluation
|
||||||
Value see(Move m) const;
|
bool see_ge(Move m, Value threshold = VALUE_ZERO) const;
|
||||||
Value see_sign(Move m) const;
|
|
||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key key() const;
|
Key key() const;
|
||||||
Key key_after(Move m) const;
|
Key key_after(Move m) const;
|
||||||
Key exclusion_key() const;
|
|
||||||
Key material_key() const;
|
Key material_key() const;
|
||||||
Key pawn_key() const;
|
Key pawn_key() const;
|
||||||
|
|
||||||
// Other properties of the position
|
// Other properties of the position
|
||||||
Color side_to_move() const;
|
Color side_to_move() const;
|
||||||
Phase game_phase() const;
|
|
||||||
int game_ply() const;
|
int game_ply() const;
|
||||||
bool is_chess960() const;
|
bool is_chess960() const;
|
||||||
Thread* this_thread() const;
|
Thread* this_thread() const;
|
||||||
uint64_t nodes_searched() const;
|
bool is_draw(int ply) const;
|
||||||
void set_nodes_searched(uint64_t n);
|
|
||||||
bool is_draw() const;
|
|
||||||
int rule50_count() const;
|
int rule50_count() const;
|
||||||
Score psq_score() const;
|
Score psq_score() const;
|
||||||
Value non_pawn_material(Color c) const;
|
Value non_pawn_material(Color c) const;
|
||||||
|
Value non_pawn_material() const;
|
||||||
|
|
||||||
// Position consistency check, for debugging
|
// Position consistency check, for debugging
|
||||||
bool pos_is_ok(int* failedStep = nullptr) const;
|
bool pos_is_ok() const;
|
||||||
void flip();
|
void flip();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Initialization helpers (used while setting up a position)
|
// Initialization helpers (used while setting up a position)
|
||||||
void clear();
|
|
||||||
void set_castling_right(Color c, Square rfrom);
|
void set_castling_right(Color c, Square rfrom);
|
||||||
void set_state(StateInfo* si) const;
|
void set_state(StateInfo* si) const;
|
||||||
|
void set_check_info(StateInfo* si) const;
|
||||||
|
|
||||||
// Other helpers
|
// Other helpers
|
||||||
Bitboard check_blockers(Color c, Color kingColor) const;
|
void put_piece(Piece pc, Square s);
|
||||||
void put_piece(Color c, PieceType pt, Square s);
|
void remove_piece(Piece pc, Square s);
|
||||||
void remove_piece(Color c, PieceType pt, Square s);
|
void move_piece(Piece pc, Square from, Square to);
|
||||||
void move_piece(Color c, PieceType pt, Square from, Square to);
|
|
||||||
template<bool Do>
|
template<bool Do>
|
||||||
void do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto);
|
void do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto);
|
||||||
|
|
||||||
@@ -194,14 +179,12 @@ private:
|
|||||||
Piece board[SQUARE_NB];
|
Piece board[SQUARE_NB];
|
||||||
Bitboard byTypeBB[PIECE_TYPE_NB];
|
Bitboard byTypeBB[PIECE_TYPE_NB];
|
||||||
Bitboard byColorBB[COLOR_NB];
|
Bitboard byColorBB[COLOR_NB];
|
||||||
int pieceCount[COLOR_NB][PIECE_TYPE_NB];
|
int pieceCount[PIECE_NB];
|
||||||
Square pieceList[COLOR_NB][PIECE_TYPE_NB][16];
|
Square pieceList[PIECE_NB][16];
|
||||||
int index[SQUARE_NB];
|
int index[SQUARE_NB];
|
||||||
int castlingRightsMask[SQUARE_NB];
|
int castlingRightsMask[SQUARE_NB];
|
||||||
Square castlingRookSquare[CASTLING_RIGHT_NB];
|
Square castlingRookSquare[CASTLING_RIGHT_NB];
|
||||||
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
||||||
StateInfo startState;
|
|
||||||
uint64_t nodes;
|
|
||||||
int gamePly;
|
int gamePly;
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
Thread* thisThread;
|
Thread* thisThread;
|
||||||
@@ -252,16 +235,20 @@ inline Bitboard Position::pieces(Color c, PieceType pt1, PieceType pt2) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt> inline int Position::count(Color c) const {
|
template<PieceType Pt> inline int Position::count(Color c) const {
|
||||||
return pieceCount[c][Pt];
|
return pieceCount[make_piece(c, Pt)];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<PieceType Pt> inline int Position::count() const {
|
||||||
|
return pieceCount[make_piece(WHITE, Pt)] + pieceCount[make_piece(BLACK, Pt)];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt> inline const Square* Position::squares(Color c) const {
|
template<PieceType Pt> inline const Square* Position::squares(Color c) const {
|
||||||
return pieceList[c][Pt];
|
return pieceList[make_piece(c, Pt)];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt> inline Square Position::square(Color c) const {
|
template<PieceType Pt> inline Square Position::square(Color c) const {
|
||||||
assert(pieceCount[c][Pt] == 1);
|
assert(pieceCount[make_piece(c, Pt)] == 1);
|
||||||
return pieceList[c][Pt][0];
|
return pieceList[make_piece(c, Pt)][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::ep_square() const {
|
inline Square Position::ep_square() const {
|
||||||
@@ -286,18 +273,19 @@ inline Square Position::castling_rook_square(CastlingRight cr) const {
|
|||||||
|
|
||||||
template<PieceType Pt>
|
template<PieceType Pt>
|
||||||
inline Bitboard Position::attacks_from(Square s) const {
|
inline Bitboard Position::attacks_from(Square s) const {
|
||||||
|
assert(Pt != PAWN);
|
||||||
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
||||||
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
||||||
: StepAttacksBB[Pt][s];
|
: PseudoAttacks[Pt][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
||||||
return StepAttacksBB[make_piece(c, PAWN)][s];
|
return PawnAttacks[c][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::attacks_from(Piece pc, Square s) const {
|
inline Bitboard Position::attacks_from(PieceType pt, Square s) const {
|
||||||
return attacks_bb(pc, s, byTypeBB[ALL_PIECES]);
|
return attacks_bb(pt, s, byTypeBB[ALL_PIECES]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::attackers_to(Square s) const {
|
inline Bitboard Position::attackers_to(Square s) const {
|
||||||
@@ -309,11 +297,15 @@ inline Bitboard Position::checkers() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::discovered_check_candidates() const {
|
inline Bitboard Position::discovered_check_candidates() const {
|
||||||
return check_blockers(sideToMove, ~sideToMove);
|
return st->blockersForKing[~sideToMove] & pieces(sideToMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pinned_pieces(Color c) const {
|
inline Bitboard Position::pinned_pieces(Color c) const {
|
||||||
return check_blockers(c, c);
|
return st->blockersForKing[c] & pieces(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Bitboard Position::check_squares(PieceType pt) const {
|
||||||
|
return st->checkSquares[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_passed(Color c, Square s) const {
|
inline bool Position::pawn_passed(Color c, Square s) const {
|
||||||
@@ -345,6 +337,10 @@ inline Value Position::non_pawn_material(Color c) const {
|
|||||||
return st->nonPawnMaterial[c];
|
return st->nonPawnMaterial[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Value Position::non_pawn_material() const {
|
||||||
|
return st->nonPawnMaterial[WHITE] + st->nonPawnMaterial[BLACK];
|
||||||
|
}
|
||||||
|
|
||||||
inline int Position::game_ply() const {
|
inline int Position::game_ply() const {
|
||||||
return gamePly;
|
return gamePly;
|
||||||
}
|
}
|
||||||
@@ -353,17 +349,9 @@ inline int Position::rule50_count() const {
|
|||||||
return st->rule50;
|
return st->rule50;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t Position::nodes_searched() const {
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Position::set_nodes_searched(uint64_t n) {
|
|
||||||
nodes = n;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Position::opposite_bishops() const {
|
inline bool Position::opposite_bishops() const {
|
||||||
return pieceCount[WHITE][BISHOP] == 1
|
return pieceCount[W_BISHOP] == 1
|
||||||
&& pieceCount[BLACK][BISHOP] == 1
|
&& pieceCount[B_BISHOP] == 1
|
||||||
&& opposite_colors(square<BISHOP>(WHITE), square<BISHOP>(BLACK));
|
&& opposite_colors(square<BISHOP>(WHITE), square<BISHOP>(BLACK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,66 +360,68 @@ inline bool Position::is_chess960() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::capture_or_promotion(Move m) const {
|
inline bool Position::capture_or_promotion(Move m) const {
|
||||||
|
|
||||||
assert(is_ok(m));
|
assert(is_ok(m));
|
||||||
return type_of(m) != NORMAL ? type_of(m) != CASTLING : !empty(to_sq(m));
|
return type_of(m) != NORMAL ? type_of(m) != CASTLING : !empty(to_sq(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::capture(Move m) const {
|
inline bool Position::capture(Move m) const {
|
||||||
|
|
||||||
// Castling is encoded as "king captures the rook"
|
|
||||||
assert(is_ok(m));
|
assert(is_ok(m));
|
||||||
|
// Castling is encoded as "king captures rook"
|
||||||
return (!empty(to_sq(m)) && type_of(m) != CASTLING) || type_of(m) == ENPASSANT;
|
return (!empty(to_sq(m)) && type_of(m) != CASTLING) || type_of(m) == ENPASSANT;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType Position::captured_piece_type() const {
|
inline Piece Position::captured_piece() const {
|
||||||
return st->capturedType;
|
return st->capturedPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Thread* Position::this_thread() const {
|
inline Thread* Position::this_thread() const {
|
||||||
return thisThread;
|
return thisThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::put_piece(Color c, PieceType pt, Square s) {
|
inline void Position::put_piece(Piece pc, Square s) {
|
||||||
|
|
||||||
board[s] = make_piece(c, pt);
|
board[s] = pc;
|
||||||
byTypeBB[ALL_PIECES] |= s;
|
byTypeBB[ALL_PIECES] |= s;
|
||||||
byTypeBB[pt] |= s;
|
byTypeBB[type_of(pc)] |= s;
|
||||||
byColorBB[c] |= s;
|
byColorBB[color_of(pc)] |= s;
|
||||||
index[s] = pieceCount[c][pt]++;
|
index[s] = pieceCount[pc]++;
|
||||||
pieceList[c][pt][index[s]] = s;
|
pieceList[pc][index[s]] = s;
|
||||||
pieceCount[c][ALL_PIECES]++;
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::remove_piece(Color c, PieceType pt, Square s) {
|
inline void Position::remove_piece(Piece pc, Square s) {
|
||||||
|
|
||||||
// WARNING: This is not a reversible operation. If we remove a piece in
|
// WARNING: This is not a reversible operation. If we remove a piece in
|
||||||
// do_move() and then replace it in undo_move() we will put it at the end of
|
// do_move() and then replace it in undo_move() we will put it at the end of
|
||||||
// the list and not in its original place, it means index[] and pieceList[]
|
// the list and not in its original place, it means index[] and pieceList[]
|
||||||
// are not guaranteed to be invariant to a do_move() + undo_move() sequence.
|
// are not invariant to a do_move() + undo_move() sequence.
|
||||||
byTypeBB[ALL_PIECES] ^= s;
|
byTypeBB[ALL_PIECES] ^= s;
|
||||||
byTypeBB[pt] ^= s;
|
byTypeBB[type_of(pc)] ^= s;
|
||||||
byColorBB[c] ^= s;
|
byColorBB[color_of(pc)] ^= s;
|
||||||
/* board[s] = NO_PIECE; Not needed, overwritten by the capturing one */
|
/* board[s] = NO_PIECE; Not needed, overwritten by the capturing one */
|
||||||
Square lastSquare = pieceList[c][pt][--pieceCount[c][pt]];
|
Square lastSquare = pieceList[pc][--pieceCount[pc]];
|
||||||
index[lastSquare] = index[s];
|
index[lastSquare] = index[s];
|
||||||
pieceList[c][pt][index[lastSquare]] = lastSquare;
|
pieceList[pc][index[lastSquare]] = lastSquare;
|
||||||
pieceList[c][pt][pieceCount[c][pt]] = SQ_NONE;
|
pieceList[pc][pieceCount[pc]] = SQ_NONE;
|
||||||
pieceCount[c][ALL_PIECES]--;
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::move_piece(Color c, PieceType pt, Square from, Square to) {
|
inline void Position::move_piece(Piece pc, Square from, Square to) {
|
||||||
|
|
||||||
// index[from] is not updated and becomes stale. This works as long as index[]
|
// index[from] is not updated and becomes stale. This works as long as index[]
|
||||||
// is accessed just by known occupied squares.
|
// is accessed just by known occupied squares.
|
||||||
Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to];
|
Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to];
|
||||||
byTypeBB[ALL_PIECES] ^= from_to_bb;
|
byTypeBB[ALL_PIECES] ^= from_to_bb;
|
||||||
byTypeBB[pt] ^= from_to_bb;
|
byTypeBB[type_of(pc)] ^= from_to_bb;
|
||||||
byColorBB[c] ^= from_to_bb;
|
byColorBB[color_of(pc)] ^= from_to_bb;
|
||||||
board[from] = NO_PIECE;
|
board[from] = NO_PIECE;
|
||||||
board[to] = make_piece(c, pt);
|
board[to] = pc;
|
||||||
index[to] = index[from];
|
index[to] = index[from];
|
||||||
pieceList[c][pt][index[to]] = to;
|
pieceList[pc][index[to]] = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Position::do_move(Move m, StateInfo& newSt) {
|
||||||
|
do_move(m, newSt, gives_check(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #ifndef POSITION_H_INCLUDED
|
#endif // #ifndef POSITION_H_INCLUDED
|
||||||
|
|||||||
+55
-48
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,8 +18,15 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
Value PieceValue[PHASE_NB][PIECE_NB] = {
|
||||||
|
{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg },
|
||||||
|
{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg }
|
||||||
|
};
|
||||||
|
|
||||||
namespace PSQT {
|
namespace PSQT {
|
||||||
|
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
@@ -32,33 +39,32 @@ const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
|||||||
{ },
|
{ },
|
||||||
{ // Pawn
|
{ // Pawn
|
||||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
||||||
{ S(-19, 5), S( 1,-4), S( 7, 8), S( 3,-2) },
|
{ S(-11, 7), S( 6,-4), S( 7, 8), S( 3,-2) },
|
||||||
{ S(-26,-6), S( -7,-5), S( 19, 5), S(24, 4) },
|
{ S(-18,-4), S( -2,-5), S( 19, 5), S(24, 4) },
|
||||||
{ S(-25, 1), S(-14, 3), S( 16,-8), S(31,-3) },
|
{ S(-17, 3), S( -9, 3), S( 20,-8), S(35,-3) },
|
||||||
{ S(-14, 6), S( 0, 9), S( -1, 7), S(17,-6) },
|
{ S( -6, 8), S( 5, 9), S( 3, 7), S(21,-6) },
|
||||||
{ S(-14, 6), S(-13,-5), S(-10, 2), S(-6, 4) },
|
{ S( -6, 8), S( -8,-5), S( -6, 2), S(-2, 4) },
|
||||||
{ S(-12, 1), S( 15,-9), S( -8, 1), S(-4,18) },
|
{ S( -4, 3), S( 20,-9), S( -8, 1), S(-4,18) }
|
||||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) }
|
|
||||||
},
|
},
|
||||||
{ // Knight
|
{ // Knight
|
||||||
{ S(-143, -97), S(-96,-82), S(-80,-46), S(-73,-14) },
|
{ S(-161,-105), S(-96,-82), S(-80,-46), S(-73,-14) },
|
||||||
{ S( -83, -69), S(-43,-55), S(-21,-17), S(-10, 9) },
|
{ S( -83, -69), S(-43,-54), S(-21,-17), S(-10, 9) },
|
||||||
{ S( -71, -50), S(-22,-39), S( 0, -8), S( 9, 28) },
|
{ S( -71, -50), S(-22,-39), S( 0, -7), S( 9, 28) },
|
||||||
{ S( -25, -41), S( 18,-25), S( 43, 7), S( 47, 38) },
|
{ S( -25, -41), S( 18,-25), S( 43, 6), S( 47, 38) },
|
||||||
{ S( -26, -46), S( 16,-25), S( 38, 2), S( 50, 41) },
|
{ S( -26, -46), S( 16,-25), S( 38, 3), S( 50, 40) },
|
||||||
{ S( -11, -55), S( 37,-38), S( 56, -8), S( 71, 27) },
|
{ S( -11, -54), S( 37,-38), S( 56, -7), S( 65, 27) },
|
||||||
{ S( -62, -64), S(-17,-50), S( 5,-24), S( 14, 13) },
|
{ S( -63, -65), S(-19,-50), S( 5,-24), S( 14, 13) },
|
||||||
{ S(-195,-110), S(-66,-90), S(-42,-50), S(-29,-13) }
|
{ S(-195,-109), S(-67,-89), S(-42,-50), S(-29,-13) }
|
||||||
},
|
},
|
||||||
{ // Bishop
|
{ // Bishop
|
||||||
{ S(-54,-68), S(-23,-40), S(-35,-46), S(-44,-28) },
|
{ S(-44,-58), S(-13,-31), S(-25,-37), S(-34,-19) },
|
||||||
{ S(-30,-43), S( 10,-17), S( 2,-23), S( -9, -5) },
|
{ S(-20,-34), S( 20, -9), S( 12,-14), S( 1, 4) },
|
||||||
{ S(-19,-32), S( 17, -9), S( 11,-13), S( 1, 8) },
|
{ S( -9,-23), S( 27, 0), S( 21, -3), S( 11, 16) },
|
||||||
{ S(-21,-36), S( 18,-13), S( 11,-15), S( 0, 7) },
|
{ S(-11,-26), S( 28, -3), S( 21, -5), S( 10, 16) },
|
||||||
{ S(-21,-36), S( 14,-14), S( 6,-17), S( -1, 3) },
|
{ S(-11,-26), S( 27, -4), S( 16, -7), S( 9, 14) },
|
||||||
{ S(-27,-35), S( 6,-13), S( 2,-10), S( -8, 1) },
|
{ S(-17,-24), S( 16, -2), S( 12, 0), S( 2, 13) },
|
||||||
{ S(-33,-44), S( 7,-21), S( -4,-22), S(-12, -4) },
|
{ S(-23,-34), S( 17,-10), S( 6,-12), S( -2, 6) },
|
||||||
{ S(-45,-65), S(-21,-42), S(-29,-46), S(-39,-27) }
|
{ S(-35,-55), S(-11,-32), S(-19,-36), S(-29,-17) }
|
||||||
},
|
},
|
||||||
{ // Rook
|
{ // Rook
|
||||||
{ S(-25, 0), S(-16, 0), S(-16, 0), S(-9, 0) },
|
{ S(-25, 0), S(-16, 0), S(-16, 0), S(-9, 0) },
|
||||||
@@ -71,47 +77,48 @@ const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
|||||||
{ S(-23, 0), S(-15, 0), S(-11, 0), S(-5, 0) }
|
{ S(-23, 0), S(-15, 0), S(-11, 0), S(-5, 0) }
|
||||||
},
|
},
|
||||||
{ // Queen
|
{ // Queen
|
||||||
{ S( 0,-70), S(-3,-57), S(-4,-41), S(-1,-29) },
|
{ S( 0,-71), S(-4,-56), S(-3,-42), S(-1,-29) },
|
||||||
{ S(-4,-58), S( 6,-30), S( 9,-21), S( 8, -4) },
|
{ S(-4,-56), S( 6,-30), S( 9,-21), S( 8, -5) },
|
||||||
{ S(-2,-39), S( 6,-17), S( 9, -7), S( 9, 5) },
|
{ S(-2,-39), S( 6,-17), S( 9, -8), S( 9, 5) },
|
||||||
{ S(-1,-29), S( 8, -5), S(10, 9), S( 7, 17) },
|
{ S(-1,-29), S( 8, -5), S(10, 9), S( 7, 19) },
|
||||||
{ S(-3,-27), S( 9, -5), S( 8, 10), S( 7, 23) },
|
{ S(-3,-27), S( 9, -5), S( 8, 10), S( 7, 21) },
|
||||||
{ S(-2,-40), S( 6,-16), S( 8,-11), S(10, 3) },
|
{ S(-2,-40), S( 6,-16), S( 8,-10), S(10, 3) },
|
||||||
{ S(-2,-54), S( 7,-30), S( 7,-21), S( 6, -7) },
|
{ S(-2,-55), S( 7,-30), S( 7,-21), S( 6, -6) },
|
||||||
{ S(-1,-75), S(-4,-54), S(-1,-44), S( 0,-30) }
|
{ S(-1,-74), S(-4,-55), S(-1,-43), S( 0,-30) }
|
||||||
},
|
},
|
||||||
{ // King
|
{ // King
|
||||||
{ S(291, 28), S(344, 76), S(294,103), S(219,112) },
|
{ S(267, 0), S(320, 48), S(270, 75), S(195, 84) },
|
||||||
{ S(289, 70), S(329,119), S(263,170), S(205,159) },
|
{ S(264, 43), S(304, 92), S(238,143), S(180,132) },
|
||||||
{ S(226,109), S(271,164), S(202,195), S(136,191) },
|
{ S(200, 83), S(245,138), S(176,167), S(110,165) },
|
||||||
{ S(204,131), S(212,194), S(175,194), S(137,204) },
|
{ S(177,106), S(185,169), S(148,169), S(110,179) },
|
||||||
{ S(177,132), S(205,187), S(143,224), S( 94,227) },
|
{ S(149,108), S(177,163), S(115,200), S( 66,203) },
|
||||||
{ S(147,118), S(188,178), S(113,199), S( 70,197) },
|
{ S(118, 95), S(159,155), S( 84,176), S( 41,174) },
|
||||||
{ S(116, 72), S(158,121), S( 93,142), S( 48,161) },
|
{ S( 87, 50), S(128, 99), S( 63,122), S( 20,139) },
|
||||||
{ S( 94, 30), S(120, 76), S( 78,101), S( 31,111) }
|
{ S( 63, 9), S( 88, 55), S( 47, 80), S( 0, 90) }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
|
|
||||||
Score psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
|
Score psq[PIECE_NB][SQUARE_NB];
|
||||||
|
|
||||||
// init() initializes piece square tables: the white halves of the tables are
|
// init() initializes piece-square tables: the white halves of the tables are
|
||||||
// copied from Bonus[] adding the piece value, then the black halves of the
|
// copied from Bonus[] adding the piece value, then the black halves of the
|
||||||
// tables are initialized by flipping and changing the sign of the white scores.
|
// tables are initialized by flipping and changing the sign of the white scores.
|
||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
for (PieceType pt = PAWN; pt <= KING; ++pt)
|
for (Piece pc = W_PAWN; pc <= W_KING; ++pc)
|
||||||
{
|
{
|
||||||
PieceValue[MG][make_piece(BLACK, pt)] = PieceValue[MG][pt];
|
PieceValue[MG][~pc] = PieceValue[MG][pc];
|
||||||
PieceValue[EG][make_piece(BLACK, pt)] = PieceValue[EG][pt];
|
PieceValue[EG][~pc] = PieceValue[EG][pc];
|
||||||
|
|
||||||
Score v = make_score(PieceValue[MG][pt], PieceValue[EG][pt]);
|
Score v = make_score(PieceValue[MG][pc], PieceValue[EG][pc]);
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
{
|
{
|
||||||
int edgeDistance = file_of(s) < FILE_E ? file_of(s) : FILE_H - file_of(s);
|
File f = std::min(file_of(s), ~file_of(s));
|
||||||
psq[BLACK][pt][~s] = -(psq[WHITE][pt][s] = v + Bonus[pt][rank_of(s)][edgeDistance]);
|
psq[ pc][ s] = v + Bonus[pc][rank_of(s)][f];
|
||||||
|
psq[~pc][~s] = -psq[pc][s];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+630
-597
File diff suppressed because it is too large
Load Diff
+25
-29
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,32 +21,37 @@
|
|||||||
#ifndef SEARCH_H_INCLUDED
|
#ifndef SEARCH_H_INCLUDED
|
||||||
#define SEARCH_H_INCLUDED
|
#define SEARCH_H_INCLUDED
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <memory> // For std::unique_ptr
|
|
||||||
#include <stack>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "position.h"
|
#include "movepick.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
class Position;
|
||||||
|
|
||||||
namespace Search {
|
namespace Search {
|
||||||
|
|
||||||
|
/// Threshold used for countermoves based pruning
|
||||||
|
const int CounterMovePruneThreshold = 0;
|
||||||
|
|
||||||
|
|
||||||
/// Stack struct keeps track of the information we need to remember from nodes
|
/// Stack struct keeps track of the information we need to remember from nodes
|
||||||
/// shallower and deeper in the tree during the search. Each search thread has
|
/// shallower and deeper in the tree during the search. Each search thread has
|
||||||
/// its own array of Stack objects, indexed by the current ply.
|
/// its own array of Stack objects, indexed by the current ply.
|
||||||
|
|
||||||
struct Stack {
|
struct Stack {
|
||||||
Move* pv;
|
Move* pv;
|
||||||
|
PieceToHistory* contHistory;
|
||||||
int ply;
|
int ply;
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Move excludedMove;
|
Move excludedMove;
|
||||||
Move killers[2];
|
Move killers[2];
|
||||||
Value staticEval;
|
Value staticEval;
|
||||||
bool skipEarlyPruning;
|
int statScore;
|
||||||
int moveCount;
|
int moveCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// RootMove struct is used for moves at the root of the tree. For each root move
|
/// RootMove struct is used for moves at the root of the tree. For each root move
|
||||||
/// we store a score and a PV (really a refutation in the case of moves which
|
/// we store a score and a PV (really a refutation in the case of moves which
|
||||||
/// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves.
|
/// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves.
|
||||||
@@ -54,56 +59,47 @@ struct Stack {
|
|||||||
struct RootMove {
|
struct RootMove {
|
||||||
|
|
||||||
explicit RootMove(Move m) : pv(1, m) {}
|
explicit RootMove(Move m) : pv(1, m) {}
|
||||||
|
|
||||||
bool operator<(const RootMove& m) const { return m.score < score; } // Descending sort
|
|
||||||
bool operator==(const Move& m) const { return pv[0] == m; }
|
|
||||||
void insert_pv_in_tt(Position& pos);
|
|
||||||
bool extract_ponder_from_tt(Position& pos);
|
bool extract_ponder_from_tt(Position& pos);
|
||||||
|
bool operator==(const Move& m) const { return pv[0] == m; }
|
||||||
|
bool operator<(const RootMove& m) const { // Sort in descending order
|
||||||
|
return m.score != score ? m.score < score
|
||||||
|
: m.previousScore < previousScore;
|
||||||
|
}
|
||||||
|
|
||||||
Value score = -VALUE_INFINITE;
|
Value score = -VALUE_INFINITE;
|
||||||
Value previousScore = -VALUE_INFINITE;
|
Value previousScore = -VALUE_INFINITE;
|
||||||
|
int selDepth = 0;
|
||||||
std::vector<Move> pv;
|
std::vector<Move> pv;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<RootMove> RootMoveVector;
|
typedef std::vector<RootMove> RootMoves;
|
||||||
|
|
||||||
|
|
||||||
/// LimitsType struct stores information sent by GUI about available time to
|
/// LimitsType struct stores information sent by GUI about available time to
|
||||||
/// search the current move, maximum depth/time, if we are in analysis mode or
|
/// search the current move, maximum depth/time, or if we are in analysis mode.
|
||||||
/// if we have to ponder while it's our opponent's turn to move.
|
|
||||||
|
|
||||||
struct LimitsType {
|
struct LimitsType {
|
||||||
|
|
||||||
LimitsType() { // Init explicitly due to broken value-initialization of non POD in MSVC
|
LimitsType() { // Init explicitly due to broken value-initialization of non POD in MSVC
|
||||||
nodes = time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movestogo =
|
nodes = time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] =
|
||||||
depth = movetime = mate = infinite = ponder = 0;
|
npmsec = movestogo = depth = movetime = mate = perft = infinite = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_time_management() const {
|
bool use_time_management() const {
|
||||||
return !(mate | movetime | depth | nodes | infinite);
|
return !(mate | movetime | depth | nodes | perft | infinite);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Move> searchmoves;
|
std::vector<Move> searchmoves;
|
||||||
int time[COLOR_NB], inc[COLOR_NB], npmsec, movestogo, depth, movetime, mate, infinite, ponder;
|
int time[COLOR_NB], inc[COLOR_NB], npmsec, movestogo, depth,
|
||||||
|
movetime, mate, perft, infinite;
|
||||||
int64_t nodes;
|
int64_t nodes;
|
||||||
TimePoint startTime;
|
TimePoint startTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The SignalsType struct stores atomic flags updated during the search
|
|
||||||
/// typically in an async fashion e.g. to stop the search by the GUI.
|
|
||||||
|
|
||||||
struct SignalsType {
|
|
||||||
std::atomic_bool stop, stopOnPonderhit;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::unique_ptr<std::stack<StateInfo>> StateStackPtr;
|
|
||||||
|
|
||||||
extern SignalsType Signals;
|
|
||||||
extern LimitsType Limits;
|
extern LimitsType Limits;
|
||||||
extern StateStackPtr SetupStates;
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void clear();
|
void clear();
|
||||||
template<bool Root = true> uint64_t perft(Position& pos, Depth depth);
|
|
||||||
|
|
||||||
} // namespace Search
|
} // namespace Search
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,169 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2011-2013 Ronald de Man
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TBCORE_H
|
|
||||||
#define TBCORE_H
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <pthread.h>
|
|
||||||
#define SEP_CHAR ':'
|
|
||||||
#define FD int
|
|
||||||
#define FD_ERR -1
|
|
||||||
#else
|
|
||||||
#include <windows.h>
|
|
||||||
#define SEP_CHAR ';'
|
|
||||||
#define FD HANDLE
|
|
||||||
#define FD_ERR INVALID_HANDLE_VALUE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#define LOCK_T pthread_mutex_t
|
|
||||||
#define LOCK_INIT(x) pthread_mutex_init(&(x), NULL)
|
|
||||||
#define LOCK(x) pthread_mutex_lock(&(x))
|
|
||||||
#define UNLOCK(x) pthread_mutex_unlock(&(x))
|
|
||||||
#else
|
|
||||||
#define LOCK_T HANDLE
|
|
||||||
#define LOCK_INIT(x) do { x = CreateMutex(NULL, FALSE, NULL); } while (0)
|
|
||||||
#define LOCK(x) WaitForSingleObject(x, INFINITE)
|
|
||||||
#define UNLOCK(x) ReleaseMutex(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
|
||||||
#define BSWAP32(v) __builtin_bswap32(v)
|
|
||||||
#define BSWAP64(v) __builtin_bswap64(v)
|
|
||||||
#else
|
|
||||||
#define BSWAP32(v) _byteswap_ulong(v)
|
|
||||||
#define BSWAP64(v) _byteswap_uint64(v)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WDLSUFFIX ".rtbw"
|
|
||||||
#define DTZSUFFIX ".rtbz"
|
|
||||||
#define WDLDIR "RTBWDIR"
|
|
||||||
#define DTZDIR "RTBZDIR"
|
|
||||||
#define TBPIECES 6
|
|
||||||
|
|
||||||
typedef unsigned long long uint64;
|
|
||||||
typedef unsigned int uint32;
|
|
||||||
typedef unsigned char ubyte;
|
|
||||||
typedef unsigned short ushort;
|
|
||||||
|
|
||||||
const ubyte WDL_MAGIC[4] = { 0x71, 0xe8, 0x23, 0x5d };
|
|
||||||
const ubyte DTZ_MAGIC[4] = { 0xd7, 0x66, 0x0c, 0xa5 };
|
|
||||||
|
|
||||||
#define TBHASHBITS 10
|
|
||||||
|
|
||||||
struct TBHashEntry;
|
|
||||||
|
|
||||||
typedef uint64 base_t;
|
|
||||||
|
|
||||||
struct PairsData {
|
|
||||||
char *indextable;
|
|
||||||
ushort *sizetable;
|
|
||||||
ubyte *data;
|
|
||||||
ushort *offset;
|
|
||||||
ubyte *symlen;
|
|
||||||
ubyte *sympat;
|
|
||||||
int blocksize;
|
|
||||||
int idxbits;
|
|
||||||
int min_len;
|
|
||||||
base_t base[1]; // C++ complains about base[]...
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TBEntry {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
}
|
|
||||||
#ifndef _WIN32
|
|
||||||
__attribute__((__may_alias__))
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
|
|
||||||
struct TBEntry_piece {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
ubyte enc_type;
|
|
||||||
struct PairsData *precomp[2];
|
|
||||||
int factor[2][TBPIECES];
|
|
||||||
ubyte pieces[2][TBPIECES];
|
|
||||||
ubyte norm[2][TBPIECES];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TBEntry_pawn {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
ubyte pawns[2];
|
|
||||||
struct {
|
|
||||||
struct PairsData *precomp[2];
|
|
||||||
int factor[2][TBPIECES];
|
|
||||||
ubyte pieces[2][TBPIECES];
|
|
||||||
ubyte norm[2][TBPIECES];
|
|
||||||
} file[4];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DTZEntry_piece {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
ubyte enc_type;
|
|
||||||
struct PairsData *precomp;
|
|
||||||
int factor[TBPIECES];
|
|
||||||
ubyte pieces[TBPIECES];
|
|
||||||
ubyte norm[TBPIECES];
|
|
||||||
ubyte flags; // accurate, mapped, side
|
|
||||||
ushort map_idx[4];
|
|
||||||
ubyte *map;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DTZEntry_pawn {
|
|
||||||
char *data;
|
|
||||||
uint64 key;
|
|
||||||
uint64 mapping;
|
|
||||||
ubyte ready;
|
|
||||||
ubyte num;
|
|
||||||
ubyte symmetric;
|
|
||||||
ubyte has_pawns;
|
|
||||||
ubyte pawns[2];
|
|
||||||
struct {
|
|
||||||
struct PairsData *precomp;
|
|
||||||
int factor[TBPIECES];
|
|
||||||
ubyte pieces[TBPIECES];
|
|
||||||
ubyte norm[TBPIECES];
|
|
||||||
} file[4];
|
|
||||||
ubyte flags[4];
|
|
||||||
ushort map_idx[4][4];
|
|
||||||
ubyte *map;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TBHashEntry {
|
|
||||||
uint64 key;
|
|
||||||
struct TBEntry *ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DTZTableEntry {
|
|
||||||
uint64 key1;
|
|
||||||
uint64 key2;
|
|
||||||
struct TBEntry *entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+1588
-719
File diff suppressed because it is too large
Load Diff
+66
-5
@@ -1,17 +1,78 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (c) 2013 Ronald de Man
|
||||||
|
Copyright (C) 2016-2018 Marco Costalba, Lucas Braesch
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef TBPROBE_H
|
#ifndef TBPROBE_H
|
||||||
#define TBPROBE_H
|
#define TBPROBE_H
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
#include "../search.h"
|
#include "../search.h"
|
||||||
|
|
||||||
namespace Tablebases {
|
namespace Tablebases {
|
||||||
|
|
||||||
|
enum WDLScore {
|
||||||
|
WDLLoss = -2, // Loss
|
||||||
|
WDLBlessedLoss = -1, // Loss, but draw under 50-move rule
|
||||||
|
WDLDraw = 0, // Draw
|
||||||
|
WDLCursedWin = 1, // Win, but draw under 50-move rule
|
||||||
|
WDLWin = 2, // Win
|
||||||
|
|
||||||
|
WDLScoreNone = -1000
|
||||||
|
};
|
||||||
|
|
||||||
|
// Possible states after a probing operation
|
||||||
|
enum ProbeState {
|
||||||
|
FAIL = 0, // Probe failed (missing file table)
|
||||||
|
OK = 1, // Probe succesful
|
||||||
|
CHANGE_STM = -1, // DTZ should check the other side
|
||||||
|
ZEROING_BEST_MOVE = 2 // Best move zeroes DTZ (capture or pawn move)
|
||||||
|
};
|
||||||
|
|
||||||
extern int MaxCardinality;
|
extern int MaxCardinality;
|
||||||
|
|
||||||
void init(const std::string& path);
|
void init(const std::string& paths);
|
||||||
int probe_wdl(Position& pos, int *success);
|
WDLScore probe_wdl(Position& pos, ProbeState* result);
|
||||||
int probe_dtz(Position& pos, int *success);
|
int probe_dtz(Position& pos, ProbeState* result);
|
||||||
bool root_probe(Position& pos, Search::RootMoveVector& rootMoves, Value& score);
|
bool root_probe(Position& pos, Search::RootMoves& rootMoves, Value& score);
|
||||||
bool root_probe_wdl(Position& pos, Search::RootMoveVector& rootMoves, Value& score);
|
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves, Value& score);
|
||||||
|
void filter_root_moves(Position& pos, Search::RootMoves& rootMoves);
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& os, const WDLScore v) {
|
||||||
|
|
||||||
|
os << (v == WDLLoss ? "Loss" :
|
||||||
|
v == WDLBlessedLoss ? "Blessed loss" :
|
||||||
|
v == WDLDraw ? "Draw" :
|
||||||
|
v == WDLCursedWin ? "Cursed win" :
|
||||||
|
v == WDLWin ? "Win" : "None");
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& os, const ProbeState v) {
|
||||||
|
|
||||||
|
os << (v == FAIL ? "Failed" :
|
||||||
|
v == OK ? "Success" :
|
||||||
|
v == CHANGE_STM ? "Probed opponent side" :
|
||||||
|
v == ZEROING_BEST_MOVE ? "Best move zeroes DTZ" : "None");
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+116
-112
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,171 +25,175 @@
|
|||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
using namespace Search;
|
|
||||||
|
|
||||||
ThreadPool Threads; // Global object
|
ThreadPool Threads; // Global object
|
||||||
|
|
||||||
/// Thread constructor launch the thread and then wait until it goes to sleep
|
|
||||||
/// in idle_loop().
|
|
||||||
|
|
||||||
Thread::Thread() {
|
/// Thread constructor launches the thread and waits until it goes to sleep
|
||||||
|
/// in idle_loop(). Note that 'searching' and 'exit' should be alredy set.
|
||||||
|
|
||||||
resetCalls = exit = false;
|
Thread::Thread(size_t n) : idx(n), stdThread(&Thread::idle_loop, this) {
|
||||||
maxPly = callsCnt = 0;
|
|
||||||
history.clear();
|
|
||||||
counterMoves.clear();
|
|
||||||
idx = Threads.size(); // Start from 0
|
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
wait_for_search_finished();
|
||||||
searching = true;
|
|
||||||
nativeThread = std::thread(&Thread::idle_loop, this);
|
|
||||||
sleepCondition.wait(lk, [&]{ return !searching; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Thread destructor wait for thread termination before returning
|
/// Thread destructor wakes up the thread in idle_loop() and waits
|
||||||
|
/// for its termination. Thread should be already waiting.
|
||||||
|
|
||||||
Thread::~Thread() {
|
Thread::~Thread() {
|
||||||
|
|
||||||
mutex.lock();
|
assert(!searching);
|
||||||
|
|
||||||
exit = true;
|
exit = true;
|
||||||
sleepCondition.notify_one();
|
start_searching();
|
||||||
mutex.unlock();
|
stdThread.join();
|
||||||
nativeThread.join();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Thread::wait_for_search_finished() wait on sleep condition until not searching
|
/// Thread::clear() reset histories, usually before a new game
|
||||||
|
|
||||||
|
void Thread::clear() {
|
||||||
|
|
||||||
|
counterMoves.fill(MOVE_NONE);
|
||||||
|
mainHistory.fill(0);
|
||||||
|
captureHistory.fill(0);
|
||||||
|
|
||||||
|
for (auto& to : contHistory)
|
||||||
|
for (auto& h : to)
|
||||||
|
h.fill(0);
|
||||||
|
|
||||||
|
contHistory[NO_PIECE][0].fill(Search::CounterMovePruneThreshold - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Thread::start_searching() wakes up the thread that will start the search
|
||||||
|
|
||||||
|
void Thread::start_searching() {
|
||||||
|
|
||||||
|
std::lock_guard<Mutex> lk(mutex);
|
||||||
|
searching = true;
|
||||||
|
cv.notify_one(); // Wake up the thread in idle_loop()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Thread::wait_for_search_finished() blocks on the condition variable
|
||||||
|
/// until the thread has finished searching.
|
||||||
|
|
||||||
void Thread::wait_for_search_finished() {
|
void Thread::wait_for_search_finished() {
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<Mutex> lk(mutex);
|
||||||
sleepCondition.wait(lk, [&]{ return !searching; });
|
cv.wait(lk, [&]{ return !searching; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Thread::wait() wait on sleep condition until condition is true
|
/// Thread::idle_loop() is where the thread is parked, blocked on the
|
||||||
|
/// condition variable, when it has no work to do.
|
||||||
void Thread::wait(std::atomic_bool& condition) {
|
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
|
||||||
sleepCondition.wait(lk, [&]{ return bool(condition); });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Thread::start_searching() wake up the thread that will start the search
|
|
||||||
|
|
||||||
void Thread::start_searching(bool resume) {
|
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
|
||||||
|
|
||||||
if (!resume)
|
|
||||||
searching = true;
|
|
||||||
|
|
||||||
sleepCondition.notify_one();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Thread::idle_loop() is where the thread is parked when it has no work to do
|
|
||||||
|
|
||||||
void Thread::idle_loop() {
|
void Thread::idle_loop() {
|
||||||
|
|
||||||
while (!exit)
|
// If OS already scheduled us on a different group than 0 then don't overwrite
|
||||||
|
// the choice, eventually we are one of many one-threaded processes running on
|
||||||
|
// some Windows NUMA hardware, for instance in fishtest. To make it simple,
|
||||||
|
// just check if running threads are below a threshold, in this case all this
|
||||||
|
// NUMA machinery is not needed.
|
||||||
|
if (Options["Threads"] >= 8)
|
||||||
|
WinProcGroup::bindThisThread(idx);
|
||||||
|
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<Mutex> lk(mutex);
|
||||||
|
|
||||||
searching = false;
|
searching = false;
|
||||||
|
cv.notify_one(); // Wake up anyone waiting for search finished
|
||||||
|
cv.wait(lk, [&]{ return searching; });
|
||||||
|
|
||||||
while (!searching && !exit)
|
if (exit)
|
||||||
{
|
return;
|
||||||
sleepCondition.notify_one(); // Wake up any waiting thread
|
|
||||||
sleepCondition.wait(lk);
|
|
||||||
}
|
|
||||||
|
|
||||||
lk.unlock();
|
lk.unlock();
|
||||||
|
|
||||||
if (!exit)
|
search();
|
||||||
search();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ThreadPool::set() creates/destroys threads to match the requested number.
|
||||||
|
/// Created and launced threads wil go immediately to sleep in idle_loop.
|
||||||
|
/// Upon resizing, threads are recreated to allow for binding if necessary.
|
||||||
|
|
||||||
/// ThreadPool::init() create and launch requested threads, that will go
|
void ThreadPool::set(size_t requested) {
|
||||||
/// immediately to sleep. We cannot use a constructor because Threads is a
|
|
||||||
/// static object and we need a fully initialized engine at this point due to
|
|
||||||
/// allocation of Endgames in the Thread constructor.
|
|
||||||
|
|
||||||
void ThreadPool::init() {
|
if (size() > 0) { // destroy any existing thread(s)
|
||||||
|
main()->wait_for_search_finished();
|
||||||
|
|
||||||
push_back(new MainThread);
|
while (size() > 0)
|
||||||
read_uci_options();
|
delete back(), pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requested > 0) { // create new thread(s)
|
||||||
|
push_back(new MainThread(0));
|
||||||
|
|
||||||
|
while (size() < requested)
|
||||||
|
push_back(new Thread(size()));
|
||||||
|
clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ThreadPool::clear() sets threadPool data to initial values.
|
||||||
|
|
||||||
/// ThreadPool::exit() terminate threads before the program exits. Cannot be
|
void ThreadPool::clear() {
|
||||||
/// done in destructor because threads must be terminated before deleting any
|
|
||||||
/// static objects, so while still in main().
|
|
||||||
|
|
||||||
void ThreadPool::exit() {
|
|
||||||
|
|
||||||
while (size())
|
|
||||||
delete back(), pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// ThreadPool::read_uci_options() updates internal threads parameters from the
|
|
||||||
/// corresponding UCI options and creates/destroys threads to match requested
|
|
||||||
/// number. Thread objects are dynamically allocated.
|
|
||||||
|
|
||||||
void ThreadPool::read_uci_options() {
|
|
||||||
|
|
||||||
size_t requested = Options["Threads"];
|
|
||||||
|
|
||||||
assert(requested > 0);
|
|
||||||
|
|
||||||
while (size() < requested)
|
|
||||||
push_back(new Thread);
|
|
||||||
|
|
||||||
while (size() > requested)
|
|
||||||
delete back(), pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// ThreadPool::nodes_searched() return the number of nodes searched
|
|
||||||
|
|
||||||
int64_t ThreadPool::nodes_searched() {
|
|
||||||
|
|
||||||
int64_t nodes = 0;
|
|
||||||
for (Thread* th : *this)
|
for (Thread* th : *this)
|
||||||
nodes += th->rootPos.nodes_searched();
|
th->clear();
|
||||||
return nodes;
|
|
||||||
|
main()->callsCnt = 0;
|
||||||
|
main()->previousScore = VALUE_INFINITE;
|
||||||
|
main()->previousTimeReduction = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and
|
||||||
|
/// returns immediately. Main thread will wake up other threads and start the search.
|
||||||
|
|
||||||
/// ThreadPool::start_thinking() wake up the main thread sleeping in idle_loop()
|
void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
|
||||||
/// and start a new search, then return immediately.
|
const Search::LimitsType& limits, bool ponderMode) {
|
||||||
|
|
||||||
void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
|
|
||||||
StateStackPtr& states) {
|
|
||||||
|
|
||||||
main()->wait_for_search_finished();
|
main()->wait_for_search_finished();
|
||||||
|
|
||||||
Signals.stopOnPonderhit = Signals.stop = false;
|
stopOnPonderhit = stop = false;
|
||||||
|
ponder = ponderMode;
|
||||||
main()->rootMoves.clear();
|
Search::Limits = limits;
|
||||||
main()->rootPos = pos;
|
Search::RootMoves rootMoves;
|
||||||
Limits = limits;
|
|
||||||
if (states.get()) // If we don't set a new position, preserve current state
|
|
||||||
{
|
|
||||||
SetupStates = std::move(states); // Ownership transfer here
|
|
||||||
assert(!states.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& m : MoveList<LEGAL>(pos))
|
for (const auto& m : MoveList<LEGAL>(pos))
|
||||||
if ( limits.searchmoves.empty()
|
if ( limits.searchmoves.empty()
|
||||||
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m))
|
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m))
|
||||||
main()->rootMoves.push_back(RootMove(m));
|
rootMoves.emplace_back(m);
|
||||||
|
|
||||||
|
if (!rootMoves.empty())
|
||||||
|
Tablebases::filter_root_moves(pos, rootMoves);
|
||||||
|
|
||||||
|
// After ownership transfer 'states' becomes empty, so if we stop the search
|
||||||
|
// and call 'go' again without setting a new position states.get() == NULL.
|
||||||
|
assert(states.get() || setupStates.get());
|
||||||
|
|
||||||
|
if (states.get())
|
||||||
|
setupStates = std::move(states); // Ownership transfer, states is now empty
|
||||||
|
|
||||||
|
// We use Position::set() to set root position across threads. But there are
|
||||||
|
// some StateInfo fields (previous, pliesFromNull, capturedPiece) that cannot
|
||||||
|
// be deduced from a fen string, so set() clears them and to not lose the info
|
||||||
|
// we need to backup and later restore setupStates->back(). Note that setupStates
|
||||||
|
// is shared by threads but is accessed in read-only mode.
|
||||||
|
StateInfo tmp = setupStates->back();
|
||||||
|
|
||||||
|
for (Thread* th : *this)
|
||||||
|
{
|
||||||
|
th->nodes = th->tbHits = th->nmp_ply = th->nmp_odd = 0;
|
||||||
|
th->rootDepth = th->completedDepth = DEPTH_ZERO;
|
||||||
|
th->rootMoves = rootMoves;
|
||||||
|
th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th);
|
||||||
|
}
|
||||||
|
|
||||||
|
setupStates->back() = tmp;
|
||||||
|
|
||||||
main()->start_searching();
|
main()->start_searching();
|
||||||
}
|
}
|
||||||
|
|||||||
+52
-32
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#define THREAD_H_INCLUDED
|
#define THREAD_H_INCLUDED
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <bitset>
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -36,66 +35,87 @@
|
|||||||
#include "thread_win32.h"
|
#include "thread_win32.h"
|
||||||
|
|
||||||
|
|
||||||
/// Thread struct keeps together all the thread related stuff. We also use
|
/// Thread class keeps together all the thread-related stuff. We use
|
||||||
/// per-thread pawn and material hash tables so that once we get a pointer to an
|
/// per-thread pawn and material hash tables so that once we get a
|
||||||
/// entry its life time is unlimited and we don't have to care about someone
|
/// pointer to an entry its life time is unlimited and we don't have
|
||||||
/// changing the entry under our feet.
|
/// to care about someone changing the entry under our feet.
|
||||||
|
|
||||||
class Thread {
|
class Thread {
|
||||||
|
|
||||||
std::thread nativeThread;
|
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
ConditionVariable sleepCondition;
|
ConditionVariable cv;
|
||||||
bool exit, searching;
|
size_t idx;
|
||||||
|
bool exit = false, searching = true; // Set before starting std::thread
|
||||||
|
std::thread stdThread;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Thread();
|
explicit Thread(size_t);
|
||||||
virtual ~Thread();
|
virtual ~Thread();
|
||||||
virtual void search();
|
virtual void search();
|
||||||
|
void clear();
|
||||||
void idle_loop();
|
void idle_loop();
|
||||||
void start_searching(bool resume = false);
|
void start_searching();
|
||||||
void wait_for_search_finished();
|
void wait_for_search_finished();
|
||||||
void wait(std::atomic_bool& b);
|
|
||||||
|
|
||||||
Pawns::Table pawnsTable;
|
Pawns::Table pawnsTable;
|
||||||
Material::Table materialTable;
|
Material::Table materialTable;
|
||||||
Endgames endgames;
|
Endgames endgames;
|
||||||
size_t idx, PVIdx;
|
size_t PVIdx;
|
||||||
int maxPly, callsCnt;
|
int selDepth, nmp_ply, nmp_odd;
|
||||||
|
std::atomic<uint64_t> nodes, tbHits;
|
||||||
|
|
||||||
Position rootPos;
|
Position rootPos;
|
||||||
Search::RootMoveVector rootMoves;
|
Search::RootMoves rootMoves;
|
||||||
Depth rootDepth;
|
Depth rootDepth, completedDepth;
|
||||||
HistoryStats history;
|
CounterMoveHistory counterMoves;
|
||||||
MovesStats counterMoves;
|
ButterflyHistory mainHistory;
|
||||||
Depth completedDepth;
|
CapturePieceToHistory captureHistory;
|
||||||
std::atomic_bool resetCalls;
|
ContinuationHistory contHistory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// MainThread is a derived class with a specific overload for the main thread
|
/// MainThread is a derived class specific for main thread
|
||||||
|
|
||||||
struct MainThread : public Thread {
|
struct MainThread : public Thread {
|
||||||
virtual void search();
|
|
||||||
|
|
||||||
bool easyMovePlayed, failedLow;
|
using Thread::Thread;
|
||||||
double bestMoveChanges;
|
|
||||||
|
void search() override;
|
||||||
|
void check_time();
|
||||||
|
|
||||||
|
bool failedLow;
|
||||||
|
double bestMoveChanges, previousTimeReduction;
|
||||||
|
Value previousScore;
|
||||||
|
int callsCnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// ThreadPool struct handles all the threads related stuff like init, starting,
|
/// ThreadPool struct handles all the threads-related stuff like init, starting,
|
||||||
/// parking and, most importantly, launching a thread. All the access to threads
|
/// parking and, most importantly, launching a thread. All the access to threads
|
||||||
/// data is done through this class.
|
/// is done through this class.
|
||||||
|
|
||||||
struct ThreadPool : public std::vector<Thread*> {
|
struct ThreadPool : public std::vector<Thread*> {
|
||||||
|
|
||||||
void init(); // No constructor and destructor, threads rely on globals that should
|
void start_thinking(Position&, StateListPtr&, const Search::LimitsType&, bool = false);
|
||||||
void exit(); // be initialized and valid during the whole thread lifetime.
|
void clear();
|
||||||
|
void set(size_t);
|
||||||
|
|
||||||
MainThread* main() { return static_cast<MainThread*>(at(0)); }
|
MainThread* main() const { return static_cast<MainThread*>(front()); }
|
||||||
void start_thinking(const Position&, const Search::LimitsType&, Search::StateStackPtr&);
|
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
|
||||||
void read_uci_options();
|
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
|
||||||
int64_t nodes_searched();
|
|
||||||
|
std::atomic_bool stop, ponder, stopOnPonderhit;
|
||||||
|
|
||||||
|
private:
|
||||||
|
StateListPtr setupStates;
|
||||||
|
|
||||||
|
uint64_t accumulate(std::atomic<uint64_t> Thread::* member) const {
|
||||||
|
|
||||||
|
uint64_t sum = 0;
|
||||||
|
for (Thread* th : *this)
|
||||||
|
sum += (th->*member).load(std::memory_order_relaxed);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ThreadPool Threads;
|
extern ThreadPool Threads;
|
||||||
|
|||||||
+3
-3
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,11 +25,11 @@
|
|||||||
/// relies on libwinpthread. Currently libwinpthread implements mutexes directly
|
/// relies on libwinpthread. Currently libwinpthread implements mutexes directly
|
||||||
/// on top of Windows semaphores. Semaphores, being kernel objects, require kernel
|
/// on top of Windows semaphores. Semaphores, being kernel objects, require kernel
|
||||||
/// mode transition in order to lock or unlock, which is very slow compared to
|
/// mode transition in order to lock or unlock, which is very slow compared to
|
||||||
/// interlocked operations (about 30% slower on bench test). To workaround this
|
/// interlocked operations (about 30% slower on bench test). To work around this
|
||||||
/// issue, we define our wrappers to the low level Win32 calls. We use critical
|
/// issue, we define our wrappers to the low level Win32 calls. We use critical
|
||||||
/// sections to support Windows XP and older versions. Unfortunately, cond_wait()
|
/// sections to support Windows XP and older versions. Unfortunately, cond_wait()
|
||||||
/// is racy between unlock() and WaitForSingleObject() but they have the same
|
/// is racy between unlock() and WaitForSingleObject() but they have the same
|
||||||
/// speed performance of SRW locks.
|
/// speed performance as the SRW locks.
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|||||||
+13
-14
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,27 +33,27 @@ namespace {
|
|||||||
enum TimeType { OptimumTime, MaxTime };
|
enum TimeType { OptimumTime, MaxTime };
|
||||||
|
|
||||||
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||||
const double MaxRatio = 6.93; // When in trouble, we can step over reserved time with this ratio
|
const double MaxRatio = 7.09; // When in trouble, we can step over reserved time with this ratio
|
||||||
const double StealRatio = 0.36; // However we must not steal time from remaining moves over this ratio
|
const double StealRatio = 0.35; // However we must not steal time from remaining moves over this ratio
|
||||||
|
|
||||||
|
|
||||||
// move_importance() is a skew-logistic function based on naive statistical
|
// move_importance() is a skew-logistic function based on naive statistical
|
||||||
// analysis of "how many games are still undecided after n half-moves". Game
|
// analysis of "how many games are still undecided after n half-moves". Game
|
||||||
// is considered "undecided" as long as neither side has >275cp advantage.
|
// is considered "undecided" as long as neither side has >275cp advantage.
|
||||||
// Data was extracted from CCRL game database with some simple filtering criteria.
|
// Data was extracted from the CCRL game database with some simple filtering criteria.
|
||||||
|
|
||||||
double move_importance(int ply) {
|
double move_importance(int ply) {
|
||||||
|
|
||||||
const double XScale = 8.27;
|
const double XScale = 7.64;
|
||||||
const double XShift = 59.;
|
const double XShift = 58.4;
|
||||||
const double Skew = 0.179;
|
const double Skew = 0.183;
|
||||||
|
|
||||||
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
||||||
}
|
}
|
||||||
|
|
||||||
template<TimeType T>
|
template<TimeType T>
|
||||||
int remaining(int myTime, int movesToGo, int ply, int slowMover)
|
int remaining(int myTime, int movesToGo, int ply, int slowMover) {
|
||||||
{
|
|
||||||
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
||||||
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ namespace {
|
|||||||
double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance);
|
double ratio1 = (TMaxRatio * moveImportance) / (TMaxRatio * moveImportance + otherMovesImportance);
|
||||||
double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance);
|
double ratio2 = (moveImportance + TStealRatio * otherMovesImportance) / (moveImportance + otherMovesImportance);
|
||||||
|
|
||||||
return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks an explicit cast
|
return int(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -81,8 +81,8 @@ namespace {
|
|||||||
/// inc > 0 && movestogo == 0 means: x basetime + z increment
|
/// inc > 0 && movestogo == 0 means: x basetime + z increment
|
||||||
/// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment
|
/// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment
|
||||||
|
|
||||||
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply)
|
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
||||||
{
|
|
||||||
int minThinkingTime = Options["Minimum Thinking Time"];
|
int minThinkingTime = Options["Minimum Thinking Time"];
|
||||||
int moveOverhead = Options["Move Overhead"];
|
int moveOverhead = Options["Move Overhead"];
|
||||||
int slowMover = Options["Slow Mover"];
|
int slowMover = Options["Slow Mover"];
|
||||||
@@ -91,7 +91,7 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply)
|
|||||||
// If we have to play in 'nodes as time' mode, then convert from time
|
// If we have to play in 'nodes as time' mode, then convert from time
|
||||||
// to nodes, and use resulting values in time management formulas.
|
// to nodes, and use resulting values in time management formulas.
|
||||||
// WARNING: Given npms (nodes per millisecond) must be much lower then
|
// WARNING: Given npms (nodes per millisecond) must be much lower then
|
||||||
// real engine speed to avoid time losses.
|
// the real engine speed to avoid time losses.
|
||||||
if (npmsec)
|
if (npmsec)
|
||||||
{
|
{
|
||||||
if (!availableNodes) // Only once at game start
|
if (!availableNodes) // Only once at game start
|
||||||
@@ -104,7 +104,6 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
startTime = limits.startTime;
|
startTime = limits.startTime;
|
||||||
unstablePvFactor = 1;
|
|
||||||
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
||||||
|
|
||||||
const int MaxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
const int MaxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
||||||
|
|||||||
+2
-4
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,8 +31,7 @@
|
|||||||
class TimeManagement {
|
class TimeManagement {
|
||||||
public:
|
public:
|
||||||
void init(Search::LimitsType& limits, Color us, int ply);
|
void init(Search::LimitsType& limits, Color us, int ply);
|
||||||
void pv_instability(double bestMoveChanges) { unstablePvFactor = 1 + bestMoveChanges; }
|
int optimum() const { return optimumTime; }
|
||||||
int available() const { return int(optimumTime * unstablePvFactor * 1.016); }
|
|
||||||
int maximum() const { return maximumTime; }
|
int maximum() const { return maximumTime; }
|
||||||
int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - startTime); }
|
int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - startTime); }
|
||||||
|
|
||||||
@@ -42,7 +41,6 @@ private:
|
|||||||
TimePoint startTime;
|
TimePoint startTime;
|
||||||
int optimumTime;
|
int optimumTime;
|
||||||
int maximumTime;
|
int maximumTime;
|
||||||
double unstablePvFactor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TimeManagement Time;
|
extern TimeManagement Time;
|
||||||
|
|||||||
+10
-9
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,7 +33,7 @@ TranspositionTable TT; // Our global transposition table
|
|||||||
|
|
||||||
void TranspositionTable::resize(size_t mbSize) {
|
void TranspositionTable::resize(size_t mbSize) {
|
||||||
|
|
||||||
size_t newClusterCount = size_t(1) << msb((mbSize * 1024 * 1024) / sizeof(Cluster));
|
size_t newClusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
|
||||||
|
|
||||||
if (newClusterCount == clusterCount)
|
if (newClusterCount == clusterCount)
|
||||||
return;
|
return;
|
||||||
@@ -41,7 +41,7 @@ void TranspositionTable::resize(size_t mbSize) {
|
|||||||
clusterCount = newClusterCount;
|
clusterCount = newClusterCount;
|
||||||
|
|
||||||
free(mem);
|
free(mem);
|
||||||
mem = calloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1, 1);
|
mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);
|
||||||
|
|
||||||
if (!mem)
|
if (!mem)
|
||||||
{
|
{
|
||||||
@@ -51,6 +51,7 @@ void TranspositionTable::resize(size_t mbSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
|
table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -92,19 +93,19 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
|||||||
// nature we add 259 (256 is the modulus plus 3 to keep the lowest
|
// nature we add 259 (256 is the modulus plus 3 to keep the lowest
|
||||||
// two bound bits from affecting the result) to calculate the entry
|
// two bound bits from affecting the result) to calculate the entry
|
||||||
// age correctly even after generation8 overflows into the next cycle.
|
// age correctly even after generation8 overflows into the next cycle.
|
||||||
if ( replace->depth8 - ((259 + generation8 - replace->genBound8) & 0xFC) * 2 * ONE_PLY
|
if ( replace->depth8 - ((259 + generation8 - replace->genBound8) & 0xFC) * 2
|
||||||
> tte[i].depth8 - ((259 + generation8 - tte[i].genBound8) & 0xFC) * 2 * ONE_PLY)
|
> tte[i].depth8 - ((259 + generation8 - tte[i].genBound8) & 0xFC) * 2)
|
||||||
replace = &tte[i];
|
replace = &tte[i];
|
||||||
|
|
||||||
return found = false, replace;
|
return found = false, replace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns an approximation of the hashtable occupation during a search. The
|
/// TranspositionTable::hashfull() returns an approximation of the hashtable
|
||||||
/// hash is x permill full, as per UCI protocol.
|
/// occupation during a search. The hash is x permill full, as per UCI protocol.
|
||||||
|
|
||||||
|
int TranspositionTable::hashfull() const {
|
||||||
|
|
||||||
int TranspositionTable::hashfull() const
|
|
||||||
{
|
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for (int i = 0; i < 1000 / ClusterSize; i++)
|
for (int i = 0; i < 1000 / ClusterSize; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -39,18 +39,20 @@ struct TTEntry {
|
|||||||
Move move() const { return (Move )move16; }
|
Move move() const { return (Move )move16; }
|
||||||
Value value() const { return (Value)value16; }
|
Value value() const { return (Value)value16; }
|
||||||
Value eval() const { return (Value)eval16; }
|
Value eval() const { return (Value)eval16; }
|
||||||
Depth depth() const { return (Depth)depth8; }
|
Depth depth() const { return (Depth)(depth8 * int(ONE_PLY)); }
|
||||||
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
||||||
|
|
||||||
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
|
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
|
||||||
|
|
||||||
|
assert(d / ONE_PLY * ONE_PLY == d);
|
||||||
|
|
||||||
// Preserve any existing move for the same position
|
// Preserve any existing move for the same position
|
||||||
if (m || (k >> 48) != key16)
|
if (m || (k >> 48) != key16)
|
||||||
move16 = (uint16_t)m;
|
move16 = (uint16_t)m;
|
||||||
|
|
||||||
// Don't overwrite more valuable entries
|
// Don't overwrite more valuable entries
|
||||||
if ( (k >> 48) != key16
|
if ( (k >> 48) != key16
|
||||||
|| d > depth8 - 2
|
|| d / ONE_PLY > depth8 - 4
|
||||||
/* || g != (genBound8 & 0xFC) // Matching non-zero keys are already refreshed by probe() */
|
/* || g != (genBound8 & 0xFC) // Matching non-zero keys are already refreshed by probe() */
|
||||||
|| b == BOUND_EXACT)
|
|| b == BOUND_EXACT)
|
||||||
{
|
{
|
||||||
@@ -58,7 +60,7 @@ struct TTEntry {
|
|||||||
value16 = (int16_t)v;
|
value16 = (int16_t)v;
|
||||||
eval16 = (int16_t)ev;
|
eval16 = (int16_t)ev;
|
||||||
genBound8 = (uint8_t)(g | b);
|
genBound8 = (uint8_t)(g | b);
|
||||||
depth8 = (int8_t)d;
|
depth8 = (int8_t)(d / ONE_PLY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,9 +104,9 @@ public:
|
|||||||
void resize(size_t mbSize);
|
void resize(size_t mbSize);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// The lowest order bits of the key are used to get the index of the cluster
|
// The 32 lowest order bits of the key are used to get the index of the cluster
|
||||||
TTEntry* first_entry(const Key key) const {
|
TTEntry* first_entry(const Key key) const {
|
||||||
return &table[(size_t)key & (clusterCount - 1)].entry[0];
|
return &table[(uint32_t(key) * uint64_t(clusterCount)) >> 32].entry[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+138
-101
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -60,13 +60,12 @@
|
|||||||
/// _WIN64 Building on Windows 64 bit
|
/// _WIN64 Building on Windows 64 bit
|
||||||
|
|
||||||
#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
|
#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
|
||||||
# include <intrin.h> // MSVC popcnt and bsfq instrinsics
|
# include <intrin.h> // Microsoft header for _BitScanForward64()
|
||||||
# define IS_64BIT
|
# define IS_64BIT
|
||||||
# define USE_BSFQ
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_POPCNT) && defined(__INTEL_COMPILER) && defined(_MSC_VER)
|
#if defined(USE_POPCNT) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
||||||
# include <nmmintrin.h> // Intel header for _mm_popcnt_u64() intrinsic
|
# include <nmmintrin.h> // Intel and Microsoft header for _mm_popcnt_u64()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
||||||
@@ -77,7 +76,7 @@
|
|||||||
# include <immintrin.h> // Header for _pext_u64() intrinsic
|
# include <immintrin.h> // Header for _pext_u64() intrinsic
|
||||||
# define pext(b, m) _pext_u64(b, m)
|
# define pext(b, m) _pext_u64(b, m)
|
||||||
#else
|
#else
|
||||||
# define pext(b, m) (0)
|
# define pext(b, m) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_POPCNT
|
#ifdef USE_POPCNT
|
||||||
@@ -116,7 +115,7 @@ const int MAX_PLY = 128;
|
|||||||
/// any normal move destination square is always different from origin square
|
/// any normal move destination square is always different from origin square
|
||||||
/// while MOVE_NONE and MOVE_NULL have the same origin and destination square.
|
/// while MOVE_NONE and MOVE_NULL have the same origin and destination square.
|
||||||
|
|
||||||
enum Move {
|
enum Move : int {
|
||||||
MOVE_NONE,
|
MOVE_NONE,
|
||||||
MOVE_NULL = 65
|
MOVE_NULL = 65
|
||||||
};
|
};
|
||||||
@@ -129,7 +128,7 @@ enum MoveType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum Color {
|
enum Color {
|
||||||
WHITE, BLACK, NO_COLOR, COLOR_NB = 2
|
WHITE, BLACK, COLOR_NB = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CastlingSide {
|
enum CastlingSide {
|
||||||
@@ -147,7 +146,7 @@ enum CastlingRight {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<Color C, CastlingSide S> struct MakeCastling {
|
template<Color C, CastlingSide S> struct MakeCastling {
|
||||||
static const CastlingRight
|
static constexpr CastlingRight
|
||||||
right = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO
|
right = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO
|
||||||
: S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO;
|
: S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO;
|
||||||
};
|
};
|
||||||
@@ -184,18 +183,19 @@ enum Value : int {
|
|||||||
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
||||||
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
||||||
|
|
||||||
PawnValueMg = 198, PawnValueEg = 258,
|
PawnValueMg = 171, PawnValueEg = 240,
|
||||||
KnightValueMg = 817, KnightValueEg = 846,
|
KnightValueMg = 764, KnightValueEg = 848,
|
||||||
BishopValueMg = 836, BishopValueEg = 857,
|
BishopValueMg = 826, BishopValueEg = 891,
|
||||||
RookValueMg = 1270, RookValueEg = 1281,
|
RookValueMg = 1282, RookValueEg = 1373,
|
||||||
QueenValueMg = 2521, QueenValueEg = 2558,
|
QueenValueMg = 2526, QueenValueEg = 2646,
|
||||||
|
|
||||||
MidgameLimit = 15581, EndgameLimit = 3998
|
MidgameLimit = 15258, EndgameLimit = 3915
|
||||||
};
|
};
|
||||||
|
|
||||||
enum PieceType {
|
enum PieceType {
|
||||||
NO_PIECE_TYPE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING,
|
NO_PIECE_TYPE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING,
|
||||||
ALL_PIECES = 0,
|
ALL_PIECES = 0,
|
||||||
|
QUEEN_DIAGONAL = 7,
|
||||||
PIECE_TYPE_NB = 8
|
PIECE_TYPE_NB = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -206,20 +206,24 @@ enum Piece {
|
|||||||
PIECE_NB = 16
|
PIECE_NB = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Depth {
|
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
||||||
|
|
||||||
|
enum Depth : int {
|
||||||
|
|
||||||
ONE_PLY = 1,
|
ONE_PLY = 1,
|
||||||
|
|
||||||
DEPTH_ZERO = 0,
|
DEPTH_ZERO = 0 * ONE_PLY,
|
||||||
DEPTH_QS_CHECKS = 0,
|
DEPTH_QS_CHECKS = 0 * ONE_PLY,
|
||||||
DEPTH_QS_NO_CHECKS = -1,
|
DEPTH_QS_NO_CHECKS = -1 * ONE_PLY,
|
||||||
DEPTH_QS_RECAPTURES = -5,
|
DEPTH_QS_RECAPTURES = -5 * ONE_PLY,
|
||||||
|
|
||||||
DEPTH_NONE = -6,
|
DEPTH_NONE = -6 * ONE_PLY,
|
||||||
DEPTH_MAX = MAX_PLY
|
DEPTH_MAX = MAX_PLY * ONE_PLY
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Square {
|
static_assert(!(ONE_PLY & (ONE_PLY - 1)), "ONE_PLY is not a power of 2");
|
||||||
|
|
||||||
|
enum Square : int {
|
||||||
SQ_A1, SQ_B1, SQ_C1, SQ_D1, SQ_E1, SQ_F1, SQ_G1, SQ_H1,
|
SQ_A1, SQ_B1, SQ_C1, SQ_D1, SQ_E1, SQ_F1, SQ_G1, SQ_H1,
|
||||||
SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2,
|
SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2,
|
||||||
SQ_A3, SQ_B3, SQ_C3, SQ_D3, SQ_E3, SQ_F3, SQ_G3, SQ_H3,
|
SQ_A3, SQ_B3, SQ_C3, SQ_D3, SQ_E3, SQ_F3, SQ_G3, SQ_H3,
|
||||||
@@ -230,132 +234,161 @@ enum Square {
|
|||||||
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
||||||
SQ_NONE,
|
SQ_NONE,
|
||||||
|
|
||||||
SQUARE_NB = 64,
|
SQUARE_NB = 64
|
||||||
|
|
||||||
DELTA_N = 8,
|
|
||||||
DELTA_E = 1,
|
|
||||||
DELTA_S = -8,
|
|
||||||
DELTA_W = -1,
|
|
||||||
|
|
||||||
DELTA_NN = DELTA_N + DELTA_N,
|
|
||||||
DELTA_NE = DELTA_N + DELTA_E,
|
|
||||||
DELTA_SE = DELTA_S + DELTA_E,
|
|
||||||
DELTA_SS = DELTA_S + DELTA_S,
|
|
||||||
DELTA_SW = DELTA_S + DELTA_W,
|
|
||||||
DELTA_NW = DELTA_N + DELTA_W
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum File {
|
enum Direction : int {
|
||||||
|
NORTH = 8,
|
||||||
|
EAST = 1,
|
||||||
|
SOUTH = -NORTH,
|
||||||
|
WEST = -EAST,
|
||||||
|
|
||||||
|
NORTH_EAST = NORTH + EAST,
|
||||||
|
SOUTH_EAST = SOUTH + EAST,
|
||||||
|
SOUTH_WEST = SOUTH + WEST,
|
||||||
|
NORTH_WEST = NORTH + WEST
|
||||||
|
};
|
||||||
|
|
||||||
|
enum File : int {
|
||||||
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB
|
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Rank {
|
enum Rank : int {
|
||||||
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
|
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Score enum stores a middlegame and an endgame value in a single integer
|
/// Score enum stores a middlegame and an endgame value in a single integer
|
||||||
/// (enum). The least significant 16 bits are used to store the endgame value
|
/// (enum). The least significant 16 bits are used to store the endgame value
|
||||||
/// and the upper 16 bits are used to store the middlegame value.
|
/// and the upper 16 bits are used to store the middlegame value. Take some
|
||||||
|
/// care to avoid left-shifting a signed int to avoid undefined behavior.
|
||||||
enum Score : int { SCORE_ZERO };
|
enum Score : int { SCORE_ZERO };
|
||||||
|
|
||||||
inline Score make_score(int mg, int eg) {
|
constexpr Score make_score(int mg, int eg) {
|
||||||
return Score((mg << 16) + eg);
|
return Score((int)((unsigned int)eg << 16) + mg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracting the signed lower and upper 16 bits is not so trivial because
|
/// Extracting the signed lower and upper 16 bits is not so trivial because
|
||||||
/// according to the standard a simple cast to short is implementation defined
|
/// according to the standard a simple cast to short is implementation defined
|
||||||
/// and so is a right shift of a signed integer.
|
/// and so is a right shift of a signed integer.
|
||||||
inline Value mg_value(Score s) {
|
|
||||||
|
|
||||||
union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s + 0x8000) >> 16) };
|
|
||||||
return Value(mg.s);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Value eg_value(Score s) {
|
inline Value eg_value(Score s) {
|
||||||
|
union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s + 0x8000) >> 16) };
|
||||||
union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s)) };
|
|
||||||
return Value(eg.s);
|
return Value(eg.s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ENABLE_BASE_OPERATORS_ON(T) \
|
inline Value mg_value(Score s) {
|
||||||
inline T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
|
union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s)) };
|
||||||
inline T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \
|
return Value(mg.s);
|
||||||
inline T operator*(int i, T d) { return T(i * int(d)); } \
|
}
|
||||||
inline T operator*(T d, int i) { return T(int(d) * i); } \
|
|
||||||
inline T operator-(T d) { return T(-int(d)); } \
|
|
||||||
inline T& operator+=(T& d1, T d2) { return d1 = d1 + d2; } \
|
|
||||||
inline T& operator-=(T& d1, T d2) { return d1 = d1 - d2; } \
|
|
||||||
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); }
|
|
||||||
|
|
||||||
#define ENABLE_FULL_OPERATORS_ON(T) \
|
#define ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
ENABLE_BASE_OPERATORS_ON(T) \
|
constexpr T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
|
||||||
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
constexpr T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \
|
||||||
inline T& operator--(T& d) { return d = T(int(d) - 1); } \
|
constexpr T operator-(T d) { return T(-int(d)); } \
|
||||||
inline T operator/(T d, int i) { return T(int(d) / i); } \
|
inline T& operator+=(T& d1, T d2) { return d1 = d1 + d2; } \
|
||||||
inline int operator/(T d1, T d2) { return int(d1) / int(d2); } \
|
inline T& operator-=(T& d1, T d2) { return d1 = d1 - d2; }
|
||||||
|
|
||||||
|
#define ENABLE_INCR_OPERATORS_ON(T) \
|
||||||
|
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
||||||
|
inline T& operator--(T& d) { return d = T(int(d) - 1); }
|
||||||
|
|
||||||
|
#define ENABLE_FULL_OPERATORS_ON(T) \
|
||||||
|
ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
|
ENABLE_INCR_OPERATORS_ON(T) \
|
||||||
|
constexpr T operator*(int i, T d) { return T(i * int(d)); } \
|
||||||
|
constexpr T operator*(T d, int i) { return T(int(d) * i); } \
|
||||||
|
constexpr T operator/(T d, int i) { return T(int(d) / i); } \
|
||||||
|
constexpr int operator/(T d1, T d2) { return int(d1) / int(d2); } \
|
||||||
|
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); } \
|
||||||
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
||||||
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Value)
|
ENABLE_FULL_OPERATORS_ON(Value)
|
||||||
ENABLE_FULL_OPERATORS_ON(PieceType)
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Piece)
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Color)
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Depth)
|
ENABLE_FULL_OPERATORS_ON(Depth)
|
||||||
ENABLE_FULL_OPERATORS_ON(Square)
|
ENABLE_FULL_OPERATORS_ON(Direction)
|
||||||
ENABLE_FULL_OPERATORS_ON(File)
|
|
||||||
ENABLE_FULL_OPERATORS_ON(Rank)
|
ENABLE_INCR_OPERATORS_ON(PieceType)
|
||||||
|
ENABLE_INCR_OPERATORS_ON(Piece)
|
||||||
|
ENABLE_INCR_OPERATORS_ON(Color)
|
||||||
|
ENABLE_INCR_OPERATORS_ON(Square)
|
||||||
|
ENABLE_INCR_OPERATORS_ON(File)
|
||||||
|
ENABLE_INCR_OPERATORS_ON(Rank)
|
||||||
|
|
||||||
ENABLE_BASE_OPERATORS_ON(Score)
|
ENABLE_BASE_OPERATORS_ON(Score)
|
||||||
|
|
||||||
#undef ENABLE_FULL_OPERATORS_ON
|
#undef ENABLE_FULL_OPERATORS_ON
|
||||||
|
#undef ENABLE_INCR_OPERATORS_ON
|
||||||
#undef ENABLE_BASE_OPERATORS_ON
|
#undef ENABLE_BASE_OPERATORS_ON
|
||||||
|
|
||||||
/// Additional operators to add integers to a Value
|
/// Additional operators to add integers to a Value
|
||||||
inline Value operator+(Value v, int i) { return Value(int(v) + i); }
|
constexpr Value operator+(Value v, int i) { return Value(int(v) + i); }
|
||||||
inline Value operator-(Value v, int i) { return Value(int(v) - i); }
|
constexpr Value operator-(Value v, int i) { return Value(int(v) - i); }
|
||||||
inline Value& operator+=(Value& v, int i) { return v = v + i; }
|
inline Value& operator+=(Value& v, int i) { return v = v + i; }
|
||||||
inline Value& operator-=(Value& v, int i) { return v = v - i; }
|
inline Value& operator-=(Value& v, int i) { return v = v - i; }
|
||||||
|
|
||||||
|
/// Additional operators to add a Direction to a Square
|
||||||
|
inline Square operator+(Square s, Direction d) { return Square(int(s) + int(d)); }
|
||||||
|
inline Square operator-(Square s, Direction d) { return Square(int(s) - int(d)); }
|
||||||
|
inline Square& operator+=(Square &s, Direction d) { return s = s + d; }
|
||||||
|
inline Square& operator-=(Square &s, Direction d) { return s = s - d; }
|
||||||
|
|
||||||
/// Only declared but not defined. We don't want to multiply two scores due to
|
/// Only declared but not defined. We don't want to multiply two scores due to
|
||||||
/// a very high risk of overflow. So user should explicitly convert to integer.
|
/// a very high risk of overflow. So user should explicitly convert to integer.
|
||||||
inline Score operator*(Score s1, Score s2);
|
Score operator*(Score, Score) = delete;
|
||||||
|
|
||||||
/// Division of a Score must be handled separately for each term
|
/// Division of a Score must be handled separately for each term
|
||||||
inline Score operator/(Score s, int i) {
|
inline Score operator/(Score s, int i) {
|
||||||
return make_score(mg_value(s) / i, eg_value(s) / i);
|
return make_score(mg_value(s) / i, eg_value(s) / i);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
/// Multiplication of a Score by an integer. We check for overflow in debug mode.
|
||||||
|
inline Score operator*(Score s, int i) {
|
||||||
|
|
||||||
inline Color operator~(Color c) {
|
Score result = Score(int(s) * i);
|
||||||
return Color(c ^ BLACK);
|
|
||||||
|
assert(eg_value(result) == (i * eg_value(s)));
|
||||||
|
assert(mg_value(result) == (i * mg_value(s)));
|
||||||
|
assert((i == 0) || (result / i) == s );
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square operator~(Square s) {
|
constexpr Color operator~(Color c) {
|
||||||
|
return Color(c ^ BLACK); // Toggle color
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Square operator~(Square s) {
|
||||||
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
|
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CastlingRight operator|(Color c, CastlingSide s) {
|
constexpr File operator~(File f) {
|
||||||
|
return File(f ^ FILE_H); // Horizontal flip FILE_A -> FILE_H
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Piece operator~(Piece pc) {
|
||||||
|
return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr CastlingRight operator|(Color c, CastlingSide s) {
|
||||||
return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
|
return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value mate_in(int ply) {
|
constexpr Value mate_in(int ply) {
|
||||||
return VALUE_MATE - ply;
|
return VALUE_MATE - ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value mated_in(int ply) {
|
constexpr Value mated_in(int ply) {
|
||||||
return -VALUE_MATE + ply;
|
return -VALUE_MATE + ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square make_square(File f, Rank r) {
|
constexpr Square make_square(File f, Rank r) {
|
||||||
return Square((r << 3) | f);
|
return Square((r << 3) + f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Piece make_piece(Color c, PieceType pt) {
|
constexpr Piece make_piece(Color c, PieceType pt) {
|
||||||
return Piece((c << 3) | pt);
|
return Piece((c << 3) + pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType type_of(Piece pc) {
|
constexpr PieceType type_of(Piece pc) {
|
||||||
return PieceType(pc & 7);
|
return PieceType(pc & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,27 +397,27 @@ inline Color color_of(Piece pc) {
|
|||||||
return Color(pc >> 3);
|
return Color(pc >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_ok(Square s) {
|
constexpr bool is_ok(Square s) {
|
||||||
return s >= SQ_A1 && s <= SQ_H8;
|
return s >= SQ_A1 && s <= SQ_H8;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline File file_of(Square s) {
|
constexpr File file_of(Square s) {
|
||||||
return File(s & 7);
|
return File(s & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank rank_of(Square s) {
|
constexpr Rank rank_of(Square s) {
|
||||||
return Rank(s >> 3);
|
return Rank(s >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square relative_square(Color c, Square s) {
|
constexpr Square relative_square(Color c, Square s) {
|
||||||
return Square(s ^ (c * 56));
|
return Square(s ^ (c * 56));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank relative_rank(Color c, Rank r) {
|
constexpr Rank relative_rank(Color c, Rank r) {
|
||||||
return Rank(r ^ (c * 7));
|
return Rank(r ^ (c * 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank relative_rank(Color c, Square s) {
|
constexpr Rank relative_rank(Color c, Square s) {
|
||||||
return relative_rank(c, rank_of(s));
|
return relative_rank(c, rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,36 +426,40 @@ inline bool opposite_colors(Square s1, Square s2) {
|
|||||||
return ((s >> 3) ^ s) & 1;
|
return ((s >> 3) ^ s) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square pawn_push(Color c) {
|
constexpr Direction pawn_push(Color c) {
|
||||||
return c == WHITE ? DELTA_N : DELTA_S;
|
return c == WHITE ? NORTH : SOUTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square from_sq(Move m) {
|
constexpr Square from_sq(Move m) {
|
||||||
return Square((m >> 6) & 0x3F);
|
return Square((m >> 6) & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square to_sq(Move m) {
|
constexpr Square to_sq(Move m) {
|
||||||
return Square(m & 0x3F);
|
return Square(m & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline MoveType type_of(Move m) {
|
constexpr int from_to(Move m) {
|
||||||
|
return m & 0xFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MoveType type_of(Move m) {
|
||||||
return MoveType(m & (3 << 14));
|
return MoveType(m & (3 << 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType promotion_type(Move m) {
|
constexpr PieceType promotion_type(Move m) {
|
||||||
return PieceType(((m >> 12) & 3) + KNIGHT);
|
return PieceType(((m >> 12) & 3) + KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Move make_move(Square from, Square to) {
|
inline Move make_move(Square from, Square to) {
|
||||||
return Move(to | (from << 6));
|
return Move((from << 6) + to);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<MoveType T>
|
template<MoveType T>
|
||||||
inline Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
constexpr Move make(Square from, Square to, PieceType pt = KNIGHT) {
|
||||||
return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12));
|
return Move(T + ((pt - KNIGHT) << 12) + (from << 6) + to);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_ok(Move m) {
|
constexpr bool is_ok(Move m) {
|
||||||
return from_sq(m) != to_sq(m); // Catch MOVE_NULL and MOVE_NONE
|
return from_sq(m) != to_sq(m); // Catch MOVE_NULL and MOVE_NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+84
-55
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -27,30 +28,27 @@
|
|||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
#include "tt.h"
|
||||||
#include "timeman.h"
|
#include "timeman.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
extern void benchmark(const Position& pos, istream& is);
|
extern vector<string> setup_bench(const Position&, istream&);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// FEN string of the initial position, normal chess
|
// FEN string of the initial position, normal chess
|
||||||
const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
|
|
||||||
// Stack to keep track of the position states along the setup moves (from the
|
|
||||||
// start position to the position just before the search starts). Needed by
|
|
||||||
// 'draw by repetition' detection.
|
|
||||||
Search::StateStackPtr SetupStates;
|
|
||||||
|
|
||||||
|
|
||||||
// position() is called when engine receives the "position" UCI command.
|
// position() is called when engine receives the "position" UCI command.
|
||||||
// The function sets up the position described in the given FEN string ("fen")
|
// The function sets up the position described in the given FEN string ("fen")
|
||||||
// or the starting position ("startpos") and then makes the moves given in the
|
// or the starting position ("startpos") and then makes the moves given in the
|
||||||
// following move list ("moves").
|
// following move list ("moves").
|
||||||
|
|
||||||
void position(Position& pos, istringstream& is) {
|
void position(Position& pos, istringstream& is, StateListPtr& states) {
|
||||||
|
|
||||||
Move m;
|
Move m;
|
||||||
string token, fen;
|
string token, fen;
|
||||||
@@ -68,14 +66,14 @@ namespace {
|
|||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pos.set(fen, Options["UCI_Chess960"], Threads.main());
|
states = StateListPtr(new std::deque<StateInfo>(1)); // Drop old and create a new one
|
||||||
SetupStates = Search::StateStackPtr(new std::stack<StateInfo>);
|
pos.set(fen, Options["UCI_Chess960"], &states->back(), Threads.main());
|
||||||
|
|
||||||
// Parse move list (if any)
|
// Parse move list (if any)
|
||||||
while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE)
|
while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE)
|
||||||
{
|
{
|
||||||
SetupStates->push(StateInfo());
|
states->emplace_back();
|
||||||
pos.do_move(m, SetupStates->top(), pos.gives_check(m, CheckInfo(pos)));
|
pos.do_move(m, states->back());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,10 +106,11 @@ namespace {
|
|||||||
// the thinking time and other parameters from the input string, then starts
|
// the thinking time and other parameters from the input string, then starts
|
||||||
// the search.
|
// the search.
|
||||||
|
|
||||||
void go(const Position& pos, istringstream& is) {
|
void go(Position& pos, istringstream& is, StateListPtr& states) {
|
||||||
|
|
||||||
Search::LimitsType limits;
|
Search::LimitsType limits;
|
||||||
string token;
|
string token;
|
||||||
|
bool ponderMode = false;
|
||||||
|
|
||||||
limits.startTime = now(); // As early as possible!
|
limits.startTime = now(); // As early as possible!
|
||||||
|
|
||||||
@@ -129,10 +128,53 @@ namespace {
|
|||||||
else if (token == "nodes") is >> limits.nodes;
|
else if (token == "nodes") is >> limits.nodes;
|
||||||
else if (token == "movetime") is >> limits.movetime;
|
else if (token == "movetime") is >> limits.movetime;
|
||||||
else if (token == "mate") is >> limits.mate;
|
else if (token == "mate") is >> limits.mate;
|
||||||
|
else if (token == "perft") is >> limits.perft;
|
||||||
else if (token == "infinite") limits.infinite = 1;
|
else if (token == "infinite") limits.infinite = 1;
|
||||||
else if (token == "ponder") limits.ponder = 1;
|
else if (token == "ponder") ponderMode = true;
|
||||||
|
|
||||||
Threads.start_thinking(pos, limits, SetupStates);
|
Threads.start_thinking(pos, states, limits, ponderMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// bench() is called when engine receives the "bench" command. Firstly
|
||||||
|
// a list of UCI commands is setup according to bench parameters, then
|
||||||
|
// it is run one by one printing a summary at the end.
|
||||||
|
|
||||||
|
void bench(Position& pos, istream& args, StateListPtr& states) {
|
||||||
|
|
||||||
|
string token;
|
||||||
|
uint64_t num, nodes = 0, cnt = 1;
|
||||||
|
|
||||||
|
vector<string> list = setup_bench(pos, args);
|
||||||
|
num = count_if(list.begin(), list.end(), [](string s) { return s.find("go ") == 0; });
|
||||||
|
|
||||||
|
TimePoint elapsed = now();
|
||||||
|
|
||||||
|
for (const auto& cmd : list)
|
||||||
|
{
|
||||||
|
istringstream is(cmd);
|
||||||
|
is >> skipws >> token;
|
||||||
|
|
||||||
|
if (token == "go")
|
||||||
|
{
|
||||||
|
cerr << "\nPosition: " << cnt++ << '/' << num << endl;
|
||||||
|
go(pos, is, states);
|
||||||
|
Threads.main()->wait_for_search_finished();
|
||||||
|
nodes += Threads.nodes_searched();
|
||||||
|
}
|
||||||
|
else if (token == "setoption") setoption(is);
|
||||||
|
else if (token == "position") position(pos, is, states);
|
||||||
|
else if (token == "ucinewgame") Search::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
||||||
|
|
||||||
|
dbg_print(); // Just before exiting
|
||||||
|
|
||||||
|
cerr << "\n==========================="
|
||||||
|
<< "\nTotal time (ms) : " << elapsed
|
||||||
|
<< "\nNodes searched : " << nodes
|
||||||
|
<< "\nNodes/second : " << 1000 * nodes / elapsed << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -146,8 +188,12 @@ namespace {
|
|||||||
|
|
||||||
void UCI::loop(int argc, char* argv[]) {
|
void UCI::loop(int argc, char* argv[]) {
|
||||||
|
|
||||||
Position pos(StartFEN, false, Threads.main()); // The root position
|
Position pos;
|
||||||
string token, cmd;
|
string token, cmd;
|
||||||
|
StateListPtr states(new std::deque<StateInfo>(1));
|
||||||
|
auto uiThread = std::make_shared<Thread>(0);
|
||||||
|
|
||||||
|
pos.set(StartFEN, false, &states->back(), uiThread.get());
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
cmd += std::string(argv[i]) + " ";
|
cmd += std::string(argv[i]) + " ";
|
||||||
@@ -158,61 +204,42 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
|
|
||||||
istringstream is(cmd);
|
istringstream is(cmd);
|
||||||
|
|
||||||
token.clear(); // getline() could return empty or blank line
|
token.clear(); // Avoid a stale if getline() returns empty or blank line
|
||||||
is >> skipws >> token;
|
is >> skipws >> token;
|
||||||
|
|
||||||
// The GUI sends 'ponderhit' to tell us to ponder on the same move the
|
// The GUI sends 'ponderhit' to tell us the user has played the expected move.
|
||||||
// opponent has played. In case Signals.stopOnPonderhit is set we are
|
// So 'ponderhit' will be sent if we were told to ponder on the same move the
|
||||||
// waiting for 'ponderhit' to stop the search (for instance because we
|
// user has played. We should continue searching but switch from pondering to
|
||||||
// already ran out of time), otherwise we should continue searching but
|
// normal search. In case Threads.stopOnPonderhit is set we are waiting for
|
||||||
// switching from pondering to normal search.
|
// 'ponderhit' to stop the search, for instance if max search depth is reached.
|
||||||
if ( token == "quit"
|
if ( token == "quit"
|
||||||
|| token == "stop"
|
|| token == "stop"
|
||||||
|| (token == "ponderhit" && Search::Signals.stopOnPonderhit))
|
|| (token == "ponderhit" && Threads.stopOnPonderhit))
|
||||||
{
|
Threads.stop = true;
|
||||||
Search::Signals.stop = true;
|
|
||||||
Threads.main()->start_searching(true); // Could be sleeping
|
|
||||||
}
|
|
||||||
else if (token == "ponderhit")
|
else if (token == "ponderhit")
|
||||||
Search::Limits.ponder = 0; // Switch to normal search
|
Threads.ponder = false; // Switch to normal search
|
||||||
|
|
||||||
else if (token == "uci")
|
else if (token == "uci")
|
||||||
sync_cout << "id name " << engine_info(true)
|
sync_cout << "id name " << engine_info(true)
|
||||||
<< "\n" << Options
|
<< "\n" << Options
|
||||||
<< "\nuciok" << sync_endl;
|
<< "\nuciok" << sync_endl;
|
||||||
|
|
||||||
else if (token == "ucinewgame")
|
|
||||||
{
|
|
||||||
Search::clear();
|
|
||||||
Time.availableNodes = 0;
|
|
||||||
}
|
|
||||||
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
|
||||||
else if (token == "go") go(pos, is);
|
|
||||||
else if (token == "position") position(pos, is);
|
|
||||||
else if (token == "setoption") setoption(is);
|
else if (token == "setoption") setoption(is);
|
||||||
|
else if (token == "go") go(pos, is, states);
|
||||||
|
else if (token == "position") position(pos, is, states);
|
||||||
|
else if (token == "ucinewgame") Search::clear();
|
||||||
|
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
||||||
|
|
||||||
// Additional custom non-UCI commands, useful for debugging
|
// Additional custom non-UCI commands, mainly for debugging
|
||||||
else if (token == "flip") pos.flip();
|
else if (token == "flip") pos.flip();
|
||||||
else if (token == "bench") benchmark(pos, is);
|
else if (token == "bench") bench(pos, is, states);
|
||||||
else if (token == "d") sync_cout << pos << sync_endl;
|
else if (token == "d") sync_cout << pos << sync_endl;
|
||||||
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
||||||
else if (token == "perft")
|
|
||||||
{
|
|
||||||
int depth;
|
|
||||||
stringstream ss;
|
|
||||||
|
|
||||||
is >> depth;
|
|
||||||
ss << Options["Hash"] << " "
|
|
||||||
<< Options["Threads"] << " " << depth << " current perft";
|
|
||||||
|
|
||||||
benchmark(pos, ss);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
sync_cout << "Unknown command: " << cmd << sync_endl;
|
sync_cout << "Unknown command: " << cmd << sync_endl;
|
||||||
|
|
||||||
} while (token != "quit" && argc == 1); // Passed args have one-shot behaviour
|
} while (token != "quit" && argc == 1); // Command line args are one-shot
|
||||||
|
|
||||||
Threads.main()->wait_for_search_finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -225,6 +252,8 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
|
|
||||||
string UCI::value(Value v) {
|
string UCI::value(Value v) {
|
||||||
|
|
||||||
|
assert(-VALUE_INFINITE < v && v < VALUE_INFINITE);
|
||||||
|
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
|
||||||
if (abs(v) < VALUE_MATE - MAX_PLY)
|
if (abs(v) < VALUE_MATE - MAX_PLY)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
Option(OnChange = nullptr);
|
Option(OnChange = nullptr);
|
||||||
Option(bool v, OnChange = nullptr);
|
Option(bool v, OnChange = nullptr);
|
||||||
Option(const char* v, OnChange = nullptr);
|
Option(const char* v, OnChange = nullptr);
|
||||||
Option(int v, int min, int max, OnChange = nullptr);
|
Option(int v, int minv, int maxv, OnChange = nullptr);
|
||||||
|
|
||||||
Option& operator=(const std::string&);
|
Option& operator=(const std::string&);
|
||||||
void operator<<(const Option&);
|
void operator<<(const Option&);
|
||||||
|
|||||||
+8
-7
@@ -2,7 +2,7 @@
|
|||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -39,7 +39,7 @@ namespace UCI {
|
|||||||
void on_clear_hash(const Option&) { Search::clear(); }
|
void on_clear_hash(const Option&) { Search::clear(); }
|
||||||
void on_hash_size(const Option& o) { TT.resize(o); }
|
void on_hash_size(const Option& o) { TT.resize(o); }
|
||||||
void on_logger(const Option& o) { start_logger(o); }
|
void on_logger(const Option& o) { start_logger(o); }
|
||||||
void on_threads(const Option&) { Threads.read_uci_options(); }
|
void on_threads(const Option& o) { Threads.set(o); }
|
||||||
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
||||||
|
|
||||||
|
|
||||||
@@ -55,11 +55,12 @@ bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const
|
|||||||
|
|
||||||
void init(OptionsMap& o) {
|
void init(OptionsMap& o) {
|
||||||
|
|
||||||
const int MaxHashMB = Is64Bit ? 1024 * 1024 : 2048;
|
// at most 2^32 clusters.
|
||||||
|
const int MaxHashMB = Is64Bit ? 131072 : 2048;
|
||||||
|
|
||||||
o["Write Debug Log"] << Option(false, on_logger);
|
o["Debug Log File"] << Option("", on_logger);
|
||||||
o["Contempt"] << Option(0, -100, 100);
|
o["Contempt"] << Option(20, -100, 100);
|
||||||
o["Threads"] << Option(1, 1, 128, on_threads);
|
o["Threads"] << Option(1, 1, 512, on_threads);
|
||||||
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
|
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
|
||||||
o["Clear Hash"] << Option(on_clear_hash);
|
o["Clear Hash"] << Option(on_clear_hash);
|
||||||
o["Ponder"] << Option(false);
|
o["Ponder"] << Option(false);
|
||||||
@@ -67,7 +68,7 @@ void init(OptionsMap& o) {
|
|||||||
o["Skill Level"] << Option(20, 0, 20);
|
o["Skill Level"] << Option(20, 0, 20);
|
||||||
o["Move Overhead"] << Option(30, 0, 5000);
|
o["Move Overhead"] << Option(30, 0, 5000);
|
||||||
o["Minimum Thinking Time"] << Option(20, 0, 5000);
|
o["Minimum Thinking Time"] << Option(20, 0, 5000);
|
||||||
o["Slow Mover"] << Option(84, 10, 1000);
|
o["Slow Mover"] << Option(89, 10, 1000);
|
||||||
o["nodestime"] << Option(0, 0, 10000);
|
o["nodestime"] << Option(0, 0, 10000);
|
||||||
o["UCI_Chess960"] << Option(false);
|
o["UCI_Chess960"] << Option(false);
|
||||||
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
||||||
|
|||||||
Executable
+123
@@ -0,0 +1,123 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# check for errors under valgrind or sanitizers.
|
||||||
|
|
||||||
|
error()
|
||||||
|
{
|
||||||
|
echo "instrumented testing failed on line $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
trap 'error ${LINENO}' ERR
|
||||||
|
|
||||||
|
# define suitable post and prefixes for testing options
|
||||||
|
case $1 in
|
||||||
|
--valgrind)
|
||||||
|
echo "valgrind testing started"
|
||||||
|
prefix=''
|
||||||
|
exeprefix='valgrind --error-exitcode=42'
|
||||||
|
postfix='1>/dev/null'
|
||||||
|
threads="1"
|
||||||
|
;;
|
||||||
|
--valgrind-thread)
|
||||||
|
echo "valgrind-thread testing started"
|
||||||
|
prefix=''
|
||||||
|
exeprefix='valgrind --error-exitcode=42'
|
||||||
|
postfix='1>/dev/null'
|
||||||
|
threads="2"
|
||||||
|
;;
|
||||||
|
--sanitizer-undefined)
|
||||||
|
echo "sanitizer-undefined testing started"
|
||||||
|
prefix='!'
|
||||||
|
exeprefix=''
|
||||||
|
postfix='2>&1 | grep "runtime error:"'
|
||||||
|
threads="1"
|
||||||
|
;;
|
||||||
|
--sanitizer-thread)
|
||||||
|
echo "sanitizer-thread testing started"
|
||||||
|
prefix='!'
|
||||||
|
exeprefix=''
|
||||||
|
postfix='2>&1 | grep "WARNING: ThreadSanitizer:"'
|
||||||
|
threads="2"
|
||||||
|
|
||||||
|
cat << EOF > tsan.supp
|
||||||
|
race:TTEntry::move
|
||||||
|
race:TTEntry::depth
|
||||||
|
race:TTEntry::bound
|
||||||
|
race:TTEntry::save
|
||||||
|
race:TTEntry::value
|
||||||
|
race:TTEntry::eval
|
||||||
|
|
||||||
|
race:TranspositionTable::probe
|
||||||
|
race:TranspositionTable::hashfull
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
export TSAN_OPTIONS="suppressions=./tsan.supp"
|
||||||
|
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "unknown testing started"
|
||||||
|
prefix=''
|
||||||
|
exeprefix=''
|
||||||
|
postfix=''
|
||||||
|
threads="1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# simple command line testing
|
||||||
|
for args in "eval" \
|
||||||
|
"go nodes 1000" \
|
||||||
|
"go depth 10" \
|
||||||
|
"go movetime 1000" \
|
||||||
|
"go wtime 8000 btime 8000 winc 500 binc 500" \
|
||||||
|
"bench 128 $threads 10 default depth"
|
||||||
|
do
|
||||||
|
|
||||||
|
echo "$prefix $exeprefix ./stockfish $args $postfix"
|
||||||
|
eval "$prefix $exeprefix ./stockfish $args $postfix"
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
# more general testing, following an uci protocol exchange
|
||||||
|
cat << EOF > game.exp
|
||||||
|
set timeout 10
|
||||||
|
spawn $exeprefix ./stockfish
|
||||||
|
|
||||||
|
send "uci\n"
|
||||||
|
expect "uciok"
|
||||||
|
|
||||||
|
send "setoption name Threads value $threads\n"
|
||||||
|
|
||||||
|
send "ucinewgame\n"
|
||||||
|
send "position startpos\n"
|
||||||
|
send "go nodes 1000\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "position startpos moves e2e4 e7e6\n"
|
||||||
|
send "go nodes 1000\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
|
||||||
|
send "go depth 30\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "quit\n"
|
||||||
|
expect eof
|
||||||
|
|
||||||
|
# return error code of the spawned program, useful for valgrind
|
||||||
|
lassign [wait] pid spawnid os_error_flag value
|
||||||
|
exit \$value
|
||||||
|
EOF
|
||||||
|
|
||||||
|
for exps in game.exp
|
||||||
|
do
|
||||||
|
|
||||||
|
echo "$prefix expect $exps $postfix"
|
||||||
|
eval "$prefix expect $exps $postfix"
|
||||||
|
|
||||||
|
rm $exps
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -f tsan.supp
|
||||||
|
|
||||||
|
echo "instrumented testing OK"
|
||||||
Executable
+32
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# verify perft numbers (positions from https://chessprogramming.wikispaces.com/Perft+Results)
|
||||||
|
|
||||||
|
error()
|
||||||
|
{
|
||||||
|
echo "perft testing failed on line $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
trap 'error ${LINENO}' ERR
|
||||||
|
|
||||||
|
echo "perft testing started"
|
||||||
|
|
||||||
|
cat << EOF > perft.exp
|
||||||
|
set timeout 10
|
||||||
|
lassign \$argv pos depth result
|
||||||
|
spawn ./stockfish
|
||||||
|
send "position \$pos\\ngo perft \$depth\\n"
|
||||||
|
expect "Nodes searched? \$result" {} timeout {exit 1}
|
||||||
|
send "quit\\n"
|
||||||
|
expect eof
|
||||||
|
EOF
|
||||||
|
|
||||||
|
expect perft.exp startpos 5 4865609 > /dev/null
|
||||||
|
expect perft.exp "fen r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -" 5 193690690 > /dev/null
|
||||||
|
expect perft.exp "fen 8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -" 6 11030083 > /dev/null
|
||||||
|
expect perft.exp "fen r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1" 5 15833292 > /dev/null
|
||||||
|
expect perft.exp "fen rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8" 5 89941194 > /dev/null
|
||||||
|
expect perft.exp "fen r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10" 5 164075551 > /dev/null
|
||||||
|
|
||||||
|
rm perft.exp
|
||||||
|
|
||||||
|
echo "perft testing OK"
|
||||||
Executable
+61
@@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# verify reproducible search
|
||||||
|
|
||||||
|
error()
|
||||||
|
{
|
||||||
|
echo "reprosearch testing failed on line $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
trap 'error ${LINENO}' ERR
|
||||||
|
|
||||||
|
echo "reprosearch testing started"
|
||||||
|
|
||||||
|
# repeat two short games, separated by ucinewgame.
|
||||||
|
# with go nodes $nodes they should result in exactly
|
||||||
|
# the same node count for each iteration.
|
||||||
|
cat << EOF > repeat.exp
|
||||||
|
set timeout 10
|
||||||
|
spawn ./stockfish
|
||||||
|
lassign \$argv nodes
|
||||||
|
|
||||||
|
send "uci\n"
|
||||||
|
expect "uciok"
|
||||||
|
|
||||||
|
send "ucinewgame\n"
|
||||||
|
send "position startpos\n"
|
||||||
|
send "go nodes \$nodes\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "position startpos moves e2e4 e7e6\n"
|
||||||
|
send "go nodes \$nodes\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "ucinewgame\n"
|
||||||
|
send "position startpos\n"
|
||||||
|
send "go nodes \$nodes\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "position startpos moves e2e4 e7e6\n"
|
||||||
|
send "go nodes \$nodes\n"
|
||||||
|
expect "bestmove"
|
||||||
|
|
||||||
|
send "quit\n"
|
||||||
|
expect eof
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# to increase the likelyhood of finding a non-reproducible case,
|
||||||
|
# the allowed number of nodes are varied systematically
|
||||||
|
for i in `seq 1 20`
|
||||||
|
do
|
||||||
|
|
||||||
|
nodes=$((100*3**i/2**i))
|
||||||
|
echo "reprosearch testing with $nodes nodes"
|
||||||
|
|
||||||
|
# each line should appear exactly an even number of times
|
||||||
|
expect repeat.exp $nodes 2>&1 | grep -o "nodes [0-9]*" | sort | uniq -c | awk '{if ($1%2!=0) exit(1)}'
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
rm repeat.exp
|
||||||
|
|
||||||
|
echo "reprosearch testing OK"
|
||||||
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# obtain and optionally verify Bench / signature
|
||||||
|
# if no reference is given, the output is deliberately limited to just the signature
|
||||||
|
|
||||||
|
error()
|
||||||
|
{
|
||||||
|
echo "running bench for signature failed on line $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
trap 'error ${LINENO}' ERR
|
||||||
|
|
||||||
|
# obtain
|
||||||
|
|
||||||
|
signature=`./stockfish bench 2>&1 | grep "Nodes searched : " | awk '{print $4}'`
|
||||||
|
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
# compare to given reference
|
||||||
|
if [ "$1" != "$signature" ]; then
|
||||||
|
echo "signature mismatch: reference $1 obtained $signature"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "signature OK: $signature"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# just report signature
|
||||||
|
echo $signature
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user