So I tried to make a solving algorithm for a rubiks cube that makes use of a 3 dimensional array however since a 3 dimensional array's values can not be compared to another array's values, my if statement always return False.
My code is currently this however the debug part always returns false as it can not correctly be compared. This will also run aprox 2*27^10 times so the comparison has to be fast. And using a list and a for loop wont work fast enough for this.
Current code:
public void Solving(int[,,] Tbs) // 3d array cube that has to be solved
{
bool found = false;
List<char> movements = new() {'F','U','L', 'R','D', 'B' };
Queue<int[,,]> activeFromSramble = new();
Queue<int[,,]> activeFromSolved = new();
if (DefaultCube() == DefaultCube()) // for debug purposes defaultcube has all have the same values inside
Console.WriteLine("Works");
else
{
Console.WriteLine("Broken");
}
Dictionary<object, object> fromSC = new();
Dictionary<int[,,], int[,,]> fromSOL = new();
activeFromSramble.Enqueue(Tbs);
activeFromSolved.Enqueue(DefaultCube());
fromSC.Add(Tbs, Tbs);
fromSOL.Add(DefaultCube(),DefaultCube());
while (found == false)
{
Console.WriteLine("It");
int[,,] oldCube = activeFromSramble.Dequeue();
if (fromSOL.ContainsKey(oldCube))
{
found = true;
Console.WriteLine("FOUND");
}
foreach (char c in movements)
{
for (int i = 1; i < 4; i++)
{
int[,,] newCube = PermCube(oldCube, c, i);
if (fromSC.ContainsKey(newCube)) // of hij in eigen lijst staat met key
continue;
fromSC.Add(newCube, oldCube);
activeFromSramble.Enqueue(newCube);
}
}
oldCube = activeFromSolved.Dequeue();
if (fromSC.ContainsKey(oldCube))
{
found = true;
Console.WriteLine("FOUND");
}
foreach (char c in movements)
{
for (int i = 1; i < 4; i++)
{
int[,,] newCube = PermCube(oldCube, c, i);
if (fromSOL.ContainsKey(newCube))
{
continue;
}
{
activeFromSolved.Enqueue(newCube);
fromSOL.Add(newCube, oldCube);
}
}
}
}
}
You cannot compare the data in variable sized arrays in constant time. Some possible approaches: