concept game in category scala

appears as: game, A game, Game
Get Programming with Scala

This is an excerpt from Manning's book Get Programming with Scala.

Suppose you want to represent all the suits in a deck of playing cards – the ones you usually use for a game of Poker: ♣ Clubs, ♦ Diamonds, ♥ Hearts, ♠ Spades. You need to express the general concept of a symbol, but you also need to make sure that there are precisely four of its implementations. You can achieve this by using a “sealed” trait:

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:

Let’s define the behavior of the API for your HTTP server to play the game “Rock, Paper, Scissors, Lizard, Spock!”. Your application should be able to consume HTTP POST request to the URI /play. The body of the POST request should provide information about the name and selected symbol of both the two players using the following format:

“<playerA_name>: <playerA_symbol> - <playerB_name>: <playerB_symbol>”

For example, if the player called Daniela selects Spock and the player called Martin picks Paper, the HTTP request should have the body “Daniela: Spock – Martin: Paper”. Your application should parse it and reply with a successful response that provides information about the outcome of the game (e.g., “Player Martin with symbol Paper wins!”). Figure 26.2 provides an example of the expected behavior of the API of your HTTP server.

Figure 26.2: Overview of the API for your HTTP server. After parsing the message, the server should respond successfully with a human-readable message containing the outcome of the game.