;; test-loop
;;
;; This procedure shows you how easy it is to test your code without
;; the gamesman framework. Here's how to use it on Tomororw's Tic-Tac-Toe:
;; (except you'd replace mtttt with your module name):
;;
;; unix% cd ~/ucwise/gamesman
;; unix% stk -load gamesman
;; STk> (load "test-loop.scm")
;; STk> (load "modules/mtttt")
;; STk> (test-loop (get-rule 'initial-position))

(define (test-loop position)
  (newline)
  (print-position position)                                ;; Print position
  (if (primitive-position position)                        ;; If we're done...
      (begin (display "Game over! It's a ")                ;; say so
             (display (primitive-position position))
             (newline))
      (let ((moves (generate-moves position)))             ;; Get all moves
        (display "The valid moves are: ")
        (for-each (lambda (m) (display m) (display " ")) moves) ;; print 'em
        (display "\n\nEnter a move (q=Quit): ")
        (let ((move (read)))                               ;; Read move
          (cond ((equal? move 'q) position)                ;; q=quit
                ((member move moves)                       ;; If valid move
                 (test-loop (do-move position move)))      ;; do it & loop
                (else (display "Bad move: ")
                      (display move)                       ;; Otherwise
                      (test-loop position)))))))           ;; try again