Okay, now we don't have weird recursion anymore

This commit is contained in:
Vivianne 2023-02-11 22:00:18 -08:00
parent 03e2d615fc
commit 9e79ef1c84

View file

@ -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