diff --git a/data/scenarios/Tutorials/crash-secret.sw b/data/scenarios/Tutorials/crash-secret.sw index b24f6cb32..6fe259240 100644 --- a/data/scenarios/Tutorials/crash-secret.sw +++ b/data/scenarios/Tutorials/crash-secret.sw @@ -19,37 +19,35 @@ def allOK: actor -> bool = \rob. true end; +myLoc <- whereami; + // Try to give a robot a Win, filtering out those that were already given a Win. // The robot will also receive instructions, so it **must have a logger!** -def tryGive: text -> (actor -> bool) -> int -> cmd (actor -> bool) = \msg.\f.\i. - r <- try { - robotNumbered i; - } { - log $ "could not find robot " ++ format i; - return self - }; - if (r != self && f r) { - log $ "found the robot " ++ format i; - l <- whereami; - rl <- as r {whereami}; wait 1; // WHY is this 'wait 1' required??? - if (l != rl) { - log $ "the robot" ++ format i ++ "is not in my cell"; - return f; +def tryGive: text -> (actor -> bool) -> cmd (actor -> bool) = \msg. + // (b -> actor -> cmd b) -> b -> cmd b + meetAll $ \f.\rob. + if (not $ f rob) { + log $ "skipping the robot " ++ format rob ++ "because it already has a Win"; + return f } { - try { - reprogram r { log msg; }; - log $ "successfully reprogrammed robot " ++ format i; - give r "Win"; - log $ "successfully gave Win to robot " ++ format i; + robLoc <- as rob {whereami}; + if (robLoc != myLoc) { + log $ "the robot" ++ format rob ++ "is not in my cell"; + return f; } { - log $ "the robot " ++ format i ++ "is missing a logger!" - }; - return (\rob. (rob != r && f rob)); + try { + reprogram rob { log msg; }; + log $ "successfully reprogrammed robot " ++ format rob; + give rob "Win"; + log $ "successfully gave Win to robot " ++ format rob; + return (\r. (rob != r && f rob)); + } { + log $ "the robot " ++ format rob ++ "is missing a logger!"; + return f; + }; + + } } - } { - log $ "skipping the robot " ++ format i; - return f - } end; // ------------------------------------------------------------------------- @@ -57,7 +55,7 @@ end; // ------------------------------------------------------------------------- log "Hi, I am secret"; -iterate allOK (foreachF 1 16 $ tryGive +iterate allOK (tryGive $ "Send a robot to `salvage` me and come back to `give base \"Win\"`.\n" ++ "When the rescue robot stands where I am and executes `salvage`,\n" ++ "all my inventory and logs will go to it, including the \"Win\".\n" diff --git a/data/scenarios/Tutorials/farming.sw b/data/scenarios/Tutorials/farming.sw index 46f81f515..aea3c9410 100644 --- a/data/scenarios/Tutorials/farming.sw +++ b/data/scenarios/Tutorials/farming.sw @@ -20,7 +20,6 @@ def x12 = \c. x4 (c;c;c) end; def m12 = x12 move end; def next_row = tB; m12; tL; move; tL end; def plant_field : text -> cmd unit = \thing. - log "planting"; x4 ( x12 (move; place thing; harvest); next_row diff --git a/src/Swarm/Language/Syntax.hs b/src/Swarm/Language/Syntax.hs index 6efa09db0..e8edf58cc 100644 --- a/src/Swarm/Language/Syntax.hs +++ b/src/Swarm/Language/Syntax.hs @@ -628,7 +628,7 @@ constInfo c = case c of <> "that is done automatically once you have a listening device equipped." , "Note that you can see the messages either in your logger device or the message panel." ] - Log -> command 1 Intangible "Log the string in the robot's logger." + Log -> command 1 short "Log the string in the robot's logger." View -> command 1 short "View the given actor." Appear -> command 1 short . doc "Set how the robot is displayed." $ diff --git a/src/Swarm/TUI/View.hs b/src/Swarm/TUI/View.hs index 969fb5d03..bb2d89b59 100644 --- a/src/Swarm/TUI/View.hs +++ b/src/Swarm/TUI/View.hs @@ -1091,18 +1091,13 @@ drawRobotLog :: AppState -> Widget Name drawRobotLog s = vBox [ padBottom (Pad 1) (hBorderWithLabel (txt "Log")) - , vBox . imap drawEntry $ logEntries + , vBox . F.toList . imap drawEntry $ logEntries ] where - logEntries = - s - & view (gameState . to focusedRobot . _Just . robotLog) - & Seq.sort - & F.toList - & uniq + logEntries = s ^. gameState . to focusedRobot . _Just . robotLog rn = s ^? gameState . to focusedRobot . _Just . robotName - n = length logEntries + n = Seq.length logEntries allMe = all ((== rn) . Just . view leRobotName) logEntries diff --git a/test/integration/Main.hs b/test/integration/Main.hs index af8256bff..b15d4527a 100644 --- a/test/integration/Main.hs +++ b/test/integration/Main.hs @@ -186,7 +186,7 @@ testScenarioSolution _ci _em = r1Waits = g ^?! robotMap . ix 1 . to waitingUntil active = IS.member 1 $ g ^. activeRobots waiting = elem 1 . concat . M.elems $ g ^. waitingRobots - assertBool "The game should only take one tick" $ t == 1 + assertBool "The game should only take two ticks" $ t == 2 assertBool "Robot 1 should have waiting machine" $ isJust r1Waits assertBool "Robot 1 should be still active" active assertBool "Robot 1 should not be in waiting set" $ not waiting