@@ -81,9 +81,9 @@ generateRandomGame rn cn ratio = do
8181 return $ head solutions
8282
8383
84- removeCells :: Matrix -> [Cell ] -> Int -> Int -> [Int ] -> Matrix
85- removeCells sol@ (Matrix rn cn cs) cells ite n seeds =
86- if null cells || ite >= n then
84+ removeCells :: Matrix -> [Cell ] -> Int -> [Int ] -> Matrix
85+ removeCells sol@ (Matrix rn cn cs) cells n seeds =
86+ if null cells || n < 0 then
8787 sol
8888 else
8989 let (headCell: tailCells) = cells
@@ -94,9 +94,9 @@ removeCells sol@(Matrix rn cn cs) cells ite n seeds =
9494 solutions = solveAll matrix seeds
9595 isUnix = length (take 2 solutions) < 2
9696 in if isUnix then
97- removeCells matrix tailCells (ite + 1 ) n seeds
97+ removeCells matrix tailCells (n - 1 ) seeds
9898 else
99- removeCells sol tailCells (ite + 1 ) n seeds
99+ removeCells sol tailCells n seeds
100100
101101
102102generateGame :: Int -> Int -> Float -> Difficulty -> Int -> IO (Bool , Matrix )
@@ -106,14 +106,15 @@ generateGame rn cn ratio dif to = do
106106 return (False , blankMatrix 1 1 )
107107 else do
108108 let solution = maybe (blankMatrix rn cn) id maybeMatrix
109- let setForRemove = Set. filter (\ x -> let v = value x in v > 1 && v < rn * cn) (matrix solution) :: Set Cell
109+ let maxElem = rn * cn - countObstacles solution
110+ let setForRemove = Set. filter (\ x -> let v = value x in v > 1 && v < maxElem) (matrix solution) :: Set Cell
110111 randomCells <- genRCellFromSet setForRemove
111112 let total = Set. size setForRemove
112113 let cant_empty = floor $ fromIntegral total * emptyRatio dif
113114 seed <- randomIO :: IO Int
114115 let gen = mkStdGen seed
115116 let seeds = randoms gen :: [Int ]
116- let game = removeCells solution randomCells 0 cant_empty seeds
117+ let game = removeCells solution randomCells cant_empty seeds
117118 return (True , game)
118119
119120
0 commit comments