A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: TEACH ME THE WAYS OF ..... AI

  1. #1
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Could someone help me program some ai for a basic rpg game i have no knowledge of ai so far but i wish to learn could someone help. I figured one step at a time so anyone

  2. #2
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Anyone, !

  3. #3
    Senior Member
    Join Date
    May 2001
    Location
    Sweden
    Posts
    197
    Well, what is this ai going to do?

    The basics of intelligence is pretty much this though:

    The ability to react according to a given situation with various variables.
    In other words it's all based on a bunch of condition checks.

    For example, say you have a person running around in your RPG that gets thrown into a lake.

    Part of his AI might look like this:

    Code:
    onClipEvent(enterframe){
    
    //if he's in the water
    if(this.inWater==1){
    //if he's under the water or the water is unpleasant
    if(_root.water.depth>=this.height || water=="cold"){
    swim(toShore);
    }else if(water=="pleasant"){
    drink(water);
    }
    }
    
    }
    Then you just need to define some functions and fill your world with variables to react to. It's really not very complex.

  4. #4
    Senior Member
    Join Date
    Feb 2001
    Posts
    314
    If you're looking for basic AI theory, do a search. It's been discussed many times (including once a couple of days ago).

    If you're looking for something more specific than that, you're going to have to give us more to go on. There are too many different kinds of RPG games and too many different techniques. Is your game 2d or 3d? Or is it text based? If it's 2d, is it an overhead view or a side view? How do the characters move? Do they have a full range of montion, or do they just move N, S, E and W? What kind of a combat system are you going to have? Or are you going to have combat at all?

    Those are just a few of the questions that need to be answered before you can really even start thinking about AI.

    Start working on the game. You can do a lot of it before you need to start worrying about AI. Get the characters moving around using the keys or the mouse or however you want to do it. Build your "world." Set up the rules for combat.

    Then, if you can show us that, we'll be able to offer some specific advice.

  5. #5
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    ok i wont go complex straight from the start so i wiill start where i think its simple ok ill describe the sort of at i want the same as the game alundra or zelda so i want them to try to walk after you the enimes also have 8 frames

    Up, Up right , Upleft, and so on
    so the enimes follows the hero but it goes to the accoring frame. as it moves to wards the hero.

    if you understand what im saying if not pls reply ill try to explain it a bit better



  6. #6
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    actually i dont have a specific AI i just want to learn it step by step could anyone help?

  7. #7
    Senior Member
    Join Date
    May 2001
    Location
    Sweden
    Posts
    197
    What exactly is it you wish to learn step by step?
    The secret formula that all AI is based on?
    I think you've got it all a bit wrong. As far as I know there is no specific secret way in which all Artificial Intelligense behaves other than the fact that it has the ability to adjust its behavior depending on the situation (read: if-statements).

    Allow me to blurt out a very basic step by step example:

    1. Make a new movie that's 400x400.

    2. Create a movieClip and give it the following code:

    Code:
    onClipEvent(enterFrame){
    
    speedX=random(3)-1;
    speedY=random(3)-1;
    
    // [AI]
    if(_x+speedX < 400 || _x+speedX > 0){
    _x+=speedX;
    }
    if(_y+speedY < 400 || _y+speedY > 0){
    _y+=speedY;
    }
    }
    // [/AI]
    3. You now have a movieClip that runs around wildly over the screen. The AI part in this is that it won't go outside the screen.

    AI is only as complex as you yourself make it. It is also totally case specific so asking for a general basic AI behavior is rather pointless.
    Your code should be based on what it is you want to accomplish with it, not on the strange and magic formula that everybody but you seems to know. Try to think for yourself! You'll learn a lot more by figuring things out for yourself than having it thrown at you in a step by step tutorial.

  8. #8
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    ok i guess what i really want to know is how do i make the Ai choose underdirrent circumstances.

    eg

    if hero is facing , choices =

    1/ fire

    2/ run , up down, left, right

    3/ and so on ..






  9. #9
    Senior Member
    Join Date
    Feb 2001
    Posts
    314
    There are some extremely complicated neural network simulation techniques (or at least theories) for AI, but that's way beyond what is practical in Flash.

    For our Flash games, we're pretty much confined to two general tools for decision making: (1) random numbers and (2) if statements.

    In my fighting game, I use a combination of both.

    The first thing I do is check to see if the fighters are within attack range of each other. That's done with a simple if statement. If they are not within attack range, the computer-controlled fighter moves forward a step.

    That's an artificial decision. The decision to move a step forward.

    If the fighers are within attack range of each other, I generate a random number between 0 and 19. If the random number is 0, the computer-controlled fighter does a simple punch. If it's 1, he does a simple kick. If it's 2, 3, or 4, he does a spin kick. And so on. And if it's 10-19, he doesn't do anything.

    So it's completely random, but it simulates desision making. By having three numbers assigned to the spin kick, I simulate a tendency to do that move--he's going to do it three times as often as he does a simple punch or kick. And by having half of the numbers assigned to "nothing", I simulate hesitation (it's never more than a few frames).

    Finally, there are some hard-coded decisions. For instance, if the player-controlled fighter attempts to do a "crouch move", the computer controlled fighter automatically does a snap kick, because this is one of the only moves that is effective against a crouched opponent. He would look pretty stupid if he continued to try high kicks, so I override the random move and replace it with a situation specific move, again using a simple if statement.

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