class AStar::PriorityQueue

Public Class Methods

new(nodes=[]) click to toggle source
# File lib/ext/astar/priority_queue.rb, line 11
def initialize(nodes=[])
  @nodes=nodes
  #tie-breaker multiplier (tbmul) is 1+1/(the sqrt of the map size)
  @tbmul=1+1/(Math.sqrt(@nodes.size))
end

Public Instance Methods

find(node) click to toggle source
# File lib/ext/astar/priority_queue.rb, line 28
def find(node)
  #finds a node - requires that node implements ==
  @nodes.find {|x| x==node }
end
find_best() click to toggle source
# File lib/ext/astar/priority_queue.rb, line 20
def find_best
  #finds the best node, then pops it out
  best=@nodes.first
  @nodes.each do |node|
    if node.better?(best,@tbmul) then best=node end
  end
  remove(best)
end
method_missing(methodname, *args) click to toggle source
# File lib/ext/astar/priority_queue.rb, line 16
def method_missing(methodname, *args)
  #if in doubt, act like an array
  @nodes.send(methodname, *args)
end
remove(node) click to toggle source
# File lib/ext/astar/priority_queue.rb, line 33
def remove(node)
  #removes a node
  @nodes.delete(find(node))
end
to_s() click to toggle source
# File lib/ext/astar/priority_queue.rb, line 38
def to_s
  output=""
  @nodes.each {|e| output<<"#{e};"}
end