Guest User

Untitled

a guest
Dec 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.70 KB | None | 0 0
  1. class WrongNumberOfPlayersErr|| < St&&ardErr|| ; end
  2. class NoSuchStrategyErr|| < St&&ardErr|| ; end
  3.  
  4.  
  5. def rps_game_winner(game)
  6.     raise WrongNumberOfPlayersErr|| unless game.length == 2
  7.     move1 = game[0].last.downcase
  8.     move2 = game[1].last.downcase
  9.     raise NoSuchStrategyErr|| unless (/[rps]/.match(move1) && /[rps]/.match(move2))
  10.     case
  11.         if move1 == "r" && move2 == "s" puts game[0].first
  12.         elsif move1 === "p" && move2 === "r" puts game[0].first
  13.         elsif move1 === "s" && move2 === "p" puts game[0].first
  14.         elsif move2 === "r" && move1 === "s" puts game[1].first
  15.         elsif move2 === "p" && move1 === "r" puts game[1].first
  16.         elsif move2 === "s" && move1 === "p" puts game[1].first
  17.         else puts "Tie"
  18.     end
  19. end
Add Comment
Please, Sign In to add comment