|
@@ -12,7 +12,7 @@ module Day2.Shared (
|
12
|
12
|
) where
|
13
|
13
|
|
14
|
14
|
data Shape = Rock | Paper | Scissors
|
15
|
|
- deriving (Show, Eq)
|
|
15
|
+ deriving (Show, Eq, Enum)
|
16
|
16
|
|
17
|
17
|
newtype Score = Score Int
|
18
|
18
|
deriving (Show, Eq)
|
|
@@ -36,9 +36,7 @@ newtype Game = Game (Shape, Shape)
|
36
|
36
|
deriving (Show, Eq)
|
37
|
37
|
|
38
|
38
|
shapeScore :: Shape -> Score
|
39
|
|
-shapeScore Rock = Score 1
|
40
|
|
-shapeScore Paper = Score 2
|
41
|
|
-shapeScore Scissors = Score 3
|
|
39
|
+shapeScore = Score . (+1) . fromEnum
|
42
|
40
|
|
43
|
41
|
winAgainst :: Shape -> Shape
|
44
|
42
|
winAgainst Rock = Paper
|