Module: Binary_Puzzle_Solver

Defined in:
lib/binary_puzzle_solver/base.rb,
lib/binary_puzzle_solver/version.rb

Overview

Copyright © 2012 Shlomi Fish

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


This is the MIT/X11 Licence. For more information see:

  1. www.opensource.org/licenses/mit-license.php

  2. en.wikipedia.org/wiki/MIT_License

Defined Under Namespace

Classes: BaseClass, Board, Board_View, Cell, CellHandle, Coord, GameIntegrityException, Move, RowHandle, RowSummary

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.gen_board_from_string_v1(string) ⇒ Object



1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
# File 'lib/binary_puzzle_solver/base.rb', line 1118

def Binary_Puzzle_Solver.gen_board_from_string_v1(string)
    lines = string.lines.map { |l| l.chomp }
    line_lens = lines.map { |l| l.length }
    min_line_len = line_lens.min
    max_line_len = line_lens.max
    if (min_line_len != max_line_len)
        raise RuntimeError, "lines are not uniform in length"
    end
    width = min_line_len - 2
    height = lines.length

    board = Board.new(:x => width, :y => height)

    board.dim_range(:y).each do |y|
        l = lines[y]
        if not l =~ /^\|[01 ]+\|$/
            raise RuntimeError, "Invalid format for line #{y+1}"
        end
        board.dim_range(:x).each do |x|
            c = l[x+1,1]
            state = false
            if (c == '1')
                state = Cell::ONE
            elsif (c == '0')
                state = Cell::ZERO
            end

            if state
                board.set_cell_state(Coord.new(:x => x, :y => y), state)
            end
        end
    end

    return board
end