Commits

Anonymous committed 86470a8

Add the analyze XYX triads logic.

Quoting from the comment:

# This analyzes triads that look like 1-2-1 where if the 2 had been
# black then both 1's would have been white and so it must be white.

Now we are able to successfully solve the wikipedia board.

  • Participants
  • Parent commits 9deaf40

Comments (0)

Files changed (3)

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

         ops_list.addItem("analyze_sequences")
         ops_list.addItem("expand_white_regions")
         ops_list.addItem("analyze_single_value_L_shaped_corners")
+        ops_list.addItem("analyze_xyx_triads")
         ops_list.addItem("apply_a_single_move")
 
         connect(ops_list, SIGNAL('itemClicked(QListWidgetItem *)'), \

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

             end
         end
 
+        # This analyzes triads that look like 1-2-1 where if the 2 had been
+        # black then both 1's would have been white and so it must be white.
+        def analyze_xyx_triads()
+            b = @board
+            dirs_loop do |dir|
+                ( 0 .. b.row_max(dir) ).each do |y|
+                    ( 0 .. b.col_max(dir)-2 ).each do |x|
+                        val = lambda { |x1| return b.cell(dir,[y,x1]).value }
+                        if val.call(x) == val.call(x+2)
+                            add_move(
+                                dir, y, x+1, "white",
+                                "The Y in an XYX triad sequence should be white"
+                            )
+                        end
+                    end
+                end
+            end
+        end
+
         def analyze_single_value_L_shaped_corners()
 
             dir = DIR_X

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

         1.should == 1
     end
 end
+
+describe "Process for En-Wikipedia Board" do
+
+    before (:each) do
+
+        contents = [
+            [4,8,1,6,3,2,5,7,],
+            [3,6,7,2,1,6,5,4,],
+            [2,3,4,8,2,8,6,1,],
+            [4,1,6,5,7,7,3,5,],
+            [7,2,3,1,8,5,1,2,],
+            [3,5,6,7,3,1,8,4,],
+            [6,4,2,3,5,4,[7,HitoriSolver::Cell::WHITE],[8,HitoriSolver::Cell::WHITE],],
+            [8,7,1,4,2,[3,HitoriSolver::Cell::WHITE],[5,HitoriSolver::Cell::BLACK],[6,HitoriSolver::Cell::WHITE],],
+        ]
+
+        @board = HitoriSolver::Board.new(8,8, contents)
+
+        @process = HitoriSolver::Process.new(@board)
+    end
+
+    it "should analyze XYX triads properly" do
+        # http://www.menneske.no/hitori/5x5/eng/showpuzzle.html?number=1
+        #
+        board = @board
+        process = @process
+
+        process.analyze_xyx_triads()
+        process.moves[0].is_yx_col([2,4],"white")
+
+    end
+end