now building facilities

This commit is contained in:
nek0 2018-02-15 03:50:51 +01:00
parent 5ab26a1507
commit b8028ecd54

View file

@ -50,12 +50,13 @@ buildHallFloorIO fc = do
buildHallFloor :: FloorConfig -> StdGen -> Matrix TileState
buildHallFloor fc gen =
let empty = emptyFloor fc
(g1, withElv) = buildElevator fc (placeHalls gen fc empty)
(g2, withIW) = buildInnerWalls g1 withElv
withOW = buildOuterWalls withIW
closed = closeOffices withOW
in closed
let empty = emptyFloor fc
(g1, withElv) = buildElevator fc (placeHalls gen fc empty)
(g2, withIW) = buildInnerWalls g1 withElv
withOW = buildOuterWalls withIW
closed = closeOffices withOW
(g3, facilities) = buildFacilities g2 fc closed
in facilities
emptyFloor :: FloorConfig -> Matrix TileState
emptyFloor fc =
@ -270,3 +271,43 @@ buildOuterWalls input =
, ncols horz
]
in vert
buildFacilities
:: StdGen
-> FloorConfig
-> Matrix TileState
-> (StdGen, Matrix TileState)
buildFacilities gen fc input =
let flood ts mat coords@(cr, cc) =
let cur = mat M.! coords
altered = M.setElem ts coords mat
in
if cur == ts || cur /= Offi
then mat
else foldl (\acc cs -> flood ts acc cs)
altered
[ (cr + 1, cc)
, (cr - 1, cc)
, (cr, cc + 1)
, (cr, cc - 1)
]
nearests = map (findNearestOffice input) (facilities fc)
in (foldl (\(agen, acc) x ->
let (numfac, ngen) = randomR (0 :: Int, 1 :: Int) agen
facil = if numfac == 1 then Kitc else Toil
in (ngen, flood facil acc x)
) (gen, input) nearests)
findNearestOffice
:: Matrix TileState
-> (Int, Int)
-> (Int, Int)
findNearestOffice mat (rrr, ccc) =
let matcoord = (,) <$> [1 .. nrows mat] <*> [1 .. ncols mat]
distance (ar, ac) = (ar - rrr) ^ 2 + (ac - ccc) ^ 2
inlist = zip matcoord (M.toList mat)
in foldl (\acc@(arow, acol) x@(xc@(crow, ccol), ts) ->
if ts == Offi && distance acc > distance xc
then xc
else acc
) (fst $ head inlist) inlist