Implement a partial ordering on game coordinates to allow implementing re-synchronization easily
This commit is contained in:
parent
59c467e988
commit
e2019e2d3b
1 changed files with 8 additions and 0 deletions
|
@ -13,6 +13,7 @@ module Hanafuda.Message (
|
||||||
, PublicPlayer(..)
|
, PublicPlayer(..)
|
||||||
, PublicState(..)
|
, PublicState(..)
|
||||||
, Room
|
, Room
|
||||||
|
, orderCoordinates
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Char (toLower)
|
import Data.Char (toLower)
|
||||||
|
@ -153,6 +154,13 @@ instance FromJSON Coordinates
|
||||||
instance ToJSON Coordinates where
|
instance ToJSON Coordinates where
|
||||||
toEncoding = genericToEncoding defaultOptions
|
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 {
|
data PrivateState = PrivateState {
|
||||||
link :: Coordinates
|
link :: Coordinates
|
||||||
, hands :: Map PlayerID Hanafuda.Pack
|
, hands :: Map PlayerID Hanafuda.Pack
|
||||||
|
|
Loading…
Reference in a new issue