Procedural map generation From ASCII to Prefabs
Summary In this article I describe the design and implementation of a procedural map generation system developed as a vertical slice for an indie studio. The text covers the initial and evolved constraints, the workflow from an ASCII prototype to prefab generation in Unity, door and room logic, and proposed improvements. I also include information about Q2BSTUDIO, a company specialized in custom software development, custom applications, artificial intelligence, cybersecurity, and AWS and Azure cloud services.
Key constraints that guided the design To make the maps playable and coherent, we defined constraints that guided every decision. Initially, we sought simplicity and robustness. Initial constraints included not generating wide hallways because rooms are placed adjacent without intermediate spaces, requiring each room to occupy an n by n square cell, and allowing random door placement on edges. Over time, the rules evolved to fix door positions and give the designer control over connectivity and level topology.
Challenges solved The biggest challenges were fitting rooms of different sizes into a grid without overlaps, avoiding door locations that were inaccessible or illogical, and balancing randomness with design intent. These constraints made it possible to support complex room shapes and guarantee deterministic layouts when necessary.
Step-by-step workflow I started with an ASCII system to visualize the grid quickly and effectively. That textual prototype facilitated debugging and experimentation. With a monospaced font, the result was clear and reproducible. From there, I implemented random room placement, ensuring they did not overlap, which established the foundation for the system.
Introduction of doors At first, doors were placed randomly on walls, but this created connectivity problems and conflicting corners. Constraints were added to prevent doors in corners and rules to align opposite doors when necessary. Later, we moved from random doors to fixed positions defined by templates, improving coherence between rooms and making the designer's work easier.
Transition to prefabs Translating ASCII coordinates to positions in Unity's 3D world was a significant leap. Scaling and pivots had to be adjusted so that walls, floors, and doors fit exactly. During this phase, I created room templates in Unity that allowed designers to reuse formats and maintain visual and gameplay consistency.
Refactoring and property containers I refactored the door logic and added a property container for each room that includes size, type, and door positions. This allowed dynamically switching from random doors to fixed doors and adding metadata such as start room, exit room, or thematic puzzle rooms.
Tools for designers To improve usability, I added gizmos and visual indicators that represent doors and traversable spaces in the editor just as they appear in the ASCII map. Thus, doors in the ASCII view corresponded to openings in the prefabs, facilitating quick adjustments by design.
Thematic and gameplay elements I incorporated specialized room types: entrances, exits, puzzles, and reward rooms. Logic was added to clearly define the start room and exit room and to classify templates that serve specific level objectives. This helps generate maps with coherent gameplay flow.
Planned improvements Future improvements include optimizing room placement, which currently scales in the order of n squared, offering more precise gizmos, expanding the room library, allowing room rotation, and integrating AI navigation via nav mesh. It is also desirable to add more tools to connect procedural generation with artificial intelligence systems and AI agents that enrich the experience.
ASCII system explained The ASCII representation works as a grid where each character symbolizes a map element. We use, for example, a corner symbol, a wall symbol, and a traversable space symbol. The visualization uses a monospaced font to maintain alignment. The coordinate origin is located in the bottom-left corner, which simplifies generation and conversion to mathematical coordinates in Unity.
Sizes and wall logic Each room is defined as an n by n square block where the interior traversable space is n minus two by n minus two, and the total area occupied in the grid includes the walls. In ASCII, wall thickness is one unit, while in the 3D world the wall is scaled to 0.5 units and the bottom-left corner pivot is shifted for exact alignment.
Avoiding wide hallways By placing doors on walls in the ASCII representation, connections are prevented from generating unwanted two-cell-wide hallways, and a one-tile hallway is guaranteed when appropriate.
Placement validation The placement algorithm first checks that the grid has enough space and then that the traversable cells are not occupied. If placement fails, the reason is logged and the room is skipped. This avoids overlaps and maintains level integrity.
Door logic and connectivity In random mode, doors are placed on walls, avoiding corners. In fixed-door mode, each template includes a list of valid positions. To place a new room, a local door is taken, a corresponding door from the candidate room is chosen, the pivot position is calculated by subtracting coordinates, and it is validated that the room does not collide with already occupied cells. If validation is correct, the room is added and the grid is updated.
Complexity and optimization Currently, checking door pairs scales as n squared with respect to the number of doors, so we propose limiting checks to doors in the immediate vicinity, indexing doors by region, or categorizing doors with NSWE orientation to reduce combinatorics. These optimizations will improve performance in levels with many rooms.
Example flow A typical flow places the first room at the origin, then for each open door, connections with other templates are tested by calculating pivots and performing validation. If a room does not fit, it is logged and we continue. With fixed doors, deterministic and predictable layouts are obtained, which facilitates design control and the creation of non-rectangular shapes such as L-shaped rooms.
Benefits of fixed doors Fixed positions offer deterministic layouts, support for rooms with complex shapes, and direct control for designers who want to adjust connectivity. This is especially useful when integrating narrative content or specific challenges in particular locations.
Practical considerations for integration To bring the system to production, it is advisable to add support for AI navigation, generate nav mesh after level assembly, integrate business intelligence services to analyze generation metrics, and open APIs for AI agents that can modify topologies in real time. Q2BSTUDIO can help integrate these capabilities by offering custom software solutions that include AWS and Azure cloud services and consulting in artificial intelligence and cybersecurity.
About Q2BSTUDIO Q2BSTUDIO is a custom software development company with experience in custom applications, custom software, and integrated solutions. We are specialists in artificial intelligence (AI) for businesses, AI agents, and Power BI for advanced analytics. We also offer cybersecurity services, AWS and Azure cloud services, and business intelligence services. We can support procedural generation projects from architecture to integration in production environments, ensuring good security and scalability practices.
Keywords for positioning Custom applications, custom software, artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for businesses, AI agents, Power BI.
Conclusion Procedural map generation that goes from an ASCII prototype to prefabs in Unity allows for rapid iteration, validation of placement rules, and gives designers control over connectivity through fixed doors. With a robust implementation and improvements in performance and design tools, this approach is ideal for creating varied and playable levels. If you are looking for support to bring this solution to production, Q2BSTUDIO can provide custom development, AI integration and security, and deployment on AWS and Azure cloud services.



