{"id":63,"date":"2021-05-02T11:12:05","date_gmt":"2021-05-02T11:12:05","guid":{"rendered":"https:\/\/msc-ai.knipmeyer.co.uk\/?p=63"},"modified":"2021-05-02T11:29:25","modified_gmt":"2021-05-02T11:29:25","slug":"dragon-adventure-game-maze-building","status":"publish","type":"post","link":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/2021\/05\/02\/dragon-adventure-game-maze-building\/","title":{"rendered":"Dragon Adventure Game &#8211; Maze building"},"content":{"rendered":"\n<p>For my dragon adventure game, i need to build a &#8216;maze&#8217;. The NetLogo screen itself is an ok size, but if i want playable characters suitable for a video game, i need to use more space.<\/p>\n\n\n\n<p>Firstly, i designed my simple maze on pen and paper.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-3.png\" alt=\"\" class=\"wp-image-64\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-3.png 1024w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-3-300x225.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-3-768x576.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-3-400x300.png 400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>the initial maze design &#8211; a 4&#215;4 grid<\/figcaption><\/figure>\n\n\n\n<p>As you can see I started with a 4&#215;4 grid counting from 1, but the NetLogo array function counts from 0, so i redid the map starting from 0. This becomes significant when building the array.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-4.png\" alt=\"\" class=\"wp-image-65\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-4.png 1024w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-4-300x225.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-4-768x576.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-4-400x300.png 400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>array 1, counting from 1 and slightly unordered, array , more sequential and from 0<\/figcaption><\/figure>\n\n\n\n<p>So having completed the array for the maze and the interconnecting rooms, I explored how to code this in NetLogo.<\/p>\n\n\n\n<p>Firstly, I found some pseudo code, this time based on python as I have programming experience of it<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>;map = {'corridor':&#91;'room1','room2'],'room1':&#91;'corridor'],'room2':&#91;'corridor'] - python method<\/code><\/pre>\n\n\n\n<p>So in the python, it defines two rooms and corridor, with how they are connected. This is great for a text based adventure, i want to keep it simpler and not really name the rooms, just from my physical map know which rooms are, so reduced that to numbers.<\/p>\n\n\n\n<p>I started with following the array example from the NetLogo dictionary, adjusting for the amount of rooms i needed (16).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let a array:from-list n-values 16 &#91;0] ; init array a with 16 values of 0<\/code><\/pre>\n\n\n\n<p>So my room &#8216;0&#8217; connects to room &#8216;1&#8217;, and room &#8216;1&#8217; connects to &#8216;0, 5, 2&#8217;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  array:set a 0 \"1\"\n  array:set a 1 \"0,5,2\"\n<\/code><\/pre>\n\n\n\n<p>As I am testing, i want to see the value of the array in the console as well.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print a<\/code><\/pre>\n\n\n\n<p>To make this work in NetLogo i need to create the &#8216;setup&#8217; button and assign to a routine, so i create the &#8216;setup&#8217; button from the &#8216;add&#8217; item menu, and give it the routine &#8216;setup&#8217;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"550\" height=\"306\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-5.png\" alt=\"\" class=\"wp-image-66\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-5.png 550w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-5-300x167.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-5-500x278.png 500w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><figcaption>add the setup button<\/figcaption><\/figure>\n\n\n\n<p>I then wrap the array creation in a the standard function, not forgetting to add the array extension.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>extensions &#91;array]\n\nto setup\n  let a array:from-list n-values 16 &#91;0] ; init array a with 16 values of 0\n  array:set a 0 \"1\"\n  array:set a 1 \"0,5,2\"\n  print a\nend\n<\/code><\/pre>\n\n\n\n<p>I can then run the setup procedure, which will output the array<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1018\" height=\"1024\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-6-1018x1024.png\" alt=\"\" class=\"wp-image-67\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-6-1018x1024.png 1018w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-6-298x300.png 298w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-6-150x150.png 150w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-6-768x772.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-6.png 1384w\" sizes=\"auto, (max-width: 1018px) 100vw, 1018px\" \/><figcaption>values in array represent connections between room<\/figcaption><\/figure>\n\n\n\n<p>So I can see that my array is getting populated, i will be able to use the values in an index to draw the relevant rooms.<\/p>\n\n\n\n<p>The completed array<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>extensions &#91;array]\n\nto setup\n  let dungeon array:from-list n-values 16 &#91;0] ; init array a with 16 values of 0\n  ; use this line to copy and paste from \n  ; array:set dungeon n \"\"\n  array:set dungeon 0 \"1\"\n  array:set dungeon 1 \"0,5,2\"\n  array:set dungeon 2 \"1,3\"\n  array:set dungeon 3 \"2\"\n  array:set dungeon 4 \"8\"\n  array:set dungeon 5 \"1,6\"\n  array:set dungeon 6 \"5,10,7\"\n  array:set dungeon 7 \"6,11\"\n  array:set dungeon 8 \"4,9\"\n  array:set dungeon 9 \"8\"\n  array:set dungeon 10 \"6\"\n  array:set dungeon 11 \"7,13\"\n  array:set dungeon 12 \"13\"\n  array:set dungeon 13 \"12,14\"\n  array:set dungeon 14 \"13,15\"\n  array:set dungeon 15 \"11,14\"\n  print dungeon\nend<\/code><\/pre>\n\n\n\n<p>Confirmation output<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"618\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-7-1024x618.png\" alt=\"\" class=\"wp-image-70\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-7-1024x618.png 1024w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-7-300x181.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-7-768x464.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-7-1536x927.png 1536w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-7-2048x1236.png 2048w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-7-497x300.png 497w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>this was helpful as i could spot the typo on 11.14 <\/figcaption><\/figure>\n\n\n\n<p>I spotted I had already made a typo on room 15, so I corrected that from 11.14 to 11,15 and my &#8216;dungeon&#8217; map array was complete !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my dragon adventure game, i need to build a &#8216;maze&#8217;. The NetLogo screen itself is an ok size, but if i want playable characters suitable for a video game, i need to use more space. Firstly, i designed my &hellip; <a href=\"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/2021\/05\/02\/dragon-adventure-game-maze-building\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-63","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":3,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":71,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/63\/revisions\/71"}],"wp:attachment":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}