You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let setForRemove =Set.filter (\x ->let v = value x in v >1&& v < rn * cn) (matrix solution) ::SetCell
63
-
randomCells <- genRCellFromSet setForRemove
64
-
let total =Set.size setForRemove
65
-
let cant_empty =floor$fromIntegral total * emptyRatio dif
66
-
let game =foldl editMatrixCell solution ([Cell r c 0| x <-take cant_empty randomCells, let r = row x, let c = column x])
67
-
return game
99
+
maybeMatrix <- timeout 60000000$ generateRandomGame rn cn ratio
100
+
if isNothing maybeMatrix thendo
101
+
return$error"Game not found"
102
+
elsedo
103
+
let solution =maybe (blankMatrix rn cn) (\x -> x) maybeMatrix
104
+
let setForRemove =Set.filter (\x ->let v = value x in v >1&& v < rn * cn) (matrix solution) ::SetCell
105
+
randomCells <- genRCellFromSet setForRemove
106
+
let total =Set.size setForRemove
107
+
let cant_empty =floor$fromIntegral total * emptyRatio dif
108
+
seed <- randomIO ::IOInt
109
+
let gen = mkStdGen seed
110
+
let seeds = randoms gen :: [Int]
111
+
let game = removeCells solution randomCells 0 cant_empty seeds
112
+
return game
68
113
69
114
generate::Matrix
70
115
generate =read"{. x x x x x x x x \n . 8 x x x x x x x \n . . 11 x x x x x x \n 29 . 10 . x x x x x \n 30 . . . . x x x x \n . 31 1 38 . . x x x \n . 32 . . 39 41 . x x \n . . . 22 . . 42 . x \n . . . . . . . 44 45}"::Matrix
getAdjacents (Cell r c v) rs cs s seeds = [Cell nr nc s | dr <- genShuffle seeds [-1, 0, 1], dc <- genShuffle seeds [-1, 0, 1], let (nr, nc) = (r + dr, c + dc), nr >0, nr <= rs, nc >0, nc <= cs]
0 commit comments