it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Glaurung is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Glaurung is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/// precomputes material hash keys for a few basic endgames, in order
/// to make it easy to recognize such endgames when they occur.
/// precomputes material hash keys for a few basic endgames, in order
/// to make it easy to recognize such endgames when they occur.
/// MaterialInfoTable::get_material_info() takes a position object as input,
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
/// If the material configuration is not already present in the table, it
/// MaterialInfoTable::get_material_info() takes a position object as input,
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
/// If the material configuration is not already present in the table, it
/// same material configuration occurs again.
MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) {
/// same material configuration occurs again.
MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) {
// have analysed this material configuration before, and we can simply
// return the information we found the last time instead of recomputing it:
if(mi->key == key)
// have analysed this material configuration before, and we can simply
// return the information we found the last time instead of recomputing it:
if(mi->key == key)
pos.non_pawn_material(WHITE) >= RookValueEndgame) {
mi->evaluationFunction = &EvaluateKXK;
return mi;
}
else if(pos.non_pawn_material(WHITE) == Value(0) &&
pos.non_pawn_material(WHITE) >= RookValueEndgame) {
mi->evaluationFunction = &EvaluateKXK;
return mi;
}
else if(pos.non_pawn_material(WHITE) == Value(0) &&
- pos.queen_count(WHITE) == 1 &&
- pos.rook_count(BLACK) == 1 && pos.pawn_count(BLACK) >= 1)
+ pos.piece_count(WHITE, QUEEN) == 1 &&
+ pos.piece_count(BLACK, ROOK) == 1 && pos.piece_count(BLACK, PAWN) >= 1)
- pos.queen_count(BLACK) == 1 &&
- pos.rook_count(WHITE) == 1 && pos.pawn_count(WHITE) >= 1)
+ pos.piece_count(BLACK, QUEEN) == 1 &&
+ pos.piece_count(WHITE, ROOK) == 1 && pos.piece_count(WHITE, PAWN) >= 1)
mi->scalingFunction[BLACK] = &ScaleKRPKQ;
if(pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0)) {
mi->scalingFunction[BLACK] = &ScaleKRPKQ;
if(pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0)) {
- if(pos.pawn_count(BLACK) == 0) {
- assert(pos.pawn_count(WHITE) >= 2);
+ if(pos.piece_count(BLACK, PAWN) == 0) {
+ assert(pos.piece_count(WHITE, PAWN) >= 2);
- else if(pos.pawn_count(WHITE) == 0) {
- assert(pos.pawn_count(BLACK) >= 2);
+ else if(pos.piece_count(WHITE, PAWN) == 0) {
+ assert(pos.piece_count(BLACK, PAWN) >= 2);
mi->scalingFunction[WHITE] = &ScaleKPKPw;
mi->scalingFunction[BLACK] = &ScaleKPKPb;
}
}
// Evaluate the material balance.
mi->scalingFunction[WHITE] = &ScaleKPKPw;
mi->scalingFunction[BLACK] = &ScaleKPKPb;
}
}
// Evaluate the material balance.
for(c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign) {
// No pawns makes it difficult to win, even with a material advantage:
for(c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign) {
// No pawns makes it difficult to win, even with a material advantage:
pos.non_pawn_material(c) - pos.non_pawn_material(opposite_color(c))
<= BishopValueMidgame) {
if(pos.non_pawn_material(c) == pos.non_pawn_material(opposite_color(c)))
pos.non_pawn_material(c) - pos.non_pawn_material(opposite_color(c))
<= BishopValueMidgame) {
if(pos.non_pawn_material(c) == pos.non_pawn_material(opposite_color(c)))
- mgValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16);
- egValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16);
+ mgValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
+ egValue += sign * Value(pos.piece_count(c, KNIGHT)*(pos.piece_count(c, PAWN)-5)*16);
- if(pos.rook_count(c) >= 1) {
- Value v = Value((pos.rook_count(c) - 1) * 32 + pos.queen_count(c) * 16);
+ if(pos.piece_count(c, ROOK) >= 1) {
+ Value v = Value((pos.piece_count(c, ROOK) - 1) * 32 + pos.piece_count(c, QUEEN) * 16);