Building a better RTS AI. Making AI player tanks chose and deploy on high ground
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.
Discussion