Files
@ 29f28718a69b
Branch filter:
Location: OneEye/src/go/gamerecord.py - annotation
29f28718a69b
1.2 KiB
text/x-python
transitional data processing
3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 | from util import colorNames
class Point:
def __init__(self,c,r):
self.r=r
self.c=c
def __iter__(self):
yield self.c
yield self.r
def __str__(self):
a=ord("a")
return chr(a+self.c)+chr(a+self.r)
class GameRecord:
def __init__(self):
self.playerB=""
self.playerW=""
self.root=Node()
self.currNode=self.root
def move(self,color,row,col):
if color not in colorNames:
raise ValueError("invalid color: {0}".format(color))
colorName=colorNames[color]
res=Node()
res.properties[colorName]=Point(col,row)
self.currNode.children.append(res)
self.currNode=res
return res
def __str__(self):
res=["("]
stack=[self.root]
while len(stack)!=0:
v=stack.pop()
res.append(v)
if v==")": continue
if len(v.children)>1:
res.append("(")
stack.append(")")
stack.extend(reversed(v.children))
res.append(")")
return "".join(str(x) for x in res)
class Node:
def __init__(self):
self.properties=dict()
self.parent=None
self.children=[]
## Returns textual representation of the Node itself, but disregards its children.
def __str__(self):
return ";" + "".join("{0}[{1}]".format(k,str(p)) for (k,p) in self.properties.items())
|