本文整理汇总了Python中Map.Map.get_neighbors_static方法的典型用法代码示例。如果您正苦于以下问题:Python Map.get_neighbors_static方法的具体用法?Python Map.get_neighbors_static怎么用?Python Map.get_neighbors_static使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map.Map
的用法示例。
在下文中一共展示了Map.get_neighbors_static方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import get_neighbors_static [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)
示例2: score_point
# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import get_neighbors_static [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