I am having difficulty with running the starter algorithm locally

Hello all,

I am having difficulty with running the starter algorithm locally. I have absolutely no clue how to do this due to my nonexistent knowledge of python. If anyone could give me a step-by-step list of instructions on how to run it I would be very grateful.

By the way, I am running on a Mac with Mac OS Sierra.

Pretty sure this will also work on mac. In the terminal, from the C1GamesStarterKit directory: . scripts/run.sh algos/starter-algo algos/starter-algo.

The explanation is that you want to run the run.sh script with the folders containing the algorithms you want to pit against each other as the first and second arguments.

1 Like

I don’t know how familiar you are with coding in general, but Python is a scripted language, which means it needs to be run by another process like Windows PowerShell, Linux Bash, or Mac Terminal. The run_match.sh (or run_match.ps1 for windows) script is actually not Python, it is a bash program that starts the game engine. It is a program that is designed to run on the respective operating system, which is why there is two versions of this file and why you only run a single one for your program. You only call the one that your operating system can run (for Mac run.sh).

If you look inside the run_match file you will see that it looks nothing like python, because it isn’t! The commands are things you could type into your Terminal (Mac) or PowerShell (Windows).

Looking at the run_match.sh there is the last line:

java -jar engine.jar work ${algo1}/run.sh ${algo2}/run.sh

This is what actually starts the local engine where ${algo1) and ${algo2} are just variables for the arguments you passed to the program. So if you ran scripts/run.sh algos/cool-algo algos/cooler-algo then ${algo1) is algos/cool-algo and ${algo2} is algos/cooler-algo. In the argument it calls /run.sh. Then the java engine handles starting the Python programs you have written by starting those run.sh files.

So finally, we get to the Python! As I said before, Python is scripted, so it has to be run from the Terminal/PowerShell. That is all the run.sh and run.ps1 file does. It calls your python script that starts your algo, in this case algo_strategy.py and if you look inside run you will see that file.

The key is that you could simply run any Python program by typing into your Terminal python [PROGRAM].py. However, if you did this with algo_strategy.py it would fail (I don’t know if it would crash, but it wouldn’t work) becuase the script requires information from the Java engine to work properly. This is why you call the run_match.sh instead of just calling Python by itself, the Java engine starts the Python for you.

This is why the command should be scripts/run.sh algos/starter-algo algos/starter-algo instead of just calling python like what you may see in tutorials online.

This was probably way more than what you were asking for :slight_smile: but I hope it was helpful, just ask if you have any other questions about something I said.

3 Likes

Update: I fixed the problem, thanks for your help!

Hi @Isaac,

I managed to figure out some things and eventually received these line of code. Do you know what I did wrong? The code starts and ends at the fullstops/periods. Thanks for your help!


C1GamesStarterKit-master/algos/starter-algo/run.shscripts/run.sh
algos/starter-algo
algos/starter-algo
Invalid args, format= ‘[command for ai1] [command for ai2]’

1 Like

What command did you run to generate that output? What behavior were you expecting, and what did you see? It also may be beneficial if you print the full output instead of a small piece of it.