Class: PuzzleGenerator::Puzzle
- Inherits:
-
Object
- Object
- PuzzleGenerator::Puzzle
- Includes:
- DisplayMap
- Defined in:
- lib/puzzle_generator/puzzle.rb
Instance Attribute Summary collapse
-
#tried_duration ⇒ Object
readonly
Returns the value of attribute tried_duration.
-
#tried_times ⇒ Object
readonly
Returns the value of attribute tried_times.
Attributes included from DisplayMap
Instance Method Summary collapse
-
#generate ⇒ Object
start generate a puzzle with options that created this puzzle instance.
-
#initialize(option = {}) ⇒ Puzzle
constructor
create a puzzle with option.
Methods included from DisplayMap
Constructor Details
#initialize(option = {}) ⇒ Puzzle
create a puzzle with option. this won’t start generating, call Puzzle::generate to start generating.
15 16 17 18 |
# File 'lib/puzzle_generator/puzzle.rb', line 15 def initialize option = {} @option = DefaultOption.merge option @tried_times, @tried_duration = [0, 0], [0, 0] end |
Instance Attribute Details
#tried_duration ⇒ Object (readonly)
Returns the value of attribute tried_duration.
12 13 14 |
# File 'lib/puzzle_generator/puzzle.rb', line 12 def tried_duration @tried_duration end |
#tried_times ⇒ Object (readonly)
Returns the value of attribute tried_times.
12 13 14 |
# File 'lib/puzzle_generator/puzzle.rb', line 12 def tried_times @tried_times end |
Instance Method Details
#generate ⇒ Object
start generate a puzzle with options that created this puzzle instance.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/puzzle_generator/puzzle.rb', line 20 def generate raw_colors = (1..@option[:colors]).to_a step_colors = raw_colors.rotate make_chain make_color raw_colors until @result_color.result_map.kind_of? Array if step_colors == raw_colors make_chain make_color raw_colors step_colors = raw_colors.rotate else make_color step_colors step_colors.rotate! end end @result_map = @result_color.result_map end |