2014-05-20 00:47:19 +00:00
|
|
|
function search(twoD,oneD){
|
|
|
|
for(var i=0;i<twoD.length;i++){
|
|
|
|
if(twoD[i][0] == oneD[0] && twoD[i][1] == oneD[1]) {
|
|
|
|
return true;
|
2014-05-19 14:36:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-05-17 16:39:49 +00:00
|
|
|
}
|
2014-05-24 16:48:46 +00:00
|
|
|
function floodFill(clock,side,index,deleting) {
|
2014-05-20 00:47:19 +00:00
|
|
|
if(clock.blocks[side] === undefined || clock.blocks[side][index] === undefined){return;}
|
2014-05-24 16:48:46 +00:00
|
|
|
var color = clock.blocks[side][index].color;
|
2014-05-20 00:47:19 +00:00
|
|
|
for(var x =-1;x<2;x++){
|
|
|
|
for(var y =-1;y<2;y++){
|
2014-05-20 21:09:39 +00:00
|
|
|
if(Math.abs(x)==Math.abs(y)){continue;}
|
2014-05-24 17:24:03 +00:00
|
|
|
var curSide =(side+x+clock.sides)%clock.sides;
|
2014-05-24 17:25:33 +00:00
|
|
|
var curIndex = index+y;
|
2014-05-24 17:24:03 +00:00
|
|
|
if(clock.blocks[curSide] === undefined){continue;}
|
|
|
|
if(clock.blocks[curSide][curIndex] !== undefined){
|
|
|
|
if(clock.blocks[curSide][curIndex].color == color && search(deleting,[curSide,curIndex]) === false) {
|
|
|
|
deleting.push([curSide,curIndex]);
|
|
|
|
floodFill(clock,curSide,curIndex,deleting);
|
2014-05-19 14:36:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-20 00:47:19 +00:00
|
|
|
}
|
|
|
|
function consolidateBlocks(clock,side,index){
|
|
|
|
var sidesChanged =[];
|
2014-05-24 16:48:46 +00:00
|
|
|
var deleting=[];
|
2014-05-20 00:47:19 +00:00
|
|
|
deleting.push([side,index]);
|
2014-05-24 16:48:46 +00:00
|
|
|
|
|
|
|
floodFill(clock,side,index,deleting);
|
2014-05-20 00:47:19 +00:00
|
|
|
var deleteList= deleting;
|
|
|
|
if(deleteList.length<3){return;}
|
2014-05-22 23:01:39 +00:00
|
|
|
var i;
|
2014-05-20 00:47:19 +00:00
|
|
|
for(i in deleteList){
|
|
|
|
var arr = deleteList[i];
|
|
|
|
if(arr !== undefined && arr.length==2) {
|
2014-05-22 23:01:39 +00:00
|
|
|
if(sidesChanged.indexOf(arr[0])==-1){
|
2014-05-20 00:47:19 +00:00
|
|
|
sidesChanged.push(arr[0]);
|
2014-05-19 14:36:13 +00:00
|
|
|
}
|
2014-05-20 20:48:11 +00:00
|
|
|
clock.blocks[arr[0]][arr[1]].deleted = 1;
|
2014-05-19 14:36:13 +00:00
|
|
|
}
|
2014-05-22 23:01:39 +00:00
|
|
|
}
|
2014-05-24 01:36:59 +00:00
|
|
|
|
2014-05-17 16:39:49 +00:00
|
|
|
}
|