-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.hs
50 lines (38 loc) · 1.06 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{-# LANGUAGE MultiParamTypeClasses, TemplateHaskell #-}
module Main where
import Tfoo.Foundation
import Tfoo.Board
import Tfoo.Game
import Application
import Tfoo.Handlers.Root
import Data.List
import Yesod
import Yesod.Static
import Control.Concurrent.MVar
import Control.Concurrent.Chan
import System.Random as Random
import System.Environment (getArgs)
mkYesodDispatch "Tfoo" resourcesTfoo
createGame :: IO Game
createGame = do
channel <- newChan
return Game {
playerO = Nothing,
playerX = Nothing,
channel = channel,
board = generateBoard 20
}
gameStream :: [IO Game]
gameStream = repeat createGame
main :: IO ()
main = do
nextGameId <- newMVar 1
games <- newMVar gameStream
seedP <- liftIO $ Random.getStdGen >>= (\x -> return $ next x)
static' <- static "static"
args <- getArgs
warpDebug (getPort args) (Tfoo (fst seedP) games nextGameId static')
getPort :: [String] -> Int
getPort args = extractPort $ "-p" `elemIndex` args
where extractPort (Just index) = read $ args !! (index+1)
extractPort (Nothing) = 3100