% More advanced predicates for handling family relationships. % This includes predicates that are used as commands to assert % family relationships that record births and marriages. % This predicate is changes parent, male, and female: birth(Mother, Father, Child, Gender). % This predicate is changes parent: marry(Mother, Father). :-dynamic(parent/2). :-dynamic(male/1). :-dynamic(female/1). :-style_check(-singleton). father(X,Y):-parent(X,Y), male(X). mother(X,Y):-parent(X,Y),female(X). sister(X,Y):-parent(Z,X),parent(Z,Y),female(X),X\=Y. brother(X,Y):-parent(Z,X),parent(Z,Y),male(X),X\=Y. sibling(X,Y):-sister(X,Y). sibling(X,Y):-brother(X,Y). grandparent(X,Y):-parent(X,Z),parent(Z,Y). grandfather(X,Y):-male(X),grandparent(X,Y). grandmother(X,Y):-female(X),grandparent(X,Y). grandchild(X,Y):-grandparent(Y,X). child(X,Y):-parent(Y,X). son(X,Y):-child(X,Y),male(X). daughter(X,Y):-child(X,Y),female(X). uncle(X,Y):-brother(X,P),parent(P,Y). aunt(X,Y):-sister(X,P),parent(P,Y). grandson(X,Y):-son(X,P),child(P,Y). granddaughter(X,Y):-daughter(X,P),child(P). % married(X,Y):-parent(X,Z), parent(Y,Z), X\=Y. % married(X,Y):-married(Y, X), !. wife(X,Y):-married(X,Y),female(X). husband(X,Y):-married(X,Y),male(Y). birth(Mother, Father, Child, son):-asserta(parent(Mother, Child)), asserta(parent(Father, Child)), asserta(male(Child)). birth(Mother, Father, Child, daughter):-asserta(parent(Mother, Child)), asserta(parent(Father, Child)), asserta(female(Child)). birth(Mother, Father, Child):-asserta(parent(Mother, Child)), asserta(parent(Father, Child)). adopt(Person, []). adopt(Person, [Child|Rest]):-asserta(parent(Person, Child)), adopt(Person, Rest). marry(Man, Woman):-asserta(married(Woman, Man)), findchildren(Man, Hiskids), adopt(Woman, Hiskids), findchildren(Woman,Herkids), adopt(Man, Herkids). findchildren(Person, Children):-findall(X,parent(Person,X),Children). go:-write('Input a fact with a period(input ok at end): '), read(Term), ( Term=ok , !; assert(Term), Term=..[Functor|_], listing(Functor), go ).