Friday, November 9, 2007

Game AI, or Do game AI's feel pain?

As some of you may know, I am currently working on an rpg.(Who isn't it seems like).

However, I was thinking about different AI ideas that could be implemented in an RPG. For this post, I will focus only on monster/enemy AI.

Now, the first thing that can make rpg battles/dungeons a bit more interesting is a context outside of battle, where what happens in battle does affect the overall dynamic of the dungeon. Here is one possible idea, similar in aspect to a genetic algorithm. Each enemy has a fear and an intelligence rating, randomly assigned within a predetermined racial standard deviation. Say, slimes are smarter than kobolds for example, on average.

Now what this means is that if you cross an enemy's fear/intelligence barrier, ie, "They're really tough, maybe I should run." So they'd try to escape. If they do escape, what happens? Normally, you'd never see that enemy again, or at the very least, never be able to tell. However, what if the enemies that survive or escape you, communicate with each other? And even are able to formulate plans and groups to take advantage of whatever they learn.

This can be done by giving escaping monsters a memory, a kind of statistical observation of your performance. Then in a background task, have a couple or more of such monsters communicating their knowledge to each other. Now, based on the length of time since the knowledge was obtained, the detail, and what is observed, different information will be valued more than others. By sharing the information between the monster memories, the background task is able to determine your weaknesses. Say it saw your white mage fall to two hits, but your knight took 10. That would be taken into account.

Then, the enemies would lead a charge against you, with slightly modified battle AI's. As per our example, focus on the white mage!

And since this would be largely time and number of battles based, the longer you are in the dungeon, the tougher the enemies get.

To balance that, we make it so that when you leave the dungeon, the monsters all forget about you.

This behaves similarly to a genetic algorithm, where the fitness test is fighting you. And the sharing of information is similar to swapping genes, but, in this instance, its a method that can deal with unexpected shifts of the problem space. Whereas, in genetic algorithms, the genes have to fit the problem well, and take a while to adapt. By data-mining observed actions, the enemies can adapt faster than with a genetic algorithm.


Another idea I considered was enemy genes, where each enemy you manage to kill does not reproduce, and thus, the more you fight in an area, the tougher the monsters. However, without a very flexible genetic system(IE, one too powerful to adequately simulate) this would only lead to monsters with stronger and stronger genes. Also, the algorithm would have to be tweaked to show results quicker than most GA's.

Next post: RPG AI Part II

4 comments:

Pete King said...

I think your first idea is the best and most practical of the two.

A survival of the fittest algorithm would only work if the enemies were fighting not just the player but each other, as presumably every enemy the player comes against is slain or flees in terror (in which case, you would be selecting cowardly or smarter enemies and not braver or stronger ones). This idea does get interesting if enemies are fighting each other, for example, if kobolds hate slimes.

Zeroth said...

Thanks Recursion king. That was another thought I had after I made the post. But the real difficulty is in datamining the information. If you do a really good job, the player does not have time to adjust or adapt. However, I was thinking about adding a time lapse element, ie, as time goes by the strategy gets better, or an experimental approach by the monsters, where they try different approaches, and see what works.

Pete King said...

I see your point.

I think it may depend on what you are trying to achieve here. If the goal is to create and adaptive, unbeatable opponent these techniques could be very useful to run indefinitely in the game. If the goal is more to create a challenging and entertaining opponent, once the winning ratio of the computer player is quite high, you could cut the learning process off so that it does not become unbeatable.

Zeroth said...

Yeah, Ai requires a lot of tweaking. After my current project, I'm working on a basic text rpg to experiment with different monster AI models. Thanks for the input. :)