1/* ASSI2 -- a sample adventure game, by Navya Vuppala.
    2   Consult this file and issue the command:   start.  */
    3
    4:- dynamic at/2, i_am_at/1, alive/1.   /* Needed by SWI-Prolog. */
    5:- retractall(at(_, _)), retractall(i_am_at(_)), retractall(alive(_)).    6
    7/* This defines my current location. */
    8i_am_at(labyrinth).
    9
   10/* These facts describe how the rooms are connected. */
   11
   12path(labyrinth, u, dragonworld).
   13path(labyrinth, d, lavamountains).
   14path(labyrinth, e, kingslanding).
   15path(kingslanding, e, elisisland):- at(parachute,in_hand).
   16path(kingslanding, e, elisisland):- write('You Want to fly in a jet plane without a parachute? Are you crazy! Go get parachute first.	'),nl,!,fail.
   17path(labyrinth, w, blackcastle).
   18path(blackcastle,w,cornucopia) :- at(teslacar,in_hand).
   19path(labyrinth, s, eerie).
   20path(eerie, s, wheeloffortune).
   21path(labyrinth, n, thecapitol) :-at(teslacar,in_hand),at(electricitycapsule,in_hand),at(timecapsule,in_hand),at(key,in_hand).
   22path(labyrinth, n, thecapitol) :- write('The Capitol is very far, you cant walk there. First go get a vehicle and a key to locked door.!'),nl,!,fail.
   23path(thecapitol, n,presidentsarena).
   24path(presidentsarena,l1,lockeddoor1).
   25path(presidentsarena,l2,lockeddoor2).
   26
   27path(dragonworld, d, labyrinth).
   28path(lavamountains,u,labyrinth).
   29path(kingslanding, w,labyrinth ).
   30path(elisisland,w,labyrinth).
   31path(blackcastle, e, labyrinth).
   32path(cornucopia,e,labyrinth).
   33path(eerie, n, labyrinth).
   34path(wheeloffortune, n, labyrinth).
   35path(thecapitol,s,labyrinth).
   36path(lockeddoor1,q,labyrinth).
   37
   38/* These facts tell where the various objects in the game
   39   are located. */
   40
   41at(magiclamp, cornucopia).
   42at(key,wheeloffortune).
   43at(parachute, labyrinth).
   44at(teslacar, elisisland).
   45at(timecapsule,labyrinth).
   46
   47
   48/* These rules describe how to pick up an object. */
   49
   50take(X) :-
   51        at(X, in_hand),
   52        write('You''re already holding it!'),
   53        nl, !.
   54
   55take(timecapsule):-
   56	i_am_at(labyrinth),
   57	\+ at(timecapsule, in_hand),
   58        retract(at(timecapsule, labyrinth)),
   59        assert(at(timecapsule, in_hand)),
   60	assert(at(timecapsule, labyrinth)),
   61        write('OK.'),
   62        nl, !.
   63
   64take(magiclamp):-
   65	i_am_at(cornucopia),
   66	\+ at(electricitycapsule,cornucopia),
   67	assert(at(electricitycapsule,cornucopia)),
   68	retract(at(magiclamp,cornucopia)),
   69	write('Wow look, the ginie has gifted you with unlimited electricity capsule for your car.!'),nl,
   70	write('Now your car is complete.'),nl,
   71	write('Oops, the magic lamp has disappeared now.'),nl,
   72	write('After you take the capsule, go w. to go back to labyrinth'),nl,nl,
   73	write('There is electricitycapsule here'),nl,!.
   74
   75take(X) :-
   76        i_am_at(Place),
   77        at(X, Place),
   78        retract(at(X, Place)),
   79        assert(at(X, in_hand)),
   80        write('OK.'),
   81        nl, !.
   82
   83take(_) :-
   84        write('I don''t see it here.'),
   85        nl.
   86
   87
   88/* These rules describe how to put down an object. */
   89
   90drop(timecapsule):-
   91	at(timecapsule, in_hand),
   92	write('Dropping the time capsule will end your game, I know you certainly dont wanna do that.'),nl,
   93	write('You cannot drop the time capsule'),nl,
   94	write('Enter halt. to end the game'),nl,!.
   95	
   96drop(X) :-
   97        at(X, in_hand),
   98        i_am_at(Place),
   99        retract(at(X, in_hand)),
  100        assert(at(X, Place)),
  101        write('OK.'),
  102        nl, !.
  103
  104drop(_) :-
  105        write('You aren''t holding it!'),
  106        nl.
  107
  108
  109/* These rules define the six direction letters as calls to go/1. */
  110
  111n :- go(n).
  112
  113s :- go(s).
  114
  115e :- go(e).
  116
  117w :- go(w).
  118
  119u :- go(u).
  120
  121d :- go(d).
  122
  123l1:-go(l1).
  124
  125l2:-go(l2).
  126
  127q :-go(q).
  128
  129
  130/* This rule tells how to move in a given direction. */
  131
  132go(l1):-
  133	i_am_at(presidentsarena),
  134	path(presidentsarena,l1,lockeddoor1),
  135	retract(i_am_at(presidentsarena)),
  136	assert(i_am_at(lockeddoor1)),
  137	look,
  138	retract(at(timecapsule,in_hand)),!.
  139	
  140go(l2):-
  141	i_am_at(presidentsarena),
  142	path(presidentsarena,l2,lockeddoor2),
  143	retract(i_am_at(presidentsarena)),
  144	assert(i_am_at(lockeddoor2)),
  145	look,!.
  146
  147go(q):-
  148        i_am_at(lockeddoor1),
  149        path(lockeddoor1, q, labyrinth),
  150        retract(i_am_at(lockeddoor1)),
  151        assert(i_am_at(labyrinth)),
  152        look, !.
  153
  154go(Direction) :-
  155        i_am_at(Here),
  156        path(Here, Direction, There),
  157		at(timecapsule,in_hand),
  158        retract(i_am_at(Here)),
  159        assert(i_am_at(There)),
  160        look, !.
  161
  162go(_) :-
  163        write('You can''t go that way. You either dont have the time capsule or are going in the wrong direction.').
  164
  165
  166/* This rule tells how to look about you. */
  167
  168look :-
  169        i_am_at(Place),
  170        describe(Place),
  171        nl,
  172        notice_objects_at(Place),
  173        nl.
  174
  175/*To know what all items you are currently holding*/
  176
  177hand :- 
  178        at(X, in_hand),
  179        write('There is a '), write(X), write(' in your hand.'), nl,
  180        fail.
  181
  182/* These rules set up a loop to mention all the objects
  183   in your vicinity. */
  184
  185notice_objects_at(Place) :-
  186        at(X, Place),
  187        write('There is a '), write(X), write(' here.'), nl,
  188        fail.
  189
  190notice_objects_at(_).
  191
  192
  193/* This rule tells how to die. */
  194
  195die :-
  196        !, finish.
  197
  198
  199/* Under UNIX, the   halt.  command quits Prolog but does not
  200   remove the output window. On a PC, however, the window
  201   disappears before the final output can be seen. Hence this
  202   routine requests the user to perform the final  halt.  */
  203
  204finish :-
  205        nl,
  206        write('The game is over. Please enter the   halt.   command.'),
  207        nl, !.
  208
  209
  210/* This rule just writes out game instructions. */
  211
  212instructions :-
  213        nl,
  214        write('Enter commands using standard Prolog syntax.'), nl,
  215        write('Available commands are:'), nl,
  216        write('start.                   -- to start the game.'), nl,
  217        write('n.  s.  e.  w.  u.  d. l1. l2. q. -- to go in that direction.'), nl,
  218        write('take(Object).            -- to pick up an object.'), nl,
  219        write('drop(Object).            -- to put down an object.'), nl,
  220        write('look.                    -- to look around you again.'), nl,
  221	write('hand. 			-- to know the objects in your hand.'), nl,
  222        write('instructions.            -- to see this message again.'), nl,
  223        write('halt.                    -- to end the game and quit.'), nl,
  224        nl.
  225
  226
  227/* This rule prints out instructions and tells where you are. */
  228
  229start :-
  230        instructions,
  231        look.
  232
  233
  234/* These rules describe the various rooms.  Depending on
  235   circumstances, a room may have more than one description. */
  236
  237describe(labyrinth) :-
  238	write('Your are in a labyrinth. If you want to win the throne you need some necessary items from different kingdoms.'), nl,
  239	write('Go in a (n.,s.,e.,w.,u.,d.) direction to know about a kingdom'), nl,
  240	write('You have Limited time of 40 minutes to complete the journey.'), nl,
  241	write('There are unlimited time capsules in the labyrinth, each capsule gives you 40min.'), nl, 
  242	write('You cannot take more than one capsule unless you are left with 0 min'), nl,
  243	write('Wait first look around, there are some items for you, Go take them.'), nl.
  244
  245describe(kingslanding) :-
  246	write('Welcome to the land ruled by the mighty and generous king Elon Musk. His Palace is on Elis Island to the east.'),nl,
  247	write('If you are afraid to meet the king, then go west to go back to labyrinth.'),nl,
  248	write('However, Elon doesnt disappoint his guest, so be brave and go meet him in his Palace.'),nl,
  249	write('Use the jet plane lying at the shore and go e. to fly to Elis Island. Dont forget to take the parachute with you.'),nl.
  250
  251describe(elisisland) :-
  252	write('Welcome to beautiful Elis Island. You met Elon and saw how kind and smart he is.'),nl,
  253	write('Wow! Look around, he has gifted you with a brand new Tesla Model S car minimizable to a toy size car.'),nl,
  254	write('Go take it and put it in your pocket. Do remember this is an Incomplete object and you need to obtain the fuel to get the car working.'),nl,
  255	write('Go to west to go back to labyrinth and find the fuel.'),nl.
  256
  257describe(eerie) :-
  258	write('Welcome to Eerie- the place of strangeness.'), nl,
  259	write('If you think the place is too wierd and scary go back labyrinth which is in the west.' ), nl,
  260	write('If you feel gutsy and want to conquer your fear then go south-s. and spin the wheeloffortune to know what hidden object this place beholds for you.'),nl.
  261
  262describe(wheeloffortune) :-
  263	write('You have just spinned the wheel of fortune. Look around, the key is the hidden object. Take it soon before it disappears'),nl,
  264	write('Now, go north to go back to labyrinth'),nl.
  265
  266describe(blackcastle) :-
  267	write('Welcome to the magical and mysterious Black Castle. In this Castle is a Ginie who wishes your grant. He rests in a lamp lying in between the cornucopia of Gold. Ask him for only
  268something you need. Dont be greedy for otherwise the Ginie will take back all your possessions.'),nl,
  269	write('Go west to wake the ginie up or go east to reach labyrinth. The choice is yours!'),nl.
  270
  271describe(cornucopia) :-
  272	write('Dont be mesmerized by the cornucopia of gold you see lying around.'),nl,
  273	write('This is a trap by the Genie. look around for the magiclamp. lying around.'),nl,
  274	write('Once you take it the genie will wake up and grant your wish'),nl,
  275	write('Remember once the genie grants your wish the magic lamp disappears for ever till the game ends'),nl.
  276
  277describe(thecapitol):-
  278	write('Welcome to Capitol-the modern world of flying saucers and hanging buildings.'),nl,
  279write('Surprised by the advancement of this  place? Well, try to peek into the mesmerizingly beautiful presidents arena located to north.'),nl,
  280write('That is where you will find the throne.'),nl.
  281
  282describe(lockeddoor1):-
  283	write('You have choosen the wrong door!'),nl,
  284	write('Oops you have almost only 0 minutes of time, go back to labyrinth to collect another time capsule.'),nl,
  285	write('Use the quick underground passage-q. to reach labyrinth before you get timed out,'),nl,
  286	write('Later get back here and try your luck with other door.'),nl.
  287	
  288describe(lockeddoor2):-
  289	write('Congratulations!!! You have chosen the right door. You just won the throne and an iphone6s.'),nl,
  290	write('Now take a selfie with The Throne and post it on facebook. Good bye!'),nl.
  291
  292describe(dragonworld) :-
  293	write('Watch out, there are angry flying dragons every where popping out their firey toungue to catch a prey. Go down to reach labyrinth before you become a toasted chicken for the dragons'),nl.
  294
  295describe(lavamountains) :-
  296	write('Hot molten lava overflowing from the high peaked mountains. Go up to reach labyrinth before you melt due to heat'),nl.
  297
  298describe(presidentsarena) :-
  299	write('You have almost reached your destination.'),nl,
  300	write('Now either select lockeddoor1-l1. or lockeddoor2-l2. to get to the throne'),nl,
  301	write('Use the key you found at eerie to unlock any door'),nl