on(T,do(turnon(T),S)) <- poss(turnon(T),S).
on(T,do(A,S)) <- poss(A,S) & on(T,S) & A \= turnoff(T).

unplugged(B,init).
unplugged(B,do(unplug(B),S)) <- poss(unplug(B),S).
unplugged(B,do(A,S)) <-  poss(A,S) & unplugged(B,S) & A \= plug(B).

plugged(B,do(plug(B),S)) <- poss(plug(B),S).
plugged(B,do(A,S)) <- poss(A,S) & plugged(B,S) &  A \= unplug(B).

poss(wait,S).
poss(turnon(T),S) <- off(T,S).
poss(turnoff(T),S) <- on(T,S).
poss(unplug(B),S) <- plugged(B,S).
poss(plug(B),S) <- unplugged(B,S).

pressurised(p1,init).
pressurised(p1,do(A,S)) <- pressurised(p1,S).
pressurised(p2,S) <- on(t1,S) & pressurised(p1,S).
pressurised(p3,S) <-  on(t1,S) & pressurised(p1,S).
flow(shower,S) <- on(t2,S) & pressurised(p2,S).
wet(bath,S) <- flow(shower,S).
flow(sink,S) <- on(t3,S) & pressurised(p3,S).
wet(sink,S) <- flow(sink,S).
flow(d2,S) <- wet(bath,S) & unplugged(bath,S).
flow(d1,S) <- flow(d2,S).
flow(d3,S) <- wet(sink,S) & unplugged(sink,S).
flow(d1,S) <- flow(d3,S).

off(t3,init).
off(t2,init).
off(t1,init).
off(T,do(turnoff(T),S)) <-
   poss(turnoff(T),S).
off(T,do(A,S)) <-
   poss(A,S) &
   off(T,S) &
   A \= turnon(T).

noflow(sink,S) <-
    off(t3,S).
noflow(sink,S) <- 
   unpressurised(p3,S).
unpressurised(p3,S) <- 
   off(t1,S).
unpressurised(p3,S) <- 
   unpressurised(p1,S).
noflow(shower,S) <-
    off(t2,S).
noflow(shower,S) <-
   unpressurised(p2,S).
unpressurised(p2,S) <- 
   off(t1,S).
unpressurised(p2,S) <- 
   unpressurised(p1,S).

empty(bath,S) <- 
   unplugged(bath,S).
empty(bath,do(A,S)) <- 
   poss(A,S) &
   empty(sink,S) & 
   noflow(shower,do(A,S)).

halffull(bath,do(A,S)) <-
   poss(A,S) &
   halffull(bath,S) &
   plugged(bath,do(A,S)) &
   noflow(shower,do(A,S)).
halffull(bath,do(A,S)) <-
   poss(A,S) &
   plugged(bath,do(A,S)) &
   empty(bath,S) &
   flow(shower,do(A,S)).

full(bath,do(A,S)) <-
   poss(A,S) &
   plugged(bath,do(A,S)) &
   full(bath,S).
full(bath,do(A,S)) <-
   poss(A,S) &
   plugged(bath,do(A,S)) &
   halffull(bath,S) &
   flow(shower,do(A,S)).

overflow(bath,do(A,S)) <-
   poss(A,S) &
   flow(shower,do(A,S)) &
   full(bath,S).

empty(sink,S) <- 
   unplugged(sink,S).
empty(sink,do(A,S)) <- 
   poss(A,S) &
   empty(sink,S) & 
   noflow(sink,do(A,S)).

full(sink,do(A,S)) <-
   poss(A,S) &
   plugged(sink,do(A,S)) &
   empty(sink,S) &
   flow(sink,do(A,S)).
full(sink,do(A,S)) <-
   poss(A,S) &
   plugged(sink,do(A,S)) &
   full(sink,S).

overflow(sink,do(A,S)) <-
   poss(A,S) &
   flow(sink,do(A,S)) &
   full(sink,S).

wet(floor,S) <- 
   overflow(bath,S).
wet(floor,S) <-
   overflow(sink,S).
wet(floor,do(A,S)) <-
   wet(floor,S) &
   poss(A,S).

%% load 'c:/david/teach/cs322/1999/Module09/plumbing_sitc.pl'.
%% ask wet(floor,S).
