annotate lisp/play/hanoi.el @ 584:4cd7543be581

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Mon, 16 Mar 1992 20:39:07 +0000
parents 1e0bc00dca7a
children 08eb386dd0f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
1 ;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
2 ; hanoi - towers of hanoi in GNUmacs
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
3 ;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
4 ; Author (a) 1985, Damon Anton Permezel
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
5 ;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 ;;; hanoi-topos - direct cursor addressing
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 (defun hanoi-topos (row col)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 (goto-line row)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 (beginning-of-line)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 (forward-char col))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;;; hanoi - user callable Towers of Hanoi
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;;;
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 53
diff changeset
18 ;;;###autoload
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19 (defun hanoi (nrings)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 "Towers of Hanoi diversion. Argument is number of rings."
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21 (interactive
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22 (list (if (null current-prefix-arg)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
23 3
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
24 (prefix-numeric-value current-prefix-arg))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
25 (if (<= nrings 0) (error "Negative number of rings"))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
26 (let (pole-spacing
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
27 floor-row
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
28 fly-row
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
29 (window-height (window-height (selected-window)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
30 (window-width (window-width (selected-window))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31 (let ((h (+ nrings 2))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32 (w (+ (* (1- nrings) 6) 2 5)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
33 (if (not (and (>= window-width h)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
34 (> window-width w)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
35 (progn
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
36 (delete-other-windows)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37 (if (not (and (>= (setq window-height
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
38 (window-height (selected-window))) h)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39 (> (setq window-width
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 (window-width (selected-window))) w)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 (error "Screen is too small (need at least %dx%d)" w h))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
42 (setq pole-spacing (/ window-width 6))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43 (if (not (zerop (logand pole-spacing 1)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 ;; must be even
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 (setq pole-spacing (1+ pole-spacing)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 (setq floor-row (if (> (- window-height 3) h)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47 (- window-height 3) window-height)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 (let ((fly-row (- floor-row nrings 1))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49 ;; pole: column . fill height
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
50 (pole-1 (cons pole-spacing floor-row))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
51 (pole-2 (cons (* 3 pole-spacing) floor-row))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
52 (pole-3 (cons (* 5 pole-spacing) floor-row))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
53 (rings (make-vector nrings nil)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 ;; construct the ring list
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 (let ((i 0))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 (while (< i nrings)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57 ;; ring: [pole-number string empty-string]
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 (aset rings i (vector nil
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59 (make-string (+ i i 3) (+ ?0 i))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60 (make-string (+ i i 3) ?\ )))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
61 (setq i (1+ i))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
62 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63 ;; init the screen
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 (switch-to-buffer "*Hanoi*")
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 (setq buffer-read-only nil)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 (buffer-disable-undo (current-buffer))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 (erase-buffer)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 (let ((i 0))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
70 (while (< i floor-row)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
71 (setq i (1+ i))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
72 (insert-char ?\ (1- window-width))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 (insert ?\n)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74 (insert-char ?= (1- window-width))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
76 (let ((n 1))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
77 (while (< n 6)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
78 (hanoi-topos fly-row (* n pole-spacing))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 (setq n (+ n 2))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 (let ((i fly-row))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
81 (while (< i floor-row)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
82 (setq i (1+ i))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 (next-line 1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 (insert ?\|)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
85 (delete-char 1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86 (backward-char 1)))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 ;(sit-for 0)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 ;; now draw the rings in their initial positions
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 (let ((i 0)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 ring)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 (while (< i nrings)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 (setq ring (aref rings (- nrings 1 i)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 (aset ring 0 (- floor-row i))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 (hanoi-topos (cdr pole-1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 (- (car pole-1) (- nrings i)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98 (hanoi-draw-ring ring t nil)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 (setcdr pole-1 (1- (cdr pole-1)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 (setq i (1+ i))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 (setq buffer-read-only t)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 (sit-for 0)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 ;; do it!
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
106 (hanoi0 (1- nrings) pole-1 pole-2 pole-3)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 (goto-char (point-min))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108 (message "Done")
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
109 (setq buffer-read-only t)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
110 (set-buffer-modified-p (buffer-modified-p))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
111 (sit-for 0))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
113 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114 ;;; hanoi0 - work horse of hanoi
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 (defun hanoi0 (n from to work)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 (cond ((input-pending-p)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 (signal 'quit (list "I can tell you've had enough")))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 ((< n 0))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120 (t
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 (hanoi0 (1- n) from work to)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
122 (hanoi-move-ring n from to)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
123 (hanoi0 (1- n) work to from))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
126 ;;; hanoi-move-ring - move ring 'n' from 'from' to 'to'
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
127 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
128 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
129 (defun hanoi-move-ring (n from to)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 (let ((ring (aref rings n)) ; ring <- ring: (ring# . row)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131 (buffer-read-only nil))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
132 (let ((row (aref ring 0)) ; row <- row ring is on
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 (col (- (car from) n 1)) ; col <- left edge of ring
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
134 (dst-col (- (car to) n 1)) ; dst-col <- dest col for left edge
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
135 (dst-row (cdr to))) ; dst-row <- dest row for ring
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136 (hanoi-topos row col)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
137 (while (> row fly-row) ; move up to the fly row
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
138 (hanoi-draw-ring ring nil t) ; blank out ring
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
139 (previous-line 1) ; move up a line
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
140 (hanoi-draw-ring ring t nil) ; redraw
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
141 (sit-for 0)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
142 (setq row (1- row)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
143 (setcdr from (1+ (cdr from))) ; adjust top row
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
144 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
145 ;; fly the ring over to the right pole
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
146 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
147 (while (not (equal dst-col col))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
148 (cond ((> dst-col col) ; dst-col > col: right shift
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
149 (end-of-line 1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150 (delete-backward-char 2)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
151 (beginning-of-line 1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
152 (insert ?\ ?\ )
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
153 (sit-for 0)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
154 (setq col (1+ (1+ col))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
155 ((< dst-col col) ; dst-col < col: left shift
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
156 (beginning-of-line 1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
157 (delete-char 2)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
158 (end-of-line 1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
159 (insert ?\ ?\ )
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
160 (sit-for 0)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
161 (setq col (1- (1- col))))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
162 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
163 ;; let the ring float down
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
164 ;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
165 (hanoi-topos fly-row dst-col)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
166 (while (< row dst-row) ; move down to the dest row
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
167 (hanoi-draw-ring ring nil (> row fly-row)) ; blank out ring
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
168 (next-line 1) ; move down a line
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
169 (hanoi-draw-ring ring t nil) ; redraw ring
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
170 (sit-for 0)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
171 (setq row (1+ row)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
172 (aset ring 0 dst-row)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
173 (setcdr to (1- (cdr to)))))) ; adjust top row
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
174
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
175 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
176 ;;; draw-ring - draw the ring at point, leave point unchanged
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
177 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
178 ;;; Input:
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
179 ;;; ring
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
180 ;;; f1 - flag: t -> draw, nil -> erase
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
181 ;;; f2 - flag: t -> erasing and need to draw ?\|
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
182 ;;;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
183 (defun hanoi-draw-ring (ring f1 f2)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
184 (save-excursion
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
185 (let* ((string (if f1 (aref ring 1) (aref ring 2)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
186 (len (length string)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
187 (delete-char len)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
188 (insert string)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
189 (if f2
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
190 (progn
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
191 (backward-char (/ (+ len 1) 2))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
192 (delete-char 1) (insert ?\|))))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
193