Stop the AI from sorting hands in place; unskip full-game tests

Under Emacs 28 and earlier, sort relinks a list destructively, so the
variable that held the old head can end up holding only a tail.  Four
computer-player choices sorted a list that shared structure with the
player's stored hand (cl-remove-if-not returns its argument when it
removes nothing), so Bridge, Briscola, Pitch and Euchre dropped cards
from hands mid-deal and then stopped on (= nil N).  Emacs 29's sort
reorders in place, which hid the bug there.

The previous commit skipped cgt-bridge-full and cgt-trick-ext-full
unless SVG is available, but both render text in batch; they failed
on Emacs 27 for this reason, not for want of SVG.

* card-games-bridge.el (card-games-bridge--ai-play):
* card-games-trick-ext.el (card-games-tx--ai)
(card-games-trick--ai-play) <pitch>: Sort a copy, never the hand.
* test/card-games-tests.el (cgt-bridge-full, cgt-trick-ext-full):
Drop the SVG skip.
(cgt--hands-snapshot, cgt-ai-play-leaves-hands-alone): New test; it
fails without the fix on Emacs 27 and on Emacs 29.
* NEWS: Note the fix.

Assisted-by: Mentat (for Corwin; claude-opus-5-5)
This commit is contained in:
Corwin Brust 2026-10-05 15:58:25 -05:00
parent e78fe38381
commit 74af63a089
4 changed files with 57 additions and 7 deletions

View file

@ -417,7 +417,7 @@ vulnerability, and TRICKS the declarer side's trick count. Keys:
((and partner (>= (length trick) 1))
(car (sort (copy-sequence legal) (lambda (a b) (< (cdr a) (cdr b))))))
;; can win: take it with the cheapest winner
(winners (car (sort winners (lambda (a b) (< (cdr a) (cdr b))))))
(winners (car (sort (copy-sequence winners) (lambda (a b) (< (cdr a) (cdr b))))))
;; cannot win: discard lowest
(t (car (sort (copy-sequence legal) (lambda (a b) (< (cdr a) (cdr b)))))))))))