Skip to content

Commit

Permalink
Set REPL to Working when base has program field specified (#846)
Browse files Browse the repository at this point in the history
Part of #838.  It should now work to specify a `program` for the base robot with definitions, which the player can subsequently use.  Unfortunately we still cannot *test* such a scenario since any `solution` is typechecked in an empty context instead of in a context generated by the base `program`.
  • Loading branch information
byorgey authored Nov 8, 2022
1 parent 1930fe6 commit 3dd2be5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Swarm/Game/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ import Data.List.NonEmpty (NonEmpty)
import Data.List.NonEmpty qualified as NE
import Data.Map (Map)
import Data.Map qualified as M
import Data.Maybe (fromMaybe, isJust, mapMaybe)
import Data.Maybe (fromMaybe, isJust, isNothing, mapMaybe)
import Data.Sequence (Seq ((:<|)))
import Data.Sequence qualified as Seq
import Data.Set qualified as S
Expand All @@ -135,7 +135,7 @@ import Data.Text.IO qualified as T (readFile)
import Data.Time (getZonedTime)
import GHC.Generics (Generic)
import Linear
import Swarm.Game.CESK (emptyStore, initMachine)
import Swarm.Game.CESK (emptyStore, finalValue, initMachine)
import Swarm.Game.Entity
import Swarm.Game.Recipe (
Recipe,
Expand Down Expand Up @@ -777,11 +777,11 @@ scenarioToGameState scenario userSeed toRun g = do
, _viewCenterRule = VCRobot baseID
, _viewCenter = V2 0 0
, _needsRedraw = False
, -- When starting base with the run flag, REPL status must be set to working,
-- otherwise the store of definition cells is not saved (see #333)
_replStatus = case toRun of
Nothing -> REPLDone Nothing
Just _ -> REPLWorking (Typed Nothing PolyUnit mempty)
, -- When the base starts out running a program, the REPL status must be set to working,
-- otherwise the store of definition cells is not saved (see #333, #838)
_replStatus = case running of
False -> REPLDone Nothing
True -> REPLWorking (Typed Nothing PolyUnit mempty)
, _replNextValueIndex = 0
, _messageQueue = Empty
, _focusedRobotID = baseID
Expand Down Expand Up @@ -829,6 +829,9 @@ scenarioToGameState scenario userSeed toRun g = do
zipWith instantiateRobot [baseID ..] robotsByBasePrecedence
-- If the --run flag was used, use it to replace the CESK machine of the
-- robot whose id is 0, i.e. the first robot listed in the scenario.
-- Note that this *replaces* any program the base robot otherwise
-- would have run (i.e. any program specified in the program: field
-- of the scenario description).
& ix baseID . machine
%~ case getCodeToRun <$> toRun of
Nothing -> id
Expand All @@ -843,6 +846,10 @@ scenarioToGameState scenario userSeed toRun g = do
False -> id
True -> const (fromList devices)

running = case robotList of
[] -> False
(base : _) -> isNothing (finalValue (base ^. machine))

-- Initial list of available commands = all commands enabled by
-- devices in inventory or installed; and commands that require no
-- capability.
Expand Down

0 comments on commit 3dd2be5

Please sign in to comment.