diff --git a/DroidFish/jni/stockfish/Android.mk b/DroidFish/jni/stockfish/Android.mk
index 2bf0652..1cb5de2 100644
--- a/DroidFish/jni/stockfish/Android.mk
+++ b/DroidFish/jni/stockfish/Android.mk
@@ -1,7 +1,7 @@
LOCAL_PATH := $(call my-dir)
SF_SRC_FILES := \
- benchmark.cpp main.cpp movegen.cpp pawns.cpp thread.cpp uci.cpp \
+ benchmark.cpp main.cpp movegen.cpp pawns.cpp thread.cpp uci.cpp psqt.cpp \
bitbase.cpp endgame.cpp material.cpp movepick.cpp position.cpp timeman.cpp ucioption.cpp \
bitboard.cpp evaluate.cpp misc.cpp search.cpp tt.cpp syzygy/tbprobe.cpp
diff --git a/DroidFish/jni/stockfish/benchmark.cpp b/DroidFish/jni/stockfish/benchmark.cpp
index 605c95a..8f3e6ae 100644
--- a/DroidFish/jni/stockfish/benchmark.cpp
+++ b/DroidFish/jni/stockfish/benchmark.cpp
@@ -17,7 +17,6 @@
along with this program. If not, see .
*/
-#include
#include
#include
#include
@@ -27,14 +26,13 @@
#include "position.h"
#include "search.h"
#include "thread.h"
-#include "tt.h"
#include "uci.h"
using namespace std;
namespace {
-const char* Defaults[] = {
+const vector Defaults = {
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
@@ -105,22 +103,22 @@ void benchmark(const Position& current, istream& is) {
Options["Hash"] = ttSize;
Options["Threads"] = threads;
- TT.clear();
+ Search::reset();
if (limitType == "time")
- limits.movetime = atoi(limit.c_str()); // movetime is in ms
+ limits.movetime = stoi(limit); // movetime is in ms
else if (limitType == "nodes")
- limits.nodes = atoi(limit.c_str());
+ limits.nodes = stoi(limit);
else if (limitType == "mate")
- limits.mate = atoi(limit.c_str());
+ limits.mate = stoi(limit);
else
- limits.depth = atoi(limit.c_str());
+ limits.depth = stoi(limit);
if (fenFile == "default")
- fens.assign(Defaults, Defaults + 37);
+ fens = Defaults;
else if (fenFile == "current")
fens.push_back(current.fen());
@@ -128,7 +126,7 @@ void benchmark(const Position& current, istream& is) {
else
{
string fen;
- ifstream file(fenFile.c_str());
+ ifstream file(fenFile);
if (!file.is_open())
{
@@ -144,8 +142,7 @@ void benchmark(const Position& current, istream& is) {
}
uint64_t nodes = 0;
- Search::StateStackPtr st;
- Time::point elapsed = Time::now();
+ TimePoint elapsed = now();
for (size_t i = 0; i < fens.size(); ++i)
{
@@ -158,13 +155,15 @@ void benchmark(const Position& current, istream& is) {
else
{
+ Search::StateStackPtr st;
+ limits.startTime = now();
Threads.start_thinking(pos, limits, st);
- Threads.wait_for_think_finished();
- nodes += Search::RootPos.nodes_searched();
+ Threads.main()->join();
+ nodes += Threads.nodes_searched();
}
}
- elapsed = std::max(Time::now() - elapsed, Time::point(1)); // Avoid a 'divide by zero'
+ elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
dbg_print(); // Just before to exit
diff --git a/DroidFish/jni/stockfish/bitbase.cpp b/DroidFish/jni/stockfish/bitbase.cpp
index a018d3c..0eb3b98 100644
--- a/DroidFish/jni/stockfish/bitbase.cpp
+++ b/DroidFish/jni/stockfish/bitbase.cpp
@@ -17,7 +17,9 @@
along with this program. If not, see .
*/
+#include
#include
+#include
#include
#include "bitboard.h"
@@ -51,20 +53,19 @@ namespace {
WIN = 4
};
- inline Result& operator|=(Result& r, Result v) { return r = Result(r | v); }
+ Result& operator|=(Result& r, Result v) { return r = Result(r | v); }
struct KPKPosition {
-
- KPKPosition(unsigned idx);
+ KPKPosition() = default;
+ explicit KPKPosition(unsigned idx);
operator Result() const { return result; }
Result classify(const std::vector& db)
{ return us == WHITE ? classify(db) : classify(db); }
- private:
template Result classify(const std::vector& db);
Color us;
- Square bksq, wksq, psq;
+ Square ksq[COLOR_NB], psq;
Result result;
};
@@ -82,13 +83,12 @@ bool Bitbases::probe(Square wksq, Square wpsq, Square bksq, Color us) {
void Bitbases::init() {
+ std::vector db(MAX_INDEX);
unsigned idx, repeat = 1;
- std::vector db;
- db.reserve(MAX_INDEX);
// Initialize db with known win / draw positions
for (idx = 0; idx < MAX_INDEX; ++idx)
- db.push_back(KPKPosition(idx));
+ db[idx] = KPKPosition(idx);
// Iterate through the positions until none of the unknown positions can be
// changed to either wins or draws (15 cycles needed).
@@ -107,69 +107,73 @@ namespace {
KPKPosition::KPKPosition(unsigned idx) {
- wksq = Square((idx >> 0) & 0x3F);
- bksq = Square((idx >> 6) & 0x3F);
- us = Color ((idx >> 12) & 0x01);
- psq = make_square(File((idx >> 13) & 0x3), RANK_7 - Rank((idx >> 15) & 0x7));
- result = UNKNOWN;
+ ksq[WHITE] = Square((idx >> 0) & 0x3F);
+ ksq[BLACK] = Square((idx >> 6) & 0x3F);
+ us = Color ((idx >> 12) & 0x01);
+ psq = make_square(File((idx >> 13) & 0x3), RANK_7 - Rank((idx >> 15) & 0x7));
// Check if two pieces are on the same square or if a king can be captured
- if ( distance(wksq, bksq) <= 1
- || wksq == psq
- || bksq == psq
- || (us == WHITE && (StepAttacksBB[PAWN][psq] & bksq)))
+ if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
+ || ksq[WHITE] == psq
+ || ksq[BLACK] == psq
+ || (us == WHITE && (StepAttacksBB[PAWN][psq] & ksq[BLACK])))
result = INVALID;
- else if (us == WHITE)
- {
- // Immediate win if a pawn can be promoted without getting captured
- if ( rank_of(psq) == RANK_7
- && wksq != psq + DELTA_N
- && ( distance(bksq, psq + DELTA_N) > 1
- ||(StepAttacksBB[KING][wksq] & (psq + DELTA_N))))
- result = WIN;
- }
+ // Immediate win if a pawn can be promoted without getting captured
+ else if ( us == WHITE
+ && rank_of(psq) == RANK_7
+ && ksq[us] != psq + DELTA_N
+ && ( distance(ksq[~us], psq + DELTA_N) > 1
+ || (StepAttacksBB[KING][ksq[us]] & (psq + DELTA_N))))
+ result = WIN;
+
// Immediate draw if it is a stalemate or a king captures undefended pawn
- else if ( !(StepAttacksBB[KING][bksq] & ~(StepAttacksBB[KING][wksq] | StepAttacksBB[PAWN][psq]))
- || (StepAttacksBB[KING][bksq] & psq & ~StepAttacksBB[KING][wksq]))
+ else if ( us == BLACK
+ && ( !(StepAttacksBB[KING][ksq[us]] & ~(StepAttacksBB[KING][ksq[~us]] | StepAttacksBB[PAWN][psq]))
+ || (StepAttacksBB[KING][ksq[us]] & psq & ~StepAttacksBB[KING][ksq[~us]])))
result = DRAW;
+
+ // Position will be classified later
+ else
+ result = UNKNOWN;
}
template
Result KPKPosition::classify(const std::vector& db) {
- // White to Move: If one move leads to a position classified as WIN, the result
+ // White to move: If one move leads to a position classified as WIN, the result
// of the current position is WIN. If all moves lead to positions classified
// as DRAW, the current position is classified as DRAW, otherwise the current
// position is classified as UNKNOWN.
//
- // Black to Move: If one move leads to a position classified as DRAW, the result
+ // Black to move: If one move leads to a position classified as DRAW, the result
// of the current position is DRAW. If all moves lead to positions classified
// as WIN, the position is classified as WIN, otherwise the current position is
// classified as UNKNOWN.
- const Color Them = (Us == WHITE ? BLACK : WHITE);
+ const Color Them = (Us == WHITE ? BLACK : WHITE);
+ const Result Good = (Us == WHITE ? WIN : DRAW);
+ const Result Bad = (Us == WHITE ? DRAW : WIN);
Result r = INVALID;
- Bitboard b = StepAttacksBB[KING][Us == WHITE ? wksq : bksq];
+ Bitboard b = StepAttacksBB[KING][ksq[Us]];
while (b)
- r |= Us == WHITE ? db[index(Them, bksq, pop_lsb(&b), psq)]
- : db[index(Them, pop_lsb(&b), wksq, psq)];
-
- if (Us == WHITE && rank_of(psq) < RANK_7)
- {
- Square s = psq + DELTA_N;
- r |= db[index(BLACK, bksq, wksq, s)]; // Single push
-
- if (rank_of(psq) == RANK_2 && s != wksq && s != bksq)
- r |= db[index(BLACK, bksq, wksq, s + DELTA_N)]; // Double push
- }
+ r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)]
+ : db[index(Them, pop_lsb(&b), ksq[Them] , psq)];
if (Us == WHITE)
- return result = r & WIN ? WIN : r & UNKNOWN ? UNKNOWN : DRAW;
- else
- return result = r & DRAW ? DRAW : r & UNKNOWN ? UNKNOWN : WIN;
+ {
+ if (rank_of(psq) < RANK_7) // Single push
+ r |= db[index(Them, ksq[Them], ksq[Us], psq + DELTA_N)];
+
+ if ( rank_of(psq) == RANK_2 // Double push
+ && psq + DELTA_N != ksq[Us]
+ && psq + DELTA_N != ksq[Them])
+ r |= db[index(Them, ksq[Them], ksq[Us], psq + DELTA_N + DELTA_N)];
+ }
+
+ return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad;
}
} // namespace
diff --git a/DroidFish/jni/stockfish/bitboard.cpp b/DroidFish/jni/stockfish/bitboard.cpp
index 32efaed..7a4d73c 100644
--- a/DroidFish/jni/stockfish/bitboard.cpp
+++ b/DroidFish/jni/stockfish/bitboard.cpp
@@ -18,7 +18,6 @@
*/
#include
-#include // For std::memset
#include "bitboard.h"
#include "bitcount.h"
@@ -56,7 +55,7 @@ namespace {
const uint64_t DeBruijn64 = 0x3F79D71B4CB0A89ULL;
const uint32_t DeBruijn32 = 0x783A9B23;
- int MS1BTable[256]; // To implement software msb()
+ int MSBTable[256]; // To implement software msb()
Square BSFTable[SQUARE_NB]; // To implement software bitscan
Bitboard RookTable[0x19000]; // To store rook attacks
Bitboard BishopTable[0x1480]; // To store bishop attacks
@@ -69,7 +68,7 @@ namespace {
// bsf_index() returns the index into BSFTable[] to look up the bitscan. Uses
// Matt Taylor's folding for 32 bit case, extended to 64 bit by Kim Walisch.
- FORCE_INLINE unsigned bsf_index(Bitboard b) {
+ unsigned bsf_index(Bitboard b) {
b ^= b - 1;
return Is64Bit ? (b * DeBruijn64) >> 58
: ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn32) >> 26;
@@ -109,7 +108,7 @@ Square msb(Bitboard b) {
result += 8;
}
- return Square(result + MS1BTable[b32]);
+ return Square(result + MSBTable[b32]);
}
#endif // ifndef USE_BSFQ
@@ -125,9 +124,9 @@ const std::string Bitboards::pretty(Bitboard b) {
for (Rank r = RANK_8; r >= RANK_1; --r)
{
for (File f = FILE_A; f <= FILE_H; ++f)
- s.append(b & make_square(f, r) ? "| X " : "| ");
+ s += b & make_square(f, r) ? "| X " : "| ";
- s.append("|\n+---+---+---+---+---+---+---+---+\n");
+ s += "|\n+---+---+---+---+---+---+---+---+\n";
}
return s;
@@ -145,8 +144,8 @@ void Bitboards::init() {
BSFTable[bsf_index(SquareBB[s])] = s;
}
- for (Bitboard b = 1; b < 256; ++b)
- MS1BTable[b] = more_than_one(b) ? MS1BTable[b - 1] : lsb(b);
+ for (Bitboard b = 2; b < 256; ++b)
+ MSBTable[b] = MSBTable[b - 1] + !more_than_one(b);
for (File f = FILE_A; f <= FILE_H; ++f)
FileBB[f] = f > FILE_A ? FileBB[f - 1] << 1 : FileABB;
@@ -201,17 +200,15 @@ void Bitboards::init() {
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb(s1, 0);
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
- for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
- {
- Piece pc = (PseudoAttacks[BISHOP][s1] & s2) ? W_BISHOP :
- (PseudoAttacks[ROOK][s1] & s2) ? W_ROOK : NO_PIECE;
+ for (Piece pc = W_BISHOP; pc <= W_ROOK; ++pc)
+ for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
+ {
+ if (!(PseudoAttacks[pc][s1] & s2))
+ continue;
- if (pc == NO_PIECE)
- continue;
-
- LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
- BetweenBB[s1][s2] = attacks_bb(pc, s1, SquareBB[s2]) & attacks_bb(pc, s2, SquareBB[s1]);
- }
+ LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
+ BetweenBB[s1][s2] = attacks_bb(pc, s1, SquareBB[s2]) & attacks_bb(pc, s2, SquareBB[s1]);
+ }
}
}
@@ -249,7 +246,7 @@ namespace {
{ 728, 10316, 55013, 32803, 12281, 15100, 16645, 255 } };
Bitboard occupancy[4096], reference[4096], edges, b;
- int i, size;
+ int age[4096] = {0}, current = 0, i, size;
// attacks[s] is a pointer to the beginning of the attacks table for square 's'
attacks[SQ_A1] = table;
@@ -298,22 +295,21 @@ namespace {
magics[s] = rng.sparse_rand();
while (popcount((magics[s] * masks[s]) >> 56) < 6);
- std::memset(attacks[s], 0, size * sizeof(Bitboard));
-
// A good magic must map every possible occupancy to an index that
// looks up the correct sliding attack in the attacks[s] database.
// Note that we build up the database for square 's' as a side
// effect of verifying the magic.
- for (i = 0; i < size; ++i)
+ for (++current, i = 0; i < size; ++i)
{
- Bitboard& attack = attacks[s][index(s, occupancy[i])];
+ unsigned idx = index(s, occupancy[i]);
- if (attack && attack != reference[i])
+ if (age[idx] < current)
+ {
+ age[idx] = current;
+ attacks[s][idx] = reference[i];
+ }
+ else if (attacks[s][idx] != reference[i])
break;
-
- assert(reference[i]);
-
- attack = reference[i];
}
} while (i < size);
}
diff --git a/DroidFish/jni/stockfish/bitboard.h b/DroidFish/jni/stockfish/bitboard.h
index aa4e171..4aecf41 100644
--- a/DroidFish/jni/stockfish/bitboard.h
+++ b/DroidFish/jni/stockfish/bitboard.h
@@ -200,14 +200,6 @@ inline Bitboard passed_pawn_mask(Color c, Square s) {
}
-/// squares_of_color() returns a bitboard representing all the squares of the
-/// same color of the given one.
-
-inline Bitboard squares_of_color(Square s) {
- return DarkSquares & s ? DarkSquares : ~DarkSquares;
-}
-
-
/// aligned() returns true if the squares s1, s2 and s3 are aligned either on a
/// straight or on a diagonal line.
@@ -231,7 +223,7 @@ template<> inline int distance(Square x, Square y) { return distance(rank_
/// piece of type Pt (bishop or rook) placed on 's'. The helper magic_index()
/// looks up the index using the 'magic bitboards' approach.
template
-FORCE_INLINE unsigned magic_index(Square s, Bitboard occupied) {
+inline unsigned magic_index(Square s, Bitboard occupied) {
Bitboard* const Masks = Pt == ROOK ? RookMasks : BishopMasks;
Bitboard* const Magics = Pt == ROOK ? RookMagics : BishopMagics;
@@ -271,13 +263,13 @@ inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occupied) {
# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
-FORCE_INLINE Square lsb(Bitboard b) {
+inline Square lsb(Bitboard b) {
unsigned long idx;
_BitScanForward64(&idx, b);
return (Square) idx;
}
-FORCE_INLINE Square msb(Bitboard b) {
+inline Square msb(Bitboard b) {
unsigned long idx;
_BitScanReverse64(&idx, b);
return (Square) idx;
@@ -285,28 +277,28 @@ FORCE_INLINE Square msb(Bitboard b) {
# elif defined(__arm__)
-FORCE_INLINE int lsb32(uint32_t v) {
+inline int lsb32(uint32_t v) {
__asm__("rbit %0, %1" : "=r"(v) : "r"(v));
return __builtin_clz(v);
}
-FORCE_INLINE Square msb(Bitboard b) {
+inline Square msb(Bitboard b) {
return (Square) (63 - __builtin_clzll(b));
}
-FORCE_INLINE Square lsb(Bitboard b) {
+inline Square lsb(Bitboard b) {
return (Square) (uint32_t(b) ? lsb32(uint32_t(b)) : 32 + lsb32(uint32_t(b >> 32)));
}
# else // Assumed gcc or compatible compiler
-FORCE_INLINE Square lsb(Bitboard b) { // Assembly code by Heinz van Saanen
+inline Square lsb(Bitboard b) { // Assembly code by Heinz van Saanen
Bitboard idx;
__asm__("bsfq %1, %0": "=r"(idx): "rm"(b) );
return (Square) idx;
}
-FORCE_INLINE Square msb(Bitboard b) {
+inline Square msb(Bitboard b) {
Bitboard idx;
__asm__("bsrq %1, %0": "=r"(idx): "rm"(b) );
return (Square) idx;
@@ -324,7 +316,7 @@ Square msb(Bitboard b);
/// pop_lsb() finds and clears the least significant bit in a non-zero bitboard
-FORCE_INLINE Square pop_lsb(Bitboard* b) {
+inline Square pop_lsb(Bitboard* b) {
const Square s = lsb(*b);
*b &= *b - 1;
return s;
diff --git a/DroidFish/jni/stockfish/endgame.cpp b/DroidFish/jni/stockfish/endgame.cpp
index 2c87b2a..97e7e12 100644
--- a/DroidFish/jni/stockfish/endgame.cpp
+++ b/DroidFish/jni/stockfish/endgame.cpp
@@ -71,7 +71,7 @@ namespace {
assert(pos.count(strongSide) == 1);
- if (file_of(pos.list(strongSide)[0]) >= FILE_E)
+ if (file_of(pos.square(strongSide)) >= FILE_E)
sq = Square(sq ^ 7); // Mirror SQ_H1 -> SQ_A1
if (strongSide == BLACK)
@@ -96,12 +96,9 @@ namespace {
string fen = sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
+ sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";
- return Position(fen, false, NULL).material_key();
+ return Position(fen, false, nullptr).material_key();
}
- template
- void delete_endgame(const typename M::value_type& p) { delete p.second; }
-
} // namespace
@@ -128,17 +125,11 @@ Endgames::Endgames() {
add("KRPPKRP");
}
-Endgames::~Endgames() {
- for_each(m1.begin(), m1.end(), delete_endgame);
- for_each(m2.begin(), m2.end(), delete_endgame);
-}
-
-template
+template
void Endgames::add(const string& code) {
-
- map((Endgame*)0)[key(code, WHITE)] = new Endgame(WHITE);
- map((Endgame*)0)[key(code, BLACK)] = new Endgame(BLACK);
+ map()[key(code, WHITE)] = std::unique_ptr>(new Endgame(WHITE));
+ map()[key(code, BLACK)] = std::unique_ptr>(new Endgame(BLACK));
}
@@ -156,8 +147,8 @@ Value Endgame::operator()(const Position& pos) const {
if (pos.side_to_move() == weakSide && !MoveList(pos).size())
return VALUE_DRAW;
- Square winnerKSq = pos.king_square(strongSide);
- Square loserKSq = pos.king_square(weakSide);
+ Square winnerKSq = pos.square(strongSide);
+ Square loserKSq = pos.square(weakSide);
Value result = pos.non_pawn_material(strongSide)
+ pos.count(strongSide) * PawnValueEg
@@ -167,8 +158,8 @@ Value Endgame::operator()(const Position& pos) const {
if ( pos.count(strongSide)
|| pos.count(strongSide)
||(pos.count(strongSide) && pos.count(strongSide))
- ||(pos.count(strongSide) > 1 && opposite_colors(pos.list(strongSide)[0],
- pos.list(strongSide)[1])))
+ ||(pos.count(strongSide) > 1 && opposite_colors(pos.squares(strongSide)[0],
+ pos.squares(strongSide)[1])))
result += VALUE_KNOWN_WIN;
return strongSide == pos.side_to_move() ? result : -result;
@@ -183,9 +174,9 @@ Value Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, KnightValueMg + BishopValueMg, 0));
assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
- Square winnerKSq = pos.king_square(strongSide);
- Square loserKSq = pos.king_square(weakSide);
- Square bishopSq = pos.list(strongSide)[0];
+ Square winnerKSq = pos.square(strongSide);
+ Square loserKSq = pos.square(weakSide);
+ Square bishopSq = pos.square(strongSide);
// kbnk_mate_table() tries to drive toward corners A1 or H8. If we have a
// bishop that cannot reach the above squares, we flip the kings in order
@@ -212,9 +203,9 @@ Value Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
// Assume strongSide is white and the pawn is on files A-D
- Square wksq = normalize(pos, strongSide, pos.king_square(strongSide));
- Square bksq = normalize(pos, strongSide, pos.king_square(weakSide));
- Square psq = normalize(pos, strongSide, pos.list(strongSide)[0]);
+ Square wksq = normalize(pos, strongSide, pos.square(strongSide));
+ Square bksq = normalize(pos, strongSide, pos.square(weakSide));
+ Square psq = normalize(pos, strongSide, pos.square(strongSide));
Color us = strongSide == pos.side_to_move() ? WHITE : BLACK;
@@ -237,10 +228,10 @@ Value Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, RookValueMg, 0));
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
- Square wksq = relative_square(strongSide, pos.king_square(strongSide));
- Square bksq = relative_square(strongSide, pos.king_square(weakSide));
- Square rsq = relative_square(strongSide, pos.list(strongSide)[0]);
- Square psq = relative_square(strongSide, pos.list(weakSide)[0]);
+ Square wksq = relative_square(strongSide, pos.square(strongSide));
+ Square bksq = relative_square(strongSide, pos.square(weakSide));
+ Square rsq = relative_square(strongSide, pos.square(strongSide));
+ Square psq = relative_square(strongSide, pos.square(weakSide));
Square queeningSq = make_square(file_of(psq), RANK_1);
Value result;
@@ -280,7 +271,7 @@ Value Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, RookValueMg, 0));
assert(verify_material(pos, weakSide, BishopValueMg, 0));
- Value result = Value(PushToEdges[pos.king_square(weakSide)]);
+ Value result = Value(PushToEdges[pos.square(weakSide)]);
return strongSide == pos.side_to_move() ? result : -result;
}
@@ -293,8 +284,8 @@ Value Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, RookValueMg, 0));
assert(verify_material(pos, weakSide, KnightValueMg, 0));
- Square bksq = pos.king_square(weakSide);
- Square bnsq = pos.list(weakSide)[0];
+ Square bksq = pos.square(weakSide);
+ Square bnsq = pos.square(weakSide);
Value result = Value(PushToEdges[bksq] + PushAway[distance(bksq, bnsq)]);
return strongSide == pos.side_to_move() ? result : -result;
}
@@ -310,9 +301,9 @@ Value Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, QueenValueMg, 0));
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
- Square winnerKSq = pos.king_square(strongSide);
- Square loserKSq = pos.king_square(weakSide);
- Square pawnSq = pos.list(weakSide)[0];
+ Square winnerKSq = pos.square(strongSide);
+ Square loserKSq = pos.square(weakSide);
+ Square pawnSq = pos.square(weakSide);
Value result = Value(PushClose[distance(winnerKSq, loserKSq)]);
@@ -335,8 +326,8 @@ Value Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, QueenValueMg, 0));
assert(verify_material(pos, weakSide, RookValueMg, 0));
- Square winnerKSq = pos.king_square(strongSide);
- Square loserKSq = pos.king_square(weakSide);
+ Square winnerKSq = pos.square(strongSide);
+ Square loserKSq = pos.square(weakSide);
Value result = QueenValueEg
- RookValueEg
@@ -365,15 +356,15 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
// be detected even when the weaker side has some pawns.
Bitboard pawns = pos.pieces(strongSide, PAWN);
- File pawnFile = file_of(pos.list(strongSide)[0]);
+ File pawnsFile = file_of(lsb(pawns));
- // All pawns are on a single rook file ?
- if ( (pawnFile == FILE_A || pawnFile == FILE_H)
- && !(pawns & ~file_bb(pawnFile)))
+ // All pawns are on a single rook file?
+ if ( (pawnsFile == FILE_A || pawnsFile == FILE_H)
+ && !(pawns & ~file_bb(pawnsFile)))
{
- Square bishopSq = pos.list(strongSide)[0];
- Square queeningSq = relative_square(strongSide, make_square(pawnFile, RANK_8));
- Square kingSq = pos.king_square(weakSide);
+ Square bishopSq = pos.square(strongSide);
+ Square queeningSq = relative_square(strongSide, make_square(pawnsFile, RANK_8));
+ Square kingSq = pos.square(weakSide);
if ( opposite_colors(queeningSq, bishopSq)
&& distance(queeningSq, kingSq) <= 1)
@@ -381,17 +372,17 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
}
// If all the pawns are on the same B or G file, then it's potentially a draw
- if ( (pawnFile == FILE_B || pawnFile == FILE_G)
- && !(pos.pieces(PAWN) & ~file_bb(pawnFile))
+ if ( (pawnsFile == FILE_B || pawnsFile == FILE_G)
+ && !(pos.pieces(PAWN) & ~file_bb(pawnsFile))
&& pos.non_pawn_material(weakSide) == 0
&& pos.count(weakSide) >= 1)
{
// Get weakSide pawn that is closest to the home rank
Square weakPawnSq = backmost_sq(weakSide, pos.pieces(weakSide, PAWN));
- Square strongKingSq = pos.king_square(strongSide);
- Square weakKingSq = pos.king_square(weakSide);
- Square bishopSq = pos.list(strongSide)[0];
+ Square strongKingSq = pos.square(strongSide);
+ Square weakKingSq = pos.square(weakSide);
+ Square bishopSq = pos.square(strongSide);
// There's potential for a draw if our pawn is blocked on the 7th rank,
// the bishop cannot attack it or they only have one pawn left
@@ -428,11 +419,11 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(pos.count(weakSide) == 1);
assert(pos.count(weakSide) >= 1);
- Square kingSq = pos.king_square(weakSide);
- Square rsq = pos.list(weakSide)[0];
+ Square kingSq = pos.square(weakSide);
+ Square rsq = pos.square(weakSide);
if ( relative_rank(weakSide, kingSq) <= RANK_2
- && relative_rank(weakSide, pos.king_square(strongSide)) >= RANK_4
+ && relative_rank(weakSide, pos.square(strongSide)) >= RANK_4
&& relative_rank(weakSide, rsq) == RANK_3
&& ( pos.pieces(weakSide, PAWN)
& pos.attacks_from(kingSq)
@@ -456,11 +447,11 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, weakSide, RookValueMg, 0));
// Assume strongSide is white and the pawn is on files A-D
- Square wksq = normalize(pos, strongSide, pos.king_square(strongSide));
- Square bksq = normalize(pos, strongSide, pos.king_square(weakSide));
- Square wrsq = normalize(pos, strongSide, pos.list(strongSide)[0]);
- Square wpsq = normalize(pos, strongSide, pos.list(strongSide)[0]);
- Square brsq = normalize(pos, strongSide, pos.list(weakSide)[0]);
+ Square wksq = normalize(pos, strongSide, pos.square(strongSide));
+ Square bksq = normalize(pos, strongSide, pos.square(weakSide));
+ Square wrsq = normalize(pos, strongSide, pos.square(strongSide));
+ Square wpsq = normalize(pos, strongSide, pos.square(strongSide));
+ Square brsq = normalize(pos, strongSide, pos.square(weakSide));
File f = file_of(wpsq);
Rank r = rank_of(wpsq);
@@ -480,7 +471,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
if ( r == RANK_6
&& distance(bksq, queeningSq) <= 1
&& rank_of(wksq) + tempo <= RANK_6
- && (rank_of(brsq) == RANK_1 || (!tempo && distance(file_of(brsq), f) >= 3)))
+ && (rank_of(brsq) == RANK_1 || (!tempo && distance(brsq, wpsq) >= 3)))
return SCALE_FACTOR_DRAW;
if ( r >= RANK_6
@@ -552,9 +543,9 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
// Test for a rook pawn
if (pos.pieces(PAWN) & (FileABB | FileHBB))
{
- Square ksq = pos.king_square(weakSide);
- Square bsq = pos.list(weakSide)[0];
- Square psq = pos.list(strongSide)[0];
+ Square ksq = pos.square(weakSide);
+ Square bsq = pos.square(weakSide);
+ Square psq = pos.square(strongSide);
Rank rk = relative_rank(strongSide, psq);
Square push = pawn_push(strongSide);
@@ -567,7 +558,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
{
int d = distance(psq + 3 * push, ksq);
- if (d <= 2 && !(d == 0 && ksq == pos.king_square(strongSide) + 2 * push))
+ if (d <= 2 && !(d == 0 && ksq == pos.square(strongSide) + 2 * push))
return ScaleFactor(24);
else
return ScaleFactor(48);
@@ -595,9 +586,9 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, RookValueMg, 2));
assert(verify_material(pos, weakSide, RookValueMg, 1));
- Square wpsq1 = pos.list(strongSide)[0];
- Square wpsq2 = pos.list(strongSide)[1];
- Square bksq = pos.king_square(weakSide);
+ Square wpsq1 = pos.squares(strongSide)[0];
+ Square wpsq2 = pos.squares(strongSide)[1];
+ Square bksq = pos.square(weakSide);
// Does the stronger side have a passed pawn?
if (pos.pawn_passed(strongSide, wpsq1) || pos.pawn_passed(strongSide, wpsq2))
@@ -610,11 +601,11 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
&& relative_rank(strongSide, bksq) > r)
{
switch (r) {
- case RANK_2: return ScaleFactor(10);
+ case RANK_2: return ScaleFactor(9);
case RANK_3: return ScaleFactor(10);
- case RANK_4: return ScaleFactor(15);
- case RANK_5: return ScaleFactor(20);
- case RANK_6: return ScaleFactor(40);
+ case RANK_4: return ScaleFactor(14);
+ case RANK_5: return ScaleFactor(21);
+ case RANK_6: return ScaleFactor(44);
default: assert(false);
}
}
@@ -631,15 +622,14 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(pos.count(strongSide) >= 2);
assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
- Square ksq = pos.king_square(weakSide);
+ Square ksq = pos.square(weakSide);
Bitboard pawns = pos.pieces(strongSide, PAWN);
- Square psq = pos.list(strongSide)[0];
// If all pawns are ahead of the king, on a single rook file and
// the king is within one file of the pawns, it's a draw.
if ( !(pawns & ~in_front_bb(weakSide, rank_of(ksq)))
&& !((pawns & ~FileABB) && (pawns & ~FileHBB))
- && distance(ksq, psq) <= 1)
+ && distance(ksq, lsb(pawns)) <= 1)
return SCALE_FACTOR_DRAW;
return SCALE_FACTOR_NONE;
@@ -656,10 +646,10 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, BishopValueMg, 1));
assert(verify_material(pos, weakSide, BishopValueMg, 0));
- Square pawnSq = pos.list(strongSide)[0];
- Square strongBishopSq = pos.list(strongSide)[0];
- Square weakBishopSq = pos.list(weakSide)[0];
- Square weakKingSq = pos.king_square(weakSide);
+ Square pawnSq = pos.square(strongSide);
+ Square strongBishopSq = pos.square(strongSide);
+ Square weakBishopSq = pos.square(weakSide);
+ Square weakKingSq = pos.square(weakSide);
// Case 1: Defending king blocks the pawn, and cannot be driven away
if ( file_of(weakKingSq) == file_of(pawnSq)
@@ -706,15 +696,15 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, BishopValueMg, 2));
assert(verify_material(pos, weakSide, BishopValueMg, 0));
- Square wbsq = pos.list(strongSide)[0];
- Square bbsq = pos.list(weakSide)[0];
+ Square wbsq = pos.square(strongSide);
+ Square bbsq = pos.square(weakSide);
if (!opposite_colors(wbsq, bbsq))
return SCALE_FACTOR_NONE;
- Square ksq = pos.king_square(weakSide);
- Square psq1 = pos.list(strongSide)[0];
- Square psq2 = pos.list(strongSide)[1];
+ Square ksq = pos.square(weakSide);
+ Square psq1 = pos.squares(strongSide)[0];
+ Square psq2 = pos.squares(strongSide)[1];
Rank r1 = rank_of(psq1);
Rank r2 = rank_of(psq2);
Square blockSq1, blockSq2;
@@ -777,9 +767,9 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, strongSide, BishopValueMg, 1));
assert(verify_material(pos, weakSide, KnightValueMg, 0));
- Square pawnSq = pos.list(strongSide)[0];
- Square strongBishopSq = pos.list(strongSide)[0];
- Square weakKingSq = pos.king_square(weakSide);
+ Square pawnSq = pos.square(strongSide);
+ Square strongBishopSq = pos.square(strongSide);
+ Square weakKingSq = pos.square(weakSide);
if ( file_of(weakKingSq) == file_of(pawnSq)
&& relative_rank(strongSide, pawnSq) < relative_rank(strongSide, weakKingSq)
@@ -800,8 +790,8 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
// Assume strongSide is white and the pawn is on files A-D
- Square pawnSq = normalize(pos, strongSide, pos.list(strongSide)[0]);
- Square weakKingSq = normalize(pos, strongSide, pos.king_square(weakSide));
+ Square pawnSq = normalize(pos, strongSide, pos.square(strongSide));
+ Square weakKingSq = normalize(pos, strongSide, pos.square(weakSide));
if (pawnSq == SQ_A7 && distance(SQ_A8, weakKingSq) <= 1)
return SCALE_FACTOR_DRAW;
@@ -815,9 +805,9 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
template<>
ScaleFactor Endgame::operator()(const Position& pos) const {
- Square pawnSq = pos.list(strongSide)[0];
- Square bishopSq = pos.list(weakSide)[0];
- Square weakKingSq = pos.king_square(weakSide);
+ Square pawnSq = pos.square(strongSide);
+ Square bishopSq = pos.square(weakSide);
+ Square weakKingSq = pos.square(weakSide);
// King needs to get close to promoting pawn to prevent knight from blocking.
// Rules for this are very tricky, so just approximate.
@@ -840,9 +830,9 @@ ScaleFactor Endgame::operator()(const Position& pos) const {
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
// Assume strongSide is white and the pawn is on files A-D
- Square wksq = normalize(pos, strongSide, pos.king_square(strongSide));
- Square bksq = normalize(pos, strongSide, pos.king_square(weakSide));
- Square psq = normalize(pos, strongSide, pos.list(strongSide)[0]);
+ Square wksq = normalize(pos, strongSide, pos.square(strongSide));
+ Square bksq = normalize(pos, strongSide, pos.square(weakSide));
+ Square psq = normalize(pos, strongSide, pos.square(strongSide));
Color us = strongSide == pos.side_to_move() ? WHITE : BLACK;
diff --git a/DroidFish/jni/stockfish/endgame.h b/DroidFish/jni/stockfish/endgame.h
index d7a7681..f24ac93 100644
--- a/DroidFish/jni/stockfish/endgame.h
+++ b/DroidFish/jni/stockfish/endgame.h
@@ -21,7 +21,10 @@
#define ENDGAME_H_INCLUDED
#include