// return the "true" strength of a territory including incoming transfers private int adjustedStrength(Country c, int attackBias) { int strength = c.getStrength(); int attackers = attackBias; int transfers = 0; foreach (Movement m in gScreen.movements) { if (m.dest == c) { if (m.origin.getOwner() == this) transfers++; else attackers++; } if (m.origin == c) attackers++; } // only count incoming transfers if there are more of them than outgoing transfers if (transfers >= attackers && transfers >= 0) { foreach (Movement m in gScreen.movements) { if (m.dest == c && m.origin.getOwner() == this) strength += m.origin.getStrength() - 1; } } return strength; }
private float defenseValue(Country c, Dictionary<Continent, float> myContinents) { float myStrength = adjustedStrength(c,0) - 1; float theirStrength = 0; float contValue; myContinents.TryGetValue(c.getContinent(), out contValue); foreach (Country n in c) { // enemy countries nearby make this a better target for a transfer if (n.getOwner() != this) { theirStrength += adjustedStrength(n, 0); } // if country borders a continent we control, give it some bonus if (n.getContinent() != c.getContinent()) { float otherVal; myContinents.TryGetValue(n.getContinent(), out otherVal); if (otherVal * 0.9 > contValue) { contValue = otherVal * 0.9f; } } } // value is ratio of their strength to ours (higher is more desirable target) float value = theirStrength / myStrength; // apply continent factors only to potential destinations if(value > 1) value = 1 + (value - 1) * contValue; // potential sorces become easier to steal from for low-value continents if (value < 1) value *= contValue; // if this country has no enemies, set value to negative its strength if (value == 0) value = -c.getStrength(); return value; }