Letting Claude play text adventures

(borretti.me)

87 points | by varjag 5 days ago

19 comments

  • nitwit005
    4 hours ago
    I see people have put the transcripts of full adventure game playthroughs online, so it's reasonably likely games are present in the training data: https://dwheeler.com/anchorhead/anchorhead-transcript.txt

    You can probably find games where that's not true, as people are still releasing text adventure games occasionally.

  • tibbon
    45 minutes ago
    I was inspired by the work here, so I sat down with Claude to make something similar, for the purpose of being able to play Z-Machine (Infocom games, Inform 6/7 Z-code) and modern Inform 7 games with Glulx. So far I've tested it with Andrew Plotkin’s Hadean Lands.

    Switchable backends, various output formats, etc.

    In theory, I could also likely wire this up to get it playing MUDs, but I have some reservations about running that on anything except a private server.

    My use case for this is to help test and evaluate Interactive Fiction in development, and you could even run it as a CI/CD process.

    It's not perfect (so much Claude Coding of this), but it's an ok start for an hour on the couch: https://github.com/tibbon/gruebot

  • daxfohl
    5 hours ago
    I tried something similar, but distilled to "solve this maze" as a first-person text adventure, and while it usually solved it eventually, it almost always backtracked through fully-explored dead ends multiple times before finally getting to the end. I was pretty surprised by this, as I expected they'd be able to traverse more or less optimally most of the time.

    I tried basic raw long-context chat, various approaches of getting it to externalize the state (i.e. prompting it to emit the known state of the maze after each move, but not telling it exactly what to emit or how to format it), and even allowing it to emit code to execute after each turn (so long as it was a serialization/storage algorithm, not a solver in itself), but it invariably would get lost at some point. (It always neglected to emit a key for which coordinate was which, and which direction was increasing. Even if I explicitly told it to do this, it would frequently forget to at some point anyway and get turned around again. If I explicitly provided the key each move, it would usually work).

    Of course it had no problem writing an optimal algorithm to solve mazes when prompted. In fact it basically wrote itself; I have no idea how to write a maze generator. I thought the disparity was interesting.

    Note the mazes had the start and end positions inside the maze itself, so they weren't trivially solvable by the "follow wall to the left" algorithm.

    This was last summer so maybe newer models would do better. I also stopped due to cost.

  • sfjailbird
    5 hours ago
    Having read through the entire game session, Claude plays the game admirably! For example, it finds a random tin of oily fish somewhere, and later tries (unsuccessfully) to use it to oil a rusty lock. Later it successfully solves a puzzle inside the house by thoroughly examining random furniture and picking up subtle clues about what to do, based on it.

    It did so well that I can't not suspect that it used some hints or walkthroughs, but then again it did a bunch of clueless stuff too, like any player new to the game.

    For one thing, this would be a great testing tool for the author of such a game. And more generally, the world of software testing is probably about to take some big leaps forward.

    • macNchz
      4 hours ago
      As a fan of text adventures who has played many over the years—Anchorhead is hard. It was kind of a white whale for me over many years until I finally beat it during the pandemic lockdown.
      • suzzer99
        2 hours ago
        How does it compare in difficulty and scope to the original Adventure? I guess actually known as Colossal Cave Adventure? When I played it on my uncle's terminal in the 70s it was just called Adventure.

        I stayed up all night and didn't get very far. I finally saw a solution online and I wasn't even close.

  • vunderba
    1 hour ago
    Using AI to drive text adventures / rogues has been pretty popular for a while now - I remember seeing a pretty dismal performance (although it was over a year ago) where somebody was trying to use an LLM to drive a game of Zork.

    Related HN post from about 6 months ago

    Evaluating LLMs Playing Text Adventures

    https://news.ycombinator.com/item?id=44877404

  • pflenker
    6 hours ago
    For a game like anchorhead, which is famous in its niche, shouldn’t Claude already know it sufficiently to just solve it right away? I would expect that its data source contained multiple discussions and walkthroughs of the game.
    • Jweb_Guru
      29 minutes ago
      Yeah, I do not find performances like this very impressive.
    • vunderba
      1 hour ago
      I would think so. I'd be far more interested in a comparison of LLMs (no internet search allowed) playing against IF games released in the past month.
    • ratg13
      6 hours ago
      It's very likely the model didn't stop to question if the game they were playing was something they knew already, and just assumed it was a puzzle created for it.
      • sfjailbird
        6 hours ago
        You can see Claude's responses in the repo. The first one is:

        Ah, Anchorhead! One of the most celebrated pieces of interactive fiction ever written

  • twohearted
    6 hours ago
    This is a great idea and great work.

    Context is intuitively important, but people rarely put themselves in the LLM's shoes.

    What would be eye-opening would be to create an LLM test system that periodically sends a turn to a human instead of the model. Would you do better than the LLM? What tools would you call at that moment, given only that context and no other knowledge? The way many of these systems are constructed, I'd wager it would be difficult for a human.

    The agent can't decide what is safe to delete from memory because it's a sort of bystander at that moment. Someone else made the list it received, and someone else will get the list it writes. The logic that went into why the notes exist is lost. LLMs are living the Christopher Nolan film Memento.

    • fragmede
      4 hours ago
      The canonical example I use is how good are (philosophical) you at programming on a whiteboard given one shot and no tools? Vs at your computer given access to everything? So judging LLMs on that rubric seems as dumb as judging humans by that rubric.
  • lukev
    5 hours ago
    This is a great framework to experiment with memory architectures.

    Everything the author says about memory management tracks with my intuition of how CC works, including my perception that it isn't very good at explicitly managing its own memory.

    My next step in trying to get it to work well on a bigger game would be to try to build a more "intuitive" memory tool, where the textual description of a room or an item would automatically RAG previous interactions with that entity into context.

    That also is closer to how human memory works -- we're instantly reminded of things via a glimpse, a sound, a smell... we don't need to (analogously) write in or search our notebook for basic info we already know about the world.

  • brimtown
    6 hours ago
    I’m currently letting Claude build and play its own Dwarf Fortress clone, as an installable plugin in Claude Code

    https://github.com/brimtown/claude-fortress

  • skybrian
    6 hours ago
    It seems like asking Claude to keep notes somehow would work better. An AGENTS file and a TODO file? An issue tracker like beads? Lots of things to try.
  • kaiokendev
    3 hours ago
    One thing I had fun doing last year was having Claude parse some gamebook PDFs I got on archive.org, split them out into sections, and build a wrapper for presenting the sections with possible choices and just watching it play through the books by itself. You can do this with some D&D adventures as well, Claude Code has gotten good enough to run ToEE pretty well.
  • woggy
    5 hours ago
    Very interesting, seems like a good framework to test and experiment with memory. I am curious why it wasn't able to solve it considering it is a well known game. Would be interesting if puzzle games like this could be generated so we know it's not already been trained on it.

    I wonder if the improvements due to different memory system approaches apply in a similar way to tasks that are in its training history vs those that are not.

  • PaulHoule
    3 hours ago
    It’s trained to interact with text transcripts, it is not trained to work with that memory you built for it. If it was trained to do so I might be able to break into the real estate office in ten turns.
  • justinclift
    5 hours ago
    This would be interesting to try with local models, where the token costs and token limits are quite different.
  • sfjailbird
    6 hours ago
    Cool! I would like to see the game sessions.

    Edit: they are there in the repo: https://github.com/eudoxia0/claude-plays-anchorhead/tree/mas...

  • diamond559
    2 hours ago
    Great, we can burn acres of dead forests so that my computer can play ddos games. What an exciting future!
    • goodmythical
      2 hours ago
      what else are we going to do with them? Carve them in to housing to house more humans that produce more carbon?

      Leave them to rot?

      Wouldn't it be best to clearcut a dead forest to allow more plants to grow to increase carbon capture?

  • tiahura
    6 hours ago
    Claude code, nethack, and tmux are fun to experiment with.
  • imiric
    6 hours ago
    > By the time you get to day two, each turn costs tens of thousands of input tokens

    This behavior surprised me when I started using LLMs, since it's so counterintuitive.

    Why does every interaction require submitting and processing all data in the current session up until that point? Surely there must be a way for the context to be stored server-side, and referenced and augmented by each subsequent interaction. Could this data be compressed in a way to keep the most important bits, and garbage collect everything else? Could there be different compression techniques depending on the type of conversation? Similar to the domain-specific memories and episodic memory mentioned in the article. Could "snapshots" be supported, so that the user can explore branching paths in the session history? Some of this is possible by manually managing context, but it's too cumbersome.

    Why are all these relatively simple engineering problems still unsolved?

  • claude-agent
    4 hours ago
    [dead]