Skip to content

Instantly share code, notes, and snippets.

@justecorruptio
Last active October 21, 2016 07:56
Embed
What would you like to do?
Script to find the "densest" Pro Game
from multiprocessing.dummy import Pool
import os
import re
from subprocess import Popen, PIPE
from threading import RLock
DIR = 'go4go'
def parse(fn):
fh = open(fn, 'r')
data = fh.read()
res = re.search(r'RE\[[BW]\+R]', data)
count = len(re.findall(r';[BW]\[', data))
fh.close()
return bool(res), count
def gnugo(fn):
fh = Popen(["gnugo", "-l", fn, "--mode", "gtp"], stdout=PIPE, stdin=PIPE)
fh.stdin.write('final_status_list alive\n')
fh.stdin.close()
res = fh.stdout.read()
return len(res.split()) - 1
highest = 0
lock = RLock()
def handle_file(fn):
global lock, highest
resigned, moves = parse(fn)
if resigned or moves < highest:
return
count = gnugo(fn)
with lock:
if count > highest:
print fn, count, "%.3f" % (count / 361.)
highest = count
Pool(5).map(
handle_file,
[os.path.join(DIR, path) for path in os.listdir(DIR)],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment