Module: Castar
- Includes:
- Heyes
- Defined in:
- lib/castar.rb,
lib/castar/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .get_map_with_path(driver) ⇒ Object
- .get_path(driver) ⇒ Object
-
.init_map(options = {}) ⇒ Object
make all the following instance methods module methods.
- .load_map(mapfile) ⇒ Object
Class Method Details
.get_map_with_path(driver) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/castar.rb', line 56 def get_map_with_path(driver) path = get_path(driver) pathstr="\n" map = driver.getMap (0..map.height-1).each do |row| (0..map.width-1).each do |col| value = map.getCost(col,row) if(row==driver.nodeStart.y and col==driver.nodeStart.x) pathstr<<"|S" elsif(row==driver.nodeEnd.y and col==driver.nodeEnd.x) pathstr<<"|G" elsif(path.include?(:x => col, :y => row) ) pathstr<<"|*" else pathstr<<"|#{value}" end end pathstr<<"|\n" end return pathstr end |
.get_path(driver) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/castar.rb', line 48 def get_path(driver) path = []; (0..driver.getPathLength-1).each do |i| path << {:x => driver.getPathXAtIndex(i), :y => driver.getPathYAtIndex(i)} end path end |
.init_map(options = {}) ⇒ Object
make all the following instance methods module methods
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/castar.rb', line 11 def init_map( ={} ) defaults = {:width => 90, :height => 90} = defaults.merge() nrow = [:height] ncol = [:width] # set cost for each cell to 1 a = Array.new(nrow).fill( Array.new(ncol).fill(1) ) map = Map.new(ncol, nrow) a.each_with_index do |row, y| row.each_with_index do |cost, x| map.setCost(x,y,cost) end end return map end |
.load_map(mapfile) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/castar.rb', line 30 def load_map(mapfile) map = nil y = 0 File.open(mapfile) do |f| f.each_line do |line| entries = line.chomp.split(',') map ||= Castar::Map.new( entries.size, entries.size ) x = 0 line.chomp.split(',').each do |cost| map.setCost(x,y,cost.to_i) x += 1 end y += 1 end end return map end |