diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-10-06 20:25:26 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-10-06 20:25:26 +0200 |
commit | ae7023ba666bbac6a02d9b8fbd9a33083bc944e3 (patch) | |
tree | c3d6f692b88eacd7f4575257cbce0871ace52447 /puzzle.hs | |
parent | 61233a0c7f9f80905d24bbbeb73ce8abbcc08461 (diff) |
cmdargs parsing
Diffstat (limited to 'puzzle.hs')
-rw-r--r-- | puzzle.hs | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -1,11 +1,15 @@ +{-# LANGUAGE DeriveDataTypeable #-} + module Main where +import Control.Monad (when) import Data.Array (Array, array, bounds, (!), (//)) import Data.Functor ((<$>)) import Data.Maybe import Data.List (sort) import Data.Ord (compare) import Data.Char (toUpper) +import System.Console.CmdArgs (Data, Typeable, cmdArgs) import System.Random (RandomGen, getStdGen, split, randomR, randomRs) import System.Random.Shuffle @@ -105,6 +109,7 @@ insert w p b = insertAll :: RandomGen gen => gen -> [String] -> Board -> Maybe Board insertAll _ [] b = Just b insertAll rnd (w:ws) b = do + when (null moves) Nothing b' <- insert w (pose $ sort moves !! nth) b insertAll rnd' ws b' where @@ -119,12 +124,17 @@ fill rnd b = b // zip [(x, y) | x <- [sX..eX], y <- [sY..eY], (b ! (x, y)) == em where ((sX, sY), (eX, eY)) = bounds b +data Puzzle = Puzzle { blanks :: Bool + , dimension :: (Int, Int) + } deriving (Data, Typeable, Show) + main :: IO () main = do + args <- cmdArgs $ Puzzle False (30, 30) rnd <- getStdGen c <- getContents let guests = lines (map toUpper c) in - case (showBoard . fill rnd) <$> insertAll rnd guests (mkBoard (40, 30)) of + case (showBoard . (if blanks args then id else fill rnd)) <$> insertAll rnd guests (mkBoard $ dimension args) of Just s -> putStr s Nothing -> putStr "goesnt" |