Esempio n. 1
0
    def do(self, wrld):

        NotSetThisTime = True
        # Your code here
        if self.state is 'm' and NotSetThisTime:
            exit = [0, 0]
            #get current position
            meX = wrld.me(self).x
            meY = wrld.me(self).y

            #check every gridcell for the exit. Uses the last exit found as the "goal"
            for i in range(wrld.width()):

                for j in range(wrld.height()):

                    if wrld.exit_at(i, j):
                        exit = [i, j]

            #get the [x,y] coords of the next cell to go to
            goTo = greedyBFS.getNextStep([meX, meY], exit, wrld,1)
            if goTo is None:
                goTo = greedyBFS.getNextStep([meX, meY], exit, wrld,0)
                if wrld.wall_at(goTo[0],goTo[1]):
                    NotSetThisTime = False
                    self.state='b'
                    self.place_bomb()
                    self.bomb_at = [meX,meY]
                else:
                    self.move(-meX + goTo[0], -meY + goTo[1])

            else:
                self.move(-meX + goTo[0], -meY + goTo[1])
            #move in direction to get to x,y found in prev step

        if self.state is 'b' and NotSetThisTime:
            if (wrld.bomb_at(self.bomb_at[0],self.bomb_at[1]) is not None) or (wrld.explosion_at(self.bomb_at[0],self.bomb_at[1]) is not None):
                self.move(-1,-1)
            else:
                self.state = 'm'
    def greedy(self, wrld, exit, meX, meY):
        # Returns true if the character can be moved, false if not

        # Complete the greedy algorithm
        # Get the [x,y] coords of the next cell to go to
        goTo = greedyBFS.getNextStep([meX, meY], exit, wrld)

        if goTo is None:
            # TODO: Improve bomb placement and pathfinding combinations
            goTo = conn4.getNextStep([meX, meY], exit, wrld)
            if wrld.wall_at(goTo[0], goTo[1]):
                self.place_bomb()
            else:
                self.move(-meX + goTo[0], -meY + goTo[1])
        else:
            #move in direction to get to x,y found in prev step
            self.move(-meX + goTo[0], -meY + goTo[1])