hanabi-dealer-0.3.2.0: Game/Hanabi/Msg.hs
{-# LANGUAGE DeriveGeneric, CPP #-}
module Game.Hanabi.Msg where
import Game.Hanabi
import GHC.Generics
#ifdef AESON
import Data.Aeson
instance ToJSON Msg
instance FromJSON Msg
instance ToJSON State
instance FromJSON State
instance ToJSON PrivateView
instance FromJSON PrivateView
instance ToJSON PublicInfo
instance FromJSON PublicInfo
instance ToJSON EndGame
instance FromJSON EndGame
instance ToJSON Move
instance FromJSON Move
instance ToJSON Card
instance FromJSON Card
instance ToJSON Color
instance FromJSON Color
instance ToJSON Number
instance FromJSON Number
instance ToJSON GameSpec
instance FromJSON GameSpec
instance ToJSON Rule
instance FromJSON Rule
instance ToJSON Game.Hanabi.Result
instance FromJSON Game.Hanabi.Result
#endif
-- WhatsUp and WhatsUp1 should be minimized after better clients are implemented. 効率上はminimizeすべきだが、テスト目的ではとりあえずこのままの方がやりやすい。
data Msg = Str String | WhatsUp String [PrivateView] [Move] | WhatsUp1 PrivateView Move | PrettyEndGame (Maybe (EndGame, [State], [Move])) | PrettyAvailable [(Int, (Int, Int))] deriving (Show, Read, Eq, Generic)
prettyMsg :: Verbosity -> Msg -> String
prettyMsg _ (Str xs) = xs
prettyMsg verb (WhatsUp name ps ms) = what'sUp verb name ps ms
prettyMsg verb (WhatsUp1 p m) = what'sUp1 verb p m
prettyMsg _ (PrettyEndGame tup) = prettyMbEndGame tup
prettyMsg _ (PrettyAvailable available) = unlines $ map prettyAvailableGame available
prettyMbEndGame Nothing = "Game ended abnormally, possibly by connection failure.\n"
prettyMbEndGame (Just tup) = prettyEndGame tup
prettyAvailableGame (gameid, (missing, total)) = "Game ID " ++ shows gameid ": available " ++ shows missing " out of " ++ shows total "."
defaultOptions = Opt{version = error "The verion field should be set to Game.Hanabi.VersionInfo.versionInfo",
port = 8720,
strategies = []
}
data Options = Opt{ version :: String -- ^ the version string to be shown by the `version' command.
-- This is supposed to be set to 'versionInfo', but can just be @""@
, port :: Int -- ^ the port number. This can be overridden by `-p' option.
, strategies :: [(String, IO (DynamicStrategy IO))] -- ^ the association list of the tuples of the strategy name and (the constructor for) the strategy.
}