Fixed a bunch of little bugs preventing this from working!
This commit is contained in:
parent
b9006ffd64
commit
1660010d1f
|
@ -44,8 +44,8 @@
|
||||||
(format #t "Peer picked ~a... a bold choice (do I win? ~a), I will send my unsealer\n" peer-pick won?)
|
(format #t "Peer picked ~a... a bold choice (do I win? ~a), I will send my unsealer\n" peer-pick won?)
|
||||||
unseal-pick]
|
unseal-pick]
|
||||||
[(register-receiver receiver)
|
[(register-receiver receiver)
|
||||||
((set! gobbler (spawn ^gib-gab-gobbler won? receiver))
|
(set! gobbler (spawn ^gib-gab-gobbler won? receiver))
|
||||||
$ gobbler 'get-receiver)]))
|
($ gobbler 'get-receiver)]))
|
||||||
|
|
||||||
|
|
||||||
;; Actual Tic Tac Toe game
|
;; Actual Tic Tac Toe game
|
||||||
|
@ -83,18 +83,21 @@
|
||||||
(lambda (move)
|
(lambda (move)
|
||||||
(format #t "move is ~s\n" move)
|
(format #t "move is ~s\n" move)
|
||||||
($ board 'choose! move mark)
|
($ board 'choose! move mark)
|
||||||
move)))
|
move)
|
||||||
|
#:promise? #t))
|
||||||
|
|
||||||
(define (loop-move peer)
|
(define (loop-move peer)
|
||||||
(format #t "begin move w ~s\n" peer)
|
(format #t "begin move w ~s\n" peer)
|
||||||
(on (<- peer 'exchange-move receiver (move!))
|
(on (move!)
|
||||||
;; get exchange
|
(lambda (move)
|
||||||
(lambda (peer-move)
|
(on (<- peer 'exchange-move receiver move)
|
||||||
;; Actually respond to the move
|
;; get exchange
|
||||||
(format #t "Peer move ~s\n" peer-move)
|
(lambda (peer-move)
|
||||||
($ board 'choose! peer-move peer-mark)
|
;; Actually respond to the move
|
||||||
;; And now we repeat!
|
(format #t "Peer move ~s\n" peer-move)
|
||||||
(loop-move peer))))
|
($ board 'choose! peer-move peer-mark)
|
||||||
|
;; And now we repeat!
|
||||||
|
(loop-move peer))))))
|
||||||
|
|
||||||
;; Initial logic. If the peer is not set we wait until we receive it.
|
;; Initial logic. If the peer is not set we wait until we receive it.
|
||||||
;; If we don't go first we also wait.
|
;; If we don't go first we also wait.
|
||||||
|
@ -118,15 +121,17 @@
|
||||||
(methods
|
(methods
|
||||||
;; Switch coords for clarity
|
;; Switch coords for clarity
|
||||||
[(ref coords)
|
[(ref coords)
|
||||||
((format #t "coords are ~s\n" coords)
|
(match coords ((x y) (array-ref arr y x)))]
|
||||||
(match coords ((x y) (array-ref arr y x))))]
|
|
||||||
[(chosen? coords) (not (not ($ ($ self 'ref coords) 'get)))]
|
[(chosen? coords) (not (not ($ ($ self 'ref coords) 'get)))]
|
||||||
[(choose! coords mark-char)
|
[(choose! coords mark-char)
|
||||||
(if ($ self 'chosen? coords)
|
(let* ((mark ($ self 'ref coords))
|
||||||
(error "coords already chosen:" coords)
|
(char ($ mark 'get)))
|
||||||
(begin
|
(if (not (not char))
|
||||||
($ ($ self 'ref coords) 'choose! mark-char)
|
(error "coords already chosen:" coords)
|
||||||
($ self 'display)))]
|
(begin
|
||||||
|
(pk mark mark-char)
|
||||||
|
($ mark 'choose! mark-char)
|
||||||
|
($ self 'display))))]
|
||||||
[(display)
|
[(display)
|
||||||
(define (print-mark mark)
|
(define (print-mark mark)
|
||||||
(let ((mark ($ mark 'get)))
|
(let ((mark ($ mark 'get)))
|
||||||
|
|
Loading…
Reference in New Issue