From fac29f980280871f78de9aa8544eb5660ef3325d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= <edvard.thornros@gmail.com> Date: Fri, 4 Dec 2020 14:32:39 +0100 Subject: [PATCH] Change to use a Python3 module structure from the start There's a lot of difficulty for students to share their agents between each other. When they start the project they don't think about the need to make it into a module since it "runs". A lot has been done in this commit, move everything to a separate folder which the students have to rename. Reformat the README.md to respect people reading it in the terminal and add some more instructions for the setup. --- README.md | 9 ++++++++- extra.py => myagent/extra.py | 0 myagent/main.py | 14 ++++++++++++++ main.py => start.py | 31 +++++++++++++------------------ 4 files changed, 35 insertions(+), 19 deletions(-) rename extra.py => myagent/extra.py (100%) create mode 100644 myagent/main.py rename main.py => start.py (55%) diff --git a/README.md b/README.md index 7637e19..a8c0620 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,11 @@ This repository contains a passive PyCommandCenter-based bot for StarCraft II. I 4. Everything is now ready for PyCharm: Start PyCharm, and then select "Open" and navigate to the location you cloned your fork of this repository to. -5. In order to run the code, right click the file named "main.py" in the project panel to the right, and select "Debug main". This will run the code in "main.py", and consequently start StarCraft II. You can also edit the code in "main.py" by double-clicking "main.py". +5. In order to run the code, right click the file named "start.py" in the + project panel to the right, and select "Debug main". This will run the code + in "start.py", and consequently start StarCraft II. You can also edit the + code in "start.py" by double-clicking "start.py". + +6. Rename the folder 'myagent' to something unique, preferably with your group number + in the name. This will make it easier when you want to run against other bots. So make + sure ALL of the source code for the bot lives in that folder. diff --git a/extra.py b/myagent/extra.py similarity index 100% rename from extra.py rename to myagent/extra.py diff --git a/myagent/main.py b/myagent/main.py new file mode 100644 index 0000000..baf9dc9 --- /dev/null +++ b/myagent/main.py @@ -0,0 +1,14 @@ +from typing import Optional +from library import * +from myagent.extra import * + + +class MyAgent(IDABot): + def __init__(self): + IDABot.__init__(self) + + def on_game_start(self): + IDABot.on_game_start(self) + + def on_step(self): + IDABot.on_step(self) diff --git a/main.py b/start.py similarity index 55% rename from main.py rename to start.py index 1910817..5a6bc35 100644 --- a/main.py +++ b/start.py @@ -1,29 +1,24 @@ import os -from typing import Optional -from library import * - - -class MyAgent(IDABot): - def __init__(self): - IDABot.__init__(self) - - def on_game_start(self): - IDABot.on_game_start(self) - - def on_step(self): - IDABot.on_step(self) +from library import ( + Coordinator, Difficulty, Race, + create_participants, create_computer, +) +from myagent.main import MyAgent def main(): + fight_against_agent = False coordinator = Coordinator(r"D:\StarCraft II\Versions\Base69232\SC2_x64.exe") - bot1 = MyAgent() - # bot2 = MyAgent() + bot1 = MyAgent() participant_1 = create_participants(Race.Terran, bot1) - # participant_2 = create_participants(Race.Terran, bot2) - participant_2 = create_computer(Race.Random, Difficulty.Easy) + if fight_against_agent: + bot2 = MyAgent() # Change me + participant_2 = create_participants(Race.Terran, bot2) + else: + participant_2 = create_computer(Race.Random, Difficulty.Easy) coordinator.set_real_time(True) coordinator.set_participants([participant_1, participant_2]) @@ -37,4 +32,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() -- GitLab