🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Fighting Game AI

Started by
19 comments, last by BRZGames 21 years, 10 months ago
I have to say... really nice thread. Some good ideas coming through and it sounds like it will be a fun game when it's finished.

As to the different postures, you already have that in there, except that you only allow your agent to be in one state at a time, rather than a combination of states. To permit a combination of states you need to allow the NPC to perform multiple actions. For example, walking forward and punching at the same time.

To accomplish this, you can either use two FSMs, one for the posture and one for the movement, or you can combine it all into a single FSM that checks two variables before deciding what state it is in.

Personally I like the idea of two seperate FSMs (easier to design and code). Each one makes a recommendation of an action and if the actions are not mutually exclusive (which they shouldn't be in this game) then both are executed. The period of each action may differ. You can either handle this with an internal timer, checking to see if an action has finished before deciding on the next one (for that FSM) or just make all actions take the same amount of time (not as realistic).

As for the learning of player patterns ... do you know how to compute a correlation? You can find the formula in most introductory stats or AI books, online at MathWorld, or I'd be happy to explain. Store which actions the player executes (in sequence). Once a new action is performed, add it to the list of actions recently performed (say the last 3-5 actions). Compute the correlation between the recent action and each previous action and between the sequence of actions and the damage taken by the player as a result of the sequence. This will give you a table with which you can predict the players moves and predict the damage taken. For example, the player executes a jump and your correlation data suggests that there is a strong correlation between jumps and kicks, then there is a strong (computable) probability that the next action will be a kick. The data will also provide an estimate of the damage that will be taken, which can be used to modify the NPCs behaviour (If the AI predicts that it will take a lot of damage by a sequence being executed, it may retreat into a defensive posture to protect itself. Alternatively, it may ignore the attack and press it's own attack).

You might also want to investigate Descent (I-III), which utilised patterns in player actions to formulate responses by the bots.

If you've got any questions regarding this stuff, just holler.

Cheers,

Timkin

[edited by - Timkin on September 18, 2002 11:07:03 PM]
Advertisement
Yeah, this really has become a nice thread. I think doing a Neural Network is a bit more involved than what I want to get into. Dreddnafious Maelstrom, I do plan on implementing combos in the game, but never thought so much about them related to the AI though. It may be a good idea though. Maybe weighting the likelyhood of an opponent turning an attack into a vicious combo.... Hmmm....

Timkin, you seem to be very knowledgable on this subject. I''m not quite following you on the 2 separate state machines though. If the computer decides it wants to punch a player (It will actually determine this before entering the advancing state in a state I failed to list above called a Change state), it walks up to the player in the Advancing state, and when close enough, it switches to the Attacking state to throw the punch. There is no minimum time required to stay in the walk state, only a maximum time. Each move has it''s own time interval (except for moves such as Walk, and Duck that can be started and stopped on command.) Well, after typing all of this, maybe I''m actually doing it the 2nd way you suggested...

I vaguely remember correlations, but from your post it seems like the way to go. I guess I need to did up my old college stats book!

Thanks for all the help guys.
Wow, great thread!

One way you could give the characters some ''personality'' while fighting would be to:

Measure the success of various attributes throughout the round.
Of the NPC''s punches, how many have landed. How many have been countered? How well is the defence working, etc..

With this information you could then change the NPC''s fighting dynamics. i.e. If punches are landing, throw more.. If punches are getting countered, stop throwing so many. If defence isn''t working, go in guns-a-blazin''.

To futher extend this, you could create several different state tables that would get triggered depending on the success of the NPC. i.e. If the NPC lands 19/20 punches in 10 seconds, sucking away 1/2 of the players health, the NPC goes in to ''cocky-bastard'' mode. If the NPC is getting beat to a puplp they could enter ''run like a coward'' mode.. By adjusting these tables, and the likelyhood that each on is called, you could give each of your characters their own personalites.. (ie: maybe nurse betty cowers if kicked too many times)

If you want to make it less predictable, just ''weight'' everything. 20% chance that the NPC will go into punch mode, 10% chance they will kick, etc... A random number generator does the rest of the work. You could adjust the weights throughout the fight so that the NPC looks ''responsive''.

Looking forward to seeing the finished game!
Will

------------------http://www.nentari.com
I agree with RPGeezus. If you cant be bothered to implement a neural network, than fake one! Fuzzy logic can be very effective at this. Give each state a certain % chance of turning to to another state. E.g. The player performs a jump. If you use a prediction system to predict a following kick, you have x% chance of your bot blocking, y% of retreating and z% of counterattacking. (Where x + y + z = 100%) These percentile can in turn be dynamic according to the learning table (If there is one) This will make the bot varied with the minimum of work. Also you might want to make sure that bot actions can be interrupted. (E.g. the bot starts approching for a punch and the player retreats to kick, the bot might want to "change its mind" about punching.)
I´ll take that Turing test anyday!
I''m not really into these kind of fighting games because i always get confused with the keys, but to me this seems like a rock-paper-scissors thing. At each time step you decide on a action that hits (you win), gets block (nobody wins), fails and you get hit (opponent wins). There are strategies for repeated RPS like games, so i suggest you look at these. These strategies will assume that both players always choose their action at the exact same time step, so here you''re have to solve it yourself.

With respect of player personalities you can include a memory in the actions with some decay rate. Suppose action kick will have a certain value and every time the character kicks you add one point and if it doesn''t kick you reduce this value a little according to some decay rate. If the value gets above a certain threshold the character cannot use this action and has to wait (do something else) until this value is below the threshold again. By assigning different values for the thresholds and decay rates for each action for the characters you can create different personalities. For instance if you include a pony girl (you should definitly do this ) you can make the threshold and decay rate for the backward kick high. In this way it can and hopefully will do more backward kicking. By including this mechanisme the actions selection becomes a bit more involved, but it will automatically make the charachter change actions. You are forced you come up with a action selection mechanism that does not simply select the best action and keep repeating itself....

I hope these ideas make sense.....

ps: you should also include a character like the dark mistress form dungeon keeper or like Michelle Pfeiffer as catwoman, you know, a 3D model with a decent amount of specular reflection
quote: Original post by Froztwolf
Fuzzy logic can be very effective at this. Give each state a certain % chance of turning to to another state. E.g. The player performs a jump. If you use a prediction system to predict a following kick, you have x% chance of your bot blocking, y% of retreating and z% of counterattacking. (Where x + y + z = 100%) These percentile can in turn be dynamic according to the learning table (If there is one)


Just to clarify, that''s not Fuzzy Logic that you are describing. You''re talking about probability distributions of the form:

p(me kick | opponent just jumped then kicked),
p(me block| opponent just jumped then kicked),
p(me retreat| opponent just jumped then kicked),
p(me counter_attack| opponent just jumped then kicked).


BRZGames: Can your current game logic handle your fighter walking and punching at the same time (or combining any movement action with any fighting action), as opposed to walking and THEN punching?

Cheers,

Timkin
Just to add to Timkins correlation idea. You don''t have to use statistical models. You can use string matching to produce a similar effect. Here''s how it works:

Lets say the fighter''s moves and attacks are each given a character, say A, B, C..., J; representing 10 different moves. Each frame you record the human player''s current move. Let''s say you end up, after 20 frames with this series of moves:

A, B, B, B, J, J, G, I, E, A, B, B, B, J, D, E, D, E, A, B

The most recent move is to the right. Now, to make a prediction you find the longest string that matches the most recent moves. In this example it is:

E, A, B

The move immediately following this sequence is B so there is a good chance the player may make this move his next move. Simple eh?

This method can work well but its speed deteriorates as the size of the string increases.

I know this method can be improved upon, I think there is an article in one of the Gems books (or AI Wisdom) but I can''t remember which. (I''ve only just woken up!)

It''s something you may like to consider anyway





ai-junkie.com
Wow, I can''t believe the response I''m getting!!! Thanks guys!!

Timkin,
Right now punching, and walking are two different states, not so much limited by the state machine itself, but by the fact that there are separate walking, and separate punch animation sequences. I guess if I added a walking while punching animation sequence, I could allow it.

Fup,
Your string matching idea looks very interesting. It would be very easy for me to implement such a system with the current state machine. Do you think that would work just as well as a statistical model?

Smilydon
A decent amount of specular reflection?!? LOL. I was thinking about including both a Cat Girl type, and a Mistress type character in the game just FYI. I like your idea about a memory in actions with a decay rate. I was originally considering doing something similiar, in which I''d assign a number to a move that the system would use as a weight to determine how often a move would occur. I hadn''t thought of the decay rate.

RPGeezus
Your idea of different characters mode sounds pretty cool too. Maybe have a ''Cocky Bastard Mode'', a Normal mode, and a coward mode that would effect how the computer fights, and be able to assign a number to determine at what point each character might enter any of these modes... More food for thought...

Froztwolf
Actually, what you have suggested is very similiar to the way it works now. The computer decides it wants to attack at close range, it advances toward the opponent (either by walking, or flipping), and then performs a predermined move. Now if at anypoint prior to starting her attack sequence, the computer gets attacked itself, it can change its mind and block, duck, and jump to avoid a hit.


Ideally, my first thoughts after reading everyones posts is to add Fup''s string idea (I could still use a statistical correlation here if needed), and combine with with Smilydon''s weighted move decay rate idea and RPGeezus mode idea. That should hopefully allow the characters to fight intelligently, and have a large range of personalities.

Again guys, thanks for all the ideas. Now I need to start putting them down somewhere so I can remember all of them.....
Interesting Topic. I to have a similar problem. I am trying to incorperate realistic AI that CHANGES depending on character to match personality. Guan Yu, a master in battle will be very agressive while Gan Ning will be a very defensive player, never full on attacking but rather winning with counters and evasive attacks.

Any ideas as to how to incorperate a form of personality into different characters?
According to your description of how you see personalities applying in the game, each personality could be implement as a preference for certain moves over others. You could apply a probability of selecting each type of move (defensive, aggressive, neutral) that sum to one and then a probability of each type of move within each of those categories (that also sums to one). That way, two characters that might both be defensive in nature will have different ways of going about it.

That''s just one idea though. I''m sure there are plenty of other ways you could implement personality.

Cheers,

Timkin

This topic is closed to new replies.

Advertisement