Skip to content

Commit

Permalink
copy parent robot context to child when executing build
Browse files Browse the repository at this point in the history
Fixes #394.
  • Loading branch information
byorgey committed Nov 2, 2022
1 parent ca6a4e1 commit 7a198a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
9 changes: 8 additions & 1 deletion data/scenarios/Testing/394-build-drill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ solution: |
r <- build {
wait 2;
log "Hi, I am builder";
forever (build {log "Hi, I am pusher"; turn forward; forever push}; log "- robot built")
forever (
build {
log "Hi, I am pusher";
require "drill"; // #540
forever push
};
log "- robot built"
)
};
wait 10;
place "detonator";
Expand Down
7 changes: 6 additions & 1 deletion src/Swarm/Game/Robot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module Swarm.Game.Robot (
inventoryHash,
robotCapabilities,
robotContext,
trobotContext,
robotID,
robotParentID,
robotHeavy,
Expand Down Expand Up @@ -322,9 +323,13 @@ robotOrientation = robotEntity . entityOrientation
robotInventory :: Lens' Robot Inventory
robotInventory = robotEntity . entityInventory

-- | The robot's context
-- | The robot's context.
robotContext :: Lens' Robot RobotContext

-- | The robot's context.
trobotContext :: Lens' TRobot RobotContext
trobotContext = lens _robotContext (\r c -> r {_robotContext = c})

-- | The (unique) ID number of the robot. This is only a Getter since
-- the robot ID is immutable.
robotID :: Getter Robot RID
Expand Down
3 changes: 2 additions & 1 deletion src/Swarm/Game/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,9 @@ execConst c vs s k = do
createdAt <- getNow

-- Construct the new robot and add it to the world.
parentCtx <- use robotContext
newRobot <-
addTRobot $
addTRobot . (trobotContext .~ parentCtx) $
mkRobot
()
(Just pid)
Expand Down
3 changes: 1 addition & 2 deletions test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ testScenarioSolution _ci _em =
]
, testGroup
"Regression tests"
[ expectFailBecause "Awaiting fix (#394)" $
testSolution Default "Testing/394-build-drill"
[ testSolution Default "Testing/394-build-drill"
, testSolution Default "Testing/373-drill"
, testSolution Default "Testing/428-drowning-destroy"
, testSolution' Default "Testing/475-wait-one" $ \g -> do
Expand Down

0 comments on commit 7a198a0

Please sign in to comment.