Anonymous avatar Anonymous committed 47342e2

Add the analyze L-shaped corners - now the first board can be solved.

Comments (0)

Files changed (3)

hitori-solver-in-ruby/gui/qt/hitori-gui.rb

         ops_list = Qt::ListWidget.new
         ops_list.addItem("analyze_sequences")
         ops_list.addItem("expand_white_regions")
+        ops_list.addItem("analyze_single_value_L_shaped_corners")
         ops_list.addItem("apply_a_single_move")
 
         connect(ops_list, SIGNAL('itemClicked(QListWidgetItem *)'), \

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

         end
 
         def cell(dir, coords)
-            if dir == 0 then
+            if dir == DIR_X then
                 return cell_yx(coords[0], coords[1])
             else
                 return cell_yx(coords[1], coords[0])
             end
         end
 
+        def col_max(dir)
+            if (dir == DIR_X) then
+                return maxy()
+            else
+                return maxx()
+            end
+        end
+
 
         def in_bounds(y,x)
             return (   (0 <= y) && (y < @y_len) \
             end
         end
 
+        def analyze_single_value_L_shaped_corners()
+
+            dir = DIR_X
+
+            v = lambda { |yx| return @board.cell(dir, yx).value };
+
+            analyze_coords = lambda { |coords, two, three|
+                val = v.call(coords)
+                if ((val == v.call(two)) && (val == v.call(three)))
+                    add_move(
+                        dir, coords[0], coords[1], "black",
+                        "Single-value L-shaped corner must be white-black-white"
+                    )        
+                end
+            }
+
+            row = @board.row_max(dir)
+            col = @board.col_max(dir)
+
+            for c in [[1,0],[col-1,col]] do
+                for r in [[1,0], [row-1,row]] do
+                    analyze_coords.call(
+                        [c[0],r[0]],
+                        [c[1],r[0]],
+                        [c[0],r[1]]
+                    )
+                end
+            end
+        end
+
         def expand_white_regions()
             white_regions = WhiteRegions.new(@board)
 

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

     end
 
 end
+
+describe "single-digit-L-corner test" do
+
+
+    before (:each) do
+
+        contents = [
+            [[2,HitoriSolver::Cell::BLACK],[1,HitoriSolver::Cell::WHITE],3,2,4,],
+            [[4,HitoriSolver::Cell::WHITE],[5,HitoriSolver::Cell::WHITE],3,2,2,],
+            [[3,HitoriSolver::Cell::WHITE],[4,HitoriSolver::Cell::BLACK],[2,HitoriSolver::Cell::WHITE],5,1,],
+            [[1,HitoriSolver::Cell::WHITE],[4,HitoriSolver::Cell::WHITE],[3,HitoriSolver::Cell::BLACK],[3,HitoriSolver::Cell::WHITE],2,],
+            [[2,HitoriSolver::Cell::WHITE],[5,HitoriSolver::Cell::BLACK],[1,HitoriSolver::Cell::WHITE],[4,HitoriSolver::Cell::WHITE],3,],
+]
+
+        @board = HitoriSolver::Board.new(5, 5, contents)
+
+        @process = HitoriSolver::Process.new(@board)
+    end
+    
+    it "should process a single-digit L-shaped corner" do
+        # http://www.menneske.no/hitori/5x5/eng/showpuzzle.html?number=1
+        #
+        board = @board
+        process = @process
+
+        process.analyze_single_value_L_shaped_corners()
+
+        process.moves.length.should == 1
+        process.moves[0].is_yx_col([1,3],"black")
+    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.