diff options
author | Jim Blandy <jimb@redhat.com> | 1992-12-06 22:41:11 +0000 |
---|---|---|
committer | Jim Blandy <jimb@redhat.com> | 1992-12-06 22:41:11 +0000 |
commit | 84df0b376f8f24b48bcc39d06a216746b6fbc2a1 (patch) | |
tree | b95db66b4756c25018ddd3b50967894fd74591bd /lisp/play | |
parent | bc254115cc2b986907c35035967f5b7edbaf6ccb (diff) | |
download | emacs-84df0b376f8f24b48bcc39d06a216746b6fbc2a1.tar.gz |
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.
Diffstat (limited to 'lisp/play')
-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 @@ 3 (prefix-numeric-value current-prefix-arg)))) (if (<= nrings 0) (error "Negative number of rings")) - (let (pole-spacing - floor-row - fly-row - (window-height (window-height (selected-window))) - (window-width (window-width (selected-window)))) - (let ((h (+ nrings 2)) - (w (+ (* (1- nrings) 6) 2 5))) - (if (not (and (>= window-width h) - (> window-width w))) + (let* (floor-row + fly-row + (window-height (window-height (selected-window))) + (window-width (window-width (selected-window))) + + ;; This is the unit of spacing to use between poles. It + ;; must be even. We round down, since rounding up might + ;; cause us to draw off the edge of the window. + (pole-spacing (logand (/ window-width 6) (lognot 1)))) + (let ( + ;; The poles are (1+ NRINGS) rows high; we also want an + ;; empty row at the top for the flying rings, a base, and a + ;; blank line underneath that. + (h (+ nrings 4)) + + ;; If we have NRINGS rings, we label them with the numbers 0 + ;; through NRINGS-1. The width of ring i is 2i+3; it pokes + ;; out i spaces on either side of the pole. Rather than + ;; checking if the window is wide enough to accomodate this, + ;; we make sure pole-spacing is large enough, since that + ;; works even when we have decremented pole-spacing to make + ;; it even. + (w (1+ nrings))) + (if (not (and (>= window-height h) + (> pole-spacing w))) (progn (delete-other-windows) (if (not (and (>= (setq window-height - (window-height (selected-window))) h) - (> (setq window-width - (window-width (selected-window))) w))) + (window-height (selected-window))) + h) + (> (setq pole-spacing + (logand (/ window-width 6) (lognot 1))) + w))) (error "Screen is too small (need at least %dx%d)" w h)))) - (setq pole-spacing (/ window-width 6)) - (if (not (zerop (logand pole-spacing 1))) - ;; must be even - (setq pole-spacing (1+ pole-spacing))) (setq floor-row (if (> (- window-height 3) h) (- window-height 3) window-height))) (let ((fly-row (- floor-row nrings 1)) @@ -197,4 +211,4 @@ (backward-char (/ (+ len 1) 2)) (delete-char 1) (insert ?\|)))))) -;;; hanoi.el
\ No newline at end of file +;;; hanoi.el |