From c3d2e6aba981ecc0caf82f81a1d44e8c4954e151 Mon Sep 17 00:00:00 2001 From: snicolet Date: Wed, 8 Mar 2017 18:45:09 -0800 Subject: [PATCH] Helper functions to count material for both sides Syntactic sugar: helper functions to count material or pieces for both sides. No functional change Closes #1025 --- src/evaluate.cpp | 10 +++++----- src/position.h | 10 ++++++++++ src/search.cpp | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 69a7ea37..6bd45131 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -179,7 +179,7 @@ namespace { S( 9, 10), S( 2, 10), S( 1, -8), S(-20,-12), S(-20,-12), S( 1, -8), S( 2, 10), S( 9, 10) }; - + // Protector[PieceType-2][distance] contains a protecting bonus for our king, // indexed by piece type and distance between the piece and the king. const Score Protector[4][8] = { @@ -302,7 +302,7 @@ namespace { int mob = popcount(b & ei.mobilityArea[Us]); mobility[Us] += MobilityBonus[Pt-2][mob]; - + // Bonus for this piece as a king protector score += Protector[Pt-2][distance(s, pos.square(Us))]; @@ -740,7 +740,7 @@ namespace { int kingDistance = distance(pos.square(WHITE), pos.square(BLACK)) - distance(pos.square(WHITE), pos.square(BLACK)); - int pawns = pos.count(WHITE) + pos.count(BLACK); + int pawns = pos.count(); bool bothFlanks = (pos.pieces(PAWN) & QueenSide) && (pos.pieces(PAWN) & KingSide); // Compute the initiative bonus for the attacking side @@ -847,7 +847,7 @@ Value Eval::evaluate(const Position& pos) { - evaluate_passer_pawns(pos, ei); // Evaluate space for both sides, only during opening - if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 12222) + if (pos.non_pawn_material() >= 12222) score += evaluate_space(pos, ei) - evaluate_space(pos, ei); @@ -870,7 +870,7 @@ Value Eval::evaluate(const Position& pos) { Trace::add(IMBALANCE, ei.me->imbalance()); Trace::add(PAWN, ei.pe->pawns_score()); Trace::add(MOBILITY, mobility[WHITE], mobility[BLACK]); - if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 12222) + if (pos.non_pawn_material() >= 12222) Trace::add(SPACE, evaluate_space(pos, ei) , evaluate_space(pos, ei)); Trace::add(TOTAL, score); diff --git a/src/position.h b/src/position.h index 3d0ffb85..e571048a 100644 --- a/src/position.h +++ b/src/position.h @@ -90,6 +90,7 @@ public: Square ep_square() const; bool empty(Square s) const; template int count(Color c) const; + template int count() const; template const Square* squares(Color c) const; template Square square(Color c) const; @@ -154,6 +155,7 @@ public: int rule50_count() const; Score psq_score() const; Value non_pawn_material(Color c) const; + Value non_pawn_material() const; // Position consistency check, for debugging bool pos_is_ok(int* failedStep = nullptr) const; @@ -236,6 +238,10 @@ template inline int Position::count(Color c) const { return pieceCount[make_piece(c, Pt)]; } +template inline int Position::count() const { + return pieceCount[make_piece(WHITE, Pt)] + pieceCount[make_piece(BLACK, Pt)]; +} + template inline const Square* Position::squares(Color c) const { return pieceList[make_piece(c, Pt)]; } @@ -330,6 +336,10 @@ inline Value Position::non_pawn_material(Color c) const { return st->nonPawnMaterial[c]; } +inline Value Position::non_pawn_material() const { + return st->nonPawnMaterial[WHITE] + st->nonPawnMaterial[BLACK]; +} + inline int Position::game_ply() const { return gamePly; } diff --git a/src/search.cpp b/src/search.cpp index 46e93d07..b31ed0c2 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -643,7 +643,7 @@ namespace { // Step 4a. Tablebase probe if (!rootNode && TB::Cardinality) { - int piecesCount = pos.count(WHITE) + pos.count(BLACK); + int piecesCount = pos.count(); if ( piecesCount <= TB::Cardinality && (piecesCount < TB::Cardinality || depth >= TB::ProbeDepth) @@ -900,7 +900,7 @@ moves_loop: // When in check search starts from here { if ( !captureOrPromotion && !givesCheck - && (!pos.advanced_pawn_push(move) || pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 5000)) + && (!pos.advanced_pawn_push(move) || pos.non_pawn_material() >= 5000)) { // Move count based pruning if (moveCountPruning) -- 2.39.2