projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
altos/lisp: Clean up hanoi.lisp comments.
[fw/altos]
/
src
/
test
/
hanoi.lisp
diff --git
a/src/test/hanoi.lisp
b/src/test/hanoi.lisp
index b84b8174737c56d928d0b790f140f31ab6e087da..d8ff2c86583220d3efbef3bc8856e87942cc50b2 100644
(file)
--- a/
src/test/hanoi.lisp
+++ b/
src/test/hanoi.lisp
@@
-14,8
+14,7
@@
; General Public License for more details.
;
; General Public License for more details.
;
-
-; ANSI control sequences
+ ; ANSI control sequences
(defun move-to (col row)
(patom "\033[" row ";" col "H" nil)
(defun move-to (col row)
(patom "\033[" row ";" col "H" nil)
@@
-30,20
+29,17
@@
(patom str)
)
(patom str)
)
-; Here's the pieces to display
+
; Here's the pieces to display
-(setq stack '("
*" "**" "***" "****" "*****" "******" "
*******"))
+(setq stack '("
* " " *** " " ***** " " ******* " " ********* " "****
*******"))
-(setq top (+ (length stack) 3))
+ ; Here's all of the stacks of pieces
+ ; This is generated when the program is run
-;
-; Here's all of the stacks of pieces
-; This is generated when the program is run
-;
(setq stacks nil)
(setq stacks nil)
-; Display one stack, clearing any
-; space above it
+
; Display one stack, clearing any
+
; space above it
(defun display-stack (x y clear stack)
(cond ((= 0 clear)
(defun display-stack (x y clear stack)
(cond ((= 0 clear)
@@
-55,29
+51,21
@@
)
)
(t (progn
)
)
(t (progn
- (display-string x y " ")
+ (display-string x y "
")
(display-stack x (1+ y) (1- clear) stack)
)
)
)
)
(display-stack x (1+ y) (1- clear) stack)
)
)
)
)
-; This should probably be included in the rom image...
-
-(defun length (list)
- (cond (list (1+ (length (cdr list))))
- (0)
- )
- )
-
-; Position of the top of the stack on the screen
-; Shorter stacks start further down the screen
+ ; Position of the top of the stack on the screen
+ ; Shorter stacks start further down the screen
(defun stack-pos (y stack)
(- y (length stack))
)
(defun stack-pos (y stack)
(- y (length stack))
)
-; Display all of the stacks, spaced 20 columns apart
+
; Display all of the stacks, spaced 20 columns apart
(defun display-stacks (x y stacks)
(cond (stacks (progn
(defun display-stacks (x y stacks)
(cond (stacks (progn
@@
-87,8
+75,8
@@
)
)
)
)
-; Display all of the stacks, then move the cursor
-; out of the way and flush the output
+
; Display all of the stacks, then move the cursor
+
; out of the way and flush the output
(defun display ()
(display-stacks 0 top stacks)
(defun display ()
(display-stacks 0 top stacks)
@@
-96,17
+84,18
@@
(flush)
)
(flush)
)
-; Reset stacks to the starting state, with
-; all of the pieces in the first stack and the
-; other two empty
+
; Reset stacks to the starting state, with
+
; all of the pieces in the first stack and the
+
; other two empty
(defun reset-stacks ()
(setq stacks (list stack nil nil))
(defun reset-stacks ()
(setq stacks (list stack nil nil))
+ (setq top (+ (length stack) 3))
(length stack)
)
(length stack)
)
-; more functions which could usefully
-; be in the rom image
+
; more functions which could usefully
+
; be in the rom image
(defun min (a b)
(cond ((< a b) a)
(defun min (a b)
(cond ((< a b) a)
@@
-114,14
+103,8
@@
)
)
)
)
-(defun nth (list n)
- (cond ((= n 0) (car list))
- ((nth (cdr list) (1- n)))
- )
- )
-
-; Replace a stack in the list of stacks
-; with a new value
+ ; Replace a stack in the list of stacks
+ ; with a new value
(defun replace (list pos member)
(cond ((= pos 0) (cons member (cdr list)))
(defun replace (list pos member)
(cond ((= pos 0) (cons member (cdr list)))
@@
-129,8
+112,8
@@
)
)
)
)
-; Move a piece from the top of one stack
-; to the top of another
+
; Move a piece from the top of one stack
+
; to the top of another
(defun move-piece (from to)
(let ((from-stack (nth stacks from))
(defun move-piece (from to)
(let ((from-stack (nth stacks from))
@@
-163,13
+146,25
@@
)
)
)
)
-; A pretty interface which
-; resets the state of the game,
-; clears the screen and runs
-; the program
+
; A pretty interface which
+
; resets the state of the game,
+
; clears the screen and runs
+
; the program
(defun hanoi ()
(setq len (reset-stacks))
(clear)
(_hanoi len 0 1 2)
(defun hanoi ()
(setq len (reset-stacks))
(clear)
(_hanoi len 0 1 2)
+ )
+
+ ; Run many in a row to time them
+
+(defun hanois(n)
+ (cond ((> n 0)
+ (progn
+ (hanoi)
+ (hanois (1- n))
+ )
+ )
+ )
)
)