annotate lisp/games/blackbox.el @ 163:0132846995bd r20-3b8

Import from CVS: tag r20-3b8
author cvs
date Mon, 13 Aug 2007 09:43:35 +0200
parents 54cc21c15cbb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; blackbox.el --- blackbox game in Emacs Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: F. Thomas May <uw-nsr!uw-warp!tom@beaver.cs.washington.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Adapted-By: ESR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: games
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
24 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
30 ;; by F. Thomas May <uw-nsr!uw-warp!tom@beaver.cs.washington.edu>
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
31 ;; doc comment by Root Boy Jim <rbj@dsys.icst.nbs.gov>, 27 Apr 89
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
32 ;; interface improvements by ESR, Dec 5 1991.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
33
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
34 ;; The object of the game is to find four hidden balls by shooting rays
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
35 ;; into the black box. There are four possibilities: 1) the ray will
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
36 ;; pass thru the box undisturbed, 2) it will hit a ball and be absorbed,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
37 ;; 3) it will be deflected and exit the box, or 4) be deflected immediately,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
38 ;; not even being allowed entry into the box.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
40 ;; The strange part is the method of deflection. It seems that rays will
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
41 ;; not pass next to a ball, and change direction at right angles to avoid it.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
42 ;;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
43 ;; R 3
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
44 ;; 1 - - - - - - - - 1
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
45 ;; - - - - - - - -
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
46 ;; - O - - - - - - 3
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
47 ;; 2 - - - - O - O -
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
48 ;; 4 - - - - - - - -
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
49 ;; 5 - - - - - - - - 5
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
50 ;; - - - - - - - - R
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
51 ;; H - - - - - - - O
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
52 ;; 2 H 4 H
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
53 ;;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
54 ;; Rays which enter and exit are numbered. You can see that rays 1 & 5 pass
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
55 ;; thru the box undisturbed. Ray 2 is deflected by the northwesternmost
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
56 ;; ball. Likewise rays 3 and 4. Rays which hit balls and are absorbed are
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
57 ;; marked with H. The bottom of the left and the right of the bottom hit
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
58 ;; the southeastern ball directly. Rays may also hit balls after being
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
59 ;; reflected. Consider the H on the bottom next to the 4. It bounces off
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
60 ;; the NW-ern most ball and hits the central ball. A ray shot from above
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
61 ;; the right side 5 would hit the SE-ern most ball. The R beneath the 5
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
62 ;; is because the ball is returned instantly. It is not allowed into
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
63 ;; the box if it would reflect immediately. The R on the top is a more
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
64 ;; leisurely return. Both central balls would tend to deflect it east
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
65 ;; or west, but it cannot go either way, so it just retreats.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
66
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
67 ;; At the end of the game, if you've placed guesses for as many balls as
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
68 ;; there are in the box, the true board position will be revealed. Each
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
69 ;; `x' is an incorrect guess of yours;; `o' is the true location of a ball.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defvar blackbox-mode-map nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (if blackbox-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (setq blackbox-mode-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (suppress-keymap blackbox-mode-map t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (define-key blackbox-mode-map "\C-f" 'bb-right)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (define-key blackbox-mode-map [right] 'bb-right)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (define-key blackbox-mode-map "\C-b" 'bb-left)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (define-key blackbox-mode-map [left] 'bb-left)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (define-key blackbox-mode-map "\C-p" 'bb-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (define-key blackbox-mode-map [up] 'bb-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (define-key blackbox-mode-map "\C-n" 'bb-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (define-key blackbox-mode-map [down] 'bb-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (define-key blackbox-mode-map "\C-e" 'bb-eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (define-key blackbox-mode-map "\C-a" 'bb-bol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (define-key blackbox-mode-map " " 'bb-romp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (define-key blackbox-mode-map [insert] 'bb-romp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (define-key blackbox-mode-map "\C-m" 'bb-done)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
92 (define-key blackbox-mode-map [kp-enter] 'bb-done))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; Blackbox mode is suitable only for specially formatted data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (put 'blackbox-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defvar bb-board)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defvar bb-balls-placed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defvar bb-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defvar bb-y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defvar bb-score)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defvar bb-detour-count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defun blackbox-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "Major mode for playing blackbox. To learn how to play blackbox,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 see the documentation for function `blackbox'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 The usual mnemonic keys move the cursor around the box.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 \\<blackbox-mode-map>\\[bb-bol] and \\[bb-eol] move to the beginning and end of line, respectively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 \\[bb-romp] -- send in a ray from point, or toggle a ball at point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 \\[bb-done] -- end game and get score
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (use-local-map blackbox-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq truncate-lines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (setq major-mode 'blackbox-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (setq mode-name "Blackbox"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (defun blackbox (num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 "Play blackbox. Optional prefix argument is the number of balls;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 the default is 4.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 What is blackbox?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 Blackbox is a game of hide and seek played on an 8 by 8 grid (the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Blackbox). Your opponent (Emacs, in this case) has hidden several
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 balls (usually 4) within this box. By shooting rays into the box and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 observing where they emerge it is possible to deduce the positions of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 the hidden balls. The fewer rays you use to find the balls, the lower
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 your score.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Overview of play:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 \\<blackbox-mode-map>\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 To play blackbox, type \\[blackbox]. An optional prefix argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 specifies the number of balls to be hidden in the box; the default is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 four.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 The cursor can be moved around the box with the standard cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 movement keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 To shoot a ray, move the cursor to the edge of the box and press SPC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 The result will be determined and the playfield updated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 You may place or remove balls in the box by moving the cursor into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 box and pressing \\[bb-romp].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 When you think the configuration of balls you have placed is correct,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 press \\[bb-done]. You will be informed whether you are correct or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 not, and be given your score. Your score is the number of letters and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 numbers around the outside of the box plus five for each incorrectly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 placed ball. If you placed any balls incorrectly, they will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 indicated with `x', and their actual positions indicated with `o'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 Details:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 There are three possible outcomes for each ray you send into the box:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 Detour: the ray is deflected and emerges somewhere other than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 where you sent it in. On the playfield, detours are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 denoted by matching pairs of numbers -- one where the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ray went in, and the other where it came out.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 Reflection: the ray is reflected and emerges in the same place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 it was sent in. On the playfield, reflections are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 denoted by the letter `R'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 Hit: the ray strikes a ball directly and is absorbed. It does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 not emerge from the box. On the playfield, hits are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 denoted by the letter `H'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 The rules for how balls deflect rays are simple and are best shown by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 example.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 As a ray approaches a ball it is deflected ninety degrees. Rays can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 be deflected multiple times. In the diagrams below, the dashes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 represent empty box locations and the letter `O' represents a ball.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 The entrance and exit points of each ray are marked with numbers as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 described under \"Detour\" above. Note that the entrance and exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 points are always interchangeable. `*' denotes the path taken by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ray.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 Note carefully the relative positions of the ball and the ninety
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 degree deflection it causes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 - * - - - - - - - - - - - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 - * - - - - - - - - - - - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 1 * * - - - - - - - - - - - - - - - O - - - - O -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 - - O - - - - - - - O - - - - - - - * * * * - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 - - - - - - - - - - - * * * * * 2 3 * * * - - * - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 - - - - - - - - - - - * - - - - - - - O - * - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 - - - - - - - - - - - * - - - - - - - - * * - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 - - - - - - - - - - - * - - - - - - - - * - O -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 2 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 As mentioned above, a reflection occurs when a ray emerges from the same point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 it was sent in. This can happen in several ways:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 - - - - - - - - - - - - - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 - - - - O - - - - - O - O - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 R * * * * - - - - - - - * - - - - O - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 - - - - O - - - - - - * - - - - R - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 - - - - - - - - - - - * - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 - - - - - - - - - - - * - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 - - - - - - - - R * * * * - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 - - - - - - - - - - - - O - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 In the first example, the ray is deflected downwards by the upper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ball, then left by the lower ball, and finally retraces its path to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 its point of origin. The second example is similar. The third
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 example is a bit anomalous but can be rationalized by realizing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ray never gets a chance to get into the box. Alternatively, the ray
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 can be thought of as being deflected downwards and immediately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 emerging from the box.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 A hit occurs when a ray runs straight into a ball:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 - - - - - - - - - - - - - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 - - - - - - - - - - - - - - - - - - - - O - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 - - - - - - - - - - - - O - - - H * * * * - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 - - - - - - - - H * * * * O - - - - - - * - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 - - - - - - - - - - - - O - - - - - - O - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 H * * * O - - - - - - - - - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 - - - - - - - - - - - - - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 - - - - - - - - - - - - - - - - - - - - - - - -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 Be sure to compare the second example of a hit with the first example of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 a reflection."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (switch-to-buffer "*Blackbox*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (blackbox-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (buffer-disable-undo (current-buffer))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
239 ;; XEmacs makes some local variables here and FSF doesn't.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (make-local-variable 'bb-board)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (setq bb-board (bb-init-board (or num 4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (make-local-variable 'bb-balls-placed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (setq bb-balls-placed nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (make-local-variable 'bb-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (setq bb-x -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (make-local-variable 'bb-y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (setq bb-y -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (make-local-variable 'bb-score)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (setq bb-score 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (make-local-variable 'bb-detour-count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (setq bb-detour-count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (bb-insert-board)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (bb-goto (cons bb-x bb-y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (defun bb-init-board (num-balls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (random t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (let (board pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (while (>= (setq num-balls (1- num-balls)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq pos (cons (random 8) (random 8)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (bb-member pos board)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (setq board (cons pos board)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 board))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun bb-insert-board ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (let (i (buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (insert " \n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (setq i 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (while (>= (setq i (1- i)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (insert " - - - - - - - - \n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (insert " \n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (insert (format "\nThere are %d balls in the box" (length bb-board)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (defun bb-right ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (if (= bb-x 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (forward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (setq bb-x (1+ bb-x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (defun bb-left ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (if (= bb-x -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (backward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (setq bb-x (1- bb-x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defun bb-up ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (if (= bb-y -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (setq bb-y (1- bb-y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defun bb-down ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (if (= bb-y 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (setq bb-y (1+ bb-y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defun bb-eol ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq bb-x 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (bb-goto (cons bb-x bb-y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (defun bb-bol ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (setq bb-x -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (bb-goto (cons bb-x bb-y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (defun bb-romp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ((and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (or (= bb-x -1) (= bb-x 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (or (= bb-y -1) (= bb-y 8))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ((bb-outside-box bb-x bb-y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (bb-trace-ray bb-x bb-y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (bb-place-ball bb-x bb-y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (defun bb-place-ball (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (let ((coord (cons x y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ((bb-member coord bb-balls-placed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq bb-balls-placed (bb-delete coord bb-balls-placed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (bb-update-board "-"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (setq bb-balls-placed (cons coord bb-balls-placed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (bb-update-board "O")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (defun bb-trace-ray (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (let ((result (bb-trace-ray-2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ((= x -1) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ((= x 8) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (t 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 y
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ((= y -1) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ((= y 8) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (t 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ((eq result 'hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (bb-update-board "H")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (setq bb-score (1+ bb-score)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ((equal result (cons x y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (bb-update-board "R")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (setq bb-score (1+ bb-score)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (setq bb-detour-count (1+ bb-detour-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (bb-update-board (format "%d" bb-detour-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (bb-goto result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (bb-update-board (format "%d" bb-detour-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (setq bb-score (+ bb-score 2))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (defun bb-trace-ray-2 (first x dx y dy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ((and (not first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (bb-outside-box x y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (cons x y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ((bb-member (cons (+ x dx) (+ y dy)) bb-board)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 'hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ((bb-member (cons (+ x dx dy) (+ y dy dx)) bb-board)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (bb-trace-ray-2 nil x (- dy) y (- dx)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ((bb-member (cons (+ x dx (- dy)) (+ y dy (- dx))) bb-board)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (bb-trace-ray-2 nil x dy y dx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (bb-trace-ray-2 nil (+ x dx) dx (+ y dy) dy))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (defun bb-done ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 "Finish the game and report score."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (let (bogus-balls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ((not (= (length bb-balls-placed) (length bb-board)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (message "There %s %d hidden ball%s; you have placed %d."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (if (= (length bb-board) 1) "is" "are")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (length bb-board)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (if (= (length bb-board) 1) "" "s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (length bb-balls-placed)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (setq bogus-balls (bb-show-bogus-balls bb-balls-placed bb-board))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (if (= bogus-balls 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (message "Right! Your score is %d." bb-score)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (message "Oops! You missed %d ball%s. Your score is %d."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 bogus-balls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (if (= bogus-balls 1) "" "s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (+ bb-score (* 5 bogus-balls))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (bb-goto '(-1 . -1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (defun bb-show-bogus-balls (balls-placed board)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (bb-show-bogus-balls-2 balls-placed board "x")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (bb-show-bogus-balls-2 board balls-placed "o"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (defun bb-show-bogus-balls-2 (list-1 list-2 c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ((null list-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ((bb-member (car list-1) list-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (bb-show-bogus-balls-2 (cdr list-1) list-2 c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (bb-goto (car list-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (bb-update-board c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (1+ (bb-show-bogus-balls-2 (cdr list-1) list-2 c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (defun bb-outside-box (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (or (= x -1) (= x 8) (= y -1) (= y 8)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (defun bb-goto (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (goto-char (+ (* (car pos) 2) (* (cdr pos) 22) 26)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defun bb-update-board (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (backward-char (1- (length c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (delete-char (length c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (insert c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (defun bb-member (elt list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 "Returns non-nil if ELT is an element of LIST."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (eval (cons 'or (mapcar (function (lambda (x) (equal x elt))) list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (defun bb-delete (item list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 "Deletes ITEM from LIST and returns a copy."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ((equal item (car list)) (cdr list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (t (cons (car list) (bb-delete item (cdr list))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ;;; blackbox.el ends here