{"id":1492,"date":"2011-10-12T16:58:01","date_gmt":"2011-10-12T15:58:01","guid":{"rendered":"http:\/\/positech.co.uk\/cliffsblog\/?p=1492"},"modified":"2011-10-12T16:58:01","modified_gmt":"2011-10-12T15:58:01","slug":"programming-ai-in-a-tower-defense-game","status":"publish","type":"post","link":"https:\/\/www.positech.co.uk\/cliffsblog\/2011\/10\/12\/programming-ai-in-a-tower-defense-game\/","title":{"rendered":"Programming AI in a tower defense game"},"content":{"rendered":"<p>This is not an easy task. It is for most Tower Defense games, because they are simply scripted. The level has a set number of enemies of certain types and times, and they appear as attackers. And of course, most TD games don&#8217;t let you play as the attacker, so programming the defense AI is not needed. I need both of these to be non-scripted for <a href=\"http:\/\/www.gratuitoustankbattles.com\">Gratuitous Tank Battles<\/a>.<\/p>\n<p>I need attacking AI that ideally adapts mid battle to your decisions, and this is harder than it sounds. The first approach I took was to have a system with 3 types of placement timing mode (steady placement, or hoard points for a big attack or spam the current unit) and two types of unit selection (random, and select the one that has been most effective so far&#8230;with some variation).<\/p>\n<p>The AI would switch randomly between these combinations and it looked pretty convincing. Sudden waves of identical units followed up by who-knows what. The problem was, it obviously did so with little care as to what it was up against.The &#8216;most effective unit&#8217; code was good, because it meant totally useless designs which charged into a hail of bullets would not see much repeat business, but something major was lacking. That was the anticipating of future events.<\/p>\n<p>If the defender has placed 6 machine-gun turrets (rubbish, but devastating to infantry) you shouldn&#8217;t place down infantry, regardless how well they did earlier in the battle. If they have lots of laser turrets, place down shielded units to get past them&#8230;etc.<\/p>\n<p>So today, at the end of a long day of video rendering and editing, and tweaking, and bug fixing, I&#8217;m starting work on a more generic system for opponent army composition analysis, that can take snapshots of the enemy forces and realise that its 63.2% anti-shield units, and thus we should de-prioritise shielded unit selection etc.<\/p>\n<p>This is annoying, fiddly, long winded code that nobody will ever see, as such, but will make <a href=\"http:\/\/www.gratuitoustankbattles.com\">Gratuitous Tank Battles<\/a> a convincing challenge, which is well worth spending time on.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is not an easy task. It is for most Tower Defense games, because they are simply scripted. The level has a set number of enemies of certain types and times, and they appear as attackers. And of course, most TD games don&#8217;t let you play as the attacker, so programming the defense AI is<\/p>\n<p class=\"text-right\"><span class=\"screen-reader-text\">Continue Reading&#8230; Programming AI in a tower defense game<\/span><a class=\"btn btn-secondary continue-reading\" href=\"https:\/\/www.positech.co.uk\/cliffsblog\/2011\/10\/12\/programming-ai-in-a-tower-defense-game\/\">Continue Reading&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,114,4],"tags":[],"class_list":["post-1492","post","type-post","status-publish","format-standard","hentry","category-game-design","category-gratuitous-tank-battles","category-programming"],"_links":{"self":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/comments?post=1492"}],"version-history":[{"count":2,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1492\/revisions"}],"predecessor-version":[{"id":1494,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1492\/revisions\/1494"}],"wp:attachment":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/media?parent=1492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/categories?post=1492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/tags?post=1492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}