All my secrets for winning MegaMinerAI 11 and 12. Despite giving away these secrets, I won MegaMinerAI 13 as well. Does that make this presentation a failure?
7. Breadth first search
open_queue = new queue(start)
closed_set = new set()
previous_map = new map()
while open_queue is not empty
current = open_queue.dequeue()
closed_set.add(current)
if current == end
return construct_path(end, previous_map)
else
for each n in neighbors_of(current)
if n not in closed_set
open_queue.enqueue(n)
previous_map.add(n, current)
9. BFS Dijkstra’s A*
Dijkstra’s is like breadth-first search except
• It can handle costs applied to steps
• get_cost(current, n)
A* is like Dijkstra’s except
• It can make better guesses about which way to
look first
• It does so by using a remaining-cost-heuristic
• calculate_h(n)
24. Why rewrite?
• When do you rewrite code?
• When it’s not correct
• When it’s not fast enough
• When it’s not giving the information you need
• When it’s not accepting the information you have
• When it’s not easy to use
• When it’s not easy to understand
• When it’s broken because of another rewrite
31. Conclusions
Write a flexible A*
• Multiple start points
• Multiple end points
• Configurable passability
• Configurable costs
32. Conclusions
Write code that doesn’t need rewriting
• Write tiny functions
• More correct
• More performant
• Write an input interface that doesn’t ask for extras
• More usable
• More understandable
• Provide output that is exactly what you’re willing to
support