Finish the program that implements the famous game Rock paper scissors. This is a game for two players where each selects "rock", "paper" or "scissors". Our program receives the players' choices as input lines: for the first player and for the second. If both select the same shape, the program prints draw , otherwise it prints who wins.
Introduction to collections
Rock paper scissors
Report a typo
Sample Input 1:
rock
rockSample Output 1:
drawWrite a program in Scala 3
object RockPaperScissors extends App {
val gameMap = Map(
"rock" -> Map(
"paper" -> "second win",
??? -> "first win",
),
???
)
val first = scala.io.StdIn.readLine()
val second = scala.io.StdIn.readLine()
val set = Set(first, ???)
if (set.size == 1)
println("draw")
else {
val mappingForFirst = gameMap(first)
println(mappingForFirst(???))
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.