def explosiveHelper(self, userPosition, bomb, board, direction):
        if direction == 'right':
            point = (40, 0)
        elif direction == 'left':
            point = (-40, 0)
        elif direction == 'up':
            point = (0, -40)
        elif direction == 'down':
            point = (0, 40)

        x = y = 0
        if (bomb.position == userPosition):
            return 1
        while True:
            x += point[0]
            y += point[1]
            nPoint = bomb.position.move((x, y))
            t = board.getTile(nPoint)
            # hit a block or indestructible object
            if nPoint == userPosition:
                return 1
            if not t.canBombPass():
                return 0
            # check bomb's power, this terminates the recursive loop
            if int(abs(x) / 40) == bomb.range or int(
                    abs(y) / 40) == bomb.range:
                return 0
    def degree(self, userPosition, board, bombs, enemies, direction, depth):
        # print userPosition[0], userPosition[1]
        H = board.height
        W = board.width
        board1 = board.board
        point = (0, 0)
        if direction == 'right':
            point = (40, 0)
        elif direction == 'left':
            point = (-40, 0)
        elif direction == 'up':
            point = (0, -40)
        elif direction == 'down':
            point = (0, 40)
        explored = []
        # positions_bombs = [position.position for position in bombs]
        positions_bombs = [(position[0], position[1]) for position in bombs]
        # positions_enemies = [position.position for position in enemies]
        positions_enemies = [(position[0], position[1])
                             for position in enemies]

        # DFS over all the paths
        def dfs(node, vector, depth):
            if node in vector or node in positions_bombs or node in positions_enemies:
                return 0
            if depth <= 0:
                return 1
            children = self.get_children_start(node, H, W)
            vector.append((node[0], node[1]))
            ans = 0
            for child in children:
                if (child[0], child[1]) not in vector and (
                        child[0], child[1]) not in positions_bombs and (
                            child[0],
                            child[1]) not in positions_enemies and board1[
                                child[1] / self.config.TILE_SIZE][
                                    child[0] / self.config.
                                    TILE_SIZE].type == self.config.GROUND:
                    print child
                    ans += dfs(child, vector, depth - 1)
            vector.pop()
            if ans > 0:
                return 1
            else:
                return 0

        nPoint = userPosition.move((point[0], point[1]))
        t = board.getTile(nPoint)
        if not t.canBombPass() or (nPoint[0], nPoint[1]) in positions_enemies:
            return 0
        nPoint = (nPoint[0], nPoint[1])
        explored.append((userPosition[0], userPosition[1]))
        print explored
        val = dfs(nPoint, copy.deepcopy(explored), depth - 1)
        return val
Beispiel #3
0
    def moveToTile(self, board, traversal, endPoint):
        self.walk_path = []
        for location in traversal.findPath(self.location, endPoint):
            self.walk_path.append(board.getTile(location))

        nextColumn = self.walk_path[1].column
        nextRow = self.walk_path[1].row

        self.dir = findDir(self.location, (nextColumn, nextRow))

        self.walk_path = self.walk_path[1:]
        self.moving = True

        self.boardStatus = board.floating_tile
Beispiel #4
0
    def __init__(self, player=PLAYER1, file="person1.png", items=[1, 2, 3],
                 size=(32,48), location=(0,0), board=None, computer=True,
                 name="Computer1"):

        pygame.sprite.Sprite.__init__(self)
        self.walkCycle = [[], [], [], [], []]
        self.walk_path = []

        image = util.loadImage(file)
        for x in range(4):
            print x* size[0]
            print x*size[1]
            self.walkCycle[SOUTH].append(image.subsurface(
                pygame.Rect(x*size[0], 0*size[1], size[0], size[1])))
            self.walkCycle[WEST].append(image.subsurface(
                pygame.Rect(x*size[0], 1*size[1], size[0], size[1])))
            self.walkCycle[EAST].append(image.subsurface(
                pygame.Rect(x*size[0], 2*size[1], size[0], size[1])))
            self.walkCycle[NORTH].append(image.subsurface(
                pygame.Rect(x*size[0], 3*size[1], size[0], size[1])))

        self.items = items
        self.home = location
        self.name = name

        self.location = location
        self.dir = SOUTH
        self.frame = 0

        self.image = self.walkCycle[self.dir][self.frame]
        self.imageCopy = self.walkCycle[self.dir][self.frame]

        self.warping = False
        self.moving = False
        self.sliding = -1
        self.boardStatus = None

        tile = board.getTile(location)

        self.rect = self.image.get_rect()
        self.rect.center = tile.getTileLocation().center
        self.lastLocation = None

        self.board = board

        self.tick = 0