mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-24 02:57:11 +08:00
Compare commits
155 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aaa07fb161 | ||
|
|
1361ba75cb | ||
|
|
da9c423989 | ||
|
|
3713bb26ef | ||
|
|
cff9ff2198 | ||
|
|
a6c6037813 | ||
|
|
e677185567 | ||
|
|
237dd331d5 | ||
|
|
98c8a83bb8 | ||
|
|
73be819426 | ||
|
|
2940abdac8 | ||
|
|
fa0bffeafa | ||
|
|
d56345c9ae | ||
|
|
60e23693f0 | ||
|
|
91f0c08789 | ||
|
|
6bf22f354f | ||
|
|
48b74142ef | ||
|
|
dcb323bf0d | ||
|
|
44cb792c76 | ||
|
|
e68e135771 | ||
|
|
46141b078c | ||
|
|
02fd34a5e8 | ||
|
|
20cac227bb | ||
|
|
4346445be3 | ||
|
|
21850536d5 | ||
|
|
0179a32cf5 | ||
|
|
8487069058 | ||
|
|
43ca5c926d | ||
|
|
aed542d74c | ||
|
|
aaffcf973e | ||
|
|
746bcb348f | ||
|
|
a7cb05b1eb | ||
|
|
9741694fca | ||
|
|
e145c0d3e2 | ||
|
|
24cc3a97a4 | ||
|
|
e4277c06bf | ||
|
|
dd80b9abaf | ||
|
|
84d6fe0f31 | ||
|
|
6845397c5c | ||
|
|
f74f42b298 | ||
|
|
0e0adfe2e1 | ||
|
|
049139d025 | ||
|
|
62a8f393f1 | ||
|
|
c5f44ef45b | ||
|
|
7c55b0e880 | ||
|
|
77ac1e7953 | ||
|
|
cddda7cd19 | ||
|
|
c81010a878 | ||
|
|
6709b01903 | ||
|
|
3863cd191c | ||
|
|
f205fe1fe5 | ||
|
|
9f28d8a854 | ||
|
|
76bed11f7b | ||
|
|
e33c94883f | ||
|
|
46ffea46ea | ||
|
|
03d6a86900 | ||
|
|
17c5119222 | ||
|
|
cf71efc34b | ||
|
|
c9d364f9ca | ||
|
|
97dd7568ed | ||
|
|
af220cfd52 | ||
|
|
1130c8d815 | ||
|
|
607ac0687a | ||
|
|
e9de96f0e4 | ||
|
|
9ab84a8165 | ||
|
|
ac65b14d30 | ||
|
|
9e4befe3f1 | ||
|
|
6cf28d4aa7 | ||
|
|
129cde008c | ||
|
|
b088f0aefd | ||
|
|
a5d699d62f | ||
|
|
f6d2452916 | ||
|
|
268c53ac51 | ||
|
|
595a90dfd0 | ||
|
|
e217407450 | ||
|
|
2078878376 | ||
|
|
d1d4437699 | ||
|
|
ba04eb0446 | ||
|
|
ed347e7cbd | ||
|
|
95af1e28be | ||
|
|
e9aa20ad13 | ||
|
|
e01fefbbaf | ||
|
|
e4fc957898 | ||
|
|
693b38a5e7 | ||
|
|
fbec55e52e | ||
|
|
05e70d6740 | ||
|
|
b4cb1a3a9e | ||
|
|
ec14fb1b33 | ||
|
|
cb506d3b16 | ||
|
|
e0c47a6ceb | ||
|
|
f3d0b76feb | ||
|
|
bfd4421f49 | ||
|
|
fd12e8cb23 | ||
|
|
166c09a7a0 | ||
|
|
8d369600ec | ||
|
|
f4140ecc0c | ||
|
|
60b5da4cc8 | ||
|
|
55c46b2399 | ||
|
|
76ae0e36be | ||
|
|
4251eac860 | ||
|
|
cd4604b05c | ||
|
|
e6863f46de | ||
|
|
6f1475b6fc | ||
|
|
4a777954e1 | ||
|
|
54382f8b07 | ||
|
|
339bb8a524 | ||
|
|
aa925a0e29 | ||
|
|
23ceb66950 | ||
|
|
565d12bf42 | ||
|
|
00eab73399 | ||
|
|
5be3d98d17 | ||
|
|
5b3fcab1ad | ||
|
|
977ca40d6d | ||
|
|
ae49677446 | ||
|
|
2fff532f4e | ||
|
|
da854fe83a | ||
|
|
a1096e55cf | ||
|
|
dad632ce5b | ||
|
|
2f7723fd44 | ||
|
|
152f3b13b7 | ||
|
|
bb1b049b83 | ||
|
|
50f92bed06 | ||
|
|
bdb586ac2b | ||
|
|
1b0303b6e9 | ||
|
|
5f232e0667 | ||
|
|
080a4995a3 | ||
|
|
20224a5bbf | ||
|
|
8654fee18c | ||
|
|
8b45b60327 | ||
|
|
044ad593b3 | ||
|
|
5600d91cff | ||
|
|
1cc44bcaae | ||
|
|
15eb59683e | ||
|
|
620cfbb676 | ||
|
|
fe523b2d18 | ||
|
|
2a203d8d6f | ||
|
|
b8326edea3 | ||
|
|
20e8738901 | ||
|
|
b3b1d3aaa7 | ||
|
|
0d69ac33ff | ||
|
|
342c8c883c | ||
|
|
297c12e595 | ||
|
|
5c20f59788 | ||
|
|
ea06200423 | ||
|
|
3849beb979 | ||
|
|
20ed03fc0b | ||
|
|
2a461b4b74 | ||
|
|
6f39a3fc80 | ||
|
|
7eefc1f6cc | ||
|
|
7622793080 | ||
|
|
174b40c28d | ||
|
|
03f524c591 | ||
|
|
3444b94735 | ||
|
|
2693db616d | ||
|
|
a5fce1958b |
@@ -14,7 +14,9 @@ number of CPUs on your computer and set the number of search threads
|
||||
accordingly, but please be aware that the detection is not always
|
||||
correct. It is therefore recommended to inspect the value of the
|
||||
"Threads" UCI parameter, and to make sure it equals the number of CPU
|
||||
cores on your computer.
|
||||
cores on your computer. If you are using more than four threads, it
|
||||
is recommended to raise the value of "Minimum Split Depth" UCI parameter
|
||||
to 6.
|
||||
|
||||
|
||||
2. Files
|
||||
|
||||
325
src/Makefile
325
src/Makefile
@@ -18,133 +18,246 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
###
|
||||
### Files
|
||||
###
|
||||
|
||||
### Executable name. Do not change
|
||||
EXE = stockfish
|
||||
|
||||
|
||||
### ==========================================================================
|
||||
### Compiler speed switches for both GCC and ICC. These settings are generally
|
||||
### fast on a broad range of systems, but may be changed experimentally
|
||||
### ==========================================================================
|
||||
GCCFLAGS = -O3 -msse
|
||||
ICCFLAGS = -fast -msse
|
||||
ICCFLAGS-OSX = -fast -mdynamic-no-pic
|
||||
|
||||
|
||||
### ==========================================================================
|
||||
### Enable/disable debugging, disabled by default
|
||||
### ==========================================================================
|
||||
GCCFLAGS += -DNDEBUG
|
||||
ICCFLAGS += -DNDEBUG
|
||||
ICCFLAGS-OSX += -DNDEBUG
|
||||
|
||||
|
||||
### ==========================================================================
|
||||
### Run built-in benchmark for pgo-builds with: 32MB hash 1 thread 10 depth
|
||||
### These settings are generally fast, but may be changed experimentally
|
||||
### ==========================================================================
|
||||
PGOBENCH = ./$(EXE) bench 32 1 10 default depth
|
||||
|
||||
|
||||
### General compiler settings. Do not change
|
||||
GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing
|
||||
ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -wd383,869,981,10187,10188,11505,11503
|
||||
ICCFLAGS-OSX += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -wd383,869,981,10187,10188,11505,11503
|
||||
|
||||
|
||||
### General linker settings. Do not change
|
||||
LDFLAGS = -lpthread
|
||||
|
||||
|
||||
### Object files. Do not change
|
||||
OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
|
||||
misc.o move.o movegen.o history.o movepick.o search.o piece.o \
|
||||
position.o direction.o tt.o value.o uci.o ucioption.o \
|
||||
mersenne.o book.o bitbase.o san.o benchmark.o
|
||||
|
||||
|
||||
###
|
||||
### Rules
|
||||
###
|
||||
### General rules. Do not change
|
||||
default:
|
||||
$(MAKE) gcc
|
||||
|
||||
help:
|
||||
@echo ""
|
||||
@echo "Makefile options:"
|
||||
@echo ""
|
||||
@echo "make > Default: Compiler = g++"
|
||||
@echo "make icc > Compiler = icpc"
|
||||
@echo "make icc-profile > Compiler = icpc + automatic pgo-build"
|
||||
@echo "make osx-ppc32 > PPC-Mac OS X 32 bit. Compiler = g++"
|
||||
@echo "make osx-ppc64 > PPC-Mac OS X 64 bit. Compiler = g++"
|
||||
@echo "make osx-x86 > x86-Mac OS X 32 bit. Compiler = g++"
|
||||
@echo "make osx-x86_64 > x86-Mac OS X 64 bit. Compiler = g++"
|
||||
@echo "make osx-icc32 > x86-Mac OS X 32 bit. Compiler = icpc"
|
||||
@echo "make osx-icc64 > x86-Mac OS X 64 bit. Compiler = icpc"
|
||||
@echo "make osx-icc32-profile > OSX 32 bit. Compiler = icpc + automatic pgo-build"
|
||||
@echo "make osx-icc64-profile > OSX 64 bit. Compiler = icpc + automatic pgo-build"
|
||||
@echo "make strip > Strip executable"
|
||||
@echo "make clean > Clean up"
|
||||
@echo ""
|
||||
|
||||
all: $(EXE) .depend
|
||||
|
||||
clean:
|
||||
$(RM) *.o .depend stockfish
|
||||
$(RM) *.o .depend *~ $(EXE)
|
||||
|
||||
|
||||
###
|
||||
### Compiler:
|
||||
###
|
||||
### Possible targets. You may add your own ones here
|
||||
gcc:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
all
|
||||
|
||||
CXX = g++
|
||||
# CXX = icpc
|
||||
icc:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS)" \
|
||||
all
|
||||
|
||||
icc-profile-make:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS)" \
|
||||
CXXFLAGS+='-prof-gen=srcpos -prof_dir ./profdir' \
|
||||
all
|
||||
|
||||
icc-profile-use:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS)" \
|
||||
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
||||
all
|
||||
|
||||
icc-profile:
|
||||
@rm -rf profdir
|
||||
@mkdir profdir
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) icc-profile-make
|
||||
@echo ""
|
||||
@echo "Running benchmark for pgo-build ..."
|
||||
@$(PGOBENCH) > /dev/null
|
||||
@echo "Benchmark finished. Build final executable now ..."
|
||||
@echo ""
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) icc-profile-use
|
||||
@rm -rf profdir bench.txt
|
||||
|
||||
osx-ppc32:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
CXXFLAGS+='-arch ppc' \
|
||||
LDFLAGS+='-arch ppc' \
|
||||
all
|
||||
|
||||
osx-ppc64:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
CXXFLAGS+='-arch ppc64' \
|
||||
LDFLAGS+='-arch ppc64' \
|
||||
all
|
||||
|
||||
osx-x86:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
CXXFLAGS+='-arch i386' \
|
||||
LDFLAGS+='-arch i386' \
|
||||
all
|
||||
|
||||
osx-x86_64:
|
||||
$(MAKE) \
|
||||
CXX='g++' \
|
||||
CXXFLAGS="$(GCCFLAGS)" \
|
||||
CXXFLAGS+='-arch x86_64' \
|
||||
LDFLAGS+='-arch x86_64' \
|
||||
all
|
||||
|
||||
osx-icc32:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||
CXXFLAGS+='-arch i386' \
|
||||
LDFLAGS+='-arch i386' \
|
||||
all
|
||||
|
||||
osx-icc64:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||
CXXFLAGS+='-arch x86_64' \
|
||||
LDFLAGS+='-arch x86_64' \
|
||||
all
|
||||
|
||||
osx-icc32-profile-make:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||
CXXFLAGS+='-arch i386' \
|
||||
CXXFLAGS+='-prof_gen -prof_dir ./profdir' \
|
||||
LDFLAGS+='-arch i386' \
|
||||
all
|
||||
|
||||
osx-icc32-profile-use:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||
CXXFLAGS+='-arch i386' \
|
||||
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
||||
LDFLAGS+='-arch i386' \
|
||||
all
|
||||
|
||||
osx-icc32-profile:
|
||||
@rm -rf profdir
|
||||
@mkdir profdir
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) osx-icc32-profile-make
|
||||
@echo ""
|
||||
@echo "Running benchmark for pgo-build ..."
|
||||
@$(PGOBENCH) > /dev/null
|
||||
@echo "Benchmark finished. Build final executable now ..."
|
||||
@echo ""
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) osx-icc32-profile-use
|
||||
@rm -rf profdir bench.txt
|
||||
|
||||
osx-icc64-profile-make:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||
CXXFLAGS+='-arch x86_64' \
|
||||
CXXFLAGS+='-prof_gen -prof_dir ./profdir' \
|
||||
LDFLAGS+='-arch x86_64' \
|
||||
all
|
||||
|
||||
osx-icc64-profile-use:
|
||||
$(MAKE) \
|
||||
CXX='icpc' \
|
||||
CXXFLAGS="$(ICCFLAGS-OSX)" \
|
||||
CXXFLAGS+='-arch x86_64' \
|
||||
CXXFLAGS+='-prof_use -prof_dir ./profdir' \
|
||||
LDFLAGS+='-arch x86_64' \
|
||||
all
|
||||
|
||||
osx-icc64-profile:
|
||||
@rm -rf profdir
|
||||
@mkdir profdir
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) osx-icc64-profile-make
|
||||
@echo ""
|
||||
@echo "Running benchmark for pgo-build ..."
|
||||
@$(PGOBENCH) > /dev/null
|
||||
@echo "Benchmark finished. Build final executable now ..."
|
||||
@echo ""
|
||||
@touch *.cpp *.h
|
||||
$(MAKE) osx-icc64-profile-use
|
||||
@rm -rf profdir bench.txt
|
||||
|
||||
|
||||
###
|
||||
### Dependencies
|
||||
###
|
||||
|
||||
strip:
|
||||
strip $(EXE)
|
||||
|
||||
|
||||
### Compilation. Do not change
|
||||
$(EXE): $(OBJS)
|
||||
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
||||
|
||||
|
||||
### Dependencies. Do not change
|
||||
.depend:
|
||||
$(CXX) -MM $(OBJS:.o=.cpp) > $@
|
||||
$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@
|
||||
|
||||
include .depend
|
||||
|
||||
|
||||
###
|
||||
### Compiler and linker switches
|
||||
###
|
||||
|
||||
# Enable/disable debugging, disabled by default
|
||||
|
||||
CXXFLAGS += -DNDEBUG
|
||||
|
||||
|
||||
# Compile with full warnings, and symbol names stripped, you can use
|
||||
# -g instead of -s to compile symbol's table in, useful for debugging.
|
||||
|
||||
CXXFLAGS += -Wall -s
|
||||
|
||||
|
||||
# General optimization flags. Note that -O2 might be faster than -O3 on some
|
||||
# systems; this requires testing.
|
||||
|
||||
CXXFLAGS += -O3 -fno-exceptions -fno-rtti -fno-strict-aliasing
|
||||
|
||||
# Disable most annoying warnings for the Intel C++ compiler
|
||||
|
||||
# CXXFLAGS += -wd383,869,981
|
||||
|
||||
|
||||
# Compiler optimization flags for the Intel C++ compiler in Mac OS X:
|
||||
|
||||
# CXXFLAGS += -mdynamic-no-pic -no-prec-div -ipo -static -xP
|
||||
|
||||
|
||||
# Profiler guided optimization with the Intel C++ compiler v11. To use it, first
|
||||
# create the directory ./profdata if it does not already exist, and delete its
|
||||
# contents if it does exist. Then compile with -prof_gen, and run the
|
||||
# resulting binary for a while (for instance, do ./stockfish bench 128 1, and
|
||||
# wait 15 minutes for the benchmark to complete). Then do a 'make clean', and
|
||||
# recompile with -prof_use.
|
||||
|
||||
# CXXFLAGS += -prof-gen -prof-dir./profdata
|
||||
# CXXFLAGS += -prof-use -ipo -prof_dir./profdata
|
||||
|
||||
|
||||
# Profiler guided optimization with GCC. I've never been able to make this
|
||||
# work.
|
||||
|
||||
# CXXFLAGS += -fprofile-generate
|
||||
# LDFLAGS += -fprofile-generate
|
||||
# CXXFLAGS += -fprofile-use
|
||||
# CXXFLAGS += -fprofile-use
|
||||
|
||||
|
||||
# General linker flags
|
||||
|
||||
LDFLAGS += -lm -lpthread
|
||||
|
||||
|
||||
# Compiler switches for generating binaries for various CPUs in Mac OS X.
|
||||
# Note that 'arch ppc' and 'arch ppc64' only works with g++, and not with
|
||||
# the intel compiler.
|
||||
|
||||
# CXXFLAGS += -arch ppc
|
||||
# CXXFLAGS += -arch ppc64
|
||||
# CXXFLAGS += -arch i386
|
||||
# CXXFLAGS += -arch x86_64
|
||||
# LDFLAGS += -arch ppc
|
||||
# LDFLAGS += -arch ppc64
|
||||
# LDFLAGS += -arch i386
|
||||
# LDFLAGS += -arch x86_64
|
||||
|
||||
|
||||
# Backwards compatibility with Mac OS X 10.4 when compiling under 10.5 with
|
||||
# GCC 4.0. I haven't found a way to make it work with GCC 4.2.
|
||||
|
||||
# CXXFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
|
||||
# CXXFLAGS += -mmacosx-version-min=10.4
|
||||
# LDFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
|
||||
# LDFLAGS += -Wl,-syslibroot /Developer/SDKs/MacOSX10.4u.sdk
|
||||
# LDFLAGS += -mmacosx-version-min=10.4
|
||||
|
||||
|
||||
# Backwards compatibility with Mac OS X 10.4 when compiling with ICC. Doesn't
|
||||
# work yet. :-(
|
||||
|
||||
# CXXFLAGS += -DMAC_OS_X_VERSION_MIN_REQUIRED=1040
|
||||
# CXXFLAGS += -DMAC_OS_X_VERSION_MAX_ALLOWED=1040
|
||||
# CXXFLAGS += -D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1040
|
||||
# CXXFLAGS += -F/Developer/SDKs/MacOSX10.4u.sdk/
|
||||
# LDFLAGS += -Wl,-syslibroot -Wl,/Developer/SDKs/MacOSX10.4u.sdk
|
||||
|
||||
@@ -47,7 +47,6 @@ Application::Application() {
|
||||
init_uci_options();
|
||||
Position::init_zobrist();
|
||||
Position::init_piece_square_tables();
|
||||
MovePicker::init_phase_table();
|
||||
init_eval(1);
|
||||
init_bitbases();
|
||||
init_threads();
|
||||
@@ -65,13 +64,9 @@ Application::~Application() {
|
||||
|
||||
void Application::initialize() {
|
||||
|
||||
instance();
|
||||
}
|
||||
|
||||
Application& Application::instance() {
|
||||
|
||||
// A static Application object is allocated
|
||||
// once only when this function is called.
|
||||
static Application singleton;
|
||||
return singleton;
|
||||
}
|
||||
|
||||
void Application::exit_with_failure() {
|
||||
|
||||
@@ -29,18 +29,11 @@ class Application {
|
||||
|
||||
Application();
|
||||
Application(const Application&);
|
||||
~Application();
|
||||
|
||||
public:
|
||||
static void initialize();
|
||||
static void exit_with_failure();
|
||||
|
||||
~Application();
|
||||
|
||||
private:
|
||||
static Application& instance();
|
||||
|
||||
void init();
|
||||
void deallocateAll();
|
||||
};
|
||||
|
||||
#endif // !defined(APPLICATION_H_INCLUDED)
|
||||
|
||||
@@ -163,6 +163,53 @@ const int RShift[64] = {
|
||||
|
||||
#endif // defined(IS_64BIT)
|
||||
|
||||
const Bitboard SquaresByColorBB[2] = { BlackSquaresBB, WhiteSquaresBB };
|
||||
|
||||
const Bitboard FileBB[8] = {
|
||||
FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
|
||||
};
|
||||
|
||||
const Bitboard NeighboringFilesBB[8] = {
|
||||
FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB,
|
||||
FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB
|
||||
};
|
||||
|
||||
const Bitboard ThisAndNeighboringFilesBB[8] = {
|
||||
FileABB|FileBBB, FileABB|FileBBB|FileCBB,
|
||||
FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB,
|
||||
FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB,
|
||||
FileFBB|FileGBB|FileHBB, FileGBB|FileHBB
|
||||
};
|
||||
|
||||
const Bitboard RankBB[8] = {
|
||||
Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
|
||||
};
|
||||
|
||||
const Bitboard RelativeRankBB[2][8] = {
|
||||
{ Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB },
|
||||
{ Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB }
|
||||
};
|
||||
|
||||
const Bitboard InFrontBB[2][8] = {
|
||||
{ Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank7BB | Rank8BB,
|
||||
Rank8BB,
|
||||
EmptyBoardBB
|
||||
},
|
||||
{ EmptyBoardBB,
|
||||
Rank1BB,
|
||||
Rank2BB | Rank1BB,
|
||||
Rank3BB | Rank2BB | Rank1BB,
|
||||
Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||
Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||
Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||
Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB
|
||||
}
|
||||
};
|
||||
|
||||
Bitboard RMask[64];
|
||||
int RAttackIndex[64];
|
||||
@@ -186,6 +233,8 @@ Bitboard BishopPseudoAttacks[64];
|
||||
Bitboard RookPseudoAttacks[64];
|
||||
Bitboard QueenPseudoAttacks[64];
|
||||
|
||||
uint8_t BitCount8Bit[256];
|
||||
|
||||
|
||||
////
|
||||
//// Local definitions
|
||||
@@ -248,6 +297,7 @@ void init_bitboards() {
|
||||
|
||||
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
||||
|
||||
CACHE_LINE_ALIGNMENT
|
||||
static const int BitTable[64] = {
|
||||
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15,
|
||||
46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39,
|
||||
@@ -267,6 +317,7 @@ Square pop_1st_bit(Bitboard* b) {
|
||||
|
||||
#elif !defined(USE_BSFQ)
|
||||
|
||||
CACHE_LINE_ALIGNMENT
|
||||
static const int BitTable[64] = {
|
||||
63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
|
||||
51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52,
|
||||
@@ -294,23 +345,17 @@ union b_union {
|
||||
Square pop_1st_bit(Bitboard* bb) {
|
||||
|
||||
b_union u;
|
||||
uint32_t b;
|
||||
|
||||
u.b = *bb;
|
||||
|
||||
if (u.dw.l)
|
||||
{
|
||||
b = u.dw.l;
|
||||
*((uint32_t*)bb) = b & (b - 1);
|
||||
b ^= (b - 1);
|
||||
*((uint32_t*)bb) = u.dw.l & (u.dw.l - 1);
|
||||
return Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||
}
|
||||
else
|
||||
{
|
||||
b = u.dw.h;
|
||||
*((uint32_t*)bb+1) = b & (b - 1); // Little endian only?
|
||||
b = ~(b ^ (b - 1));
|
||||
}
|
||||
return Square(BitTable[(b * 0x783a9b23) >> 26]);
|
||||
|
||||
*((uint32_t*)bb+1) = u.dw.h & (u.dw.h - 1); // Little endian only?
|
||||
return Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -335,6 +380,9 @@ namespace {
|
||||
in_front_bb(c, s) & this_and_neighboring_files_bb(s);
|
||||
OutpostMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
||||
}
|
||||
|
||||
for (Bitboard b = 0ULL; b < 256ULL; b++)
|
||||
BitCount8Bit[b] = (uint8_t)count_1s(b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ const Bitboard EmptyBoardBB = 0ULL;
|
||||
|
||||
const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL;
|
||||
const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL;
|
||||
const Bitboard SquaresByColorBB[2] = { BlackSquaresBB, WhiteSquaresBB };
|
||||
|
||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
||||
const Bitboard FileBBB = 0x0202020202020202ULL;
|
||||
@@ -51,22 +50,6 @@ const Bitboard FileFBB = 0x2020202020202020ULL;
|
||||
const Bitboard FileGBB = 0x4040404040404040ULL;
|
||||
const Bitboard FileHBB = 0x8080808080808080ULL;
|
||||
|
||||
const Bitboard FileBB[8] = {
|
||||
FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
|
||||
};
|
||||
|
||||
const Bitboard NeighboringFilesBB[8] = {
|
||||
FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB,
|
||||
FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB
|
||||
};
|
||||
|
||||
const Bitboard ThisAndNeighboringFilesBB[8] = {
|
||||
FileABB|FileBBB, FileABB|FileBBB|FileCBB,
|
||||
FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB,
|
||||
FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB,
|
||||
FileFBB|FileGBB|FileHBB, FileGBB|FileHBB
|
||||
};
|
||||
|
||||
const Bitboard Rank1BB = 0xFFULL;
|
||||
const Bitboard Rank2BB = 0xFF00ULL;
|
||||
const Bitboard Rank3BB = 0xFF0000ULL;
|
||||
@@ -76,35 +59,13 @@ const Bitboard Rank6BB = 0xFF0000000000ULL;
|
||||
const Bitboard Rank7BB = 0xFF000000000000ULL;
|
||||
const Bitboard Rank8BB = 0xFF00000000000000ULL;
|
||||
|
||||
const Bitboard RankBB[8] = {
|
||||
Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
|
||||
};
|
||||
|
||||
const Bitboard RelativeRankBB[2][8] = {
|
||||
{ Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB },
|
||||
{ Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB }
|
||||
};
|
||||
|
||||
const Bitboard InFrontBB[2][8] = {
|
||||
{ Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank5BB | Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank6BB | Rank7BB | Rank8BB,
|
||||
Rank7BB | Rank8BB,
|
||||
Rank8BB,
|
||||
EmptyBoardBB
|
||||
},
|
||||
{ EmptyBoardBB,
|
||||
Rank1BB,
|
||||
Rank2BB | Rank1BB,
|
||||
Rank3BB | Rank2BB | Rank1BB,
|
||||
Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||
Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||
Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
|
||||
Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB
|
||||
}
|
||||
};
|
||||
extern const Bitboard SquaresByColorBB[2];
|
||||
extern const Bitboard FileBB[8];
|
||||
extern const Bitboard NeighboringFilesBB[8];
|
||||
extern const Bitboard ThisAndNeighboringFilesBB[8];
|
||||
extern const Bitboard RankBB[8];
|
||||
extern const Bitboard RelativeRankBB[2][8];
|
||||
extern const Bitboard InFrontBB[2][8];
|
||||
|
||||
extern Bitboard SetMaskBB[65];
|
||||
extern Bitboard ClearMaskBB[65];
|
||||
@@ -132,6 +93,8 @@ extern Bitboard BishopPseudoAttacks[64];
|
||||
extern Bitboard RookPseudoAttacks[64];
|
||||
extern Bitboard QueenPseudoAttacks[64];
|
||||
|
||||
extern uint8_t BitCount8Bit[256];
|
||||
|
||||
|
||||
////
|
||||
//// Inline functions
|
||||
@@ -360,13 +323,13 @@ inline Bitboard isolated_pawn_mask(Square s) {
|
||||
|
||||
#if defined(USE_BSFQ) // Assembly code by Heinz van Saanen
|
||||
|
||||
inline Square __attribute__((always_inline)) first_1(Bitboard b) {
|
||||
inline Square first_1(Bitboard b) {
|
||||
Bitboard dummy;
|
||||
__asm__("bsfq %1, %0": "=r"(dummy): "rm"(b) );
|
||||
return (Square)(dummy);
|
||||
}
|
||||
|
||||
inline Square __attribute__((always_inline)) pop_1st_bit(Bitboard* b) {
|
||||
inline Square pop_1st_bit(Bitboard* b) {
|
||||
const Square s = first_1(*b);
|
||||
*b &= ~(1ULL<<s);
|
||||
return s;
|
||||
|
||||
10
src/book.cpp
10
src/book.cpp
@@ -429,11 +429,11 @@ Move Book::get_move(const Position& pos) {
|
||||
if (!bookMove)
|
||||
return MOVE_NONE;
|
||||
|
||||
MoveStack moves[256];
|
||||
int n = generate_legal_moves(pos, moves);
|
||||
for (int j = 0; j < n; j++)
|
||||
if ((int(moves[j].move) & 07777) == bookMove)
|
||||
return moves[j].move;
|
||||
MoveStack mlist[256];
|
||||
MoveStack* last = generate_moves(pos, mlist);
|
||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
||||
if ((int(cur->move) & 07777) == bookMove)
|
||||
return cur->move;
|
||||
|
||||
return MOVE_NONE;
|
||||
}
|
||||
|
||||
@@ -29,41 +29,6 @@
|
||||
#include "endgame.h"
|
||||
|
||||
|
||||
////
|
||||
//// Constants and variables
|
||||
////
|
||||
|
||||
/// Evaluation functions
|
||||
|
||||
// Generic "mate lone king" eval
|
||||
EvaluationFunction<KXK> EvaluateKXK(WHITE), EvaluateKKX(BLACK);
|
||||
|
||||
// K and two minors vs K and one or two minors
|
||||
EvaluationFunction<KmmKm> EvaluateKmmKm(WHITE);
|
||||
|
||||
EvaluationFunction<KBNK> EvaluateKBNK(WHITE), EvaluateKKBN(BLACK); // KBN vs K
|
||||
EvaluationFunction<KPK> EvaluateKPK(WHITE), EvaluateKKP(BLACK); // KP vs K
|
||||
EvaluationFunction<KRKP> EvaluateKRKP(WHITE), EvaluateKPKR(BLACK); // KR vs KP
|
||||
EvaluationFunction<KRKB> EvaluateKRKB(WHITE), EvaluateKBKR(BLACK); // KR vs KB
|
||||
EvaluationFunction<KRKN> EvaluateKRKN(WHITE), EvaluateKNKR(BLACK); // KR vs KN
|
||||
EvaluationFunction<KQKR> EvaluateKQKR(WHITE), EvaluateKRKQ(BLACK); // KQ vs KR
|
||||
EvaluationFunction<KBBKN> EvaluateKBBKN(WHITE), EvaluateKNKBB(BLACK); // KBB vs KN
|
||||
|
||||
|
||||
/// Scaling functions
|
||||
|
||||
ScalingFunction<KBPK> ScaleKBPK(WHITE), ScaleKKBP(BLACK); // KBP vs K
|
||||
ScalingFunction<KQKRP> ScaleKQKRP(WHITE), ScaleKRPKQ(BLACK); // KQ vs KRP
|
||||
ScalingFunction<KRPKR> ScaleKRPKR(WHITE), ScaleKRKRP(BLACK); // KRP vs KR
|
||||
ScalingFunction<KRPPKRP> ScaleKRPPKRP(WHITE), ScaleKRPKRPP(BLACK); // KRPP vs KRP
|
||||
ScalingFunction<KPsK> ScaleKPsK(WHITE), ScaleKKPs(BLACK); // King and pawns vs king
|
||||
ScalingFunction<KBPKB> ScaleKBPKB(WHITE), ScaleKBKBP(BLACK); // KBP vs KB
|
||||
ScalingFunction<KBPPKB> ScaleKBPPKB(WHITE), ScaleKBKBPP(BLACK); // KBPP vs KB
|
||||
ScalingFunction<KBPKN> ScaleKBPKN(WHITE), ScaleKNKBP(BLACK); // KBP vs KN
|
||||
ScalingFunction<KNPK> ScaleKNPK(WHITE), ScaleKKNP(BLACK); // KNP vs K
|
||||
ScalingFunction<KPKP> ScaleKPKPw(WHITE), ScaleKPKPb(BLACK); // KPKP
|
||||
|
||||
|
||||
////
|
||||
//// Local definitions
|
||||
////
|
||||
@@ -364,7 +329,7 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
|
||||
assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
|
||||
assert(pos.piece_count(weakerSide, KNIGHT) == 1);
|
||||
assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
|
||||
assert(pos.pawns() == EmptyBoardBB);
|
||||
assert(pos.pieces(PAWN) == EmptyBoardBB);
|
||||
|
||||
Value result = BishopValueEndgame;
|
||||
Square wksq = pos.king_square(strongerSide);
|
||||
@@ -378,16 +343,23 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
|
||||
result += Value(square_distance(bksq, nsq) * 32);
|
||||
|
||||
// Bonus for restricting the knight's mobility
|
||||
result += Value((8 - count_1s_max_15(pos.piece_attacks<KNIGHT>(nsq))) * 8);
|
||||
result += Value((8 - count_1s_max_15(pos.attacks_from<KNIGHT>(nsq))) * 8);
|
||||
|
||||
return (strongerSide == pos.side_to_move() ? result : -result);
|
||||
}
|
||||
|
||||
|
||||
/// K and two minors vs K and one or two minors or K and two knights against
|
||||
/// king alone are always draw.
|
||||
template<>
|
||||
Value EvaluationFunction<KmmKm>::apply(const Position&) {
|
||||
return Value(0);
|
||||
}
|
||||
|
||||
template<>
|
||||
Value EvaluationFunction<KNNK>::apply(const Position&) {
|
||||
return Value(0);
|
||||
}
|
||||
|
||||
/// KBPKScalingFunction scales endgames where the stronger side has king,
|
||||
/// bishop and one or more pawns. It checks for draws with rook pawns and a
|
||||
@@ -395,7 +367,7 @@ Value EvaluationFunction<KmmKm>::apply(const Position&) {
|
||||
/// returned. If not, the return value is SCALE_FACTOR_NONE, i.e. no scaling
|
||||
/// will be used.
|
||||
template<>
|
||||
ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
|
||||
ScaleFactor ScalingFunction<KBPsK>::apply(const Position& pos) {
|
||||
|
||||
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
|
||||
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
||||
@@ -404,7 +376,7 @@ ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
|
||||
// No assertions about the material of weakerSide, because we want draws to
|
||||
// be detected even when the weaker side has some pawns.
|
||||
|
||||
Bitboard pawns = pos.pawns(strongerSide);
|
||||
Bitboard pawns = pos.pieces(PAWN, strongerSide);
|
||||
File pawnFile = square_file(pos.piece_list(strongerSide, PAWN, 0));
|
||||
|
||||
// All pawns are on a single rook file ?
|
||||
@@ -421,7 +393,6 @@ ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
|
||||
// The bishop has the wrong color, and the defending king is on the
|
||||
// file of the pawn(s) or the neighboring file. Find the rank of the
|
||||
// frontmost pawn.
|
||||
|
||||
Rank rank;
|
||||
if (strongerSide == WHITE)
|
||||
{
|
||||
@@ -450,7 +421,7 @@ ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
|
||||
/// It tests for fortress draws with a rook on the third rank defended by
|
||||
/// a pawn.
|
||||
template<>
|
||||
ScaleFactor ScalingFunction<KQKRP>::apply(const Position& pos) {
|
||||
ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) {
|
||||
|
||||
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
|
||||
assert(pos.piece_count(strongerSide, QUEEN) == 1);
|
||||
@@ -461,12 +432,12 @@ ScaleFactor ScalingFunction<KQKRP>::apply(const Position& pos) {
|
||||
Square kingSq = pos.king_square(weakerSide);
|
||||
if ( relative_rank(weakerSide, kingSq) <= RANK_2
|
||||
&& relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
|
||||
&& (pos.rooks(weakerSide) & relative_rank_bb(weakerSide, RANK_3))
|
||||
&& (pos.pawns(weakerSide) & relative_rank_bb(weakerSide, RANK_2))
|
||||
&& (pos.piece_attacks<KING>(kingSq) & pos.pawns(weakerSide)))
|
||||
&& (pos.pieces(ROOK, weakerSide) & relative_rank_bb(weakerSide, RANK_3))
|
||||
&& (pos.pieces(PAWN, weakerSide) & relative_rank_bb(weakerSide, RANK_2))
|
||||
&& (pos.attacks_from<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
|
||||
{
|
||||
Square rsq = pos.piece_list(weakerSide, ROOK, 0);
|
||||
if (pos.pawn_attacks(strongerSide, rsq) & pos.pawns(weakerSide))
|
||||
if (pos.attacks_from<PAWN>(rsq, strongerSide) & pos.pieces(PAWN, weakerSide))
|
||||
return ScaleFactor(0);
|
||||
}
|
||||
return SCALE_FACTOR_NONE;
|
||||
@@ -645,7 +616,7 @@ ScaleFactor ScalingFunction<KPsK>::apply(const Position &pos) {
|
||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
||||
assert(pos.piece_count(weakerSide, PAWN) == 0);
|
||||
|
||||
Bitboard pawns = pos.pawns(strongerSide);
|
||||
Bitboard pawns = pos.pieces(PAWN, strongerSide);
|
||||
|
||||
// Are all pawns on the 'a' file?
|
||||
if ((pawns & ~FileABB) == EmptyBoardBB)
|
||||
@@ -723,9 +694,9 @@ ScaleFactor ScalingFunction<KBPKB>::apply(const Position &pos) {
|
||||
else
|
||||
{
|
||||
Bitboard ray = ray_bb(pawnSq, (strongerSide == WHITE)? SIGNED_DIR_N : SIGNED_DIR_S);
|
||||
if (ray & pos.kings(weakerSide))
|
||||
if (ray & pos.pieces(KING, weakerSide))
|
||||
return ScaleFactor(0);
|
||||
if( (pos.piece_attacks<BISHOP>(weakerBishopSq) & ray)
|
||||
if( (pos.attacks_from<BISHOP>(weakerBishopSq) & ray)
|
||||
&& square_distance(weakerBishopSq, pawnSq) >= 3)
|
||||
return ScaleFactor(0);
|
||||
}
|
||||
@@ -790,13 +761,13 @@ ScaleFactor ScalingFunction<KBPPKB>::apply(const Position& pos) {
|
||||
if ( ksq == blockSq1
|
||||
&& square_color(ksq) != square_color(wbsq)
|
||||
&& ( bbsq == blockSq2
|
||||
|| (pos.piece_attacks<BISHOP>(blockSq2) & pos.bishops(weakerSide))
|
||||
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
|
||||
|| rank_distance(r1, r2) >= 2))
|
||||
return ScaleFactor(0);
|
||||
else if ( ksq == blockSq2
|
||||
&& square_color(ksq) != square_color(wbsq)
|
||||
&& ( bbsq == blockSq1
|
||||
|| (pos.piece_attacks<BISHOP>(blockSq1) & pos.bishops(weakerSide))))
|
||||
|| (pos.attacks_from<BISHOP>(blockSq1) & pos.pieces(BISHOP, weakerSide))))
|
||||
return ScaleFactor(0);
|
||||
else
|
||||
return SCALE_FACTOR_NONE;
|
||||
|
||||
@@ -45,11 +45,12 @@ enum EndgameType {
|
||||
KRKN, // KR vs KN
|
||||
KQKR, // KQ vs KR
|
||||
KBBKN, // KBB vs KN
|
||||
KNNK, // KNN vs K
|
||||
KmmKm, // K and two minors vs K and one or two minors
|
||||
|
||||
// Scaling functions
|
||||
KBPK, // KBP vs K
|
||||
KQKRP, // KQ vs KRP
|
||||
KBPsK, // KB+pawns vs K
|
||||
KQKRPs, // KQ vs KR+pawns
|
||||
KRPKR, // KRP vs KR
|
||||
KRPPKRP, // KRPP vs KRP
|
||||
KPsK, // King and pawns vs king
|
||||
@@ -68,6 +69,7 @@ public:
|
||||
EndgameFunctionBase(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
|
||||
virtual ~EndgameFunctionBase() {}
|
||||
virtual T apply(const Position&) = 0;
|
||||
Color color() const { return strongerSide; }
|
||||
|
||||
protected:
|
||||
Color strongerSide, weakerSide;
|
||||
@@ -81,42 +83,19 @@ typedef EndgameFunctionBase<ScaleFactor> EndgameScalingFunctionBase;
|
||||
|
||||
template<EndgameType>
|
||||
struct EvaluationFunction : public EndgameEvaluationFunctionBase {
|
||||
typedef EndgameEvaluationFunctionBase Base;
|
||||
explicit EvaluationFunction(Color c): EndgameEvaluationFunctionBase(c) {}
|
||||
Value apply(const Position&);
|
||||
};
|
||||
|
||||
template<EndgameType>
|
||||
struct ScalingFunction : public EndgameScalingFunctionBase {
|
||||
typedef EndgameScalingFunctionBase Base;
|
||||
explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
|
||||
ScaleFactor apply(const Position&);
|
||||
};
|
||||
|
||||
|
||||
////
|
||||
//// Constants and variables
|
||||
////
|
||||
|
||||
extern EvaluationFunction<KXK> EvaluateKXK, EvaluateKKX; // Generic "mate lone king" eval
|
||||
extern EvaluationFunction<KBNK> EvaluateKBNK, EvaluateKKBN; // KBN vs K
|
||||
extern EvaluationFunction<KPK> EvaluateKPK, EvaluateKKP; // KP vs K
|
||||
extern EvaluationFunction<KRKP> EvaluateKRKP, EvaluateKPKR; // KR vs KP
|
||||
extern EvaluationFunction<KRKB> EvaluateKRKB, EvaluateKBKR; // KR vs KB
|
||||
extern EvaluationFunction<KRKN> EvaluateKRKN, EvaluateKNKR; // KR vs KN
|
||||
extern EvaluationFunction<KQKR> EvaluateKQKR, EvaluateKRKQ; // KQ vs KR
|
||||
extern EvaluationFunction<KBBKN> EvaluateKBBKN, EvaluateKNKBB; // KBB vs KN
|
||||
extern EvaluationFunction<KmmKm> EvaluateKmmKm; // K and two minors vs K and one or two minors:
|
||||
|
||||
extern ScalingFunction<KBPK> ScaleKBPK, ScaleKKBP; // KBP vs K
|
||||
extern ScalingFunction<KQKRP> ScaleKQKRP, ScaleKRPKQ; // KQ vs KRP
|
||||
extern ScalingFunction<KRPKR> ScaleKRPKR, ScaleKRKRP; // KRP vs KR
|
||||
extern ScalingFunction<KRPPKRP> ScaleKRPPKRP, ScaleKRPKRPP; // KRPP vs KRP
|
||||
extern ScalingFunction<KPsK> ScaleKPsK, ScaleKKPs; // King and pawns vs king
|
||||
extern ScalingFunction<KBPKB> ScaleKBPKB, ScaleKBKBP; // KBP vs KB
|
||||
extern ScalingFunction<KBPPKB> ScaleKBPPKB, ScaleKBKBPP; // KBPP vs KB
|
||||
extern ScalingFunction<KBPKN> ScaleKBPKN, ScaleKNKBP; // KBP vs KN
|
||||
extern ScalingFunction<KNPK> ScaleKNPK, ScaleKKNP; // KNP vs K
|
||||
extern ScalingFunction<KPKP> ScaleKPKPw, ScaleKPKPb; // KP vs KP
|
||||
|
||||
////
|
||||
//// Prototypes
|
||||
////
|
||||
|
||||
472
src/evaluate.cpp
472
src/evaluate.cpp
@@ -43,7 +43,7 @@ namespace {
|
||||
const int Sign[2] = { 1, -1 };
|
||||
|
||||
// Evaluation grain size, must be a power of 2
|
||||
const int GrainSize = 4;
|
||||
const int GrainSize = 8;
|
||||
|
||||
// Evaluation weights, initialized from UCI options
|
||||
int WeightMobilityMidgame, WeightMobilityEndgame;
|
||||
@@ -58,15 +58,15 @@ namespace {
|
||||
// parameters at 100, which looks prettier.
|
||||
//
|
||||
// Values modified by Joona Kiiski
|
||||
const int WeightMobilityMidgameInternal = 0x0FA;
|
||||
const int WeightMobilityEndgameInternal = 0x10A;
|
||||
const int WeightPawnStructureMidgameInternal = 0x0EC;
|
||||
const int WeightPawnStructureEndgameInternal = 0x0CD;
|
||||
const int WeightPassedPawnsMidgameInternal = 0x108;
|
||||
const int WeightPassedPawnsEndgameInternal = 0x109;
|
||||
const int WeightKingSafetyInternal = 0x0F7;
|
||||
const int WeightKingOppSafetyInternal = 0x101;
|
||||
const int WeightSpaceInternal = 0x02F;
|
||||
const int WeightMobilityMidgameInternal = 248;
|
||||
const int WeightMobilityEndgameInternal = 271;
|
||||
const int WeightPawnStructureMidgameInternal = 233;
|
||||
const int WeightPawnStructureEndgameInternal = 201;
|
||||
const int WeightPassedPawnsMidgameInternal = 252;
|
||||
const int WeightPassedPawnsEndgameInternal = 259;
|
||||
const int WeightKingSafetyInternal = 247;
|
||||
const int WeightKingOppSafetyInternal = 259;
|
||||
const int WeightSpaceInternal = 46;
|
||||
|
||||
// Mobility and outposts bonus modified by Joona Kiiski
|
||||
//
|
||||
@@ -207,8 +207,8 @@ namespace {
|
||||
((1ULL << SQ_A8) | (1ULL << SQ_H8))
|
||||
};
|
||||
|
||||
// The SpaceMask[color] contains area of the board which is consdered by
|
||||
// the space evaluation. In the middle game, each side is given a bonus
|
||||
// The SpaceMask[color] contains the area of the board which is considered
|
||||
// by the space evaluation. In the middle game, each side is given a bonus
|
||||
// based on how many squares inside this area are safe and available for
|
||||
// friendly minor pieces.
|
||||
const Bitboard SpaceMask[2] = {
|
||||
@@ -266,33 +266,26 @@ namespace {
|
||||
const int PawnTableSize = 16384;
|
||||
const int MaterialTableSize = 1024;
|
||||
|
||||
// Array which gives the number of nonzero bits in an 8-bit integer
|
||||
uint8_t BitCount8Bit[256];
|
||||
|
||||
// Function prototypes
|
||||
template<bool HasPopCnt>
|
||||
Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID);
|
||||
|
||||
template<PieceType Piece, bool HasPopCnt>
|
||||
void evaluate_pieces(const Position& p, Color us, EvalInfo& ei);
|
||||
template<Color Us, bool HasPopCnt>
|
||||
void evaluate_pieces_of_color(const Position& pos, EvalInfo& ei);
|
||||
|
||||
template<bool HasPopCnt>
|
||||
void evaluate_king(const Position& p, Color us, EvalInfo &ei);
|
||||
template<Color Us, bool HasPopCnt>
|
||||
void evaluate_king(const Position& pos, EvalInfo& ei);
|
||||
|
||||
void evaluate_passed_pawns(const Position &pos, EvalInfo &ei);
|
||||
void evaluate_trapped_bishop_a7h7(const Position &pos, Square s, Color us,
|
||||
EvalInfo &ei);
|
||||
void evaluate_trapped_bishop_a1h1(const Position &pos, Square s, Color us,
|
||||
EvalInfo &ei);
|
||||
template<bool HasPopCnt>
|
||||
void evaluate_space(const Position &p, Color us, EvalInfo &ei);
|
||||
template<Color Us, bool HasPopCnt>
|
||||
void evaluate_space(const Position& pos, EvalInfo& ei);
|
||||
|
||||
void evaluate_passed_pawns(const Position& pos, EvalInfo& ei);
|
||||
void evaluate_trapped_bishop_a7h7(const Position& pos, Square s, Color us, EvalInfo& ei);
|
||||
void evaluate_trapped_bishop_a1h1(const Position& pos, Square s, Color us, EvalInfo& ei);
|
||||
inline Value apply_weight(Value v, int w);
|
||||
Value scale_by_game_phase(Value mv, Value ev, Phase ph, const ScaleFactor sf[]);
|
||||
|
||||
int compute_weight(int uciWeight, int internalWeight);
|
||||
int weight_option(const std::string& opt, int weight);
|
||||
void init_safety();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -326,8 +319,8 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||
|
||||
// Probe the material hash table
|
||||
ei.mi = MaterialTable[threadID]->get_material_info(pos);
|
||||
ei.mgValue += ei.mi->mg_value();
|
||||
ei.egValue += ei.mi->eg_value();
|
||||
ei.mgValue += ei.mi->material_value();
|
||||
ei.egValue += ei.mi->material_value();
|
||||
|
||||
// If we have a specialized evaluation function for the current material
|
||||
// configuration, call it and return
|
||||
@@ -345,38 +338,33 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||
ei.egValue += apply_weight(ei.pi->eg_value(), WeightPawnStructureEndgame);
|
||||
|
||||
// Initialize king attack bitboards and king attack zones for both sides
|
||||
ei.attackedBy[WHITE][KING] = pos.piece_attacks<KING>(pos.king_square(WHITE));
|
||||
ei.attackedBy[BLACK][KING] = pos.piece_attacks<KING>(pos.king_square(BLACK));
|
||||
ei.attackedBy[WHITE][KING] = pos.attacks_from<KING>(pos.king_square(WHITE));
|
||||
ei.attackedBy[BLACK][KING] = pos.attacks_from<KING>(pos.king_square(BLACK));
|
||||
ei.kingZone[WHITE] = ei.attackedBy[BLACK][KING] | (ei.attackedBy[BLACK][KING] >> 8);
|
||||
ei.kingZone[BLACK] = ei.attackedBy[WHITE][KING] | (ei.attackedBy[WHITE][KING] << 8);
|
||||
|
||||
// Initialize pawn attack bitboards for both sides
|
||||
ei.attackedBy[WHITE][PAWN] = ((pos.pawns(WHITE) << 9) & ~FileABB) | ((pos.pawns(WHITE) << 7) & ~FileHBB);
|
||||
ei.attackedBy[BLACK][PAWN] = ((pos.pawns(BLACK) >> 7) & ~FileABB) | ((pos.pawns(BLACK) >> 9) & ~FileHBB);
|
||||
ei.kingAttackersCount[WHITE] = count_1s_max_15<HasPopCnt>(ei.attackedBy[WHITE][PAWN] & ei.attackedBy[BLACK][KING])/2;
|
||||
ei.kingAttackersCount[BLACK] = count_1s_max_15<HasPopCnt>(ei.attackedBy[BLACK][PAWN] & ei.attackedBy[WHITE][KING])/2;
|
||||
ei.attackedBy[WHITE][PAWN] = ei.pi->pawn_attacks(WHITE);
|
||||
ei.attackedBy[BLACK][PAWN] = ei.pi->pawn_attacks(BLACK);
|
||||
Bitboard b1 = ei.attackedBy[WHITE][PAWN] & ei.attackedBy[BLACK][KING];
|
||||
Bitboard b2 = ei.attackedBy[BLACK][PAWN] & ei.attackedBy[WHITE][KING];
|
||||
if (b1)
|
||||
ei.kingAttackersCount[WHITE] = count_1s_max_15<HasPopCnt>(b1)/2;
|
||||
|
||||
if (b2)
|
||||
ei.kingAttackersCount[BLACK] = count_1s_max_15<HasPopCnt>(b2)/2;
|
||||
|
||||
// Evaluate pieces
|
||||
for (Color c = WHITE; c <= BLACK; c++)
|
||||
{
|
||||
evaluate_pieces<KNIGHT, HasPopCnt>(pos, c, ei);
|
||||
evaluate_pieces<BISHOP, HasPopCnt>(pos, c, ei);
|
||||
evaluate_pieces<ROOK, HasPopCnt>(pos, c, ei);
|
||||
evaluate_pieces<QUEEN, HasPopCnt>(pos, c, ei);
|
||||
|
||||
// Sum up all attacked squares
|
||||
ei.attackedBy[c][0] = ei.attackedBy[c][PAWN] | ei.attackedBy[c][KNIGHT]
|
||||
| ei.attackedBy[c][BISHOP] | ei.attackedBy[c][ROOK]
|
||||
| ei.attackedBy[c][QUEEN] | ei.attackedBy[c][KING];
|
||||
}
|
||||
evaluate_pieces_of_color<WHITE, HasPopCnt>(pos, ei);
|
||||
evaluate_pieces_of_color<BLACK, HasPopCnt>(pos, ei);
|
||||
|
||||
// Kings. Kings are evaluated after all other pieces for both sides,
|
||||
// because we need complete attack information for all pieces when computing
|
||||
// the king safety evaluation.
|
||||
for (Color c = WHITE; c <= BLACK; c++)
|
||||
evaluate_king<HasPopCnt>(pos, c, ei);
|
||||
evaluate_king<WHITE, HasPopCnt>(pos, ei);
|
||||
evaluate_king<BLACK, HasPopCnt>(pos, ei);
|
||||
|
||||
// Evaluate passed pawns. We evaluate passed pawns for both sides at once,
|
||||
// Evaluate passed pawns. We evaluate passed pawns for both sides at once,
|
||||
// because we need to know which side promotes first in positions where
|
||||
// both sides have an unstoppable passed pawn.
|
||||
if (ei.pi->passed_pawns())
|
||||
@@ -403,8 +391,8 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||
// Evaluate space for both sides
|
||||
if (ei.mi->space_weight() > 0)
|
||||
{
|
||||
evaluate_space<HasPopCnt>(pos, WHITE, ei);
|
||||
evaluate_space<HasPopCnt>(pos, BLACK, ei);
|
||||
evaluate_space<WHITE, HasPopCnt>(pos, ei);
|
||||
evaluate_space<BLACK, HasPopCnt>(pos, ei);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,8 +429,7 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||
factor[BLACK] = sf;
|
||||
}
|
||||
|
||||
// Interpolate between the middle game and the endgame score, and
|
||||
// return
|
||||
// Interpolate between the middle game and the endgame score
|
||||
Color stm = pos.side_to_move();
|
||||
|
||||
Value v = Sign[stm] * scale_by_game_phase(ei.mgValue, ei.egValue, phase, factor);
|
||||
@@ -453,7 +440,7 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||
} // namespace
|
||||
|
||||
/// quick_evaluate() does a very approximate evaluation of the current position.
|
||||
/// It currently considers only material and piece square table scores. Perhaps
|
||||
/// It currently considers only material and piece square table scores. Perhaps
|
||||
/// we should add scores from the pawn and material hash tables?
|
||||
|
||||
Value quick_evaluate(const Position &pos) {
|
||||
@@ -472,7 +459,7 @@ Value quick_evaluate(const Position &pos) {
|
||||
}
|
||||
|
||||
|
||||
/// init_eval() initializes various tables used by the evaluation function.
|
||||
/// init_eval() initializes various tables used by the evaluation function
|
||||
|
||||
void init_eval(int threads) {
|
||||
|
||||
@@ -493,16 +480,10 @@ void init_eval(int threads) {
|
||||
if (!MaterialTable[i])
|
||||
MaterialTable[i] = new MaterialInfoTable(MaterialTableSize);
|
||||
}
|
||||
|
||||
for (Bitboard b = 0ULL; b < 256ULL; b++)
|
||||
{
|
||||
assert(count_1s(b) == int(uint8_t(count_1s(b))));
|
||||
BitCount8Bit[b] = (uint8_t)count_1s(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// quit_eval() releases heap-allocated memory at program termination.
|
||||
/// quit_eval() releases heap-allocated memory at program termination
|
||||
|
||||
void quit_eval() {
|
||||
|
||||
@@ -516,24 +497,29 @@ void quit_eval() {
|
||||
}
|
||||
|
||||
|
||||
/// read_weights() reads evaluation weights from the corresponding UCI
|
||||
/// parameters.
|
||||
/// read_weights() reads evaluation weights from the corresponding UCI parameters
|
||||
|
||||
void read_weights(Color us) {
|
||||
|
||||
Color them = opposite_color(us);
|
||||
|
||||
WeightMobilityMidgame = weight_option("Mobility (Middle Game)", WeightMobilityMidgameInternal);
|
||||
WeightMobilityEndgame = weight_option("Mobility (Endgame)", WeightMobilityEndgameInternal);
|
||||
WeightPawnStructureMidgame = weight_option("Pawn Structure (Middle Game)", WeightPawnStructureMidgameInternal);
|
||||
WeightPawnStructureEndgame = weight_option("Pawn Structure (Endgame)", WeightPawnStructureEndgameInternal);
|
||||
WeightPassedPawnsMidgame = weight_option("Passed Pawns (Middle Game)", WeightPassedPawnsMidgameInternal);
|
||||
WeightPassedPawnsEndgame = weight_option("Passed Pawns (Endgame)", WeightPassedPawnsEndgameInternal);
|
||||
WeightSpace = weight_option("Space", WeightSpaceInternal);
|
||||
WeightKingSafety[us] = weight_option("Cowardice", WeightKingSafetyInternal);
|
||||
WeightKingSafety[them] = weight_option("Aggressiveness", WeightKingOppSafetyInternal);
|
||||
|
||||
Color them = opposite_color(us);
|
||||
|
||||
WeightKingSafety[us] = weight_option("Cowardice", WeightKingSafetyInternal);
|
||||
WeightKingSafety[them] = weight_option("Aggressiveness", WeightKingOppSafetyInternal);
|
||||
WeightSpace = weight_option("Space", WeightSpaceInternal);
|
||||
|
||||
// If running in analysis mode, make sure we use symmetrical king safety. We do this
|
||||
// by replacing both WeightKingSafety[us] and WeightKingSafety[them] by their average.
|
||||
if (get_option_value_bool("UCI_AnalyseMode"))
|
||||
{
|
||||
WeightKingSafety[us] = (WeightKingSafety[us] + WeightKingSafety[them]) / 2;
|
||||
WeightKingSafety[them] = WeightKingSafety[us];
|
||||
}
|
||||
init_safety();
|
||||
}
|
||||
|
||||
@@ -542,114 +528,127 @@ namespace {
|
||||
|
||||
// evaluate_mobility() computes mobility and attacks for every piece
|
||||
|
||||
template<PieceType Piece, bool HasPopCnt>
|
||||
int evaluate_mobility(const Position& p, const Bitboard& b, Color us, Color them, EvalInfo& ei) {
|
||||
template<PieceType Piece, Color Us, bool HasPopCnt>
|
||||
int evaluate_mobility(const Position& pos, Bitboard b, EvalInfo& ei) {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
static const int AttackWeight[] = { 0, 0, KnightAttackWeight, BishopAttackWeight, RookAttackWeight, QueenAttackWeight };
|
||||
static const Value* MgBonus[] = { 0, 0, MidgameKnightMobilityBonus, MidgameBishopMobilityBonus, MidgameRookMobilityBonus, MidgameQueenMobilityBonus };
|
||||
static const Value* EgBonus[] = { 0, 0, EndgameKnightMobilityBonus, EndgameBishopMobilityBonus, EndgameRookMobilityBonus, EndgameQueenMobilityBonus };
|
||||
static const int lastIndex[] = { 0, 0, 8, 15, 15, 31 };
|
||||
|
||||
// Update attack info
|
||||
ei.attackedBy[us][Piece] |= b;
|
||||
ei.attackedBy[Us][Piece] |= b;
|
||||
|
||||
// King attacks
|
||||
if (b & ei.kingZone[us])
|
||||
if (b & ei.kingZone[Us])
|
||||
{
|
||||
ei.kingAttackersCount[us]++;
|
||||
ei.kingAttackersWeight[us] += AttackWeight[Piece];
|
||||
Bitboard bb = (b & ei.attackedBy[them][KING]);
|
||||
ei.kingAttackersCount[Us]++;
|
||||
ei.kingAttackersWeight[Us] += AttackWeight[Piece];
|
||||
Bitboard bb = (b & ei.attackedBy[Them][KING]);
|
||||
if (bb)
|
||||
ei.kingAdjacentZoneAttacksCount[us] += count_1s_max_15<HasPopCnt>(bb);
|
||||
ei.kingAdjacentZoneAttacksCount[Us] += count_1s_max_15<HasPopCnt>(bb);
|
||||
}
|
||||
|
||||
// Remove squares protected by enemy pawns
|
||||
Bitboard bb = (b & ~ei.attackedBy[them][PAWN]);
|
||||
// Remove squares protected by enemy pawns or occupied by our pieces
|
||||
b &= ~(ei.attackedBy[Them][PAWN] | pos.pieces_of_color(Us));
|
||||
|
||||
// The squares occupied by enemy pieces (not defended by pawns) will be
|
||||
// counted two times instead of one. The shift (almost) guarantees that
|
||||
// intersection of the shifted value with b is zero so that after or-ing
|
||||
// the count of 1s bits is increased by the number of affected squares.
|
||||
b |= Us == WHITE ? ((b & pos.pieces_of_color(Them)) >> 1)
|
||||
: ((b & pos.pieces_of_color(Them)) << 1);
|
||||
|
||||
// Mobility
|
||||
int mob = (Piece != QUEEN ? count_1s_max_15<HasPopCnt>(bb & ~p.pieces_of_color(us))
|
||||
: count_1s<HasPopCnt>(bb & ~p.pieces_of_color(us)));
|
||||
int mob = (Piece != QUEEN ? count_1s_max_15<HasPopCnt>(b)
|
||||
: count_1s<HasPopCnt>(b));
|
||||
|
||||
ei.mgMobility += Sign[us] * MgBonus[Piece][mob];
|
||||
ei.egMobility += Sign[us] * EgBonus[Piece][mob];
|
||||
if (mob > lastIndex[Piece])
|
||||
mob = lastIndex[Piece];
|
||||
|
||||
ei.mgMobility += Sign[Us] * MgBonus[Piece][mob];
|
||||
ei.egMobility += Sign[Us] * EgBonus[Piece][mob];
|
||||
return mob;
|
||||
}
|
||||
|
||||
|
||||
// evaluate_outposts() evaluates bishop and knight outposts squares
|
||||
|
||||
template<PieceType Piece>
|
||||
void evaluate_outposts(const Position& p, Color us, Color them, EvalInfo& ei, Square s) {
|
||||
template<PieceType Piece, Color Us>
|
||||
void evaluate_outposts(const Position& pos, EvalInfo& ei, Square s) {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
|
||||
// Initial bonus based on square
|
||||
Value bonus = (Piece == BISHOP ? BishopOutpostBonus[relative_square(us, s)]
|
||||
: KnightOutpostBonus[relative_square(us, s)]);
|
||||
Value bonus = (Piece == BISHOP ? BishopOutpostBonus[relative_square(Us, s)]
|
||||
: KnightOutpostBonus[relative_square(Us, s)]);
|
||||
|
||||
// Increase bonus if supported by pawn, especially if the opponent has
|
||||
// no minor piece which can exchange the outpost piece
|
||||
if (bonus && (p.pawn_attacks(them, s) & p.pawns(us)))
|
||||
if (bonus && (pos.attacks_from<PAWN>(s, Them) & pos.pieces(PAWN, Us)))
|
||||
{
|
||||
if ( p.knights(them) == EmptyBoardBB
|
||||
&& (SquaresByColorBB[square_color(s)] & p.bishops(them)) == EmptyBoardBB)
|
||||
if ( pos.pieces(KNIGHT, Them) == EmptyBoardBB
|
||||
&& (SquaresByColorBB[square_color(s)] & pos.pieces(BISHOP, Them)) == EmptyBoardBB)
|
||||
bonus += bonus + bonus / 2;
|
||||
else
|
||||
bonus += bonus / 2;
|
||||
}
|
||||
ei.mgValue += Sign[us] * bonus;
|
||||
ei.egValue += Sign[us] * bonus;
|
||||
ei.mgValue += Sign[Us] * bonus;
|
||||
ei.egValue += Sign[Us] * bonus;
|
||||
}
|
||||
|
||||
|
||||
// evaluate_pieces<>() assigns bonuses and penalties to the pieces of a given
|
||||
// color.
|
||||
// evaluate_pieces<>() assigns bonuses and penalties to the pieces of a given color
|
||||
|
||||
template<PieceType Piece, bool HasPopCnt>
|
||||
void evaluate_pieces(const Position& pos, Color us, EvalInfo& ei) {
|
||||
template<PieceType Piece, Color Us, bool HasPopCnt>
|
||||
void evaluate_pieces(const Position& pos, EvalInfo& ei) {
|
||||
|
||||
Bitboard b;
|
||||
Square s, ksq;
|
||||
int mob;
|
||||
File f;
|
||||
Color them = opposite_color(us);
|
||||
|
||||
for (int i = 0, e = pos.piece_count(us, Piece); i < e; i++)
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square* ptr = pos.piece_list_begin(Us, Piece);
|
||||
|
||||
while ((s = *ptr++) != SQ_NONE)
|
||||
{
|
||||
s = pos.piece_list(us, Piece, i);
|
||||
|
||||
if (Piece == KNIGHT || Piece == QUEEN)
|
||||
b = pos.piece_attacks<Piece>(s);
|
||||
b = pos.attacks_from<Piece>(s);
|
||||
else if (Piece == BISHOP)
|
||||
b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.queens(us));
|
||||
b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
|
||||
else if (Piece == ROOK)
|
||||
b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.rooks_and_queens(us));
|
||||
b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
|
||||
else
|
||||
assert(false);
|
||||
|
||||
// Attacks and mobility
|
||||
mob = evaluate_mobility<Piece, HasPopCnt>(pos, b, us, them, ei);
|
||||
mob = evaluate_mobility<Piece, Us, HasPopCnt>(pos, b, ei);
|
||||
|
||||
// Bishop and knight outposts squares
|
||||
if ((Piece == BISHOP || Piece == KNIGHT) && pos.square_is_weak(s, them))
|
||||
evaluate_outposts<Piece>(pos, us, them, ei, s);
|
||||
if ((Piece == BISHOP || Piece == KNIGHT) && pos.square_is_weak(s, Them))
|
||||
evaluate_outposts<Piece, Us>(pos, ei, s);
|
||||
|
||||
// Special patterns: trapped bishops on a7/h7/a2/h2
|
||||
// and trapped bishops on a1/h1/a8/h8 in Chess960.
|
||||
if (Piece == BISHOP)
|
||||
{
|
||||
if (bit_is_set(MaskA7H7[us], s))
|
||||
evaluate_trapped_bishop_a7h7(pos, s, us, ei);
|
||||
if (bit_is_set(MaskA7H7[Us], s))
|
||||
evaluate_trapped_bishop_a7h7(pos, s, Us, ei);
|
||||
|
||||
if (Chess960 && bit_is_set(MaskA1H1[us], s))
|
||||
evaluate_trapped_bishop_a1h1(pos, s, us, ei);
|
||||
if (Chess960 && bit_is_set(MaskA1H1[Us], s))
|
||||
evaluate_trapped_bishop_a1h1(pos, s, Us, ei);
|
||||
}
|
||||
|
||||
if (Piece == ROOK || Piece == QUEEN)
|
||||
{
|
||||
// Queen or rook on 7th rank
|
||||
if ( relative_rank(us, s) == RANK_7
|
||||
&& relative_rank(us, pos.king_square(them)) == RANK_8)
|
||||
if ( relative_rank(Us, s) == RANK_7
|
||||
&& relative_rank(Us, pos.king_square(Them)) == RANK_8)
|
||||
{
|
||||
ei.mgValue += Sign[us] * (Piece == ROOK ? MidgameRookOn7thBonus : MidgameQueenOn7thBonus);
|
||||
ei.egValue += Sign[us] * (Piece == ROOK ? EndgameRookOn7thBonus : EndgameQueenOn7thBonus);
|
||||
ei.mgValue += Sign[Us] * (Piece == ROOK ? MidgameRookOn7thBonus : MidgameQueenOn7thBonus);
|
||||
ei.egValue += Sign[Us] * (Piece == ROOK ? EndgameRookOn7thBonus : EndgameQueenOn7thBonus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,102 +657,103 @@ namespace {
|
||||
{
|
||||
// Open and half-open files
|
||||
f = square_file(s);
|
||||
if (ei.pi->file_is_half_open(us, f))
|
||||
if (ei.pi->file_is_half_open(Us, f))
|
||||
{
|
||||
if (ei.pi->file_is_half_open(them, f))
|
||||
if (ei.pi->file_is_half_open(Them, f))
|
||||
{
|
||||
ei.mgValue += Sign[us] * RookOpenFileBonus;
|
||||
ei.egValue += Sign[us] * RookOpenFileBonus;
|
||||
ei.mgValue += Sign[Us] * RookOpenFileBonus;
|
||||
ei.egValue += Sign[Us] * RookOpenFileBonus;
|
||||
}
|
||||
else
|
||||
{
|
||||
ei.mgValue += Sign[us] * RookHalfOpenFileBonus;
|
||||
ei.egValue += Sign[us] * RookHalfOpenFileBonus;
|
||||
ei.mgValue += Sign[Us] * RookHalfOpenFileBonus;
|
||||
ei.egValue += Sign[Us] * RookHalfOpenFileBonus;
|
||||
}
|
||||
}
|
||||
|
||||
// Penalize rooks which are trapped inside a king. Penalize more if
|
||||
// king has lost right to castle.
|
||||
if (mob > 6 || ei.pi->file_is_half_open(us, f))
|
||||
if (mob > 6 || ei.pi->file_is_half_open(Us, f))
|
||||
continue;
|
||||
|
||||
ksq = pos.king_square(us);
|
||||
ksq = pos.king_square(Us);
|
||||
|
||||
if ( square_file(ksq) >= FILE_E
|
||||
&& square_file(s) > square_file(ksq)
|
||||
&& (relative_rank(us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
|
||||
&& (relative_rank(Us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
|
||||
{
|
||||
// Is there a half-open file between the king and the edge of the board?
|
||||
if (!ei.pi->has_open_file_to_right(us, square_file(ksq)))
|
||||
ei.mgValue -= pos.can_castle(us)? Sign[us] * ((TrappedRookPenalty - mob * 16) / 2)
|
||||
: Sign[us] * (TrappedRookPenalty - mob * 16);
|
||||
if (!ei.pi->has_open_file_to_right(Us, square_file(ksq)))
|
||||
ei.mgValue -= pos.can_castle(Us)? Sign[Us] * ((TrappedRookPenalty - mob * 16) / 2)
|
||||
: Sign[Us] * (TrappedRookPenalty - mob * 16);
|
||||
}
|
||||
else if ( square_file(ksq) <= FILE_D
|
||||
&& square_file(s) < square_file(ksq)
|
||||
&& (relative_rank(us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
|
||||
&& (relative_rank(Us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
|
||||
{
|
||||
// Is there a half-open file between the king and the edge of the board?
|
||||
if (!ei.pi->has_open_file_to_left(us, square_file(ksq)))
|
||||
ei.mgValue -= pos.can_castle(us)? Sign[us] * ((TrappedRookPenalty - mob * 16) / 2)
|
||||
: Sign[us] * (TrappedRookPenalty - mob * 16);
|
||||
if (!ei.pi->has_open_file_to_left(Us, square_file(ksq)))
|
||||
ei.mgValue -= pos.can_castle(Us)? Sign[Us] * ((TrappedRookPenalty - mob * 16) / 2)
|
||||
: Sign[Us] * (TrappedRookPenalty - mob * 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline Bitboard shiftRowsDown(const Bitboard& b, int num) {
|
||||
|
||||
return b >> (num << 3);
|
||||
// evaluate_pieces_of_color<>() assigns bonuses and penalties to all the
|
||||
// pieces of a given color.
|
||||
|
||||
template<Color Us, bool HasPopCnt>
|
||||
void evaluate_pieces_of_color(const Position& pos, EvalInfo& ei) {
|
||||
|
||||
evaluate_pieces<KNIGHT, Us, HasPopCnt>(pos, ei);
|
||||
evaluate_pieces<BISHOP, Us, HasPopCnt>(pos, ei);
|
||||
evaluate_pieces<ROOK, Us, HasPopCnt>(pos, ei);
|
||||
evaluate_pieces<QUEEN, Us, HasPopCnt>(pos, ei);
|
||||
|
||||
// Sum up all attacked squares
|
||||
ei.attackedBy[Us][0] = ei.attackedBy[Us][PAWN] | ei.attackedBy[Us][KNIGHT]
|
||||
| ei.attackedBy[Us][BISHOP] | ei.attackedBy[Us][ROOK]
|
||||
| ei.attackedBy[Us][QUEEN] | ei.attackedBy[Us][KING];
|
||||
}
|
||||
|
||||
// evaluate_king<>() assigns bonuses and penalties to a king of a given color.
|
||||
|
||||
template<bool HasPopCnt>
|
||||
void evaluate_king(const Position& p, Color us, EvalInfo& ei) {
|
||||
// evaluate_king<>() assigns bonuses and penalties to a king of a given color
|
||||
|
||||
int shelter = 0, sign = Sign[us];
|
||||
Square s = p.king_square(us);
|
||||
template<Color Us, bool HasPopCnt>
|
||||
void evaluate_king(const Position& pos, EvalInfo& ei) {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square s = pos.king_square(Us);
|
||||
int shelter = 0;
|
||||
|
||||
// King shelter
|
||||
if (relative_rank(us, s) <= RANK_4)
|
||||
if (relative_rank(Us, s) <= RANK_4)
|
||||
{
|
||||
// Shelter cache lookup
|
||||
shelter = ei.pi->kingShelter(us, s);
|
||||
if (shelter == -1)
|
||||
{
|
||||
shelter = 0;
|
||||
Bitboard pawns = p.pawns(us) & this_and_neighboring_files_bb(s);
|
||||
Rank r = square_rank(s);
|
||||
for (int i = 1; i < 4; i++)
|
||||
shelter += BitCount8Bit[shiftRowsDown(pawns, r+i*sign) & 0xFF] * (128 >> i);
|
||||
|
||||
// Cache shelter value in pawn info
|
||||
ei.pi->setKingShelter(us, s, shelter);
|
||||
}
|
||||
ei.mgValue += sign * Value(shelter);
|
||||
shelter = ei.pi->get_king_shelter(pos, Us, s);
|
||||
ei.mgValue += Sign[Us] * Value(shelter);
|
||||
}
|
||||
|
||||
// King safety. This is quite complicated, and is almost certainly far
|
||||
// from optimally tuned.
|
||||
Color them = opposite_color(us);
|
||||
|
||||
if ( p.piece_count(them, QUEEN) >= 1
|
||||
&& ei.kingAttackersCount[them] >= 2
|
||||
&& p.non_pawn_material(them) >= QueenValueMidgame + RookValueMidgame
|
||||
&& ei.kingAdjacentZoneAttacksCount[them])
|
||||
if ( pos.piece_count(Them, QUEEN) >= 1
|
||||
&& ei.kingAttackersCount[Them] >= 2
|
||||
&& pos.non_pawn_material(Them) >= QueenValueMidgame + RookValueMidgame
|
||||
&& ei.kingAdjacentZoneAttacksCount[Them])
|
||||
{
|
||||
// Is it the attackers turn to move?
|
||||
bool sente = (them == p.side_to_move());
|
||||
bool sente = (Them == pos.side_to_move());
|
||||
|
||||
// Find the attacked squares around the king which has no defenders
|
||||
// apart from the king itself
|
||||
Bitboard undefended =
|
||||
ei.attacked_by(them) & ~ei.attacked_by(us, PAWN)
|
||||
& ~ei.attacked_by(us, KNIGHT) & ~ei.attacked_by(us, BISHOP)
|
||||
& ~ei.attacked_by(us, ROOK) & ~ei.attacked_by(us, QUEEN)
|
||||
& ei.attacked_by(us, KING);
|
||||
ei.attacked_by(Them) & ~ei.attacked_by(Us, PAWN)
|
||||
& ~ei.attacked_by(Us, KNIGHT) & ~ei.attacked_by(Us, BISHOP)
|
||||
& ~ei.attacked_by(Us, ROOK) & ~ei.attacked_by(Us, QUEEN)
|
||||
& ei.attacked_by(Us, KING);
|
||||
|
||||
Bitboard occ = p.occupied_squares(), b, b2;
|
||||
Bitboard occ = pos.occupied_squares(), b, b2;
|
||||
|
||||
// Initialize the 'attackUnits' variable, which is used later on as an
|
||||
// index to the SafetyTable[] array. The initial value is based on the
|
||||
@@ -761,17 +761,17 @@ namespace {
|
||||
// undefended squares around the king, the square of the king, and the
|
||||
// quality of the pawn shelter.
|
||||
int attackUnits =
|
||||
Min((ei.kingAttackersCount[them] * ei.kingAttackersWeight[them]) / 2, 25)
|
||||
+ (ei.kingAdjacentZoneAttacksCount[them] + count_1s_max_15<HasPopCnt>(undefended)) * 3
|
||||
+ InitKingDanger[relative_square(us, s)] - (shelter >> 5);
|
||||
Min((ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) / 2, 25)
|
||||
+ (ei.kingAdjacentZoneAttacksCount[Them] + count_1s_max_15<HasPopCnt>(undefended)) * 3
|
||||
+ InitKingDanger[relative_square(Us, s)] - (shelter >> 5);
|
||||
|
||||
// Analyse safe queen contact checks
|
||||
b = undefended & ei.attacked_by(them, QUEEN) & ~p.pieces_of_color(them);
|
||||
b = undefended & ei.attacked_by(Them, QUEEN) & ~pos.pieces_of_color(Them);
|
||||
if (b)
|
||||
{
|
||||
Bitboard attackedByOthers =
|
||||
ei.attacked_by(them, PAWN) | ei.attacked_by(them, KNIGHT)
|
||||
| ei.attacked_by(them, BISHOP) | ei.attacked_by(them, ROOK);
|
||||
ei.attacked_by(Them, PAWN) | ei.attacked_by(Them, KNIGHT)
|
||||
| ei.attacked_by(Them, BISHOP) | ei.attacked_by(Them, ROOK);
|
||||
|
||||
b &= attackedByOthers;
|
||||
if (b)
|
||||
@@ -782,10 +782,10 @@ namespace {
|
||||
attackUnits += QueenContactCheckBonus * count * (sente ? 2 : 1);
|
||||
|
||||
// Is there a mate threat?
|
||||
if (QueenContactMates && !p.is_check())
|
||||
if (QueenContactMates && !pos.is_check())
|
||||
{
|
||||
Bitboard escapeSquares =
|
||||
p.piece_attacks<KING>(s) & ~p.pieces_of_color(us) & ~attackedByOthers;
|
||||
pos.attacks_from<KING>(s) & ~pos.pieces_of_color(Us) & ~attackedByOthers;
|
||||
|
||||
while (b)
|
||||
{
|
||||
@@ -794,15 +794,15 @@ namespace {
|
||||
{
|
||||
// We have a mate, unless the queen is pinned or there
|
||||
// is an X-ray attack through the queen.
|
||||
for (int i = 0; i < p.piece_count(them, QUEEN); i++)
|
||||
for (int i = 0; i < pos.piece_count(Them, QUEEN); i++)
|
||||
{
|
||||
from = p.piece_list(them, QUEEN, i);
|
||||
if ( bit_is_set(p.piece_attacks<QUEEN>(from), to)
|
||||
&& !bit_is_set(p.pinned_pieces(them), from)
|
||||
&& !(rook_attacks_bb(to, occ & ClearMaskBB[from]) & p.rooks_and_queens(us))
|
||||
&& !(bishop_attacks_bb(to, occ & ClearMaskBB[from]) & p.bishops_and_queens(us)))
|
||||
from = pos.piece_list(Them, QUEEN, i);
|
||||
if ( bit_is_set(pos.attacks_from<QUEEN>(from), to)
|
||||
&& !bit_is_set(pos.pinned_pieces(Them), from)
|
||||
&& !(rook_attacks_bb(to, occ & ClearMaskBB[from]) & pos.pieces(ROOK, QUEEN, Us))
|
||||
&& !(bishop_attacks_bb(to, occ & ClearMaskBB[from]) & pos.pieces(BISHOP, QUEEN, Us)))
|
||||
|
||||
ei.mateThreat[them] = make_move(from, to);
|
||||
ei.mateThreat[Them] = make_move(from, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -813,38 +813,38 @@ namespace {
|
||||
// Analyse safe distance checks
|
||||
if (QueenCheckBonus > 0 || RookCheckBonus > 0)
|
||||
{
|
||||
b = p.piece_attacks<ROOK>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
||||
b = pos.attacks_from<ROOK>(s) & ~pos.pieces_of_color(Them) & ~ei.attacked_by(Us);
|
||||
|
||||
// Queen checks
|
||||
b2 = b & ei.attacked_by(them, QUEEN);
|
||||
if( b2)
|
||||
b2 = b & ei.attacked_by(Them, QUEEN);
|
||||
if (b2)
|
||||
attackUnits += QueenCheckBonus * count_1s_max_15<HasPopCnt>(b2);
|
||||
|
||||
// Rook checks
|
||||
b2 = b & ei.attacked_by(them, ROOK);
|
||||
b2 = b & ei.attacked_by(Them, ROOK);
|
||||
if (b2)
|
||||
attackUnits += RookCheckBonus * count_1s_max_15<HasPopCnt>(b2);
|
||||
}
|
||||
if (QueenCheckBonus > 0 || BishopCheckBonus > 0)
|
||||
{
|
||||
b = p.piece_attacks<BISHOP>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
||||
b = pos.attacks_from<BISHOP>(s) & ~pos.pieces_of_color(Them) & ~ei.attacked_by(Us);
|
||||
|
||||
// Queen checks
|
||||
b2 = b & ei.attacked_by(them, QUEEN);
|
||||
b2 = b & ei.attacked_by(Them, QUEEN);
|
||||
if (b2)
|
||||
attackUnits += QueenCheckBonus * count_1s_max_15<HasPopCnt>(b2);
|
||||
|
||||
// Bishop checks
|
||||
b2 = b & ei.attacked_by(them, BISHOP);
|
||||
b2 = b & ei.attacked_by(Them, BISHOP);
|
||||
if (b2)
|
||||
attackUnits += BishopCheckBonus * count_1s_max_15<HasPopCnt>(b2);
|
||||
}
|
||||
if (KnightCheckBonus > 0)
|
||||
{
|
||||
b = p.piece_attacks<KNIGHT>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
||||
b = pos.attacks_from<KNIGHT>(s) & ~pos.pieces_of_color(Them) & ~ei.attacked_by(Us);
|
||||
|
||||
// Knight checks
|
||||
b2 = b & ei.attacked_by(them, KNIGHT);
|
||||
b2 = b & ei.attacked_by(Them, KNIGHT);
|
||||
if (b2)
|
||||
attackUnits += KnightCheckBonus * count_1s_max_15<HasPopCnt>(b2);
|
||||
}
|
||||
@@ -853,16 +853,16 @@ namespace {
|
||||
// adding pawns later).
|
||||
if (DiscoveredCheckBonus)
|
||||
{
|
||||
b = p.discovered_check_candidates(them) & ~p.pawns();
|
||||
b = pos.discovered_check_candidates(Them) & ~pos.pieces(PAWN);
|
||||
if (b)
|
||||
attackUnits += DiscoveredCheckBonus * count_1s_max_15<HasPopCnt>(b) * (sente? 2 : 1);
|
||||
attackUnits += DiscoveredCheckBonus * count_1s_max_15<HasPopCnt>(b) * (sente ? 2 : 1);
|
||||
}
|
||||
|
||||
// Has a mate threat been found? We don't do anything here if the
|
||||
// side with the mating move is the side to move, because in that
|
||||
// case the mating side will get a huge bonus at the end of the main
|
||||
// evaluation function instead.
|
||||
if (ei.mateThreat[them] != MOVE_NONE)
|
||||
if (ei.mateThreat[Them] != MOVE_NONE)
|
||||
attackUnits += MateThreatBonus;
|
||||
|
||||
// Ensure that attackUnits is between 0 and 99, in order to avoid array
|
||||
@@ -879,19 +879,19 @@ namespace {
|
||||
// that the king safety scores can sometimes be very big, and that
|
||||
// capturing a single attacking piece can therefore result in a score
|
||||
// change far bigger than the value of the captured piece.
|
||||
Value v = apply_weight(SafetyTable[attackUnits], WeightKingSafety[us]);
|
||||
Value v = apply_weight(SafetyTable[attackUnits], WeightKingSafety[Us]);
|
||||
|
||||
ei.mgValue -= sign * v;
|
||||
ei.mgValue -= Sign[Us] * v;
|
||||
|
||||
if (us == p.side_to_move())
|
||||
if (Us == pos.side_to_move())
|
||||
ei.futilityMargin += v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// evaluate_passed_pawns() evaluates the passed pawns for both sides.
|
||||
// evaluate_passed_pawns() evaluates the passed pawns for both sides
|
||||
|
||||
void evaluate_passed_pawns(const Position &pos, EvalInfo &ei) {
|
||||
void evaluate_passed_pawns(const Position& pos, EvalInfo& ei) {
|
||||
|
||||
bool hasUnstoppable[2] = {false, false};
|
||||
int movesToGo[2] = {100, 100};
|
||||
@@ -901,7 +901,7 @@ namespace {
|
||||
Color them = opposite_color(us);
|
||||
Square ourKingSq = pos.king_square(us);
|
||||
Square theirKingSq = pos.king_square(them);
|
||||
Bitboard b = ei.pi->passed_pawns() & pos.pawns(us), b2, b3, b4;
|
||||
Bitboard b = ei.pi->passed_pawns() & pos.pieces(PAWN, us), b2, b3, b4;
|
||||
|
||||
while (b)
|
||||
{
|
||||
@@ -935,14 +935,14 @@ namespace {
|
||||
// If there is an enemy rook or queen attacking the pawn from behind,
|
||||
// add all X-ray attacks by the rook or queen.
|
||||
if ( bit_is_set(ei.attacked_by(them,ROOK) | ei.attacked_by(them,QUEEN),s)
|
||||
&& (squares_behind(us, s) & pos.rooks_and_queens(them)))
|
||||
&& (squares_behind(us, s) & pos.pieces(ROOK, QUEEN, them)))
|
||||
b3 = b2;
|
||||
|
||||
// Squares attacked or occupied by enemy pieces
|
||||
b3 |= (b2 & pos.pieces_of_color(them));
|
||||
|
||||
// There are no enemy pawns in the pawn's path
|
||||
assert((b2 & pos.pieces_of_color_and_type(them, PAWN)) == EmptyBoardBB);
|
||||
assert((b2 & pos.pieces(PAWN, them)) == EmptyBoardBB);
|
||||
|
||||
// Are any of the squares in the pawn's path attacked or occupied by the enemy?
|
||||
if (b3 == EmptyBoardBB)
|
||||
@@ -963,10 +963,10 @@ namespace {
|
||||
}
|
||||
|
||||
// If the pawn is supported by a friendly pawn, increase bonus
|
||||
b2 = pos.pawns(us) & neighboring_files_bb(s);
|
||||
b2 = pos.pieces(PAWN, us) & neighboring_files_bb(s);
|
||||
if (b2 & rank_bb(s))
|
||||
ebonus += Value(r * 20);
|
||||
else if (pos.pawn_attacks(them, s) & b2)
|
||||
else if (pos.attacks_from<PAWN>(s, them) & b2)
|
||||
ebonus += Value(r * 12);
|
||||
|
||||
// If the other side has only a king, check whether the pawn is
|
||||
@@ -1005,7 +1005,7 @@ namespace {
|
||||
if ( pos.non_pawn_material(them) <= KnightValueMidgame
|
||||
&& pos.piece_count(them, KNIGHT) <= 1)
|
||||
ebonus += ebonus / 4;
|
||||
else if (pos.rooks_and_queens(them))
|
||||
else if (pos.pieces(ROOK, QUEEN, them))
|
||||
ebonus -= ebonus / 4;
|
||||
}
|
||||
|
||||
@@ -1033,7 +1033,7 @@ namespace {
|
||||
// side wins.
|
||||
if (movesToGo[WHITE] <= movesToGo[BLACK] - 3)
|
||||
ei.egValue += UnstoppablePawnValue - Value(0x40 * (movesToGo[WHITE]/2));
|
||||
else if(movesToGo[BLACK] <= movesToGo[WHITE] - 3)
|
||||
else if (movesToGo[BLACK] <= movesToGo[WHITE] - 3)
|
||||
ei.egValue -= UnstoppablePawnValue - Value(0x40 * (movesToGo[BLACK]/2));
|
||||
|
||||
// We could also add some rules about the situation when one side
|
||||
@@ -1049,8 +1049,8 @@ namespace {
|
||||
// (a2/h2 for black) is trapped by enemy pawns, and assigns a penalty
|
||||
// if it is.
|
||||
|
||||
void evaluate_trapped_bishop_a7h7(const Position &pos, Square s, Color us,
|
||||
EvalInfo &ei) {
|
||||
void evaluate_trapped_bishop_a7h7(const Position& pos, Square s, Color us, EvalInfo &ei) {
|
||||
|
||||
assert(square_is_ok(s));
|
||||
assert(pos.piece_on(s) == piece_of_color_and_type(us, BISHOP));
|
||||
|
||||
@@ -1069,11 +1069,11 @@ namespace {
|
||||
|
||||
// evaluate_trapped_bishop_a1h1() determines whether a bishop on a1/h1
|
||||
// (a8/h8 for black) is trapped by a friendly pawn on b2/g2 (b7/g7 for
|
||||
// black), and assigns a penalty if it is. This pattern can obviously
|
||||
// black), and assigns a penalty if it is. This pattern can obviously
|
||||
// only occur in Chess960 games.
|
||||
|
||||
void evaluate_trapped_bishop_a1h1(const Position &pos, Square s, Color us,
|
||||
EvalInfo &ei) {
|
||||
void evaluate_trapped_bishop_a1h1(const Position& pos, Square s, Color us, EvalInfo& ei) {
|
||||
|
||||
Piece pawn = piece_of_color_and_type(us, PAWN);
|
||||
Square b2, b3, c3;
|
||||
|
||||
@@ -1117,38 +1117,30 @@ namespace {
|
||||
// squares one, two or three squares behind a friendly pawn are counted
|
||||
// twice. Finally, the space bonus is scaled by a weight taken from the
|
||||
// material hash table.
|
||||
template<bool HasPopCnt>
|
||||
void evaluate_space(const Position &pos, Color us, EvalInfo &ei) {
|
||||
template<Color Us, bool HasPopCnt>
|
||||
void evaluate_space(const Position& pos, EvalInfo& ei) {
|
||||
|
||||
Color them = opposite_color(us);
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
|
||||
// Find the safe squares for our pieces inside the area defined by
|
||||
// SpaceMask[us]. A square is unsafe it is attacked by an enemy
|
||||
// SpaceMask[us]. A square is unsafe if it is attacked by an enemy
|
||||
// pawn, or if it is undefended and attacked by an enemy piece.
|
||||
|
||||
Bitboard safeSquares = SpaceMask[us]
|
||||
& ~pos.pawns(us)
|
||||
& ~ei.attacked_by(them, PAWN)
|
||||
& ~(~ei.attacked_by(us) & ei.attacked_by(them));
|
||||
Bitboard safeSquares = SpaceMask[Us]
|
||||
& ~pos.pieces(PAWN, Us)
|
||||
& ~ei.attacked_by(Them, PAWN)
|
||||
& ~(~ei.attacked_by(Us) & ei.attacked_by(Them));
|
||||
|
||||
// Find all squares which are at most three squares behind some friendly
|
||||
// pawn.
|
||||
Bitboard behindFriendlyPawns = pos.pawns(us);
|
||||
if (us == WHITE)
|
||||
{
|
||||
behindFriendlyPawns |= (behindFriendlyPawns >> 8);
|
||||
behindFriendlyPawns |= (behindFriendlyPawns >> 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
behindFriendlyPawns |= (behindFriendlyPawns << 8);
|
||||
behindFriendlyPawns |= (behindFriendlyPawns << 16);
|
||||
}
|
||||
Bitboard behindFriendlyPawns = pos.pieces(PAWN, Us);
|
||||
behindFriendlyPawns |= (Us == WHITE ? behindFriendlyPawns >> 8 : behindFriendlyPawns << 8);
|
||||
behindFriendlyPawns |= (Us == WHITE ? behindFriendlyPawns >> 16 : behindFriendlyPawns << 16);
|
||||
|
||||
int space = count_1s_max_15<HasPopCnt>(safeSquares)
|
||||
+ count_1s_max_15<HasPopCnt>(behindFriendlyPawns & safeSquares);
|
||||
|
||||
ei.mgValue += Sign[us] * apply_weight(Value(space * ei.mi->space_weight()), WeightSpace);
|
||||
ei.mgValue += Sign[Us] * apply_weight(Value(space * ei.mi->space_weight()), WeightSpace);
|
||||
}
|
||||
|
||||
|
||||
@@ -1176,23 +1168,17 @@ namespace {
|
||||
}
|
||||
|
||||
|
||||
// compute_weight() computes the value of an evaluation weight, by combining
|
||||
// weight_option() computes the value of an evaluation weight, by combining
|
||||
// an UCI-configurable weight with an internal weight.
|
||||
|
||||
int compute_weight(int uciWeight, int internalWeight) {
|
||||
int weight_option(const std::string& opt, int internalWeight) {
|
||||
|
||||
int uciWeight = get_option_value_int(opt);
|
||||
uciWeight = (uciWeight * 0x100) / 100;
|
||||
return (uciWeight * internalWeight) / 0x100;
|
||||
}
|
||||
|
||||
|
||||
// helper used in read_weights()
|
||||
int weight_option(const std::string& opt, int weight) {
|
||||
|
||||
return compute_weight(get_option_value_int(opt), weight);
|
||||
}
|
||||
|
||||
|
||||
// init_safety() initizes the king safety evaluation, based on UCI
|
||||
// parameters. It is called from read_weights().
|
||||
|
||||
@@ -1217,9 +1203,9 @@ namespace {
|
||||
{
|
||||
if (i < b)
|
||||
SafetyTable[i] = Value(0);
|
||||
else if(quad)
|
||||
else if (quad)
|
||||
SafetyTable[i] = Value((int)(a * (i - b) * (i - b)));
|
||||
else if(linear)
|
||||
else if (linear)
|
||||
SafetyTable[i] = Value((int)(100 * a * (i - b)));
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +86,9 @@ typedef pthread_mutex_t Lock;
|
||||
|
||||
#else
|
||||
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
typedef CRITICAL_SECTION Lock;
|
||||
# define lock_init(x, y) InitializeCriticalSection(x)
|
||||
|
||||
273
src/material.cpp
273
src/material.cpp
@@ -28,7 +28,8 @@
|
||||
|
||||
#include "material.h"
|
||||
|
||||
using std::string;
|
||||
using namespace std;
|
||||
|
||||
|
||||
////
|
||||
//// Local definitions
|
||||
@@ -36,68 +37,91 @@ using std::string;
|
||||
|
||||
namespace {
|
||||
|
||||
// Values modified by Joona Kiiski
|
||||
const Value BishopPairMidgameBonus = Value(109);
|
||||
const Value BishopPairEndgameBonus = Value(97);
|
||||
// Polynomial material balance parameters
|
||||
const Value RedundantQueenPenalty = Value(320);
|
||||
const Value RedundantRookPenalty = Value(554);
|
||||
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
||||
|
||||
Key KNNKMaterialKey, KKNNMaterialKey;
|
||||
const int QuadraticCoefficientsSameColor[][6] = {
|
||||
{ 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 },
|
||||
{ 7, 25, 4, 7, 7, 7 }, { -27, -2, 46, 100, 56, 7 }, { 58, 29, 83, 148, -3, -25 } };
|
||||
|
||||
const int QuadraticCoefficientsOppositeColor[][6] = {
|
||||
{ 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 },
|
||||
{ 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } };
|
||||
|
||||
// Named endgame evaluation and scaling functions, these
|
||||
// are accessed direcly and not through the function maps.
|
||||
EvaluationFunction<KmmKm> EvaluateKmmKm(WHITE);
|
||||
EvaluationFunction<KXK> EvaluateKXK(WHITE), EvaluateKKX(BLACK);
|
||||
ScalingFunction<KBPsK> ScaleKBPsK(WHITE), ScaleKKBPs(BLACK);
|
||||
ScalingFunction<KQKRPs> ScaleKQKRPs(WHITE), ScaleKRPsKQ(BLACK);
|
||||
ScalingFunction<KPsK> ScaleKPsK(WHITE), ScaleKKPs(BLACK);
|
||||
ScalingFunction<KPKP> ScaleKPKPw(WHITE), ScaleKPKPb(BLACK);
|
||||
|
||||
typedef EndgameEvaluationFunctionBase EF;
|
||||
typedef EndgameScalingFunctionBase SF;
|
||||
}
|
||||
|
||||
|
||||
////
|
||||
//// Classes
|
||||
////
|
||||
|
||||
|
||||
/// See header for a class description. It is declared here to avoid
|
||||
/// to include <map> in the header file.
|
||||
/// EndgameFunctions class stores endgame evaluation and scaling functions
|
||||
/// in two std::map. Because STL library is not guaranteed to be thread
|
||||
/// safe even for read access, the maps, although with identical content,
|
||||
/// are replicated for each thread. This is faster then using locks.
|
||||
|
||||
class EndgameFunctions {
|
||||
|
||||
public:
|
||||
EndgameFunctions();
|
||||
EndgameEvaluationFunctionBase* getEEF(Key key) const;
|
||||
EndgameScalingFunctionBase* getESF(Key key, Color* c) const;
|
||||
~EndgameFunctions();
|
||||
template<class T> T* get(Key key) const;
|
||||
|
||||
private:
|
||||
void add(const string& keyCode, EndgameEvaluationFunctionBase* f);
|
||||
void add(const string& keyCode, Color c, EndgameScalingFunctionBase* f);
|
||||
Key buildKey(const string& keyCode);
|
||||
template<class T> void add(const string& keyCode);
|
||||
|
||||
struct ScalingInfo
|
||||
{
|
||||
Color col;
|
||||
EndgameScalingFunctionBase* fun;
|
||||
};
|
||||
static Key buildKey(const string& keyCode);
|
||||
static const string swapColors(const string& keyCode);
|
||||
|
||||
std::map<Key, EndgameEvaluationFunctionBase*> EEFmap;
|
||||
std::map<Key, ScalingInfo> ESFmap;
|
||||
// Here we store two maps, for evaluate and scaling functions
|
||||
pair<map<Key, EF*>, map<Key, SF*> > maps;
|
||||
|
||||
// Maps accessing functions returning const and non-const references
|
||||
template<typename T> const map<Key, T*>& get() const { return maps.first; }
|
||||
template<typename T> map<Key, T*>& get() { return maps.first; }
|
||||
};
|
||||
|
||||
// Explicit specializations of a member function shall be declared in
|
||||
// the namespace of which the class template is a member.
|
||||
template<> const map<Key, SF*>&
|
||||
EndgameFunctions::get<SF>() const { return maps.second; }
|
||||
|
||||
template<> map<Key, SF*>&
|
||||
EndgameFunctions::get<SF>() { return maps.second; }
|
||||
|
||||
|
||||
////
|
||||
//// Functions
|
||||
////
|
||||
|
||||
|
||||
/// Constructor for the MaterialInfoTable class
|
||||
/// MaterialInfoTable c'tor and d'tor, called once by each thread
|
||||
|
||||
MaterialInfoTable::MaterialInfoTable(unsigned int numOfEntries) {
|
||||
|
||||
size = numOfEntries;
|
||||
entries = new MaterialInfo[size];
|
||||
funcs = new EndgameFunctions();
|
||||
|
||||
if (!entries || !funcs)
|
||||
{
|
||||
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(MaterialInfo))
|
||||
<< " bytes for material hash table." << std::endl;
|
||||
cerr << "Failed to allocate " << numOfEntries * sizeof(MaterialInfo)
|
||||
<< " bytes for material hash table." << endl;
|
||||
Application::exit_with_failure();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Destructor for the MaterialInfoTable class
|
||||
|
||||
MaterialInfoTable::~MaterialInfoTable() {
|
||||
|
||||
delete funcs;
|
||||
@@ -127,18 +151,10 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
mi->clear();
|
||||
mi->key = key;
|
||||
|
||||
// A special case before looking for a specialized evaluation function
|
||||
// KNN vs K is a draw.
|
||||
if (key == KNNKMaterialKey || key == KKNNMaterialKey)
|
||||
{
|
||||
mi->factor[WHITE] = mi->factor[BLACK] = 0;
|
||||
return mi;
|
||||
}
|
||||
|
||||
// Let's look if we have a specialized evaluation function for this
|
||||
// particular material configuration. First we look for a fixed
|
||||
// configuration one, then a generic one if previous search failed.
|
||||
if ((mi->evaluationFunction = funcs->getEEF(key)) != NULL)
|
||||
if ((mi->evaluationFunction = funcs->get<EF>(key)) != NULL)
|
||||
return mi;
|
||||
|
||||
else if ( pos.non_pawn_material(BLACK) == Value(0)
|
||||
@@ -155,14 +171,14 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
mi->evaluationFunction = &EvaluateKKX;
|
||||
return mi;
|
||||
}
|
||||
else if ( pos.pawns() == EmptyBoardBB
|
||||
&& pos.rooks() == EmptyBoardBB
|
||||
&& pos.queens() == EmptyBoardBB)
|
||||
else if ( pos.pieces(PAWN) == EmptyBoardBB
|
||||
&& pos.pieces(ROOK) == EmptyBoardBB
|
||||
&& pos.pieces(QUEEN) == EmptyBoardBB)
|
||||
{
|
||||
// Minor piece endgame with at least one minor piece per side,
|
||||
// and no pawns.
|
||||
assert(pos.knights(WHITE) | pos.bishops(WHITE));
|
||||
assert(pos.knights(BLACK) | pos.bishops(BLACK));
|
||||
// Minor piece endgame with at least one minor piece per side and
|
||||
// no pawns. Note that the case KmmK is already handled by KXK.
|
||||
assert((pos.pieces(KNIGHT, WHITE) | pos.pieces(BISHOP, WHITE)));
|
||||
assert((pos.pieces(KNIGHT, BLACK) | pos.pieces(BISHOP, BLACK)));
|
||||
|
||||
if ( pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
|
||||
&& pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
|
||||
@@ -176,41 +192,43 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
// material configuration. Is there a suitable scaling function?
|
||||
//
|
||||
// The code below is rather messy, and it could easily get worse later,
|
||||
// if we decide to add more special cases. We face problems when there
|
||||
// if we decide to add more special cases. We face problems when there
|
||||
// are several conflicting applicable scaling functions and we need to
|
||||
// decide which one to use.
|
||||
Color c;
|
||||
EndgameScalingFunctionBase* sf;
|
||||
SF* sf;
|
||||
|
||||
if ((sf = funcs->getESF(key, &c)) != NULL)
|
||||
if ((sf = funcs->get<SF>(key)) != NULL)
|
||||
{
|
||||
mi->scalingFunction[c] = sf;
|
||||
mi->scalingFunction[sf->color()] = sf;
|
||||
return mi;
|
||||
}
|
||||
|
||||
// Generic scaling functions that refer to more then one material
|
||||
// distribution. Should be probed after the specialized ones.
|
||||
// Note that these ones don't return after setting the function.
|
||||
if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
|
||||
&& pos.piece_count(WHITE, BISHOP) == 1
|
||||
&& pos.piece_count(WHITE, PAWN) >= 1)
|
||||
mi->scalingFunction[WHITE] = &ScaleKBPK;
|
||||
mi->scalingFunction[WHITE] = &ScaleKBPsK;
|
||||
|
||||
if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
|
||||
&& pos.piece_count(BLACK, BISHOP) == 1
|
||||
&& pos.piece_count(BLACK, PAWN) >= 1)
|
||||
mi->scalingFunction[BLACK] = &ScaleKKBP;
|
||||
mi->scalingFunction[BLACK] = &ScaleKKBPs;
|
||||
|
||||
if ( pos.piece_count(WHITE, PAWN) == 0
|
||||
&& pos.non_pawn_material(WHITE) == QueenValueMidgame
|
||||
&& pos.piece_count(WHITE, QUEEN) == 1
|
||||
&& pos.piece_count(BLACK, ROOK) == 1
|
||||
&& pos.piece_count(BLACK, PAWN) >= 1)
|
||||
mi->scalingFunction[WHITE] = &ScaleKQKRP;
|
||||
mi->scalingFunction[WHITE] = &ScaleKQKRPs;
|
||||
|
||||
else if ( pos.piece_count(BLACK, PAWN) == 0
|
||||
&& pos.non_pawn_material(BLACK) == QueenValueMidgame
|
||||
&& pos.piece_count(BLACK, QUEEN) == 1
|
||||
&& pos.piece_count(WHITE, ROOK) == 1
|
||||
&& pos.piece_count(WHITE, PAWN) >= 1)
|
||||
mi->scalingFunction[BLACK] = &ScaleKRPKQ;
|
||||
mi->scalingFunction[BLACK] = &ScaleKRPsKQ;
|
||||
|
||||
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
|
||||
{
|
||||
@@ -226,6 +244,8 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
}
|
||||
else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
|
||||
{
|
||||
// This is a special case because we set scaling functions
|
||||
// for both colors instead of only one.
|
||||
mi->scalingFunction[WHITE] = &ScaleKPKPw;
|
||||
mi->scalingFunction[BLACK] = &ScaleKPKPb;
|
||||
}
|
||||
@@ -244,10 +264,13 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
}
|
||||
|
||||
// Evaluate the material balance
|
||||
|
||||
const int pieceCount[2][6] = { { pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT),
|
||||
pos.piece_count(WHITE, BISHOP), pos.piece_count(WHITE, ROOK), pos.piece_count(WHITE, QUEEN) },
|
||||
{ pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
|
||||
pos.piece_count(BLACK, BISHOP), pos.piece_count(BLACK, ROOK), pos.piece_count(BLACK, QUEEN) } };
|
||||
Color c, them;
|
||||
int sign;
|
||||
Value egValue = Value(0);
|
||||
Value mgValue = Value(0);
|
||||
int matValue = 0;
|
||||
|
||||
for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
|
||||
{
|
||||
@@ -274,73 +297,67 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||
}
|
||||
}
|
||||
|
||||
// Bishop pair
|
||||
if (pos.piece_count(c, BISHOP) >= 2)
|
||||
{
|
||||
mgValue += sign * BishopPairMidgameBonus;
|
||||
egValue += sign * BishopPairEndgameBonus;
|
||||
}
|
||||
|
||||
// Knights are stronger when there are many pawns on the board. The
|
||||
// formula is taken from Larry Kaufman's paper "The Evaluation of Material
|
||||
// Imbalances in Chess":
|
||||
// Redundancy of major pieces, formula based on Kaufman's paper
|
||||
// "The Evaluation of Material Imbalances in Chess"
|
||||
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
|
||||
mgValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
|
||||
egValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
|
||||
if (pieceCount[c][ROOK] >= 1)
|
||||
matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);
|
||||
|
||||
// Redundancy of major pieces, again based on Kaufman's paper:
|
||||
if (pos.piece_count(c, ROOK) >= 1)
|
||||
them = opposite_color(c);
|
||||
|
||||
// Second-degree polynomial material imbalance by Tord Romstad
|
||||
//
|
||||
// We use NO_PIECE_TYPE as a place holder for the bishop pair "extended piece",
|
||||
// this allow us to be more flexible in defining bishop pair bonuses.
|
||||
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
||||
{
|
||||
Value v = Value((pos.piece_count(c, ROOK) - 1) * 32 + pos.piece_count(c, QUEEN) * 16);
|
||||
mgValue -= sign * v;
|
||||
egValue -= sign * v;
|
||||
int c1 = sign * pieceCount[c][pt1];
|
||||
if (!c1)
|
||||
continue;
|
||||
|
||||
matValue += c1 * LinearCoefficients[pt1];
|
||||
|
||||
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
|
||||
{
|
||||
matValue += c1 * pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2];
|
||||
matValue += c1 * pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];
|
||||
}
|
||||
}
|
||||
}
|
||||
mi->mgValue = int16_t(mgValue);
|
||||
mi->egValue = int16_t(egValue);
|
||||
mi->value = int16_t(matValue / 16);
|
||||
return mi;
|
||||
}
|
||||
|
||||
|
||||
/// EndgameFunctions member definitions. This class is used to store the maps
|
||||
/// of end game and scaling functions that MaterialInfoTable will query for
|
||||
/// each key. The maps are constant and are populated only at construction,
|
||||
/// but are per-thread instead of globals to avoid expensive locks.
|
||||
/// EndgameFunctions member definitions.
|
||||
|
||||
EndgameFunctions::EndgameFunctions() {
|
||||
|
||||
KNNKMaterialKey = buildKey("KNNK");
|
||||
KKNNMaterialKey = buildKey("KKNN");
|
||||
add<EvaluationFunction<KNNK> >("KNNK");
|
||||
add<EvaluationFunction<KPK> >("KPK");
|
||||
add<EvaluationFunction<KBNK> >("KBNK");
|
||||
add<EvaluationFunction<KRKP> >("KRKP");
|
||||
add<EvaluationFunction<KRKB> >("KRKB");
|
||||
add<EvaluationFunction<KRKN> >("KRKN");
|
||||
add<EvaluationFunction<KQKR> >("KQKR");
|
||||
add<EvaluationFunction<KBBKN> >("KBBKN");
|
||||
|
||||
add("KPK", &EvaluateKPK);
|
||||
add("KKP", &EvaluateKKP);
|
||||
add("KBNK", &EvaluateKBNK);
|
||||
add("KKBN", &EvaluateKKBN);
|
||||
add("KRKP", &EvaluateKRKP);
|
||||
add("KPKR", &EvaluateKPKR);
|
||||
add("KRKB", &EvaluateKRKB);
|
||||
add("KBKR", &EvaluateKBKR);
|
||||
add("KRKN", &EvaluateKRKN);
|
||||
add("KNKR", &EvaluateKNKR);
|
||||
add("KQKR", &EvaluateKQKR);
|
||||
add("KRKQ", &EvaluateKRKQ);
|
||||
add("KBBKN", &EvaluateKBBKN);
|
||||
add("KNKBB", &EvaluateKNKBB);
|
||||
add<ScalingFunction<KNPK> >("KNPK");
|
||||
add<ScalingFunction<KRPKR> >("KRPKR");
|
||||
add<ScalingFunction<KBPKB> >("KBPKB");
|
||||
add<ScalingFunction<KBPPKB> >("KBPPKB");
|
||||
add<ScalingFunction<KBPKN> >("KBPKN");
|
||||
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||
}
|
||||
|
||||
add("KNPK", WHITE, &ScaleKNPK);
|
||||
add("KKNP", BLACK, &ScaleKKNP);
|
||||
add("KRPKR", WHITE, &ScaleKRPKR);
|
||||
add("KRKRP", BLACK, &ScaleKRKRP);
|
||||
add("KBPKB", WHITE, &ScaleKBPKB);
|
||||
add("KBKBP", BLACK, &ScaleKBKBP);
|
||||
add("KBPPKB", WHITE, &ScaleKBPPKB);
|
||||
add("KBKBPP", BLACK, &ScaleKBKBPP);
|
||||
add("KBPKN", WHITE, &ScaleKBPKN);
|
||||
add("KNKBP", BLACK, &ScaleKNKBP);
|
||||
add("KRPPKRP", WHITE, &ScaleKRPPKRP);
|
||||
add("KRPKRPP", BLACK, &ScaleKRPKRPP);
|
||||
add("KRPPKRP", WHITE, &ScaleKRPPKRP);
|
||||
add("KRPKRPP", BLACK, &ScaleKRPKRPP);
|
||||
EndgameFunctions::~EndgameFunctions() {
|
||||
|
||||
for (map<Key, EF*>::iterator it = maps.first.begin(); it != maps.first.end(); ++it)
|
||||
delete (*it).second;
|
||||
|
||||
for (map<Key, SF*>::iterator it = maps.second.begin(); it != maps.second.end(); ++it)
|
||||
delete (*it).second;
|
||||
}
|
||||
|
||||
Key EndgameFunctions::buildKey(const string& keyCode) {
|
||||
@@ -348,11 +365,11 @@ Key EndgameFunctions::buildKey(const string& keyCode) {
|
||||
assert(keyCode.length() > 0 && keyCode[0] == 'K');
|
||||
assert(keyCode.length() < 8);
|
||||
|
||||
std::stringstream s;
|
||||
stringstream s;
|
||||
bool upcase = false;
|
||||
|
||||
// Build up a fen substring with the given pieces, note
|
||||
// that the fen string could be of an illegal position.
|
||||
// Build up a fen string with the given pieces, note that
|
||||
// the fen string could be of an illegal position.
|
||||
for (size_t i = 0; i < keyCode.length(); i++)
|
||||
{
|
||||
if (keyCode[i] == 'K')
|
||||
@@ -364,29 +381,25 @@ Key EndgameFunctions::buildKey(const string& keyCode) {
|
||||
return Position(s.str()).get_material_key();
|
||||
}
|
||||
|
||||
void EndgameFunctions::add(const string& keyCode, EndgameEvaluationFunctionBase* f) {
|
||||
const string EndgameFunctions::swapColors(const string& keyCode) {
|
||||
|
||||
EEFmap.insert(std::pair<Key, EndgameEvaluationFunctionBase*>(buildKey(keyCode), f));
|
||||
// Build corresponding key for the opposite color: "KBPKN" -> "KNKBP"
|
||||
size_t idx = keyCode.find("K", 1);
|
||||
return keyCode.substr(idx) + keyCode.substr(0, idx);
|
||||
}
|
||||
|
||||
void EndgameFunctions::add(const string& keyCode, Color c, EndgameScalingFunctionBase* f) {
|
||||
template<class T>
|
||||
void EndgameFunctions::add(const string& keyCode) {
|
||||
|
||||
ScalingInfo s = {c, f};
|
||||
ESFmap.insert(std::pair<Key, ScalingInfo>(buildKey(keyCode), s));
|
||||
typedef typename T::Base F;
|
||||
|
||||
get<F>().insert(pair<Key, F*>(buildKey(keyCode), new T(WHITE)));
|
||||
get<F>().insert(pair<Key, F*>(buildKey(swapColors(keyCode)), new T(BLACK)));
|
||||
}
|
||||
|
||||
EndgameEvaluationFunctionBase* EndgameFunctions::getEEF(Key key) const {
|
||||
template<class T>
|
||||
T* EndgameFunctions::get(Key key) const {
|
||||
|
||||
std::map<Key, EndgameEvaluationFunctionBase*>::const_iterator it(EEFmap.find(key));
|
||||
return (it != EEFmap.end() ? it->second : NULL);
|
||||
}
|
||||
|
||||
EndgameScalingFunctionBase* EndgameFunctions::getESF(Key key, Color* c) const {
|
||||
|
||||
std::map<Key, ScalingInfo>::const_iterator it(ESFmap.find(key));
|
||||
if (it == ESFmap.end())
|
||||
return NULL;
|
||||
|
||||
*c = it->second.col;
|
||||
return it->second.fun;
|
||||
typename map<Key, T*>::const_iterator it(get<T>().find(key));
|
||||
return (it != get<T>().end() ? it->second : NULL);
|
||||
}
|
||||
|
||||
@@ -51,8 +51,7 @@ class MaterialInfo {
|
||||
public:
|
||||
MaterialInfo() : key(0) { clear(); }
|
||||
|
||||
Value mg_value() const;
|
||||
Value eg_value() const;
|
||||
Value material_value() const;
|
||||
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
||||
int space_weight() const;
|
||||
bool specialized_eval_exists() const;
|
||||
@@ -62,27 +61,18 @@ private:
|
||||
inline void clear();
|
||||
|
||||
Key key;
|
||||
int16_t mgValue;
|
||||
int16_t egValue;
|
||||
int16_t value;
|
||||
uint8_t factor[2];
|
||||
EndgameEvaluationFunctionBase* evaluationFunction;
|
||||
EndgameScalingFunctionBase* scalingFunction[2];
|
||||
int spaceWeight;
|
||||
};
|
||||
|
||||
|
||||
/// EndgameFunctions class stores the endgame evaluation functions std::map.
|
||||
/// Because STL library is not thread safe even for read access, the maps,
|
||||
/// although with identical content, are replicated for each thread. This
|
||||
/// is faster then using locks with an unique set of global maps.
|
||||
|
||||
class EndgameFunctions;
|
||||
|
||||
|
||||
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
||||
/// just an array of MaterialInfo objects and a few methods for accessing these
|
||||
/// objects. The most important method is get_material_info, which looks up a
|
||||
/// position in the table and returns a pointer to a MaterialInfo object.
|
||||
class EndgameFunctions;
|
||||
|
||||
class MaterialInfoTable {
|
||||
|
||||
@@ -102,17 +92,12 @@ private:
|
||||
//// Inline functions
|
||||
////
|
||||
|
||||
/// MaterialInfo::mg_value and MaterialInfo::eg_value simply returns the
|
||||
/// material balance evaluation for the middle game and the endgame.
|
||||
/// MaterialInfo::material_value simply returns the material balance
|
||||
/// evaluation that is independent from game phase.
|
||||
|
||||
inline Value MaterialInfo::mg_value() const {
|
||||
inline Value MaterialInfo::material_value() const {
|
||||
|
||||
return Value(mgValue);
|
||||
}
|
||||
|
||||
inline Value MaterialInfo::eg_value() const {
|
||||
|
||||
return Value(egValue);
|
||||
return Value(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +106,7 @@ inline Value MaterialInfo::eg_value() const {
|
||||
|
||||
inline void MaterialInfo::clear() {
|
||||
|
||||
mgValue = egValue = 0;
|
||||
value = 0;
|
||||
factor[WHITE] = factor[BLACK] = uint8_t(SCALE_FACTOR_NORMAL);
|
||||
evaluationFunction = NULL;
|
||||
scalingFunction[WHITE] = scalingFunction[BLACK] = NULL;
|
||||
|
||||
44
src/misc.cpp
44
src/misc.cpp
@@ -29,33 +29,10 @@
|
||||
# include <unistd.h>
|
||||
|
||||
#else
|
||||
/*
|
||||
(c) Copyright 1992 Eric Backus
|
||||
|
||||
This software may be used freely so long as this copyright notice is
|
||||
left intact. There is no warrantee on this software.
|
||||
*/
|
||||
# include <windows.h>
|
||||
# include <time.h>
|
||||
# include "dos.h"
|
||||
|
||||
static int gettimeofday(struct timeval* tp, struct timezone*)
|
||||
{
|
||||
SYSTEMTIME systime;
|
||||
|
||||
if (tp)
|
||||
{
|
||||
struct tm tmrec;
|
||||
time_t theTime = time(NULL);
|
||||
|
||||
tmrec = *localtime(&theTime);
|
||||
tp->tv_sec = mktime(&tmrec);
|
||||
GetLocalTime(&systime); /* system time */
|
||||
|
||||
tp->tv_usec = systime.wMilliseconds * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#include <windows.h>
|
||||
#include <sys/timeb.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -73,7 +50,7 @@ using namespace std;
|
||||
/// Version number. If this is left empty, the current date (in the format
|
||||
/// YYMMDD) is used as a version number.
|
||||
|
||||
static const string EngineVersion = "1.4";
|
||||
static const string EngineVersion = "1.5";
|
||||
static const string AppName = "Stockfish";
|
||||
static const string AppTag = "";
|
||||
|
||||
@@ -189,9 +166,16 @@ const string engine_name() {
|
||||
/// milliseconds.
|
||||
|
||||
int get_system_time() {
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return t.tv_sec*1000 + t.tv_usec/1000;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
struct _timeb t;
|
||||
_ftime(&t);
|
||||
return int(t.time*1000 + t.millitm);
|
||||
#else
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return t.tv_sec*1000 + t.tv_usec/1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
732
src/movegen.cpp
732
src/movegen.cpp
File diff suppressed because it is too large
Load Diff
@@ -32,12 +32,13 @@
|
||||
//// Prototypes
|
||||
////
|
||||
|
||||
extern int generate_captures(const Position& pos, MoveStack* mlist);
|
||||
extern int generate_noncaptures(const Position& pos, MoveStack* mlist);
|
||||
extern int generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc);
|
||||
extern int generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
|
||||
extern int generate_legal_moves(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_captures(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc);
|
||||
extern MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
|
||||
extern MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLegal = false);
|
||||
extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned);
|
||||
extern bool move_is_legal(const Position& pos, const Move m);
|
||||
|
||||
|
||||
#endif // !defined(MOVEGEN_H_INCLUDED)
|
||||
|
||||
562
src/movepick.cpp
562
src/movepick.cpp
@@ -27,7 +27,6 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "history.h"
|
||||
#include "evaluate.h"
|
||||
#include "movegen.h"
|
||||
#include "movepick.h"
|
||||
#include "search.h"
|
||||
@@ -40,14 +39,23 @@
|
||||
|
||||
namespace {
|
||||
|
||||
/// Variables
|
||||
|
||||
MovePicker::MovegenPhase PhaseTable[32];
|
||||
int MainSearchPhaseIndex;
|
||||
int EvasionsPhaseIndex;
|
||||
int QsearchWithChecksPhaseIndex;
|
||||
int QsearchWithoutChecksPhaseIndex;
|
||||
enum MovegenPhase {
|
||||
PH_TT_MOVES, // Transposition table move and mate killer
|
||||
PH_GOOD_CAPTURES, // Queen promotions and captures with SEE values >= 0
|
||||
PH_KILLERS, // Killer moves from the current ply
|
||||
PH_NONCAPTURES, // Non-captures and underpromotions
|
||||
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < 0
|
||||
PH_EVASIONS, // Check evasions
|
||||
PH_QCAPTURES, // Captures in quiescence search
|
||||
PH_QCHECKS, // Non-capture checks in quiescence search
|
||||
PH_STOP
|
||||
};
|
||||
|
||||
CACHE_LINE_ALIGNMENT
|
||||
const uint8_t MainSearchPhaseTable[] = { PH_TT_MOVES, PH_GOOD_CAPTURES, PH_KILLERS, PH_NONCAPTURES, PH_BAD_CAPTURES, PH_STOP};
|
||||
const uint8_t EvasionsPhaseTable[] = { PH_EVASIONS, PH_STOP};
|
||||
const uint8_t QsearchWithChecksPhaseTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_QCHECKS, PH_STOP};
|
||||
const uint8_t QsearchWithoutChecksPhaseTable[] = { PH_TT_MOVES, PH_QCAPTURES, PH_STOP};
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +64,7 @@ namespace {
|
||||
////
|
||||
|
||||
|
||||
/// Constructor for the MovePicker class. Apart from the position for which
|
||||
/// Constructor for the MovePicker class. Apart from the position for which
|
||||
/// it is asked to pick legal moves, MovePicker also wants some information
|
||||
/// 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
|
||||
@@ -65,142 +73,272 @@ namespace {
|
||||
|
||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
||||
const History& h, SearchStack* ss) : pos(p), H(h) {
|
||||
ttMove = ttm;
|
||||
int searchTT = ttm;
|
||||
ttMoves[0].move = ttm;
|
||||
finished = false;
|
||||
lastBadCapture = badCaptures;
|
||||
|
||||
if (ss)
|
||||
{
|
||||
mateKiller = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller;
|
||||
killer1 = ss->killers[0];
|
||||
killer2 = ss->killers[1];
|
||||
ttMoves[1].move = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller;
|
||||
searchTT |= ttMoves[1].move;
|
||||
killers[0].move = ss->killers[0];
|
||||
killers[1].move = ss->killers[1];
|
||||
} else
|
||||
mateKiller = killer1 = killer2 = MOVE_NONE;
|
||||
|
||||
movesPicked = numOfMoves = numOfBadCaptures = 0;
|
||||
checkKillers = checkLegal = finished = false;
|
||||
|
||||
if (p.is_check())
|
||||
phaseIndex = EvasionsPhaseIndex;
|
||||
else if (d > Depth(0))
|
||||
phaseIndex = MainSearchPhaseIndex;
|
||||
else if (d == Depth(0))
|
||||
phaseIndex = QsearchWithChecksPhaseIndex;
|
||||
else
|
||||
phaseIndex = QsearchWithoutChecksPhaseIndex;
|
||||
ttMoves[1].move = killers[0].move = killers[1].move = MOVE_NONE;
|
||||
|
||||
Color us = pos.side_to_move();
|
||||
|
||||
dc = p.discovered_check_candidates(us);
|
||||
pinned = p.pinned_pieces(us);
|
||||
|
||||
finished = false;
|
||||
if (p.is_check())
|
||||
phasePtr = EvasionsPhaseTable;
|
||||
else if (d > Depth(0))
|
||||
phasePtr = MainSearchPhaseTable + !searchTT;
|
||||
else if (d == Depth(0))
|
||||
phasePtr = QsearchWithChecksPhaseTable + !searchTT;
|
||||
else
|
||||
phasePtr = QsearchWithoutChecksPhaseTable + !searchTT;
|
||||
|
||||
phasePtr--;
|
||||
go_next_phase();
|
||||
}
|
||||
|
||||
|
||||
/// MovePicker::go_next_phase() generates, scores and sorts the next bunch
|
||||
/// of moves when there are no more moves to try for the current phase.
|
||||
|
||||
void MovePicker::go_next_phase() {
|
||||
|
||||
curMove = moves;
|
||||
phase = *(++phasePtr);
|
||||
switch (phase) {
|
||||
|
||||
case PH_TT_MOVES:
|
||||
curMove = ttMoves;
|
||||
lastMove = curMove + 2;
|
||||
return;
|
||||
|
||||
case PH_GOOD_CAPTURES:
|
||||
lastMove = generate_captures(pos, moves);
|
||||
score_captures();
|
||||
std::sort(moves, lastMove);
|
||||
return;
|
||||
|
||||
case PH_KILLERS:
|
||||
curMove = killers;
|
||||
lastMove = curMove + 2;
|
||||
return;
|
||||
|
||||
case PH_NONCAPTURES:
|
||||
lastMove = generate_noncaptures(pos, moves);
|
||||
score_noncaptures();
|
||||
std::sort(moves, lastMove);
|
||||
return;
|
||||
|
||||
case PH_BAD_CAPTURES:
|
||||
// Bad captures SEE value is already calculated so just sort them
|
||||
// to get SEE move ordering.
|
||||
curMove = badCaptures;
|
||||
lastMove = lastBadCapture;
|
||||
std::sort(badCaptures, lastMove);
|
||||
return;
|
||||
|
||||
case PH_EVASIONS:
|
||||
assert(pos.is_check());
|
||||
lastMove = generate_evasions(pos, moves, pinned);
|
||||
score_evasions();
|
||||
std::sort(moves, lastMove);
|
||||
return;
|
||||
|
||||
case PH_QCAPTURES:
|
||||
lastMove = generate_captures(pos, moves);
|
||||
score_captures();
|
||||
std::sort(moves, lastMove);
|
||||
return;
|
||||
|
||||
case PH_QCHECKS:
|
||||
// Perhaps we should order moves move here? FIXME
|
||||
lastMove = generate_non_capture_checks(pos, moves, dc);
|
||||
return;
|
||||
|
||||
case PH_STOP:
|
||||
lastMove = curMove + 1; // hack to be friendly for get_next_move()
|
||||
return;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// MovePicker::score_captures(), MovePicker::score_noncaptures() and
|
||||
/// MovePicker::score_evasions() assign a numerical move ordering score
|
||||
/// to each move in a move list. The moves with highest scores will be
|
||||
/// picked first by get_next_move().
|
||||
|
||||
void MovePicker::score_captures() {
|
||||
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
||||
// Suprisingly, this appears to perform slightly better than SEE based
|
||||
// move ordering. The reason is probably that in a position with a winning
|
||||
// capture, capturing a more valuable (but sufficiently defended) piece
|
||||
// first usually doesn't hurt. The opponent will have to recapture, and
|
||||
// the hanging piece will still be hanging (except in the unusual cases
|
||||
// where it is possible to recapture with the hanging piece). Exchanging
|
||||
// big pieces before capturing a hanging piece probably helps to reduce
|
||||
// the subtree size.
|
||||
// In main search we want to push captures with negative SEE values to
|
||||
// badCaptures[] array, but instead of doing it now we delay till when
|
||||
// the move has been picked up in pick_move_from_list(), this way we save
|
||||
// some SEE calls in case we get a cutoff (idea from Pablo Vazquez).
|
||||
Move m;
|
||||
|
||||
// Use MVV/LVA ordering
|
||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||
{
|
||||
m = cur->move;
|
||||
if (move_is_promotion(m))
|
||||
cur->score = QueenValueMidgame;
|
||||
else
|
||||
cur->score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
||||
-int(pos.type_of_piece_on(move_from(m)));
|
||||
}
|
||||
}
|
||||
|
||||
void MovePicker::score_noncaptures() {
|
||||
// First score by history, when no history is available then use
|
||||
// piece/square tables values. This seems to be better then a
|
||||
// random choice when we don't have an history for any move.
|
||||
Move m;
|
||||
Piece piece;
|
||||
Square from, to;
|
||||
int hs;
|
||||
|
||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||
{
|
||||
m = cur->move;
|
||||
from = move_from(m);
|
||||
to = move_to(m);
|
||||
piece = pos.piece_on(from);
|
||||
hs = H.move_ordering_score(piece, to);
|
||||
|
||||
// Ensure history is always preferred to pst
|
||||
if (hs > 0)
|
||||
hs += 1000;
|
||||
|
||||
// pst based scoring
|
||||
cur->score = hs + pos.pst_delta<Position::MidGame>(piece, from, to);
|
||||
}
|
||||
}
|
||||
|
||||
void MovePicker::score_evasions() {
|
||||
|
||||
Move m;
|
||||
|
||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||
{
|
||||
m = cur->move;
|
||||
if (m == ttMoves[0].move)
|
||||
cur->score = 2 * HistoryMax;
|
||||
else if (!pos.square_is_empty(move_to(m)))
|
||||
{
|
||||
int seeScore = pos.see(m);
|
||||
cur->score = seeScore + (seeScore >= 0 ? HistoryMax : 0);
|
||||
} else
|
||||
cur->score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
|
||||
}
|
||||
}
|
||||
|
||||
/// MovePicker::get_next_move() is the most important method of the MovePicker
|
||||
/// class. It returns a new legal move every time it is called, until there
|
||||
/// are no more moves left of the types we are interested in.
|
||||
/// class. It returns a new legal move every time it is called, until there
|
||||
/// are no more moves left.
|
||||
/// It picks the move with the biggest score from a list of generated moves taking
|
||||
/// care not to return the tt move if has already been searched previously.
|
||||
|
||||
Move MovePicker::get_next_move() {
|
||||
|
||||
assert(!pos.is_check() || *phasePtr == PH_EVASIONS || *phasePtr == PH_STOP);
|
||||
assert( pos.is_check() || *phasePtr != PH_EVASIONS);
|
||||
|
||||
Move move;
|
||||
|
||||
while (true)
|
||||
{
|
||||
// If we already have a list of generated moves, pick the best move from
|
||||
// the list, and return it.
|
||||
move = pick_move_from_list();
|
||||
if (move != MOVE_NONE)
|
||||
{
|
||||
assert(move_is_ok(move));
|
||||
return move;
|
||||
}
|
||||
while (curMove != lastMove)
|
||||
{
|
||||
move = (curMove++)->move;
|
||||
|
||||
// Next phase
|
||||
phaseIndex++;
|
||||
switch (PhaseTable[phaseIndex]) {
|
||||
switch (phase) {
|
||||
|
||||
case PH_TT_MOVE:
|
||||
if (ttMove != MOVE_NONE)
|
||||
{
|
||||
assert(move_is_ok(ttMove));
|
||||
if (move_is_legal(pos, ttMove, pinned))
|
||||
return ttMove;
|
||||
}
|
||||
break;
|
||||
case PH_TT_MOVES:
|
||||
if ( move != MOVE_NONE
|
||||
&& move_is_legal(pos, move, pinned))
|
||||
return move;
|
||||
break;
|
||||
|
||||
case PH_MATE_KILLER:
|
||||
if (mateKiller != MOVE_NONE)
|
||||
{
|
||||
assert(move_is_ok(mateKiller));
|
||||
if (move_is_legal(pos, mateKiller, pinned))
|
||||
return mateKiller;
|
||||
}
|
||||
break;
|
||||
case PH_GOOD_CAPTURES:
|
||||
if ( move != ttMoves[0].move
|
||||
&& move != ttMoves[1].move
|
||||
&& pos.pl_move_is_legal(move, pinned))
|
||||
{
|
||||
// Check for a non negative SEE now
|
||||
int seeValue = pos.see_sign(move);
|
||||
if (seeValue >= 0)
|
||||
return move;
|
||||
|
||||
case PH_GOOD_CAPTURES:
|
||||
numOfMoves = generate_captures(pos, moves);
|
||||
score_captures();
|
||||
std::sort(moves, moves + numOfMoves);
|
||||
movesPicked = 0;
|
||||
checkLegal = true;
|
||||
break;
|
||||
// Losing capture, move it to the badCaptures[] array, note
|
||||
// that move has now been already checked for legality.
|
||||
assert(int(lastBadCapture - badCaptures) < 63);
|
||||
lastBadCapture->move = move;
|
||||
lastBadCapture->score = seeValue;
|
||||
lastBadCapture++;
|
||||
}
|
||||
break;
|
||||
|
||||
case PH_KILLERS:
|
||||
movesPicked = numOfMoves = 0;
|
||||
checkLegal = false;
|
||||
if (killer1 != MOVE_NONE && move_is_legal(pos, killer1, pinned) && !pos.move_is_capture(killer1))
|
||||
moves[numOfMoves++].move = killer1;
|
||||
if (killer2 != MOVE_NONE && move_is_legal(pos, killer2, pinned) && !pos.move_is_capture(killer2) )
|
||||
moves[numOfMoves++].move = killer2;
|
||||
break;
|
||||
case PH_KILLERS:
|
||||
if ( move != MOVE_NONE
|
||||
&& move != ttMoves[0].move
|
||||
&& move != ttMoves[1].move
|
||||
&& move_is_legal(pos, move, pinned)
|
||||
&& !pos.move_is_capture(move))
|
||||
return move;
|
||||
break;
|
||||
|
||||
case PH_NONCAPTURES:
|
||||
checkKillers = (numOfMoves != 0); // previous phase is PH_KILLERS
|
||||
numOfMoves = generate_noncaptures(pos, moves);
|
||||
score_noncaptures();
|
||||
std::sort(moves, moves + numOfMoves);
|
||||
movesPicked = 0;
|
||||
checkLegal = true;
|
||||
break;
|
||||
case PH_NONCAPTURES:
|
||||
if ( move != ttMoves[0].move
|
||||
&& move != ttMoves[1].move
|
||||
&& move != killers[0].move
|
||||
&& move != killers[1].move
|
||||
&& pos.pl_move_is_legal(move, pinned))
|
||||
return move;
|
||||
break;
|
||||
|
||||
case PH_BAD_CAPTURES:
|
||||
// Bad captures SEE value is already calculated by score_captures()
|
||||
// so just sort them to get SEE move ordering.
|
||||
std::sort(badCaptures, badCaptures + numOfBadCaptures);
|
||||
movesPicked = 0;
|
||||
break;
|
||||
case PH_EVASIONS:
|
||||
case PH_BAD_CAPTURES:
|
||||
return move;
|
||||
|
||||
case PH_EVASIONS:
|
||||
assert(pos.is_check());
|
||||
numOfMoves = generate_evasions(pos, moves, pinned);
|
||||
score_evasions();
|
||||
std::sort(moves, moves + numOfMoves);
|
||||
movesPicked = 0;
|
||||
break;
|
||||
case PH_QCAPTURES:
|
||||
case PH_QCHECKS:
|
||||
// Maybe postpone the legality check until after futility pruning?
|
||||
if ( move != ttMoves[0].move
|
||||
&& pos.pl_move_is_legal(move, pinned))
|
||||
return move;
|
||||
break;
|
||||
|
||||
case PH_QCAPTURES:
|
||||
numOfMoves = generate_captures(pos, moves);
|
||||
score_qcaptures();
|
||||
std::sort(moves, moves + numOfMoves);
|
||||
movesPicked = 0;
|
||||
break;
|
||||
case PH_STOP:
|
||||
return MOVE_NONE;
|
||||
|
||||
case PH_QCHECKS:
|
||||
// Perhaps we should order moves move here? FIXME
|
||||
numOfMoves = generate_non_capture_checks(pos, moves, dc);
|
||||
movesPicked = 0;
|
||||
break;
|
||||
|
||||
case PH_STOP:
|
||||
return MOVE_NONE;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
return MOVE_NONE;
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
go_next_phase();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A variant of get_next_move() which takes a lock as a parameter, used to
|
||||
/// prevent multiple threads from picking the same move at a split point.
|
||||
|
||||
@@ -219,203 +357,3 @@ Move MovePicker::get_next_move(Lock &lock) {
|
||||
lock_release(&lock);
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/// MovePicker::score_captures(), MovePicker::score_noncaptures(),
|
||||
/// MovePicker::score_evasions() and MovePicker::score_qcaptures() assign a
|
||||
/// numerical move ordering score to each move in a move list. The moves
|
||||
/// with highest scores will be picked first by pick_move_from_list().
|
||||
|
||||
void MovePicker::score_captures() {
|
||||
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
||||
// Suprisingly, this appears to perform slightly better than SEE based
|
||||
// move ordering. The reason is probably that in a position with a winning
|
||||
// capture, capturing a more valuable (but sufficiently defended) piece
|
||||
// first usually doesn't hurt. The opponent will have to recapture, and
|
||||
// the hanging piece will still be hanging (except in the unusual cases
|
||||
// where it is possible to recapture with the hanging piece). Exchanging
|
||||
// big pieces before capturing a hanging piece probably helps to reduce
|
||||
// the subtree size.
|
||||
// While scoring captures it moves all captures with negative SEE values
|
||||
// to the badCaptures[] array.
|
||||
Move m;
|
||||
int seeValue;
|
||||
|
||||
for (int i = 0; i < numOfMoves; i++)
|
||||
{
|
||||
m = moves[i].move;
|
||||
seeValue = pos.see(m);
|
||||
if (seeValue >= 0)
|
||||
{
|
||||
if (move_is_promotion(m))
|
||||
moves[i].score = QueenValueMidgame;
|
||||
else
|
||||
moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
||||
-int(pos.type_of_piece_on(move_from(m)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Losing capture, move it to the badCaptures[] array
|
||||
assert(numOfBadCaptures < 63);
|
||||
moves[i].score = seeValue;
|
||||
badCaptures[numOfBadCaptures++] = moves[i];
|
||||
moves[i--] = moves[--numOfMoves];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MovePicker::score_noncaptures() {
|
||||
// First score by history, when no history is available then use
|
||||
// piece/square tables values. This seems to be better then a
|
||||
// random choice when we don't have an history for any move.
|
||||
Piece piece;
|
||||
Square from, to;
|
||||
int hs;
|
||||
|
||||
for (int i = 0; i < numOfMoves; i++)
|
||||
{
|
||||
from = move_from(moves[i].move);
|
||||
to = move_to(moves[i].move);
|
||||
piece = pos.piece_on(from);
|
||||
hs = H.move_ordering_score(piece, to);
|
||||
|
||||
// Ensure history is always preferred to pst
|
||||
if (hs > 0)
|
||||
hs += 1000;
|
||||
|
||||
// pst based scoring
|
||||
moves[i].score = hs + pos.pst_delta<Position::MidGame>(piece, from, to);
|
||||
}
|
||||
}
|
||||
|
||||
void MovePicker::score_evasions() {
|
||||
|
||||
for (int i = 0; i < numOfMoves; i++)
|
||||
{
|
||||
Move m = moves[i].move;
|
||||
if (m == ttMove)
|
||||
moves[i].score = 2*HistoryMax;
|
||||
else if (!pos.square_is_empty(move_to(m)))
|
||||
{
|
||||
int seeScore = pos.see(m);
|
||||
moves[i].score = (seeScore >= 0)? seeScore + HistoryMax : seeScore;
|
||||
} else
|
||||
moves[i].score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
|
||||
}
|
||||
}
|
||||
|
||||
void MovePicker::score_qcaptures() {
|
||||
|
||||
// Use MVV/LVA ordering
|
||||
for (int i = 0; i < numOfMoves; i++)
|
||||
{
|
||||
Move m = moves[i].move;
|
||||
if (move_is_promotion(m))
|
||||
moves[i].score = QueenValueMidgame;
|
||||
else
|
||||
moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
|
||||
-int(pos.type_of_piece_on(move_from(m)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// MovePicker::pick_move_from_list() picks the move with the biggest score
|
||||
/// from a list of generated moves (moves[] or badCaptures[], depending on
|
||||
/// the current move generation phase). It takes care not to return the
|
||||
/// transposition table move if that has already been serched previously.
|
||||
|
||||
Move MovePicker::pick_move_from_list() {
|
||||
|
||||
assert(movesPicked >= 0);
|
||||
assert(!pos.is_check() || PhaseTable[phaseIndex] == PH_EVASIONS || PhaseTable[phaseIndex] == PH_STOP);
|
||||
assert( pos.is_check() || PhaseTable[phaseIndex] != PH_EVASIONS);
|
||||
|
||||
switch (PhaseTable[phaseIndex]) {
|
||||
|
||||
case PH_GOOD_CAPTURES:
|
||||
case PH_KILLERS:
|
||||
case PH_NONCAPTURES:
|
||||
while (movesPicked < numOfMoves)
|
||||
{
|
||||
Move move = moves[movesPicked++].move;
|
||||
if ( move != ttMove
|
||||
&& move != mateKiller
|
||||
&& (!checkKillers || (move != killer1 && move != killer2))
|
||||
&& (!checkLegal || pos.pl_move_is_legal(move, pinned)))
|
||||
return move;
|
||||
}
|
||||
break;
|
||||
|
||||
case PH_EVASIONS:
|
||||
if (movesPicked < numOfMoves)
|
||||
return moves[movesPicked++].move;
|
||||
|
||||
break;
|
||||
|
||||
case PH_BAD_CAPTURES:
|
||||
while (movesPicked < numOfBadCaptures)
|
||||
{
|
||||
Move move = badCaptures[movesPicked++].move;
|
||||
if ( move != ttMove
|
||||
&& move != mateKiller
|
||||
&& pos.pl_move_is_legal(move, pinned))
|
||||
return move;
|
||||
}
|
||||
break;
|
||||
|
||||
case PH_QCAPTURES:
|
||||
case PH_QCHECKS:
|
||||
while (movesPicked < numOfMoves)
|
||||
{
|
||||
Move move = moves[movesPicked++].move;
|
||||
// Maybe postpone the legality check until after futility pruning?
|
||||
if ( move != ttMove
|
||||
&& pos.pl_move_is_legal(move, pinned))
|
||||
return move;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return MOVE_NONE;
|
||||
}
|
||||
|
||||
|
||||
/// MovePicker::init_phase_table() initializes the PhaseTable[],
|
||||
/// MainSearchPhaseIndex, EvasionPhaseIndex, QsearchWithChecksPhaseIndex
|
||||
/// and QsearchWithoutChecksPhaseIndex. It is only called once during
|
||||
/// program startup, and never again while the program is running.
|
||||
|
||||
void MovePicker::init_phase_table() {
|
||||
|
||||
int i = 0;
|
||||
|
||||
// Main search
|
||||
MainSearchPhaseIndex = i - 1;
|
||||
PhaseTable[i++] = PH_TT_MOVE;
|
||||
PhaseTable[i++] = PH_MATE_KILLER;
|
||||
PhaseTable[i++] = PH_GOOD_CAPTURES;
|
||||
PhaseTable[i++] = PH_KILLERS;
|
||||
PhaseTable[i++] = PH_NONCAPTURES;
|
||||
PhaseTable[i++] = PH_BAD_CAPTURES;
|
||||
PhaseTable[i++] = PH_STOP;
|
||||
|
||||
// Check evasions
|
||||
EvasionsPhaseIndex = i - 1;
|
||||
PhaseTable[i++] = PH_EVASIONS;
|
||||
PhaseTable[i++] = PH_STOP;
|
||||
|
||||
// Quiescence search with checks
|
||||
QsearchWithChecksPhaseIndex = i - 1;
|
||||
PhaseTable[i++] = PH_TT_MOVE;
|
||||
PhaseTable[i++] = PH_QCAPTURES;
|
||||
PhaseTable[i++] = PH_QCHECKS;
|
||||
PhaseTable[i++] = PH_STOP;
|
||||
|
||||
// Quiescence search without checks
|
||||
QsearchWithoutChecksPhaseIndex = i - 1;
|
||||
PhaseTable[i++] = PH_TT_MOVE;
|
||||
PhaseTable[i++] = PH_QCAPTURES;
|
||||
PhaseTable[i++] = PH_STOP;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
//// Types
|
||||
////
|
||||
|
||||
struct EvalInfo;
|
||||
struct SearchStack;
|
||||
|
||||
/// MovePicker is a class which is used to pick one legal move at a time from
|
||||
@@ -51,45 +50,27 @@ class MovePicker {
|
||||
MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
|
||||
|
||||
public:
|
||||
|
||||
enum MovegenPhase {
|
||||
PH_TT_MOVE, // Transposition table move
|
||||
PH_MATE_KILLER, // Mate killer from the current ply
|
||||
PH_GOOD_CAPTURES, // Queen promotions and captures with SEE values >= 0
|
||||
PH_KILLERS, // Killer moves from the current ply
|
||||
PH_NONCAPTURES, // Non-captures and underpromotions
|
||||
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < 0
|
||||
PH_EVASIONS, // Check evasions
|
||||
PH_QCAPTURES, // Captures in quiescence search
|
||||
PH_QCHECKS, // Non-capture checks in quiescence search
|
||||
PH_STOP
|
||||
};
|
||||
|
||||
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL);
|
||||
Move get_next_move();
|
||||
Move get_next_move(Lock& lock);
|
||||
int number_of_moves() const;
|
||||
int number_of_evasions() const;
|
||||
Bitboard discovered_check_candidates() const;
|
||||
|
||||
static void init_phase_table();
|
||||
|
||||
private:
|
||||
void score_captures();
|
||||
void score_noncaptures();
|
||||
void score_evasions();
|
||||
void score_qcaptures();
|
||||
Move pick_move_from_list();
|
||||
void go_next_phase();
|
||||
|
||||
const Position& pos;
|
||||
const History& H;
|
||||
Move ttMove, mateKiller, killer1, killer2;
|
||||
Bitboard pinned, dc;
|
||||
MoveStack moves[256], badCaptures[64];
|
||||
int phaseIndex;
|
||||
int numOfMoves, numOfBadCaptures;
|
||||
int movesPicked;
|
||||
bool checkKillers, checkLegal;
|
||||
MoveStack ttMoves[2], killers[2];
|
||||
bool finished;
|
||||
int phase;
|
||||
const uint8_t* phasePtr;
|
||||
MoveStack *curMove, *lastMove, *lastBadCapture;
|
||||
Bitboard dc, pinned;
|
||||
MoveStack moves[256], badCaptures[64];
|
||||
};
|
||||
|
||||
|
||||
@@ -97,13 +78,14 @@ private:
|
||||
//// Inline functions
|
||||
////
|
||||
|
||||
/// MovePicker::number_of_moves() simply returns the numOfMoves member
|
||||
/// variable. It is intended to be used in positions where the side to move
|
||||
/// is in check, for detecting checkmates or situations where there is only
|
||||
/// a single reply to check.
|
||||
/// MovePicker::number_of_evasions() simply returns the number of moves in
|
||||
/// evasions phase. It is intended to be used in positions where the side to
|
||||
/// move is in check, for detecting checkmates or situations where there is
|
||||
/// only a single reply to check.
|
||||
/// WARNING: It works as long as PH_EVASIONS is the _only_ phase for evasions.
|
||||
|
||||
inline int MovePicker::number_of_moves() const {
|
||||
return numOfMoves;
|
||||
inline int MovePicker::number_of_evasions() const {
|
||||
return int(lastMove - moves);
|
||||
}
|
||||
|
||||
/// MovePicker::discovered_check_candidates() returns a bitboard containing
|
||||
|
||||
156
src/pawns.cpp
156
src/pawns.cpp
@@ -23,6 +23,7 @@
|
||||
////
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "bitcount.h"
|
||||
#include "pawns.h"
|
||||
@@ -37,67 +38,67 @@ namespace {
|
||||
|
||||
/// Constants and variables
|
||||
|
||||
// Doubled pawn penalty by file, middle game.
|
||||
// Doubled pawn penalty by file, middle game
|
||||
const Value DoubledPawnMidgamePenalty[8] = {
|
||||
Value(13), Value(20), Value(23), Value(23),
|
||||
Value(23), Value(23), Value(20), Value(13)
|
||||
};
|
||||
|
||||
// Doubled pawn penalty by file, endgame.
|
||||
// Doubled pawn penalty by file, endgame
|
||||
const Value DoubledPawnEndgamePenalty[8] = {
|
||||
Value(43), Value(48), Value(48), Value(48),
|
||||
Value(48), Value(48), Value(48), Value(43)
|
||||
};
|
||||
|
||||
// Isolated pawn penalty by file, middle game.
|
||||
// Isolated pawn penalty by file, middle game
|
||||
const Value IsolatedPawnMidgamePenalty[8] = {
|
||||
Value(25), Value(36), Value(40), Value(40),
|
||||
Value(40), Value(40), Value(36), Value(25)
|
||||
};
|
||||
|
||||
// Isolated pawn penalty by file, endgame.
|
||||
// Isolated pawn penalty by file, endgame
|
||||
const Value IsolatedPawnEndgamePenalty[8] = {
|
||||
Value(30), Value(35), Value(35), Value(35),
|
||||
Value(35), Value(35), Value(35), Value(30)
|
||||
};
|
||||
|
||||
// Backward pawn penalty by file, middle game.
|
||||
// Backward pawn penalty by file, middle game
|
||||
const Value BackwardPawnMidgamePenalty[8] = {
|
||||
Value(20), Value(29), Value(33), Value(33),
|
||||
Value(33), Value(33), Value(29), Value(20)
|
||||
};
|
||||
|
||||
// Backward pawn penalty by file, endgame.
|
||||
// Backward pawn penalty by file, endgame
|
||||
const Value BackwardPawnEndgamePenalty[8] = {
|
||||
Value(28), Value(31), Value(31), Value(31),
|
||||
Value(31), Value(31), Value(31), Value(28)
|
||||
};
|
||||
|
||||
// Pawn chain membership bonus by file, middle game.
|
||||
// Pawn chain membership bonus by file, middle game
|
||||
const Value ChainMidgameBonus[8] = {
|
||||
Value(11), Value(13), Value(13), Value(14),
|
||||
Value(14), Value(13), Value(13), Value(11)
|
||||
};
|
||||
|
||||
// Pawn chain membership bonus by file, endgame.
|
||||
// Pawn chain membership bonus by file, endgame
|
||||
const Value ChainEndgameBonus[8] = {
|
||||
Value(-1), Value(-1), Value(-1), Value(-1),
|
||||
Value(-1), Value(-1), Value(-1), Value(-1)
|
||||
};
|
||||
|
||||
// Candidate passed pawn bonus by rank, middle game.
|
||||
// Candidate passed pawn bonus by rank, middle game
|
||||
const Value CandidateMidgameBonus[8] = {
|
||||
Value( 0), Value( 6), Value(6), Value(14),
|
||||
Value(34), Value(83), Value(0), Value( 0)
|
||||
};
|
||||
|
||||
// Candidate passed pawn bonus by rank, endgame.
|
||||
// Candidate passed pawn bonus by rank, endgame
|
||||
const Value CandidateEndgameBonus[8] = {
|
||||
Value( 0), Value( 13), Value(13), Value(29),
|
||||
Value(68), Value(166), Value( 0), Value( 0)
|
||||
};
|
||||
|
||||
// Pawn storm tables for positions with opposite castling:
|
||||
// Pawn storm tables for positions with opposite castling
|
||||
const int QStormTable[64] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
-22,-22,-22,-14,-6, 0, 0, 0,
|
||||
@@ -140,7 +141,7 @@ PawnInfoTable::PawnInfoTable(unsigned numOfEntries) {
|
||||
|
||||
size = numOfEntries;
|
||||
entries = new PawnInfo[size];
|
||||
if (entries == NULL)
|
||||
if (!entries)
|
||||
{
|
||||
std::cerr << "Failed to allocate " << (numOfEntries * sizeof(PawnInfo))
|
||||
<< " bytes for pawn hash table." << std::endl;
|
||||
@@ -156,22 +157,32 @@ PawnInfoTable::~PawnInfoTable() {
|
||||
}
|
||||
|
||||
|
||||
/// PawnInfo::clear() resets to zero the PawnInfo entry. Note that
|
||||
/// kingSquares[] is initialized to SQ_NONE instead.
|
||||
|
||||
void PawnInfo::clear() {
|
||||
|
||||
memset(this, 0, sizeof(PawnInfo));
|
||||
kingSquares[WHITE] = kingSquares[BLACK] = SQ_NONE;
|
||||
}
|
||||
|
||||
|
||||
/// PawnInfoTable::get_pawn_info() takes a position object as input, computes
|
||||
/// a PawnInfo object, and returns a pointer to it. The result is also
|
||||
/// stored in a hash table, so we don't have to recompute everything when
|
||||
/// the same pawn structure occurs again.
|
||||
|
||||
PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
||||
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
|
||||
Key key = pos.get_pawn_key();
|
||||
int index = int(key & (size - 1));
|
||||
PawnInfo *pi = entries + index;
|
||||
PawnInfo* pi = entries + index;
|
||||
|
||||
// If pi->key matches the position's pawn hash key, it means that we
|
||||
// have analysed this pawn structure before, and we can simply return the
|
||||
// information we found the last time instead of recomputing it
|
||||
// have analysed this pawn structure before, and we can simply return
|
||||
// the information we found the last time instead of recomputing it.
|
||||
if (pi->key == key)
|
||||
return pi;
|
||||
|
||||
@@ -182,40 +193,40 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
||||
Value mgValue[2] = {Value(0), Value(0)};
|
||||
Value egValue[2] = {Value(0), Value(0)};
|
||||
|
||||
// Calculate pawn attacks
|
||||
pi->pawnAttacks[WHITE] = ((pos.pieces(PAWN, WHITE) << 9) & ~FileABB) | ((pos.pieces(PAWN, WHITE) << 7) & ~FileHBB);
|
||||
pi->pawnAttacks[BLACK] = ((pos.pieces(PAWN, BLACK) >> 7) & ~FileABB) | ((pos.pieces(PAWN, BLACK) >> 9) & ~FileHBB);
|
||||
|
||||
// Loop through the pawns for both colors
|
||||
for (Color us = WHITE; us <= BLACK; us++)
|
||||
{
|
||||
Color them = opposite_color(us);
|
||||
Bitboard ourPawns = pos.pawns(us);
|
||||
Bitboard theirPawns = pos.pawns(them);
|
||||
Bitboard ourPawns = pos.pieces(PAWN, us);
|
||||
Bitboard theirPawns = pos.pieces(PAWN, them);
|
||||
Bitboard pawns = ourPawns;
|
||||
int bonus;
|
||||
|
||||
// Initialize pawn storm scores by giving bonuses for open files
|
||||
for (File f = FILE_A; f <= FILE_H; f++)
|
||||
if (Position::file_is_half_open(ourPawns, f))
|
||||
if (!(pawns & file_bb(f)))
|
||||
{
|
||||
pi->ksStormValue[us] += KStormOpenFileBonus[f];
|
||||
pi->qsStormValue[us] += QStormOpenFileBonus[f];
|
||||
pi->halfOpenFiles[us] |= (1 << f);
|
||||
}
|
||||
|
||||
// Loop through all pawns of the current color and score each pawn
|
||||
while (pawns)
|
||||
{
|
||||
bool passed, doubled, isolated, backward, chain, candidate;
|
||||
Square s = pop_1st_bit(&pawns);
|
||||
File f = square_file(s);
|
||||
Rank r = square_rank(s);
|
||||
|
||||
assert(pos.piece_on(s) == piece_of_color_and_type(us, PAWN));
|
||||
|
||||
// The file containing the pawn is not half open
|
||||
pi->halfOpenFiles[us] &= ~(1 << f);
|
||||
|
||||
// Passed, isolated or doubled pawn?
|
||||
passed = Position::pawn_is_passed(theirPawns, us, s);
|
||||
isolated = Position::pawn_is_isolated(ourPawns, s);
|
||||
doubled = Position::pawn_is_doubled(ourPawns, us, s);
|
||||
bool passed = Position::pawn_is_passed(theirPawns, us, s);
|
||||
bool isolated = Position::pawn_is_isolated(ourPawns, s);
|
||||
bool doubled = Position::pawn_is_doubled(ourPawns, us, s);
|
||||
|
||||
// We calculate kingside and queenside pawn storm
|
||||
// scores for both colors. These are used when evaluating
|
||||
@@ -227,7 +238,7 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
||||
// enemy pawn on an adjacent file gets an additional bonus.
|
||||
|
||||
// Kingside pawn storms
|
||||
bonus = KStormTable[relative_square(us, s)];
|
||||
int bonus = KStormTable[relative_square(us, s)];
|
||||
if (f >= FILE_F)
|
||||
{
|
||||
Bitboard b = outpost_mask(us, s) & theirPawns & (FileFBB | FileGBB | FileHBB);
|
||||
@@ -282,9 +293,9 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
||||
// the test a little by introducing an array of masks indexed by color
|
||||
// and square for doing the test, but because everything is hashed,
|
||||
// it probably won't make any noticable difference.
|
||||
chain = ourPawns
|
||||
& neighboring_files_bb(f)
|
||||
& (rank_bb(r) | rank_bb(r - (us == WHITE ? 1 : -1)));
|
||||
bool chain = ourPawns
|
||||
& neighboring_files_bb(f)
|
||||
& (rank_bb(r) | rank_bb(r - (us == WHITE ? 1 : -1)));
|
||||
|
||||
// Test for backward pawn
|
||||
//
|
||||
@@ -292,10 +303,11 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
||||
// it cannot be backward. If can capture an enemy pawn or if
|
||||
// there are friendly pawns behind on neighboring files it cannot
|
||||
// be backward either.
|
||||
bool backward;
|
||||
if ( passed
|
||||
|| isolated
|
||||
|| chain
|
||||
|| (pos.pawn_attacks(us, s) & theirPawns)
|
||||
|| (pos.attacks_from<PAWN>(s, us) & theirPawns)
|
||||
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
|
||||
backward = false;
|
||||
else
|
||||
@@ -304,80 +316,72 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
||||
// pawn on neighboring files. We now check whether the pawn is
|
||||
// backward by looking in the forward direction on the neighboring
|
||||
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
||||
Bitboard b;
|
||||
Bitboard b = pos.attacks_from<PAWN>(s, us);
|
||||
if (us == WHITE)
|
||||
{
|
||||
for (b = pos.pawn_attacks(us, s); !(b & (ourPawns | theirPawns)); b <<= 8);
|
||||
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
|
||||
backward = (b | (b << 8)) & theirPawns;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (b = pos.pawn_attacks(us, s); !(b & (ourPawns | theirPawns)); b >>= 8);
|
||||
for ( ; !(b & (ourPawns | theirPawns)); b >>= 8);
|
||||
backward = (b | (b >> 8)) & theirPawns;
|
||||
}
|
||||
}
|
||||
|
||||
// Test for candidate passed pawn
|
||||
bool candidate;
|
||||
candidate = !passed
|
||||
&& Position::file_is_half_open(theirPawns, f)
|
||||
&& ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns)
|
||||
- count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns)
|
||||
>= 0);
|
||||
&& !(theirPawns & file_bb(f))
|
||||
&& ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns)
|
||||
- count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns)
|
||||
>= 0);
|
||||
|
||||
// In order to prevent doubled passed pawns from receiving a too big
|
||||
// bonus, only the frontmost passed pawn on each file is considered as
|
||||
// a true passed pawn.
|
||||
if (passed && (ourPawns & squares_in_front_of(us, s)))
|
||||
{
|
||||
// candidate = true;
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// Score this pawn
|
||||
Value mv = Value(0), ev = Value(0);
|
||||
if (passed)
|
||||
set_bit(&(pi->passedPawns), s);
|
||||
|
||||
if (isolated)
|
||||
{
|
||||
mv -= IsolatedPawnMidgamePenalty[f];
|
||||
ev -= IsolatedPawnEndgamePenalty[f];
|
||||
if (Position::file_is_half_open(theirPawns, f))
|
||||
mgValue[us] -= IsolatedPawnMidgamePenalty[f];
|
||||
egValue[us] -= IsolatedPawnEndgamePenalty[f];
|
||||
if (!(theirPawns & file_bb(f)))
|
||||
{
|
||||
mv -= IsolatedPawnMidgamePenalty[f] / 2;
|
||||
ev -= IsolatedPawnEndgamePenalty[f] / 2;
|
||||
mgValue[us] -= IsolatedPawnMidgamePenalty[f] / 2;
|
||||
egValue[us] -= IsolatedPawnEndgamePenalty[f] / 2;
|
||||
}
|
||||
}
|
||||
if (doubled)
|
||||
{
|
||||
mv -= DoubledPawnMidgamePenalty[f];
|
||||
ev -= DoubledPawnEndgamePenalty[f];
|
||||
mgValue[us] -= DoubledPawnMidgamePenalty[f];
|
||||
egValue[us] -= DoubledPawnEndgamePenalty[f];
|
||||
}
|
||||
if (backward)
|
||||
{
|
||||
mv -= BackwardPawnMidgamePenalty[f];
|
||||
ev -= BackwardPawnEndgamePenalty[f];
|
||||
if (Position::file_is_half_open(theirPawns, f))
|
||||
mgValue[us] -= BackwardPawnMidgamePenalty[f];
|
||||
egValue[us] -= BackwardPawnEndgamePenalty[f];
|
||||
if (!(theirPawns & file_bb(f)))
|
||||
{
|
||||
mv -= BackwardPawnMidgamePenalty[f] / 2;
|
||||
ev -= BackwardPawnEndgamePenalty[f] / 2;
|
||||
mgValue[us] -= BackwardPawnMidgamePenalty[f] / 2;
|
||||
egValue[us] -= BackwardPawnEndgamePenalty[f] / 2;
|
||||
}
|
||||
}
|
||||
if (chain)
|
||||
{
|
||||
mv += ChainMidgameBonus[f];
|
||||
ev += ChainEndgameBonus[f];
|
||||
mgValue[us] += ChainMidgameBonus[f];
|
||||
egValue[us] += ChainEndgameBonus[f];
|
||||
}
|
||||
if (candidate)
|
||||
{
|
||||
mv += CandidateMidgameBonus[relative_rank(us, s)];
|
||||
ev += CandidateEndgameBonus[relative_rank(us, s)];
|
||||
mgValue[us] += CandidateMidgameBonus[relative_rank(us, s)];
|
||||
egValue[us] += CandidateEndgameBonus[relative_rank(us, s)];
|
||||
}
|
||||
|
||||
mgValue[us] += mv;
|
||||
egValue[us] += ev;
|
||||
|
||||
// If the pawn is passed, set the square of the pawn in the passedPawns
|
||||
// bitboard
|
||||
if (passed)
|
||||
set_bit(&(pi->passedPawns), s);
|
||||
} // while(pawns)
|
||||
} // for(colors)
|
||||
|
||||
@@ -385,3 +389,21 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
|
||||
pi->egValue = int16_t(egValue[WHITE] - egValue[BLACK]);
|
||||
return pi;
|
||||
}
|
||||
|
||||
|
||||
/// PawnInfo::updateShelter calculates and caches king shelter. It is called
|
||||
/// only when king square changes, about 20% of total get_king_shelter() calls.
|
||||
int PawnInfo::updateShelter(const Position& pos, Color c, Square ksq) {
|
||||
|
||||
unsigned shelter = 0;
|
||||
Bitboard pawns = pos.pieces(PAWN, c) & this_and_neighboring_files_bb(ksq);
|
||||
unsigned r = ksq & (7 << 3);
|
||||
for (int i = 1, k = (c ? -8 : 8); i < 4; i++)
|
||||
{
|
||||
r += k;
|
||||
shelter += BitCount8Bit[(pawns >> r) & 0xFF] * (128 >> i);
|
||||
}
|
||||
kingSquares[c] = ksq;
|
||||
kingShelters[c] = shelter;
|
||||
return shelter;
|
||||
}
|
||||
|
||||
34
src/pawns.h
34
src/pawns.h
@@ -51,23 +51,25 @@ public:
|
||||
Value eg_value() const;
|
||||
Value kingside_storm_value(Color c) const;
|
||||
Value queenside_storm_value(Color c) const;
|
||||
Bitboard pawn_attacks(Color c) const;
|
||||
Bitboard passed_pawns() const;
|
||||
int file_is_half_open(Color c, File f) const;
|
||||
int has_open_file_to_left(Color c, File f) const;
|
||||
int has_open_file_to_right(Color c, File f) const;
|
||||
int kingShelter(Color c, Square ksq) const;
|
||||
void setKingShelter(Color c, Square ksq, int value);
|
||||
int get_king_shelter(const Position& pos, Color c, Square ksq);
|
||||
|
||||
private:
|
||||
inline void clear();
|
||||
void clear();
|
||||
int updateShelter(const Position& pos, Color c, Square ksq);
|
||||
|
||||
Key key;
|
||||
Bitboard passedPawns;
|
||||
Bitboard pawnAttacks[2];
|
||||
int16_t mgValue, egValue;
|
||||
int16_t ksStormValue[2], qsStormValue[2];
|
||||
uint8_t halfOpenFiles[2];
|
||||
Square kingSquares[2];
|
||||
int16_t kingShelters[2];
|
||||
uint8_t kingShelters[2];
|
||||
};
|
||||
|
||||
/// The PawnInfoTable class represents a pawn hash table. It is basically
|
||||
@@ -104,6 +106,10 @@ inline Bitboard PawnInfo::passed_pawns() const {
|
||||
return passedPawns;
|
||||
}
|
||||
|
||||
inline Bitboard PawnInfo::pawn_attacks(Color c) const {
|
||||
return pawnAttacks[c];
|
||||
}
|
||||
|
||||
inline Value PawnInfo::kingside_storm_value(Color c) const {
|
||||
return Value(ksStormValue[c]);
|
||||
}
|
||||
@@ -124,24 +130,8 @@ inline int PawnInfo::has_open_file_to_right(Color c, File f) const {
|
||||
return halfOpenFiles[c] & ~((1 << int(f+1)) - 1);
|
||||
}
|
||||
|
||||
inline int PawnInfo::kingShelter(Color c, Square ksq) const {
|
||||
return (kingSquares[c] == ksq ? kingShelters[c] : -1);
|
||||
inline int PawnInfo::get_king_shelter(const Position& pos, Color c, Square ksq) {
|
||||
return (kingSquares[c] == ksq ? kingShelters[c] : updateShelter(pos, c, ksq));
|
||||
}
|
||||
|
||||
inline void PawnInfo::setKingShelter(Color c, Square ksq, int value) {
|
||||
kingSquares[c] = ksq;
|
||||
kingShelters[c] = (int16_t)value;
|
||||
}
|
||||
|
||||
inline void PawnInfo::clear() {
|
||||
|
||||
passedPawns = EmptyBoardBB;
|
||||
mgValue = egValue = 0;
|
||||
ksStormValue[WHITE] = ksStormValue[BLACK] = 0;
|
||||
qsStormValue[WHITE] = qsStormValue[BLACK] = 0;
|
||||
halfOpenFiles[WHITE] = halfOpenFiles[BLACK] = 0xFF;
|
||||
kingSquares[WHITE] = kingSquares[BLACK] = SQ_NONE;
|
||||
}
|
||||
|
||||
|
||||
#endif // !defined(PAWNS_H_INCLUDED)
|
||||
|
||||
@@ -83,10 +83,6 @@ inline int piece_is_slider(Piece p) {
|
||||
return SlidingArray[int(p)];
|
||||
}
|
||||
|
||||
inline int piece_is_slider(PieceType pt) {
|
||||
return SlidingArray[int(pt)];
|
||||
}
|
||||
|
||||
inline SquareDelta pawn_push(Color c) {
|
||||
return (c == WHITE ? DELTA_N : DELTA_S);
|
||||
}
|
||||
|
||||
981
src/position.cpp
981
src/position.cpp
File diff suppressed because it is too large
Load Diff
238
src/position.h
238
src/position.h
@@ -133,7 +133,7 @@ public:
|
||||
};
|
||||
|
||||
// Constructors
|
||||
Position() {};
|
||||
Position() {}
|
||||
Position(const Position& pos);
|
||||
Position(const std::string& fen);
|
||||
|
||||
@@ -162,26 +162,10 @@ public:
|
||||
Bitboard empty_squares() const;
|
||||
Bitboard occupied_squares() const;
|
||||
Bitboard pieces_of_color(Color c) const;
|
||||
Bitboard pieces_of_type(PieceType pt) const;
|
||||
Bitboard pieces_of_color_and_type(Color c, PieceType pt) const;
|
||||
Bitboard pawns() const;
|
||||
Bitboard knights() const;
|
||||
Bitboard bishops() const;
|
||||
Bitboard rooks() const;
|
||||
Bitboard queens() const;
|
||||
Bitboard kings() const;
|
||||
Bitboard rooks_and_queens() const;
|
||||
Bitboard bishops_and_queens() const;
|
||||
Bitboard sliders() const;
|
||||
Bitboard pawns(Color c) const;
|
||||
Bitboard knights(Color c) const;
|
||||
Bitboard bishops(Color c) const;
|
||||
Bitboard rooks(Color c) const;
|
||||
Bitboard queens(Color c) const;
|
||||
Bitboard kings(Color c) const;
|
||||
Bitboard rooks_and_queens(Color c) const;
|
||||
Bitboard bishops_and_queens(Color c) const;
|
||||
Bitboard sliders_of_color(Color c) const;
|
||||
Bitboard pieces(PieceType pt) const;
|
||||
Bitboard pieces(PieceType pt, Color c) const;
|
||||
Bitboard pieces(PieceType pt1, PieceType pt2) const;
|
||||
Bitboard pieces(PieceType pt1, PieceType pt2, Color c) const;
|
||||
|
||||
// Number of pieces of each color and type
|
||||
int piece_count(Color c, PieceType pt) const;
|
||||
@@ -199,36 +183,23 @@ public:
|
||||
Square initial_kr_square(Color c) const;
|
||||
Square initial_qr_square(Color c) const;
|
||||
|
||||
// Attack bitboards
|
||||
Bitboard sliding_attacks(Square s, Direction d) const;
|
||||
Bitboard ray_attacks(Square s, SignedDirection d) const;
|
||||
Bitboard pawn_attacks(Color c, Square s) const;
|
||||
|
||||
template<PieceType>
|
||||
Bitboard piece_attacks(Square s) const;
|
||||
|
||||
// Bitboards for pinned pieces and discovered check candidates
|
||||
Bitboard discovered_check_candidates(Color c) const;
|
||||
Bitboard pinned_pieces(Color c, Bitboard& p) const;
|
||||
Bitboard pinned_pieces(Color c) const;
|
||||
|
||||
// Checking pieces
|
||||
// Checking pieces and under check information
|
||||
Bitboard checkers() const;
|
||||
bool is_check() const;
|
||||
|
||||
// Piece lists
|
||||
Square piece_list(Color c, PieceType pt, int index) const;
|
||||
const Square* piece_list_begin(Color c, PieceType pt) const;
|
||||
|
||||
// Attack information for a given square
|
||||
bool square_is_attacked(Square s, Color c) const;
|
||||
Bitboard attacks_to(Square s) const;
|
||||
Bitboard attacks_to(Square s, Color c) const;
|
||||
bool is_check() const;
|
||||
bool pawn_attacks_square(Color c, Square f, Square t) const;
|
||||
|
||||
template<PieceType>
|
||||
Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
|
||||
|
||||
bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time
|
||||
// Information about attacks to or from a given square
|
||||
Bitboard attackers_to(Square s) const;
|
||||
Bitboard attacks_from(Piece p, Square s) const;
|
||||
template<PieceType> Bitboard attacks_from(Square s) const;
|
||||
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||
|
||||
// Properties of moves
|
||||
bool pl_move_is_legal(Move m) const;
|
||||
@@ -236,10 +207,7 @@ public:
|
||||
bool move_is_check(Move m) const;
|
||||
bool move_is_check(Move m, Bitboard dcCandidates) const;
|
||||
bool move_is_capture(Move m) const;
|
||||
bool move_is_deep_pawn_push(Move m) const;
|
||||
bool move_is_pawn_push_to_7th(Move m) const;
|
||||
bool move_is_passed_pawn_push(Move m) const;
|
||||
bool move_was_passed_pawn_push(Move m) const;
|
||||
bool move_attacks_square(Move m, Square s) const;
|
||||
|
||||
// Information about pawns
|
||||
@@ -248,10 +216,6 @@ public:
|
||||
static bool pawn_is_isolated(Bitboard ourPawns, Square s);
|
||||
static bool pawn_is_doubled(Bitboard ourPawns, Color c, Square s);
|
||||
|
||||
// Open and half-open files
|
||||
static bool file_is_open(Bitboard pawns, File f);
|
||||
static bool file_is_half_open(Bitboard pawns, File f);
|
||||
|
||||
// Weak squares
|
||||
bool square_is_weak(Square s, Color c) const;
|
||||
|
||||
@@ -267,6 +231,7 @@ public:
|
||||
int see(Square from, Square to) const;
|
||||
int see(Move m) const;
|
||||
int see(Square to) const;
|
||||
int see_sign(Move m) const;
|
||||
|
||||
// Accessing hash keys
|
||||
Key get_key() const;
|
||||
@@ -300,7 +265,7 @@ public:
|
||||
// Position consistency check, for debugging
|
||||
bool is_ok(int* failedStep = NULL) const;
|
||||
|
||||
// Static member functions:
|
||||
// Static member functions
|
||||
static void init_zobrist();
|
||||
static void init_piece_square_tables();
|
||||
|
||||
@@ -313,13 +278,9 @@ private:
|
||||
void allow_ooo(Color c);
|
||||
|
||||
// Helper functions for doing and undoing moves
|
||||
void do_capture_move(PieceType capture, Color them, Square to);
|
||||
void do_capture_move(Bitboard& key, PieceType capture, Color them, Square to, bool ep);
|
||||
void do_castle_move(Move m);
|
||||
void do_promotion_move(Move m);
|
||||
void do_ep_move(Move m);
|
||||
void undo_castle_move(Move m);
|
||||
void undo_promotion_move(Move m);
|
||||
void undo_ep_move(Move m);
|
||||
void find_checkers();
|
||||
|
||||
template<PieceType Piece>
|
||||
@@ -338,21 +299,20 @@ private:
|
||||
template<GamePhase> Value compute_value() const;
|
||||
Value compute_non_pawn_material(Color c) const;
|
||||
|
||||
// Bitboards
|
||||
Bitboard byColorBB[2], byTypeBB[8];
|
||||
|
||||
// Board
|
||||
Piece board[64];
|
||||
|
||||
// Bitboards
|
||||
Bitboard byTypeBB[8], byColorBB[2];
|
||||
|
||||
// Piece counts
|
||||
int pieceCount[2][8]; // [color][pieceType]
|
||||
|
||||
// Piece lists
|
||||
Square pieceList[2][8][16]; // [color][pieceType][index]
|
||||
int index[64];
|
||||
int index[64]; // [square]
|
||||
|
||||
// Other info
|
||||
Square kingSquare[2];
|
||||
Color sideToMove;
|
||||
int gamePly;
|
||||
Key history[MaxGameLength];
|
||||
@@ -420,80 +380,20 @@ inline Bitboard Position::pieces_of_color(Color c) const {
|
||||
return byColorBB[c];
|
||||
}
|
||||
|
||||
inline Bitboard Position::pieces_of_type(PieceType pt) const {
|
||||
inline Bitboard Position::pieces(PieceType pt) const {
|
||||
return byTypeBB[pt];
|
||||
}
|
||||
|
||||
inline Bitboard Position::pieces_of_color_and_type(Color c, PieceType pt) const {
|
||||
return pieces_of_color(c) & pieces_of_type(pt);
|
||||
inline Bitboard Position::pieces(PieceType pt, Color c) const {
|
||||
return byTypeBB[pt] & byColorBB[c];
|
||||
}
|
||||
|
||||
inline Bitboard Position::pawns() const {
|
||||
return pieces_of_type(PAWN);
|
||||
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2) const {
|
||||
return byTypeBB[pt1] | byTypeBB[pt2];
|
||||
}
|
||||
|
||||
inline Bitboard Position::knights() const {
|
||||
return pieces_of_type(KNIGHT);
|
||||
}
|
||||
|
||||
inline Bitboard Position::bishops() const {
|
||||
return pieces_of_type(BISHOP);
|
||||
}
|
||||
|
||||
inline Bitboard Position::rooks() const {
|
||||
return pieces_of_type(ROOK);
|
||||
}
|
||||
|
||||
inline Bitboard Position::queens() const {
|
||||
return pieces_of_type(QUEEN);
|
||||
}
|
||||
|
||||
inline Bitboard Position::kings() const {
|
||||
return pieces_of_type(KING);
|
||||
}
|
||||
|
||||
inline Bitboard Position::rooks_and_queens() const {
|
||||
return rooks() | queens();
|
||||
}
|
||||
|
||||
inline Bitboard Position::bishops_and_queens() const {
|
||||
return bishops() | queens();
|
||||
}
|
||||
|
||||
inline Bitboard Position::sliders() const {
|
||||
return bishops() | queens() | rooks();
|
||||
}
|
||||
|
||||
inline Bitboard Position::pawns(Color c) const {
|
||||
return pieces_of_color_and_type(c, PAWN);
|
||||
}
|
||||
|
||||
inline Bitboard Position::knights(Color c) const {
|
||||
return pieces_of_color_and_type(c, KNIGHT);
|
||||
}
|
||||
|
||||
inline Bitboard Position::bishops(Color c) const {
|
||||
return pieces_of_color_and_type(c, BISHOP);
|
||||
}
|
||||
|
||||
inline Bitboard Position::rooks(Color c) const {
|
||||
return pieces_of_color_and_type(c, ROOK);
|
||||
}
|
||||
|
||||
inline Bitboard Position::queens(Color c) const {
|
||||
return pieces_of_color_and_type(c, QUEEN);
|
||||
}
|
||||
|
||||
inline Bitboard Position::kings(Color c) const {
|
||||
return pieces_of_color_and_type(c, KING);
|
||||
}
|
||||
|
||||
inline Bitboard Position::rooks_and_queens(Color c) const {
|
||||
return rooks_and_queens() & pieces_of_color(c);
|
||||
}
|
||||
|
||||
inline Bitboard Position::bishops_and_queens(Color c) const {
|
||||
return bishops_and_queens() & pieces_of_color(c);
|
||||
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2, Color c) const {
|
||||
return (byTypeBB[pt1] | byTypeBB[pt2]) & byColorBB[c];
|
||||
}
|
||||
|
||||
inline int Position::piece_count(Color c, PieceType pt) const {
|
||||
@@ -504,12 +404,16 @@ inline Square Position::piece_list(Color c, PieceType pt, int index) const {
|
||||
return pieceList[c][pt][index];
|
||||
}
|
||||
|
||||
inline const Square* Position::piece_list_begin(Color c, PieceType pt) const {
|
||||
return pieceList[c][pt];
|
||||
}
|
||||
|
||||
inline Square Position::ep_square() const {
|
||||
return st->epSquare;
|
||||
}
|
||||
|
||||
inline Square Position::king_square(Color c) const {
|
||||
return kingSquare[c];
|
||||
return pieceList[c][KING][0];
|
||||
}
|
||||
|
||||
inline bool Position::can_castle_kingside(Color side) const {
|
||||
@@ -532,33 +436,29 @@ inline Square Position::initial_qr_square(Color c) const {
|
||||
return relative_square(c, make_square(initialQRFile, RANK_1));
|
||||
}
|
||||
|
||||
inline Bitboard Position::pawn_attacks(Color c, Square s) const {
|
||||
template<>
|
||||
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
||||
return StepAttackBB[piece_of_color_and_type(c, PAWN)][s];
|
||||
}
|
||||
|
||||
template<PieceType Piece> // Knight and King
|
||||
inline Bitboard Position::piece_attacks(Square s) const {
|
||||
template<PieceType Piece> // Knight and King and white pawns
|
||||
inline Bitboard Position::attacks_from(Square s) const {
|
||||
return StepAttackBB[Piece][s];
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
|
||||
return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s];
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Bitboard Position::piece_attacks<BISHOP>(Square s) const {
|
||||
inline Bitboard Position::attacks_from<BISHOP>(Square s) const {
|
||||
return bishop_attacks_bb(s, occupied_squares());
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Bitboard Position::piece_attacks<ROOK>(Square s) const {
|
||||
inline Bitboard Position::attacks_from<ROOK>(Square s) const {
|
||||
return rook_attacks_bb(s, occupied_squares());
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Bitboard Position::piece_attacks<QUEEN>(Square s) const {
|
||||
return piece_attacks<ROOK>(s) | piece_attacks<BISHOP>(s);
|
||||
inline Bitboard Position::attacks_from<QUEEN>(Square s) const {
|
||||
return attacks_from<ROOK>(s) | attacks_from<BISHOP>(s);
|
||||
}
|
||||
|
||||
inline Bitboard Position::checkers() const {
|
||||
@@ -569,27 +469,8 @@ inline bool Position::is_check() const {
|
||||
return st->checkersBB != EmptyBoardBB;
|
||||
}
|
||||
|
||||
inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const {
|
||||
return bit_is_set(pawn_attacks(c, f), t);
|
||||
}
|
||||
|
||||
template<PieceType Piece>
|
||||
Bitboard Position::piece_attacks_square(Square f, Square t) const {
|
||||
return bit_is_set(piece_attacks<Piece>(f), t);
|
||||
}
|
||||
|
||||
inline Bitboard Position::attacks_to(Square s, Color c) const {
|
||||
|
||||
return attacks_to(s) & pieces_of_color(c);
|
||||
}
|
||||
|
||||
inline bool Position::square_is_attacked(Square s, Color c) const {
|
||||
|
||||
return attacks_to(s, c) != EmptyBoardBB;
|
||||
}
|
||||
|
||||
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
||||
return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s));
|
||||
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
|
||||
}
|
||||
|
||||
inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) {
|
||||
@@ -604,16 +485,8 @@ inline bool Position::pawn_is_doubled(Bitboard ourPawns, Color c, Square s) {
|
||||
return ourPawns & squares_behind(c, s);
|
||||
}
|
||||
|
||||
inline bool Position::file_is_open(Bitboard pawns, File f) {
|
||||
return !(pawns & file_bb(f));
|
||||
}
|
||||
|
||||
inline bool Position::file_is_half_open(Bitboard pawns, File f) {
|
||||
return !(pawns & file_bb(f));
|
||||
}
|
||||
|
||||
inline bool Position::square_is_weak(Square s, Color c) const {
|
||||
return !(pawns(c) & outpost_mask(opposite_color(c), s));
|
||||
return !(pieces(PAWN, c) & outpost_mask(opposite_color(c), s));
|
||||
}
|
||||
|
||||
inline Key Position::get_key() const {
|
||||
@@ -655,8 +528,8 @@ inline Value Position::non_pawn_material(Color c) const {
|
||||
inline Phase Position::game_phase() const {
|
||||
|
||||
// Values modified by Joona Kiiski
|
||||
static const Value MidgameLimit = Value(15713);
|
||||
static const Value EndgameLimit = Value(4428);
|
||||
static const Value MidgameLimit = Value(15581);
|
||||
static const Value EndgameLimit = Value(3998);
|
||||
|
||||
Value npm = non_pawn_material(WHITE) + non_pawn_material(BLACK);
|
||||
|
||||
@@ -668,20 +541,6 @@ inline Phase Position::game_phase() const {
|
||||
return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
|
||||
}
|
||||
|
||||
inline bool Position::move_is_deep_pawn_push(Move m) const {
|
||||
|
||||
Color c = side_to_move();
|
||||
return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN)
|
||||
&& relative_rank(c, move_to(m)) > RANK_4;
|
||||
}
|
||||
|
||||
inline bool Position::move_is_pawn_push_to_7th(Move m) const {
|
||||
|
||||
Color c = side_to_move();
|
||||
return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN)
|
||||
&& relative_rank(c, move_to(m)) == RANK_7;
|
||||
}
|
||||
|
||||
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
||||
|
||||
Color c = side_to_move();
|
||||
@@ -689,13 +548,6 @@ inline bool Position::move_is_passed_pawn_push(Move m) const {
|
||||
&& pawn_is_passed(c, move_to(m));
|
||||
}
|
||||
|
||||
inline bool Position::move_was_passed_pawn_push(Move m) const {
|
||||
|
||||
Color c = opposite_color(side_to_move());
|
||||
return piece_on(move_to(m)) == piece_of_color_and_type(c, PAWN)
|
||||
&& pawn_is_passed(c, move_to(m));
|
||||
}
|
||||
|
||||
inline int Position::rule_50_counter() const {
|
||||
|
||||
return st->rule50;
|
||||
@@ -710,7 +562,7 @@ inline bool Position::opposite_colored_bishops() const {
|
||||
|
||||
inline bool Position::has_pawn_on_7th(Color c) const {
|
||||
|
||||
return pawns(c) & relative_rank_bb(c, RANK_7);
|
||||
return pieces(PAWN, c) & relative_rank_bb(c, RANK_7);
|
||||
}
|
||||
|
||||
inline bool Position::move_is_capture(Move m) const {
|
||||
|
||||
177
src/search.cpp
177
src/search.cpp
@@ -189,9 +189,6 @@ namespace {
|
||||
// Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply
|
||||
const Value RazorApprMargins[6] = { Value(0x520), Value(0x300), Value(0x300), Value(0x300), Value(0x300), Value(0x300) };
|
||||
|
||||
// The main transposition table
|
||||
TranspositionTable TT;
|
||||
|
||||
|
||||
/// Variables initialized by UCI options
|
||||
|
||||
@@ -202,10 +199,10 @@ namespace {
|
||||
Depth ThreatDepth; // heavy SMP read access
|
||||
|
||||
// Last seconds noise filtering (LSN)
|
||||
bool UseLSNFiltering;
|
||||
bool looseOnTime = false;
|
||||
int LSNTime; // In milliseconds
|
||||
Value LSNValue;
|
||||
const bool UseLSNFiltering = false;
|
||||
const int LSNTime = 4000; // In milliseconds
|
||||
const Value LSNValue = value_from_centipawns(200);
|
||||
bool loseOnTime = false;
|
||||
|
||||
// Extensions. Array index 0 is used at non-PV nodes, index 1 at PV nodes.
|
||||
// There is heavy SMP read access on these arrays
|
||||
@@ -226,8 +223,7 @@ namespace {
|
||||
// Time managment variables
|
||||
int SearchStartTime;
|
||||
int MaxNodes, MaxDepth;
|
||||
int MaxSearchTime, AbsoluteMaxSearchTime, ExtraSearchTime;
|
||||
Move EasyMove;
|
||||
int MaxSearchTime, AbsoluteMaxSearchTime, ExtraSearchTime, ExactMaxTime;
|
||||
int RootMoveNumber;
|
||||
bool InfiniteSearch;
|
||||
bool PonderSearch;
|
||||
@@ -237,8 +233,6 @@ namespace {
|
||||
bool FailHigh;
|
||||
bool FailLow;
|
||||
bool Problem;
|
||||
bool PonderingEnabled;
|
||||
int ExactMaxTime;
|
||||
|
||||
// Show current line?
|
||||
bool ShowCurrentLine;
|
||||
@@ -357,7 +351,6 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||
// Initialize global search variables
|
||||
Idle = false;
|
||||
SearchStartTime = get_system_time();
|
||||
EasyMove = MOVE_NONE;
|
||||
for (int i = 0; i < THREAD_MAX; i++)
|
||||
{
|
||||
Threads[i].nodes = 0ULL;
|
||||
@@ -377,9 +370,12 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||
// Read UCI option values
|
||||
TT.set_size(get_option_value_int("Hash"));
|
||||
if (button_was_pressed("Clear Hash"))
|
||||
{
|
||||
TT.clear();
|
||||
loseOnTime = false; // reset at the beginning of a new game
|
||||
}
|
||||
|
||||
PonderingEnabled = get_option_value_bool("Ponder");
|
||||
bool PonderingEnabled = get_option_value_bool("Ponder");
|
||||
MultiPV = get_option_value_int("MultiPV");
|
||||
|
||||
CheckExtension[1] = Depth(get_option_value_int("Check Extension (PV nodes)"));
|
||||
@@ -410,15 +406,12 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||
if (UseLogFile)
|
||||
LogFile.open(get_option_value_string("Search Log Filename").c_str(), std::ios::out | std::ios::app);
|
||||
|
||||
UseLSNFiltering = get_option_value_bool("LSN filtering");
|
||||
LSNTime = get_option_value_int("LSN Time Margin (sec)") * 1000;
|
||||
LSNValue = value_from_centipawns(get_option_value_int("LSN Value Margin"));
|
||||
|
||||
MinimumSplitDepth = get_option_value_int("Minimum Split Depth") * OnePly;
|
||||
MaxThreadsPerSplitPoint = get_option_value_int("Maximum Number of Threads per Split Point");
|
||||
|
||||
read_weights(pos.side_to_move());
|
||||
|
||||
// Set the number of active threads
|
||||
int newActiveThreads = get_option_value_int("Threads");
|
||||
if (newActiveThreads != ActiveThreads)
|
||||
{
|
||||
@@ -479,7 +472,6 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||
else
|
||||
NodesBetweenPolls = 30000;
|
||||
|
||||
|
||||
// Write information to search log file
|
||||
if (UseLogFile)
|
||||
LogFile << "Searching: " << pos.to_fen() << std::endl
|
||||
@@ -491,17 +483,19 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||
|
||||
|
||||
// We're ready to start thinking. Call the iterative deepening loop function
|
||||
if (!looseOnTime)
|
||||
//
|
||||
// FIXME we really need to cleanup all this LSN ugliness
|
||||
if (!loseOnTime)
|
||||
{
|
||||
Value v = id_loop(pos, searchMoves);
|
||||
looseOnTime = ( UseLSNFiltering
|
||||
&& myTime < LSNTime
|
||||
&& myIncrement == 0
|
||||
&& v < -LSNValue);
|
||||
loseOnTime = ( UseLSNFiltering
|
||||
&& myTime < LSNTime
|
||||
&& myIncrement == 0
|
||||
&& v < -LSNValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
looseOnTime = false; // reset for next match
|
||||
loseOnTime = false; // reset for next match
|
||||
while (SearchStartTime + myTime + 1000 > get_system_time())
|
||||
; // wait here
|
||||
id_loop(pos, searchMoves); // to fail gracefully
|
||||
@@ -630,6 +624,15 @@ namespace {
|
||||
// searchMoves are verified, copied, scored and sorted
|
||||
RootMoveList rml(p, searchMoves);
|
||||
|
||||
// Print RootMoveList c'tor startup scoring to the standard output,
|
||||
// so that we print information also for iteration 1.
|
||||
std::cout << "info depth " << 1 << "\ninfo depth " << 1
|
||||
<< " score " << value_to_string(rml.get_move_score(0))
|
||||
<< " time " << current_search_time()
|
||||
<< " nodes " << nodes_searched()
|
||||
<< " nps " << nps()
|
||||
<< " pv " << rml.get_move(0) << "\n";
|
||||
|
||||
// Initialize
|
||||
TT.new_search();
|
||||
H.clear();
|
||||
@@ -641,7 +644,7 @@ namespace {
|
||||
IterationInfo[1] = IterationInfoType(rml.get_move_score(0), rml.get_move_score(0));
|
||||
Iteration = 1;
|
||||
|
||||
EasyMove = rml.scan_for_easy_move();
|
||||
Move EasyMove = rml.scan_for_easy_move();
|
||||
|
||||
// Iterative deepening loop
|
||||
while (Iteration < PLY_MAX)
|
||||
@@ -861,8 +864,9 @@ namespace {
|
||||
<< " currmovenumber " << i + 1 << std::endl;
|
||||
|
||||
// Decide search depth for this move
|
||||
bool moveIsCapture = pos.move_is_capture(move);
|
||||
bool dangerous;
|
||||
ext = extension(pos, move, true, pos.move_is_capture(move), pos.move_is_check(move), false, false, &dangerous);
|
||||
ext = extension(pos, move, true, moveIsCapture, pos.move_is_check(move), false, false, &dangerous);
|
||||
newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
|
||||
|
||||
// Make the move, and search it
|
||||
@@ -886,15 +890,30 @@ namespace {
|
||||
}
|
||||
else
|
||||
{
|
||||
value = -search(pos, ss, -alpha, newDepth, 1, true, 0);
|
||||
if ( newDepth >= 3*OnePly
|
||||
&& i >= MultiPV + LMRPVMoves
|
||||
&& !dangerous
|
||||
&& !moveIsCapture
|
||||
&& !move_is_promotion(move)
|
||||
&& !move_is_castle(move))
|
||||
{
|
||||
ss[0].reduction = OnePly;
|
||||
value = -search(pos, ss, -alpha, newDepth-OnePly, 1, true, 0);
|
||||
} else
|
||||
value = alpha + 1; // Just to trigger next condition
|
||||
|
||||
if (value > alpha)
|
||||
{
|
||||
// Fail high! Set the boolean variable FailHigh to true, and
|
||||
// re-search the move with a big window. The variable FailHigh is
|
||||
// used for time managment: We try to avoid aborting the search
|
||||
// prematurely during a fail high research.
|
||||
FailHigh = true;
|
||||
value = -search_pv(pos, ss, -beta, -alpha, newDepth, 1, 0);
|
||||
value = -search(pos, ss, -alpha, newDepth, 1, true, 0);
|
||||
if (value > alpha)
|
||||
{
|
||||
// Fail high! Set the boolean variable FailHigh to true, and
|
||||
// re-search the move with a big window. The variable FailHigh is
|
||||
// used for time managment: We try to avoid aborting the search
|
||||
// prematurely during a fail high research.
|
||||
FailHigh = true;
|
||||
value = -search_pv(pos, ss, -beta, -alpha, newDepth, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -928,6 +947,7 @@ namespace {
|
||||
// Update PV
|
||||
rml.set_move_score(i, value);
|
||||
update_pv(ss, 0);
|
||||
TT.extract_pv(pos, ss[0].pv);
|
||||
rml.set_move_pv(i, ss[0].pv);
|
||||
|
||||
if (MultiPV == 1)
|
||||
@@ -941,6 +961,8 @@ namespace {
|
||||
// Print search information to the standard output
|
||||
std::cout << "info depth " << Iteration
|
||||
<< " score " << value_to_string(value)
|
||||
<< ((value >= beta)?
|
||||
" lowerbound" : ((value <= alpha)? " upperbound" : ""))
|
||||
<< " time " << current_search_time()
|
||||
<< " nodes " << nodes_searched()
|
||||
<< " nps " << nps()
|
||||
@@ -1044,16 +1066,16 @@ namespace {
|
||||
|
||||
// Initialize a MovePicker object for the current position, and prepare
|
||||
// to search all moves
|
||||
MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
|
||||
|
||||
Move move, movesSearched[256];
|
||||
int moveCount = 0;
|
||||
Value value, bestValue = -VALUE_INFINITE;
|
||||
Bitboard dcCandidates = mp.discovered_check_candidates();
|
||||
Color us = pos.side_to_move();
|
||||
bool isCheck = pos.is_check();
|
||||
bool mateThreat = pos.has_mate_threat(opposite_color(us));
|
||||
|
||||
MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
|
||||
Bitboard dcCandidates = mp.discovered_check_candidates();
|
||||
|
||||
// Loop through all legal moves until no moves remain or a beta cutoff
|
||||
// occurs.
|
||||
while ( alpha < beta
|
||||
@@ -1062,7 +1084,7 @@ namespace {
|
||||
{
|
||||
assert(move_is_ok(move));
|
||||
|
||||
bool singleReply = (isCheck && mp.number_of_moves() == 1);
|
||||
bool singleReply = (isCheck && mp.number_of_evasions() == 1);
|
||||
bool moveIsCheck = pos.move_is_check(move, dcCandidates);
|
||||
bool moveIsCapture = pos.move_is_capture(move);
|
||||
|
||||
@@ -1083,7 +1105,7 @@ namespace {
|
||||
{
|
||||
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
||||
// if the move fails high will be re-searched at full depth.
|
||||
if ( depth >= 2*OnePly
|
||||
if ( depth >= 3*OnePly
|
||||
&& moveCount >= LMRPVMoves
|
||||
&& !dangerous
|
||||
&& !moveIsCapture
|
||||
@@ -1252,11 +1274,7 @@ namespace {
|
||||
|
||||
pos.undo_null_move();
|
||||
|
||||
if (value_is_mate(nullValue))
|
||||
{
|
||||
/* Do not return unproven mates */
|
||||
}
|
||||
else if (nullValue >= beta)
|
||||
if (nullValue >= beta)
|
||||
{
|
||||
if (depth < 6 * OnePly)
|
||||
return beta;
|
||||
@@ -1315,6 +1333,10 @@ namespace {
|
||||
bool useFutilityPruning = depth < SelectiveDepth
|
||||
&& !isCheck;
|
||||
|
||||
// Avoid calling evaluate() if we already have the score in TT
|
||||
if (tte && (tte->type() & VALUE_TYPE_EVAL))
|
||||
futilityValue = value_from_tt(tte->value(), ply) + FutilityMargins[int(depth) - 2];
|
||||
|
||||
// Loop through all legal moves until no moves remain or a beta cutoff
|
||||
// occurs.
|
||||
while ( bestValue < beta
|
||||
@@ -1323,7 +1345,7 @@ namespace {
|
||||
{
|
||||
assert(move_is_ok(move));
|
||||
|
||||
bool singleReply = (isCheck && mp.number_of_moves() == 1);
|
||||
bool singleReply = (isCheck && mp.number_of_evasions() == 1);
|
||||
bool moveIsCheck = pos.move_is_check(move, dcCandidates);
|
||||
bool moveIsCapture = pos.move_is_capture(move);
|
||||
|
||||
@@ -1367,7 +1389,7 @@ namespace {
|
||||
|
||||
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
||||
// if the move fails high will be re-searched at full depth.
|
||||
if ( depth >= 2*OnePly
|
||||
if ( depth >= 3*OnePly
|
||||
&& moveCount >= LMRNonPVMoves
|
||||
&& !dangerous
|
||||
&& !moveIsCapture
|
||||
@@ -1492,10 +1514,9 @@ namespace {
|
||||
if (isCheck)
|
||||
staticValue = -VALUE_INFINITE;
|
||||
|
||||
else if (tte && tte->type() == VALUE_TYPE_EVAL)
|
||||
else if (tte && (tte->type() & VALUE_TYPE_EVAL))
|
||||
{
|
||||
// Use the cached evaluation score if possible
|
||||
assert(tte->value() == evaluate(pos, ei, threadID));
|
||||
assert(ei.futilityMargin == Value(0));
|
||||
|
||||
staticValue = tte->value();
|
||||
@@ -1514,7 +1535,7 @@ namespace {
|
||||
{
|
||||
// Store the score to avoid a future costly evaluation() call
|
||||
if (!isCheck && !tte && ei.futilityMargin == 0)
|
||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EVAL, Depth(-127*OnePly), MOVE_NONE);
|
||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EV_LO, Depth(-127*OnePly), MOVE_NONE);
|
||||
|
||||
return bestValue;
|
||||
}
|
||||
@@ -1568,9 +1589,7 @@ namespace {
|
||||
// Don't search captures and checks with negative SEE values
|
||||
if ( !isCheck
|
||||
&& !move_is_promotion(move)
|
||||
&& (pos.midgame_value_of_piece_on(move_from(move)) >
|
||||
pos.midgame_value_of_piece_on(move_to(move)))
|
||||
&& pos.see(move) < 0)
|
||||
&& pos.see_sign(move) < 0)
|
||||
continue;
|
||||
|
||||
// Make and search the move.
|
||||
@@ -1604,9 +1623,13 @@ namespace {
|
||||
Move m = ss[ply].pv[ply];
|
||||
if (!pvNode)
|
||||
{
|
||||
// If bestValue isn't changed it means it is still the static evaluation of
|
||||
// the node, so keep this info to avoid a future costly evaluation() call.
|
||||
ValueType type = (bestValue == staticValue && !ei.futilityMargin ? VALUE_TYPE_EV_UP : VALUE_TYPE_UPPER);
|
||||
Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
|
||||
|
||||
if (bestValue < beta)
|
||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, d, MOVE_NONE);
|
||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), type, d, MOVE_NONE);
|
||||
else
|
||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, d, m);
|
||||
}
|
||||
@@ -1922,15 +1945,15 @@ namespace {
|
||||
bool includeAllMoves = (searchMoves[0] == MOVE_NONE);
|
||||
|
||||
// Generate all legal moves
|
||||
int lm_count = generate_legal_moves(pos, mlist);
|
||||
MoveStack* last = generate_moves(pos, mlist);
|
||||
|
||||
// Add each move to the moves[] array
|
||||
for (int i = 0; i < lm_count; i++)
|
||||
for (MoveStack* cur = mlist; cur != last; cur++)
|
||||
{
|
||||
bool includeMove = includeAllMoves;
|
||||
|
||||
for (int k = 0; !includeMove && searchMoves[k] != MOVE_NONE; k++)
|
||||
includeMove = (searchMoves[k] == mlist[i].move);
|
||||
includeMove = (searchMoves[k] == cur->move);
|
||||
|
||||
if (!includeMove)
|
||||
continue;
|
||||
@@ -1939,7 +1962,7 @@ namespace {
|
||||
StateInfo st;
|
||||
SearchStack ss[PLY_MAX_PLUS_2];
|
||||
|
||||
moves[count].move = mlist[i].move;
|
||||
moves[count].move = cur->move;
|
||||
pos.do_move(moves[count].move, st);
|
||||
moves[count].score = -qsearch(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, Depth(0), 1, 0);
|
||||
pos.undo_move(moves[count].move);
|
||||
@@ -2110,7 +2133,9 @@ namespace {
|
||||
// the second move is assumed to be a move from the current position.
|
||||
|
||||
bool connected_moves(const Position& pos, Move m1, Move m2) {
|
||||
|
||||
Square f1, t1, f2, t2;
|
||||
Piece p;
|
||||
|
||||
assert(move_is_ok(m1));
|
||||
assert(move_is_ok(m2));
|
||||
@@ -2136,31 +2161,32 @@ namespace {
|
||||
return true;
|
||||
|
||||
// Case 4: The destination square for m2 is attacked by the moving piece in m1
|
||||
if (pos.piece_attacks_square(pos.piece_on(t1), t1, t2))
|
||||
p = pos.piece_on(t1);
|
||||
if (bit_is_set(pos.attacks_from(p, t1), t2))
|
||||
return true;
|
||||
|
||||
// Case 5: Discovered check, checking piece is the piece moved in m1
|
||||
if ( piece_is_slider(pos.piece_on(t1))
|
||||
if ( piece_is_slider(p)
|
||||
&& bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), f2)
|
||||
&& !bit_is_set(squares_between(t2, pos.king_square(pos.side_to_move())), t2))
|
||||
&& !bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), t2))
|
||||
{
|
||||
Bitboard occ = pos.occupied_squares();
|
||||
Color us = pos.side_to_move();
|
||||
Square ksq = pos.king_square(us);
|
||||
clear_bit(&occ, f2);
|
||||
if (pos.type_of_piece_on(t1) == BISHOP)
|
||||
if (type_of_piece(p) == BISHOP)
|
||||
{
|
||||
if (bit_is_set(bishop_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
else if (pos.type_of_piece_on(t1) == ROOK)
|
||||
else if (type_of_piece(p) == ROOK)
|
||||
{
|
||||
if (bit_is_set(rook_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(pos.type_of_piece_on(t1) == QUEEN);
|
||||
assert(type_of_piece(p) == QUEEN);
|
||||
if (bit_is_set(queen_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
@@ -2208,25 +2234,29 @@ namespace {
|
||||
assert(m != MOVE_NONE);
|
||||
|
||||
Depth result = Depth(0);
|
||||
*dangerous = check || singleReply || mateThreat;
|
||||
*dangerous = check | singleReply | mateThreat;
|
||||
|
||||
if (check)
|
||||
result += CheckExtension[pvNode];
|
||||
if (*dangerous)
|
||||
{
|
||||
if (check)
|
||||
result += CheckExtension[pvNode];
|
||||
|
||||
if (singleReply)
|
||||
result += SingleReplyExtension[pvNode];
|
||||
if (singleReply)
|
||||
result += SingleReplyExtension[pvNode];
|
||||
|
||||
if (mateThreat)
|
||||
result += MateThreatExtension[pvNode];
|
||||
if (mateThreat)
|
||||
result += MateThreatExtension[pvNode];
|
||||
}
|
||||
|
||||
if (pos.type_of_piece_on(move_from(m)) == PAWN)
|
||||
{
|
||||
if (pos.move_is_pawn_push_to_7th(m))
|
||||
Color c = pos.side_to_move();
|
||||
if (relative_rank(c, move_to(m)) == RANK_7)
|
||||
{
|
||||
result += PawnPushTo7thExtension[pvNode];
|
||||
*dangerous = true;
|
||||
}
|
||||
if (pos.move_is_passed_pawn_push(m))
|
||||
if (pos.pawn_is_passed(c, move_to(m)))
|
||||
{
|
||||
result += PassedPawnExtension[pvNode];
|
||||
*dangerous = true;
|
||||
@@ -2247,7 +2277,7 @@ namespace {
|
||||
if ( pvNode
|
||||
&& capture
|
||||
&& pos.type_of_piece_on(move_to(m)) != PAWN
|
||||
&& pos.see(m) >= 0)
|
||||
&& pos.see_sign(m) >= 0)
|
||||
{
|
||||
result += OnePly/2;
|
||||
*dangerous = true;
|
||||
@@ -2320,7 +2350,7 @@ namespace {
|
||||
&& threat != MOVE_NONE
|
||||
&& piece_is_slider(pos.piece_on(tfrom))
|
||||
&& bit_is_set(squares_between(tfrom, tto), mto)
|
||||
&& pos.see(m) >= 0)
|
||||
&& pos.see_sign(m) >= 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -2383,6 +2413,7 @@ namespace {
|
||||
ss.killers[0] = m;
|
||||
}
|
||||
|
||||
|
||||
// fail_high_ply_1() checks if some thread is currently resolving a fail
|
||||
// high at ply 1 at the node below the first root node. This information
|
||||
// is used for time managment.
|
||||
|
||||
99
src/tt.cpp
99
src/tt.cpp
@@ -25,9 +25,13 @@
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#include "movegen.h"
|
||||
#include "tt.h"
|
||||
|
||||
// The main transposition table
|
||||
TranspositionTable TT;
|
||||
|
||||
////
|
||||
//// Functions
|
||||
@@ -55,16 +59,16 @@ void TranspositionTable::set_size(unsigned mbSize) {
|
||||
|
||||
unsigned newSize = 1024;
|
||||
|
||||
// We store a cluster of 4 TTEntry for each position and newSize is
|
||||
// the maximum number of storable positions
|
||||
while ((2 * newSize) * 4 * (sizeof(TTEntry)) <= (mbSize << 20))
|
||||
// We store a cluster of ClusterSize number of TTEntry for each position
|
||||
// and newSize is the maximum number of storable positions.
|
||||
while ((2 * newSize) * sizeof(TTCluster) <= (mbSize << 20))
|
||||
newSize *= 2;
|
||||
|
||||
if (newSize != size)
|
||||
{
|
||||
size = newSize;
|
||||
delete [] entries;
|
||||
entries = new TTEntry[size * 4];
|
||||
entries = new TTCluster[size];
|
||||
if (!entries)
|
||||
{
|
||||
std::cerr << "Failed to allocate " << mbSize
|
||||
@@ -83,7 +87,17 @@ void TranspositionTable::set_size(unsigned mbSize) {
|
||||
|
||||
void TranspositionTable::clear() {
|
||||
|
||||
memset(entries, 0, size * 4 * sizeof(TTEntry));
|
||||
memset(entries, 0, size * sizeof(TTCluster));
|
||||
}
|
||||
|
||||
|
||||
/// TranspositionTable::first_entry returns a pointer to the first
|
||||
/// entry of a cluster given a position. The low 32 bits of the key
|
||||
/// are used to get the index in the table.
|
||||
|
||||
inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
|
||||
|
||||
return entries[uint32_t(posKey) & (size - 1)].data;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,20 +114,21 @@ void TranspositionTable::clear() {
|
||||
void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, Move m) {
|
||||
|
||||
TTEntry *tte, *replace;
|
||||
uint32_t posKey32 = posKey >> 32; // Use the high 32 bits as key
|
||||
|
||||
tte = replace = first_entry(posKey);
|
||||
for (int i = 0; i < 4; i++, tte++)
|
||||
for (int i = 0; i < ClusterSize; i++, tte++)
|
||||
{
|
||||
if (!tte->key() || tte->key() == posKey) // empty or overwrite old
|
||||
if (!tte->key() || tte->key() == posKey32) // empty or overwrite old
|
||||
{
|
||||
// Do not overwrite when new type is VALUE_TYPE_EVAL
|
||||
if (tte->key() && t == VALUE_TYPE_EVAL)
|
||||
// Do not overwrite when new type is VALUE_TYPE_EV_LO
|
||||
if (tte->key() && t == VALUE_TYPE_EV_LO)
|
||||
return;
|
||||
|
||||
if (m == MOVE_NONE)
|
||||
m = tte->move();
|
||||
|
||||
*tte = TTEntry(posKey, v, t, d, m, generation);
|
||||
*tte = TTEntry(posKey32, v, t, d, m, generation);
|
||||
return;
|
||||
}
|
||||
else if (i == 0) // replace would be a no-op in this common case
|
||||
@@ -126,7 +141,7 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
|
||||
if (c1 + c2 + c3 > 0)
|
||||
replace = tte;
|
||||
}
|
||||
*replace = TTEntry(posKey, v, t, d, m, generation);
|
||||
*replace = TTEntry(posKey32, v, t, d, m, generation);
|
||||
writes++;
|
||||
}
|
||||
|
||||
@@ -137,24 +152,38 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
|
||||
|
||||
TTEntry* TranspositionTable::retrieve(const Key posKey) const {
|
||||
|
||||
TTEntry *tte = first_entry(posKey);
|
||||
uint32_t posKey32 = posKey >> 32;
|
||||
TTEntry* tte = first_entry(posKey);
|
||||
|
||||
for (int i = 0; i < 4; i++, tte++)
|
||||
if (tte->key() == posKey)
|
||||
for (int i = 0; i < ClusterSize; i++, tte++)
|
||||
if (tte->key() == posKey32)
|
||||
return tte;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/// TranspositionTable::first_entry returns a pointer to the first
|
||||
/// entry of a cluster given a position.
|
||||
/// TranspositionTable::prefetch looks up the current position in the
|
||||
/// transposition table and load it in L1/L2 cache. This is a non
|
||||
/// blocking function and do not stalls the CPU waiting for data
|
||||
/// to be loaded from RAM, that can be very slow. When we will
|
||||
/// subsequently call retrieve() the TT data will be already
|
||||
/// quickly accessible in L1/L2 CPU cache.
|
||||
|
||||
inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
|
||||
void TranspositionTable::prefetch(const Key posKey) const {
|
||||
|
||||
return entries + (int(posKey & (size - 1)) << 2);
|
||||
#if defined(__INTEL_COMPILER) || defined(__ICL)
|
||||
// This hack prevents prefetches to be optimized away by the
|
||||
// Intel compiler. Both MSVC and gcc seems not affected.
|
||||
__asm__ ("");
|
||||
#endif
|
||||
|
||||
char const* addr = (char*)first_entry(posKey);
|
||||
_mm_prefetch(addr, _MM_HINT_T2);
|
||||
_mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
|
||||
}
|
||||
|
||||
|
||||
/// TranspositionTable::new_search() is called at the beginning of every new
|
||||
/// search. It increments the "generation" variable, which is used to
|
||||
/// distinguish transposition table entries from previous searches from
|
||||
@@ -185,12 +214,44 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
||||
}
|
||||
|
||||
|
||||
/// TranspositionTable::extract_pv() extends a PV by adding moves from the
|
||||
/// transposition table at the end. This should ensure that the PV is almost
|
||||
/// always at least two plies long, which is important, because otherwise we
|
||||
/// will often get single-move PVs when the search stops while failing high,
|
||||
/// and a single-move PV means that we don't have a ponder move.
|
||||
|
||||
void TranspositionTable::extract_pv(const Position& pos, Move pv[]) {
|
||||
|
||||
int ply;
|
||||
Position p(pos);
|
||||
StateInfo st[100];
|
||||
|
||||
for (ply = 0; pv[ply] != MOVE_NONE; ply++)
|
||||
p.do_move(pv[ply], st[ply]);
|
||||
|
||||
bool stop;
|
||||
const TTEntry* tte;
|
||||
for (stop = false, tte = retrieve(p.get_key());
|
||||
tte && tte->move() != MOVE_NONE && !stop;
|
||||
tte = retrieve(p.get_key()), ply++)
|
||||
{
|
||||
if (!move_is_legal(p, tte->move()))
|
||||
break;
|
||||
pv[ply] = tte->move();
|
||||
p.do_move(pv[ply], st[ply]);
|
||||
for (int j = 0; j < ply; j++)
|
||||
if (st[j].key == p.get_key()) stop = true;
|
||||
}
|
||||
pv[ply] = MOVE_NONE;
|
||||
}
|
||||
|
||||
|
||||
/// TranspositionTable::full() returns the permill of all transposition table
|
||||
/// entries which have received at least one write during the current search.
|
||||
/// It is used to display the "info hashfull ..." information in UCI.
|
||||
|
||||
int TranspositionTable::full() const {
|
||||
|
||||
double N = double(size) * 4.0;
|
||||
double N = double(size) * ClusterSize;
|
||||
return int(1000 * (1 - exp(writes * log(1.0 - 1.0/N))));
|
||||
}
|
||||
|
||||
40
src/tt.h
40
src/tt.h
@@ -36,12 +36,12 @@
|
||||
|
||||
/// The TTEntry class is the class of transposition table entries
|
||||
///
|
||||
/// A TTEntry needs 128 bits to be stored
|
||||
/// A TTEntry needs 96 bits to be stored
|
||||
///
|
||||
/// bit 0-63: key
|
||||
/// bit 64-95: data
|
||||
/// bit 96-111: value
|
||||
/// bit 112-127: depth
|
||||
/// bit 0-31: key
|
||||
/// bit 32-63: data
|
||||
/// bit 64-79: value
|
||||
/// bit 80-95: depth
|
||||
///
|
||||
/// the 32 bits of the data field are so defined
|
||||
///
|
||||
@@ -54,11 +54,11 @@ class TTEntry {
|
||||
|
||||
public:
|
||||
TTEntry() {}
|
||||
TTEntry(Key k, Value v, ValueType t, Depth d, Move m, int generation)
|
||||
TTEntry(uint32_t k, Value v, ValueType t, Depth d, Move m, int generation)
|
||||
: key_ (k), data((m & 0x1FFFF) | (t << 20) | (generation << 23)),
|
||||
value_(int16_t(v)), depth_(int16_t(d)) {}
|
||||
|
||||
Key key() const { return key_; }
|
||||
uint32_t key() const { return key_; }
|
||||
Depth depth() const { return Depth(depth_); }
|
||||
Move move() const { return Move(data & 0x1FFFF); }
|
||||
Value value() const { return Value(value_); }
|
||||
@@ -66,13 +66,27 @@ public:
|
||||
int generation() const { return (data >> 23); }
|
||||
|
||||
private:
|
||||
Key key_;
|
||||
uint32_t key_;
|
||||
uint32_t data;
|
||||
int16_t value_;
|
||||
int16_t depth_;
|
||||
};
|
||||
|
||||
/// The transposition table class. This is basically just a huge array
|
||||
|
||||
/// This is the number of TTEntry slots for each position
|
||||
const int ClusterSize = 5;
|
||||
|
||||
/// Each group of ClusterSize number of TTEntry form a TTCluster
|
||||
/// that is indexed by a single position key. Cluster is padded
|
||||
/// to a cache line size so to guarantee always aligned accesses.
|
||||
|
||||
struct TTCluster {
|
||||
TTEntry data[ClusterSize];
|
||||
char cache_line_padding[64 - sizeof(TTEntry[ClusterSize])];
|
||||
};
|
||||
|
||||
|
||||
/// The transposition table class. This is basically just a huge array
|
||||
/// containing TTEntry objects, and a few methods for writing new entries
|
||||
/// and reading new ones.
|
||||
|
||||
@@ -85,22 +99,26 @@ public:
|
||||
void clear();
|
||||
void store(const Key posKey, Value v, ValueType type, Depth d, Move m);
|
||||
TTEntry* retrieve(const Key posKey) const;
|
||||
void prefetch(const Key posKey) const;
|
||||
void new_search();
|
||||
void insert_pv(const Position& pos, Move pv[]);
|
||||
void extract_pv(const Position& pos, Move pv[]);
|
||||
int full() const;
|
||||
|
||||
private:
|
||||
inline TTEntry* first_entry(const Key posKey) const;
|
||||
|
||||
// Be sure 'writes' is at least one cacheline away
|
||||
// Be sure 'writes' is at least one cache line away
|
||||
// from read only variables.
|
||||
unsigned char pad_before[64 - sizeof(unsigned)];
|
||||
unsigned writes; // heavy SMP read/write access here
|
||||
unsigned char pad_after[64];
|
||||
|
||||
unsigned size;
|
||||
TTEntry* entries;
|
||||
TTCluster* entries;
|
||||
uint8_t generation;
|
||||
};
|
||||
|
||||
extern TranspositionTable TT;
|
||||
|
||||
#endif // !defined(TT_H_INCLUDED)
|
||||
|
||||
11
src/types.h
11
src/types.h
@@ -31,7 +31,7 @@ typedef __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef __int16 int16;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
@@ -62,8 +62,15 @@ typedef uint64_t Bitboard;
|
||||
#define IS_64BIT
|
||||
#endif
|
||||
|
||||
#if defined(IS_64BIT) && !defined(_WIN64) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
|
||||
#if defined(IS_64BIT) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
|
||||
#define USE_BSFQ
|
||||
#endif
|
||||
|
||||
// Cache line alignment specification
|
||||
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||
#define CACHE_LINE_ALIGNMENT __declspec(align(64))
|
||||
#else
|
||||
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
|
||||
#endif
|
||||
|
||||
#endif // !defined(TYPES_H_INCLUDED)
|
||||
|
||||
@@ -242,7 +242,10 @@ namespace {
|
||||
}
|
||||
if (token == "value")
|
||||
{
|
||||
getline(uip, token); // reads until end of line
|
||||
// Reads until end of line and left trim white space
|
||||
getline(uip, token);
|
||||
token.erase(0, token.find_first_not_of(" \n\r\t"));
|
||||
|
||||
set_option_value(name, token);
|
||||
} else
|
||||
push_button(name);
|
||||
|
||||
@@ -116,12 +116,9 @@ namespace {
|
||||
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
||||
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||
o["Full Depth Moves (PV nodes)"] = Option(14, 1, 100);
|
||||
o["Full Depth Moves (PV nodes)"] = Option(10, 1, 100);
|
||||
o["Full Depth Moves (non-PV nodes)"] = Option(3, 1, 100);
|
||||
o["Threat Depth"] = Option(5, 0, 100);
|
||||
o["LSN filtering"] = Option(false);
|
||||
o["LSN Time Margin (sec)"] = Option(4, 1, 10);
|
||||
o["LSN Value Margin"] = Option(200, 100, 600);
|
||||
o["Randomness"] = Option(0, 0, 10);
|
||||
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
||||
@@ -133,6 +130,7 @@ namespace {
|
||||
o["MultiPV"] = Option(1, 1, 500);
|
||||
o["UCI_ShowCurrLine"] = Option(false);
|
||||
o["UCI_Chess960"] = Option(false);
|
||||
o["UCI_AnalyseMode"] = Option(false);
|
||||
|
||||
// Any option should know its name so to be easily printed
|
||||
for (Options::iterator it = o.begin(); it != o.end(); ++it)
|
||||
@@ -194,15 +192,6 @@ void init_uci_options() {
|
||||
|
||||
options["Threads"].defaultValue = stringify(Min(cpu_count(), 7));
|
||||
options["Threads"].currentValue = stringify(Min(cpu_count(), 7));
|
||||
|
||||
// Increase the minimum split depth when the number of CPUs is big.
|
||||
// It would probably be better to let this depend on the number of threads
|
||||
// instead.
|
||||
if (cpu_count() > 4)
|
||||
{
|
||||
options["Minimum Split Depth"].defaultValue = "6";
|
||||
options["Minimum Split Depth"].currentValue = "6";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@ enum ValueType {
|
||||
VALUE_TYPE_UPPER = 1, // Upper bound
|
||||
VALUE_TYPE_LOWER = 2, // Lower bound
|
||||
VALUE_TYPE_EXACT = 3, // Exact score
|
||||
VALUE_TYPE_EVAL = 4 // Evaluation cache
|
||||
VALUE_TYPE_EVAL = 4, // Evaluation cache
|
||||
VALUE_TYPE_EV_UP = 5, // Evaluation cache for upper bound
|
||||
VALUE_TYPE_EV_LO = 6 // Evaluation cache for lower bound
|
||||
};
|
||||
|
||||
|
||||
@@ -96,7 +98,7 @@ const Value PieceValueEndgame[17] = {
|
||||
/// Bonus for having the side to move (modified by Joona Kiiski)
|
||||
|
||||
const Value TempoValueMidgame = Value(48);
|
||||
const Value TempoValueEndgame = Value(21);
|
||||
const Value TempoValueEndgame = Value(22);
|
||||
|
||||
|
||||
////
|
||||
|
||||
Reference in New Issue
Block a user