-
Notifications
You must be signed in to change notification settings - Fork 52
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
Capability exercise cost #1777
Capability exercise cost #1777
Conversation
e817921
to
28bc252
Compare
92f3423
to
d5643c1
Compare
7624011
to
01ac86a
Compare
62ee143
to
1ca0385
Compare
9660bb0
to
4158726
Compare
1e44c75
to
56b2a35
Compare
getCapabilitySet :: Capabilities e -> Set Capability | ||
getCapabilitySet (Capabilities m) = M.keysSet m | ||
|
||
type SingleEntityCapabilities e = Capabilities (ExerciseCost e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type SingleEntityCapabilities e = Capabilities (ExerciseCost e) | |
-- | Records an 'ExerciseCost', i.e. list of consumed ingredients, per capability that can be exercised. This represents information about a single entity/device, which can provide multiple capabilities (with a different exercise cost for each). | |
type SingleEntityCapabilities e = Capabilities (ExerciseCost e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After understanding the relationship between SingleEntityCapabilities
and MultiEntityCapabilities
, I was kind of expecting to see a function with a type like
Map e (SingleEntityCapabilities en) -> MultiEntityCapabilities e en
(that type might not work as written but hopefully you get the idea). Is there a function like this somewhere in a different module? Can it go in this module instead?
56b2a35
to
bacc71e
Compare
fdddaee
to
83f26eb
Compare
Co-authored-by: Brent Yorgey <[email protected]>
All review comments now addressed, @byorgey. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Closes #1684
Closes #1262
Demo
A simple "puzzle" that makes use of consumables:
Demo of enabled commands and costs display in left pane:
In this PR
tshow
implementation fromSwarm.Doc.Util
Entity lookup approaches
The cost of exercising a capability in terms of "ingredients" is specified by the
_entityCapabilities
field within anEntity
definition. Each ingredient itself is an entity, specified by name.For many purposes, having ingredients just of type
EntityName
is sufficient. But forSwarm.Game.Recipe.findLacking
in particular, the ingredients list must be actualEntity
objects, not just names of entities. So at some point the names need to be looked up in the global entity map to be promoted toEntity
objects.The full list of entities is not available at
Entity
parse time to look up an ingredient entity by name, so we cannot store ingredients lists of type(Count, Entity)
within a parentEntity
object.Approaches considered were:
entityMap
inRobotR
, for use by theequippedDevices
lensEntity
representing a "parse phase"Store
entityMap
inRobotR
One approach explored was to add a field to
RobotR
:This allowed the
equippedDevices
lens implementation to promote theEntityName
s toEntity
s when setting the value of the_robotCapabilities
field. However, it was rather invasive as it entailed threading theEntityMap
through many new code paths.Entity
type parameterCurrently,
Entity
has a field:This would entail a huge refactoring, with:
At initial parse time we would obtain a list of
Entity EntityName
, but somewhere later duringScenario
parse time, we can do another pass to obtainEntity Entity
objects.This would at least have the advantage of doing the entity lookup/validation on ingredient lists in exactly one place, at parse time.
Defer
EntityName -> Entity
promotion to command execution timeThis is what is implemented in this PR. The global set of capability costs is validated at scenario parse time. But it is also redundantly validated in the
payExerciseCost
function, which is not ideal.