X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/d52969e8afaa19ed1acc01f4ff0bb651bf7869a7..4fa924951b55e6b428e852b62d6c8ef3464ea1dd:/lisp/play/mpuz.el diff --git a/lisp/play/mpuz.el b/lisp/play/mpuz.el index bb7cac1bce..e16bb2f1bd 100644 --- a/lisp/play/mpuz.el +++ b/lisp/play/mpuz.el @@ -1,7 +1,6 @@ ;;; mpuz.el --- multiplication puzzle for GNU Emacs -;; Copyright (C) 1990, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, -;; 2009, 2010, 2011 Free Software Foundation, Inc. +;; Copyright (C) 1990, 2001-2012 Free Software Foundation, Inc. ;; Author: Philippe Schnoebelen ;; Overhauled: Daniel Pfeiffer @@ -36,11 +35,9 @@ :prefix "mpuz-" :group 'games) -(random t) ; randomize - (defcustom mpuz-silent 'error "Set this to nil if you want dings on inputs. -t means never ding, and `error' means only ding on wrong input." +The value t means never ding, and `error' means only ding on wrong input." :type '(choice (const :tag "No" nil) (const :tag "Yes" t) (const :tag "If correct" error)) @@ -57,26 +54,26 @@ t means never ding, and `error' means only ding on wrong input." :group 'mpuz) (defface mpuz-unsolved - '((((class color)) (:foreground "red1" :bold t)) - (t (:bold t))) - "Face to use for letters to be solved." + '((default :weight bold) + (((class color)) :foreground "red1")) + "Face for letters to be solved." :group 'mpuz) (defface mpuz-solved - '((((class color)) (:foreground "green1" :bold t)) - (t (:bold t))) - "Face to use for solved digits." + '((default :weight bold) + (((class color)) :foreground "green1")) + "Face for solved digits." :group 'mpuz) (defface mpuz-trivial - '((((class color)) (:foreground "blue" :bold t)) - (t (:bold t))) - "Face to use for trivial digits solved for you." + '((default :weight bold) + (((class color)) :foreground "blue")) + "Face for trivial digits solved for you." :group 'mpuz) (defface mpuz-text - '((t (:inherit variable-pitch))) - "Face to use for text on right." + '((t :inherit variable-pitch)) + "Face for text on right." :group 'mpuz) @@ -89,33 +86,14 @@ t means never ding, and `error' means only ding on wrong input." (defvar mpuz-mode-map (let ((map (make-sparse-keymap))) - (define-key map "a" 'mpuz-try-letter) - (define-key map "b" 'mpuz-try-letter) - (define-key map "c" 'mpuz-try-letter) - (define-key map "d" 'mpuz-try-letter) - (define-key map "e" 'mpuz-try-letter) - (define-key map "f" 'mpuz-try-letter) - (define-key map "g" 'mpuz-try-letter) - (define-key map "h" 'mpuz-try-letter) - (define-key map "i" 'mpuz-try-letter) - (define-key map "j" 'mpuz-try-letter) - (define-key map "A" 'mpuz-try-letter) - (define-key map "B" 'mpuz-try-letter) - (define-key map "C" 'mpuz-try-letter) - (define-key map "D" 'mpuz-try-letter) - (define-key map "E" 'mpuz-try-letter) - (define-key map "F" 'mpuz-try-letter) - (define-key map "G" 'mpuz-try-letter) - (define-key map "H" 'mpuz-try-letter) - (define-key map "I" 'mpuz-try-letter) - (define-key map "J" 'mpuz-try-letter) + (mapc (lambda (ch) + (define-key map (char-to-string ch) 'mpuz-try-letter)) + "abcdefghijABCDEFGHIJ") (define-key map "\C-g" 'mpuz-offer-abort) (define-key map "?" 'describe-mode) map) "Local keymap to use in Mult Puzzle.") - - (defun mpuz-mode () "Multiplication puzzle mode. @@ -172,7 +150,7 @@ You may abort a game by typing \\\\[mpuz-offer-abort]." "A permutation from [0..9] to [0..9].") (defvar mpuz-letter-to-digit (make-vector 10 0) - "The inverse of mpuz-digit-to-letter.") + "The inverse of `mpuz-digit-to-letter'.") (defmacro mpuz-to-digit (letter) (list 'aref 'mpuz-letter-to-digit letter)) @@ -199,17 +177,16 @@ You may abort a game by typing \\\\[mpuz-offer-abort]." (defvar mpuz-board (make-vector 10 nil) "The board associates to any digit the list of squares where it appears.") -(defun mpuz-put-number-on-board (number row &rest l) +(defun mpuz-put-number-on-board (number row &rest columns) "Put (last digit of) NUMBER on ROW and COLUMNS of the puzzle board." (let (digit) - (while l + (dolist (column columns) (setq digit (% number 10) - number (/ number 10)) - (aset mpuz-board digit `((,row . ,(car l)) ,@(aref mpuz-board digit))) - (setq l (cdr l))))) + number (/ number 10)) + (aset mpuz-board digit `((,row . ,column) ,@(aref mpuz-board digit)))))) (defun mpuz-check-all-solved (&optional row col) - "Check whether all digits have been solved. Return t if yes." + "Check whether all digits have been solved. Return t if yes." (catch 'solved (let (A B1 B2 C D E squares) (and mpuz-solve-when-trivial @@ -295,7 +272,7 @@ You may abort a game by typing \\\\[mpuz-offer-abort]." "The general picture of the puzzle screen, as a string.") (defun mpuz-create-buffer () - "Create (or recreate) the puzzle buffer. Return it." + "Create (or recreate) the puzzle buffer. Return it." (let ((buf (get-buffer-create "*Mult Puzzle*")) (face '(face mpuz-text)) buffer-read-only) @@ -426,7 +403,7 @@ You may abort a game by typing \\\\[mpuz-offer-abort]." "Propose a digit for a letter in puzzle." (interactive) (if mpuz-in-progress - (let (letter-char digit digit-char message) + (let (letter-char digit digit-char) (setq letter-char (upcase last-command-event) digit (mpuz-to-digit (- letter-char ?A))) (cond ((mpuz-digit-solved-p digit) @@ -455,8 +432,7 @@ You may abort a game by typing \\\\[mpuz-offer-abort]." "Propose LETTER-CHAR as code for DIGIT-CHAR." (let* ((letter (- letter-char ?A)) (digit (- digit-char ?0)) - (correct-digit (mpuz-to-digit letter)) - (game mpuz-nb-completed-games)) + (correct-digit (mpuz-to-digit letter))) (cond ((mpuz-digit-solved-p correct-digit) (message "%c has already been found." (+ correct-digit ?0))) ((mpuz-digit-solved-p digit) @@ -519,5 +495,4 @@ You may abort a game by typing \\\\[mpuz-offer-abort]." (provide 'mpuz) -;; arch-tag: 2781d6ba-89e7-43b5-85c7-5d3a2e73feb1 ;;; mpuz.el ends here