Skip to content
Snippets Groups Projects
Commit a1c3a1a7 authored by David Bergström's avatar David Bergström
Browse files

Update example to match sc2-python-bot

parent 561d89af
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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``.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment