Making AI player tanks chose high ground when defending base.
Find a path with the start point the enemy base and the end your base. This will be the attack path of the enemy. For every node in the attack path of the enemy run the pathfinding algorithm to nearby tiles. Lets call the resulting paths Test paths. Nearby tiles means all the tiles that fall in the range of a tank in deploy mode. For each test path compute the direct distance between path start tile and path end tile. Then make a comparison between the length of the test path and the length of the direct distance. If the test path is longer then direct distance you found a tile that is difficult to reach. You need to go around to get there hence it's a good location to place tanks. What you found could be high ground or some kind of other difficult spot to reach (i.e. there could be a compact cluster of buildings in between, a row of crystal tiles etc. )
The problem is you might find areas difficult to reach far away from your base. If you place tanks there the enemy will just avoid the tanks and find another path to your base. To solve this problem there is a solution. In a game like Starcraft often there is only one entrance in the base (a ramp or just a map bottleneck). You can find out if there is only one entrance by trancing two or three paths to the base(lets call them scout paths) from different locations on the map. One location could be the enemy base the other locations could be places on the opposite side of the map. If all scout paths begin to overlap somewhere you found a unique entrance in your base. You can deploy tanks around in that location.
Making AI player tanks chose high ground when attacking the enemy base/expansions
It's pretty much the same strategy. If you know the place where the enemy is you can trace paths all around that place and find a location difficult to reach.
No bad idea, but ther are the usual problems of such stochastic approach utilizing randomness. E.g., if all your random locations on the map are on the left of the base, than you might miss the entrance on the right.
Randomness includes bad luck, and to avoid it, you need more ‘samples’, or locations in your case. It also matters that the samples are well distributed. E.g. if you generate them using a 4x4 grid over the whole map, chances you would miss the right entrance are smaller than using 16 of random points over the map.
However, i think there is a better way: Instead tracing paths from random points to the base, you can use Dijkstra to grow paths outwards from the base. No goal is needed, just grow the paths until they have a distance large enough to ensure we're outside. Would look like this:
All the possible paths from the base form a tree. The green start point in the base is the root.
We get many red end points, and we know the shrotest path to each of them.
So we also know the shortest path from each red point to the base, obviously. Which is what you're interested in.
Now we can walk the path from each red do to the base, and we could increase a counter for each path segment we visit. Would look like this maybe:
The less entrances you have, the higher the numbers near them.
So maybe you could use that number to identify entries, or more generaral: Locations worth to defend, and paths more likely to be visited than others.
Comparing this with your idea to use random points of the whole map, using Dijsktra your entire map would be filled with paths, so you do much more work. And maybe even better: You do not need to come up with good random points at all. And maybe you do not need to classify an ‘entrance’ either. Maybe the number is all you need to get expected behavior.
(Maybe the number can be computed already while doing the path finding, and there is no need to traverse the paths.)