Rock-paper-scissors: Difference between revisions

m
Line 6,510:
Semi-translation of Go version:
 
<syntaxhighlight lang="vlang">import rand
import rand
import os
 
const rps = 'rps'(
rps = 'rps'
const msg = [
'Rock breaks scissors',s
'Paper covers rock',
'Scissors cut paper'
]
)
 
fn main() {
Line 6,529 ⟶ 6,532:
mut a_choice := rand.intn(3) or {0} // ai choice for first play is completely random
for _ in 0..6 {
// get player choice
pi = os.input('Play: ').str()
if typeof(pi).name != 'string' || pi.len != 1 {break}
p_choice := rps.index_any(pi)
if p_choice < 0 {break}
Line 6,546 ⟶ 6,549:
println('$p_score : $a_score')
// compute ai choice for next play
rn := rand.intn(3) or {0}
match true {
rn < pcf[0] {a_choice = 2}
rn < pcf[0] + pcf[1] {a_choice = 0}
else {a_choice = rand.intn(3) or {0}}
}
}
}
}
}</syntaxhighlight>
 
{{out}}
291

edits