ID:97647
 
Keywords: ai, tutorial
I wanted to try my hand at creating a tutorial, so here's one about enemy AI. AI seems to be an aspect of games that is often avoided here (I avoided it for a long time too, myself). Hopefully this tutorial will take some of the magic out of AI and make people realize that they can create better enemy AI than they thought they could.

You can download the latest version from this hub entry.

The tutorial consists of simple examples of how to implement enemy AI. The examples are all for a generic action game, but in the end you should be able to understand how to apply the concepts in other situations.

The .zip contains a set of code files (code-01.dm through code-18.dm), each is an example that builds on the previous one. code-01.dm starts with very basic AI and each file introduces a new feature. Each code file contains a comment at the top explaining what feature was added and a high-level description of how it was implemented. There are comments within the code to show what changes were made.

To run a demo you only need a few of the files. If you include too many files it won't work (because each code file is an entire example, including more than one will give you lots of "duplicate definition" errors). If you want to run the example from code-01.dm, Dream Maker should look like this:



_always_include.dm is required for all examples to run. Most examples also use map-1.dmm. If an example uses map-2.dmm it will say so in the code file.

If you wanted to run the next example, uncheck code-01.dm and check code-02.dm. Dream Maker should now look like this:



code-07.dm, code-11.dm, and code-18.dm are not examples, but explanations of the concepts covered by the examples.

__instructions.dm provides instructions similar to those seen here.

Feedback would be very much appreciated.
Very great tutorial. I think newcomers and old timers to BYOND that are intimidated by AI functions will get a great boost in confidence.

5/5
Hi Forum_acc, it seems the download link for your hub page has stopped working. Would appreciate a fix ASAP. :-)

Also, out of curiosity, did you use to go by 'OneFishDown' around here?
The download link is working for me. If it doesn't work for you, you can download the files directly from this url: http://BYONDfiles.fileave.com/ai-3.zip

And no, this is my first account.
Downloaded, great tutorial! I love how you structured it. We seriously need more like these. The only 'suggestion' I might have is not exactly a suggestion but, there are some concepts I find important, that I think it would be nice if you mention in say, the footnotes to code-18, and perhaps expand on in a later tutorial (if you are planning any!):

1) The tutorial dealt wonderfully with AI behaviour, but it didn't look to deal with some of the efficiency problems that stem from the ai loop (or if it did, sorry!). The way it is now, each mob has its own personal, constantly running loop, and the effects of this could possibly be devastating in a large game. It would be nice if you acknowledged this, and perhaps offered a few alternatives, such as deactivating the AI when there are no players in its vicinity. It might be beyond the scope of the tutorial to actually deal with this, but perhaps some cautionary advice would be nice.

2) In the interest of both structure and efficiency, you could mention the possibility of moving the ai loop into a general 'master loop', that takes the looping responsibility from the ais... the concept is illustrated better than I can explain it in Deadron's Event Loop library. The main added benefit here is the much expanded control you have over your AIs.

3) You began addressing the concept of 'thinking ahead' in some parts of the tutorial to do with utility. Perhaps expand on this concept and have a foreword to task, goal-based action queues?
1) ...

Excellent idea. When writing the examples I kept imagining a game like Spies!, where you'd have just a few AI players. As people apply these concepts in their own games they obviously could run into efficiency issues.

2) ...

Also a good suggestion. I'll take a look at that library.

These two suggestions don't directly relate to AI but are still important. I included some examples that indirectly relate to AI to give the reader a break from the AI concepts. I'll probably include these suggestions as appendices, or if I find enough topics I'll make a separate tutorial of it. I'm sure there's enough content for that.

3)

This is definitely the logical next step. I wasn't sure if people would want another tutorial that went into more advanced concepts or one that provided more, simple examples. I wanted to be sure at least one person would appreciate the advanced tutorial before writing the whole thing.

Thanks for the feedback. It's nice to know that someone actually read the text =)
(which is the good thing, because the next tutorial will be text-heavy and light on the code compared to this tutorial).
Would really like to try this, though none of the DL links are working. Looks useful.
Sorry about that. I think I set up the hub entry before I was a member so I couldn't host the files on the BYOND site. I'll see if I can fix it now, if I can't I'll certainly have it fixed this weekend.
Ok, the download link should be working now. Sorry for the inconvenience!
Good example, thx. But i have one question - this is recursion, what about call stack, can it overflow?