How can I get iterative JSON game data, of game_statistics?


#1

I used Fluorine to save JSON data from the replay.HLT file and it’s great, but I have to do it manually.
Is there a better way to get a dictionary of game data out of the HLT FILE?

Decompress HLT file?


#2

You can use ‘–no-compression’ to get the .hlt in JSON format.


#3
with open(file_name, 'rb') as f:
            data = json.loads(zstd.loads(f.read()))

That’s taken straight from the Machine Learning Starter Kit parse file. You could modify their code, or at least use it to understand the format of the JSON that you get from a .hlt replay file.


#4

Haha I don’t know how i missed that. Thanks!
–no-compression
Disables compression for output files. (They will just be plain JSON.)


#6

Another way is to run it from Python with the following kind of script:

result = subprocess.run(["./halite.exe", "--replay-directory", "replays/", "--results-as-json", "--width 32", "--height 32", \
            "python bot0.py","python bot1.py"], stdout=subprocess.PIPE)
resultsJson = result.stdout.decode('utf8')
data = json.loads(resultsJson)
error_log = data['error_logs']
stats = data['stats']

This way you will get the results in ‘stats’ and any error message in ‘error_log’.

This allow you to run several times and find which bot is better, for example.


#7

python -m hlt_client replay user -l 100 -d . --decompress

The right command is --decompress in the latest Halite CLI