From a1c3a1a7183568b1250ad2559a66af52697b1315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <david-bergstrom@outlook.com> Date: Mon, 13 Aug 2018 14:49:34 +0200 Subject: [PATCH] Update example to match sc2-python-bot --- README.md | 15 ++++++++++++--- docs/gettingstarted.rst | 27 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d720c5e..95453c5 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,12 @@ Key differences: # Code example for making a bot ``` python +import os + from library import * -class DoNothingBot(IDABot): + +class MyAgent(IDABot): def __init__(self): IDABot.__init__(self) @@ -32,7 +35,7 @@ class DoNothingBot(IDABot): def main(): coordinator = Coordinator() - bot1 = DoNothingBot() + bot1 = MyAgent() participant_1 = create_participants(Race.Terran, bot1) participant_2 = create_computer(Race.Random, Difficulty.Easy) @@ -40,10 +43,16 @@ def main(): coordinator.set_participants([participant_1, participant_2]) coordinator.launch_starcraft() - coordinator.start_game("InterloperTest.SC2Map") + + path = os.path.join(os.getcwd(), "maps", "InterloperTest.SC2Map") + coordinator.start_game(path) while coordinator.update(): pass + + +if __name__ == "__main__": + main() ``` # How to build (Windows) diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst index 29a31fc..4603829 100644 --- a/docs/gettingstarted.rst +++ b/docs/gettingstarted.rst @@ -7,11 +7,18 @@ The goal of this page is to get you quickly started using the API. The following code block is the bare minimum you need to start Starcraft II and run your own bot. +An entire AI template project is available here_, it contains the code below +and more. + +.. _here: https://gitlab.ida.liu.se/starcraft-api/sc2-python-bot + .. code-block:: python + import os from library import * - class DoNothingBot(IDABot): + + class MyAgent(IDABot): def __init__(self): IDABot.__init__(self) @@ -24,7 +31,7 @@ your own bot. def main(): coordinator = Coordinator() - bot1 = DoNothingBot() + bot1 = MyAgent() participant_1 = create_participants(Race.Terran, bot1) participant_2 = create_computer(Race.Random, Difficulty.Easy) @@ -32,14 +39,16 @@ your own bot. coordinator.set_participants([participant_1, participant_2]) coordinator.launch_starcraft() - coordinator.start_game("InterloperTest.SC2Map") + + path = os.path.join(os.getcwd(), "maps", "InterloperTest.SC2Map") + coordinator.start_game(path) while coordinator.update(): pass if __name__ == "__main__": - main() + main() Now, let us break it down piece by piece to understand it. @@ -53,7 +62,7 @@ Next, we need to define our bot. .. code-block:: python - class DoNothingBot(IDABot): + class MyAgent(IDABot): def __init__(self): IDABot.__init__(self) @@ -80,7 +89,7 @@ Moving on, we have the code which sets up a game of Starcraft II: def main(): coordinator = Coordinator() - bot1 = DoNothingBot() + bot1 = MyAgent() participant_1 = create_participants(Race.Terran, bot1) participant_2 = create_computer(Race.Random, Difficulty.Easy) @@ -88,7 +97,9 @@ Moving on, we have the code which sets up a game of Starcraft II: coordinator.set_participants([participant_1, participant_2]) coordinator.launch_starcraft() - coordinator.start_game("InterloperTest.SC2Map") + + path = os.path.join(os.getcwd(), "maps", "InterloperTest.SC2Map") + coordinator.start_game(path) while coordinator.update(): pass @@ -111,4 +122,4 @@ to: bot2 = SomeOtherBot() participant_2 = create_participant(Race.Terran, bot2) -where ``SomeOtherBot`` is a bot defined in the same way as ``DoNothingBot``. +where ``SomeOtherBot`` is a bot defined in the same way as ``MyAgent``. -- GitLab