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

GetChildren takes too much time + outputs too many children #2

Closed
YoshuaNava opened this issue Oct 8, 2017 · 1 comment
Closed

Comments

@YoshuaNava
Copy link
Owner

YoshuaNava commented Oct 8, 2017

I modified the GetChildren method of GameNode, so that the GameNodes are self-contained, and we don't need to go back and forth between state and nodes. Hence, our successor function is part of the GameNode definition. The new method is:

    def getChildren(self):
        children = []
        # Translations relative to the middle of the board
        for translation in range(-5, 6, 1):
            for rotation in range(0, 4, 1):  # Number of rotations
                # Simulate the game by dong a few rotations and translations: get the new state (for each performed move)
                new_state = GameState.TetrisGame(self.state.grid, self.state.curr_piece, self.state.next_piece, rotation, translation)
                action = (rotation, translation)
                child = GameNode(new_state, self, action)
                children.append(child)
                # Calculate the hash value
                # hash_val = abs(hash(new_state_string))
                # Check for hash collision
                # if (self.hashtable[hash_val % 1000000] == 0):
                #     self.hashtable[hash_val % 1000000] = 1
                #     child = GameNode(new_state.getGrid(), piece, next_piece, new_state.getActions())
                #     self.children.append(child)
        return children

However, I'm getting about 44 children out of each state. I think we should only take into account some of them. But which ones?

Furthermore, this function takes quite some CPU time. I think it could be because we run deepcopy while creating new GameState objects. Could this be the case?

@viktortuul
Copy link
Collaborator

Hashing now works properly, no more duplicate nodes.

Considering the CPU time, we could start with managing the ranges in;

for translation in range(-5, 6, 1):
for rotation in range(0, 4, 1):

such that not unnecessary game simulations are done. For example, if a square block is falling there is no point in rotating it. If this does not make it, we should indeed look into how we manage the GameState objects.

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

2 participants