タグ

ブックマーク / branch14.org (1)

  • a star in ruby

    1 class AStar 2 3 def initialize(adjacency_func, cost_func, distance_func) 4 @adjacency = adjacency_func 5 @cost = cost_func 6 @distance = distance_func 7 end 8 9 def find_path(start, goal) 10 been_there = {} 11 pqueue = PriorityQueue.new 12 pqueue << [1, [start, [], 0]] 13 while !pqueue.empty? 14 spot, path_so_far, cost_so_far = pqueue.next 15 next if been_there[spot] 16 newpath = path_so_far + [

  • 1