% This code is meant to be run from ws.prova.test.ProvaRunner.testConsultSync2()
% The file "kk_rules003_include.prova" consulted below
%    is meant to have a syntax error that will be caught by the above
%    function.
% If we had a local handler for ws.prova.parser.ParsingException, the
%    exception could have been dealt with by the Prova code itself.
% If you correct the error, the code will execute correctly.
%%% A revised version of yale shooter with all combinations
%%%  of free and bound variables possible in the queries

:- eval(consult('prova/prova-examples/kk_rules003_include.prova')).

%:- solve(holds_at(X,T)). % -> see all states at all times

holds_at(F,T) :-
	initially_p(F),
	time(T),
	not(clipped(t0,F,T)).
holds_at(F,T2) :-
	happens(A,T1),
	initiates(A,F,T1),
	less(T1,T2),
	not(clipped(T1,F,T2)).

clipped(T1,F,T2) :-
	happens(A,T),
	less(T1,T),
	less(T,T2),
	terminates(A,F,T).

initiates(load,loaded,_).
initiates(shoot,dead,T) :-
	holds_at(loaded,T).

terminates(shoot,alive,T) :-
	holds_at(loaded,T).
terminates(shoot,loaded,T) :-
   holds_at(loaded,T).

initially_p(alive).

happens(load,t1).
happens(sneeze,t2).
happens(shoot,t3).

less(T1,T2) :-
	fact_less(T1,T2).
less(T1,T2) :-
	fact_less(T1,T),
	less(T,T2).

fact_less(t0,t1).
fact_less(t1,t2).
fact_less(t2,t3).
fact_less(t3,t4).
   
time(t0).
time(t1).
time(t2).
time(t3).
time(t4).
