What would be an efficient way for making the AI on a game with mass amounts of units, like an RTS? Who's purpose would be to of course, locate nearby enemy units and "attack" them. Specifically, I'm talking about the locating of enemies rather than the attacking of them. My first thought would be, say, go through the entire list of units using a for loop and then finding the "closest" one that's an enemy, but this obviously causes a lot of lag with a lot of units. I'm not asking for any scripting to be done for me, just wondering of what methods could be used to efficiently find close by enemies? I'm unaware of a "get nearest" function to use, so if anyone could help point me in the right direction, or discuss the reasoning behind why this method would be an efficient choice, that'd be lovely.
COMMUNITY QUESTION
What would be the best way to script AI for an RTS? (enemy location?)
1 answer
Unit Grouping and Culling
The last picked for the team.
Keep groups of units in locations. For a grid based example, you could keep a table of tables for every location on a grid and add/remove units from the tables when they enter or leave the grid spaces. That way, you have a data structure that you can use to search from the inside out and therefore get your closest enemies first.
There is a small issue. Your question is regarding an AI - An AI does not certainly get the nearest enemies. You may want to consider a different data structure which can do weighting, or a mixture where you switch between searching methods under certain conditions.
This discussion is preserved as it was. New answers, comments, and votes are closed.
