-- This is the default main module Main where import Mahjong.Set import Mahjong.Hand import Mahjong.Tile import System.Random import Data.Array.IO import Control.Monad import Control.Monad.Loops allTiles = concat $ take 4 $ repeat orderedTile shuffle :: [a] -> IO [a] shuffle xs = do ar <- newArray n xs forM [1..n] $ \i -> do j <- randomRIO (i,n) vi <- readArray ar i vj <- readArray ar j writeArray ar j vi return vj where n = length xs newArray :: Int -> [a] -> IO (IOArray Int a) newArray n xs = newListArray (1,n) xs main = do t <- shuffle allTiles let h = take 13 t let r = drop 13 t choose (Hand h []) r choose :: Hand -> MSet -> IO () choose h r = do let (n:rr) = r let hand = getHand h let call = getCall h let nh = hand++[n] let l = listen $ Hand nh call putStrLn $ (showMSet hand) ++ ":" ++ (show n) putStrLn $ (show l) ++ " "++ (show $ map showMSet $ call) putStrLn $ show $ nextTileSet $ Hand nh call if l == 0 then putStrLn "End" else do c <- iterateWhile (\c -> not $ c `elem` nh) $ do i <- getLine let c = head $ readMSet i return c let nnh = nh `rmTile` c choose (Hand nnh call) rr