Created
March 15, 2012 16:11
-
-
Save davidkaste/2045016 to your computer and use it in GitHub Desktop.
RPS game based on nested vectors. Written in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn rpswinner | |
[match] | |
(if (= ((match 0) 1) ((match 1) 1)) | |
(match 0) | |
(if (and (= ((match 0) 1) "R") (= ((match 1) 1) "P")) | |
(match 1) | |
(if (and (= ((match 0) 1) "P") (= ((match 1) 1) "S")) | |
(match 1) | |
(if (and (= ((match 0) 1) "S") (= ((match 1) 1) "R")) | |
(match 1) | |
(match 0) | |
) | |
) | |
) | |
) | |
) | |
(defn rpstournament | |
[tournament] | |
(if (instance? String (tournament 0)) | |
tournament | |
(rpswinner (vector (rpstournament (tournament 0)) (rpstournament (tournament 1)))) | |
) | |
) | |
(println (rpstournament | |
[ | |
[ | |
[ ["Player1", "P"] ["Player2", "S"] ] | |
[ ["Player3", "R"] ["Player4", "S"] ] | |
] | |
[ | |
[ ["Player5", "S"] ["Player6", "P"] ] | |
[ ["Player7", "R"] ["Player8", "P"] ] | |
] | |
] | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment