altos/lisp: Improve hanoi demo
[fw/altos] / src / test / hanoi.lisp
index 01398d9121029dba270802d9362e687bb3e9c888..0c4bfca5cfb077b4f5d69ca6133bac8312d0c06a 100644 (file)
@@ -6,36 +6,31 @@
   (patom "\033[2J" nil)
   )
 
-(defun test ()
-  (clear)
-  (move-to 30 12)
-  (patom "hello, world")
-  (move-to 0 19)
-  )
-
 (setq stack '("*" "**" "***" "****" "*****" "******" "*******"))
 
+(setq top (+ (length stack) 3))
+
 (setq stacks nil)
 
 (defun display-string (x y str)
-  (move-to x y)
   (move-to x y)
   (patom str)
   )
 
-(defun display-stack (x y stack)
-  (cond (stack (progn
-                (display-string x y (car stack))
-                (display-stack x (1+ y) (cdr stack)))))
-  )
-
-(defun clear-stack (x y)
-  (cond ((> y 0) (progn
-                  (move-to x y)
-                  (patom "            ")
-                  (clear-stack x (1- y))
-                  )
+(defun display-stack (x y clear stack)
+  (cond ((= 0 clear)
+        (cond (stack (progn
+                       (display-string x y (car stack))
+                       (display-stack x (1+ y) 0 (cdr stack))
+                       )
+                     )
+              )
         )
+       (t (progn
+            (display-string x y "          ")
+            (display-stack x (1+ y) (1- clear) stack)
+            )
+          )
        )
   )
 
 
 (defun display-stacks (x y stacks)
   (cond (stacks (progn
-                 (clear-stack x 20)
-                 (display-stack x (stack-pos y (car stacks)) (car stacks))
+                 (display-stack x 0 (stack-pos y (car stacks)) (car stacks))
                  (display-stacks (+ x 20) y (cdr stacks)))
                )
        )
   )
 
 (defun display ()
-  (display-stacks 0 20 stacks)
+  (display-stacks 0 top stacks)
   (move-to 1 21)
   (flush)
   )