Thread: Game Design Topic #1 - AI Behavior

  1. #1
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050

    Game Design Topic #1 - AI Behavior

    Well, it seems to me lately that not many threads are concentrated enough on game programming and game design. Most thread seem to be about answering 'newbie' questions, which is fine to have threads like that. However, I want to try to spark some discussion on game design and other topics like that.

    Game Design Topic #1
    ----------------------------
    AI Behavior in a Space Shooting Game
    ______________________________

    What type of AI would you like to see in a space shooting game? Do you want to see an AI that goes after the player aggressively with no other regard. An AI that plays it smart and tries to avoid the 'danger' areas? An AI that is completely random (however this usually creates a rather dumb AI)?

    Personally I think it's a matter of trying to set up a predertimed method the AI should follow. Like have a bunch of different types of methods the AI can go from. Meaning that one enemy ship might try to come from one top corner and then diagonally slide down to the middle of the screen and from there make it's way towards the player ship. Another enemy AI might try to stay to the side of the screen the whole time while shooting at the player fiercely but it would be really difficult for the player to shoot the ship because the player's attention might be focused on in the middle of the screen. Basically I think it's smart to use a variation of predertimend AI behaviors without including much randomness at all. The randomness slows down the AI decision making and usually makes the AI decision AI making worse. I don't think each AI behavior should have more than one 'bail-out' if it comes to a point where it might be killed (i.e. run into player ship, hit by a bullet, etc...). I think to create a smiple yet potent AI it is best to leave as much randomness out of the equation as possible. It's ok to have a few random AI behaviors but that's about it.

    Well, those are my thoughts on how AI behavior should be dealt w/ in a (2D) space shooter game. What do the rest of you think? Come on people lets get some good discussion going!

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    The AI should be unpredictable: Games with a predictable AI get boring FAST!
    The AI should play smart, yet aggresive: It should find the right moment to attack, but when it does, it should attack very well.

  3. #3
    Registered User Bieh's Avatar
    Join Date
    Sep 2002
    Posts
    83
    AI Behavior in a Space Shooting Game
    My first real game that I made (ie: post-pong) was a 2d space-invaders clone like the one you describe, and it's ai was pretty simple. basically the enemys were trying to reach the bottom of the screen; if they got past you, they won.

    Basically I think it's smart to use a variation of predertimend AI behaviors without including much randomness at all.
    thats what I did

    When they spawned, they randomly chose one of 5 'ai styles':
    -try to attack the player, angleling (sp?) down towards him
    -rushing towards the bottom in the middle, shooting constantly
    -rushing towards the bottom on the sides, shooting constantly
    -camping up the top of the screen, trying to snipe the player from afar
    -and one other one, which i've forgotten

    These styles were pretty basic, but as you were facing 40+ of them in the later levels, it looked pretty impressive

    With 20/20 hindsight, there were probably far better ways of doing this; I could have made them team up (ie: they wait up the top, then attack in waves) and make them try not to shoot each other so much .
    Formations would have been cool as well...and having them change attack styles if losing, or if the player is low on health / occupied...or all rush for the side of the screen the player is furthest away from...damn, why didn't I think of this stuff at the time?



    ...whew, that went on a bit longer than I intended
    "It always takes longer than you think, even when you take Hofstadter's Law into account."
    -Hofstadter's Law

    Bored? Try my game SpaceWars , made in Allegro and VC++
    or see my new game Redoubt , made in OpenGL and VC++

  4. #4
    Registered User Bieh's Avatar
    Join Date
    Sep 2002
    Posts
    83
    Originally posted by face_master
    [B]The AI should be unpredictable: Games with a predictable AI get boring FAST!
    Very true; I think that's one of the main reasons why SpaceWars gets old so fast - the AI is pretty predictible
    "It always takes longer than you think, even when you take Hofstadter's Law into account."
    -Hofstadter's Law

    Bored? Try my game SpaceWars , made in Allegro and VC++
    or see my new game Redoubt , made in OpenGL and VC++

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    For one, I think the AI should be adjustable to levels of difficulty for a player. I always hate football games and shoot-em-up's for that very reason. They always use the most intense attacks, resulting in a very short game Aside from that, the AI should be delegated into certain tasks, ie: AI for following a character separate from the AI of choosing an attack approach, etc.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    Originally posted by Bieh
    Very true; I think that's one of the main reasons why SpaceWars gets old so fast - the AI is pretty predictible
    not so, the game raptor (its posted somewhere on this board, just search for it) has a pridictable ai for each kind of nme ship, but its a fun game to play.
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  7. #7
    Shadow12345
    Guest
    Well I haven't done any good AI programming, but i can only imagine Artificial Intelligence directly implies something that cannot think for itself but must react to conditions in the 'world'. I think that is what the other people who posted on this thread were getting at. For example having 'enemy spaceships change formation when losing' could be done with static class variables that keep track of how many spaceships exist. If there are less than a certain amount of spaceships then they assume a tighter position otherwise they choose a larger position. Of course you could have a whole ****load of positions to choose from, not just one. It also seems to me that the AI that seems the most intelligent are simply the ones that can react to the most conditions. For example they do not just change position if they are losing, but the least damaged enemy spaceships protect the more damaged enemy spaceships by getting in between them and the player, and spaceships with a more appropriate type of armor plating face the player when the player uses a weapon that isn't as strong against their type of armor plating, and so on and so forth. Ideally artificial intelligence can test for every condition possible, but even in some simple games it can be very difficult to program for every condition.

  8. #8
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    face_master, all that is easier said than done. I think in a space shooting it is best (in terms of ease and effiency) to have most of the AI behavior predertimened. This doesn't mean that the behavior can't be complex. It's just that an AI that is largely based off of randomness is going to be poor. If the AI were to check too many conditions it might wind up making an even worse decision than staying on it's 'normal' path. If a good AI behavior is planned out for the enemy then the enemy shouldn't have much need to changed it's course of movement. Such as if you have the behaviors like Bieh listed. Maybe include a few more behaviors that are little bit more divers, but that shoud still provide for a decent AI.

    Although, including a few special conditions when the AI should act differently *to add to the inpredictability of the AI* couldn't hurt too much. All in all, though, I think predertimened AI behaviors, with little change in it's behavior, is best for a space shooting game, because it's very easy and it's potent.

  9. #9
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I am no expert, but I have many opinions and some experience with this field. I want to digress a little and use some prose to further the discussion a little... There are two main difficulties in artificial intelligence: the abstraction and the implementation. Though seemingly simple, the abstraction is difficult to implement, the implementation hard to abstract. Bringing the two together in an intelligent and perhaps reusable way is the puzzle.
    The abstraction is, of course, the easier of the two. Like asking someone a strategic question: the mind does little work here.
    It is the implementation where most mistakes are made, mainly because the coupling between the two must be just right, neither too loose nor too tight.
    So for most games, predetemined patterns are favored because people like a little predictability. Unwelcome surprises make unpopular games...but the pattern must be loose enough to seem life-like. A good modelling technique is known as the "wandering gunsight". Here we construct a gunsight to be controlled by some input method, whether mouse, keyboard, or otherwise. At first we design it such that commands from the controller have a clear, separated interface with the virtual gun. Then we insert a single object between these two which takes in the input from the first and feeds directly to the second. Add an external toggle to remove and replace this "fudging" object at any moment. Perfecting this technique will pave the way to more generic code. Finally, the intervening object should do three main things: using very small random deviations, it should cause the sight to wander just above the threshold of noticability. Next, it should randomly ignore some of the input, thus "malfunctioning" just slightly. Finally, it should be recieve one more input, called "intent". This might be the coords of a moving target which have themselves been altered by a similar object, creating a "not so perfect aim", or similar. Altogether this yeilds:

    "intent" + "wander" + "imperfection" == good AI!

    Just remember that the algorithms and data structures used must be a careful mix of reusable and specific code.

    Anyway, are you using C++ or what? This seems like a fun project though...good luck to you!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  10. #10
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    I think that was very well put, Sebastiani. However, you left out one important category---adaption but you might have included that as part of its intent. The AI should be able to adapt to the unexpected occurrences, such as the player cutting off its intended path. This is where really the hard part comes into play. It's hard to come up with an algorithm for the AI to adapt to the situation, which is why AI still has a long ways to go before it can truly challenge the human. Although, in a simple space shooting game a perfect AI isn't neccessary. That's why in the game I'm creating I've decided to do away with having a lot of AI adaption. It seems to me that I will probably spend more time on making the AI fairly adaptable for it to actually be worth it. Basically I think in overall terms I'll be better off just sticking with the AI's predertimened behavior method. So far I've come up with a decent way of doing this or so it appears.

    Anyway, are you using C++ or what? This seems like a fun project though...good luck to you!
    Yes, I am using C++. I've been working on the project around a month now (maybe longer or shorter). It's taken me a while to get to this point, because I've been trying to learn a lot of new, more advanced concepts. But the main reason why is that I have very little time to do it. I pretty much have to give up my sleep to program on most days. My plan is to make this game as good as I possibly can; I expect to be able to have at least a Nov/Dec release. Maybe with a demo coming out towards the end of this month.

  11. #11
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    However, you left out one important category---adaption...
    Ahh, real AI! Yes, that would be nice, wouldn't it? I guess I was focusing more on "simulated" AI. Well, the main problem with this aspect is usually the memory. You have to store that learning somewhere, and it takes a lot to become meaningful! But yes, that would be a good ultimate goal! I'm looking forward toward seeing your game. I am (slowly) developing a game myself, similar in genre to the mario games. But right now I'm stuck on the mathematical physics of it (not my strong point...). Hopefully I'll be done with the first level in a few months...here's his profile:


    Very dorky, but my neices and nephews love him! They've been bugging me to get him to do more than just walk and jump, of course...

    Anyway, just let me know if you get stuck on anything. Good luck!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  12. #12
    Shadow12345
    Guest
    Aww its cute

    by the way I had like no clue what you guys were talking about in your posts, especially you S man

    What exactly do you mean by ai abstraction is hard to implement and the ai implementation is hard to abstract? Can you say it in human terms? Something mortals might be able to understand?

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    What exactly do you mean by ai abstraction is hard to implement and the ai implementation is hard to abstract?
    The abstraction is simply the desired top-down functionality. The implementation is the bottom-up necessity. They are really "one", but must be separated to get the work done. Here's a simple example: remember when you first started programming, and when asked how you might write a game you would concieve something like:

    int main(){
    player john;
    player larry;
    while(john.dead == false && larry.dead==false){
    john.move();
    larry.move();
    if(john.collides(&larry);
    crash();
    }//...while...
    return 0;
    }

    Because we were beginners we gave people names to the characters, thought of interactions in a simple way, and basically could not separate from the "top-down" view (the abstraction). If asked how to program this game, the implementation would be less than easy and the game would quickly degenerate into a bug-ridden mess! Thus, "the abstraction is difficult to implement".

    Now switch to an old school systems programmer who is asked to write such a game. He might start with:

    int main() {
    if( (seg_fault(r_entire_bin(h_result, p_main))) == SEG_FATAL) {
    //...
    }
    do{
    if( (r_tree_parse(&h_result)) & PARSE_FATAL) {
    //...
    }
    //...
    while(h_result);

    return EXIT_SUCCESS;
    }

    Here we have the opposite problem altogether. This programmer can certainly get the program to work, but when asked to add a new feature, he fears he will have to give the user (another programmer) four more functions instead of one, which must be called in a certain order, and which must recieve certain ranges of preinitialized values, and on top of that, the return values might be one of six possible results for each of the functions, all of which must be checked! The problem is, he cannot seem to get "the big picture" in order to connect things properly. This is the meaning of "the implementation is hard to abstract".

    The whole idea of OOP was to facilitate a happier medium, by encouraging more humanistic viewpoints of programs, by giving the programmer things such as operator overloading, templates, etc - things that encouraged more maintainable and generic coding practices, basically. Object oriented programming is here to stay, and for a good reason.

    Anyway, with reference to AI we have to first realize that there are real data structures that must be dealt with, real algorithms to be debugged and perfected, and that we cannot simply start coding under the pretense that the interactions will be clean and simple. The reality is that programming involves more low level interactions than high level, and that to ensure total connectivity, some hard design decisions and trade-offs must be made.

    Where the line is drawn is the art of it!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  14. #14
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    I'm looking forward toward seeing your game.
    Well, thank you...

    I am (slowly) developing a game myself, similar in genre to the mario games. But right now I'm stuck on the mathematical physics of it (not my strong point...). Hopefully I'll be done with the first level in a few months...here's his profile:
    That's pretty cool; how long have you been working on the game? And your character really does look awesome.

    Anyway, just let me know if you get stuck on anything. Good luck!
    Again, thank you.

    by the way I had like no clue what you guys were talking about in your posts, especially you S man
    Don't feel too bad; I'm no expert on the issue either. I understand what Sebastiani is saying, but he's still much much smarter than me on the topic.

    Where the line is drawn is the art of it!
    Yes, that really is the fun part of it. Making the critical decisions of how far you're going to go into implementing a feature molds your game into what it eventually becomes.

    The other day I came up with a way that's going to make it very easy for me to have a plethora of different AI behaviors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. My Memory Game
    By jazy921 in forum C Programming
    Replies: 0
    Last Post: 05-05-2003, 05:13 PM
  3. game design from the non programming side
    By Scourfish in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-29-2002, 01:07 AM
  4. Anyone heard of FULL SAIL GAME DESIGN DEGREE?
    By marCplusplus in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-30-2001, 10:06 PM
  5. Im a Newbie with a graphics design problem for my simple game
    By Robert_Ingleby in forum C++ Programming
    Replies: 1
    Last Post: 11-23-2001, 06:41 PM