+
+ // evaluate_initiative() computes the initiative correction value for the position, i.e.
+ // second order bonus/malus based on the known attacking/defending status of the players.
+ Score evaluate_initiative(const Position& pos, const EvalInfo& ei, const Score positional_score) {
+
+ int pawns = pos.count<PAWN>(WHITE) + pos.count<PAWN>(BLACK);
+ int king_separation = distance<File>(pos.square<KING>(WHITE), pos.square<KING>(BLACK));
+ int asymmetry = ei.pi->pawn_asymmetry();
+
+ // Compute the initiative bonus for the attacking side
+ int attacker_bonus = 8 * (pawns + asymmetry + king_separation) - 120;
+
+ // Now apply the bonus: note that we find the attacking side by extracting the sign
+ // of the endgame value of "positional_score", and that we carefully cap the bonus so
+ // that the endgame score with the correction will never be divided by more than two.
+ int eg = eg_value(positional_score);
+ int value = ((eg > 0) - (eg < 0)) * std::max( attacker_bonus , -abs( eg / 2 ) );
+
+ return make_score( 0 , value ) ;
+ }
+