concept Lizard in category scala

This is an excerpt from Manning's book Get Programming with Scala.
In the previous unit, you have mastered how to create a simple HTTP server. In this lesson, you’ll discover an essential tool in your Scala’s toolbox, called “case class”. When coding, dealing with data is a fundamental and recurring task. A case class provides a convenient and efficient way to represent your data in an immutable way: this allows you to share data between multiple threads safely. Being able to express data efficiently and conveniently is essential to make sure our program works correctly. You will also learn about case objects and how they can be useful when serialization is involved. Finally, you will see how pattern matching provides dedicated support for case classes thanks to the unapply function. In the capstone, you’ll use case classes and case objects to represent the core elements of the game “Paper, Rock, Scissors, Lizard, Spock!”.
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).
![]()
Listing 26.2: Creating instances for Symbol
// file src/main/scala/org/example/game/entities/Symbol.scala package org.example.game.entities sealed trait Symbol { //#A protected def beats: List[Symbol] def wins(other: Symbol): Boolean = beats.contains(other) } /** * Rock crushes Lizard * Rock crushes Scissors. */ case object Rock extends Symbol { //#B protected val beats = List(Lizard, Scissors) } /** * Paper covers Rock * Paper disproves Spock */ case object Paper extends Symbol { //#B protected val beats = List(Rock, Spock) } /** * Scissors cuts Paper * Scissors decapitates Lizard */ case object Scissors extends Symbol { //#B protected val beats = List(Paper, Lizard) } /** * Lizard poisons Spock * Lizard eats Paper */ case object Lizard extends Symbol { //#B protected val beats = List(Spock, Paper) } /** * Spock smashes Scissors * Spock vaporizes Rock */ case object Spock extends Symbol { //#B protected val beats = List(Scissors, Rock) }