1
votes

I have the Prolog rule:

superAbility(M1,A,M2) :-
    monsterAbility(M1,M1A),
    ability(M1A,M1T),
    monster(M2,M2T),
    typeEffectiveness(M1T,M2T,A).

Where M1A is Monster1 Ability, M1T is Monster1 Type and so on

I call the rule using: superAbility(squirtle,A,charmander)

and get the results

A = ordinary
A = super
A = super
A = ordinary

How do I alter my rule so that I only return when A = super?

1
Inside the rule you can rename A to RequiredEffectiveness and add the goal RequiredEffectiveness = super before the last line.Isabelle Newbie

1 Answers

0
votes

You have 3 choices. First is to alter your function to get the result as mentioned from Isabelle Newbie:

superAbility(M1,A,M2) :-
    monsterAbility(M1,M1A),
    ability(M1A,M1T),
    monster(M2,M2T),
    A = super,
    typeEffectiveness(M1T,M2T,A).

Instead you can also call the predicate with the desired result:

?- superAbility(M1,super,M2).

Or you can use an additional predicate to tunnel the desired result:

superDuperAbility(M1,A,M2) :- 
    A = super,
    superAbility(M1,A,M2).

Or shorter without the unneccessary middle variable

superDuperAbility(M1,M2) :- superAbility(M1,super,M2).