Class: PuzzleGenerator::Map
- Inherits:
-
Object
- Object
- PuzzleGenerator::Map
- Includes:
- Enumerable, DisplayMap
- Defined in:
- lib/puzzle_generator/map.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#chains ⇒ Object
readonly
Returns the value of attribute chains.
Instance Method Summary collapse
-
#[](x, y = nil) ⇒ Object
NOTICE!! this is not view (reference).
- #[]=(x, y, v) ⇒ Object
- #break_chains(map, result_map) ⇒ Object
- #clone_with_map ⇒ Object
- #each ⇒ Object
- #each_column ⇒ Object
- #each_column_with_index ⇒ Object
- #each_with_index_2d ⇒ Object
-
#initialize(option = {}) ⇒ Map
constructor
A new instance of Map.
- #result_map ⇒ Object
- #to_a ⇒ Object
Methods included from DisplayMap
Constructor Details
#initialize(option = {}) ⇒ Map
Returns a new instance of Map.
15 16 17 18 19 |
# File 'lib/puzzle_generator/map.rb', line 15 def initialize option = {} @option = DefaultOption.merge option @data = @option[:data] || (Array.new(@option[:width])).map{ [0]*@option[:height] } @chains = @option[:chains] || [] end |
Instance Attribute Details
#chains ⇒ Object (readonly)
Returns the value of attribute chains.
13 14 15 |
# File 'lib/puzzle_generator/map.rb', line 13 def chains @chains end |
Instance Method Details
#[](x, y = nil) ⇒ Object
NOTICE!! this is not view (reference)
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/puzzle_generator/map.rb', line 24 def [] x, y = nil if y.nil? @data[x] else if x.kind_of? Range @data[x].transpose[y] else @data[x][y] end end end |
#[]=(x, y, v) ⇒ Object
35 |
# File 'lib/puzzle_generator/map.rb', line 35 def []= x, y, v; @data[x][y] = v; end |
#break_chains(map, result_map) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/puzzle_generator/map.rb', line 49 def break_chains map, result_map @temp_map = map @temp_result_map = result_map result = [] map.each_column_with_index{ |column, ix| column.each_with_index{ |y, iy| result << [ix, iy] if y != 0 } } # e.g., [[0, 0], [1, 1]] result = transform result, :with_belows, :with_directs, :to_chains, :strip_duplicated_chain, :strip_out_bounded_chain, :strip_overflow_chain, :strip_floating_chain @temp_result_map = nil @temp_map = nil result end |
#clone_with_map ⇒ Object
38 39 40 41 42 43 |
# File 'lib/puzzle_generator/map.rb', line 38 def clone_with_map Map.new @option.merge( :data => @data.transpose.map{ |row| row.map{ |i| yield i } }.transpose, :chains => chains ) end |
#each ⇒ Object
45 |
# File 'lib/puzzle_generator/map.rb', line 45 def each; @data.flatten.each{ |i| yield i }; end |
#each_column ⇒ Object
37 |
# File 'lib/puzzle_generator/map.rb', line 37 def each_column; @data.each{ |column| yield column }; end |
#each_column_with_index ⇒ Object
36 |
# File 'lib/puzzle_generator/map.rb', line 36 def each_column_with_index; @data.each_with_index{ |column, index| yield column, index }; end |
#each_with_index_2d ⇒ Object
46 47 48 |
# File 'lib/puzzle_generator/map.rb', line 46 def each_with_index_2d @data.transpose.each_with_index{ |row, y| row.each_with_index{ |i, x| yield i, x, y } } end |
#result_map ⇒ Object
14 |
# File 'lib/puzzle_generator/map.rb', line 14 def result_map; @data; end |
#to_a ⇒ Object
44 |
# File 'lib/puzzle_generator/map.rb', line 44 def to_a; @data.clone; end |