Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Nim-game/Scala/nim-game.scala
Normal file
31
Task/Nim-game/Scala/nim-game.scala
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
var tokens = 12
|
||||
|
||||
def playerTurn(curTokens: Int): Unit =
|
||||
{
|
||||
val take = readLine("How many tokens would you like to take? ").toInt
|
||||
if (take < 1 || take > 3) {
|
||||
println("Number must be between 1 and 3.")
|
||||
playerTurn(curTokens)
|
||||
}
|
||||
else {
|
||||
tokens = curTokens - take
|
||||
println(s"You take $take tokens. $tokens tokens remaining.\n")
|
||||
}
|
||||
}
|
||||
|
||||
def compTurn(curTokens: Int): Unit =
|
||||
{
|
||||
val take = curTokens % 4
|
||||
tokens = curTokens - take
|
||||
println(s"Computer takes $take tokens. $tokens remaining.\n")
|
||||
}
|
||||
|
||||
def main(args: Array[String]): Unit =
|
||||
{
|
||||
while (tokens > 0)
|
||||
{
|
||||
playerTurn(tokens)
|
||||
compTurn(tokens)
|
||||
}
|
||||
println("Computer wins!")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue