Not sure if it’s “proper”, but you could just alts! twice on all three
channels:
(let [[_ p1] (alts! [player1-ch player2-ch timeout-ch])
[_ p2] (alts! [player1-ch player2-ch timeout-ch])]
(cond
(= p1 timeout-ch) No players played.
(= p2 timeout-ch) (str p1 played, and the other
Hi,
I'm learning core.async with a game I'm developing.
This is a one on one game where players have 5 seconds to play. If only one
has played before 5 seconds, he is the winner. If none has played, I
randomly choose a winner.
I have 3 channels, player1-channel, player2-channel and
You might want to put it into a loop, keeping the 'played' values as the
loop bindings. (I imagine [false false] in my head, but whatever is
meaningful to you.)
If the timer dings, you evaluate the winner.
If you get a value on a player channel and the other player HAS played, you
might recur