Improve move sorting
authorH.G.Muller <hgm@hgm-xboard.(none)>
Wed, 11 Apr 2018 18:35:08 +0000 (20:35 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 12 Apr 2018 07:14:25 +0000 (09:14 +0200)
Just prepending the best move as a duplicat, an relying on a hash hit
to skip searching the later occurrence, is not satisfactory in multi-PV
mode, as moves with the same score would both output a PV. We now erase
the original move (by setting it to the invalid 0), an skip such moves
in the move loop.

dropper.c

index de421e3..d0a5ad5 100644 (file)
--- a/dropper.c
+++ b/dropper.c
@@ -1436,7 +1436,7 @@ Search (int stm, int alpha, int beta, StackFrame *ff, int depth, int reduction,
                }
            }
 
-           if(ply == 0 && moveMap[moveStack[curMove] & 0xFFFF]) continue; // excluded root move
+           if(!moveStack[curMove] || ply == 0 && moveMap[moveStack[curMove] & 0xFFFF]) continue; // erased, or excluded root move
 
            // make move
            if(MakeMove(&f, moveStack[curMove])) { // aborts if fails to evade existing check
@@ -1536,7 +1536,8 @@ printf("%d:%d:%d %2d. %08x %c%d%c%d %6d %6d %6d\n",ply,depth,iterDepth,curMove,m
        // put best in front
        if(bestNr > m.firstMove) {
            int bestMove = moveStack[bestNr];
-           if(bestNr == m.firstMove+1) moveStack[bestNr] = moveStack[m.firstMove]; else m.firstMove--; // swap first two, or prepend duplicat
+           if(bestNr == m.firstMove+1) moveStack[bestNr] = moveStack[m.firstMove]; // swap first two
+           else m.firstMove--, moveStack[bestNr] = 0; // or prepend and erase in original location
            moveStack[bestNr = m.firstMove] = bestMove;
        } else m.late += (m.late == bestNr); // if best already in front (or non-existing), just make sure it is not reduced