]> git.sesse.net Git - stockfish/blob - src/endgame.h
Partially space inflate search.cpp
[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
103 /// Abstract base class for all evaluation scaling functions:
104
105 class ScalingFunction {
106 public:
107   ScalingFunction(Color c);
108   virtual ~ScalingFunction() { }
109
110   virtual ScaleFactor apply(const Position &pos) =0;
111
112 protected:
113   Color strongerSide, weakerSide;
114 };
115
116
117 /// Subclasses for various concrete endgames:
118
119 // KBP vs K:
120 class KBPKScalingFunction : public ScalingFunction {
121 public:
122   KBPKScalingFunction(Color c);
123   ScaleFactor apply(const Position &pos);
124 };
125
126 // KQ vs KRP:
127 class KQKRPScalingFunction: public ScalingFunction {
128 public:
129   KQKRPScalingFunction(Color c);
130   ScaleFactor apply(const Position &pos);
131 };
132
133 // KRP vs KR:
134 class KRPKRScalingFunction : public ScalingFunction {
135 public:
136   KRPKRScalingFunction(Color c);
137   ScaleFactor apply(const Position &pos);
138 };
139
140 // KRPP vs KRP:
141 class KRPPKRPScalingFunction : public ScalingFunction {
142 public:
143   KRPPKRPScalingFunction(Color c);
144   ScaleFactor apply(const Position &pos);
145 };
146
147 // King and pawns vs king:
148 class KPsKScalingFunction : public ScalingFunction {
149 public:
150   KPsKScalingFunction(Color c);
151   ScaleFactor apply(const Position &pos);
152 };
153
154 // KBP vs KB:
155 class KBPKBScalingFunction : public ScalingFunction {
156 public:
157   KBPKBScalingFunction(Color c);
158   ScaleFactor apply(const Position &pos);
159 };
160
161 // KBP vs KN:
162 class KBPKNScalingFunction : public ScalingFunction {
163 public:
164   KBPKNScalingFunction(Color c);
165   ScaleFactor apply(const Position &pos);
166 };
167
168 // KNP vs K:
169 class KNPKScalingFunction : public ScalingFunction {
170 public:
171   KNPKScalingFunction(Color c);
172   ScaleFactor apply(const Position &pos);
173 };
174
175 // KP vs KP:
176 class KPKPScalingFunction : public ScalingFunction {
177 public:
178   KPKPScalingFunction(Color c);
179   ScaleFactor apply(const Position &pos);
180 };
181
182
183 ////
184 //// Constants and variables
185 ////
186
187 // Generic "mate lone king" eval:
188 extern KXKEvaluationFunction EvaluateKXK, EvaluateKKX;
189
190 // KBN vs K:
191 extern KBNKEvaluationFunction EvaluateKBNK, EvaluateKKBN;
192
193 // KP vs K:
194 extern KPKEvaluationFunction EvaluateKPK, EvaluateKKP;
195
196 // KR vs KP:
197 extern KRKPEvaluationFunction EvaluateKRKP, EvaluateKPKR;
198
199 // KR vs KB:
200 extern KRKBEvaluationFunction EvaluateKRKB, EvaluateKBKR;
201
202 // KR vs KN:
203 extern KRKNEvaluationFunction EvaluateKRKN, EvaluateKNKR;
204
205 // KQ vs KR:
206 extern KQKREvaluationFunction EvaluateKQKR, EvaluateKRKQ;
207
208 // KBP vs K:
209 extern KBPKScalingFunction ScaleKBPK, ScaleKKBP;
210
211 // KQ vs KRP:
212 extern KQKRPScalingFunction ScaleKQKRP, ScaleKRPKQ;
213
214 // KRP vs KR:
215 extern KRPKRScalingFunction ScaleKRPKR, ScaleKRKRP;
216
217 // KRPP vs KRP:
218 extern KRPPKRPScalingFunction ScaleKRPPKRP, ScaleKRPKRPP;
219
220 // King and pawns vs king:
221 extern KPsKScalingFunction ScaleKPsK, ScaleKKPs;
222
223 // KBP vs KB:
224 extern KBPKBScalingFunction ScaleKBPKB, ScaleKBKBP;
225
226 // KBP vs KN:
227 extern KBPKNScalingFunction ScaleKBPKN, ScaleKNKBP;
228
229 // KNP vs K:
230 extern KNPKScalingFunction ScaleKNPK, ScaleKKNP;
231
232 // KP vs KP:
233 extern KPKPScalingFunction ScaleKPKPw, ScaleKPKPb;
234
235
236 ////
237 //// Prototypes
238 ////
239
240 extern void init_bitbases();
241
242
243 #endif // !defined(ENDGAME_H_INCLUDED)