Here are the algorithms that the Computer Nations use. Note that this assumes that NPC_PATROL is TRUE. The only part of the algorithms that this affects is step seven of the draft algorithm. If NPC_PATROL is false, no patrolling armies will be drafted. Algorithm 1: NPC MOVES Step 1: Allocate memory to evaluate sector desirability. Step 2: Perform the INITIALIZATION algorithm. Step 3: If the turn number is greater than one or there is a race-specific army type available, perform the DRAFT algorithm. Step 4: Merge armies using the MERGE algorithm. Step 5: Split armies using the SPLIT algorithm. Step 6: Summon monsters using the SUMMON algorithm. Step 7: Move armies using the MOVE algorithm. Step 8: Redesignate sectors using the REDESIGNATE algorithm. Step 9: Free the memory that was allocated in steps 1 and 2. Algorithm 2: INITIALIZE Step 1: Create lists of available armies and monsters. Step 2: If there is a race-specific army type available to this nation, store its index in a global variable, npc_specific. Step 3: Read in the diplomacy information and modify the nation's diplomatic status using the DIPLOMACY algorithm. Also determine what sectors are visible. Step 5: If the nation is at war, set the optimal army size to be (number of soldiers * 2) / (number of sectors). If this is less than 150, use 150 instead. Then perform step 6. If the nation is not at war, set the optimal army size to be 100 and perform step 7. Step 6: Set the tax rate at 25 percent. Put 15 percent of monetary income into magic and technological research. Do not put any metal into research. If there are not enough jewels left to support a mage, do not put any into research. Otherwise, spend your entire income or half of your storage, whichever number is lower. Step 7: Set the tax rate to 15 percent. Put 25 percent of money and 30 percent of metal into technological research. Put 25 percent of money and 10 percent of jewels into magical research. Algorithm 3: DRAFT Step 1: If the nation is at war, set the maximum number of troops to be (aggressiveness) * (civilians) / 200. Otherwise, set the maximum number of troops to be (aggressiveness) * (civilians) / 300. If the nation already has the maximum number of troops or more, quit. Step 2: Calculate the number of troops to be drafted this turn as the average of (aggressiveness) * (net reproductive rate) and (maximum soldiers) - (current soldiers). Make sure this number is no larger than the number of civilians in the capital. Calculate the number of armies to draft this turn as (number of troops) / (optimal army size). Step 3: Create a list of all army types that can be drafted, eliminating those armies with special abilities. Step 4: For each army type in the list, find the force and the metal and money cost. Step 5: While the number of armies left to draft is greater than zero, perform steps 6 and 7. Step 6: For each army type in the list, calculate how many armies of that type can be drafted. Consider money cost, metal cost, and the number of armies left to draft. Then multiply that number by the force of that army type. This gives the total force. Step 7: Draft one army of whatever type had the greatest total force in step 6. If the percentage of patrolling troops is less than npc_iso, set the status of the army to PATROL. Reduce the amount of money and metal in storage by the cost of the army and reduce the number of armies to be drafted by one. Algorithm 4: MERGE Step 1: Calculate the minimum size of an army as 2/3 * (optimal army size). Step 2: For each army in the nation, if the number of troops in the army or the force of the army is smaller than the minimum size, perform steps 3 and 4. Step 3: Find out what sectors this army can move to using the LEGAL MOVES algorithm. Find the best army in those sectors for this army to merge with. The size and force of the two armies combined should be close to and greater than the minimum size. Step 4: Move the small army onto the same sector as the 'best' army and merge the two armies together. Algorithm 5: SPLIT Step 1: For each army in the nation, if the number of troops in the army or the force of the army is larger than double the optimal army size, perform step 2. Step 2: Split this army into armies of optimal size until the number of troops in this army is less than double the optimal army size. Algorithm 6: SUMMON Step 1: If the nation is at war and has more than one spell point, perform steps 2 and 3. Step 2: If the nation does not have a mage and the nation has enough jewels to afford one, initiate one in the capital. If the nation cannot afford a mage, stop. Step 3: While the nation still has spell points left, summon the most expensive monster that the nation can afford and that has no special abilities. Reduce the number of spell points left by the cost of the monster. Algorithm 7: MOVE Step 1: Give each sector on the map a desirability using the DESIRABILITY algorithm. Step 2: For each army in the nation with a status of ATTACK or DEFEND, find all the sectors it can move to using the LEGAL MOVE algorithm. Move the army to the sector that has the highest desirability and set its status to 'occupy'. Divide the desirability of the sector by 2 * (army size) / (optimal army size) Step 3: For each army in the nation with a status of PATROL, find all the sectors it can move to using the LEGAL MOVE algorithm. Move the army to the sector that has the highest desirability. Set the status of that sector and all adjacent sectors to zero. Algorithm 8: REDESIGNATE Step 1: If the game turn is less than six, enough food is being produced, or more than ten percent of the civilians are unemployed, perform steps 4 and 5. Otherwise perform steps 2 through 5. Step 2: Create two lists, one of sectors used for metal mines and one of jewel mines. Order the lists by how high the soil value is for the sectors. Do not put sectors with a soil value of zero in the lists. Step 3: Change the sectors in the lists into farms, proceeding from higher to lower soil values. Stop when enough food is being produced or when half of the sectors in each list have been changed to farms. Also stop if the nation runs out of money. Step 4: For all the sectors in the nation that do not have a designation, perform step 5. Step 5: If the sector has no metal or jewel value and does have a soil value, change the sector to a farm. Otherwise, change the sector to a metal or jewel mine, depending on whether the metal or jewel value is higher. Algorithm 9: DIPLOMACY Step 1: Count the number of nations that are at war with this nation and assign that number to atwar. Step 2: Calculate the effective aggressiveness as (aggressiveness) / (atwar + 1). Step 3: For each active nation in the world that has met this nation, perform steps 4 and 5. Step 4: Pick a random number between 0 and 99. If this number is greater than the effective aggressiveness, increase the diplomatic status toward that nation. Otherwise, lower the diplomatic status. Step 5: Do not let the diplomatic status remain lower than Jihad or higher than the status of the other nation toward us. Algorithm 10: DESIRABILITY Step 1: Count the number of friendly and unowned sectors that can be seen. Double the number of enemy sectors that can be seen. Keep track of the maximum of these three numbers. Step 2: For each sector in the world, calculate the base desirability. If the sector is owned by a friendly nation, the desirability is zero. If the nation is not at war, the desirability of friendly sectors is zero. If the nation is at war and the sector is friendly, perform steps 3 and 4. If the nation is at war and the sector is owned by an enemy, perform step 5. If the sector is unowned, perform step 6. After all sectors have been processed, perform step 7. Step 3: If the sector is a farm, the desirability is 3 + (soil value) * (ratio of food eaten to food produced). If the sector is a metal or jewel mine, the desirability is 3 + 1.3 * (metal or jewel value). If the sector is a city, university, or capital, the desirability is 11. All other sectors have a desirability of 2. Step 4: Increase the desirability of the sector by one for each adjacent enemy sector. Multiply the desirability by the ratio of (enemy sectors) / (maximum) and by the ratio of (friendly sectors) / (3 * the number of armies we have + 1). Divide this number by two. Step 5: The desirability of the sector is 12. Increase the desirability by one for each adjacent friendly sector. Divide this number by two. Step 6: The desirability of the sector is (soil value) * (ratio of food eaten to food produced) + (metal value) + (jewel value). Increase the desirability by one for each adjacent friendly sector. Divide this number by two. Step 7: For each sector in the world, calculate the final desirability of the sector as the base desirability squared. If the nation is not at war and or the base desirability is not zero, perform step 8. Add (population of the sector) / 25. If the sector is a capital, double this number. Then perform step 8. Step 8: If the sector is visible to this nation according to the rules of Dominion, increase the desirability of nearby sectors. Add (base desirability) - 1 to immediately adjacent sectors, (base desirability) -2 to the sectors just beyond those, and so on. Algorithm 11: LEGAL MOVES Step 1: Initialize a two dimensional array of odd side length to contain negative ones. Let the center of the array represent the sector that the army is on. Change the value of this location to the number of movement points the army in question has. Place the x and y of this location, along with the number of movement points the army has, into a list. Step 2: Take the element off the top of the list. For all adjacent sectors with a value of negative one and a movement cost less than the movement points in the element, perform step 3. If there are any elements left in the list, repeat step 2. Step 3: Calculate the number of movement points left upon entering the sector as (movement left) - (movement cost). If this movement left is not zero, store it in the list, along with the x and y coordinates of this sector. Keep the list in sorted order, with the highest movement left first.