{"id":39,"date":"2021-04-29T17:59:07","date_gmt":"2021-04-29T17:59:07","guid":{"rendered":"https:\/\/msc-ai.knipmeyer.co.uk\/?p=39"},"modified":"2021-04-29T17:59:07","modified_gmt":"2021-04-29T17:59:07","slug":"pacman-ai-flee-and-seek","status":"publish","type":"post","link":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/2021\/04\/29\/pacman-ai-flee-and-seek\/","title":{"rendered":"Pacman AI &#8211; flee and seek"},"content":{"rendered":"\n<p>In this post I explore the Netlogo PacMan game, focusing on interaction between player (pacman) and ghosts.<\/p>\n\n\n\n<p>Pacman is a classic 1980&#8217;s video game which demonstrates attract and flee AI. The objective of the player is to eat dots and progress to the next level, whilst optionally eating &#8216;power up&#8217; pills to eat or keep the opponent ghosts at bay or eat them for extra points. Random &#8216;bonus&#8217; items also appear to increase the score. As the game progresses the layout progresses between 5 maps increasing in complexity and the speed of the ghosts increases making navigating and consuming the dots more challenging.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"974\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-5-1024x974.png\" alt=\"\" class=\"wp-image-41\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-5-1024x974.png 1024w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-5-300x285.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-5-768x731.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-5-315x300.png 315w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-5.png 1482w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>pac-man \/ ghost encounter without pill = died<\/figcaption><\/figure>\n\n\n\n<p>As can be seen, where pacman encounters a ghost without a power pill, he is killed. The results in the level restarting, minus any already consumed pills. The ghost return to their center square home and pacman to his standard &#8216;spawning&#8217; point on the maze map.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"979\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-7-1024x979.png\" alt=\"\" class=\"wp-image-43\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-7-1024x979.png 1024w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-7-300x287.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-7-768x734.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-7-314x300.png 314w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-7.png 1486w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>new pacman, ghosts return, dots still in place<\/figcaption><\/figure>\n\n\n\n<p>The ghosts to start with exhibit a random path, but as soon as the line of sight between pacman and ghost on the maze is established, the ghosts exhibit the AI behaviour of &#8216;seek&#8217;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"963\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-8-1024x963.png\" alt=\"\" class=\"wp-image-44\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-8-1024x963.png 1024w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-8-300x282.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-8-768x723.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-8-319x300.png 319w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-8.png 1486w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>ghosts see pacman and are attracted to him giving chase !<\/figcaption><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>to choose-heading ;; Ghosts Procedure<br>let dirs clear-headings<br>let new-dirs remove opposite heading dirs<br>let pacman-dir false<\/p><p>if length dirs = 1<br>[ set heading item 0 dirs ]<br>if length dirs = 2<br>[ ifelse see-pacman item 0 dirs<br>[ set pacman-dir item 0 dirs ]<br>[ ifelse see-pacman item 1 dirs<br>[ set pacman-dir item 1 dirs ]<br>[ set heading one-of new-dirs ]<\/p><cite>gHOSTS ROUTINE TO SEEK PACMAN<\/cite><\/blockquote>\n\n\n\n<p>This can result in an untimely ending to pacman if his escape around the maze is not done from the pursuing ghosts. A strategy is to allow the ghosts to see pacman, but in range of a power pill, whereby pacman will then be able to consume the ghosts and score more points. The ghosts exhibit the AI &#8216;flee&#8217; behaviour.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"977\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-9-1024x977.png\" alt=\"\" class=\"wp-image-45\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-9-1024x977.png 1024w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-9-300x286.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-9-768x733.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-9-314x300.png 314w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/04\/image-9.png 1480w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>power pill consumed ghosts flee !<\/figcaption><\/figure>\n\n\n\n<p>The interaction of player and pacman is straightforward enough, press a key and move, with some animation. Edge detection is used to determine the walls between pacman and the maze.<\/p>\n\n\n\n<p>Conclusion<\/p>\n\n\n\n<p>In this classic 80&#8217;s game we can observe classic seek and flee behaviours of the AI. The AI also seems to loose interest in chasing pacman if the ghost is outwitted long enough. Whilst a simple game, its no doubt that the hunt and chase of ghosts still makes compelling game play even in todays modern era of far more graphically superior games.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I explore the Netlogo PacMan game, focusing on interaction between player (pacman) and ghosts. Pacman is a classic 1980&#8217;s video game which demonstrates attract and flee AI. The objective of the player is to eat dots and &hellip; <a href=\"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/2021\/04\/29\/pacman-ai-flee-and-seek\/\">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-39","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\/39","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=39"}],"version-history":[{"count":2,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":47,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions\/47"}],"wp:attachment":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}