diff --git a/gib-gab-gob/board.scm b/gib-gab-gob/board.scm index d986ee3..ada7626 100644 --- a/gib-gab-gob/board.scm +++ b/gib-gab-gob/board.scm @@ -2,6 +2,7 @@ #:use-module (srfi srfi-1) #:export (make-board board-ref + board-assert-vacant board-choose! board-display board-winner?)) @@ -11,14 +12,13 @@ (define (make-board) (make-array #f ggg-size ggg-size)) -(define (board-ref board x y) - (array-ref board y x)) +(define (board-assert-vacant x y) + (define ref (board-ref board x y)) + (if ref (error "That space is already occupied with:" ref) ref)) (define (board-choose! board val x y) - (define ref (board-ref board x y)) - (if ref - (error "That space is already occupied with:" ref) - (array-set! board val y x))) + (board-assert-vacant) + (array-set! board val y x)) (define (board-display board) (array-slice-for-each-in-order diff --git a/gib-gab-gob/game.scm b/gib-gab-gob/game.scm index 0d1fa61..fdbb8d7 100644 --- a/gib-gab-gob/game.scm +++ b/gib-gab-gob/game.scm @@ -31,12 +31,14 @@ ;; TODO: These need to go somewhere else so the peer can't move or init for us! [(try-transition) 'playing] [(initialize!) - (on (<- peer 'try-transition) (lambda (status) (format #t "Peer's status: ~a\n" status)) #:promise? #t)] + (on (<- peer 'try-transition) (λ (status) (format #t "Peer's status: ~a\n" status)) #:promise? #t)] [(my-turn! x y) (if my-turn? (begin - (board-choose! board mark x y) - (set! my-turn? (not my-turn?)) - (display) - (<- peer 'peer-turn! x y)) + (board-assert-vacant board x y) + (on (<- peer 'peer-turn! x y) + (λ (_) + (board-choose! board mark x y) + (set! my-turn? (not my-turn?)) + (display)))) (error "It's not my turn."))]))