@@ -51,6 +51,17 @@ type Message = String
5151data PlayerAction = PlayerAction ActionType Card
5252data ActionType = Play | Drop | BuildCompany
5353
54+ -- | Some types for non empty lists
55+ data NonEmpty a = NonEmpty a [a ]
56+
57+ _NonEmpty :: Prism' [a ] (NonEmpty a )
58+ _NonEmpty = prism fromNonEmpty toNonEmpty
59+ where
60+ fromNonEmpty (NonEmpty x xs) = x : xs
61+ toNonEmpty l = case l of
62+ [] -> Left l
63+ (x: xs) -> Right (NonEmpty x xs)
64+
5465-- | This describe the capabilities needed to write the rules, when no
5566-- interaction with the player is required.
5667type NonInteractive m = (MonadState GameState m , Monad m , MonadError Message m , Functor m , Applicative m )
@@ -61,15 +72,15 @@ class NonInteractive m => GameMonad m where
6172 playerDecision :: Age -> Turn -> PlayerId -> [Card ] -> GameState -> m (PlayerAction , Exchange )
6273 -- | Ask the player to chose a card, along with a descriptive message.
6374 -- This is used for the Recycling and CopyCommunity effects.
64- askCard :: Age -> PlayerId -> [ Card ] -> GameState -> Message -> m Card
75+ askCard :: Age -> PlayerId -> NonEmpty Card -> GameState -> Message -> m Card
6576 tellPlayer :: PlayerId -> Message -> m () -- ^ Tell some information to a specific player
6677 generalMessage :: Message -> m () -- ^ Broadcast some information
6778
6879-- We define "safe" versions of the `askCard` function, that makes sure the
6980-- player doesn't introduce a new card in the game.
7081
71- askCardSafe :: GameMonad m => Age -> PlayerId -> [ Card ] -> GameState -> Message -> m Card
82+ askCardSafe :: GameMonad m => Age -> PlayerId -> NonEmpty Card -> GameState -> Message -> m Card
7283askCardSafe a p cl s m = do
7384 card <- askCard a p cl s m
74- when (card `notElem` cl ) (throwError " The player tried to play a non proposed card" )
85+ when (card `notElem` (cl ^. re _NonEmpty) ) (throwError " The player tried to play a non proposed card" )
7586 return card
0 commit comments