case PH_NONCAPTURES:
lastMove = generate_noncaptures(pos, moves);
score_noncaptures();
- sort_moves(moves, lastMove);
+ sort_moves(moves, lastMove, &lastGoodNonCapture);
return;
case PH_BAD_CAPTURES:
Move m;
Piece piece;
Square from, to;
+ int hs;
for (MoveStack* cur = moves; cur != lastMove; cur++)
{
from = move_from(m);
to = move_to(m);
piece = pos.piece_on(from);
- cur->score = H.move_ordering_score(piece, to);
+ hs = H.move_ordering_score(piece, to);
+
+ // Ensure history has always highest priority
+ if (hs > 0)
+ hs += 10000;
+
+ // Gain table based scoring
+ cur->score = hs + 16 * H.gain(piece, to);
}
}
break;
case PH_NONCAPTURES:
+
+ // Sort negative scored moves only when we get there
+ if (curMove == lastGoodNonCapture)
+ insertion_sort(lastGoodNonCapture, lastMove);
+
move = (curMove++)->move;
if ( move != ttMoves[0].move
&& move != ttMoves[1].move