Ceasar's Mind

Follow me: @Ceasar_Bautista

Posts Tagged ‘math

Balancing Forces

leave a comment »

Let me start this post with an email from my friend Vinh, as he explains the core concepts of force strength particularly well.

This formula relates n amount of Unit 1, and n amount of Unit 2. I call it the “N vs N” formula where N obviously stands for the amount units.

Basically I started with this formula:

H1*D1 = H2*D2

But what would happen if there are 2 of Unit 2? Lets call these two units “Force 2.”

Intuition would tell me to multiply the attributes of Unit 1 by 2, in order to balance the two forces. However, if we just plug in numbers we can see that this doesn’t work out. Force 2 will still have an edge.

We can demonstrate this with a scenario.

H1*D1 = H2*D2

H1 = 100 H2 = 50
D1 = 1 D2 = 2

Since there are 2 of Unit 2, we multiply H1 by 2 to balance it.

H1 = 200 D1 = 1

1 Unit of Force 2 will die in 50 seconds, during which time Force 2 will deal a total of 200 damage and kill Force 1 completely! Both forces do not kill each other at the same time and therefore they are not balanced.

Obviously there is a trick involved here. We have to derive a formula mathematically. Intuition fails us here.

For both forces to be balanced, they must kill each other at the same time. Given a set amount of time (T), both forces must deal the same amount of damage.

Now if we set T equal to the time the unit is alive, which is his HP divided by the enemy’s damage and arbitrarily balance against an enemy whose damage is equal to 1 we can get a unit’s net damage.

D1 * T = D1 * (H1/1) = D1 * H1 = Net Damage

We can conclude that in order to be balanced, both forces must deal the same amount of Net Damage.

Force 2 has 2 Units, and therefore the total time the whole Force is alive is modeled differently.

1 Unit in the Force 2 will eventually die, within the time that he is alive the whole of Force 2 does 2 times his damage (since there are 2 units).

So, 2*(D2*H2) = Net Damage. However, this is not the whole story, since there is still one more unit alive. The damage that the solo unit does when he is alive also contributes to the Net Damage, therefore we must add his damage to the formula.

2*(D2*H2) + (D2*H2) = Net Damage.

Now we set the Net Damage of Unit 1 and 2 equal to get

H1*D1 = 2*(D2*H2) + (D2*H2).

I’ll shorten this letter by letting you clarify this with your own scenario.

Using mathematically induction I can prove this to be true if Force 2 is comprised of 3 units (And Force 1 still has 1 Unit).

H1*D1 = 3*(H2*D2) + 2*(H2*D2) + (H2*D2) (I can add the terms together)
H1*D1 = 6*(H2*D2)

Now what if it was a 2 vs 3 situation?

Using the pattern that I found, this would be my guess

2*(H1*D1) + (H1*D1) = 3(H2*D2) + 2*(H2*D2) + (H2*D2)
3*(H1*D1) = 6*(H2*D2)

Once again, I’ll leave you to make a scenario to clarify this formula. It should work out.

Take note that the amount of Units in both Forces is a relative term. It isn’t really the “amount” of units, its actually the ratio between their cost.

For 1 v 1 scenario, both Units cost the same amount. For 1 v 2, Unit 2 cost half as much as Unit 1. For 1 v 3, Unit 2 cost a third as much as Unit 1, etc. . .

So in fact, a 2 v 2, or a 3 v 3 scenario is modeled by the same formula as a 1 v 1 scenario, since their ratios will reduce to 1 : 1.

-Vinh

As we can see, the strength of a force grows exponentially with each additional unit. (Assuming units take up no space and don’t overkill their targets.) We can conclude then that a unit that costs twice as much as another unit should be exponentially more powerful. (The particular function for determining the strength of a unit given is price is given by the triangular numbers. Equally, the triangular numbers model the strength of a homogeneous force as it increases in size.)

If we multiply a force’s strength by the raw strength of any unit in the force we can find the true strength of a force. I arbitrarily chose to call this value K. K is a useful concept because it allows us to determine the prices of units by simply solving the equation on the right for x, which represents the number of units in the force. Since the number of units is directly proportional to the price, simply divide another constant arbitrary value by x in order to obtain prices.

From actually putting this formula to use, I’ve found a few problems. First off, it’s very difficult to be precise. Not much of a problem, but a problem nonetheless. Secondly, the formula is strictly for pricing units in respect to combat. Since many attributes have utility along other dimensions, movement speed for example, the pricing is not exactly accurate. Finally, as mentioned before, collision size is not accounted for either. Theoretically, collision size should be directly proportional to cost, with larger units being bigger, but as that’s not always the case it can really break the numbers sometimes.

Nevertheless, the formula should be a decent start for any designer.

Written by Ceasar Bautista

2010/06/17 at 13:21

1v1 Combat

leave a comment »

At the lowest level of the RTS, units have to be balanced against other units. Typically this is achieved by first guessing approximate values for a unit and then play-testing extensively until the unit no longer breaks the game. Play-testing anything enough should always return acceptable results.
However, there is undoubtedly a math to it all. Some laws of RTS nature. They are not at all simple however, and it’s probably impractical to figure them out, but it’s kind of fun and in certain ways useful.

Anyway, the first thing I looked at was how to balance one unit against another. To do so, I imagined a two-dimensional world that was completely empty of everything except the two units to be balanced, placed apart so that neither could immediately strike the other. From there, the idea was that if both units could kill each other at the same time, the two were balanced.

I examined only four basic attributes to start: Damage per second, Hit Points, Range, and Movement Speed. To start, I considered basic scenarios. For example, imagine the following two units:

Unit A Unit B
Hit Points 10 X
Damage 1 1
Range 10 0
Speed 0 2
What value of X will work to make things fair? Well, since Unit A has more range than Unit B, Unit B will be doing the running and with two speed it will take 5 seconds. During each of those seconds, he will take 1 damage from A, for a total of 5 damage. Then B will proceed to strike A, and with A’s 10 HP and B’s 1 Damage, it will take 10 seconds for B to kill A, during which time B will take another 10 Damage. So we add the two together and see B will take a total of 15 Damage. B should therefore have 15 HP to be balanced against A.

Furthermore, we can say that if A is balanced against B, and B is balanced against C, then A is balanced against C, even if A and C were not to kill each other at the same time. This is important because speed provides an advantage only if the unit has less range than the enemy.

Using the transitive property, the easiest way to balance units is to pit them against the Universal Unit (UU). The UU has 1 damage, 1 speed, 0 range, and infinite HP.

A general formula can be constructed, where Unit 1 has longer range than Unit 2:
(R1-R2)/S2*D1+H1/D2*D1=H2
OR:
(R1-R2)/S2+H1/D2=H2/D1

Personally, I find that a bit confusing. And worse, it doesn’t fully cover everything since there is no mention of S1. The formula is incomplete and had me confused for a very long time.

The solution came as an epiphany when I was looking stats of units had I generated that were “fair.” As such, there is very little evidence besides the idea being evidence for itself. But it does in many ways make sense. So instead of that other formula, it turns out that balance can be simplified as such:

(H1+R1)*(D1+S1)=(H2+R2)+(D2+S2)=…=K

K represents an arbitrary value of the designers choice and effectively, the value of the unit (and so the price).

This formula seems to make intuitive sense. Units with high range do well with high damage, but not so well with high HP. In fact, for the most part, such a unit would plainly suck. Likewise, a unit with high damage and high speed but low HP and low Range would also suck. It would never make it to it’s enemy alive. (Such units can be useful however. It’s just that in 1v1 they aren’t at all.) On the other hand, a unit with high HP and high damage though would be pretty solid.

Now, this formula only effectively explains 1v1 match-ups and doesn’t do a good job at all when it comes to mixed units or even just group combat. But it does give a pretty solid way of balancing units at the most basic level to start.

Countering
So, we know that (H+R)*(D+S)=K, but that doesn’t exactly tell us how to counter. Fortunately, it’s really rather simple.

The basic idea is to nullify the opponent’s strength. If an enemy unit is fast, render its speed useless by attacking it with tough units that possesses little range. If an enemy unit has excessively powerful attacks, swarm it with expendable units so as to waste the enemy’s strength. If a unit has excessive hit points, employ units that deal heavy damage in short bursts so as  to minimize overkill. And finally, if an enemy unit long range, attack  it with a unit that moves quickly to make full use of the speed.

This seems to be intuitive, but a player may easily miss the fact that if units are properly balanced, then these match-ups must be in your favor- the numbers force it to be so.

Written by Ceasar Bautista

2010/06/16 at 21:14

Posted in Uncategorized

Tagged with , , , ,

The Power of Speed

leave a comment »

Speed is perhaps the single most valuable attribute a unit can have. While it’s not particularly useful without some power to back it up, speed can be nasty when utilized by an intelligent player.

Basics

At the most basic level, speed has some very direct power to it. In the picture above, let’s assume that Blue’s units move faster than Red’s and that both units are equally powerful and subsequently obliterate each other when they meet. For the most part, Blue’s speed does nothing for him except move the location of the front line. If Blue is twice as fast, he’ll control twice as much of the line. Alone, this is not particularly useful. However, in one dimensional space one there is one advantage still: For every additional unit you have, the front line will be pushed back  a certain distance proportional to your speed and the rate of general production. Effectively, each units gives you the percentage of all speed controlled (your unit speed / (your unit speed + opponent’s unit speed)) multiplied by the distance between your opponent’s units. Some implications:

  • There’s a certain strength in slow units in that the distance between allied units is relatively short, making it more difficult for an opponent to gain space. Fast units however initially control more space and capture space quicker.
  • Effectively, this means that the less quick production is, the more important each individual unit becomes. This is rather obvious when production is slowed down to an extreme, to a point where a single extra unit could travel unopposed to the enemy base.

In isolation, this is not particularly useful. But when combined with multiple control points it’s really extremely powerful.

Batteries

The real strength of speed is made apparent when batteries are available or can be formed. In the picture to the right, Blue will be able to strike Red’s left node and defeat him before the right node can move in to suppress Blue’s advantage.

The real beauty here though is that each node connected through allied nodes can always trade space in order to reinforce another node. The slower your opponent is or otherwise the more distance between you two, the more resources can be directed elsewhere. And by temporarily redistributing resources, a player can conceivably strengthen a particular node enough to knock out an enemy one, and subsequently use the extra production to win the game.

More to come…

Written by Ceasar Bautista

2010/06/07 at 23:51

Distance is Money

leave a comment »

Consider this thought:

At the start of the game, the most aggressive option your opponent has before him is to immediately start streaming units. The stream, however, takes time to arrive. When it does arrive, you can simply stop moving units from the point of attack and simply match his stream. What’s important though is what happens in the meantime: any resources generated are free to be spent as you please. (Furthermore, your opponent, in producing units to attack, does not collect any free resources, or otherwise does so after he stops streaming.)

The implications are rather important. Effectively, whether or not a player can expand to uncontested points is based entirely on whether or not he has enough free resources to pay the price. Or more simply, in maps where the bases are closer, more resources have to be spent on directly fighting the opponent, while in maps where the bases are farther apart, players are more free to use their resources for other means (such as research, upgrades, or expansions).

Cutting the Distance

This central idea also means that when a buffer is destroyed, a bunch of resources that were free instantly become locked up, since the “distance” is now shorter. It now takes less time to get through the buffer since the stream can move through unopposed. This locks up units on both sides, which can be absolutely devastating if your opponent is not prepared. (Think, proxying.)

Consider the StarCraft 2 map Scrapyards. In the center, there are breakable rocks that otherwise obstruct ground movement. Upon their destruction, a player who has recently expanded could be utterly destroyed, while in general, the cost of expansion will be much higher for both players.

 

Air Units

Since air unit’s don’t deal with any physical obstruction, the distance between them and the opponent is significantly shorter. Make sure to invest in defenses as appropriate!

 

Mobile Factories

sandtrap-1.jpg image by YakZSmelk

In games with mobile factories, for example Halo 3’s Sandtrap (the one with the Elephants), this means that the freedom of units can be adjusted by adjusting the distance. For those of you unfamiliar with Halo 3, Sandtrap is a unique map where players can drive around Elephants, slowing moving, indestructible bases, which house the Flag objects for Capture the Flag, and influence where players spawn. If for example, the Elephants are driven near each other, then both teams will be constricted to fighting rather directly. On the other hand, if the Elephants are kept at a distance, then players are more free to search for vehicles and weapons.

Written by Ceasar Bautista

2010/05/12 at 00:04