Created
December 11, 2023 11:23
-
-
Save nikolavojicic/8591d9bb1ffead8cdc94e3a847e8c610 to your computer and use it in GitHub Desktop.
This file contains 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
(def break (System/getProperty "line.separator")) | |
(def moves | |
{:p {:desc "PAPER" :beats :r} | |
:r {:desc "ROCK" :beats :s} | |
:s {:desc "SCISSORS" :beats :p}}) | |
(defn vs [m1 m2] | |
(cond | |
(= m1 m2) "IT'S A DRAW" | |
(= (:beats (m1 moves)) m2) "YOU WIN" | |
:else "YOU LOOSE")) | |
(defn -main [& args] | |
(println "(P)APER, (R)OCK, (S)CISSORS OR (E)XIT?") | |
(let [you (keyword (.toLowerCase (read-line))) | |
bot (rand-nth (keys moves))] | |
(when (not= :e you) | |
(println | |
(str "YOU :: " (:desc (you moves) "INVALID") break | |
"BOT :: " (:desc (bot moves)) break | |
"-----> " (vs you bot) break | |
(apply str (repeat 38 "-")))) | |
(recur args)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment