Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only meet interactive robots #2262

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
only meet interactive robots
  • Loading branch information
kostmo committed Jan 4, 2025
commit c130339168b504ffaa4e5540d14f57e786310b27
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to improve this heuristic, or make it an explicit "interactive" property.

For example, I don't think we ever want to meet a "growing" flower.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree, growing trees, flowers, etc. are going to be a problem here. We use robots internally to simulate growth --- but from the perspective of a player that is just an implementation detail, they should not be returned by meet. This heuristic is better than nothing, but we will definitely want to improve it. I am fine with either merging this as is and making an issue to improve it later, or coming up with a better heuristic in this PR.

An explicit boolean interactive property probably makes sense, and I think it makes sense for interactive = true to be the default, but invisible system robots can still be non-interactive by default.


-- | 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
Loading