Sha256: b1fddeea34d4410633f4d45968ea0b7566bc82fcb34569a7f1b9435951d856e7
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
#!/usr/bin/env ruby require './lib/rmaze.rb' require 'optparse' options = { :width => 10, :height => 10, :format => :ascii, :algorithm => :backtrace } OptionParser.new do |opts| opts.banner = "Usage: rmaze [options]" opts.separator "" opts.separator "Basic options:" opts.on("-w", "--width width", "Specify the maze width (default: #{options[:width]})") do |width| options[:width] = width end opts.on("-h", "--height height", "Specify the maze height (default: #{options[:height]})") do |height| options[:height] = height end opts.on("-d", "--depth depth", "Specify the maze depth (default: #{options[:depth]})") do |depth| options[:depth] = depth end opts.on("-f", "--format format", "Specify the format output (default: #{options[:format]})") do |format| options[:format] = format.to_sym end opts.separator "" opts.separator "Algorithms:" opts.on("-b", "--backtrace", "Choose backtrace algorithm (default)") do |bt| options[:algorithm] = bt ? :backtrace : nil end end.parse! if not options[:depth] maze = Maze.new options[:width], options[:height] else maze = Maze.new options[:width], options[:height], options[:depth] end maze.set_raw_value_all 1 case options[:algorithm] when :backtrace backtrace = Backtrace.new maze backtrace.generate else $stderr.puts "Error: the algorithm must be set." exit -1 end case options[:format] when :ascii maze.matrix.each do |row| row = [row] if maze.dimensions.length == 2 row.each do |depth| puts depth.map(&:to_s).join(' ').gsub('0', ' ').gsub('1', '#') end end when :json puts maze.to_json end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rmaze-2.1.0 | bin/rmaze |