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:
parent
9af486526d
commit
e816cc0551
6 changed files with 108 additions and 14 deletions
|
|
@ -134,6 +134,19 @@
|
|||
"Registry of playable games.
|
||||
Each entry is (NAME COMMAND DESCRIPTION); `card-game' lists them.")
|
||||
|
||||
(defun card-game--cycle-ai (_button)
|
||||
"Cycle the AI difficulty (`cg-ai-level') and refresh the chooser."
|
||||
(setq cg-ai-level (pcase cg-ai-level ('easy 'normal) ('normal 'hard) (_ 'easy)))
|
||||
(card-game))
|
||||
|
||||
;;;###autoload
|
||||
(defun card-games-set-ai-level (level)
|
||||
"Set the computer-opponent difficulty to LEVEL (easy, normal, or hard)."
|
||||
(interactive
|
||||
(list (intern (completing-read "AI level: " '("easy" "normal" "hard") nil t))))
|
||||
(setq cg-ai-level level)
|
||||
(message "AI level: %s" level))
|
||||
|
||||
(defun card-game--launch (button)
|
||||
"Start the game whose command is stored on BUTTON."
|
||||
(let ((cmd (button-get button 'card-game-command)))
|
||||
|
|
@ -169,8 +182,15 @@ Press RET (or click) on a game to start it."
|
|||
(erase-buffer)
|
||||
(insert (propertize " Card Games for Emacs\n" 'face 'bold))
|
||||
(insert (propertize
|
||||
" Choose a game with RET or the mouse. q to quit.\n\n"
|
||||
" Choose a game with RET or the mouse. q to quit.\n"
|
||||
'face 'shadow))
|
||||
(insert " AI opponents: ")
|
||||
(insert-text-button
|
||||
(symbol-name cg-ai-level)
|
||||
'face 'link
|
||||
'help-echo "Click to change the AI difficulty (easy/normal/hard)"
|
||||
'action #'card-game--cycle-ai)
|
||||
(insert (propertize " (click to cycle easy/normal/hard)\n\n" 'face 'shadow))
|
||||
(dolist (g card-games-list)
|
||||
(insert " ")
|
||||
(insert-text-button
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue