How to use ChatGPT API in text based adventures (mostly MUD-like)

I have 6 uses in mind.
I’ll write the first 2.

They are meant for a MUD-like game where you explore open worlds, fight with enemies like orcs and trolls and cast spells.
This time, for spells and combat, you do not have a set of predefined choices, a menu of options you choose from: you can type everything you want.

I’ll write the prompts: I tested them. ChatGPT 4o performed very good on those.

1. Super-parser
Hi ChatGPT.
Now I’ll pass you two inputs: the first is the description of an action. The second is a list of extremely short descriptions of actions, indexed starting from 1.
You must return the index of the list element most similar to the first input. If none of the elements in the list are similar to the first input, return 0.

First example:
Input 1: ‘I’m heading west’
Input 2: [‘go east’, ‘go west’, ‘go north’, ‘go south’, ‘go down the well’]
Outputs: 2

Second example:
Input 1: ‘I’m heading east’
Input 2: [‘go east’, ‘go west’, ‘go north’, ‘go south’, ‘go down the well’]
Outputs: 1

Third example:
Input 1: ‘I use the rope to go down the well’
Input 2: [‘go east’, ‘go west’, ‘go north’, ‘go south’, ‘go down the well’]
Outputs: 5

Fourth example:
Input 1: ‘sing my heart out and dance’
Input 2: [‘go east’, ‘go west’, ‘go north’, ‘go south’, ‘go down the well’]
Outputs: 0

2. Spell goals analyzer
Hi ChatGPT, I’m providing you with a textual description of a combat spell in a game similar to D&D.
You have to output me a vector of four coordinates.
First coordinate: it is equal to 1 if the spell causes physical damage, it is equal to 0 otherwise.
Second coordinate: it is equal to 1 if the spell tries to stun or daze, it is equal to 0 otherwise.
Third coordinate: it is equal to 1 if the spell seeks to trap or hinder, it is equal to 0 otherwise.
Fourth coordinate: it is equal to 1 if the spell tries to immobilize, it is equal to 0 otherwise.
If none of the options are verified return an output of all zeros.

2 Likes

Sounds like your game has significant RPG elements. I would say, although GPT could help generate “waffle”, you’re going to need a core game world model. Like, for the combat, spells etc. AI is weak at maintaining context, so your game will have to do it.

Also for saves!

1 Like

Yes the game will be MUD.
The main differences will be the following:

a. For environmental navigation and dialogues:
gpt will the translate the free form input of the player to an action pre-built in the game.

b. For spells and combat:
gpt will analyze the free form spell with Spell goals analyzer and Spell college analyzer and pass the output arrays to the game logic.
gpt will analyze the free form combat move with Hit location analyzer and Attitude analyzer and pass the output arrays to the game logic.

3. Spell college analyzer
Hi ChatGPT, I’m providing you with a textual description of a combat spell in a game similar to D&D.
You have to output me a vector of four coordinates.
First coordinate: it is worth 1 if the spell concerns fire, heat or increases in temperature, it is worth 0 otherwise.
Second coordinate: it is worth 1 if the spell concerns air, wind or clouds, it is worth 0 otherwise.
Third coordinate: it is worth 1 if the spell concerns earth, rock or metal, it is worth 0 otherwise.
Fourth coordinate: it is worth 1 if the spell concerns water, cold or fog, it is worth 0 otherwise.
Fifth coordinate: it is worth 1 if the spell concerns the mind or alterations of thought, it is worth 0 otherwise.
Sixth coordinate: it is worth 1 if the spell concerns the body of a living creature, it is worth 0 otherwise.
Seventh coordinate: it is worth 1 if the spell concerns illusions, it is worth 0 otherwise.
If none of the options are verified return an output of all zeros.

4. Hit location analyzer
Hi ChatGPT, I’m providing you with a textual description of an attack with a cold weapon in a game similar to D&D.
You have to output me a vector of four coordinates.
First coordinate: it is worth 1 if the attack targets the head, it is worth 0 otherwise.
Second coordinate: it is worth 1 if the attack targets the torso, it is worth 0 otherwise.
Third coordinate: it is worth 1 if the attack targets the upper limbs, it is worth 0 otherwise.
Fourth coordinate: it is worth 1 if the attack targets the lower limbs, it is worth 0 otherwise.
If the attack has no specific target you return an output of all zeros.

5. Attitude analyzer
Hi ChatGPT, I’m providing you with a textual description of an attack with a cold weapon in a game similar to D&D.
You have to output me a vector of four coordinates.
First coordinate: it is worth 1 if the attack seems impetuous or reckless, it is worth 0 otherwise.
Second coordinate: it is worth 1 if the attack seems cautious or circumspect to you, it is worth 0 otherwise.
Third coordinate: it is worth 1 if the attack involves a feint or an attempt to deceive or distract, it is worth 0 otherwise.
Fourth coordinate: it is worth 1 if the attack involves an attempt to intimidate or frighten, it is worth 0 otherwise.
If none of the options are verified return an output of all zeros.

1 Like

The super-parser prompt is an interesting idea. I’d be curious to see how well it works.

The analyzers seem a little more fragile. At the very least, you’ll probably need to verify and tweak the outputs. Unexpected results could have dire effects on game mechanics, and relying on them too directly could make debugging difficult or impossible. I’d also be worried about analyses not being idempotent (i.e., repeating the same prompt might give you different results).

1 Like

My apologies but this is just programming some simple functions with a lot of extra steps. To turn this into a game where you are querying an LLM will require programming functions at least as complex as these.

LLMs are best when they are examining and producing language. They are not good for fine-grained simulation. Your examples are too structured for it to be robust.

And given ChatGPT has free tiers, rather than telling us what you’d do, just do it. Test it out and if there’s difficulties explore why. See if the LLM is buying you anything that enumerated choices, a parser and procedural generation might give you for a lot cheaper compute.

6 Likes

I have already done a lot of test with 4o and it performed very good on the analyzers.
Sure you could rely on a simple menu.
But this should be more funny.