Anonymous user
Rock-paper-scissors: Difference between revisions
m
→{{header|Tcl}}: More comments
(→{{header|Tcl}}: Small correction to show error handling) |
m (→{{header|Tcl}}: More comments) |
||
Line 430:
=={{header|Tcl}}==
<lang tcl>package require Tcl 8.5
### Choices are represented by integers, which are indices into this list:
### Rock, Paper, Scissors
### Normally, idiomatic Tcl code uses names for these sorts of things, but it
### turns out that using integers simplifies the move-comparison logic.
# How to ask for a move from the human player
Line 443 ⟶ 448:
set len [string length $line]
foreach play {0 1 2} name {"rock" "paper" "scissors"} {
# Do a prefix comparison
if {$len && [string equal -nocase -length $len $line $name]} {
return $play
|