From e22b0edd4822ad5030d19d8fdb61511690e34239 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 23 Oct 2015 12:23:11 +0200 Subject: handwapper --- interactor/common.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 interactor/common.js (limited to 'interactor/common.js') diff --git a/interactor/common.js b/interactor/common.js new file mode 100644 index 0000000..dbc3484 --- /dev/null +++ b/interactor/common.js @@ -0,0 +1,43 @@ +var W=7,H=8; + +function emptyboard(){ + return new Array(H).fill(0).map(function(){ + return new Array(W).fill(0).map(function(){ + return {n:0,c:0}; + }); + }); +} + +function bdcopy(bd){ + return bd.map(function(r){ + return r.map(function(c){ + return {n:c.n,c:c.c}; + }); + }); +} + +function stabilise(bd){ + var newbd; + var changes; + var x,y,nnei,quo; + do { + changes=false; + newbd=bdcopy(bd); + for(y=0;y0)+(x>0)+(y=nnei){ + quo=~~(bd[y][x].n/nnei); + newbd[y][x].n-=quo*nnei; + if(y>0) {newbd[y-1][x].n+=quo;newbd[y-1][x].c=bd[y][x].c;} + if(x>0) {newbd[y][x-1].n+=quo;newbd[y][x-1].c=bd[y][x].c;} + if(y