Advertisement
Guest User

Untitled

a guest
Sep 10th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.23 KB | None | 0 0
  1. def open (file)
  2.     line = file.gets;
  3.     opencells = 0;
  4.     puts "this is reached"
  5.     puts "#{opencells}";
  6.     if line == nil then return end
  7.  
  8.     # read additional lines
  9.  
  10.     while line = file.gets do
  11.  
  12.         # begins with "path", must be path specification
  13.         if line[0...4] == "path"
  14.           p, name, x, y, ds = line.split(/\s/)
  15.  
  16.         # otherwise must be cell specification (since maze spec must be valid)
  17.         else
  18.             x, y, ds, w = line.split(/\s/,4)
  19.             #puts "cell spec: coordinates (#{x},#{y}) with dirs #{ds}"
  20.  
  21.             #check if all four walls are open
  22.             check = true;
  23.                 if ds.length == 4
  24.                     4.times do |i|
  25.                       case ds[i]
  26.                         when "u", "d", "l", "r"
  27.                             check = true;  
  28.                         else
  29.                             check = false;  
  30.                       end
  31.  
  32.                       if check == false
  33.                         break;
  34.                       end
  35.                     end
  36.                 end
  37.             if check == true
  38.                 opencells = opencells + 1;
  39.             end
  40.         end
  41.     end
  42.   puts "#{opencells}";
  43. end
  44.  
  45. open(maze_file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement