Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def grow(self, depth=1e900000):
  2. '''Grow the tree of GameStates, starting from this one.
  3.  
  4. Assumptions:
  5. The tree of GameStates generated from this one is finite, and is
  6. specified (recursively) by self.value.make_move()
  7. '''
  8.  
  9. if depth == 0:
  10. return self
  11.  
  12. h = hash(self.value)
  13.  
  14. if h not in gamestates:
  15.  
  16. for m in self.value.next_move():
  17. child = GameStateNode(self.value.make_move(m), m)
  18. child = child.grow(depth -1)
  19. self.children.append(child)
  20.  
  21. gamestates[h] = self
  22.  
  23. else:
  24. for child in gamestates[h].children:
  25. self.children.append(child)
  26.  
  27. return gamestates[h]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement