why you no work

This commit is contained in:
Garrett Finucane 2014-05-19 20:47:19 -04:00
parent 4ca5d26df8
commit 9663294e1e
3 changed files with 65 additions and 112 deletions

View file

@ -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<twoD.length;i++){
if(twoD[i][0] == oneD[0] && twoD[i][1] == oneD[1]) {
return true;
}
else {
break;
}
}
var downcount =0;
while(clock.blocks[side][index-downcount-1] !== undefined) {
if(clock.blocks[side][index-downcount-1].color == color) {
downcount++;
}
else {
break;
}
}
if(downcount+upcount>=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<clock.blocks[side].length;i++) {
consolidateBlocks(clock,side,i);
}
}
function consolidateBlocks(clock,side,index){
for(var i=0;i<clock.sides.length;i++){
deleted.push(0);
}
if (clock.blocks[side][index] !== undefined){
if(horizontalScore(clock,side,index)){
sidesChanged.push(side);
console.log(sidesChanged);
var count=1;
var x=(side-count+clock.sides)%clock.sides;
while(clock.blocks[x][index] !== undefined) {
if(clock.blocks[x][index].color == color) {
sidesChanged.push(x);
clock.blocks[x].splice(index,1);
consolidateBlocks(clock,x,index);
count++;
}
else {
break;
}
x=(side-count+clock.sides)%clock.sides;
var sidesChanged =[];
deleting=[];
deleting.push([side,index]);
floodFill(clock,side,index);
debugger;
var deleteList= deleting;
if(deleteList.length<3){return;}
for(i in deleteList){
var arr = deleteList[i];
if(arr !== undefined && arr.length==2) {
if(sidesChanged.indexOf(arr[0])==-1){
sidesChanged.push(arr[0]);
}
var count=0;
var x = (side+count+clock.sides)%clock.sides;
while(clock.blocks[x][index] !== undefined) {
if(clock.blocks[x][index].color == color) {
sidesChanged.push(x);
clock.blocks[x].splice(index,1);
consolidateBlocks(clock,x,index);
count++;
}
else {
break;
}
x = (side+count+clock.sides)%clock.sides;
}
console.log(sidesChanged);
clock.blocks[arr[0]].splice(arr[1]-deleted[arr[0]],1);
deleted[arr[0]]++;
}
}
}
sidesChanged.forEach(function(o) {
MainClock.blocks[o].forEach(function(block) {
console.log('unsettled');
block.settled = 0;
})
});
}

6
js/checking_pseudo Normal file
View file

@ -0,0 +1,6 @@
use pre existing minimum
2 dimensional array that holds sides
get layer one get sides it applies to
do that again to all sides touching one level up that are the same color

24
js/hey.js Normal file
View file

@ -0,0 +1,24 @@
floodFill.deleted = [];
function floodFill(clock,side,index) {
if(clock.blocks[side] !== undefined){return;}
if(clock.blocks[side][index] !== undefined){return;}
var color = clock.blocks[side][index].color;
var arrX = [-1,0,1];
var arrY = [-1,0,1];
for( X in arrX){
for(Y in arrY){
var x = arrX[X];
var y = arrY[Y];
if(x==0 && y==0){return;}
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 && floodFill.deleted.indexOf([side+x,index+y]) == -1){
deleted.push([(side+x+clock.sides)%clock.sides,index+y]);
floodFill(clock,(side+x+clock.sides)%clock.sides,index+y);
}
}
}
}
}