Skip to content

Instantly share code, notes, and snippets.

@tieorange
Created June 23, 2015 09:50
Show Gist options
  • Save tieorange/80e52a7f1313253c9e2e to your computer and use it in GitHub Desktop.
Save tieorange/80e52a7f1313253c9e2e to your computer and use it in GitHub Desktop.
Prolog Dragon's world
:- dynamic i_am_at/1, is_at/2, i_have/1.
:- retractall(is_at(_, _)), retractall(i_am_at(_)).
/* start point*/
i_am_at(academy).
/* description of ways to go*/
transition(castle, e, valley).
transition(valley, w, castle).
transition(valley, e, sea).
transition(sea, w, valley).
transition(academy, e, castle).
transition(castle, w, academy).
transition(pub, e, park).
transition(park, w, pub).
transition(park, e, river).
transition(river, w, park).
transition(lab, e, island).
transition(island, w, lab).
transition(lab, s, academy).
transition(academy, n, lab).
transition(academy, s, pub).
transition(pub, n, academy).
transition(castle, s, park).
transition(park, n, castle).
transition(castle, n, island).
transition(island, s, castle).
transition(valley, s, river).
transition(river, n, valley).
/*WHERE and WHAT objects are situated*/
is_at(key, castle).
is_at(bloodwine, pub).
is_at(trolls, valley).
is_at(dragons, academy).
is_at(crystals, island).
/*academy*/
askii_at(
" *\n :\n |\n |\n |\n :|:\n |||\n _____|||_____\n /=============\\n ---<~~~~~~~~~~~~~~~>---\n \-------------/\n \___________/\n \||:::||/\n ||:::||\n ||:::||\n ||:::||\n ||ooo||\n ||___||\n ||:::||\n ||:::||\n ||:::||\n ||:::||\n ||:::||\n /||:::||\\n / ||:::|| \\n / ||:::|| \\n / ||:::|| \\n ___/____||:::||____\____\n /~~~~~~~~~~~~~~~~~~~~~~~~\\n / |~~~~~~~~| _____ \\n | |________| | | | | Cygnus Mineah\n ______|______________|__|__|_____|_\n"
,
academy).
/*beer*/
askii_at(
" \n \n :MMMMMBMMMMM8 \n :S@MM7,:8MWi,:ZMMZi rZ8a: \n 2MMMM0 BMMMMMMMMMMZ \n MM8 X; aMM \n rMZ 2M2 \n 2M7 iMZ \n MM. MM \n MMMSr70MMBX;SMMMWXrSMMMBXrSMMM, \n S@MMBX7WMMWZ:7BMM@ai7WMM@Zi \n iZBBZS. 7 : ,2 ,, .a :, ,S \n ZMMMMMMMMMMMS 0MMMMi MMMMM. MMMMM \n MMM2 7MMMM7 aMMMM: WMMMM MMMMM \n 2MMi 7MMMM7 aMMMM: 0MMMM MMMMM \n BMM XMMMMr 2MMMM: BMMMM MMMMM \n BMM XMMMM7 aMMMM: 0MMMM MMMMM \n 0MM XMMMMr 2MMMM: BMMMM MMMMM \n 0MM XMMMM7 aMMMM, BMMMM MMMMM \n 0MM SMMMMr aMMMM: BMMMM MMMMM \n BMM XMMMM7 aMMMM, BMMMM MMMMM \n BMM XMMMMr aMMMM: BMMMM MMMMM \n SMM7 rMMMM7 aMMMM: 0MMMM MMMMM \n @MMB: XMMMM; 2MMMM: BMMMM @MMMM \n XMMMMMMMMMMMi XMMMM ZMMMM WMMMM \n .XaZaZMMMMB;@MMMM0;MMMMMZrMMMMM \n 2MMMMMMMMMMMMMMMMMMMMMMM, \n .ZMMMMMMMMMMMMMMMMMM@X \n \n\n"
,
pub).
/*island*/
askii_at(" X. \n MS \n ,7X2SX;. 7MMr \n .0MMMMMMMMMM2 BMM: \n BMMMMMMMMMMMMMM8 ;MMZ \n r07:.. ..:iS0MMMMMi .MM2 \n :2MM, M@ .:i;;: \n ,rSaZ2XXZ@MBM8a@MMMMMMMMMWX \n .MMMMMMMMMWZXZM@B87: .;XZ@MMMMX \n .MMMMMZr. SM8aMM8i ,X08, \n @MM0i S. 0MZ rMMMWi \n ,MW. X2 MMM iMMMW \n :. ,7 ,M rMMM ;MMM. \n .@M. M7 MMM7 2MM \n MM2 ZM 0MMa .MM \n .MZ XWMMM0 .M, 2MMX W8 \n .X8WBZi MMMMM0X. M@ aMM i \n ,WMMM@MMa 0MMM2, 7M. MM. \n iMM r,;WMMMMr MM X \n .MM; B ;2MM0 ;MX \n 0MM Mi WM: \n 7MB .M: MM \n Ba rM ;MM \n 0M ZMB \n MZ MMZ \n BM MMX \n 7Ma rMMi \n ,MM 8MM. \n XX :rr \n ,i;irSZ2SSaa2Xri. \n :X8WMMMMMMMMMMMMMMMMMMMMMWZX, \n rZMMMMMMM@@WWWWWWWWWWWWW@W@@MMMMMMW2i \n .SWMMMMMWWWWWWWWBWBWBWBWBWBWBWWWBWWWWMMMMMB7 \n SMMMMMMW@WWWWW@MMMMW@WWWWWWW@@MMM@@WWWWWWWMMMMMB; \n iWMMM0@MMMMMMMMMMMM80MMMMMMMMMMMMWXWMMMMMMMMMMMM8BMMM2 \n XBZi ;X222Xr. :;XS2SX;. .iXXSX7i. X0Z \n"
,
island).
/*troll face*/
askii_at(
"88888888888888888888888888888888477 777250888888888888888888888888888888888888\n8888888888888888888888888807 77288888888888888888888888888\n888888888888888888888887 7208888044490888888052777 708888888888888888888\n888888888888888888887 7888888857772222211554088888888888888827 28888888888888888\n8888888888888888887 288888027777777777777777777777777722540888888897 88888888888888\n88888888888888888 88888802777724452777222154412777777777777725540888887 088888888888\n8888888888888888 088888842408882777777212221488888888888042777777718888882 8888888888\n8888888888888887 0888888888887 748888888888278888888888880908880427 7888887 888888888\n888888888888888 88888888887 78888888888888887 4888888888888888888888077488888 88888888\n88888888888888 0888888888778888888041771888880 8888888881588888888888884888887 88888888\n8888888888807 9888888888488887 28887588888888788827 708888888 8888888\n8888887 28888888888888 88887 88888888888884 590047 788477 7888888\n8885 72888888888888888885 70882 488888807782 888977 78857 8888\n88 7888888877 72888881 7208888857 2 5888888807 28888888888887 88\n87 8888880 725527 728888888888888888881 088888888888 721408888888888888888885887 8\n0 8880487 78888888888827 77508888888888888888588888888888 58888888888888847 2887887 \n 888282 88888888 0888888842254888888888888888888888888887 8888888 777 84788 \n 88458 28888888 788888888888888888888 7708888888888 7488882 7488888888778 58 \n7 88978 888827 887 288888888577 7 88888888888888888827 788888888880 88888887 48 \n8 78874488887798 88882 7288888888888 8888 775888888888888 7758888888 888888774 5\n88 78874888888888 4888888 788888888 2887742720808888882 75777298888 88888222 78\n887 48528888888887 98888 881 288885788888888884 7 7888888888887 8880481 788\n8882 70440888888887 28 08888887 72888888888888877708888888888882 7 788885 2888\n88888 2122488888882 71 7888888888 7 70888888888888888847 2882 8880 78888\n8888884 7801140888884 7882 7088 88888277 74 888 788 88888\n888888887 088800888888 5 182 088888887 7888880 444888 8888 2 84 888888\n8888888888 888888888888 88888827 72 888888 888888 1827 87 888888\n888888888882 1888888888884 8888888888 7 8 82 888888\n8888888888880 8888888888887 8888888 8888927 74 48 480 888888\n88888888888888 0888888888888 28887 8888888888 788044 7777 48 0887 8 888 788888\n8888888888888882 88888888888887 0 888888888 788880 78888 884 88 88887 88888\n88888888888888888 08888888888885 888888888 78888 7888 782 88 78888888 78888\n88888888888888888887 78888888888888847 75888 18888 888 787 28888888888 8888\n8888888888888888888882 588888880008888817 772 77 72088888888888884 8888\n8888888888888888888888887 58888880427722408809017 7 724088888888844888528888 2888\n8888888888888888888888888887 7588888027777777224088888888888888888042198881 08888 2888\n8888888888888888888888888888887 78888817777772221554444444452222088882 088880 8888\n888888888888888888888888888888888807 7088882777777772215440888889277 75888888 8888\n888888888888888888888888888888888888888807 5888884277777777777 7772988888888 88888\n88888888888888888888888888888888888888888888847 58888888888888888888888888882 888888\n888888888888888888888888888888888888888888888888807 28888888888888888888807 78888888\n888888888888888888888888888888888888888888888888888885 729888788222777 7284550774\n888888888888888888888888888888888888888888888888888888888847 777719247777777 5\n"
,
valley).
/* Rules for the directions of fly_to(direction) */
n :- fly_to(n).
s :- fly_to(s).
e :- fly_to(e).
w :- fly_to(w).
/* Rules of how to fly to the particular direction. */
fly_to(Direction) :-
i_am_at(Here),
transition(Here, Direction, There),
retract(i_am_at(Here)),
assert(i_am_at(There)),
look.
fly_to(_) :-
write('Cant fly there :( .').
/* Rules of how to take the object . */
take(X) :-
i_have(X),
write('Already have it!'),
!, nl.
take(X) :-
i_am_at(Somewhere),
is_at(X, Somewhere),
retract(is_at(X, Somewhere)),
assert(i_have(X)),
write('OK.'),
!, nl.
take(_) :-
write('Cant find it here :( .'),
nl.
/* How to drop object. */
/*function */
drop(dragons) :-
i_am_at(Somewhere),
Somewhere == lab,
write('You won the game. Dancing elephants'), nl,
write("")
,nl.
drop(X) :-
i_have(X),
i_am_at(Somewhere),
Somewhere \== lab,
X \== dragons,
retract(i_have(X)),
assert(is_at(X, Somewhere)),
write('OK.'),
!, nl.
drop(_) :-
i_am_at(Somewhere),
Somewhere \== lab,
write('You dont have it! :('),
nl.
/* Rules of how to look around you (print where are you and what do u see). */
look :-
i_am_at(Somewhere),
describe(Somewhere),
nl,
what_is_at(Somewhere),
nl.
/* All the objects situated here. */
what_is_at(Somewhere) :-
askii_at(Image, Somewhere),
write(Image), nl,nl,
is_at(X, Somewhere),
write('Here you see:') ,write(X), write('.'), nl,
nl,fail.
what_is_at(_).
end :-
nl,
write('Game over'),
nl.
/* Rules of available commands. */
instructions :-
nl,
write(" *$$$$$$eeee\n ***$$$$$$$$e\n **$$$$$e\n e$$$e *$$$$$\n $$$$ e$$$$$\n $$$$ ee$$$$$$$\n $$$$ ee***ee***eeeee$$$$$$$$$$$*\n $$$$e eee$$$ $ $$$$$$$$$$$$$* ee\n *$$$$$$$$$$$$$$$$$$ $$$ $ $$$ $$$$$$$$** ee****WW$\n eeeeee *$$$$$$$$$$$$$$$$ $$ $ $$ $***** e*!!!W**!W*\n$!WWWW!***ee *************eee$$**eee$ e*!W**!!!!$\n $!!!!***WW!**eee e**!!!!!!!!!!!***e e**!!W*!!!!!!$\n $!!!!!!!!!*W!!!!$ $!!!!W****WWWW!!!!!$ *W!!!*WW!!!!!$\n $!!!!!!!!!WW*!!!$ *W!!*W!!!!!!!!*W!!W* e*!!!!!!*W!!!$\n $!!!!!W***!!WW!!*e ******WWWWW***** $!!!W***W!**W*\n $!!!W*WW****!!*W!!*eee ee $!!$ ee ee*!!W*!!!!!*W!!$\n $W*!$!!!!!!!!!!*WW!!!****!W***!!!!***W!*****!!!!$!!!!!!!!*W$\n $!W*!!!!!!!!!!!W**!WW!!!!W*!!!!!!!!!!*WW*****W!!$!!!!!!!!!W*\n *WW!!!!!!!!!W*!W**!!***W$!!!!W!!!W!!!$!!!!!!$!W*!!!!!!W**\n ****WW!W*!W$WWW!!!!!!$!!!!*WWW*!!!$!!!!!!$W$!!!WWWW*\n *$W*!!!!!*WW!!!$!!!!!!$!!!!W*!!WW**!!!*$*\n $!!!!!!!!!*W!*W!!!!!$!!!!$!W*!!!!!!!!!$\n *W!!!!!!!!!!***W!!!!$!!!!$*!!!!!!!!!!!$\n $!!!!!!!!!!!!!$!!!!$!!!W*!!!!!!!!!!!$\n $!!!!!*W!!!!!$!!!!$!!!$!!!!!W!!!!!$\neeeeeeee $!!!!!!$!!!!$!!!!$!!!$!!!!W*!!!!W*\n$!!!!W* ee$W$!!!!!!$!!!$!!!!$!!!$!!!W*!!!!W*\n$!!!*ee**e**e*WW*!!$!!!!!!$!!$!!!!$!!!$!!!$!!!WW*\n$!$WW!!*******!!WWW**W*W!!$WW*!!!!$!!!$!W$WW**W!*e\n$* **WWWWWW***e*!!$!!$**!W*!!!WW*$!!!*W!!*W!!*W!*e\n e*!!!$!!W*!W*!!!!$ $!!!!$!!!$!!!$!*e\n *WWW*WW*WWW*WWWW* *WWW*WWW*WWW*WW*\n "
),nl,
write('Welcome to the Dragon\'s World \n\n\n'), nl,
write('Your task: Find a DRAGONS and help them to get to the Lab. For making some magic :) \n'), nl,
write('Commands:'), nl,
write('start -- start your game.'), nl,
write('n s e w -- possible directions to fly.'), nl,
write('take(Object) -- take an object.'), nl,
write('drop(Object) -- drop an object away.'), nl,
write('look -- look around.'), nl,
write('instructions -- your instructions.'), nl,
write('end -- game over.'),
nl,nl.
/* Rule of printing where you are and what do you see */
start :-
instructions,
look.
/* Description of particular rooms */
describe(castle) :- write('Youre near the Dragons Castle. There are a lot of dragons here'), nl.
describe(valley) :- write('Youre near the Magic Valley. Lets meet some trolls :)'), nl.
describe(sea) :- write('Youre near the Sea of Monsters. But dragons dont like to swim…. '), nl.
describe(academy) :- write('Youre near the Dragons Academy. Its time to learn something new. Yahoo..'), nl.
describe(pub) :- write('Youre near the Dragons Bloody Pub. Music is not the best today. ehh... '), nl.
describe(park) :- write('Youre in the Abandoned Park. All attractions are closed today:('), nl.
describe(river) :- write('Youre near the River of Monsters...Brr... lets fly to some other place'), nl.
describe(lab) :- write('Youre in the Magician Lab. Lets make some magic! '), nl.
describe(island) :- write('Youre near the Deserted Island . Nice!'), nl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment