当前位置: 首页>>代码示例>>Python>>正文


Python Map.point_to_index方法代码示例

本文整理汇总了Python中Map.Map.point_to_index方法的典型用法代码示例。如果您正苦于以下问题:Python Map.point_to_index方法的具体用法?Python Map.point_to_index怎么用?Python Map.point_to_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Map.Map的用法示例。


在下文中一共展示了Map.point_to_index方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import point_to_index [as 别名]
    def __init__(self, terrain_map):
        height = terrain_map.height
        width = terrain_map.width
        time0 = time()
        score_array = self.create_score_array(terrain_map, height, width)
        if PRINT_TIMING:
            print("\nScoreMap init", time() - time0)
        to_score = set()  # stores the next tiles to update score in a set
        curr_score = INITIAL_SCORE
        if PRINT_TIMING:
            time0 = time()
        # Set bottom row of scores to (1, [SOUTH]) or (NON_TRAVERSIBLE_SCORE, [])
        for i in range(width):
            p = Point(i, height - 1)
            ndx = Map.point_to_index(p, width, height)
            if self.needs_scoring(score_array, ndx):
                score_array[ndx] = ScoreTile(INITIAL_SCORE, [Directions.SOUTH])
                neighbors = Map.get_neighbors_static(p, width, height)
                for neighbor_key in neighbors:
                    neighbor_point = neighbors[neighbor_key]
                    if neighbor_point is not None:
                        neighbor_ndx = Map.point_to_index(neighbor_point, width, height)
                        if self.needs_scoring(score_array, neighbor_ndx):
                            to_score.add(neighbor_point)

        if PRINT_TIMING:
            print("ScoreMap add to bottom", time() - time0)
        #TODO check that this works
        # Start scoring all other tiles

        if PRINT_TIMING:
            time0 = time()
        while len(to_score) > 0:
            curr_score += 1
            currently_scoring = to_score
            to_score = set()
            for point in currently_scoring:
                ndx = Map.point_to_index(point, width, height)
                if self.needs_scoring(score_array, ndx):
                    score = self.score_point(score_array, point, curr_score, height, width)
                    score_array[ndx] = score
                    neighbors = Map.get_neighbors_static(point, width, height)
                    for neighbor_key in neighbors:
                        neighbor_point = neighbors[neighbor_key]
                        if neighbor_point is not None:
                            neighbor_ndx = Map.point_to_index(neighbor_point, width, height)
                            if self.needs_scoring(score_array, neighbor_ndx):
                                to_score.add(neighbor_point)

        if PRINT_TIMING:
            print("ScoreMap score rest", time() - time0)

        super(ScoreMap, self).__init__(score_array, width, height)
开发者ID:siegelhorn,项目名称:cs370-project,代码行数:55,代码来源:ScoreMap.py

示例2: create_score_array

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import point_to_index [as 别名]
 def create_score_array(self, terrain_map, height, width):
     score_array = [None] * (height * width)
     # Set scores of non traversable tiles to NON_TRAVERSABLE_SCORE
     for x in range(width):
         for y in range(height):
             p = Point(x, y)
             ndx = Map.point_to_index(p, width, height)
             t_tile = terrain_map.map[ndx]
             if not t_tile.is_traversable():
                 score_array[ndx] = ScoreTile(NON_TRAVERSABLE_SCORE, [])
     return score_array
开发者ID:siegelhorn,项目名称:cs370-project,代码行数:13,代码来源:ScoreMap_SharedMemory.py

示例3: get_all_traversable_states

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import point_to_index [as 别名]
 def get_all_traversable_states(self):
     states = []
     for x in range(self.width):
         for y in range(self.height):
             pnt = Point(x, y)
             ndx = Map.point_to_index(pnt, self.width, self.height)
             terrain = self.map[ndx]
             if terrain.is_traversable():
                 for dir in Directions:
                     state = State(pnt, dir)
                     states.append(state)
     return states
开发者ID:siegelhorn,项目名称:cs370-project,代码行数:14,代码来源:TerrainMap.py

示例4: score_point

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import point_to_index [as 别名]
 def score_point(self, score_array, point, score, height, width):
     result_score = ScoreTile(score, [])
     ndx = Map.point_to_index(point, width, height)
     neighbors = Map.get_neighbors_static(point, width, height)
     # TODO Test THIS directions and score from surrounding tiles
     # for neighbor_point in neighbors:
     #     neighbor_ndx = map.point_to_index(neighbor_point, width, height)
     #     neighbor_tile = score_array[neighbor_ndx]
     #     if neighbor_tile
     # for neighbor in neighbors:
     # print(neighbor)
     # print(neighbors[neighbor])
     for direction in Directions:
         neighbor_point = neighbors[direction]
         if neighbor_point is not None:
             neighbor_ndx = Map.point_to_index(neighbor_point, width, height)
             neighbor_tile = score_array[neighbor_ndx]
             if neighbor_tile is not None:
                 if neighbor_tile.score < score and neighbor_tile.score != -1:
                     result_score.directions.append(direction)
     return result_score
开发者ID:siegelhorn,项目名称:cs370-project,代码行数:23,代码来源:ScoreMap_SharedMemory.py

示例5: score_rest

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import point_to_index [as 别名]
    def score_rest(self, to_score, next_to_score, start_index, processor_count):

        for index in range(start_index, len(to_score), processor_count):
            Map.point_to_index(to_score[index], width, height)
开发者ID:siegelhorn,项目名称:cs370-project,代码行数:6,代码来源:ScoreMap_SharedMemory.py


注:本文中的Map.Map.point_to_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。