1. Shlomi Fish
  2. abc-path

Commits

Shlomi Fish  committed 315dba4

[JS] Implement _calc_offset and other methods.

  • Participants
  • Parent commits cd3d866
  • Branches default

Comments (0)

Files changed (2)

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

View file
  • Ignore whitespace
         // TEST
         equals(myboard.getIter_changed(), 2, 'iter_changed is 2 after two _add_move-s.');
     });
+
+    test("Solver.Board _calc_offset", function() {
+        expect(2);
+
+        var myboard = new ABC_Path.Solver.Board({});
+
+        // TEST
+        equals(myboard._calc_offset(0, 0, 0), 0*25+0*5+0, 
+            '_calc_offset(0,0,0)'
+        );
+
+        // TEST
+        equals(myboard._calc_offset(20, 3, 2), 20*25+2*5+3, 
+            '_calc_offset(20,3,2)'
+        );
+    });
 }

File abc-path/js/abc-path.js

View file
  • Ignore whitespace
             is: 'rw',
             init: undefined,
         },
+        _successful_layouts: {
+            is: 'rw',
+            init: function() { return [];},
+        },
+        _layout: {
+            is: 'rw',
+            init: '',
+        },
     },
     methods: {
         ABCP_VERDICT_NO: function() {
             this._inc_changed();
             return;
         },
+        get_successful_layouts: function() {
+            // slice(0) performs a shallow copy.
+            return this.getSuccesful_layouts().slice(0);
+        },
+        _l_indexes: function() {
+            return this._perl_range(0, this.ABCP_MAX_LETTER());
+        },
+        _calc_offset: function(letter, x, y) {
+            return letter * this.BOARD_SIZE() + this._xy_to_int([y,x]);
+        },
     },
 });