]> git.sesse.net Git - stockfish/commitdiff
Introduce see_sign() and use it to shortcut full see()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 11 Jul 2009 08:54:30 +0000 (09:54 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 12 Jul 2009 07:37:43 +0000 (08:37 +0100)
Mostly of times we are interested only in the sign of SEE,
namely if a capture is negative or not.

If the capturing piece is smaller then the captured one we
already know SEE cannot be negative and this information
is enough most of the times. And of course it is much
faster to detect then a full SEE.

Note that in case see_sign() is negative then the returned
value is exactly the see() value, this is very important,
especially for ordering capturing moves.

With this patch the calls to the costly see() are reduced
of almost 30%.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/movepick.cpp
src/position.cpp
src/position.h
src/search.cpp

index 22845ba2a2a86f3f3cfb86c9ed0428fee21de582..25cbdefd0b10a1b23e9674a35b09776c6bebe98e 100644 (file)
@@ -244,7 +244,7 @@ void MovePicker::score_captures() {
   for (int i = 0; i < numOfMoves; i++)
   {
       m = moves[i].move;
   for (int i = 0; i < numOfMoves; i++)
   {
       m = moves[i].move;
-      seeValue = pos.see(m);
+      seeValue = pos.see_sign(m);
       if (seeValue >= 0)
       {
           if (move_is_promotion(m))
       if (seeValue >= 0)
       {
           if (move_is_promotion(m))
index 1179f6f98a8aa61733cb81df7cdecae906c4a042..8099764c07f758ae3b13d1d3d3b4f190053a4516 100644 (file)
@@ -1474,6 +1474,22 @@ int Position::see(Move m) const {
   return see(move_from(m), move_to(m));
 }
 
   return see(move_from(m), move_to(m));
 }
 
+int Position::see_sign(Move m) const {
+
+  assert(move_is_ok(m));
+
+  Square from = move_from(m);
+  Square to = move_to(m);
+
+  // Early return if SEE cannot be negative because capturing piece value
+  // is not bigger then captured one.
+  if (   midgame_value_of_piece_on(from) <= midgame_value_of_piece_on(to)
+      && type_of_piece_on(from) != KING)
+         return 1;
+
+  return see(from, to);
+}
+
 int Position::see(Square from, Square to) const {
 
   // Material values
 int Position::see(Square from, Square to) const {
 
   // Material values
index 5fe1a8fdddae4dd6a85858d21dac2f4ada97b759..97166360ff390c101c828e455930fcbd9d59682a 100644 (file)
@@ -267,6 +267,7 @@ public:
   int see(Square from, Square to) const;
   int see(Move m) const;
   int see(Square to) const;
   int see(Square from, Square to) const;
   int see(Move m) const;
   int see(Square to) const;
+  int see_sign(Move m) const;
 
   // Accessing hash keys
   Key get_key() const;
 
   // Accessing hash keys
   Key get_key() const;
index 7e2f9727291df6bffbd90b218ecb854c3f549cf6..e64950283445f001e0e69158684d22f5aee3ac5f 100644 (file)
@@ -1561,9 +1561,7 @@ namespace {
       // Don't search captures and checks with negative SEE values
       if (   !isCheck
           && !move_is_promotion(move)
       // Don't search captures and checks with negative SEE values
       if (   !isCheck
           && !move_is_promotion(move)
-          && (pos.midgame_value_of_piece_on(move_from(move)) >
-              pos.midgame_value_of_piece_on(move_to(move)))
-          &&  pos.see(move) < 0)
+          &&  pos.see_sign(move) < 0)
           continue;
 
       // Make and search the move.
           continue;
 
       // Make and search the move.
@@ -2240,7 +2238,7 @@ namespace {
     if (   pvNode
         && capture
         && pos.type_of_piece_on(move_to(m)) != PAWN
     if (   pvNode
         && capture
         && pos.type_of_piece_on(move_to(m)) != PAWN
-        && pos.see(m) >= 0)
+        && pos.see_sign(m) >= 0)
     {
         result += OnePly/2;
         *dangerous = true;
     {
         result += OnePly/2;
         *dangerous = true;
@@ -2313,7 +2311,7 @@ namespace {
         && threat != MOVE_NONE
         && piece_is_slider(pos.piece_on(tfrom))
         && bit_is_set(squares_between(tfrom, tto), mto)
         && threat != MOVE_NONE
         && piece_is_slider(pos.piece_on(tfrom))
         && bit_is_set(squares_between(tfrom, tto), mto)
-        && pos.see(m) >= 0)
+        && pos.see_sign(m) >= 0)
         return false;
 
     return true;
         return false;
 
     return true;