split up
This commit is contained in:
parent
617641ee7d
commit
a991f2436b
1 changed files with 105 additions and 102 deletions
|
@ -29,18 +29,19 @@ placeInteriorIO imat imgmat irp graph =
|
|||
rnd <- newStdGen
|
||||
let (_, matps) =
|
||||
foldl
|
||||
traverseGraph
|
||||
(traverseGraph imat)
|
||||
(rnd, (imgmat, irp))
|
||||
graph
|
||||
return matps
|
||||
where
|
||||
|
||||
traverseGraph
|
||||
:: (StdGen, (Matrix (Maybe ImgId), [ReachPoint]))
|
||||
:: Matrix TileState
|
||||
-> (StdGen, (Matrix (Maybe ImgId), [ReachPoint]))
|
||||
-> Graph
|
||||
-> (StdGen, (Matrix (Maybe ImgId), [ReachPoint]))
|
||||
traverseGraph acc (GHall sub) =
|
||||
foldl traverseGraph acc sub
|
||||
traverseGraph putt (GRoom _ bnds) =
|
||||
traverseGraph imat acc (GHall sub) =
|
||||
foldl (traverseGraph imat) acc sub
|
||||
traverseGraph imat putt (GRoom _ bnds) =
|
||||
let applicable =
|
||||
L.sortBy (\b a -> size a `compare` size b) (
|
||||
L.filter
|
||||
|
@ -61,18 +62,20 @@ placeInteriorIO imat imgmat irp graph =
|
|||
)
|
||||
in
|
||||
foldl
|
||||
(\(orng, (omat, orp)) -> placeCluster orng bnds 1 omat orp)
|
||||
(\(orng, (omat, orp)) -> placeCluster imat orng bnds 1 omat orp)
|
||||
putt
|
||||
applicable
|
||||
|
||||
placeCluster
|
||||
:: StdGen
|
||||
:: Matrix TileState
|
||||
-> StdGen
|
||||
-> Boundaries Int
|
||||
-> Int
|
||||
-> Matrix (Maybe ImgId)
|
||||
-> [ReachPoint]
|
||||
-> Cluster
|
||||
-> (StdGen, (Matrix (Maybe ImgId), [ReachPoint]))
|
||||
placeCluster rng bnds try mat rp appl =
|
||||
placeCluster imat rng bnds try mat rp appl =
|
||||
let (pr, g1) = randomR (fst (matmin bnds) - 1, fst (matmax bnds) - 1) rng
|
||||
(pc, g2) = randomR (snd (matmin bnds) - 1, snd (matmax bnds) - 1) g1
|
||||
freeRoom = foldl
|
||||
|
@ -108,7 +111,7 @@ placeInteriorIO imat imgmat irp graph =
|
|||
if pr + nrows cmat - 1 > fst (matmax bnds) ||
|
||||
pc + ncols cmat - 1 > snd (matmax bnds)
|
||||
then A.log A.Debug ("no cluster placed") $
|
||||
placeCluster g2 bnds (try + 1) mat rp appl
|
||||
placeCluster imat g2 bnds (try + 1) mat rp appl
|
||||
else if
|
||||
any (`notElem` clusterRoom appl)
|
||||
(M.toList (M.submatrix
|
||||
|
@ -123,20 +126,20 @@ placeInteriorIO imat imgmat irp graph =
|
|||
mat
|
||||
))
|
||||
then A.log A.Debug ("no cluster placed") $
|
||||
placeCluster g2 bnds (try + 1) mat rp appl
|
||||
placeCluster imat g2 bnds (try + 1) mat rp appl
|
||||
else if
|
||||
any (`elem` (oldreaches))
|
||||
(V2
|
||||
<$> [pr .. pr + nrows cmat - 1]
|
||||
<*> [pc .. pc + ncols cmat - 1])
|
||||
then A.log A.Debug ("no cluster placed") $
|
||||
placeCluster g2 bnds (try + 1) mat rp appl
|
||||
placeCluster imat g2 bnds (try + 1) mat rp appl
|
||||
else if
|
||||
not (isReachable newmat [] (oldreaches ++ reaches) exits)
|
||||
then A.log A.Debug ("no cluster placed") $
|
||||
placeCluster g2 bnds (try + 1) mat rp appl
|
||||
else A.log A.Debug ("placed cluster" ++ show appl) $
|
||||
placeCluster g2 bnds (try + 1) newmat newrp appl
|
||||
isReachable newmat [(V2 10 10, Boundaries (0, 1) (0, 1))] (oldreaches ++ reaches) exits
|
||||
then A.log A.Debug ("placed cluster" ++ show appl) $
|
||||
placeCluster imat g2 bnds (try + 1) newmat newrp appl
|
||||
else A.log A.Debug ("no cluster placed") $
|
||||
placeCluster imat g2 bnds (try + 1) mat rp appl
|
||||
|
||||
insertMat
|
||||
:: Matrix (Maybe a)
|
||||
|
|
Loading…
Reference in a new issue