1/* Dragon ball z : An adventerous trip
    2   Search for fire to dragon to enter earth.  */
    3
    4:- dynamic at/2, i_am_at/1, my_fuel/1.   /* Needed by SWI-Prolog. */
    5:- retractall(at(_, _)), retractall(i_am_at(_)), retractall(fuel(_)).    6
    7/* This defines my current location. */
    8
    9i_am_at(mercury).
   10
   11/* Intial fuel */
   12fuel(200).
   13
   14/* Checks the fuel is greater than 0. everytime */
   15checkfuel(Fuel) :-  Fuel > 0.
   16
   17
   18/* These facts describe how planets and stars are connected. */
   19
   20/* path from mercury to polestar and back. */
   21path(mercury, e, polestar).
   22path(polestar, w, mercury).
   23
   24/* path from mercury to venus and back. */
   25path(mercury, w, venus).
   26path(venus, e, mercury).
   27
   28
   29/* path from mercury to sun and back. */
   30path(mercury, s, sun) :- at(lifejacket, in_hand).
   31path(mercury, s, sun) :-
   32        write('Going to sun without life jacket?  Are you crazy?'), nl,
   33        !, fail.
   34path(sun, n, mercury).
   35
   36
   37/* path from mercury to earth and back. */
   38path(mercury, n, earth) :- at(fire, in_hand).
   39path(mercury, n, earth) :-      write('The dragon will not allow you without fire in hand.'), nl,
   40        !, fail.
   41path(earth, s, mercury).
   42
   43
   44/* path from milky way back to venus and back. */
   45/* need to pick up bullets from milkyway. */
   46path(venus, s, milkyway) :- at(bullets, in_hand).
   47path(venus, s, milkyway) :-     
   48	write('The gun is not filled with enough bullets.'), nl,
   49        !, fail.
   50path(milkyway, n, venus).
   51
   52
   53/* path from sun to mercury and back*/
   54/*need lifejacket to enter sun*/
   55path(mercury, s, sun) :- at(lifejacket, in_hand).
   56path(mercury, s, sun) :-
   57        write('Going to sun without life jacket?  Are you crazy?'), nl,
   58        !, fail.
   59
   60
   61/*path from venus to box and back*/
   62/*need to give starcount to open the box*/
   63path(venus, w, box) :- at(starcount, in_hand).
   64path(venus, w, box) :-
   65        write('You do not have the star count yet.'), nl,
   66        fail.
   67path(box, e, venus).
   68
   69/* These facts tell where the various objects in the game
   70   are located. */
   71
   72at(lifejacket, box).
   73at(fire, sun).
   74at(bullets, polestar).
   75at(starcount, milkyway).
   76
   77
   78
   79/* These rules describe how to pick up an object. */
   80
   81take(X) :-
   82        at(X, in_hand),
   83        write('You''re already holding it!'),
   84        nl, !.
   85
   86take(X) :-
   87        i_am_at(Place),
   88        at(X, Place),
   89        retract(at(X, Place)),
   90        assert(at(X, in_hand)),
   91        write('OK.'),
   92        nl, !.
   93
   94take(_) :-
   95        write('I don''t see it here.'),
   96        nl.
   97
   98
   99/* These rules describe how to put down an object. */
  100
  101drop(X) :-
  102        at(X, in_hand),
  103        i_am_at(Place),
  104        retract(at(X, in_hand)),
  105        assert(at(X, Place)),
  106        write('OK.'),
  107        nl, !.
  108
  109drop(_) :-
  110        write('You aren''t holding it!'),
  111        nl.
  112
  113
  114/* These rules define the six direction letters as calls to go/1. */
  115
  116n :- go(n).
  117
  118s :- go(s).
  119
  120e :- go(e).
  121
  122w :- go(w).
  123
  124
  125
  126/* This rule tells how to move in a given direction. */
  127
  128go(Direction) :-
  129        i_am_at(Here),
  130        path(Here, Direction, There),
  131        retract(i_am_at(Here)),
  132        assert(i_am_at(There)),
  133	    fuel(Fuel),
  134        checkfuel(Fuel),!,
  135    	NewFuel is Fuel - 10,nl,
  136    	write('Fuel left is '),
  137    	write(NewFuel),nl,
  138	retract(fuel(Fuel)),
  139	assert(fuel(NewFuel)),
  140        look, !.
  141
  142go(_) :-
  143        write('You can''t go that way.').
  144
  145
  146/* This rule tells how to look about you. */
  147
  148look :-
  149        i_am_at(Place),
  150        describe(Place),
  151        nl,
  152        notice_objects_at(Place),
  153        nl.
  154
  155
  156/* These rules set up a loop to mention all the objects
  157   in your vicinity. */
  158
  159notice_objects_at(Place) :-
  160        at(X, Place),
  161        write('There is a '), write(X), write(' here.'), nl,
  162        fail.
  163
  164notice_objects_at(_).
  165
  166
  167
  168finish :-
  169        nl,
  170        write('The game is over. Please enter the   halt.   command.'),
  171        nl, !.
  172
  173
  174i :-
  175	write('We found these items in your inventory: '), nl,
  176	notice_objects_at(in_hand),nl,
  177        nl.
  178
  179
  180/* This rule just writes out game instructions. */
  181
  182instructions :-
  183        nl,
  184        write('Enter commands using standard Prolog syntax.'), nl,
  185        write('Available commands are:'), nl,
  186        write('start.                   -- to start the game.'), nl,
  187        write('n.  s.  e.  w.   -- to go in that direction.'), nl,
  188        write('take(Object).            -- to pick up an object.'), nl,
  189        write('drop(Object).            -- to put down an object.'), nl,
  190        write('look.                    -- to look around you again.'), nl,
  191        write('instructions.            -- to see this message again.'), nl,
  192        write('halt.                    -- to end the game and quit.'), nl,
  193        nl.
  194
  195/* This rule prints out instructions and tells where you are. */
  196
  197start :-
  198        instructions,
  199        look.
  200
  201
  202/* These rules describe the various rooms.  Depending on
  203   circumstances, a room may have more than one description. */
  204
  205describe(_) :-
  206        fuel(Fuel),
  207	    \+ checkfuel(Fuel)
  208		,!,
  209        write('Sorry ! Fuel is up'), nl,
  210        write('and you lost the game.'), nl,
  211        finish, !.
  212
  213describe(earth) :-
  214        at(fire, in_hand),
  215        write('Congratulations!!  You have entered earth'), nl,
  216        write('and won the game.'), nl,
  217        finish, !.
  218
  219describe(mercury) :-
  220        write('You are at mercury and have a spaceship which will take you along your journey.'),nl,
  221		write('Be careful, you cannot travel once the fuel in the spaceship is over !!! '),nl,
  222		write('To the north is earth in which you have to enter and be cautious, '), nl,
  223		write('the dragon wont let you in without the fire'),nl,
  224        write('To the south is sun from where you have to pick up fire and cannot '), nl,
  225        write('enter without a life jacket. To the east is pole star which has'), nl,
  226        write('bullets to fight the shooting stars on the way to milky way from venus'), nl,
  227        write('which is south of venus. Go to the west of venus and there is locked box'), nl,
  228        write('Star count of the stars at the milky way is the code key to open the box.'), nl.
  229		
  230describe(venus) :-
  231        write('You have to pick up lifejacket in the box which is towards west from here.'), nl,
  232        write('The key of the box is count of stars at the milky way.'), nl,
  233        write('You need enough bullets in the gun to fight on the way to milky way'), nl,
  234	    write('which is to the south.'), nl.
  235
  236describe(milkyway) :-
  237        write('Take the count of stars from milkyway'), nl,
  238        write('and then head back to venus!'), nl.
  239
  240describe(sun) :-
  241        write('Procure fire from the sun, and now head to the mercury'), nl,
  242        write('and earth from there, offer fire to the dragon.'), nl.
  243
  244describe(polestar) :-
  245        write('You reached the polestar. Load your gun with bullets'), nl,
  246	    write('to fight shooting stars on the milky way, take bullets here and'), nl,
  247	    write('rush to west.'), nl.
  248
  249describe(box) :-
  250        write('Take life jacket from here'), nl,
  251	    write('and rush to the sun to take fire.'), nl