works better

This commit is contained in:
nek0 2018-02-16 22:16:28 +01:00
parent 713bc1adf2
commit e6fc4011ac

View file

@ -43,7 +43,7 @@ data FloorConfig = FloorConfig
data Boundaries = Boundaries
{ matmin :: (Int, Int)
, matmax :: (Int, Int)
} deriving (Show)
} deriving (Show, Eq)
buildHallFloorIO :: FloorConfig -> IO (Matrix TileState)
buildHallFloorIO fc = do
@ -372,20 +372,26 @@ buildDoorsGraph mat =
in
if Hall `elem` map snd neighs
then
let nroot = GHall
{ connects = connects (head root) ++ [GRoom neighs b]
} : tail root
let nroot =
if GRoom neighs b `notElem` connects (head root)
then
GHall
{ connects = connects (head root) ++ [GRoom neighs b]
} : tail root
else root
in buildGraph amat nroot (br, 1 + snd (matmax b))
else
let nroot = root ++
[GRoom neighs b]
if GRoom neighs b `elem` root
then []
else [GRoom neighs b]
in buildGraph amat nroot (br, 1 + snd (matmax b))
| otherwise =
buildGraph amat root (br, maxCol br (bc + 1))
in buildGraph mat [GHall []] (2, 2)
data GraphDirection = North | South | East | West
deriving (Eq)
deriving (Show, Eq)
data Graph
= GHall
@ -395,9 +401,11 @@ data Graph
{ neighbs :: [(GraphDirection, TileState)]
, bounds :: Boundaries
}
deriving (Show, Eq)
buildDoors :: Matrix TileState -> [Graph] -> IO (Matrix TileState)
buildDoors input graph =
buildDoors input graph = do
traceIO ("graph: " ++ show (tail graph))
foldM placeDoors input graph
where
placeDoors :: Matrix TileState -> Graph -> IO (Matrix TileState)
@ -406,6 +414,7 @@ buildDoors input graph =
placeDoors amat (GRoom neighs bounds) =
if Hall `elem` map snd neighs
then do
traceIO "door in Hall"
let halls = filter ((== Hall) . snd) neighs
idx <- randomRIO (0, length halls - 1)
let (dir, _) = halls !! idx
@ -431,6 +440,7 @@ buildDoors input graph =
(fst (matmin bounds), fst (matmax bounds))
(snd (matmax bounds) + 1)
else do
traceIO "door in Office"
idx <- randomRIO (0, length neighs - 1)
let (dir, _) = neighs !! idx
case dir of
@ -467,7 +477,7 @@ buildDoors input graph =
if Door `elem` M.toList (M.submatrix row row (fst cols) (snd cols) mat)
then return mat
else do
traceIO "placing door"
traceIO ("placing door: " ++ show (row, col))
return $ M.setElem Door (row, col) mat
else
inRow mat row cols
@ -484,7 +494,7 @@ buildDoors input graph =
if Door `elem` M.toList (M.submatrix (fst rows) (snd rows) col col mat)
then return mat
else do
traceIO "placing door"
traceIO ("placing door: " ++ show (row, col))
return $ M.setElem Door (row, col) mat
else
inCol mat rows col