Files @ dc1ed8ff56ef
Branch filter:

Location: OneEye/src/tests/util.py

Laman
cleaned up and documented shutdown
import re

from go.core import Go
from statebag import BoardState


def simpleLoadSgf(filename):
	with open(filename) as f:
		contents=f.read()
	g=lambda m: tuple(ord(c)-ord('a') for c in reversed(m.group(1)))
	return [g(m) for m in re.finditer(r"\b[BW]\[([a-z]{2})\]",contents)]


def listBoards(moves):
	g=Go()
	res=[tuple(list(x for x in row) for row in g.board)]
	for m in moves:
		g.doMove(g.toMove,*m)
		res.append(tuple(list(x for x in row) for row in g.board))
	return res


def listStates(moves):
	return [BoardState(b) for b in listBoards(moves)]