Skip to content

Commit 3b99565

Browse files
committed
More correct harmonics switching.
refs #5.
1 parent 118b72d commit 3b99565

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Algorithms.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ fill bid dir p@(x,y,z) = do
4949
grounded <- willBeGrounded p
5050
unless grounded $
5151
setHarmonics bid High
52-
issueFill bid diff'
53-
setHarmonics bid Low
52+
grounded' <- issueFill bid diff'
53+
when grounded' $
54+
setHarmonics bid Low
5455
step
5556

5657
-- This would be too slow

src/Generator.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
121122
issueFill 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

Comments
 (0)