aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2018-06-10 10:37:51 +1200
committerDevine Lu Linvega <[email protected]>2018-06-10 10:37:51 +1200
commit3d21b68431e1411ec06e93f502ec875bfb78d46a (patch)
tree49028f183778814d6adb8ff3233042d4293e7cfe
parent933d5708c62aecbf42c6d73dc28bd66717572b33 (diff)
downloadOrca-3d21b68431e1411ec06e93f502ec875bfb78d46a.tar.gz
Orca-3d21b68431e1411ec06e93f502ec875bfb78d46a.zip
Minor optimisations
-rw-r--r--desktop/sources/scripts/programs/_.js49
-rw-r--r--desktop/sources/scripts/programs/y.js2
2 files changed, 18 insertions, 33 deletions
diff --git a/desktop/sources/scripts/programs/_.js b/desktop/sources/scripts/programs/_.js
index c87d916..c2843e1 100644
--- a/desktop/sources/scripts/programs/_.js
+++ b/desktop/sources/scripts/programs/_.js
@@ -69,24 +69,9 @@ function Program_Default(x,y)
return pico.program.glyph_at(this.x+x,this.y+y) != "." ? {x:this.x+x,y:this.y+y,glyph:pico.program.glyph_at(this.x+x,this.y+y)} : null;
}
- this.neighbors = function()
+ this.neighbors = function(g)
{
- var a = [];
- if(pico.program.glyph_at(this.x+1,this.y) != "."){ a.push({x:this.x+1,y:this.y,glyph:pico.program.glyph_at(this.x+1,this.y)}); }
- if(pico.program.glyph_at(this.x-1,this.y) != "."){ a.push({x:this.x-1,y:this.y,glyph:pico.program.glyph_at(this.x-1,this.y)}); }
- if(pico.program.glyph_at(this.x,this.y+1) != "."){ a.push({x:this.x,y:this.y+1,glyph:pico.program.glyph_at(this.x,this.y+1)}); }
- if(pico.program.glyph_at(this.x,this.y-1) != "."){ a.push({x:this.x,y:this.y-1,glyph:pico.program.glyph_at(this.x,this.y-1)}); }
- return a;
- }
-
- this.neighbors_like = function(g)
- {
- var a = [];
- if(this.up(g)){ a.push(this.up(g)); }
- if(this.right(g)){ a.push(this.right(g)); }
- if(this.down(g)){ a.push(this.down(g)); }
- if(this.left(g)){ a.push(this.left(g)); }
- return a;
+ return [this.up(g),this.right(g),this.down(g),this.left(g)].filter(function(e){return e});
}
this.neighbors_unlike = function(g)
@@ -123,38 +108,38 @@ function Program_Default(x,y)
this.bang = function()
{
- var ns = this.neighbors_like("b");
+ var ns = this.neighbors("b");
for(id in ns){
var n = ns[id]
- if(!pico.program.glyph_like_at(n.x,n.y-1,"h")){
- return true // Special case, where H is found above B.
+ if(pico.program.glyph_at(n.x,n.y-1) != "h"){
+ return true;
}
}
return false;
}
- this.left = function(req = null)
+ this.left = function(target = null)
{
- var g = pico.program.glyph_at(this.x-1,this.y,req);
- return g != "." ? {x:this.x-1,y:this.y,glyph:g} : null;
+ var g = pico.program.glyph_at(this.x-1,this.y);
+ return g == target || !target ? {x:this.x-1,y:this.y,glyph:g} : null;
}
- this.right = function(req)
+ this.right = function(target)
{
- var g = pico.program.glyph_at(this.x+1,this.y,req);
- return g != "." ? {x:this.x+1,y:this.y,glyph:g} : null;
+ var g = pico.program.glyph_at(this.x+1,this.y);
+ return g == target || !target ? {x:this.x+1,y:this.y,glyph:g} : null;
}
- this.up = function(req)
+ this.up = function(target)
{
- var g = pico.program.glyph_at(this.x,this.y-1,req);
- return g != "." ? {x:this.x,y:this.y+1,glyph:g} : null;
+ var g = pico.program.glyph_at(this.x,this.y-1);
+ return g == target || !target ? {x:this.x,y:this.y-1,glyph:g} : null;
}
- this.down = function(req)
+ this.down = function(target)
{
- var g = pico.program.glyph_at(this.x,this.y+1,req);
- return g != "." ? {x:this.x,y:this.y-1,glyph:g} : null;
+ var g = pico.program.glyph_at(this.x,this.y+1);
+ return g == target || !target ? {x:this.x,y:this.y+1,glyph:g} : null;
}
this.docs = function()
diff --git a/desktop/sources/scripts/programs/y.js b/desktop/sources/scripts/programs/y.js
index e4a0af4..3e54a21 100644
--- a/desktop/sources/scripts/programs/y.js
+++ b/desktop/sources/scripts/programs/y.js
@@ -7,7 +7,7 @@ function program_Y(x,y)
this.operation = function()
{
- var ns = this.neighbors_like("y")
+ var ns = this.neighbors("y")
// Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
if(ns.length == 1){