-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.java
More file actions
140 lines (131 loc) · 3.71 KB
/
Color.java
File metadata and controls
140 lines (131 loc) · 3.71 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import java.util.*;
enum Color {
WHITE, YELLOW, RED, ORANGE, GREEN, BLUE;
public Color complement() {
switch (this) {
case WHITE:
return YELLOW;
case YELLOW:
return WHITE;
case RED:
return ORANGE;
case ORANGE:
return RED;
case GREEN:
return BLUE;
}
return GREEN;
}
public int index() {
switch (this) {
case WHITE:
return 0;
case YELLOW:
return 5;
case RED:
return 2;
case ORANGE:
return 4;
case GREEN:
return 1;
}
return 3;
}
public Color[] getAdj() {
switch (this) {
case WHITE:
Color[] whiteAdj = { Color.BLUE, Color.RED, Color.GREEN, Color.ORANGE };
return whiteAdj;
case YELLOW:
Color[] yellowAdj = { Color.GREEN, Color.RED, Color.BLUE, Color.ORANGE };
return yellowAdj;
case RED:
Color[] redAdj = { Color.WHITE, Color.BLUE, Color.YELLOW, Color.GREEN };
return redAdj;
case ORANGE:
Color[] orangeAdj = { Color.WHITE, Color.GREEN, Color.YELLOW, Color.BLUE };
return orangeAdj;
case GREEN:
Color[] greenAdj = { Color.WHITE, Color.RED, Color.YELLOW, Color.ORANGE };
return greenAdj;
}
Color[] blueAdj = { Color.WHITE, Color.ORANGE, Color.YELLOW, Color.RED };
return blueAdj;
}
public Color pivotColor(Color start, int amount) {
Color[] pivotCols = new Color[4];
switch (this) {
case WHITE:
Color[] whitePivotCols = { Color.BLUE, Color.RED, Color.GREEN, Color.ORANGE };
pivotCols = whitePivotCols;
break;
case YELLOW:
Color[] yellowPivotCols = { Color.GREEN, Color.RED, Color.BLUE, Color.ORANGE };
pivotCols = yellowPivotCols;
break;
case RED:
Color[] redPivotCols = { Color.WHITE, Color.BLUE, Color.YELLOW, Color.GREEN };
pivotCols = redPivotCols;
break;
case ORANGE:
Color[] orangePivotCols = { Color.WHITE, Color.GREEN, Color.YELLOW, Color.BLUE };
pivotCols = orangePivotCols;
break;
case GREEN:
Color[] greenPivotCols = { Color.WHITE, Color.RED, Color.YELLOW, Color.ORANGE };
pivotCols = greenPivotCols;
break;
default:
Color[] bluePivotCols = { Color.WHITE, Color.ORANGE, Color.YELLOW, Color.RED };
pivotCols = bluePivotCols;
}
int i = Arrays.asList(pivotCols).indexOf(start);
if (amount == -1) {
amount = 3;
}
i += amount;
i %= 4;
return pivotCols[i];
}
public int findPivot(Color start, Color end) {
Map<Color, Integer> pivotCols = new HashMap<Color, Integer>();
switch (this) {
case WHITE:
Map<Color, Integer> whitePivotCols = Map.of(Color.BLUE, 0, Color.RED, 1, Color.GREEN, 2, Color.ORANGE, 3);
pivotCols = whitePivotCols;
break;
case YELLOW:
Map<Color, Integer> yellowPivotCols = Map.of(Color.GREEN, 0, Color.RED, 1, Color.BLUE, 2, Color.ORANGE, 3);
pivotCols = yellowPivotCols;
break;
case RED:
Map<Color, Integer> redPivotCols = Map.of(Color.WHITE, 0, Color.BLUE, 1, Color.YELLOW, 2, Color.GREEN, 3);
pivotCols = redPivotCols;
break;
case ORANGE:
Map<Color, Integer> orangePivotCols = Map.of(Color.WHITE, 0, Color.GREEN, 1, Color.YELLOW, 2, Color.BLUE, 3);
pivotCols = orangePivotCols;
break;
case GREEN:
Map<Color, Integer> greenPivotCols = Map.of(Color.WHITE, 0, Color.RED, 1, Color.YELLOW, 2, Color.ORANGE, 3);
pivotCols = greenPivotCols;
break;
default:
Map<Color, Integer> bluePivotCols = Map.of(Color.WHITE, 0, Color.ORANGE, 1, Color.YELLOW, 2, Color.RED, 3);
pivotCols = bluePivotCols;
}
int startIndex = pivotCols.get(start);
int endIndex = pivotCols.get(end);
int diff = endIndex - startIndex;
if (diff < -1) {
diff += 4;
}
if (diff > 2) {
diff -= 4;
}
return diff;
}
public boolean inOrder(Color leftCol, Color rightCol) {
return (findPivot(leftCol, rightCol) == -1);
}
}