Skip to content

Commit

Permalink
only meet interactive robots (#2262)
Browse files Browse the repository at this point in the history
As I was trying to solve #2249, I was rather confused after trying to `meet` a built robot and `give` them an item, but the item was not delivered.  It turns out that I had been `meet`-ing the `judge` robot instead.

We should distinguish between robots that are intended to be interactive or not, and only allow `meet`-ing an interactive robot.
  • Loading branch information
kostmo authored Jan 5, 2025
1 parent 8335051 commit f5c0700
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/swarm-engine/Swarm/Game/Step/Const.hs
Original file line number Diff line number Diff line change
Expand Up @@ -926,14 +926,15 @@ execConst runChildProg c vs s k = do
let neighbor =
find ((/= rid) . (^. robotID)) -- pick one other than ourself
. sortOn ((manhattan `on` view planar) loc . (^. robotLocation)) -- prefer closer
$ robotsInArea loc 1
. filter isInteractive
. robotsInArea loc 1
$ g ^. robotInfo -- all robots within Manhattan distance 1
return $ mkReturn neighbor
MeetAll -> do
loc <- use robotLocation
rid <- use robotID
g <- get @GameState
let neighborIDs = filter ((/= rid) . (^. robotID)) . robotsInArea loc 1 $ g ^. robotInfo
let neighborIDs = filter ((/= rid) . (^. robotID)) . filter isInteractive . robotsInArea loc 1 $ g ^. robotInfo
return $ mkReturn neighborIDs
Whoami -> case vs of
[] -> do
Expand Down
4 changes: 4 additions & 0 deletions src/swarm-scenario/Swarm/Game/Robot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module Swarm.Game.Robot (

-- ** Query
robotKnows,
isInteractive,

-- ** Constants
hearingDistance,
Expand Down Expand Up @@ -276,6 +277,9 @@ inventoryHash = to (\r -> 17 `hashWithSalt` (r ^. (robotEntity . entityHash)) `h
robotKnows :: Robot -> Entity -> Bool
robotKnows r e = contains0plus e (r ^. robotInventory) || contains0plus e (r ^. equippedDevices)

isInteractive :: Robot -> Bool
isInteractive r = not $ r ^. robotDisplay . invisible && r ^. systemRobot

-- | Get the set of capabilities this robot possesses. This is only a
-- getter, not a lens, because it is automatically generated from
-- the 'equippedDevices'. The only way to change a robot's
Expand Down

0 comments on commit f5c0700

Please sign in to comment.