summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-05-24 11:58:56 -0500
committerTuowen Zhao <ztuowen@gmail.com>2016-05-24 11:58:56 -0500
commita7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8 (patch)
treea819a538301e320a254c7debdbb4d68a739393c4 /src/Main.hs
parent27d29076135ab9bb8903c9d64b0988c3b366844d (diff)
downloadhmj-master.tar.gz
hmj-master.tar.bz2
hmj-master.zip
chi peng kangHEADmaster
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
+