2 Glaurung, a UCI chess playing engine.
3 Copyright (C) 2004-2008 Tord Romstad
5 Glaurung 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 Glaurung 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/>.
20 #if !defined(ENDGAME_H_INCLUDED)
21 #define ENDGAME_H_INCLUDED
36 /// Abstract base class for all special endgame evaluation functions:
38 class EndgameEvaluationFunction {
40 EndgameEvaluationFunction(Color c);
41 virtual ~EndgameEvaluationFunction() { }
43 virtual Value apply(const Position &pos) =0;
46 Color strongerSide, weakerSide;
50 /// Subclasses for various concrete endgames:
52 // Generic "mate lone king" eval:
53 class KXKEvaluationFunction : public EndgameEvaluationFunction {
55 KXKEvaluationFunction(Color c);
56 Value apply(const Position &pos);
60 class KBNKEvaluationFunction : public EndgameEvaluationFunction {
62 KBNKEvaluationFunction(Color c);
63 Value apply(const Position &pos);
67 class KPKEvaluationFunction : public EndgameEvaluationFunction {
69 KPKEvaluationFunction(Color c);
70 Value apply(const Position &pos);
74 class KRKPEvaluationFunction : public EndgameEvaluationFunction {
76 KRKPEvaluationFunction(Color c);
77 Value apply(const Position &pos);
81 class KRKBEvaluationFunction : public EndgameEvaluationFunction {
83 KRKBEvaluationFunction(Color c);
84 Value apply(const Position &pos);
88 class KRKNEvaluationFunction : public EndgameEvaluationFunction {
90 KRKNEvaluationFunction(Color c);
91 Value apply(const Position &pos);
95 class KQKREvaluationFunction : public EndgameEvaluationFunction {
97 KQKREvaluationFunction(Color c);
98 Value apply(const Position &pos);
102 /// Abstract base class for all evaluation scaling functions:
104 class ScalingFunction {
106 ScalingFunction(Color c);
107 virtual ~ScalingFunction() { }
109 virtual ScaleFactor apply(const Position &pos) =0;
112 Color strongerSide, weakerSide;
116 /// Subclasses for various concrete endgames:
119 class KBPKScalingFunction : public ScalingFunction {
121 KBPKScalingFunction(Color c);
122 ScaleFactor apply(const Position &pos);
126 class KQKRPScalingFunction: public ScalingFunction {
128 KQKRPScalingFunction(Color c);
129 ScaleFactor apply(const Position &pos);
133 class KRPKRScalingFunction : public ScalingFunction {
135 KRPKRScalingFunction(Color c);
136 ScaleFactor apply(const Position &pos);
140 class KRPPKRPScalingFunction : public ScalingFunction {
142 KRPPKRPScalingFunction(Color c);
143 ScaleFactor apply(const Position &pos);
146 // King and pawns vs king:
147 class KPsKScalingFunction : public ScalingFunction {
149 KPsKScalingFunction(Color c);
150 ScaleFactor apply(const Position &pos);
154 class KBPKBScalingFunction : public ScalingFunction {
156 KBPKBScalingFunction(Color c);
157 ScaleFactor apply(const Position &pos);
161 class KBPKNScalingFunction : public ScalingFunction {
163 KBPKNScalingFunction(Color c);
164 ScaleFactor apply(const Position &pos);
168 class KNPKScalingFunction : public ScalingFunction {
170 KNPKScalingFunction(Color c);
171 ScaleFactor apply(const Position &pos);
175 class KPKPScalingFunction : public ScalingFunction {
177 KPKPScalingFunction(Color c);
178 ScaleFactor apply(const Position &pos);
183 //// Constants and variables
186 // Generic "mate lone king" eval:
187 extern KXKEvaluationFunction EvaluateKXK, EvaluateKKX;
190 extern KBNKEvaluationFunction EvaluateKBNK, EvaluateKKBN;
193 extern KPKEvaluationFunction EvaluateKPK, EvaluateKKP;
196 extern KRKPEvaluationFunction EvaluateKRKP, EvaluateKPKR;
199 extern KRKBEvaluationFunction EvaluateKRKB, EvaluateKBKR;
202 extern KRKNEvaluationFunction EvaluateKRKN, EvaluateKNKR;
205 extern KQKREvaluationFunction EvaluateKQKR, EvaluateKRKQ;
208 extern KBPKScalingFunction ScaleKBPK, ScaleKKBP;
211 extern KQKRPScalingFunction ScaleKQKRP, ScaleKRPKQ;
214 extern KRPKRScalingFunction ScaleKRPKR, ScaleKRKRP;
217 extern KRPPKRPScalingFunction ScaleKRPPKRP, ScaleKRPKRPP;
219 // King and pawns vs king:
220 extern KPsKScalingFunction ScaleKPsK, ScaleKKPs;
223 extern KBPKBScalingFunction ScaleKBPKB, ScaleKBKBP;
226 extern KBPKNScalingFunction ScaleKBPKN, ScaleKNKBP;
229 extern KNPKScalingFunction ScaleKNPK, ScaleKKNP;
232 extern KPKPScalingFunction ScaleKPKPw, ScaleKPKPb;
239 extern void init_bitbases();
242 #endif // !defined(ENDGAME_H_INCLUDED)