{"id":140,"date":"2018-11-07T16:03:07","date_gmt":"2018-11-07T20:03:07","guid":{"rendered":"http:\/\/sites.nd.edu\/code-fair\/?p=140"},"modified":"2018-11-07T16:17:32","modified_gmt":"2018-11-07T20:17:32","slug":"maze-generation-advanced","status":"publish","type":"post","link":"https:\/\/sites.nd.edu\/code-fair\/2018\/11\/07\/maze-generation-advanced\/","title":{"rendered":"Maze Generation (Advanced)"},"content":{"rendered":"<h5>Difficulty: Advanced<\/h5>\n<h3><b>Prerequisites<\/b><\/h3>\n<ul>\n<li>This project requires knowledge of how to code in Python.<\/li>\n<li>This project requires the following Python modules to be installed on your computer:<br \/>\n<code>matplotlib<\/code> <code>numpy<\/code><\/li>\n<\/ul>\n<p><small><a href=\"http:\/\/sites.nd.edu\/code-fair\/2018\/09\/18\/how-to-use-python\/\">Need help with Python?<\/a><\/small><\/p>\n<h3><b>Background<\/b><\/h3>\n<p>Solving mazes can be done just for fun, but it can also help introduce some important concepts in computer science and programming. A simple maze can be made from an arrangement of open rectangular cells (paths) with filled cells (walls) between them.<\/p>\n<h2><b>Part 1 &#8211; Implementing an Algorithm<\/b><\/h3>\n<p>The King of Programmia has hired you to inspect one of the many giant mazes he has built. Halfway through your inspection, your phone battery dies, leaving you trapped on the far side of the maze. What&#8217;s more, your map of the maze was on your phone! You need to find your way back through the maze to get home.<br \/>\nThinking hard, you remember that, as long as the entrance and exit of a maze are both on the maze&#8217;s edge (so neither is in the center of the maze), you can always get from the entrance to the exit by always following the wall on your right &#8211; that is, taking right turns at every intersection, and turning around at every dead end. As you are navigating the maze this way, you realize that you could implement this as a Python program.<\/p>\n<h3><b>What to Do<\/b><\/h3>\n<ol>\n<li> Download <code><a href=\"https:\/\/drive.google.com\/open?id=1i_XpciW9h4j9SbihOHwZ47vC2PDLGUfu\">maze_util.py<\/a><\/code> and <code><a href=\"https:\/\/drive.google.com\/open?id=1MGO6_RSM7mnOOptowcDcQLCjt5tS3k5h\">solve_maze.py<\/a><\/code>. Make sure to put them in the same folder.<\/li>\n<li>What are these files? <code>maze_util.py<\/code> is already completely written for you; you don&#8217;t need to worry about how it works (though you can look if you want). You just need to have it in the same folder as the file you will be working with, <code>solve_maze.py<\/code>.<\/li>\n<li>Run <code>solve_maze.py<\/code>. The result should look something like this:<\/li>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sites.nd.edu\/code-fair\/files\/2018\/11\/maze_solve_1.png\" alt=\"\" width=\"637\" height=\"511\" class=\"alignnone size-full wp-image-145\" srcset=\"https:\/\/sites.nd.edu\/code-fair\/files\/2018\/11\/maze_solve_1.png 637w, https:\/\/sites.nd.edu\/code-fair\/files\/2018\/11\/maze_solve_1-300x241.png 300w\" sizes=\"auto, (max-width: 637px) 100vw, 637px\" \/><\/p>\n<li>This shows a random maze, but you will notice that, though the file is named <code>solve_maze.py<\/code>, there is no solution visible. This is because you have not provided one yet!<\/li>\n<li>Open <code>solve_maze.py<\/code> and read through the comments. When you are ready, write some python code to walk through the maze fill in the <code>solution<\/code> list with all the points along the way as you continuously follow the wall on your right from the start of the maze to the end.<\/li>\n<li>Hint: create one variable to keep track of your current position, and one to keep track of what direction you are facing. &#8220;Walk&#8221; through the maze by updating these based on if there are to your front, left, right, and back. Add each new position you reach to <code>solution<\/code>. Do this until you reach the end of the maze.<\/li>\n<li>Don&#8217;t worry if your code doesn&#8217;t work the first time, or even the tenth time. Test your code often to make sure it works how you think it does. Don&#8217;t be afraid to ask a teacher or other mentor for help if you get stuck!<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Difficulty: Advanced Prerequisites This project requires knowledge of how to code in Python. This project requires the following Python modules to be installed on your computer: matplotlib numpy Need help with Python? Background Solving mazes can be done just for fun, but it can also help introduce some important concepts in computer science and programming. &hellip; <\/p>\n<p><a class=\"more-link block-button\" href=\"https:\/\/sites.nd.edu\/code-fair\/2018\/11\/07\/maze-generation-advanced\/\">Continue reading &raquo;<\/a><\/p>\n","protected":false},"author":3185,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[314428],"tags":[],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-advanced","nodate"],"_links":{"self":[{"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/users\/3185"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":7,"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/posts\/140\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.nd.edu\/code-fair\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}