1992-05-30 22:12:04 +00:00
|
|
|
|
;;; mpuz.el --- multiplication puzzle for GNU Emacs
|
|
|
|
|
|
2013-01-01 09:11:05 +00:00
|
|
|
|
;; Copyright (C) 1990, 2001-2013 Free Software Foundation, Inc.
|
1992-07-22 01:53:42 +00:00
|
|
|
|
|
1997-09-21 12:34:40 +00:00
|
|
|
|
;; Author: Philippe Schnoebelen <phs@lsv.ens-cachan.fr>
|
2002-03-08 08:11:21 +00:00
|
|
|
|
;; Overhauled: Daniel Pfeiffer <occitan@esperanto.org>
|
1992-07-16 04:23:17 +00:00
|
|
|
|
;; Keywords: games
|
|
|
|
|
|
1990-12-19 18:11:55 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1994-04-07 20:30:18 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1994-04-07 20:30:18 +00:00
|
|
|
|
|
1990-12-19 18:11:55 +00:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
1994-04-07 20:30:18 +00:00
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
1993-03-22 05:42:35 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2002-03-08 08:11:21 +00:00
|
|
|
|
;; `M-x mpuz' generates a random multiplication puzzle. This is a
|
|
|
|
|
;; multiplication example in which each digit has been consistently replaced
|
|
|
|
|
;; with some letter. Your job is to reconstruct the original digits. Type
|
|
|
|
|
;; `?' while the mode is active for detailed help.
|
1993-03-22 05:42:35 +00:00
|
|
|
|
|
1992-07-16 04:23:17 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
1998-04-05 16:14:58 +00:00
|
|
|
|
(defgroup mpuz nil
|
|
|
|
|
"Multiplication puzzle."
|
|
|
|
|
:prefix "mpuz-"
|
|
|
|
|
:group 'games)
|
|
|
|
|
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(defcustom mpuz-silent 'error
|
2009-09-04 07:00:22 +00:00
|
|
|
|
"Set this to nil if you want dings on inputs.
|
2011-04-21 12:06:01 +00:00
|
|
|
|
The value t means never ding, and `error' means only ding on wrong input."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
:type '(choice (const :tag "No" nil)
|
|
|
|
|
(const :tag "Yes" t)
|
|
|
|
|
(const :tag "If correct" error))
|
|
|
|
|
:group 'mpuz)
|
|
|
|
|
|
|
|
|
|
(defcustom mpuz-solve-when-trivial t
|
2009-09-04 07:00:22 +00:00
|
|
|
|
"Solve any row that can be trivially calculated from what you've found."
|
1998-04-05 16:14:58 +00:00
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'mpuz)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(defcustom mpuz-allow-double-multiplicator nil
|
2009-09-04 07:00:22 +00:00
|
|
|
|
"Allow 2nd factors like 33 or 77."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'mpuz)
|
|
|
|
|
|
2005-06-10 11:38:27 +00:00
|
|
|
|
(defface mpuz-unsolved
|
Face cleanups. Remove some uses of old-style face spec and :bold/:italic.
* faces.el (set-face-attribute): Doc fix.
(modify-face): Don't use :bold and :italic.
(error, warning, success): Tweak definitions.
* cus-edit.el (custom-modified, custom-invalid, custom-rogue)
(custom-modified, custom-set, custom-changed, custom-themed)
(custom-saved, custom-button, custom-button-mouse)
(custom-button-pressed, custom-state, custom-comment-tag)
(custom-variable-tag, custom-group-tag-1, custom-group-tag)
(custom-group-subtitle): Use new-style face specs.
(custom-invalid-face, custom-rogue-face, custom-modified-face)
(custom-set-face, custom-changed-face, custom-saved-face)
(custom-button-face, custom-button-pressed-face)
(custom-documentation-face, custom-state-face)
(custom-comment-face, custom-comment-tag-face)
(custom-variable-tag-face, custom-variable-button-face)
(custom-face-tag-face, custom-group-tag-face-1)
(custom-group-tag-face): Remove obsolete face alias.
* epa.el (epa-validity-high, epa-validity-medium)
(epa-validity-low, epa-mark, epa-field-name, epa-string)
(epa-field-name, epa-field-body):
* font-lock.el (font-lock-comment-face, font-lock-string-face)
(font-lock-keyword-face, font-lock-builtin-face)
(font-lock-function-name-face, font-lock-variable-name-face)
(font-lock-type-face, font-lock-constant-face):
* ido.el (ido-first-match, ido-only-match, ido-subdir)
(ido-virtual, ido-indicator, ido-incomplete-regexp):
* speedbar.el (speedbar-button-face, speedbar-file-face)
(speedbar-directory-face, speedbar-tag-face)
(speedbar-selected-face, speedbar-highlight-face)
(speedbar-separator-face):
* whitespace.el (whitespace-newline, whitespace-space)
(whitespace-hspace, whitespace-tab, whitespace-trailing)
(whitespace-line, whitespace-space-before-tab)
(whitespace-space-after-tab, whitespace-indentation)
(whitespace-empty):
* emulation/cua-base.el (cua-global-mark):
* eshell/em-prompt.el (eshell-prompt):
* net/newst-plainview.el (newsticker-new-item-face)
(newsticker-old-item-face, newsticker-immortal-item-face)
(newsticker-obsolete-item-face, newsticker-date-face)
(newsticker-statistics-face, newsticker-default-face):
* net/newst-reader.el (newsticker-feed-face)
(newsticker-extra-face, newsticker-enclosure-face):
* net/newst-treeview.el (newsticker-treeview-face)
(newsticker-treeview-new-face, newsticker-treeview-old-face)
(newsticker-treeview-immortal-face)
(newsticker-treeview-obsolete-face)
(newsticker-treeview-selection-face):
* net/rcirc.el (rcirc-my-nick, rcirc-other-nick)
(rcirc-bright-nick, rcirc-server, rcirc-timestamp)
(rcirc-nick-in-message, rcirc-nick-in-message-full-line)
(rcirc-prompt, rcirc-track-keyword, rcirc-url, rcirc-keyword):
* nxml/nxml-outln.el (nxml-heading, nxml-outline-indicator)
(nxml-outline-active-indicator, nxml-outline-ellipsis):
* play/mpuz.el (mpuz-unsolved, mpuz-solved, mpuz-trivial)
(mpuz-text):
* progmodes/vera-mode.el (vera-font-lock-number)
(vera-font-lock-function, vera-font-lock-interface):
* textmodes/table.el (table-cell): Use new-style face specs, and
don't use the old :bold and :italic attributes.
* erc-button.el (erc-button):
* erc-goodies.el (erc-bold-face, erc-inverse-face)
(erc-underline-face, fg:erc-color-*):
* erc-match.el (erc-current-nick-face, erc-dangerous-host-face)
(erc-pal-face, erc-fool-face, erc-keyword-face):
* erc-stamp.el (erc-timestamp-face): Likewise.
* erc.el (erc-direct-msg-face, erc-header-line, erc-input-face)
(erc-command-indicator-face, erc-notice-face, erc-action-face)
(erc-error-face, erc-my-nick-face, erc-nick-default-face)
(erc-nick-msg-face): Use new-style face specs, and avoid :bold.
* progmodes/ebrowse.el (ebrowse-tree-mark, ebrowse-root-class)
(ebrowse-member-attribute, ebrowse-default, ebrowse-file-name)
(ebrowse-member-class, ebrowse-progress): Likewise.
(ebrowse-tree-mark-face, ebrowse-root-class-face)
(ebrowse-file-name-face, ebrowse-default-face)
(ebrowse-member-attribute-face, ebrowse-member-class-face)
(ebrowse-progress-face): Remove obsolete faces.
* progmodes/flymake.el (flymake-errline, flymake-warnline):
Inherit from error and warning faces respectively.
* textmodes/flyspell.el (flyspell-incorrect, flyspell-duplicate):
Likewise.
(flyspell-incorrect-face, flyspell-duplicate-face): Remove
obsolete aliases.
* display.texi (Face Attributes): Font family does not accept
wildcards. De-document obsolete :bold and :italic attributes.
(Defining Faces): Use new-style face spec format.
2012-06-08 16:39:49 +00:00
|
|
|
|
'((default :weight bold)
|
|
|
|
|
(((class color)) :foreground "red1"))
|
|
|
|
|
"Face for letters to be solved."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
:group 'mpuz)
|
|
|
|
|
|
2005-06-10 11:38:27 +00:00
|
|
|
|
(defface mpuz-solved
|
Face cleanups. Remove some uses of old-style face spec and :bold/:italic.
* faces.el (set-face-attribute): Doc fix.
(modify-face): Don't use :bold and :italic.
(error, warning, success): Tweak definitions.
* cus-edit.el (custom-modified, custom-invalid, custom-rogue)
(custom-modified, custom-set, custom-changed, custom-themed)
(custom-saved, custom-button, custom-button-mouse)
(custom-button-pressed, custom-state, custom-comment-tag)
(custom-variable-tag, custom-group-tag-1, custom-group-tag)
(custom-group-subtitle): Use new-style face specs.
(custom-invalid-face, custom-rogue-face, custom-modified-face)
(custom-set-face, custom-changed-face, custom-saved-face)
(custom-button-face, custom-button-pressed-face)
(custom-documentation-face, custom-state-face)
(custom-comment-face, custom-comment-tag-face)
(custom-variable-tag-face, custom-variable-button-face)
(custom-face-tag-face, custom-group-tag-face-1)
(custom-group-tag-face): Remove obsolete face alias.
* epa.el (epa-validity-high, epa-validity-medium)
(epa-validity-low, epa-mark, epa-field-name, epa-string)
(epa-field-name, epa-field-body):
* font-lock.el (font-lock-comment-face, font-lock-string-face)
(font-lock-keyword-face, font-lock-builtin-face)
(font-lock-function-name-face, font-lock-variable-name-face)
(font-lock-type-face, font-lock-constant-face):
* ido.el (ido-first-match, ido-only-match, ido-subdir)
(ido-virtual, ido-indicator, ido-incomplete-regexp):
* speedbar.el (speedbar-button-face, speedbar-file-face)
(speedbar-directory-face, speedbar-tag-face)
(speedbar-selected-face, speedbar-highlight-face)
(speedbar-separator-face):
* whitespace.el (whitespace-newline, whitespace-space)
(whitespace-hspace, whitespace-tab, whitespace-trailing)
(whitespace-line, whitespace-space-before-tab)
(whitespace-space-after-tab, whitespace-indentation)
(whitespace-empty):
* emulation/cua-base.el (cua-global-mark):
* eshell/em-prompt.el (eshell-prompt):
* net/newst-plainview.el (newsticker-new-item-face)
(newsticker-old-item-face, newsticker-immortal-item-face)
(newsticker-obsolete-item-face, newsticker-date-face)
(newsticker-statistics-face, newsticker-default-face):
* net/newst-reader.el (newsticker-feed-face)
(newsticker-extra-face, newsticker-enclosure-face):
* net/newst-treeview.el (newsticker-treeview-face)
(newsticker-treeview-new-face, newsticker-treeview-old-face)
(newsticker-treeview-immortal-face)
(newsticker-treeview-obsolete-face)
(newsticker-treeview-selection-face):
* net/rcirc.el (rcirc-my-nick, rcirc-other-nick)
(rcirc-bright-nick, rcirc-server, rcirc-timestamp)
(rcirc-nick-in-message, rcirc-nick-in-message-full-line)
(rcirc-prompt, rcirc-track-keyword, rcirc-url, rcirc-keyword):
* nxml/nxml-outln.el (nxml-heading, nxml-outline-indicator)
(nxml-outline-active-indicator, nxml-outline-ellipsis):
* play/mpuz.el (mpuz-unsolved, mpuz-solved, mpuz-trivial)
(mpuz-text):
* progmodes/vera-mode.el (vera-font-lock-number)
(vera-font-lock-function, vera-font-lock-interface):
* textmodes/table.el (table-cell): Use new-style face specs, and
don't use the old :bold and :italic attributes.
* erc-button.el (erc-button):
* erc-goodies.el (erc-bold-face, erc-inverse-face)
(erc-underline-face, fg:erc-color-*):
* erc-match.el (erc-current-nick-face, erc-dangerous-host-face)
(erc-pal-face, erc-fool-face, erc-keyword-face):
* erc-stamp.el (erc-timestamp-face): Likewise.
* erc.el (erc-direct-msg-face, erc-header-line, erc-input-face)
(erc-command-indicator-face, erc-notice-face, erc-action-face)
(erc-error-face, erc-my-nick-face, erc-nick-default-face)
(erc-nick-msg-face): Use new-style face specs, and avoid :bold.
* progmodes/ebrowse.el (ebrowse-tree-mark, ebrowse-root-class)
(ebrowse-member-attribute, ebrowse-default, ebrowse-file-name)
(ebrowse-member-class, ebrowse-progress): Likewise.
(ebrowse-tree-mark-face, ebrowse-root-class-face)
(ebrowse-file-name-face, ebrowse-default-face)
(ebrowse-member-attribute-face, ebrowse-member-class-face)
(ebrowse-progress-face): Remove obsolete faces.
* progmodes/flymake.el (flymake-errline, flymake-warnline):
Inherit from error and warning faces respectively.
* textmodes/flyspell.el (flyspell-incorrect, flyspell-duplicate):
Likewise.
(flyspell-incorrect-face, flyspell-duplicate-face): Remove
obsolete aliases.
* display.texi (Face Attributes): Font family does not accept
wildcards. De-document obsolete :bold and :italic attributes.
(Defining Faces): Use new-style face spec format.
2012-06-08 16:39:49 +00:00
|
|
|
|
'((default :weight bold)
|
|
|
|
|
(((class color)) :foreground "green1"))
|
|
|
|
|
"Face for solved digits."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
:group 'mpuz)
|
|
|
|
|
|
2005-06-10 11:38:27 +00:00
|
|
|
|
(defface mpuz-trivial
|
Face cleanups. Remove some uses of old-style face spec and :bold/:italic.
* faces.el (set-face-attribute): Doc fix.
(modify-face): Don't use :bold and :italic.
(error, warning, success): Tweak definitions.
* cus-edit.el (custom-modified, custom-invalid, custom-rogue)
(custom-modified, custom-set, custom-changed, custom-themed)
(custom-saved, custom-button, custom-button-mouse)
(custom-button-pressed, custom-state, custom-comment-tag)
(custom-variable-tag, custom-group-tag-1, custom-group-tag)
(custom-group-subtitle): Use new-style face specs.
(custom-invalid-face, custom-rogue-face, custom-modified-face)
(custom-set-face, custom-changed-face, custom-saved-face)
(custom-button-face, custom-button-pressed-face)
(custom-documentation-face, custom-state-face)
(custom-comment-face, custom-comment-tag-face)
(custom-variable-tag-face, custom-variable-button-face)
(custom-face-tag-face, custom-group-tag-face-1)
(custom-group-tag-face): Remove obsolete face alias.
* epa.el (epa-validity-high, epa-validity-medium)
(epa-validity-low, epa-mark, epa-field-name, epa-string)
(epa-field-name, epa-field-body):
* font-lock.el (font-lock-comment-face, font-lock-string-face)
(font-lock-keyword-face, font-lock-builtin-face)
(font-lock-function-name-face, font-lock-variable-name-face)
(font-lock-type-face, font-lock-constant-face):
* ido.el (ido-first-match, ido-only-match, ido-subdir)
(ido-virtual, ido-indicator, ido-incomplete-regexp):
* speedbar.el (speedbar-button-face, speedbar-file-face)
(speedbar-directory-face, speedbar-tag-face)
(speedbar-selected-face, speedbar-highlight-face)
(speedbar-separator-face):
* whitespace.el (whitespace-newline, whitespace-space)
(whitespace-hspace, whitespace-tab, whitespace-trailing)
(whitespace-line, whitespace-space-before-tab)
(whitespace-space-after-tab, whitespace-indentation)
(whitespace-empty):
* emulation/cua-base.el (cua-global-mark):
* eshell/em-prompt.el (eshell-prompt):
* net/newst-plainview.el (newsticker-new-item-face)
(newsticker-old-item-face, newsticker-immortal-item-face)
(newsticker-obsolete-item-face, newsticker-date-face)
(newsticker-statistics-face, newsticker-default-face):
* net/newst-reader.el (newsticker-feed-face)
(newsticker-extra-face, newsticker-enclosure-face):
* net/newst-treeview.el (newsticker-treeview-face)
(newsticker-treeview-new-face, newsticker-treeview-old-face)
(newsticker-treeview-immortal-face)
(newsticker-treeview-obsolete-face)
(newsticker-treeview-selection-face):
* net/rcirc.el (rcirc-my-nick, rcirc-other-nick)
(rcirc-bright-nick, rcirc-server, rcirc-timestamp)
(rcirc-nick-in-message, rcirc-nick-in-message-full-line)
(rcirc-prompt, rcirc-track-keyword, rcirc-url, rcirc-keyword):
* nxml/nxml-outln.el (nxml-heading, nxml-outline-indicator)
(nxml-outline-active-indicator, nxml-outline-ellipsis):
* play/mpuz.el (mpuz-unsolved, mpuz-solved, mpuz-trivial)
(mpuz-text):
* progmodes/vera-mode.el (vera-font-lock-number)
(vera-font-lock-function, vera-font-lock-interface):
* textmodes/table.el (table-cell): Use new-style face specs, and
don't use the old :bold and :italic attributes.
* erc-button.el (erc-button):
* erc-goodies.el (erc-bold-face, erc-inverse-face)
(erc-underline-face, fg:erc-color-*):
* erc-match.el (erc-current-nick-face, erc-dangerous-host-face)
(erc-pal-face, erc-fool-face, erc-keyword-face):
* erc-stamp.el (erc-timestamp-face): Likewise.
* erc.el (erc-direct-msg-face, erc-header-line, erc-input-face)
(erc-command-indicator-face, erc-notice-face, erc-action-face)
(erc-error-face, erc-my-nick-face, erc-nick-default-face)
(erc-nick-msg-face): Use new-style face specs, and avoid :bold.
* progmodes/ebrowse.el (ebrowse-tree-mark, ebrowse-root-class)
(ebrowse-member-attribute, ebrowse-default, ebrowse-file-name)
(ebrowse-member-class, ebrowse-progress): Likewise.
(ebrowse-tree-mark-face, ebrowse-root-class-face)
(ebrowse-file-name-face, ebrowse-default-face)
(ebrowse-member-attribute-face, ebrowse-member-class-face)
(ebrowse-progress-face): Remove obsolete faces.
* progmodes/flymake.el (flymake-errline, flymake-warnline):
Inherit from error and warning faces respectively.
* textmodes/flyspell.el (flyspell-incorrect, flyspell-duplicate):
Likewise.
(flyspell-incorrect-face, flyspell-duplicate-face): Remove
obsolete aliases.
* display.texi (Face Attributes): Font family does not accept
wildcards. De-document obsolete :bold and :italic attributes.
(Defining Faces): Use new-style face spec format.
2012-06-08 16:39:49 +00:00
|
|
|
|
'((default :weight bold)
|
|
|
|
|
(((class color)) :foreground "blue"))
|
|
|
|
|
"Face for trivial digits solved for you."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
:group 'mpuz)
|
|
|
|
|
|
2005-06-10 11:38:27 +00:00
|
|
|
|
(defface mpuz-text
|
Face cleanups. Remove some uses of old-style face spec and :bold/:italic.
* faces.el (set-face-attribute): Doc fix.
(modify-face): Don't use :bold and :italic.
(error, warning, success): Tweak definitions.
* cus-edit.el (custom-modified, custom-invalid, custom-rogue)
(custom-modified, custom-set, custom-changed, custom-themed)
(custom-saved, custom-button, custom-button-mouse)
(custom-button-pressed, custom-state, custom-comment-tag)
(custom-variable-tag, custom-group-tag-1, custom-group-tag)
(custom-group-subtitle): Use new-style face specs.
(custom-invalid-face, custom-rogue-face, custom-modified-face)
(custom-set-face, custom-changed-face, custom-saved-face)
(custom-button-face, custom-button-pressed-face)
(custom-documentation-face, custom-state-face)
(custom-comment-face, custom-comment-tag-face)
(custom-variable-tag-face, custom-variable-button-face)
(custom-face-tag-face, custom-group-tag-face-1)
(custom-group-tag-face): Remove obsolete face alias.
* epa.el (epa-validity-high, epa-validity-medium)
(epa-validity-low, epa-mark, epa-field-name, epa-string)
(epa-field-name, epa-field-body):
* font-lock.el (font-lock-comment-face, font-lock-string-face)
(font-lock-keyword-face, font-lock-builtin-face)
(font-lock-function-name-face, font-lock-variable-name-face)
(font-lock-type-face, font-lock-constant-face):
* ido.el (ido-first-match, ido-only-match, ido-subdir)
(ido-virtual, ido-indicator, ido-incomplete-regexp):
* speedbar.el (speedbar-button-face, speedbar-file-face)
(speedbar-directory-face, speedbar-tag-face)
(speedbar-selected-face, speedbar-highlight-face)
(speedbar-separator-face):
* whitespace.el (whitespace-newline, whitespace-space)
(whitespace-hspace, whitespace-tab, whitespace-trailing)
(whitespace-line, whitespace-space-before-tab)
(whitespace-space-after-tab, whitespace-indentation)
(whitespace-empty):
* emulation/cua-base.el (cua-global-mark):
* eshell/em-prompt.el (eshell-prompt):
* net/newst-plainview.el (newsticker-new-item-face)
(newsticker-old-item-face, newsticker-immortal-item-face)
(newsticker-obsolete-item-face, newsticker-date-face)
(newsticker-statistics-face, newsticker-default-face):
* net/newst-reader.el (newsticker-feed-face)
(newsticker-extra-face, newsticker-enclosure-face):
* net/newst-treeview.el (newsticker-treeview-face)
(newsticker-treeview-new-face, newsticker-treeview-old-face)
(newsticker-treeview-immortal-face)
(newsticker-treeview-obsolete-face)
(newsticker-treeview-selection-face):
* net/rcirc.el (rcirc-my-nick, rcirc-other-nick)
(rcirc-bright-nick, rcirc-server, rcirc-timestamp)
(rcirc-nick-in-message, rcirc-nick-in-message-full-line)
(rcirc-prompt, rcirc-track-keyword, rcirc-url, rcirc-keyword):
* nxml/nxml-outln.el (nxml-heading, nxml-outline-indicator)
(nxml-outline-active-indicator, nxml-outline-ellipsis):
* play/mpuz.el (mpuz-unsolved, mpuz-solved, mpuz-trivial)
(mpuz-text):
* progmodes/vera-mode.el (vera-font-lock-number)
(vera-font-lock-function, vera-font-lock-interface):
* textmodes/table.el (table-cell): Use new-style face specs, and
don't use the old :bold and :italic attributes.
* erc-button.el (erc-button):
* erc-goodies.el (erc-bold-face, erc-inverse-face)
(erc-underline-face, fg:erc-color-*):
* erc-match.el (erc-current-nick-face, erc-dangerous-host-face)
(erc-pal-face, erc-fool-face, erc-keyword-face):
* erc-stamp.el (erc-timestamp-face): Likewise.
* erc.el (erc-direct-msg-face, erc-header-line, erc-input-face)
(erc-command-indicator-face, erc-notice-face, erc-action-face)
(erc-error-face, erc-my-nick-face, erc-nick-default-face)
(erc-nick-msg-face): Use new-style face specs, and avoid :bold.
* progmodes/ebrowse.el (ebrowse-tree-mark, ebrowse-root-class)
(ebrowse-member-attribute, ebrowse-default, ebrowse-file-name)
(ebrowse-member-class, ebrowse-progress): Likewise.
(ebrowse-tree-mark-face, ebrowse-root-class-face)
(ebrowse-file-name-face, ebrowse-default-face)
(ebrowse-member-attribute-face, ebrowse-member-class-face)
(ebrowse-progress-face): Remove obsolete faces.
* progmodes/flymake.el (flymake-errline, flymake-warnline):
Inherit from error and warning faces respectively.
* textmodes/flyspell.el (flyspell-incorrect, flyspell-duplicate):
Likewise.
(flyspell-incorrect-face, flyspell-duplicate-face): Remove
obsolete aliases.
* display.texi (Face Attributes): Font family does not accept
wildcards. De-document obsolete :bold and :italic attributes.
(Defining Faces): Use new-style face spec format.
2012-06-08 16:39:49 +00:00
|
|
|
|
'((t :inherit variable-pitch))
|
|
|
|
|
"Face for text on right."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
:group 'mpuz)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Mpuz mode and keymaps
|
|
|
|
|
;;----------------------
|
1998-04-05 16:14:58 +00:00
|
|
|
|
(defcustom mpuz-mode-hook nil
|
|
|
|
|
"Hook to run upon entry to mpuz."
|
|
|
|
|
:type 'hook
|
|
|
|
|
:group 'mpuz)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
2010-10-10 23:12:30 +00:00
|
|
|
|
(defvar mpuz-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2011-04-21 12:06:01 +00:00
|
|
|
|
(mapc (lambda (ch)
|
|
|
|
|
(define-key map (char-to-string ch) 'mpuz-try-letter))
|
|
|
|
|
"abcdefghijABCDEFGHIJ")
|
2010-10-10 23:12:30 +00:00
|
|
|
|
(define-key map "\C-g" 'mpuz-offer-abort)
|
|
|
|
|
(define-key map "?" 'describe-mode)
|
|
|
|
|
map)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
"Local keymap to use in Mult Puzzle.")
|
|
|
|
|
|
2013-09-11 03:31:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-derived-mode mpuz-mode fundamental-mode "Mult Puzzle"
|
1992-09-26 21:27:08 +00:00
|
|
|
|
"Multiplication puzzle mode.
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
1991-04-10 15:06:00 +00:00
|
|
|
|
You have to guess which letters stand for which digits in the
|
1992-09-26 21:27:08 +00:00
|
|
|
|
multiplication displayed inside the `*Mult Puzzle*' buffer.
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
1992-09-26 21:27:08 +00:00
|
|
|
|
You may enter a guess for a letter's value by typing first the letter,
|
2002-03-08 08:11:21 +00:00
|
|
|
|
then the digit. Thus, to guess that A=3, type `A 3'.
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
1992-09-26 21:27:08 +00:00
|
|
|
|
To leave the game to do other editing work, just switch buffers.
|
|
|
|
|
Then you may resume the game with M-x mpuz.
|
|
|
|
|
You may abort a game by typing \\<mpuz-mode-map>\\[mpuz-offer-abort]."
|
2013-09-11 03:31:56 +00:00
|
|
|
|
(setq tab-width 30))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Some variables for statistics
|
|
|
|
|
;;------------------------------
|
|
|
|
|
(defvar mpuz-nb-errors 0
|
1991-04-10 15:06:00 +00:00
|
|
|
|
"Number of errors made in current game.")
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defvar mpuz-nb-completed-games 0
|
1991-04-10 15:06:00 +00:00
|
|
|
|
"Number of games completed.")
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defvar mpuz-nb-cumulated-errors 0
|
|
|
|
|
"Number of errors made in previous games.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Some variables for game tracking
|
|
|
|
|
;;---------------------------------
|
|
|
|
|
(defvar mpuz-in-progress nil
|
|
|
|
|
"True if a game is currently in progress.")
|
|
|
|
|
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(defvar mpuz-found-digits (make-bool-vector 10 nil)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
"A vector recording which digits have been decrypted.")
|
|
|
|
|
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(defvar mpuz-trivial-digits (make-bool-vector 10 nil)
|
|
|
|
|
"A vector recording which digits have been solved for you.")
|
|
|
|
|
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(defmacro mpuz-digit-solved-p (digit)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
`(or (aref mpuz-found-digits ,digit)
|
|
|
|
|
(aref mpuz-trivial-digits ,digit)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; A puzzle uses a permutation of [0..9] into itself.
|
|
|
|
|
;; We use both the permutation and its inverse.
|
|
|
|
|
;;---------------------------------------------------
|
|
|
|
|
(defvar mpuz-digit-to-letter (make-vector 10 0)
|
|
|
|
|
"A permutation from [0..9] to [0..9].")
|
|
|
|
|
|
|
|
|
|
(defvar mpuz-letter-to-digit (make-vector 10 0)
|
2011-04-21 12:06:01 +00:00
|
|
|
|
"The inverse of `mpuz-digit-to-letter'.")
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defmacro mpuz-to-digit (letter)
|
|
|
|
|
(list 'aref 'mpuz-letter-to-digit letter))
|
|
|
|
|
|
|
|
|
|
(defmacro mpuz-to-letter (digit)
|
|
|
|
|
(list 'aref 'mpuz-digit-to-letter digit))
|
|
|
|
|
|
|
|
|
|
(defun mpuz-build-random-perm ()
|
|
|
|
|
"Initialize puzzle coding with a random permutation."
|
|
|
|
|
(let ((letters (list 0 1 2 3 4 5 6 7 8 9)) ; new cons cells, because of delq
|
|
|
|
|
(index 10)
|
|
|
|
|
elem)
|
|
|
|
|
(while letters
|
1993-08-01 20:50:07 +00:00
|
|
|
|
(setq elem (nth (random index) letters)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
letters (delq elem letters)
|
|
|
|
|
index (1- index))
|
|
|
|
|
(aset mpuz-digit-to-letter index elem)
|
|
|
|
|
(aset mpuz-letter-to-digit elem index))))
|
|
|
|
|
|
|
|
|
|
|
1993-06-09 11:59:12 +00:00
|
|
|
|
;; A puzzle also uses a board displaying a multiplication.
|
1990-12-19 18:11:55 +00:00
|
|
|
|
;; Every digit appears in the board, crypted or not.
|
|
|
|
|
;;------------------------------------------------------
|
|
|
|
|
(defvar mpuz-board (make-vector 10 nil)
|
1993-07-29 23:21:30 +00:00
|
|
|
|
"The board associates to any digit the list of squares where it appears.")
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
2011-04-21 12:06:01 +00:00
|
|
|
|
(defun mpuz-put-number-on-board (number row &rest columns)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
"Put (last digit of) NUMBER on ROW and COLUMNS of the puzzle board."
|
|
|
|
|
(let (digit)
|
2011-04-21 12:06:01 +00:00
|
|
|
|
(dolist (column columns)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(setq digit (% number 10)
|
2011-04-21 12:06:01 +00:00
|
|
|
|
number (/ number 10))
|
|
|
|
|
(aset mpuz-board digit `((,row . ,column) ,@(aref mpuz-board digit))))))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(defun mpuz-check-all-solved (&optional row col)
|
2011-04-21 12:06:01 +00:00
|
|
|
|
"Check whether all digits have been solved. Return t if yes."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(catch 'solved
|
|
|
|
|
(let (A B1 B2 C D E squares)
|
|
|
|
|
(and mpuz-solve-when-trivial
|
|
|
|
|
(not row)
|
|
|
|
|
(while
|
|
|
|
|
(cond ((or (and (setq B1 (or B1 (mpuz-check-all-solved 4 7))
|
|
|
|
|
B2 (or B2 (mpuz-check-all-solved 4 9))
|
|
|
|
|
E (or E (mpuz-check-all-solved 10))
|
|
|
|
|
A (or A (mpuz-check-all-solved 2)))
|
|
|
|
|
B1 B2)
|
|
|
|
|
(and E (or A (and B1 B2))))
|
|
|
|
|
(mpuz-solve)
|
|
|
|
|
(mpuz-paint-board)
|
|
|
|
|
(throw 'solved t))
|
|
|
|
|
((and (setq D (or D (mpuz-check-all-solved 8))
|
|
|
|
|
C (or C (mpuz-check-all-solved 6)))
|
|
|
|
|
D (not E))
|
|
|
|
|
(mpuz-solve 10))
|
|
|
|
|
((and E (not (eq C D)))
|
|
|
|
|
(mpuz-solve (if D 6 8)))
|
|
|
|
|
((and A (not (eq B2 C)))
|
|
|
|
|
(mpuz-solve (if C 4 6) (if C 9)))
|
|
|
|
|
((and A (not (eq B1 D)))
|
|
|
|
|
(mpuz-solve (if D 4 8) (if D 7)))
|
|
|
|
|
((and (not A) (or (and B2 C) (and B1 D)))
|
|
|
|
|
(mpuz-solve 2)))))
|
|
|
|
|
(mpuz-paint-board)
|
|
|
|
|
(mapc (lambda (digit)
|
|
|
|
|
(and (not (mpuz-digit-solved-p digit)) ; unsolved
|
|
|
|
|
(setq squares (aref mpuz-board digit))
|
|
|
|
|
(if row
|
|
|
|
|
(if col
|
|
|
|
|
(member (cons row col) squares)
|
|
|
|
|
(assq row squares))
|
|
|
|
|
squares) ; and appearing in the puzzle!
|
|
|
|
|
(throw 'solved nil)))
|
|
|
|
|
[0 1 2 3 4 5 6 7 8 9]))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
t))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; To build a puzzle, we take two random numbers and multiply them.
|
|
|
|
|
;; We also take a random permutation for encryption.
|
|
|
|
|
;; The random numbers are only use to see which digit appears in which square
|
|
|
|
|
;; of the board. Everything is stored in individual squares.
|
|
|
|
|
;;---------------------------------------------------------------------------
|
|
|
|
|
(defun mpuz-random-puzzle ()
|
|
|
|
|
"Draw random values to be multiplied in a puzzle."
|
|
|
|
|
(mpuz-build-random-perm)
|
|
|
|
|
(fillarray mpuz-board nil) ; erase the board
|
2002-03-08 08:11:21 +00:00
|
|
|
|
;; A,B,C,D & E, are the five rows of our multiplication.
|
|
|
|
|
;; Choose random values, discarding cases with leading zeros in C or D.
|
2007-02-04 17:29:50 +00:00
|
|
|
|
(let* ((A (if mpuz-allow-double-multiplicator (+ 112 (random 888))
|
|
|
|
|
(+ 125 (random 875))))
|
|
|
|
|
(min (1+ (/ 999 A)))
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(B1 (+ min (random (- 10 min))))
|
|
|
|
|
B2 C D E)
|
|
|
|
|
(while (if (= B1 (setq B2 (+ min (random (- 10 min)))))
|
|
|
|
|
(not mpuz-allow-double-multiplicator)))
|
|
|
|
|
(setq C (* A B2)
|
|
|
|
|
D (* A B1)
|
|
|
|
|
E (+ C (* D 10)))
|
1996-01-05 22:21:28 +00:00
|
|
|
|
;; Individual digits are now put on their respective squares.
|
2002-03-08 08:11:21 +00:00
|
|
|
|
;; [NB: A square is a pair (row . column) of the screen.]
|
|
|
|
|
(mpuz-put-number-on-board A 2 9 7 5)
|
|
|
|
|
(mpuz-put-number-on-board (+ (* B1 10) B2) 4 9 7)
|
|
|
|
|
(mpuz-put-number-on-board C 6 9 7 5 3)
|
|
|
|
|
(mpuz-put-number-on-board D 8 7 5 3 1)
|
|
|
|
|
(mpuz-put-number-on-board E 10 9 7 5 3 1)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
;; Display
|
|
|
|
|
;;--------
|
|
|
|
|
(defconst mpuz-framework
|
|
|
|
|
"
|
|
|
|
|
. . .
|
2002-03-08 08:11:21 +00:00
|
|
|
|
Number of errors (this game): 0
|
1990-12-19 18:11:55 +00:00
|
|
|
|
x . .
|
|
|
|
|
-------
|
|
|
|
|
. . . .
|
2002-03-08 08:11:21 +00:00
|
|
|
|
Number of completed games: 0
|
1990-12-19 18:11:55 +00:00
|
|
|
|
. . . .
|
2002-03-08 08:11:21 +00:00
|
|
|
|
--------- Average number of errors: 0.00
|
1990-12-19 18:11:55 +00:00
|
|
|
|
. . . . ."
|
|
|
|
|
"The general picture of the puzzle screen, as a string.")
|
|
|
|
|
|
|
|
|
|
(defun mpuz-create-buffer ()
|
2011-04-21 12:06:01 +00:00
|
|
|
|
"Create (or recreate) the puzzle buffer. Return it."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(let ((buf (get-buffer-create "*Mult Puzzle*"))
|
2005-06-10 11:38:27 +00:00
|
|
|
|
(face '(face mpuz-text))
|
2002-03-08 08:11:21 +00:00
|
|
|
|
buffer-read-only)
|
* url-util.el (url-insert-entities-in-string):
* url-nfs.el (url-nfs-unescape):
* url-ldap.el (url-ldap):
* url-imap.el (url-imap):
* url-cid.el (url-cid-gnus, url-cid): Use with-current-buffer.
* erc.el (erc-display-line-1, erc-process-away):
* erc-truncate.el (erc-truncate-buffer-to-size):
Use with-current-buffer.
* term/ns-win.el (ns-scroll-bar-move, ns-face-at-pos):
* play/mpuz.el (mpuz-create-buffer):
* play/landmark.el (lm-prompt-for-move, lm-print-wts, lm-print-smell)
(lm-print-y,s,noise, lm-print-w0, lm-init):
* play/gomoku.el (gomoku-prompt-for-move):
* play/fortune.el (fortune-in-buffer):
* play/dissociate.el (dissociated-press):
* play/decipher.el (decipher-adjacency-list, decipher-display-regexp)
(decipher-analyze-buffer, decipher-stats-buffer,decipher-stats-buffer):
* mail/supercite.el (sc-eref-show):
* mail/smtpmail.el (smtpmail-send-it):
* mail/rmailsum.el (rmail-summary-next-labeled-message)
(rmail-summary-previous-labeled-message, rmail-summary-wipe)
(rmail-summary-undelete-many, rmail-summary-rmail-update)
(rmail-summary-goto-msg, rmail-summary-expunge)
(rmail-summary-get-new-mail, rmail-summary-search-backward)
(rmail-summary-add-label, rmail-summary-output-menu)
(rmail-summary-output-body):
* mail/rfc822.el (rfc822-addresses):
* mail/reporter.el (reporter-dump-variable, reporter-dump-state):
* mail/mailpost.el (post-mail-send-it):
* mail/hashcash.el (hashcash-generate-payment):
* mail/feedmail.el (feedmail-run-the-queue)
(feedmail-queue-send-edit-prompt-help-first)
(feedmail-send-it-immediately, feedmail-give-it-to-buffer-eater)
(feedmail-deduce-address-list):
* eshell/esh-ext.el (eshell-remote-command):
* eshell/em-unix.el (eshell-occur-mode-mouse-goto):
* emulation/viper-util.el (viper-glob-unix-files, viper-save-setting)
(viper-wildcard-to-regexp, viper-glob-mswindows-files)
(viper-save-string-in-file, viper-valid-marker):
* emulation/viper-keym.el (viper-toggle-key):
* emulation/viper-ex.el (ex-expand-filsyms, viper-get-ex-file)
(ex-edit, ex-global, ex-mark, ex-next-related-buffer, ex-quit)
(ex-get-inline-cmd-args, ex-tag, ex-command, ex-compile):
* emulation/viper-cmd.el (viper-exec-form-in-vi)
(viper-exec-form-in-emacs, viper-brac-function):
* emulation/viper.el (viper-delocalize-var):
* emulation/vip.el (vip-mode, vip-get-ex-token, vip-ex, vip-get-ex-pat)
(vip-get-ex-command, vip-get-ex-opt-gc, vip-get-ex-buffer)
(vip-get-ex-count, vip-get-ex-file, ex-edit, ex-global, ex-mark)
(ex-map, ex-unmap, ex-quit, ex-read, ex-tag, ex-command):
* emulation/vi.el (vi-switch-mode, vi-ex-cmd):
* emulation/edt.el (edt-electric-helpify):
* emulation/cua-rect.el (cua--rectangle-aux-replace):
* emulation/cua-gmrk.el (cua--insert-at-global-mark)
(cua--delete-at-global-mark, cua--copy-rectangle-to-global-mark)
(cua-indent-to-global-mark-column):
* calendar/diary-lib.el (calendar-mark-1):
* calendar/cal-hebrew.el (calendar-hebrew-mark-date-pattern):
Use with-current-buffer.
* emulation/viper.el (viper-delocalize-var): Use dolist.
2009-11-03 02:04:29 +00:00
|
|
|
|
(with-current-buffer buf
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(erase-buffer)
|
|
|
|
|
(insert mpuz-framework)
|
|
|
|
|
(set-text-properties 13 42 face)
|
|
|
|
|
(set-text-properties 79 105 face)
|
|
|
|
|
(set-text-properties 128 153 face)
|
|
|
|
|
(mpuz-paint-board)
|
|
|
|
|
(mpuz-paint-errors)
|
|
|
|
|
(mpuz-paint-statistics))
|
|
|
|
|
buf))
|
|
|
|
|
|
|
|
|
|
(defun mpuz-paint-number (n &optional eol words)
|
|
|
|
|
(end-of-line eol)
|
|
|
|
|
(let (buffer-read-only)
|
|
|
|
|
(delete-region (point)
|
|
|
|
|
(progn (backward-word (or words 1)) (point)))
|
|
|
|
|
(insert n)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defun mpuz-paint-errors ()
|
|
|
|
|
"Paint error count on the puzzle screen."
|
|
|
|
|
(mpuz-switch-to-window)
|
2009-08-21 07:40:24 +00:00
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(forward-line 2)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(mpuz-paint-number (prin1-to-string mpuz-nb-errors)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defun mpuz-paint-statistics ()
|
|
|
|
|
"Paint statistics about previous games on the puzzle screen."
|
2009-08-21 07:40:24 +00:00
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(forward-line 6)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(mpuz-paint-number (prin1-to-string mpuz-nb-completed-games))
|
|
|
|
|
(mpuz-paint-number
|
|
|
|
|
(format "%.2f"
|
|
|
|
|
(if (zerop mpuz-nb-completed-games)
|
|
|
|
|
0
|
|
|
|
|
(/ (+ 0.0 mpuz-nb-cumulated-errors)
|
|
|
|
|
mpuz-nb-completed-games)))
|
|
|
|
|
3 2))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defun mpuz-paint-board ()
|
|
|
|
|
"Paint board situation on the puzzle screen."
|
|
|
|
|
(mpuz-switch-to-window)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(mapc 'mpuz-paint-digit [0 1 2 3 4 5 6 7 8 9])
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(goto-char (point-min)))
|
|
|
|
|
|
|
|
|
|
(defun mpuz-paint-digit (digit)
|
|
|
|
|
"Paint all occurrences of DIGIT on the puzzle board."
|
|
|
|
|
(let ((char (if (mpuz-digit-solved-p digit)
|
|
|
|
|
(+ digit ?0)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(+ (mpuz-to-letter digit) ?A)))
|
|
|
|
|
(face `(face
|
2005-06-10 11:38:27 +00:00
|
|
|
|
,(cond ((aref mpuz-trivial-digits digit) 'mpuz-trivial)
|
|
|
|
|
((aref mpuz-found-digits digit) 'mpuz-solved)
|
|
|
|
|
('mpuz-unsolved))))
|
2002-03-08 08:11:21 +00:00
|
|
|
|
buffer-read-only)
|
|
|
|
|
(mapc (lambda (square)
|
2009-08-21 07:40:24 +00:00
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(forward-line (1- (car square))) ; line before column!
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(move-to-column (cdr square))
|
|
|
|
|
(insert char)
|
|
|
|
|
(set-text-properties (1- (point)) (point) face)
|
|
|
|
|
(delete-char 1))
|
|
|
|
|
(aref mpuz-board digit))))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defun mpuz-get-buffer ()
|
|
|
|
|
"Get the puzzle buffer if it exists."
|
|
|
|
|
(get-buffer "*Mult Puzzle*"))
|
|
|
|
|
|
|
|
|
|
(defun mpuz-switch-to-window ()
|
|
|
|
|
"Find or create the Mult-Puzzle buffer, and display it."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(let ((buf (mpuz-get-buffer)))
|
|
|
|
|
(or buf (setq buf (mpuz-create-buffer)))
|
|
|
|
|
(switch-to-buffer buf)
|
2002-05-04 14:17:21 +00:00
|
|
|
|
(setq buffer-read-only t)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(mpuz-mode)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Game control
|
|
|
|
|
;;-------------
|
|
|
|
|
(defun mpuz-start-new-game ()
|
|
|
|
|
"Start a new puzzle."
|
|
|
|
|
(message "Here we go...")
|
|
|
|
|
(setq mpuz-nb-errors 0
|
|
|
|
|
mpuz-in-progress t)
|
|
|
|
|
(fillarray mpuz-found-digits nil) ; initialize mpuz-found-digits
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(fillarray mpuz-trivial-digits nil)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(mpuz-random-puzzle)
|
|
|
|
|
(mpuz-switch-to-window)
|
|
|
|
|
(mpuz-paint-board)
|
|
|
|
|
(mpuz-paint-errors)
|
|
|
|
|
(mpuz-ask-for-try))
|
|
|
|
|
|
1992-09-26 21:27:08 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun mpuz ()
|
1990-12-19 18:11:55 +00:00
|
|
|
|
"Multiplication puzzle with GNU Emacs."
|
|
|
|
|
;; Main entry point
|
|
|
|
|
(interactive)
|
|
|
|
|
(mpuz-switch-to-window)
|
|
|
|
|
(if mpuz-in-progress
|
|
|
|
|
(mpuz-offer-abort)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(mpuz-start-new-game)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defun mpuz-offer-abort ()
|
|
|
|
|
"Ask if user wants to abort current puzzle."
|
|
|
|
|
(interactive)
|
2005-09-25 Romain Francoise <romain@orebokech.com>
* dired-aux.el (dired-copy-file-recursive):
* dired.el (dired-delete-file):
* ediff-mult.el (ediff-dir-diff-copy-file):
* ediff-util.el (ediff-test-save-region):
* forms.el (forms-mode):
* ido.el (ido-file-internal, ido-delete-file-at-head):
* log-edit.el (log-edit-done):
* ses.el (ses-yank-resize):
* play/gomoku.el (gomoku-human-plays, gomoku)
(gomoku-human-resigns, gomoku-prompt-for-other-game)
(gomoku-offer-a-draw):
* play/landmark.el (lm-human-resigns, lm):
* net/eudcb-ldap.el (eudc-ldap-check-base):
* play/mpuz.el (mpuz-offer-abort, mpuz-try-letter, mpuz-close-game):
* progmodes/ebrowse.el (ebrowse-find-pattern):
* progmodes/idlw-shell.el (idlwave-shell-set-bp-check):
* textmodes/reftex-index.el (reftex-index-initialize-phrases-buffer):
End `yes-or-no-p' and `y-or-n-p' prompts with question mark and
space.
* vc.el (vc-delete-file):
* play/gomoku.el (gomoku-terminate-game, gomoku)
(gomoku-prompt-for-move, gomoku-human-takes-back):
* play/landmark.el (lm-human-takes-back, lm-prompt-for-move)
(lm-start-robot, lm-human-plays): Remove extraneous spaces in
messages.
2005-09-24 23:26:28 +00:00
|
|
|
|
(if (y-or-n-p "Abort game? ")
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(let ((buf (mpuz-get-buffer)))
|
|
|
|
|
(message "Mult Puzzle aborted.")
|
|
|
|
|
(setq mpuz-in-progress nil
|
|
|
|
|
mpuz-nb-errors 0)
|
|
|
|
|
(fillarray mpuz-board nil)
|
|
|
|
|
(if buf (kill-buffer buf)))
|
|
|
|
|
(mpuz-ask-for-try)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defun mpuz-ask-for-try ()
|
|
|
|
|
"Ask for user proposal in puzzle."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(message "Your try?"))
|
|
|
|
|
|
|
|
|
|
(defun mpuz-ding (error)
|
|
|
|
|
"Dings, unless global variable `mpuz-silent' forbids it."
|
|
|
|
|
(cond ((eq mpuz-silent t))
|
|
|
|
|
((not mpuz-silent) (ding t))
|
|
|
|
|
(error (ding t))))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defun mpuz-try-letter ()
|
|
|
|
|
"Propose a digit for a letter in puzzle."
|
|
|
|
|
(interactive)
|
|
|
|
|
(if mpuz-in-progress
|
2011-04-21 12:24:46 +00:00
|
|
|
|
(let (letter-char digit digit-char)
|
2009-01-09 04:23:38 +00:00
|
|
|
|
(setq letter-char (upcase last-command-event)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
digit (mpuz-to-digit (- letter-char ?A)))
|
|
|
|
|
(cond ((mpuz-digit-solved-p digit)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(message "%c already solved." letter-char)
|
|
|
|
|
(mpuz-ding t))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
((null (aref mpuz-board digit))
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(message "%c does not appear." letter-char)
|
|
|
|
|
(mpuz-ding t))
|
1993-04-02 08:12:40 +00:00
|
|
|
|
((progn (message "%c = " letter-char)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
;; <char> has been entered.
|
|
|
|
|
;; Print "<char> =" and
|
|
|
|
|
;; read <num> or = <num>
|
1993-04-02 08:12:40 +00:00
|
|
|
|
(setq digit-char (read-char))
|
|
|
|
|
(if (eq digit-char ?=)
|
|
|
|
|
(setq digit-char (read-char)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(or (> digit-char ?9) (< digit-char ?0))) ; bad input
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(message "%c = %c" letter-char digit-char)
|
|
|
|
|
(mpuz-ding t))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(t
|
|
|
|
|
(mpuz-try-proposal letter-char digit-char))))
|
2005-09-25 Romain Francoise <romain@orebokech.com>
* dired-aux.el (dired-copy-file-recursive):
* dired.el (dired-delete-file):
* ediff-mult.el (ediff-dir-diff-copy-file):
* ediff-util.el (ediff-test-save-region):
* forms.el (forms-mode):
* ido.el (ido-file-internal, ido-delete-file-at-head):
* log-edit.el (log-edit-done):
* ses.el (ses-yank-resize):
* play/gomoku.el (gomoku-human-plays, gomoku)
(gomoku-human-resigns, gomoku-prompt-for-other-game)
(gomoku-offer-a-draw):
* play/landmark.el (lm-human-resigns, lm):
* net/eudcb-ldap.el (eudc-ldap-check-base):
* play/mpuz.el (mpuz-offer-abort, mpuz-try-letter, mpuz-close-game):
* progmodes/ebrowse.el (ebrowse-find-pattern):
* progmodes/idlw-shell.el (idlwave-shell-set-bp-check):
* textmodes/reftex-index.el (reftex-index-initialize-phrases-buffer):
End `yes-or-no-p' and `y-or-n-p' prompts with question mark and
space.
* vc.el (vc-delete-file):
* play/gomoku.el (gomoku-terminate-game, gomoku)
(gomoku-prompt-for-move, gomoku-human-takes-back):
* play/landmark.el (lm-human-takes-back, lm-prompt-for-move)
(lm-start-robot, lm-human-plays): Remove extraneous spaces in
messages.
2005-09-24 23:26:28 +00:00
|
|
|
|
(if (y-or-n-p "Start a new game? ")
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(mpuz-start-new-game)
|
|
|
|
|
(message "OK. I won't."))))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
|
|
|
|
(defun mpuz-try-proposal (letter-char digit-char)
|
|
|
|
|
"Propose LETTER-CHAR as code for DIGIT-CHAR."
|
|
|
|
|
(let* ((letter (- letter-char ?A))
|
|
|
|
|
(digit (- digit-char ?0))
|
2011-04-21 12:24:46 +00:00
|
|
|
|
(correct-digit (mpuz-to-digit letter)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(cond ((mpuz-digit-solved-p correct-digit)
|
1999-06-17 05:29:34 +00:00
|
|
|
|
(message "%c has already been found." (+ correct-digit ?0)))
|
|
|
|
|
((mpuz-digit-solved-p digit)
|
|
|
|
|
(message "%c has already been placed." digit-char))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
((= digit correct-digit)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(message "%c = %c correct!" letter-char digit-char)
|
|
|
|
|
(mpuz-ding nil)
|
|
|
|
|
(aset mpuz-found-digits digit t) ; Mark digit as solved
|
|
|
|
|
(and (mpuz-check-all-solved)
|
|
|
|
|
(mpuz-close-game)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(t ;;; incorrect guess
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(message "%c = %c incorrect!" letter-char digit-char)
|
|
|
|
|
(mpuz-ding t)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(setq mpuz-nb-errors (1+ mpuz-nb-errors))
|
|
|
|
|
(mpuz-paint-errors)))))
|
|
|
|
|
|
|
|
|
|
(defun mpuz-close-game ()
|
|
|
|
|
"Housecleaning when puzzle has been solved."
|
|
|
|
|
(setq mpuz-in-progress nil
|
|
|
|
|
mpuz-nb-cumulated-errors (+ mpuz-nb-cumulated-errors mpuz-nb-errors)
|
|
|
|
|
mpuz-nb-completed-games (1+ mpuz-nb-completed-games))
|
|
|
|
|
(mpuz-paint-statistics)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(let ((message (format "Puzzle solved with %d error%s. That's %s"
|
|
|
|
|
mpuz-nb-errors
|
|
|
|
|
(if (= mpuz-nb-errors 1) "" "s")
|
|
|
|
|
(cond ((= mpuz-nb-errors 0) "perfect!")
|
|
|
|
|
((= mpuz-nb-errors 1) "very good!")
|
|
|
|
|
((= mpuz-nb-errors 2) "good.")
|
|
|
|
|
((= mpuz-nb-errors 3) "not bad.")
|
|
|
|
|
((= mpuz-nb-errors 4) "not too bad...")
|
|
|
|
|
((< mpuz-nb-errors 10) "bad!")
|
|
|
|
|
((< mpuz-nb-errors 15) "awful.")
|
|
|
|
|
(t "not serious.")))))
|
2007-12-08 01:02:29 +00:00
|
|
|
|
(message "%s" message)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(sit-for 4)
|
2005-09-25 Romain Francoise <romain@orebokech.com>
* dired-aux.el (dired-copy-file-recursive):
* dired.el (dired-delete-file):
* ediff-mult.el (ediff-dir-diff-copy-file):
* ediff-util.el (ediff-test-save-region):
* forms.el (forms-mode):
* ido.el (ido-file-internal, ido-delete-file-at-head):
* log-edit.el (log-edit-done):
* ses.el (ses-yank-resize):
* play/gomoku.el (gomoku-human-plays, gomoku)
(gomoku-human-resigns, gomoku-prompt-for-other-game)
(gomoku-offer-a-draw):
* play/landmark.el (lm-human-resigns, lm):
* net/eudcb-ldap.el (eudc-ldap-check-base):
* play/mpuz.el (mpuz-offer-abort, mpuz-try-letter, mpuz-close-game):
* progmodes/ebrowse.el (ebrowse-find-pattern):
* progmodes/idlw-shell.el (idlwave-shell-set-bp-check):
* textmodes/reftex-index.el (reftex-index-initialize-phrases-buffer):
End `yes-or-no-p' and `y-or-n-p' prompts with question mark and
space.
* vc.el (vc-delete-file):
* play/gomoku.el (gomoku-terminate-game, gomoku)
(gomoku-prompt-for-move, gomoku-human-takes-back):
* play/landmark.el (lm-human-takes-back, lm-prompt-for-move)
(lm-start-robot, lm-human-plays): Remove extraneous spaces in
messages.
2005-09-24 23:26:28 +00:00
|
|
|
|
(if (y-or-n-p (concat message " Start a new game? "))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(mpuz-start-new-game)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(message "Good Bye!"))))
|
|
|
|
|
|
|
|
|
|
(defun mpuz-solve (&optional row col)
|
|
|
|
|
"Find solution for autosolving."
|
|
|
|
|
(mapc (lambda (digit)
|
|
|
|
|
(or (mpuz-digit-solved-p digit)
|
|
|
|
|
(if row
|
|
|
|
|
(not (if col
|
|
|
|
|
(member (cons row col) (aref mpuz-board digit))
|
|
|
|
|
(assq row (aref mpuz-board digit)))))
|
|
|
|
|
(aset mpuz-trivial-digits digit t)))
|
|
|
|
|
[0 1 2 3 4 5 6 7 8 9])
|
|
|
|
|
t)
|
|
|
|
|
|
|
|
|
|
(defun mpuz-show-solution (row)
|
1990-12-19 18:11:55 +00:00
|
|
|
|
"Display solution for debugging purposes."
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(interactive "P")
|
1990-12-19 18:11:55 +00:00
|
|
|
|
(mpuz-switch-to-window)
|
2002-03-08 08:11:21 +00:00
|
|
|
|
(mpuz-solve (if row (* 2 (prefix-numeric-value row))))
|
|
|
|
|
(mpuz-paint-board)
|
|
|
|
|
(if (mpuz-check-all-solved)
|
|
|
|
|
(mpuz-close-game)))
|
1990-12-19 18:11:55 +00:00
|
|
|
|
|
1997-06-22 18:57:55 +00:00
|
|
|
|
(provide 'mpuz)
|
|
|
|
|
|
1992-05-30 22:12:04 +00:00
|
|
|
|
;;; mpuz.el ends here
|