#include <cassert>
-#include "bitbase.h"
#include "bitcount.h"
#include "endgame.h"
/// init_bitbases() is called during program initialization, and simply loads
/// bitbases from disk into memory. At the moment, there is only the bitbase
/// for KP vs K, but we may decide to add other bitbases later.
+extern void generate_kpk_bitbase(uint8_t bitbase[]);
void init_bitbases() {
generate_kpk_bitbase(KPKBitbase);
template<>
Value EvaluationFunction<KXK>::apply(const Position& pos) const {
- assert(pos.non_pawn_material(weakerSide) == Value(0));
- assert(pos.piece_count(weakerSide, PAWN) == Value(0));
+ assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
+ assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
Square winnerKSq = pos.king_square(strongerSide);
Square loserKSq = pos.king_square(weakerSide);
template<>
Value EvaluationFunction<KBNK>::apply(const Position& pos) const {
- assert(pos.non_pawn_material(weakerSide) == Value(0));
- assert(pos.piece_count(weakerSide, PAWN) == Value(0));
+ assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
+ assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame + BishopValueMidgame);
assert(pos.piece_count(strongerSide, BISHOP) == 1);
assert(pos.piece_count(strongerSide, KNIGHT) == 1);
template<>
Value EvaluationFunction<KPK>::apply(const Position& pos) const {
- assert(pos.non_pawn_material(strongerSide) == Value(0));
- assert(pos.non_pawn_material(weakerSide) == Value(0));
+ assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
+ assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
assert(pos.piece_count(strongerSide, PAWN) == 1);
assert(pos.piece_count(weakerSide, PAWN) == 0);
result += Value(square_distance(bksq, nsq) * 32);
// Bonus for restricting the knight's mobility
- result += Value((8 - count_1s_max_15(pos.attacks_from<KNIGHT>(nsq))) * 8);
+ result += Value((8 - count_1s<CNT32_MAX15>(pos.attacks_from<KNIGHT>(nsq))) * 8);
return strongerSide == pos.side_to_move() ? result : -result;
}
/// king alone are always draw.
template<>
Value EvaluationFunction<KmmKm>::apply(const Position&) const {
- return Value(0);
+ return VALUE_DRAW;
}
template<>
Value EvaluationFunction<KNNK>::apply(const Position&) const {
- return Value(0);
+ return VALUE_DRAW;
}
/// KBPKScalingFunction scales endgames where the stronger side has king,
template<>
ScaleFactor ScalingFunction<KPsK>::apply(const Position& pos) const {
- assert(pos.non_pawn_material(strongerSide) == Value(0));
+ assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
assert(pos.piece_count(strongerSide, PAWN) >= 2);
- assert(pos.non_pawn_material(weakerSide) == Value(0));
+ assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
assert(pos.piece_count(weakerSide, PAWN) == 0);
Square ksq = pos.king_square(weakerSide);
assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame);
assert(pos.piece_count(strongerSide, KNIGHT) == 1);
assert(pos.piece_count(strongerSide, PAWN) == 1);
- assert(pos.non_pawn_material(weakerSide) == Value(0));
+ assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
assert(pos.piece_count(weakerSide, PAWN) == 0);
Square pawnSq = pos.piece_list(strongerSide, PAWN, 0);
template<>
ScaleFactor ScalingFunction<KPKP>::apply(const Position& pos) const {
- assert(pos.non_pawn_material(strongerSide) == Value(0));
- assert(pos.non_pawn_material(weakerSide) == Value(0));
+ assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
+ assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
assert(pos.piece_count(WHITE, PAWN) == 1);
assert(pos.piece_count(BLACK, PAWN) == 1);