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)
|
#:use-module (srfi srfi-1)
|
||||||
#:export (make-board
|
#:export (make-board
|
||||||
board-ref
|
board-ref
|
||||||
|
board-assert-vacant
|
||||||
board-choose!
|
board-choose!
|
||||||
board-display
|
board-display
|
||||||
board-winner?))
|
board-winner?))
|
||||||
|
@ -11,14 +12,13 @@
|
||||||
(define (make-board)
|
(define (make-board)
|
||||||
(make-array #f ggg-size ggg-size))
|
(make-array #f ggg-size ggg-size))
|
||||||
|
|
||||||
(define (board-ref board x y)
|
(define (board-assert-vacant x y)
|
||||||
(array-ref board y x))
|
(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 (board-choose! board val x y)
|
||||||
(define ref (board-ref board x y))
|
(board-assert-vacant)
|
||||||
(if ref
|
(array-set! board val y x))
|
||||||
(error "That space is already occupied with:" ref)
|
|
||||||
(array-set! board val y x)))
|
|
||||||
|
|
||||||
(define (board-display board)
|
(define (board-display board)
|
||||||
(array-slice-for-each-in-order
|
(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!
|
;; TODO: These need to go somewhere else so the peer can't move or init for us!
|
||||||
[(try-transition) 'playing]
|
[(try-transition) 'playing]
|
||||||
[(initialize!)
|
[(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)
|
[(my-turn! x y)
|
||||||
(if my-turn?
|
(if my-turn?
|
||||||
(begin
|
(begin
|
||||||
(board-choose! board mark x y)
|
(board-assert-vacant board x y)
|
||||||
(set! my-turn? (not my-turn?))
|
(on (<- peer 'peer-turn! x y)
|
||||||
(display)
|
(λ (_)
|
||||||
(<- peer 'peer-turn! x y))
|
(board-choose! board mark x y)
|
||||||
|
(set! my-turn? (not my-turn?))
|
||||||
|
(display))))
|
||||||
(error "It's not my turn."))]))
|
(error "It's not my turn."))]))
|
||||||
|
|
Loading…
Reference in New Issue