diff options
Diffstat (limited to 'interactor/common.js')
-rw-r--r-- | interactor/common.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/interactor/common.js b/interactor/common.js index 65313ce..af7c462 100644 --- a/interactor/common.js +++ b/interactor/common.js @@ -16,6 +16,24 @@ function bdcopy(bd){ }); } +function checkwin(bd){ + var wincolour=-1,i; + for(i=0;i<W*H;i++){ + if(bd[~~(i/W)][i%W].n){ + if(wincolour==-1)wincolour=bd[~~(i/W)][i%W].c + else if(bd[~~(i/W)][i%W].c!=wincolour)return -1; + } + } + return wincolour; +} + +function countballs(bd){ + var count=0; + var x,y; + for(y=0;y<H;y++)for(x=0;x<W;x++)count+=bd[y][x].n; + return count; +} + function stabilise(bd){ var newbd; var changes; @@ -38,6 +56,7 @@ function stabilise(bd){ } } bd=newbd; + if(checkwin(bd)!=-1)break; } while(changes); return bd; } |