示例#1
0
    def to_move(self, tile):
        (tx, ty) = tup(tile)
        (x, y) = tup(self.m.robot)

        if tx < x:
            return MT.LEFT
        if tx > x:
            return MT.RIGHT
        if ty < y:
            return MT.DOWN
        if ty > y:
            return MT.UP
示例#2
0
    def next_move(self, m, v):

        self.m = m
        self.v = v

        adj_tiles = self.get_adjacent_tiles()
        lambdas = self.get_all_lambdas()

        best_dist = sys.maxint + 1
        best_tile = None

        for (direction, tx, ty) in adj_tiles:
            dist = 0
            for (lx, ly) in lambdas:
                dist += self.get_man_dist(
                    (tx, ty), (lx, ly)
                )  # use sum dist to all lambdas as heuristic for how bad this position is
            if dist < best_dist:
                best_dist = dist
                best_tile = (direction, tx, ty)

        assert best_tile != None, "GreedyBot doesn't know where to go!"

        (rx, ry) = tup(self.m.robot)
        (direction, tx, ty) = best_tile

        return direction
示例#3
0
    def next_move(self, m, v):
        self.m = m
        self.v = v

        (rx, ry) = tup(self.m.robot)

        if not self.path:  # if path is empty, reset to oblivious state
            self.state = BotState.OBLIVIOUS

        if self.m.water >= ry:
            if self.m.wetness == self.m.waterproof:
                return MT.ABORT                     # abort before death
            elif self.state != BotState.SWIMMING:
                self.find_escape_path()

                if not self.path:                   # abort if found nothing
                    return MT.ABORT
                else:
                    self.path.reverse()             # reverse because it's faster to pop list
                    self.path.pop()
                self.state = BotState.SWIMMING
                return self.to_move(self.path.pop())
            elif self.state == BotState.SWIMMING:
                return self.to_move(self.path.pop())
        else:
            return MT.WAIT
示例#4
0
 def walkable(self, tile):
     (x, y) = tup(tile)
     return True if x < w() and x >= 0 and y < h() and y >= 0 and\
                    self.v.get(num(x, y)) != TileType.WALL    and\
                    self.v.get(num(x, y)) != TileType.ROCK    and\
                    self.v.get(num(x, y)) != TileType.CLL        \
                 else False
示例#5
0
    def next_move(self):

        (rx, ry) = tup(self.m.robot)

        # if path is empty, go to oblivious state
        if not self.path:
            self.state = BotState.OBLIVIOUS

        if self.m.water >= ry:
            if self.m.wetness == self.m.waterproof:  # abort before death
                return MT.ABORT

            elif self.state != BotState.SWIMMING:
                self.state = BotState.SWIMMING
                self.find_escape_path()
                if not self.path:  # abort if found nothing
                    return MT.ABORT
                else:
                    self.path.reverse()  # reverse path because it's faster to pop list
                    self.path.pop()
                return self.to_move(self.path.pop())

            elif self.state == BotState.SWIMMING:
                return self.to_move(self.path.pop())

        else:
            return MT.WAIT
示例#6
0
 def walkable(self, tile):
     (x, y) = tup(tile)
     tile_type = self.v.get(tile)
     return 0 <= x < w() and \
         0 <= y < h() and \
         tile_type != TT.WALL and \
         tile_type != TT.ROCK and \
         tile_type != TT.CLL
示例#7
0
    def get_adjacent_tiles(self):  # returns set of tuples (direction, tile x, tile y)
        (rx, ry) = tup(self.m.robot)

        adj_set = set()

        if self.walkable(rx - 1, ry):  # left
            adj_set.add((MT.LEFT, rx - 1, ry))
        if self.walkable(rx + 1, ry):  # right
            adj_set.add((MT.RIGHT, rx + 1, ry))
        if self.walkable(rx, ry - 1):  # down
            adj_set.add((MT.DOWN, rx, ry - 1))
        if self.walkable(rx, ry + 1):  # up
            adj_set.add((MT.UP, rx, ry + 1))

        return adj_set
示例#8
0
    def get_adjacent_tiles(self):
        (rx, ry) = tup(self.m.robot)

        adj_set = set()

        if self.walkable(rx - 1, ry):  # left
            adj_set.add((MT.LEFT, rx - 1, ry))
        if self.walkable(rx + 1, ry):  # right
            adj_set.add((MT.RIGHT, rx + 1, ry))
        if self.walkable(rx, ry - 1):  # down
            adj_set.add((MT.DOWN, rx, ry - 1))
        if self.walkable(rx, ry + 1):  # up
            adj_set.add((MT.UP, rx, ry + 1))

        return adj_set
示例#9
0
 def get_all_lambdas(self):
     list_lambdas = set()
     for i in range(h() * w()):
         if self.v.get(i) == TileType.LAMBDA:
             list_lambdas.add(tup(i))
     return list_lambdas
示例#10
0
 def get_all_lambdas(self):
     list_lambdas = set()
     for i in range(h() * w()):
         if self.v.get(i) == TT.LAMBDA:
             list_lambdas.add(tup(i))
     return list_lambdas