Mastodon Politics, Power, and Science: I Built an Infinite Dungeon Generator with Python and Gemini AI (And You Can Too)

Tuesday, December 2, 2025

I Built an Infinite Dungeon Generator with Python and Gemini AI (And You Can Too)

J. Rogers, SE Ohio

We have all been there as Dungeon Masters. It's 30 minutes before the session starts. You have no map, no NPCs, and no plot hooks. You need a miracle.

So, I wrote some Python code to create one.

I’m releasing a suite of Mega-Mapping tools as an open-source Proof of Concept. It combines old-school procedural generation (like the rogue-likes of the 80s) with modern Generative AI to create something entirely new.

Check out the project here:
https://github.com/BuckRogers1965/Mega-Mappers

What It Does Right Now

This isn't just a tech demo; these are functional tools you can use at your table tonight. The project creates visual maps using Pygame and then—this is the magic part—uses Google’s Gemini AI to "look" at those maps and write adventures for you.

1. The Mega Dungeon

It generates a massive 150x150 grid dungeon. That is dozens of rooms per level. It uses a "viewport" system so you can scroll infinitely.

  • The AI Hook: Find a sector you like, press 'C', and the script sends the visible room geometry to the AI. It returns a fully formatted Markdown file with room descriptions, monster rosters, and trap mechanics tailored to exactly what you see on screen. It saves a map with the same name.  And you can output a well drawn map of the entire level that has an old school hand drawn look.

2. The Mega Village

Need a town fast? This generates a hex-based settlement with logical placement (mills near water, inns near roads).

  • The AI Hook: Press 'G' and the AI writes a "Visitor's Guide" for that specific village, inventing personalities for the innkeeper and rumors for the blacksmith based on the town layout.

3. The Tactical Map

A zoomed-in, hand-drawn style renderer for battle maps. It even simulates ink wobble and hatching.

The "Schrödinger's Campaign" Concept

While these tools are useful now, they are a Proof of Concept for something much bigger: A Persistent Campaign Database.

Imagine a campaign where nothing is fixed until your players look at it.

  1. You generate a village map. It exists, but the "Blacksmith" is just a blank database entry.

  2. Your players decide to visit the smithy.

  3. You click the building.

  4. The system calls the AI, generates a name ("Grumble"), a personality ("Hates elves"), and a quest hook. It has a picture from the description in the style you choose for the campaign

  5. This is instantly saved to a local database.

  6. Two months later, when the players return, the system loads "Grumble" from the database. He remembers he hates elves.

This allows for infinite detail without infinite prep time.

A Challenge to the Community

I have built the engine. I have connected the pipes between Pygame and Gemini. The code is clean, modular, and ready to be hacked.

I want you to take this and run with it.

Go beyond my meager efforts.

  • Add the SQLite persistence layer to make the world remember.

  • Have the world remember all the towns you explore and have a list of NPCs that are remembered with all the detail you added to each one.

  • Hook it up to Stable Diffusion to generate character portraits on the fly that are remembered for that character.

  • Build a second screen for your players that reveals the map as they walk.

The code is open source. The foundation is laid. The dungeon is waiting.

Fork the Repo on GitHub

No comments:

Post a Comment

Progress on the campaign manager

You can see that you can build tactical maps automatically from the world map data.  You can place roads, streams, buildings. The framework ...