lib/crossyglot/formats/puz.rb
def renumber_cells(clues, min_word_length=2)
        num = 0
        # make sure we don't change original
        clues = clues.dup
        each_cell do |c, x, y|
          unless c.black?
            across = x == 0 || cell_at(x - 1, y).black?
            across &&= (min_word_length - 1).times.all? do |n|
              x1 = x + n + 1
              x1 < width && !cell_at(x1, y).black?
            end

            down = y == 0 || cell_at(x, y - 1).black?
            down &&= (min_word_length - 1).times.all? do |n|
              y1 = y + n + 1
              y1 < height && !cell_at(x, y1).black?
            end

            n = across || down ? num += 1 : nil

            c.across_clue = clues.shift  if across
            c.down_clue = clues.shift  if down

            c.number = n
          end
        end
      end
# (Re)assigns number, across_clue and down_clue to each non black cell based on their position
# in the grid and the minimum word length
(Re)assigns number, across_clue and down_clue to each non black cell based on their position
in the grid and the minimum word length
( Re ) assigns number across_clue and down_clue to each non black cell based on their position in the grid and the minimum word length
def renumber_cells(clues, min_word_length=2)
        num = 0
        clues = clues.dup
        each_cell do |c, x, y|
          unless c.black?
            across = x == 0 || cell_at(x - 1, y).black?
            across &&= (min_word_length - 1).times.all? do |n|
              x1 = x + n + 1
              x1 < width && !cell_at(x1, y).black?
            end
            down = y == 0 || cell_at(x, y - 1).black?
            down &&= (min_word_length - 1).times.all? do |n|
              y1 = y + n + 1
              y1 < height && !cell_at(x, y1).black?
            end
            n = across || down ? num += 1 : nil
            c.across_clue = clues.shift  if across
            c.down_clue = clues.shift  if down
            c.number = n
          end
        end
      end
def renumber_cells ( clues , min_word_length = 2 ) num = 0 clues = clues . dup each_cell do | c , x , y | unless c . black? across = x == 0 || cell_at ( x - 1 , y ) . black? across &&= ( min_word_length - 1 ) . times . all? do | n | x1 = x + n + 1 x1 < width && ! cell_at ( x1 , y ) . black? end down = y == 0 || cell_at ( x , y - 1 ) . black? down &&= ( min_word_length - 1 ) . times . all? do | n | y1 = y + n + 1 y1 < height && ! cell_at ( x , y1 ) . black? end n = across || down ? num += 1 : nil c . across_clue = clues . shift if across c . down_clue = clues . shift if down c . number = n end end end
(Re)assigns number, across_clue and down_clue to each non black cell based on their position
in the grid and the minimum word length
( Re ) assigns number across_clue and down_clue to each non black cell based on their position in the grid and the minimum word length
# make sure we don't change original
clues
min_word_length