Fixed a bunch of little bugs preventing this from working!
This commit is contained in:
parent
b9006ffd64
commit
1660010d1f
1 changed files with 23 additions and 18 deletions
|
@ -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?)
|
||||
unseal-pick]
|
||||
[(register-receiver receiver)
|
||||
((set! gobbler (spawn ^gib-gab-gobbler won? receiver))
|
||||
$ gobbler 'get-receiver)]))
|
||||
(set! gobbler (spawn ^gib-gab-gobbler won? receiver))
|
||||
($ gobbler 'get-receiver)]))
|
||||
|
||||
|
||||
;; Actual Tic Tac Toe game
|
||||
|
@ -83,18 +83,21 @@
|
|||
(lambda (move)
|
||||
(format #t "move is ~s\n" move)
|
||||
($ board 'choose! move mark)
|
||||
move)))
|
||||
move)
|
||||
#:promise? #t))
|
||||
|
||||
(define (loop-move peer)
|
||||
(format #t "begin move w ~s\n" peer)
|
||||
(on (<- peer 'exchange-move receiver (move!))
|
||||
;; get exchange
|
||||
(lambda (peer-move)
|
||||
;; Actually respond to the move
|
||||
(format #t "Peer move ~s\n" peer-move)
|
||||
($ board 'choose! peer-move peer-mark)
|
||||
;; And now we repeat!
|
||||
(loop-move peer))))
|
||||
(on (move!)
|
||||
(lambda (move)
|
||||
(on (<- peer 'exchange-move receiver move)
|
||||
;; get exchange
|
||||
(lambda (peer-move)
|
||||
;; Actually respond to the move
|
||||
(format #t "Peer move ~s\n" peer-move)
|
||||
($ 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.
|
||||
;; If we don't go first we also wait.
|
||||
|
@ -118,15 +121,17 @@
|
|||
(methods
|
||||
;; Switch coords for clarity
|
||||
[(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)))]
|
||||
[(choose! coords mark-char)
|
||||
(if ($ self 'chosen? coords)
|
||||
(error "coords already chosen:" coords)
|
||||
(begin
|
||||
($ ($ self 'ref coords) 'choose! mark-char)
|
||||
($ self 'display)))]
|
||||
(let* ((mark ($ self 'ref coords))
|
||||
(char ($ mark 'get)))
|
||||
(if (not (not char))
|
||||
(error "coords already chosen:" coords)
|
||||
(begin
|
||||
(pk mark mark-char)
|
||||
($ mark 'choose! mark-char)
|
||||
($ self 'display))))]
|
||||
[(display)
|
||||
(define (print-mark mark)
|
||||
(let ((mark ($ mark 'get)))
|
||||
|
|
Loading…
Reference in a new issue