Try an extension method
This commit is contained in:
parent
0528d4b50e
commit
cdb80d9b9d
|
@ -1,16 +1,18 @@
|
|||
import scala.io.Source
|
||||
import scala.math.floorMod
|
||||
|
||||
extension (i: Int) def %%(modulus: Int) = floorMod(i, modulus)
|
||||
|
||||
enum RPS(val score: Int):
|
||||
case Rock extends RPS(1)
|
||||
case Paper extends RPS(2)
|
||||
case Scissors extends RPS(3)
|
||||
|
||||
def +(amount: Int) = RPS.fromOrdinal(floorMod(ordinal + amount, 3))
|
||||
def -(amount: Int) = RPS.fromOrdinal(floorMod(ordinal - amount, 3))
|
||||
def +(amount: Int) = RPS.fromOrdinal((ordinal + amount) %% 3)
|
||||
def -(amount: Int) = RPS.fromOrdinal((ordinal - amount) %% 3)
|
||||
def -(other: RPS) = score - other.score
|
||||
|
||||
def vs(other: RPS) = floorMod(this - other, 3) match
|
||||
def vs(other: RPS) = (this - other) %% 3 match
|
||||
case 1 => 6
|
||||
case 2 => 0
|
||||
case _ => 3
|
||||
|
|
Loading…
Reference in New Issue