Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Endelig udgave
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevnbak committed Dec 9, 2022
1 parent 612d248 commit 2d42101
Show file tree
Hide file tree
Showing 30 changed files with 94 additions and 116 deletions.
Binary file modified .vs/ProjectEvaluation/rubikscubesolver.metadata.v5.1
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/rubikscubesolver.projects.v5.1
Binary file not shown.
Binary file modified .vs/RubiksCubeSolver/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/RubiksCubeSolver/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/RubiksCubeSolver/v17/.suo
Binary file not shown.
27 changes: 13 additions & 14 deletions Cube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ namespace RubiksCubeSolver
internal class Cube
{
//State array
public string[] state = new string[54];
public char[] state = new char[54];

//Total rotations
public int totalRotations = 0;

//Constructors
public Cube(bool scramble)
{
string[] colors = new string[6] { "w", "o", "g", "r", "b", "y" };
for(int c = 0; c < 6; c++)
char[] colors = new char[6] { 'w', 'o', 'g', 'r', 'b', 'y' };
for (int c = 0; c < 6; c++)
{
for (int i = 0; i < 9; i++)
{
Expand All @@ -45,8 +45,7 @@ private void Scramble(int moves)
Random rnd = new Random();
for (int i = 0; i < moves; i++)
{
string[] algorithms = new string[20] {"FRUruf","RUrURUUr","luLulUUL","RbRFFrBRFFRR","FFurLFFRluFF","RRURUrururUr","RuruRURDruRdrUUr","RUrurFRRuruRUrf","RRuRuRUrURRdURurD","rURurfuFRUrFrfRuR","RRDrUURdrUUr","RUruYURuyr","rFRUrufUR","RUburURBr","yruRurURurUUYR","RUURRuRurUUFRf","RUrUrFRfUUrFRf","XFRUruxfUFRUruf","uRUrubrFRfB","YRUruyURur"
};
string[] algorithms = new string[20] {"FRUruf","RUrURUUr","luLulUUL","RbRFFrBRFFRR","FFurLFFRluFF","RRURUrururUr","RuruRURDruRdrUUr","RUrurFRRuruRUrf","RRuRuRUrURRdURurD","rURurfuFRUrFrfRuR","RRDrUURdrUUr","RUruYURuyr","rFRUrufUR","RUburURBr","yruRurURurUUYR","RUURRuRurUUFRf","RUrUrFRfUUrFRf","XFRUruxfUFRUruf","uRUrubrFRfB","YRUruyURur"};
int r = rnd.Next(20);
Program.performAlgorithm(algorithms[r], this, 0, 2);
}
Expand Down Expand Up @@ -108,14 +107,14 @@ public void Log()
Console.WriteLine("---------------------------------");

//Color function
ConsoleColor color(string value)
ConsoleColor color(char value)
{
if (value == "w") return ConsoleColor.White;
else if (value == "o") return ConsoleColor.DarkYellow;
else if (value == "g") return ConsoleColor.Green;
else if (value == "r") return ConsoleColor.DarkRed;
else if (value == "b") return ConsoleColor.Blue;
else if (value == "y") return ConsoleColor.Yellow;
if (value == 'w') return ConsoleColor.White;
else if (value == 'o') return ConsoleColor.DarkYellow;
else if (value == 'g') return ConsoleColor.Green;
else if (value == 'r') return ConsoleColor.DarkRed;
else if (value == 'b') return ConsoleColor.Blue;
else if (value == 'y') return ConsoleColor.Yellow;
else return ConsoleColor.Black;
}
}
Expand All @@ -125,7 +124,7 @@ public void RotateClockWise(int side, bool count = true)
{
if (count) totalRotations++;
//Create copy of state
string[] oldState = new string[54];
char[] oldState = new char[54];
state.CopyTo(oldState, 0);

//Create dictionary of face pairs
Expand Down Expand Up @@ -178,7 +177,7 @@ public void RotateCenterClockWise(int side, bool count = true)
{
if (count) totalRotations++;
//Create copy of state
string[] oldState = new string[54];
char[] oldState = new char[54];
state.CopyTo(oldState, 0);

//Create dictionary of face pairs
Expand Down
50 changes: 25 additions & 25 deletions Method1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@ internal class Method1
{
public static void SolveOLL(Cube cube)
{
//OLL - Cross
int correctEdges = ollCheckCross(cube);
while (correctEdges != 4)
{
Program.performAlgorithm("FRUruf", cube, 0, 2);
correctEdges = ollCheckCross(cube);
if(cube.state[3] != "w" || cube.state[5] != "w")
//OLL - Cross
int correctEdges = ollCheckCross(cube);
while (correctEdges != 4)
{
cube.RotateClockWise(0); //U
Program.performAlgorithm("FRUruf", cube, 0, 2);
correctEdges = ollCheckCross(cube);
if(cube.state[3] != 'w' || cube.state[5] != 'w')
{
cube.RotateClockWise(0); //U
}
}
int ollCheckCross(Cube cube)
{
int correct = 0;
if (cube.state[1] == 'w') correct += 1;
if (cube.state[3] == 'w') correct += 1;
if (cube.state[5] == 'w') correct += 1;
if (cube.state[7] == 'w') correct += 1;
return correct;
}
}
int ollCheckCross(Cube cube)
{
int correct = 0;
if (cube.state[1] == "w") correct += 1;
if (cube.state[3] == "w") correct += 1;
if (cube.state[5] == "w") correct += 1;
if (cube.state[7] == "w") correct += 1;
return correct;
}
//OLL - Corners
int correctCorners = ollCheckCorners(cube);
int tries = 0;
while (correctCorners != 4)
{
if(correctCorners == 1)
{
while(cube.state[0] != "w")
while(cube.state[0] != 'w')
{
cube.RotateClockWise(0);
}
if (cube.state[11] == "w")
if (cube.state[11] == 'w')
{
Program.performAlgorithm("RUrURUUr", cube, 0, 1);
} else if(cube.state[36] == "w")
} else if(cube.state[36] == 'w')
{
Program.performAlgorithm("luLulUUL", cube, 0, 4);
}
Expand All @@ -66,10 +66,10 @@ int ollCheckCross(Cube cube)
int ollCheckCorners(Cube cube)
{
int correctCorners = 0;
if (cube.state[0] == "w") correctCorners += 1;
if (cube.state[2] == "w") correctCorners += 1;
if (cube.state[6] == "w") correctCorners += 1;
if (cube.state[8] == "w") correctCorners += 1;
if (cube.state[0] == 'w') correctCorners += 1;
if (cube.state[2] == 'w') correctCorners += 1;
if (cube.state[6] == 'w') correctCorners += 1;
if (cube.state[8] == 'w') correctCorners += 1;
return correctCorners;
}
}
Expand Down
74 changes: 37 additions & 37 deletions Method2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,31 +329,31 @@ public static void SolvePLL(Cube cube)
//Check state
private static string checkOLLState(Cube cube)
{
//Corners
int[] cornerStates = new int[4];
for (int i = 1; i <= 4; i++)
{
int corner = i == 1 ? 0 : i == 2 ? 2 : i == 3 ? 6 : 8;
if (cube.state[corner] == "w")
{
cornerStates[i - 1] = 0;
continue;
}
int side1 = i == 1 ? 1 : i == 2 ? 4 : i == 3 ? 2 : 3;
int side2 = i == 1 ? 4 : i == 2 ? 3 : i == 3 ? 1 : 2;
if (cube.state[side1 * 9] == "w")
//Corners
int[] cornerStates = new int[4];
for (int i = 1; i <= 4; i++)
{
cornerStates[i - 1] = side1;
continue;
int corner = i == 1 ? 0 : i == 2 ? 2 : i == 3 ? 6 : 8;
if (cube.state[corner] == 'w')
{
cornerStates[i - 1] = 0;
continue;
}
int side1 = i == 1 ? 1 : i == 2 ? 4 : i == 3 ? 2 : 3;
int side2 = i == 1 ? 4 : i == 2 ? 3 : i == 3 ? 1 : 2;
if (cube.state[side1 * 9] == 'w')
{
cornerStates[i - 1] = side1;
continue;
}
else if (cube.state[side2 * 9 + 2] == 'w')
{
cornerStates[i - 1] = side2;
continue;
}
}
else if (cube.state[side2 * 9 + 2] == "w")
for (int s = 1; s <= 4; s++)
{
cornerStates[i - 1] = side2;
continue;
}
}
for (int s = 1; s <= 4; s++)
{
//Edges
string edgeCase;
int left = ((s - 1) * 2 + 1);
Expand All @@ -365,31 +365,31 @@ private static string checkOLLState(Cube cube)
down = down switch { 5 => 7, 7 => 5, _ => down, };
up = up switch { 5 => 7, 7 => 5, _ => up, };

if (cube.state[up] == "w" && cube.state[down] == "w" && cube.state[right] == "w" && cube.state[left] == "w")
if (cube.state[up] == 'w' && cube.state[down] == 'w' && cube.state[right] == 'w' && cube.state[left] == 'w')
{
//Full cross
edgeCase = "full";
} else if (cube.state[up] == "w" && cube.state[down] == "w")
} else if (cube.state[up] == 'w' && cube.state[down] == 'w')
{
//Vertical bar
edgeCase = "vbar";
} else if (cube.state[left] == "w" && cube.state[right] == "w")
} else if (cube.state[left] == 'w' && cube.state[right] == 'w')
{
//Horizontal bar
edgeCase = "hbar";
} else if (cube.state[up] == "w" && cube.state[left] == "w")
} else if (cube.state[up] == 'w' && cube.state[left] == 'w')
{
//Top left
edgeCase = "topleft";
} else if (cube.state[up] == "w" && cube.state[right] == "w")
} else if (cube.state[up] == 'w' && cube.state[right] == 'w')
{
//Top right
edgeCase = "topright";
} else if (cube.state[down] == "w" && cube.state[left] == "w")
} else if (cube.state[down] == 'w' && cube.state[left] == 'w')
{
//Bottom left
edgeCase = "bottomleft";
} else if (cube.state[down] == "w" && cube.state[right] == "w")
} else if (cube.state[down] == 'w' && cube.state[right] == 'w')
{
//Bottom right
edgeCase = "bottomright";
Expand Down Expand Up @@ -496,17 +496,17 @@ private static string checkOLLState(Cube cube)
private static string checkPLLState(Cube cube)
{
//Corners
KeyValuePair<string, string>[] cornerStates = new KeyValuePair<string, string>[4];
KeyValuePair<char, char>[] cornerStates = new KeyValuePair<char, char>[4];
for (int i = 0; i < 4; i++)
{
int side1 = i == 0 ? 1 : i == 1 ? 4 : i == 2 ? 2 : 3;
int side2 = i == 0 ? 4 : i == 1 ? 3 : i == 2 ? 1 : 2;
string c1 = cube.state[side1 * 9];
string c2 = cube.state[side2 * 9 + 2];
cornerStates[i] = new KeyValuePair<string, string>(c1, c2);
char c1 = cube.state[side1 * 9];
char c2 = cube.state[side2 * 9 + 2];
cornerStates[i] = new KeyValuePair<char, char>(c1, c2);
}
//Edges
string[] edgeStates = new string[4];
char[] edgeStates = new char[4];
for (int i = 0; i < 4; i++)
{
int side = i == 0 ? 4 : i == 1 ? 1 : i == 2 ? 3 : 2;
Expand All @@ -517,13 +517,13 @@ private static string checkPLLState(Cube cube)
for (int s = 1; s <= 4; s++)
{
//Corners
KeyValuePair<string, string>[] corners = new KeyValuePair<string, string>[4];
KeyValuePair<char, char>[] corners = new KeyValuePair<char, char>[4];
corners[0] = cornerStates[s == 1 ? 1 : s == 2 ? 0 : s == 3 ? 2 : 3];
corners[1] = cornerStates[s == 1 ? 3 : s == 2 ? 1 : s == 3 ? 0 : 2];
corners[2] = cornerStates[s == 1 ? 0 : s == 2 ? 2 : s == 3 ? 3 : 1];
corners[3] = cornerStates[s == 1 ? 2 : s == 2 ? 3 : s == 3 ? 1 : 0];
//Edges
string[] edges = new string[4];
char[] edges = new char[4];
edges[0] = edgeStates[s == 1 ? 2 : s == 2 ? 0 : s == 3 ? 1 : 3];
edges[1] = edgeStates[s == 1 ? 0 : s == 2 ? 1 : s == 3 ? 3 : 2];
edges[2] = edgeStates[s == 1 ? 3 : s == 2 ? 2 : s == 3 ? 0 : 1];
Expand All @@ -544,7 +544,7 @@ private static string checkPLLState(Cube cube)
else if (edges[0] == corners[2].Key && edges[3] == corners[0].Value) return s + "H";
}
//Edges correct
else if (edges[0] == edges[3] switch{"b"=>"g","g"=>"b","r"=>"o","o"=>"r",_=>""} && edges[1] == edges[2] switch{"b"=>"g","g"=>"b","r"=>"o","o"=>"r",_=>""})
else if (edges[0] == edges[3] switch{'b'=>'g','g'=>'b','r'=>'o','o'=>'r'} && edges[1] == edges[2] switch{'b'=>'g','g'=>'b','r'=>'o','o'=>'r'})
{
if (corners[2].Key == edges[3] && corners[2].Value == edges[1])
{
Expand Down
44 changes: 15 additions & 29 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,26 @@ static void Main(string[] args)
Console.WriteLine($"Starting solving {amount} cubes...");
Console.ForegroundColor = ConsoleColor.White;

object[,] data = new object[amount, 5];
object[,] data = new object[amount, 3];

for (int i = 0; i < amount; i++)
{
Cube cube11 = new(true);
Cube cube12 = new(cube11);
Cube cube21 = new(cube11);
Cube cube22 = new(cube11);
Cube cube1 = new(true);
Cube cube2 = new(cube1);

//Save cube state
data[i, 0] = $"[{String.Join(";", cube11.state)}]";
data[i, 0] = $"[{String.Join(";", cube1.state)}]";

// 11
Method1.SolveOLL(cube11);
Method1.SolvePLL(cube11);
checkSolved(cube11);
data[i, 1] = cube11.totalRotations;
// 12
Method1.SolveOLL(cube12);
Method2.SolvePLL(cube12);
checkSolved(cube12);
data[i, 2] = cube12.totalRotations;
// 21
Method2.SolveOLL(cube21);
Method1.SolvePLL(cube21);
checkSolved(cube21);
data[i, 3] = cube21.totalRotations;
// 22
Method2.SolveOLL(cube22);
Method2.SolvePLL(cube22);
checkSolved(cube22);
data[i, 4] = cube22.totalRotations;
// 1 - Begynder
Method1.SolveOLL(cube1);
Method1.SolvePLL(cube1);
checkSolved(cube1);
data[i, 1] = cube1.totalRotations;
// 2 - CFOP
Method2.SolveOLL(cube2);
Method2.SolvePLL(cube2);
checkSolved(cube2);
data[i, 2] = cube2.totalRotations;
updatePercent(i + 1, amount);
}

Expand All @@ -75,7 +63,6 @@ static void Main(string[] args)
//Open Excel
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Opening Excel workbook...");

Application xl = new Application();
Workbook wb = xl.Workbooks.Open(Directory.GetCurrentDirectory() + "\\Data.xlsx");
Worksheet template = wb.Sheets[1];
Expand All @@ -85,8 +72,7 @@ static void Main(string[] args)
//Add data to excel
Console.WriteLine("Adding data to Excel...");
Console.ForegroundColor = ConsoleColor.White;
sheet.Range["A" + 2, "E" + (amount + 1)].Value = data;

sheet.Range["A" + 2, "C" + (amount + 1)].Value = data;
wb.Save();

//Done!
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# RubiksCubeSolver
Rubik's Cube solver, Studie Område Projekt.

## Guide til brug
1. Download zip filen Release her: [Release](https://github.com/Stevnbak/RubiksCubeSolver/releases/tag/Program).
2. Udpak zip filen.
3. Kør "RubiksCubeSolver.exe".
4. Skriv hvor mange Rubik's Cubes der skal løses.
5. Lad programmet kører.
6. Se resultaterne i Excel arket.
Rubik's Cube solver
Studie Område Projekt, SOP.

## Lavet af Kasper Stevnbak
4 changes: 2 additions & 2 deletions RubiksCubeSolver.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EDB893C9-229A-40F7-81FC-F5080D58EB48}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{EDB893C9-229A-40F7-81FC-F5080D58EB48}.Debug|Any CPU.Build.0 = Release|Any CPU
{EDB893C9-229A-40F7-81FC-F5080D58EB48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDB893C9-229A-40F7-81FC-F5080D58EB48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDB893C9-229A-40F7-81FC-F5080D58EB48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDB893C9-229A-40F7-81FC-F5080D58EB48}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
Binary file modified bin/Debug/net6.0/RubiksCubeSolver.dll
Binary file not shown.
Binary file modified bin/Debug/net6.0/RubiksCubeSolver.pdb
Binary file not shown.
Binary file modified bin/Release/net6.0/Data.xlsx
Binary file not shown.
Binary file modified bin/Release/net6.0/RubiksCubeSolver.dll
Binary file not shown.
Binary file modified bin/Release/net6.0/RubiksCubeSolver.pdb
Binary file not shown.
Binary file modified obj/Debug/net6.0/Interop.Microsoft.Office.Interop.Excel.dll
Binary file not shown.
Binary file modified obj/Debug/net6.0/RubiksCubeSolver.dll
Binary file not shown.
Binary file modified obj/Debug/net6.0/RubiksCubeSolver.pdb
Binary file not shown.
Binary file modified obj/Debug/net6.0/ref/RubiksCubeSolver.dll
Binary file not shown.
Binary file modified obj/Debug/net6.0/refint/RubiksCubeSolver.dll
Binary file not shown.
Binary file modified obj/Release/net6.0/Interop.Microsoft.Office.Interop.Excel.dll
Binary file not shown.
Binary file modified obj/Release/net6.0/RubiksCubeSolver.dll
Binary file not shown.
Binary file modified obj/Release/net6.0/RubiksCubeSolver.pdb
Binary file not shown.
Binary file modified obj/Release/net6.0/ref/RubiksCubeSolver.dll
Binary file not shown.
Binary file modified obj/Release/net6.0/refint/RubiksCubeSolver.dll
Binary file not shown.

0 comments on commit 2d42101

Please sign in to comment.