Noob AI Q... Programming Error Margins

Started by
11 comments, last by gentrinity 17 years, 2 months ago
Hello everybody, to explain my post, I am building a fighting game with RPG style stat building. What I wanted to do is program the AI to be able to commit errors when fighting depending on their level. So a level 10 is more prone to errors in judegment and has worse reflexes than a level 90. Is this getting into neural networks? I would imagine that this would need several mathematical formulas with a Math.random() in Actionscript. And the higher the level, the more I increment the players level, the lower I make the possible range for errors. if player_A sees player_B make overhead attack errorVar = calculate random number 1-100 if errorVar < (variable storing error range) commit error else make appropriate move Can anyone comment. Thanks!!
Advertisement
Your code sample seems like a good approach, just adding a random error-commiting element to a finite state machine. It will probably be a bit more advanced than that when you start tweaking, but it should give you the results you want. You can always try neural networks, but would probably find them far more trouble than they're worth.
h20, member of WFG 0 A.D.
Perhaps it's just me, but I would have thought the way to go would be to approach it from the other direction; write a simple code to figure out what the AI should do, and then add more sophisticated tricks for situations where the simple code makes the AI too predictable or vulnerable to something or whatever. Then have the AI get access to more tricks the higher level it is. Essentially the same, as I suppose you could say not using the trick is a mistake, but it strikes me as a more intuitive way to look at the problem.
This isn't getting into neural networks.

You could create opponent AIs that use neural networks if you wanted. You'd just train the network using (input, output) pairs, where the input represented the current state or what the opponent saw or whatever and the output was the action you wanted the AI to use in that situation. This would only be useful if it was impractical to enumerate outputs for all the possible inputs and you designed the network based decision maker to be able to interpolate good outputs for those inputs. A neural network doesn't really have any definite advantages over using a more explicit rule based decision making algorithm. You could even try using both in the same game and see how that feels.

For slowing down reflexes, you can just add a delay to your decision making. Randomly choosing bad moves can work and so can providing an inferior AI with a strategy that is worse than what you believe to be optimal. You can mix these methods to get AIs that behave differently and in interesting ways. Even a good AI opponent might randomly choose between several good alternatives to keep the opponent off guard.

Making the different levels of AI behave in radically different ways can be a big part of a game. Nintendo's Punchout games had boxers with widely varying patterns and the goal for the player was to learn to recognize and respond to these patterns.
Sigh... again with the NN talk. We still need to institute a 30-day moritorium or something.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Thanks to everyone for replying. Basically, I am pretty sure Im sticking to a finite state machine. I have two main reasons for this. One is that I plan on moving to MMO in a near future, so no need to go into all the trouble of neural networks. Two, I dont really see where neural networks will do something I cant do with a finite state machine. Obviously its going to be a very elaborated one, but still, Id rather go through all the possible If statements. Never done AI programming so I should start with finite state.

The delay in their reflexes at times, maybe add animations where they get awe strucked when they see a blade heading for their head.

I know most people here dont use Actionscripting, but how could I go about adding a delay. I could use the same randomization concept I wrote in my OP, but the delay is a little harder. I could use a setInterval(), and I would imagine that I could have an incrementing var and an If statement that once that var reaches its second increment, make a delay or something. Something like this;

if player_A sees player_B make overhead attack
errorVar = calculate random number 1-100
if errorVar < (variable storing error range)
commit error
else
make appropriate move

if (commit error)
var i = 1;
freeze opponent
setInterval to 300 milliseconds(each 300 seconds, run delay() function)
function delay() {
i++;
if (i == 3)
execute move now
}

This could work for the delay. Logic is a little weird, but you should get the idea.

The other thing I can do as Vorpy suggested is maybe build some strategy Classes. Basically, each class is a different battle strategy, be it very offensive, very defensive, based on counterattacking, based on quick movements, based on overpowering opponents. And then just use a FSM to cycle through the AIs stats and decide which one is better for his stats, then, use the same error calculating code I used and sometimes the AI will not choose a fighting style best suited for him.

Also, I can build an Array of moves, that I trigger when the AI sees the user make a certain move. Then, based on my fighting style Classes, it will choose the appropriate array and an element in the array randomly usually creating a random successfull or unsuccessfull move, as each array can have moves that are not as effective as others, and maybe one or two moves that are just plain errors.

One last question; In which forum would yall recommend I ask about using Kinematics for animations instead of prerendered ones?

@Innocuous Fox - Thread wasnt meant for that.

@mnansgar - Great to hear, I plan on implementing it then definately.

@Protagoras - Could you please elaborate a bit more and provide an example like what i did above. I dont quite follow you. Thanks.

@Vorpy - Like I said above, dont really want to get into NN, but thanks for the suggestion. Thanks for the idea on making various battle strategies and not always letting the AI choose the correct one.
OK, I'll try to give an example. Player does attack move A. The simple computer knows that counter-attacks X, Y, and Z all sometimes work in response to A, and picks one, no doubt weighting the more frequently successful and more damaging counter-attacks more. So say X does the most damage, and they're all about equally likely to hit. It'll choose Y or Z once in a while, to keep the player off guard, but choose X slightly more often (either because of a weighted randomizer, or my preference would be having how often the computer has done various moves recently, and how well they've done, figure into its decision-making, favoring moves that haven't been done in a while for surprise, or that haven't gone badly recently to get off a losing track, or more likely both).

All well and good. But your game surely has combo moves, and A can lead into B, C, or D. Now, if player does D after A, and computer has done X, he's totally screwed. If he's done Y or Z, he's still OK. Knowing about this combo would be one of the additional things that could be added to the computer to make the more sophisticated AI smarter than the simple AI. The more sophisticated AI, with this knowledge, will pick X less frequently than it picks Y or Z, because it takes into account the possible AD combo when deciding what to do.

In general, I'm thinking of this like a chess program (a good model, I think; a fully deterministic game with utterly unexpected outcomes. A much better model for computer games to follow than the roll dice everywhere approach, especially as removing randomness helps debugging). Give the smarter AIs essentially deeper searches into possible moves and counter-moves. It might also be worthwhile, if possible, to make them more sophisticated in evaluating quality of position above and beyond mere comparison of hit points, assuming there is any meaningful sense of quality of position in your game (perhaps more likely when combat involves more than one on one).
Quote:Original post by Protagoras
OK, I'll try to give an example. Player does attack move A. The simple computer knows that counter-attacks X, Y, and Z all sometimes work in response to A, and picks one, no doubt weighting the more frequently successful and more damaging counter-attacks more. So say X does the most damage, and they're all about equally likely to hit. It'll choose Y or Z once in a while, to keep the player off guard, but choose X slightly more often (either because of a weighted randomizer, or my preference would be having how often the computer has done various moves recently, and how well they've done, figure into its decision-making, favoring moves that haven't been done in a while for surprise, or that haven't gone badly recently to get off a losing track, or more likely both).

All well and good. But your game surely has combo moves, and A can lead into B, C, or D. Now, if player does D after A, and computer has done X, he's totally screwed. If he's done Y or Z, he's still OK. Knowing about this combo would be one of the additional things that could be added to the computer to make the more sophisticated AI smarter than the simple AI. The more sophisticated AI, with this knowledge, will pick X less frequently than it picks Y or Z, because it takes into account the possible AD combo when deciding what to do.

In general, I'm thinking of this like a chess program (a good model, I think; a fully deterministic game with utterly unexpected outcomes. A much better model for computer games to follow than the roll dice everywhere approach, especially as removing randomness helps debugging). Give the smarter AIs essentially deeper searches into possible moves and counter-moves. It might also be worthwhile, if possible, to make them more sophisticated in evaluating quality of position above and beyond mere comparison of hit points, assuming there is any meaningful sense of quality of position in your game (perhaps more likely when combat involves more than one on one).


Its great that you touched on the countering system because the fighting engine I want has a few unique features;

It is heavily based on a continuous cycle of moves and countermoves until someone lands the killing blow. Hence, I really do not plan on implementing combos of sorts, and like you said, aim at a chess match style of fighting were you can even bait your opponent into attacking a certain way in order to be able to land the strike you want.

I like your ideas on differentiating the AIs search possibilities. Also, there will be no hit points, rather, if you land a certain blow, you will kill your opponent like in real life. Hit his arm, and you will dismember it.

I also plan on eliminating some stupid AI tendancies I have seen in other games where they will attack even if they are not in your vicinity. So yes, position is very important in this game. It is meant to be very very tactical, yet easy enough to be able to enjoy. I mean, dodges, sidesteps, step backs, and rolls are going to be implemented in every possible way.

What are your thoughts on using kinematics and physics to program the animations rather than pre-rendered ones? I know the latter is much easier, but I think the first would be uber realistic and much more tactiful in comparison.
I'm afraid I have few thoughts on using kinematics and physics. I like robust and detailed models in general, because they provide a good base for adding new things, but you always need to let your designs be constrained by the practical issues, which in this particular area I know almost nothing about.

However, I will add that based on what you describe about the system, one obvious way to introduce natural-seeming mistakes into AI behavior is to have a delay while the AI figures out what the player is doing before it adjusts its action in response, and have that delay go down for better AI opponents. Then the poorer opponent will sometimes choose the right move for what was going on a little while ago instead of the right move for now, which strikes me as a more natural kind of mistake than just randomly doing some wrong thing.
Quote:Original post by Protagoras
I'm afraid I have few thoughts on using kinematics and physics. I like robust and detailed models in general, because they provide a good base for adding new things, but you always need to let your designs be constrained by the practical issues, which in this particular area I know almost nothing about.

However, I will add that based on what you describe about the system, one obvious way to introduce natural-seeming mistakes into AI behavior is to have a delay while the AI figures out what the player is doing before it adjusts its action in response, and have that delay go down for better AI opponents. Then the poorer opponent will sometimes choose the right move for what was going on a little while ago instead of the right move for now, which strikes me as a more natural kind of mistake than just randomly doing some wrong thing.



Yeah, I do agree that I should research and test out different error commiting scenarios and try and get something that looks realistic. Your suggestion is pretty good.

What forum would you recommend I enquire about kinematics for animations instead of prerendered animations?

This topic is closed to new replies.

Advertisement