171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/game/map/map.rb', line 171
def astar(node_start, node_goal)
iterations = 0
open = AStar::PriorityQueue.new()
closed = AStar::PriorityQueue.new()
node_start.calc_h(node_goal)
open.push(node_start)
costmap = generate_costmap
while !open.empty? do
iterations += 1
node_current = open.find_best
if node_current == node_goal
return node_current
end
generate_successor_nodes(node_current, costmap) { |node_successor|
node_successor.calc_g(node_current)
if open_successor=open.find(node_successor) then
if open_successor<=node_successor then next end
end
if closed_successor=closed.find(node_successor) then
if closed_successor<=node_successor then next end
end
open.remove(node_successor)
closed.remove(node_successor)
node_successor.parent=node_current
node_successor.calc_h(node_goal)
open.push(node_successor)
}
closed.push(node_current)
end
end
|