Class: Nonograms::Logic
- Inherits:
-
Object
- Object
- Nonograms::Logic
- Defined in:
- lib/nonograms/logic.rb
Instance Method Summary collapse
-
#cross_acceptable?(row, column) ⇒ Boolean
the vertical and the horizontal vectors have acceptable values.
-
#horizontal_acceptable?(row, column) ⇒ Boolean
the horizontal vector have acceptable values.
-
#initialize(horizontal, vertical) ⇒ Logic
constructor
A new instance of Logic.
- #matrix ⇒ Object
-
#vector_acceptable?(origin, piece) ⇒ Boolean
the vector have acceptable values * origin - vector base * piece - vector to verifi * return - true or false example: origin = [3, 2, 2]; piece = [3, 1]; return true origin = [3, 2, 2]; piece = [3, 3]; return false.
-
#vertical_acceptable?(row, column) ⇒ Boolean
the vertical vector have acceptable values.
Constructor Details
#initialize(horizontal, vertical) ⇒ Logic
Returns a new instance of Logic.
8 9 10 11 12 13 14 |
# File 'lib/nonograms/logic.rb', line 8 def initialize(horizontal, vertical) @vertical = vertical @horizontal = horizontal @amount_row = horizontal.length @amount_column = vertical.length @matrix = Nonograms::Matrix.new(@amount_row, @amount_column) end |
Instance Method Details
#cross_acceptable?(row, column) ⇒ Boolean
the vertical and the horizontal vectors have acceptable values
21 22 23 |
# File 'lib/nonograms/logic.rb', line 21 def cross_acceptable?(row, column) vertical_acceptable?(row, column) and horizontal_acceptable?(row, column) end |
#horizontal_acceptable?(row, column) ⇒ Boolean
the horizontal vector have acceptable values
35 36 37 38 39 40 41 |
# File 'lib/nonograms/logic.rb', line 35 def horizontal_acceptable?(row, column) unless column == @amount_column-1 vector_acceptable?( @horizontal[row], @matrix.count_horizontal(row) ) else return ( @horizontal[row] == @matrix.count_horizontal(row)) end end |
#matrix ⇒ Object
16 17 18 |
# File 'lib/nonograms/logic.rb', line 16 def matrix @matrix end |
#vector_acceptable?(origin, piece) ⇒ Boolean
the vector have acceptable values
-
origin - vector base
-
piece - vector to verifi
-
return - true or false
example: origin = [3, 2, 2]; piece = [3, 1]; return true origin = [3, 2, 2]; piece = [3, 3]; return false
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nonograms/logic.rb', line 50 def vector_acceptable?(origin, piece) return false if piece.length > origin.length piece.each_with_index do |value, index| if index == piece.length-1 return false unless origin[index] >= piece[index] else return false unless origin[index] == piece[index] end end return true end |
#vertical_acceptable?(row, column) ⇒ Boolean
the vertical vector have acceptable values
26 27 28 29 30 31 32 |
# File 'lib/nonograms/logic.rb', line 26 def vertical_acceptable?(row, column) unless row == @amount_row-1 vector_acceptable?( @vertical[column], @matrix.count_vertical(column) ) else return ( @vertical[column] == @matrix.count_vertical(column) ) end end |