AI Design

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
User avatar
Maevik
Chaos Rift Junior
Chaos Rift Junior
Posts: 230
Joined: Mon Mar 02, 2009 3:22 pm
Current Project: www.keedepictions.com/Pewpew/
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Long Beach, CA

AI Design

Post by Maevik »

I'm having an issue with the AI design of the SHMUP game I'm building at the moment and was hoping the community might have some insight or input to help me out.

While planning out my AI procedures, I'm finding that for a lot of the functions I wan't to know the location of the player so that I can do things like:
Trigger things by proximity
Fly directly at the player
Shoot directly at the player
Avoid the Player

Is there a good method for allowing all instances of my Enemy class knowing at all times where my instances of Player class are?

My only real option I can see is passing a ptr to the player every time I update the enemy. And do that for each enemy I guess. I would also have to do that for each player when I implement multiplayer. Something like:

Code: Select all

myEnemy.update( player1 , player2 );
My love is like a Haddoken, it's downright fierce!
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: AI Design

Post by avansc »

what you want is shared memory

lets assume that no enemy knows where the player is.

when a enemy sees the player it post the location to the shared memory of the AI, that way all enemies know the location.

you can go in pretty complex with this, but that is the simple version.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
Maevik
Chaos Rift Junior
Chaos Rift Junior
Posts: 230
Joined: Mon Mar 02, 2009 3:22 pm
Current Project: www.keedepictions.com/Pewpew/
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Long Beach, CA

Re: AI Design

Post by Maevik »

Ok, not exactly that far just yet, but in a way you hit the nail right on the head. I guess I'm essentially asking "How do I get my enemies to SEE the player?"

I suppose the easy answer would be what I presented in the OP, where you just update the enemy with the player location ever frame by passing it into the update function. Are there better algorithms for this? What other ways can I get my Enemies to see my Players?
My love is like a Haddoken, it's downright fierce!
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: AI Design

Post by dandymcgee »

I think what I did last time I came across this issue is store a target pointer. Essentially your Enemy class has a member pointer (or maybe an array, list or vector in your case).

Code: Select all

class Enemy{
     vector target<*Player>;
}
Store 'em once and they're available whenever you need them. Varying targets are a bit more work as you have to remember to add the new instances where needed and avoid storing dead pointers.

May not be the best method, but it's all I can think of atm.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Innerscope
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon May 04, 2009 5:15 pm
Current Project: Gridbug
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: Obj-C, C++
Location: Emeryville, CA
Contact:

Re: AI Design

Post by Innerscope »

Maevik wrote:Ok, not exactly that far just yet, but in a way you hit the nail right on the head. I guess I'm essentially asking "How do I get my enemies to SEE the player?"

I suppose the easy answer would be what I presented in the OP, where you just update the enemy with the player location ever frame by passing it into the update function. Are there better algorithms for this? What other ways can I get my Enemies to see my Players?
Do you want the enemy to always know where the player is?(omniscient A.I)
or do you want the enemy to have a "sense of sight" and not know the player's position until he's spotted?
For the first one, it's pretty easy, you can just have the player's position global. (feel free to harp at me about bad programming practices ;) )
The second one you would have something similar to a collision algorithm only the range would be the enemies line of sight or range of vision. You could then have some kind of flag for when the player's spotted and that could be relayed to other bots. The bots can have a targetLocation property (similar to what dandymcgee was saying), and within the sight algorithm you could have bots copy that property from other bots within range.
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: AI Design

Post by thejahooli »

You could just store a pointer to a Player object and when you initialize the enemy either pass a pointer to the player object that allocates it or have a function which registers the Player object.

Code: Select all

class Enemy
{
public:
    Enemy(Player *player)
    {
        this->player = player;
    }

private:
   Player *player;
This would have the same output as passing the Player pointer to the Update function, but it is neater this way as you only have to send the object once.
I'll make your software hardware.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: AI Design

Post by dandymcgee »

thejahooli wrote:You could just store a pointer to a Player object and when you initialize the enemy either pass a pointer to the player object that allocates it or have a function which registers the Player object.

Code: Select all

class Enemy
{
public:
    Enemy(Player *player)
    {
        this->player = player;
    }

private:
   Player *player;
This would have the same output as passing the Player pointer to the Update function, but it is neater this way as you only have to send the object once.
Don't take this the wrong way, but how is that different from what I just said? :roll:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply