Sha256: 2c759f181a1fa60027105fe4c14f19e7170baa20f6ccfdcab85233ff2e8ace2d
Contents?: true
Size: 1.33 KB
Versions: 5
Compression:
Stored size: 1.33 KB
Contents
# alpha at 2007.10.14 require 'puzzle_generator/puzzle' require 'ludy/hash/reverse_merge' # require 'rubygems' if RUBY_VERSION < '1.9.0' # require 'facets/timer' require 'ludy/timer' # simple and stupid timer.... # puzzle generator for shooting-cubes[http://shooting-cubes.googlecodes.com], # example usage: # PuzzleGenerator.debug = true # pg = PuzzleGenerator::Puzzle.new :level => 4, :timeout => 2, :invoke_max => 5 # begin # pg.generate # pg.display_map # rescue Ludy::Timeout => e # puts e # ensure # p pg.tried_times # p pg.tried_duration # end module PuzzleGenerator def self.generate_chained_map option = {} #:nodoc: generate_klass ChainedMap, option end def self.generate_klass klass, option = {} #:nodoc: option.reverse_merge! :timeout => 5 generate(option[:timeout]){ klass.new option } end LastTriedInfo = {} # :nodoc: # generate someing with generator with timeout, used in Puzzle#generate def self.generate timeout = 5, &generator timer = Ludy::Timer.new(timeout).start tried_times = 1 begin result = generator.call until result.result_map.kind_of? Array tried_times += 1 result = generator.call end ensure # timer.stop LastTriedInfo.merge! :tried_times => tried_times, :tried_duration => timer.total_time end result end end
Version data entries
5 entries across 5 versions & 2 rubygems
Version | Path |
---|---|
godfat-ludy-0.1.13 | lib/puzzle_generator.rb |
ludy-0.1.15 | lib/puzzle_generator.rb |
ludy-0.1.10 | lib/puzzle_generator.rb |
ludy-0.1.11 | lib/puzzle_generator.rb |
ludy-0.1.13 | lib/puzzle_generator.rb |