alt.hn

4/22/2025 at 12:25:12 AM

Prolog Adventure Game

https://github.com/stefanrodrigues2/Prolog-Adventure-game

by shakna

4/22/2025 at 12:56:13 AM

Very nice. I gave a lab assignment like this once! It's a great way to learn Prolog.

https://github.com/agiacalone/cecs-342-lab-prolog

by agiacalone

4/22/2025 at 1:08:31 AM

There's even a book "Adventure in Prolog" by Dennis Merritt (ISBN 1520918917)

It's a lot of fun to work through, other prolog resources can be a little dry

by pacaro

4/22/2025 at 3:50:14 AM

This one? [0]

[0] https://amzi.com/AdventureInProlog/

by shakna

4/22/2025 at 4:08:03 AM

Yes! that one!. I have a paper copy, so it didn't occur to me that there would be an online version

by pacaro

4/22/2025 at 6:20:42 AM

Going to tell the Preface story tomorrow at work, I guess if your reading this you now know my HN handle ;) Not sure I will do the 'game' but that into was worth clicking the link.

by Sn0wCoder

4/22/2025 at 2:40:38 PM

> I guess if your reading this you now know my HN handle

No worries. A great philosopher once wrote:

"There is a theory which states that if ever anyone discovers exactly what your HN handle is for and why it is here, it will instantly disappear and be replaced by an HN handle even more bizarre and inexplicable."

by rickydroll

4/22/2025 at 10:29:30 PM

I also heard:

"There is another theory which states that this has already happened..."

by agiacalone

4/22/2025 at 7:25:18 AM

Yep. That's how I passed my Prolog course as well :)

by nottorp

4/22/2025 at 9:46:33 AM

Just for curiosity I just asked chat deepseek to load and solve the game and it solved it in half a second.

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)).

by hazymemory

4/22/2025 at 2:34:14 AM

If you wrote an adventure game in Prolog, you could write a client that would also solve the adventure.

by ForOldHack

4/22/2025 at 5:44:41 PM

That's only if you are using pure predicates. From a quick glance, the code makes liberal use of assert, retract, and the cut operator, so you can't write a query that solves the problem automatically.

by ooopdddddd

4/22/2025 at 7:21:37 AM

I can imagine it's easier to write that client in Prolog than the adventure.

by mcv

4/22/2025 at 4:11:05 PM

Or write a program that generates the adventure game!

by johnisgood

4/22/2025 at 5:35:52 AM

I have never heard of Prolog before so this was cool. I did think the "make sure the flashlight is turned on" point was kind of confusing. I have the battery and flashlight, but there's no way to turn it on. I couldn't run it with gprolog but swipl works fine.

by wfurney

4/22/2025 at 5:08:02 PM

The flashlight should be automatically on in this case:

    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".

by klibertp

4/22/2025 at 9:08:28 AM

is it generated by LLM using prompt at https://github.com/stefanrodrigues2/Prolog-Adventure-game/bl...?

by codesnik

4/22/2025 at 9:12:41 AM

Given [1], probably :)))

[1] https://github.com/stefanrodrigues2/Prolog-Adventure-game/bl...

by Kaethar

4/22/2025 at 4:13:20 PM

Good catch! Although I do have some README.md templates where I use "yourusername" or whatever. I bet it would be said it was generated by an LLM. :/ Oh well, it still would take someone skilled to have it made by an LLM anyways. :D

by johnisgood

4/22/2025 at 4:03:41 PM

I only learned Prolog as a hobby, so I may be mistaken, but the quality of the code seems really bad? Starting from keeping game state in a bunch of magic globals (assert/retract everywhere), to a lack of input parsing (even though DCGs would be a perfect match), to comments that disagree with the code[1], to the game logic coupled with game mechanics as side effects (the winning condition is checked inside `take`)... I may be too used to Prolog code from books and tutorials, but the number of cuts also seems much larger than expected.

...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`.

by klibertp

4/22/2025 at 2:40:28 AM

Cool! I got stuck trying to figure out how to turn on the flashlight and then got stuck in the woods and died.

by asciii

4/22/2025 at 4:17:56 AM

When I was in school I had to do some stuff with prolog. I got my wife interested enough that she added some rooms and items to a game like this. Good times!

by twothamendment

4/22/2025 at 4:09:15 PM

I love text-based adventure games in Prolog.

by johnisgood

4/22/2025 at 5:09:49 PM

I can't get this game to start, am I stupid?

$ swipl -s treasure_hunt.pl

and then what?

by mparnisari

4/22/2025 at 5:58:18 PM

    -▶ 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...

by klibertp

4/23/2025 at 3:28:02 PM

Thanks!

by mparnisari