| License | BSD-3-Clause |
|---|---|
| Safe Haskell | None |
| Language | Haskell2010 |
Swarm.Game.Device
Description
A device is an entity that provides capabilities.
Some capabilities have a cost to exercise. Items will be consumed from the inventory for invoking a command that utilizes a given capability.
Synopsis
- type SingleEntityCapabilities e = Capabilities (ExerciseCost e)
- type MultiEntityCapabilities e en = Capabilities (NonEmpty (DeviceUseCost e en))
- newtype Capabilities e = Capabilities {
- getMap :: Map Capability e
- data DeviceUseCost e en = DeviceUseCost {
- device :: e
- useCost :: ExerciseCost en
- newtype ExerciseCost e = ExerciseCost {}
- data CommandsAndCost e = CommandsAndCost {}
- getCapabilitySet :: Capabilities e -> Set Capability
- zeroCostCapabilities :: Set Capability -> SingleEntityCapabilities e
- commandsForDeviceCaps :: SingleEntityCapabilities e -> Capabilities (CommandsAndCost e)
Documentation
type SingleEntityCapabilities e = Capabilities (ExerciseCost e) Source #
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 MultiEntityCapabilities e en = Capabilities (NonEmpty (DeviceUseCost e en)) Source #
Records a list of devices capable of providing each capability;
along with each device is recorded the ExerciseCost needed to use
that device to achieve the given capability.
See DeviceUseCost for explanation of type parameters.
newtype Capabilities e Source #
The 'Capabilities e' wrapper type stores information of type e for each
of some set of capabilities.
For example, e could be a list of ingredients needed to exercise a
capability, or a set of devices capable of providing a capability.
Constructors
| Capabilities | |
Fields
| |
Instances
data DeviceUseCost e en Source #
A device paired with a cost to use it.
At scenario parse time, the type parameters e and en will stand for
Entity and EntityName.
This is because ExerciseCost is a member of the Entity datatype, and
therefore can only refer to another Entity by name before all Entitys
are parsed.
However, after parse time, we are able to look up actual Entity objects
by name, and therefore can instantiate ExerciseCost with Entity as
the type parameter.
Then the two type parameters of DeviceUseCost are both of Entity type.
Constructors
| DeviceUseCost | |
Fields
| |
Instances
| Foldable (DeviceUseCost e) Source # | |||||
Defined in Swarm.Game.Device Methods fold :: Monoid m => DeviceUseCost e m -> m # foldMap :: Monoid m => (a -> m) -> DeviceUseCost e a -> m # foldMap' :: Monoid m => (a -> m) -> DeviceUseCost e a -> m # foldr :: (a -> b -> b) -> b -> DeviceUseCost e a -> b # foldr' :: (a -> b -> b) -> b -> DeviceUseCost e a -> b # foldl :: (b -> a -> b) -> b -> DeviceUseCost e a -> b # foldl' :: (b -> a -> b) -> b -> DeviceUseCost e a -> b # foldr1 :: (a -> a -> a) -> DeviceUseCost e a -> a # foldl1 :: (a -> a -> a) -> DeviceUseCost e a -> a # toList :: DeviceUseCost e a -> [a] # null :: DeviceUseCost e a -> Bool # length :: DeviceUseCost e a -> Int # elem :: Eq a => a -> DeviceUseCost e a -> Bool # maximum :: Ord a => DeviceUseCost e a -> a # minimum :: Ord a => DeviceUseCost e a -> a # sum :: Num a => DeviceUseCost e a -> a # product :: Num a => DeviceUseCost e a -> a # | |||||
| Traversable (DeviceUseCost e) Source # | |||||
Defined in Swarm.Game.Device Methods traverse :: Applicative f => (a -> f b) -> DeviceUseCost e a -> f (DeviceUseCost e b) # sequenceA :: Applicative f => DeviceUseCost e (f a) -> f (DeviceUseCost e a) # mapM :: Monad m => (a -> m b) -> DeviceUseCost e a -> m (DeviceUseCost e b) # sequence :: Monad m => DeviceUseCost e (m a) -> m (DeviceUseCost e a) # | |||||
| Functor (DeviceUseCost e) Source # | |||||
Defined in Swarm.Game.Device Methods fmap :: (a -> b) -> DeviceUseCost e a -> DeviceUseCost e b # (<$) :: a -> DeviceUseCost e b -> DeviceUseCost e a # | |||||
| (FromJSON e, FromJSON en) => FromJSON (DeviceUseCost e en) Source # | |||||
Defined in Swarm.Game.Device Methods parseJSON :: Value -> Parser (DeviceUseCost e en) # parseJSONList :: Value -> Parser [DeviceUseCost e en] # omittedField :: Maybe (DeviceUseCost e en) # | |||||
| (ToJSON en, ToJSON e) => ToJSON (DeviceUseCost e en) Source # | |||||
Defined in Swarm.Game.Device Methods toJSON :: DeviceUseCost e en -> Value # toEncoding :: DeviceUseCost e en -> Encoding # toJSONList :: [DeviceUseCost e en] -> Value # toEncodingList :: [DeviceUseCost e en] -> Encoding # omitField :: DeviceUseCost e en -> Bool # | |||||
| Generic (DeviceUseCost e en) Source # | |||||
Defined in Swarm.Game.Device Associated Types
Methods from :: DeviceUseCost e en -> Rep (DeviceUseCost e en) x # to :: Rep (DeviceUseCost e en) x -> DeviceUseCost e en # | |||||
| (Show e, Show en) => Show (DeviceUseCost e en) Source # | |||||
Defined in Swarm.Game.Device Methods showsPrec :: Int -> DeviceUseCost e en -> ShowS # show :: DeviceUseCost e en -> String # showList :: [DeviceUseCost e en] -> ShowS # | |||||
| (Eq e, Eq en) => Eq (DeviceUseCost e en) Source # | |||||
Defined in Swarm.Game.Device Methods (==) :: DeviceUseCost e en -> DeviceUseCost e en -> Bool # (/=) :: DeviceUseCost e en -> DeviceUseCost e en -> Bool # | |||||
| (Ord e, Eq en) => Ord (DeviceUseCost e en) Source # | |||||
Defined in Swarm.Game.Device Methods compare :: DeviceUseCost e en -> DeviceUseCost e en -> Ordering # (<) :: DeviceUseCost e en -> DeviceUseCost e en -> Bool # (<=) :: DeviceUseCost e en -> DeviceUseCost e en -> Bool # (>) :: DeviceUseCost e en -> DeviceUseCost e en -> Bool # (>=) :: DeviceUseCost e en -> DeviceUseCost e en -> Bool # max :: DeviceUseCost e en -> DeviceUseCost e en -> DeviceUseCost e en # min :: DeviceUseCost e en -> DeviceUseCost e en -> DeviceUseCost e en # | |||||
| type Rep (DeviceUseCost e en) Source # | |||||
Defined in Swarm.Game.Device type Rep (DeviceUseCost e en) = D1 ('MetaData "DeviceUseCost" "Swarm.Game.Device" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-swarm-scenario" 'False) (C1 ('MetaCons "DeviceUseCost" 'PrefixI 'True) (S1 ('MetaSel ('Just "device") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 e) :*: S1 ('MetaSel ('Just "useCost") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (ExerciseCost en)))) | |||||
newtype ExerciseCost e Source #
Exercising a capability may have a cost, in the form of entities that must be consumed each time it is used.
Constructors
| ExerciseCost | |
Fields | |
Instances
| Foldable ExerciseCost Source # | |||||
Defined in Swarm.Game.Device Methods fold :: Monoid m => ExerciseCost m -> m # foldMap :: Monoid m => (a -> m) -> ExerciseCost a -> m # foldMap' :: Monoid m => (a -> m) -> ExerciseCost a -> m # foldr :: (a -> b -> b) -> b -> ExerciseCost a -> b # foldr' :: (a -> b -> b) -> b -> ExerciseCost a -> b # foldl :: (b -> a -> b) -> b -> ExerciseCost a -> b # foldl' :: (b -> a -> b) -> b -> ExerciseCost a -> b # foldr1 :: (a -> a -> a) -> ExerciseCost a -> a # foldl1 :: (a -> a -> a) -> ExerciseCost a -> a # toList :: ExerciseCost a -> [a] # null :: ExerciseCost a -> Bool # length :: ExerciseCost a -> Int # elem :: Eq a => a -> ExerciseCost a -> Bool # maximum :: Ord a => ExerciseCost a -> a # minimum :: Ord a => ExerciseCost a -> a # sum :: Num a => ExerciseCost a -> a # product :: Num a => ExerciseCost a -> a # | |||||
| Traversable ExerciseCost Source # | |||||
Defined in Swarm.Game.Device Methods traverse :: Applicative f => (a -> f b) -> ExerciseCost a -> f (ExerciseCost b) # sequenceA :: Applicative f => ExerciseCost (f a) -> f (ExerciseCost a) # mapM :: Monad m => (a -> m b) -> ExerciseCost a -> m (ExerciseCost b) # sequence :: Monad m => ExerciseCost (m a) -> m (ExerciseCost a) # | |||||
| Functor ExerciseCost Source # | |||||
Defined in Swarm.Game.Device Methods fmap :: (a -> b) -> ExerciseCost a -> ExerciseCost b # (<$) :: a -> ExerciseCost b -> ExerciseCost a # | |||||
| FromJSON e => FromJSON (ExerciseCost e) Source # | |||||
Defined in Swarm.Game.Device Methods parseJSON :: Value -> Parser (ExerciseCost e) # parseJSONList :: Value -> Parser [ExerciseCost e] # omittedField :: Maybe (ExerciseCost e) # | |||||
| FromJSON e => FromJSON (SingleEntityCapabilities e) Source # | First, attempt to parse capabilities as a list, interpreted as a set of capabilities with no exercise cost. Otherwise, parse as a Map from capabilities to ingredients. | ||||
Defined in Swarm.Game.Device Methods parseJSON :: Value -> Parser (SingleEntityCapabilities e) # parseJSONList :: Value -> Parser [SingleEntityCapabilities e] # | |||||
| ToJSON e => ToJSON (ExerciseCost e) Source # | |||||
Defined in Swarm.Game.Device Methods toJSON :: ExerciseCost e -> Value # toEncoding :: ExerciseCost e -> Encoding # toJSONList :: [ExerciseCost e] -> Value # toEncodingList :: [ExerciseCost e] -> Encoding # omitField :: ExerciseCost e -> Bool # | |||||
| Generic (ExerciseCost e) Source # | |||||
Defined in Swarm.Game.Device Associated Types
Methods from :: ExerciseCost e -> Rep (ExerciseCost e) x # to :: Rep (ExerciseCost e) x -> ExerciseCost e # | |||||
| Show e => Show (ExerciseCost e) Source # | |||||
Defined in Swarm.Game.Device Methods showsPrec :: Int -> ExerciseCost e -> ShowS # show :: ExerciseCost e -> String # showList :: [ExerciseCost e] -> ShowS # | |||||
| Eq e => Eq (ExerciseCost e) Source # | |||||
Defined in Swarm.Game.Device Methods (==) :: ExerciseCost e -> ExerciseCost e -> Bool # (/=) :: ExerciseCost e -> ExerciseCost e -> Bool # | |||||
| Eq e => Ord (ExerciseCost e) Source # | Sort | ||||
Defined in Swarm.Game.Device Methods compare :: ExerciseCost e -> ExerciseCost e -> Ordering # (<) :: ExerciseCost e -> ExerciseCost e -> Bool # (<=) :: ExerciseCost e -> ExerciseCost e -> Bool # (>) :: ExerciseCost e -> ExerciseCost e -> Bool # (>=) :: ExerciseCost e -> ExerciseCost e -> Bool # max :: ExerciseCost e -> ExerciseCost e -> ExerciseCost e # min :: ExerciseCost e -> ExerciseCost e -> ExerciseCost e # | |||||
| Hashable e => Hashable (ExerciseCost e) Source # | |||||
Defined in Swarm.Game.Device | |||||
| type Rep (ExerciseCost e) Source # | |||||
Defined in Swarm.Game.Device type Rep (ExerciseCost e) = D1 ('MetaData "ExerciseCost" "Swarm.Game.Device" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-swarm-scenario" 'True) (C1 ('MetaCons "ExerciseCost" 'PrefixI 'True) (S1 ('MetaSel ('Just "ingredients") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (IngredientList e)))) | |||||
data CommandsAndCost e Source #
A nonempty list of commands together with an exercise cost for using any of them (typically these will be a list of commands all requiring the same capability).
Constructors
| CommandsAndCost | |
Fields | |
getCapabilitySet :: Capabilities e -> Set Capability Source #
Get the set of capabilities about which we are storing information.
zeroCostCapabilities :: Set Capability -> SingleEntityCapabilities e Source #
Create a default SingleEntityCapabilities map for a device which provides capabilities with no associated costs.
commandsForDeviceCaps :: SingleEntityCapabilities e -> Capabilities (CommandsAndCost e) Source #
Given mapping from capabilities to their exercise costs provided by a single device, turn it into an mapping from capabilities to their exercise cost and enabled commands.
NOTE: Because each Const is mapped to at most one
Capability by the constCaps function, we know that
a given Const will not appear more than once as a value in the Map produced by
this function, i.e. for the capabilities provided by a single Entity
(SingleEntityCapabilities).