1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-03 01:59:36 +00:00

Reformat piece values arrays

And rename stuff while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-08-20 18:41:28 +01:00
parent 7c8b7222f5
commit b84af67f4c
8 changed files with 91 additions and 109 deletions

View file

@ -141,7 +141,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
Square loserKSq = pos.king_square(weakerSide); Square loserKSq = pos.king_square(weakerSide);
Value result = pos.non_pawn_material(strongerSide) Value result = pos.non_pawn_material(strongerSide)
+ pos.piece_count(strongerSide, PAWN) * PawnValueEndgame + pos.piece_count(strongerSide, PAWN) * PawnValueEg
+ MateTable[loserKSq] + MateTable[loserKSq]
+ DistanceBonus[square_distance(winnerKSq, loserKSq)]; + DistanceBonus[square_distance(winnerKSq, loserKSq)];
@ -162,7 +162,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO); assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO); assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame + BishopValueMidgame); assert(pos.non_pawn_material(strongerSide) == KnightValueMg + BishopValueMg);
assert(pos.piece_count(strongerSide, BISHOP) == 1); assert(pos.piece_count(strongerSide, BISHOP) == 1);
assert(pos.piece_count(strongerSide, KNIGHT) == 1); assert(pos.piece_count(strongerSide, KNIGHT) == 1);
assert(pos.piece_count(strongerSide, PAWN) == 0); assert(pos.piece_count(strongerSide, PAWN) == 0);
@ -225,9 +225,7 @@ Value Endgame<KPK>::operator()(const Position& pos) const {
if (!Bitbases::probe_kpk(wksq, wpsq, bksq, stm)) if (!Bitbases::probe_kpk(wksq, wpsq, bksq, stm))
return VALUE_DRAW; return VALUE_DRAW;
Value result = VALUE_KNOWN_WIN Value result = VALUE_KNOWN_WIN + PawnValueEg + Value(rank_of(wpsq));
+ PawnValueEndgame
+ Value(rank_of(wpsq));
return strongerSide == pos.side_to_move() ? result : -result; return strongerSide == pos.side_to_move() ? result : -result;
} }
@ -240,7 +238,7 @@ Value Endgame<KPK>::operator()(const Position& pos) const {
template<> template<>
Value Endgame<KRKP>::operator()(const Position& pos) const { Value Endgame<KRKP>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame); assert(pos.non_pawn_material(strongerSide) == RookValueMg);
assert(pos.piece_count(strongerSide, PAWN) == 0); assert(pos.piece_count(strongerSide, PAWN) == 0);
assert(pos.non_pawn_material(weakerSide) == 0); assert(pos.non_pawn_material(weakerSide) == 0);
assert(pos.piece_count(weakerSide, PAWN) == 1); assert(pos.piece_count(weakerSide, PAWN) == 1);
@ -266,13 +264,13 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
// If the stronger side's king is in front of the pawn, it's a win // If the stronger side's king is in front of the pawn, it's a win
if (wksq < bpsq && file_of(wksq) == file_of(bpsq)) if (wksq < bpsq && file_of(wksq) == file_of(bpsq))
result = RookValueEndgame - Value(square_distance(wksq, bpsq)); result = RookValueEg - Value(square_distance(wksq, bpsq));
// If the weaker side's king is too far from the pawn and the rook, // If the weaker side's king is too far from the pawn and the rook,
// it's a win // it's a win
else if ( square_distance(bksq, bpsq) - (tempo ^ 1) >= 3 else if ( square_distance(bksq, bpsq) - (tempo ^ 1) >= 3
&& square_distance(bksq, wrsq) >= 3) && square_distance(bksq, wrsq) >= 3)
result = RookValueEndgame - Value(square_distance(wksq, bpsq)); result = RookValueEg - Value(square_distance(wksq, bpsq));
// If the pawn is far advanced and supported by the defending king, // If the pawn is far advanced and supported by the defending king,
// the position is drawish // the position is drawish
@ -297,9 +295,9 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
template<> template<>
Value Endgame<KRKB>::operator()(const Position& pos) const { Value Endgame<KRKB>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame); assert(pos.non_pawn_material(strongerSide) == RookValueMg);
assert(pos.piece_count(strongerSide, PAWN) == 0); assert(pos.piece_count(strongerSide, PAWN) == 0);
assert(pos.non_pawn_material(weakerSide) == BishopValueMidgame); assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
assert(pos.piece_count(weakerSide, PAWN) == 0); assert(pos.piece_count(weakerSide, PAWN) == 0);
assert(pos.piece_count(weakerSide, BISHOP) == 1); assert(pos.piece_count(weakerSide, BISHOP) == 1);
@ -313,9 +311,9 @@ Value Endgame<KRKB>::operator()(const Position& pos) const {
template<> template<>
Value Endgame<KRKN>::operator()(const Position& pos) const { Value Endgame<KRKN>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame); assert(pos.non_pawn_material(strongerSide) == RookValueMg);
assert(pos.piece_count(strongerSide, PAWN) == 0); assert(pos.piece_count(strongerSide, PAWN) == 0);
assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame); assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
assert(pos.piece_count(weakerSide, PAWN) == 0); assert(pos.piece_count(weakerSide, PAWN) == 0);
assert(pos.piece_count(weakerSide, KNIGHT) == 1); assert(pos.piece_count(weakerSide, KNIGHT) == 1);
@ -336,16 +334,16 @@ Value Endgame<KRKN>::operator()(const Position& pos) const {
template<> template<>
Value Endgame<KQKR>::operator()(const Position& pos) const { Value Endgame<KQKR>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame); assert(pos.non_pawn_material(strongerSide) == QueenValueMg);
assert(pos.piece_count(strongerSide, PAWN) == 0); assert(pos.piece_count(strongerSide, PAWN) == 0);
assert(pos.non_pawn_material(weakerSide) == RookValueMidgame); assert(pos.non_pawn_material(weakerSide) == RookValueMg);
assert(pos.piece_count(weakerSide, PAWN) == 0); assert(pos.piece_count(weakerSide, PAWN) == 0);
Square winnerKSq = pos.king_square(strongerSide); Square winnerKSq = pos.king_square(strongerSide);
Square loserKSq = pos.king_square(weakerSide); Square loserKSq = pos.king_square(weakerSide);
Value result = QueenValueEndgame Value result = QueenValueEg
- RookValueEndgame - RookValueEg
+ MateTable[loserKSq] + MateTable[loserKSq]
+ DistanceBonus[square_distance(winnerKSq, loserKSq)]; + DistanceBonus[square_distance(winnerKSq, loserKSq)];
@ -356,12 +354,12 @@ template<>
Value Endgame<KBBKN>::operator()(const Position& pos) const { Value Endgame<KBBKN>::operator()(const Position& pos) const {
assert(pos.piece_count(strongerSide, BISHOP) == 2); assert(pos.piece_count(strongerSide, BISHOP) == 2);
assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame); assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMg);
assert(pos.piece_count(weakerSide, KNIGHT) == 1); assert(pos.piece_count(weakerSide, KNIGHT) == 1);
assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame); assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
assert(!pos.pieces(PAWN)); assert(!pos.pieces(PAWN));
Value result = BishopValueEndgame; Value result = BishopValueEg;
Square wksq = pos.king_square(strongerSide); Square wksq = pos.king_square(strongerSide);
Square bksq = pos.king_square(weakerSide); Square bksq = pos.king_square(weakerSide);
Square nsq = pos.piece_list(weakerSide, KNIGHT)[0]; Square nsq = pos.piece_list(weakerSide, KNIGHT)[0];
@ -398,7 +396,7 @@ Value Endgame<KNNK>::operator()(const Position&) const {
template<> template<>
ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const { ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame); assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
assert(pos.piece_count(strongerSide, BISHOP) == 1); assert(pos.piece_count(strongerSide, BISHOP) == 1);
assert(pos.piece_count(strongerSide, PAWN) >= 1); assert(pos.piece_count(strongerSide, PAWN) >= 1);
@ -450,7 +448,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
template<> template<>
ScaleFactor Endgame<KQKRPs>::operator()(const Position& pos) const { ScaleFactor Endgame<KQKRPs>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame); assert(pos.non_pawn_material(strongerSide) == QueenValueMg);
assert(pos.piece_count(strongerSide, QUEEN) == 1); assert(pos.piece_count(strongerSide, QUEEN) == 1);
assert(pos.piece_count(strongerSide, PAWN) == 0); assert(pos.piece_count(strongerSide, PAWN) == 0);
assert(pos.piece_count(weakerSide, ROOK) == 1); assert(pos.piece_count(weakerSide, ROOK) == 1);
@ -480,9 +478,9 @@ ScaleFactor Endgame<KQKRPs>::operator()(const Position& pos) const {
template<> template<>
ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const { ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame); assert(pos.non_pawn_material(strongerSide) == RookValueMg);
assert(pos.piece_count(strongerSide, PAWN) == 1); assert(pos.piece_count(strongerSide, PAWN) == 1);
assert(pos.non_pawn_material(weakerSide) == RookValueMidgame); assert(pos.non_pawn_material(weakerSide) == RookValueMg);
assert(pos.piece_count(weakerSide, PAWN) == 0); assert(pos.piece_count(weakerSide, PAWN) == 0);
Square wksq = pos.king_square(strongerSide); Square wksq = pos.king_square(strongerSide);
@ -598,9 +596,9 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
template<> template<>
ScaleFactor Endgame<KRPPKRP>::operator()(const Position& pos) const { ScaleFactor Endgame<KRPPKRP>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == RookValueMidgame); assert(pos.non_pawn_material(strongerSide) == RookValueMg);
assert(pos.piece_count(strongerSide, PAWN) == 2); assert(pos.piece_count(strongerSide, PAWN) == 2);
assert(pos.non_pawn_material(weakerSide) == RookValueMidgame); assert(pos.non_pawn_material(weakerSide) == RookValueMg);
assert(pos.piece_count(weakerSide, PAWN) == 1); assert(pos.piece_count(weakerSide, PAWN) == 1);
Square wpsq1 = pos.piece_list(strongerSide, PAWN)[0]; Square wpsq1 = pos.piece_list(strongerSide, PAWN)[0];
@ -673,10 +671,10 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
template<> template<>
ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const { ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame); assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
assert(pos.piece_count(strongerSide, BISHOP) == 1); assert(pos.piece_count(strongerSide, BISHOP) == 1);
assert(pos.piece_count(strongerSide, PAWN) == 1); assert(pos.piece_count(strongerSide, PAWN) == 1);
assert(pos.non_pawn_material(weakerSide) == BishopValueMidgame); assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
assert(pos.piece_count(weakerSide, BISHOP) == 1); assert(pos.piece_count(weakerSide, BISHOP) == 1);
assert(pos.piece_count(weakerSide, PAWN) == 0); assert(pos.piece_count(weakerSide, PAWN) == 0);
@ -728,10 +726,10 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
template<> template<>
ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const { ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame); assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
assert(pos.piece_count(strongerSide, BISHOP) == 1); assert(pos.piece_count(strongerSide, BISHOP) == 1);
assert(pos.piece_count(strongerSide, PAWN) == 2); assert(pos.piece_count(strongerSide, PAWN) == 2);
assert(pos.non_pawn_material(weakerSide) == BishopValueMidgame); assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
assert(pos.piece_count(weakerSide, BISHOP) == 1); assert(pos.piece_count(weakerSide, BISHOP) == 1);
assert(pos.piece_count(weakerSide, PAWN) == 0); assert(pos.piece_count(weakerSide, PAWN) == 0);
@ -803,10 +801,10 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
template<> template<>
ScaleFactor Endgame<KBPKN>::operator()(const Position& pos) const { ScaleFactor Endgame<KBPKN>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame); assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
assert(pos.piece_count(strongerSide, BISHOP) == 1); assert(pos.piece_count(strongerSide, BISHOP) == 1);
assert(pos.piece_count(strongerSide, PAWN) == 1); assert(pos.piece_count(strongerSide, PAWN) == 1);
assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame); assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
assert(pos.piece_count(weakerSide, KNIGHT) == 1); assert(pos.piece_count(weakerSide, KNIGHT) == 1);
assert(pos.piece_count(weakerSide, PAWN) == 0); assert(pos.piece_count(weakerSide, PAWN) == 0);
@ -830,7 +828,7 @@ ScaleFactor Endgame<KBPKN>::operator()(const Position& pos) const {
template<> template<>
ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const { ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame); assert(pos.non_pawn_material(strongerSide) == KnightValueMg);
assert(pos.piece_count(strongerSide, KNIGHT) == 1); assert(pos.piece_count(strongerSide, KNIGHT) == 1);
assert(pos.piece_count(strongerSide, PAWN) == 1); assert(pos.piece_count(strongerSide, PAWN) == 1);
assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO); assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);

View file

@ -435,8 +435,8 @@ Value do_evaluate(const Position& pos, Value& margin) {
&& sf == SCALE_FACTOR_NORMAL) && sf == SCALE_FACTOR_NORMAL)
{ {
// Only the two bishops ? // Only the two bishops ?
if ( pos.non_pawn_material(WHITE) == BishopValueMidgame if ( pos.non_pawn_material(WHITE) == BishopValueMg
&& pos.non_pawn_material(BLACK) == BishopValueMidgame) && pos.non_pawn_material(BLACK) == BishopValueMg)
{ {
// Check for KBP vs KB with only a single pawn that is almost // Check for KBP vs KB with only a single pawn that is almost
// certainly a draw or at least two pawns. // certainly a draw or at least two pawns.
@ -492,7 +492,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
// Init king safety tables only if we are going to use them // Init king safety tables only if we are going to use them
if ( pos.piece_count(Us, QUEEN) if ( pos.piece_count(Us, QUEEN)
&& pos.non_pawn_material(Us) >= QueenValueMidgame + RookValueMidgame) && pos.non_pawn_material(Us) >= QueenValueMg + RookValueMg)
{ {
ei.kingRing[Them] = (b | (Us == WHITE ? b >> 8 : b << 8)); ei.kingRing[Them] = (b | (Us == WHITE ? b >> 8 : b << 8));
b &= ei.attackedBy[Us][PAWN]; b &= ei.attackedBy[Us][PAWN];
@ -938,7 +938,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
// value if the other side has a rook or queen. // value if the other side has a rook or queen.
if (file_of(s) == FILE_A || file_of(s) == FILE_H) if (file_of(s) == FILE_A || file_of(s) == FILE_H)
{ {
if (pos.non_pawn_material(Them) <= KnightValueMidgame) if (pos.non_pawn_material(Them) <= KnightValueMg)
ebonus += ebonus / 4; ebonus += ebonus / 4;
else if (pos.pieces(Them, ROOK, QUEEN)) else if (pos.pieces(Them, ROOK, QUEEN))
ebonus -= ebonus / 4; ebonus -= ebonus / 4;
@ -1172,7 +1172,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
// A couple of little helpers used by tracing code, to_cp() converts a value to // A couple of little helpers used by tracing code, to_cp() converts a value to
// a double in centipawns scale, trace_add() stores white and black scores. // a double in centipawns scale, trace_add() stores white and black scores.
double to_cp(Value v) { return double(v) / double(PawnValueMidgame); } double to_cp(Value v) { return double(v) / double(PawnValueMg); }
void trace_add(int idx, Score wScore, Score bScore) { void trace_add(int idx, Score wScore, Score bScore) {

View file

@ -63,11 +63,11 @@ namespace {
const Color Them = (Us == WHITE ? BLACK : WHITE); const Color Them = (Us == WHITE ? BLACK : WHITE);
return pos.non_pawn_material(Them) == VALUE_ZERO return pos.non_pawn_material(Them) == VALUE_ZERO
&& pos.piece_count(Them, PAWN) == 0 && pos.piece_count(Them, PAWN) == 0
&& pos.non_pawn_material(Us) >= RookValueMidgame; && pos.non_pawn_material(Us) >= RookValueMg;
} }
template<Color Us> bool is_KBPsKs(const Position& pos) { template<Color Us> bool is_KBPsKs(const Position& pos) {
return pos.non_pawn_material(Us) == BishopValueMidgame return pos.non_pawn_material(Us) == BishopValueMg
&& pos.piece_count(Us, BISHOP) == 1 && pos.piece_count(Us, BISHOP) == 1
&& pos.piece_count(Us, PAWN) >= 1; && pos.piece_count(Us, PAWN) >= 1;
} }
@ -75,7 +75,7 @@ namespace {
template<Color Us> bool is_KQKRPs(const Position& pos) { template<Color Us> bool is_KQKRPs(const Position& pos) {
const Color Them = (Us == WHITE ? BLACK : WHITE); const Color Them = (Us == WHITE ? BLACK : WHITE);
return pos.piece_count(Us, PAWN) == 0 return pos.piece_count(Us, PAWN) == 0
&& pos.non_pawn_material(Us) == QueenValueMidgame && pos.non_pawn_material(Us) == QueenValueMg
&& pos.piece_count(Us, QUEEN) == 1 && pos.piece_count(Us, QUEEN) == 1
&& pos.piece_count(Them, ROOK) == 1 && pos.piece_count(Them, ROOK) == 1
&& pos.piece_count(Them, PAWN) >= 1; && pos.piece_count(Them, PAWN) >= 1;
@ -191,20 +191,20 @@ MaterialEntry* MaterialTable::probe(const Position& pos) {
} }
// No pawns makes it difficult to win, even with a material advantage // No pawns makes it difficult to win, even with a material advantage
if (pos.piece_count(WHITE, PAWN) == 0 && npm_w - npm_b <= BishopValueMidgame) if (pos.piece_count(WHITE, PAWN) == 0 && npm_w - npm_b <= BishopValueMg)
{ {
e->factor[WHITE] = (uint8_t) e->factor[WHITE] = (uint8_t)
(npm_w == npm_b || npm_w < RookValueMidgame ? 0 : NoPawnsSF[std::min(pos.piece_count(WHITE, BISHOP), 2)]); (npm_w == npm_b || npm_w < RookValueMg ? 0 : NoPawnsSF[std::min(pos.piece_count(WHITE, BISHOP), 2)]);
} }
if (pos.piece_count(BLACK, PAWN) == 0 && npm_b - npm_w <= BishopValueMidgame) if (pos.piece_count(BLACK, PAWN) == 0 && npm_b - npm_w <= BishopValueMg)
{ {
e->factor[BLACK] = (uint8_t) e->factor[BLACK] = (uint8_t)
(npm_w == npm_b || npm_b < RookValueMidgame ? 0 : NoPawnsSF[std::min(pos.piece_count(BLACK, BISHOP), 2)]); (npm_w == npm_b || npm_b < RookValueMg ? 0 : NoPawnsSF[std::min(pos.piece_count(BLACK, BISHOP), 2)]);
} }
// Compute the space weight // Compute the space weight
if (npm_w + npm_b >= 2 * QueenValueMidgame + 4 * RookValueMidgame + 2 * KnightValueMidgame) if (npm_w + npm_b >= 2 * QueenValueMg + 4 * RookValueMg + 2 * KnightValueMg)
{ {
int minorPieceCount = pos.piece_count(WHITE, KNIGHT) + pos.piece_count(WHITE, BISHOP) int minorPieceCount = pos.piece_count(WHITE, KNIGHT) + pos.piece_count(WHITE, BISHOP)
+ pos.piece_count(BLACK, KNIGHT) + pos.piece_count(BLACK, BISHOP); + pos.piece_count(BLACK, KNIGHT) + pos.piece_count(BLACK, BISHOP);

View file

@ -79,8 +79,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
killers[1].move = ss->killers[1]; killers[1].move = ss->killers[1];
// Consider sligtly negative captures as good if at low depth and far from beta // Consider sligtly negative captures as good if at low depth and far from beta
if (ss && ss->eval < beta - PawnValueMidgame && d < 3 * ONE_PLY) if (ss && ss->eval < beta - PawnValueMg && d < 3 * ONE_PLY)
captureThreshold = -PawnValueMidgame; captureThreshold = -PawnValueMg;
// Consider negative captures as good if still enough to reach beta // Consider negative captures as good if still enough to reach beta
else if (ss && ss->eval > beta) else if (ss && ss->eval > beta)
@ -131,7 +131,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, const History& h, PieceType
phase = PROBCUT; phase = PROBCUT;
// In ProbCut we generate only captures better than parent's captured piece // In ProbCut we generate only captures better than parent's captured piece
captureThreshold = PieceValueMidgame[pt]; captureThreshold = PieceValue[Mg][pt];
ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE); ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
if (ttMove && (!pos.is_capture(ttMove) || pos.see(ttMove) <= captureThreshold)) if (ttMove && (!pos.is_capture(ttMove) || pos.see(ttMove) <= captureThreshold))
@ -165,11 +165,11 @@ void MovePicker::score_captures() {
for (MoveStack* cur = moves; cur != lastMove; cur++) for (MoveStack* cur = moves; cur != lastMove; cur++)
{ {
m = cur->move; m = cur->move;
cur->score = PieceValueMidgame[pos.piece_on(to_sq(m))] cur->score = PieceValue[Mg][pos.piece_on(to_sq(m))]
- type_of(pos.piece_moved(m)); - type_of(pos.piece_moved(m));
if (type_of(m) == PROMOTION) if (type_of(m) == PROMOTION)
cur->score += PieceValueMidgame[promotion_type(m)]; cur->score += PieceValue[Mg][promotion_type(m)];
} }
} }
@ -200,7 +200,7 @@ void MovePicker::score_evasions() {
if ((seeScore = pos.see_sign(m)) < 0) if ((seeScore = pos.see_sign(m)) < 0)
cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
else if (pos.is_capture(m)) else if (pos.is_capture(m))
cur->score = PieceValueMidgame[pos.piece_on(to_sq(m))] cur->score = PieceValue[Mg][pos.piece_on(to_sq(m))]
- type_of(pos.piece_moved(m)) + History::MaxValue; - type_of(pos.piece_moved(m)) + History::MaxValue;
else else
cur->score = H.value(pos.piece_moved(m), to_sq(m)); cur->score = H.value(pos.piece_moved(m), to_sq(m));

View file

@ -43,7 +43,7 @@ string score_to_uci(Value v, Value alpha, Value beta) {
stringstream s; stringstream s;
if (abs(v) < VALUE_MATE_IN_MAX_PLY) if (abs(v) < VALUE_MATE_IN_MAX_PLY)
s << "cp " << v * 100 / int(PawnValueMidgame); s << "cp " << v * 100 / int(PawnValueMg);
else else
s << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2; s << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2;
@ -216,7 +216,7 @@ static string score_to_string(Value v) {
s << "-#" << (VALUE_MATE + v) / 2; s << "-#" << (VALUE_MATE + v) / 2;
else else
s << setprecision(2) << fixed << showpos << float(v) / PawnValueMidgame; s << setprecision(2) << fixed << showpos << float(v) / PawnValueMg;
return s.str(); return s.str();
} }

View file

@ -36,35 +36,18 @@ using std::string;
using std::cout; using std::cout;
using std::endl; using std::endl;
// To convert a Piece to and from a FEN char
static const string PieceToChar(" PNBRQK pnbrqk"); static const string PieceToChar(" PNBRQK pnbrqk");
// Material values arrays, indexed by Piece
const Value PieceValueMidgame[17] = {
VALUE_ZERO,
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
RookValueMidgame, QueenValueMidgame,
VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
RookValueMidgame, QueenValueMidgame
};
const Value PieceValueEndgame[17] = {
VALUE_ZERO,
PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
RookValueEndgame, QueenValueEndgame,
VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
RookValueEndgame, QueenValueEndgame
};
CACHE_LINE_ALIGNMENT CACHE_LINE_ALIGNMENT
Score pieceSquareTable[16][64]; Score pieceSquareTable[16][64]; // [piece][square]
Value PieceValue[2][18] = { // [Mg / Eg][piece / pieceType]
{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg },
{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } };
namespace Zobrist { namespace Zobrist {
Key psq[2][8][64]; // [color][pieceType][square]/[piece count] Key psq[2][8][64]; // [color][pieceType][square / piece count]
Key enpassant[8]; // [file] Key enpassant[8]; // [file]
Key castle[16]; // [castleRight] Key castle[16]; // [castleRight]
Key side; Key side;
@ -103,7 +86,10 @@ void init() {
for (PieceType pt = PAWN; pt <= KING; pt++) for (PieceType pt = PAWN; pt <= KING; pt++)
{ {
Score v = make_score(PieceValueMidgame[pt], PieceValueEndgame[pt]); PieceValue[Mg][make_piece(BLACK, pt)] = PieceValue[Mg][pt];
PieceValue[Eg][make_piece(BLACK, pt)] = PieceValue[Eg][pt];
Score v = make_score(PieceValue[Mg][pt], PieceValue[Eg][pt]);
for (Square s = SQ_A1; s <= SQ_H8; s++) for (Square s = SQ_A1; s <= SQ_H8; s++)
{ {
@ -808,7 +794,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
st->pawnKey ^= Zobrist::psq[them][PAWN][capsq]; st->pawnKey ^= Zobrist::psq[them][PAWN][capsq];
} }
else else
st->npMaterial[them] -= PieceValueMidgame[capture]; st->npMaterial[them] -= PieceValue[Mg][capture];
// Remove the captured piece // Remove the captured piece
byTypeBB[ALL_PIECES] ^= capsq; byTypeBB[ALL_PIECES] ^= capsq;
@ -916,7 +902,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
- pieceSquareTable[make_piece(us, PAWN)][to]; - pieceSquareTable[make_piece(us, PAWN)][to];
// Update material // Update material
st->npMaterial[us] += PieceValueMidgame[promotion]; st->npMaterial[us] += PieceValue[Mg][promotion];
} }
// Update pawn hash key // Update pawn hash key
@ -1221,7 +1207,7 @@ int Position::see_sign(Move m) const {
// Early return if SEE cannot be negative because captured piece value // Early return if SEE cannot be negative because captured piece value
// is not less then capturing one. Note that king moves always return // is not less then capturing one. Note that king moves always return
// here because king midgame value is set to 0. // here because king midgame value is set to 0.
if (PieceValueMidgame[piece_on(to_sq(m))] >= PieceValueMidgame[piece_moved(m)]) if (PieceValue[Mg][piece_on(to_sq(m))] >= PieceValue[Mg][piece_moved(m)])
return 1; return 1;
return see(m); return see(m);
@ -1270,7 +1256,7 @@ int Position::see(Move m) const {
stm = ~color_of(piece_on(from)); stm = ~color_of(piece_on(from));
stmAttackers = attackers & pieces(stm); stmAttackers = attackers & pieces(stm);
if (!stmAttackers) if (!stmAttackers)
return PieceValueMidgame[capturedType]; return PieceValue[Mg][capturedType];
// The destination square is defended, which makes things rather more // The destination square is defended, which makes things rather more
// difficult to compute. We proceed by building up a "swap list" containing // difficult to compute. We proceed by building up a "swap list" containing
@ -1278,7 +1264,7 @@ int Position::see(Move m) const {
// destination square, where the sides alternately capture, and always // destination square, where the sides alternately capture, and always
// capture with the least valuable piece. After each capture, we look for // capture with the least valuable piece. After each capture, we look for
// new X-ray attacks from behind the capturing piece. // new X-ray attacks from behind the capturing piece.
swapList[0] = PieceValueMidgame[capturedType]; swapList[0] = PieceValue[Mg][capturedType];
capturedType = type_of(piece_on(from)); capturedType = type_of(piece_on(from));
do { do {
@ -1299,7 +1285,7 @@ int Position::see(Move m) const {
// Add the new entry to the swap list // Add the new entry to the swap list
assert(slIndex < 32); assert(slIndex < 32);
swapList[slIndex] = -swapList[slIndex - 1] + PieceValueMidgame[capturedType]; swapList[slIndex] = -swapList[slIndex - 1] + PieceValue[Mg][capturedType];
slIndex++; slIndex++;
// Remember the value of the capturing piece, and change the side to // Remember the value of the capturing piece, and change the side to
@ -1312,7 +1298,7 @@ int Position::see(Move m) const {
if (capturedType == KING && stmAttackers) if (capturedType == KING && stmAttackers)
{ {
assert(slIndex < 32); assert(slIndex < 32);
swapList[slIndex++] = QueenValueMidgame*10; swapList[slIndex++] = QueenValueMg * 16;
break; break;
} }
} while (stmAttackers); } while (stmAttackers);
@ -1454,7 +1440,7 @@ Value Position::compute_non_pawn_material(Color c) const {
Value value = VALUE_ZERO; Value value = VALUE_ZERO;
for (PieceType pt = KNIGHT; pt <= QUEEN; pt++) for (PieceType pt = KNIGHT; pt <= QUEEN; pt++)
value += piece_count(c, pt) * PieceValueMidgame[pt]; value += piece_count(c, pt) * PieceValue[Mg][pt];
return value; return value;
} }
@ -1468,7 +1454,7 @@ bool Position::is_draw() const {
// Draw by material? // Draw by material?
if ( !pieces(PAWN) if ( !pieces(PAWN)
&& (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMidgame)) && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg))
return true; return true;
// Draw by the 50 moves rule? // Draw by the 50 moves rule?

View file

@ -159,7 +159,7 @@ namespace {
&& type_of(pos.piece_on(to_sq(m))) != PAWN && type_of(pos.piece_on(to_sq(m))) != PAWN
&& type_of(m) == NORMAL && type_of(m) == NORMAL
&& ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) && ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
- PieceValueMidgame[pos.piece_on(to_sq(m))] == VALUE_ZERO)) - PieceValue[Mg][pos.piece_on(to_sq(m))] == VALUE_ZERO))
return true; return true;
return false; return false;
@ -688,7 +688,7 @@ namespace {
Depth R = 3 * ONE_PLY + depth / 4; Depth R = 3 * ONE_PLY + depth / 4;
// Null move dynamic reduction based on value // Null move dynamic reduction based on value
if (refinedValue - PawnValueMidgame > beta) if (refinedValue - PawnValueMg > beta)
R += ONE_PLY; R += ONE_PLY;
pos.do_null_move<true>(st); pos.do_null_move<true>(st);
@ -1176,7 +1176,7 @@ split_point_start: // At split points actual search starts from here
alpha = bestValue; alpha = bestValue;
futilityBase = ss->eval + evalMargin + FutilityMarginQS; futilityBase = ss->eval + evalMargin + FutilityMarginQS;
enoughMaterial = pos.non_pawn_material(pos.side_to_move()) > RookValueMidgame; enoughMaterial = pos.non_pawn_material(pos.side_to_move()) > RookValueMg;
} }
// Initialize a MovePicker object for the current position, and prepare // Initialize a MovePicker object for the current position, and prepare
@ -1204,8 +1204,8 @@ split_point_start: // At split points actual search starts from here
&& !pos.is_passed_pawn_push(move)) && !pos.is_passed_pawn_push(move))
{ {
futilityValue = futilityBase futilityValue = futilityBase
+ PieceValueEndgame[pos.piece_on(to_sq(move))] + PieceValue[Eg][pos.piece_on(to_sq(move))]
+ (type_of(move) == ENPASSANT ? PawnValueEndgame : VALUE_ZERO); + (type_of(move) == ENPASSANT ? PawnValueEg : VALUE_ZERO);
if (futilityValue < beta) if (futilityValue < beta)
{ {
@ -1243,7 +1243,7 @@ split_point_start: // At split points actual search starts from here
&& givesCheck && givesCheck
&& move != ttMove && move != ttMove
&& !pos.is_capture_or_promotion(move) && !pos.is_capture_or_promotion(move)
&& ss->eval + PawnValueMidgame / 4 < beta && ss->eval + PawnValueMg / 4 < beta
&& !check_is_dangerous(pos, move, futilityBase, beta)) && !check_is_dangerous(pos, move, futilityBase, beta))
continue; continue;
@ -1328,7 +1328,7 @@ split_point_start: // At split points actual search starts from here
while (b) while (b)
{ {
// Note that here we generate illegal "double move"! // Note that here we generate illegal "double move"!
if (futilityBase + PieceValueEndgame[pos.piece_on(pop_lsb(&b))] >= beta) if (futilityBase + PieceValue[Eg][pos.piece_on(pop_lsb(&b))] >= beta)
return true; return true;
} }
@ -1440,7 +1440,7 @@ split_point_start: // At split points actual search starts from here
// Case 2: If the threatened piece has value less than or equal to the // Case 2: If the threatened piece has value less than or equal to the
// value of the threatening piece, don't prune moves which defend it. // value of the threatening piece, don't prune moves which defend it.
if ( pos.is_capture(threat) if ( pos.is_capture(threat)
&& ( PieceValueMidgame[pos.piece_on(tfrom)] >= PieceValueMidgame[pos.piece_on(tto)] && ( PieceValue[Mg][pos.piece_on(tfrom)] >= PieceValue[Mg][pos.piece_on(tto)]
|| type_of(pos.piece_on(tfrom)) == KING) || type_of(pos.piece_on(tfrom)) == KING)
&& pos.move_attacks_square(m, tto)) && pos.move_attacks_square(m, tto))
return true; return true;
@ -1500,7 +1500,7 @@ split_point_start: // At split points actual search starts from here
// RootMoves are already sorted by score in descending order // RootMoves are already sorted by score in descending order
size_t size = std::min(MultiPV, RootMoves.size()); size_t size = std::min(MultiPV, RootMoves.size());
int variance = std::min(RootMoves[0].score - RootMoves[size - 1].score, PawnValueMidgame); int variance = std::min(RootMoves[0].score - RootMoves[size - 1].score, PawnValueMg);
int weakness = 120 - 2 * SkillLevel; int weakness = 120 - 2 * SkillLevel;
int max_s = -VALUE_INFINITE; int max_s = -VALUE_INFINITE;
Move best = MOVE_NONE; Move best = MOVE_NONE;

View file

@ -168,16 +168,13 @@ enum Value {
VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX, VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX,
VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN, VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN,
PawnValueMidgame = 198, Mg = 0, Eg = 1,
PawnValueEndgame = 258,
KnightValueMidgame = 817, PawnValueMg = 198, PawnValueEg = 258,
KnightValueEndgame = 846, KnightValueMg = 817, KnightValueEg = 846,
BishopValueMidgame = 836, BishopValueMg = 836, BishopValueEg = 857,
BishopValueEndgame = 857, RookValueMg = 1270, RookValueEg = 1278,
RookValueMidgame = 1270, QueenValueMg = 2521, QueenValueEg = 2558
RookValueEndgame = 1278,
QueenValueMidgame = 2521,
QueenValueEndgame = 2558
}; };
enum PieceType { enum PieceType {
@ -323,7 +320,7 @@ inline Score apply_weight(Score v, Score w) {
namespace Zobrist { namespace Zobrist {
extern Key psq[2][8][64]; // [color][pieceType][square]/[piece count] extern Key psq[2][8][64]; // [color][pieceType][square / piece count]
extern Key enpassant[8]; // [file] extern Key enpassant[8]; // [file]
extern Key castle[16]; // [castleRight] extern Key castle[16]; // [castleRight]
extern Key side; extern Key side;
@ -332,10 +329,11 @@ namespace Zobrist {
void init(); void init();
} }
extern Score pieceSquareTable[16][64]; CACHE_LINE_ALIGNMENT
extern int SquareDistance[64][64];
extern const Value PieceValueMidgame[17]; // Indexed by Piece or PieceType extern Score pieceSquareTable[16][64]; // [piece][square]
extern const Value PieceValueEndgame[17]; extern Value PieceValue[2][18]; // [Mg / Eg][piece / pieceType]
extern int SquareDistance[64][64]; // [square][square]
struct MoveStack { struct MoveStack {
Move move; Move move;