Check if we are vacant and set after peer done.
This commit is contained in:
parent
aea22730d3
commit
ffddf2a975
|
@ -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
|
||||
|
|
|
@ -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."))]))
|
||||
|
|
Loading…
Reference in New Issue