{"author_name":"panda","cat":"LD #33","comments":[{"author_name":"randoman","time":"August 30, 2015 12:30 am","epoch":1440912600,"text":"I love finding new techniques in puzzle design, that was a very interesting approach. I haven&#8217;t played it yet but I&#8217;ll be sure to check your game and see this in action!","spam":"N"},{"author_name":"panda","time":"August 30, 2015 1:10 am","epoch":1440915000,"text":"Thanks, @randoman!","spam":"N"},{"author_name":"","time":"August 30, 2015 7:26 am","epoch":1440937560,"text":"This is a really cool approach. It seems like at heart it could just be boiled down to a linear algebra problem, and so optimised a lot. Could be an interesting project&#8230;","spam":"N"}],"epoch":1440910620,"likes":3,"metadata":{"p_key":"13169","p_author":"panda","p_authorkey":"16086","p_urlkey":"48424","p_title":"How to make procedural puzzles","p_cat":"LD #33","p_event":"LD33","p_time":"1440910620","p_likes":"3","p_comments":"3","p_status":"UPD5","us_key":"16086","us_name":"panda","us_username":"panda","event_start":"1440115200","event_key":"29","event_name":"LD33"},"text":"<p>I&#8217;d like to share what I did in my game to procedurally generate puzzles. The cool thing is that this technique is quite general, so it may work for your games as well. If you&#8217;d like to, you can <a href=\"http:\/\/ludumdare.com\/compo\/ludum-dare-33\/?action=preview&amp;uid=16086\">play &#8220;You! Are the monster&#8221;<\/a> before reading on.<\/p>\n <p>In my case I generate a &#8220;whodunit&#8221; type puzzle. There are four people and they say things about where they were, what they wore, and who they saw. Sometimes it&#8217;s vague, like &#8220;I saw someone tall at the bar&#8221;. The bad guy is a monster, of course, and they can lie but no one else does.<\/p>\n <p>We can&#8217;t just generate those statements entirely at random, because some puzzles may end up unsolvable. So here&#8217;s what I do instead.<\/p>\n <p>I start with only a few statements &#8211; one per person. I pick those at random. Then, I try to solve the puzzle (more on this later). If there is more than one person who could be the monster, then I add more statements. If instead no one can possibly be the monster, I start over. This eventually leads to finding a solvable puzzle.<\/p>\n <p>Then I trim it down, removing statements that are not necessary to the puzzle being solvable. This results in a puzzle that is hopefully fun to solve.<\/p>\n <p>One thing I only realized after the compo deadline is that this technique sometimes generates trivial puzzles, where the monster says things that contradict themselves. I fixed this is the post-compo version.<\/p>\n <p>Now, you may ask, how do I solve the puzzle? I use brute force. Each randomly-generated statement is not only a bit of text, but also a bit of code that can check if what it says is true. I cycle through every possible choice for who is the monster, and then look for a combination of choices (people,location,color) such that every non-monster person tells the truth. If I find one then it means that that particular monster can be a solution. There can be either zero, one, or more solutions. I stop as soon as I find two since I know that&#8217;s not a puzzle I&#8217;ll want to keep. So a good puzzle has exactly one solution: if I remove the monster, then there exists a scenario that means everyone else tells the truth. If I pick anyone else as the monster then the remaining statements (including the actual monster&#8217;s) don&#8217;t go together &#8211; there is no scenario where they can all be true at the same time.<\/p>\n <p>Surprisingly enough, this generation is fast enough that I can run it at the client as you load the page, and I didn&#8217;t even feel the need to put up an animated spinner or other &#8220;please wait&#8221; indicator. For more complicated problems, though, this may become necessary.<\/p>\n <p>So there you go! With this simple technique you too can generate procedural puzzles to add to your game. Let me know what you think in the comments!<\/p>","time":"August 29th, 2015 11:57 pm","title":"How to make procedural puzzles"}