{"id":742,"date":"2014-06-13T06:21:55","date_gmt":"2014-06-12T22:21:55","guid":{"rendered":"http:\/\/www.gridsagegames.com\/blog\/?p=742"},"modified":"2014-09-09T21:52:24","modified_gmt":"2014-09-09T13:52:24","slug":"procedural-map-generation","status":"publish","type":"post","link":"https:\/\/www.gridsagegames.com\/blog\/2014\/06\/procedural-map-generation\/","title":{"rendered":"Procedural Map Generation"},"content":{"rendered":"<p>Procedurally generated maps are a core feature of roguelikes. For a genre that is almost synonymous with &#8220;randomness&#8221; (within reason), randomized maps are the easiest way to broadly manifest that key element since maps affect many aspects of gameplay from exploration strategy and tactical positioning to item and enemy locations.<\/p>\n<p>Notice how walkthroughs for strategy games need only mark key locations on an overview map and indicate what to do where--you can win every time by following that series of steps. While players can enjoy having multiple attempts to solve what is essentially a glorified puzzle, no matter how fun the game is it will come to an end once all the solutions are found.<\/p>\n<p>So randomized maps give us infinite replayability by providing different challenges every time, not to mention the extra satisfaction from overcoming less spoilable challenges where player progress is measured by personal skill rather than trial-and-error. That the layout of every new map is 100% unknown also lends a good amount of suspense to exploration.<\/p>\n<p>Of course the benefits of procedural maps are pointless without sufficient variety in mechanics and content to make multiple playthroughs worthwhile--the same old hack-and-slash affair won&#8217;t do. Hence any roguelikes that survive the test of time will have deep gameplay, too.<\/p>\n<p>Lately I&#8217;ve turned my attention to Cogmind&#8217;s map generation, so here begins a series of posts on the topic.<\/p>\n<h2>Methods<\/h1>\n<p>There is a wide variety of methods for generating maps. Naturally no single method is suitable for all purposes, thus most developers will end up tweaking whatever method(s) they choose to fit the needs of their game more closely. Of course designing a method from scratch is also possible, though conceptually a few of the common ones are a good place to start exploring the topic.<\/p>\n<p>There&#8217;s no need to go into implementation details here since that&#8217;s already been done all over the web; instead I&#8217;ll just link to the source of each image where you can find an explanation.<\/p>\n<h3>BSP Trees<\/h2>\n<p><a title=\"Binary Space Partitioning\" href=\"http:\/\/en.wikipedia.org\/wiki\/Binary_space_partitioning\" target=\"_blank\">BSP trees<\/a> can be used to create some of the simplest and most immediately recognizable roguelike maps--rectangular rooms attached to one another by corridors.<\/p>\n<div id=\"attachment_748\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_bsp1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-748\" class=\"wp-image-748 \" title=\"Dungeon Generation: BSP Tree\" alt=\"mapgen_bsp1\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_bsp1.png\" width=\"400\" height=\"400\" \/><\/a><p id=\"caption-attachment-748\" class=\"wp-caption-text\">BSP Tree, Example 1 (<a href=\"http:\/\/eskerda.com\/bsp-dungeon-generation\/\">source<\/a>)<\/p><\/div>\n<div id=\"attachment_749\" style=\"width: 490px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_bsp2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-749\" class=\"wp-image-749 \" title=\"Dungeon Generation: BSP Tree\" alt=\"mapgen_bsp2\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_bsp2.png\" width=\"480\" height=\"360\" \/><\/a><p id=\"caption-attachment-749\" class=\"wp-caption-text\">BSP Tree, Example 2 (<a href=\"http:\/\/gamedevelopment.tutsplus.com\/tutorials\/how-to-use-bsp-trees-to-generate-game-maps--gamedev-12268\">source<\/a>)<\/p><\/div>\n<h3>Tunneling Algorithms<\/h2>\n<p>Tunneling algorithms dig corridors and rooms out of solid terrain, much as a real dungeon architect might. Except for the often useless or redundant pathways&#8230;<\/p>\n<div id=\"attachment_752\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_tunneler.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-752\" class=\"size-full wp-image-752  \" title=\"Dungeon Generation: Tunneler\" alt=\"mapgen_tunneler\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_tunneler.png\" width=\"400\" height=\"400\" \/><\/a><p id=\"caption-attachment-752\" class=\"wp-caption-text\">Tunneler Example (<a href=\"http:\/\/dungeonmaker.sourceforge.net\/DM2_Manual\/manual1.html\">source<\/a>)<\/p><\/div>\n<p>Drunkard&#8217;s Walk, a highly-randomized tunneling algorithm, is useful for creating cave-like environments with a mix of open and narrow areas.<\/p>\n<div id=\"attachment_744\" style=\"width: 546px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_drunkard1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-744\" class=\"wp-image-744    \" title=\"Dungeon Generation: Drunkard's Walk\" alt=\"mapgen_drunkard1\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_drunkard1.png\" width=\"536\" height=\"371\" \/><\/a><p id=\"caption-attachment-744\" class=\"wp-caption-text\">Drunkard&#8217;s Walk, Example 1 (<a href=\"http:\/\/forums.roguetemple.com\/index.php?topic=4128.0\">source<\/a>)<\/p><\/div>\n<div id=\"attachment_745\" style=\"width: 321px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_drunkard2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-745\" class=\"size-full wp-image-745 \" title=\"Dungeon Generation: Drunkard's Walk\" alt=\"mapgen_drunkard2\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_drunkard2.png\" width=\"311\" height=\"410\" \/><\/a><p id=\"caption-attachment-745\" class=\"wp-caption-text\">Drunkard&#8217;s Walk, Example 2 (<a href=\"http:\/\/www.roguebasin.com\/index.php?title=Random_Walk_Cave_Generation\">source<\/a>)<\/p><\/div>\n<h3>Cellular Automata<\/h2>\n<p><a title=\"Cellular Automaton\" href=\"http:\/\/en.wikipedia.org\/wiki\/Cellular_automaton\" target=\"_blank\">Cellular automata<\/a> are great for digging natural-looking cave systems. Unlike other methods you have to find a way to ensure connectivity in a post-generation phase, since certain algorithms are likely to produce disconnected areas.<\/p>\n<div id=\"attachment_746\" style=\"width: 394px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_automata1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-746\" class=\"wp-image-746 \" title=\"Dungeon Generation: Cellular Automata\" alt=\"mapgen_automata1\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_automata1.png\" width=\"384\" height=\"384\" \/><\/a><p id=\"caption-attachment-746\" class=\"wp-caption-text\">Cellular Automata, Example 1 (<a href=\"http:\/\/gamedevelopment.tutsplus.com\/tutorials\/generate-random-cave-levels-using-cellular-automata--gamedev-9664\">source<\/a>)<\/p><\/div>\n<div id=\"attachment_747\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_automata2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-747\" class=\"wp-image-747 \" title=\"Dungeon Generation: Cellular Automata\" alt=\"mapgen_automata2\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_automata2.png\" width=\"490\" height=\"427\" \/><\/a><p id=\"caption-attachment-747\" class=\"wp-caption-text\">Cellular Automata, Example 2 (<a href=\"http:\/\/www.roguebasin.com\/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels\">source<\/a>)<\/p><\/div>\n<p>As you can see from the types listed above, what I&#8217;m really talking about here is procedural <em>dungeon<\/em> generation. Most roguelikes take place beneath the ground, which makes sense from a design standpoint. The highly random nature of roguelikes means it&#8217;s likely that at some point (many points&#8230;) the player will face an encounter for which they are woefully unprepared and must escape. Underground environments offer a greater amount of negative space that can be used to control what can and cannot be seen or reached from a certain vantage point, and all of it shown in an easy-to-digest manner, e.g. rectangular rooms, corridors, and cavern walls. Compartmentalizing encounters into rooms enables dungeons to provide a tighter experience, fitting more content within a smaller overall area. Sure one encounter may very well spill over into the next when you start running for your life, but that&#8217;s why every experienced rogueliker will tell you to never flee into the unknown!<\/p>\n<h2>Design<\/h1>\n<p>Beyond choosing a method of generation (or mixing multiple methods), any number of parameters must be established and tweaked to produce layouts that work for the gameplay. Many small rooms or fewer large rooms? Lots of long corridors, or no corridors at all, just rooms separated by doors? An expansive winding cave system that draws the player to explore and lose themselves in it, or a mostly linear cavern contoured as it is for the atmosphere?<\/p>\n<p>Map layout isn&#8217;t just about theme, it reflects how the game (or sub-area) plays. Many roguelikes have fairly small rooms and narrow corridors due to a high percentage of close-range combat. Cogmind is mostly ranged combat, so wider corridors and large rooms are much more common to give combatants room to find a shot.<\/p>\n<h3>Exploration &amp; Fun<\/h2>\n<p>Aside from designing maps that complement game mechanics, it&#8217;s also important to consider available travel routes from one encounter to the next. Unpopulated rooms and corridors actually do serve a purpose, as there doesn&#8217;t need to be a fight around every corner. Real players do need some rest, or more importantly some extra space to work with when things aren&#8217;t going according to plan. In Cogmind in particular that extra space is also useful for taking the stealth approach--with the right components and know-how many confrontations can be avoided entirely.<\/p>\n<p>But the primary factor I pay attention to when tweaking map parameters is the number and density of loops. By loops I mean places where multiple pathways reach the same destination. A map with few or no loops in its layout will require lots of backtracking, and backtracking is <em>not<\/em> fun! Players may still choose to travel along previous paths be it to gather items or escape an enemy, but taking the same route multiple times shouldn&#8217;t be <em>forced<\/em> on them. Long paths that lead to dead ends had better at least contain treasure or access to a new area. Cogmind has some fairly large maps by roguelike standards, so I have to be especially cognizant of pointless pathways.<\/p>\n<p>This is good opportunity to point out that while developing and tweaking a map generator is often done outside the game itself so you can see the entire thing and examine it from a higher level, the fact that a map &#8220;looks good&#8221; can be misleading and is rarely something that players notice once inside the thing, anyway. Inside it may not be fun at all!<\/p>\n<div id=\"attachment_760\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_deadends.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-760\" class=\"size-full wp-image-760 \" title=\"Dungeon Generation: Too Many Dead Ends\" alt=\"mapgen_deadends\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_deadends.png\" width=\"400\" height=\"400\" \/><\/a><p id=\"caption-attachment-760\" class=\"wp-caption-text\">Here&#8217;s a map that doesn&#8217;t look too bad as a cave system but wouldn&#8217;t be very fun to play without the right mechanics--waaay too many long dead ends.<\/p><\/div>\n<p>Testing a map for connectivity post generation is an important step in determining whether to use that map (more on that in a future post). Some more complex procedural methods can build that requirement into the generation process itself:<\/p>\n<div id=\"attachment_759\" style=\"width: 557px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_complex.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-759\" class=\"size-full wp-image-759 \" title=\"Dungeon Generation: Complex\/Graphs\" alt=\"mapgen_complex\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/mapgen_complex.png\" width=\"547\" height=\"483\" \/><\/a><p id=\"caption-attachment-759\" class=\"wp-caption-text\">A graph-based map generation technique that ensures a general number of loops (<a href=\"http:\/\/www.reddit.com\/r\/gamedev\/comments\/1dlwc4\/procedural_dungeon_generation_algorithm_explained\/\">source<\/a>).<\/p><\/div>\n<h2>Content<\/h1>\n<p>How we decide what to put where in these maps is another big issue, obviously a very game-specific one. Randomly spawning objects everywhere could be fun (heck, that&#8217;s what I did for the 7DRL!), but the most enjoyable experience can only come by considering the terrain and choosing locations with a purpose. This step is often dependent on dungeon metrics, which I&#8217;ll be dedicating a post to later on.<\/p>\n<p>In a general sense, I should mention here that Cogmind will make use of some manually designed dungeon sections. These &#8220;prefab&#8221; areas will have to be integrated into the existing dungeon generation algorithms. Before that there&#8217;s also the issue of having a way to create and edit them, a process I&#8217;ll likely handle via <a title=\"REXPaint\" href=\"http:\/\/www.gridsagegames.com\/rexpaint\" target=\"_blank\">REXPaint<\/a> in combination with text files.<\/p>\n<p>Prefab map pieces have many advantages, essentially all those things that are good about hand-crafted levels: Increased control over a specific part of the experience, their uniqueness draws attention to them and makes them more memorable\/meaningful, and they provide a reference point common across games that players can talk about. I won&#8217;t go overboard in the prefab department, the second point of procedural maps being that you <em>save<\/em> time on content creation, but I&#8217;ll probably want more control over the look and feel of significant plot-related locations.<\/p>\n<h2>Cogmind<\/h1>\n<p>Cogmind maps will be using a combination of tunnelers and cellular automata, which I&#8217;ll be introducing in subsequent posts.<\/p>\n<p><em>This is the first in a five-part series on procedural maps:<\/em><\/p>\n<ul>\n<li><em>Part 2: <a title=\"Mapgen: Tunneling Algorithm\" href=\"http:\/\/www.gridsagegames.com\/blog\/2014\/06\/mapgen-tunneling-algorithm\/\">Tunneling Algorithm<\/a><\/em><\/li>\n<li><em>Part 3: <a title=\"Mapgen: Cellular Automata\" href=\"http:\/\/www.gridsagegames.com\/blog\/2014\/06\/mapgen-cellular-automata\/\">Cellular Automata<\/a><\/em><\/li>\n<li><em>Part 4: <a title=\"Dungeon Metrics\" href=\"http:\/\/www.gridsagegames.com\/blog\/2014\/07\/dungeon-metrics\/\">Dungeon Metrics<\/a><\/em><\/li>\n<li><em>Part 5: <a title=\"Dungeon Prefabs\" href=\"http:\/\/www.gridsagegames.com\/blog\/2014\/07\/dungeon-prefabs\/\">Dungeon Prefabs<\/a><em><br \/>\n<\/em><\/em><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Procedurally generated maps are a core feature of roguelikes. For a genre that is almost synonymous with &#8220;randomness&#8221; (within reason), randomized maps are the easiest way to broadly manifest that key element since maps affect many aspects of gameplay from exploration strategy and tactical positioning to item and enemy locations. Notice how walkthroughs for strategy [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":759,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,92],"tags":[83,77,4,76,82,79],"class_list":["post-742","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-design","category-dev-series-procedural-maps","tag-bsp-trees","tag-cellular-automata","tag-cogmind","tag-map-generation","tag-prefabs","tag-tunneling-algorithm"],"_links":{"self":[{"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/posts\/742","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/comments?post=742"}],"version-history":[{"count":20,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/posts\/742\/revisions"}],"predecessor-version":[{"id":858,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/posts\/742\/revisions\/858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/media\/759"}],"wp:attachment":[{"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/media?parent=742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/categories?post=742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/tags?post=742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}