Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monte_carlo_tree_search/mcst_example.py: expand(node) method not work in checking new state already exists #6

Open
charleschen6 opened this issue Dec 31, 2019 · 0 comments

Comments

@charleschen6
Copy link

charleschen6 commented Dec 31, 2019

expand node filter by add eq and hash for class State

def expand(node):
  tried_sub_node_states = [
      sub_node.get_state() for sub_node in node.get_children()
  ]

  new_state = node.get_state().get_next_state_with_random_choice()

  # Check until get the new state which has the different action from others
  while new_state in tried_sub_node_states:
    new_state = node.get_state().get_next_state_with_random_choice()

origin code not work for state object using default hash and not find same state in python3.8

by add below codes will correct the error.

class State(object):
  .....
  def __eq__(self, other):
    if isinstance(other, self.__class__):
      return (self.current_value, self.current_round_index, self.cumulative_choices) == \
             (other.current_value, other.current_round_index, other.cumulative_choices)
    else:
      return False

  def __hash__(self):
    return hash('{},{},{}'.format(self.current_value, self.current_round_index, self.cumulative_choices))
@charleschen6 charleschen6 changed the title monte_carlo_tree_search/mcst_example.py: class Node(object)/expand(node) monte_carlo_tree_search/mcst_example.py: expand(node) method not work in checking new state already exists Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant