Lesson 26 Capstone 4: 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 high 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 play the game by each picking a symbol randomly: the selected symbols determine who the winner is. The allowed moves are Paper, Rock, Scissors, Lizard, Spock and they interact as follows:

“Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates 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. Have a look at figure 26.1 for a visual representation of the rules for “Rock, Paper, Scissors, Lizard, Spock!”.

Figure 26.1: “Rock, Paper, Scissors, Lizard, Spock!” has five symbols: Scissors, Paper, Rock, Lizard, Spock. The diagram summarizes the interaction between the 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   The ugly bits of our solution

 

26.3   Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest