Implement a partial ordering on game coordinates to allow implementing re-synchronization easily

This commit is contained in:
Tissevert 2020-01-25 11:13:56 +01:00
parent 59c467e988
commit e2019e2d3b
1 changed files with 8 additions and 0 deletions

View File

@ -13,6 +13,7 @@ module Hanafuda.Message (
, PublicPlayer(..)
, PublicState(..)
, Room
, orderCoordinates
) where
import Data.Char (toLower)
@ -153,6 +154,13 @@ instance FromJSON Coordinates
instance ToJSON Coordinates where
toEncoding = genericToEncoding defaultOptions
orderCoordinates :: Coordinates -> Coordinates -> Maybe Ordering
orderCoordinates coordinatesA coordinatesB
| gameID coordinatesA == gameID coordinatesB = Just $ compare
(month coordinatesA, turn coordinatesA)
(month coordinatesB, turn coordinatesB)
| otherwise = Nothing
data PrivateState = PrivateState {
link :: Coordinates
, hands :: Map PlayerID Hanafuda.Pack