archived / shipped / access: artifacts

SC2 Streamer Companion & Win Chance Predictor

A playful SC2 stream companion that turned finished games into win-chance charts, opponent history, and occasionally physical feedback for supply blocks.

span
2023-2024
role
solo developer · streamer
audience

Context

I occasionally streamed my gaming sessions on Twitch and wanted to enhance the idle time between games in some fun way when there was no chat interaction. This project mostly served as tooling that could be used as a source in an OBS scene. The solution is generic: the predictor was used by four of my StarCraft peers, and the results tracker ended up being used by another streamer friend.

What I Built

I built a real-time companion tool for StarCraft II in Python, incorporating an ML model and an OCR solution. It watches the game's replay folder for new replays, which indicate that a match has finished, and processes each freshly concluded game in several ways. Its main components are:

  • Win-chance predictor — the highlight of the project. I used public tournament replays and parsed them to extract time-series data based on snapshots of the in-game situation taken roughly every eight seconds. The features were mostly economic and military statistics for each player. I trained an RNN on these data as a win/loss predictor. After a match concludes, it draws an estimated win-chance chart to provide a better overview of which passages of the game were crucial.
  • Results tracker — player metadata and match results are stored in a local SQLite database, creating a persistent, searchable match history. This provides fun stream information about the head-to-head score in past matches, average game length, how often the opponent wrote "glhf" at the start and "gg" at the end, and so on. It also tracks the names used on each account. Since players frequently change their in-game names, this helps establish whether the user has encountered the player before under different alias.
  • PiShock integration — an experimental way to train one aspect of the game that I tend to struggle with. OCR scanned a specific region of the game screen containing the supply counter and parsed the displayed numbers. The bad play I wanted to correct was allowing used supply to reach or exceed supply capacity; players usually build additional supply structures preemptively to avoid this problem. When the OCR detected that I had remained supply-blocked, it triggered a remote PiShock device that delivered an electrical stimulus as feedback for my mistake.

Interesting Problems

  • Validating the win-chance predictor — It was quite difficult to evaluate whether the estimated win chance was realistic at any given moment. At the end of a match, it is usually easy to see that one side is almost certain to win (players rarely leave a game they still have a chance to come back in), but the middle is muddy. I discussed the results with a few pro players and several semi-pro friends. I mainly asked, "Does the line look realistic?" and "What were the turning points in the game for you?" Seven out of ten cases were judged realistic enough, with high agreement between reviewers. The turning points identified in informal discussions also mapped well to dips in the line. Essentially all human-identified turning points were visible, although some additional movement could not be explained by those turning points alone. The charts rated as unrealistic did not map well to the identified turning points.
  • Identifying bad supply states — there are cases in which being at full supply is actually the correct play, or in which a supply block is a forced error. Such cases should not trigger the bad-play feedback, so I added heuristics to blunt these edge cases. In particular, I ignored the first two minutes of each game because I frequently chose an opening build that deliberately entered a supply-blocked state for a small economic advantage. This also meant that the in-game clock had to be tracked through the game API.
  • ML model validity on different patches — game patches were usually quite small while the project was active, without any major overhauls. However, SC2 recently received a patch that made major changes to the economy and the starting conditions. Intuitively, this would affect the model's quality if it were applied to current game replays.

Related projects

  • RTS Data Manager — a project collecting various RTS game data

  • SC2 Enemy Info — another companion tool that tracks user notes for players encountered on the ladder