Bibor
Doomsday Machine
I've seen some of the programming "decision making" notes of the developer of PG forever, so that makes me as competent to suggest this as a badger is competent to talk about Hermann Hesse. But bear with me.
The following steps get refreshed every turn.
STEP ONE:
AI takes a look at it's own cities designates importance numbers for them. This is based on:
a. capital or not
b. total yield summed up in 2-hex radius of a city
c. number of resources available in 2-hex radius
d. whether city resources are available in other cities or not
e. population number of the city
f. number of buildings and wonders in the city
g. number of improved tiles around the city
h. proximity to competing civ (high bonus)
Example screenshot (I later decided on another city to be priority #1)
STEP TWO:
The AI marks tiles adjacent to its cities as "danger" or "safe" in the following fashion:
the AI draws a line in each of the 6 directions from every city.
a. if the line ends at hostile borders or passes a hex adjacent to enemy borders, the adjacent city tile is "hostile"
b. if the line ends in a friendly city or there's a friendly city adjacent to the line, the city tile is "safe"
c. if the line doesn't pass at least 5 friendly tiles, it's considered "hostile"
This is also the way AI determines "border cities". And here's the image:
STEP THREE:
The AI marks the cities and the safe zones as GREEN.
STEP FOUR:
The AI creates 3 lines of hexes, Orange (hostile), red (danger) and Green (safe) in the following fashion:
a. Any hostile hex is marked "red"
b. Any hex adjacent to a "red" hex AND would border a "green" hex is tagged "red"
c. Any hex adjacent to a "red" hex AND would NOT border a "green" hex is tagged "orange"
d. cities are automatically tagged "green"
e. any hex bordering two "green" hexes and a "red" one becomes "green"
STEP FIVE:
AI determines "good defense" tiles in the ORANGE LINE.
a. first it marks all hills and forests
b. then it marks all orange tiles that have a river crossing directly OPPOSITE of a RED hex (it does this for red hexes, but is not shown on images)
STEP SIX:
AI abandons all "good defense" ORANGE hexes that do not:
a: border a RED hill
b: do not border at least THREE red hexes
and marks them BLUE
STEP SEVEN:
AI designates melee and ranged units to hexes:
a. BLUE hexes gets tagged as MELEE
b. every RED hex gets tagged as MELEE
c. every RED hex that would border 3 or more MELEE gets converted to RANGED
d. every GREEN hex that borders at least two MELEE gets tagged as RANGED
e. every city gets tagged as RANGED
f. every GREEN that borders 2 or more RANGED gets tagged as REINFORCEMENTS
STEP EIGHT:
So far, we described several sets of tiles (melee, ranged, reinforcements) that can be easily calculated and understood by an AI. These tiles would help it defend itself IF it would have enough units to fill out all the tiles it used for the calculation. However, that is almost never the case. Now we have to implement a way to get the AI make use of the tile values it added itself to the hexes in question, considering the army it has at its disposal.
For us to help him do this, we are going to introduce a way of reducing the values of the stated hexes, from melee to "abandon", from ranged to melee and from reinforcements to ranged.
Lets say Montezuma has 6 units at his disposal. We also made the AI calculate distance of every red tile to each of his cities and Texcoco proved to be the shortest distance to all the red tiles. So, he has 6 units around Texcoco, 3 swordsmen, 1 catapult and 2 archers.
We invade Montezuma and he can see our first unit threathening him on the Cotton between Beijing and Tlatelolco.
By using the city priority numbers he decided upon this round he decides Tlatelolco is his highest priority and his units can reach it in 2 turns.
STEP NINE:
The Defense of Tlatelolco.
We tell it: AI you have 3 melee and 3 ranged units to defend yourself. We also code him so that AI can use only 1st and 2nd ring of a city to defend itself. The AI Determines that the following tiles match the criteria.
The AI places his units in the following fashion:
a. first it determines one unit MUST go into the city. the top priority for city units is, as we know, RANGED. and among ranged, ARTILLERY has top priority. So the catapult goes into the city. It has 3 melee and 2 ranged units left.
b. it has 10 vacant tiles and "less than 7" units. Thus, it cuts all the tiles not adjacent to the city first.
c. Since the ranged and reinf. tiles don't match the criteria anymore, they get reduced by one rank, to melee and ranged, respectively.
c. now he places the 1st swordsman on tile that was tagged as "good defense" (hills or river crossing opposed to green zone).
d. since no other optimal defense tiles are available, he proceeds to place the RANGED
e. and now he places the remaining melee so that they are adjacent to ranged (otherwise it would proceed to place melee on good spots and adjust RANGED accordingly).
STEP TEN:
The Issue of suicidal AI moves becomes fixed by simply coding the AI NOT TO MOVE units when on defense, except if one of the following criteria matches:
a. the hex changed state (from melee to abandon, from ranged to melee) or becomes vacant
b. peace broke out
c. enemy units are elsewhere
Damn, my brain hurts after these 5 hours.
The following steps get refreshed every turn.
STEP ONE:
AI takes a look at it's own cities designates importance numbers for them. This is based on:
a. capital or not
b. total yield summed up in 2-hex radius of a city
c. number of resources available in 2-hex radius
d. whether city resources are available in other cities or not
e. population number of the city
f. number of buildings and wonders in the city
g. number of improved tiles around the city
h. proximity to competing civ (high bonus)
Example screenshot (I later decided on another city to be priority #1)
Spoiler :
STEP TWO:
The AI marks tiles adjacent to its cities as "danger" or "safe" in the following fashion:
the AI draws a line in each of the 6 directions from every city.
a. if the line ends at hostile borders or passes a hex adjacent to enemy borders, the adjacent city tile is "hostile"
b. if the line ends in a friendly city or there's a friendly city adjacent to the line, the city tile is "safe"
c. if the line doesn't pass at least 5 friendly tiles, it's considered "hostile"
This is also the way AI determines "border cities". And here's the image:
Spoiler :
STEP THREE:
The AI marks the cities and the safe zones as GREEN.
Spoiler :
STEP FOUR:
The AI creates 3 lines of hexes, Orange (hostile), red (danger) and Green (safe) in the following fashion:
a. Any hostile hex is marked "red"
b. Any hex adjacent to a "red" hex AND would border a "green" hex is tagged "red"
c. Any hex adjacent to a "red" hex AND would NOT border a "green" hex is tagged "orange"
d. cities are automatically tagged "green"
e. any hex bordering two "green" hexes and a "red" one becomes "green"
Spoiler :
STEP FIVE:
AI determines "good defense" tiles in the ORANGE LINE.
a. first it marks all hills and forests
b. then it marks all orange tiles that have a river crossing directly OPPOSITE of a RED hex (it does this for red hexes, but is not shown on images)
Spoiler :
STEP SIX:
AI abandons all "good defense" ORANGE hexes that do not:
a: border a RED hill
b: do not border at least THREE red hexes
and marks them BLUE
Spoiler :
STEP SEVEN:
AI designates melee and ranged units to hexes:
a. BLUE hexes gets tagged as MELEE
b. every RED hex gets tagged as MELEE
c. every RED hex that would border 3 or more MELEE gets converted to RANGED
d. every GREEN hex that borders at least two MELEE gets tagged as RANGED
e. every city gets tagged as RANGED
f. every GREEN that borders 2 or more RANGED gets tagged as REINFORCEMENTS
Spoiler :
STEP EIGHT:
So far, we described several sets of tiles (melee, ranged, reinforcements) that can be easily calculated and understood by an AI. These tiles would help it defend itself IF it would have enough units to fill out all the tiles it used for the calculation. However, that is almost never the case. Now we have to implement a way to get the AI make use of the tile values it added itself to the hexes in question, considering the army it has at its disposal.
For us to help him do this, we are going to introduce a way of reducing the values of the stated hexes, from melee to "abandon", from ranged to melee and from reinforcements to ranged.
Lets say Montezuma has 6 units at his disposal. We also made the AI calculate distance of every red tile to each of his cities and Texcoco proved to be the shortest distance to all the red tiles. So, he has 6 units around Texcoco, 3 swordsmen, 1 catapult and 2 archers.
We invade Montezuma and he can see our first unit threathening him on the Cotton between Beijing and Tlatelolco.
By using the city priority numbers he decided upon this round he decides Tlatelolco is his highest priority and his units can reach it in 2 turns.
STEP NINE:
The Defense of Tlatelolco.
We tell it: AI you have 3 melee and 3 ranged units to defend yourself. We also code him so that AI can use only 1st and 2nd ring of a city to defend itself. The AI Determines that the following tiles match the criteria.
Spoiler :
The AI places his units in the following fashion:
a. first it determines one unit MUST go into the city. the top priority for city units is, as we know, RANGED. and among ranged, ARTILLERY has top priority. So the catapult goes into the city. It has 3 melee and 2 ranged units left.
b. it has 10 vacant tiles and "less than 7" units. Thus, it cuts all the tiles not adjacent to the city first.
Spoiler :
c. Since the ranged and reinf. tiles don't match the criteria anymore, they get reduced by one rank, to melee and ranged, respectively.
Spoiler :
c. now he places the 1st swordsman on tile that was tagged as "good defense" (hills or river crossing opposed to green zone).
d. since no other optimal defense tiles are available, he proceeds to place the RANGED
e. and now he places the remaining melee so that they are adjacent to ranged (otherwise it would proceed to place melee on good spots and adjust RANGED accordingly).
Spoiler :
STEP TEN:
The Issue of suicidal AI moves becomes fixed by simply coding the AI NOT TO MOVE units when on defense, except if one of the following criteria matches:
a. the hex changed state (from melee to abandon, from ranged to melee) or becomes vacant
b. peace broke out
c. enemy units are elsewhere
Spoiler :
Damn, my brain hurts after these 5 hours.