-
Notifications
You must be signed in to change notification settings - Fork 0
/
extracode.py
102 lines (88 loc) · 2.5 KB
/
extracode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
class var:
def __init__(self):
self.jdstring = ''
def jdict():
f = open(r"C:\Python26\go_analyzer\KJD_example1.sgf", 'r')
#f = open(r"C:\Python26\go_analyzer\KJD_clean2.sgf", 'r')
#jdstring = ''
for line in f:
jdstring = jdstring + line.strip()
jt = tree.jtree()
#imports the joseki dictionary
#jt = tree.jtree()
def getchar():
char = jdstring[0]
jdstring = jdstring[1:]
return char
def getmove():
move = var.jdstring[0:5]
jdstring = jdstring[5:]
return move
def peekchar():
return jdstring[0]
def recur_tom():
## removes leading (
getchar()
node = Node()
while(peekchar() == '('):
node.next.append(recur_tom())
## removes trailing )
getchar()
return node
def bad_recur():
node = tree.Node()
while peekchar() == ")" or peekchar() == "(" or peekchar() == ";":
if peekchar() == ")": ### the end of a sequence! return
return None
elif peekchar() == "(": ### I want to look at multiple ( then
node.next.append(recur())
data_string = data_string[1:]
recur(data_string, temp.next[len(temp.next)])
else: ### a move
temp.data = Node(process_move(string[0:4]))
data_string = data_string[4:]
recur(data_string, temp.next)
if line[i+1] == "W":
player = 'W'
elif line[i+1] == "B":
player = 'B'
x = coord(line[i+3])
y = coord(line[i+4])
return [x, y, p]
def recur():
paren = False
node = tree.Node()
if peekchar() == "(":
getchar()
paren = True
if peekchar() == ";":
move = getmove()
if move[i+1] == "W":
player = 'W'
elif line[i+1] == "B":
player = 'B'
x = coord(line[i+3])
y = coord(line[i+4])
return [x, y, p]
while peekchar() == "(":
pass
def jdict_cleanformat():
#imports the joseki dictionary
jd = open(r"C:\Python26\go_analyzer\KJD_clean2.sgf")
total = ""
clean = ""
comment = False
for line in jd:
word = line.strip()
total = total + str(word)
print len(total)
for i in range(len(total)):
if total[i] == '(' or total[i] == ')':
print str(total[i])
print str(total[i]),
print "clean done"
print len(clean)
newjd = open(r"C:\Python26\go_analyzer\KJD_clean3.sgf", 'w')
newjd.write(clean)
return
#jdict_cleanformat()