Document where we want a uint16_t instead of a uint64_t
[glaurung_clone.git] / src / endgame.h
blobae3526fedaeae8777416c5fa7263ced01c7a618f
1 /*
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
23 ////
24 //// Includes
25 ////
27 #include "position.h"
28 #include "scale.h"
29 #include "value.h"
32 ////
33 //// Types
34 ////
36 /// Abstract base class for all special endgame evaluation functions:
38 class EndgameEvaluationFunction {
39 public:
40 EndgameEvaluationFunction(Color c);
41 virtual ~EndgameEvaluationFunction() { }
43 virtual Value apply(const Position &pos) =0;
45 protected:
46 Color strongerSide, weakerSide;
50 /// Subclasses for various concrete endgames:
52 // Generic "mate lone king" eval:
53 class KXKEvaluationFunction : public EndgameEvaluationFunction {
54 public:
55 KXKEvaluationFunction(Color c);
56 Value apply(const Position &pos);
59 // KBN vs K:
60 class KBNKEvaluationFunction : public EndgameEvaluationFunction {
61 public:
62 KBNKEvaluationFunction(Color c);
63 Value apply(const Position &pos);
66 // KP vs K:
67 class KPKEvaluationFunction : public EndgameEvaluationFunction {
68 public:
69 KPKEvaluationFunction(Color c);
70 Value apply(const Position &pos);
73 // KR vs KP:
74 class KRKPEvaluationFunction : public EndgameEvaluationFunction {
75 public:
76 KRKPEvaluationFunction(Color c);
77 Value apply(const Position &pos);
80 // KR vs KB:
81 class KRKBEvaluationFunction : public EndgameEvaluationFunction {
82 public:
83 KRKBEvaluationFunction(Color c);
84 Value apply(const Position &pos);
87 // KR vs KN:
88 class KRKNEvaluationFunction : public EndgameEvaluationFunction {
89 public:
90 KRKNEvaluationFunction(Color c);
91 Value apply(const Position &pos);
94 // KQ vs KR:
95 class KQKREvaluationFunction : public EndgameEvaluationFunction {
96 public:
97 KQKREvaluationFunction(Color c);
98 Value apply(const Position &pos);
102 /// Abstract base class for all evaluation scaling functions:
104 class ScalingFunction {
105 public:
106 ScalingFunction(Color c);
107 virtual ~ScalingFunction() { }
109 virtual ScaleFactor apply(const Position &pos) =0;
111 protected:
112 Color strongerSide, weakerSide;
116 /// Subclasses for various concrete endgames:
118 // KBP vs K:
119 class KBPKScalingFunction : public ScalingFunction {
120 public:
121 KBPKScalingFunction(Color c);
122 ScaleFactor apply(const Position &pos);
125 // KQ vs KRP:
126 class KQKRPScalingFunction: public ScalingFunction {
127 public:
128 KQKRPScalingFunction(Color c);
129 ScaleFactor apply(const Position &pos);
132 // KRP vs KR:
133 class KRPKRScalingFunction : public ScalingFunction {
134 public:
135 KRPKRScalingFunction(Color c);
136 ScaleFactor apply(const Position &pos);
139 // KRPP vs KRP:
140 class KRPPKRPScalingFunction : public ScalingFunction {
141 public:
142 KRPPKRPScalingFunction(Color c);
143 ScaleFactor apply(const Position &pos);
146 // King and pawns vs king:
147 class KPsKScalingFunction : public ScalingFunction {
148 public:
149 KPsKScalingFunction(Color c);
150 ScaleFactor apply(const Position &pos);
153 // KBP vs KB:
154 class KBPKBScalingFunction : public ScalingFunction {
155 public:
156 KBPKBScalingFunction(Color c);
157 ScaleFactor apply(const Position &pos);
160 // KBP vs KN:
161 class KBPKNScalingFunction : public ScalingFunction {
162 public:
163 KBPKNScalingFunction(Color c);
164 ScaleFactor apply(const Position &pos);
167 // KNP vs K:
168 class KNPKScalingFunction : public ScalingFunction {
169 public:
170 KNPKScalingFunction(Color c);
171 ScaleFactor apply(const Position &pos);
174 // KP vs KP:
175 class KPKPScalingFunction : public ScalingFunction {
176 public:
177 KPKPScalingFunction(Color c);
178 ScaleFactor apply(const Position &pos);
182 ////
183 //// Constants and variables
184 ////
186 // Generic "mate lone king" eval:
187 extern KXKEvaluationFunction EvaluateKXK, EvaluateKKX;
189 // KBN vs K:
190 extern KBNKEvaluationFunction EvaluateKBNK, EvaluateKKBN;
192 // KP vs K:
193 extern KPKEvaluationFunction EvaluateKPK, EvaluateKKP;
195 // KR vs KP:
196 extern KRKPEvaluationFunction EvaluateKRKP, EvaluateKPKR;
198 // KR vs KB:
199 extern KRKBEvaluationFunction EvaluateKRKB, EvaluateKBKR;
201 // KR vs KN:
202 extern KRKNEvaluationFunction EvaluateKRKN, EvaluateKNKR;
204 // KQ vs KR:
205 extern KQKREvaluationFunction EvaluateKQKR, EvaluateKRKQ;
207 // KBP vs K:
208 extern KBPKScalingFunction ScaleKBPK, ScaleKKBP;
210 // KQ vs KRP:
211 extern KQKRPScalingFunction ScaleKQKRP, ScaleKRPKQ;
213 // KRP vs KR:
214 extern KRPKRScalingFunction ScaleKRPKR, ScaleKRKRP;
216 // KRPP vs KRP:
217 extern KRPPKRPScalingFunction ScaleKRPPKRP, ScaleKRPKRPP;
219 // King and pawns vs king:
220 extern KPsKScalingFunction ScaleKPsK, ScaleKKPs;
222 // KBP vs KB:
223 extern KBPKBScalingFunction ScaleKBPKB, ScaleKBKBP;
225 // KBP vs KN:
226 extern KBPKNScalingFunction ScaleKBPKN, ScaleKNKBP;
228 // KNP vs K:
229 extern KNPKScalingFunction ScaleKNPK, ScaleKKNP;
231 // KP vs KP:
232 extern KPKPScalingFunction ScaleKPKPw, ScaleKPKPb;
235 ////
236 //// Prototypes
237 ////
239 extern void init_bitbases();
242 #endif // !defined(ENDGAME_H_INCLUDED)