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 /// Abstract base class for all evaluation scaling functions:
105 class ScalingFunction {
107 ScalingFunction(Color c);
108 virtual ~ScalingFunction() { }
110 virtual ScaleFactor apply(const Position &pos) =0;
113 Color strongerSide, weakerSide;
117 /// Subclasses for various concrete endgames:
120 class KBPKScalingFunction : public ScalingFunction {
122 KBPKScalingFunction(Color c);
123 ScaleFactor apply(const Position &pos);
127 class KQKRPScalingFunction: public ScalingFunction {
129 KQKRPScalingFunction(Color c);
130 ScaleFactor apply(const Position &pos);
134 class KRPKRScalingFunction : public ScalingFunction {
136 KRPKRScalingFunction(Color c);
137 ScaleFactor apply(const Position &pos);
141 class KRPPKRPScalingFunction : public ScalingFunction {
143 KRPPKRPScalingFunction(Color c);
144 ScaleFactor apply(const Position &pos);
147 // King and pawns vs king:
148 class KPsKScalingFunction : public ScalingFunction {
150 KPsKScalingFunction(Color c);
151 ScaleFactor apply(const Position &pos);
155 class KBPKBScalingFunction : public ScalingFunction {
157 KBPKBScalingFunction(Color c);
158 ScaleFactor apply(const Position &pos);
162 class KBPKNScalingFunction : public ScalingFunction {
164 KBPKNScalingFunction(Color c);
165 ScaleFactor apply(const Position &pos);
169 class KNPKScalingFunction : public ScalingFunction {
171 KNPKScalingFunction(Color c);
172 ScaleFactor apply(const Position &pos);
176 class KPKPScalingFunction : public ScalingFunction {
178 KPKPScalingFunction(Color c);
179 ScaleFactor apply(const Position &pos);
184 //// Constants and variables
187 // Generic "mate lone king" eval:
188 extern KXKEvaluationFunction EvaluateKXK, EvaluateKKX;
191 extern KBNKEvaluationFunction EvaluateKBNK, EvaluateKKBN;
194 extern KPKEvaluationFunction EvaluateKPK, EvaluateKKP;
197 extern KRKPEvaluationFunction EvaluateKRKP, EvaluateKPKR;
200 extern KRKBEvaluationFunction EvaluateKRKB, EvaluateKBKR;
203 extern KRKNEvaluationFunction EvaluateKRKN, EvaluateKNKR;
206 extern KQKREvaluationFunction EvaluateKQKR, EvaluateKRKQ;
209 extern KBPKScalingFunction ScaleKBPK, ScaleKKBP;
212 extern KQKRPScalingFunction ScaleKQKRP, ScaleKRPKQ;
215 extern KRPKRScalingFunction ScaleKRPKR, ScaleKRKRP;
218 extern KRPPKRPScalingFunction ScaleKRPPKRP, ScaleKRPKRPP;
220 // King and pawns vs king:
221 extern KPsKScalingFunction ScaleKPsK, ScaleKKPs;
224 extern KBPKBScalingFunction ScaleKBPKB, ScaleKBKBP;
227 extern KBPKNScalingFunction ScaleKBPKN, ScaleKNKBP;
230 extern KNPKScalingFunction ScaleKNPK, ScaleKKNP;
233 extern KPKPScalingFunction ScaleKPKPw, ScaleKPKPb;
240 extern void init_bitbases();
243 #endif // !defined(ENDGAME_H_INCLUDED)