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 Marco Costalba
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.
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.
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/>.
21 #if !defined(ENDGAME_H_INCLUDED)
22 #define ENDGAME_H_INCLUDED
37 /// Abstract base class for all special endgame evaluation functions
39 class EndgameEvaluationFunction {
41 EndgameEvaluationFunction(Color c);
42 virtual ~EndgameEvaluationFunction() { }
44 virtual Value apply(const Position &pos) = 0;
47 Color strongerSide, weakerSide;
51 /// Template subclass for various concrete endgames
54 KXK, // Generic "mate lone king" eval
62 KmmKm // K and two minors vs K and one or two minors
66 class EvaluationFunction : public EndgameEvaluationFunction {
68 explicit EvaluationFunction(Color c): EndgameEvaluationFunction(c) {}
69 Value apply(const Position& pos);
72 /// Abstract base class for all evaluation scaling functions:
74 class ScalingFunction {
76 ScalingFunction(Color c);
77 virtual ~ScalingFunction() { }
79 virtual ScaleFactor apply(const Position &pos) =0;
82 Color strongerSide, weakerSide;
86 /// Subclasses for various concrete endgames:
89 class KBPKScalingFunction : public ScalingFunction {
91 KBPKScalingFunction(Color c);
92 ScaleFactor apply(const Position &pos);
96 class KQKRPScalingFunction: public ScalingFunction {
98 KQKRPScalingFunction(Color c);
99 ScaleFactor apply(const Position &pos);
103 class KRPKRScalingFunction : public ScalingFunction {
105 KRPKRScalingFunction(Color c);
106 ScaleFactor apply(const Position &pos);
110 class KRPPKRPScalingFunction : public ScalingFunction {
112 KRPPKRPScalingFunction(Color c);
113 ScaleFactor apply(const Position &pos);
116 // King and pawns vs king:
117 class KPsKScalingFunction : public ScalingFunction {
119 KPsKScalingFunction(Color c);
120 ScaleFactor apply(const Position &pos);
124 class KBPKBScalingFunction : public ScalingFunction {
126 KBPKBScalingFunction(Color c);
127 ScaleFactor apply(const Position &pos);
131 class KBPKNScalingFunction : public ScalingFunction {
133 KBPKNScalingFunction(Color c);
134 ScaleFactor apply(const Position &pos);
138 class KNPKScalingFunction : public ScalingFunction {
140 KNPKScalingFunction(Color c);
141 ScaleFactor apply(const Position &pos);
145 class KPKPScalingFunction : public ScalingFunction {
147 KPKPScalingFunction(Color c);
148 ScaleFactor apply(const Position &pos);
153 //// Constants and variables
156 extern EvaluationFunction<KXK> EvaluateKXK, EvaluateKKX; // Generic "mate lone king" eval
157 extern EvaluationFunction<KBNK> EvaluateKBNK, EvaluateKKBN; // KBN vs K
158 extern EvaluationFunction<KPK> EvaluateKPK, EvaluateKKP; // KP vs K
159 extern EvaluationFunction<KRKP> EvaluateKRKP, EvaluateKPKR; // KR vs KP
160 extern EvaluationFunction<KRKB> EvaluateKRKB, EvaluateKBKR; // KR vs KB
161 extern EvaluationFunction<KRKN> EvaluateKRKN, EvaluateKNKR; // KR vs KN
162 extern EvaluationFunction<KQKR> EvaluateKQKR, EvaluateKRKQ; // KQ vs KR
163 extern EvaluationFunction<KBBKN> EvaluateKBBKN, EvaluateKNKBB; // KBB vs KN
164 extern EvaluationFunction<KmmKm> EvaluateKmmKm; // K and two minors vs K and one or two minors:
167 extern KBPKScalingFunction ScaleKBPK, ScaleKKBP;
170 extern KQKRPScalingFunction ScaleKQKRP, ScaleKRPKQ;
173 extern KRPKRScalingFunction ScaleKRPKR, ScaleKRKRP;
176 extern KRPPKRPScalingFunction ScaleKRPPKRP, ScaleKRPKRPP;
178 // King and pawns vs king:
179 extern KPsKScalingFunction ScaleKPsK, ScaleKKPs;
182 extern KBPKBScalingFunction ScaleKBPKB, ScaleKBKBP;
185 extern KBPKNScalingFunction ScaleKBPKN, ScaleKNKBP;
188 extern KNPKScalingFunction ScaleKNPK, ScaleKKNP;
191 extern KPKPScalingFunction ScaleKPKPw, ScaleKPKPb;
198 extern void init_bitbases();
201 #endif // !defined(ENDGAME_H_INCLUDED)