summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 6a8ebb3..653b399 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,5 +1,51 @@
-- 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
- print "Just a test"
+ 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
+