AI suggestions

BlitzMax Forums/BlitzMax Programming/AI suggestions

Cruis.In(Posted 2013) [#1]
Hey guys, looking for some wisdom on handling AI.

So my AI in a space game can turn, fly anywhere once given a destination.

There will be many different ships based on the different alien races with different goals.

So I've placed these methods in the class which controls these ships. Then I guess based on their destinations meaning IF they have a destination based on their logic, they will call the methods which transit them to their destination :)

I have been wondering how to properly control who gets the destinations, because if I have many alien races, all of their ships can't each do what the other is doing.

So I've been wondering I can separate the ships into lists, and then for which ships I want to do X, use for eachin loops on them.

But instantly that seems to me never ending lines of code if I had hundreds of ships running around. Suppose I just want to give individual ships something to do and I have 1000 individual ships in the world. A list would contain one item, or I'd make that ship particularly like PirateShip1:tenemyship and then give pirateship his job.

What about giving a couple different ships jobs, but in different areas.

Just wondering what I am not thinking of, to limit excessive micro management of the AI ships, while still creating something which feels like their is activity around.


Banshee(Posted 2013) [#2]
Rather than the ship being a child of it's strategic logic, why not have its strategic logic a child of the ship?

A ship only needs a new destination when it reaches its current waypoint, or an outside factor (such as being shot at) changes its strategic state.

When the strategic state needs to change, check its job type against the available options and set its destination accordingly.

No list necessary.


Cruis.In(Posted 2013) [#3]
so based on what that ship is going through it calls what it needs.

but I don't think I am getting how to apply the logic across the spectrum of ship goals.

Like a warship will patrol, and a transport ship will transport stuff.

Ok I am starting to wrap my head around it...each ship needs to check its own conditions relative to itself. What conditions one is going through has nothing to do with another.

Two ships, one under attack and one not. Once the ship realizes its under attack, it takes certain steps calls certain methods. While the other one not under attack, has no need to break from its routine.

This is just accomplished by using self can it not be?

So the methods are in the type.

ActivateDefense()

if othership nearby

if hostile

self.shields = true
self.weaponsystem = true

self.Defend() // where defend() is a series of routines for fighting, how fast to go, when to slow down where to maneuver etc.

Based on what I said, does this gel with what you told me? Have I interpreted it right?


Banshee(Posted 2013) [#4]
Yeah pretty much.


Kryzon(Posted 2013) [#5]
For me, I wouldn't go with the complex behavior at first. Rather build a palette of simple actions that I can use to build these complex behaviors.

Such simple actions: move, stop, shoot, jettison cargo and many more. It's easier to come up with these actions if you think of yourself inside the ship's cockpit: what can you do with the ship with just the controls in the cockpit?
Because that's what an actual pilot would be doing, in the end. He makes the ship do actions; it's the string of several actions that is interpreted as behaviour.

When you have a list of these actions then you can proceed to build states:
Patrol would be the sequence of actions: "move to A, move to B, move to C, repeat."
Transport would be: "move to cargo, pickup cargo, move to A, jettison cargo, repeat".

Then you can have a single update function for each ship: self.Update(), with a huge Select statement that has several code blocks for each possible state the ship can perform.
Each state analyses the context in which the ship finds itself and calls the appropriate actions. For instance, if while patrolling the ship encounters an enemy then the patrolling state changes from itself to an attack state, with the target being the enemy, until the enemy escapes or is destroyed and the ship goes back to patrolling.
Now I just realized that states have hierarchies (destroying\attacking enemies has priority over patrolling), and that adds another layer of complexity...


Cruis.In(Posted 2013) [#6]
cool thanks for the explanations. Really helps! Any more thoughts on the matter feel free to update here!


Cruis.In(Posted 2013) [#7]
question again guys, if I have a list of planets, whether randomly created or not.

How can I retrieve their coordinates so that I can then set a patrol pattern? As in for the AI to know where these planets are.

want the AI to be able to retrieve them and feed them to its FlyTO(x,y) function, to enable it to get its coordinates, input them and then execute.


Scaremonger(Posted 2013) [#8]
I imagine your Planet type has some co-ordinates as properties; in which case you could pass the planet object to the FlyTo() function instead of co-ordinates. The advantage here is that you could also pass a Space Station, Asteroid or another ship object if you so wished.