MCPcopy Create free account
hub / github.com/MeigenChou/DCTimer-Android / phase1Opt

Method phase1Opt

app/src/main/java/cs/sq12phase/Search.java:142–212  ·  view source on GitHub ↗
(int shape, int prunvalue, int maxl, int depth, int lm, int lastTurns)

Source from the content-addressed store, hash-verified

140 }
141
142 private boolean phase1Opt(int shape, int prunvalue, int maxl, int depth, int lm, int lastTurns) {
143 int i = count0xf((lastTurns ^ ~0x000000) & 0xff00ff)
144 - count0xf((lastTurns ^ ~0x666666) & 0xff00ff);
145 if (i < 0 || i == 0 && (lastTurns >> 20 & 0xf) >= 6) {
146 return false;
147 }
148
149 if (maxl / PRUN_INC == 0) {
150 movelen1 = depth;
151 if (isSolvedInPhase1()) {
152 return true;
153 }
154 if (maxl == 0) {
155 return false;
156 }
157 }
158 //try each possible move. First twist;
159 if (lm != 0) {
160 int shapex = Shape.spTwistMove[shape];
161 int prun = Shape.ShapePrunOpt[shapex];
162 if (prun < maxl / PRUN_INC) {
163 move[depth] = 0;
164 int next_maxl = (maxl / PRUN_INC - 1) * PRUN_INC;
165 if (phase1Opt(shapex, prun, next_maxl, depth + 1, 0, lastTurns << 8))
166 return true;
167 }
168 }
169
170 //Try top layer
171 int shapex = shape;
172 if (lm <= 0) {
173 int m = 0;
174 while (true) {
175 m += Shape.spTopMove[shapex];
176 shapex = m >> 4;
177 m &= 0x0f;
178 if (m >= 12)
179 break;
180 int prun = Shape.ShapePrunOpt[shapex];
181 if (prun * PRUN_INC > (maxl + PRUN_INC - 1)) {
182 break;
183 } else if (prun * PRUN_INC < (maxl + PRUN_INC - 1)) {
184 move[depth] = m;
185 if (phase1Opt(shapex, prun, maxl - 1, depth + 1, 1, lastTurns | m << 4))
186 return true;
187 }
188 }
189 }
190
191 shapex = shape;
192 //Try bottom layer
193 if (lm <= 1) {
194 int m = 0;
195 while (true) {
196 m += Shape.spBottomMove[shapex];
197 shapex = m >> 4;
198 m &= 0x0f;
199 if (m >= 12)

Callers 1

solutionOptMethod · 0.95

Calls 2

count0xfMethod · 0.95
isSolvedInPhase1Method · 0.95

Tested by

no test coverage detected