]> git.sesse.net Git - stockfish/commitdiff
MovePicker: introduce per square MVV/LVA ordering
authorMarco Costalba <mcostalba@gmail.com>
Fri, 14 Nov 2008 20:49:46 +0000 (21:49 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 16 Nov 2008 11:37:45 +0000 (12:37 +0100)
Just added the infrastructure, no functional change.

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

index 187a3c513e0275a112c377919a40d62cbdebf586..c51fe69f783baaa2385e07212ae374395867aa2f 100644 (file)
@@ -134,6 +134,7 @@ Move MovePicker::get_next_move() {
     case PH_GOOD_CAPTURES:
         numOfMoves = generate_captures(pos, moves);
         score_captures();
     case PH_GOOD_CAPTURES:
         numOfMoves = generate_captures(pos, moves);
         score_captures();
+        capSquares = EmptyBoardBB;
         movesPicked = 0;
         break;
 
         movesPicked = 0;
         break;
 
@@ -288,8 +289,11 @@ void MovePicker::score_qcaptures() {
 }
 
 
 }
 
 
-/// find_best_index() loops across the moves and returns index of
-/// the highest scored one.
+/// find_best_index() loops across the moves and returns index of\r
+/// the highest scored one. There is also a second version that\r
+/// lowers the priority of moves that attack the same square,\r
+/// so that if the best move that attack a square fails the next\r
+/// move picked attacks a different square if any, not the same one.
 
 int MovePicker::find_best_index() {
 
 
 int MovePicker::find_best_index() {
 
@@ -304,6 +308,43 @@ int MovePicker::find_best_index() {
   return bestIndex;
 }
 
   return bestIndex;
 }
 
+int MovePicker::find_best_index(Bitboard* squares, int values[]) {\r
+\r
+  int hs;\r
+  Move m;\r
+  Square to;\r
+  int bestScore = -10000000, bestIndex = -1;\r
+\r
+  for (int i = movesPicked; i < numOfMoves; i++)\r
+  {\r
+      m = moves[i].move;\r
+      to = move_to(m);\r
+      \r
+      if (!bit_is_set(*squares, to))\r
+      {\r
+          // Init at first use\r
+          set_bit(squares, to);\r
+          values[to] = 0;\r
+      }\r
+\r
+      hs = moves[i].score - values[to];\r
+      if (hs > bestScore)\r
+      {\r
+          bestIndex = i;\r
+          bestScore = hs;\r
+      }\r
+  }\r
+\r
+  if (bestIndex != -1)\r
+  {\r
+      // Raise value of the picked square, so next attack\r
+      // to the same square will get low priority.\r
+      to = move_to(moves[bestIndex].move);\r
+      values[to] += 0xB00;\r
+  }\r
+  return bestIndex;\r
+}
+
 
 /// MovePicker::pick_move_from_list() picks the move with the biggest score
 /// from a list of generated moves (moves[] or badCaptures[], depending on
 
 /// MovePicker::pick_move_from_list() picks the move with the biggest score
 /// from a list of generated moves (moves[] or badCaptures[], depending on
index 5a38826188811eb634f053d5cd3396760325d69f..c7b1ddaf58be40533e6e170b8ca6ef1e047b4801 100644 (file)
@@ -77,11 +77,14 @@ private:
   void score_qcaptures();
   Move pick_move_from_list();
   int find_best_index();
   void score_qcaptures();
   Move pick_move_from_list();
   int find_best_index();
+  int MovePicker::find_best_index(Bitboard* squares, int values[]);
 
   const Position& pos;
   Move ttMove, mateKiller, killer1, killer2;
   Bitboard pinned, dc;
   MoveStack moves[256], badCaptures[64];
 
   const Position& pos;
   Move ttMove, mateKiller, killer1, killer2;
   Bitboard pinned, dc;
   MoveStack moves[256], badCaptures[64];
+  Bitboard capSquares;\r
+  int capSqValues[64];
   bool pvNode;
   Depth depth;
   int phaseIndex;
   bool pvNode;
   Depth depth;
   int phaseIndex;