@@ -81,9 +81,9 @@ generateRandomGame rn cn ratio = do
81
81
return $ head solutions
82
82
83
83
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
87
87
sol
88
88
else
89
89
let (headCell: tailCells) = cells
@@ -94,9 +94,9 @@ removeCells sol@(Matrix rn cn cs) cells ite n seeds =
94
94
solutions = solveAll matrix seeds
95
95
isUnix = length (take 2 solutions) < 2
96
96
in if isUnix then
97
- removeCells matrix tailCells (ite + 1 ) n seeds
97
+ removeCells matrix tailCells (n - 1 ) seeds
98
98
else
99
- removeCells sol tailCells (ite + 1 ) n seeds
99
+ removeCells sol tailCells n seeds
100
100
101
101
102
102
generateGame :: Int -> Int -> Float -> Difficulty -> Int -> IO (Bool , Matrix )
@@ -106,14 +106,15 @@ generateGame rn cn ratio dif to = do
106
106
return (False , blankMatrix 1 1 )
107
107
else do
108
108
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
110
111
randomCells <- genRCellFromSet setForRemove
111
112
let total = Set. size setForRemove
112
113
let cant_empty = floor $ fromIntegral total * emptyRatio dif
113
114
seed <- randomIO :: IO Int
114
115
let gen = mkStdGen seed
115
116
let seeds = randoms gen :: [Int ]
116
- let game = removeCells solution randomCells 0 cant_empty seeds
117
+ let game = removeCells solution randomCells cant_empty seeds
117
118
return (True , game)
118
119
119
120
0 commit comments