kakuro-cross-sums / solver / ruby / kakuro-board.rb

shl...@b384bcd7-… a7b80b8 











































shl...@b384bcd7-… 128cef8 
shl...@b384bcd7-… a7b80b8 










shl...@b384bcd7-… 128cef8 
shl...@b384bcd7-… a7b80b8 







module Kakuro

    class Cell

        attr_reader :id

        def initialize(id, content)
            @id = id
            @is_solid = (content =~ /\\/)
        end

        def solid?
            return @is_solid
        end

    end

    class Board

        def initialize()
            @next_cell_id = 0
            @cells = Array.new

            @matrix = Array.new
            @height = nil
            @width = nil
        end

        def parse(board_string)
            board_string.split(/\n+/).each do |line|
                _parse_line(line)
            end
        end

        def _next_cell_id()
            ret = @next_cell_id
            @next_cell_id += 1
            return ret
        end

        def _parse_line(line)
            # TODO : Make sure the widths of all the lines are the same.
            width = 0
            row = []
            while line.sub!(/\A\s*\[([^\]]*)\]\s*/, "")
                content = $1

                cell = Cell.new(_next_cell_id(), content)

                @cells << cell

                width += 1

                row << cell.id
            end
            @width = width
            @matrix.push(row)
        end

        def cell_yx(row,col)
            return @cells[@matrix[row][col]];
        end

    end

end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.