26 Rock, Paper, Scissors, Lizard, Spock!

 

In this capstone, you will

  • Implement the main components of your game using case classes and case objects
  • Manipulate immutable data using higher order and pure functions
  • Represent nullable values using Option
  • Use tuples to group elements together
  • Define unapply methods to pattern match on classes

In this capstone, you’ll implement an HTTP server to play a popular variation of the classic game “Paper, Rock, Scissors!” called “Rock, Paper, Scissors, Lizard, Spock!” Two players each pick a symbol randomly, and the selected symbols determine who the winner is. The allowed moves are paper, rock, scissors, lizard, Spock, and they interact as follows:

Scissors cut paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitate lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, rock crushes scissors.

If both players pick the same symbol, your application will not select a winner and declare the game a tie. Figure 26.1 shows a visual representation of the rules.

Figure 26.1 “Rock, Paper, Scissors, Lizard, Spock!” has five symbols: scissors, paper, rock, lizard, Spock. The diagram summarizes the interaction between its symbols. You will use them in your implementation to determine the winner (if any).

26.1 Implementing Rock, Paper, Scissors, Lizard, Spock!

26.1.1 sbt project setup and packages

26.1.2 Defining a symbol

26.1.3 Representing a player

26.1.4 Defining a game

26.1.5 The API routes

26.1.6 The HTTP server

26.1.7 Let’s try it out!

26.2 Possible improvements to our solution

Summary

sitemap