GraylinKim / sc2reader

A python library that extracts data from various Starcraft II resources to power tools and services for the SC2 community. Who doesn't want to hack on the games they play?
http://sc2reader.readthedocs.org
MIT License
411 stars 85 forks source link

Build Order Update #179

Open y4n9squared opened 9 years ago

y4n9squared commented 9 years ago

I noticed that past attempts to extract build orders (e.g. #35) have proved difficult. It seems pretty straight-forward now, correct? I've been using a custom engine plugin to parse build orders but have only tested it on a small handful of replays. Would you be interested in having me submit a pull request for the engine plugin?

StoicLoofah commented 9 years ago

This might be slight hijacking, but the purpose of Spawning Tool https://github.com/StoicLoofah/spawningtool is to extract build orders from replays, so it's a wrapper around sc2reader to do that. There's various normalization that goes into it that presumably could be handled within a plugin but doesn't quite cleanly map to the data from sc2reader in all cases just to make it readable, so it comes out slightly differently. Is this what you were hoping to accomplish, or was there something else you were looking for?

y4n9squared commented 9 years ago

Thanks for the link @StoicLoofah. Indeed we are trying to accomplish the same goal, albeit the module that I'm using is substantially less featured but serves my purposes:


# -*- coding: utf-8 -*-
"""Build order plugin for sc2reader.

.. moduleauthor:: Yang Yang <y4n9squared@gmail.com>

"""

from sc2reader.events.game import AbilityEvent

_BUILD_IDS = {
    3872: "Command Center",
    3873: "Supply Depot",
    # Rest omitted for brevity
}

class BuildOrderTracker(object):
    """Builds ``player.build_order`` lists where elements are tuples (frame,
    second, building).
    """

    name = 'BuildOrderTracker'

    def handleInitGame(self, event, replay):
        print(replay.players)
        for human in replay.humans:
            human.build_order = []

    def handlePlayerActionEvent(self, event, replay):
        if isinstance(event, AbilityEvent) and event.ability_id in _BUILD_IDS:
            replay.humans[event.pid].build_order.append(
                (event.frame, event.second, _BUILD_IDS[event.ability_id]))

    def handlePlayerLeaveEvent(self, event, replay):
        pass

    def handleEndGame(self, event, replay):
        pass

I do think, however, that the BO feature would enjoy more attention and support if it were merged into this repo.

StoicLoofah commented 9 years ago

That's a fair point. There are a few reasons why it's separate:

  1. spawningtool is built on top of rather than in conjunction with sc2reader. As such, it uses structures and conversions that don't necessarily align with the structure in sc2reader
  2. the functionality of spawningtool is sprawling for whatever I need for the spawningtool website. As such, it doesn't really neatly fit into the core library as an isolated plugin
  3. furthermore, my development is haphazard and irregular and best not linked to the typical open source flow for the sc2reader library

Regardless, you're welcome to steal mercilessly from the spawningtool work (or make your own, better version as you proposed above) if you want to write a plugin for the sc2reader core. I can see the value for it, and there could be a cleaned up version of spawningtool that would fit quite nicely into sc2reader. For myself, however, spawningtool serves my purposes and is made available as it aligns with others' goals