Do you know of any document or other source that tells you about fighting game AI?
Let's say I want to do a classic 2D fighting game, be it for a console or just as a PC game.
I would probably be able to program the physics quite easily. It would take a while until the game feels right, but it probably wouldn't pose a major problem.
But how do you implement a decent computer AI, i.e. something like in "Street Fighter II"?
Is there any general tutorial on that?
An extremely good AI would be able to predict your actions and react to everything else. Nobody would want to play against that.
There was
an article about "Fun AI" vs "Good AI". "Fun AI" is trying to make a game experience for the player, and not necessarily trying to win at all costs. "Good AI" is more like the chess computers.
The problem with the Street Fighter 2 AI is that they cheat. No charge times for special moves and no initial attacks for rapid mashing moves.
As for the question of a fighting game AI, you'd need to know the attack ranges of moves, so you'd know if a character would be hit if the player decided to make a move. You'd need to know how many frames are remaining in a jump or jump attack. Which move has priority over other moves, how to block, lots of stuff to consider.
Sure, good AI vs. fun AI is something to consider when it comes to balancing.
But in the moment, I'm looking more into the hard facts:
Is it about writing all possible combinations of situations that two fighters can be in and then fill some randomizer with possible outcomes? Or are there more eloquent ways to implement an AI? Is there a commonly used way for games like these?
Something like that would be helpful.
One way to think about the problem that forces you to consider lots of fighting game and AI intricacies is "what if the AI can only react to things that were 10 or more frames back?" or conversely "what if any buttons the AI presses now will happen 10 frames later?".
The question as I understood it was "how do I even start making an AI", not "how do I fine-tune it".
If you're looking to start making an AI, one approach used in (relatively) modern games is creating state machines.
I imagine this would work on the NES, but I haven't seen any concrete examples.
For example, you can have an "Idle" state that transitions into a "High Attack" state when the opponent jumps.
Couple that with a bit of randomness, and you likely have a solid formula for AI.
Here's some AI files from Skullgirls in Lua. (From an old July 6th 2013 build of the game since I happen to have them.) I could probably get more recent ones, but these are already on my computer.
I'm not sure there's really any tricks to fighting game AI. It's complicated because fighting games are complicated. If you know good fighting game strategy (what to do in what situations), you can use that to make your AI. Same as you'd study chess to make a chess AI.
Honestly, I'd just do something based on random button press for a start. Maybe I'd fine tune it from there to make existing combos a little more likely, I don't know how.
A pattern would look more realistic and less crazy but also more predictable and more defeatable.
The simplest AI design I know of is a priority-sorted if-then list. You test a series of conditions, such as "player location relative to me falls into this bounding box", pick the first one that returns true, and then carry out the matching action, such as "execute a high kick". Final Fantasy XII has a player-visible implementation of such an AI, in the form of the gambit system, that probably describes it better than I could.
The next step up from that is a finite state machine. You can think of it as a combination of several if-then chains, with a persistant "state" variable selecting which one to use, and a "go to state N" action to change the current state. For example, any action that causes the AI to jump could switch to an aerial state.
You can of course add randomness and timing and whatever else you like to the basic structure; conceptually it's just chains of if statements wrapped in a switch statement.
I remember an anecdote from an old C64 fighting game (IK+?) that the AI had a table with the exact way to block every possible attack from the player, but the AI would read the wrong table entry sometimes (more errors on lower difficulty settings, less errors on the hardest settings).
tepples wrote:
The question as I understood it was "how do I even start making an AI", not "how do I fine-tune it".
That's right. I'm looking for a description on how to do this in the first place. A description of how professional games did this.
The tips that you all give are nice and good. And yes, if I can't find anything, I will probably start with a bunch of hard-coded stuff to check for all possible combinations and then I'll fine-tune it and include the things from this thread.
So, sure, I can always make something up yourself and experiment with it.
But I was hoping for a single, consistent tutorial or document. A description that explains an effective way and best practices on how this was actually done in professional fighting games.
I mean, the behavior of the characters themselves is of course different every time. But maybe there are some things that these engines have in common to implement intelligent behavior at all. And I'd like to find out how the pros do this.
Yes, I can be creative and give it a shot in the dark and simply try to implement my very own AI by checking for position (standing, jumping, ducking) and distance and then include everything else as I go along, hoping that the AI will feel natural.
But I was hoping for some place on the internet that explains you what you have to look out for and what you have to think of when designing an AI for a fighting game.
You're looking for a description of how professional games did this, but an actual AI implementation from a professional game is not any help?
Oh right, I forgot to mention your scripts. Sorry.
Well, the thing is this: It is pretty difficult to read through and to understand unknown source code when it comes to complex stuff like this.
When I have a generally working program and there's a little detail that I just don't know how to do it, then looking into specific parts of existing source code might help.
But when you're at the start of something, then looking at a completely finished project of several thousands of lines of codes will not really help you, unless you're some kind of genius who can read through source code like a compiler.
That's also the reason why I discourage people who want to learn game programming from taking an open source game and trying to learn from it by modifying it: First of all, it is definitely too much code. And secondly, you don't really learn it from the ground up.
I would need a tutorial that explains the components of an AI in prose. A description from the very basic stuff to the more complicated things, step by step, so that you actually understand what the tutorial tells you and don't just see the finished end result.
Looking at source code of a complete game would hardly help me.
I found a video that does a pretty good first explanation of how AI can be implemented:
www.youtube.com/watch?v=MnW3bBdCaOk
DRW wrote:
A description of how professional games did this.
And how are we supposed to know that ? None of us worked at Capcom when creating Street Figther II, as far as I know. Your best bet is to look at books, once I found a book on game AI which was interesting (although a large part of the book was too advanced for things applicable to NES games, a large part of it actually was applicable). However I don't think fighting games were mentionned at all, and they're quite different from other games. I suspect most of them were supposed to be played "normally" with 2 players, and the AI is really a placebo to allow for bored players to still play the game now and them.
Bregalad wrote:
And how are we supposed to know that ? None of us worked at Capcom when creating Street Figther II, as far as I know.
And still, many of the people here know, for example, the NES better than the developers from back then. So, I guess it's not a
too stupid idea and ask this community if they have some information about this kind of stuff, despite them not having been licensed developers, right?
Bregalad wrote:
DRW wrote:
A description of how professional games did this.
And how are we supposed to know that ? None of us worked at Capcom when creating Street Figther II, as far as I know.
I guess DRW assumed that some intrepid ROM hacker knew
Street Fighter II as well as ShaneM knows
Super Mario Bros.
You could always reverse engineer one of the Street Fighter II clones on nes.
If the AI in those games is as good as the controls or the physics, that doesn't sound like such a great idea.
The NES does have a few licensed fighting games, though: TMNT Tournament Fighters, Joy Mecha Fight, Datach Yu Yu Hakusho, Datach Dragon Ball Z...
And any Super NES fighting game will have 65816 code, which shouldn't be hard for a 6502 hacker to learn.
I don't have much to add to the question, just a little anecdote. I got a 3DO recently that came with Way of the Warrior which I tried out, it's absolutely brutal. Not that I'm a great fighting game player or anything, but I found it entirely unwinnable without setting the handicap to my favor. Out of curiosity I read a little bit about the game, the programmer has a degree in artificial intelligence and touted the game's AI as being a great feature of the game. It may be technically impressive, but it was easily the most frustrating and un-fun fighting game I've ever tried to play.
Yeah I owned that game for 3d0 and was quite excited when I read that about the programmer....then I played it.
tepples wrote:
I guess DRW assumed that some intrepid ROM hacker knew Street Fighter II as well as ShaneM knows Super Mario Bros.
I didn't assume anything specific, I was just hoping that somebody might know details about any old-school fighting game AI. I didn't know what I could expect, that's why I asked to find out what knowledge exists about this topic.
OmegaMax wrote:
You could always reverse engineer one of the Street Fighter II clones on nes.
The developers of these games are just as unlicensed as myself, so their AI is no more a representation of a professional 90s fighting game AI as if I made one up myself.
Also, these AIs are shit and don't feel like the real "Street Fighter II" at all.
Well if you want the "real"street fighter 2 ai logic you'll need to reverse engineer the game,that's going to be very difficult if you already have no idea how fighting games are handled.There is the Art of fighting source code floating around.
It's not actually specifically about "Street Fighter II". I'm not planning to do a SF2 port. My game, if I ever do one (in the moment it's just a general thought, but there's nothing concrete yet), would be an original fighting game with its own characters.
I was asking more about old-school fighting AIs in general. (NES pirate games don't count since they're badly-programmed.)
As I said, reading source code will barely help me, even if it was C code. Except if someone took the time to extract specifically the AI-relevant functions. But learning this kind of stuff from the full code of a complete game: That's not something that I'm any good at.
That's why I was asking for tutorials and the like. I'm interested more in general concepts, to see a (complete) way this is handled in general. I was hoping that fighting game AIs might have been done similarly enough, so that people today can say: "Old fighting games used this and that approach. Here's a tutorial on how to do something like this in your own code."
DRW wrote:
And still, many of the people here know, for example, the NES better than the developers from back then. So, I guess it's not a too stupid idea and ask this community if they have some information about this kind of stuff, despite them not having been licensed developers, right?
Nope, but reverse engineering the hardware and reverse engineering games are two completely different things.
A lot of people DO reverse engineer games though... it's not too farfetched to imagine someone has already analyzed a good fighting game thoroughly. Whether they shared their findings or frequent these forums is another issue.
The way I'd probably start to program AI for a fighting game (I think it would be 100x easier to come up with something yourself rather than reverse engineer a game) is by doing a bunch of conditional branches.
This is a lame example I came up with: If there's a projectile coming your way, consider jumping; if not, don't. Next, consider how fast it is going. If it is moving slowly, jump forward; if not, jump not moving horizontally.
Obviously this can be expounded upon to where it checks if there are more projectiles behind the one and how fast those are going and when to attack in the air (if at all) and things like that. For more novice AI, I'd limit the number of things being checked or have it to where they're only checked sometimes. I'd also have it to where the timing is less precise (there should be a sort of random number generator that stays in between certain values) as even the best AI shouldn't be frame perfect; otherwise, they'd be untouchable.
The major problem I can think of is actually making the AI play offensively. If you don't do anything, the AI has nothing to react to, but it could check to see how long you've been idle and decide to walk over to you. Well, I mean, it a start.
Espozo wrote:
The way I'd probably start to program AI for a fighting game (I think it would be 100x easier to come up with something yourself rather than reverse engineer a game) is by doing a bunch of conditional branches.
The thing with this is: If I do that, then it will just be an AI in the way I, as an amateur, imagine an AI.
But there is a pretty big difference between games like "Street Fighter II" or "Fatal Fury" and their NES pirate counterparts.
So, while the companies work independently from each other, there must be something that they all do differently from all those shitty amateur fighting games. And I was hoping that knowledge about those various AIs is partly available or that someone designed an AI algorithm that rivals professional ones.
Of course I can make up something myself. But maybe there's some kind of design pattern or best practices for an AI that is not just "I implement whatever comes to my mind."
OmegaMax wrote:
https://sf2platinum.wordpress.com/
Thanks. This guy might actually be able to help me.