|
@@ -4,6 +4,9 @@
|
|
|
|
|
|
import Data.Char
|
|
|
|
|
|
+import Data.Set ( Set )
|
|
|
+import qualified Data.Set as S
|
|
|
+
|
|
|
|
|
|
-- Types
|
|
|
|
|
@@ -13,6 +16,8 @@ data Cell = Covered Int Bool Bool -- number of bombs around ; has bomb ; has f
|
|
|
|
|
|
data Grid = Grid [[Cell]]
|
|
|
|
|
|
+data StdGen = SG -- TODO : replace
|
|
|
+
|
|
|
|
|
|
-- Methods
|
|
|
|
|
@@ -22,10 +27,23 @@ instance Show Cell where
|
|
|
show Selected = ">x<"
|
|
|
|
|
|
instance Show Grid where
|
|
|
- show (Grid a) = unlines $ map (unwords . map show) a
|
|
|
+ show (Grid a) = unlines $ map (unwords . map show) a
|
|
|
|
|
|
-- Functions
|
|
|
|
|
|
+randSet::Int -> StdGen -> StdGen -> Int -> Int -> Set (Int, Int)
|
|
|
+randSet n sg1 sg2 h w =
|
|
|
+ let byl = randomRs (0, h - 1) sg1 in
|
|
|
+ let bxl = randomRs (0, w - 1) sg2 in
|
|
|
+ let bl = zip byl bxl in
|
|
|
+ let biggerSets = scanl (flip S.insert) S.empty bl in
|
|
|
+ head (dropWhile (\s -> S.size s < n) biggerSets)
|
|
|
+
|
|
|
+grid::Int -> Int -> Set (Int, Int) -> Grid
|
|
|
+grid h w s = Grid [ [Covered 0 (S.member (y, x) s) False | x <- [0..w-1] ] | y <- [0..h-1] ]
|
|
|
+
|
|
|
+randomRs (x, y) sg = [x + mod k (y - x) | k <- [1..y] ] -- TODO : replace
|
|
|
+
|
|
|
|
|
|
-- Testing data
|
|
|
|