Okay, now we don't have weird recursion anymore
This commit is contained in:
parent
03e2d615fc
commit
9e79ef1c84
1 changed files with 10 additions and 7 deletions
|
@ -55,7 +55,7 @@
|
|||
[(exchange-move peer coords)
|
||||
(format #t "exchange-move ~s\n" coords)
|
||||
($ board 'choose! coords peer-mark)
|
||||
(move! peer)]))
|
||||
(move!)]))
|
||||
|
||||
(define receiver (spawn ^move-receiver))
|
||||
|
||||
|
@ -66,12 +66,15 @@
|
|||
(map string->number (string-tokenize (read) char-set:digit)))
|
||||
|
||||
;; Do our move, and send it to the peer. We then await its response.
|
||||
(define (move! peer)
|
||||
(define (move!)
|
||||
(let ((move (prompt->move)))
|
||||
($ board 'choose! move mark)
|
||||
move))
|
||||
|
||||
(define (initiate-move peer)
|
||||
(format #t "begin move w ~s\n" peer)
|
||||
(on (<- peer 'exchange-move receiver
|
||||
(let ((move (prompt->move)))
|
||||
($ board 'choose! move mark)
|
||||
move))
|
||||
(move!))
|
||||
;; get exchange
|
||||
(lambda (peer-move)
|
||||
;; Actually respond to the move
|
||||
|
@ -81,14 +84,14 @@
|
|||
;; Initial logic. If the peer is not set we wait until we receive it.
|
||||
;; If we don't go first we also wait.
|
||||
(when (and arg-peer initiator)
|
||||
(move! arg-peer))
|
||||
(initiate-move arg-peer))
|
||||
|
||||
(methods
|
||||
[(get-receiver) receiver]
|
||||
;; Learn about the receiver from the peer. Then do our move if we are first.
|
||||
[(register-receiver peer)
|
||||
(when initiator
|
||||
(move! peer))]))
|
||||
(initiate-move peer))]))
|
||||
|
||||
;; Board logic
|
||||
|
||||
|
|
Loading…
Reference in a new issue