-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCube.cpp
More file actions
executable file
·75 lines (64 loc) · 1.46 KB
/
Copy pathCube.cpp
File metadata and controls
executable file
·75 lines (64 loc) · 1.46 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
//
// Created by jscholl4 on 1/9/18.
//
#include "Cube.h"
#define ENUM_TO_STR(ENUM) std::string(#ENUM)
Cube::Cube(Colors top, Colors bottom, Colors left, Colors right, Colors front, Colors back)
: top(top), bottom(bottom), left(left), right(right), front(front), back(back) {}
void Cube::NextOrientation() {
//a total of 24 distinct orientations?
if (spinCount == 3) {
if ((flipCount % 2 == 0)) {
flipUp();
} else {
//to alternate flipping up from the left and the right
spinVertAxis();
spinVertAxis();
flipUp();
}
} else {
spinVertAxis();
}
++orientation;
}
void Cube::spinVertAxis() {
Colors tmp = front;
front = right;
right = back;
back = left;
left = tmp;
++spinCount;
}
void Cube::flipUp() {
Colors tmp = front;
front = top;
top = back;
back = bottom;
bottom = tmp;
spinCount = 0;
++flipCount;
}
string enumToString(Colors c) {
switch (c) {
case green:
return "green";
case red:
return "red";
case blue:
return "blue";
case white:
return "white";
default:
return "unknown color";
}
}
string Cube::toString() {
string cube;
cube += enumToString(top) + " ";
cube += enumToString(bottom) + " ";
cube += enumToString(left) + " ";
cube += enumToString(right) + " ";
cube += enumToString(front) + " ";
cube += enumToString(back) + " ";
return cube;
}