Adjustable AI difficulty, and fix red-on-red alternating-colour builds

* cg-core.el (cg-ai-level): new difficulty defcustom.  (cg-red-suit-p):
return a normalised boolean so two red suits compare equal by colour --
diamond and heart were wrongly treated as opposite colours, letting a red
card build on another red card in the alternating-colour games.
* cg-crapette.el (cg-crap--ai-greedy-move, cg-crap--ai-play): honour easy
/ normal / hard.
* cg-trick.el (cg-trick--run): easy plays a random legal card.
* card-games.el (card-game): clickable AI-level control.
(card-game--cycle-ai, card-games-set-ai-level): change it.
* test/card-games-tests.el: cgt-red-suit-boolean, cgt-ai-level-easy-crapette;
bind cg-ai-level in cgt-crap-ai-enabling.
* NEWS.
This commit is contained in:
Corwin Brust 2026-07-01 11:40:55 -05:00
parent 9af486526d
commit e816cc0551
6 changed files with 108 additions and 14 deletions

View file

@ -394,7 +394,11 @@
"Play a whole hand with AI for every seat (used by tests)."
(while (not (cg-trick--hand-over-p game))
(let ((seat (cg-get game :turn)))
(cg-trick--play game seat (cg-trick--ai-play game seat))))
(cg-trick--play game seat
(if (eq cg-ai-level 'easy)
(let ((moves (cg-trick--legal-moves game seat)))
(nth (random (length moves)) moves))
(cg-trick--ai-play game seat)))))
(cg-trick--score-hand game))
;;;; New-game / hand lifecycle