@@ -117,7 +117,8 @@ negateNear (NearDiff dx dy dz) = NearDiff (-dx) (-dy) (-dz)
117117
118118-- | Issue the Fill command
119119-- This will mark the voxel as filled in generator's state
120- issueFill :: BID -> NearDiff -> Generator ()
120+ -- Returns True if as a result the voxel is grounded.
121+ issueFill :: BID -> NearDiff -> Generator Bool
121122issueFill bid nd = do
122123 bot <- getBot bid
123124 let c' = nearPlus (_pos bot) nd
@@ -129,12 +130,13 @@ issueFill bid nd = do
129130 modify $ \ st -> st {gsFilled = gsFilled st BA. // [(c', True )]}
130131 updateGrounded c'
131132 where
132- updateGrounded :: P3 -> Generator ()
133+ updateGrounded :: P3 -> Generator Bool
133134 updateGrounded p@ (x,y,z) = do
134135 filled <- gets gsFilled
135136 grounded <- gets gsGrounded
136137 let result = check filled grounded p
137138 modify $ \ st -> st {gsGrounded = gsGrounded st BA. // [(p, result)]}
139+ return result
138140 where
139141 check _ _ (_,0 ,_) = True
140142 check filled grounded p@ (x,y,z) =
@@ -161,6 +163,13 @@ willBeGrounded (x,y,z) = do
161163 (x- 1 , y, z), (x, y- 1 , z), (x, y, z- 1 )]
162164 return $ or [fromMaybe False (grounded BA. !? neighbour) | neighbour <- neighbours]
163165
166+ allAreGrounded :: Generator Bool
167+ allAreGrounded = do
168+ filledMatrix <- gets gsFilled
169+ let filledIdxs = [idx | idx <- BA. indices filledMatrix, filledMatrix BA. ! idx]
170+ grounded <- gets gsGrounded
171+ return $ and [grounded BA. ! idx | idx <- filledIdxs]
172+
164173-- | Switch to the next step.
165174-- If we did not issue commands for some bots on current steps,
166175-- automatically issue Wait command for them.
0 commit comments