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

Safe HaskellNone

Language.Nomyx.Rule

Description

Basic rules examples.

Synopsis

Documentation

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

checkWithMetarules :: Rule -> Nomex BoolRespSource

active metarules are automatically used to evaluate a given rule

onRuleProposed :: (Rule -> Nomex BoolResp) -> RuleFuncSource

any new rule will be activate if the rule in parameter returns True

type Assessor a = StateT VoteData Nomex aSource

voteWith :: CountVotes -> Assessor () -> Rule -> Nomex BoolRespSource

Performs a vote for a rule on all players. The provided function is used to count the votes. the assessors allows to configure how and when the vote will be assessed. The assessors can be chained.

assessOnEveryVotes :: Assessor ()Source

assess the vote on every new vote with the assess function, and as soon as the vote has an issue (positive of negative), sends a signal

assessOnTimeLimit :: UTCTime -> Assessor ()Source

assess the vote with the assess function when time is reached, and sends a signal with the issue (positive of negative)

assessOnTimeDelay :: NominalDiffTime -> Assessor ()Source

assess the vote with the assess function when time is elapsed, and sends a signal with the issue (positive of negative)

assessWhenEverybodyVoted :: Assessor ()Source

assess the vote only when every body voted. An error is generated if the assessing function returns Nothing.

noStatusQuo :: [Vote] -> [Vote]Source

players that did not voted are counted as negative.

cleanVote :: VoteData -> Nomex ()Source

clean events and variables necessary for the vote

quorum :: Int -> [Vote] -> BoolSource

a quorum is the neccessary number of voters for the validity of the vote

withQuorum :: CountVotes -> Int -> CountVotesSource

adds a quorum to an assessing function

unanimity :: [Vote] -> Maybe BoolSource

assess the vote results according to a unanimity (everybody votes for)

majority :: [Vote] -> Maybe BoolSource

assess the vote results according to an absolute majority (half voters plus one, no quorum is needed)

majorityWith :: Int -> [Vote] -> Maybe BoolSource

assess the vote results according to a majority of x (in %)

numberPositiveVotes :: Int -> [Vote] -> Maybe BoolSource

assess the vote results according to a necessary number of positive votes

voteQuota :: Int -> [Vote] -> Maybe BoolSource

helper function for assessement functions

nbFor :: [Vote] -> IntSource

get the number of positive votes and negative votes

nbAgainst :: [Vote] -> IntSource

get the number of positive votes and negative votes

voters :: [(PlayerNumber, Maybe ForAgainst)] -> [(PlayerNumber, ForAgainst)]Source

get only those who voted

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

activate or reject a rule

forEachPlayer :: (PlayerNumber -> Nomex ()) -> (PlayerNumber -> Nomex ()) -> (PlayerNumber -> Nomex ()) -> Nomex ()Source

perform an action for each current players, new players and leaving players

forEachPlayer_ :: (PlayerNumber -> Nomex ()) -> Nomex ()Source

perform the same action for each players, including new players

createValueForEachPlayer :: Int -> V [(Int, Int)] -> Nomex ()Source

create a value initialized for each players manages players joining and leaving

createValueForEachPlayer_ :: V [(Int, Int)] -> Nomex ()Source

create a value initialized for each players initialized to zero manages players joining and leaving

modifyAllValues :: V [(Int, Int)] -> (Int -> Int) -> Nomex ()Source

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:

maybeWhen :: Maybe a -> (a -> Nomex ()) -> Nomex ()Source