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:
Defined Under Namespace
Classes: Board, Board_View, Cell, Coord, GameIntegrityException, Move, RowHandle, RowSummary
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Class Method Details
.gen_board_from_string_v1(string) ⇒ Object
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/binary_puzzle_solver/base.rb', line 680 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 |