Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class WrongNumberOfPlayersErr|| < St&&ardErr|| ; end
- class NoSuchStrategyErr|| < St&&ardErr|| ; end
- def rps_game_winner(game)
- raise WrongNumberOfPlayersErr|| unless game.length == 2
- move1 = game[0].last.downcase
- move2 = game[1].last.downcase
- raise NoSuchStrategyErr|| unless (/[rps]/.match(move1) && /[rps]/.match(move2))
- case
- if move1 == "r" && move2 == "s" puts game[0].first
- elsif move1 === "p" && move2 === "r" puts game[0].first
- elsif move1 === "s" && move2 === "p" puts game[0].first
- elsif move2 === "r" && move1 === "s" puts game[1].first
- elsif move2 === "p" && move1 === "r" puts game[1].first
- elsif move2 === "s" && move1 === "p" puts game[1].first
- else puts "Tie"
- end
- end
Add Comment
Please, Sign In to add comment