Skip to content

Commit 06b9140

Browse files
committed
Temporary revert "Expose EvalInfo struct to search"
It is not needed for the release and introduces a slowdown, although very small. Probably it will be readded after the release. No functional change.
1 parent 1566357 commit 06b9140

File tree

4 files changed

+69
-73
lines changed

4 files changed

+69
-73
lines changed

src/evaluate.cpp

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,53 @@
2424

2525
#include "bitcount.h"
2626
#include "evaluate.h"
27+
#include "material.h"
28+
#include "pawns.h"
2729
#include "thread.h"
2830
#include "ucioption.h"
2931

30-
using namespace Eval;
31-
3232
namespace {
3333

34+
// Struct EvalInfo contains various information computed and collected
35+
// by the evaluation functions.
36+
struct EvalInfo {
37+
38+
// Pointers to material and pawn hash table entries
39+
Material::Entry* mi;
40+
Pawns::Entry* pi;
41+
42+
// attackedBy[color][piece type] is a bitboard representing all squares
43+
// attacked by a given color and piece type, attackedBy[color][ALL_PIECES]
44+
// contains all squares attacked by the given color.
45+
Bitboard attackedBy[COLOR_NB][PIECE_TYPE_NB];
46+
47+
// kingRing[color] is the zone around the king which is considered
48+
// by the king safety evaluation. This consists of the squares directly
49+
// adjacent to the king, and the three (or two, for a king on an edge file)
50+
// squares two ranks in front of the king. For instance, if black's king
51+
// is on g8, kingRing[BLACK] is a bitboard containing the squares f8, h8,
52+
// f7, g7, h7, f6, g6 and h6.
53+
Bitboard kingRing[COLOR_NB];
54+
55+
// kingAttackersCount[color] is the number of pieces of the given color
56+
// which attack a square in the kingRing of the enemy king.
57+
int kingAttackersCount[COLOR_NB];
58+
59+
// kingAttackersWeight[color] is the sum of the "weight" of the pieces of the
60+
// given color which attack a square in the kingRing of the enemy king. The
61+
// weights of the individual piece types are given by the variables
62+
// QueenAttackWeight, RookAttackWeight, BishopAttackWeight and
63+
// KnightAttackWeight in evaluate.cpp
64+
int kingAttackersWeight[COLOR_NB];
65+
66+
// kingAdjacentZoneAttacksCount[color] is the number of attacks to squares
67+
// directly adjacent to the king of the given color. Pieces which attack
68+
// more than one square are counted multiple times. For instance, if black's
69+
// king is on g8 and there's a white knight on g5, this knight adds
70+
// 2 to kingAdjacentZoneAttacksCount[BLACK].
71+
int kingAdjacentZoneAttacksCount[COLOR_NB];
72+
};
73+
3474
// Evaluation grain size, must be a power of 2
3575
const int GrainSize = 8;
3676

@@ -200,27 +240,27 @@ namespace {
200240

201241
// Function prototypes
202242
template<bool Trace>
203-
Value do_evaluate(const Position& pos, Value& margin, Info& ei);
243+
Value do_evaluate(const Position& pos, Value& margin);
204244

205245
template<Color Us>
206-
void init_eval_info(const Position& pos, Info& ei);
246+
void init_eval_info(const Position& pos, EvalInfo& ei);
207247

208248
template<Color Us, bool Trace>
209-
Score evaluate_pieces_of_color(const Position& pos, Info& ei, Score& mobility);
249+
Score evaluate_pieces_of_color(const Position& pos, EvalInfo& ei, Score& mobility);
210250

211251
template<Color Us, bool Trace>
212-
Score evaluate_king(const Position& pos, Info& ei, Value margins[]);
252+
Score evaluate_king(const Position& pos, EvalInfo& ei, Value margins[]);
213253

214254
template<Color Us>
215-
Score evaluate_threats(const Position& pos, Info& ei);
255+
Score evaluate_threats(const Position& pos, EvalInfo& ei);
216256

217257
template<Color Us>
218-
int evaluate_space(const Position& pos, Info& ei);
258+
int evaluate_space(const Position& pos, EvalInfo& ei);
219259

220260
template<Color Us>
221-
Score evaluate_passed_pawns(const Position& pos, Info& ei);
261+
Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei);
222262

223-
Score evaluate_unstoppable_pawns(const Position& pos, Info& ei);
263+
Score evaluate_unstoppable_pawns(const Position& pos, EvalInfo& ei);
224264

225265
Value interpolate(const Score& v, Phase ph, ScaleFactor sf);
226266
Score weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight);
@@ -236,8 +276,8 @@ namespace Eval {
236276
/// values, an endgame score and a middle game score, and interpolates
237277
/// between them based on the remaining material.
238278

239-
Value evaluate(const Position& pos, Value& margin, Info* ei) {
240-
return do_evaluate<false>(pos, margin, *ei);
279+
Value evaluate(const Position& pos, Value& margin) {
280+
return do_evaluate<false>(pos, margin);
241281
}
242282

243283

@@ -273,15 +313,14 @@ namespace Eval {
273313

274314
Value margin;
275315
std::string totals;
276-
Info ei;
277316

278317
Search::RootColor = pos.side_to_move();
279318

280319
TraceStream.str("");
281320
TraceStream << std::showpoint << std::showpos << std::fixed << std::setprecision(2);
282321
memset(TracedScores, 0, 2 * 16 * sizeof(Score));
283322

284-
do_evaluate<true>(pos, margin, ei);
323+
do_evaluate<true>(pos, margin);
285324

286325
totals = TraceStream.str();
287326
TraceStream.str("");
@@ -317,10 +356,11 @@ namespace Eval {
317356
namespace {
318357

319358
template<bool Trace>
320-
Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
359+
Value do_evaluate(const Position& pos, Value& margin) {
321360

322361
assert(!pos.checkers());
323362

363+
EvalInfo ei;
324364
Value margins[COLOR_NB];
325365
Score score, mobilityWhite, mobilityBlack;
326366
Thread* th = pos.this_thread();
@@ -443,7 +483,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
443483
// pawn attacks. To be done at the beginning of the evaluation.
444484

445485
template<Color Us>
446-
void init_eval_info(const Position& pos, Info& ei) {
486+
void init_eval_info(const Position& pos, EvalInfo& ei) {
447487

448488
const Color Them = (Us == WHITE ? BLACK : WHITE);
449489

@@ -466,7 +506,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
466506
// evaluate_outposts() evaluates bishop and knight outposts squares
467507

468508
template<PieceType Piece, Color Us>
469-
Score evaluate_outposts(const Position& pos, Info& ei, Square s) {
509+
Score evaluate_outposts(const Position& pos, EvalInfo& ei, Square s) {
470510

471511
const Color Them = (Us == WHITE ? BLACK : WHITE);
472512

@@ -492,7 +532,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
492532
// evaluate_pieces<>() assigns bonuses and penalties to the pieces of a given color
493533

494534
template<PieceType Piece, Color Us, bool Trace>
495-
Score evaluate_pieces(const Position& pos, Info& ei, Score& mobility, Bitboard mobilityArea) {
535+
Score evaluate_pieces(const Position& pos, EvalInfo& ei, Score& mobility, Bitboard mobilityArea) {
496536

497537
Bitboard b;
498538
Square s, ksq;
@@ -641,7 +681,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
641681
// and the type of attacked one.
642682

643683
template<Color Us>
644-
Score evaluate_threats(const Position& pos, Info& ei) {
684+
Score evaluate_threats(const Position& pos, EvalInfo& ei) {
645685

646686
const Color Them = (Us == WHITE ? BLACK : WHITE);
647687

@@ -683,7 +723,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
683723
// pieces of a given color.
684724

685725
template<Color Us, bool Trace>
686-
Score evaluate_pieces_of_color(const Position& pos, Info& ei, Score& mobility) {
726+
Score evaluate_pieces_of_color(const Position& pos, EvalInfo& ei, Score& mobility) {
687727

688728
const Color Them = (Us == WHITE ? BLACK : WHITE);
689729

@@ -708,7 +748,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
708748
// evaluate_king<>() assigns bonuses and penalties to a king of a given color
709749

710750
template<Color Us, bool Trace>
711-
Score evaluate_king(const Position& pos, Info& ei, Value margins[]) {
751+
Score evaluate_king(const Position& pos, EvalInfo& ei, Value margins[]) {
712752

713753
const Color Them = (Us == WHITE ? BLACK : WHITE);
714754

@@ -821,7 +861,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
821861
// evaluate_passed_pawns<>() evaluates the passed pawns of the given color
822862

823863
template<Color Us>
824-
Score evaluate_passed_pawns(const Position& pos, Info& ei) {
864+
Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei) {
825865

826866
const Color Them = (Us == WHITE ? BLACK : WHITE);
827867

@@ -919,7 +959,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
919959
// evaluate_unstoppable_pawns() evaluates the unstoppable passed pawns for both sides, this is quite
920960
// conservative and returns a winning score only when we are very sure that the pawn is winning.
921961

922-
Score evaluate_unstoppable_pawns(const Position& pos, Info& ei) {
962+
Score evaluate_unstoppable_pawns(const Position& pos, EvalInfo& ei) {
923963

924964
Bitboard b, b2, blockers, supporters, queeningPath, candidates;
925965
Square s, blockSq, queeningSquare;
@@ -1084,7 +1124,7 @@ Value do_evaluate(const Position& pos, Value& margin, Info& ei) {
10841124
// twice. Finally, the space bonus is scaled by a weight taken from the
10851125
// material hash table. The aim is to improve play on game opening.
10861126
template<Color Us>
1087-
int evaluate_space(const Position& pos, Info& ei) {
1127+
int evaluate_space(const Position& pos, EvalInfo& ei) {
10881128

10891129
const Color Them = (Us == WHITE ? BLACK : WHITE);
10901130

src/evaluate.h

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,56 +20,14 @@
2020
#if !defined(EVALUATE_H_INCLUDED)
2121
#define EVALUATE_H_INCLUDED
2222

23-
#include "material.h"
24-
#include "pawns.h"
2523
#include "types.h"
2624

2725
class Position;
2826

2927
namespace Eval {
3028

31-
// Struct Eval::Info contains various information computed and collected
32-
// by the evaluation functions.
33-
struct Info {
34-
35-
// Pointers to material and pawn hash table entries
36-
Material::Entry* mi;
37-
Pawns::Entry* pi;
38-
39-
// attackedBy[color][piece type] is a bitboard representing all squares
40-
// attacked by a given color and piece type, attackedBy[color][ALL_PIECES]
41-
// contains all squares attacked by the given color.
42-
Bitboard attackedBy[COLOR_NB][PIECE_TYPE_NB];
43-
44-
// kingRing[color] is the zone around the king which is considered
45-
// by the king safety evaluation. This consists of the squares directly
46-
// adjacent to the king, and the three (or two, for a king on an edge file)
47-
// squares two ranks in front of the king. For instance, if black's king
48-
// is on g8, kingRing[BLACK] is a bitboard containing the squares f8, h8,
49-
// f7, g7, h7, f6, g6 and h6.
50-
Bitboard kingRing[COLOR_NB];
51-
52-
// kingAttackersCount[color] is the number of pieces of the given color
53-
// which attack a square in the kingRing of the enemy king.
54-
int kingAttackersCount[COLOR_NB];
55-
56-
// kingAttackersWeight[color] is the sum of the "weight" of the pieces of the
57-
// given color which attack a square in the kingRing of the enemy king. The
58-
// weights of the individual piece types are given by the variables
59-
// QueenAttackWeight, RookAttackWeight, BishopAttackWeight and
60-
// KnightAttackWeight in evaluate.cpp
61-
int kingAttackersWeight[COLOR_NB];
62-
63-
// kingAdjacentZoneAttacksCount[color] is the number of attacks to squares
64-
// directly adjacent to the king of the given color. Pieces which attack
65-
// more than one square are counted multiple times. For instance, if black's
66-
// king is on g8 and there's a white knight on g5, this knight adds
67-
// 2 to kingAdjacentZoneAttacksCount[BLACK].
68-
int kingAdjacentZoneAttacksCount[COLOR_NB];
69-
};
70-
7129
extern void init();
72-
extern Value evaluate(const Position& pos, Value& margin, Info* ei);
30+
extern Value evaluate(const Position& pos, Value& margin);
7331
extern std::string trace(const Position& pos);
7432

7533
}

src/search.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ namespace {
593593
// Never assume anything on values stored in TT
594594
if ( (ss->staticEval = eval = tte->eval_value()) == VALUE_NONE
595595
||(ss->evalMargin = tte->eval_margin()) == VALUE_NONE)
596-
eval = ss->staticEval = evaluate(pos, ss->evalMargin, &ss->ei);
596+
eval = ss->staticEval = evaluate(pos, ss->evalMargin);
597597

598598
// Can ttValue be used as a better position evaluation?
599599
if (ttValue != VALUE_NONE)
@@ -603,7 +603,7 @@ namespace {
603603
}
604604
else
605605
{
606-
eval = ss->staticEval = evaluate(pos, ss->evalMargin, &ss->ei);
606+
eval = ss->staticEval = evaluate(pos, ss->evalMargin);
607607
TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE,
608608
ss->staticEval, ss->evalMargin);
609609
}
@@ -1178,10 +1178,10 @@ namespace {
11781178
// Never assume anything on values stored in TT
11791179
if ( (ss->staticEval = bestValue = tte->eval_value()) == VALUE_NONE
11801180
||(ss->evalMargin = tte->eval_margin()) == VALUE_NONE)
1181-
ss->staticEval = bestValue = evaluate(pos, ss->evalMargin, &ss->ei);
1181+
ss->staticEval = bestValue = evaluate(pos, ss->evalMargin);
11821182
}
11831183
else
1184-
ss->staticEval = bestValue = evaluate(pos, ss->evalMargin, &ss->ei);
1184+
ss->staticEval = bestValue = evaluate(pos, ss->evalMargin);
11851185

11861186
// Stand pat. Return immediately if static value is at least beta
11871187
if (bestValue >= beta)

src/search.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <stack>
2626
#include <vector>
2727

28-
#include "evaluate.h"
2928
#include "misc.h"
3029
#include "position.h"
3130
#include "types.h"
@@ -49,7 +48,6 @@ struct Stack {
4948
Value evalMargin;
5049
int skipNullMove;
5150
int futilityMoveCount;
52-
Eval::Info ei;
5351
};
5452

5553

0 commit comments

Comments
 (0)