7
9execute(A,Sr) :- ask_execute(A,Sr).
10exog_occurs(_) :- fail.
11
12fl(N) :- N=1; N=2; N=3; N=4; N=5; N=6. 13
15prim_action(down). 16prim_action(up). 17prim_action(off(N)) :- fl(N). 18prim_action(look). 19
21prim_fluent(floor). 22prim_fluent(lights). 23
25causes_val(up, floor, N, N is floor+1).
26causes_val(down, floor, N, N is floor-1).
27causes_val(off(N), lights, L, repl(lights,L,N,0)). 28
30poss(down, neg(floor=1)).
31poss(up, neg(floor=6)).
32poss(off(N), and(floor=N,lighton(N))).
33poss(look, true).
34
36senses(look, lights). 37
39initially(floor,3).
40
42proc(below_floor(N), floor<N).
43proc(above_floor(N), floor>N).
44proc(next_floor_to_serve(N), lighton(N)).
45proc(lighton(N), nth1(N,lights,1)).
46proc(floor_waiting, member(1,lights)).
47
49repl([_|L],[X|L],1,X).
50repl([Y|L1],[Y|L2],N,X) :- repl(L1,L2,M,X), N is M+1.
51
54
57
59proc(go_floor(N), while(neg(floor=N), if(below_floor(N),up,down))).
60proc(serve_a_floor, pi(n, [?(next_floor_to_serve(n)), go_floor(n), off(n)])).
61proc(control,
62 [ look,
63 while(or(floor_waiting, above_floor(1)),
64 if(floor_waiting, serve_a_floor, [down,look])) ])