Running Games Iteratively


#1

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!


#2

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!


#3

I am looking for exactly the same thing.


#4

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.


#5

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.


#6

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


#7

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:


#8

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.


#9

Is your tool Linux only?


#10

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 manager.py 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.


#11

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 = f.read()
    os.remove("out.txt")
    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

print(wins)

#12

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()
command.append("python3 MyBot.py")
command.append("python3 MyBot.py")

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 halite.io 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)
#13

This is awesome, thanks for the explanation.


#14

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]


#15

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


#16

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