import java.awt.event.*;
import java.awt.*;


public class SolverAnalyze {

    public static int[] faceNeighborsSolid(Solver SOL,int k) {
	int[] K={k};
	boolean test=false;
	while(test==false) {
	    int l1=K.length;
	    K=faceNeighborsSolid1(SOL,K);
	    int l2=K.length;
	    if(l1==l2) test=true;
	}
	return K;
    }

    public static int[] faceNeighborsSolid1(Solver SOL,int[] k) {
	int count=0;
	int[] LIST=new int[200];
	for(int i=0;i<k.length;++i) LIST[i]=k[i];
	count=k.length;
	
	for(int i=0;i<k.length;++i) {
	    int[] list=faceNeighborsSolid0(SOL,k[i]);
	    for(int j=0;j<list.length;++j) {
		LIST[count]=list[j];
		++count;
	    }
	}
	LIST=ListHelp.trim(LIST,count);
	LIST=ListHelp.irredundant(LIST);
	return LIST;
    }


    public static int[] faceNeighborsSolid0(Solver SOL,int k) {
	int[] LIST=faceNeighbors(SOL,k);
	int[] LIST2=new int[3];
	int count=0;
	
	for(int i=0;i<3;++i) {
	    int j=LIST[i];
	    if(SOL.SOL[j]==SOL.SOL[k]) {
		LIST2[count]=j;
		++count;
	    }
	}
	LIST2=ListHelp.trim(LIST2,count);
	return LIST2;
    }


    public static int[] faceNeighbors(Solver SOL,int k) {
	int count=0;
	int[] LIST=new int[6];

	for(int i=0;i<4;++i) {
	    for(int j=0;j<3;++j) {
		int j1=(j+1)%3;
		int j2=(j+2)%3;
		if(SOL.F[i][j]==k) {
		    LIST[0]=SOL.F[i][j1];
		    LIST[1]=SOL.F[i][j2];
		    count=count+2;
		}
	    }
	}
	
	for(int i=4;i<SOL.COUNT;++i) {
	    for(int j=0;j<6;++j) {
	        int j1=(j+1)%6;
	        int j2=(j+5)%6;
		if(SOL.F[i][j]==k) {
  		    LIST[count]=SOL.F[i][j1];
  		    LIST[count+1]=SOL.F[i][j2];
		    count=count+2;
		}
	    }
	}
	
	int[] LIST2=ListHelp.trim(LIST,count);
	
        LIST2=ListHelp.irredundant(LIST2);
	return LIST2;
    }


}

