take rulebase

define Rule_1 {
    (IF (hasFact 'engine_getting_petrol)
        (IF (hasFact 'engine_turns_over)
            (.
                (say '(Problem with spark plugs))
                (1)
            )
            (0)
        )
        (0)
    )
}

define Rule_2 {
    (IF (NOT (hasFact 'engine_turns_over))
        (IF (NOT (hasFact 'lights_come_on))
            (.
                (say '(Problem with battery))
                (1)
            )
            (0)
        )
        (0)
    )
}

define Rule_3 {
    (IF (NOT (hasFact 'engine_turns_over))
        (IF (hasFact 'lights_come_on)
            (.
                (say '(Problem with starter))
                (1)
            )
            (0)
        )
        (0)
    )
}

define rule_4 {
    (IF (hasFact 'petrol_in_fuel_tank)
        (.
            (addFact 'engine_getting_petrol)
            (1)
        )
        (0)
    )
}


echo
echo >>> FIRST CASE
echo >>> Car won't start, there is no obvious sign.
removeAllGoal
removeAllFact
fireRule {rule_1 rule_2 rule_3 rule_4 rule_5}
echo

echo
echo >>> SECOND CASE
echo >>> Car won't start, there is petrol in fuel tank and lights come on
removeAllGoal
removeAllFact
addFact petrol_in_fuel_tank lights_come_on
fireRule {rule_1 rule_2 rule_3 rule_4 rule_5}
echo

echo
echo >>> THIRD CASE
echo >>> Car won't start, there is petrol in fuel tank and engine turns over.
removeAllGoal
removeAllFact
addFact petrol_in_fuel_tank engine_turn_over
fireRule {rule_1 rule_2 rule_3 rule_4 rule_5}

echo
echo >>> FOUR CASE
echo >>> Car won't start, engine gets petrol and engine turns over.
removeAllGoal
removeAllFact
addFact engine_turns_over engine_getting_petrol
fireRule {rule_1 rule_2 rule_3 rule_4 rule_5}

