-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
113 lines (88 loc) · 2.97 KB
/
main.cpp
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
103
104
105
106
107
108
109
110
111
112
113
#include "Cube.h"
#include "Solver.h"
#include <string>
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
vector<int> setMoves(string moves, unordered_map<string, int> &turns);
int main(){
Cube *c = new Cube();
cout << "Welcome to the Rubiks Cube Solver, to begin, please enter a scramble state to start the program."<<endl<<endl;
cout << "------------------------------------------------------------------------------"<<endl;
cout << "The format of the input should be as follows: " << endl;
cout << "U is Up\nD is Down\nF is Front\nB is Back\nR is Right\nL is Left" <<endl;
cout << "Add an apostrophe (') after the move to indicate a counter clockwise turn\nAdd a 2 after the move to indicate a half turn." <<endl;
cout << "An example input is: U R B F' R' U' F L' B2 F' L2 F R' F' D2 F' L' D U B F' R' U2 F' U";
cout << "------------------------------------------------------------------------------"<<endl;
string moves = "";
string tmp;
do{
cout << "Enter scramble here (Enter -1 when done): ";
cin >> tmp;
if(tmp != "-1")
moves += (tmp + " ");
}while(tmp != "-1");
string redo;
do{
cout << moves << " ------ is this the move set you want to scramble your cube with (y/n)? ";
//for simplicity, assumes input of redo is correct.
cin >> redo;
if(redo == "n"){
moves = "";
do{
cout << "Enter scramble here (Enter -1 when done): ";
cin >> tmp;
if(tmp != "-1")
moves += (tmp + " ");
} while(tmp != "-1");
}
} while(redo == "n");
unordered_map<string, int> turns;
//initialize turn map for user input.
turns["F"] = 3;
turns["U"] = 1;
turns["R"] = 2;
turns["D"] = 4;
turns["L"] = 5;
turns["B"] = 6;
turns["F'"] = -3;
turns["U'"] = -1;
turns["R'"] = -2;
turns["D'"] = -4;
turns["L'"] = -5;
turns["B'"] = -6;
cout <<endl<< "Scrambling cube now" << endl;
cout << moves << endl;
vector<int> moveSet = setMoves(moves, turns);
//scramble the cube, then print it out.
c->applyMoves(moveSet);
cout << "Scrambled cube is: " << endl;
c->printCube();
cout << endl;
//intialize solver with scrambled cube
Solver solver(*c);
solver.solveStages();
return 0;
}
//function used to turn string moveset input into a vector of integer moves.
vector<int> setMoves(string moves, unordered_map<string, int> &turns){
vector<int> moveSet;
string tmp = "";
for(int i = 0; i < moves.length()-1; i++){
if(string(moves.substr(i,1)) != " " && string(moves.substr(i,1)) != "2" && string(moves.substr(i,1)) != "'"){
if(string(moves.substr(i+1,1)) == "'"){
tmp = moves.substr(i,1) + "'";
moveSet.push_back(turns[tmp]);
}
if(string(moves.substr(i+1,1)) == "2"){
moveSet.push_back(turns[moves.substr(i,1)]);
moveSet.push_back(turns[moves.substr(i,1)]);
}
if(string(moves.substr(i+1, 1)) == " "){
moveSet.push_back(turns[moves.substr(i,1)]);
}
}
}
return moveSet;
}