Compare commits

..

No commits in common. "ecb7cb59aa9a485411520baf84b4d9bca4cbc674" and "9dddc9363f5ec4b8b26e80f2ea6e418cbe659b03" have entirely different histories.

2 changed files with 16 additions and 6 deletions

View File

@ -138,14 +138,23 @@ class SourceCollector:
sn.dp = sn.val
sn.final_pos = sn.pos
sn.path = [sn]
# 先对子节点全部深搜一遍,收集路径长度
# 对子节点按收益/距离优先遍历
children = sn.children[:]
for child in children:
self.dfs(child)
children.sort(key=lambda c: len(c.path))
# 计算每个child的“贪心优先级”金币优先距离近优先
def child_priority(child):
# 距离=曼哈顿距离
dist = abs(child.pos[0] - sn.pos[0]) + abs(child.pos[1] - sn.pos[1])
# 金币优先,陷阱次之
if self.maze[child.pos[0]][child.pos[1]].startswith('g'):
return (0, dist) # 金币优先,距离近优先
elif self.maze[child.pos[0]][child.pos[1]].startswith('t'):
return (2, dist) # 陷阱最后
else:
return (1, dist) # 普通通路
children.sort(key=child_priority)
cur = None
for idx, child in enumerate(children):
self.dfs(child)
if child.dp > 0:
sn.dp += child.dp
if cur is not None:

View File

@ -378,8 +378,9 @@ def main():
print("\n读取的迷宫:")
reader.print_maze()
for i in generator.get_history_mazes():
for j in i:
for j in i :
print(j)
print()
if __name__ == "__main__":