implement custom config dialog
[hs-pgms.git] / src / Main.hs
blob1a7b173b74601f9962105c9777ec9e24da9998bc
1 module Main (main) where
3 import UI
4 import Mine
5 import Strategies
6 import System.Random
7 import Control.Monad
8 import Control.Concurrent
9 import Control.Exception
11 nGames :: Int
12 nGames = 10000
14 config :: Config
15 config = intermediate
17 strategy :: Strategy
18 strategy = simpleStrat
20 singleGame :: Bool -> Int -> IO Int
21 singleGame verbose n = do
22 gen <- newStdGen
23 gen2 <- newStdGen
24 let (res, brd) = playGame config gen (sRun strategy config gen2)
25 when verbose $ putStr (show res ++ show brd)
26 if res == Won then return $! (n+1) else return n
28 summary :: Int -> IO ()
29 summary i = do
30 putStrLn ("Won " ++ show i ++ "/" ++ show nGames ++ " games")
32 mainSingle :: IO ()
33 mainSingle = do
34 singleGame True 0
35 singleGame True 0
36 foldM (\n _ -> singleGame False n) 0 (replicate nGames ()) >>= summary
38 mainUI' = do
39 finish <- newEmptyMVar
40 forkOS (finally (mainUI strategies) (putMVar finish ()))
41 readMVar finish
43 main :: IO ()
44 main = do
45 mainUI strategies