The goal
I'm trying to use BFS to make a Rubik's cube solver. I know that it'll probably be slow with all of the ways that it can be permuted. =P It's not for school in case anyone is wondering.
The probably-easy-to-fix problem
Whenever I'm putting another state of the scrambled Rubik's cube into the queue<array>
it is just a shallow copy, so once other states of the Rubik's cube are added in, the previous states inside of the queue actually change and match up with the newer states. In other words, how do I make sure that all of the elements inside of the queue<array>
remain the same?
Attempts that I have made to fix this
https://stackoverflow.com/a/129395/984680
I basically use this code to create a new copy of the cube when it comes out of the queue, and then I create another new copy before I put it into the queue again (in a different state). The code below shows how a new copy is made before it's inserted into the queue.
//make deep copy of ccube (char array)
char[][][] newcube = DeepClone(ccube);
buffer.Enqueue(new State(newcube, calg + face + " ")); //even though newcube gets put into array, it ends up changed after ccube changes
And this is the deepcopy that's made when the array is pulled out from the front of the queue.
ccube = DeepClone(buffer.Peek().cube);
Even though I cloned the array so many times (something tells me that I don't need to make so many copies) the newer states that I add in are still the same as the older states. I know this because there are only 2 distinct elements inside of the queue, even though I made all of the faces of the cube turn in every way each time.
Thanks in advance to anyone who is able to help.