Python - speed up pathfinding
<p>This is my pathfinding function:</p>

<pre><code>def get_distance(x1,y1,x2,y2):
    neighbors = [(-1,0),(1,0),(0,-1),(0,1)]
    old_nodes = [(square_pos[x1,y1],0)]
    new_nodes = []
    for i in range(50):
        for node in old_nodes:
            if node[0].x == x2 and node[0].y == y2:
                return node[1]
            for neighbor in neighbors:
                try:
                    square = square_pos[node[0].x+neighbor[0],node[0].y+neighbor[1]]
                    if square.lightcycle == None:
                        new_nodes.append((square,node[1]))
                except KeyError:
                    pass
        old_nodes = []
        old_nodes = list(new_nodes)
        new_nodes = []
        nodes = []
    return 50
</code></pre>

<p>The problem is that the AI takes to long to respond( <em>response time &lt;= 100ms</em>)
This is just a python way of doing <a href="https://en.wikipedia.org/wiki/Pathfinding#Sample_algorithm" rel="nofollow">https://en.wikipedia.org/wiki/Pathfinding#Sample_algorithm</a></p>

<p>You should replace your algorithm with <a href="https://en.wikipedia.org/wiki/A*_search_algorithm" rel="nofollow">A*-search</a> with the Manhattan distance as a heuristic.</p>

python path-finding