Jump to content
  • Advertisement
Sign in to follow this  

Prolog problem

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

parent(b, a).
parent(c, a).
parent(d, a).
parent(e, b).
parent(f, b).
parent(h, d).
parent(i, d).
parent(j, d).
parent(k, d).

child(X, Y) :-
    parent(Y, X).

grandparent(X, Y) :-
    parent(X, Z),
    parent(Z, Y).

grandchild(X, Y) :- 
    child(X, Z),
    child(Z, Y).

sibling(X, Y) :-
    parent(X, Z),
    parent(Y, Z),

auncle(X, Y) :-
    parent(X, Z),
    sibling(Z, Y).

cousin(X, Y) :-
    auncle(X, Z),
    child(Y, Z).

happy(X) :-

The procedure "happy" works if you have a specific unit in mind, i.e. happy(a) returns no and happy(c) returns yes (happy defined as not having kids). However, I can't seem to figure out how to list ALL happy units, ala happy(X).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!