September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -6,7 +6,7 @@ const msg = [
"Scissors cut paper",
]
say <<"EOT";
say <<"EOT"
\n>> Rock Paper Scissors <<\n
** Enter 'r', 'p', or 's' as your play.
** Enter 'q' to exit the game.
@ -17,7 +17,7 @@ var plays = 0
var aScore = 0
var pScore = 0
var pcf = [0,0,0] # pcf = player choice frequency
var aChoice = 3.irand # ai choice for first play is completely random
var aChoice = pick(0..2) # ai choice for first play is completely random
loop {
var pi = Sys.scanln("Play: ")
@ -34,19 +34,19 @@ loop {
++plays
# show result of play
">> My play: %-8s".printf(rps[aChoice])
">> My play: %-8s".printf(rps[aChoice])
given ((aChoice - pChoice + 3) % 3) {
when (0) { say "Tie." }
when (1) { "%-*s %s".printlnf(30, msg[aChoice], 'My point'); aScore++ }
when (2) { "%-*s %s".printlnf(30, msg[pChoice], 'Your point'); pScore++ }
when (1) { "%-*s %s".printlnf(30, msg[aChoice], 'My point'); aScore++ }
when (2) { "%-*s %s".printlnf(30, msg[pChoice], 'Your point'); pScore++ }
}
# show score
"%-6s".printf("%d:%d" % (pScore, aScore))
# compute ai choice for next play
given (plays.irand) { |rn|
given (plays.rand.int) { |rn|
case (rn < pcf[0]) { aChoice = 1 }
case (pcf[0]+pcf[1] > rn) { aChoice = 2 }
default { aChoice = 0 }