The Daily Click ::. Forums ::. Klik Coding Help ::. Doubts on Fighting Engine
 

Post Reply  Post Oekaki 
 

Posted By Message

Diefox

Possibly Insane

Registered
  23/02/2003
Points
  3481

VIP MemberGOTM -SEPTEMBER 2009 - 2nd place!GOTW WINNER APRIL 2010!
21st March, 2005 at 17:21:24 -

greetings to you all!

i´m making a fighting game in MMF (try searching for "duel toyes" on google and you might find something) and im having some troubles with my AI, not trouble, its working quite fine, but i have just somes doubts.
should i use only one random variable to decide what the enemy does? or should i use different ones for attack, special attacks, jumping and etc.
should the enemy act differently whether the player is attacking or not?
should i make different types of AI? I.E. Deffensive,Balanced and Offensive.

I could use some others tips on AI if you are kind enough to give me any.

thanks in advance to you all.

 
__________
amandapps.com

RapidFlash

Savior of the Universe

Registered
  14/05/2002
Points
  2712
21st March, 2005 at 18:10:21 -

You should make the enemy act differently depending on if the player is aggresive or passive.
You don't want to make your AI based off of completely random events. Make the AI's events based on what the player does (or doesn't do). Some great advice for AI is to step through it one piece at a time. Play the AI until it does something stupid, then fix that, and then play it again.

 
http://www.klik-me.com

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
21st March, 2005 at 19:31:15 -

Personally i wouldnt know where to start with fighting ai, but it may help if you use a certain amount of randomness.
How about coding an impossible fighter that blocks every move you make and use the randomness to decide whether they actually do block your move or not.

Or for every action you take there could be a random reaction.

When player throws a punch set counter to random (4)+1

1 block
2 nothing
3 nothing
4 jump
5 counter attack

something like that maybe?

 
.

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
21st March, 2005 at 19:50:46 -

part of an article i found a while back...

http://www.peachpit.com/articles/article.asp?p=102090&seqNum=10


Fighting Games
The algorithms used to code fighting games vary greatly from one case to another. From quasi-random action selection in older titles to today's sophisticated AIs and learning features, fighting AI has evolved spectacularly.

As an example, we could implement a state machine with seven states: attack, stand, retreat, advance, block, duck, and jump. When connected in a meaningful way, these states should create a rather realistic fighting behavior. All we need to do is compute the distance to the player and the move he's performing and decide which behavior to trigger. Adding a timer to the mix ensures the character does not stay in the same state forever.

If you want something more sophisticated, we can build a predictive AI, where the enemy learns to detect action sequences as he fights us. Here, the enemy would learn our favorite moves and adapt to them. The idea is quite straightforward: Keep a list with the chronological sequence of the last N player movements. This can be a circular queue, for example. Then, using standard statistics, compute the degree of independence from the events in the queue. For example, if the player is performing a kick and then a punch, we need to compute whether these two events are correlated. Thus, we compute the number of times they appear in sequence versus the number of times a kick is not followed by a punch. Tabulating these correlations, we can learn about the player's fighting patterns and adapt to them. For example, the next time he begins the kick sequence, we will know beforehand whether or not he's likely to punch afterward, so we can take appropriate countermeasures.

The finite-state machine plus correlations approach is very powerful. It is just a problem of adding states to the machine so we have more and more flexibility. If we need to create several fighters, each with its own style, all we need to do is slightly change the states or the correlation-finding routine to change the fighter's personality. Don't be overly optimistic, though, most games implement character personality at the purely aesthetic level, giving each character specific moves, a certain attitude in the animation, and so on.

So far, our fighter is highly reactive. He knows how to respond to attacks efficiently by learning our behavior patterns. It would be great, especially for higher-difficulty enemies, to make him proactive as well, making him capable of performing sophisticated tactics. To do so, the ideal technique would be to use space-state search. The idea would be to build a graph (not a very big one, indeed) with all the movement possibilities, chained in sequences. Then, by doing a limited depth search (say, three or four levels), we can get the movement sequence that better suits our needs according to a heuristic. Then, the heuristic would be used to implement the personality. Although this looks like a good idea, executing the state search in real time at 60 frames per second (fps) can be an issue.

Thus, a simpler approach is to use a tabulated representation. We start with a table with simple attack moves and their associated damage. Then, every time we do a new attack combination, we store the damage performed and the distance at which we triggered it. For example, we can store:

Distance = 3 meters, high kick, jump, punch, Damage = 5

Then, we can use this list afterward, accessing it by distance and selecting the attack that maximizes damage. It's all just very simple pattern matching both for the attack and defense, but it produces the right look and feel.



 
n/a

_rydin



Registered
  06/06/2004
Points
  317
24th March, 2005 at 00:44:51 -

I would make the AI reflect the character's actual style of fighting. Like the big barbarian guy would go only for the offense and not worry about health, or the small fast guy would only wait for the right moment to strike and try to dodge everything else, or the guy with the shield would know how to use it effectively. You could also have it so the more skillful AI (assuming you are making different difficulties/levels) would try to not just beat the player to a pulp, but do it with style, and taunt/trick the player.

Just an idea. This would probably take alot of coding to do though, if you care.

 
"Computers in the future may perhaps only weigh 1.5 tons."
-Popular Mechanics, forecasting the development of computer technology, 1949

c-jayf



Registered
  06/07/2003
Points
  274
24th March, 2005 at 00:47:05 -

I agree, rydin. Make sure the barbarian would have a shirt though.

 
I hate witty signatures.

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
24th March, 2005 at 07:22:36 -

You can make the nmy have a reaction for every move of the player, or maybe many. And then you just randomize which counter-move it uses, and then you randomize if it succeeds or not.

 
n/a

SculptureOfSoul



Registered
  14/03/2005
Points
  52
24th March, 2005 at 08:34:03 -

I'd go with Agggge's idea! If you want to make certain fighters have their own fighting style, what I'd do is create certain "behaviors" or states that the enemy can be in. [Aggressive] [Defensive] [NearDeath] [PlayerNearDeath] etc. Make each one of these a seperate ini, and then put the same groups in each.

[CounterHighPunch]
[CounterLowPunch]
[CounterHighKick]
[CounterLowKick]

etc.

Then each group would need a certain number of items.
[CounterHighPunch]
PossibleReactions=100
Reaction1=DodgeLow
Reaction2=DodgeLow
Reaction3=DodgeLow
Reaction4=DodgeLow
Reaction5=DodgeLow
Reaction6=Sweepkick
Reaction7=Sweepkick

For this example lets just say that Reaction8 to Reaction100=Block.

The game engine should first look at the PossibleReactions item (and this will be in every group of every Behavior INI), and then use the value there to get a random number:
Counter1 = Random(Value of INI item "PossibleReactions")+1

In this case we just got a number from 1-100, and then you set the INI's item to
the text "Reaction" + the string of the value stored in the counter.
Set INI item to:
"Reaction" + Str$(Value(Counter1))

Then you get the item that the INI is pointing to and call the corresponding event.

IF INI item = "Dodgelow"
do DodgeLow stuff here.

The reason I had DodgeLow in more than one spot is because this allows you to set the percentage chance that that item will be called. Since DodgeLow is in 5 spots, and the random number goes from 1-100, there is a 5% chance that DodgeLow will be called. Note that SweepKick would have a 2% chance and Block would have an 83% chance.

Of course this is only determining the behavior of the enemy. To see if the enemies action actually succeeds you'd need to implement more code. You could for instance have each fighter have a variety of stats...
Block% could be one.

Set this to something different for each fighter. Bob the Barbarian is a crazy berseker so his is at 15%. Tim the Tank is a pussy hiding in 500lbs of platemail, set his at 70%. Now whenever the "block" action is called, get a random # from 1-100, see ifit's less than their block%. If so, they sucessfully blocked.

Also, to have a more dynamic engine, you could have it that their blocking ability diminishes as they lose health. Maybe for every 10 hp's they lose, their blocking ability goes down 3%.
WhenEnemyIsHit: do
Set Block%: MaxBlock% - ((MaxHp - Current Hp/10)*3)

Of course these formulas are just off the top of my head and are only for the purposes of illustration. The hardest part, besides the coding , would be decent balance.

~SoS

Image Edited by the Author.

 
Current Project: Undertaking the design of my mammoth RPG. Utilizing all of the knowledge gained while coding the now defunct "Shadow Reign".

SculptureOfSoul



Registered
  14/03/2005
Points
  52
24th March, 2005 at 08:42:10 -

In hindsight, such an elaborate AI system really isn't necessary. If you hard-code the AI right, it will look and work excellent. The only problem with hard-coding (and benefit of using an approach like I was mentioning) is that it's hard to make changes to enemy behaviors, and really hard to make multiple opponents with different fighting styles.


 
Current Project: Undertaking the design of my mammoth RPG. Utilizing all of the knowledge gained while coding the now defunct "Shadow Reign".
   

Post Reply



 



Advertisement

Worth A Click