% state(me,ce,mw,cw) %safe(Me,Ce,MW,CW) :- Me >= Ce, MW >= CW. unsafe(Me,Ce,MW,CW) :- Me > 0, Ce > Me. unsafe(Me,Ce,MW,CW) :- MW > 0, CW > MW. % move 2 missionaries from east to west move(state(Me,Ce, Mw, Cw), state(ME,CE,MW,CW)) :- Me > 1, ME is Me-2, MW is Mw+2, CW = Cw, CE = Ce, not(unsafe(ME,CE,MW,CW)). % move 2 cannibals from east to west move(state(Me,Ce, Mw, Cw), state(ME,CE,MW,CW)) :- Ce > 1, ME is Me, MW is Mw, CW is Cw+2, CE is Ce-2, not(unsafe(ME,CE,MW,CW)).