room(ballroom).
room(kitchen).

suspect(maria).
suspect(john).
suspect(fred).
suspect(peter).
suspect(timmy).
suspect(paul).
in_room(maria, ballroom).
in_room(john, ballroom).
in_room(fred, kitchen).
in_room(paul, kitchen).
in_room(peter, kitchen).
relationship(fred, maria).
relationship(timmy, maria).
relationship(paul, john).

related(X,Y) :- relationship(X,Y);relationship(Y,X).
related(X,Y) :- not(X=Y), related(X,Z), relationship(Z,Y).
covers_sibling(X, Y) :- related(X,Y), Z is random(2),!,Z =:= 1.
alibi(X, Y) :- share_room(X,Y); related(X,Y).
share_room(X,Y) :- suspect(X), suspect(Y), room(Z), not(X = Y), in_room(X,Z), in_room(Y,Z).

% list_rooms :- room(X), writeln(X), fail.
suspects :- suspect(X), writeln(X), fail.

accuse(_) :-  nb_getval(made_accusation, X), X = true, writeln('You made your choice, no backsies.').
accuse(timmy) :- writeln('Good job, you found your guy. No he will rot in jail for the rest of the eternity.'), nb_setval(made_accusation, true).
accuse(_) :- writeln('You are a shame of a detective, unable to solve even the trivial cases. Maybe you should become a gardnerer or something.'), nb_setval(made_accusation, true).

get_murderer(X) :- suspect(X), \+innocent(X).
innocent(X) :- suspect(Y), share_room(Y,X).

main :- writeln('Detective, old Mr. Frederik has been killed! It is up to you to find who did it. You have gathered all the people who were in the house at the time of the murder and you have to find the muredere amongst them.'),
	writeln('  - "suspects." will give you the names of the suspects'),
	writeln('  - "alibi(name1, name2)." is true if "name1" gives alibi to "name2". Unfortunatelly relatives are not required by law to tell truth about each other, so they may make the alibi up.'),
	writeln('  - "related(name1,name2)." is true if "name1" and "name2" are relatives.'),
        writeln('  - "accusse(name)." will accuse "name" of the murder. You have only one try!'),
	nb_setval(made_accusation, false).

