Commits

Shlomi Fish committed 82e007b

Add _clues_positions.

  • Participants
  • Parent commits cf88400

Comments (0)

Files changed (2)

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

         equal(calc_final_layout_string(final_layout), expected_string,
             'Layout with seed 25 is right.');
     });
+
+    test("_clues_positions", function() {
+        expect(1);
+
+        // The seed does not matter.
+        var gen = new ABC_Path.Generator.Generator({seed : 1});
+
+        var map_clue = function(clue) { return clue.map(function (i) { 
+            return gen._to_xy(i);
+        }) };
+
+        // TEST
+        deepEqual(map_clue(gen._clues_positions[0]), [[0,0],[1,1],[2,2],[3,3],[4,4]],
+            'clue No. 0 (diagonal) is OK.'
+        );
+    });
 }

abc-path/js/abc-path.js

         });
         },
         },
+        _clues_positions: { is: ro, init: function () {
+            var that = this;
+
+            var _gen_clue_positions = function (cb) {
+                return that._x_indexes().map(cb);
+            };
+
+            var _gen_clue_int_positions = function (cb) {
+                return _gen_clue_positions(cb).map(function (xy) { 
+                    return that._xy_to_int(xy); 
+                });
+            };
+
+            var callbacks = [].concat.apply([], [
+                    [function (i) { return [i,i]; }],
+                    [function (i) { return [i,4-i]; }],
+                    that._y_indexes().map(function (y) { 
+                        return function (x) { return [y,x]; };
+                    }),
+                    that._x_indexes().map(function (x) { 
+                        return function (y) { return [y,x]; };
+                    })]);
+
+            return callbacks.map(_gen_clue_int_positions);
+        }
+        },
     },
     methods: {
         _shuffle: function(deck) {