Develop a Rock, Paper, Scissors game that allows users to play against the computer.
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.
# 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'
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.
Can be found on the solutions branch on github.
I've been a software engineer for the past decade and have traveled the world building applications and training individuals on a wide variety of topics.