Getting Data From Running a Replay
After coming to the disappointing conclusion that statistics are not uploaded with BAR replays, I realized that I needed to come at this from a different direction in order to get everything I needed. I knew that the Spring engine calculates statistics during the running game (you can see this when running a replay and clicking the “statistics” button), so if I could figure a way to pull that out then we could have our solution. But doing this was not as easy as I had hoped (there are a lot of moving pieces).
In order to get these statistics out I know that we have to generate statistics into a file from headless mode (basically run only the simulation aspect of the game, not the graphics or anything extra). In the BAR engine folder lives an executable called spring-headless.txt
, so my hunch is that this is how you run a headless game (crazy I know!). To get this executable to actually run a headless game from a specific replay file I edited the <BAR install directory>/data/_script.txt
to point to the replay file located in <BAR install directory>/data/demos like this:
|
|
Then we can run the game using the following command:
|
|
This successfully runs the replay in headless mode! The only problem is it runs at normal game speed (or at least not super-duper fast game speed) and doesn’t actually generate any output.
Looking at the BAR engine source again I found an example Lua widget that edits the game speed during a headless game. As I looked around I found in a few places (like here) that widgets do not have to be consistent between users, therefore adding widgets to this rerun of the replay should not cause any desync issues, so I figured that all my future endeavors of headless and information gathering would be best served by creating widgets to hook into the game. By copying the following stripped-down and sped-up version of the BAR headless script into the data/engine/<BAR engine>/LuaUI/Widgets directory and re-running the earlier command I was able to run the replay at blistering speeds, which will be much better for generating data from lots of replays!
|
|
Now something about the GetInfo
data is very particular. I copy/pasted this from gui_build_eta.lua
so that it is basically spoofing an already existing widget, but even that is acting quite flaky. It will intermittently not be run in the replay, so then the replay takes a very long time and doesn’t give you any statistics. I’m guessing there is some sort of a whitelist somewhere in the engine just like with the AI’s, but I’m not sure. Either way, this makes it run well enough that I can ignore the replays that don’t cooperate.
Side note: Trying to find the right combination of directory, command, and Widget setup to get this to work properly was atrocious! I was throwing Widget directories all up and down the directory tree, renaming stuff left and right, and editing the crap out of the _script.txt
file. Fun times! Do not recommend! I’m sure there were others who are much smarter than me and had already figured all of this out, but I’m notorious for taking the long way around….
Other side note: In all of this searching I also found this forum post that notes you can edit your _script.txt
to also speed up a game or replay to be ridiculously fast using the following. I don’t know who might need this, but it is really fun trying to play the game at x2000 speed (in case you were wondering, I lost in about 5 real-time seconds).
|
|
With this running it was time to move on to actually getting statistics out of the replay run. Now I was starting to get my head wrapped around how BAR works internally, I knew I needed to find where these statistics come from:
My hunch was this is a widget, along with most everything else that is displayed on the screen during a BAR match. If I could find this file and the stats it generates, then I could pop those out into a file. Sure enough, I found the BAR statistics overlay widget source, and within it a series of commands that continuously pull frame, player, and statistics data to display them on the screen. I don’t really care much about the displaying, but by adding a few lines to our headless script I can generate a basic CSV file of the statistics data in the BAR data directory:
|
|
While doing this I figured it would probably also be useful to get the unit defs for the replay and unit counts for each player. I found some basic information in this widget and retrofitted it to also generate CSV’s for unitdefs and unit creation/destruction like this:
|
|
Now that this data is successfully generating, I hope to be able to actually train an AI, and to get that I’ll have to randomly download replays with all their dependencies. I’m still in the process of doing that, but once it’s together I’ll make a post all about it.