diff --git a/gib-gab-gob/actors.scm b/gib-gab-gob/actors.scm index 942d0e3..2706173 100644 --- a/gib-gab-gob/actors.scm +++ b/gib-gab-gob/actors.scm @@ -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