Add nice, documented CLI parameters
This commit is contained in:
parent
9a1cf149df
commit
0ddc766aea
3 changed files with 27 additions and 9 deletions
28
app/Main.hs
28
app/Main.hs
|
|
@ -1,19 +1,35 @@
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE StandaloneDeriving #-}
|
||||||
|
{-# LANGUAGE TypeOperators #-}
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Lib
|
import Lib
|
||||||
import System.Environment
|
import Options.Generic
|
||||||
import System.Random
|
import System.Random
|
||||||
import Text.Read
|
import Text.Read
|
||||||
|
|
||||||
|
data Parameters w =
|
||||||
|
Parameters
|
||||||
|
{ width :: w ::: Int <?> "Width of the board"
|
||||||
|
, length :: w ::: Int <?> "Length of the board"
|
||||||
|
, bombs :: w ::: Int <?> "Number of bombs to be placed"
|
||||||
|
}
|
||||||
|
deriving (Generic)
|
||||||
|
|
||||||
|
instance ParseRecord (Parameters Wrapped)
|
||||||
|
|
||||||
|
deriving instance Show (Parameters Unwrapped)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
(Parameters boardWidth boardLength bombsCount) <- unwrapRecord "Minesweeper"
|
||||||
let boardWidth = read (head args)
|
|
||||||
boardLength = read (args !! 1)
|
|
||||||
bombs = read (args !! 2)
|
|
||||||
generator <- newStdGen
|
generator <- newStdGen
|
||||||
gameStep . createBoard boardWidth boardLength $
|
gameStep . createBoard boardWidth boardLength $
|
||||||
generateRandomCoordinates (boardWidth - 1) (boardLength - 1) bombs generator
|
generateRandomCoordinates (boardWidth - 1) (boardLength - 1) bombsCount generator
|
||||||
|
|
||||||
gameStep :: Board -> IO ()
|
gameStep :: Board -> IO ()
|
||||||
gameStep board = do
|
gameStep board = do
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ cabal-version: 1.12
|
||||||
--
|
--
|
||||||
-- see: https://github.com/sol/hpack
|
-- see: https://github.com/sol/hpack
|
||||||
--
|
--
|
||||||
-- hash: 512c036467601196724c0e9412fc6175989ea1a8c48bf158d2cf62aa1c0b4311
|
-- hash: ae0d0337fef94e96da9aaca377817a7cbca70851243db8fe2a6c435fe06f0cfa
|
||||||
|
|
||||||
name: minesweeper
|
name: minesweeper
|
||||||
version: 0.1.0.0
|
version: 0.1.0.0
|
||||||
|
|
@ -37,6 +37,7 @@ executable minesweeper
|
||||||
build-depends:
|
build-depends:
|
||||||
base
|
base
|
||||||
, minesweeper
|
, minesweeper
|
||||||
|
, optparse-generic
|
||||||
, random
|
, random
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ executables:
|
||||||
dependencies:
|
dependencies:
|
||||||
- minesweeper
|
- minesweeper
|
||||||
- random
|
- random
|
||||||
|
- optparse-generic
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
minesweeper-test:
|
minesweeper-test:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue