I noticed that CompareMoves() and CompareMovesGeneral() do not return 0
even when the comparison results are completely identical.

CompareMoves() returns -1 even when both rScore and rScore2 are
equal. Additionally, CompareMovesGeneral() does not return 0 when both
moves immediately end the game, or when back[0] == back[1] in the final
tie-break.

Since these functions are used as comparison functions for qsort(), they
must return 0 for equivalent elements. Furthermore, it is possible for
both CompareMoves(a, b) and CompareMoves(b, a) to return -1, which
results in an inconsistent ordering for a comparison function.

I modified them to return 0 only when the moves are completely tied,
without changing the existing move ranking or tie-break rules.

Specifically:

 - CompareMoves() now compares rScore followed by rScore2, and returns 0
   if both are equal.
 - CompareMovesGeneral() now prioritizes an immediate win as before only
   when exactly one move achieves it; if both result in an immediate
   win, it proceeds to the subsequent score comparison. It also now
   returns 0 at the end if all existing tie-breaks are equal.

NaN is not specially handled in this change. The existing assumption
that evaluation values are normal finite values remains unchanged, and
the fix only addresses the issue where the comparison function failed to
correctly handle equivalent elements.

Best regards,
-- 
TAKAHASHI Kaoru

Attachment: 0001-Fix-move-comparison-functions-to-return-equality.patch.gz
Description: application/gzip

Reply via email to