pguardiario 的上述解决方案可以根据以下内容进行修改,以显示 (1) 哪个玩家获胜(而不是选择获胜的对象)和 (2) 平局时的结果:
def rps(p1, p2)
@results = {
'rock/paper' => "Player 2 won!",
'rock/scissors' => "Player 1 won!",
'paper/scissors' => "Player 2 won!",
'paper/rock' => "Player 1 won!",
'scissors/paper' => "Player 1 won!",
'scissors/rock' => "Player 2 won!",
'rock/rock' => "Draw!",
'scissors/scissors' => "Draw!",
'paper/paper' => "Draw!"
}
@results["#{p1}/#{p2}"]
end
rps("rock", "rock") => "Draw!"
rps("rock", "scissors") => "Player 1 won!"
rps("rock", "paper") => "Player 2 won!"
...ETC