Part 1: Analyzing the Map - Distinguishing a rock from a hard place (so as not to get stuck between them).
Before the AI can do anything at all, it will need to be able to navigate the map and work with and around the map's terrain.
Here's a tentative list of terrain-based decision making the AI will need to deal with:
-Locate and defend at bottlenecks.
-Identify inaccessible sections of the map (eg that huge mountain in the middle of Around The World).
-Determine the "real" distance from a mining beacon to its base. By "real" I mean "take into account obstacles like cliffs and rocks".
-Locate enemy bases. This should be easy enough.
-Utilize vehicle waypoints effectively, since OP2's built-in pathfinding is horrible.
-Identify optimal base locations.
BottlenecksIn a real fight, the AI is going to need to know enough about to defense to park its units at bottlenecks to keep the enemy out of its base. All we care about right now is getting the AI to tell where those bottlenecks actually are, though, so how would we do that?
A bottleneck is, of course, a gap of passible terrain between two or more pieces of impassible terrain designed so that enemy units have to funnel into them, putting the defenders at an advantage.
Unforuntately, a lot of terrain matches the description of "passible between impassible" so we're going to have to be clever if we want to avoid getting false positives.
Anyways, let's look at a few examples of bottlenecks. Some are obvious...
...Others, not so much.
Think of your favorite maps. What do the bottlenecks look like? Can we define a few general "structures" that will allow the AI to identify bottlenecks accurately? Are there any similarly-shaped sections of terrain that might create false positives? How do we distinguish these from real bottlenecks?
We need to think of criteria to look for when searching for bottlenecks. Here are some thoughts, please add your own:
-A "bottleneck" should be defined as a line with two sectors of open terrain on both sides. The line's endpoints must be impassible terrain. Should we require the terrain on one side to be bigger than the other (be funnel-shaped)?
-Should we limit the number of bottlenecks we can have in close proximity to each other? If so, based on what?
-Should there be boundaries (lower and/or upper limits) on the size of bottlenecks?
-Should we implement some kind of system to "rank" bottlenecks? How do we determine what makes one bottleneck "good" while another one "bad"?
Note: Implementing bottlenecks this way may have the added benefit of dividing the map into several discrete sectors, where a sector is defined by an area enclosed by bottlenecks and impassible terrain.
Identifying Inaccessible Terrain: Because our AI isn't a Colony SearcherSo let's say the AI is playing a round on La Corrida. It's in the bottom left corner. To the left of its base, there are high mountains. To the north we've got a valley. Units can reach neither of these places. This probably isn't going to be a problem, since pathfinding will just treat those as obstacles.
They will become a problem when we go to do a Land Rush though. Say we're playing a custom map, and there's all sorts of ore mines down there because whoever made the map has a sick sense of humor. If the AI doesn't realize that it can't get to those parts of the map, it may consider those viable base locations and never get around to actually building anything since it's hung up on reaching the unreachable.
So how do we check if part of the map is blocked off from the AI (since what is and is not "reachable" is relative to where the AI spawns)? Beats me. We could just pick an AI unit and check every passible tile on the map to see if the unit can reach that tile. We'd need to figure out a way to optimize it though, or that will really bog down the game.
We're going to need to discuss this issue a bit more, and do some research. BB/Hooman: if you're reading this, got any advice?
Simple Pathfinding: Determining the "real" distance from the base to a mining beaconLook at this image:
We have two mining beacons near our Smelter: one at (220, 102) and the other at (238, 104). If we just apply the distance formula (D = sqrt( [x1-x2]^2 + [y1-y2]^2 ) then the one on the left is closer. Of course, in order to actually reach that beacon we have to go around a fairly large section of cliffs. So we want the one on the right. How do we figure out which one is "really" closer to us?
One option is to write our own pathfinding code. _A_ recommended the A* pathfinding algorithm awhile back since it's pretty fast, works well, and is supposedly pretty easy to code. There's plenty of info on A* all over the place, we can just Google it and pick a nice tutorial/demo/whatever. But since this is all about discussion, if anybody else has a different suggestion please speak up.
Before moving on to the next subject, I will mention this one thing: if we implement A* right, we should also be able to apply it to units. If we do it
really well we may be able to overwrite OP2's horrible pathfinding system for use in regular play. But don't hold your breath on this one.
Locating and Identifying Enemy BasesWell, locating them is simple enough. Just look for buildings owned by other players. But how do we tell what types of bases they are?
I classify bases into a few different categories:
-Main base: Generally the player's starting base. Should be the biggest one, and have all kinds of structures. Key things to look for will be a Structure Factory, power, and non-strategic buildings (Agridomes, University, etc.).
-Sub-base: The only reason this isn't one of the other base types is because it doesn't have its own Command Center. Instead, there's a (long) tube connecting it to another (probably the main) base. Attempt to classify it anyways.
-Military outpost: If somebody has a bunch of Vehicle Factories built outside your base, and it's not you or your ally, you have 3 guesses as to what they're going to do with them. No bonus points for guessing correctly.
-Mining outpost: Look for a Mine or Magma Well, Smelters, and a CC.
-Spaceport farm: This is probably behind the main base if terrain allows it. Anyways, EMP Missiles are gonna be flying from this soon.
Of course, things don't always fit cleanly into those categories. An ore base might have a few VFs with it, for example, so we would want to identify that as such. I'll leave it to the rest of you (and ultimately, whoever decides to implement this part) to figure out exactly how many types of bases there are.
Anything else we can do here? Let's see... Well, if we find their base we can search for bottlenecks and backdoors. That would be useful in planning attack routes and predicting where they'll defend.
Anyways, I'm not sure this section really classifies as "terrain analysis" but I figured you guys would want to play around with bases instead of dirt and cliffs all day. I'm nice like that.
Waypoints and Improved Pathfinding: Too Dumb To DriveRemember how in the section about finding good mining beacons I said "if we do A* right we can also apply it to AI pathfinding"? Well, that was more on an individual unit level. This section is moslty concerned with the movement of large groups and planning ore-hauling routes if necessary. In other words, we've got to get the AI to make use of waypoint plotting. Luckily for us we've already gone and divided the map into sectors and bottlenecks, so we can use these to help us plot waypoints!
Here's just a rough idea of what I think the AI would do to issue group waypoints:
1) Set up a queue of waypoints. It should start out completely empty.
2) Determine sector the group's destination is in.
3) Determine sector group is in. (Note that groups may take up more than 1 sector depending on their size; in this case go with whichever sector has more group units in it.) Push this to our queue.
4) Check all bottlenecks leading out of this sector. Don't store anything yet.
5) Check all bottlenecks leading out of this new sector (excluding the one we used to enter this sector).
6) Choose the bottleneck from step 5 that brings us closest to the target area. Get the one from step 4 that gave us the one from step 5. Push them both to the queue (in order step 4, then step 5).
7) Repeat until we get to the target location.
Issue move orders to all units in that group, making sure they go through each waypoint (and wait for the group to catch up at each stop?).
Again, this is blurring the lines between terrain stuff and unit stuff, but I don't think anybody will complain.
Also note that trucks will have to do a similar thing.
Identifying Good Base Locations: Nice neighborhood AND affordable! Just watch out for those sub-prime mortgages...Okay, so, what do you want when you build a base in a Land Rush? Good ore, enough space for buildings, enemies not nearby, allies close (if applicable), and nice bottlenecks to make defense manageable, right?
So how can the AI determine all of these factors? I see a few possible methods:
1) Search for large chunks of open land suitable for building, evaluate based on number of bottlenecks and quality/quantity of mines. Such a system may favor building in the middle of the map.
2) Search for small, defendable bottlenecks, maximizing defendability. Factor in amount of available land and mines. This AI may favor small bases in corners and tight spaces.
3) Search for the best mines. This is probably how most people play.
Really, we can judge locations based on whatever criteria we want, and we can have the factors influence the decision making process in any number of ways. This is something we'll really want to discuss in detail before we start anything.
Okay, I need to take a break. Start the discussion and I'll see you around.
Note: This was just pasted in from a text file I wrote in advance, so let me know if there are any weird formatting errors/etc.