]> git.sesse.net Git - stockfish/blobdiff - src/move.h
Similarize pruning code in search() and sp_search()
[stockfish] / src / move.h
index 5a58afe69c6e09f66d79e886985f67a534430cd4..2ba0884087422d7bdd908d1130d3b19ed3a02486 100644 (file)
@@ -62,9 +62,29 @@ struct MoveStack {
   int score;
 };
 
-// Note that operator< is set up such that std::sort() will sort in descending order
+// Note that operator< is set up such that sorting will be in descending order
 inline bool operator<(const MoveStack& f, const MoveStack& s) { return s.score < f.score; }
 
+// Our stable insertion sort in range [firstMove, lastMove), platform independent
+template<typename T>
+inline void sort_moves(T* firstMove, T* lastMove)
+{
+    T value;
+    T *cur, *p, *d;
+
+    if (firstMove != lastMove)
+        for (cur = firstMove; ++cur != lastMove; )
+        {
+            p = d = cur;
+            value = *p--;
+            if (value < *p)
+            {
+                do *d = *p;
+                while (--d != firstMove && value < *--p);
+                *d = value;
+            }
+        }
+}
 
 ////
 //// Inline functions
@@ -78,10 +98,14 @@ inline Square move_to(Move m) {
   return Square(m & 0x3F);
 }
 
-inline PieceType move_promotion(Move m) {
+inline PieceType move_promotion_piece(Move m) {
   return PieceType((int(m) >> 12) & 7);
 }
 
+inline int move_is_promotion(Move m) {
+  return m & (7 << 12);
+}
+
 inline int move_is_ep(Move m) {
   return m & (1 << 15);
 }