import re
import datetime
class Sgf:
gameName=None
black=None
white=None
rankB=None
rankW=None
result=None
komi=6.5
date=None
place=None
moves=[]
def __init__(self,s):
m=re.search("GN\[.*\]",s)
if m: self.gameName=m.group()
m=re.search("PB\[.*\]",s)
if m: self.black=m.group()
m=re.search("PW\[.*\]",s)
if m: self.white=m.group()
m=re.search("BR\[.*\]",s)
if m: self.rankB=m.group()
m=re.search("WR\[.*\]",s)
if m: self.rankW=m.group()
m=re.search("RE\[.*\]",s)
if m: self.result=m.group()
m=re.search("KM\[.*\]",s)
if m: self.komi=m.group()
m=re.search("PC\[.*\]",s)
if m: self.place=m.group()
m=re.search("DT\[.*\]",s)
if m: self.date=m.group() # naparsovat ho
self.moves=re.findall("\W([BW])\[([a-s]{2})\]",s) # a pass?
char2int=lambda a:ord(a)-ord('a')
self.moves=[(c,(char2int(m[0]),char2int(m[1]))) for c,m in self.moves]
def getMoves(self):
return self.moves.copy()