mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Further streamline connected pawn evaluation
Make even more clear what are the terms that contribute to evaluate connected pawns, and completely separate them from the weights that are now fully looked up in a table. For future tuning makes sense to init the table with a formula instead of hard-code it. This allows to reduce problem space cardinality and makes tuning easier. And fix a MSVC warning while there: warning C4804: '>>' : unsafe use of type 'bool' in operation No functional change.
This commit is contained in:
parent
069073ea68
commit
91de6b0f37
3 changed files with 24 additions and 16 deletions
|
@ -37,6 +37,7 @@ int main(int argc, char* argv[]) {
|
||||||
Bitbases::init_kpk();
|
Bitbases::init_kpk();
|
||||||
Search::init();
|
Search::init();
|
||||||
Eval::init();
|
Eval::init();
|
||||||
|
Pawns::init();
|
||||||
Threads.init();
|
Threads.init();
|
||||||
TT.resize(Options["Hash"]);
|
TT.resize(Options["Hash"]);
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ namespace {
|
||||||
{ S(20, 28), S(29, 31), S(33, 31), S(33, 31),
|
{ S(20, 28), S(29, 31), S(33, 31), S(33, 31),
|
||||||
S(33, 31), S(33, 31), S(29, 31), S(20, 28) } };
|
S(33, 31), S(33, 31), S(29, 31), S(20, 28) } };
|
||||||
|
|
||||||
// Connected bonus by rank
|
// Connected pawn bonus by opposed, phalanx flags and rank
|
||||||
const int Connected[RANK_NB] = {0, 6, 15, 10, 57, 75, 135, 258};
|
Score Connected[2][2][RANK_NB];
|
||||||
|
|
||||||
// Levers bonus by rank
|
// Levers bonus by rank
|
||||||
const Score Lever[RANK_NB] = {
|
const Score Lever[RANK_NB] = {
|
||||||
|
@ -89,9 +89,9 @@ namespace {
|
||||||
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
||||||
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
||||||
|
|
||||||
Bitboard b, p, doubled;
|
Bitboard b, p, doubled, connected;
|
||||||
Square s;
|
Square s;
|
||||||
bool passed, isolated, opposed, connected, backward, unsupported, lever;
|
bool passed, isolated, opposed, phalanx, backward, unsupported, lever;
|
||||||
Score value = SCORE_ZERO;
|
Score value = SCORE_ZERO;
|
||||||
const Square* pl = pos.list<PAWN>(Us);
|
const Square* pl = pos.list<PAWN>(Us);
|
||||||
const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)];
|
const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)];
|
||||||
|
@ -111,7 +111,6 @@ namespace {
|
||||||
{
|
{
|
||||||
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
||||||
|
|
||||||
Rank r = rank_of(s), rr = relative_rank(Us, s);
|
|
||||||
File f = file_of(s);
|
File f = file_of(s);
|
||||||
|
|
||||||
// This file cannot be semi-open
|
// This file cannot be semi-open
|
||||||
|
@ -120,12 +119,10 @@ namespace {
|
||||||
// Previous rank
|
// Previous rank
|
||||||
p = rank_bb(s - pawn_push(Us));
|
p = rank_bb(s - pawn_push(Us));
|
||||||
|
|
||||||
// Our rank plus previous one
|
|
||||||
b = rank_bb(s) | p;
|
|
||||||
|
|
||||||
// Flag the pawn as passed, isolated, doubled,
|
// Flag the pawn as passed, isolated, doubled,
|
||||||
// unsupported or connected (but not the backward one).
|
// unsupported or connected (but not the backward one).
|
||||||
connected = ourPawns & adjacent_files_bb(f) & b;
|
connected = ourPawns & adjacent_files_bb(f) & (rank_bb(s) | p);
|
||||||
|
phalanx = connected & rank_bb(s);
|
||||||
unsupported = !(ourPawns & adjacent_files_bb(f) & p);
|
unsupported = !(ourPawns & adjacent_files_bb(f) & p);
|
||||||
isolated = !(ourPawns & adjacent_files_bb(f));
|
isolated = !(ourPawns & adjacent_files_bb(f));
|
||||||
doubled = ourPawns & forward_bb(Us, s);
|
doubled = ourPawns & forward_bb(Us, s);
|
||||||
|
@ -176,15 +173,11 @@ namespace {
|
||||||
if (backward)
|
if (backward)
|
||||||
value -= Backward[opposed][f];
|
value -= Backward[opposed][f];
|
||||||
|
|
||||||
if (connected) {
|
if (connected)
|
||||||
int bonus = Connected[rr];
|
value += Connected[opposed][phalanx][relative_rank(Us, s)];
|
||||||
if (ourPawns & adjacent_files_bb(f) & rank_bb(r))
|
|
||||||
bonus += (Connected[rr+1] - Connected[rr]) / 2;
|
|
||||||
value += make_score(bonus / 2, bonus >> opposed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lever)
|
if (lever)
|
||||||
value += Lever[rr];
|
value += Lever[relative_rank(Us, s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
b = e->semiopenFiles[Us] ^ 0xFF;
|
b = e->semiopenFiles[Us] ^ 0xFF;
|
||||||
|
@ -201,6 +194,19 @@ namespace {
|
||||||
|
|
||||||
namespace Pawns {
|
namespace Pawns {
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
const int c[RANK_NB] = {0, 6, 15, 10, 57, 75, 135, 258};
|
||||||
|
|
||||||
|
for (Rank r = RANK_2; r <= RANK_7; ++r)
|
||||||
|
for (int opposed = false; opposed <= true; ++opposed)
|
||||||
|
for (int phalanx = false; phalanx <= true; ++phalanx)
|
||||||
|
{
|
||||||
|
int bonus = c[r] + (phalanx ? (c[r + 1] - c[r]) / 2 : 0);
|
||||||
|
Connected[opposed][phalanx][r] = make_score(bonus / 2, bonus >> opposed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// probe() takes a position as input, computes a Entry object, and returns a
|
/// probe() takes a position as input, computes a Entry object, and returns a
|
||||||
/// pointer to it. The result is also stored in a hash table, so we don't have
|
/// pointer to it. The result is also stored in a hash table, so we don't have
|
||||||
/// to recompute everything when the same pawn structure occurs again.
|
/// to recompute everything when the same pawn structure occurs again.
|
||||||
|
|
|
@ -79,6 +79,7 @@ struct Entry {
|
||||||
|
|
||||||
typedef HashTable<Entry, 16384> Table;
|
typedef HashTable<Entry, 16384> Table;
|
||||||
|
|
||||||
|
void init();
|
||||||
Entry* probe(const Position& pos, Table& entries);
|
Entry* probe(const Position& pos, Table& entries);
|
||||||
|
|
||||||
} // namespace Pawns
|
} // namespace Pawns
|
||||||
|
|
Loading…
Add table
Reference in a new issue