Fighting Game A.I.

Started by
18 comments, last by DirectorX 20 years, 10 months ago
Hello, Can anyone provide information regarding obtaining source code or some reference on 3D fighting games A.I. ? Have anyone in here ever developed an A.I. system for a fighting game ? Thanks DirectorX ICQ#175747591
Advertisement
I wanted to make a fighting game with AI a long time ago, but never did. My best guess at how the AI works is that it uses some form of a finite state machine, but I don''t know anything about fighting game AI so don''t take that as gospel.
as a fighter myself, I would say it''s something along the line of a finite state machine with simple pattern recognition.

When I''m fighting, I look for certain patterns. Most fighters use the same sequence of moves, and when the first move of the sequence is thrown, the next few moves are almost certain to follow. For example, a simple combo: jab+punch+kick. for most amatuer fighters, if they throw this combo once, then it is almost a certainty they will throw a kick once they have thrown a jab+punch.

also, depending on what set of combos a fighter is useing, I will adjust my timing to suit. If someone is using a lot of kicking combos, I will try to preemptively attack with hands, or block and counter with a power kick or punch, or stay out of range and counter. However, if a fighter is using more punching combos, I will fight with more kicks, trying to keep the fighter at the edge of my range.

Now, disregarding the opponent completely, I have certain techniques that I like to use. For some people its hands. They should generally fight more aggressively, beginning combonations with kicks to bring them in range to use hands. For other people, it''s kicks using speed generally with very weak hands. They should also fight aggressively, but should use a variety of kicks and lay off the hands. Finally, there are people that like to use powerful kicks. The should fight more defensively, generally looking to counter-attack more often then attacking straight on. Combonations will usually start with hands and end with kicks as the fighter retreats back to a safe distance.

Technique is useless if it has no chance of hitting a target. All it does is create openings for your opponent to exploit and allows your opponent to analyze your fighting style. Attacks should only be thrown if the target is in range. The opponent may come into range, or the attacker may launch himself into range, but either way it is dangerous to throw technique that hits nothing.

some fighters have unconcious habits, like "poker faces", or "nervous ticks". in fighting they are called "telegraphs". Some fighters are bad about it. For example, I knew a guy that would wipe his nose before throwing a kick to the head. Eventually, after walking head first into it for about a month, I realised this and was able to counter. A lot of people tend to tap their foot before kicking, or bob their hand before punching. Watching for these little tells can really enhance the ability to counter.

And that''s all i care to tell you...

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Not all fighters follow "programmatic" responses, so I''m not sure a FSM with pattern recognition would be the only way to go. While a great many people can and do develop repetitive patterns or telegraph their moves, some are better than others about this.

Plus, what happens when you face a fighter of a style you''ve never seen before? I''ve had the privilege to have been exposed (and sometimes trained) to at least 10 different martial styles (off the top of my head, Shotokan, Wing Chun, Escrima, Judo, Aiki-jiujitsu, Hapkido, Boxing, College Wrestling, Choy Lay Fut, Baguazhang, Tai Chi and even western fencing). What''s amazing is both the similarities all martial styles have, and some really huge differences. I''ve seen first hand and have participated in fights against opponents of totally different styles. It''s funny sometimes to watch what happens when a fighter who is used to fighting against certain techniques or fighting strategies to be paired off against someone with very differnt techniques and/or strategies.

Ultimately, a fighter learns not to think, and the more mental "chatter" you have in your head (ie "ohh, he just rotated his hip...I bet a roundhouse kick is coming" or, "I''ve got to throw a feint to get him to lower his guard") the worse off you''ll be. So how does a fighter do what he does? Partially it''s autonomic "wiring" that when an attack is initiated, a certain move is initiated in response. This follows capn_midnight''s suggestion of an FSM.

However, there''s a problem with this. Once you figured out your opponent''s "wiring", he''s in trouble. I suppose you could use a GA to have the AI learn what kinds of combinations or reactions are typical of a certain style or even an individual. And then from this, use this knowledge to your advantage. A truly good fighter however doesn''t have "technique" or form anymore, and is what Bruce Lee referred to about formlessness. Indeed, Japanese martial arts often talks about "mu" which means void or emptiness, and that from this nothingness comes form. In other words, you just do what you do without sticking to a formalized way of doing something. It seems paradoxical that people train for decades in a structured and ritualized way to learn to just "do it".

There''s a story about Chang Sang Fen (the creator of Tai Chi) and how he taught a disciple. He asked this disciple to study for one year on a remote mountain top the Tai Chi forms. When the student came back after one year, Chang asked him how his training went. The student replied, "it was okay, but I feel as if I''m doing the forms wrong, some of the moves don''t feel right". Chang shook his head and told him to spend another year alone practicing the forms. Again, after a year, the student came back and was asked how his training went. This time the student apologetically replied, "I''m sorry master, but my training has become worse, I feel as if I''m doing all of my forms wrong now". Chang looked sternly at the student and told him he must practice one more year again. Finally after one year, the student could not bare to look in Chang''s eyes. When Chang asked the student how his training went the student replied with bowed head, "forgive me master, but I no longer remember the forms as you have taught me. They all feel different". At last Chang sighed then laughed, and told the student that he had made Tai Chi his own and had learned well.

The moral of the story is that techniques aren''t random at the highest level, they just don''t really have a shape or form anymore. Now, how you can represent this in a game...I don''t know. Admittedly, I''m talking master level fighting skills here that few attain, so you can probably do away with alot of this and just go with the FSM that capn suggested as it will account for the majority of fighters. I do think that FSM''s will fail when encountering a martial style that the AI has never seen before, so some kind of learning algorithm will have to be used instead.


They that can give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety. - Benjamin Franklin
The world has achieved brilliance without wisdom, power without conscience. Ours is a world of nuclear giants and ethical infants. We know more about war than we know about peace, more about killing than we know about living. We have grasped the mystery of the atom and rejected the Sermon on the Mount." - General Omar Bradley
Chase the player when you''re healthy

Run when hurting

Attack when you can

move to where you can attack when you can''t

[ just felt like telling you something useful rather than random musings over martial arts ]
From conception Fighting games have been dominated by the Japanese. The most popular in the arcades Street Fighter, Virtua Fighter, Tekken and King of Fighters are all Japanese games. There is rarely no tutorials or books available on writing A.I. for fighting games. The western hemisphere of the world have a fetish for A.I. for First Person Shooter games. Can someone please provide me with some reference on creating good A.I. for a fighting game.

Thanks
Director X
Just to correct the Zhang San Feng story, which is in Jin Yong''s Heavenly Sword and Dragon Sabre (my translation):

The disciple in the story is Zhang Wuji (who used to be from Wudang), and he in his own right is one of the best pugilists around, but no one knew at the moment. But some people wanted to challenge the Wudang sect (where Zhang San Feng is the leader) and most of the guys in Wudang were either injured or too weak. So Zhang Sanfeng taught Wuji the Taiji-Quan (or the Fist of Tai-Chi).

After the first time he demonstrated, Wuji said, "I only remember half of it."

After the second time, Wuji said, "I cannot remember anything."

And that was when he mastered it.
I would go with the finite state machine with simple pattern recognition!

Make a table with all posibilities (should not be that many (since you controle it with the keyboard)).
(with a posibility i mean:
ex:
1: in range for kick/not in range for punch/oponent is blocking
)
Then give the AI the same controles as the human player.

Now you could make an A.I. recorder, witch look at you playing another person, finds witch posibilitie you are in, and record your action....
if (close_enough_to_kick && oponent_dont_block_kick) kick :-)
There should be more then 5 options on each posibility, and they should be rated on how well they did.

You should not create the perfect fighter! (that would be booring to always loose, the human player is always slower, and smarter)

Now when you have the big table of all the fighting posibilities, and all data is stored, you can start to create personalities!
feks:
a kicker: ( lower the rate on all punches)
a boss: ( remove all with rates below this and that )

Now in the game, find out what situation the player is in, find what action that are good... choose action (randomly or patterned) do action.

to make it bether, you can mark every action(in a psiibility) with a timer!
if the action was bad, mark it -10, and the AI will not do it for some time ( ten seconds... ??? )
if the action was bad, mark it +10, witch means that this move works realy good!

hope i helped, and that my englis is not to bad!

[edited by - uncutno on May 24, 2003 8:06:29 AM]
-Anders-Oredsson-Norway-
I would have to disagree with the idea that fighters become totally confused when facing a style they have no experience with. Or, atleast it depends on the particular style the person studies.

My school competed in a large tournament about a year ago. We study Tae Kwon Do (or rather, our masters art which is based on Tae Kwon Do). There was a Kung Fu school represented at the tournament with a lot of students. The most Kung Fu we have ever seen has been from Hong Kong action flicks. I didn''t get to fight any of them, but some of our other students did. These Kung Fu stylists were fooling everyone else at the tournament, except our students. They would try these Crane stances, and Tiger stances, and generally strange things. (in our expeirence, we''re used to fighters staying level with both feet on the ground). But, our students destroyed them, and I think it was because we haven''t been taught "Use this technique versus this technique", or "when your oppenent throws a reverse punch, you throw this kick", we''ve been taught, "When your opponent creates this OPENING, use this technique". For us, our fighting is completely independent of our opponents style. We study human nature as well, ie. if I flick a punch in someones face, or fake a kick, and they flinch, they are fairly certain to do it again. Humans are creatures of habit. Even the greatest fighters have their habits. Bill "Superfoot" Wallace, WPK Undefeated Champion, retired at 20 consecutive wins with 11 KO''s, beating nearly everyone with a hook kick. Everyone knew what he was doing, he was too fast for you to stop it.

Anyway, fighting should be independent of style. There isn''t that much difference between styles anyway (except for stance, and that''s just an illusion). A punch HAS to have a starting and ending point, it HAS to have a target, and it always opens the body up for a counter. It doesn''t matter if it''s a Kung Fu punch or a Karate punch or a Boxing punch. There are only just so many ways to start and end a particular technique.

For example, three kicks, the rising kicking, the round kick, and the cut kick. The only difference between these kicks are the starting and end point. Rising Kick starts low and ends high.
Round Kick stays level. Cut kick starts high and ends low. All three kicks are basically the same otherwise, they both contact with the same part of the foot, both follow right to left (or left to right, depending on which foot you use), both use manly the lower leg.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

quote:There was a Kung Fu school represented at the tournament with a lot of students. The most Kung Fu we have ever seen has been from Hong Kong action flicks. I didn''t get to fight any of them, but some of our other students did. These Kung Fu stylists were fooling everyone else at the tournament, except our students. They would try these Crane stances, and Tiger stances, and generally strange things. (in our expeirence, we''re used to fighters staying level with both feet on the ground). But, our students destroyed them, and I think it was because we haven''t been taught "Use this technique versus this technique", or "when your oppenent throws a reverse punch, you throw this kick", we''ve been taught, "When your opponent creates this OPENING, use this technique". For us, our fighting is completely independent of our opponents style. We study human nature as well, ie. if I flick a punch in someones face, or fake a kick, and they flinch, they are fairly certain to do it again
Don''t kid yourself. You beat them because they sucked. A better fighter would know that he fliches, and incorporate that into his style. I pull my face back when you feint a punch? Great, use an inverted knifehand or ridgehand with your front hand to siphon the power of your retreating body into an attack.

And nobody really stands on one leg in kung fu. The reason for doing so is so you can feint a kick or lift your foot up to avoid sweeps that are too short or kicks to the shin or ankle, and still throw really nasty attacks without needing to set your foot down. The moving up and down stuff is for fighting people who have fallen down (and are probably trying to get up), or dodging. (or just fighting really short people) At the advanced levels, you fall and rise with your falling and rising attacks to increase the power.

Giving yourself a new "nature" isn''t that tough, either. I''ve only been studying jujutsu for two years, and I''ve already stopped resisting pushes to my body almost completely.

For the record, crane and tiger are easy, and relatively similar to tae kwon do. Come back when you''ve fought against someone good at preying mantis or monkey.

quote:Anyway, fighting should be independent of style. There isn''t that much difference between styles anyway (except for stance, and that''s just an illusion). A punch HAS to have a starting and ending point, it HAS to have a target, and it always opens the body up for a counter. It doesn''t matter if it''s a Kung Fu punch or a Karate punch or a Boxing punch. There are only just so many ways to start and end a particular technique.

Stance is an illusion only so far as stances are evanescent. The differences between stances have strong effects on the number of techniques available to you and the power of them. Your stances also have a very strong effect on your ability to counter, move around, and dodge.

Anyway, there are two categories of martial arts, one of which invalidates your statement that fighting is independent of style. There are striking and grappling arts. The older a martial art is, the more likely it is to straddle the boundary. If you were to fight an aikido expert, you would find yourself completely confused. There may be little difference between a kung fu punch and a karate punch, but there''s a hell of a difference between a kung fu punch and an aikido punch, considering that there''s no punches in aikido (correct me if I''m wrong about that). It''s not a deficiency, not a blind spot, it''s a style.

quote:Even the greatest fighters have their habits. Bill "Superfoot" Wallace, WPK Undefeated Champion, retired at 20 consecutive wins with 11 KO''s, beating nearly everyone with a hook kick. Everyone knew what he was doing, he was too fast for you to stop it.
I don''t know the specifics of the WPK (google finds nothing), but I''ve heard in Tae Kwon Do tournaments, it''s against the rules to punch the kidneys. In most tournaments, it''s against the rules to aim for the groin. In tournaments for striking arts, throwing is either not allowed or strongly discouraged (and certainly not taught). Without any of these options, a spinning hook kick is mostly unstoppable. Even if you counter, you still get kicked really hard.

The trivial method of stopping a hook kick, without these restrictions, is to tackle your opponent. Almost regardless of the point in the attack when you realize your opponent''s attack, a tackle mitigates or avoids the damage. A spinning hook kick is useless at close range, and if you put your head on the opposite side from the kick, the only available target is your shoulder, which can take extreme amounts of punishment without being damaged.

Back on topic:
The finite state machine is definately the way to go. At the broadest level, there are two states -- free to move and not free to move. Beyond "free to move", there''s states that correspond to the different distances from your opponent: too far to matter, jump kick distance, kicking distance, punching distance, knee/elbow distance, trapping distance (real fighting games never seem to get to the last two). If you''re too far to matter, move in. If you''re in jump kick distance, move in. If you''re in kicking distance, choose the fastest move for which you are in range or the move that precipitates the most devastating combo or simply move in to punching distance. If you''re in punching distance, choose the fastest move or the move that precipitates the most devastating combo. Or, for any of the above, just wait.

To choose from one of the choices, you could vary the selections from character to character, or you could use the history of the character to choose. If the player frequently uses slow, devastating attacks, the AI should wait, then block, then counter. At a design level, you need only select "wait" as your action and let the "wait" command block and counter, rather than add states like "incoming attack" for which the action is to block.
---New infokeeps brain running;must gas up!

This topic is closed to new replies.

Advertisement