Commits

Shlomi Fish committed 85a00c0

Implement the _get_next_cells.

  • Participants
  • Parent commits e7c5c42

Comments (0)

Files changed (2)

File abc-path/js/Makefile

 all:
 
 edit:
-	gvim -o abc-path.js abc-path-test.js ../Games-ABC_Path-Generator/t/ms-rand.t ../Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator/FinalLayoutObj.pm
+	gvim -o abc-path.js abc-path-test.js ../Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator.pm
 
 test:
 	firefox abc-path-test.html

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

         },
     },
 });
+Class('ABC_Path.Generator.Generator', {
+    isa: ABC_Path.Solver.Base,
+    has: {
+        seed: { is: rw },
+        rand: { is: rw, init: function () {
+            return new ABC_Path.MicrosoftRand({ seed : this.seed });
+        }
+        },
+        get_next_cells_lookup: { is: ro, init: function() {
+            var that = this;
+            return this._perl_range(0, this.BOARD_SIZE() - 1).map(function (cell) {
+                var s = that._to_xy(cell);
+                return [].concat.apply([], ([ [-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1] ].map(function(offsets) {
+                    var y = s[that.Y()]+offsets[that.Y()];
+                    var x = s[that.X()]+offsets[that.X()];
+                    return ((that._x_in_range(x) && that._y_in_range(y)) ? [that._xy_to_int([y,x])] : []);
+                })));
+        });
+        },
+        },
+    },
+    methods: {
+        _shuffle: function(deck) {
+            return this.rand.shuffle(deck);
+        },
+        _get_next_cells: function(l, init_idx) {
+            return this.get_next_cells_lookup[init_idx].filter(function (x)
+                {
+                    return (l.charCodeAt(x) == 0);
+                }
+            );
+        },
+    }
+});