Ich muss leider nocheinmal nachhaken.
Ich habe nun ein paar Änderungen an meinem Script vorgenommen, muss jetzt allerdings feststellen, dass das Pathfinding nichtmehr richtig funktioniert.
Der Weg wird zwar gefunden, doch mit absoluter Sicherheit nicht der kürzeste Weg.
Das Problem liegt darin, dass die Einheiten nun zufällige Zickzackrouten zu laufen scheinen. Manchmal gehen sie sogar einen Schritt zurück um danach wieder forwärts zu gehen.

Noch ein Hinweis, dieses Verhalten taucht nur bei längeren Strecken auf, bei kurzen Pfaden von 3 oder 4 Nodes ist kein Problem erkennbar, sobald allerdings viele Kurven genommen werden müssen und der Weg länger wird dann nimmt auch die Genauigkeit des Pathfindings ab.

Vielleicht habe ich mich einmal wieder irgendwo vertan?
(An den nodes wurde keinerlei relevante Veränderung vorgenommen)
Hier das neue Script:
Code:
module Pathfinding
  module_function
  
  def node_list= (node_list)
    @node_list = node_list
  end
  
  def find_path(start_node, to_tile_x, to_tile_y)
    #array of all nodes which have not been expanded yet
    open_nodes = [start_node]
    
    current_node = start_node
    loop do
      #end if no nodes can be expanded anymore == no path found
      if open_nodes.size == 0
        self.cleanup
        return nil
      end
      if current_node.x == to_tile_x && current_node.y == to_tile_y
        final_node = current_node
        #break if the final node has been reached
        break
      else
        #expand the current node
        self.expand_node(current_node,open_nodes,to_tile_x,to_tile_y)
        #the next node to be expanded is the node with the best value
        current_node = open_nodes[0]
        for node in open_nodes
          if current_node.approx_value > node.approx_value
            current_node = node
          end
        end
        #current_node = open_nodes.max{|ary,node| node.approx_value}
      end
    end
    #get the move route, an array containing the nodes to move along in order
    move_route = self.generate_move_route(start_node,final_node)
    #reset all data for the next task
    self.cleanup
    return move_route
  end
  
  def expand_node(current_node,open_nodes,to_tile_x,to_tile_y)
    #iterate through every adjacent node of the current node and add it to the open_nodes array
    for node in current_node.adjacent_nodes
      #if the node is already closed it cannot be opened again
      #if the node has an exact value it has been expanded already
      next if node.closed || node.exact_value != 0
      #calculate the approximated distance to the end node
      distance_x = node.x - to_tile_x
      distance_y = node.y - to_tile_y
      approx_distance = distance_x.abs + distance_y.abs
      
      #the exact costs to reach this node
      exact_value = current_node.exact_value + node.cost
      #the approximated costs from this node to the end node
      approx_value = exact_value + approx_distance * Node::MINIMAL_SPEED_FACTOR
      
      node.exact_value = exact_value
      node.approx_value = approx_value
      node.predecessor = current_node
      open_nodes.push(node)
    end
    #after a node has been expanded it is closed
    open_nodes.delete(current_node)
    current_node.closed = true
  end
  
  def cleanup
    #iterate through every node and reset its data
    for node in @node_list
      node.closed = false
      node.exact_value = 0
      node.approx_value = 999999
      node.predecessor = nil
    end
  end
  
  def generate_move_route(start_node,end_node)
    #the move_route is an array containing the locations of all nodes
    move_route = [end_node]
    predecessor = end_node.predecessor
    loop do
      if predecessor.nil?
        break 
      end
      move_route.insert(0,predecessor)
      predecessor = predecessor.predecessor
      if predecessor == start_node
        break
      end
    end
    return move_route
  end
  
end
Ich bitte nochmals um Hilfe.