I made an AI DnD dungeon master

Jeffer1981
3 min readNov 17, 2023

Why would you make something like this?

Well, my son loves to play Dungeons and Dragons. It’s a great game, as it uses a lot of his imagination, but it takes a lot of preparation in creating the characters and planning an exciting campaign.

Something AI could really help with, right?

How did I design the game?

I used ChatGPT from OpenAI as my AI engine and by just using the public ChatGPT website, it’s clear that ChatGPT can serve as a dungeon master, except for the fact that ChatGPT has issues keeping history. Depending on which version you use (GPT 3 or 4), the web app is limited to a (short) memory. The API will not keep even any history.

So the solution is to save the progress (characters and adventure progress) in a MongoDB database.

However, storing all details of the adventure and every time sending those to ChatGPT as context would 1) break the limit of what ChatGPT accepts as context and 2) make every request to the API quite expensive. So instead of storing all details, we first have ChatGPT summarize the progress and we save the summary.

We even did something extra

I’ve added some functionality to have Dall-E generate images when creating your main hero or the current scene, just make things a bit more visual. It does work, though I personally find the images (using Dall-E 2) a bit underwhelming and expensive. Dall-E 3 does give very nice results.

Looking to try it out?

You can do so here: https://dndmaster-e8ki26ip8-jeffer1980.vercel.app/

How to play this game?

The home page is your main page where you interact with the game.

1. Fill out a value for game id. The game will save any character and progress in this value and this allows you to pick up the adventure later on.
2. Press load character. If you have a saved game under that game id, it will load the previously created character, If it’s a new game id, you will get the create character page (more on this later).
3. Play the game by typing something in the ‘Ask the dungeonmaster’ box and then press ‘send to dungeonmaster’. Then keep on responding to what the dungeonmaster tells you.

Tip: Your first command can be something like ‘Start a scary adventury in a graveyard!’, but feel free to try stuff out.

Creating a character page

Select your race and class and press on ‘create character’.
When you get the character, press ‘save character’ and then ‘go back’

Note: the ‘get image’ buttons are disabled. Normally they allow the user to generate through AI a picture of the hero or scene, but since I’m using dall-e 2 is way to expensive for quite poor results.

--

--

Jeffer1981

Project Manager for ERP software | Tech enthousiast in python, AI | Loves sports and martial arts | Living in Belgium