Code Monkey home page Code Monkey logo

dd2380_project's People

Contributors

kholdcro avatar samirkhays avatar viktortuul avatar yoshuanava avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dd2380_project's Issues

GetChildren takes too much time + outputs too many children

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?

Error in heuristic function

When I try to call the heuristic function in the simulation method of MCTS, as follows:

        print("-------- Simulation --------")
        points = 0
        itr = 1
        child = node

        while (itr <= self.max_length):
            # Get all the possible actions, and choose a random one. Predict the next state and evaluate it with the heuristic function
            children = child.getChildren()
            child = random.choice(children)
            points += th.heuristic(child.state.grid)   # Run heuristic here
            itr += 1

I get the following output:

************  MCTS ************
    Length of future nodes list = 44
##### Iteration 0 #####
-------- Selection --------
    Tree depth explored = 1
    Time elapsed = 0.101644039154
-------- Simulation --------
Traceback (most recent call last):
  File "tetris.py", line 14, in <module>
    Core(gfx).run()
  File "/home/alfredoso/GitHub/DD2380_Project/tetris-master/tetris/core.py", line 40, in run
    self.play()     # Our playing method
  File "/home/alfredoso/GitHub/DD2380_Project/tetris-master/tetris/core.py", line 108, in play
    mcts.run()
  File "/home/alfredoso/GitHub/DD2380_Project/tetris-master/tetris/TreeSearch.py", line 240, in run
    node = self.simulation(node)
  File "/home/alfredoso/GitHub/DD2380_Project/tetris-master/tetris/TreeSearch.py", line 195, in simulation
    points += th.heuristic(child.state.grid)   # Run heuristic here
  File "/home/alfredoso/GitHub/DD2380_Project/tetris-master/tetris/heuristic.py", line 9, in heuristic
    h1 = nHoles(gamefield)
  File "/home/alfredoso/GitHub/DD2380_Project/tetris-master/tetris/heuristic.py", line 26, in nHoles
    maxheights = getMaxHeights(gamefield)
  File "/home/alfredoso/GitHub/DD2380_Project/tetris-master/tetris/heuristic.py", line 76, in getMaxHeights
    if (gamefield[row][col] > 0):
IndexError: list index out of range

Maybe I'm not using it appropriately. Is this the case?

Root node initialization and problems with MCST

The root node should be initialized in game.py inside the method new_piece, as this method is called when a new brick is spawned. Currently, the root node is initialized in core.py (even before the game is started, which implies that the root is "Null").

There are some issues in the MCST class. If a node has no children, the commands
random.choice(node.children)
and
random.choice(unexplored_children)
returns an index error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.