Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Nim-game/R/nim-game.r
Normal file
20
Task/Nim-game/R/nim-game.r
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
## Nim game
|
||||
##
|
||||
|
||||
tokens <- 12
|
||||
|
||||
while(tokens > 0) {
|
||||
print(paste("Tokens remaining:",tokens))
|
||||
playertaken <- 0
|
||||
while(playertaken == 0) {
|
||||
playeropts <- c(1:min(c(tokens,3)))
|
||||
playertaken <- menu(playeropts, title = "Your go, how many tokens will you take? ")
|
||||
tokens <- tokens - playertaken
|
||||
if(tokens == 0) {print("Well done you won, that shouldn't be possible!")}
|
||||
}
|
||||
cputaken <- 4 - playertaken
|
||||
tokens <- tokens - cputaken
|
||||
print(paste("I take",cputaken,"tokens,",tokens,"remain"))
|
||||
if(tokens == 0) {print("I win!")}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue