Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstracted Replay Data Parsers #119

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bffd088
added SetProcessDPIAware() to fix screen size issue for windows users
cole-maclean Nov 7, 2017
1a78352
abstarting parser class
cole-maclean Nov 9, 2017
3eb8869
replar parser abstracted, analog to agents abstraction
cole-maclean Nov 9, 2017
1bdf502
further abstraction of replay processing
cole-maclean Nov 9, 2017
d31a9e9
action stats scrapper fully abstracted into seperate class using base…
cole-maclean Nov 10, 2017
ad28d78
updated args to allow user inputter feature resolutions, same as play…
cole-maclean Nov 10, 2017
09e3274
added state scrapper example and ability to save to file
cole-maclean Nov 10, 2017
6c6caf4
updates as per @tewalds review
cole-maclean Nov 10, 2017
bf4ad86
remove local flags workaround
cole-maclean Nov 10, 2017
e642f72
trailing line
cole-maclean Nov 10, 2017
a25dff6
trailing line
cole-maclean Nov 10, 2017
5dd050b
renamed state parser to player_info_parser
cole-maclean Nov 10, 2017
6fa4d1e
added documentation for replay parsing
cole-maclean Nov 10, 2017
9969d86
remove state-parser example
cole-maclean Nov 10, 2017
b65ed0d
doc edits and typo fixes
cole-maclean Nov 10, 2017
677ec46
rename StateParser to PlayerInfoParser
cole-maclean Nov 10, 2017
e9e4924
updated replay_actions to process_replays and documentation references
cole-maclean Nov 12, 2017
9b62b47
fix typo
cole-maclean Nov 12, 2017
ea30f55
building out unit tests for replay parsing
cole-maclean Nov 17, 2017
be6cda9
refactored process_replays to have load_replays method for single rep…
cole-maclean Nov 17, 2017
c72f8a9
removed required flag for replays argument, default is string 'None' …
cole-maclean Nov 17, 2017
6aa04aa
added unit tests for replay parsing
cole-maclean Nov 17, 2017
14d732d
remove debug lines
cole-maclean Nov 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 51 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,6 @@ The left side is a basic rendering (which will likely be replaced by a proper
rendering some day). The right side is the feature layers that the agent
receives, with some coloring to make it more useful to us.

## Watch a replay

Running the random agent and playing as a human save a replay by default. You
can watch that replay by running:

```shell
$ python -m pysc2.bin.play --replay <path-to-replay>
```

This works for any replay as long as the map can be found by the game.

The same controls work as for playing the game, so `F4` to exit, `pgup`/`pgdn`
to control the speed, etc.

## List the maps

[Maps](docs/maps.md) need to be configured before they're known to the
Expand Down Expand Up @@ -190,11 +176,6 @@ configure your own, take a look [here](docs/maps.md).
A replay lets you review what happened during a game. You can see the actions
and observations that each player made as they played.

Blizzard is releasing a large number of anonymized 1v1 replays played on the
ladder. You can find instructions for how to get the
[replay files](https://github.com/Blizzard/s2client-proto#downloads) on their
site. You can also review your own replays.

Replays can be played back to get the observations and actions made during that
game. The observations are rendered at the resolution you request, so may differ
from what the human actually saw. Similarly the actions specify a point, which
Expand All @@ -203,6 +184,55 @@ match in our observations, though they should be fairly similar.

Replays are version dependent, so a 3.15 replay will fail in a 3.16 binary.

## Watch a replay

Running the random agent and playing as a human will save a replay by default. You
can watch that replay by running:

```shell
$ python -m pysc2.bin.play --replay <path-to-replay>
```

This works for any replay as long as the map can be found by the game.

The same controls work as for playing the game, so `F4` to exit, `pgup`/`pgdn`
to control the speed, etc.

You can visualize the replays with the full game, or with `pysc2.bin.play`.
Alternatively you can run `pysc2.bin.replay_actions` to process many replays
in parallel.
Alternatively you can run `pysc2.bin.process_replays` to process many replays
in parallel by supplying a replay directory. Each replay in the supplied directory
will be processed.

```shell
$ python -m pysc2.bin.process_replays --replays <path-to-replay-directory>
```
The default number of instances to run in parallel is 1, but can be changed using
the `parallel` argument.

```shell
$ python -m pysc2.bin.process_replays --replays <path-to-replay-directory> --parallel <number-of-parallel-instances>
```

## Parse a replay

To collect data from one or more replays, a replay parser can be used. Two example
replay parsers can be found in the replay_parsers folder:

* `action_parser`: Collects statistics about actions and general replay stats and prints to console
* `player_info_parser`: Collects General player info at each replay step and saves to file

To run a specific replay parser, pass the parser as the `parser` argument. If the replay parser
returns data to be stored in a file, a directory must be supplied to the `data_dir` argument

```shell
$ python -m pysc2.bin.process_replays --replays <path-to-replay-directory> --parser pysc2.replay_parsers.action_parser.ActionParser --data_dir <path-to-save-directory>
```

Details on how to implement a custom replay parser can be found in the [here](docs/environment.md#replay-parsers).

## Public Replays

Blizzard is releasing a large number of anonymized 1v1 replays played on the
ladder. You can find instructions for how to get the
[replay files](https://github.com/Blizzard/s2client-proto#downloads) on their
site.
21 changes: 21 additions & 0 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,24 @@ There are a couple basic agents.

* `random_agent`: Just plays randomly, shows how to make valid moves.
* `scripted_agent`: These are scripted for a single easy map.

## Replay Parsers

Custom replay parsers can be built to collect data from replay files. Two example
replay parsers can be found in the replay_parsers folder:

* `action_parser`: Collects statistics about actions and general replay stats and prints to console
* `player_info_parser`: Collects General player info at each replay step and saves to file

To build a custom replay parser, a class that inherits from BaseParser needs to be defined.
The main method of the replay parser is the `parse_step` method. This function must take as arguments:
`obs`,`feat` and `info` which are the game observations, feature layers and replay information at a single
step in the replay, which is passed to the parser from `process_replays` script for each step in the
replay file. This information is used to parse the desired data. If the `parse_step` function returns,
the returned value is appended to a list containing the parsed data for each step in the replay. Once the
replay is finished, this list is saved to a data file in the supplied `data_dir` directory.
If no directory is supplied, the data is not saved to a file.

The `valid_replay` method of the parent BaseParser class can be overridden to supply a custom
definition for valid replays (ie. filter out replays having players with small MMR). The `valid_replay`
method must take as arguments `info` and `ping` supplied from `process_replays` and return a boolean.
Loading