summaryrefslogtreecommitdiff
path: root/tsumego
diff options
context:
space:
mode:
Diffstat (limited to 'tsumego')
-rwxr-xr-xtsumego51
1 files changed, 27 insertions, 24 deletions
diff --git a/tsumego b/tsumego
index 9b92aa0..57c5d04 100755
--- a/tsumego
+++ b/tsumego
@@ -121,13 +121,6 @@ class Board:
self.to_play = "W"
if key == "C":
print("---> "+val[0])
- if not node.variations:
- self.current_node = node.next
- if not node.next:
- self.finished = True
- else:
- i = randint(0,len(node.variations)-1)
- self.current_node = node.variations[i]
def is_move(self,node):
for key in node.properties.keys():
@@ -137,26 +130,39 @@ class Board:
return False
def add_next(self,nmoves):
+
nm = 0
- if nmoves == 0:
- while self.is_move(self.current_node.next):
- self.add_node(self.current_node)
- return
+
while 1:
- if not self.current_node:
+
+ # Decide which node comes next
+ if not self.current_node.variations:
+ n = self.current_node.next
+ if not self.current_node.next:
+ self.finished = True
+ else:
+ i = randint(0,len(self.current_node.variations)-1)
+ n = self.current_node.variations[i]
+
+ if self.finished:
print("Finished!")
- break
- if self.is_move(self.current_node):
+ return
+
+ if self.is_move(n):
if nm == nmoves:
return
nm += 1
- self.add_node(self.current_node)
+
+ self.add_node(n)
+ self.current_node = n
def __init__(self,root):
self.current_node = root
+ self.add_node(root)
def set_node(self,root):
self.current_node = root
+ self.add_node(root)
def fit_board(self):
self.ys = 0
@@ -230,22 +236,19 @@ class Board:
def find_variation(self,move):
- print("Looking for ",move)
- print(self.current_node.properties)
-
- # Is it just the next move?
- if self.current_node.properties[self.to_play][0] == move:
- return self.current_node
-
# Is it in one of the variations?
for var in self.current_node.variations:
- print("Checking ",var.properties)
if not self.to_play in var.properties:
print("No move in this variation!")
print(var.properties)
if var.properties[self.to_play][0] == move:
return var
+ # Is it just the next move?
+ if self.current_node.next.properties[self.to_play][0] == move:
+ return self.current_node.next
+
+ print("Not found!")
def n2l(n):
return string.ascii_lowercase[n-1]
@@ -289,5 +292,5 @@ while not board.finished:
exit(0)
board.set_node(var)
- board.add_next(2)
+ board.add_next(1)
board.show()