diff options
| author | Jim Blandy | 1992-12-06 22:41:11 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-12-06 22:41:11 +0000 |
| commit | 84df0b376f8f24b48bcc39d06a216746b6fbc2a1 (patch) | |
| tree | b95db66b4756c25018ddd3b50967894fd74591bd | |
| parent | bc254115cc2b986907c35035967f5b7edbaf6ccb (diff) | |
| download | emacs-84df0b376f8f24b48bcc39d06a216746b6fbc2a1.tar.gz emacs-84df0b376f8f24b48bcc39d06a216746b6fbc2a1.zip | |
Tue Dec 1 22:34:42 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
* hanoi.el (hanoi): If pole-spacing is odd, round down, not up.
To see if the window is wide enough, just check if one half of a
ring will fit inside pole-spacing.
| -rw-r--r-- | lisp/play/hanoi.el | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/lisp/play/hanoi.el b/lisp/play/hanoi.el index 65c5afe6e69..e65608235fd 100644 --- a/lisp/play/hanoi.el +++ b/lisp/play/hanoi.el | |||
| @@ -29,26 +29,40 @@ | |||
| 29 | 3 | 29 | 3 |
| 30 | (prefix-numeric-value current-prefix-arg)))) | 30 | (prefix-numeric-value current-prefix-arg)))) |
| 31 | (if (<= nrings 0) (error "Negative number of rings")) | 31 | (if (<= nrings 0) (error "Negative number of rings")) |
| 32 | (let (pole-spacing | 32 | (let* (floor-row |
| 33 | floor-row | 33 | fly-row |
| 34 | fly-row | 34 | (window-height (window-height (selected-window))) |
| 35 | (window-height (window-height (selected-window))) | 35 | (window-width (window-width (selected-window))) |
| 36 | (window-width (window-width (selected-window)))) | 36 | |
| 37 | (let ((h (+ nrings 2)) | 37 | ;; This is the unit of spacing to use between poles. It |
| 38 | (w (+ (* (1- nrings) 6) 2 5))) | 38 | ;; must be even. We round down, since rounding up might |
| 39 | (if (not (and (>= window-width h) | 39 | ;; cause us to draw off the edge of the window. |
| 40 | (> window-width w))) | 40 | (pole-spacing (logand (/ window-width 6) (lognot 1)))) |
| 41 | (let ( | ||
| 42 | ;; The poles are (1+ NRINGS) rows high; we also want an | ||
| 43 | ;; empty row at the top for the flying rings, a base, and a | ||
| 44 | ;; blank line underneath that. | ||
| 45 | (h (+ nrings 4)) | ||
| 46 | |||
| 47 | ;; If we have NRINGS rings, we label them with the numbers 0 | ||
| 48 | ;; through NRINGS-1. The width of ring i is 2i+3; it pokes | ||
| 49 | ;; out i spaces on either side of the pole. Rather than | ||
| 50 | ;; checking if the window is wide enough to accomodate this, | ||
| 51 | ;; we make sure pole-spacing is large enough, since that | ||
| 52 | ;; works even when we have decremented pole-spacing to make | ||
| 53 | ;; it even. | ||
| 54 | (w (1+ nrings))) | ||
| 55 | (if (not (and (>= window-height h) | ||
| 56 | (> pole-spacing w))) | ||
| 41 | (progn | 57 | (progn |
| 42 | (delete-other-windows) | 58 | (delete-other-windows) |
| 43 | (if (not (and (>= (setq window-height | 59 | (if (not (and (>= (setq window-height |
| 44 | (window-height (selected-window))) h) | 60 | (window-height (selected-window))) |
| 45 | (> (setq window-width | 61 | h) |
| 46 | (window-width (selected-window))) w))) | 62 | (> (setq pole-spacing |
| 63 | (logand (/ window-width 6) (lognot 1))) | ||
| 64 | w))) | ||
| 47 | (error "Screen is too small (need at least %dx%d)" w h)))) | 65 | (error "Screen is too small (need at least %dx%d)" w h)))) |
| 48 | (setq pole-spacing (/ window-width 6)) | ||
| 49 | (if (not (zerop (logand pole-spacing 1))) | ||
| 50 | ;; must be even | ||
| 51 | (setq pole-spacing (1+ pole-spacing))) | ||
| 52 | (setq floor-row (if (> (- window-height 3) h) | 66 | (setq floor-row (if (> (- window-height 3) h) |
| 53 | (- window-height 3) window-height))) | 67 | (- window-height 3) window-height))) |
| 54 | (let ((fly-row (- floor-row nrings 1)) | 68 | (let ((fly-row (- floor-row nrings 1)) |
| @@ -197,4 +211,4 @@ | |||
| 197 | (backward-char (/ (+ len 1) 2)) | 211 | (backward-char (/ (+ len 1) 2)) |
| 198 | (delete-char 1) (insert ?\|)))))) | 212 | (delete-char 1) (insert ?\|)))))) |
| 199 | 213 | ||
| 200 | ;;; hanoi.el \ No newline at end of file | 214 | ;;; hanoi.el |