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