annotate lisp/play/solitaire.el @ 108219:252a60daa4fb

* src/m/amdx86-64.h: Fix typo in previous.
author Glenn Morris <rgm@gnu.org>
date Sun, 02 May 2010 19:23:42 -0700
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 12766
diff changeset
1 ;;; solitaire.el --- game of solitaire in Emacs Lisp
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
104848
1382a0cd8022 Remove leading * from defcustom and defface docs.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
3 ;; Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 104848
diff changeset
4 ;; 2009, 2010 Free Software Foundation, Inc.
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
44551
5545a62c342c Update author's email address, at his request.
Eli Zaretskii <eliz@gnu.org>
parents: 22211
diff changeset
6 ;; Author: Jan Schormann <Jan.Schormann@rechen-gilde.de>
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: Fri afternoon, Jun 3, 1994
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: games
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; (at your option) any later version.
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; This mode is for playing a well-known game of solitaire
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; in which you jump pegs across other pegs.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; The game itself is somehow self-explanatory. Read the help text to
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; solitaire, and try it.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; Code:
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
35 (defgroup solitaire nil
96973
32a1bbf01ebb * play/solitaire.el (solitaire-mode): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94675
diff changeset
36 "Game of Solitaire."
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
37 :prefix "solitaire-"
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
38 :group 'games)
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
39
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
40 (defcustom solitaire-mode-hook nil
96973
32a1bbf01ebb * play/solitaire.el (solitaire-mode): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94675
diff changeset
41 "Hook to run upon entry to Solitaire."
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
42 :type 'hook
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
43 :group 'solitaire)
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
44
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
45 (defvar solitaire-mode-map
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
46 (let ((map (make-sparse-keymap)))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
47 (suppress-keymap map t)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
49 (define-key map "\C-f" 'solitaire-right)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
50 (define-key map "\C-b" 'solitaire-left)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
51 (define-key map "\C-p" 'solitaire-up)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
52 (define-key map "\C-n" 'solitaire-down)
98374
78848db62e02 (solitaire-mode-map): Bind "\r" rather than [return]. (Bug#1031)
Glenn Morris <rgm@gnu.org>
parents: 97008
diff changeset
53 (define-key map "\r" 'solitaire-move)
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
54 (define-key map [remap undo] 'solitaire-undo)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
55 (define-key map " " 'solitaire-do-check)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
56 (define-key map "q" 'quit-window)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
57
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
58 (define-key map [right] 'solitaire-right)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
59 (define-key map [left] 'solitaire-left)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
60 (define-key map [up] 'solitaire-up)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
61 (define-key map [down] 'solitaire-down)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
63 (define-key map [S-right] 'solitaire-move-right)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
64 (define-key map [S-left] 'solitaire-move-left)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
65 (define-key map [S-up] 'solitaire-move-up)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
66 (define-key map [S-down] 'solitaire-move-down)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
68 (define-key map [kp-6] 'solitaire-right)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
69 (define-key map [kp-4] 'solitaire-left)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
70 (define-key map [kp-8] 'solitaire-up)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
71 (define-key map [kp-2] 'solitaire-down)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
72 (define-key map [kp-5] 'solitaire-center-point)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
74 (define-key map [S-kp-6] 'solitaire-move-right)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
75 (define-key map [S-kp-4] 'solitaire-move-left)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
76 (define-key map [S-kp-8] 'solitaire-move-up)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
77 (define-key map [S-kp-2] 'solitaire-move-down)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
79 (define-key map [kp-enter] 'solitaire-move)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
80 (define-key map [kp-0] 'solitaire-undo)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
82 ;; spoil it with s ;)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
83 (define-key map [?s] 'solitaire-solve)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
85 ;; (define-key map [kp-0] 'solitaire-hint) - Not yet provided ;)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
86 map)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
87 "Keymap for playing Solitaire.")
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; Solitaire mode is suitable only for specially formatted data.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (put 'solitaire-mode 'mode-class 'special)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
92 (define-derived-mode solitaire-mode nil "Solitaire"
96973
32a1bbf01ebb * play/solitaire.el (solitaire-mode): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94675
diff changeset
93 "Major mode for playing Solitaire.
32a1bbf01ebb * play/solitaire.el (solitaire-mode): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94675
diff changeset
94 To learn how to play Solitaire, see the documentation for function
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 `solitaire'.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 \\<solitaire-mode-map>
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 The usual mnemonic keys move the cursor around the board; in addition,
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 \\[solitaire-move] is a prefix character for actually moving a stone on the board."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (setq truncate-lines t)
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
100 (setq show-trailing-whitespace nil))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (defvar solitaire-stones 0
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 "Counter for the stones that are still there.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (defvar solitaire-center nil
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 "Center of the board.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defvar solitaire-start nil
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "Upper left corner of the board.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defvar solitaire-start-x nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (defvar solitaire-start-y nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (defvar solitaire-end nil
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 "Lower right corner of the board.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (defvar solitaire-end-x nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (defvar solitaire-end-y nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
120 (defcustom solitaire-auto-eval t
104848
1382a0cd8022 Remove leading * from defcustom and defface docs.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
121 "Non-nil means check for possible moves after each major change.
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 This takes a while, so switch this on if you like to be informed when
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
123 the game is over, or off, if you are working on a slow machine."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
124 :type 'boolean
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
125 :group 'solitaire)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defconst solitaire-valid-directions
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 '(solitaire-left solitaire-right solitaire-up solitaire-down))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;;;###autoload
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (defun solitaire (arg)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 "Play Solitaire.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 To play Solitaire, type \\[solitaire].
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 \\<solitaire-mode-map>
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 Move around the board using the cursor keys.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 Move stones using \\[solitaire-move] followed by a direction key.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 Undo moves using \\[solitaire-undo].
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 Check for possible moves using \\[solitaire-do-check].
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 21098
diff changeset
140 \(The variable `solitaire-auto-eval' controls whether to automatically
96973
32a1bbf01ebb * play/solitaire.el (solitaire-mode): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94675
diff changeset
141 check after each move or undo.)
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 What is Solitaire?
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 I don't know who invented this game, but it seems to be rather old and
22169
6de2236eab5f (solitaire): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 21363
diff changeset
146 its origin seems to be northern Africa. Here's how to play:
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 Initially, the board will look similar to this:
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
149 Le Solitaire
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
150 ============
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
151
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
152 o o o
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
153
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
154 o o o
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
155
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 o o o o o o o
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
157
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 o o o . o o o
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
159
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 o o o o o o o
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
161
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
162 o o o
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
163
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
164 o o o
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 Let's call the o's stones and the .'s holes. One stone fits into one
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 hole. As you can see, all holes but one are occupied by stones. The
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 aim of the game is to get rid of all but one stone, leaving that last
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 one in the middle of the board if you're cool.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 A stone can be moved if there is another stone next to it, and a hole
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 after that one. Thus there must be three fields in a row, either
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 horizontally or vertically, up, down, left or right, which look like
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 this: o o .
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 Then the first stone is moved to the hole, jumping over the second,
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 which therefore is taken away. The above thus `evaluates' to: . . o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 That's all. Here's the board after two moves:
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
181 o o o
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
182
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
183 . o o
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
184
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 o o . o o o o
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
186
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 o . o o o o o
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
188
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 o o o o o o o
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
190
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
191 o o o
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
192
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 Pick your favourite shortcuts:
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 \\{solitaire-mode-map}"
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (interactive "P")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (switch-to-buffer "*Solitaire*")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (solitaire-mode)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (setq buffer-read-only t)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (setq solitaire-stones 32)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (solitaire-insert-board)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (solitaire-build-modeline)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (goto-char (point-max))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (setq solitaire-center (search-backward "."))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (setq buffer-undo-list (list (point)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (set-buffer-modified-p nil))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (defun solitaire-build-modeline ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (setq mode-line-format
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (list "" "---" 'mode-line-buffer-identification
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (if (< 1 solitaire-stones)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (format "--> There are %d stones left <--" solitaire-stones)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 "------")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 'global-mode-string " %[(" 'mode-name 'minor-mode-alist "%n"
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ")%]-%-"))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (force-mode-line-update))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (defun solitaire-insert-board ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (let* ((buffer-read-only nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (w (window-width))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (h (window-height))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (hsep (cond ((> w 26) " ")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 ((> w 20) " ")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (t "")))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (vsep (cond ((> h 17) "\n\n")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (t "\n")))
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
230 (indent (make-string (/ (- w 7 (* 6 (length hsep))) 2) ?\s)))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (erase-buffer)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (insert (make-string (/ (- h 7 (if (> h 12) 3 0)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (* 6 (1- (length vsep)))) 2) ?\n))
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
234 (when (or (string= vsep "\n\n") (> h 12))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
235 (insert (format "%sLe Solitaire\n" indent))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
236 (insert (format "%s============\n\n" indent)))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (insert indent)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (setq solitaire-start (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (setq solitaire-start-x (current-column))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (setq solitaire-start-y (solitaire-current-line))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (insert (format " %s %so%so%so%s" hsep hsep hsep hsep vsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (insert (format "%s %s %so%so%so%s" indent hsep hsep hsep hsep vsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (insert (format "%so%so%so%so%so%so%so%s" indent hsep hsep hsep hsep hsep hsep vsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (insert (format "%so%so%so%s" indent hsep hsep hsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (setq solitaire-center (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (insert (format ".%so%so%so%s" hsep hsep hsep vsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (insert (format "%so%so%so%so%so%so%so%s" indent hsep hsep hsep hsep hsep hsep vsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (insert (format "%s %s %so%so%so%s" indent hsep hsep hsep hsep vsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (insert (format "%s %s %so%so%so%s %s " indent hsep hsep hsep hsep hsep hsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (setq solitaire-end (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (setq solitaire-end-x (current-column))
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
252 (setq solitaire-end-y (solitaire-current-line))))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (defun solitaire-right ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (let ((start (point)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (forward-char)
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
258 (while (= ?\s (following-char))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (forward-char))
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
260 (when (or (= 0 (following-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
261 (= ?\s (following-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
262 (= ?\n (following-char)))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
263 (goto-char start))))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (defun solitaire-left ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (let ((start (point)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (backward-char)
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
269 (while (= ?\s (following-char))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (backward-char))
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
271 (when (or (= 0 (preceding-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
272 (= ?\s (following-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
273 (= ?\n (following-char)))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
274 (goto-char start))))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (defun solitaire-up ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (let ((start (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (c (current-column)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (forward-line -1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (move-to-column c)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (while (and (= ?\n (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (forward-line -1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (move-to-column c)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (not (bolp))))
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
286 (when (or (= 0 (preceding-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
287 (= ?\s (following-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
288 (= ?\= (following-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
289 (= ?\n (following-char)))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
290 (goto-char start))))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (defun solitaire-down ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (let ((start (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (c (current-column)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (forward-line 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (move-to-column c)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (while (and (= ?\n (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (forward-line 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (move-to-column c)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (not (eolp))))
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
302 (when (or (= 0 (following-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
303 (= ?\s (following-char))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
304 (= ?\n (following-char)))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
305 (goto-char start))))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (defun solitaire-center-point ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (goto-char solitaire-center))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (defun solitaire-move-right () (interactive) (solitaire-move '[right]))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (defun solitaire-move-left () (interactive) (solitaire-move '[left]))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (defun solitaire-move-up () (interactive) (solitaire-move '[up]))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (defun solitaire-move-down () (interactive) (solitaire-move '[down]))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (defun solitaire-possible-move (movesymbol)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 "Check if a move is possible from current point in the specified direction.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 MOVESYMBOL specifies the direction.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 Returns either a string, indicating cause of contraindication, or a
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 list containing three numbers: starting field, skipped field (from
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 which a stone will be taken away) and target."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (save-excursion
22211
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
324 (if (memq movesymbol solitaire-valid-directions)
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
325 (let ((start (point))
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
326 (skip (progn (funcall movesymbol) (point)))
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
327 (target (progn (funcall movesymbol) (point))))
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
328 (if (= skip target)
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
329 "Off Board!"
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
330 (if (or (/= ?o (char-after start))
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
331 (/= ?o (char-after skip))
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
332 (/= ?. (char-after target)))
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
333 "Wrong move!"
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
334 (list start skip target))))
c8fa861cb852 (solitaire-possible-move): Use funcall to invoke movesymbol.
Richard M. Stallman <rms@gnu.org>
parents: 22169
diff changeset
335 "Not a valid direction")))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (defun solitaire-move (dir)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 "Pseudo-prefix command to move a stone in Solitaire."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (interactive "kMove where? ")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (let* ((class (solitaire-possible-move (lookup-key solitaire-mode-map dir)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (buffer-read-only nil))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (if (stringp class)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (error class)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (let ((start (car class))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (skip (car (cdr class)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
346 (target (car (cdr (cdr class)))))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (goto-char start)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (delete-char 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (insert ?.)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (goto-char skip)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (delete-char 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (insert ?.)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (goto-char target)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (delete-char 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (insert ?o)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (goto-char target)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (setq solitaire-stones (1- solitaire-stones))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (solitaire-build-modeline)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (if solitaire-auto-eval (solitaire-do-check))))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (defun solitaire-undo (arg)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 "Undo a move in Solitaire."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (interactive "P")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (let ((buffer-read-only nil))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (undo arg))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (save-excursion
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (setq solitaire-stones
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (let ((count 0))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (goto-char solitaire-end)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (while (search-backward "o" solitaire-start 'done)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (and (>= (current-column) solitaire-start-x)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (<= (current-column) solitaire-end-x)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (>= (solitaire-current-line) solitaire-start-y)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (<= (solitaire-current-line) solitaire-end-y)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (setq count (1+ count))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 count)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49175
diff changeset
377 (solitaire-build-modeline)
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
378 (when solitaire-auto-eval (solitaire-do-check)))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (defun solitaire-check ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (save-excursion
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (if (= 1 solitaire-stones)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 0
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (goto-char solitaire-end)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (let ((count 0))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (while (search-backward "o" solitaire-start 'done)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (and (>= (current-column) solitaire-start-x)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (<= (current-column) solitaire-end-x)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (>= (solitaire-current-line) solitaire-start-y)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (<= (solitaire-current-line) solitaire-end-y)
84915
4baa88b428f9 (solitaire-check, solitaire-solve): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78227
diff changeset
391 (mapc
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (lambda (movesymbol)
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
393 (when (listp (solitaire-possible-move movesymbol))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
394 (setq count (1+ count))))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 solitaire-valid-directions)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 count))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (defun solitaire-do-check (&optional arg)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 "Check for any possible moves in Solitaire."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (interactive "P")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (let ((moves (solitaire-check)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (cond ((= 1 solitaire-stones)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (message "Yeah! You made it! Only the King is left!"))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 ((zerop moves)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (message "Sorry, no more possible moves."))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 ((= 1 moves)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (message "There is one possible move."))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (t (message "There are %d possible moves." moves)))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (defun solitaire-current-line ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 "Return the vertical position of point.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 Seen in info on text lines."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (+ (count-lines (point-min) (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (if (= (current-column) 0) 1 0)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 -1))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 ;; And here's the spoiler:)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (defun solitaire-solve ()
96973
32a1bbf01ebb * play/solitaire.el (solitaire-mode): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94675
diff changeset
419 "Spoil Solitaire by solving the game for you - nearly ...
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 ... stops with five stones left ;)"
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (interactive)
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
422 (when (< solitaire-stones 32)
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
423 (error "Cannot solve game in progress"))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (let ((allmoves [up up S-down up left left S-right up up left S-down
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 up up right right S-left down down down S-up up
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 S-down down down down S-up left left down
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 S-right left left up up S-down right right right
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 S-left left S-right right right right S-left
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 right down down S-up down down left left S-right
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 up up up S-down down S-up up up up S-down up
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 right right S-left down right right down S-up
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 left left left S-right right S-left down down
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 left S-right S-up S-left S-left S-down S-right
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 up S-right left left])
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 ;; down down S-up left S-right
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 ;; right S-left
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (solitaire-auto-eval nil))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (solitaire-center-point)
84915
4baa88b428f9 (solitaire-check, solitaire-solve): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78227
diff changeset
439 (mapc (lambda (op)
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
440 (when (memq op '(S-left S-right S-up S-down))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
441 (sit-for 0.2))
84915
4baa88b428f9 (solitaire-check, solitaire-solve): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78227
diff changeset
442 (execute-kbd-macro (vector op))
97008
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
443 (when (memq op '(S-left S-right S-up S-down))
b6326d1fbbef * play/solitaire.el (solitaire-mode-map): Define within defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 96973
diff changeset
444 (sit-for 0.4)))
84915
4baa88b428f9 (solitaire-check, solitaire-solve): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78227
diff changeset
445 allmoves))
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (solitaire-do-check))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (provide 'solitaire)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
450 ;; arch-tag: 1b18ee1c-1e79-4a5b-8658-9560b82e63dd
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 ;;; solitaire.el ends here