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 /// Subclasses for various concrete endgames:
53 // Generic "mate lone king" eval:
54 class KXKEvaluationFunction : public EndgameEvaluationFunction {
56 KXKEvaluationFunction(Color c);
57 Value apply(const Position &pos);
61 class KBNKEvaluationFunction : public EndgameEvaluationFunction {
63 KBNKEvaluationFunction(Color c);
64 Value apply(const Position &pos);
68 class KPKEvaluationFunction : public EndgameEvaluationFunction {
70 KPKEvaluationFunction(Color c);
71 Value apply(const Position &pos);
75 class KRKPEvaluationFunction : public EndgameEvaluationFunction {
77 KRKPEvaluationFunction(Color c);
78 Value apply(const Position &pos);
82 class KRKBEvaluationFunction : public EndgameEvaluationFunction {
84 KRKBEvaluationFunction(Color c);
85 Value apply(const Position &pos);
89 class KRKNEvaluationFunction : public EndgameEvaluationFunction {
91 KRKNEvaluationFunction(Color c);
92 Value apply(const Position &pos);
96 class KQKREvaluationFunction : public EndgameEvaluationFunction {
98 KQKREvaluationFunction(Color c);
99 Value apply(const Position &pos);
103 class KBBKNEvaluationFunction : public EndgameEvaluationFunction {
105 KBBKNEvaluationFunction(Color C);
106 Value apply(const Position &pos);
109 // K and two minors vs K and one or two minors:
110 class KmmKmEvaluationFunction : public EndgameEvaluationFunction {
112 KmmKmEvaluationFunction(Color c);
113 Value apply(const Position &pos);
117 /// Abstract base class for all evaluation scaling functions:
119 class ScalingFunction {
121 ScalingFunction(Color c);
122 virtual ~ScalingFunction() { }
124 virtual ScaleFactor apply(const Position &pos) =0;
127 Color strongerSide, weakerSide;
131 /// Subclasses for various concrete endgames:
134 class KBPKScalingFunction : public ScalingFunction {
136 KBPKScalingFunction(Color c);
137 ScaleFactor apply(const Position &pos);
141 class KQKRPScalingFunction: public ScalingFunction {
143 KQKRPScalingFunction(Color c);
144 ScaleFactor apply(const Position &pos);
148 class KRPKRScalingFunction : public ScalingFunction {
150 KRPKRScalingFunction(Color c);
151 ScaleFactor apply(const Position &pos);
155 class KRPPKRPScalingFunction : public ScalingFunction {
157 KRPPKRPScalingFunction(Color c);
158 ScaleFactor apply(const Position &pos);
161 // King and pawns vs king:
162 class KPsKScalingFunction : public ScalingFunction {
164 KPsKScalingFunction(Color c);
165 ScaleFactor apply(const Position &pos);
169 class KBPKBScalingFunction : public ScalingFunction {
171 KBPKBScalingFunction(Color c);
172 ScaleFactor apply(const Position &pos);
176 class KBPKNScalingFunction : public ScalingFunction {
178 KBPKNScalingFunction(Color c);
179 ScaleFactor apply(const Position &pos);
183 class KNPKScalingFunction : public ScalingFunction {
185 KNPKScalingFunction(Color c);
186 ScaleFactor apply(const Position &pos);
190 class KPKPScalingFunction : public ScalingFunction {
192 KPKPScalingFunction(Color c);
193 ScaleFactor apply(const Position &pos);
198 //// Constants and variables
201 // Generic "mate lone king" eval:
202 extern KXKEvaluationFunction EvaluateKXK, EvaluateKKX;
205 extern KBNKEvaluationFunction EvaluateKBNK, EvaluateKKBN;
208 extern KPKEvaluationFunction EvaluateKPK, EvaluateKKP;
211 extern KRKPEvaluationFunction EvaluateKRKP, EvaluateKPKR;
214 extern KRKBEvaluationFunction EvaluateKRKB, EvaluateKBKR;
217 extern KRKNEvaluationFunction EvaluateKRKN, EvaluateKNKR;
220 extern KQKREvaluationFunction EvaluateKQKR, EvaluateKRKQ;
223 extern KBBKNEvaluationFunction EvaluateKBBKN, EvaluateKNKBB;
225 // K and two minors vs K and one or two minors:
226 extern KmmKmEvaluationFunction EvaluateKmmKm;
229 extern KBPKScalingFunction ScaleKBPK, ScaleKKBP;
232 extern KQKRPScalingFunction ScaleKQKRP, ScaleKRPKQ;
235 extern KRPKRScalingFunction ScaleKRPKR, ScaleKRKRP;
238 extern KRPPKRPScalingFunction ScaleKRPPKRP, ScaleKRPKRPP;
240 // King and pawns vs king:
241 extern KPsKScalingFunction ScaleKPsK, ScaleKKPs;
244 extern KBPKBScalingFunction ScaleKBPKB, ScaleKBKBP;
247 extern KBPKNScalingFunction ScaleKBPKN, ScaleKNKBP;
250 extern KNPKScalingFunction ScaleKNPK, ScaleKKNP;
253 extern KPKPScalingFunction ScaleKPKPw, ScaleKPKPb;
260 extern void init_bitbases();
263 #endif // !defined(ENDGAME_H_INCLUDED)