How MarkovJunior Generates Endless Unique Mazes for Games
MarkovJunior, a probabilistic programming language based on Markov algorithms, can automatically create countless non‑repeating 2D and 3D mazes, terrain maps, and circuit diagrams for games, using simple rewrite rules and a single line of code.
Exploring mazes in games can become stale, but the newly released probabilistic programming language MarkovJunior solves this by using Markov algorithms to randomly generate batches of unique mazes, both 2D and 3D, so players never know what the next maze will look like.
The project quickly rose to the GitHub trending list, earning 2.6k stars within a week, and users report that it can directly generate buildings for RPG or action games; even the author of Keras has expressed interest.
Construction Based on Markov Algorithms
The language borrows the Markov algorithm (named after mathematician Andrey Markov) and consists of an ordered list of rewrite rules. During model generation, the Markov algorithm provides the randomness, while the rewrite rules determine the type of model—maze, terrain map, circuit diagram, etc.
Markov chains have a “memoryless” property: the probability distribution of the next state depends only on the current state, not on any previous events.
Typical rewrite rules include turning black blocks into white blocks, or converting a white‑black pattern into white‑white, which, combined with the Markov algorithm, yields probabilistic generation models.
2D/3D Mazes, Terrain Maps and Circuit Diagrams
For a 2D maze, the algorithm places a red start point and randomly rewrites paths until the whole black map is filled, creating a maze with branches and an endpoint.
Two simple rules are enough:
Rule 1 : randomly rewrite “red‑black‑black” into “green‑green‑red”.
Rule 2 : when Rule 1 cannot apply, rewrite “red‑green‑green” into “white‑white‑red”.
These rules let the algorithm generate a random path, backtrack to create branches, and eventually fill the entire map, producing a complete 2D maze. A single line of code can also generate 2D or 3D mazes.
By adjusting the rule set, the same system can produce random terrain maps (e.g., rivers) and even 3D buildings by inserting staircases between two 2D maze layers. Circuit diagrams can also be drawn using appropriate rules.
According to the author, flexible use of these rules enables MarkovJunior to randomly generate a wide variety of structures and drawings.
The Creator Behind the Famous WFC Algorithm
MarkovJunior was created by Maxim Gumin, an independent game developer best known for the Wave Function Collapse (WFC) algorithm, which has attracted 18.7k stars on GitHub and inspired games such as Townscaper.
WFC was inspired by the quantum‑mechanics concept of wave‑function collapse and has been applied in several games.
Project links: https://github.com/mxgmn/MarkovJunior . References: Twitter , WFC GitHub , YouTube , Keras tweet .
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
