{-# LANGUAGE OverloadedStrings, CPP #-}
import Network.Wai
import Network.HTTP.Types
import Network.Wai.Handler.Warp (run)
import Game.Hanabi(mkDS, DynamicStrategy)
import Game.Hanabi.Client(clientApp)
import Game.Hanabi.Backend(hanabiApp)
import Game.Hanabi.Msg(defaultOptions, Options(..))
import Game.Hanabi.Strategies.SimpleStrategy hiding (main)
import Game.Hanabi.Strategies.StatefulStrategy hiding (main)
import Game.Hanabi.Strategies.Stateless hiding (main)
import Game.Hanabi.Strategies.EndGameSearch hiding (main)
main :: IO ()
main = do putStrLn "localhost:8080" -- Seemingly other port than 8080 does not work.
let opt = defaultOptions{version="hanabi-dealer quickbuilt server", strategies=strs}
capp <- clientApp opt
bapp <- hanabiApp opt $ \_ resp -> resp $ responseLBS status400 [("Content-Type", "text/plain")] "400 Not a WebSocket request."
run 8080 $ route capp bapp
route :: Application -> Application -> Application
route capp bapp request respond = case rawPathInfo request of
"/ws/" -> bapp request respond
_ -> capp request respond
-- _ -> respond $ responseLBS status404 [("Content-Type", "text/plain")] "404 Not found"
strs :: [(String, IO (DynamicStrategy IO))]
strs = [
("Stupid example strategy", return $ mkDS "Stupid example strategy" $ S),
("Example strategy with states", return $ mkDS "Example strategy with states" $ SF []),
("Stateless implementation of the strategy with states", return $ mkDS "Stateless implementation of the strategy with states" SL),
("Strategy with end game search", return $ mkDS "Strategy with end game search" EG)
-- x , ("Sontakki", return $ mkDS "Sontakki" (Sontakki emptyDefault))
]