Skip to content

Commit

Permalink
Show duplicate robot logs (#1022)
Browse files Browse the repository at this point in the history
- show duplicate robot logs in the log view
- make the log a tangible short command, like say
- fixup tests
  - Use meetAll to make crash tutorial more resilient
  - Account for log in wait-one test
  - Remove log from farming solution to fix timing
- closes #1021
  • Loading branch information
xsebek authored Jan 24, 2023
1 parent 2857c2d commit 07673d1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
52 changes: 25 additions & 27 deletions data/scenarios/Tutorials/crash-secret.sw
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,43 @@ 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;

// -------------------------------------------------------------------------
// RUN
// -------------------------------------------------------------------------

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"
Expand Down
1 change: 0 additions & 1 deletion data/scenarios/Tutorials/farming.sw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Swarm/Language/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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." $
Expand Down
11 changes: 3 additions & 8 deletions src/Swarm/TUI/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07673d1

Please sign in to comment.