diff --git a/js/checking.js b/js/checking.js index 9cae265..63d3432 100644 --- a/js/checking.js +++ b/js/checking.js @@ -1,129 +1,52 @@ -function verticalScore(clock,side,index){ - var color = clock.blocks[side][index].color; - var upcount =0; - while(clock.blocks[side][index+upcount+1] !== undefined) { - if(clock.blocks[side][index+upcount+1].color == color) { - upcount++; +var deleting; +function search(twoD,oneD){ + for(var i=0;i=2){ - - return true; } return false; } -function horizontalScore(clock,side,index){ - var color = clock.blocks[side][index].color; - var upcount =0; - while(clock.blocks[(side+upcount+1)%clock.sides][index] !== undefined) { - if(clock.blocks[(side+upcount+1)%clock.sides][index].color == color) { - upcount++; - } - else { - break; +function floodFill(clock,side,index) { + if(clock.blocks[side] === undefined || clock.blocks[side][index] === undefined){return;} + var color = clock.blocks[side][index].color; + for(var x =-1;x<2;x++){ + for(var y =-1;y<2;y++){ + if(x==0 && y==0){continue;} + if(clock.blocks[(side+x+clock.sides)%clock.sides][index+y] !== undefined){ + if(clock.blocks[(side+x+clock.sides)%clock.sides][index+y].color== color && search(deleting,[(side+x+clock.sides)%clock.sides,index+y]) == -1){ + deleting.push([(side+x+clock.sides)%clock.sides,index+y]); + floodFill(clock,(side+x+clock.sides)%clock.sides,index+y); + } + } } } - var downcount =0; - while(clock.blocks[(side-downcount-1+clock.sides)%clock.sides][index] !== undefined) { - if(clock.blocks[(side-downcount-1+clock.sides)%clock.sides][index].color == color) { - downcount++; - } - else { - break; - } - } - if(downcount+upcount>=2){ - - return true; - } - return false; - } -function consolidateBlocks(clock, side, index) { - var sidesChanged = []; - if (clock.blocks[side][index] !== undefined){ - var color = clock.blocks[side][index].color; - var count =1; - if(verticalScore(clock,side,index)){ - console.log("hey"); - sidesChanged.push(side); - while(clock.blocks[side][index-count] !== undefined) { - if(clock.blocks[side][index-count].color == color) { - clock.blocks[side].splice(index-1,1); - index--; - } - else { - break; - } - } - var count=0; - while(clock.blocks[side][index+count] !== undefined) { - if(clock.blocks[side][index+count].color == color) { - clock.blocks[side].splice(index,1); - } - else { - break; - } - } - for(var i=index;i