2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2023 The Stockfish developers (see AUTHORS file)
5 Stockfish 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.
10 Stockfish 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.
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/>.
19 #ifndef MATERIAL_H_INCLUDED
20 #define MATERIAL_H_INCLUDED
27 namespace Stockfish::Material {
29 /// Material::Entry contains various information about a material configuration.
30 /// It contains a material imbalance evaluation, a function pointer to a special
31 /// endgame evaluation function (which in most cases is nullptr, meaning that the
32 /// standard evaluation function will be used), and scale factors.
34 /// The scale factors are used to scale the evaluation score up or down. For
35 /// instance, in KRB vs KR endgames, the score is scaled down by a factor of 4,
36 /// which will result in scores of absolute value less than one pawn.
40 Score imbalance() const { return score; }
41 Phase game_phase() const { return (Phase)gamePhase; }
42 bool specialized_eval_exists() const { return evaluationFunction != nullptr; }
43 Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
45 // scale_factor() takes a position and a color as input and returns a scale factor
46 // for the given color. We have to provide the position in addition to the color
47 // because the scale factor may also be a function which should be applied to
48 // the position. For instance, in KBP vs K endgames, the scaling function looks
49 // for rook pawns and wrong-colored bishops.
50 ScaleFactor scale_factor(const Position& pos, Color c) const {
51 ScaleFactor sf = scalingFunction[c] ? (*scalingFunction[c])(pos)
53 return sf != SCALE_FACTOR_NONE ? sf : ScaleFactor(factor[c]);
57 const EndgameBase<Value>* evaluationFunction;
58 const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
59 // side (e.g. KPKP, KBPsK)
62 uint8_t factor[COLOR_NB];
65 typedef HashTable<Entry, 8192> Table;
67 Entry* probe(const Position& pos);
69 } // namespace Stockfish::Material
71 #endif // #ifndef MATERIAL_H_INCLUDED