Rev 154 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
96 | pmbaty | 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-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
||
5 | Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad |
||
6 | |||
7 | Stockfish is free software: you can redistribute it and/or modify |
||
8 | it under the terms of the GNU General Public License as published by |
||
9 | the Free Software Foundation, either version 3 of the License, or |
||
10 | (at your option) any later version. |
||
11 | |||
12 | Stockfish is distributed in the hope that it will be useful, |
||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | GNU General Public License for more details. |
||
16 | |||
17 | You should have received a copy of the GNU General Public License |
||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
19 | */ |
||
20 | |||
21 | #ifndef MATERIAL_H_INCLUDED |
||
22 | #define MATERIAL_H_INCLUDED |
||
23 | |||
24 | #include "endgame.h" |
||
25 | #include "misc.h" |
||
26 | #include "position.h" |
||
27 | #include "types.h" |
||
28 | |||
29 | namespace Material { |
||
30 | |||
31 | /// Material::Entry contains various information about a material configuration. |
||
32 | /// It contains a material imbalance evaluation, a function pointer to a special |
||
33 | /// endgame evaluation function (which in most cases is NULL, meaning that the |
||
34 | /// standard evaluation function will be used), and scale factors. |
||
35 | /// |
||
36 | /// The scale factors are used to scale the evaluation score up or down. For |
||
37 | /// instance, in KRB vs KR endgames, the score is scaled down by a factor of 4, |
||
38 | /// which will result in scores of absolute value less than one pawn. |
||
39 | |||
40 | struct Entry { |
||
41 | |||
42 | Score imbalance() const { return make_score(value, value); } |
||
43 | Phase game_phase() const { return gamePhase; } |
||
44 | bool specialized_eval_exists() const { return evaluationFunction != nullptr; } |
||
45 | Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); } |
||
46 | |||
47 | // scale_factor takes a position and a color as input and returns a scale factor |
||
48 | // for the given color. We have to provide the position in addition to the color |
||
49 | // because the scale factor may also be a function which should be applied to |
||
50 | // the position. For instance, in KBP vs K endgames, the scaling function looks |
||
51 | // for rook pawns and wrong-colored bishops. |
||
52 | ScaleFactor scale_factor(const Position& pos, Color c) const { |
||
53 | return !scalingFunction[c] |
||
54 | || (*scalingFunction[c])(pos) == SCALE_FACTOR_NONE ? ScaleFactor(factor[c]) |
||
55 | : (*scalingFunction[c])(pos); |
||
56 | } |
||
57 | |||
58 | Key key; |
||
59 | int16_t value; |
||
60 | uint8_t factor[COLOR_NB]; |
||
61 | EndgameBase<Value>* evaluationFunction; |
||
62 | EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each |
||
63 | // side (e.g. KPKP, KBPsKs) |
||
64 | Phase gamePhase; |
||
65 | }; |
||
66 | |||
67 | typedef HashTable<Entry, 8192> Table; |
||
68 | |||
69 | Entry* probe(const Position& pos); |
||
70 | |||
71 | } // namespace Material |
||
72 | |||
73 | #endif // #ifndef MATERIAL_H_INCLUDED |