Commits

Shlomi Fish committed 9ab819b

Add _xy_loop.

Comments (0)

Files changed (2)

abc-path/js/abc-path-test.js

             '_calc_offset(20,3,2)'
         );
     });
+
+    test("Solver.Board _xy_loop", function() {
+        expect(1);
+
+        var myboard = new ABC_Path.Solver.Board({});
+
+        var result = [];
+
+        // TEST
+        equals(myboard._xy_loop(function(x,y) { 
+            result.push('' + y + ',' + x '');
+            return;
+        });
+
+        deepEqual(result, [
+            [ "0,0", "0,1", "0,2", "0,3", "0,4", ],
+            [ "1,0", "1,1", "1,2", "1,3", "1,4", ],
+            [ "2,0", "2,1", "2,2", "2,3", "2,4", ],
+            [ "3,0", "3,1", "3,2", "3,3", "3,4", ],
+            [ "4,0", "4,1", "4,2", "4,3", "4,4", ],
+        ],
+        '_xy_loop works.'
+        );
+
+    });
+
+
 }

abc-path/js/abc-path.js

         },
         _layout: {
             is: 'rw',
-            init: '',
+            init: function() { return [];},
         },
     },
     methods: {
         _calc_offset: function(letter, x, y) {
             return letter * this.BOARD_SIZE() + this._xy_to_int([y,x]);
         },
+        _get_verdict: function(letter, x, y) {
+            return this.getLayout()[this._calc_offset(letter, x, y)];
+        },
+        _set_verdict: function(letter, x, y, verdict) {
+
+            if (! ( 
+                        ( verdict == this.ABCP_VERDICT_NO() )
+                    ||
+                    (verdict == this.ABCP_VERDICT_MAYBE())
+                    ||
+                    (verdict == this.ABCP_VERDICT_YES())
+                  )
+               )
+            {
+                throw "Invalid verdict " + verdict + ".";
+            }
+
+            this.getLayout()[this._calc_offset(letter, x, y)] = verdict;
+
+            return;
+        },
+        _xy_loop: function(sub_ref) {
+
+            var y_indexes = this._y_indexes();
+            var x_indexes = this._x_indexes();
+
+            for var y_ (y_indexes)
+            {
+                var y = y_indexes[y_];
+                if (this.getError())
+                {
+                    return;
+                }
+                for var x_ (x_indexes)
+                {
+                    var x = x_indexes[x_]
+                    if (this.getError())
+                    {
+                        return;
+                    }
+                    
+                    sub_ref(x,y);
+                }
+            }
+            return;
+        },
     },
 });
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.