Пример #1
0
def iceItUp(watl, terrainMap, terrainImagePixels):
    q = Queue()
    for w in watl:
        w.previous = True
        w.terrain = Terrain.ICE
        terrainImagePixels[w.coords] = Terrain.ICE.color()
        w.f = 0     
        q.put(w)
    while not q.empty():
        current = q.get()
        for n in getNeighbors(current, terrainMap):
            if not n.previous == True:
                n.visited = True
                if n.terrain == Terrain.WATER:
                    if current.f < 6:
                        n.terrain = Terrain.ICE
                        terrainImagePixels[n.coords] = Terrain.ICE.color()
                        n.f = current.f+1
                        q.put(n)
            else: #if it's already been visited
                if n.f > current.f+1 and current.f+1 < 6:
                    n.terrain = Terrain.ICE
                    terrainImagePixels[n.coords] = Terrain.ICE.color()
                    n.f = current.f+1
                    q.put(n)
Пример #2
0
def mudItUp(watl, terrainMap, terrainImagePixels):

    notMuddable = (Terrain.ROAD, Terrain.WATER, Terrain.NO_NO_ZONE)

    q = Queue()
    for w in watl:
        w.previous = True
        w.h = w.elevation #storing water level in the h slot
        w.f = 0
        q.put(w)
    while not q.empty():
        current = q.get()
        for n in getNeighbors(current, terrainMap):
            if not n.previous == True:
                n.visited = True
                if not n.terrain in notMuddable:
                    if current.f < 15 and n.elevation < current.h+1:
                        n.terrain = Terrain.MUD
                        terrainImagePixels[n.coords] = Terrain.MUD.color()
                        n.h = current.h
                        n.f = current.f+1
                        q.put(n)
            else: #if it's already been visited
                if n.f > current.f+1 and current.f+1 < 15 and n.elevation < current.h+1:
                    n.terrain = Terrain.MUD
                    terrainImagePixels[n.coords] = Terrain.MUD.color()
                    n.f = current.f+1
                    q.put(n)
Пример #3
0
def get_set_of_frontier_gridpos(nav, unknown):
    f = set()
    for nav_el in nav:
        neighbors = getNeighbors(nav_el)
        for n in neighbors:
            if n in unknown:
                f.add(nav_el)
                break
    return f
Пример #4
0
 def fill_frontier_mkii(self, start, set_of_frontier_gridpos, cluster=None):
     if cluster is None:
         cluster = set()
     set_of_frontier_gridpos.discard(start)
     cluster.add(start)
     neighbors = getNeighbors(start, set_of_frontier_gridpos)
     for n in neighbors:
         self.fill_frontier_mkii(n, set_of_frontier_gridpos, cluster)
     return cluster
    def runAway(self, wrld):
        # put current position into the path
        path = [customEntities.Node(self.x, self.y)]
        possibleNodes = []
        shouldRun = False

        # start by setting the lowest sum to infinity
        highestSum = -math.inf

        # get the set of neighbors, including ourself
        neighbors = astar.getNeighbors(self, customEntities.Node(7, 18), wrld)
        neighbors.append(customEntities.Node(self.x, self.y))

        # iterate over the available spots of the eight cardinal directions
        for node in neighbors:
            currSum = 0

            # if there's an explosion, don't add
            if wrld.explosion_at(node.x, node.y):
                continue

            shouldContinue = False

            # TODO account for other players bombs
            # do not include the nodes that would be in bomb's path of explosion
            if self.bombTimer <= 2 and self.bombPosition is not None:
                bombRange = wrld.expl_range
                for x in range(-bombRange, bombRange + 1):
                    if node.x == self.bombPosition.x + x and node.y == self.bombPosition.y:
                        shouldContinue = True
                        break

                for y in range(-bombRange, bombRange + 1):
                    if node.x == self.bombPosition.x and node.y == self.bombPosition.y + y:
                        shouldContinue = True
                        break
            if shouldContinue:
                continue

            node.hval = math.inf
            # for monster in monsterlist:
            for monster in self.monsters:
                pathBetweenSelfAndMonster = astar.calculateAStarPath(
                    node, monster, wrld, self.monsters, False)
                myDistance = len(
                    astar.calculateAStarPath(self, monster, wrld,
                                             self.monsters, False)[1])

                # if there is a path between myself and the monster
                if pathBetweenSelfAndMonster[0]:
                    distance = len(pathBetweenSelfAndMonster[1])
                    # distance = self.chebyshevDistance(node, monster, False)
                    if myDistance < self.distanceSmart and monster.type == "smart":
                        if distance < (self.distanceSmart - 1):
                            # try very hard not to get into detection range
                            currSum -= 5

                        elif distance < (self.distanceSmart - 2):
                            currSum -= 10
                            shouldRun = True

                        currSum += distance
                        node.hval = astar.manhattanDistance(node, monster)

                    elif myDistance < self.distanceStupid + 1:
                        currSum += distance
                        if distance < self.distanceStupid - 1:
                            shouldRun = True

            if currSum == highestSum:
                possibleNodes.append(node)

            elif currSum > highestSum:
                highestSum = currSum
                possibleNodes = [node]

        pathToStart = (astar.calculateAStarPath(self,
                                                customEntities.Node(5, 13),
                                                wrld, self.monsters, True))[1]
        self.calculateCharacterPath(customEntities.Node(7, 18), wrld, True)
        if not possibleNodes:
            # accept death.
            self.path = [
                customEntities.Node(self.x, self.y),
                customEntities.Node(self.x, self.y)
            ]
            return

        bestNode = None
        highestSum = -math.inf

        if shouldRun:
            for node in possibleNodes:
                if node.hval > highestSum:
                    bestNode = node
                    highestSum = node.hval

        if bestNode is None:
            # append possible nodes
            for node in possibleNodes:
                # if node is in the path to the end
                if len(self.path) > 1 and self.path[
                        1].x == node.x and self.path[1].y == node.y:
                    bestNode = node
                    break

        if bestNode is None:
            for node in possibleNodes:
                # if node is in the path to the start
                if len(pathToStart) > 1 and pathToStart[
                        1].x == node.x and pathToStart[1].y == node.y:
                    bestNode = node
                    break

        # if no node was added before, just add the first node
        if bestNode is not None:
            path.append(bestNode)
        else:
            path.append(possibleNodes[0])
        self.path = path
Пример #6
0
def tatfChecker(node,terrainMap):
    if node.terrain == Terrain.TRAIL:
        for n in getNeighbors(node, terrainMap):
            if n.terrain == Terrain.EASY_MOVE_FOREST:
                return True
    return False
Пример #7
0
def watlChecker(node, terrainMap):
    if node.terrain == Terrain.WATER:
        for n in getNeighbors(node, terrainMap):
            if not n.terrain == Terrain.WATER:
                return True
    return False