That ratio would depend on what the other player was doing at the same time.That represents too many possibilities and may result in illogical actions.The goal here is that the AI acts like a human would.
AI in a fighting game
I'm designing a fighting game myself, only it's gonna be Mortal Kombat vs Street Fighter. Here's what you can do for AI for your fighters. Oh and forget about recording your movements in a
table. I just may have a better idea. Plus you are gonna want the AI to be random, yet smart.
Step 1) Make a list of constants based on actions your fighters gonna do. Kinda like numberical codes for every single action a fighter can do. For example: (Visual Basic)
Public Const Neutral as Long = 0
Public Const Walk_Forward as Long = 1
Public Const Walk_Backward as Long = 2
Public Const Croutch as Long = 3
Public Const Hit_High as Long = 4
Public Const Standing_Jab_Punch as Long = 5
Public Const Crouching_Fierce_Punch as Long = 6
Public Const Turn_Around as Long = 7
etc. etc. etc.
There's probably gonna be over a 100 constants, especially if you are gonna simulate street fighter. Then you can use these constants in functions that control the animation of the sprite.
It's a start so far.
Step 2) Create a state machine engine. A state machine is a
logical thought based AI you can use. Like for example, let's
keep it simple and base it on moving forward and backward. You have a function that creates a random number every time a fighter stands still or is done with an action, every second or two (hint: difficulty can be done here where time in seconds or milliseconds every action can take place ;D), and based on the value, whether it's 0, 1 or 2 (Neutral, Walk_Forward, Walk_Backward constants), it will do the move. Now here is where the state machine comes in. If the CPU fighter walks backwards, for example, and ends up on the edge of the screen, the state machine tells the computer that it is not possible, and another action can take place. This is basic, but it's getting better. Here is somewhat of an example, though REALLY not complete:
Randomize
Dim bForward As Boolean
Dim bBackward As Boolean
bForward = True
bBackward = True
Sprite(1).X = Sprite(1).X + 20
If Sprite(1).X >= Global_Map.Map_Rect.Right Then
Sprite(1).X = Global_Map.Map_Rect.Right
bBackward = false
Sprite_Animation(Rnd * Max_Number_Of_Moves)
'Note: All animation is done here, with the value
going through a Select Case method.
Else
bBackward = True
End If
Step 3) Setup Pattern Tables
This is difficult to program, but what you can do is have series of patterns that the computer opponent can do randomly, with each pattern representing a number. Then after having a random value calculated, you use a Select Case method (or Switch if it's C++) and depending on the value, it'll do a series of moves, (i.e combos, walk up and throw (based on distance), fireball dragon punch patterns, etc.) Street Fighter 2 did something like this, though I don't know their code (I WISH) I was able to pick up their patterns easily and counter them with ease, even on expert mode!
Of couse it took me years to become an elite street fighter guru.
Step 4) Fuzzy logic anyone.
This technique is a little too random rather than helping create smart opponents. But it helps make it seem like their smart.
I kinda introduced this in step 2, only it's based on probability rather than Boolean (True & False). You have a random value, and depending on what it is, you have a function or a sub find what value is closest to it. Like this for example:
Public Sub Fuzzy_Logic(Value as Long)
If Value <= 10 Then
'Do Move
ElseIf Value > 10 And Value <= 15 Then
'Do a different move
ElseIf Value > 15 Then
'Do a different move.
End If
End Sub
Step 5) Base AI on what you, the player does.
This is when our computer opponents actually have brains!!! But it's difficult to impliment. Obviously you have a number of patterns again, only it depends on what YOU do. If I do a low block, computer walks up and throws me. If I jump at them, depending on distance (calculating distance between sprites is part of the AI), computer uppercuts me. If I throw a fireball, computer either blocks, jumps over, or throws a fireball in return. Etc etc etc. You create a number of scenarios and vwola.
Step 6) (Still thinking, I had more than 5 in my head ya know but I'll modify this post when I can)
Now combine everything in here and you got one hell of an AI engine. Combining Physics with AI would be even better. Though this reply by me is a bit vague and lacking much more information, all in all I did my best to lead you in the right direction. I gotta game to work on myself ya know ;).
[Edited by - Jacob Roman on September 21, 2004 10:41:59 PM]
table. I just may have a better idea. Plus you are gonna want the AI to be random, yet smart.
Step 1) Make a list of constants based on actions your fighters gonna do. Kinda like numberical codes for every single action a fighter can do. For example: (Visual Basic)
Public Const Neutral as Long = 0
Public Const Walk_Forward as Long = 1
Public Const Walk_Backward as Long = 2
Public Const Croutch as Long = 3
Public Const Hit_High as Long = 4
Public Const Standing_Jab_Punch as Long = 5
Public Const Crouching_Fierce_Punch as Long = 6
Public Const Turn_Around as Long = 7
etc. etc. etc.
There's probably gonna be over a 100 constants, especially if you are gonna simulate street fighter. Then you can use these constants in functions that control the animation of the sprite.
It's a start so far.
Step 2) Create a state machine engine. A state machine is a
logical thought based AI you can use. Like for example, let's
keep it simple and base it on moving forward and backward. You have a function that creates a random number every time a fighter stands still or is done with an action, every second or two (hint: difficulty can be done here where time in seconds or milliseconds every action can take place ;D), and based on the value, whether it's 0, 1 or 2 (Neutral, Walk_Forward, Walk_Backward constants), it will do the move. Now here is where the state machine comes in. If the CPU fighter walks backwards, for example, and ends up on the edge of the screen, the state machine tells the computer that it is not possible, and another action can take place. This is basic, but it's getting better. Here is somewhat of an example, though REALLY not complete:
Randomize
Dim bForward As Boolean
Dim bBackward As Boolean
bForward = True
bBackward = True
Sprite(1).X = Sprite(1).X + 20
If Sprite(1).X >= Global_Map.Map_Rect.Right Then
Sprite(1).X = Global_Map.Map_Rect.Right
bBackward = false
Sprite_Animation(Rnd * Max_Number_Of_Moves)
'Note: All animation is done here, with the value
going through a Select Case method.
Else
bBackward = True
End If
Step 3) Setup Pattern Tables
This is difficult to program, but what you can do is have series of patterns that the computer opponent can do randomly, with each pattern representing a number. Then after having a random value calculated, you use a Select Case method (or Switch if it's C++) and depending on the value, it'll do a series of moves, (i.e combos, walk up and throw (based on distance), fireball dragon punch patterns, etc.) Street Fighter 2 did something like this, though I don't know their code (I WISH) I was able to pick up their patterns easily and counter them with ease, even on expert mode!
Of couse it took me years to become an elite street fighter guru.
Step 4) Fuzzy logic anyone.
This technique is a little too random rather than helping create smart opponents. But it helps make it seem like their smart.
I kinda introduced this in step 2, only it's based on probability rather than Boolean (True & False). You have a random value, and depending on what it is, you have a function or a sub find what value is closest to it. Like this for example:
Public Sub Fuzzy_Logic(Value as Long)
If Value <= 10 Then
'Do Move
ElseIf Value > 10 And Value <= 15 Then
'Do a different move
ElseIf Value > 15 Then
'Do a different move.
End If
End Sub
Step 5) Base AI on what you, the player does.
This is when our computer opponents actually have brains!!! But it's difficult to impliment. Obviously you have a number of patterns again, only it depends on what YOU do. If I do a low block, computer walks up and throws me. If I jump at them, depending on distance (calculating distance between sprites is part of the AI), computer uppercuts me. If I throw a fireball, computer either blocks, jumps over, or throws a fireball in return. Etc etc etc. You create a number of scenarios and vwola.
Step 6) (Still thinking, I had more than 5 in my head ya know but I'll modify this post when I can)
Now combine everything in here and you got one hell of an AI engine. Combining Physics with AI would be even better. Though this reply by me is a bit vague and lacking much more information, all in all I did my best to lead you in the right direction. I gotta game to work on myself ya know ;).
[Edited by - Jacob Roman on September 21, 2004 10:41:59 PM]
You didnt have to worry about all that explanation dude,my fsm's are already running player wise.Thanks though.As for the matter at hand,the randomn number generate are exactly what was supposed to be in the table ( as i was thinking about it anyways).From how i understood Hap's method,recording the mouvements just made it so I didnt have to hand out numbers on my own.The state the character is in seems to be sufficient data.Anyways,I'm still working on implementing the other type of AI,so post up any more suggestions they'll be useful when i get to this type of AI.
Quote: Original post by SneftelI'd definately follow this approach. A enemy which learns is all very interesting for example, but not really any better to play against than levels of difficulty - would the player even notice as long as each fight got harder. You want it to be finished and for a 2D game a 2D game style would be appropriate. You can easily categorise attacks/blocks into low/middle/high and follow Sneftel's advice to match them up. Combos could be chosen by whether the starting move would beat their current stance. You can customize a script for each character giving them favourite moves etc.
Well, you know the rules of your fighting system, so base your AI off that. First, defense: for a particular move made by the human player, there are certain moves the AI can do to counter, so just have it execute one of them. Next, offense: when the AI isn't involved in defence, have it pick an offensive move that the human player's current state is not blocking, either purely at random or based on a weighting. He may also choose to wait, especially if the player is currently blocking.
Now you have a perfect AI. Tone him down a little by having him fail to execute the proper defensive moves at times, and by sometimes making easily blockable offensive moves.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement