-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstage3.cpp
More file actions
140 lines (119 loc) · 3.19 KB
/
stage3.cpp
File metadata and controls
140 lines (119 loc) · 3.19 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
//
// stage3.cpp
// Rubiks2
//
// Created by 田 博 on 12-12-8.
// Copyright (c) 2012年 田 博. All rights reserved.
//
#include "stage3.h"
#include "rubiks.h"
void stage3_init(Rubiks &now)
{
for (int i = 0; i < 6; i++) {
if (now.data[i][1][1] == White)
{
now.change_vp(Side(i), Side((i+2)%6));
now.FtoU();
return ;
}
}
}
void stage3_check(Rubiks &now)
{
for (int i = 0; i < 3; i++) {
if (now.data[Up][1][i] != White)
{
cerr << "Up 1 " << i << " is not white!\n";
now.print_state();
assert(false);
}
if (now.data[Up][i][1] != White)
{
cerr << "Up " << i << " 1 is not white!\n";
now.print_state();
assert(false);
}
}
const Side seq[4] = {Front, Left, Right};
for (int i = 0; i < 4; i++) {
if (now.data[seq[i]][0][1] != now.data[seq[i]][1][1])
{
cerr << "seq "<<i<<" color not same!"<<endl;
assert(false);
}
}
if (now.data[Back][2][1] != now.data[Back][1][1])
{
cerr << "Back "<<" color not same!"<<endl;
assert(false);
}
}
bool down_to_up(Rubiks &now)
{
int (*data)[3][3] = now.data;
for (int i = 0; i < 4; i++) {
now.FtoR();
if (data[Up][2][2] == White)
{
//assert(data[Front][0][2] == data[Front][0][1] && data[Right][0][0] == data[Right][0][1]);
}
else
{
bool in[6], flag = false;
for (int j = 0; j < 4; j++) {
memset(in, false, sizeof(in));
in[data[Front][2][2]] = in[data[Down][0][2]] = in[data[Right][2][0]] = true;
if (in[data[Front][0][1]] && in[data[Right][0][1]] && in[White]) {
flag = true;
break;
}
now.D();
}
if (!flag)
continue;
while (!(data[Up][2][2] == White && data[Front][0][2] == data[Front][0][1] && data[Right][0][0] == data[Right][0][1]))
{
now.Ri();
now.Di();
now.R();
now.D();
}
return true;
}
}
return false;
}
bool up_to_down(Rubiks &now)
{
int (*data)[3][3] = now.data;
for (int i = 0; i < 4; i++) {
bool flag = false;
while ((data[Front][0][2] == White || data[Right][0][0] == White) ||
(data[Up][2][2] == White && (data[Front][0][2] != data[Front][0][1] || data[Right][0][0] != data[Right][0][1])))
{
now.Ri();
now.Di();
now.R();
flag = true;
}
if (flag)
return true;
now.FtoR();
}
return false;
}
void stage3(Rubiks &now)
{
cerr << "Enter stage2\n";
now.print_state();
stage3_init(now);
stage3_check(now);
now.print_state();
while(down_to_up(now));
while (up_to_down(now)) {
while (!down_to_up(now))
assert(false);
}
now.print_state();
cerr << "Leave stage2\n";
}