
-----------------------------------
BlakeJustBlake
Thu Apr 17, 2008 2:37 pm

Values Changing Mysteriously
-----------------------------------
So, I usually don't like to post my programming problems for homework assignments, but this one just has me stumped at the moment. All I'm looking for is help solving this one problem, if you think you see a way I change or redo my program to solve my homework assignment better, don't tell me, I don't want to know, because I'm not looking for solutions to my assignment, I want to learn that part on my own. So please only give help as far as my described problem or design tips.

Here's a summary of the problem:

I've got a solver for a puzzle where there are four cubes on a rod with four sides on each cube. Each side (top bottom front back) has a color, solving the puzzle means that each cube has been rotated so that all the top sides of the cubes have different colors, all the bottom sides have different colors, etc. So there are several solutions and my program finds 5 solutions. So what I have is a two dimensional array to store all the solutions and a one dimensional array to send through the solving method and then after a solution is found be added to the two dimensional solution array. The solution array is like this: private Listclass insanitySolver {
	private String Title;
	private List[] boxes;
	private List[][] solutions = new List[5][4];
	private int k;
	private int rotations = 0;
	private int stuckBox;
	private boolean noSolutionOutput = false;
	
	public insanitySolver(String name, List[] boxes) {
		Title = name;
		this.boxes = boxes;
		for(k = 0; k < 5; k++) {
		boxes = Solve(this.boxes, 2);
			for(int i = 3;i>=0;i--) {
			solutions[k][i]=boxes[i];
			}
		}
		if(!noSolutionOutput) {
			getSolutions();
		}
	}

private List[] rotateBox (List[] box,int current) {
		box[current].add(box[current].get(0));
		box[current].remove(0);
		return box;
	}//Rotates box by removing the first element and adding it to the end of the List.

	private boolean solutionFound(List[] box) {
			boolean found = true;
		for(int i = k-1;i>=0;i--) {
			for(int j = 0;j 0 && currentBox == 2 && solutionFound(cubes)) {
			cubes = rotateBox(cubes, currentBox + 1);
			cubes = rotateBox(cubes, currentBox);
			cubes = rotateBox(cubes, currentBox);
		}
		
		try{
		boolean duplicated = isDuplicated(cubes, currentBox);
		
		if(currentBox==0&&!duplicated) {
			return cubes;
		}
		if(duplicated) {
			if(rotations == 3){
				rotations = 0;

				return Solve(rotateBox(cubes, stuckBox), stuckBox);}
			rotations++;
			return Solve(rotateBox(cubes,currentBox), currentBox);
		}
		if(!duplicated) {
			rotations = 0;
			return Solve(cubes,currentBox-1);
		}
		}
		
		catch(StackOverflowError e) {
			if(!noSolutionOutput) {
			System.out.print("No Solution\n");
			noSolutionOutput = true;
			}
		}

		return cubes; 
	}

And here's the data being sent through it:
This is the first test.
White, Blue, Yellow, Red
Green, Blue, White, Blue
White, Yellow, Green, Green
Blue, Red, Yellow, Red


And just so you can see how the data is processed in, here's the main method that calls the insanitySolver class:

public class eakinProg5 {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner retrieve  = new Scanner(new File("test.txt"));
		Scanner retrieveLines;
		List[] boxes = new List[4];
		String title;
		for(int i = 0;i=0;i--) {
				retrieveLines = new Scanner(retrieve.nextLine()).useDelimiter("\\x2C\\s");
				//System.out.print(i);
				for(int j = 0;j