]> git.sesse.net Git - stockfish/blob - src/evaluate.h
Tidy up middle game specific evaluation
[stockfish] / src / evaluate.h
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
5   Glaurung is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9   
10   Glaurung is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14   
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20 #if !defined(EVALUATE_H_INCLUDED)
21 #define EVALUATE_H_INCLUDED
22
23 ////
24 //// Includes
25 ////
26
27 #include "material.h"
28 #include "pawns.h"
29 #include "position.h"
30
31
32 ////
33 //// Types
34 ////
35
36 /// The EvalInfo struct contains various information computed and collected
37 /// by the evaluation function.  An EvalInfo object is passed as one of the
38 /// arguments to the evaluation function, and the search can make use of its
39 /// contents to make intelligent search decisions.
40 ///
41 /// At the moment, this is not utilized very much:  The only part of the
42 /// EvalInfo object which is used by the search is futilityMargin.
43
44 struct EvalInfo {
45   
46   // Middle game and endgame evaluations:
47   Value mgValue, egValue;
48
49   // Pointers to material and pawn hash table entries:
50   MaterialInfo *mi;
51   PawnInfo *pi;
52
53   // attackedBy[color][piece type] is a bitboard representing all squares
54   // attacked by a given color and piece type.  attackedBy[color][0] contains
55   // all squares attacked by the given color.
56   Bitboard attackedBy[2][8];
57   Bitboard attacked_by(Color c) const { return attackedBy[c][0]; }
58   Bitboard attacked_by(Color c, PieceType pt) const { return attackedBy[c][pt]; }
59
60   // kingZone[color] is the zone around the enemy king which is considered
61   // by the king safety evaluation.  This consists of the squares directly
62   // adjacent to the king, and the three (or two, for a king on an edge file)
63   // squares two ranks in front of the king.  For instance, if black's king
64   // is on g8, kingZone[WHITE] is a bitboard containing the squares f8, h8,
65   // f7, g7, h7, f6, g6 and h6.
66   Bitboard kingZone[2];
67
68   // kingAttackersCount[color] is the number of pieces of the given color which
69   // attack a square adjacent to the enemy king.
70   int kingAttackersCount[2];
71
72   // kingAttackersWeight[color] is the sum of the "weight" of the pieces of the
73   // given color which attack a square adjacent to the enemy king.  The weights
74   // of the individual piece types are given by the variables QueenAttackWeight,
75   // RookAttackWeight, BishopAttackWeight and KnightAttackWeight in evaluate.cpp
76   int kingAttackersWeight[2];
77
78   // kingZoneAttacksCount[color] is the number of attacks to squares directly
79   // adjacent to the king of the given color.  Pieces which attack more
80   // than one square are counted multiple times.  For instance, if black's
81   // king is on g8 and there's a white knight on g5, this knight adds
82   // 2 to kingZoneAttacksCount[BLACK].
83   int kingZoneAttacksCount[2];
84
85   // mateThreat[color] is a move for the given side which gives a direct mate.
86   Move mateThreat[2];
87
88   // Middle game and endgame mobility scores.
89   Value mgMobility, egMobility;
90
91   // Extra futility margin.  This is added to the standard futility margin
92   // in the quiescence search.  
93   Value futilityMargin;
94 };
95
96
97 ////
98 //// Prototypes
99 ////
100
101 extern Value evaluate(const Position &pos, EvalInfo &ei, int threadID);
102 extern Value quick_evaluate(const Position &pos);
103 extern void init_eval(int threads);
104 extern void quit_eval();
105 extern void read_weights(Color sideToMove);
106
107
108 #endif // !defined(EVALUATE_H_INCLUDED)