• Log InLog In
  • Register
Liquid`
TeamLiquid Liquipedia LiquidDota LiquidLegends
EST 22:50
CET 04:50
KST 12:50
  • 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
Super Tournament 1 - RO16 Day 1 Preview (2021)8BSL - Season 1121Trap wins DreamHack: Last Chance 202118DH Last Chance: RO16 Group C Preview8[ASTL2] Power Rank28
Community News
Blizzard Team 1 (SC:R/SC2 Devs) was dissolved/restructured in October101$9,000 WardiTV 2021 - Jan 23-Feb 733Cheeseadelphia Winter Championship $10K Tournament - Jan 23-2451IEM Katowice 2021 to be held online, prize money redistributed61Super Tournament 1 (2021) bracket40
StarCraft 2
General
Super Tournament 1 - RO16 Day 1 Preview (2021) New ladder maps for first season of 2021 ? Super Tournament 1 (2021) bracket Blizzard Team 1 (SC:R/SC2 Devs) was dissolved/restructured in October Trap wins DreamHack: Last Chance 2021
Tourneys
[GSL 2021] Super Tournament 1 - Day 1 The Three-Winged Angel 2021 NA Apprentice Cheeseadelphia Winter Championship $10K Tournament - Jan 23-24 ITaX Trovo Weekly#20 TIME, Rogue, Creator & Patien
Strategy
Select Larvae + Morph unit Rapidfire 4gate robo stalker all in vs T [G] PvZ Cheese: PartinG's "Adios Amigo" Build HuShang Tutorials
Custom Maps
Re-created map Ghost Tower Re-created map Wasteland [Q] BO Practice Custom Map
External Content
Sponsoring a Bo7 between 2 pros of your choice Mutation #249 Dark Ritual Mutation #248 Boom Town New edition of the Dank Templars SC2 newsletter!
Brood War
General
SC:R bunker command? [StarCastTV] Update Thread Blizzard Classic Games "quietly dismantled" Battle for Aiur: Bonyth vs Dewalt FlaSh on Arm Surgery, Sacrifices & Naivety
Tourneys
[ASTL2] Week 2 Day 2 tQ show match tournament - match/add to my funding [BSL10] Gosu League [BWCL] Season 52 - Main Page
Strategy
Zerg: Lurkers Vs Vessels FlaSh's TvP Gas FE into 3 Tank Pressure [subbed] What is this new pvt style with no arbiters? PvP Bonyth style 2 gate 3 zealot 21 gas guide
Other Games
Heroes of the Storm
Hots Newbie here HotS: WP and Funny Moments [HotS] NA Stands Supreme
General Games
Sid Meier's Civilization VI Path of Exile Genshin Impact - Coop RPG Final Fantasy XIV Final Fantasy I・II・III Fanmade Remake
TL Mafia
[M][N] Mafia Mafia: Mafia Edition [M][N] I'm a cop you idiot! - Round 4 [M][T] Personality Mafia: Mini Edition Active List of Mafia Games 2.0 TL Mafia Plays: Diplomacy
Hearthstone
Is Hearthstone Gambling?
LoL General
LoL Tournaments
LoL Strategy
Community
General
US Politics Mega-thread Coronavirus and You Trading/Investing Thread Ask and answer stupid questions here! The Games Industry And ATVI
Fan Clubs
The Scarlett Fan Club The TY Fan Club INnoVation Fan Club
Media & Entertainment
Anime Discussion Thread Korean Music Discussion [Movie] Legendary Picture's Godzilla (2014) [SCIFI Series] The Expanse Dragon Ball Super Discussion
Sports
2020 - 2021 Football Thread 2020 NFL and College Football Corona Season NBA Season 2019-2020 NHL 19-20: Hop Off my Kakko UFC/MMA Discussion Thread
Tech Support
Mac Mouse woes be gone! Locked out of Blizzard Account Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Ask TL Staff Anything Recent Gifted Posts
Blogs
Game Programming with SFM…
ChristianS
My profession - Being A S…
jameswatts
GSL 2010 Season 1: A L…
TheRealNanMan
hazelynut's "3+1 = 4 pool"…
hazelynut
My fourth semester of colle…
DeNikSSB
TrapGod
EheroSC2
How Do We Improve Su…
waywardstrategy
My iPhone game
GroT
Customize Sidebar...

Website Feedback

Closed Threads



Active: 882 users

Towards a good SC bot - P56 - Latency

Blogs > imp42
Post a Reply
imp42
Profile Blog Joined November 2010
398 Posts
March 07 2017 17:32 GMT
#1
Towards a good StarCraft bot - Part 6 - "Latency in Brood War"

Summary:
+ Show Spoiler +
Introduction into latency considerations and one example how to apply it in a micro situation.


When programming a bot sooner or later you will deal with latency. And more likely than not you will experience a couple of surprises the first time you play against other bots over a network.
This posts intends to save you some frustration and shed some light on the internal workings of Brood War.

Let’s start with some definitions to create a common vocabulary for discussion.

Latency Frames (constant throughout the course of a game)

Latency in Brood War is the maximum delay between the frame a command gets issued and the frame that command gets executed. Latency Frames define the maximum delay in terms of number of frames.

Turn (constant throughout the course of a game)

A turn is a set of sequential frames, which are bundled together such that commands issued in any of those frames are executed together. If a turn consists of 3 frames, then any commands issued in frame 1 and 2 will be executed together with commands issued in frame 3.

Turn Size

The number of frames per turn

BWAPI Remaining Latency Frames (variable per frame)

Remaining latency frames indicate the actual delay until an issued command is executed (as opposed to the maximum delay). Since commands from the same turn are executed together, this delay varies depending on when during the turn the command was issued. If a command is issued during the first frame of a turn, then Remaining Latency Frames will be equal to Latency Frames. That is, the actual delay will be equal to the maximum delay.

BWAPI latency compensation (default: enabled)

BWAPI has a functionality to simulate status changes as soon as a command is issued rather than when it is executed. This includes order, target position and a bunch of stats like isIdle, etc. The drawback being the information is not actually correct. So there might be just as many cases where latency compensation backfires and does hurt more than it helps. Imagine an SCV constructing a building and you tell it to stop. With latency compensation enabled it will immediately show as isIdle. But relying on the unit to be idle may result in an error since actually the unit is still constructing. The general recommendation is therefore to disable latency compensation.

Example: latency frames = 6, turn size = 2

Frame 0: issue unit1.attack(). Remaining latency frames: 6
Frame 1: issue unit2.attack(). Remaining latency frames: 5
Frame 2: do nothing. Remaining latency frames: 6
Frame 3: do nothing. Remaining latency frames: 5
Frame 4: do nothing. Remaining latency frames: 6
Frame 5: do nothing. Remaining latency frames: 5
Frame 6: execute unit1.attack(), execute unit2.attack()

How do you detect the latency settings?

Latency Frames and Remaining Latency Frames can be queried via BWAPI. To detect the turn size you need to calculate how many frames it takes until Remaining Latency Frames equals Latency Frames.

Application

Consider the scenario where a marine runs into a group of hostile units. The image below shows the exact moment a teal marine detected it is outnumbered and turned around to run away. The circles show the attack range (weapon max range) of the respective units.
As you can see, the teal marine is well within the attack range of the closer red marine and will therefore take hits.
[image loading]

Two factors are responsible:

1. If the teal marine issues a move command to run away the exact moment it spots enemy units within their weapon range the command will only be executed <remaining latency frames> later.
2. Furthermore, the teal marine will require a couple of frames to turn around (between 4 and 5 in this case)

So how do we make sure we run away in time?

We could of course just run away as soon as enemies are in sight range. But this will result in a very conservative behavior with many missed opportunities to get your own shots off.
Instead, we account for latency and frames required to turn as follows:

If (distance between enemy position and my position <= enemy weapon range) then run away

Becomes

If (distance between enemy position in <remaining latency frames + turn frames> frames into the future and my position <remaining latency frames> frames into the future <= enemy weapon range) then run away.

Ok, but where will each unit be x frames into the future?

For your own units you can just extrapolate along the current path.
For enemy units, there are two main approaches:
- Either assume they are walking directly towards you (conservative case)
- Or assume they continue their current direction at their current speed

The image below shows a scenario where the green marine accounts for 6 latency frames and 4 frames to turn. It therefore calculates the distance between where the teal marines will be 10 frames into the future and itself 6 frames into the future (since it turns on the spot).
[image loading]

The result is a very precise micro, where the green marine will remain just outside of enemy weapon range.

Disclaimer:
A word of warning: escaping is considerably harder than attacking. You need to avoid getting cornered and may have to take unexpected turns, allowing the enemy to catch up. It might be a good idea to introduce some safety margin to account for this.

Credits:
Thanks tscmoo for proof-reading
RadicalZephyr explained turns and latency well at https://github.com/RadicalZephyr/bwapi/wiki/Latency



*****
50 pts Copper League
Psyonic_Reaver
Profile Blog Joined June 2007
United States4042 Posts
March 11 2017 09:24 GMT
#2
Pretty soon we dont even need to play BW. It will play itself and there will finally be peace on earth.
So wait? I'm bad? =(
imp42
Profile Blog Joined November 2010
398 Posts
March 12 2017 02:53 GMT
#3
On March 11 2017 18:24 Psyonic_Reaver wrote:
Pretty soon we dont even need to play BW. It will play itself and there will finally be peace on earth.

it already plays itself 24/7 at https://www.twitch.tv/sscait
50 pts Copper League
Please log in or register to reply.
Live Events Refresh
OSC
02:00
Orca Cup Qualifiers
Liquipedia
The NA Apprentice
01:00
Code S Group A
BeoMulf8
LiquipediaDiscussion
Coach Pupil League
00:00
Match of the Week - WEEK 1-A
coachpupilleague30
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PartinGtheBigBoy 1001
ViBE335
NeuroSwarm 298
SpeCial 287
RuFF_SC2 181
Nina 138
CosmosSc2 107
Forgg! 91
PiLiPiLi 50
StarCraft: Brood War
Artosis1780
ToSsGirL 275
Super Smash Bros
C9.Mang02177
ChuDatz29
Other Games
summit1g30533
Day[9].tv2858
shahzam1946
WinterStarcraft324
nookyyy 177
HugS86110
kaitlyn100
Hui .86
Maynarde82
-ZergGirl59
Organizations
Counter-Strike: Global Offensive
ESL CS:GO2349
Other Games
BasetradeTV401
StarCraft 2
ESL.tv186
OGamingTV SC2 88
SC2 Vod Archives71
Blizzard YouTube
[ Show 21 non-featured ]
StarCraft 2
• SkrOs 145
• FEqualsMA 13
• D4rkn0ob1k 4
• RayReign 3
• hirohiro 1
• Genesis Gaming
• LaughNgamez Trovo
• AlphaB_SC2
• Migwel
• Matiz_pl
• Laughngamez YouTube
• IndyKCrew
• aXEnki
• Kozan
• intothetv
SC2: Legacy of the Void
• KarlJayG
• PSISTORM Gaming
StarCraft: Brood War
• HerbMon 20
• sscaitournament2
• AfreecaTV YouTube
Other Games
• TSM TheOddOne945
Upcoming Events
GSL Super Tournament
4h 10m
Trap vs Dark
INnoVation vs Solar
sOs vs ByuN
DongRaeGu vs Dream
OSC
5h 10m
ITaX Trovo Weekly
9h 10m
Patience vs TIME
Rogue vs Creator
The Three-Winged Angel
13h 10m
MaNa vs Bee
Lambo vs MarineLorD
MarineLorD vs MaNa
Krystianer vs Lambo
Lambo vs MaNa
Shinhan Tank Proleague
16h 10m
Coach Pupil League
20h 10m
The NA Apprentice
20h 10m
The Three-Winged Angel
1d 13h
WardiTV 2021
1d 13h
BWCL
1d 15h
[ Show More ]
The NA Apprentice
1d 21h
Shinhan Tank Proleague
2 days
The NA Apprentice
2 days
PSISTORM Gaming Misc
2 days
Showmatch
3 days
PSISTORM Gaming Misc
3 days
The Three-Winged Angel
3 days
OSC
3 days
BSL: Ladder Tournament
3 days
Battle for Aiur
3 days
Bonyth vs Dewalt
Student Starcraft AI To…
3 days
The NA Apprentice
3 days
AfreecaTV Starcraft Tea…
4 days
WardiTV 2021
4 days
Trap vs ByuN
Trap vs Solar
Solar vs MaxPax
ByuN vs MaxPax
Trap vs MaxPax
Creator vs MaxPax
ByuN vs Creator
Trap vs Creator
The Three-Winged Angel
4 days
Platinum Heroes Events
4 days
Student Starcraft AI To…
4 days
ESL Pro Tour
5 days
ESL Pro Tour
5 days
ESL Pro Tour
5 days
AfreecaTV Starcraft Tea…
6 days
OlimoLeague
6 days
Liquipedia Results

Completed

Polish Starcraft League 3
Cheeseadelphia Winter
MCC 2021 Qualifier 1
BLAST Premier Global Final

Ongoing

Ultimate Battle
Shinhan Tank Proleague S4
BWCL Season 52
ASTL Season 2
BW Jeez weekly GF 2020
WardiTV 2021
2021 AfreecaTV GSL Super Tournament 1
MCC 2021 Qualifiers
NGS Storm Division S2 Quals
NGS Storm Division S2 Qual. 4
ESEA S36 - NA Premier
ESEA S36 - EU Premier
ESEA S36 - AU Premier
cs_summit 7

Upcoming

Bombastic StarLeague 11
Rogue City Rumble
IEM Katowice 2021
Masters Clash Champ. 2021
NGS Storm Division S2 Qual. 7
NGS Storm Division S2 Qual. 6
NGS Storm Division S2 Qual. 5
MCC 2021 Qualifier 2
DH Masters Spring 2021
BLAST Premier Spring Showd.
ESL Pro League Season 13
IEM Katowice 2021
BLAST Premier Spring Groups
DreamHack Open Jan 2021
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 © 2021 TLnet. All Rights Reserved.