{"author_name":"HuvaaKoodia","cat":"LD #36","comments":[],"epoch":1475652660,"likes":5,"metadata":{"p_key":"3171","p_author":"HuvaaKoodia","p_authorkey":"21836","p_urlkey":"38640","p_title":"Desert Strife Post-Jam AI (with more code examples!)","p_cat":"LD #36","p_event":"LD36","p_time":"1475652660","p_likes":"5","p_comments":"0","p_status":"UPD5","us_key":"21836","us_name":"HuvaaKoodia","us_username":"\/author\/huvaakoodia\/","event_start":"1472169600","event_key":"35","event_name":"LD36"},"text":"<p><img class=\"aligncenter\" src=\"http:\/\/drive.google.com\/uc?export=view&amp;id=0B0MghCoVXkVlLVdCUzIzRXZTLWc\" alt=\"GIF!\" \/><\/p>\n <h4>Intro<\/h4>\n <p>Took a while (too many projects at the moment; loving it!), but here it is: Part 2. The basis of the system is still a reactive AI using heuristics. It doesn&#8217;t plan ahead at all, which is good enough even if it does show every once in a while.<\/p>\n <p>The full AI code can be found <a href=\"http:\/\/pastebin.com\/MMT5gnky\" target=\"_blank\">here<\/a>, if you care for that sort of thing!<\/p>\n <h4>Heatmaps<\/h4>\n <p>Heatmap, the main technique utilized, simply stores values in an extra tilemap (int array!) for spatial information evaluation. In this case the heatmap stores threat and support values used in choosing the AI attack target and movement path.<\/p>\n <p><img class=\"aligncenter wp-image-584572\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/Pic2Small-300x300.png\" alt=\"Pic2Small\" width=\"350\" height=\"350\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/Pic2Small-150x150.png 150w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/Pic2Small-300x300.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/Pic2Small-768x767.png 768w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/Pic2Small-550x549.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/Pic2Small.png 894w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/p>\n <p style=\"text-align: center\"><em>Heatmap visualization<\/em><\/p>\n <p><img class=\"aligncenter wp-image-584579 \" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/HeatMap-550x525.png\" alt=\"\" width=\"600\" height=\"573\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/HeatMap-300x286.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/HeatMap-768x733.png 768w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/HeatMap-550x525.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/HeatMap.png 885w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n <p style=\"text-align: center\"><em>The recursive heatmap function is called for each enemy and ally on the map<\/em><\/p>\n <h4>Threat evaluation<\/h4>\n <p>Calculating the threat (and support) values is a cinch: Add up the probable averages of all usable weapon types of your allies and enemies. There is a bit of quess work involved if the enemy ammo counts are not known already.<\/p>\n <p>&nbsp;<\/p>\n <p><img class=\"aligncenter wp-image-584588 size-large\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/ThreatEvaluation-550x618.png\" alt=\"\" width=\"550\" height=\"618\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/ThreatEvaluation-267x300.png 267w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/ThreatEvaluation-768x863.png 768w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/ThreatEvaluation-550x618.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/ThreatEvaluation.png 882w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/p>\n <p style=\"text-align: center\"><em>\u00a0Nothing out of ordinary here I&#8217;d hope<br \/>\n <\/em><\/p>\n <h4>Panic!<\/h4>\n <p>New feature alert! Taken that we already have threat values for each group and location data about safe areas, we might as well have a bit of fun with them! Every time a group gets into a fight its support value is compared to the threat level around it. A high enough difference will send the group in panic, running away from enemies and finally fleeing if reaching the level border. Now you can bully your enemies to submission!<\/p>\n <p><img class=\"aligncenter size-large wp-image-584597\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/PanicCalculation_-550x551.png\" alt=\"PanicCalculation_\" width=\"550\" height=\"551\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/PanicCalculation_-150x150.png 150w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/PanicCalculation_-300x300.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/PanicCalculation_-550x551.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2016\/10\/PanicCalculation_.png 657w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/p>\n <p style=\"text-align: center\"><em>Panic also ensues if the total enemy force is overwhelming, but that is checked elsewhere<br \/>\n <\/em><\/p>\n <h4>Conclusions<\/h4>\n <p>Simple and seems to work alright. In the next project I&#8217;ll be using <a href=\"https:\/\/en.wikipedia.org\/wiki\/Monte_Carlo_tree_search\" target=\"_blank\">Monte Carlo Tree Search<\/a>, no doubt about that. It is much less work with potentially more intelligent results. Working on a generic version at the moment.<\/p>\n <h2><a href=\"https:\/\/huvaakoodia.itch.io\/desert-strife\" target=\"_blank\">Play it here!<\/a><\/h2>\n <p>PS:<\/p>\n <p><cite class=\"fn\"><a href=\"http:\/\/ludumdare.com\/compo\/author\/seththefirst\/\" target=\"_blank\">seththefirst<\/a><\/cite> suggested taking a look into <a href=\"https:\/\/alastaira.wordpress.com\/2013\/01\/25\/at-a-glance-functions-for-modelling-utility-based-game-ai\/\" target=\"_blank\">AI utility functions<\/a> in <a href=\"http:\/\/ludumdare.com\/compo\/2016\/09\/06\/desert-strife-ai-with-code-examples\/\" target=\"_blank\">part 1<\/a> . The threat level comparison turned out to be sufficient so I didn&#8217;t implement anything like it, but maybe you (yes, you!) will find it useful.<\/p>\n \n <p>Tags: <a href=\"http:\/\/ludumdare.com\/compo\/tag\/2d\/\" rel=\"tag\">2D<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/ai\/\" rel=\"tag\">AI<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/animated-gif\/\" rel=\"tag\">animated gif<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/code\/\" rel=\"tag\">code<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/gif\/\" rel=\"tag\">gif<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/net-c\/\" rel=\"tag\">Net C#<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/post-jam\/\" rel=\"tag\">post-jam<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/unity\/\" rel=\"tag\">unity<\/a><\/p>","time":"October 5th, 2016 2:31 am","title":"Desert Strife Post-Jam AI (with more code examples!)"}