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:
parent
e78fe38381
commit
74af63a089
4 changed files with 57 additions and 7 deletions
|
|
@ -98,9 +98,9 @@ POWERFN, LEDFN rank cards; VALUEFN gives a card's point worth."
|
|||
trump powerfn ledfn))
|
||||
(push c winners) (push c losers)))
|
||||
(if winners
|
||||
(car (sort winners (lambda (a b) (< (funcall powerfn a trump led)
|
||||
(car (sort (copy-sequence winners) (lambda (a b) (< (funcall powerfn a trump led)
|
||||
(funcall powerfn b trump led)))))
|
||||
(car (sort (or losers legal)
|
||||
(car (sort (copy-sequence (or losers legal))
|
||||
(lambda (a b) (< (funcall valuefn a) (funcall valuefn b))))))))))
|
||||
|
||||
(defun card-games-tx--plain-led (card _trump) "Return CARD's suit (the plain led suit)." (car card))
|
||||
|
|
@ -236,8 +236,8 @@ SEAT plays CARD as usual once trump is fixed."
|
|||
(dotimes (s 4)
|
||||
(let ((v (card-games-pitch--suit-strength game seat s)))
|
||||
(when (> v bestv) (setq bestv v best s))))
|
||||
(car (sort (cl-remove-if-not (lambda (c) (= (car c) best))
|
||||
(card-games-trick--hand game seat))
|
||||
(car (sort (copy-sequence (cl-remove-if-not (lambda (c) (= (car c) best))
|
||||
(card-games-trick--hand game seat)))
|
||||
(lambda (a b) (> (cdr a) (cdr b))))))
|
||||
(card-games-tx--ai game seat #'card-games-pitch--power #'card-games-tx--plain-led
|
||||
(lambda (c) (card-games-pitch--pip (cdr c))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue