dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Implementing AI on marmotte's engine

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    5

    Implementing AI on marmotte's engine

    Hi guys,

    I'm trying to implement some computer behavior on marmotte's fighting game engine but I'm having some... unexpected problems:

    I cannot figure out how and when the functions (like movment_left(), for example) are executed. I was expecting to find a function associated with an event like onEnterFrame on which to place my AI function, but I didn't.

    I see that the functions are named like stand_enterframe(), but I simply cannot find where they are used.

    Can you explain this a little bit to me?

    Thank you.

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    from what I remember there are blank movieclips with clipEvents which run code on the frames. There should be a control or brain layer I think
    lather yourself up with soap - soap arcade

  3. #3
    Junior Member
    Join Date
    Jul 2007
    Posts
    5
    Thank you! You are right! There's a layer called "mc_function activation" and a little piece of code is placed there... like this:

    Code:
    onClipEvent (enterFrame) {
    	_parent.attack_enterFrame();
    }
    I think I saw them before, but I'm not used to this way of organizing...

    Did you use the same engine when you've created your version of Street Fighter? I love your game! It's.. perfect... The gameplay is fantastic!

    Where do you recommend to place some basic AI? I've never tried this before... I guess I'll start with some very very simple ai_getCloser(); and ai_attack(); functions... How should I use them in the source? I saw you are loading the sprites from outside, so, I think you didn't write the code for every character... Can you give me some tips?

    Thank you very much for your help.
    Last edited by virruss; 03-17-2008 at 06:29 AM.

  4. #4
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    marmottes engine is quite old now, I'm sure he would re-write it if he wanted, but the logic still remains. I created my own engine, but its similar, definitely used his as inspiration.

    I don't know if there's a golden AI algorithm for a fighting game. But my approach was a state based system. The AI would be put into different states, and within those states act accordingly, sometimes if a condition was met a new state would be entered and therefore give different functionality to the AI.

    So yeah, put all your different functionality in seperate functions. Like a basic moveTowards(), jumpAway(), and have bigger functions which handle different behavior: attackBrain(), damageBrain(), defendBrain(), and within those, you run the specific actions you need.

    And yes, I didn't write code for every character, only one, so I suggest using a OOP approach to simplify things.

    AI extends Fighter extends Entity...

    Player extends Fighter extends Entity...

    and pass character attributes to the class (Ken, Ryu), because as I quickly found out, ActionScript doesn't support multiple inheritance.
    lather yourself up with soap - soap arcade

  5. #5
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    WOW, yes now that's a very, very old engine (something like 2003?)!
    onClipEvent, haha

    Anyway, I did a quick google search, and I found something that can be very interesting for you... http://www.gamedev.net/community/for...opic_id=157327

    I did also read many in-depth guides at gamefaqs when I was developing the engine, there are many useful informations there (you should check with games like SF3, MvsC...). Nothing too much AI oriented, but hints.


    That, and... I still want to create a fighting game in flash
    (That's what I say since years)

  6. #6
    Patron Saint of Beatings WilloughbyJackson's Avatar
    Join Date
    Nov 2000
    Location
    Ro-cha-cha-cha, New York
    Posts
    1,992
    Quote Originally Posted by marmotte
    That, and... I still want to create a fighting game in flash
    (That's what I say since years)
    Amen, brother ~!

  7. #7
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796
    There's some really indepth books written about how to code 3d fighters (complete with state machine AI routines) down my local bookshop.
    Only problem is you'll have to learn Japanese first to read them!

  8. #8
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    IMO Inheritance is the wrong way to go for a fighter AI.
    As far as I understand, there is only one "Level" of AI you will need, therefore you don't need to break it up into an inheritance hierarchy. Now, if, for example, as well as a full AI you also had tiny guys that just jumped around you may want to add a second level to the inheritance tree for code reuse.

    I would approach it as what it is, a finite state machine, and use the State/Strategy pattern along with composition. This would be much easier to modify and allow you to fit portions of different AI together by splitting each state or subroutine into a separate class (or method, but class would have more benefits).

    Of course, since you are aiming to adapt a prebuilt AI to your game, its somewhat moot since I will assume you aren't a strong coder. The problem with AI is that it is extremely difficult to make a cookie cutter solution since every scenario, even if they seem superficially similar, generally requires very different behavior.

    I would suggest going for something extremely simple, consider how you would play the game and write down some rules:
    - If he is far away, move closer
    - If he is charging an attack, defend/run
    - If he is in front of you, attack
    Etc...

    From there make a chain of if... else's to decide what action to take. Depending on the AIs reaction time (Perfect?) and how you choose your rules it could put up quite a fight, although it may be predictable (Throw in some randoms).
    Last edited by 691175002; 03-17-2008 at 11:34 PM.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center