(define-module (gib-gab-gob ui console) #:use-module (gib-gab-gob board) #:use-module (ice-9 rdelim) #:use-module (ice-9 exceptions) #:export (begin-game-loop)) ;; Module for simple console-based UI (no curses) ;; A single run of the loop for a bespoke REPL for playing the game (define (%loop b) (%print b) (let ((coords (%read))) (if coords (%eval coords) #f))) (define (%read) (define line (read-line (current-input-port))) (if (string-prefix? ",q" line) #f (let ((coords (map string->number (string-tokenize line char-set:digit)))) (if (not (= (length coords) 2)) (begin (format #t "Must be two numbers, x y; or ,quit to quit. Try again.\n") (%prompt) (%read)) coords)))) (define (%eval coordinates) (format #t "Moving ~a\n" coordinates)) (define (%print board) (board-display board) (%prompt)) (define (%prompt) (format #t "Enter your move: ")) (define (begin-game-loop board) (while (%loop board)) (format #t "bye-bye!\n") #f)