1 |
;;; blackbox.el --- blackbox game in Emacs Lisp |
;;; blackbox.el --- blackbox game in Emacs Lisp |
2 |
|
|
3 |
;; Copyright (C) 1985, 1986, 1987, 1992, 2001 Free Software Foundation, Inc. |
;; Copyright (C) 1985, 1986, 1987, 1992, 2001, 2002 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: F. Thomas May <uw-nsr!uw-warp!tom@beaver.cs.washington.edu> |
;; Author: F. Thomas May <uw-nsr!uw-warp!tom@beaver.cs.washington.edu> |
6 |
;; Adapted-By: ESR |
;; Adapted-By: ESR |
34 |
;; pass thru the box undisturbed, 2) it will hit a ball and be absorbed, |
;; pass thru the box undisturbed, 2) it will hit a ball and be absorbed, |
35 |
;; 3) it will be deflected and exit the box, or 4) be deflected immediately, |
;; 3) it will be deflected and exit the box, or 4) be deflected immediately, |
36 |
;; not even being allowed entry into the box. |
;; not even being allowed entry into the box. |
37 |
;; |
;; |
38 |
;; The strange part is the method of deflection. It seems that rays will |
;; The strange part is the method of deflection. It seems that rays will |
39 |
;; not pass next to a ball, and change direction at right angles to avoid it. |
;; not pass next to a ball, and change direction at right angles to avoid it. |
40 |
;; |
;; |
41 |
;; R 3 |
;; R 3 |
42 |
;; 1 - - - - - - - - 1 |
;; 1 - - - - - - - - 1 |
43 |
;; - - - - - - - - |
;; - - - - - - - - |
44 |
;; - O - - - - - - 3 |
;; - O - - - - - - 3 |
45 |
;; 2 - - - - O - O - |
;; 2 - - - - O - O - |
46 |
;; 4 - - - - - - - - |
;; 4 - - - - - - - - |
47 |
;; 5 - - - - - - - - 5 |
;; 5 - - - - - - - - 5 |
48 |
;; - - - - - - - - R |
;; - - - - - - - - R |
49 |
;; H - - - - - - - O |
;; H - - - - - - - O |
50 |
;; 2 H 4 H |
;; 2 H 4 H |
51 |
;; |
;; |
52 |
;; Rays which enter and exit are numbered. You can see that rays 1 & 5 pass |
;; Rays which enter and exit are numbered. You can see that rays 1 & 5 pass |
53 |
;; thru the box undisturbed. Ray 2 is deflected by the northwesternmost |
;; thru the box undisturbed. Ray 2 is deflected by the northwesternmost |
54 |
;; ball. Likewise rays 3 and 4. Rays which hit balls and are absorbed are |
;; ball. Likewise rays 3 and 4. Rays which hit balls and are absorbed are |
194 |
Note carefully the relative positions of the ball and the ninety |
Note carefully the relative positions of the ball and the ninety |
195 |
degree deflection it causes. |
degree deflection it causes. |
196 |
|
|
197 |
1 |
1 |
198 |
- * - - - - - - - - - - - - - - - - - - - - - - |
- * - - - - - - - - - - - - - - - - - - - - - - |
199 |
- * - - - - - - - - - - - - - - - - - - - - - - |
- * - - - - - - - - - - - - - - - - - - - - - - |
200 |
1 * * - - - - - - - - - - - - - - - O - - - - O - |
1 * * - - - - - - - - - - - - - - - O - - - - O - |
201 |
- - O - - - - - - - O - - - - - - - * * * * - - |
- - O - - - - - - - O - - - - - - - * * * * - - |
202 |
- - - - - - - - - - - * * * * * 2 3 * * * - - * - - |
- - - - - - - - - - - * * * * * 2 3 * * * - - * - - |
203 |
- - - - - - - - - - - * - - - - - - - O - * - - |
- - - - - - - - - - - * - - - - - - - O - * - - |
204 |
- - - - - - - - - - - * - - - - - - - - * * - - |
- - - - - - - - - - - * - - - - - - - - * * - - |
205 |
- - - - - - - - - - - * - - - - - - - - * - O - |
- - - - - - - - - - - * - - - - - - - - * - O - |
206 |
2 3 |
2 3 |
207 |
|
|
208 |
As mentioned above, a reflection occurs when a ray emerges from the same point |
As mentioned above, a reflection occurs when a ray emerges from the same point |
209 |
it was sent in. This can happen in several ways: |
it was sent in. This can happen in several ways: |
210 |
|
|
211 |
|
|
212 |
- - - - - - - - - - - - - - - - - - - - - - - - |
- - - - - - - - - - - - - - - - - - - - - - - - |
213 |
- - - - O - - - - - O - O - - - - - - - - - - - |
- - - - O - - - - - O - O - - - - - - - - - - - |
214 |
R * * * * - - - - - - - * - - - - O - - - - - - - |
R * * * * - - - - - - - * - - - - O - - - - - - - |
275 |
(insert (format "\nThere are %d balls in the box" (length bb-board))) |
(insert (format "\nThere are %d balls in the box" (length bb-board))) |
276 |
)) |
)) |
277 |
|
|
278 |
(defun bb-right () |
(defun bb-right (count) |
279 |
(interactive) |
(interactive "p") |
280 |
(if (= bb-x 8) |
(while (and (> count 0) (< bb-x 8)) |
|
() |
|
281 |
(forward-char 2) |
(forward-char 2) |
282 |
(setq bb-x (1+ bb-x)))) |
(setq bb-x (1+ bb-x)) |
283 |
|
(setq count (1- count)))) |
284 |
|
|
285 |
(defun bb-left () |
(defun bb-left (count) |
286 |
(interactive) |
(interactive "p") |
287 |
(if (= bb-x -1) |
(while (and (> count 0) (> bb-x -1)) |
|
() |
|
288 |
(backward-char 2) |
(backward-char 2) |
289 |
(setq bb-x (1- bb-x)))) |
(setq bb-x (1- bb-x)) |
290 |
|
(setq count (1- count)))) |
291 |
|
|
292 |
(defun bb-up () |
(defun bb-up (count) |
293 |
(interactive) |
(interactive "p") |
294 |
(if (= bb-y -1) |
(while (and (> count 0) (> bb-y -1)) |
|
() |
|
295 |
(previous-line 1) |
(previous-line 1) |
296 |
(setq bb-y (1- bb-y)))) |
(setq bb-y (1- bb-y)) |
297 |
|
(setq count (1- count)))) |
298 |
|
|
299 |
(defun bb-down () |
(defun bb-down (count) |
300 |
(interactive) |
(interactive "p") |
301 |
(if (= bb-y 8) |
(while (and (> count 0) (< bb-y 8)) |
|
() |
|
302 |
(next-line 1) |
(next-line 1) |
303 |
(setq bb-y (1+ bb-y)))) |
(setq bb-y (1+ bb-y)) |
304 |
|
(setq count (1- count)))) |
305 |
|
|
306 |
(defun bb-eol () |
(defun bb-eol () |
307 |
(interactive) |
(interactive) |
426 |
(delete-char (length c)) |
(delete-char (length c)) |
427 |
(insert c) |
(insert c) |
428 |
(backward-char 1))) |
(backward-char 1))) |
429 |
|
|
430 |
(provide 'blackbox) |
(provide 'blackbox) |
431 |
|
|
432 |
;;; blackbox.el ends here |
;;; blackbox.el ends here |