Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyCommandCenter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Starcraft AI Course
PyCommandCenter
Commits
42b1e185
Commit
42b1e185
authored
4 years ago
by
Rojikku98
Browse files
Options
Downloads
Patches
Plain Diff
Started replays doc
parent
d5a2f7c7
No related branches found
No related tags found
1 merge request
!6
Replays
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/replays.rst
+98
-0
98 additions, 0 deletions
docs/replays.rst
with
98 additions
and
0 deletions
docs/replays.rst
+
98
−
0
View file @
42b1e185
Replays
=======
This page will describe two different techniques for handling replays. The
first technique parses the information saved in the replay file. The secund
uses the information in the replay file to actually replay the game. The
different techniques have serten advetedeges and disadvantages.
SC2Reader
---------
SC2Reader_ is a library that can be used to implement the first technique.
Here is a short example that uses SC2Reader to extract the build order.
.. _SC2Reader: https://github.com/ggtracker/sc2reader
.. code-block:: python
import sc2reader
import json
from sc2reader.factories import SC2Factory
# The path to the replays
PATH = "../Replays"
def main():
# Creates a generator of all the replays in the dictionary
replays = sc2reader.load_replays(PATH, load_level=3)
games = []
# Loops through every relay
for replay in replays:
building_order = []
if is_terran_vs_terran(replay):
# Loops through every event
for event in replay.events:
# Check if the event is that a building is crated
if type(event) == sc2reader.events.tracker.UnitInitEvent:
if event.unit.name not in building_order:
building_order.append(event.unit.name)
games.append(building_order)
return games
def is_terran_vs_terran(replay):
try:
return sc2reader.constants.LOCALIZED_RACES[replay.players[0].play_race] == "Terran" \
and sc2reader.constants.LOCALIZED_RACES[replay.players[1].play_race] == "Terran"
except(KeyError):
return False
if __name__ == '__main__':
games = main()
text = json.dumps(games)
print("Res: " + text)
SC2Reader has good documation_ that also describe what information
could be found. `What is in a Replay`_ and Events_ gives a good idea
if the information you want could be colleced whithe SC2Reader.
.. _documation: https://sc2reader.readthedocs.io/en/latest/index.html
.. _What is in a Replay: https://sc2reader.readthedocs.io/en/latest/articles/whatsinareplay.html
.. _Events: https://sc2reader.readthedocs.io/en/latest/events/index.html
ReplayObserver
--------------
This is the second technique it is much like using a bot but whit the diffrens
that no action can be preform just observations
.. code-block:: python
from library import *
class MyObserver(ReplayObserver):
def __init__(self):
ReplayObserver.__init__(self)
def on_game_start(self):
ReplayObserver.on_game_start(self)
def on_step(self):
ReplayObserver.on_step(self)
def main():
coordinator = Coordinator(r"D:\StarCraft II\Versions\Base69232\SC2_x64.exe")
print(coordinator.load_replay_list("D:\\Replays\\"))
coordinator.add_replay_observer(MyObserver())
while coordinator.update():
pass
if __name__ == "__main__":
main()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment