still working on clearance levels
This commit is contained in:
parent
33a8e496bb
commit
8b5a9e6006
1 changed files with 28 additions and 25 deletions
|
@ -54,7 +54,7 @@ buildHallFloorIO fc progress increment = do
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Closed offices"
|
, "Closed offices"
|
||||||
)))
|
)))
|
||||||
let doorgraph = buildDoorsGraph closed
|
doorgraph <- buildDoorsGraph closed
|
||||||
modifyMVar_ progress (return . (\(p, _) ->
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Doorgraph"
|
, "Doorgraph"
|
||||||
|
@ -69,12 +69,12 @@ buildHallFloorIO fc progress increment = do
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Built facilities"
|
, "Built facilities"
|
||||||
)))
|
)))
|
||||||
accessGraph <- assignClearance doorgraph facils
|
-- accessGraph <- assignClearance doorgraph facils
|
||||||
modifyMVar_ progress (return . (\(p, _) ->
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Assigned room clearances"
|
, "Assigned room clearances"
|
||||||
)))
|
)))
|
||||||
return (facils, accessGraph)
|
return (facils, doorgraph)
|
||||||
|
|
||||||
emptyFloor :: FloorConfig -> Matrix TileState
|
emptyFloor :: FloorConfig -> Matrix TileState
|
||||||
emptyFloor fc =
|
emptyFloor fc =
|
||||||
|
@ -341,7 +341,7 @@ findNearestOffice mat (V2 rrr ccc) =
|
||||||
else acc
|
else acc
|
||||||
) (fst $ head inlist) inlist
|
) (fst $ head inlist) inlist
|
||||||
|
|
||||||
buildDoorsGraph :: Matrix TileState -> [Graph]
|
buildDoorsGraph :: Matrix TileState -> IO [Graph]
|
||||||
buildDoorsGraph mat =
|
buildDoorsGraph mat =
|
||||||
let maxCol r c
|
let maxCol r c
|
||||||
| M.safeGet r (c + 1) mat == Just Offi = maxCol r (c + 1)
|
| M.safeGet r (c + 1) mat == Just Offi = maxCol r (c + 1)
|
||||||
|
@ -402,31 +402,34 @@ buildDoorsGraph mat =
|
||||||
in buildGraph amat nroot (br, 1 + snd (matmax b))
|
in buildGraph amat nroot (br, 1 + snd (matmax b))
|
||||||
| otherwise =
|
| otherwise =
|
||||||
buildGraph amat root (br, maxCol br (bc + 1))
|
buildGraph amat root (br, maxCol br (bc + 1))
|
||||||
in buildGraph mat [GHall []] (2, 2)
|
in weedOut $ buildGraph mat [GHall []] (2, 2)
|
||||||
|
where
|
||||||
|
weedOut (hall@(GHall _):gs) = (hall :) <$> weedOut gs
|
||||||
|
weedOut (g@(GRoom neighs _ _ _):gs) = do
|
||||||
|
let filtered = filter ((== Offi) . snd) neighs
|
||||||
|
rand <- randomRIO (0, length filtered -1) :: IO Int
|
||||||
|
let nneigh = filtered !! rand : []
|
||||||
|
rest <- weedOut gs
|
||||||
|
return (g { neighbs = nneigh } : rest)
|
||||||
|
weedOut [] = return []
|
||||||
|
|
||||||
assignClearance :: [Graph] -> M.Matrix TileState -> IO [Graph]
|
assignClearance :: [Graph] -> M.Matrix TileState -> IO [Graph]
|
||||||
assignClearance graph imat =
|
assignClearance graph imat =
|
||||||
mapM doAssignClearance graph
|
mapM doAssignClearance graph
|
||||||
where
|
where
|
||||||
doAssignClearance (GHall hgs) = do
|
doAssignClearance (GHall conns) =
|
||||||
arooms <- mapM doAssignClearance hgs
|
GHall <$> mapM (reassign True) conns
|
||||||
return (GHall arooms)
|
doAssignClearance room =
|
||||||
doAssignClearance s@(GRoom _ _ _ _) = error (show s)
|
reassign False room
|
||||||
doAssignClearance gr@(GRoom neighs bnds _ _)
|
reassign p room@(GRoom ns b c t) =
|
||||||
| all ((/= Offi) . flip actualRoomType imat . bounds) (
|
if p
|
||||||
filter graphIsRoom (catMaybes $ map (\g -> findNeighbor g bnds imat graph) neighs)) &&
|
then do
|
||||||
actualRoomType bnds imat == Offi = do
|
if actualRoomType b imat == Offi
|
||||||
aroom <- doRandomAssign gr
|
then doRandomAssign room
|
||||||
return aroom
|
else return room
|
||||||
| all ((== Offi) . flip actualRoomType imat . bounds) (
|
else do
|
||||||
filter graphIsRoom (catMaybes $ map (\g -> findNeighbor g bnds imat graph) neighs)) &&
|
let neigh = findNeighbor (head ns) b imat graph
|
||||||
actualRoomType bnds imat == Offi = do
|
|
||||||
aroom <- doBoundedAssign gr
|
|
||||||
(minimum $ map
|
|
||||||
(\n -> fromMaybe 0 (clearance <$> (\g -> findNeighbor g bnds imat graph) n))
|
|
||||||
neighs
|
|
||||||
)
|
|
||||||
return aroom
|
|
||||||
|
|
||||||
actualRoomType :: Boundaries Int -> M.Matrix TileState -> TileState
|
actualRoomType :: Boundaries Int -> M.Matrix TileState -> TileState
|
||||||
actualRoomType (Boundaries (minrow, mincol) (maxrow, maxcol)) imat =
|
actualRoomType (Boundaries (minrow, mincol) (maxrow, maxcol)) imat =
|
||||||
|
@ -438,7 +441,7 @@ doRandomAssign :: Graph -> IO Graph
|
||||||
doRandomAssign g = do
|
doRandomAssign g = do
|
||||||
c <- randomRIO (0, 4)
|
c <- randomRIO (0, 4)
|
||||||
return g
|
return g
|
||||||
{ clearance = c
|
{ clearance = if actualRoomType c
|
||||||
}
|
}
|
||||||
|
|
||||||
doBoundedAssign :: Graph -> Word -> IO Graph
|
doBoundedAssign :: Graph -> Word -> IO Graph
|
||||||
|
|
Loading…
Reference in a new issue