コード例 #1
0
    def expand(self):
        '''
         Expand the current tree node for one-level.
         Add one child node for each possible next move in the game.
         Inputs:
                node: the current tree node to be expanded 
        '''
        # if the game has already ended, return/exit without expanding the tree
        if TicTacToe.check(self.s) is not None:
            return

        # if the game has not ended yet, expand the current node with one child node for each valid move
        all_moves = TicTacToe.avail_moves(self.s)
        for r, c in all_moves:
            # update s
            s = np.copy(self.s)
            s[r, c] = 1 if self.x == 1 else -1
            node = Node(s, x=-self.x, parent=self)
            self.c.append(node)
コード例 #2
0
    def expand(self):
        '''
         Expand the current tree node for one-level.
         Add one child node for each possible next move in the game.
         Inputs:
                node: the current tree node to be expanded 
        '''
        #########################################
        ## INSERT YOUR CODE HERE

        # if the game has already ended,  return/exit without expanding the tree
        if (TicTacToe.check(self.s) != None):
            return

        # if the game has not ended yet, expand the current node with one child node for each valid move

        valid_moves = TicTacToe.avail_moves(self.s)
        for move in valid_moves:
            new_s = np.copy(self.s)
            i = move[0]
            j = move[1]
            new_s[i][j] = self.x
            Child = Node(s=new_s, x=self.x * -1, parent=self)
            self.c.append(Child)