2019-09-21 17:32:48

Note: All of my code samples are in bgt, as it's the only language I'm confident in enough to do with this.
So, logically, you can make a simple AI, by following something like this:

void botloop()
{
for(i=0; i<enemies.length; i++)
{
if(enemies[i].pos>pos)
{
enemies[i].pos--;
playstep();
}
//etc
and if(enemies[i].inrange==true)
{
enemies[i].attack();
}
//etc
}
}

All this would do is move toward you, and attack when in range. This is dumb, and it has no reguard for other things such as moving around walls in a 3d or 2d grid, aiming correctly if there is rotation, or dodging or blocking attacks if that were possible.

Of course, we can solve the navigational thing with a pathfinder... maybe? But the other ones confused me.

Does anyone, including Aprone, know or is willing to share how Aprone makes AI's in Swamp, or how similar ones are made?

This is just logically, unless you want to provide sample bgt code.

I'd like logic first though to see if I can do it on my own.

Sub question:

Is making AI's that learn, inside of a game, possible... And if so, how?

Cheers:
Redfox.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-09-21 17:59:31

AI is kind of an overloaded term. Look into state machines. You can have an Attacking state that moves toward your enemy and engages, a Retreating state that moves away when health is low, etc. That's a bit simplistic, but will get you in the right direction.

There's a book called something like AI for Game Developers. Might be worth looking for. I read a copy 15 or so years ago, and imagine it probably gets semi-regular updates. Even if it doesn't, there's lots of good info on everything from fighting games, to path-finding and swarm behavior. Worth the read. It had a good chapter that modeled AI behaviors based on chemical interactions. So certain molecules attract others to certain degrees, while others repel them. So you could build AI agents that calculate paths by steering toward the player, modeling them as being attracted to the player. Yet if there were hazards, like mines or enemies that could attack the AI, they'd steer toward the player while navigating around the hazard because it repelled them. So instead of calculating a direct course toward the player, the AI would steer toward them while avoiding the intervening hazards, averaging out the attracting/repelling forces and calculating a course that seemed a bit more natural. Really changed how I conceptualized game AI 15 or so years back. It wasn't "do this or do that," but rather "do this one thing that takes both this and that into account and averages the two decisions."

2019-09-21 21:39:55

Finite State Machines are commonly used, which are essentially decision tree's. If player within X spaces, moves towards player, if player has garlic move away from player, etc. Random number generators in this case can be really good for building more personality into your AI, like rolling a number between 1 to 10 every few seconds or so, if below 5 approach the player, if above stop moving, etc.

On the more technical aspects of navigation and targetting, you would need a pathfinding algorithm like A Star or something similar, aiming in terms of rotation would involving taking the position of the enemy and the position of the player and rotating in the given direction towards the player. Same thing with dodging or blocking, if the player attacks the AI registers the action and chooses a given reaction, possibly with random number generation. If dodge move X to try and avoid attack, if block, well, block.

Learning AI's within games are also possible based on retained variables, some being referred to as [Genetic Algorithms], seeing as they learn through a process of natural selection. There's actually an interesting game called [Echo] where each room is filled with clones of the player. Every action the player takes "updates" these clones so they can do the same next round, so if you run around jumping mad and shoot them all, next time they'll do the same to you. Crawl through the next map as a total pacifist, they will too next round. This mechanic allows the player to set the difficulty of their opponents each round through their actions, you could get up and blow past the crawling pacifists this round, but expect them to rush you the next as a result.

There's also a Total Beginners Guide to AI article [here], not likely the same as the book nolan mentioned but may still be worth a read.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-09-22 15:09:07

These are great questions and @magurp244 has covered most of what I was going to write on this subject. With respect to AStar, I've found it to be the most useful and actually employ it in TDV quite successfully.

Since we're talking about instant turns here, you can definitely use a aim-and-shoot situation for your NPCs. The trick here is you don't want your NPC to turn too quickly, so you need to set a delay or have them turn faster or slower at random. The alternative is to have them turn instantly, and since we're not using graphics here we don't need to simulate anything turning. So all you need to do is get the angle between the NPC and the player and shoot in that direction. This is simple enough to do:

            float X = 0f;
            float Y = 0f;
            X = X1 - X2;
            Y = Y2 - Y1;
            TheTa = Math.Atan2(-X, Y);
            if (TheTa < 0)
            {
                TheTa = TheTa + 2f * PI;
            }
            return (int)((float)TheTa * 180f / PI);

Now the object at x1 y1 will need to face those degrees to form a straight line to x2 y2

2019-09-22 20:05:06

With AI, the thing to remember is the computer wants to score the highest score possible.
So, if AI steps towards player and shoots, then he gains 5 points from hitting the player, but he is then also in range of player. therefore, minus 2 points automatically.
Therefore, does stepping towards the player to the right of the player, or to the left of the player give the highest score?

Also, have a look into seudo code. It's a style of writing code without using language syntax

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!