Commits

Shlomi Fish  committed d5eec21

Got calc_riddle to pass.

  • Participants
  • Parent commits 1157c98

Comments (0)

Files changed (2)

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

             'clue No. 2+5 (x=0) is OK.'
         );
     });
+
+    test("calc_riddle", function() {
+        expect(1);
+        var gen = new ABC_Path.Generator.Generator({seed : 1});
+        var riddle = gen.calc_riddle();
+
+        // TEST
+        deepEqual(riddle.get_clues_for_input_to_board(),
+            {
+            clue_letter: 'A',
+            clue_letter_x: 1,
+            clue_letter_y: 3,
+            major_diagonal: ['Y', 'L'],
+            minor_diagonal: ['T', 'H'],
+            columns: [
+            ['G','E',],
+            ['B','X',],
+            ['J','C',],
+            ['N','Q',],
+            ['U','P',],
+            ],
+            rows: [
+            ['S','R',],
+            ['D','W',],
+            ['F','V',],
+            ['O','K',],
+            ['M','I',],
+            ],
+            }, 'clues for layout No. 1 are OK.');
+    });
 }

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

     methods: {
         get_clues_for_input_to_board: function() {
             var that = this;
+
+            // Letter clues.
+            var l_clues = that.clues.map(function (clue) { 
+                return clue.map(function (l_idx) { return that.letters()[l_idx-1];});
+            });
+
             return {
                 clue_letter: 'A',
                 clue_letter_x: that.A_pos[that.X()],
                 clue_letter_y: that.A_pos[that.Y()],
-                major_diagonal: that.clues[0],
-                minor_diagonal: that.clues[1],
-                rows: that.clues.slice(2, 2+5),
-                columns: that.clues.slice(2+5, 2+5+5)
+                major_diagonal: l_clues[0],
+                minor_diagonal: l_clues[1],
+                rows: l_clues.slice(2, 2+5),
+                columns: l_clues.slice(2+5, 2+5+5)
             };
         },
     },
             while (dfs_stack.length > 0) {
                 var last_state = dfs_stack[dfs_stack.length - 1];
 
-                if (! 'chosen_clue' in last_state) {
+                if (! ('chosen_clue' in last_state)) {
                     var clues = that._perl_range(0, that.NUM_CLUES()-1).map( function (idx) {
                         return [idx, last_state.clues[idx]];
                     }).filter( function (pair) {
-                        return (! 'cells' in pair[1]);
+                        return (! ('cells' in pair[1]));
                     }).sort( function (a,b) {
                         var aa = a[1].num_remaining ;
                         var bb = b[1].num_remaining ;
                                 return layout.get_cell_contents(idx);
                             });
                         };
-                        var riddle = ABC_Path.Generator.RiddleObj.new({
+                        var riddle = new ABC_Path.Generator.RiddleObj({
                             solution: layout,
                             clues: last_state.clues.map(handle_clue),
                             A_pos: that._to_xy(A_pos)
                     var clue_idx = clues[0][0];
                     last_state.chosen_clue = clue_idx;
 
-                    var positions = _clues_positions[clue_idx].filter ( function (x) {
+                    var positions = that._clues_positions[clue_idx].filter ( function (x) {
                         return ((last_state.pos_taken & (1 << x)) == 0);
                     });