• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 13:44
CEST 19:44
KST 02:44
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Voting9[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
BSL Team A vs Koreans - Sat-Sun 16:00 CET4Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)80Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition32
StarCraft 2
General
Stellar Fest: StarCraft II returns to Canada The New Patch Killed Mech! herO Talks: Poor Performance at EWC and more... TL.net Map Contest #21: Voting Revisiting the game after10 years and wow it's bad
Tourneys
$1,200 WardiTV October (Oct 21st-31st) WardiTV Mondays RSL Offline Finals Dates + Ticket Sales! SC4ALL $6,000 Open LAN in Philadelphia Crank Gathers Season 2: SC II Pro Teams
Strategy
Custom Maps
External Content
Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More
Brood War
General
BW General Discussion BSL Team A vs Koreans - Sat-Sun 16:00 CET Question regarding recent ASL Bisu vs Larva game [Interview] Grrrr... 2024 Pros React To: BarrackS + FlaSh Coaching vs SnOw
Tourneys
[ASL20] Semifinal B SC4ALL $1,500 Open Bracket LAN [Megathread] Daily Proleagues [ASL20] Semifinal A
Strategy
BW - ajfirecracker Strategy & Training Relatively freeroll strategies Current Meta Siegecraft - a new perspective
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Path of Exile Nintendo Switch Thread ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
SPIRED by.ASL Mafia {211640} TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Series you have seen recently... Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The Heroism of Pepe the Fro…
Peanutsc
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1669 users

Towards a good SC bot - P2 - Expanding (1/2)

Blogs > imp42
Post a Reply
imp42
Profile Blog Joined November 2010
398 Posts
Last Edited: 2016-09-23 17:36:31
September 22 2016 20:22 GMT
#1
Towards a good StarCraft bot - Part 2 - "Expanding (1/2)"

Summary:
+ Show Spoiler +

The earliest possible time to expand is calculated as an intermediate step.

A more precise calculation of the mineral rate r_n for n SCVs at a base location is given.

Then the optimal expansion timing is calculated, based on a given income goal. The actual example uses the income goal "max. minerals long-term (large time t)", which gives a somewhat trivial result. But the calculation holds for actually interesting applications with real income goals. It can be extended to account for delays because of enemy intervention.



“When is the right time to expand?”

The answer to this question depends on our army goal. We can state such a goal as “army composition at time t”. At the moment, we are not concerned with what constitutes a good army goal. Let’s just assume some higher-level decision maker tells us: “I want composition x by time t!” and we are in charge of gathering the necessary resources.

Side note: The price of an army depends on how early it needs to be ready:+ Show Spoiler +
It is noteworthy that the price of an army composition depends on t. This is because lower t requires more parallel production. Parallel production requires additional buildings, which have a cost. I will dedicate a separate post to answer the question “what is the cost of army composition x at time t?”. Here, we consider this question answered and therefore arrive at a simple requirement to produce a certain income by time t, described as Income_t = (minerals, gas)


The following graph illustrates the problem using cc@6 vs 1-base as an example. The yellow and grey curve indicate total minerals mined while the green and blue curve show the net income = total income – expenditure (cost of produced SCVs, depots, command centers).

[image loading]

The nature of the income curve for one base (gross: grey and net: dark blue) has been examined in a previous post. We only have to consider expanding if the requirement “Income_t” cannot be satisfied on one base. In the above example, this is the case for any income requirements above the blue line. In the above graph, the breakeven of cc@6 compared to 1-base is achieved at the 12400 frame mark. So the question becomes: “at what earliest time is the combined income curve of main and natural higher than the income curve of the main alone?” (gross: intersection of grey and yellow, net: intersection of blue and green).

The answer lies somewhere between the earliest possible expansion and never expanding.

When is the earliest possible time one can expand?

A simple answer would be “by the earliest time we can gather the 400 minerals required to build a command center”. This can be calculated easily with the formula from the previous post and turns out to be @6 supply. So the build order would be “SCV, SCV, CC”.

However, more optimized builds will have an SCV ready at the construction site exactly by the time they hit 400 minerals. This makes things a little more complicated. In particular, we have to account for the distance to the construction site at the natural and the lost mining time during travel.

[image loading]

Let’s say we have n SCVs mining at rate r_n each. If we pull an SCV off to send to the construction site, by the time it arrives the remaining n-1 will have gathered (n-1)*(travel time) * r_n-1 minerals. Note that the rate is not the same (r_n != r_n-1) because efficiency decreases with increasing number of SCVs.

Let d be the distance between the main command center and the construction site at the natural (In a real implementation we would probably want to use the SCV closest to the construction site, so d might vary…).

Travel time t_travel = d / V_scv with max(V_scv) = 4.92

A note on SCV speed:+ Show Spoiler +
4.92 is the top speed, but SCVs accelerate, slow down, and lose time when turning. Some empirically measured average should be used or mathematically account for start, stop, and at least two turns.


Let t(y) be the time we have gathered y minerals and choose y such that:

y + (mining during travel) = y + (n-1)( t_travel)r_n-1 = 400.
y = 400 – (n-1)( t_travel)r_n-1 (=the amount of minerals we want before sending SCV to expand)
y = f(t, n) (f being the function for income over time and SCVs from the previous post)

we want to solve f(t, n) = 400 – (n-1)(t_travel)r_n-1

A note on "r" (previously only approximated by a simple function):+ Show Spoiler +

[image loading]
Let’s examine some cases:
a) 1 SCV, m = 2, d(p1) = 2*180, d(p2) = 2*230:
t(p1) = 73 frames, saturation(p1) = 1.91, as(p1) = 1, rate(p1) = 1*8 / (73+80) = 0.052 minerals / frame
t(p2) = 93 frames, saturation(p2) = 2.16, as(p2) = 1, rate(p2) = 1*8 / (93+80) = 0.046 minerals / frame
the SCV would mine from patch p1

b) 2 SCVs
assigned(p1) = 2, rate changes to rate(p1) = 1*8 / (80) = 0.1 minerals / frame because assigned(p1) > saturation(p1)
t(p2) remains the same

the second SCV would also mine from patch p1 even though it has to wait for a bit before the mineral patch becomes available. Because: efficiency(p1) = 0.05 while efficiency(p2) = 0.046

c) 3 SCVs
efficiency(p1) changes to 0.034
t(p2) remains the same

the third SCV would mine from patch p2 because efficiency 0.046 > 0.034
and so on…



Let us have a look at expanding @4, @5, @6, @7, assuming 400 frames of travel time (measured on 9 o’clock Lost Temple, where t_travel = 400 frames):

[image loading]

Note: The higher “r” at column “5” denotes the mining rate of the 5 SCVs to accumulate 320+50 total minerals (50 minerals were spent on the 5th SCV). The lower “r” denotes the mining rate of the remaining 4 SCVs while one of the 5 was sent to construct the natural.
As can be seen in the table, the earliest possible time to expand, given a travel time to the natural of about 400 frames, is at frame 2054. Unfortunately, this comes at the very high cost of interrupting SCV production for 2054 – (2*300) + 215 = 1669 frames (we stopped at frame 600 and can resume only after having gathered another 50 minerals after command center construction has started, which takes approximately 215 frames given the rate of the remaining 5 workers mining). This is equal to sacrificing about 5.5 SCVs.

What are the total opportunity costs of a natural?

The true cost of expanding to the natural is: cost of command center + lost mining during travel and construction. Lost mining = (400 + 1800) frames at rate 0.045 = 98 minerals. Therefore: 498 minerals.
Furthermore, depending on when the command center is constructed, SCV production at the main is interrupted. We can therefore model the opportunity cost of a command center over time as:

op_cost(Command Center at t) = (mineral cost + lost mining cost) + interruptedScvProduction(t)

What is the benefit of having a natural?

There are two benefits: maximum speed of SCV production is doubled and the mining rate “r” is increased. For example, 30 SCVs in the main can mine about 0.71 minerals / frame. A 15/15 split between main and natural can yield about 2 * 0.65 = 1.3 minerals / frame. Splitting 15/15 comes at a cost of sending 15 SCVs to the natural, which equals to 15*400 frames of lost mining at a rate of r_30 - r_15. Therefore: 6000 * (0.71-0.65) = 360 minerals, which are recuperated within 360/(2*r_15 - r_30) = 610 frames after transfer.

More generally: Splitting n workers into j + k brings a benefit of:
Benefit(splitting into j+k at time t) = t * (r_j + r_k_nat) – t * (r_n) - t_travel * k * (r_n – r_j)
achieving the break even at: t = t_travel * k * (r_n – r_j) / (r_j + r_k_nat - r_n)

Nicer formatting:
+ Show Spoiler +

[image loading]

Note that r_k_nat != r_k_main because r depends on the number and distances of the mineral patches.

It is “comparatively” easy to calculate optimal j and k, given t. If there is no further SCV production and t is infinite, then we can just pick j and k such that (r_j + r_k_nat) is maximized. If we continue to pump out SCVs at both command centers, then we have to account for the fact that we reach max saturation earlier. That is, the advantage diminishes over time due to diminishing rate of return per SCV and reaches 0 once the natural would have reached max saturation without the SCV split.

For practical purposes maximizing (r_j + r_k_nat) should be sufficient, maybe accounting for the fact that we might pull of workers for gas or to construct buildings in the main in the near future.
A quick note on the additional SCV production: a natural that is operational 300 frames earlier yields one additional SCV.

profit(Command Center at t) = benefitSplitting(t) + additionalScvProduction(t)

What is the optimal time to expand?

Simply put:
at the earliest time t such that profit(Command Center at t) > op_cost(Command Center at t)

Maybe it is worthwhile to briefly elaborate why the fastest possible expansion is not the optimal one. Firstly, benefitSplitting(t) is almost negligible when splitting 6 workers into 3 and 3. We’re talking about an advantage of 0.034 minerals / frame and a breakeven of 4200 frames to make up for the lost mining time during travel alone. But more importantly, if the additional SCV production does not make up for the sacrificed SCV production, then it is not worth it. That is, for every SCV sacrificed the command center should be constructed 300 frames earlier to make it profitable.

Let’s look at op_cost(Command Center at t) for SCV 6 through 13, this time calculated, not measured (11-13 SCVs have to produce a supply depot as well):
[image loading]

I marked two interesting cells yellow. For CC@11 for the first time we will have more than 400 minerals when arriving at the construction site, because the 11th SCV is the limiting factor. The other one: CC@13 is the earliest CC that does not interrupt SCV production anymore.

The curves for profit(Command Center at t) all look similar, except they are shifted to the right for higher t, therefore, no earlier build will ever be able to catch up on a later one, once behind. Hence, the important conclusion is the following: long-term, an earlier command center is only worth it, if it can produce more workers than a later command center. This the case for the first time @13. All earlier command centers are not able to make up for their delayed SCV production before a later command center also starts SCV production. For example: Let’s compare CC@9 and CC@10. CC@10 produces the first SCV after the CC at 2326 frames, which is 137 frames later than CC@9. However, CC@9 interrupts SCV production for 163 more frames than CC@10. So CC@9 will always be behind in SCV production and can never catch up to CC@10.

The final answer: The optimal time to expand on Lost Temple 9 o’clock position, given a large enough time horizon for return on investment, is at 13 supply. A quick cross check with http://wiki.teamliquid.net/starcraft2/CC_First shows that the optimal build for command center first is considered to be cc@14, which is in line with our calculation when accounting for the scouting probe, which is pulled off from mining.

Further expansions:
About further expansions beyond the just the natural: The 3rd expansion behaves in a similar way to the natural expansion. Except for practical purposes we don’t need the same level of detail. A very simple way to approach the problem, probably sufficient for all practical scenarios: Expand to a third if the given income requirement cannot be satisfied on two bases.

Quick refresher: Why do all the complicated calculations when you can just measure / ask a pro player?

The calculations replace expert knowledge and allow an AI to reason. Instead of hard-coding a cc-first build order with cc@13 (which is considered “expert knowledge”: some higher instance just knows it is optimal and tells us so) we can query our system to fulfill a given income requirement the fastest possible way for any map and any mineral patch distances. In a more extreme case, the system could easily deal with a situation where the cost for a command center is increased from 400 to 500 minerals.

Disclaimer:
I had to reformat formulas manually for the TL post format. There might be inconsistencies with the included images.
The calculation for "r" is more exact than the previous approximation, but it systematically calculates more income than measured empirically. This is most likely due to unpredictable SCV movement between main and mineral patch containing unnecessary turns (the measure was done with only 1 SCV in the test).
This means that the calculated earliest time frames may not actually be reached in a real game, nevertheless the calculations remain the same, even if coefficients in the algorithm for "r" will be adjusted in the future.

Limitations:
The empirical tests are naturally done only on one map and must be performed for every map, every location.
The calculation for "r" is much more precise than the previous approximation, but requires exact travel times for SCVs to each mineral patch. These travel times are very hard to calculate because of the somewhat unpredictable behavior of SCVs and the path they choose. As Shalashaska_123 suggested, it is probably better to measure travel time rather than calculating it. I did measure it for Lost Temple 9 o'clock main and natural.

Of course all of this is only accurate as long as there is no enemy intervening with our mining. If an incoming enemy harass is scouted, then we must formulate a very short-term goal to produce defending units. Only when successfully defended we can go back to formulate a more long-term goal and consider expanding. How to account for such delays will be the topic of a future post.

Credit:
Shalashaska_123 for good input on calculation of "r"
Liquipedia for the "CC first" BO





*****
50 pts Copper League
YokoKano
Profile Blog Joined July 2012
United States612 Posts
September 24 2016 10:28 GMT
#2
yea i think you are 100% correct handling the matter this way. if i could do anything of this nature, I'd probably run a bootstrap simulation of each LT position, aiming to run maybe 100 trials of each possible permutation of SCV distribution and then tweaking the algorithm with helpful micro like spam clicking. the short run result that 13-CC is superior to 14-CC is earthshattering to say the least. i think we all have at least one memorable rep where it seems that one player is mining faster than is usual at that position, whether it is depot placement, worker micro, or some kind of anomalous field. no matter how we try to emulate these properties in practice, they seem to escape our mastery. there is nothing to be done except robust trial tailored to results.
IQ 155.905638752
imp42
Profile Blog Joined November 2010
398 Posts
September 24 2016 19:58 GMT
#3
On September 24 2016 19:28 YokoKano wrote:
yea i think you are 100% correct handling the matter this way.

Thank you, I knew somebody would understand! :p


the short run result that 13-CC is superior to 14-CC is earthshattering to say the least.

You probably missed the part where I said that this was an example calculation (without considering a scouting SCV).

i think we all have at least one memorable rep where it seems that one player is mining faster than is usual at that position, whether it is depot placement, worker micro, or some kind of anomalous field.

Keep in mind that I have standardized worker micro. It is executed by a bot with a fixed algorithm. The only missing piece to a purely calculated prediction is the unpredictable roundtrip time for mining SCVs.

Keep also in mind that the purpose of the calculation is to support a BW bot in decision making. It is not meant for human players.
50 pts Copper League
Please log in or register to reply.
Live Events Refresh
Safe House 2
17:00
Round Robin
ZombieGrub402
TKL 148
CranKy Ducklings71
EnkiAlexander 32
3DClanTV 28
LiquipediaDiscussion
Online Event
14:00
Waterfall Cup #1
MindelVK74
BRAT_OK 50
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Clem_sc2 792
ZombieGrub402
TKL 148
MindelVK 74
BRAT_OK 50
Codebar 22
StarCraft: Brood War
Britney 46546
Calm 4431
Hyuk 3626
Rain 3513
Bisu 1673
Horang2 762
firebathero 311
Shuttle 250
Hyun 135
Backho 100
[ Show more ]
Dewaltoss 76
Barracks 75
Rock 37
soO 29
Sacsri 20
ZZZero.O 0
Dota 2
Gorgc7637
qojqva2278
LuMiX0
Heroes of the Storm
Liquid`Hasu420
Khaldor334
Other Games
B2W.Neo773
Beastyqt562
Skadoodle498
Mew2King157
KnowMe126
Liquid`VortiX94
ToD59
Trikslyr47
rGuardiaN23
fpsfer 1
Organizations
Other Games
gamesdonequick1436
BasetradeTV38
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 22 non-featured ]
StarCraft 2
• printf 27
• Adnapsc2 4
• IndyKCrew
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• LaughNgamezSOOP
• Kozan
StarCraft: Brood War
• Airneanach27
• blackmanpl 21
• Michael_bg 6
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2993
• Ler88
League of Legends
• Nemesis7043
• Jankos3931
• HappyZerGling137
Other Games
• imaqtpie1185
• Shiphtur234
Upcoming Events
Sparkling Tuna Cup
16h 16m
Safe House 2
23h 16m
Monday Night Weeklies
1d 22h
WardiTV Invitational
2 days
WardiTV Invitational
2 days
Tenacious Turtle Tussle
4 days
The PondCast
4 days
WardiTV Invitational
5 days
Online Event
5 days
RSL Revival
6 days
[ Show More ]
RSL Revival
6 days
WardiTV Invitational
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.