{"id":4085,"date":"2009-08-12T08:42:46","date_gmt":"2009-08-12T12:42:46","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=4085"},"modified":"2020-01-22T03:06:10","modified_gmt":"2020-01-22T08:06:10","slug":"ai-follies-introduction","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=4085","title":{"rendered":"AI Follies: Introduction"},"content":{"rendered":"<p>A while back I had a post that criticized the AI of Far Cry, and in the comments <a href=\"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=4079#comment-127579\">Legal Tender asked<\/a>:<\/p>\n<blockquote><p>I wonder if you could elaborate further on the super-senses issue with the AI, Shamus?<\/p>\n<p>I don&#39;t mean a more detailed description of it but rather what it takes to fix it from a programming point of view.<\/p>\n<p>I remember you wrote a little something about AI behavior. I can&#39;t find that post but it left me thinking of&#8230;procedural AI? You know, give the AI grunts a set of behaviours and then let them loose on the world.<\/p>\n<p>What can be done about super-senses? I mean, is there a setting, something like AIdetection=1 or AItrackingtrfoliage=1? and then you adjust them to 0.8 so foes will ignore you or can&#39;t aim if you are behind obstacles?<\/p><\/blockquote>\n<p>I started trying to write a response in the comments, which grew into a post, which grew into a series of posts. I had a post on this back in 2006, where I talked about <a href=\"?p=605\">the problems of having an NPC accompany you<\/a> through the game.  In that post, I said:<\/p>\n<div class=\"quote\">People ask why AI sucks so bad? This is why: It&#39;s hard, it&#39;s expensive, and when it&#39;s working right people don&#39;t notice because they only notice when the thing screws up. The developer can spend money making the gameworld bigger, or spend money adding lots of detail to some inconsequential NPC just so it doesn&#39;t kill immersion.<\/div>\n<p>Developing AI is all about concealing or mitigating AI mishaps and screwups.  If you hire a brilliant programmer and he does astounding work, in the end you&#8217;ll have spectacularly stupid AI that doesn&#8217;t do anything too obviously stupid when the player is looking.  That&#8217;s the best you can hope for, because that&#8217;s the best that you can hope to do with a &#8220;mere&#8221; 10,000 lines of C++ code and a couple percent of your dual core processor. (Actually, processor isn&#8217;t that much of a bottleneck. The check to figure out where a given bullet will go and which of the 1,000,000 polygons in the scene it&#8217;s going to hit is going to be an order of magnitude more time consuming than anything your AI coder can throw at it.  We don&#8217;t really need more AI processing power, because we&#8217;ve only just begun to figure out what to do with the power we already have.)<\/p>\n<p>Note that I&#8217;ve never written production-quality AI before.  I&#8217;ve dabbled quite a bit over the last quarter century, like most curious coders, and I&#8217;ve made a few simple systems.  (Some of my first coding projects way back in 1983 at the tender age of 12 involved AI pathfinding.) But this series is more my overview of the problem and how I&#8217;d approach it than a review of work I&#8217;ve done in the past.  I&#8217;m going to be outlining the problem &#8211; which is far bigger than a lot of people realize &#8211; but not offering any solutions.  (If you want the solutions, feel free to send me an overview of the salary and benefits package you&#8217;re offering, because we&#8217;re going to be working together for a long time. (I&#8217;m Kidding. (Mostly.)))  <\/p>\n<p>I&#8217;m going to be talking mostly about dealing with enemy AI in this series and what a programmer needs to accomplish to reach the lofty goal of having enemies that aren&#8217;t <em>obviously<\/em> complete morons. Let&#8217;s assume we&#8217;re talking about generalized, dynamic AI as opposed to pre-scripted stuff.  Imagine we&#8217;re talking about AI to oppose the player in various situations both indoors and outdoors.  Ideally, we want the level designer to be able to drop a bunch of enemy AI dudes into the level, click and drag over the group, and say &#8220;You lot are all on a team.  Work together.&#8221; In the end, we want that team to fight in a way that isn&#8217;t obviously stupid, unfair, or boring.<\/p>\n<p>I divide combat AI into four distinct parts, in order of descending importance and increasing difficulty to implement: Detection, Targeting, Pathing, Behavior.  I&#8217;ll talk about each of these in its own post.  Later, you see.<\/p>\n<p><span class=\"date\">Getting Started<\/span><\/p>\n<p>If I were developing AI, my first step would be to get as far away from the game engine as possible.  AI development is very expensive in terms of experimentation and testing. (Or should be, if you hope to do a good job.)   If you&#8217;re testing group tactics, you need to test all sorts of situations and behaviors.  There are hundreds and hundreds of ways a battle can play out, and you need to be testing a wide variety of scenarios to make sure you&#8217;re not just playing whack-a-mole.  You don&#8217;t want to spend two days fixing the code that lets the AI navigate around buildings only to find you&#8217;ve completely broken the code that lets it snipe from a distance, and then spend another day fixing that to find the AI can no longer take turns going through doors.  <\/p>\n<p>You need to run a lot of tests, and you don&#8217;t want to launch the alpha version of a AAA game engine and sit through a bunch of loading screens every time you want to see the AI do its thing.  The game will be very unoptimized and unstable early in development, and you don&#8217;t want to deal with long loads and crashes. You also don&#8217;t want to have to manually <em>play<\/em> the level, either.  At least, not every single time.  <\/p>\n<p>Having a clear view of the battlefield would also help in giving me a nice objective view of things.  It&#8217;s much more difficult to spot irrational or absurd behavior in a sea of foliage, particle effects, lens flares, tracer rounds, blood decals, and flying ragdolls.  This wouldn&#8217;t be a problem if I was watching icons battle it out on a sterile &#8220;Tron&#8221;-style grid.  (Aside: Didja see the new <a href=\"http:\/\/www.youtube.com\/watch?v=a1IpPpB3iWI\">Tron Legacy<\/a> teaser? Whee.)<\/p>\n<p>I have no idea how AI coders work these days, but I would write something exceptionally lightweight.  A simple program that moves 2d sprites around a simple &#8220;maze&#8221; of arbitrary shapes.  Ideally, I&#8217;d want a program that can launch directly into the battle in a second or two.  It would be able to run in accelerated time and fight itself while I watch and analyze the action.  I could then iterate on that thing about twenty times faster than someone loading up (say) Crysis every single time they want to see the AI work.  Once I had it polished to a mirror shine, <em>then<\/em> I&#8217;d integrate it into the game.<\/p>\n<p>No development approach is perfect, and this one wouldn&#8217;t be without faults.  But I think this would let me make the AI as <del datetime=\"2009-08-12T12:04:49+00:00\">smart<\/del> <em>non-stupid<\/em> as possible without pushing back the release date until (insert Episode 3 joke here).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while back I had a post that criticized the AI of Far Cry, and in the comments Legal Tender asked: I wonder if you could elaborate further on the super-senses issue with the AI, Shamus? I don&#39;t mean a more detailed description of it but rather what it takes to fix it from a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-4085","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/4085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4085"}],"version-history":[{"count":1,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/4085\/revisions"}],"predecessor-version":[{"id":49093,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/4085\/revisions\/49093"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}