Daily Dose of Code October 17, 2016






facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

What is Lacking from Real Time Strategy (RTS) Artificial Intelligence (A.I.) Programming?


“We all have big changes in our lives that are more or less a second chance.” — Harrison Ford





How many times have you played a Real Time Strategy (RTS) game and had to micromanage every aspect of the game characters? The other extreme is where characters create colonies or use overkill measures on small groups of enemies. In some games, you can set actions of how leaders and their subordinates react to situations but when it is left up to Artificial Intelligence (A.I.) often the end result is anything but desirable.

Expansion of colonies is a must to generate a healthy economy in (RTS) games. Depending on the allocation of resources and location, this can be a boost to the civilization or a logistical nightmare. An example would be if you needed a buffer colony between your civilization and another regardless of their intentions. The problem lies between terrain, availability of natural resources, commerce routes, and time from more advanced or secure colonies to arrive to support this new colony.







Questions that need to be addressed by a sensible A.I. model

  • How many troops will be needed to start maintaining order?
  • Is it possible to build a viable defense system and a local economy based upon available resources and terrain?
  • What is the likelihood of an attack by another civilization?
  • What is the total cost?

Many times I’ve encountered these problems. You’ve built up defenses and structures only to have them torn down by the enemy. Constantly resupplying and rebuilding can drain cash reserves quickly. Is this new territory a lost cause? Am I not employing the best strategy to preserve this territory? Does it seem like the enemy is constantly attacking the same territory when they could easily manage two attack multiple areas at once? Why this particular territory? Again, resources and location play a key part in this decision.

First, examine the weighted properties for how much does this territory mean to both civilizations.

The number of available resources, special bonus for controlling this area (extra troops, regenerate health, extra speed for units, population cap bonus, advantages of terrain, etc…) Now, weigh in the logistics or how long will it take to resupply this area and how much will it cost to do so?

The ‘Camp’ represents the base from which has a stockpile of buildings, units, and resources. The ‘New Location’ has lumber, food, and water available. These are raw materials so at least some time and money will be spent on either bringing these resources back to the ‘Camp’ or setting up a new camp here.


A simplified game unit represents the distance in the game/sim world. In this example, the new location works to our favor as it a shorter distance to us than the enemy. If the scenario were to be flipped, this would present a bigger challenge. Can we defend and reinforce this location in time?
How bad do we need the resources at this location? Do we know if the enemy really needs these or just does not want us to have access to it?

From this model distance from ‘Camp’ to ‘New Location’ weighs heavier than the distance from ‘New Location to ‘Enemy Base’. The number and importance of the resources are important but only if the territory can be defended.

To express this mathematically, I’ve assigned nodes A = ‘Camp’, B = ‘New Location’, C = ‘Enemy Base’ with the entire length representing 1.0 or 100 percent. Since most of the decision making should be the distance from camp, this receives a .7 while the Enemy Base to New Location receives a .3 and floating weights for the resources change based on how many resources and how vital they are to the civilization. This value will receive somewhere around .2 and when its all said and done, the decision to set up camp will be based on a logical value below .55 or close to 2/3.

The first few equations were basic, but more than a few minutes of coding in Python I arrived at the following result.





decisionPoints = ((math.sqrt((distanceFromHome *.70) + (distanceFromEnemy*.30))+resPoints)/10)
print(“decsion points: “,decisionPoints)
if (decisionPoints < approval): #approval for now equals .55
print(“lets setup camp!”)
else:
print(“No, its too dangerous!”)


From this code a variable decisionPoints has to equal less than .55 in order to decide to set up camp.

The variable decisionPoints is comprised of the following:

  • Are we close enough to ‘Camp’?
    • The greater the distance will influence a negative decision
    • A weighted score of distanceFromHome greatly influences the overall decision
  • The distanceFromEnemy is the next most important factor.
    • comparing this to distanceFromCamp also greatly influences the final decision
    • using a slightly less important but still somewhat important weight score is attached
  • Resources count in this decision but not as much
    • the total weight of this decision lies in
      • how many total resources are available
      • how bad do we need these resources
      • what is the total cost for these resources
    • a score of .01 to .1 is assigned to the importance of these resources
      • the lower the score the higher the importance
      • scale of 1-10 or .01 to .1
    • the total weight of this variable should be around .2

Conclusion

Alright, so the total value if all variables are added together equaled more than 1.0 and in the first few trials the math yielded some really bad results. The idea of a unanimous decision was out of the question. Approval can be altered depending on how aggressive or cautious the civilization is. This is set during the constructor of base class Civilization (not illustrated in this example.) where a 2/3’s majority vote would require a .66 value. A value of .51 would break the 50/50 tie. Where a more aggressive approach would be to set approval to .33 or even .2 to approve rapid expansion of colonies.

Obviously this code and idea will take some time and many revisions to refine not only the code but the end result. The goal is to create an A.I. civilization that thinks before it leaps. Or in this case before it builds nine colonies right on top of each other or too spread out to manage properly.

What if anything have we learned today? I look forward to your comments and if you liked this post please tell a friend.

Comments

Popular posts from this blog

GoldCoin is making the case to get onboard early

Reasons Why You Need A Red Nose… Day

Amazon Prime Members Save Money at Whole Foods Market