|
@@ -90,21 +90,18 @@ while not distances.hasKey(targetNode):
|
90
|
90
|
|
91
|
91
|
distances[node] = distance
|
92
|
92
|
|
|
93
|
+ # At each node we can switch tools once, with a cost of 7 minutes
|
|
94
|
+ for tool in tools[erosions[node.pos] mod 3]:
|
|
95
|
+ if tool != node.tool and not distances.hasKey((node.pos, tool)):
|
|
96
|
+ stack.insert(((node.pos, tool)), distance + 7)
|
|
97
|
+
|
93
|
98
|
# Up to four possible moves from the current node, depending on
|
94
|
99
|
# terrain and tools.
|
95
|
100
|
for newPos in node.pos.moves:
|
96
|
|
- if erosions.hasKey(newPos) and not distances.hasKey((newPos, node.tool)):
|
97
|
|
- let targetTools = tools[erosions[newPos] mod 3]
|
98
|
|
- if node.tool in targetTools:
|
99
|
|
- # We have a tool that lets us pass, there's no point trying to
|
100
|
|
- # swap.
|
101
|
|
- stack.insert(((newPos, node.tool)), distance + 1)
|
102
|
|
- else:
|
103
|
|
- # See if we can switch to a compatible tool and treat it as
|
104
|
|
- # a single step.
|
105
|
|
- for newTool in targetTools:
|
106
|
|
- if newTool in tools[erosions[node.pos] mod 3]:
|
107
|
|
- stack.insert(((newPos, newTool)), distance + 8)
|
|
101
|
+ if erosions.hasKey(newPos) and
|
|
102
|
+ node.tool in tools[erosions[newPos] mod 3] and
|
|
103
|
+ not distances.hasKey((newPos, node.tool)):
|
|
104
|
+ stack.insert(((newPos, node.tool)), distance + 1)
|
108
|
105
|
|
109
|
106
|
echo dangerSum
|
110
|
107
|
echo distances[targetNode]
|