Class

RuleSystem

:

agenda

: Rule[]

state

: any

facts

: Map<string, number>

addRuleExecutingAction

(predicate: Predicate$1, action: Action, salience?: number) => void

Adds a rule which runs an action if its predicate evaluates to true.

param predicate- Predicate to evaluate. A function taking the system as parameter.

param action- Action to execute. A function taking the system as parameter.

param salience- Priority of the rule.

addRuleAssertingFact

(predicate: Predicate$1, fact: string, grade?: number, salience?: number) => void

Add a rule which asserts a fact if its predicate evaluates to true.

param predicate- Predicate to evaluate. A function taking the system as parameter.

param fact- The fact to assert.

param grade- The optional grade to use when asserting the fact.

param salience- Priority of the rule.

addRuleRetractingFact

(predicate: Predicate$1, fact: string, grade?: number, salience?: number) => void

Add a rule which retracts a fact if its predicate evaluates to true.

param predicate- Predicate to evaluate. A function taking the system as parameter.

param fact- The fact to retract.

param grade- The optional grade to use when retracting the fact.

param salience- Priority of the rule.

addRule

(rule: Rule) => void

Add a custom rule.

param rule- The rule to add.

removeAllRules

() => void

Removes all rules.

execute

() => void

Executes all rules for which the predicate evaluates to true.

assertFact

(fact: string, grade?: number) => void

Asserts a fact.

param fact- The fact to assert.

param grade- The optional grade to use.

retractFact

(fact: string, grade?: number) => void

Retracts a fact.

param fact- The fact to retract.

param grade- The optional grade to use.

gradeForFact

(fact: string) => number

Returns the grade for the specified fact.

param fact- The fact to obtain the grade from.

returns The grade for the fact.

minimumGradeForFacts

(facts: string[]) => number

Returns the minimum grade for the specified facts.

param facts- The facts to obtain the minimum grade from.

returns The minimum grade for the facts.

maximumGradeForFacts

(facts: string[]) => number

Returns the maximum grade for the specified facts.

param facts- The facts to obtain the maximum grade from.

returns The maximum grade for the facts.

reset

() => void

Resets the facts.

kaplay logo

Components

Miscalenous