Skip to content

Instantly share code, notes, and snippets.

@lrusnac
Created November 2, 2016 18:41
Show Gist options
  • Save lrusnac/96ded807bbe6d2dbaf2901ca61c52d51 to your computer and use it in GitHub Desktop.
Save lrusnac/96ded807bbe6d2dbaf2901ca61c52d51 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 0*0
import json
import os
import tqdm
import pickle
INPUTFILE = 'games.txt'
OUTPUTFILE = 'states.txt'
states = {}
def moves_to_states(moves = [], winner = 0):
state = ['0'] * 81
player = True
for move in moves:
if move is not '-1':
state[int(move)] = '1' if player else '2'
player = not player
state_str = ''.join(state)
if state_str not in states:
states[state_str] = [0, 0, 0]
states[state_str][winner] += 1
if __name__ == '__main__':
with open(INPUTFILE) as f:
for game in tqdm.tqdm(f):
game_parts = game.split(';')
moves_to_states(game_parts[1].split(','), int(game_parts[0]))
print len(states)
with open(OUTPUTFILE, 'w') as f:
pickle.dump(states, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment