Commits

Anonymous committed 5cd67e3

Implement the all_coords instead of coords_loop

Comments (0)

Files changed (1)

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

             return @y_len-1
         end
 
-        def coords_loop
-            for y in (0 .. maxy()) do
-                for x in (0 .. maxx()) do
-                    yield [y,x]
+        class Coords_Loop
+            include Enumerable
+
+            def initialize(maxy, maxx) 
+                @maxy = maxy
+                @maxx = maxx
+            end
+
+            def each
+                ( 0 .. @maxy ).each do |y|
+                    ( 0 .. @maxx ).each do |x|
+                        yield [y,x]
+                    end
                 end
             end
         end
 
+        def all_coords
+            return Coords_Loop.new(maxy(), maxx())
+        end
+
         def loop_over_whites
-            coords_loop do |yx|
+            all_coords.each do |yx|
                 if cell_yx(yx).is_white() then
                     yield yx
                 end
             end
 
             def _calc_adjacent(board)
-                board.coords_loop do |yx|
+                board.all_coords.each do |yx|
                     # TODO : Write better. The loop with assignment 
                     # is ugly.
                     is_adj = false
             counter[DIR_X] = (0 .. @board.maxx).map { |x| Hash.new }
             counter[DIR_Y] = (0 .. @board.maxy).map { |y| Hash.new }
 
-            @board.coords_loop do |yx|
+            @board.all_coords.each do |yx|
                 val = @board.cell(0, yx).value
 
                 counter.set_val(yx, val)
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.