[DEVLOG] Procedural Co-Op Labyrinth
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
-
- Posts: 2
- Joined: April 17th, 2025, 9:11 pm
[DEVLOG] Procedural Co-Op Labyrinth
Hi everyone,I’m working on a somewhat crazy project for Battle for Wesnoth, and I thought this would be a good time to share a first devlog.
DISCLAIMER: This post was partially written using ChatGPT, both for convenience and due to technical limitations (I only speak Italian and have many gaps in English).
1_ Goal
-A system for generating infinite, replayable labyrinths in Wesnoth
-Balanced maps for co-op or singleplayer
-Maybe even a fully working survival-style mini-roguelike
the concept started as a simple, static 200x200 map: a large labyrinth with tight corridors and 1x1 paths.
But soon I wanted to push it further:
Each time the map is loaded, a brand new maze is created — complete with dead ends, guaranteed paths, and four exits placed at the corners.
The goal is to escape the maze starting from the center.
Ironically, this scripting part — which seemed the hardest — was the first to work right away.
2_ Current Status: functional but very incomplete
There is currently only one playable version, but it's in a very early, embryonic state.
What works:
-The 200x200 map generates correctly
-The labyrinth layout is coherent and follows the 1x1 corridor structure
-The central spawn area and exit/center generation are reliable
-All 4 exits are reachable and pathing works as intended
What doesn’t work (or is completely missing):
-No enemies or NPCs
-Win and lose conditions are incorrect or missing entirely
-In-game settings don’t work: they are disabled by default due to the scenario type being “singleplayer campaign” (issue traced to _main.cfg)
3_ The biggest problem: the _main.cfg file
One of the most frustrating (and still unresolved) issues is the _main.cfg file.
I'm trying to get the map to show up properly in the game menu, but:
-The file doesn’t load correctly
-The map either appears in the wrong menu category, or doesn’t appear at all
I’ve followed the structure of working add-ons, but something’s still off.
And worst of all: since I use ChatGPT as my main assistant, it sometimes suggests fake tags, made-up attributes, or invalid WML structures — leading to false positives and endless debugging loops.
Additionally:
-Based on my tests, the average minimum turn count to reach a corner of the 200x200 maze is between 200 and 500 turns
-Adding fog of war and enemies would push this to 650+ turns, which is insane and completely unplayable
-In comparison, a 50x50 labyrinth takes around 25 turns
This could be fixed by resizing the map (e.g. 64x64 or 80x80), but at the moment I can’t change the map dimensions without breaking the generation algorithm.
My ideal target duration for a full playthrough — with fog, enemies, and full features — is around 80 to 90 turns max.
I don’t know WML or Lua very well (I’m learning day by day), but with ChatGPT and many experiments I’ve already achieved some solid results. I work in iterations, fix bugs as I go, and little by little the labyrinth is taking shape.
4_ What I need to continue the project
-Someone willing to look at the map and give feedback
-Anyone open to writing even a small Lua or WML function
-Technical advice on add-ons, procedural generation, gameplay/balance, or just good prompts for using ChatGPT effectively Even a few minutes of your time would be extremely helpful.
Thanks to anyone who read this far.
Draft:
DISCLAIMER: This post was partially written using ChatGPT, both for convenience and due to technical limitations (I only speak Italian and have many gaps in English).
1_ Goal
-A system for generating infinite, replayable labyrinths in Wesnoth
-Balanced maps for co-op or singleplayer
-Maybe even a fully working survival-style mini-roguelike
the concept started as a simple, static 200x200 map: a large labyrinth with tight corridors and 1x1 paths.
But soon I wanted to push it further:
So I built a unicursal maze using Lua scripting.“What if it was procedurally generated every time?”
Each time the map is loaded, a brand new maze is created — complete with dead ends, guaranteed paths, and four exits placed at the corners.
The goal is to escape the maze starting from the center.
Ironically, this scripting part — which seemed the hardest — was the first to work right away.
2_ Current Status: functional but very incomplete
There is currently only one playable version, but it's in a very early, embryonic state.
What works:
-The 200x200 map generates correctly
-The labyrinth layout is coherent and follows the 1x1 corridor structure
-The central spawn area and exit/center generation are reliable
-All 4 exits are reachable and pathing works as intended
What doesn’t work (or is completely missing):
-No enemies or NPCs
-Win and lose conditions are incorrect or missing entirely
-In-game settings don’t work: they are disabled by default due to the scenario type being “singleplayer campaign” (issue traced to _main.cfg)
3_ The biggest problem: the _main.cfg file
One of the most frustrating (and still unresolved) issues is the _main.cfg file.
I'm trying to get the map to show up properly in the game menu, but:
-The file doesn’t load correctly
-The map either appears in the wrong menu category, or doesn’t appear at all
I’ve followed the structure of working add-ons, but something’s still off.
And worst of all: since I use ChatGPT as my main assistant, it sometimes suggests fake tags, made-up attributes, or invalid WML structures — leading to false positives and endless debugging loops.
Additionally:
-Based on my tests, the average minimum turn count to reach a corner of the 200x200 maze is between 200 and 500 turns
-Adding fog of war and enemies would push this to 650+ turns, which is insane and completely unplayable
-In comparison, a 50x50 labyrinth takes around 25 turns
This could be fixed by resizing the map (e.g. 64x64 or 80x80), but at the moment I can’t change the map dimensions without breaking the generation algorithm.
My ideal target duration for a full playthrough — with fog, enemies, and full features — is around 80 to 90 turns max.
I don’t know WML or Lua very well (I’m learning day by day), but with ChatGPT and many experiments I’ve already achieved some solid results. I work in iterations, fix bugs as I go, and little by little the labyrinth is taking shape.
4_ What I need to continue the project
-Someone willing to look at the map and give feedback
-Anyone open to writing even a small Lua or WML function
-Technical advice on add-ons, procedural generation, gameplay/balance, or just good prompts for using ChatGPT effectively Even a few minutes of your time would be extremely helpful.
Thanks to anyone who read this far.
Draft:
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: [DEVLOG] Procedural Co-Op Labyrinth
I can't imagine this. I can't imagine code that is so bad that you can't change it that way. The size should be a variable that you can change everywhere by modifying one line of code. This is very important for testing. To test this add-on, you will need to play it many times, so you need to have the ability to make the map tiny to test new features. You want to be able to play in only four or five turns. I will take a look at your code and see if I can fix that part because I am curious what the code looks like. If I help, I will need the full add-on. I don't want something that I cannot open and test in the game.asdinobello wrote: ↑June 5th, 2025, 5:47 pm I can’t change the map dimensions without breaking the generation algorithm.
You should not be using chatGPT to write WML. You have already seen the problems. I suggest downloading "WML Guide." It has code with many explanatory notes. You can learn how use WML to add enemies, fog of war, messages, and other things. That would be faster and less frustrating than using AI. You will need to translate the notes in the code, but that shouldn't be difficult if you have a little knowledge of English.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
-
- Posts: 2
- Joined: April 17th, 2025, 9:11 pm
Re: [DEVLOG] Procedural Co-Op Labyrinth
Hi, thanks for feedback.
map size can be changed I actually did it myself, but unfortunately, it caused major issues like unreachable exits or misaligned positions.
I don’t really understand code, but I believe the procedural algorithm is worth looking into.
let me know what you think, but I warn, code is
as you can well imagine, starting from map_data and as you also said: code notes are in Italian
map size can be changed I actually did it myself, but unfortunately, it caused major issues like unreachable exits or misaligned positions.
I don’t really understand code, but I believe the procedural algorithm is worth looking into.
let me know what you think, but I warn, code is
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: [DEVLOG] Procedural Co-Op Labyrinth
I would like to say things in a nicer way, but I assume you will translate my message, and I don't want the meaning to be lost.
I think I will have time this weekend. If you want, I will see if I can rewrite the map generator and scenario file so that it makes sense (and is 10 times shorter). I can't promise that I will be able to in the time I have, but I can give it a try.
It was immediately obvious to me why this happens, but I won't just change the relevant numbers. Your problems are going to get worse than this. If you can't fix this easy one, then you don't have the experience to fix harder ones either.asdinobello wrote: ↑June 6th, 2025, 4:28 am map size can be changed I actually did it myself, but unfortunately, it caused major issues like unreachable exits or misaligned positions.
I can see that you're right, and you will not be able to finish this project without that knowledge. You need to learn some basics at least. Make a simple campaign that you can play and that shows up in the menu correctly. (You can use WMLGuide as a foundation for this.) That is the easy step. Next, work through a Lua tutorial online so you can write the map generator you want. That is the harder step. This will take you several days, but it will save you weeks of frustration later. I am sure that you cannot complete the rest of the project with the method you are trying to use.
It is worse than you think. It does things, and then undoes them right away. The variable names seem random, and don't describe what they are for. Nothing is in the normal place. Wesnoth has a structure for including a lua map generator, and you are not using it. I can't fix this code. I could only rewrite it from the beginning.asdinobello wrote: ↑June 6th, 2025, 4:28 amlet me know what you think, but I warn, code isas you can well imagine
I think I will have time this weekend. If you want, I will see if I can rewrite the map generator and scenario file so that it makes sense (and is 10 times shorter). I can't promise that I will be able to in the time I have, but I can give it a try.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: [DEVLOG] Procedural Co-Op Labyrinth
What you sent me today is much closer to a standard Wesnoth campaign. You don't really need all the empty folders though. I would put the Lua code in utils.
I found some time last night and fixed all the code from before. I used it as a challenge for myself and a way to practice Lua coding. Use it if you want. I won't be offended if you don't use it.
Now the maze dimensions are defined one time in the [scenario] file, which is what I intended to fix from the beginning. Also, the Lua code runs a standard map generator instead of changing the running map, so it's much faster. I made the center map area separate, so now you can load it in the Wesnoth map editor. You can add the corners by using the editor and [terrain_mask] the same way I did for the center. This version doesn't incorporate all your newer scenario code, so I will leave that up to you to add.
I'm off to work now.
I found some time last night and fixed all the code from before. I used it as a challenge for myself and a way to practice Lua coding. Use it if you want. I won't be offended if you don't use it.
Now the maze dimensions are defined one time in the [scenario] file, which is what I intended to fix from the beginning. Also, the Lua code runs a standard map generator instead of changing the running map, so it's much faster. I made the center map area separate, so now you can load it in the Wesnoth map editor. You can add the corners by using the editor and [terrain_mask] the same way I did for the center. This version doesn't incorporate all your newer scenario code, so I will leave that up to you to add.
I'm off to work now.
- Attachments
-
Procedural_Maze.zip
- (9.47 KiB) Downloaded 8 times
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide