• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 18:56
CET 00:56
KST 08:56
  • 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
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge1[TLMC] Fall/Winter 2025 Ladder Map Rotation13Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge [TLMC] Fall/Winter 2025 Ladder Map Rotation Mech is the composition that needs teleportation t RSL Season 3 - RO16 Groups C & D Preview
Tourneys
2025 RSL Offline Finals Dates + Ticket Sales! $5,000+ WardiTV 2025 Championship RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review BW General Discussion
Tourneys
[BSL21] GosuLeague T1 Ro16 - Tue & Thu 22:00 CET [Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET
Strategy
Current Meta How to stay on top of macro? PvZ map balance Simple Questions, Simple Answers
Other Games
General Games
Clair Obscur - Expedition 33 Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games? Path of Exile Nintendo Switch Thread
Dota 2
Official 'what is Dota anymore' discussion
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread The Games Industry And ATVI Things Aren’t Peaceful in Palestine About SC2SEA.COM
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 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
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2246 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
Replay Cast
23:00
WardiTV Mondays #60
CranKy Ducklings80
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft398
SteadfastSC 91
StarCraft: Brood War
UpATreeSC 96
NaDa 27
yabsab 7
Dota 2
NeuroSwarm25
Super Smash Bros
PPMD37
Other Games
Grubby5078
shahzam528
Maynarde204
C9.Mang0163
ToD72
Trikslyr36
Organizations
Other Games
gamesdonequick19
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 21 non-featured ]
StarCraft 2
• kabyraGe 146
• Hupsaiya 58
• poizon28 18
• IndyKCrew
• sooper7s
• Migwel
• AfreecaTV YouTube
• LaughNgamezSOOP
• intothetv
• Kozan
StarCraft: Brood War
• HerbMon 39
• Azhi_Dahaki26
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2957
League of Legends
• Doublelift2864
Other Games
• imaqtpie1261
• Scarra482
• WagamamaTV340
• Shiphtur261
Upcoming Events
ChoboTeamLeague
1h 4m
WardiTV Korean Royale
12h 4m
BSL: GosuLeague
21h 4m
PiGosaur Cup
1d 1h
The PondCast
1d 10h
Replay Cast
1d 23h
RSL Revival
2 days
herO vs Zoun
Classic vs Reynor
Maru vs SHIN
MaxPax vs TriGGeR
BSL: GosuLeague
2 days
RSL Revival
3 days
WardiTV Korean Royale
3 days
[ Show More ]
RSL Revival
4 days
WardiTV Korean Royale
4 days
IPSL
4 days
Julia vs Artosis
JDConan vs DragOn
RSL Revival
5 days
Wardi Open
5 days
IPSL
5 days
StRyKeR vs OldBoy
Sziky vs Tarson
Replay Cast
5 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 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.