
This is my "Rock, Paper and Scissors" Game on 1 Tweet.
importrandomrandomize()echo"Rock r\nPaper p\nScissor s"leto=["rock","paper","scissor"]pc=rand0..2us=casestdin.readLine[0]of'r':0of'p':1else:2echo"\nPC\tYou\tWinner\n",o[pc],'\t',o[us],'\t',case(3+pc.ord-us.ord)mod3of1:"PC"of2:"You"else:"No"
How to run the code:
$ nim r file.nimRock rPaper pScissor spPC You Winnerpaper paper No$
Keys:
- Rock = r
- Paper = p
- Scissors = s
It is not even too code-golfed, because we can remove the lineimport random
by compiling with--import:random
.
We can remove therandomize()
but then we need to recompile to make the PC choose another option, so is not a good idea.
It uses therandom
module from standard library:
https://nim-lang.github.io/Nim/random.html
case
switch from from standard library:
https://nim-lang.github.io/Nim/manual.html#statements-and-expressions-case-statement
readLine
to read a line from standard input:
https://nim-lang.github.io/Nim/io.html#readLine%2CFile
- How your Rock, Paper and Scissors game looks like?
Thank you for reading
Come learn programming with us...
👑
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse