Skip to content
Permalink
Browse files

simplify some scoring.

  • Loading branch information...
protonspring committed Jun 12, 2019
1 parent a9cca5c commit df3805652df7f254b1ee0745c9f9612bfab4a300
Showing with 19 additions and 15 deletions.
  1. +6 −6 src/evaluate.cpp
  2. +8 −9 src/pawns.cpp
  3. +5 −0 src/types.h
@@ -625,12 +625,12 @@ namespace {
Square blockSq = s + Up;

// Adjust bonus based on the king's proximity
bonus += make_score(0, ( king_proximity(Them, blockSq) * 5
- king_proximity(Us, blockSq) * 2) * w);
bonus += score_eg((king_proximity(Them, blockSq) * 5
- king_proximity(Us, blockSq) * 2) * w);

// If blockSq is not the queening square then consider also a second push
if (r != RANK_7)
bonus -= make_score(0, king_proximity(Us, blockSq + Up) * w);
bonus -= score_eg(king_proximity(Us, blockSq + Up) * w);

// If the pawn is free to advance, then increase the bonus
if (pos.empty(blockSq))
@@ -707,7 +707,7 @@ namespace {

int bonus = popcount(safe) + popcount(behind & safe);
int weight = pos.count<ALL_PIECES>(Us) - 1;
Score score = make_score(bonus * weight * weight / 16, 0);
Score score = score_mg(bonus * weight * weight / 16);

if (T)
Trace::add(SPACE, Us, score);
@@ -743,9 +743,9 @@ namespace {
int v = ((eg > 0) - (eg < 0)) * std::max(complexity, -abs(eg));

if (T)
Trace::add(INITIATIVE, make_score(0, v));
Trace::add(INITIATIVE, score_eg(v));

return make_score(0, v);
return score_eg(v);
}


@@ -183,8 +183,7 @@ void Entry::evaluate_shelter(const Position& pos, Square ksq, Score& shelter) {
Bitboard ourPawns = b & pos.pieces(Us);
Bitboard theirPawns = b & pos.pieces(Them);

Value bonus[] = { (shift<Down>(theirPawns) & BlockSquares & ksq) ? Value(374) : Value(5),
VALUE_ZERO };
Score bonus = score_mg((shift<Down>(theirPawns) & BlockSquares & ksq) ? Value(374) : Value(5));

File center = clamp(file_of(ksq), FILE_B, FILE_G);
for (File f = File(center - 1); f <= File(center + 1); ++f)
@@ -196,16 +195,16 @@ void Entry::evaluate_shelter(const Position& pos, Square ksq, Score& shelter) {
Rank theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;

int d = std::min(f, ~f);
bonus[MG] += ShelterStrength[d][ourRank];
bonus += score_mg(ShelterStrength[d][ourRank]);

if (ourRank && (ourRank == theirRank - 1))
bonus[MG] -= 82 * (theirRank == RANK_3), bonus[EG] -= 82 * (theirRank == RANK_3);
bonus -= make_score(82 * (theirRank == RANK_3), 82 * (theirRank == RANK_3));
else
bonus[MG] -= UnblockedStorm[d][theirRank];
bonus -= score_mg(UnblockedStorm[d][theirRank]);
}

if (bonus[MG] > mg_value(shelter))
shelter = make_score(bonus[MG], bonus[EG]);
if (mg_value(bonus) > mg_value(shelter))
shelter = bonus;
}


@@ -228,7 +227,7 @@ Score Entry::do_king_safety(const Position& pos) {
else while (pawns)
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns)));

Score shelter = make_score(-VALUE_INFINITE, VALUE_ZERO);
Score shelter = score_mg(-VALUE_INFINITE);
evaluate_shelter<Us>(pos, ksq, shelter);

// If we can castle use the bonus after the castling if it is bigger
@@ -238,7 +237,7 @@ Score Entry::do_king_safety(const Position& pos) {
if (pos.can_castle(Us | QUEEN_SIDE))
evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1), shelter);

return shelter - make_score(VALUE_ZERO, 16 * minPawnDist);
return shelter - score_eg(16 * minPawnDist);
}

// Explicit template instantiation
@@ -265,6 +265,7 @@ constexpr Score make_score(int mg, int eg) {
return Score((int)((unsigned int)eg << 16) + mg);
}


/// Extracting the signed lower and upper 16 bits is not so trivial because
/// according to the standard a simple cast to short is implementation defined
/// and so is a right shift of a signed integer.
@@ -278,6 +279,10 @@ inline Value mg_value(Score s) {
return Value(mg.s);
}

inline Score score_mg(int v) { return make_score(v, 0); }
inline Score score_eg(int v) { return make_score(0, v); }


#define ENABLE_BASE_OPERATORS_ON(T) \
constexpr T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
constexpr T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \

1 comment on commit df38056

@protonspring

This comment has been minimized.

Copy link
Owner Author

commented on df38056 Jun 13, 2019

I decided not to submit this. If someone disagrees, let me know.

Please sign in to comment.
You can’t perform that action at this time.