-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split scenario construction into separate sublibrary
- Loading branch information
Showing
77 changed files
with
230 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- State-aware robot utility functions | ||
module Swarm.Game.Robot.Query where | ||
|
||
import Control.Lens (view, (^.)) | ||
import Data.Maybe (isNothing) | ||
import Swarm.Game.CESK qualified as C | ||
import Swarm.Game.Robot | ||
import Swarm.Language.Value as V | ||
|
||
-- | Is the robot actively in the middle of a computation? | ||
isActive :: Robot -> Bool | ||
{-# INLINE isActive #-} | ||
isActive = isNothing . getResult | ||
|
||
-- | "Active" robots include robots that are waiting; 'wantsToStep' is | ||
-- true if the robot actually wants to take another step right now | ||
-- (this is a /subset/ of active robots). | ||
wantsToStep :: C.TickNumber -> Robot -> Bool | ||
wantsToStep now robot | ||
| not (isActive robot) = False | ||
| otherwise = maybe True (now >=) (waitingUntil robot) | ||
|
||
-- | The time until which the robot is waiting, if any. | ||
waitingUntil :: Robot -> Maybe C.TickNumber | ||
waitingUntil robot = | ||
case robot ^. machine of | ||
C.Waiting time _ -> Just time | ||
_ -> Nothing | ||
|
||
-- | Get the result of the robot's computation if it is finished. | ||
getResult :: Robot -> Maybe (Value, C.Store) | ||
{-# INLINE getResult #-} | ||
getResult = C.finalValue . view machine | ||
|
||
hearingDistance :: (Num i) => i | ||
hearingDistance = 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.