[O] Better implementation for insert_move_sequence
This commit is contained in:
@@ -173,15 +173,14 @@ class GameTree:
|
|||||||
if index == len(moves):
|
if index == len(moves):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Next root already exists
|
sub = self.find_subtree_by_move(moves[index])
|
||||||
for c in self._subtrees:
|
|
||||||
if c.move == moves[index]:
|
|
||||||
c.insert_move_sequence_helper(moves, index + 1)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Next root doesn't exist
|
# Create subtree if not exist
|
||||||
sub = GameTree(moves[index], not self.is_white_move)
|
if not sub:
|
||||||
self.add_subtree(sub)
|
sub = GameTree(moves[index], not self.is_white_move)
|
||||||
|
self.add_subtree(sub)
|
||||||
|
|
||||||
|
# Insert move
|
||||||
sub.insert_move_sequence_helper(moves, index + 1)
|
sub.insert_move_sequence_helper(moves, index + 1)
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user