%%%%%%%%%%%%%%% Solve mystery rules for hercule (5*-9*) % 20.10.1997 12.15 /* Begin_to_solve */ rule(50):- pr_firing(50), goal(begin_to_solve), then, af(walk_to(r1994)), af(look_in(r1994)), af(visit_room(hercule,r1994)), af(sendf(fact(visit_room(hercule,r1994)))), %_ccq: should I tell sherlock this? af(location(hercule,r1994)), af(locate_in_victim_room), af(first_pass). rule(51):- pr_firing(51), goal(begin_to_solve), then, rg(begin_to_solve), ag(list_suspects), ag(prove_motives), ag(prove_how), ag(prove_opportunity), ag(look_rooms), ag(ask_objects), ag(read_objects), ag(look_objects). /* Prove_motives */ rule(52):- pr_firing(52), goal(prove_motives), then, not(fact(prove_affair(love))), af(prove_affair(love)), not(fact(prove_affair(money))), af(prove_affair(money)), not(fact(prove_affair(work))), af(prove_affair(work)). /* Update lists */ %object(asked,X) rule(530):- pr_firing(530), then, fact(object(ask,X)), not(fact(object(asked,X))), af(object(asked,X)), not(fact(page_object(ask))), af(page_object(ask)), not(fact(command_in_the_same_room)), af(command_in_the_same_room), not(fact(new_object(ask))), af(new_object(ask)). %object(looked,X) rule(531):- pr_firing(531), then, fact(object(look,X)), not(fact(object(looked,X))), af(object(looked,X)), fact(location(hercule,R)), af(object(look,X,R)), not(fact(page_object(look))), af(page_object(look)), not(fact(new_object(look))), af(new_object(look)), not(fact(command_in_the_same_room)), af(command_in_the_same_room). %object(readit,X) rule(532):- pr_firing(532), then, fact(object(read,X)), not(fact(object(readit,X))), af(object(readit,X)), fact(location(hercule,R)), af(object(read,X,R)), not(fact(page_object(read))), af(page_object(read)), not(fact(new_object(read))), af(new_object(read)), not(fact(command_in_the_same_room)), af(command_in_the_same_room). /* Some advice to sherlock */ %interesting objects to ask about rule(5330):- pr_firing(5330), fact(page_object(ask)), then, fact(object(ask,X)), fact(location(hercule,R)), not(fact(visit_room(sherlock,R))), not(fact(paged(fact(object(hercule,ask,X))))), not(fact(must_page(fact(object(hercule,ask,X))))), af(sendf(fact(object(hercule,ask,X)))), fail. %if sherlock was in that room, then af(paged(_)) %ATTN: not available for human agent! rule(5331):- pr_firing(5331), fact(page_object(ask)), then, rf(page_object(ask)), fact(object(ask,X)), fact(location(hercule,R)), fact(visit_room(sherlock,R)), af(paged(fact(object(hercule,ask,X)))). %interesting objects to look and read in a specific room rule(5332):- pr_firing(5332), then, fact(page_object(M)), rf(page_object(M)), fact(object(M,X)), fact(location(hercule,R)), not(fact(visit_room(sherlock,R))), not(fact(paged(fact(object(hercule,M,X,R))))), not(fact(must_page(fact(object(hercule,M,X,R))))), af(sendf(fact(object(hercule,M,X,R)))), fail. /* Update visit */ %If there is new objects to ask, then visited all suspects again rule(5341):- pr_firing(5341), fact(new_object(ask)), fact(location(hercule,r1963)), then, rf(new_object(ask)), af(remove_visit_suspects_rooms), not(goal(tour_suspects_for_ask)), ag(tour_suspects_for_ask). rule(5342):- pr_firing(5342), fact(remove_visit_suspects_rooms), then, fact(room(R)), fact(locate(R,S)), fact(suspect(S,_)), fact(object(ask,X)), not(fact(already_object(ask,S,X))), rf(visit_room(hercule,R)). rule(5343):- pr_firing(5343), fact(remove_visit_suspects_rooms), then, rf(remove_visit_suspects_rooms). /* Visit another room */ %If visit_one_room, then not rule(540):- pr_firing(540), fact(visit_one_room), then, rf(visit_one_room). %List of rooms visited by me /* rule(5404):- pr_firing(5404), fact(visit_room(hercule,X)), write('Visited by me, room: '), write(X),nl. */ %List of rooms visited by sherlock /* rule(5405):- pr_firing(5405), fact(visit_room(sherlock,X)), write('Visited by sherlock, room: '), write(X),nl. */ %Remove where am I fact rule(5408):- pr_firing(5408), not(fact(locate_in_victim_room)), not(fact(command_in_the_same_room)), then, fact(room(R)), fact(visit_room(hercule,R)), fact(location(hercule,R)), rf(location(hercule,R)). %Move in another room (first tour) rule(541):- pr_firing(541), goal(look_rooms), not(fact(locate_in_victim_room)), not(fact(command_in_the_same_room)), then, fact(room(R)), not(fact(visit_one_room)), not(fact(visit_room(hercule,R))), not(fact(visit_room(sherlock,R))), af(visit_one_room), af(visit_room(hercule,R)), af(location(hercule,R)), af(walk_to(R)), af(look_in(R)), %advice: page sherlock af(sendf(fact(visit_room(hercule,R)))), fail. %Move in another room (new tour, only for asking) rule(542):- pr_firing(542), goal(tour_suspects_for_ask), fact(end_first_tour), not(fact(command_in_the_same_room)), then, fact(room(R)), not(fact(visit_one_room)), not(fact(visit_room(hercule,R))), %if not asking something fact(locate(R,S)), not(S=nothing), fact(object(ask,X)), not(fact(already_object(ask,S,X))), then, not(fact(new_room)), af(new_room), not(fact(walk_to(R))), af(walk_to(R)), %advice: page sherlock (maybe another fact: I'll see) af(sendf(fact(visit_room(hercule,R)))), not(fact(visit_one_room)), af(visit_one_room), not(fact(visit_room(hercule,R))), af(visit_room(hercule,R)), not(fact(location(hercule,R))), af(location(hercule,R)), fail. %If not visiting another room, hercule it's moved in upper corridor rule(543):- pr_firing(543), not(fact(visit_one_room)), not(fact(command_in_the_same_room)), not(fact(locate_in_victim_room)), not(fact(location(hercule,r1963))), then, af(walk_to(r1963)), af(location(hercule,r1963)), af(moving_upper), goal(look_rooms), rg(look_rooms). rule(5430):- pr_firing(5430), fact(location(hercule,r1963)), not(fact(end_first_tour)), then, af(end_first_tour). rule(5431):- pr_firing(5431), fact(new_room), fact(location(hercule,r1963)), then, rf(location(hercule,r1963)). %in case of find 2 rooms (upper corridor and other) rule(5432):- pr_firing(5432), fact(new_room), fact(walk_to(r1963)), then, rf(walk_to(r1963)). %walk_to command rule(5441):- pr_firing(5441), then, fact(walk_to(R)), name(R,RF), remove_first(1,RF,X), append("walk to #",X,Q), name(QQ,Q), af(advice(QQ)), rf(walk_to(R)). %look_in command rule(5442):- pr_firing(5442), then, fact(look_in(R)), name(R,RF), remove_first(1,RF,X), append("look #",X,C), name(CC,C), af(command(CC)), afw(register_command(CC,look,R)), rf(look_in(R)). /* Look objects */ rule(5511):- pr_firing(5511), fact(new_object(look)), then, fact(object(look,X)), not(fact(already_object(look,X))), af(sendc(look,X)), afw(already_object(look,X)), rfw(object(look,X)), fail. rule(5512):- pr_firing(5512), fact(new_object(look)), then, rf(new_object(look)). /* Read objects */ rule(5521):- pr_firing(5521), fact(new_object(read)), then, fact(object(read,X)), not(fact(already_object(read,X))), af(sendc(read,X)), af(already_object(read,X)), rf(object(read,X)). rule(5522):- pr_firing(5522), fact(new_object(read)), then, rf(new_object(read)). /* Ask suspects about objects */ rule(5531):- pr_firing(5531), not(fact(new_object(ask))), not(goal(tour_suspects_for_ask)), then, af(do_not(ask)). rule(5532):- pr_firing(5532), not(fact(do_not(ask))), then, %room fact(location(hercule,R)), %suspect(s) fact(locate(R,S)), not(S=nothing), %not victim not(fact(victim(S))), %about what fact(object(ask,X)), not(fact(already_object(ask,S,X))), af(sendc(ask,S,about,X)), afw(already_object(ask,S,X)), fail. /* Ask sherlock what did he find out about look or read objects */ rule(5534):- pr_firing(5534), fact(communication_established), then, fact(must_visit(R)), fact(end_first_tour), fact(object(M,X,R)), not(fact(already_object(M,X))), not(fact(paged(fact(what_about(hercule,M,X,R))))), not(fact(must_page(fact(what_about(hercule,M,X,R))))), not(fact(one_question_wa)), af(one_question_wa), af(sendf(fact(what_about(hercule,M,X,R)))). /* Ask sherlock if he ask suspect(s) about something */ rule(5535):- pr_firing(5535), fact(communication_established), fact(end_first_tour), then, fact(room(R)), fact(locate(R,S)), not(S=nothing), fact(object(ask,X)), not(fact(paged(fact(did_you(hercule,ask,X))))), not(fact(must_page(fact(did_you(hercule,ask,X))))), not(fact(one_question_dy)), af(one_question_dy), af(sendf(fact(did_you(hercule,ask,X)))). /* Give permision to move from victim_room */ rule(5541):- pr_firing(5541), fact(second_pass), then, rf(second_pass), rf(locate_in_victim_room). rule(5542):- pr_firing(5542), fact(first_pass), then, rf(first_pass), af(second_pass). /* Inference part !!! */ /* Prove_affair(T), where type T could be 'money', 'love', 'work' */ %inference rule(5551):- pr_firing(5551), goal(prove_motives), then, fact(prove_affair(T)), fact(victim(V)), fact(suspect(X,_)), fact(knows(X,V,relation(V,Z,T),1)), not(fact(type_affair(V,Z,T))), af(type_affair(V,Z,T)), not(fact(relation(V,Z,T))), af(relation(V,Z,T)), %ATTN: forced!!! T = work, not(fact(has(motives,X,T))), af(has(motives,X,T)). rule(5552):- pr_firing(5552), goal(prove_motives), then, fact(prove_affair(T)), fact(victim(V)), fact(suspect(X,_)), fact(knows(X,V,relation(V,X,T),1)), not(fact(type_affair(V,X,T))), af(type_affair(V,X,T)), not(fact(relation(V,Z,T))), af(relation(V,Z,T)), %ATTN: forced!!! T = work, not(fact(has(motives,X,T))), af(has(motives,X,T)). rule(5561):- pr_firing(5561), fact(prove_affair(money)), then, fact(suspect(X,_)), fact(knows(X,Ob,fake(Ob),1)), not(fact(fake(Ob))), af(fake(Ob)). rule(55621):- pr_firing(55621), fact(prove_affair(money)), then, fact(victim(V)), fact(suspect(X,_)), fact(type_affair(V,X,money)), fact(knows(X,Ob,original(Ob),1)), not(fact(original(Ob))), af(original(Ob)). rule(55622):- pr_firing(55622), fact(prove_affair(money)), then, fact(victim(V)), fact(suspect(X,_)), fact(type_affair(V,X,money)), fact(knows(X,Ob,original(Ob),1)), fact(fake(Ob)), fact(insured(Ob,X,NM)), NM > 1000, not(fact(has(motives,X,money))), af(has(motives,X,money)), not(fact(type_affair(V,X,money))), af(type_affair(V,X,money)). rule(5571):- pr_firing(5571), fact(prove_affair(love)), then, fact(victim(V)), fact(suspect(X,_)), fact(knows(X,V,upset(U,relation(V,Y,love)),1)), not(fact(relation(U,Y,love))), af(relation(U,Y,love)). rule(5572):- pr_firing(5572), fact(prove_affair(love)), then, fact(victim(V)), fact(relation(V,X,love)), fact(relation(U,X,love)), U \= V, not(fact(jealous(U,V))), af(jealous(U,V)), not(fact(has(motives,U,love))), af(has(motives,U,love)). rule(5573):- pr_firing(5573), fact(prove_affair(love)), then, fact(victim(V)), fact(knows(X,V,wife(X,V),1)), fact(relation(V,Y,love)), not(fact(jealous(X,Y))), af(jealous(X,Y)), not(fact(has(motives,X,love))), af(has(motives,X,love)). %communication rule(558):- pr_firing(558), goal(prove_motives), then, fact(prove_affair(T)), fact(victim(V)), fact(type_affair(V,X,T)), not(fact(paged(fact(kill_reason(hercule,T,0.5))))), not(fact(sendf(fact(kill_reason(hercule,T,0.5))))), not(fact(must_page(fact(kill_reason(hercule,T,0.5))))), af(sendf(fact(kill_reason(hercule,T,0.5)))). /* Prove_opportunity */ %here must be sure that the victim was the person who called (that can be prove, because at 18 o'clock the victim made the same number) rule(5611):- pr_firing(5611), goal(prove_opportunity), not(fact(victim_life_last)), then, fact(victim(V)), fact(locate(RV,V)), fact(victim_found(TimeF)), fact(victim_life(TimeL)), fact(phone_call(RV,TimeCall,Period)), TimeCall > TimeL, convert(Period,D), TimeLNew is TimeCall + D, rf(victim_life(TimeL)), af(victim_life(TimeLNew)), af(victim_life_last), af(get_not_alibi). rule(5612):- pr_firing(5612), fact(get_not_alibi), fact(victim_life_last), then, fact(victim_life(TimeL)), fact(was_at(X,_,T1,T2,with([]),_)), T1 < TimeL, TimeL < T2, not(fact(has(opportunity,X,T1))), af(has(opportunity,X,T1)). /* Prove_how */ rule(571):- pr_firing(571), goal(prove_how), then, fact(suspect(X,_)), fact(knows(X,gun,GunOwner,_)), fact(knows(GunOwner,gun,GunOwner,D)), D = 1, not(fact(gun_owner(GunOwner))), af(gun_owner(GunOwner)), not(fact(find_gun_location)), af(find_gun_location). rule(572):- pr_firing(572), fact(find_gun_location), fact(gun_owner(GunOwner)), then, fact(locate(R,GunOwner)), not(fact(gun_location(R))), rf(find_gun_location), af(gun_location(R)), af(find_gun_out_of_room). rule(573):- pr_firing(573), fact(find_gun_out_of_room), then, fact(gun_location(RG)), fact(gun_owner(GunOwner)), fact(was_at(GunOwner,R,T1,T2,_,_)), R \= RG, not(fact(out_of_room(GunOwner,T1,T2))), rf(find_gun_out_of_room), af(out_of_room(GunOwner,T1,T2)), af(find_has_weapon). rule(574):- pr_firing(574), fact(find_has_weapon), then, fact(out_of_room(GunOwner,T1,T2)), fact(was_at(X,_,Ts1,Ts2,with([]),_)), (Ts2>T1, Ts2T1, Ts1T2;Ts2=T2)), not(fact(has(weapon,X,access))), af(has(weapon,X,access)). rule(575):- pr_firing(575), fact(find_has_weapon), then, fact(out_of_room(GunOwner,T1,T2)), fact(was_at(X,R,_,_,_,left(X,R,Tout))), Tout < T2, Tout > T1, not(fact(has(weapon,X,access))), af(has(weapon,X,access)). /* Communication after inference part */ rule(80):- pr_firing(80), then, fact(has(H,X,T)), not(fact(paged(fact(find_has(hercule,X,H,T,1))))), not(fact(sendf(fact(find_has(hercule,X,H,T,1))))), not(fact(must_page(fact(find_has(hercule,X,H,T,1))))), af(sendf(fact(find_has(hercule,X,H,T,1)))). /* UPGRADE SUSPECTS' DEGREES OF GUILTY ******************************/ rule(90):- pr_firing(90), goal(list_suspects), then, fact(suspect(X,_)), fact(has(H,X,T)), not(fact(added(X,H))), fact(suspect(X,N)), N1 is N + 1, rf(suspect(X,N)), af(suspect(X,N1)), af(added(X,H)). rule(91):- pr_firing(91), goal(list_suspects), then, fact(suspect(X,N)), write('suspect '), write(X),write(' = '),write(N), forall( fact(added(X,H)), ( fact(has(H,X,T)), write(' ** had '),write(H),write(' '),write(T) ) ), nl, fail. rule(92):- pr_firing(92), fact(suspect(X,4)), then, ag(mystery_solved), af(criminal(X)). /* Page sherlock what's new */ rule(9311):- pr_firing(9311), fact(communication_established), then, afw(what_send('page sherlock ')), afw(number(what_send,0)), fact(sendf(F)), fact(number(what_send,N)), %ATTN: here N can be less or equal than 20, but for not congestion (N<5), N1 is N + 1, rfw(number(what_send,N)), afw(number(what_send,N1)), rfw(sendf(F)), fact(what_send(B)), name(B,BB), append(BB,"~",P1), appenda(P1,F,PP), name(P,PP), afw(paged(F)), rfw(what_send(B)), afw(what_send(P)). rule(9312):- pr_firing(9312), fact(what_send('page sherlock ')), then, rfw(what_send('page sherlock ')). rule(9313):- pr_firing(9313), fact(number(what_send,N)), then, rfw(number(what_send,N)). rule(932):- pr_firing(932), not(fact(communication_established)), then, fact(sendf(F)), rfw(sendf(F)), %only things who don't happend in real time (like now I'm locate in R)! af(must_page(F)), fail. rule(933):- pr_firing(933), then, fact(what_send(P)), af(advice(P)), rfw(what_send(P)). /* Page monitor what's new */ %but now it's sherlock, because monitor doesn't work (talk David) rule(9341):- pr_firing(9341), then, afw(what_sendm('page sherlock ')), afw(number(what_sendm,0)), fact(sendm(F)), fact(number(what_sendm,N)), (N<5), N1 is N + 1, rfw(number(what_sendm,N)), afw(number(what_sendm,N1)), rfw(sendm(F)), fact(what_sendm(B)), name(B,BB), append(BB,"~",P1), appenda(P1,F,PP), name(P,PP), afw(paged(F)), rfw(what_sendm(B)), afw(what_sendm(P)). rule(9342):- pr_firing(9342), fact(what_sendm('page sherlock ')), then, rfw(what_sendm('page sherlock ')). rule(9343):- pr_firing(9343), fact(number(what_sendm,N)), then, rfw(number(what_sendm,N)). rule(935):- pr_firing(935), then, fact(what_sendm(P)), af(advice(P)), rfw(what_sendm(P)). /* Commands to MOO */ rule(9371):- pr_firing(9371), then, fact(sendc(C1, C2)), name(C1,CC1), name(C2,CCI), filterunderscore1(CCI,CC2), append(CC1," ",X1), append(X1,CC2,CC), name(C,CC), af(command(C)), fact(location(hercule,R)), afw(register_command(C,C1,C2,R)), rfw(sendc(C1, C2)), fail. rule(9372):- pr_firing(9372), then, fact(sendc(C1,C2,C3,C4)), name(C1,CC1), name(C2,CC2), name(C3,CC3), name(C4,CCI), filterunderscore1(CCI,CC4), append(CC1," ",X1), append(X1,CC2,X2), append(X2," ",X3), append(X3,CC3,X4), append(X4," ",X5), append(X5,CC4,CC), name(C,CC), af(command(C)), afw(register_command(C,C1,C2,C3,C4)), rfw(sendc(C1,C2,C3,C4)), fail. /* Remove intermediares */ rule(9391):- pr_firing(9391), fact(command_in_the_same_room), then, rf(command_in_the_same_room). rule(9392):- pr_firing(9392), fact(new_room), then, rf(new_room). rule(9393):- pr_firing(9393), fact(moving_upper), then, rf(moving_upper). rule(9394):- pr_firing(9394), then, fact(visit_room(hercule,R)), fact(must_visit(R)), rf(must_visit(R)). rule(9395):- pr_firing(9395), fact(one_question_wa), then, rf(one_question_wa). rule(9396):- pr_firing(9396), fact(one_question_dy), then, rf(one_question_dy).