From: Marco Costalba Date: Fri, 20 Feb 2009 11:05:07 +0000 (+0100) Subject: Unify compute_mg_value() and compute_eg_value() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=f30aa83f8ad46a794e83f030fdab576371c8c825 Unify compute_mg_value() and compute_eg_value() No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/position.cpp b/src/position.cpp index 5a8ef0b1..d5f28218 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -210,8 +210,8 @@ void Position::from_fen(const std::string& fen) { key = compute_key(); pawnKey = compute_pawn_key(); materialKey = compute_material_key(); - mgValue = compute_mg_value(); - egValue = compute_eg_value(); + mgValue = compute_value(MidGame); + egValue = compute_value(EndGame); npMaterial[WHITE] = compute_non_pawn_material(WHITE); npMaterial[BLACK] = compute_non_pawn_material(BLACK); } @@ -1817,7 +1817,7 @@ Key Position::compute_material_key() const { /// up, and to verify that the scores are correctly updated by do_move /// and undo_move when the program is running in debug mode. -Value Position::compute_mg_value() const { +Value Position::compute_value(GamePhase p) const { Value result = Value(0); Bitboard b; @@ -1831,31 +1831,12 @@ Value Position::compute_mg_value() const { { s = pop_1st_bit(&b); assert(piece_on(s) == piece_of_color_and_type(c, pt)); - result += mg_pst(c, pt, s); + result += (p == MidGame ? mg_pst(c, pt, s) : eg_pst(c, pt, s)); } } - result += (side_to_move() == WHITE)? TempoValueMidgame / 2 : -TempoValueMidgame / 2; - return result; -} - -Value Position::compute_eg_value() const { - - Value result = Value(0); - Bitboard b; - Square s; - for (Color c = WHITE; c <= BLACK; c++) - for (PieceType pt = PAWN; pt <= KING; pt++) - { - b = pieces_of_color_and_type(c, pt); - while(b) - { - s = pop_1st_bit(&b); - assert(piece_on(s) == piece_of_color_and_type(c, pt)); - result += eg_pst(c, pt, s); - } - } - result += (side_to_move() == WHITE)? TempoValueEndgame / 2 : -TempoValueEndgame / 2; + const Value TempoValue = (p == MidGame ? TempoValueMidgame : TempoValueEndgame); + result += (side_to_move() == WHITE)? TempoValue / 2 : -TempoValue / 2; return result; } @@ -2076,8 +2057,8 @@ void Position::flipped_copy(const Position &pos) { materialKey = compute_material_key(); // Incremental scores - mgValue = compute_mg_value(); - egValue = compute_eg_value(); + mgValue = compute_value(MidGame); + egValue = compute_value(EndGame); // Material npMaterial[WHITE] = compute_non_pawn_material(WHITE); @@ -2206,10 +2187,10 @@ bool Position::is_ok(int* failedStep) const { if (failedStep) (*failedStep)++; if (debugIncrementalEval) { - if (mgValue != compute_mg_value()) + if (mgValue != compute_value(MidGame)) return false; - if (egValue != compute_eg_value()) + if (egValue != compute_value(EndGame)) return false; } diff --git a/src/position.h b/src/position.h index aaed663b..11b9e2de 100644 --- a/src/position.h +++ b/src/position.h @@ -315,10 +315,13 @@ private: Key compute_material_key() const; // Computing incremental evaluation scores and material counts + enum GamePhase { + MidGame, + EndGame + }; Value mg_pst(Color c, PieceType pt, Square s) const; Value eg_pst(Color c, PieceType pt, Square s) const; - Value compute_mg_value() const; - Value compute_eg_value() const; + Value compute_value(GamePhase p) const; Value compute_non_pawn_material(Color c) const; // Bitboards