rps_game_winner
CodeAcademy Labs でメソッド (以下を参照)を使用しようとすると、次の入力で問題なく動作します。
> rps_game_winner([ ["Dave", "P"], ["Armando", "S"] ])
valid value: p
valid value: s
=> ["Armando", "S"]
> rps_game_winner([ ["Allen", "P"], ["Richard", "P"] ])[0]
valid value: p
valid value: p
=> "Allen"
オートグレーダーの宿題に提出すると、常にNoSuchStrategyError
.
Failure/Error: rps_game_winner([ ["Dave", "P"], ["Armando", "S"] ])[0].should eq("Armando"), "Incorrect Winner returned"
NoSuchStrategyError:
NoSuchStrategyError
誰か助けてくれませんか?ありがとう。
def rps_game_winner(game)
raise WrongNumberOfPlayersError unless game.length == 2
a1=[(game[0][1]).downcase]
a2=[(game[1][1]).downcase]
a3=a1.to_s
a4=a2.to_s
valid=["r","p","s"]
if(valid.include?(a3))
puts "valid value: "+a3
else
raise NoSuchStrategyError
end
if(valid.include?(a4))
puts "valid value: "+a4
else
raise NoSuchStrategyError
end
if(win(a1, a2))
return game[0]
else
if a1.eql?(a2)
return game[0]
else
return game[1]
end
end
return game[0] if a1.eql?(a2)
end