• Advertisement
Sign in to follow this  

Noob AI Q... Programming Error Margins

This topic is 4043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
I think questions about kinematics might do well in the math or graphics forum.

Inverse kinematics is calculating the positions of joints and such that would result in something being in the desired position. It's a useful tool for animators since it lets them position a hand, for example, and have shoulder, elbow, and wrist orientations calculated automatically. For a fighting game you could decide where you want a fist to go in a punch and use inverse kinematics to position the rest of the arm.

Inverse kinematics doesn't really account for physical forces. Kinematics is just accelerations, motions, and positions. If you get into simulating forces, then that's dynamics. Inverse dynamics (calculating the forces needed to move an object a certain way) is a more complicated problem, and you're probably better off avoiding it and just using inverse kinematics because it introduces a lot of complex issues.

Share this post


Link to post
Share on other sites
Quote:
Original post by InnocuousFox
Sigh... again with the NN talk. We still need to institute a 30-day moritorium or something.


You can step away for a day or a year, but some things will always be the same when you come back! ;)

Not wanting to take this off topic, but to reinforce the point about NOT using ANNs on this problem...

Quote:
You'd just train the network using (input, output) pairs


Why is it that people think this is a given; that is, if you have input-output pairs that you can always train an ANN to represent an appropriate mapping between these two spaces. It's simply not the case and so making a statement such as this is misleading and often wrong. Please folks, let's stop talking about using artificial neural networks every time someone has (or could possibly generate) a data set representing input-output pairs. There are very few, if any, game AI problems that would be best solved using this tool and almost certainly another tool that is better suited to 99.9% of all game AI problems.

Back on topic...

This is certainly a case for applying sub-optimal planning and one could easily determine a variety of different ways to select a sub-optimal action given any particular state (it's a lot easier to select a sub-optimal action than it is to select the optimal one)! My recommendation: work out how you would implement the 'perfect' AI for choosing the next action (technique) given the current state and the perceived action of your opponent. You can then play around with sub-optimality based on the incorrect perception of the opponents behaviour and/or the incorrect inference of the optimal behaviour. Each should give slighty different results and I would expect that a good sub-optimal system that didn't look stupid would be based around both principles.

Cheers,

Timkin

Share this post


Link to post
Share on other sites
@Timkin

That sounds good. I was just discussing with my team the combat system and button mapping. I think we have finally decided on how we are going to do this.

Also, since I started this topic, I read a book on AI. Not the whole thing, I skipped the exercises and just read the theories and explanations so I know what the hell Im talking about.

Based on that, I will make the following conclusion. I am not getting into neural networks. I think that the most advanced I will get is fuzzy state machine with a rule based environment.

However, a genetic algorythm seems very very interesting as it might even find moves and strategies the team wont think off.

Anyway, I decided that I am going to leave the AI to the other programmer, Im going to concentrate on just about everything else.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement