HOG2
RubiksCube7Edges.cpp
Go to the documentation of this file.
1 //
2 // Rubik7Edge.cpp
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 1/4/13.
6 // Copyright (c) 2013 University of Denver. All rights reserved.
7 //
8 
9 #include "RubiksCube7Edges.h"
10 #include "GLUtil.h"
11 #include <cassert>
12 
14 {
15 // for (int x = 0; x < 12; x++)
16 // {
17 // s.SetCubeInLoc(0, 0xF);
18 // s.SetCubeOrientation(x, 0);
19 // }
20  for (int x = 0; x < 12; x++)
21  {
22  s.SetCubeInLoc(GetCubeInLoc(x), x);
24  }
25 }
26 
27 void Rubik7Edge::GetSuccessors(const Rubik7EdgeState &nodeID, std::vector<Rubik7EdgeState> &neighbors) const
28 {
30  for (int x = 0; x < 18; x++)
31  {
32  GetNextState(nodeID, x, s);
33  neighbors.push_back(s);
34  }
35 }
36 
37 void Rubik7Edge::GetActions(const Rubik7EdgeState &nodeID, std::vector<Rubik7EdgeAction> &actions) const
38 {
39  actions.resize(0);
40  for (int x = 0; x < 18; x++)
41  {
42  actions.push_back(x);
43  }
44 }
45 
47 {
48  assert(false);
50  return a;
51 }
52 
54 {
55  ApplyAction(s, a->act);
56 }
57 
59 {
60  Rubik7EdgeAction todo = a->act;
61  if (0 == todo%3)
62  {
63  todo += 1;
64  }
65  else if (1 == todo%3)
66  {
67  todo -= 1;
68  }
69  ApplyAction(s, todo);
70 }
71 
73 {
74  switch (a)
75  {
76  case 0: // face 0
77  {
78  int a = s.GetCubeInLoc(1-1);
79  int b = s.GetCubeInLoc(3-1);
80  int c = s.GetCubeInLoc(5-1);
81  int d = s.GetCubeInLoc(7-1);
82  s.SetCubeInLoc(1-1, d);
83  s.SetCubeInLoc(3-1, a);
84  s.SetCubeInLoc(5-1, b);
85  s.SetCubeInLoc(7-1, c);
86  }
87  break;
88  case 1:
89  {
90  int a = s.GetCubeInLoc(1-1);
91  int b = s.GetCubeInLoc(3-1);
92  int c = s.GetCubeInLoc(5-1);
93  int d = s.GetCubeInLoc(7-1);
94  s.SetCubeInLoc(1-1, b);
95  s.SetCubeInLoc(3-1, c);
96  s.SetCubeInLoc(5-1, d);
97  s.SetCubeInLoc(7-1, a);
98  }
99  break;
100  case 2:
101  {
102  int a = s.GetCubeInLoc(1-1);
103  int b = s.GetCubeInLoc(3-1);
104  int c = s.GetCubeInLoc(5-1);
105  int d = s.GetCubeInLoc(7-1);
106  s.SetCubeInLoc(1-1, c);
107  s.SetCubeInLoc(3-1, d);
108  s.SetCubeInLoc(5-1, a);
109  s.SetCubeInLoc(7-1, b);
110  }
111  break;
112  case 3: // face 5
113  {
114  int a = s.GetCubeInLoc(9-1);
115  int b = s.GetCubeInLoc(10-1);
116  int c = s.GetCubeInLoc(11-1);
117  int d = s.GetCubeInLoc(12-1);
118  s.SetCubeInLoc(9-1, d);
119  s.SetCubeInLoc(10-1, a);
120  s.SetCubeInLoc(11-1, b);
121  s.SetCubeInLoc(12-1, c);
122  }
123  break;
124  case 4:
125  {
126  int a = s.GetCubeInLoc(9-1);
127  int b = s.GetCubeInLoc(10-1);
128  int c = s.GetCubeInLoc(11-1);
129  int d = s.GetCubeInLoc(12-1);
130  s.SetCubeInLoc(9-1, b);
131  s.SetCubeInLoc(10-1, c);
132  s.SetCubeInLoc(11-1, d);
133  s.SetCubeInLoc(12-1, a);
134  }
135  break;
136  case 5:
137  {
138  int a = s.GetCubeInLoc(9-1);
139  int b = s.GetCubeInLoc(10-1);
140  int c = s.GetCubeInLoc(11-1);
141  int d = s.GetCubeInLoc(12-1);
142  s.SetCubeInLoc(9-1, c);
143  s.SetCubeInLoc(10-1, d);
144  s.SetCubeInLoc(11-1, a);
145  s.SetCubeInLoc(12-1, b);
146  }
147  break;
148 
149  case 6: // face 2
150  {
151  int a = s.GetCubeInLoc(2-1);
152  int b = s.GetCubeInLoc(3-1);
153  int c = s.GetCubeInLoc(4-1);
154  int d = s.GetCubeInLoc(10-1);
155  s.SetCubeInLoc(2-1, d);
156  s.SetCubeInLoc(3-1, a);
157  s.SetCubeInLoc(4-1, b);
158  s.SetCubeInLoc(10-1, c);
159  s.FlipCubeOrientation(b);
161  }
162  break;
163  case 7:
164  {
165  int a = s.GetCubeInLoc(2-1);
166  int b = s.GetCubeInLoc(3-1);
167  int c = s.GetCubeInLoc(4-1);
168  int d = s.GetCubeInLoc(10-1);
169  s.SetCubeInLoc(2-1, b);
170  s.SetCubeInLoc(3-1, c);
171  s.SetCubeInLoc(4-1, d);
172  s.SetCubeInLoc(10-1, a);
173  s.FlipCubeOrientation(a);
174  s.FlipCubeOrientation(c);
175  }
176  break;
177  case 8:
178  {
179  int a = s.GetCubeInLoc(2-1);
180  int b = s.GetCubeInLoc(3-1);
181  int c = s.GetCubeInLoc(4-1);
182  int d = s.GetCubeInLoc(10-1);
183  s.SetCubeInLoc(2-1, c);
184  s.SetCubeInLoc(3-1, d);
185  s.SetCubeInLoc(4-1, a);
186  s.SetCubeInLoc(10-1, b);
187  s.FlipCubeOrientation(a);
188  s.FlipCubeOrientation(b);
189  s.FlipCubeOrientation(c);
191  }
192  break;
193 
194  case 9: // face 4
195  {
196  int a = s.GetCubeInLoc(6-1);
197  int b = s.GetCubeInLoc(7-1);
198  int c = s.GetCubeInLoc(8-1);
199  int d = s.GetCubeInLoc(12-1);
200  s.SetCubeInLoc(6-1, d);
201  s.SetCubeInLoc(7-1, a);
202  s.SetCubeInLoc(8-1, b);
203  s.SetCubeInLoc(12-1, c);
204  s.FlipCubeOrientation(c);
206  }
207  break;
208  case 10:
209  {
210  int a = s.GetCubeInLoc(6-1);
211  int b = s.GetCubeInLoc(7-1);
212  int c = s.GetCubeInLoc(8-1);
213  int d = s.GetCubeInLoc(12-1);
214  s.SetCubeInLoc(6-1, b);
215  s.SetCubeInLoc(7-1, c);
216  s.SetCubeInLoc(8-1, d);
217  s.SetCubeInLoc(12-1, a);
218  s.FlipCubeOrientation(a);
220  }
221  break;
222  case 11:
223  {
224  int a = s.GetCubeInLoc(6-1);
225  int b = s.GetCubeInLoc(7-1);
226  int c = s.GetCubeInLoc(8-1);
227  int d = s.GetCubeInLoc(12-1);
228  s.SetCubeInLoc(6-1, c);
229  s.SetCubeInLoc(7-1, d);
230  s.SetCubeInLoc(8-1, a);
231  s.SetCubeInLoc(12-1, b);
232  s.FlipCubeOrientation(b);
234  }
235  break;
236 
237  case 12: // face 1
238  {
239  int a = s.GetCubeInLoc(1-1);
240  int b = s.GetCubeInLoc(2-1);
241  int c = s.GetCubeInLoc(9-1);
242  int d = s.GetCubeInLoc(8-1);
243  s.SetCubeInLoc(1-1, d);
244  s.SetCubeInLoc(2-1, a);
245  s.SetCubeInLoc(9-1, b);
246  s.SetCubeInLoc(8-1, c);
247  s.FlipCubeOrientation(a);
249  }
250  break;
251  case 13:
252  {
253  int a = s.GetCubeInLoc(1-1);
254  int b = s.GetCubeInLoc(2-1);
255  int c = s.GetCubeInLoc(9-1);
256  int d = s.GetCubeInLoc(8-1);
257  s.SetCubeInLoc(1-1, b);
258  s.SetCubeInLoc(2-1, c);
259  s.SetCubeInLoc(9-1, d);
260  s.SetCubeInLoc(8-1, a);
261  s.FlipCubeOrientation(a);
262  s.FlipCubeOrientation(b);
263  }
264  break;
265  case 14:
266  {
267  int a = s.GetCubeInLoc(1-1);
268  int b = s.GetCubeInLoc(2-1);
269  int c = s.GetCubeInLoc(9-1);
270  int d = s.GetCubeInLoc(8-1);
271  s.SetCubeInLoc(1-1, c);
272  s.SetCubeInLoc(2-1, d);
273  s.SetCubeInLoc(9-1, a);
274  s.SetCubeInLoc(8-1, b);
275  s.FlipCubeOrientation(a);
276  s.FlipCubeOrientation(c);
277  }
278  break;
279  case 15: // face 3
280  {
281  int a = s.GetCubeInLoc(4-1);
282  int b = s.GetCubeInLoc(5-1);
283  int c = s.GetCubeInLoc(6-1);
284  int d = s.GetCubeInLoc(11-1);
285  s.SetCubeInLoc(4-1, d);
286  s.SetCubeInLoc(5-1, a);
287  s.SetCubeInLoc(6-1, b);
288  s.SetCubeInLoc(11-1, c);
289  s.FlipCubeOrientation(b);
291  }
292  break;
293  case 16:
294  {
295  int a = s.GetCubeInLoc(4-1);
296  int b = s.GetCubeInLoc(5-1);
297  int c = s.GetCubeInLoc(6-1);
298  int d = s.GetCubeInLoc(11-1);
299  s.SetCubeInLoc(4-1, b);
300  s.SetCubeInLoc(5-1, c);
301  s.SetCubeInLoc(6-1, d);
302  s.SetCubeInLoc(11-1, a);
303  s.FlipCubeOrientation(a);
304  s.FlipCubeOrientation(c);
305  }
306  break;
307  case 17:
308  {
309  int a = s.GetCubeInLoc(4-1);
310  int b = s.GetCubeInLoc(5-1);
311  int c = s.GetCubeInLoc(6-1);
312  int d = s.GetCubeInLoc(11-1);
313  s.SetCubeInLoc(4-1, c);
314  s.SetCubeInLoc(5-1, d);
315  s.SetCubeInLoc(6-1, a);
316  s.SetCubeInLoc(11-1, b);
317  s.FlipCubeOrientation(a);
318  s.FlipCubeOrientation(b);
319  s.FlipCubeOrientation(c);
321  }
322  break;
323  default:
324  break;
325  }
326 
327 }
328 
330 {
331  s1 = s0;
332  ApplyAction(s1, a);
333 }
334 
335 inline uint64_t Factorial(int n)
336 {
337  static uint64_t Factorial[21] =
338  { 1ll, 1ll, 2ll, 6ll, 24ll, 120ll, 720ll, 5040ll, 40320ll, 362880ll, 3628800ll, 39916800ll, 479001600ll,
339  6227020800ll, 87178291200ll, 1307674368000ll, 20922789888000ll, 355687428096000ll,
340  6402373705728000ll, 121645100408832000ll, 2432902008176640000ll };
341 
342  return Factorial[n];
343 }
344 
345 inline int get(uint64_t state, int whichLoc)
346 {
347  //return (state>>(4*whichLoc))&0xF;
348  return (state>>((whichLoc<<2)))&0xF;
349 }
350 
351 inline void set(uint64_t &state, int whichLoc, int cube)
352 {
353  const uint64_t blank = 0xF;
354  uint64_t value = cube;//&0xF;
355  state = state&(~(blank<<((whichLoc<<2))));
356  state |= (value<<((whichLoc<<2)));
357 }
358 
359 inline void swap(uint64_t &state, int loc1, int loc2)
360 {
361  loc1<<=2;
362  loc2<<=2;
363  uint64_t val1 = (state>>(loc1))&0xF;
364  uint64_t val2 = (state>>(loc2))&0xF;
365  const uint64_t blank = 0xF;
366  uint64_t mask = (blank<<(loc1))|(blank<<(loc2));
367  state = state&(~mask);
368  state = state|(val1<<(loc2))|(val2<<(loc1));
369 }
370 
372 {
373  static uint64_t Factorial[21] =
374  { 1ll, 1ll, 2ll, 6ll, 24ll, 120ll, 720ll, 5040ll, 40320ll, 362880ll, 3628800ll, 39916800ll, 479001600ll,
375  6227020800ll, 87178291200ll, 1307674368000ll, 20922789888000ll, 355687428096000ll,
376  6402373705728000ll, 121645100408832000ll, 2432902008176640000ll };
377 
378  return (Factorial[12]/Factorial[12-pieces])*(0x1<<pieces);
379  // return 980995276800ll;
380 }
381 
383 {
384  // return 12;
385  // return 16;
386  // return 64;
387  return (1<<pieces);
388  //return 4;
389 }
390 
391 int64_t Rubik7Edge::getMaxSinglePlayerRank2(int64_t firstIndex)
392 {
393  return Factorial(12)/Factorial(12-pieces);
394  // return (Factorial(12)*(0x1<<7));
395  // return (Factorial(12)*(0x1<<9));
396  // return 81749606400ll;
397 }
398 
399 void Rubik7Edge::rankPlayerFirstTwo(const Rubik7EdgeState &node, int, int64_t &rank)
400 {
401  uint64_t hash1 = 0;
402  for (unsigned int x = 0; x < pieces; x++)
403  {
404  //hash1 = (hash1<<1)+node.GetCubeOrientation(locs[x]);
405  hash1 = (hash1<<1)+node.GetCubeOrientation(x);
406  }
407 
408  rank = hash1;
409 }
410 
411 void Rubik7Edge::rankPlayerRemaining(const Rubik7EdgeState &node, int, int64_t &rank)
412 {
413  int locs[pieces];
414  for (int x = 0; x < 12; x++)
415  {
416  if (node.GetCubeInLoc(x) < pieces)
417  {
418  locs[node.GetCubeInLoc(x)] = x;
419  }
420  }
421 
422  uint64_t hash2 = 0;
423  int numEntriesLeft = 12;
424  for (unsigned int x = 0; x < pieces; x++)
425  {
426  hash2 += locs[x]*Factorial(numEntriesLeft-1)/Factorial(12-pieces);
427  numEntriesLeft--;
428  for (unsigned y = x+1; y < pieces; y++)
429  {
430  if (locs[y] > locs[x])
431  locs[y]--;
432  }
433  }
434  rank = hash2;
435 }
436 
437 
439 {
440  uint64_t hash1 = 0;
441  int locs[pieces];
442  for (int x = 0; x < 12; x++)
443  {
444  if (node.GetCubeInLoc(x) < pieces)
445  {
446  locs[node.GetCubeInLoc(x)] = x;
447  }
448  }
449  for (unsigned int x = 0; x < pieces; x++)
450  {
451  hash1 = (hash1<<1)+node.GetCubeOrientation(x);
452  }
453 
454  uint64_t hash2 = 0;
455  int numEntriesLeft = 12;
456  for (unsigned int x = 0; x < pieces; x++)
457  {
458  hash2 += locs[x]*Factorial(numEntriesLeft-1)/Factorial(12-pieces);
459  numEntriesLeft--;
460  for (unsigned y = x+1; y < pieces; y++)
461  {
462  if (locs[y] > locs[x])
463  locs[y]--;
464  }
465  }
466  return hash1*Factorial(12)/Factorial(12-pieces)+hash2;
467 }
468 
470 {
471  //int cnt = 0;
472  uint64_t bits = hash*Factorial(12-pieces)/Factorial(12);
473  uint64_t hash2 = hash%(Factorial(12)/Factorial(12-pieces));
474  //printf("-bits: %" PRId64 " -perm: %" PRId64 "\n", bits, hash2);
475 
476  int locs[pieces];
477 
478  int numEntriesLeft = 12-pieces+2;
479  for (int x = pieces-1; x >= 0; x--)
480  {
481 // if (numEntriesLeft == 1)
482 // {
483 // locs[x] = (int)hash2;
484 // hash2 = 0;
485 // }
486 // else {
487  locs[x] = (int)(hash2%(numEntriesLeft-1));
488  hash2 = hash2/(numEntriesLeft-1);
489 // }
490  //hash2 += locs[x]*Factorial(numEntriesLeft-1)/Factorial(12-pieces);
491  numEntriesLeft++;
492  //printf("Converting: ");
493  for (unsigned y = x+1; y < pieces; y++)
494  {
495  if (locs[y] >= locs[x])
496  locs[y]++;
497  //printf("%d ", locs[y]);
498  }
499  //printf("\n");
500  }
501 // printf("Locs: ");
502 // for (int x = 0; x < pieces; x++)
503 // {
504 // printf("%d ", locs[x]);
505 // }
506 // printf("\n");
507 
508  for (int x = 0; x < 12; x++)
509  {
510  node.SetCubeInLoc(x, 0xF);
511  //node.SetCubeOrientation(x, 0);
512  }
513  for (int x = pieces-1; x >= 0; x--)
514  {
515  node.SetCubeInLoc(locs[x], x);
516  //node.SetCubeOrientation(locs[x], bits&1);
517  node.SetCubeOrientation(x, bits&1);
518  bits = bits>>1;
519  }
520  int next = pieces;
521  for (int x = 0; x < 12; x++)
522  {
523  if (node.GetCubeInLoc(x) == 0xF)
524  node.SetCubeInLoc(x, next++);
525  //node.SetCubeOrientation(x, 0);
526  }
527 
528 }
529 
531 {
532 
533 }
534 
536 {
537  float scale = 0.3;
538  float offset = 2.0*scale/3.0;
539  glBegin(GL_QUADS);
540  // top
542  //SetCubeColor(0);
543  // 1 - top
544  SetCubeColor(1, false, s);
545  glVertex3f(-scale, -scale, offset/2.0);
546  glVertex3f(-scale, -scale, -offset/2.0);
547  glVertex3f(-scale+offset, -scale, -offset/2.0);
548  glVertex3f(-scale+offset, -scale, offset/2.0);
549 
550  SetCubeColor(5, false, s);
551  // 5 - top
552  glVertex3f(scale, -scale, offset/2.0);
553  glVertex3f(scale, -scale, -offset/2.0);
554  glVertex3f(scale-offset, -scale, -offset/2.0);
555  glVertex3f(scale-offset, -scale, offset/2.0);
556 
557  SetCubeColor(3, false, s);
558  // 3 - top
559  glVertex3f(-offset/2.0, -scale, -scale);
560  glVertex3f(-offset/2.0, -scale, -scale+offset);
561  glVertex3f(offset/2.0, -scale, -scale+offset);
562  glVertex3f(offset/2.0, -scale, -scale);
563 
564  SetCubeColor(7, false, s);
565  // 7 - top
566  glVertex3f(-offset/2.0, -scale, scale);
567  glVertex3f(-offset/2.0, -scale, scale-offset);
568  glVertex3f(offset/2.0, -scale, scale-offset);
569  glVertex3f(offset/2.0, -scale, scale);
570 
572  SetCubeColor(9, true, s);
573  // 9 - bottom
574  glVertex3f(-scale, scale, offset/2.0);
575  glVertex3f(-scale, scale, -offset/2.0);
576  glVertex3f(-scale+offset, scale, -offset/2.0);
577  glVertex3f(-scale+offset, scale, offset/2.0);
578 
579  SetCubeColor(11, true, s);
580  // 11 - bottom
581  glVertex3f(scale, scale, offset/2.0);
582  glVertex3f(scale, scale, -offset/2.0);
583  glVertex3f(scale-offset, scale, -offset/2.0);
584  glVertex3f(scale-offset, scale, offset/2.0);
585 
586  SetCubeColor(10, true, s);
587  // 10 - bottom
588  glVertex3f(-offset/2.0, scale, -scale);
589  glVertex3f(-offset/2.0, scale, -scale+offset);
590  glVertex3f(offset/2.0, scale, -scale+offset);
591  glVertex3f(offset/2.0, scale, -scale);
592 
593  SetCubeColor(12, true, s);
594  // 12 - bottom
595  glVertex3f(-offset/2.0, scale, scale);
596  glVertex3f(-offset/2.0, scale, scale-offset);
597  glVertex3f(offset/2.0, scale, scale-offset);
598  glVertex3f(offset/2.0, scale, scale);
599 
601  SetCubeColor(1, true, s);
602  // 1 - side
603  glVertex3f(-scale, -scale+offset, -offset/2.0);
604  glVertex3f(-scale, -scale+offset, offset/2.0);
605  glVertex3f(-scale, -scale, offset/2.0);
606  glVertex3f(-scale, -scale, -offset/2.0);
607 
608  SetCubeColor(9, false, s);
609  // 9 - side
610  glVertex3f(-scale, scale-offset, -offset/2.0);
611  glVertex3f(-scale, scale-offset, offset/2.0);
612  glVertex3f(-scale, scale, offset/2.0);
613  glVertex3f(-scale, scale, -offset/2.0);
614 
615  SetCubeColor(2, false, s);
616  // 2 - side(1)
617  glVertex3f(-scale, -offset/2.0, -scale+offset);
618  glVertex3f(-scale, offset/2.0, -scale+offset);
619  glVertex3f(-scale, offset/2.0, -scale);
620  glVertex3f(-scale, -offset/2.0, -scale);
621 
622  SetCubeColor(8, false, s);
623  // 8 - side(1)
624  glVertex3f(-scale, -offset/2.0, scale-offset);
625  glVertex3f(-scale, offset/2.0, scale-offset);
626  glVertex3f(-scale, offset/2.0, scale);
627  glVertex3f(-scale, -offset/2.0, scale);
628 
630  SetCubeColor(5, true, s);
631  // 5 - side
632  glVertex3f(scale, -scale+offset, -offset/2.0);
633  glVertex3f(scale, -scale+offset, offset/2.0);
634  glVertex3f(scale, -scale, offset/2.0);
635  glVertex3f(scale, -scale, -offset/2.0);
636 
637  SetCubeColor(11, false, s);
638  // 11 - side
639  glVertex3f(scale, scale-offset, -offset/2.0);
640  glVertex3f(scale, scale-offset, offset/2.0);
641  glVertex3f(scale, scale, offset/2.0);
642  glVertex3f(scale, scale, -offset/2.0);
643 
644  SetCubeColor(4, true, s);
645  // 4 - side(1)
646  glVertex3f(scale, -offset/2.0, -scale+offset);
647  glVertex3f(scale, offset/2.0, -scale+offset);
648  glVertex3f(scale, offset/2.0, -scale);
649  glVertex3f(scale, -offset/2.0, -scale);
650 
651  SetCubeColor(6, false, s);
652  // 6 - side(1)
653  glVertex3f(scale, -offset/2.0, scale-offset);
654  glVertex3f(scale, offset/2.0, scale-offset);
655  glVertex3f(scale, offset/2.0, scale);
656  glVertex3f(scale, -offset/2.0, scale);
657 
659  SetCubeColor(3, true, s);
660  // 3 - side
661  glVertex3f(-offset/2.0, -scale+offset, -scale);
662  glVertex3f(offset/2.0, -scale+offset, -scale);
663  glVertex3f(offset/2.0, -scale, -scale);
664  glVertex3f(-offset/2.0, -scale, -scale);
665 
666  SetCubeColor(10, false, s);
667  // 10 - side
668  glVertex3f(-offset/2.0, scale-offset, -scale);
669  glVertex3f(offset/2.0, scale-offset, -scale);
670  glVertex3f(offset/2.0, scale, -scale);
671  glVertex3f(-offset/2.0, scale, -scale);
672 
673  SetCubeColor(2, true, s);
674  // 2 - side
675  glVertex3f(-scale+offset, -offset/2.0, -scale);
676  glVertex3f(-scale+offset, offset/2.0, -scale);
677  glVertex3f(-scale, offset/2.0, -scale);
678  glVertex3f(-scale, -offset/2.0, -scale);
679 
680  SetCubeColor(4, false, s);
681  // 4 - side
682  glVertex3f(scale-offset, -offset/2.0, -scale);
683  glVertex3f(scale-offset, offset/2.0, -scale);
684  glVertex3f(scale, offset/2.0, -scale);
685  glVertex3f(scale, -offset/2.0, -scale);
686 
687 
689  SetCubeColor(7, true, s);
690  // 7 - side
691  glVertex3f(-offset/2.0, -scale+offset, scale);
692  glVertex3f(offset/2.0, -scale+offset, scale);
693  glVertex3f(offset/2.0, -scale, scale);
694  glVertex3f(-offset/2.0, -scale, scale);
695 
696  SetCubeColor(12, false, s);
697  // 12 - side
698  glVertex3f(-offset/2.0, scale-offset, scale);
699  glVertex3f(offset/2.0, scale-offset, scale);
700  glVertex3f(offset/2.0, scale, scale);
701  glVertex3f(-offset/2.0, scale, scale);
702 
703  SetCubeColor(8, true, s);
704  // 8 - side
705  glVertex3f(-scale+offset, -offset/2.0, scale);
706  glVertex3f(-scale+offset, offset/2.0, scale);
707  glVertex3f(-scale, offset/2.0, scale);
708  glVertex3f(-scale, -offset/2.0, scale);
709 
710  SetCubeColor(6, true, s);
711  // 6 - side
712  glVertex3f(scale-offset, -offset/2.0, scale);
713  glVertex3f(scale-offset, offset/2.0, scale);
714  glVertex3f(scale, offset/2.0, scale);
715  glVertex3f(scale, -offset/2.0, scale);
716 
717  glEnd();
718 
719 }
722 void Rubik7Edge::OpenGLDraw(const Rubik7EdgeState&, const Rubik7EdgeState&, float) const
723 {
724 
725 }
726 
728 {
729 
730 }
731 
732 void Rubik7Edge::SetCubeColor(int which, bool face, const Rubik7EdgeState &s) const
733 {
734  int cubes_first[12] = { 0, 1, 0, 2, 0, 3, 0, 1, 1, 2, 3, 4};
735  int cubes_second[12] = { 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5};
736 
737  int theColor = -1;
738  int cube = s.GetCubeInLoc(which-1);
739  if (cube == 0xF)
740  {
741  glColor3f(0.0, 0.0, 0.0);
742  return;
743  }
744  bool flipped = s.GetCubeOrientation(cube);
745  if (flipped == face)
746  theColor = cubes_first[cube];
747  else
748  theColor = cubes_second[cube];
749 
750  switch (theColor)
751  {
752  case 0: glColor3f(1.0, 0.0, 0.0); break;
753  case 1: glColor3f(0.0, 1.0, 0.0); break;
754  case 2: glColor3f(0.0, 0.0, 1.0); break;
755  case 3: glColor3f(1.0, 1.0, 0.0); break;
756  case 4: glColor3f(1.0, 0.75, 0.0); break;
757  case 5: glColor3f(1.0, 1.0, 1.0); break;
758  default: assert(false);
759  }
760 }
Rubik7EdgeState
Definition: RubiksCube7Edges.h:19
Rubik7EdgeState::FlipCubeOrientation
void FlipCubeOrientation(int whichCube)
Definition: RubiksCube7Edges.h:56
Rubik7Edge::getMaxSinglePlayerRank
int64_t getMaxSinglePlayerRank() const
Definition: RubiksCube7Edges.cpp:371
Rubik7EdgeState::SetCubeOrientation
void SetCubeOrientation(int whichCube, bool flip)
Definition: RubiksCube7Edges.h:48
Rubik7EdgeMove::act
Rubik7EdgeAction act
Definition: RubiksCube7Edges.h:97
Rubik7EdgeMove
Definition: RubiksCube7Edges.h:95
Rubik7Edge::GetActions
virtual void GetActions(const Rubik7EdgeState &nodeID, std::vector< Rubik7EdgeAction > &actions) const
Definition: RubiksCube7Edges.cpp:37
d
mcData d[]
Definition: MotionCaptureMovement.cpp:21
Factorial
uint64_t Factorial(int n)
Definition: RubiksCube7Edges.cpp:335
pieces
const int pieces
Definition: RubiksCube7Edges.h:17
Rubik7EdgeState::SetCubeInLoc
void SetCubeInLoc(int whichLoc, int cube)
Definition: RubiksCube7Edges.h:37
Rubik7Edge::OpenGLDraw
virtual void OpenGLDraw() const
Definition: RubiksCube7Edges.cpp:530
Rubik7Edge::rankPlayerFirstTwo
void rankPlayerFirstTwo(const Rubik7EdgeState &s, int who, int64_t &rank)
Definition: RubiksCube7Edges.cpp:399
Rubik7Edge::GetNextState
virtual void GetNextState(const Rubik7EdgeState &, Rubik7EdgeAction, Rubik7EdgeState &) const
Definition: RubiksCube7Edges.cpp:329
Rubik7Edge::GetStateFromHash
virtual void GetStateFromHash(uint64_t hash, Rubik7EdgeState &node) const
Definition: RubiksCube7Edges.cpp:469
Rubik7Edge::ApplyAction
virtual void ApplyAction(Rubik7EdgeState &s, Rubik7EdgeAction a) const
Definition: RubiksCube7Edges.cpp:72
Rubik7Edge::GetStateHash
virtual uint64_t GetStateHash(const Rubik7EdgeState &node) const
Definition: RubiksCube7Edges.cpp:438
RubiksCube7Edges.h
Rubik7Edge::ApplyMove
void ApplyMove(Rubik7EdgeState &s, Rubik7EdgeMove *a)
Definition: RubiksCube7Edges.cpp:53
set
void set(uint64_t &state, int whichLoc, int cube)
Definition: RubiksCube7Edges.cpp:351
Rubik7Edge::getMaxSinglePlayerRank2
int64_t getMaxSinglePlayerRank2()
Definition: RubiksCube7Edges.cpp:382
GLUtil.h
Rubik7EdgeState::GetCubeInLoc
int GetCubeInLoc(int whichLoc) const
Definition: RubiksCube7Edges.h:33
get
int get(uint64_t state, int whichLoc)
Definition: RubiksCube7Edges.cpp:345
Rubik7Edge::rankPlayerRemaining
void rankPlayerRemaining(const Rubik7EdgeState &s, int who, int64_t &rank)
Definition: RubiksCube7Edges.cpp:411
Rubik7Edge::UndoMove
void UndoMove(Rubik7EdgeState &s, Rubik7EdgeMove *a)
Definition: RubiksCube7Edges.cpp:58
Rubik7Edge::SetCubeColor
void SetCubeColor(int which, bool face, const Rubik7EdgeState &) const
Definition: RubiksCube7Edges.cpp:732
Rubik7Edge::GetSuccessors
virtual void GetSuccessors(const Rubik7EdgeState &nodeID, std::vector< Rubik7EdgeState > &neighbors) const
Definition: RubiksCube7Edges.cpp:27
Rubik7EdgeState::GetDual
void GetDual(Rubik7EdgeState &s) const
Definition: RubiksCube7Edges.cpp:13
Rubik7EdgeAction
int Rubik7EdgeAction
Definition: RubiksCube7Edges.h:93
swap
void swap(uint64_t &state, int loc1, int loc2)
Definition: RubiksCube7Edges.cpp:359
Rubik7Edge::GetAction
virtual Rubik7EdgeAction GetAction(const Rubik7EdgeState &s1, const Rubik7EdgeState &s2) const
Definition: RubiksCube7Edges.cpp:46
Rubik7EdgeState::GetCubeOrientation
bool GetCubeOrientation(int whichCube) const
Definition: RubiksCube7Edges.h:44
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
bits
constexpr uint64_t bits(uint64_t a, uint64_t b, uint64_t c)
Definition: Hexagon.cpp:16