166 points · by shakna · 1y ago · 26 comments
It's a lot of fun to work through, other prolog resources can be a little dry
It suggested adding some riddle, for example:
path(castle, up, tower) :-
at(blueprint, holding),
(solved_riddle -> true ;
write('Answer the riddle first: What walks on four legs in the morning...?'), nl,
read(Answer),
(Answer = 'human' -> assert(solved_riddle) ;
write('Wrong! Try again.'), nl, fail)). flashlight_on :- at(flashlight,holding), at(battery,holding).
This condition is checked when you try to reach "woods" and "woods_1". (And that's the only place you can test if the flashlight is on, because it's otherwise not checked and doesn't change any of the descriptions.) The flashlight doesn't save you from dying in the "deepforest_X".[1] https://github.com/stefanrodrigues2/Prolog-Adventure-game/bl...
...now that I look at this, it's 3 years old. I wonder how much better today's LLMs would fare?
[1] https://github.com/stefanrodrigues2/Prolog-Adventure-game/bl... - no, the routine does not "wait" on Windows, you'd need to put `get_char(_)` or something before `halt`.
$ swipl -s treasure_hunt.pl
and then what?
-▶ swipl -s treasure_hunt.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.2.9)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- start. % <- this
Enter commands using standard Prolog syntax.
Available commands are:
start. -- to start the game.
up. down. right. left. -- to go in that direction.
...etc...