AI for Games
In my recent life update post I mentioned my goal to start the AI for Games book by Ian Millington and after a solid week of progress I managed to get through the first 2 chapters and the first couple of sections of chapter 3. That might sound like a lot but really it's not, the first 2 chapters were roughly 20 pages each and the entirety of chapter 3 is roughly 150 pages. Additionally the first 2 chapters were more or less just lecture material about what AI is and how it is applied in games. Chapter 3 is where I also started implementing the material so that slowed me down as well. I could probably talk at great length why I think we are safe from AI for a while, but I really just want to limit the scope of this to what I learned reading this book.
Chapter 1 Summarized
The topic of AI is pretty deep and mysterious right now given the popularity of tools such as ChatGPT, deepfakes, AI generated art, and billionaires reassuring us that current AI is not a problem but the real problem is the kind of AI that might look like something out of The Terminator franchise. I am of the opinion that that is a bit of an extreme scenario and I would say we are a long long time away from anything remotely like that, but I could be wrong. The book broke the history of AI down into 3 periods in time: the early days, the symbolic era, and the natural computing / statistical era.
Millington characterized the early days as a very philosophical period when questions like "can consciousness be given to inanimate objects?" which might be akin to Blade Runner or I, Robot.
He defines the Symbolic Era as having occurred throughout the 1950's through the early 1980's which is really surprising to me because I would not have considered AI to have been even a thought before the 90's but based on my further reading it actually makes sense. The kind of AI during the Symbolic Era is simply just a set of data being combined with an algorithm (a set of instructions) that performs actions or discovers new things based on the rules and data. This is also known as an expert system. So, it's not really AI that is self-aware nor learning on the fly but rather it's just operating its instructions within some set of rules that live within the bounds of the supplied data. This is actually the most common type of AI we see in games as he points out. What he points out that I really had not considered is that something as simple as "if health < 2 then heal" is AI. We the engineers see it as a simple line of code that may happen depending on the state of the health variable in the update loop, but players see it as a smart CPU controlled enemy that is giving them a challenge.
Lastly the Statistical Era, which occurred throughout the late 1980's through the 1990's, was an attempt by engineers to make AI mimic biology such as neural networks since symbolic approaches couldn't make AI feel like true AI. He didn't say what the era post Y2K is so I am assuming that there hasn't been a significant advance and we're still just using the research and systems that were contrived during the 80's and 90's. What makes these designs work is the availability of computing power. With the increased availability high speed networks that can offload intensive computer operations onto cloud servers we can make implement these deep AI models for learning. The key thing about this AI is the need to learn and learning requires running 1000's upon 1000's of simulations which might be too intensive on a local machine.
Chapter 2 Summarized
There are 3 kinds of techniques to create AI that is believable to players and not every game uses every technique. They are Hacking (ad hoc solutions and neat effects), Heuristics (rules of thumb that work in most but not all cases), and Algorithms (the proper stuff).
Hacks can be used for providing visuals to players such as animations like an enemy operating a vending machine. We know it's just the geometry of the model being warped over a set of points, but the players don't see that. Instead they see a world full of life, unless the game is bugged and every enemy model is stuck in a t-pose.
Millington says that there are many Heuristics such as "replace complex capabilities of a unit with a number to determine how good the unit is" which he uses the example of chess. The basic unit of a pawn might have a value of a 1 and the queen might have a value of a 9 representing that it is good and should be protected at all costs (not before the king of course). This is useful because the AI just has to analyze the number value of its pieces and not the capabilities of the piece and determining if it should be saved or sacrificed.
Algorithms are straight forward such as doing a depth-first search. These algorithms aren't necessarily intended for games which require a lot of resources and so they might not be the best choice and can have major impacts to speed and memory budgets. Algorithms might need some sort of mod to prevent using more resources than desired such as early termination clauses of "if loop performs more than 1000 times then break"
Chapter 3
Finally, chapter 3 I will just demonstrate what I made which the implementation is quite simple and I could have done it on my own but my code wouldn't have looked like how I did it following his pseudo code and I actually feel pretty good about it.
I have 1 AI who continuously moves to the player, 1 AI who continuously flees from the character, 1 AI who continuously arrives at the player or rather moves to the player but stops within a range, and then 1 AI who just wanders aimlessly which I don't think looks the best. Take a look below. Here is the github link
https://github.com/voporak5/ai-lessons in case you want to see the code.
That's it for today...
Until next time!
P.S.
I feel like it'd be respectful to include a shopping link to the book which I highly recommend purchasing
here
Comments
Post a Comment