From c4c7541b71c0fabee673684119bca57a01df688e Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 14 Oct 2018 23:18:41 +0200 Subject: [PATCH] eliminating toilet bug --- src/Interior.hs | 25 +++++++++++++++++-------- src/Types/Interior.hs | 2 +- src/Util.hs | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Interior.hs b/src/Interior.hs index 9224bf2..aa53bd5 100644 --- a/src/Interior.hs +++ b/src/Interior.hs @@ -1,5 +1,7 @@ module Interior where +import qualified Affection as A + import Data.Matrix as M import qualified Data.Map.Strict as Map import Data.List as L @@ -100,11 +102,14 @@ placeInteriorIO imat imgmat irp graph = newrp = rp ++ map (\(a, b, c) -> ReachPoint a b c) (zip3 reachtypes reaches reachdirs) in - if try > 10 || fromIntegral freeRoom < size appl + if try >= 10 || fromIntegral freeRoom <= size appl then (g2, (mat, rp)) else - if (pr + nrows cmat - 1 > fst (matmax bnds) || - pc + ncols cmat - 1 > snd (matmax bnds) || + 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 + else if any (`notElem` clusterRoom appl) (M.toList (M.submatrix pr (pr + nrows cmat - 1) @@ -116,11 +121,15 @@ placeInteriorIO imat imgmat irp graph = pr (pr + nrows cmat - 1) pc (pc + ncols cmat - 1) mat - ))) || - not (isReachable newmat [] (oldreaches ++ reaches) exits) - then placeCluster g2 bnds (try + 1) mat rp appl - else placeCluster - g2 bnds (try + 1) newmat newrp appl + )) + then A.log A.Debug ("no cluster placed") $ + placeCluster 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 insertMat :: Matrix (Maybe a) diff --git a/src/Types/Interior.hs b/src/Types/Interior.hs index cb60c58..c81c5bc 100644 --- a/src/Types/Interior.hs +++ b/src/Types/Interior.hs @@ -27,7 +27,7 @@ data Cluster | ClusterPlant2 | ClusterToilet | ClusterWatercooler - deriving (Enum, Bounded) + deriving (Enum, Bounded, Show) clusterMat :: Cluster -> Matrix (Maybe ImgId) clusterMat ClusterBox1 = diff --git a/src/Util.hs b/src/Util.hs index 54771e7..7e6585c 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -171,7 +171,7 @@ naviGraph imgmat animBounds (V2 r c) = map snd (filter (\(V2 br bc, _) -> floor br == r + rr && floor bc == c + cc) animBounds)) - then V2 (r + rr) (c + cc): acc + then V2 (r + rr) (c + cc) : acc else acc ) []