Skip to content

Commit

Permalink
Update SEE to return a Value
Browse files Browse the repository at this point in the history
It seems more natural because the actual returned
value is from PieceValue[] array.

No functional change.
  • Loading branch information
mcostalba committed Feb 16, 2014
1 parent 17ffc22 commit 7b0a2f2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/movepick.cpp
Expand Up @@ -193,12 +193,12 @@ void MovePicker::score<EVASIONS>() {
// is not under attack, ordered by history value, then bad-captures and quiet // is not under attack, ordered by history value, then bad-captures and quiet
// moves with a negative SEE. This last group is ordered by the SEE score. // moves with a negative SEE. This last group is ordered by the SEE score.
Move m; Move m;
int seeScore; Value seeScore;


for (ExtMove* it = moves; it != end; ++it) for (ExtMove* it = moves; it != end; ++it)
{ {
m = it->move; m = it->move;
if ((seeScore = pos.see_sign(m)) < 0) if ((seeScore = pos.see_sign(m)) < VALUE_ZERO)
it->score = seeScore - HistoryStats::Max; // At the bottom it->score = seeScore - HistoryStats::Max; // At the bottom


else if (pos.capture(m)) else if (pos.capture(m))
Expand Down Expand Up @@ -317,7 +317,7 @@ Move MovePicker::next_move<false>() {
move = pick_best(cur++, end)->move; move = pick_best(cur++, end)->move;
if (move != ttMove) if (move != ttMove)
{ {
if (pos.see_sign(move) >= 0) if (pos.see_sign(move) >= VALUE_ZERO)
return move; return move;


// Losing capture, move it to the tail of the array // Losing capture, move it to the tail of the array
Expand Down
3 changes: 2 additions & 1 deletion src/movepick.h
Expand Up @@ -103,7 +103,8 @@ class MovePicker {
Move ttMove; Move ttMove;
ExtMove killers[6]; ExtMove killers[6];
Square recaptureSquare; Square recaptureSquare;
int captureThreshold, stage; Value captureThreshold;
int stage;
ExtMove *cur, *end, *endQuiets, *endBadCaptures; ExtMove *cur, *end, *endQuiets, *endBadCaptures;
ExtMove moves[MAX_MOVES]; ExtMove moves[MAX_MOVES];
}; };
Expand Down
11 changes: 6 additions & 5 deletions src/position.cpp
Expand Up @@ -1013,24 +1013,25 @@ void Position::undo_null_move() {
/// Position::see() is a static exchange evaluator: It tries to estimate the /// Position::see() is a static exchange evaluator: It tries to estimate the
/// material gain or loss resulting from a move. /// material gain or loss resulting from a move.


int Position::see_sign(Move m) const { Value Position::see_sign(Move m) const {


assert(is_ok(m)); assert(is_ok(m));


// 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 (PieceValue[MG][moved_piece(m)] <= PieceValue[MG][piece_on(to_sq(m))]) if (PieceValue[MG][moved_piece(m)] <= PieceValue[MG][piece_on(to_sq(m))])
return 1; return VALUE_KNOWN_WIN;


return see(m); return see(m);
} }


int Position::see(Move m) const { Value Position::see(Move m) const {


Square from, to; Square from, to;
Bitboard occupied, attackers, stmAttackers; Bitboard occupied, attackers, stmAttackers;
int swapList[32], slIndex = 1; Value swapList[32];
int slIndex = 1;
PieceType captured; PieceType captured;
Color stm; Color stm;


Expand All @@ -1046,7 +1047,7 @@ int Position::see(Move m) const {
// handled correctly. Simply return 0 that is always the correct value // handled correctly. Simply return 0 that is always the correct value
// unless in the rare case the rook ends up under attack. // unless in the rare case the rook ends up under attack.
if (type_of(m) == CASTLING) if (type_of(m) == CASTLING)
return 0; return VALUE_ZERO;


if (type_of(m) == ENPASSANT) if (type_of(m) == ENPASSANT)
{ {
Expand Down
4 changes: 2 additions & 2 deletions src/position.h
Expand Up @@ -141,8 +141,8 @@ class Position {
void undo_null_move(); void undo_null_move();


// Static exchange evaluation // Static exchange evaluation
int see(Move m) const; Value see(Move m) const;
int see_sign(Move m) const; Value see_sign(Move m) const;


// Accessing hash keys // Accessing hash keys
Key key() const; Key key() const;
Expand Down
8 changes: 4 additions & 4 deletions src/search.cpp
Expand Up @@ -779,7 +779,7 @@ namespace {
|| pos.advanced_pawn_push(move); || pos.advanced_pawn_push(move);


// Step 12. Extend checks // Step 12. Extend checks
if (givesCheck && pos.see_sign(move) >= 0) if (givesCheck && pos.see_sign(move) >= VALUE_ZERO)
ext = ONE_PLY; ext = ONE_PLY;


// Singular extension search. If all moves but one fail low on a search of // Singular extension search. If all moves but one fail low on a search of
Expand Down Expand Up @@ -850,7 +850,7 @@ namespace {
} }


// Prune moves with negative SEE at low depths // Prune moves with negative SEE at low depths
if (predictedDepth < 4 * ONE_PLY && pos.see_sign(move) < 0) if (predictedDepth < 4 * ONE_PLY && pos.see_sign(move) < VALUE_ZERO)
{ {
if (SpNode) if (SpNode)
splitPoint->mutex.lock(); splitPoint->mutex.lock();
Expand Down Expand Up @@ -1175,7 +1175,7 @@ namespace {
continue; continue;
} }


if (futilityBase < beta && pos.see(move) <= 0) if (futilityBase < beta && pos.see(move) <= VALUE_ZERO)
{ {
bestValue = std::max(bestValue, futilityBase); bestValue = std::max(bestValue, futilityBase);
continue; continue;
Expand All @@ -1193,7 +1193,7 @@ namespace {
&& (!InCheck || evasionPrunable) && (!InCheck || evasionPrunable)
&& move != ttMove && move != ttMove
&& type_of(move) != PROMOTION && type_of(move) != PROMOTION
&& pos.see_sign(move) < 0) && pos.see_sign(move) < VALUE_ZERO)
continue; continue;


// Check for legality just before making the move // Check for legality just before making the move
Expand Down

0 comments on commit 7b0a2f2

Please sign in to comment.