1. Cat's Eye Technologies
  2. Circute

Commits

catseye  committed d89cfd5

Regen js from latest alpaca version. Import yoob.js 0.2 Playfield.

  • Participants
  • Parent commits 2fcadf2
  • Branches default

Comments (0)

Files changed (3)

File demo/circute.html

View file
  • Ignore whitespace
   c.step = function() {
       var newPf = new yoob.Playfield();
       newPf.setDefault('Space');
-      pf.map(newPf, evalState, -1, -1, +1, +1);
+      evolve_playfield(pf, newPf);
       pf = newPf;
       var output = document.getElementById('output');
       output.innerHTML = pf.dump(dumper);

File demo/yoob/playfield.js

View file
  • Ignore whitespace
 /*
- * This file is part of yoob.js version 0.2-PRE
+ * This file is part of yoob.js version 0.2
  * This file is in the public domain.  See http://unlicense.org/ for details.
  */
 if (window.yoob === undefined) yoob = {};

File script/circute.js

View file
  • Ignore whitespace
  * EDIT AT YOUR OWN RISK!
  */
 
-Playfield = function() {
-    this._store = {};
-    this.min_x = undefined;
-    this.min_y = undefined;
-    this.max_x = undefined;
-    this.max_y = undefined;
-    this.default = undefined;
-
-    this.get = function(x, y) {
-        var state = this._store[x+','+y];
-        return state === undefined ? this.default : state;
-    };
-
-    this.put = function(x, y, value) {
-        if (value === this.default) {
-            delete this._store[x+','+y];
-        } else {
-            this._store[x+','+y] = value;
-        }
-    };
-
-    this.recalculate_limits = function() {
-        this.min_x = undefined;
-        this.min_y = undefined;
-        this.max_x = undefined;
-        this.max_y = undefined;
-
-        for (var cell in this._store) {
-            var pos = cell.split(',');
-            var x = parseInt(pos[0], 10);
-            var y = parseInt(pos[1], 10);
-            if (this.min_x === undefined || this.min_x > x)
-                this.min_x = x;
-            if (this.max_x === undefined || this.max_x < x)
-                this.max_x = x;
-            if (this.min_y === undefined || this.min_y > y)
-                this.min_y = y;
-            if (this.max_y === undefined || this.max_y < y)
-                this.max_y = y;
-        }
-    };
-};
 
 function in_nbhd_pred(pf, x, y, pred, nbhd) {
   var count = 0;
 }
 
 function evolve_playfield(pf, new_pf) {
-  for (var y = pf.min_y - 1; y <= pf.max_y - -1; y++) {
-    for (var x = pf.min_x - 1; x <= pf.max_x - -1; x++) {
-      new_pf.put(x, y, evalState(pf, x, y));
-    }
-  }
-  new_pf.recalculate_limits();
+  pf.map(new_pf, evalState, -1, -1, 1, 1);
 }
 function eval_Space(pf, x, y) {
 var id;