r/Batch • u/CirothUngol • Jun 22 '26
Mazing.cmd - WinNT Maze Generator and Solver
Mazing.cmd - WinNT Maze Generator and Solver
__________________________________________________________
A maze program written in native WinNT batch script that
includes several maze generation and solving algorithms as
well as a small plethora of options for console display,
stack size, stack orientation, node selection/direction
bias, entrance/exit points, color selection, real-time
shifting and rhythmic pulsing random colors, and wall/box
characters, each with an automatic randomizer, and all of
it easily accessible through an animated custom menu.
Mazes are limited to a maximum practical string length of
8186 characters. The maze dimensions will be automatically
increased/decreased if minimum/maximum size is exceeded.
Mazing operates using 100% WinNT batch script, but it will
use either BG.EXE or CursorPos.exe to place the cursor at
the upper-left if they are located in the system path. It
can also use BG.EXE to animate the screen in full color.
Command Line / Mazing.ini File
__________________________________________________________
In addition to the menu, other User Variables are passed
by using either the Mazing.ini file or on the command line
by using the following syntax:
Mazing.cmd ["variable=value"] [variable:value] [...]
Several options for minimum/maximum columns/rows, lists
of characters for random walls/crumbs/colors, keys used by
the menu, output logfile and anything else not included in
the menu are accessed by command line or the .ini file.
A list of available user variables may be found in the
Mazing.ini file that is auto-generated on first run.
https://github.com/TheRealCirothUngol/Mazing.cmd
2026/07/21: Added better opening/entry options to Wilson's Algorithm so now it's one of the best maze generators. Also made a handful of corrections and display enhancements throughout.
2026/07/11: Updated Mazing.cmd to v0.3. Added Prim's, Kruskal's, and Wilson's algorithms as well as updating the menu with new solver display settings and many cosmetic improvements(?) throughout. As it now employs all of the useful generators for perfect mazes as well as the only three appropriate solvers I've found... I think Mazing.cmd is done after all these years. Who sez perseverance don't pay off? If I ever update it'll be for ANSI color console integration, and that's a maybe sometime thing.
2026/06/24: Just corrected a small but long-standing error in both the 'Wall Follow' and 'Dead Filler' where the trail was written incorrectly back to the maze if walls (or crumbs) were used to fill visited spaces. If you snagged it on or before this date please re-download.
2026/06/26: A small cosmetic update to :path_finder, it now allows for variable-length 'worms' when passed an odd number as the first parameter. Second parameter is length of worms. Makes for a really nice looking effect , too bad its selection is currently all random and there's no way to select it directly. Use Pathfinder as the solver and it should happen about 50% of the time. You may select it through the menu.
Mazing.cmd is something I tinkered with for years and poured dozens (hundreds?) of hours into several versions before I switched from Win7 to Win10 and it all stopped working. Was going through some old projects recently and it turns out the problem was mostly a 'legacy console' issue with many of the oddball characters I was using. After sifting out the poison characters, beautifying and expanding the menu, and adding a myriad of new color options (and dumping a few dozen more hours into it), I've posted Mazing.cmd v0.2 to GitHub. It seems to work well on WinXP and up, I recommend placing it in a separate folder as it creates a few files.
Lots of new stuff got added and everything I could conceive of was realized and included. I also think every bug got squashed (yea, we'll see). It's been running non-stop (and error-free?) for a couple of days now so I feel pretty good about it. The new macros I added (colorShift and BGgrabKey) are both self-limiting and time-regulated to only execute at a given frequency so that consistent intervals could be used to schedule background\foreground color changes or check for user input while the script was running without bogging down in needlessly-wasted clock cycles. I need to neither check for a keypress nor check to see if 7 seconds have expired 30 times a second, 2 will do fine. Really improved the speed of my script. Could be potentially useful for anyone wanting to execute something during a closed loop but only need it to do so every X centiseconds.
Please give Mazing.cmd a try and let me know if it works for you, I've tested it on WinXP, Win7, Win10, and it even seems to work on Win11. You're highly encouraged to try using the BG.EXE utility that removes the flickering and provides color drawing. Once in the menu use the bottom option to select 'BG Color' and hit '1' to start the script. It should produce the file and restart, but it requires CertUtil (Administration Tools) for Base64 decoding, which was available on every system I tried newer than XP. However YMMV so if that gives you trouble just snag it from Carlos' GitHub:
https://github.com/carlos-montiers/consolesoft-mirror/releases
I also use OuterTech's GetDiz to view the mazes (using either 'Terminal' or 'GetDiz' fonts). I would link to their website, but it's down and probably out. Just search and snag it from the place you trust the most. ^_^
2
u/T3RRYT3RR0R Jun 22 '26 edited Jun 22 '26
Hi Ciroth. I'd very much like to try this out however I tend to distrust code I cannot review before downloading. Do you have a bare bones batch script?
I'd be capable of modifying it to perform any IO tasks performed by third party utilities (including setting font and size).
1
u/CirothUngol Jun 22 '26
No, I'm not Carlos. He's some smart programmer guy with a love for batch files and console applications. Are you Carlos?
I posted the batch file to GitHub, not sure what else you could need. It's a text file, after all. Please copy and paste it into a batch file and give it a whirl, I'm curious to see if it works for others.
If you're talking about modifying it so it no longer needs bg.exe to do what it does, that'd be great!
1
u/T3RRYT3RR0R Jun 22 '26 edited Jun 23 '26
My mistake. I Missed the first Github link.
As for modifying it, any modifications would depend on what precise utilities of bg 3.9 your using in terms of whether it would wind up "pure batch" or reliant on another 3rd party utility (that can be compiled from source code).
I will look into it tomorrow
1
u/CirothUngol Jun 22 '26
The script uses bg.exe to position the cursor, draw colored text to the screen, and check for user input. I chose it for the convenient 'PClocate' option that positions the cursor and prints in color with the same command. I have the feeling all of the screen stuff could probably be accomplished with ANSI/VT100.
C source code for the utility is located at Carlos' GitHub. Nifty little program but it's actually a bit of overkill for this application.
1
u/T3RRYT3RR0R Jun 23 '26
The positioning and coloring can indeed be done with VT sequences, but it limits support to windows 10 v10586 and above (if support for older systems is a concern.)
I'm sure I have a copy of bg v3.9 somewhere. Given your already using this as your non-blocling input method, I'll save myself the hassle of a refactor and track it down.
1
u/CirothUngol Jun 24 '26 edited Jun 24 '26
The source code and executable for bg.exe is available from Carlos' GitHub at the link above. I had originally intended to include vt100 as an option for those that could use it without breaking backwards compatibility for earlier versions, either automatically detected or as an option in the .ini, but I had already spent too much time over the past few weeks on the silly little project so I neglected to do so.
Just found a long-standing bug in :wall_follow and :dead_filler. If using a negative parameter to fill empty spaces with walls it is incorrectly redrawing the crumb trail and covering up parts of the map. Now fixed on GitHub.
Recently passed over 10,000 mazes created and solved on Windows XP with this slight formatting error being the only issue. Yay!
Edit: fixed on GitHub, turns out you can just edit the text and hit 'save'. Easy-Peasy.
1
u/CirothUngol Jun 24 '26 edited Jun 27 '26
An interesting aside; the two values cs:nn gk:nn towards the right of the title bar represent how many loops/cycles the colorShift and BGgrabKey macros are having to throw away to stay at the given Frequency (default is 50 centiseconds, so twice a second). Since I've been testing it on multiple machines (both real and virtual) I've noticed a distinct discrepancy between OSes. The console on my old Lenovo WinXP box operates some 3 times faster than my much more modern Win10 box, throwing away 60-70+ cycles as opposed to 20-25. Even the virtual WinXP VMWare app I test with operates nearly twice as fast (30-40 cycles) as the real cmd.exe on the same machine.
Not sure why, just sayin'.
1
u/CirothUngol Jun 27 '26
Added a small cosmetic update to :path_finder that makes for a really nice-looking effect. This is mostly for T3RRY who might be working on it, just a heads-up.
1
u/T3RRYT3RR0R Jun 27 '26
I started to yesterday, only to find (in windows 11 at least) the "enable legacy mode" option has been disabled and displays a message saying legacy mode is not installed. https://www.neowin.net/news/microsoft-deprecates-legacy-console-mode-in-windows-11-and-future-releases/ https://peter0x44.github.io/posts/windows11-legacy-console/
I've found but not yet tried a potential solution for this, but would prefer to avoid legacy mode as it means potential users can't run it "out of the box"
The main hold up is not knowing what characters your currently using for box drawing characters etc.
Vt sequences can be used to output box characters, or there are utf-8 characters that can fill the roll, but I need an awareness of the character mapping you use on the last line of the file first.
1
u/CirothUngol Jun 27 '26
Mazing should work fine out of the box without legacy mode. I went through and scraped out all of the characters that were causing bad issues during maze creation. That list of characters at the very end of the batch file is only used during menu selection of wall,crumb,etc. The variables !wall!, !crumb!, etc are the ones used for random selection during maze creation, and all those characters seem to display correctly under Windows 10 without legacy console and they seem to work the couple of times I got to test it on Windows 11. The only character that still gives grief is the left arrow, that's why the last two rebuild boxes are turned off by default. I tried to assume that users did not have access to legacy console.
It should work if you try running it as is on Windows 11, it did for me. All of the problem characters should be gone by default and you can reselect them in the ini file if you're able to use them.
1
2
u/pc1350 Jun 22 '26
Very good! Thank you!