
Street Fighter II's AI Engine - FroshKiller
https://sf2platinum.wordpress.com/2017/01/20/the-ai-engine/
======
billmalarky
"When reacting to an attack the scripts are chosen based on something called a
yoke. Each frame of animation for both avatars and projectiles contains a
value for the yoke in the metadata, which the AI peeks at to select a script
suitable for responding to that attack. The computer sees the yoke of your
move as soon as you have input it, before the first animation frame has even
displayed. As such it gets one more frame of advantage on top of your reaction
time."

I KNEW IT!

------
indspenceable
> These days, when most people talk about AI they’re talking about machine
> learning. There’s not any of that in SF2.

Actually, AI for games is pretty much never equivalent to AI for non-games.
The end goal is different - games want to provide a non-optimal set of
instructions, so that it's challenging but not impossible to win. The goals
are entirely different.

If you're making a game, this is probably at least a useful example to look
at, even if I don't agree with some of the decisions they made
(uninterruptible moves, for instance)

~~~
echan00
Completely agree. Games are typically only "fun" when you feel challenged.
Most people do not find "fun" in losing.

~~~
Houshalter
The thing is most simple game AI isn't challenging. Or it's challenging in
boring ways. Like having 100% perfect aim or long health bars. It's awesome to
have an AI that is challenging by actually being good at the game. Having some
actual strategy and intelligence.

It's a complete misconception that "real AI" needs to be super hard. Give it
realistic constraints like slow reaction times or noisy input. You can
handicap it in many ways to control the difficulty. Modern chess engines can
easily beat even the best players in the world. But by limiting the number of
moves they search, you can set one up that new players can beat.

My favorite game AI is from age of empires 2. All other RTSes just let the AI
cheat like crazy to provide challenge. For AoE2 they went to a lot of work to
design an expert system and a custom scripting language for it. Tons of
features were implemented to make it easy to write relatively sophisticated AI
strategies. And they documented it well and made it easy for modders to write
even better AI scripts.

As a result the AI on hardest can beat all but skilled competitive players
without cheating at all (at least the current AI shipped with the steam
version.) It's actually fun to play against and isn't a terrible substitute
for a real human player.

~~~
krasi0
Similarly to that, there exist AIs for Starcraft Broodwar that are capable of
providing a decent challenge to novice and intermediate level human players.
You could check some examples at play on:
[http://sscaitournament.com/](http://sscaitournament.com/) and also develop
your own AI in one of the more popular programming languages (C++, Java, etc).
Disclaimer: I am the author of one of those Starcraft Broodwar AIs

------
RealNeatoDude
It's funny how much SF slang hints at you and your opponent being lackluster
AI scripts:

\- Downloaded: when you've identified your opponents patterns and know what
they're going to do next. Ex. they always jump after they jab.

\- Conditioning: when you've trained your opponent to react the same way
consistently to something you do. Ex. they always jump when you throw a
fireball because you've let them do it successfully.

\- "time to guess": situations where, if executed correctly, your opponent
must choose one defense from many defenses randomly. Ex. your jump trajectory
is such that whether you end up on the left or right side of your opponent is
determined by a pixel.

A phrase that novice players say a lot is "HOW DID HE KNOW?" because they're
in shock that their opponent is "guessing" right every time when really their
opponent just knows what the novice is going to do in every situation. What's
impressive is that "every situation" is really the more skilled player
abstracting over similar situations. Ex. they recognize kick->jump =
punch->jump for their particular opponent. I don't think an AI will be able to
make complicated abstractions like that on an offline game console for a
while.

~~~
vvanders
Yeah, Sirlin covers that really well in his Layers of Yomi on Playing to Win:

[http://www.sirlin.net/ptw-book/7-spies-of-the-
mind](http://www.sirlin.net/ptw-book/7-spies-of-the-mind)

------
ivan_ah
I wonder if knowing the different strategies would make pro-humans better at
playing the game. I feel like they might already have internalized the
different strategies the computer uses, but still pretty surprising to see how
simple the source code is.

Also cool to think about would be AI-vs-AI street fighter competitions. Or SF
AI that learns from live matches currently being played online.

~~~
unkoman
> AI-vs-AI street fighter competitions

[http://www.saltybet.com/](http://www.saltybet.com/) does just that.

~~~
ivan_ah
nice... somewhat glitchy, but still pretty good.

I doubt there is reinforcement learning going on though, I think the AIs of
the mugen characters are hard coded.

------
redm
> Anyone looking for some insight into how to write an AI engine for a game
> today will be disappointed.

And yet, it was really effective and fun. This is like a magician revealing
how a trick was done, it's always a "letdown".

~~~
EGreg
Well you are in luck because in a major sense, deep learning AI cannot reveal
how the trick was done unless you are willing to speak in terms of a model
with trillions of variables and feedback loops.

------
CocaKoala
"Charge moves such as blade kicks are simply executed as instructions, so they
cannot fail. Guile can do a bladekick from a standing position simply because
that’s what’s in the script."

That's a pretty big cheat, to be honest.

~~~
ben174
Welcome to the frustrations of my childhood.

I sort of neat trick is during a dump you can be holding down to charge your
"blade kick"* and immediately when you hit the ground, press up and kick to
execute the move, and it gives the appearance of one of performing the move
without charging. Sometimes gets a surprised look by your opponent.

* we called it a flash kick, but whatever.

------
kensai
I wonder if one can create an invincible AI for Street Fighter II. One that
obviously makes the right choice always and can counter every possible human
attack.

(kind of think that it was also possible even back in the 90s, but never
implemented; what would have been the point?)

~~~
kstenerud
Mortal Kombat II effectively did this with really shitty AI. If you jumped
towards an opponent, they would jump straight up and hit you with a projectile
with perfect accuracy. Every time. It was impossible to throw a computer
opponent because the AI had better timing then you. Every time.

In fact, the only way to beat the computer opponent was to take advantage of
weaknesses in the AI script, the biggest one of which is jumping backwards
when there's a specific distance between you. The computer would jump towards
you, leaving them open to you jumping forwards with a kick. Every time. Just
don't get caught in the corner.

~~~
jordigh
There's a "bug" in the MK2 script I've never quite understood nor seen
explained. Sometimes when jumping at the computer from a certain distance (and
perhaps certain difficulty level) it will move back and will keep moving back
trying to separate itself from you as long as you press no button. You can
walk it into the edge and will stay there, forever trying to move back. Then
you could move back yourself, wait a second, and it would throw a projectile,
letting you jump in over the projectile for a corner combo.

Yeah, the MK2 AI isn't much fun. It's designed to eat quarters, not to provide
a fair fight. :-/

------
radarsat1
That's pretty fun, thanks for sharing ;)

Actually with a machine learning approach it's not immediately obvious to me
how to incorporate it. I suppose an RNN or reinforcement learning could be
used, in principle, to learn good reactions to a given sequence from the
opponent, but it would take so many failures to train it, which would have to
be generated more or less manually. I don't see how it could be done easily,
and certainly not in an "online" way without delivering a pretty terrible play
experience.

Are there any good examples of computer-controlled players using an online (or
offline) machine learning-based approach to player control, that doesn't
suffer from these problems?

The image that comes to mind for me is a computer player that gets better and
better at beating you, but the problem is that with reinforcement learning
there is no guarantee that this happens reliably and in an amount of time and
gradient that would provide a good playing experience -- and then you'd be
faced with the problem of it getting "too good", equally not a particularly
good play experience.

Perhaps something in between? A machine learning approach that helps select
and maybe parameterize these "scripts"?

~~~
NikolaeVarius
They're fighting games. Why do we need to incorporate machine learning at all?
If the computer wanted to they could always play perfectly because it could
react to any input perfectly.

~~~
viewer5
'learning to fight against you, sort of like a human would' is a lot more fun
than 'literally cheating and perfectly countering you'

~~~
eyko
Since humans are not infallible, let's leave it at 'learning to fight against
you, sort of like a superhuman would'.

It would make for a formidable opponent since you can still defeat it (with a
good dose of luck).

~~~
wmil
If you forced the AI to work with a substantial input lag, it could be quite
complex yet still possible to defeat.

------
c0achmcguirk
I'm going to find Vega's script and replace it with NOOPs. I hated playing
Vega. He would climb that wall like a spider and then jump with a shrill yell
and then body-slam me.

I think that's the most rage I've ever experienced in my life....just
repeatedly getting beat by Vega.

The only thing that comes close is getting hit by the blue shell in Mario
Kart.

~~~
madshiva
lol, vega is easy to beat come on! There's a lot of trick in SF2, with almost
every character.

Thanks for the info, I'm currently building my SF2 game and was wondering how
they made their AI, then much thanks for the sharing.

------
michaelbuddy
Losing is not fun but _almost_ winning IS fun. Progress through refinement,
strategy and speed is fun.

------
faragon
Gaming AI must be "beatable". "Good" AI is not good for having fun games.

------
the_denial
Why aren't there longer bytecode instructions?

~~~
sf2platinum
1\. Because it's not necessary, there are a lot of them instead, so it runs
through a short script, picks another one at random, rinse, lather, repeat.
2\. Longer scripts would be recognisable and easy to beat.

------
nischay
seems like it is down, 502 error
[https://usafacts.org/](https://usafacts.org/)

------
snickmy
AI != IF STATEMENT + RANDOM

~~~
luhn
Sure it is. AI is a computer reacting to its environment to solve a problem.
It doesn't necessitate machine learning, neural networks, or what-have-you.

~~~
snickmy
Sorry but I don't see any intelligence in this.

~~~
Kiro
It's still AI though.

~~~
snickmy
I always thought that the I in AI stood for Intelligence

~~~
0x0
AI always seems to be that elusive magical self-conscious computer algorithm,
which when revealed to run on actual binary logic is claimed to be "not AI
after all"

