Nomyx-Language-0.4.1: Language to express rules for Nomic

Safe HaskellNone




Basic rules examples.


Rule management

activateRule :: RuleNumber -> Nomex BoolSource

activate a rule: change its state to Active and execute it

rejectRule :: RuleNumber -> Nomex BoolSource

reject a rule: change its state to Suppressed and suppresses all its environment (events, variables, inputs) the rule can be activated again later

addRule :: Rule -> Nomex BoolSource

add a rule to the game, it will have to be activated

getFreeNumber :: (Eq a, Num a, Enum a) => [a] -> aSource

autoActivate :: RuleFuncSource

This rule will activate automatically any new rule.

legal :: RuleFuncSource

This rule will forbid any new rule to delete the rule in parameter immutableRule :: RuleNumber -> RuleFunc immutableRule rn = return $ Meta f where f r = do protectedRule <- getRule rn case protectedRule of Just pr -> case _rRuleFunc r of RuleRule paramRule -> paramRule pr _ -> return $ BoolResp True Nothing -> return $ BoolResp True

A rule will be always legal

illegal :: RuleFuncSource

A rule will be always illegal

maybeMetaRule :: Rule -> Nomex (Maybe (Rule -> Nomex BoolResp))Source

active metarules are automatically used to evaluate a given rule checkWithMetarules :: Rule -> Nomex (Event (Message ForAgainst) checkWithMetarules rule = do rs <- getActiveRules (metas :: [Rule -> Nomex BoolResp]) <- mapMaybeM maybeMetaRule rs let (evals :: [Nomex BoolResp]) = map (meta -> meta rule) metas foldr (&&*) true evals

activateOrReject :: Rule -> Bool -> Nomex ()Source

activate or reject a rule

noPlayPlayer :: PlayerNumber -> RuleFuncSource

Player p cannot propose anymore rules

autoDelete :: Nomex ()Source

a rule can autodelete itself (generaly after having performed some actions)

eraseAllRules :: PlayerNumber -> Nomex BoolSource

All rules from player p are erased:

getSelfRuleNumber :: Nomex RuleNumberSource

allows a rule to retrieve its own number (for auto-deleting for example)

defaultRule :: RuleSource

a default rule

mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]Source