mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 14:27:45 +00:00
Compare commits
232 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7fcdfd6bf | |||
| 41816b7ced | |||
| 13224e1d9d | |||
| 10c1ae8da0 | |||
| 3a62738174 | |||
| 84451191f3 | |||
| 2ed3358faf | |||
| 08634b06a3 | |||
| 0e33fc6fd4 | |||
| a5a8830e97 | |||
| 2a14123550 | |||
| 8fabd69d4a | |||
| 1fc88071d1 | |||
| 7dca461927 | |||
| 7618ee2df1 | |||
| 661d48c27b | |||
| 42de93ac15 | |||
| 426f55b78d | |||
| b638f6b035 | |||
| 3de0bc43a2 | |||
| 9fc602bae7 | |||
| 49c50399fe | |||
| a4551c59e0 | |||
| c853b87c08 | |||
| 92bada1a32 | |||
| eaed535c5f | |||
| 49dfc50b12 | |||
| c835ee8853 | |||
| 7ff9678651 | |||
| 4ef068a506 | |||
| f23a9e8f88 | |||
| cc2a249952 | |||
| 55f0d6377f | |||
| aeb664e0ea | |||
| 8abdb131c8 | |||
| 43c93cb151 | |||
| 8d1d9f7181 | |||
| a303bde26c | |||
| 0f50f10327 | |||
| 8286e6ded2 | |||
| 3a558a3d8b | |||
| 14dbeb22dd | |||
| 68eb7e77f1 | |||
| 57340c109b | |||
| 111aa44662 | |||
| 29fb389760 | |||
| 0d292d1a2d | |||
| 5bb9da9287 | |||
| 34c7f1387d | |||
| fc23466236 | |||
| 01b228b5e1 | |||
| 2142be7d7f | |||
| 3888d14bd4 | |||
| 7bcd97933a | |||
| 9d4abbc6eb | |||
| c3b3dcc31a | |||
| e6f2d43b8a | |||
| 1a03f0b0d3 | |||
| 62f6d39204 | |||
| 936cd5b83d | |||
| 3c31776a20 | |||
| 0980f43ab0 | |||
| 9eedc0a463 | |||
| 195b54c312 | |||
| 89b4ad6433 | |||
| 77bb9a94ae | |||
| 8a78ac84f3 | |||
| 5c944fb3b4 | |||
| c974d9ef33 | |||
| 12feb5866f | |||
| 80810e4951 | |||
| c67b9916f1 | |||
| 78c6bb1079 | |||
| 85e60bfc8e | |||
| 79b57dd4ca | |||
| b9537edbb0 | |||
| d38f4f61e7 | |||
| 27c74c5245 | |||
| 2f2e8a68d8 | |||
| 1ea70dd9dd | |||
| 13c096f839 | |||
| 2de2b76896 | |||
| 8b99e94562 | |||
| 512a4e4ff0 | |||
| 2da290d72b | |||
| b39a24ecca | |||
| 189a005a0b | |||
| 7c61b8ad2a | |||
| a093f33154 | |||
| 0895f1ac71 | |||
| b29198354c | |||
| 40a7ffd53f | |||
| 8eae6a95fb | |||
| 2b740f5495 | |||
| fb5ba1d329 | |||
| 78e494fcbc | |||
| a16415f44d | |||
| 8a504d36f9 | |||
| 093dd8fe88 | |||
| 6382324afd | |||
| cb08413dc4 | |||
| 711ef615c7 | |||
| 74203e181d | |||
| 97fe0ac777 | |||
| 7ae16a193b | |||
| 8261f61964 | |||
| 6e1cb6e45b | |||
| 4bfa0c429e | |||
| 2e70a2873f | |||
| 9429d2d028 | |||
| d44fa46082 | |||
| c7866a4215 | |||
| 69644d3f73 | |||
| b0858877ae | |||
| 321f6d1d19 | |||
| e738fa7d10 | |||
| c5d546e18e | |||
| 8d65fcc0f3 | |||
| d8e5b8c133 | |||
| 6fe36d13de | |||
| 337ec0f3d0 | |||
| 5b1043ee11 | |||
| 439aea9ab7 | |||
| 770db27164 | |||
| 21d32aa7fe | |||
| 95d33aef9f | |||
| b5a4edd86f | |||
| 35ada63174 | |||
| 06a695d5b8 | |||
| 4b55d3d883 | |||
| 8008f78415 | |||
| 3941e4bdb3 | |||
| d7d2c1b7e3 | |||
| 17502a5659 | |||
| e84488ed6b | |||
| 252844e899 | |||
| b651e5334b | |||
| bd358533a4 | |||
| e4d3a15656 | |||
| 1d7a3f26e0 | |||
| a0005ba45f | |||
| bdd61b1744 | |||
| 973e574e1f | |||
| 27393ebae2 | |||
| 3c7eebb48d | |||
| 548bae80bd | |||
| 2360c8aa2f | |||
| 32bd6e44f0 | |||
| c83fd08fd4 | |||
| 62b43130e2 | |||
| cd112ee8eb | |||
| bb968fd42a | |||
| 307909bed8 | |||
| b95ba7b37e | |||
| f37741cc83 | |||
| 54b3d44194 | |||
| ea53006a9d | |||
| 6247f27a05 | |||
| 5b2fc1e1c0 | |||
| 05a8c318b8 | |||
| 22b8dc8c98 | |||
| cfe59de27d | |||
| c43c5fe9e0 | |||
| d0daa16769 | |||
| 87303d7ed3 | |||
| cf9bf4e58f | |||
| 5ca4284027 | |||
| dac1bcab90 | |||
| 81cfd81366 | |||
| d844a75d2c | |||
| c5e71f5150 | |||
| c5858ff9ae | |||
| 0ff91e16da | |||
| c2df60048e | |||
| 84ec1f7331 | |||
| b1ac6c69a0 | |||
| 56e09b4cc8 | |||
| 5ed0a60203 | |||
| 1588a4e846 | |||
| 5894c759cd | |||
| 3975a2b94f | |||
| eb6ddd54f1 | |||
| 01ebb3d996 | |||
| 285df57a9a | |||
| 806c1d8723 | |||
| a1b8c8109b | |||
| c01af56769 | |||
| 66d5c13a88 | |||
| 0edad63b44 | |||
| b833c8247a | |||
| 419c5b69ca | |||
| 72e1e9b986 | |||
| 1062459029 | |||
| b5d38ad1e5 | |||
| 000a975eaf | |||
| d457594197 | |||
| 942c18ef66 | |||
| 007285be2d | |||
| e817a55bc6 | |||
| 638f3d31cc | |||
| 55745f4105 | |||
| 968c3de8e0 | |||
| 6a6facc058 | |||
| 5b21c10afb | |||
| dba072c449 | |||
| e2e360fcbc | |||
| 49b1c5dccd | |||
| c99d963fa5 | |||
| 7c0679ad61 | |||
| cc974fa7a4 | |||
| 807844eab1 | |||
| 860260c3b1 | |||
| d11af1de11 | |||
| 721d557681 | |||
| 0e15b0f1d3 | |||
| 9e6d38d224 | |||
| c8af7a867e | |||
| 5c8f571459 | |||
| 0256db2a11 | |||
| 12d8f74242 | |||
| 7824603549 | |||
| 0f39e5c4ff | |||
| 990d83a72d | |||
| cf486cf229 | |||
| e0a8b36436 | |||
| 8d724220a7 | |||
| 0973cc2ef6 | |||
| 3f14f9a478 | |||
| aa86d81f79 | |||
| b884351cc7 | |||
| 4d9e9ac3d4 | |||
| 3dc9f95225 |
+37
-11
@@ -21,15 +21,16 @@
|
|||||||
### Executable name. Do not change
|
### Executable name. Do not change
|
||||||
EXE = stockfish
|
EXE = stockfish
|
||||||
|
|
||||||
|
### Installation dir definitions
|
||||||
|
PREFIX = /usr/local
|
||||||
|
BINDIR = $(PREFIX)/bin
|
||||||
|
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Compiler speed switches for both GCC and ICC. These settings are generally
|
### Compiler speed switches for both GCC and ICC. These settings are generally
|
||||||
### fast on a broad range of systems, but may be changed experimentally
|
### fast on a broad range of systems, but may be changed experimentally
|
||||||
###
|
|
||||||
### NOTE: Some versions of gcc miscompile value.h with -O2 or -O3, this is the
|
|
||||||
### safe setup, try changing to -O3 or -O2 and verify it works for you.
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
GCCFLAGS = -O1 -msse
|
GCCFLAGS = -O3 -msse
|
||||||
ICCFLAGS = -fast -msse
|
ICCFLAGS = -fast -msse
|
||||||
ICCFLAGS-OSX = -fast -mdynamic-no-pic
|
ICCFLAGS-OSX = -fast -mdynamic-no-pic
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ help:
|
|||||||
@echo "Makefile options:"
|
@echo "Makefile options:"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make > Default: Compiler = g++"
|
@echo "make > Default: Compiler = g++"
|
||||||
|
@echo "make gcc-popcnt > Compiler = g++ + popcnt-support"
|
||||||
@echo "make icc > Compiler = icpc"
|
@echo "make icc > Compiler = icpc"
|
||||||
@echo "make icc-profile > Compiler = icpc + automatic pgo-build"
|
@echo "make icc-profile > Compiler = icpc + automatic pgo-build"
|
||||||
@echo "make icc-profile-popcnt > Compiler = icpc + automatic pgo-build + popcnt-support"
|
@echo "make icc-profile-popcnt > Compiler = icpc + automatic pgo-build + popcnt-support"
|
||||||
@@ -94,14 +96,18 @@ help:
|
|||||||
@echo "make osx-icc64 > x86-Mac OS X 64 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-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 osx-icc64-profile > OSX 64 bit. Compiler = icpc + automatic pgo-build"
|
||||||
|
@echo "make hpux > HP-UX. Compiler = aCC"
|
||||||
@echo "make strip > Strip executable"
|
@echo "make strip > Strip executable"
|
||||||
@echo "make clean > Clean up"
|
@echo "make clean > Clean up"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
all: $(EXE) .depend
|
all: $(EXE) .depend
|
||||||
|
|
||||||
|
test check: default
|
||||||
|
@$(PGOBENCH)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o .depend *~ $(EXE)
|
$(RM) *.o .depend *~ $(EXE) core bench.txt
|
||||||
|
|
||||||
|
|
||||||
### Possible targets. You may add your own ones here
|
### Possible targets. You may add your own ones here
|
||||||
@@ -111,6 +117,13 @@ gcc:
|
|||||||
CXXFLAGS="$(GCCFLAGS)" \
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
all
|
all
|
||||||
|
|
||||||
|
gcc-popcnt:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='g++' \
|
||||||
|
CXXFLAGS="$(GCCFLAGS) -DUSE_POPCNT" \
|
||||||
|
all
|
||||||
|
|
||||||
|
|
||||||
icc:
|
icc:
|
||||||
$(MAKE) \
|
$(MAKE) \
|
||||||
CXX='icpc' \
|
CXX='icpc' \
|
||||||
@@ -184,6 +197,7 @@ osx-ppc32:
|
|||||||
CXX='g++' \
|
CXX='g++' \
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
CXXFLAGS+='-arch ppc' \
|
CXXFLAGS+='-arch ppc' \
|
||||||
|
CXXFLAGS+='-DBIGENDIAN' \
|
||||||
LDFLAGS+='-arch ppc' \
|
LDFLAGS+='-arch ppc' \
|
||||||
all
|
all
|
||||||
|
|
||||||
@@ -192,6 +206,7 @@ osx-ppc64:
|
|||||||
CXX='g++' \
|
CXX='g++' \
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
CXXFLAGS+='-arch ppc64' \
|
CXXFLAGS+='-arch ppc64' \
|
||||||
|
CXXFLAGS+='-DBIGENDIAN' \
|
||||||
LDFLAGS+='-arch ppc64' \
|
LDFLAGS+='-arch ppc64' \
|
||||||
all
|
all
|
||||||
|
|
||||||
@@ -199,16 +214,16 @@ osx-x86:
|
|||||||
$(MAKE) \
|
$(MAKE) \
|
||||||
CXX='g++' \
|
CXX='g++' \
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
CXXFLAGS+='-arch i386' \
|
CXXFLAGS+='-arch i386 -mdynamic-no-pic' \
|
||||||
LDFLAGS+='-arch i386' \
|
LDFLAGS+='-arch i386 -mdynamic-no-pic' \
|
||||||
all
|
all
|
||||||
|
|
||||||
osx-x86_64:
|
osx-x86_64:
|
||||||
$(MAKE) \
|
$(MAKE) \
|
||||||
CXX='g++' \
|
CXX='g++' \
|
||||||
CXXFLAGS="$(GCCFLAGS)" \
|
CXXFLAGS="$(GCCFLAGS)" \
|
||||||
CXXFLAGS+='-arch x86_64' \
|
CXXFLAGS+='-arch x86_64 -mdynamic-no-pic' \
|
||||||
LDFLAGS+='-arch x86_64' \
|
LDFLAGS+='-arch x86_64 -mdynamic-no-pic' \
|
||||||
all
|
all
|
||||||
|
|
||||||
osx-icc32:
|
osx-icc32:
|
||||||
@@ -291,6 +306,12 @@ osx-icc64-profile:
|
|||||||
$(MAKE) osx-icc64-profile-use
|
$(MAKE) osx-icc64-profile-use
|
||||||
@rm -rf profdir bench.txt
|
@rm -rf profdir bench.txt
|
||||||
|
|
||||||
|
hpux:
|
||||||
|
$(MAKE) \
|
||||||
|
CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG' \
|
||||||
|
CXXFLAGS="" \
|
||||||
|
LDFLAGS="" \
|
||||||
|
all
|
||||||
|
|
||||||
|
|
||||||
strip:
|
strip:
|
||||||
@@ -301,9 +322,14 @@ strip:
|
|||||||
$(EXE): $(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
install: default
|
||||||
|
-mkdir -p -m 755 $(BINDIR)
|
||||||
|
-cp $(EXE) $(BINDIR)
|
||||||
|
-strip $(BINDIR)/$(EXE)
|
||||||
|
|
||||||
### Dependencies. Do not change
|
### Dependencies. Do not change
|
||||||
.depend:
|
.depend:
|
||||||
$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@
|
-@$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
||||||
|
|
||||||
include .depend
|
-include .depend
|
||||||
|
|||||||
+3
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -49,6 +49,7 @@ Application::Application() {
|
|||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
init_eval(1);
|
init_eval(1);
|
||||||
init_bitbases();
|
init_bitbases();
|
||||||
|
init_search();
|
||||||
init_threads();
|
init_threads();
|
||||||
|
|
||||||
// Make random number generation less deterministic, for book moves
|
// Make random number generation less deterministic, for book moves
|
||||||
@@ -58,7 +59,7 @@ Application::Application() {
|
|||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
|
||||||
stop_threads();
|
exit_threads();
|
||||||
quit_eval();
|
quit_eval();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -84,9 +84,9 @@ void benchmark(const string& commandLine) {
|
|||||||
}
|
}
|
||||||
csStr >> threads;
|
csStr >> threads;
|
||||||
csVal >> val;
|
csVal >> val;
|
||||||
if (val < 1 || val > THREAD_MAX)
|
if (val < 1 || val > MAX_THREADS)
|
||||||
{
|
{
|
||||||
cerr << "The number of threads must be between 1 and " << THREAD_MAX << endl;
|
cerr << "The number of threads must be between 1 and " << MAX_THREADS << endl;
|
||||||
Application::exit_with_failure();
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
set_option_value("Hash", ttSize);
|
set_option_value("Hash", ttSize);
|
||||||
@@ -155,7 +155,7 @@ void benchmark(const string& commandLine) {
|
|||||||
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
|
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
|
||||||
if (limitType == "perft")
|
if (limitType == "perft")
|
||||||
totalNodes += perft(pos, maxDepth * OnePly);
|
totalNodes += perft(pos, maxDepth * OnePly);
|
||||||
else if (!think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
|
else if (!think(pos, false, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
|
||||||
break;
|
break;
|
||||||
totalNodes += nodes_searched();
|
totalNodes += nodes_searched();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+34
-21
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -297,8 +297,8 @@ void init_bitboards() {
|
|||||||
|
|
||||||
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
#if defined(IS_64BIT) && !defined(USE_BSFQ)
|
||||||
|
|
||||||
CACHE_LINE_ALIGNMENT
|
static CACHE_LINE_ALIGNMENT
|
||||||
static const int BitTable[64] = {
|
const int BitTable[64] = {
|
||||||
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15,
|
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15,
|
||||||
46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39,
|
46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39,
|
||||||
16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43,
|
16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43,
|
||||||
@@ -348,45 +348,58 @@ union b_union {
|
|||||||
|
|
||||||
Square pop_1st_bit(Bitboard* bb) {
|
Square pop_1st_bit(Bitboard* bb) {
|
||||||
|
|
||||||
b_union* u;
|
b_union u;
|
||||||
Square ret;
|
Square ret;
|
||||||
|
|
||||||
u = (b_union*)bb;
|
u.b = *bb;
|
||||||
|
|
||||||
if (u->dw.l)
|
if (u.dw.l)
|
||||||
{
|
{
|
||||||
ret = Square(BitTable[((u->dw.l ^ (u->dw.l - 1)) * 0x783a9b23) >> 26]);
|
ret = Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||||
u->dw.l &= (u->dw.l - 1);
|
u.dw.l &= (u.dw.l - 1);
|
||||||
|
*bb = u.b;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = Square(BitTable[((~(u->dw.h ^ (u->dw.h - 1))) * 0x783a9b23) >> 26]);
|
ret = Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
|
||||||
u->dw.h &= (u->dw.h - 1);
|
u.dw.h &= (u.dw.h - 1);
|
||||||
|
*bb = u.b;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Optimized bitScanReverse32() implementation by Pascal Georges. Note
|
||||||
|
// that first bit is 1, this allow to differentiate between 0 and 1.
|
||||||
|
static CACHE_LINE_ALIGNMENT
|
||||||
|
const char MsbTable[256] = {
|
||||||
|
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||||
|
5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||||
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||||
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||||
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||||
|
7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||||
|
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||||
|
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||||
|
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||||
|
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||||
|
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
|
||||||
|
};
|
||||||
|
|
||||||
int bitScanReverse32(uint32_t b)
|
int bitScanReverse32(uint32_t b)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
if (b > 0xFFFF) {
|
if (b > 0xFFFF)
|
||||||
|
{
|
||||||
b >>= 16;
|
b >>= 16;
|
||||||
result += 16;
|
result += 16;
|
||||||
}
|
}
|
||||||
if (b > 0xFF) {
|
if (b > 0xFF)
|
||||||
|
{
|
||||||
b >>= 8;
|
b >>= 8;
|
||||||
result += 8;
|
result += 8;
|
||||||
}
|
}
|
||||||
if (b > 0xF) {
|
return result + MsbTable[b];
|
||||||
b >>= 4;
|
|
||||||
result += 4;
|
|
||||||
}
|
|
||||||
if (b > 0x3) {
|
|
||||||
b >>= 2;
|
|
||||||
result += 2;
|
|
||||||
}
|
|
||||||
return result + (b > 0) + (b > 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+24
-33
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,40 +26,18 @@
|
|||||||
|
|
||||||
// Select type of intrinsic bit count instruction to use, see
|
// Select type of intrinsic bit count instruction to use, see
|
||||||
// README.txt on how to pgo compile with POPCNT support.
|
// README.txt on how to pgo compile with POPCNT support.
|
||||||
|
#if !defined(USE_POPCNT)
|
||||||
#if defined(__INTEL_COMPILER) && defined(USE_POPCNT) // Intel compiler
|
|
||||||
|
|
||||||
#include <nmmintrin.h>
|
|
||||||
|
|
||||||
inline bool cpu_has_popcnt() {
|
|
||||||
|
|
||||||
int CPUInfo[4] = {-1};
|
|
||||||
__cpuid(CPUInfo, 0x00000001);
|
|
||||||
return (CPUInfo[2] >> 23) & 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) _mm_popcnt_u64(x)
|
|
||||||
|
|
||||||
#elif defined(_MSC_VER) && defined(USE_POPCNT) // Microsoft compiler
|
|
||||||
|
|
||||||
#include <intrin.h>
|
|
||||||
|
|
||||||
inline bool cpu_has_popcnt() {
|
|
||||||
|
|
||||||
int CPUInfo[4] = {-1};
|
|
||||||
__cpuid(CPUInfo, 0x00000001);
|
|
||||||
return (CPUInfo[2] >> 23) & 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) __popcnt64(x)
|
|
||||||
|
|
||||||
#else // Safe fallback for unsupported compilers or when USE_POPCNT is disabled
|
|
||||||
|
|
||||||
inline bool cpu_has_popcnt() { return false; }
|
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) 0
|
#define POPCNT_INTRINSIC(x) 0
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define POPCNT_INTRINSIC(x) (int)__popcnt64(x)
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
|
||||||
#endif // cpu_has_popcnt() and POPCNT_INTRINSIC() definitions
|
#define POPCNT_INTRINSIC(x) ({ \
|
||||||
|
unsigned long __ret; \
|
||||||
|
__asm__("popcnt %1, %0" : "=r" (__ret) : "r" (x)); \
|
||||||
|
__ret; })
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// Software implementation of bit count functions
|
/// Software implementation of bit count functions
|
||||||
@@ -126,10 +104,23 @@ inline int count_1s_max_15(Bitboard b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Detect hardware POPCNT support
|
||||||
|
inline bool cpu_has_popcnt() {
|
||||||
|
|
||||||
|
int CPUInfo[4] = {-1};
|
||||||
|
__cpuid(CPUInfo, 0x00000001);
|
||||||
|
return (CPUInfo[2] >> 23) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Global constant initialized at startup that is set to true if
|
// Global constant initialized at startup that is set to true if
|
||||||
// CPU on which application runs supports POPCNT intrinsic. Unless
|
// CPU on which application runs supports POPCNT intrinsic. Unless
|
||||||
// USE_POPCNT is not defined.
|
// USE_POPCNT is not defined.
|
||||||
|
#if defined(USE_POPCNT)
|
||||||
const bool CpuHasPOPCNT = cpu_has_popcnt();
|
const bool CpuHasPOPCNT = cpu_has_popcnt();
|
||||||
|
#else
|
||||||
|
const bool CpuHasPOPCNT = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Global constant used to print info about the use of 64 optimized
|
// Global constant used to print info about the use of 64 optimized
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -390,7 +390,7 @@ void Book::close() {
|
|||||||
/// Book::file_name() returns the file name of the currently active book,
|
/// Book::file_name() returns the file name of the currently active book,
|
||||||
/// or the empty string if no book is open.
|
/// or the empty string if no book is open.
|
||||||
|
|
||||||
const string Book::file_name() const {
|
const string Book::file_name() { // Not const to compile on HP-UX 11.X
|
||||||
|
|
||||||
return is_open() ? fileName : "";
|
return is_open() ? fileName : "";
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -53,11 +53,14 @@ struct BookEntry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Book : private std::ifstream {
|
class Book : private std::ifstream {
|
||||||
|
Book(const Book&); // just decleared..
|
||||||
|
Book& operator=(const Book&); // ..to avoid a warning
|
||||||
public:
|
public:
|
||||||
|
Book() {}
|
||||||
~Book();
|
~Book();
|
||||||
void open(const std::string& fName);
|
void open(const std::string& fName);
|
||||||
void close();
|
void close();
|
||||||
const std::string file_name() const;
|
const std::string file_name();
|
||||||
Move get_move(const Position& pos);
|
Move get_move(const Position& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -49,6 +49,7 @@ inline void operator+= (Depth &d1, Depth d2) { d1 += int(d2); }
|
|||||||
inline Depth operator- (Depth d, int i) { return Depth(int(d) - i); }
|
inline Depth operator- (Depth d, int i) { return Depth(int(d) - i); }
|
||||||
inline Depth operator- (Depth d1, Depth d2) { return Depth(int(d1) - int(d2)); }
|
inline Depth operator- (Depth d1, Depth d2) { return Depth(int(d1) - int(d2)); }
|
||||||
inline void operator-= (Depth &d, int i) { d = Depth(int(d) - i); }
|
inline void operator-= (Depth &d, int i) { d = Depth(int(d) - i); }
|
||||||
|
inline void operator-= (Depth &d1, Depth d2) { d1 -= int(d2); }
|
||||||
inline Depth operator* (Depth d, int i) { return Depth(int(d) * i); }
|
inline Depth operator* (Depth d, int i) { return Depth(int(d) * i); }
|
||||||
inline Depth operator* (int i, Depth d) { return Depth(int(d) * i); }
|
inline Depth operator* (int i, Depth d) { return Depth(int(d) * i); }
|
||||||
inline void operator*= (Depth &d, int i) { d = Depth(int(d) * i); }
|
inline void operator*= (Depth &d, int i) { d = Depth(int(d) * i); }
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+25
-50
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -224,15 +224,19 @@ namespace {
|
|||||||
|
|
||||||
const int AttackWeight[] = { 0, 0, KnightAttackWeight, BishopAttackWeight, RookAttackWeight, QueenAttackWeight };
|
const int AttackWeight[] = { 0, 0, KnightAttackWeight, BishopAttackWeight, RookAttackWeight, QueenAttackWeight };
|
||||||
|
|
||||||
// Bonuses for safe checks, initialized from UCI options
|
// Bonuses for safe checks
|
||||||
int QueenContactCheckBonus, DiscoveredCheckBonus;
|
const int QueenContactCheckBonus = 3;
|
||||||
int QueenCheckBonus, RookCheckBonus, BishopCheckBonus, KnightCheckBonus;
|
const int DiscoveredCheckBonus = 3;
|
||||||
|
const int QueenCheckBonus = 2;
|
||||||
|
const int RookCheckBonus = 1;
|
||||||
|
const int BishopCheckBonus = 1;
|
||||||
|
const int KnightCheckBonus = 1;
|
||||||
|
|
||||||
// Scan for queen contact mates?
|
// Scan for queen contact mates?
|
||||||
const bool QueenContactMates = true;
|
const bool QueenContactMates = true;
|
||||||
|
|
||||||
// Bonus for having a mate threat, initialized from UCI options
|
// Bonus for having a mate threat
|
||||||
int MateThreatBonus;
|
const int MateThreatBonus = 3;
|
||||||
|
|
||||||
// InitKingDanger[] contains bonuses based on the position of the defending
|
// InitKingDanger[] contains bonuses based on the position of the defending
|
||||||
// king.
|
// king.
|
||||||
@@ -251,9 +255,10 @@ namespace {
|
|||||||
// in init_safety().
|
// in init_safety().
|
||||||
Value SafetyTable[100];
|
Value SafetyTable[100];
|
||||||
|
|
||||||
// Pawn and material hash tables, indexed by the current thread id
|
// Pawn and material hash tables, indexed by the current thread id.
|
||||||
MaterialInfoTable* MaterialTable[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
// Note that they will be initialized at 0 being global variables.
|
||||||
PawnInfoTable* PawnTable[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
MaterialInfoTable* MaterialTable[MAX_THREADS];
|
||||||
|
PawnInfoTable* PawnTable[MAX_THREADS];
|
||||||
|
|
||||||
// Sizes of pawn and material hash tables
|
// Sizes of pawn and material hash tables
|
||||||
const int PawnTableSize = 16384;
|
const int PawnTableSize = 16384;
|
||||||
@@ -304,7 +309,7 @@ template<bool HasPopCnt>
|
|||||||
Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(threadID >= 0 && threadID < THREAD_MAX);
|
assert(threadID >= 0 && threadID < MAX_THREADS);
|
||||||
assert(!pos.is_check());
|
assert(!pos.is_check());
|
||||||
|
|
||||||
memset(&ei, 0, sizeof(EvalInfo));
|
memset(&ei, 0, sizeof(EvalInfo));
|
||||||
@@ -435,28 +440,13 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
/// quick_evaluate() does a very approximate evaluation of the current position.
|
|
||||||
/// 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) {
|
|
||||||
|
|
||||||
assert(pos.is_ok());
|
|
||||||
|
|
||||||
static const ScaleFactor sf[2] = {SCALE_FACTOR_NORMAL, SCALE_FACTOR_NORMAL};
|
|
||||||
|
|
||||||
Value v = scale_by_game_phase(pos.value(), MaterialInfoTable::game_phase(pos), sf);
|
|
||||||
return (pos.side_to_move() == WHITE ? v : -v);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// 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) {
|
void init_eval(int threads) {
|
||||||
|
|
||||||
assert(threads <= THREAD_MAX);
|
assert(threads <= MAX_THREADS);
|
||||||
|
|
||||||
for (int i = 0; i < THREAD_MAX; i++)
|
for (int i = 0; i < MAX_THREADS; i++)
|
||||||
{
|
{
|
||||||
if (i >= threads)
|
if (i >= threads)
|
||||||
{
|
{
|
||||||
@@ -478,7 +468,7 @@ void init_eval(int threads) {
|
|||||||
|
|
||||||
void quit_eval() {
|
void quit_eval() {
|
||||||
|
|
||||||
for (int i = 0; i < THREAD_MAX; i++)
|
for (int i = 0; i < MAX_THREADS; i++)
|
||||||
{
|
{
|
||||||
delete PawnTable[i];
|
delete PawnTable[i];
|
||||||
delete MaterialTable[i];
|
delete MaterialTable[i];
|
||||||
@@ -874,16 +864,13 @@ namespace {
|
|||||||
// capturing a single attacking piece can therefore result in a score
|
// capturing a single attacking piece can therefore result in a score
|
||||||
// change far bigger than the value of the captured piece.
|
// change far bigger than the value of the captured piece.
|
||||||
Score v = apply_weight(make_score(SafetyTable[attackUnits], 0), WeightKingSafety[Us]);
|
Score v = apply_weight(make_score(SafetyTable[attackUnits], 0), WeightKingSafety[Us]);
|
||||||
|
|
||||||
ei.value -= Sign[Us] * v;
|
ei.value -= Sign[Us] * v;
|
||||||
|
ei.futilityMargin[Us] += mg_value(v);
|
||||||
if (Us == pos.side_to_move())
|
|
||||||
ei.futilityMargin += mg_value(v);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// evaluate_passed_pawns() evaluates the passed pawns of the given color
|
// evaluate_passed_pawns_of_color() evaluates the passed pawns of the given color
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
void evaluate_passed_pawns_of_color(const Position& pos, int movesToGo[], Square pawnToGo[], EvalInfo& ei) {
|
void evaluate_passed_pawns_of_color(const Position& pos, int movesToGo[], Square pawnToGo[], EvalInfo& ei) {
|
||||||
@@ -1217,29 +1204,17 @@ namespace {
|
|||||||
|
|
||||||
void init_safety() {
|
void init_safety() {
|
||||||
|
|
||||||
QueenContactCheckBonus = get_option_value_int("Queen Contact Check Bonus");
|
int maxSlope = 30;
|
||||||
QueenCheckBonus = get_option_value_int("Queen Check Bonus");
|
int peak = 0x500;
|
||||||
RookCheckBonus = get_option_value_int("Rook Check Bonus");
|
double a = 0.4;
|
||||||
BishopCheckBonus = get_option_value_int("Bishop Check Bonus");
|
double b = 0.0;
|
||||||
KnightCheckBonus = get_option_value_int("Knight Check Bonus");
|
|
||||||
DiscoveredCheckBonus = get_option_value_int("Discovered Check Bonus");
|
|
||||||
MateThreatBonus = get_option_value_int("Mate Threat Bonus");
|
|
||||||
|
|
||||||
int maxSlope = get_option_value_int("King Safety Max Slope");
|
|
||||||
int peak = get_option_value_int("King Safety Max Value") * 256 / 100;
|
|
||||||
double a = get_option_value_int("King Safety Coefficient") / 100.0;
|
|
||||||
double b = get_option_value_int("King Safety X Intercept");
|
|
||||||
bool quad = (get_option_value_string("King Safety Curve") == "Quadratic");
|
|
||||||
bool linear = (get_option_value_string("King Safety Curve") == "Linear");
|
|
||||||
|
|
||||||
for (int i = 0; i < 100; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
if (i < b)
|
if (i < b)
|
||||||
SafetyTable[i] = Value(0);
|
SafetyTable[i] = Value(0);
|
||||||
else if (quad)
|
else
|
||||||
SafetyTable[i] = Value((int)(a * (i - b) * (i - b)));
|
SafetyTable[i] = Value((int)(a * (i - b) * (i - b)));
|
||||||
else if (linear)
|
|
||||||
SafetyTable[i] = Value((int)(100 * a * (i - b)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 100; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
|
|||||||
+5
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -47,6 +47,8 @@ class Position;
|
|||||||
|
|
||||||
struct EvalInfo {
|
struct EvalInfo {
|
||||||
|
|
||||||
|
EvalInfo() { futilityMargin[0] = futilityMargin[1] = Value(0); }
|
||||||
|
|
||||||
// Middle game and endgame evaluations
|
// Middle game and endgame evaluations
|
||||||
Score value;
|
Score value;
|
||||||
|
|
||||||
@@ -94,8 +96,8 @@ struct EvalInfo {
|
|||||||
Score mobility;
|
Score mobility;
|
||||||
|
|
||||||
// Extra futility margin. This is added to the standard futility margin
|
// Extra futility margin. This is added to the standard futility margin
|
||||||
// in the quiescence search.
|
// in the quiescence search. One for each color.
|
||||||
Value futilityMargin;
|
Value futilityMargin[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -104,7 +106,6 @@ struct EvalInfo {
|
|||||||
////
|
////
|
||||||
|
|
||||||
extern Value evaluate(const Position& pos, EvalInfo& ei, int threadID);
|
extern Value evaluate(const Position& pos, EvalInfo& ei, int threadID);
|
||||||
extern Value quick_evaluate(const Position& pos);
|
|
||||||
extern void init_eval(int threads);
|
extern void init_eval(int threads);
|
||||||
extern void quit_eval();
|
extern void quit_eval();
|
||||||
extern void read_weights(Color sideToMove);
|
extern void read_weights(Color sideToMove);
|
||||||
|
|||||||
+27
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -42,6 +42,7 @@ History::History() { clear(); }
|
|||||||
|
|
||||||
void History::clear() {
|
void History::clear() {
|
||||||
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
memset(history, 0, 2 * 8 * 64 * sizeof(int));
|
||||||
|
memset(maxStaticValueDelta, 0, 2 * 8 * 64 * sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ void History::success(Piece p, Square to, Depth d) {
|
|||||||
if (history[p][to] >= HistoryMax)
|
if (history[p][to] >= HistoryMax)
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
for (int j = 0; j < 64; j++)
|
for (int j = 0; j < 64; j++)
|
||||||
history[i][j] /= 4;
|
history[i][j] /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -75,8 +76,12 @@ void History::failure(Piece p, Square to, Depth d) {
|
|||||||
assert(square_is_ok(to));
|
assert(square_is_ok(to));
|
||||||
|
|
||||||
history[p][to] -= int(d) * int(d);
|
history[p][to] -= int(d) * int(d);
|
||||||
if (history[p][to] < 0)
|
|
||||||
history[p][to] = 0;
|
// Prevent history underflow
|
||||||
|
if (history[p][to] <= -HistoryMax)
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
for (int j = 0; j < 64; j++)
|
||||||
|
history[i][j] /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,3 +95,21 @@ int History::move_ordering_score(Piece p, Square to) const {
|
|||||||
|
|
||||||
return history[p][to];
|
return history[p][to];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// History::set_gain() and History::gain() store and retrieve the
|
||||||
|
/// gain of a move given the delta of the static position evaluations
|
||||||
|
/// before and after the move.
|
||||||
|
|
||||||
|
void History::set_gain(Piece p, Square to, Value delta)
|
||||||
|
{
|
||||||
|
if (delta >= maxStaticValueDelta[p][to])
|
||||||
|
maxStaticValueDelta[p][to] = delta;
|
||||||
|
else
|
||||||
|
maxStaticValueDelta[p][to]--;
|
||||||
|
}
|
||||||
|
|
||||||
|
Value History::gain(Piece p, Square to) const
|
||||||
|
{
|
||||||
|
return Value(maxStaticValueDelta[p][to]);
|
||||||
|
}
|
||||||
|
|||||||
+7
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
|
#include "value.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -49,9 +50,12 @@ public:
|
|||||||
void success(Piece p, Square to, Depth d);
|
void success(Piece p, Square to, Depth d);
|
||||||
void failure(Piece p, Square to, Depth d);
|
void failure(Piece p, Square to, Depth d);
|
||||||
int move_ordering_score(Piece p, Square to) const;
|
int move_ordering_score(Piece p, Square to) const;
|
||||||
|
void set_gain(Piece p, Square to, Value delta);
|
||||||
|
Value gain(Piece p, Square to) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int history[16][64]; // [piece][square]
|
int history[16][64]; // [piece][square]
|
||||||
|
int maxStaticValueDelta[16][64]; // [piece][from_square][to_square]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -61,13 +65,13 @@ private:
|
|||||||
|
|
||||||
/// HistoryMax controls how often the history counters will be scaled down:
|
/// HistoryMax controls how often the history counters will be scaled down:
|
||||||
/// When the history score for a move gets bigger than HistoryMax, all
|
/// When the history score for a move gets bigger than HistoryMax, all
|
||||||
/// entries in the table are divided by 4. It is difficult to guess what
|
/// entries in the table are divided by 2. It is difficult to guess what
|
||||||
/// the ideal value of this constant is. Scaling down the scores often has
|
/// the ideal value of this constant is. Scaling down the scores often has
|
||||||
/// the effect that parts of the search tree which have been searched
|
/// the effect that parts of the search tree which have been searched
|
||||||
/// recently have a bigger importance for move ordering than the moves which
|
/// recently have a bigger importance for move ordering than the moves which
|
||||||
/// have been searched a long time ago.
|
/// have been searched a long time ago.
|
||||||
|
|
||||||
const int HistoryMax = 25000 * OnePly;
|
const int HistoryMax = 50000 * OnePly;
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(HISTORY_H_INCLUDED)
|
#endif // !defined(HISTORY_H_INCLUDED)
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -99,5 +99,4 @@ typedef CRITICAL_SECTION Lock;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(LOCK_H_INCLUDED)
|
#endif // !defined(LOCK_H_INCLUDED)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -374,7 +374,6 @@ EndgameFunctions::EndgameFunctions() {
|
|||||||
add<ScalingFunction<KBPPKB> >("KBPPKB");
|
add<ScalingFunction<KBPPKB> >("KBPPKB");
|
||||||
add<ScalingFunction<KBPKN> >("KBPKN");
|
add<ScalingFunction<KBPKN> >("KBPKN");
|
||||||
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
||||||
add<ScalingFunction<KRPPKRP> >("KRPPKRP");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EndgameFunctions::~EndgameFunctions() {
|
EndgameFunctions::~EndgameFunctions() {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+64
-6
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,6 +27,9 @@
|
|||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
# if defined(__hpux)
|
||||||
|
# include <sys/pstat.h>
|
||||||
|
# endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -38,6 +41,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -50,7 +54,7 @@ using namespace std;
|
|||||||
/// Version number. If this is left empty, the current date (in the format
|
/// Version number. If this is left empty, the current date (in the format
|
||||||
/// YYMMDD) is used as a version number.
|
/// YYMMDD) is used as a version number.
|
||||||
|
|
||||||
static const string EngineVersion = "1.6.1";
|
static const string EngineVersion = "1.7";
|
||||||
static const string AppName = "Stockfish";
|
static const string AppName = "Stockfish";
|
||||||
static const string AppTag = "";
|
static const string AppTag = "";
|
||||||
|
|
||||||
@@ -179,23 +183,32 @@ int get_system_time() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// cpu_count() tries to detect the number of CPU cores.
|
/// builtin_cpu_count() tries to detect the number of CPU cores, if
|
||||||
|
/// hyper-threading is enabled this is the number of logical processors.
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
|
|
||||||
# if defined(_SC_NPROCESSORS_ONLN)
|
# if defined(_SC_NPROCESSORS_ONLN)
|
||||||
int cpu_count() {
|
static int builtin_cpu_count() {
|
||||||
return Min(sysconf(_SC_NPROCESSORS_ONLN), 8);
|
return Min(sysconf(_SC_NPROCESSORS_ONLN), 8);
|
||||||
}
|
}
|
||||||
|
# elif defined(__hpux)
|
||||||
|
static int builtin_cpu_count() {
|
||||||
|
struct pst_dynamic psd;
|
||||||
|
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) == -1)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return Min(psd.psd_proc_cnt, 8);
|
||||||
|
}
|
||||||
# else
|
# else
|
||||||
int cpu_count() {
|
static int builtin_cpu_count() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int cpu_count() {
|
static int builtin_cpu_count() {
|
||||||
SYSTEM_INFO s;
|
SYSTEM_INFO s;
|
||||||
GetSystemInfo(&s);
|
GetSystemInfo(&s);
|
||||||
return Min(s.dwNumberOfProcessors, 8);
|
return Min(s.dwNumberOfProcessors, 8);
|
||||||
@@ -204,6 +217,51 @@ int cpu_count() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/// HT_enabled() returns true if hyper-threading is enabled on current machine
|
||||||
|
|
||||||
|
static bool HT_enabled() {
|
||||||
|
|
||||||
|
char CPUString[0x20];
|
||||||
|
int CPUInfo[4] = {-1};
|
||||||
|
int nIds, nLogicalCPU, nCores;
|
||||||
|
|
||||||
|
// Detect CPU producer
|
||||||
|
__cpuid(CPUInfo, 0);
|
||||||
|
nIds = CPUInfo[0];
|
||||||
|
|
||||||
|
memset(CPUString, 0, sizeof(CPUString));
|
||||||
|
memcpy(&CPUString[0], &CPUInfo[1], sizeof(int));
|
||||||
|
memcpy(&CPUString[4], &CPUInfo[3], sizeof(int));
|
||||||
|
memcpy(&CPUString[8], &CPUInfo[2], sizeof(int));
|
||||||
|
|
||||||
|
// Not an Intel CPU or CPUID.4 not supported
|
||||||
|
if (strcmp(CPUString, "GenuineIntel") || nIds < 4)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Detect if HT Technology is supported
|
||||||
|
__cpuid(CPUInfo, 1);
|
||||||
|
if (!((CPUInfo[3] >> 28) & 1))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
nLogicalCPU = (CPUInfo[1] >> 16) & 0xFF;
|
||||||
|
|
||||||
|
// Detect number of cores
|
||||||
|
__cpuid(CPUInfo, 4);
|
||||||
|
nCores = 1 + ((CPUInfo[0] >> 26) & 0x3F);
|
||||||
|
|
||||||
|
return nLogicalCPU > nCores;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// cpu_count() tries to detect the number of physical CPU cores taking
|
||||||
|
/// in account hyper-threading.
|
||||||
|
|
||||||
|
int cpu_count() {
|
||||||
|
|
||||||
|
return HT_enabled() ? builtin_cpu_count() / 2 : builtin_cpu_count();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
From Beowulf, from Olithink
|
From Beowulf, from Olithink
|
||||||
*/
|
*/
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+6
-26
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -86,10 +86,10 @@ inline void insertion_sort(T* firstMove, T* lastMove)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our dedicated sort in range [firstMove, lastMove), it is well
|
// Our dedicated sort in range [firstMove, lastMove), first splits
|
||||||
// tuned for non-captures where we have a lot of zero scored moves.
|
// positive scores from ramining then order seaprately the two sets.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void sort_moves(T* firstMove, T* lastMove)
|
inline void sort_moves(T* firstMove, T* lastMove, T** lastPositive)
|
||||||
{
|
{
|
||||||
T tmp;
|
T tmp;
|
||||||
T *p, *d;
|
T *p, *d;
|
||||||
@@ -114,29 +114,9 @@ inline void sort_moves(T* firstMove, T* lastMove)
|
|||||||
|
|
||||||
} while (p != d);
|
} while (p != d);
|
||||||
|
|
||||||
// Sort positives
|
// Sort just positive scored moves, remaining only when we get there
|
||||||
insertion_sort<T>(firstMove, p);
|
insertion_sort<T>(firstMove, p);
|
||||||
|
*lastPositive = p;
|
||||||
d = lastMove;
|
|
||||||
p--;
|
|
||||||
|
|
||||||
// Split zero vs negatives
|
|
||||||
do {
|
|
||||||
while ((++p)->score == 0);
|
|
||||||
|
|
||||||
if (p != d)
|
|
||||||
{
|
|
||||||
while (--d != p && d->score < 0);
|
|
||||||
|
|
||||||
tmp = *p;
|
|
||||||
*p = *d;
|
|
||||||
*d = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (p != d);
|
|
||||||
|
|
||||||
// Sort negatives
|
|
||||||
insertion_sort<T>(p, lastMove);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Picks up the best move in range [curMove, lastMove), one per cycle.
|
// Picks up the best move in range [curMove, lastMove), one per cycle.
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+40
-33
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -71,11 +71,11 @@ namespace {
|
|||||||
/// move ordering is at the current node.
|
/// move ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
||||||
const History& h, SearchStack* ss) : pos(p), H(h) {
|
const History& h, SearchStack* ss, Value beta) : pos(p), H(h) {
|
||||||
int searchTT = ttm;
|
int searchTT = ttm;
|
||||||
ttMoves[0].move = ttm;
|
ttMoves[0].move = ttm;
|
||||||
finished = false;
|
|
||||||
lastBadCapture = badCaptures;
|
lastBadCapture = badCaptures;
|
||||||
|
badCaptureThreshold = 0;
|
||||||
|
|
||||||
pinned = p.pinned_pieces(pos.side_to_move());
|
pinned = p.pinned_pieces(pos.side_to_move());
|
||||||
|
|
||||||
@@ -91,12 +91,26 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
|
|||||||
if (p.is_check())
|
if (p.is_check())
|
||||||
phasePtr = EvasionsPhaseTable;
|
phasePtr = EvasionsPhaseTable;
|
||||||
else if (d > Depth(0))
|
else if (d > Depth(0))
|
||||||
|
{
|
||||||
|
// Consider sligtly negative captures as good if at low
|
||||||
|
// depth and far from beta.
|
||||||
|
if (ss && ss->eval < beta - PawnValueMidgame && d < 3 * OnePly)
|
||||||
|
badCaptureThreshold = -PawnValueMidgame;
|
||||||
|
|
||||||
phasePtr = MainSearchPhaseTable;
|
phasePtr = MainSearchPhaseTable;
|
||||||
else if (d == Depth(0))
|
} else if (d == Depth(0))
|
||||||
phasePtr = QsearchWithChecksPhaseTable;
|
phasePtr = QsearchWithChecksPhaseTable;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
phasePtr = QsearchWithoutChecksPhaseTable;
|
phasePtr = QsearchWithoutChecksPhaseTable;
|
||||||
|
|
||||||
|
// Skip TT move if is not a capture or a promotion, this avoids
|
||||||
|
// qsearch tree explosion due to a possible perpetual check or
|
||||||
|
// similar rare cases when TT table is full.
|
||||||
|
if (ttm != MOVE_NONE && !pos.move_is_capture_or_promotion(ttm))
|
||||||
|
searchTT = ttMoves[0].move = MOVE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
phasePtr += !searchTT - 1;
|
phasePtr += !searchTT - 1;
|
||||||
go_next_phase();
|
go_next_phase();
|
||||||
}
|
}
|
||||||
@@ -129,7 +143,7 @@ void MovePicker::go_next_phase() {
|
|||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
lastMove = generate_noncaptures(pos, moves);
|
lastMove = generate_noncaptures(pos, moves);
|
||||||
score_noncaptures();
|
score_noncaptures();
|
||||||
sort_moves(moves, lastMove);
|
sort_moves(moves, lastMove, &lastGoodNonCapture);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
case PH_BAD_CAPTURES:
|
||||||
@@ -142,7 +156,7 @@ void MovePicker::go_next_phase() {
|
|||||||
case PH_EVASIONS:
|
case PH_EVASIONS:
|
||||||
assert(pos.is_check());
|
assert(pos.is_check());
|
||||||
lastMove = generate_evasions(pos, moves);
|
lastMove = generate_evasions(pos, moves);
|
||||||
score_evasions();
|
score_evasions_or_checks();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_QCAPTURES:
|
case PH_QCAPTURES:
|
||||||
@@ -151,12 +165,12 @@ void MovePicker::go_next_phase() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_QCHECKS:
|
case PH_QCHECKS:
|
||||||
// Perhaps we should order moves move here? FIXME
|
|
||||||
lastMove = generate_non_capture_checks(pos, moves);
|
lastMove = generate_non_capture_checks(pos, moves);
|
||||||
|
score_evasions_or_checks();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_STOP:
|
case PH_STOP:
|
||||||
lastMove = curMove + 1; // hack to be friendly for get_next_move()
|
lastMove = curMove + 1; // Avoids another go_next_phase() call
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -216,16 +230,16 @@ void MovePicker::score_noncaptures() {
|
|||||||
piece = pos.piece_on(from);
|
piece = pos.piece_on(from);
|
||||||
hs = H.move_ordering_score(piece, to);
|
hs = H.move_ordering_score(piece, to);
|
||||||
|
|
||||||
// Ensure history is always preferred to pst
|
// Ensure history has always highest priority
|
||||||
if (hs > 0)
|
if (hs > 0)
|
||||||
hs += 1000;
|
hs += 10000;
|
||||||
|
|
||||||
// pst based scoring
|
// Gain table based scoring
|
||||||
cur->score = hs + mg_value(pos.pst_delta(piece, from, to));
|
cur->score = hs + 16 * H.gain(piece, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovePicker::score_evasions() {
|
void MovePicker::score_evasions_or_checks() {
|
||||||
// Try good captures ordered by MVV/LVA, then non-captures if
|
// Try good captures ordered by MVV/LVA, then non-captures if
|
||||||
// destination square is not under attack, ordered by history
|
// destination square is not under attack, ordered by history
|
||||||
// value, and at the end bad-captures and non-captures with a
|
// value, and at the end bad-captures and non-captures with a
|
||||||
@@ -233,11 +247,15 @@ void MovePicker::score_evasions() {
|
|||||||
Move m;
|
Move m;
|
||||||
int seeScore;
|
int seeScore;
|
||||||
|
|
||||||
|
// Skip if we don't have at least two moves to order
|
||||||
|
if (lastMove < moves + 2)
|
||||||
|
return;
|
||||||
|
|
||||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
{
|
{
|
||||||
m = cur->move;
|
m = cur->move;
|
||||||
if ((seeScore = pos.see_sign(m)) < 0)
|
if ((seeScore = pos.see_sign(m)) < 0)
|
||||||
cur->score = seeScore;
|
cur->score = seeScore - HistoryMax; // Be sure are at the bottom
|
||||||
else if (pos.move_is_capture(m))
|
else if (pos.move_is_capture(m))
|
||||||
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
||||||
- pos.type_of_piece_on(move_from(m)) + HistoryMax;
|
- pos.type_of_piece_on(move_from(m)) + HistoryMax;
|
||||||
@@ -251,6 +269,8 @@ void MovePicker::score_evasions() {
|
|||||||
/// are no more moves left.
|
/// are no more moves left.
|
||||||
/// It picks the move with the biggest score from a list of generated moves taking
|
/// It picks the move with the biggest score from a list of generated moves taking
|
||||||
/// care not to return the tt move if has already been searched previously.
|
/// care not to return the tt move if has already been searched previously.
|
||||||
|
/// Note that this function is not thread safe so should be lock protected by
|
||||||
|
/// caller when accessed through a shared MovePicker object.
|
||||||
|
|
||||||
Move MovePicker::get_next_move() {
|
Move MovePicker::get_next_move() {
|
||||||
|
|
||||||
@@ -277,7 +297,7 @@ Move MovePicker::get_next_move() {
|
|||||||
{
|
{
|
||||||
// Check for a non negative SEE now
|
// Check for a non negative SEE now
|
||||||
int seeValue = pos.see_sign(move);
|
int seeValue = pos.see_sign(move);
|
||||||
if (seeValue >= 0)
|
if (seeValue >= badCaptureThreshold)
|
||||||
return move;
|
return move;
|
||||||
|
|
||||||
// Losing capture, move it to the badCaptures[] array, note
|
// Losing capture, move it to the badCaptures[] array, note
|
||||||
@@ -300,6 +320,11 @@ Move MovePicker::get_next_move() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
|
|
||||||
|
// Sort negative scored moves only when we get there
|
||||||
|
if (curMove == lastGoodNonCapture)
|
||||||
|
insertion_sort(lastGoodNonCapture, lastMove);
|
||||||
|
|
||||||
move = (curMove++)->move;
|
move = (curMove++)->move;
|
||||||
if ( move != ttMoves[0].move
|
if ( move != ttMoves[0].move
|
||||||
&& move != ttMoves[1].move
|
&& move != ttMoves[1].move
|
||||||
@@ -340,21 +365,3 @@ Move MovePicker::get_next_move() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A variant of get_next_move() which takes a lock as a parameter, used to
|
|
||||||
/// prevent multiple threads from picking the same move at a split point.
|
|
||||||
|
|
||||||
Move MovePicker::get_next_move(Lock &lock) {
|
|
||||||
|
|
||||||
lock_grab(&lock);
|
|
||||||
if (finished)
|
|
||||||
{
|
|
||||||
lock_release(&lock);
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
|
||||||
Move m = get_next_move();
|
|
||||||
if (m == MOVE_NONE)
|
|
||||||
finished = true;
|
|
||||||
|
|
||||||
lock_release(&lock);
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|||||||
+5
-8
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -50,24 +49,22 @@ class MovePicker {
|
|||||||
MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
|
MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL);
|
MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL, Value beta = -VALUE_INFINITE);
|
||||||
Move get_next_move();
|
Move get_next_move();
|
||||||
Move get_next_move(Lock& lock);
|
|
||||||
int number_of_evasions() const;
|
int number_of_evasions() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void score_captures();
|
void score_captures();
|
||||||
void score_noncaptures();
|
void score_noncaptures();
|
||||||
void score_evasions();
|
void score_evasions_or_checks();
|
||||||
void go_next_phase();
|
void go_next_phase();
|
||||||
|
|
||||||
const Position& pos;
|
const Position& pos;
|
||||||
const History& H;
|
const History& H;
|
||||||
MoveStack ttMoves[2], killers[2];
|
MoveStack ttMoves[2], killers[2];
|
||||||
bool finished;
|
int badCaptureThreshold, phase;
|
||||||
int phase;
|
|
||||||
const uint8_t* phasePtr;
|
const uint8_t* phasePtr;
|
||||||
MoveStack *curMove, *lastMove, *lastBadCapture;
|
MoveStack *curMove, *lastMove, *lastGoodNonCapture, *lastBadCapture;
|
||||||
Bitboard pinned;
|
Bitboard pinned;
|
||||||
MoveStack moves[256], badCaptures[64];
|
MoveStack moves[256], badCaptures[64];
|
||||||
};
|
};
|
||||||
|
|||||||
+17
-27
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -226,21 +226,16 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
|
|||||||
Bitboard b = outpost_mask(Us, s) & theirPawns & (FileFBB | FileGBB | FileHBB);
|
Bitboard b = outpost_mask(Us, s) & theirPawns & (FileFBB | FileGBB | FileHBB);
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
|
// Give a bonus according to the distance of the nearest enemy pawn
|
||||||
Square s2 = pop_1st_bit(&b);
|
Square s2 = pop_1st_bit(&b);
|
||||||
|
int v = StormLeverBonus[f] - 2 * square_distance(s, s2);
|
||||||
|
|
||||||
|
// If enemy pawn has no pawn beside itself is particularly vulnerable.
|
||||||
|
// Big bonus, especially against a weakness on the rook file
|
||||||
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||||
{
|
v *= (square_file(s2) == FILE_H ? 4 : 2);
|
||||||
// The enemy pawn has no pawn beside itself, which makes it
|
|
||||||
// particularly vulnerable. Big bonus, especially against a
|
bonus += v;
|
||||||
// weakness on the rook file.
|
|
||||||
if (square_file(s2) == FILE_H)
|
|
||||||
bonus += 4*StormLeverBonus[f] - 8*square_distance(s, s2);
|
|
||||||
else
|
|
||||||
bonus += 2*StormLeverBonus[f] - 4*square_distance(s, s2);
|
|
||||||
} else
|
|
||||||
// There is at least one enemy pawn beside the enemy pawn we look
|
|
||||||
// at, which means that the pawn has somewhat better chances of
|
|
||||||
// defending itself by advancing. Smaller bonus.
|
|
||||||
bonus += StormLeverBonus[f] - 2*square_distance(s, s2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pi->ksStormValue[Us] += bonus;
|
pi->ksStormValue[Us] += bonus;
|
||||||
@@ -252,21 +247,16 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
|
|||||||
Bitboard b = outpost_mask(Us, s) & theirPawns & (FileABB | FileBBB | FileCBB);
|
Bitboard b = outpost_mask(Us, s) & theirPawns & (FileABB | FileBBB | FileCBB);
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
|
// Give a bonus according to the distance of the nearest enemy pawn
|
||||||
Square s2 = pop_1st_bit(&b);
|
Square s2 = pop_1st_bit(&b);
|
||||||
|
int v = StormLeverBonus[f] - 4 * square_distance(s, s2);
|
||||||
|
|
||||||
|
// If enemy pawn has no pawn beside itself is particularly vulnerable.
|
||||||
|
// Big bonus, especially against a weakness on the rook file
|
||||||
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
if (!(theirPawns & neighboring_files_bb(s2) & rank_bb(s2)))
|
||||||
{
|
v *= (square_file(s2) == FILE_A ? 4 : 2);
|
||||||
// The enemy pawn has no pawn beside itself, which makes it
|
|
||||||
// particularly vulnerable. Big bonus, especially against a
|
bonus += v;
|
||||||
// weakness on the rook file.
|
|
||||||
if (square_file(s2) == FILE_A)
|
|
||||||
bonus += 4*StormLeverBonus[f] - 16*square_distance(s, s2);
|
|
||||||
else
|
|
||||||
bonus += 2*StormLeverBonus[f] - 8*square_distance(s, s2);
|
|
||||||
} else
|
|
||||||
// There is at least one enemy pawn beside the enemy pawn we look
|
|
||||||
// at, which means that the pawn has somewhat better chances of
|
|
||||||
// defending itself by advancing. Smaller bonus.
|
|
||||||
bonus += StormLeverBonus[f] - 4*square_distance(s, s2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pi->qsStormValue[Us] += bonus;
|
pi->qsStormValue[Us] += bonus;
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+75
-32
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -44,8 +44,6 @@ using std::string;
|
|||||||
//// Variables
|
//// Variables
|
||||||
////
|
////
|
||||||
|
|
||||||
int Position::castleRightsMask[64];
|
|
||||||
|
|
||||||
Key Position::zobrist[2][8][64];
|
Key Position::zobrist[2][8][64];
|
||||||
Key Position::zobEp[64];
|
Key Position::zobEp[64];
|
||||||
Key Position::zobCastle[16];
|
Key Position::zobCastle[16];
|
||||||
@@ -76,15 +74,39 @@ CheckInfo::CheckInfo(const Position& pos) {
|
|||||||
checkSq[KING] = EmptyBoardBB;
|
checkSq[KING] = EmptyBoardBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Position c'tors. Here we always create a slower but safer copy of
|
||||||
|
/// the original position or the FEN string, we want the new born Position
|
||||||
|
/// object do not depend on any external data. Instead if we know what we
|
||||||
|
/// are doing and we need speed we can create a position with default
|
||||||
|
/// c'tor Position() and then use just fast_copy().
|
||||||
|
|
||||||
|
Position::Position() {}
|
||||||
|
|
||||||
Position::Position(const Position& pos) {
|
Position::Position(const Position& pos) {
|
||||||
copy(pos);
|
|
||||||
|
memcpy(this, &pos, sizeof(Position));
|
||||||
|
detach(); // Always detach() in copy c'tor to avoid surprises
|
||||||
}
|
}
|
||||||
|
|
||||||
Position::Position(const string& fen) {
|
Position::Position(const string& fen) {
|
||||||
|
|
||||||
from_fen(fen);
|
from_fen(fen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Position::detach() copies the content of the current state and castling
|
||||||
|
/// masks inside the position itself. This is needed when the st pointee could
|
||||||
|
/// become stale, as example because the caller is about to going out of scope.
|
||||||
|
|
||||||
|
void Position::detach() {
|
||||||
|
|
||||||
|
startState = *st;
|
||||||
|
st = &startState;
|
||||||
|
st->previous = NULL; // as a safe guard
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::from_fen() initializes the position object with the given FEN
|
/// Position::from_fen() initializes the position object with the given FEN
|
||||||
/// string. This function is not very robust - make sure that input FENs are
|
/// string. This function is not very robust - make sure that input FENs are
|
||||||
/// correct (this is assumed to be the responsibility of the GUI).
|
/// correct (this is assumed to be the responsibility of the GUI).
|
||||||
@@ -204,11 +226,16 @@ void Position::from_fen(const string& fen) {
|
|||||||
while (fen[i] == ' ')
|
while (fen[i] == ' ')
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
// En passant square
|
// En passant square -- ignore if no capture is possible
|
||||||
if ( i <= fen.length() - 2
|
if ( i <= fen.length() - 2
|
||||||
&& (fen[i] >= 'a' && fen[i] <= 'h')
|
&& (fen[i] >= 'a' && fen[i] <= 'h')
|
||||||
&& (fen[i+1] == '3' || fen[i+1] == '6'))
|
&& (fen[i+1] == '3' || fen[i+1] == '6'))
|
||||||
|
{
|
||||||
|
Square fenEpSquare = square_from_string(fen.substr(i, 2));
|
||||||
|
Color them = opposite_color(sideToMove);
|
||||||
|
if (attacks_from<PAWN>(fenEpSquare, them) & this->pieces(PAWN, sideToMove))
|
||||||
st->epSquare = square_from_string(fen.substr(i, 2));
|
st->epSquare = square_from_string(fen.substr(i, 2));
|
||||||
|
}
|
||||||
|
|
||||||
// Various initialisation
|
// Various initialisation
|
||||||
for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
|
for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
|
||||||
@@ -265,11 +292,25 @@ const string Position::to_fen() const {
|
|||||||
}
|
}
|
||||||
fen += (sideToMove == WHITE ? "w " : "b ");
|
fen += (sideToMove == WHITE ? "w " : "b ");
|
||||||
if (st->castleRights != NO_CASTLES)
|
if (st->castleRights != NO_CASTLES)
|
||||||
|
{
|
||||||
|
if (initialKFile == FILE_E && initialQRFile == FILE_A && initialKRFile == FILE_H)
|
||||||
{
|
{
|
||||||
if (can_castle_kingside(WHITE)) fen += 'K';
|
if (can_castle_kingside(WHITE)) fen += 'K';
|
||||||
if (can_castle_queenside(WHITE)) fen += 'Q';
|
if (can_castle_queenside(WHITE)) fen += 'Q';
|
||||||
if (can_castle_kingside(BLACK)) fen += 'k';
|
if (can_castle_kingside(BLACK)) fen += 'k';
|
||||||
if (can_castle_queenside(BLACK)) fen += 'q';
|
if (can_castle_queenside(BLACK)) fen += 'q';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (can_castle_kingside(WHITE))
|
||||||
|
fen += char(toupper(file_to_char(initialKRFile)));
|
||||||
|
if (can_castle_queenside(WHITE))
|
||||||
|
fen += char(toupper(file_to_char(initialQRFile)));
|
||||||
|
if (can_castle_kingside(BLACK))
|
||||||
|
fen += file_to_char(initialKRFile);
|
||||||
|
if (can_castle_queenside(BLACK))
|
||||||
|
fen += file_to_char(initialQRFile);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
fen += '-';
|
fen += '-';
|
||||||
|
|
||||||
@@ -300,8 +341,9 @@ void Position::print(Move m) const {
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
if (m != MOVE_NONE)
|
if (m != MOVE_NONE)
|
||||||
{
|
{
|
||||||
|
Position p(*this);
|
||||||
string col = (color_of_piece_on(move_from(m)) == BLACK ? ".." : "");
|
string col = (color_of_piece_on(move_from(m)) == BLACK ? ".." : "");
|
||||||
std::cout << "Move is: " << col << move_to_san(*this, m) << std::endl;
|
std::cout << "Move is: " << col << move_to_san(p, m) << std::endl;
|
||||||
}
|
}
|
||||||
for (Rank rank = RANK_8; rank >= RANK_1; rank--)
|
for (Rank rank = RANK_8; rank >= RANK_1; rank--)
|
||||||
{
|
{
|
||||||
@@ -326,20 +368,11 @@ void Position::print(Move m) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::copy() creates a copy of the input position.
|
|
||||||
|
|
||||||
void Position::copy(const Position& pos) {
|
|
||||||
|
|
||||||
memcpy(this, &pos, sizeof(Position));
|
|
||||||
saveState(); // detach and copy state info
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Position:hidden_checkers<>() returns a bitboard of all pinned (against the
|
/// Position:hidden_checkers<>() returns a bitboard of all pinned (against the
|
||||||
/// king) pieces for the given color and for the given pinner type. Or, when
|
/// king) pieces for the given color and for the given pinner type. Or, when
|
||||||
/// template parameter FindPinned is false, the pieces of the given color
|
/// template parameter FindPinned is false, the pieces of the given color
|
||||||
/// candidate for a discovery check against the enemy king.
|
/// candidate for a discovery check against the enemy king.
|
||||||
/// Note that checkersBB bitboard must be already updated.
|
/// Bitboard checkersBB must be already updated when looking for pinners.
|
||||||
|
|
||||||
template<bool FindPinned>
|
template<bool FindPinned>
|
||||||
Bitboard Position::hidden_checkers(Color c) const {
|
Bitboard Position::hidden_checkers(Color c) const {
|
||||||
@@ -373,7 +406,8 @@ Bitboard Position::hidden_checkers(Color c) const {
|
|||||||
|
|
||||||
|
|
||||||
/// Position:pinned_pieces() returns a bitboard of all pinned (against the
|
/// Position:pinned_pieces() returns a bitboard of all pinned (against the
|
||||||
/// king) pieces for the given color.
|
/// king) pieces for the given color. Note that checkersBB bitboard must
|
||||||
|
/// be already updated.
|
||||||
|
|
||||||
Bitboard Position::pinned_pieces(Color c) const {
|
Bitboard Position::pinned_pieces(Color c) const {
|
||||||
|
|
||||||
@@ -383,7 +417,8 @@ Bitboard Position::pinned_pieces(Color c) const {
|
|||||||
|
|
||||||
/// Position:discovered_check_candidates() returns a bitboard containing all
|
/// Position:discovered_check_candidates() returns a bitboard containing all
|
||||||
/// pieces for the given side which are candidates for giving a discovered
|
/// pieces for the given side which are candidates for giving a discovered
|
||||||
/// check.
|
/// check. Contrary to pinned_pieces() here there is no need of checkersBB
|
||||||
|
/// to be already updated.
|
||||||
|
|
||||||
Bitboard Position::discovered_check_candidates(Color c) const {
|
Bitboard Position::discovered_check_candidates(Color c) const {
|
||||||
|
|
||||||
@@ -1422,19 +1457,6 @@ int Position::see(Square from, Square to) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::saveState() copies the content of the current state
|
|
||||||
/// inside startState and makes st point to it. This is needed
|
|
||||||
/// when the st pointee could become stale, as example because
|
|
||||||
/// the caller is about to going out of scope.
|
|
||||||
|
|
||||||
void Position::saveState() {
|
|
||||||
|
|
||||||
startState = *st;
|
|
||||||
st = &startState;
|
|
||||||
st->previous = NULL; // as a safe guard
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Position::clear() erases the position object to a pristine state, with an
|
/// Position::clear() erases the position object to a pristine state, with an
|
||||||
/// empty board, white to move, and no castling rights.
|
/// empty board, white to move, and no castling rights.
|
||||||
|
|
||||||
@@ -1636,6 +1658,7 @@ Value Position::compute_non_pawn_material(Color c) const {
|
|||||||
/// Position::is_draw() tests whether the position is drawn by material,
|
/// Position::is_draw() tests whether the position is drawn by material,
|
||||||
/// repetition, or the 50 moves rule. It does not detect stalemates, this
|
/// repetition, or the 50 moves rule. It does not detect stalemates, this
|
||||||
/// must be done by the search.
|
/// must be done by the search.
|
||||||
|
// FIXME: Currently we are not handling 50 move rule correctly when in check
|
||||||
|
|
||||||
bool Position::is_draw() const {
|
bool Position::is_draw() const {
|
||||||
|
|
||||||
@@ -1649,7 +1672,7 @@ bool Position::is_draw() const {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Draw by repetition?
|
// Draw by repetition?
|
||||||
for (int i = 2; i < Min(Min(gamePly, st->rule50), st->pliesFromNull); i += 2)
|
for (int i = 4; i <= Min(Min(gamePly, st->rule50), st->pliesFromNull); i += 2)
|
||||||
if (history[gamePly - i] == st->key)
|
if (history[gamePly - i] == st->key)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -1843,6 +1866,7 @@ bool Position::is_ok(int* failedStep) const {
|
|||||||
static const bool debugNonPawnMaterial = false;
|
static const bool debugNonPawnMaterial = false;
|
||||||
static const bool debugPieceCounts = false;
|
static const bool debugPieceCounts = false;
|
||||||
static const bool debugPieceList = false;
|
static const bool debugPieceList = false;
|
||||||
|
static const bool debugCastleSquares = false;
|
||||||
|
|
||||||
if (failedStep) *failedStep = 1;
|
if (failedStep) *failedStep = 1;
|
||||||
|
|
||||||
@@ -1979,6 +2003,25 @@ bool Position::is_ok(int* failedStep) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failedStep) (*failedStep)++;
|
||||||
|
if (debugCastleSquares) {
|
||||||
|
for (Color c = WHITE; c <= BLACK; c++) {
|
||||||
|
if (can_castle_kingside(c) && piece_on(initial_kr_square(c)) != piece_of_color_and_type(c, ROOK))
|
||||||
|
return false;
|
||||||
|
if (can_castle_queenside(c) && piece_on(initial_qr_square(c)) != piece_of_color_and_type(c, ROOK))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (castleRightsMask[initial_kr_square(WHITE)] != (ALL_CASTLES ^ WHITE_OO))
|
||||||
|
return false;
|
||||||
|
if (castleRightsMask[initial_qr_square(WHITE)] != (ALL_CASTLES ^ WHITE_OOO))
|
||||||
|
return false;
|
||||||
|
if (castleRightsMask[initial_kr_square(BLACK)] != (ALL_CASTLES ^ BLACK_OO))
|
||||||
|
return false;
|
||||||
|
if (castleRightsMask[initial_qr_square(BLACK)] != (ALL_CASTLES ^ BLACK_OOO))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (failedStep) *failedStep = 0;
|
if (failedStep) *failedStep = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-7
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -146,9 +146,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
Position() {}
|
Position();
|
||||||
Position(const Position& pos);
|
explicit Position(const Position& pos);
|
||||||
Position(const std::string& fen);
|
explicit Position(const std::string& fen);
|
||||||
|
|
||||||
// Text input/output
|
// Text input/output
|
||||||
void from_fen(const std::string& fen);
|
void from_fen(const std::string& fen);
|
||||||
@@ -156,7 +156,6 @@ public:
|
|||||||
void print(Move m = MOVE_NONE) const;
|
void print(Move m = MOVE_NONE) const;
|
||||||
|
|
||||||
// Copying
|
// Copying
|
||||||
void copy(const Position& pos);
|
|
||||||
void flipped_copy(const Position& pos);
|
void flipped_copy(const Position& pos);
|
||||||
|
|
||||||
// The piece on a given square
|
// The piece on a given square
|
||||||
@@ -224,6 +223,9 @@ public:
|
|||||||
bool move_is_passed_pawn_push(Move m) const;
|
bool move_is_passed_pawn_push(Move m) const;
|
||||||
bool move_attacks_square(Move m, Square s) const;
|
bool move_attacks_square(Move m, Square s) const;
|
||||||
|
|
||||||
|
// Piece captured with previous moves
|
||||||
|
PieceType captured_piece() const;
|
||||||
|
|
||||||
// Information about pawns
|
// Information about pawns
|
||||||
bool pawn_is_passed(Color c, Square s) const;
|
bool pawn_is_passed(Color c, Square s) const;
|
||||||
static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
|
static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
|
||||||
@@ -234,7 +236,7 @@ public:
|
|||||||
bool square_is_weak(Square s, Color c) const;
|
bool square_is_weak(Square s, Color c) const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void saveState();
|
void detach();
|
||||||
void do_move(Move m, StateInfo& st);
|
void do_move(Move m, StateInfo& st);
|
||||||
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
@@ -326,12 +328,12 @@ private:
|
|||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
int gamePly;
|
int gamePly;
|
||||||
Key history[MaxGameLength];
|
Key history[MaxGameLength];
|
||||||
|
int castleRightsMask[64];
|
||||||
File initialKFile, initialKRFile, initialQRFile;
|
File initialKFile, initialKRFile, initialQRFile;
|
||||||
StateInfo startState;
|
StateInfo startState;
|
||||||
StateInfo* st;
|
StateInfo* st;
|
||||||
|
|
||||||
// Static variables
|
// Static variables
|
||||||
static int castleRightsMask[64];
|
|
||||||
static Key zobrist[2][8][64];
|
static Key zobrist[2][8][64];
|
||||||
static Key zobEp[64];
|
static Key zobEp[64];
|
||||||
static Key zobCastle[16];
|
static Key zobCastle[16];
|
||||||
@@ -567,4 +569,8 @@ inline bool Position::move_is_capture_or_promotion(Move m) const {
|
|||||||
return (m & (0x1F << 12)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
|
return (m & (0x1F << 12)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline PieceType Position::captured_piece() const {
|
||||||
|
return st->capture;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(POSITION_H_INCLUDED)
|
#endif // !defined(POSITION_H_INCLUDED)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+6
-6
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -63,7 +63,7 @@ namespace {
|
|||||||
/// that the move is a legal move from the position. The return value is
|
/// that the move is a legal move from the position. The return value is
|
||||||
/// a string containing the move in short algebraic notation.
|
/// a string containing the move in short algebraic notation.
|
||||||
|
|
||||||
const string move_to_san(const Position& pos, Move m) {
|
const string move_to_san(Position& pos, Move m) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
@@ -123,10 +123,10 @@ const string move_to_san(const Position& pos, Move m) {
|
|||||||
// Position::move_is_check doesn't detect all checks (not castling moves,
|
// Position::move_is_check doesn't detect all checks (not castling moves,
|
||||||
// promotions and en passant captures).
|
// promotions and en passant captures).
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
Position p(pos);
|
pos.do_move(m, st);
|
||||||
p.do_move(m, st);
|
if (pos.is_check())
|
||||||
if (p.is_check())
|
san += pos.is_mate() ? "#" : "+";
|
||||||
san += p.is_mate()? "#" : "+";
|
pos.undo_move(m);
|
||||||
|
|
||||||
return san;
|
return san;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
extern const std::string move_to_san(const Position& pos, Move m);
|
extern const std::string move_to_san(Position& pos, Move m);
|
||||||
extern Move move_from_san(const Position& pos, const std::string& str);
|
extern Move move_from_san(const Position& pos, const std::string& str);
|
||||||
extern const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines);
|
extern const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines);
|
||||||
extern const std::string pretty_pv(const Position& pos, int time, int depth, uint64_t nodes, Value score, ValueType type, Move pv[]);
|
extern const std::string pretty_pv(const Position& pos, int time, int depth, uint64_t nodes, Value score, ValueType type, Move pv[]);
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1356
-1274
File diff suppressed because it is too large
Load Diff
+6
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "depth.h"
|
#include "depth.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
#include "value.h"
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -46,6 +47,7 @@ const int KILLER_MAX = 2;
|
|||||||
/// from nodes shallower and deeper in the tree during the search. Each
|
/// from nodes shallower and deeper in the tree during the search. Each
|
||||||
/// search thread has its own array of SearchStack objects, indexed by the
|
/// search thread has its own array of SearchStack objects, indexed by the
|
||||||
/// current ply.
|
/// current ply.
|
||||||
|
struct EvalInfo;
|
||||||
|
|
||||||
struct SearchStack {
|
struct SearchStack {
|
||||||
Move pv[PLY_MAX_PLUS_2];
|
Move pv[PLY_MAX_PLUS_2];
|
||||||
@@ -54,6 +56,7 @@ struct SearchStack {
|
|||||||
Move threatMove;
|
Move threatMove;
|
||||||
Move killers[KILLER_MAX];
|
Move killers[KILLER_MAX];
|
||||||
Depth reduction;
|
Depth reduction;
|
||||||
|
Value eval;
|
||||||
|
|
||||||
void init(int ply);
|
void init(int ply);
|
||||||
void initKillers();
|
void initKillers();
|
||||||
@@ -64,8 +67,9 @@ struct SearchStack {
|
|||||||
//// Prototypes
|
//// Prototypes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
extern void init_search();
|
||||||
extern void init_threads();
|
extern void init_threads();
|
||||||
extern void stop_threads();
|
extern void exit_threads();
|
||||||
extern bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
extern bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
||||||
int time[], int increment[], int movesToGo, int maxDepth,
|
int time[], int increment[], int movesToGo, int maxDepth,
|
||||||
int maxNodes, int maxTime, Move searchMoves[]);
|
int maxNodes, int maxTime, Move searchMoves[]);
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+35
-19
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,6 +26,8 @@
|
|||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
@@ -36,7 +38,8 @@
|
|||||||
//// Constants and variables
|
//// Constants and variables
|
||||||
////
|
////
|
||||||
|
|
||||||
const int THREAD_MAX = 8;
|
const int MAX_THREADS = 8;
|
||||||
|
const int ACTIVE_SPLIT_POINTS_MAX = 8;
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
@@ -44,35 +47,48 @@ const int THREAD_MAX = 8;
|
|||||||
////
|
////
|
||||||
|
|
||||||
struct SplitPoint {
|
struct SplitPoint {
|
||||||
|
|
||||||
|
// Const data after splitPoint has been setup
|
||||||
SplitPoint* parent;
|
SplitPoint* parent;
|
||||||
Position pos;
|
const Position* pos;
|
||||||
SearchStack sstack[THREAD_MAX][PLY_MAX_PLUS_2];
|
|
||||||
SearchStack *parentSstack;
|
|
||||||
int ply;
|
|
||||||
Depth depth;
|
|
||||||
volatile Value alpha, beta, bestValue, futilityValue;
|
|
||||||
Value approximateEval;
|
|
||||||
bool pvNode;
|
bool pvNode;
|
||||||
int master, slaves[THREAD_MAX];
|
Depth depth;
|
||||||
Lock lock;
|
bool mateThreat;
|
||||||
|
Value beta;
|
||||||
|
int ply, master, slaves[MAX_THREADS];
|
||||||
|
SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
|
||||||
|
|
||||||
|
// Const pointers to shared data
|
||||||
MovePicker* mp;
|
MovePicker* mp;
|
||||||
|
SearchStack* parentSstack;
|
||||||
|
|
||||||
|
// Shared data
|
||||||
|
Lock lock;
|
||||||
|
volatile Value alpha;
|
||||||
|
volatile Value bestValue;
|
||||||
volatile int moves;
|
volatile int moves;
|
||||||
volatile int cpus;
|
volatile int cpus;
|
||||||
bool finished;
|
volatile bool stopRequest;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ThreadState type is used to represent thread's current state
|
||||||
|
|
||||||
|
enum ThreadState
|
||||||
|
{
|
||||||
|
THREAD_SEARCHING, // thread is performing work
|
||||||
|
THREAD_AVAILABLE, // thread is polling for work
|
||||||
|
THREAD_SLEEPING, // we are not thinking, so thread is sleeping
|
||||||
|
THREAD_BOOKED, // other thread (master) has booked us as a slave
|
||||||
|
THREAD_WORKISWAITING, // master has ordered us to start
|
||||||
|
THREAD_TERMINATED // we are quitting and thread is terminated
|
||||||
|
};
|
||||||
|
|
||||||
struct Thread {
|
struct Thread {
|
||||||
SplitPoint* splitPoint;
|
SplitPoint* splitPoint;
|
||||||
int activeSplitPoints;
|
volatile int activeSplitPoints;
|
||||||
uint64_t nodes;
|
uint64_t nodes;
|
||||||
uint64_t betaCutOffs[2];
|
uint64_t betaCutOffs[2];
|
||||||
bool failHighPly1;
|
volatile ThreadState state;
|
||||||
volatile bool stop;
|
|
||||||
volatile bool running;
|
|
||||||
volatile bool idle;
|
|
||||||
volatile bool workIsWaiting;
|
|
||||||
volatile bool printCurrentLine;
|
|
||||||
unsigned char pad[64]; // set some distance among local data for each thread
|
unsigned char pad[64]; // set some distance among local data for each thread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+11
-6
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,7 +25,9 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#if !(defined(__hpux) || defined(__ppc__) || defined(__ppc64__) || defined(__arm__))
|
||||||
# include <xmmintrin.h>
|
# include <xmmintrin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
@@ -53,11 +55,9 @@ TranspositionTable::~TranspositionTable() {
|
|||||||
/// TranspositionTable::set_size sets the size of the transposition table,
|
/// TranspositionTable::set_size sets the size of the transposition table,
|
||||||
/// measured in megabytes.
|
/// measured in megabytes.
|
||||||
|
|
||||||
void TranspositionTable::set_size(unsigned mbSize) {
|
void TranspositionTable::set_size(size_t mbSize) {
|
||||||
|
|
||||||
assert(mbSize >= 4 && mbSize <= 4096);
|
size_t newSize = 1024;
|
||||||
|
|
||||||
unsigned newSize = 1024;
|
|
||||||
|
|
||||||
// We store a cluster of ClusterSize number of TTEntry for each position
|
// We store a cluster of ClusterSize number of TTEntry for each position
|
||||||
// and newSize is the maximum number of storable positions.
|
// and newSize is the maximum number of storable positions.
|
||||||
@@ -125,6 +125,7 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
|
|||||||
if (tte->key() && t == VALUE_TYPE_EV_LO)
|
if (tte->key() && t == VALUE_TYPE_EV_LO)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Preserve any exsisting ttMove
|
||||||
if (m == MOVE_NONE)
|
if (m == MOVE_NONE)
|
||||||
m = tte->move();
|
m = tte->move();
|
||||||
|
|
||||||
@@ -169,11 +170,14 @@ TTEntry* TranspositionTable::retrieve(const Key posKey) const {
|
|||||||
/// to be loaded from RAM, that can be very slow. When we will
|
/// to be loaded from RAM, that can be very slow. When we will
|
||||||
/// subsequently call retrieve() the TT data will be already
|
/// subsequently call retrieve() the TT data will be already
|
||||||
/// quickly accessible in L1/L2 CPU cache.
|
/// quickly accessible in L1/L2 CPU cache.
|
||||||
|
#if defined(__hpux) || defined(__ppc__) || defined(__ppc64__) || defined(__arm__)
|
||||||
|
void TranspositionTable::prefetch(const Key) const {} // Not supported on HP UX
|
||||||
|
#else
|
||||||
|
|
||||||
void TranspositionTable::prefetch(const Key posKey) const {
|
void TranspositionTable::prefetch(const Key posKey) const {
|
||||||
|
|
||||||
#if defined(__INTEL_COMPILER) || defined(__ICL)
|
#if defined(__INTEL_COMPILER) || defined(__ICL)
|
||||||
// This hack prevents prefetches to be optimized away by the
|
// This hack prevents prefetches to be optimized away by
|
||||||
// Intel compiler. Both MSVC and gcc seems not affected.
|
// Intel compiler. Both MSVC and gcc seems not affected.
|
||||||
__asm__ ("");
|
__asm__ ("");
|
||||||
#endif
|
#endif
|
||||||
@@ -183,6 +187,7 @@ void TranspositionTable::prefetch(const Key posKey) const {
|
|||||||
_mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
|
_mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/// TranspositionTable::new_search() is called at the beginning of every new
|
/// TranspositionTable::new_search() is called at the beginning of every new
|
||||||
/// search. It increments the "generation" variable, which is used to
|
/// search. It increments the "generation" variable, which is used to
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -95,7 +95,7 @@ class TranspositionTable {
|
|||||||
public:
|
public:
|
||||||
TranspositionTable();
|
TranspositionTable();
|
||||||
~TranspositionTable();
|
~TranspositionTable();
|
||||||
void set_size(unsigned mbSize);
|
void set_size(size_t mbSize);
|
||||||
void clear();
|
void clear();
|
||||||
void store(const Key posKey, Value v, ValueType type, Depth d, Move m);
|
void store(const Key posKey, Value v, ValueType type, Depth d, Move m);
|
||||||
TTEntry* retrieve(const Key posKey) const;
|
TTEntry* retrieve(const Key posKey) const;
|
||||||
@@ -114,7 +114,7 @@ private:
|
|||||||
unsigned writes; // heavy SMP read/write access here
|
unsigned writes; // heavy SMP read/write access here
|
||||||
unsigned char pad_after[64];
|
unsigned char pad_after[64];
|
||||||
|
|
||||||
unsigned size;
|
size_t size;
|
||||||
TTCluster* entries;
|
TTCluster* entries;
|
||||||
uint8_t generation;
|
uint8_t generation;
|
||||||
};
|
};
|
||||||
|
|||||||
+25
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -73,4 +73,28 @@ typedef uint64_t Bitboard;
|
|||||||
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
|
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Define a __cpuid() function for gcc compilers, for Intel and MSVC
|
||||||
|
// is already available as an intrinsic.
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include <intrin.h>
|
||||||
|
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||||
|
inline void __cpuid(int CPUInfo[4], int InfoType)
|
||||||
|
{
|
||||||
|
int* eax = CPUInfo + 0;
|
||||||
|
int* ebx = CPUInfo + 1;
|
||||||
|
int* ecx = CPUInfo + 2;
|
||||||
|
int* edx = CPUInfo + 3;
|
||||||
|
|
||||||
|
*eax = InfoType;
|
||||||
|
*ecx = 0;
|
||||||
|
__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
|
||||||
|
: "0" (*eax), "2" (*ecx));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
inline void __cpuid(int CPUInfo[4], int)
|
||||||
|
{
|
||||||
|
CPUInfo[0] = CPUInfo[1] = CPUInfo[2] = CPUInfo[3] = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // !defined(TYPES_H_INCLUDED)
|
#endif // !defined(TYPES_H_INCLUDED)
|
||||||
|
|||||||
+28
-46
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -107,7 +107,8 @@ namespace {
|
|||||||
UCIInputParser uip(command);
|
UCIInputParser uip(command);
|
||||||
string token;
|
string token;
|
||||||
|
|
||||||
uip >> token; // operator>>() skips any whitespace
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
|
return true;
|
||||||
|
|
||||||
if (token == "quit")
|
if (token == "quit")
|
||||||
return false;
|
return false;
|
||||||
@@ -159,14 +160,8 @@ namespace {
|
|||||||
else if (token == "perft")
|
else if (token == "perft")
|
||||||
perft(uip);
|
perft(uip);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
cout << "Unknown command: " << command << endl;
|
cout << "Unknown command: " << command << endl;
|
||||||
while (!uip.eof())
|
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
cout << token << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,33 +176,33 @@ namespace {
|
|||||||
|
|
||||||
string token;
|
string token;
|
||||||
|
|
||||||
uip >> token; // operator>>() skips any whitespace
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
|
return;
|
||||||
|
|
||||||
if (token == "startpos")
|
if (token == "startpos")
|
||||||
RootPosition.from_fen(StartPosition);
|
RootPosition.from_fen(StartPosition);
|
||||||
else if (token == "fen")
|
else if (token == "fen")
|
||||||
{
|
{
|
||||||
string fen;
|
string fen;
|
||||||
while (token != "moves" && !uip.eof())
|
while (uip >> token && token != "moves")
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
fen += token;
|
fen += token;
|
||||||
fen += ' ';
|
fen += ' ';
|
||||||
}
|
}
|
||||||
RootPosition.from_fen(fen);
|
RootPosition.from_fen(fen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uip.eof())
|
if (uip.good())
|
||||||
{
|
{
|
||||||
if (token != "moves")
|
if (token != "moves")
|
||||||
uip >> token;
|
uip >> token;
|
||||||
|
|
||||||
if (token == "moves")
|
if (token == "moves")
|
||||||
{
|
{
|
||||||
Move move;
|
Move move;
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
move = move_from_string(RootPosition, token);
|
move = move_from_string(RootPosition, token);
|
||||||
RootPosition.do_move(move, st);
|
RootPosition.do_move(move, st);
|
||||||
if (RootPosition.rule_50_counter() == 0)
|
if (RootPosition.rule_50_counter() == 0)
|
||||||
@@ -215,7 +210,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
// Our StateInfo st is about going out of scope so copy
|
// Our StateInfo st is about going out of scope so copy
|
||||||
// its content inside RootPosition before they disappear.
|
// its content inside RootPosition before they disappear.
|
||||||
RootPosition.saveState();
|
RootPosition.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,27 +224,22 @@ namespace {
|
|||||||
|
|
||||||
void set_option(UCIInputParser& uip) {
|
void set_option(UCIInputParser& uip) {
|
||||||
|
|
||||||
string token, name;
|
string token, name, value;
|
||||||
|
|
||||||
uip >> token;
|
if (!(uip >> token)) // operator>>() skips any whitespace
|
||||||
if (token == "name")
|
return;
|
||||||
{
|
|
||||||
uip >> name;
|
|
||||||
while (!uip.eof())
|
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
if (token == "value")
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
if (token == "name" && uip >> name)
|
||||||
|
{
|
||||||
|
while (uip >> token && token != "value")
|
||||||
name += (" " + token);
|
name += (" " + token);
|
||||||
}
|
|
||||||
if (token == "value")
|
|
||||||
{
|
|
||||||
// Reads until end of line and left trim white space
|
|
||||||
getline(uip, token);
|
|
||||||
token.erase(0, token.find_first_not_of(" \n\r\t"));
|
|
||||||
|
|
||||||
set_option_value(name, token);
|
if (token == "value" && uip >> value)
|
||||||
|
{
|
||||||
|
while (uip >> token)
|
||||||
|
value += (" " + token);
|
||||||
|
|
||||||
|
set_option_value(name, value);
|
||||||
} else
|
} else
|
||||||
push_button(name);
|
push_button(name);
|
||||||
}
|
}
|
||||||
@@ -276,10 +266,8 @@ namespace {
|
|||||||
|
|
||||||
searchMoves[0] = MOVE_NONE;
|
searchMoves[0] = MOVE_NONE;
|
||||||
|
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
{
|
||||||
uip >> token;
|
|
||||||
|
|
||||||
if (token == "infinite")
|
if (token == "infinite")
|
||||||
infinite = true;
|
infinite = true;
|
||||||
else if (token == "ponder")
|
else if (token == "ponder")
|
||||||
@@ -303,18 +291,13 @@ namespace {
|
|||||||
else if (token == "searchmoves")
|
else if (token == "searchmoves")
|
||||||
{
|
{
|
||||||
int numOfMoves = 0;
|
int numOfMoves = 0;
|
||||||
while (!uip.eof())
|
while (uip >> token)
|
||||||
{
|
|
||||||
uip >> token;
|
|
||||||
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
searchMoves[numOfMoves++] = move_from_string(RootPosition, token);
|
||||||
}
|
|
||||||
searchMoves[numOfMoves] = MOVE_NONE;
|
searchMoves[numOfMoves] = MOVE_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moveTime)
|
|
||||||
infinite = true; // HACK
|
|
||||||
|
|
||||||
assert(RootPosition.is_ok());
|
assert(RootPosition.is_ok());
|
||||||
|
|
||||||
return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
|
return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
|
||||||
@@ -325,12 +308,11 @@ namespace {
|
|||||||
|
|
||||||
string token;
|
string token;
|
||||||
int depth, tm, n;
|
int depth, tm, n;
|
||||||
Position pos = RootPosition;
|
Position pos(RootPosition);
|
||||||
|
|
||||||
if (uip.eof())
|
if (!(uip >> depth))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uip >> depth;
|
|
||||||
tm = get_system_time();
|
tm = get_system_time();
|
||||||
|
|
||||||
n = perft(pos, depth * OnePly);
|
n = perft(pos, depth * OnePly);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+35
-34
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -88,26 +88,10 @@ namespace {
|
|||||||
o["Space"] = Option(100, 0, 200);
|
o["Space"] = Option(100, 0, 200);
|
||||||
o["Aggressiveness"] = Option(100, 0, 200);
|
o["Aggressiveness"] = Option(100, 0, 200);
|
||||||
o["Cowardice"] = Option(100, 0, 200);
|
o["Cowardice"] = Option(100, 0, 200);
|
||||||
o["King Safety Curve"] = Option("Quadratic", COMBO);
|
|
||||||
|
|
||||||
o["King Safety Curve"].comboValues.push_back("Quadratic");
|
|
||||||
o["King Safety Curve"].comboValues.push_back("Linear"); /*, "From File"*/
|
|
||||||
|
|
||||||
o["King Safety Coefficient"] = Option(40, 1, 100);
|
|
||||||
o["King Safety X Intercept"] = Option(0, 0, 20);
|
|
||||||
o["King Safety Max Slope"] = Option(30, 10, 100);
|
|
||||||
o["King Safety Max Value"] = Option(500, 100, 1000);
|
|
||||||
o["Queen Contact Check Bonus"] = Option(3, 0, 8);
|
|
||||||
o["Queen Check Bonus"] = Option(2, 0, 4);
|
|
||||||
o["Rook Check Bonus"] = Option(1, 0, 4);
|
|
||||||
o["Bishop Check Bonus"] = Option(1, 0, 4);
|
|
||||||
o["Knight Check Bonus"] = Option(1, 0, 4);
|
|
||||||
o["Discovered Check Bonus"] = Option(3, 0, 8);
|
|
||||||
o["Mate Threat Bonus"] = Option(3, 0, 8);
|
|
||||||
o["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
o["Single Reply Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Single Evasion Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Single Reply Extension (non-PV nodes)"] = Option(2, 0, 2);
|
o["Single Evasion Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Mate Threat Extension (PV nodes)"] = Option(0, 0, 2);
|
o["Mate Threat Extension (PV nodes)"] = Option(0, 0, 2);
|
||||||
o["Mate Threat Extension (non-PV nodes)"] = Option(0, 0, 2);
|
o["Mate Threat Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||||
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
@@ -116,20 +100,16 @@ namespace {
|
|||||||
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||||
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
o["Full Depth Moves (PV nodes)"] = Option(10, 1, 100);
|
|
||||||
o["Full Depth Moves (non-PV nodes)"] = Option(3, 1, 100);
|
|
||||||
o["Threat Depth"] = Option(5, 0, 100);
|
|
||||||
o["Randomness"] = Option(0, 0, 10);
|
o["Randomness"] = Option(0, 0, 10);
|
||||||
o["Minimum Split Depth"] = Option(4, 4, 7);
|
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||||
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
||||||
o["Threads"] = Option(1, 1, 8);
|
o["Threads"] = Option(1, 1, MAX_THREADS);
|
||||||
o["Hash"] = Option(32, 4, 4096);
|
o["Hash"] = Option(32, 4, 8192);
|
||||||
o["Clear Hash"] = Option(false, BUTTON);
|
o["Clear Hash"] = Option(false, BUTTON);
|
||||||
o["New Game"] = Option(false, BUTTON);
|
o["New Game"] = Option(false, BUTTON);
|
||||||
o["Ponder"] = Option(true);
|
o["Ponder"] = Option(true);
|
||||||
o["OwnBook"] = Option(true);
|
o["OwnBook"] = Option(true);
|
||||||
o["MultiPV"] = Option(1, 1, 500);
|
o["MultiPV"] = Option(1, 1, 500);
|
||||||
o["UCI_ShowCurrLine"] = Option(false);
|
|
||||||
o["UCI_Chess960"] = Option(false);
|
o["UCI_Chess960"] = Option(false);
|
||||||
o["UCI_AnalyseMode"] = Option(false);
|
o["UCI_AnalyseMode"] = Option(false);
|
||||||
|
|
||||||
@@ -196,15 +176,18 @@ void init_uci_options() {
|
|||||||
|
|
||||||
load_defaults(options);
|
load_defaults(options);
|
||||||
|
|
||||||
// Limit the default value of "Threads" to 7 even if we have 8 CPU cores.
|
// Set optimal value for parameter "Minimum Split Depth"
|
||||||
// According to Ken Dail's tests, Glaurung plays much better with 7 than
|
// according to number of available cores.
|
||||||
// with 8 threads. This is weird, but it is probably difficult to find out
|
|
||||||
// why before I have a 8-core computer to experiment with myself.
|
|
||||||
assert(options.find("Threads") != options.end());
|
assert(options.find("Threads") != options.end());
|
||||||
assert(options.find("Minimum Split Depth") != options.end());
|
assert(options.find("Minimum Split Depth") != options.end());
|
||||||
|
|
||||||
options["Threads"].defaultValue = stringify(Min(cpu_count(), 7));
|
Option& thr = options["Threads"];
|
||||||
options["Threads"].currentValue = stringify(Min(cpu_count(), 7));
|
Option& msd = options["Minimum Split Depth"];
|
||||||
|
|
||||||
|
thr.defaultValue = thr.currentValue = stringify(cpu_count());
|
||||||
|
|
||||||
|
if (cpu_count() >= 8)
|
||||||
|
msd.defaultValue = msd.currentValue = stringify(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -292,10 +275,28 @@ void set_option_value(const string& name, const string& value) {
|
|||||||
else if (v == "false")
|
else if (v == "false")
|
||||||
v = "0";
|
v = "0";
|
||||||
|
|
||||||
if (options.find(name) != options.end())
|
if (options.find(name) == options.end())
|
||||||
options[name].currentValue = v;
|
{
|
||||||
else
|
|
||||||
std::cout << "No such option: " << name << std::endl;
|
std::cout << "No such option: " << name << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normally it's up to the GUI to check for option's limits,
|
||||||
|
// but we could receive the new value directly from the user
|
||||||
|
// by teminal window. So let's check the bounds anyway.
|
||||||
|
Option& opt = options[name];
|
||||||
|
|
||||||
|
if (opt.type == CHECK && v != "0" && v != "1")
|
||||||
|
return;
|
||||||
|
|
||||||
|
else if (opt.type == SPIN)
|
||||||
|
{
|
||||||
|
int val = atoi(v.c_str());
|
||||||
|
if (val < opt.minValue || val > opt.maxValue)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.currentValue = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+17
-4
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||||
Copyright (C) 2008-2009 Marco Costalba
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -48,7 +48,8 @@ enum Value {
|
|||||||
VALUE_KNOWN_WIN = 15000,
|
VALUE_KNOWN_WIN = 15000,
|
||||||
VALUE_MATE = 30000,
|
VALUE_MATE = 30000,
|
||||||
VALUE_INFINITE = 30001,
|
VALUE_INFINITE = 30001,
|
||||||
VALUE_NONE = 30002
|
VALUE_NONE = 30002,
|
||||||
|
VALUE_ENSURE_SIGNED = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -56,10 +57,22 @@ enum Value {
|
|||||||
/// integer (enum), first LSB 16 bits are used to store endgame
|
/// integer (enum), first LSB 16 bits are used to store endgame
|
||||||
/// value, while upper bits are used for midgame value.
|
/// value, while upper bits are used for midgame value.
|
||||||
|
|
||||||
enum Score {};
|
// Compiler is free to choose the enum type as long as can keep
|
||||||
|
// its data, so ensure Score to be an integer type.
|
||||||
|
enum Score { ENSURE_32_BITS_SIZE_P = (1 << 16), ENSURE_32_BITS_SIZE_N = -(1 << 16)};
|
||||||
|
|
||||||
|
// Extracting the _signed_ lower and upper 16 bits it not so trivial
|
||||||
|
// because according to the standard a simple cast to short is
|
||||||
|
// implementation defined and so is a right shift of a signed integer.
|
||||||
|
inline Value mg_value(Score s) { return Value(((int(s) + 32768) & ~0xffff) / 0x10000); }
|
||||||
|
|
||||||
|
// Unfortunatly on Intel 64 bit we have a small speed regression, so use a faster code in
|
||||||
|
// this case, although not 100% standard compliant it seems to work for Intel and MSVC.
|
||||||
|
#if defined(IS_64BIT) && (!defined(__GNUC__) || defined(__INTEL_COMPILER))
|
||||||
inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); }
|
inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); }
|
||||||
inline Value mg_value(Score s) { return Value((int(s) + 32768) >> 16); }
|
#else
|
||||||
|
inline Value eg_value(Score s) { return Value((int)(unsigned(s) & 0x7fffu) - (int)(unsigned(s) & 0x8000u)); }
|
||||||
|
#endif
|
||||||
|
|
||||||
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
|
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user