Commits

Anonymous committed 87f6459

cell_yx now accepts a coords array ref instead of two separate arguments.

  • Participants
  • Parent commits 47342e2

Comments (0)

Files changed (2)

File hitori-solver-in-ruby/hitori-solver.rb

             @cells = board
         end
 
-        def cell_yx(y,x)
+        def cell_yx(yx)
+            y, x = yx
             return @cells[y][x]
         end
 
         def cell(dir, coords)
             if dir == DIR_X then
-                return cell_yx(coords[0], coords[1])
+                return cell_yx(coords)
             else
-                return cell_yx(coords[1], coords[0])
+                return cell_yx(coords.reverse)
             end
         end
 
 
         def loop_over_whites
             coords_loop do |yx|
-                if cell_yx(*yx).is_white() then
+                if cell_yx(yx).is_white() then
                     yield yx
                 end
             end
                     if (! is_adj) then
                         next
                     end
-                    if board.cell_yx(*yx).is_black() then
+                    if board.cell_yx(yx).is_black() then
                         @adjacent_blacks[yx] = true
-                    elsif board.cell_yx(*yx).is_unknown() then
+                    elsif board.cell_yx(yx).is_unknown() then
                         @adjacent_unknowns[yx] = true
                     end
                 end
         def _find_adjacent_regions(yx)
             found_regions = []
             Offset_Module::Prev_Offsets.loop(yx, @board) do |new_yx|
-                if ! @board.cell_yx(*new_yx).is_white() then
+                if ! @board.cell_yx(new_yx).is_white() then
                     next
                 end
                 found_regions << @cells_map[new_yx]
 
         def _apply_black_move(move)
             yx = [move.y, move.x]
-            if !@board.cell_yx(*yx).mark_as_black() then
+            if !@board.cell_yx(yx).mark_as_black() then
                 return false
             end
             Offset_Module::Offsets.loop(yx, @board) do |new_yx|
 
         def _apply_white_move(move)
             yx = [move.y, move.x]
-            if (!@board.cell_yx(*yx).mark_as_white())
+            if (!@board.cell_yx(yx).mark_as_white())
                 return false
             end
-            val = @board.cell_yx(*yx).value
+            val = @board.cell_yx(yx).value
             # Look for identical values in the same x/y
             # and mark them as black.
             for dir in [ DIR_X, DIR_Y ] do

File hitori-solver-in-ruby/t/parse-board.rb

             [2,5,1,4,3]
         ]
         board = HitoriSolver::Board.new(5, 5, contents)
-        board.cell_yx(0,0).value.should == 2
-        board.cell_yx(0,1).value.should == 1
-        board.cell_yx(0,2).value.should == 3
-        board.cell_yx(4,2).value.should == 1
+        board.cell_yx([0,0]).value.should == 2
+        board.cell_yx([0,1]).value.should == 1
+        board.cell_yx([0,2]).value.should == 3
+        board.cell_yx([4,2]).value.should == 1
         board.cell(0, [0,1]).value.should == 1
         board.cell(1, [0,1]).value.should == 4        
     end
         process.moves[0].is_yx_col([3,2],"black");
 
         process.apply_a_single_move()
-        board.cell_yx(3,2).state.should == HitoriSolver::Cell::BLACK
+        board.cell_yx([3,2]).state.should == HitoriSolver::Cell::BLACK
 
         process.moves.length().should == 4
         process.moves[0].is_yx_col([2,2],"white")
         process.apply_a_single_move()
         process.moves.length().should == 3
 
-        board.cell_yx(2,2).state.should == HitoriSolver::Cell::WHITE
+        board.cell_yx([2,2]).state.should == HitoriSolver::Cell::WHITE
 
         # (y,x) = 3,1 ; color = white
         process.apply_a_single_move()
         process.moves.length().should == 3
 
-        board.cell_yx(3,1).state.should == HitoriSolver::Cell::WHITE
+        board.cell_yx([3,1]).state.should == HitoriSolver::Cell::WHITE
         process.moves[0].is_yx_col([3,3],"white")
         process.moves[1].is_yx_col([4,2],"white")
         process.moves[2].is_yx_col([2,1],"black")
         board = @board
         process = @process
 
-        board.cell_yx(0,0).value.should == 2
-        board.cell_yx(0,0).state.should == HitoriSolver::Cell::BLACK 
+        board.cell_yx([0,0]).value.should == 2
+        board.cell_yx([0,0]).state.should == HitoriSolver::Cell::BLACK 
 
-        board.cell_yx(0,1).value.should == 1
-        board.cell_yx(0,1).state.should == HitoriSolver::Cell::WHITE
+        board.cell_yx([0,1]).value.should == 1
+        board.cell_yx([0,1]).state.should == HitoriSolver::Cell::WHITE
 
-        board.cell_yx(1,0).value.should == 4
-        board.cell_yx(1,0).state.should == HitoriSolver::Cell::WHITE
+        board.cell_yx([1,0]).value.should == 4
+        board.cell_yx([1,0]).state.should == HitoriSolver::Cell::WHITE
 
-        board.cell_yx(1,2).value.should == 3
-        board.cell_yx(1,2).state.should == HitoriSolver::Cell::UNKNOWN
+        board.cell_yx([1,2]).value.should == 3
+        board.cell_yx([1,2]).state.should == HitoriSolver::Cell::UNKNOWN
 
     end