- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Summary
Develop a Rock, Paper, Scissors game that allows users to play against the computer.
Exercise Description
Build a game class that allows users to guess rock
, paper
, or scissors
. Additionally, build a method that generates a random guess from the computer. Finally, pass both guesses through a rule's engine to return who is the winner of the game is. Focus on building a rule's engine that could scale to other rules instead of simply creating a large conditional.
Example Input/Output
# Examples below assume the computer guesses 'paper' rps = RPS.new(guess: 'rock') rps.winner_is # => 'Computer wins' rps = RPS.new(guess: 'Scissors') rps.winner_is # => 'You win!' rps = RPS.new(guess: 'paper') rps.winner_is # => 'Tie'
Real World Usage
This is a popular coding interview question, not because it's overly complex, but because it allows you to demonstrate your problem solving ability, especially as it relates to code flexibility. If you were to build this game and the rule's engine was comprised of a long set of conditionals, as soon as new rules were added to the game, the program would become convoluted and difficult to alter. However if you properly separate the game concerns it becomes easier to manage.