@@ -85,6 +85,23 @@ issue bid cmd = do
8585 let trace' = trace ++ [cmd]
8686 modify $ \ st -> st {gsTraces = gsTraces st // [(bid, trace')]}
8787
88+ nearPlus :: P3 -> NearDiff -> P3
89+ nearPlus (x,y,z) (NearDiff dx dy dz) = (x+ fromIntegral dx, y+ fromIntegral dy, z+ fromIntegral dz)
90+
91+ negateNear :: NearDiff -> NearDiff
92+ negateNear (NearDiff dx dy dz) = NearDiff (- dx) (- dy) (- dz)
93+
94+ -- | Issue the Fill command
95+ -- This will mark the voxel as filled in generator's state
96+ issueFill :: BID -> NearDiff -> Generator ()
97+ issueFill bid nd = do
98+ bot <- getBot bid
99+ let c' = nearPlus (_pos bot) nd
100+ filled <- isFilled c'
101+ if filled
102+ then fail $ " Voxel is already filled: " ++ show c'
103+ else issue bid $ Fill nd
104+
88105-- | Switch to the next step.
89106-- If we did not issue commands for some bots on current steps,
90107-- automatically issue Wait command for them.
@@ -118,9 +135,7 @@ origin :: P3
118135origin = (0 ,0 ,0 )
119136
120137clamp :: Ord a => (a , a ) -> a -> a
121- clamp (low, high) value
122- | value >= low && value <= high = max low (min value high)
123- | otherwise = error " clamp: value is outside of clamping range"
138+ clamp (low, high) value = max low (min value high)
124139
125140extractMove :: P3d -> Either P3d (Command , P3d )
126141extractMove p@ (dx, dy, dz) =
@@ -188,6 +203,18 @@ isFilledInModel p = do
188203 matrix <- gets (mfMatrix . gsModel)
189204 return $ matrix BA. ! p
190205
206+ -- | Returns True if voxel was not filled by generator yet
207+ isFree :: P3 -> Generator Bool
208+ isFree p = do
209+ matrix <- gets gsFilled
210+ return $ not $ matrix BA. ! p
211+
212+ -- | Returns True if voxel is already filled by the generator
213+ isFilled :: P3 -> Generator Bool
214+ isFilled p = do
215+ matrix <- gets gsFilled
216+ return $ matrix BA. ! p
217+
191218makeTrace :: ModelFile -> Generator a -> [Command ]
192219makeTrace model gen =
193220 let st = execState gen (initState model)
0 commit comments