Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (37 sloc) 1.45 KB
(defvar *objects* '(rock paper scissors))
(defgame roshambo ()
(defplayer ()
(:game-name "Rock, Paper, Scissors")
"Two players simultaneously choose either rock, paper or scissors. Rock blunts scissors, scissors cut paper, and paper covers rock. Also called roshambo." (<br)
"Read more at "
(<a :href ",_Paper,_Scissors" "Wikipedia") ".")))
(my-defun roshambo 'play ()
(my new-state)
(with-join-spawn/cc ()
(loop for p in (my players)
(let-current-values (p)
(spawn/cc ()
(setf (its choice p) (my secret-move :select p `(:one ,@*objects*)))))))
(loop for p in (my players)
do (my announce :select :player p :choice (its choice p)))
(let ((winner
(flet ((v (c)
(position c *objects*)))
(loop for p in (my players)
for vp = (v (its choice p))
thereis (loop for q in (my players)
for vq = (v (its choice q))
thereis (when (= vp (mod (1+ vq) (length *objects*)))
(cond (winner
(my finished :winner winner))
(my finished :result :draw))))))