annotate lisp/play/solitaire.el @ 13232:e31057e55df7

(x_term_init, XTread_socket): Add HAVE_X_I18N support.
author Richard M. Stallman <rms@gnu.org>
date Tue, 17 Oct 1995 17:12:20 +0000
parents eed43624bc00
children 84acc3adcd63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12766
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; solitaire.el --- game of solitaire in emacs lisp
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Jan Schormann <Jan.Schormann@informatik.uni-oldenburg.de>
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Created: Fri afternoon, Jun 3, 1994
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: games
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with this program; if not, write to the Free Software
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (defvar solitaire-mode-map nil
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 "Keymap for playing solitaire.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (if solitaire-mode-map
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (setq solitaire-mode-map (make-sparse-keymap))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (suppress-keymap solitaire-mode-map t)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (define-key solitaire-mode-map "\C-f" 'solitaire-right)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (define-key solitaire-mode-map "\C-b" 'solitaire-left)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (define-key solitaire-mode-map "\C-p" 'solitaire-up)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 (define-key solitaire-mode-map "\C-n" 'solitaire-down)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (define-key solitaire-mode-map [return] 'solitaire-move)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (substitute-key-definition 'undo 'solitaire-undo
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 solitaire-mode-map global-map)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (define-key solitaire-mode-map " " 'solitaire-do-check)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (define-key solitaire-mode-map "q" 'solitaire-quit)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (define-key solitaire-mode-map [right] 'solitaire-right)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (define-key solitaire-mode-map [left] 'solitaire-left)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (define-key solitaire-mode-map [up] 'solitaire-up)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (define-key solitaire-mode-map [down] 'solitaire-down)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (define-key solitaire-mode-map [S-right] 'solitaire-move-right)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (define-key solitaire-mode-map [S-left] 'solitaire-move-left)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (define-key solitaire-mode-map [S-up] 'solitaire-move-up)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (define-key solitaire-mode-map [S-down] 'solitaire-move-down)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (define-key solitaire-mode-map [kp-6] 'solitaire-right)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (define-key solitaire-mode-map [kp-4] 'solitaire-left)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (define-key solitaire-mode-map [kp-8] 'solitaire-up)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (define-key solitaire-mode-map [kp-2] 'solitaire-down)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (define-key solitaire-mode-map [kp-5] 'solitaire-center-point)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (define-key solitaire-mode-map [S-kp-6] 'solitaire-move-right)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (define-key solitaire-mode-map [S-kp-4] 'solitaire-move-left)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (define-key solitaire-mode-map [S-kp-8] 'solitaire-move-up)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (define-key solitaire-mode-map [S-kp-2] 'solitaire-move-down)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (define-key solitaire-mode-map [kp-enter] 'solitaire-move)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (define-key solitaire-mode-map [kp-0] 'solitaire-undo)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; spoil it with s ;)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (define-key solitaire-mode-map [?s] 'solitaire-solve)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; (define-key solitaire-mode-map [kp-0] 'solitaire-hint) - Not yet provided ;)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 )
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; Solitaire mode is suitable only for specially formatted data.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (put 'solitaire-mode 'mode-class 'special)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (defun solitaire-mode ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 "Major mode for playing solitaire.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 To learn how to play solitaire, see the documentation for function
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 `solitaire'.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 \\<solitaire-mode-map>
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 The usual mnemonic keys move the cursor around the board; in addition,
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 \\[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
92 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (kill-all-local-variables)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (use-local-map solitaire-mode-map)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (setq truncate-lines t)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (setq major-mode 'solitaire-mode)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (setq mode-name "Solitaire")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (run-hooks 'solitaire-mode-hook))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (defvar solitaire-stones 0
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 "Counter for the stones that are still there.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (defvar solitaire-center nil
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 "Center of the board.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (defvar solitaire-start nil
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 "Upper left corner of the board.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (defvar solitaire-start-x nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (defvar solitaire-start-y nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (defvar solitaire-end nil
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 "Lower right corner of the board.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (defvar solitaire-end-x nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (defvar solitaire-end-y nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (defvar solitaire-auto-eval t
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 "*Non-nil means check for possible moves after each major change.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 This takes a while, so switch this on if you like to be informed when
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 the game is over, or off, if you are working on a slow machine.")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defconst solitaire-valid-directions
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 '(solitaire-left solitaire-right solitaire-up solitaire-down))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;;;###autoload
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defun solitaire (arg)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 "Play Solitaire.
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 To play Solitaire, type \\[solitaire].
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 \\<solitaire-mode-map>
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 Move around the board using the cursor keys.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 Move stones using \\[solitaire-move] followed by a direction key.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 Undo moves using \\[solitaire-undo].
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 Check for possible moves using \\[solitaire-do-check].
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (The variable solitaire-auto-eval controls whether to automatically
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 check after each move or undo)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 What is Solitaire?
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 I don't know who invented this game, but it seems to be rather old and
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 it's origin seems be northern Africa. Here's how to play:
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 Initially, the board will look similar to this:
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 Le Solitaire
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ============
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 o o o o o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 o o o . o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 o o o o o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 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
163 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
164 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
165 one in the middle of the board if you're cool.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 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
168 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
169 horizontally or vertically, up, down, left or right, which look like
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 this: o o .
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 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
173 which therefore is taken away. The above thus `evaluates' to: . . o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 That's all. Here's the board after two moves:
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 o o 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 . o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 o o . o o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 o . o o o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 o o o o o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 o o o
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 Pick your favourite shortcuts:
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 \\{solitaire-mode-map}"
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 (interactive "P")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (switch-to-buffer "*Solitaire*")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (solitaire-mode)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (setq buffer-read-only t)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (setq solitaire-stones 32)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (solitaire-insert-board)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (solitaire-build-modeline)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (goto-char (point-max))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (setq solitaire-center (search-backward "."))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (setq buffer-undo-list (list (point)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (set-buffer-modified-p nil))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (defun solitaire-build-modeline ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (setq mode-line-format
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (list "" "---" 'mode-line-buffer-identification
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (if (< 1 solitaire-stones)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (format "--> There are %d stones left <--" solitaire-stones)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 "------")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 'global-mode-string " %[(" 'mode-name 'minor-mode-alist "%n"
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ")%]-%-"))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (force-mode-line-update))
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 (defun solitaire-insert-board ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (let* ((buffer-read-only nil)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (w (window-width))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (h (window-height))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (hsep (cond ((> w 26) " ")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ((> w 20) " ")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (t "")))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (vsep (cond ((> h 17) "\n\n")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (t "\n")))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (indent (make-string (/ (- w 7 (* 6 (length hsep))) 2) ?\ )))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (erase-buffer)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (insert (make-string (/ (- h 7 (if (> h 12) 3 0)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (* 6 (1- (length vsep)))) 2) ?\n))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (if (or (string= vsep "\n\n") (> h 12))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (progn
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (insert (format "%sLe Solitaire\n" indent))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (insert (format "%s============\n\n" indent))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (insert indent)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (setq solitaire-start (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (setq solitaire-start-x (current-column))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (setq solitaire-start-y (solitaire-current-line))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (insert (format " %s %so%so%so%s" hsep hsep hsep hsep vsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (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
240 (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
241 (insert (format "%so%so%so%s" indent hsep hsep hsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (setq solitaire-center (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (insert (format ".%so%so%so%s" hsep hsep hsep vsep))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (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
245 (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
246 (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
247 (setq solitaire-end (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (setq solitaire-end-x (current-column))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (setq solitaire-end-y (solitaire-current-line))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (defun solitaire-right ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (let ((start (point)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (forward-char)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (while (= ?\ (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (forward-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (if (or (= 0 (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (= ?\ (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (= ?\n (following-char)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (goto-char start))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (defun solitaire-left ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (let ((start (point)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (backward-char)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (while (= ?\ (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (backward-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (if (or (= 0 (preceding-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (= ?\ (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (= ?\n (following-char)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (goto-char start))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (defun solitaire-up ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (let ((start (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (c (current-column)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (forward-line -1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (move-to-column c)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (while (and (= ?\n (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (forward-line -1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (move-to-column c)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (not (bolp))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (if (or (= 0 (preceding-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (= ?\ (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (= ?\= (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (= ?\n (following-char)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (goto-char start)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 )))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (defun solitaire-down ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (let ((start (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (c (current-column)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (forward-line 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (move-to-column c)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (while (and (= ?\n (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (forward-line 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (move-to-column c)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (not (eolp))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (if (or (= 0 (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (= ?\ (following-char))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (= ?\n (following-char)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (goto-char start))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (defun solitaire-center-point ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (goto-char solitaire-center))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (defun solitaire-move-right () (interactive) (solitaire-move '[right]))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (defun solitaire-move-left () (interactive) (solitaire-move '[left]))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (defun solitaire-move-up () (interactive) (solitaire-move '[up]))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (defun solitaire-move-down () (interactive) (solitaire-move '[down]))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (defun solitaire-possible-move (movesymbol)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 "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
317 MOVESYMBOL specifies the direction.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 Returns either a string, indicating cause of contraindication, or a
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 list containing three numbers: starting field, skipped field (from
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 which a stone will be taken away) and target."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (save-excursion
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (let (move)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (fset 'move movesymbol)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (if (memq movesymbol solitaire-valid-directions)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (let ((start (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (skip (progn (move) (point)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (target (progn (move) (point))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (if (= skip target)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 "Off Board!"
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (if (or (/= ?o (char-after start))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (/= ?o (char-after skip))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (/= ?. (char-after target)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 "Wrong move!"
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (list start skip target))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 "Not a valid direction"))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (defun solitaire-move (dir)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 "Pseudo-prefix command to move a stone in Solitaire."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (interactive "kMove where? ")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (let* ((class (solitaire-possible-move (lookup-key solitaire-mode-map dir)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (buffer-read-only nil))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (if (stringp class)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (error class)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (let ((start (car class))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (skip (car (cdr class)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (target (car (cdr (cdr class)))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (goto-char start)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (delete-char 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (insert ?.)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (goto-char skip)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (delete-char 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (insert ?.)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (goto-char target)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (delete-char 1)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (insert ?o)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (goto-char target)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (setq solitaire-stones (1- solitaire-stones))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (solitaire-build-modeline)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (if solitaire-auto-eval (solitaire-do-check))))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (defun solitaire-undo (arg)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 "Undo a move in Solitaire."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (interactive "P")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (let ((buffer-read-only nil))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (undo arg))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (save-excursion
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (setq solitaire-stones
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (let ((count 0))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (goto-char solitaire-end)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (while (search-backward "o" solitaire-start 'done)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (and (>= (current-column) solitaire-start-x)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (<= (current-column) solitaire-end-x)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (>= (solitaire-current-line) solitaire-start-y)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (<= (solitaire-current-line) solitaire-end-y)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (setq count (1+ count))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 count)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (solitaire-build-modeline)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (if solitaire-auto-eval (solitaire-do-check)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (defun solitaire-check ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (save-excursion
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (if (= 1 solitaire-stones)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 0
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (goto-char solitaire-end)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (let ((count 0))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (while (search-backward "o" solitaire-start 'done)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (and (>= (current-column) solitaire-start-x)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (<= (current-column) solitaire-end-x)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (>= (solitaire-current-line) solitaire-start-y)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (<= (solitaire-current-line) solitaire-end-y)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (mapcar
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (lambda (movesymbol)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (if (listp (solitaire-possible-move movesymbol))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (setq count (1+ count))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 solitaire-valid-directions)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 count))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (defun solitaire-do-check (&optional arg)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 "Check for any possible moves in Solitaire."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (interactive "P")
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (let ((moves (solitaire-check)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (cond ((= 1 solitaire-stones)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (message "Yeah! You made it! Only the King is left!"))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 ((zerop moves)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (message "Sorry, no more possible moves."))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 ((= 1 moves)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (message "There is one possible move."))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (t (message "There are %d possible moves." moves)))))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (defun solitaire-current-line ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 "Return the vertical position of point.
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 Seen in info on text lines."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (+ (count-lines (point-min) (point))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (if (= (current-column) 0) 1 0)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 -1))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (defun solitaire-quit ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 "Quit playing Solitaire."
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (kill-buffer "*Solitaire*"))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 ;; And here's the spoiler:)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (defun solitaire-solve ()
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 "Spoil solitaire by solving the game for you - nearly ...
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 ... stops with five stones left ;)"
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (interactive)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (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
429 up up right right S-left down down down S-up up
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 S-down down down down S-up left left down
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 S-right left left up up S-down right right right
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 S-left left S-right right right right S-left
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 right down down S-up down down left left S-right
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 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
435 right right S-left down right right down S-up
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 left left left S-right right S-left down down
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 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
438 up S-right left left])
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 ;; down down S-up left S-right
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 ;; right S-left
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (solitaire-auto-eval nil))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (solitaire-center-point)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (mapcar (lambda (op)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (if (memq op '(S-left S-right S-up S-down))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (sit-for 0.2))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (execute-kbd-macro (vector op))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (if (memq op '(S-left S-right S-up S-down))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (sit-for 0.4)))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 allmoves))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (solitaire-do-check))
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (provide 'solitaire)
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453
eed43624bc00 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 ;;; solitaire.el ends here