DricomDragon 5 роки тому
батько
коміт
1bec0605b0
1 змінених файлів з 7 додано та 16 видалено
  1. 7 16
      tp/mine-sweeper/main.hs

+ 7 - 16
tp/mine-sweeper/main.hs

@@ -11,7 +11,9 @@ import Data.Universe.Helpers ( cartesianProduct ) -- Need to be installed : `cab
 
 import Data.List ( foldl1' )
 
-import Systeme.IO
+import System.IO
+
+import System.Random
 
 -- Types
 
@@ -21,8 +23,6 @@ data Cell   = Covered Int Bool Bool -- number of bombs around ; has bomb ; has f
 
 data Grid = Grid [[Cell]]
 
-data StdGen = SG -- TODO : replace
-
 type Mat = [[Int]]
 
 
@@ -49,8 +49,6 @@ randSet n sg1 sg2 h w =
 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
-
 mineIndic::Cell -> Int
 mineIndic c = let Covered _ b _ = c in if b then 1 else 0
 
@@ -161,17 +159,9 @@ main = do
     let h = 7
     let w = 10
 
-    ... -- create grid, add mines, update neighbours
-    loop ... -- start loop
-
-
+    let bombs = randSet nmines sg sg' h w -- add mines,
+    let trappedGrid = grid h w bombs -- create grid
+    let scanedGrid = updateGrid trappedGrid (neighbourMap trappedGrid) -- update neighbours
 
-dtTinyGrid = Grid [
-                    [Covered 1 True False, Uncovered 2, Covered 0 True False],
-                    [Uncovered 0, Uncovered 0, Covered 1 True True]
-                ]
+    loop (div h 2) (div w 2) nmines scanedGrid -- start loop
 
-dtRS = randSet 3 SG SG 4 5
-dtGridCover = grid 4 5 dtRS
-dtMines = mines dtGridCover