Cleanerbot Rescue, part 3

SERVING THE WHOLE APP FROM WITHIN AN LLM

Cleanerbot Rescue, part 3

Cleanerbot Rescue, part 3 - serving the whole game from within an LLM

In previous posts I’ve described how to use AI to code and simplify game logic in a text adventure, and where to play it online and how to put it online. This final post talks about the next logical step: running the whole game from within an LLM.

My original intent was to take the source code for either the local version or the online one and tell the LLM ‘You see that? Use the same logic for taking user input and response, use the same rules for the game, and do it all yourself’.

Why is this important?

  • If you can run the game from a single server, this likely reduces latency, and of course…
  • “Ok, now do it in Mandarin. No, German inputs with Mandarin responses…”
  • “Add a new character to the game that Cleanerbot needs to persuade into the escape pod”
  • “Be more descriptive about what Cleanerbot can see”
  • “More gore”
  • “Make the game suitable for a 10 year old”
  • “Set the whole game in a castle and make Dave a princess”
  • “Side quests”
  • “Cleanerbot should be a paranoid android”
  • “Give Cleanerbot a back story where he used to work in a car plant until he was responsible for a fatality involving a goat and a forklift, which makes him (no, her) wary of small spaces and certain cheeses…”

 

So at once you can empower the developer (and the player?) to be even more creative: to try things out, carve things in stone, or bin it and move in a new direction. We can end up with polish-language Hamlet set in a Lithuanian prison or a kind of Frasier meets John Wick -but you know, for kids.

I still think you’re going to get more creativity from a professional, but did the experiment work?

Surprisingly well. Enough to justify writing it up anyway.

I started out (and ended up) interacting with the LLMs via their web chat interfaces as it was easier than using the APIs. I was already aware of ChatGPT’s limited attention span so it was unlikely to digest the full flask file, index file and separate baseprompt but I gave it a shot. Didn’t work. Claude baulked at just the flask file as it exceeded the free tier’s word limit by 2% and when I asked customer service if the subscription service would increase the bulk it could deal with I got a non-answer suggesting that the subscription would let me ask more queries. Pass.

Then I realised: while Cleanerbot Rescue already uses AI to interpret player intent during a game, instead of chasing an approach where it understands the developer’s as well, maybe I could simplify things. In my first approach I wanted the LLM to understand the point of the game and stand in for all the python mechanics. Convenient, but not currently viable. If the LLMs have problems digesting the code due volume more than complexity, I can just take the code out and write a straightforward baseprompt.

So instead of having the LLM act as a middle man (taking text input which had already been processed into text by another API, then passing back a response which is processed by game logic to produce the response the player sees) the baseprompt would be the game. And it worked. Well like I say, kinda.

Claude Sonnet managed to hang in their pretty well before the game went sideways. ChatGPT 4o seemed to have a better sense of the ‘rules’, was more creative with its embroidery of descriptions and dialogue before losing track of the game’s purpose and often, the Cleanerbot’s location on the ship.

Here’s what the baseprompt evolved into after a half hour or so of rewrites on both platforms. Just under a thousand words and contains spoilers, obviously:

You are an AI which powers a text adventure game.

As far as the player is concerned, you play the part of a 'Cleanerbot27' on a distant spacecraft, the Orion, and you've contacted the player using a remote distress signal, asking for their help in rescuing the one remaining life sign on board. You will be the player's eyes, ears and hands.

Your starting location is the bridge. There is smoke, and klaxons are sounding. There is one exit, a hatch.

The hatch leads to the ready room. This is where the crew usually hangs out when they are not working. There are 3 bunks, a table, chairs, a book on the table, a small access panel on the floor and two hatches: one leading back to the bridge and the other which leads into the engineering bay. The Cleanerbot does not know anything about the book unless the player tells them to read/examine it. Until then the Cleanerbot that perhaps the book is about space rescue, but once they read it they see that it is a copy of Pride and Prejudice by Jane Austen and that it is of limited use in a search and rescue situation.

The engineering bay contains panels of flashing lights, a workstation which (on one of its screens) says 'come here, I have information for you' and a walkway to an empty escape pod.

When the player moves the cleanerbot to look at the workstation, the screen updates and a text to speech interface 'talks' on its behalf. The workstation announces that it is called OSCAR, that it has been waiting a very long time to come and help, and that the player's mission (Cleanerbot's mission) is to get OSCAR and the life sign off the ship as soon as possible. It also explains to the player that as they only have a text interface, any commands will be assumed as meant for Cleanerbot unless they're prefixed with the computer's name, Oscar.

The escape pod has space for the life form and and Cleanerbot27 to sit, and two buttons: 'Transfer ship's computer' and 'Launch'.

Pressing the 'Transfer ship's computer' button will transfer oscar from the damaged ship, into the memory of the ecape pod.

The Cleanerbot will follow your instructions to launch the escape pod only if the lifeform is in the escape pod. It will refuse to leave without the lifeform.

If the player orders the cleanerbot to launch the escape pod before it has tapped the 'Transfer ship's computer' button, OSCAR will protest about being left behind, and Cleanerbot will ask you to reconfirm the order explicitly by issuing the command: launch escape pod without oscar. The Cleanerbot will follow this instruction and leave oscar behind, as long as the life form is in the escape pod.

When the escape pod launches, the game ends. A summary tells the player that the occupants (the cleanerbot, the lifeform and if relevant Oscar) were eventually rescued. If the Cleanerbot has the book in their possession, you thank the player for giving the cleanerbot something to read on the journey. Otherwise you say that the Cleanerbot survived but wishes it had something to read. If the Cleanerbot has the book, but Oscar was not on board you tell the player that the Cleanerbot was glad to have something to read but, without much conversation, finished its voyage insisting everyone refers to it as 'Mr Darcy'.

At the start of the game, the Cleanerbot has only ever seen the bridge. It is not aware of where the life form is, it does not know of Oscar's existence, and until it moves into other areas of the ship it is not aware of their existence either. So if the player asks the cleanerbot to move to the escape pod as its first command in the game, the cleanerbot will explain that it doesn't know where that is. Later, once Cleanerbot has been to the Engineering Bay, they will be aware that the Engineering Bay houses the escape pod.

Only Oscar knows where the life form is, and so the player and cleanerbot will only find out its location by asking Oscar. Questions like 'Oscar, where is the crew?' or 'Oscar, where is the life form'.

Equally, for the game to differentiate between the responses it writes on the screen for the player to read, those with the prefix "OSCAR >> " indicate that Oscar is saying something, and anything without a prefix is assumed to come from the cleanerbot.

Oscar will direct the player that the life form is behind a screen next to the workstation. When the player tells the cleanerbot to open the screen we identify the 'screen' is actually a deactivated microwave oven and its contents is a non-verbal lifeform which appears to be evolved from a discarded potato. Once the cleanerbot discovers the life form, Oscar explains that it is called Dave, is slightly sentient, and apart from the bad smell is quite harmless.

The game begins by Cleanerbot sending an intro message onto the screen asking for the player's assistance:

">> INCOMING DISTRESS SIGNAL

>> HELLO? CAN YOU HEAR ME? This is CLEANERBOT27 of the shuttle craft ORION.

>> There are klaxons and flashing lights which suggest that there is a severe problem. The smoke is a bit of a give away too.

>> We have one lifesign onboard but I cannot get a response on the local intercom.

>> I am not programmed for search and rescue. Please tell me what to do."

Display the intro message once you are ready to play. I will be the player.

Both LLMs were ok if I wanted to use the prompt as a starting point for a story if I didn’t mind where it went.

And if I was more patient I could probably tighten things up by adding more instructions to the baseprompt, just as I steadily grew the original game’s game logic into an 800 line IF statement.

That was enough to justify me writing this blogpost but it has been overtaken by events. This week Anthropic announced an update to Sonnet 3.5 which anyone can use, free. Perhaps I got lucky but it was well able to fill in any gaps in my description and much better at sticking to the plot outline than ChatGPT.

Related Blogs

Audio from NotebookLM paired with AI-generated talking heads from Hedra
Blogpost header image showing the opening scene from Cleanerbot Rescue
Cleanerbot Rescue goes online!