-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_solver.cpp
More file actions
102 lines (78 loc) · 3.52 KB
/
test_solver.cpp
File metadata and controls
102 lines (78 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <bits/stdc++.h>
#include "Model/RubiksCubeBitboard.cpp"
#include "Solver/BFSSolver.h"
#include "Solver/IDAstarSolver.h"
#include <chrono>
using namespace std;
int main() {
string fileName = "Databases/cornerDepth5V1.txt";
cout << "=== Rubik's Cube Solver Test ===\n\n";
// Test 1: Shallow shuffle (5 moves)
cout << "Test 1: Solving a 5-move shuffle\n";
cout << "--------------------------------\n";
{
RubiksCubeBitboard cube;
auto shuffleMoves = cube.randomShuffleCube(5);
cout << "Shuffle moves: ";
for (auto move: shuffleMoves) cout << cube.getMove(move) << " ";
cout << "\n\n";
cube.print();
auto start = chrono::high_resolution_clock::now();
IDAstarSolver<RubiksCubeBitboard, HashBitboard> solver(cube, fileName);
auto solveMoves = solver.solve();
auto end = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::milliseconds>(end - start);
cout << "Solution found in " << duration.count() << " ms\n";
cout << "Number of moves: " << solveMoves.size() << "\n";
cout << "Solution: ";
for (auto move: solveMoves) cout << cube.getMove(move) << " ";
cout << "\n\n";
}
// Test 2: Medium shuffle (10 moves)
cout << "\nTest 2: Solving a 10-move shuffle\n";
cout << "---------------------------------\n";
{
RubiksCubeBitboard cube;
auto shuffleMoves = cube.randomShuffleCube(10);
cout << "Shuffle moves: ";
for (auto move: shuffleMoves) cout << cube.getMove(move) << " ";
cout << "\n\n";
cube.print();
auto start = chrono::high_resolution_clock::now();
IDAstarSolver<RubiksCubeBitboard, HashBitboard> solver(cube, fileName);
auto solveMoves = solver.solve();
auto end = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::milliseconds>(end - start);
cout << "Solution found in " << duration.count() << " ms\n";
cout << "Number of moves: " << solveMoves.size() << "\n";
cout << "Solution: ";
for (auto move: solveMoves) cout << cube.getMove(move) << " ";
cout << "\n\n";
}
// Test 3: Deep shuffle with BFS (12 moves)
cout << "\nTest 3: Solving a 12-move shuffle with BFS\n";
cout << "------------------------------------------\n";
{
RubiksCubeBitboard cube;
auto shuffleMoves = cube.randomShuffleCube(12);
cout << "Shuffle moves: ";
for (auto move: shuffleMoves) cout << cube.getMove(move) << " ";
cout << "\n\n";
cube.print();
cout << "Using BFS for optimal solution...\n";
auto start = chrono::high_resolution_clock::now();
BFSSolver<RubiksCubeBitboard, HashBitboard> solver(cube);
auto solveMoves = solver.solve();
auto end = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::milliseconds>(end - start);
cout << "Solution found in " << duration.count() << " ms\n";
cout << "Number of moves: " << solveMoves.size() << "\n";
cout << "Solution: ";
for (auto move: solveMoves) cout << cube.getMove(move) << " ";
cout << "\n\n";
cout << "Final state:\n";
solver.rubiksCube.print();
}
cout << "All tests completed successfully!\n";
return 0;
}