1:- dynamic(current_state/1).    2:- assert(current_state([])).    3
    4wumpus(3,1).
    5pit(1,3).
    6pit(2,5).
    7pit(3,3).
    8gold(4,4).
    9
   10	
   11
   12
   13perform(turn, []) :-
   14	write('turn'), nl,
   15	current_state([at(X,Y),facing(D)]),
   16	retract(current_state([at(X,Y),facing(D)])),
   17	( D < 4 -> D1 is D+1 ; D1 is 1 ),
   18	assert(current_state([at(X,Y),facing(D1)])).
   19
   20perform(enter, [Breeze,Stench,Glitter]) :-
   21	write('enter'), nl,
   22	current_state(Z),
   23	retract(current_state(Z)),
   24	assert(current_state([at(1,1),facing(1)])),
   25	( gold(1,1) -> Glitter = true ; Glitter = false ),
   26	( (wumpus(1,2) ; wumpus(2,1)) -> Stench = true ;
   27	    Stench = false ),
   28	( (pit(2,1) ; pit(1,2)) -> Breeze = true ;
   29	    Breeze = false ).
   30
   31perform(exit, []) :-
   32	write('exit'), nl,
   33	current_state([at(X,Y),facing(D)]),
   34	retract(current_state([at(X,Y),facing(D)])),
   35	assert(current_state([])).
   36
   37perform(grab, []) :-
   38	write('grab'), nl.
   39
   40perform(shoot, [Scream]) :-
   41	write('shoot'), nl,
   42	current_state([at(X,Y),facing(D)]),
   43	wumpus(WX, WY),
   44	( in_direction(X, Y, D, WX, WY), Scream = true ; Scream = false ).
   45
   46perform(go, [Breeze,Stench,Glitter]) :-
   47	write('go'), nl,
   48	current_state([at(X,Y),facing(D)]),
   49	retract(current_state([at(X,Y),facing(D)])),
   50	( D = 1 -> X1 is X, Y1 is Y+1 ;
   51	  D = 3 -> X1 is X, Y1 is Y-1 ;
   52	  D = 2 -> X1 is X+1, Y1 is Y ;
   53	  D = 4 -> X1 is X-1, Y1 is Y ),
   54	assert(current_state([at(X1,Y1),facing(D)])),
   55	( gold(X1,Y1) -> Glitter = true ; Glitter = false ),
   56	X_east is X1+1, X_west is X1-1, Y_north is Y1+1, Y_south is Y1-1,
   57	( (wumpus(X_east,Y1) ; wumpus(X1,Y_north) ;
   58           wumpus(X_west,Y1) ; wumpus(X1,Y_south)) -> Stench = true ;
   59	    Stench = false ),
   60	( (pit(X_east,Y1) ; pit(X1,Y_north) ;
   61           pit(X_west,Y1) ; pit(X1,Y_south)) -> Breeze = true ;
   62	    Breeze = false )