Example #1
0
    def __init__(self):
        '''

		'''
        self.outerlines_heurestic = [[7, 6, 5, 4], [6, 4, 3, 3], [5, 3, 2, 2],
                                     [4, 3, 2, 1]]
        self.snake_heurestic = [[16, 15, 14, 13], [9, 10, 11, 12],
                                [8, 7, 6, 5], [1, 2, 3, 4]]
        self.gradient_heurestic = [[7, 6, 5, 4], [6, 5, 4, 3], [5, 4, 3, 2],
                                   [4, 3, 2, 1]]
        self.directions = {1: "RIGHT", 2: "LEFT", 3: "UP", 4: "DOWN"}
        self.logic = Gamelogic()
        self.neighbours = list()
        heapq.heapify(self.neighbours)
Example #2
0
        '''

		'''
        if depth == 0:
            h = self.heuristic(board)
            return h
        if maximizing_player:
            #Return value of maximum-valued child node
            alpha = float("-inf")
            for neighbour in self.get_neighbours(board):
                alpha = max(alpha, self.expectimax(neighbour, depth - 1,
                                                   False))
        elif maximizing_player == False:
            # Return weighted average of all child nodes' values
            alpha = 0
            neighbours = self.logic.append_all_random_numbers(board)
            for key in neighbours.keys():
                for neighbour in neighbours[key]:
                    alpha += (self.probability_of_reaching_node(key, board) *
                              self.expectimax(neighbour, depth - 1, True))
        #print("alpha")
        return alpha


if __name__ == "__main__":
    solver = Solver()
    logic = Gamelogic()
    print("-----------")
    board = [[2, 0, 0, 0], [0, 2, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    neighbours = solver.get_neighbours(board)
    #print(neighbours)