summaryrefslogtreecommitdiff
path: root/common.js
diff options
context:
space:
mode:
Diffstat (limited to 'common.js')
-rw-r--r--common.js43
1 files changed, 0 insertions, 43 deletions
diff --git a/common.js b/common.js
deleted file mode 100644
index dbc3484..0000000
--- a/common.js
+++ /dev/null
@@ -1,43 +0,0 @@
-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;y<H;y++){
- for(x=0;x<W;x++){
- nnei=(y>0)+(x>0)+(y<H-1)+(x<W-1);
- if(bd[y][x].n>=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<H-1){newbd[y+1][x].n+=quo;newbd[y+1][x].c=bd[y][x].c;}
- if(x<W-1){newbd[y][x+1].n+=quo;newbd[y][x+1].c=bd[y][x].c;}
- changes=true;
- }
- }
- }
- bd=newbd;
- } while(changes);
- return bd;
-}