Running Games Iteratively


Does anybody know if it’s possible to run games iteratively in a loop? I’m trying to train my agent with self-play and I can’t seem to figure it out.

Thanks a lot!


I found a workaround by running a for loop in the shell and saving/loading arrays used in the optimization process outside of the python file. If anyone finds a cleaner solution, I’d love to hear it!


I am looking for exactly the same thing.


Can you tell who won the match from inside the game loop? I couldn’t find it. The winner is decided in turn 401 for 32x32 games, but the loop only goes up to 400.


I was just about to ask the same thing, for a similar reason, and haven’t found anything better.

I’m saving my experience replay buffer to a file, and just using save/restore utilities in TF for the model. I was hoping that there was something more along the lines of OpenAI Gym but that doesn’t appear to be the case.


This isn’t set up for training, but you may be able to adapt my match manager to suit your needs:


You can do a little hack by tracking the amount of halite each player has with ‘me.halite_amount’, and at the end of the game, you can see who wins :slight_smile:


I found that parsing the replay file was more reliable and it wasn’t too hard. Some matches are decided on the last turn and you won’t get the correct info by doing that.


Is your tool Linux only?


You will need to modify the path to the Halite binary to make it work on Windows, but from memory people used it with Windows last year.

Near the top of the file is a line like this:

halite_command = "./halite"

If you change that to something like this and copy e.g halite.exe into the directory, it should work:

halite_command = "halite.exe"

If it doesn’t, I’ll be happy to try to help, though I don’t have a Windows installation to test on.


Here is my hack & slash used on windows. Prints the number of times player 0 wins out of the 10 games.

import os

def run_single_game():
    os.popen('run_game.bat 1>>out.txt 2>>&1').read()
    with open('out.txt') as f:
        read_data =
    res = read_data.find("Player 0" )
    res = read_data[res:].find("rank") + res + 5

    return read_data[res]

wins = 0
for x in range(10):
    wins += 1 if run_single_game() == '1' else 0



The halite executable supports ‘–results-as-json’. Instead of parsing the game output, you can directly access the results.

import json, subprocess

command = "./halite --replay-directory ./replays/ --width 32 --height 32 --no-timeout --seed 1234567 --results-as-json".split()

print(f"Command used:\n{command}")
results = subprocess.check_output(command)
results = json.loads(results)
print(f"Player stats from match:\n{results['stats']}")

As for extensive usage, data tracking, etc., there appear to be several tools around, but I’m unclear as to the differences/purposes of each.

Just from downloads, there is a gym, a visualizer, and a client. At the bottom, there are more community visualizers (I’m using fluorine currently).

In the GitHub Repo there are halite-in-a-box, hlt_client, and manager.

I also posted here, hoping to get clarification on the differences between the tools.

[Solved] Benchmark Bots (zlib, base64, and pyminifier)

This is awesome, thanks for the explanation.


In Windows I made the JSON approach work with the following changes:
1 - Instead of running the full command I had to change it to run the bat file otherwise it would crash halite.exe (don’t know why).
2 - When parsing the result the following code was necessary to make it read the results properly:
results = str(results).replace("\r\n", “”)
results = results[163:-1]


This is awesome! But I can’t get it to work with my other bots… or any other bot that’s not named “”


If you’re getting error logs I can look at them, but I haven’t had a problem running other bots