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