Original Post
I was browsing the web to see how a RTS ai was implemented (i was looking into the fighting part) - how to get the ai to use it's troops in an coordinated way... Almost everything i read used some kind of FSM together with a hierarchy of general->squad->unit or something like that. As i was reading a different approach suddenly came to me. What you do is divide the map (or at least the part that they're fighting in) into a grid with the size of each cell about the size of 5 units. Then you make the whole fight into an attempt to occupy the best (or most) squares (the occupier is the ones with the most units in the square). then, every few frames the ai has 3 options for every occupied square: 1) move troops (not necessarily all) from this square to another (neighboring) empty square. 2) move troops (not necessarily all) from this square to another (neighboring) occupied square. 3) "clear out" an enemy square (by killing the troops in the enemy square). Then you have to define what "good square" are. I'm not sure about this but you could define the value of a position by the number of squares that it lets you control - you decide who controls a square by checking who has an occupied square closest to that square. So for example, if the enemy occupies 4 squares in the middle: (-1,1),(1,1),(-1,-1),(1,-1) then occupying the 4 squares (-2,2),(2,2),(-2,-2),(2,-2) would be optimal because that means that you control the whole map except for the 4 ones in the middles. now the only move left to control more squares is move 3 - to kill the ones in the middle. so if the enemy is in the middle and the ai is scattered around the map the ai would surround and then kill the enemy. A refined version of this model could potentially give a flexible and pretty unpredictable (in the good way:) ) ai. What do you think?