def getRoomTerrain(self, room, shard):

        if shard not in self.cache_terrain:
            self.cache_terrain[shard] = {}

        if room in self.cache_terrain[shard]:
            return self.cache_terrain[shard][room]

        terrain_list = screepsclient.room_terrain(room, shard=shard)
        screepsclient.api_error_except(terrain_list)
        terrain_matrix = {}
        for terrain in terrain_list['terrain']:
            if terrain['x'] not in terrain_matrix:
                terrain_matrix[terrain['x']] = {}

            if terrain['x'] in terrain_matrix and terrain[
                    'y'] in terrain_matrix[terrain['x']]:
                terrain_matrix[terrain['x']][terrain['y']] = 'wall'
            else:
                terrain_matrix[terrain['x']][terrain['y']] = terrain['type']

        for x in range(0, 50):
            if x not in terrain_matrix:
                terrain_matrix[x] = {}
            for y in range(0, 50):
                if y not in terrain_matrix[x]:
                    terrain_matrix[x][y] = 'plain'

        self.cache_terrain[shard][room] = terrain_matrix
        return terrain_matrix
    def getRoomList(self, shard, sector):
        p = re.compile('^(E|W)(\d+)(N|S)(\d+)$')
        matches = p.match(sector).groups()
        dir_x = matches[0]
        dir_y = matches[2]
        start_x = int(matches[1]) - 4
        start_y = int(matches[3]) - 4
        roomlist = []
        for x in range(start_x, start_x + 9):
            for y in range(start_y, start_y + 9):
                roomname = "%s%s%s%s" % (dir_x, x, dir_y, y)
                if x < 7 and y < 7:
                    if x > 3 and y > 3:
                        continue
                roomlist.append(roomname)
        mapstats = screepsclient.map_stats(roomlist, 'owner0', shard)
        screepsclient.api_error_except(mapstats)
        filteredroomlist = []
        for roomname in roomlist:
            sys.stdout.write('.')
            sys.stdout.flush()
            if self.filterRoom(roomname, shard, mapstats):
                filteredroomlist.append(roomname)

        sys.stdout.write('\n')
        return filteredroomlist
 def getRoom(self, shard):
     sectors = screepsclient.world_start_room(shard=shard)['room']
     screepsclient.api_error_except(sectors)
     while True:
         sector = sectors.pop()
         rooms = self.getRoomList(shard, sector)
         if len(rooms) < 1:
             if len(sectors) < 1:
                 return False
             continue
         rooms = self.sortRooms(rooms)
         return rooms[0]
 def getBannedRooms(self, shard):
     if not self.banned_rooms:
         self.banned_rooms = screepsclient.respawn_prohibited_rooms(
             shard=shard)['rooms']
         screepsclient.api_error_except(self.banned_rooms)
     return self.banned_rooms