]> git.sesse.net Git - stockfish/blob - src/endgame.h
Preserve options order when printed
[stockfish] / src / endgame.h
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
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.
9   
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.
14   
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/>.
17 */
18
19
20 #if !defined(ENDGAME_H_INCLUDED)
21 #define ENDGAME_H_INCLUDED
22
23 ////
24 //// Includes
25 ////
26
27 #include "position.h"
28 #include "scale.h"
29 #include "value.h"
30
31
32 ////
33 //// Types
34 ////
35
36 /// Abstract base class for all special endgame evaluation functions:
37
38 class EndgameEvaluationFunction {
39 public:
40   EndgameEvaluationFunction(Color c);
41   virtual ~EndgameEvaluationFunction() { }
42
43   virtual Value apply(const Position &pos) =0;
44
45 protected:
46   Color strongerSide, weakerSide;
47 };
48
49
50 /// Subclasses for various concrete endgames:
51
52 // Generic "mate lone king" eval:
53 class KXKEvaluationFunction : public EndgameEvaluationFunction {
54 public:
55   KXKEvaluationFunction(Color c);
56   Value apply(const Position &pos);
57 };
58
59 // KBN vs K:
60 class KBNKEvaluationFunction : public EndgameEvaluationFunction {
61 public:
62   KBNKEvaluationFunction(Color c);
63   Value apply(const Position &pos);
64 };
65
66 // KP vs K:
67 class KPKEvaluationFunction : public EndgameEvaluationFunction {
68 public:
69   KPKEvaluationFunction(Color c);
70   Value apply(const Position &pos);
71 };
72
73 // KR vs KP:
74 class KRKPEvaluationFunction : public EndgameEvaluationFunction {
75 public:
76   KRKPEvaluationFunction(Color c);
77   Value apply(const Position &pos);
78 };
79
80 // KR vs KB:
81 class KRKBEvaluationFunction : public EndgameEvaluationFunction {
82 public:
83   KRKBEvaluationFunction(Color c);
84   Value apply(const Position &pos);
85 };
86
87 // KR vs KN:
88 class KRKNEvaluationFunction : public EndgameEvaluationFunction {
89 public:
90   KRKNEvaluationFunction(Color c);
91   Value apply(const Position &pos);
92 };
93
94 // KQ vs KR:
95 class KQKREvaluationFunction : public EndgameEvaluationFunction {
96 public:
97   KQKREvaluationFunction(Color c);
98   Value apply(const Position &pos);
99 };
100
101
102 /// Abstract base class for all evaluation scaling functions:
103
104 class ScalingFunction {
105 public:
106   ScalingFunction(Color c);
107   virtual ~ScalingFunction() { }
108
109   virtual ScaleFactor apply(const Position &pos) =0;
110
111 protected:
112   Color strongerSide, weakerSide;
113 };
114
115
116 /// Subclasses for various concrete endgames:
117
118 // KBP vs K:
119 class KBPKScalingFunction : public ScalingFunction {
120 public:
121   KBPKScalingFunction(Color c);
122   ScaleFactor apply(const Position &pos);
123 };
124
125 // KQ vs KRP:
126 class KQKRPScalingFunction: public ScalingFunction {
127 public:
128   KQKRPScalingFunction(Color c);
129   ScaleFactor apply(const Position &pos);
130 };
131
132 // KRP vs KR:
133 class KRPKRScalingFunction : public ScalingFunction {
134 public:
135   KRPKRScalingFunction(Color c);
136   ScaleFactor apply(const Position &pos);
137 };
138
139 // KRPP vs KRP:
140 class KRPPKRPScalingFunction : public ScalingFunction {
141 public:
142   KRPPKRPScalingFunction(Color c);
143   ScaleFactor apply(const Position &pos);
144 };
145
146 // King and pawns vs king:
147 class KPsKScalingFunction : public ScalingFunction {
148 public:
149   KPsKScalingFunction(Color c);
150   ScaleFactor apply(const Position &pos);
151 };
152
153 // KBP vs KB:
154 class KBPKBScalingFunction : public ScalingFunction {
155 public:
156   KBPKBScalingFunction(Color c);
157   ScaleFactor apply(const Position &pos);
158 };
159
160 // KBP vs KN:
161 class KBPKNScalingFunction : public ScalingFunction {
162 public:
163   KBPKNScalingFunction(Color c);
164   ScaleFactor apply(const Position &pos);
165 };
166
167 // KNP vs K:
168 class KNPKScalingFunction : public ScalingFunction {
169 public:
170   KNPKScalingFunction(Color c);
171   ScaleFactor apply(const Position &pos);
172 };
173
174 // KP vs KP:
175 class KPKPScalingFunction : public ScalingFunction {
176 public:
177   KPKPScalingFunction(Color c);
178   ScaleFactor apply(const Position &pos);
179 };
180
181
182 ////
183 //// Constants and variables
184 ////
185
186 // Generic "mate lone king" eval:
187 extern KXKEvaluationFunction EvaluateKXK, EvaluateKKX;
188
189 // KBN vs K:
190 extern KBNKEvaluationFunction EvaluateKBNK, EvaluateKKBN;
191
192 // KP vs K:
193 extern KPKEvaluationFunction EvaluateKPK, EvaluateKKP;
194
195 // KR vs KP:
196 extern KRKPEvaluationFunction EvaluateKRKP, EvaluateKPKR;
197
198 // KR vs KB:
199 extern KRKBEvaluationFunction EvaluateKRKB, EvaluateKBKR;
200
201 // KR vs KN:
202 extern KRKNEvaluationFunction EvaluateKRKN, EvaluateKNKR;
203
204 // KQ vs KR:
205 extern KQKREvaluationFunction EvaluateKQKR, EvaluateKRKQ;
206
207 // KBP vs K:
208 extern KBPKScalingFunction ScaleKBPK, ScaleKKBP;
209
210 // KQ vs KRP:
211 extern KQKRPScalingFunction ScaleKQKRP, ScaleKRPKQ;
212
213 // KRP vs KR:
214 extern KRPKRScalingFunction ScaleKRPKR, ScaleKRKRP;
215
216 // KRPP vs KRP:
217 extern KRPPKRPScalingFunction ScaleKRPPKRP, ScaleKRPKRPP;
218
219 // King and pawns vs king:
220 extern KPsKScalingFunction ScaleKPsK, ScaleKKPs;
221
222 // KBP vs KB:
223 extern KBPKBScalingFunction ScaleKBPKB, ScaleKBKBP;
224
225 // KBP vs KN:
226 extern KBPKNScalingFunction ScaleKBPKN, ScaleKNKBP;
227
228 // KNP vs K:
229 extern KNPKScalingFunction ScaleKNPK, ScaleKKNP;
230
231 // KP vs KP:
232 extern KPKPScalingFunction ScaleKPKPw, ScaleKPKPb;
233
234
235 ////
236 //// Prototypes
237 ////
238
239 extern void init_bitbases();
240
241
242 #endif // !defined(ENDGAME_H_INCLUDED)