{"id":665,"date":"2014-11-05T03:55:52","date_gmt":"2014-11-05T03:55:52","guid":{"rendered":"http:\/\/anthonybarranco.com\/blog\/?p=665"},"modified":"2014-11-05T04:37:10","modified_gmt":"2014-11-05T04:37:10","slug":"rubiks-cube-ai-1","status":"publish","type":"post","link":"http:\/\/anthonybarranco.com\/blog\/rubiks-cube-ai-1\/","title":{"rendered":"Rubiks Cube AI Part 1 &#8211; Parity"},"content":{"rendered":"<p>Rubiks Cubes! I cant solve them to completetion for the life of me. But now I can just solve them using an AI.<\/p>\n<p>But before jumping into heuristics, A* algorithms, and all kinds of solving. First, let us consider a random Rubiks Cube itself. Is the cube actually\u00a0<em>solveable\u00a0<\/em>in the first place? Can we go from the random state pictured above to a solved cube?<\/p>\n<p>The answer is no. The Rubiks Cube parity has been altered!<\/p>\n<p><!--more--><\/p>\n<h1>Intro<\/h1>\n<p>Note that this is for a classic Rubiks cube (3x3x3).<\/p>\n<p>Quite simply, the cube&#8217;s corners have been twisted. Its the equivalent of taking the stickers off a normal Rubiks Cube and sticking them into different positions. It makes the cube\u00a0<em>impossible to solve<\/em>. Or at least, the chances of getting random stickers into a solveable position is tough. The total number of possible <em>valid<\/em>\u00a0Rubiks Cube scrambles is\u00a0<strong>43 quintillion<\/strong> (8! x 3^7 x (12!\/2) x 2^11). The total number of possible Rubiks Cube scrambles\u00a0<em>in total (both valid and invalid)\u00a0<\/em>is a rediculous\u00a0<strong>519 quintillion <em>. <\/em><\/strong>(8! x 3^8 x 12! x 2^12) And that&#8217;s not including the possibility of switching stickers (invalid cubie possibilities, but more on that later). So the number is even more astronomical.<\/p>\n<p><strong><em>You have a 1\/12 chance for a random Rubiks Cube to be valid (that was made with valid cube colors)<\/em><\/strong><\/p>\n<p><em>What is a Rubiks Cube made of?<\/em><br \/>\nAs a 2D representation, a Rubiks Cube has unique 54 squares (or stickers) and there are 6 colors represented on each of the 6 faces of the cube. So there are 9 squares of each color. Usually Red, Orange, Yellow, Green, Blue, White.<\/p>\n<p>There is more to a Rubiks Cube though. Categorically, you can split a Rubiks Cube up into 3\u00a0types of &#8220;cubes&#8221;. Otherwise known as\u00a0<em>Cubies<\/em>. Its easier to picture this in 3D. A\u00a0<em>Cubie<\/em> is a 3D cube that represents part of the whole Cube.<br \/>\nThere are\u00a026\u00a0<em>Cubies<\/em> on a Rubiks Cube.<br \/>\n8 of them are\u00a0<em>Corner Cubies<\/em> and\u00a0<em>12\u00a0<\/em>of them are\u00a0<em>Edge Cubies<\/em>. \u00a0The other 6 are\u00a0<em>Center Cubies<\/em>.<br \/>\nThe main difference between corner and edge cubies are that corner cubies have\u00a0<em>3 different colors<\/em> and edge cubies have\u00a0<em>2 different colors<\/em>. Center cubies\u00a0<em>only have 1<\/em> and its impossible to actually move a center cubie.<\/p>\n<p><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/2000px-Rubiks_cube.svg_.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-682\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/2000px-Rubiks_cube.svg_-288x300.png\" alt=\"2000px-Rubik's_cube.svg\" width=\"288\" height=\"300\" srcset=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/2000px-Rubiks_cube.svg_-288x300.png 288w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/2000px-Rubiks_cube.svg_-983x1024.png 983w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/2000px-Rubiks_cube.svg_-624x649.png 624w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/2000px-Rubiks_cube.svg_.png 2000w\" sizes=\"auto, (max-width: 288px) 100vw, 288px\" \/><\/a><\/p>\n<p>So right off the bat, there are a bunch of ways to tell if a Cubie is not solveable. It has to have 6 colors and 9 stickers or squares of each color. Each color has to be represented in a center cubie\u00a0<em>only once<\/em>. No more, no less. If you peel off a center sticker and replace it with a different color, the cube is immediately not &#8220;solveable&#8221;.<\/p>\n<p>However, just these alone are not enough. You need more than that. Namely, none of those checks look at\u00a0<em>parity.<\/em> The parity of a cube needs to be correct in order for all the cubies to be able to properly be orientated in their home positions.\u00a0<em>Home positions<\/em> in a Rubiks Cube is the position on a face in which the cubie is facing the right direction. For example, the Blue\/Yellow edge cubie has its Blue side touching the Blue center and the Yellow side is touching the Yellow Center. Its in its home position. When all cubies are in their home position with correct orientation, the cubie is solved.<\/p>\n<p>So in my original example at the top of the page, the picture has the corners all twisted. The parity is off because we&#8217;ve twisted corner cubies and their orientations can never be correct with the rest of the cube now. Those corners can never be in the right position and orientation without the rest of the cube being incorrect!<\/p>\n<p>So how does one check for these? Three tests:<\/p>\n<ol>\n<li>Permutation<\/li>\n<li>Corner Parity<\/li>\n<li>Edge Parity<\/li>\n<\/ol>\n<p>Believe it or not, I found an incredible lack of information online regarding these tests. The best rescources I can find through Google were <a href=\"http:\/\/www.ryanheise.com\/cube\/cube_laws.html\">here<\/a>,\u00a0<a href=\"http:\/\/math.stackexchange.com\/questions\/127577\/how-to-tell-if-a-rubiks-cube-is-solvable\">here<\/a>\u00a0and <a href=\"http:\/\/rosettacode.org\/wiki\/User:Arjun_sunel\/Solvability_of_a_3x3x3_Rubik's_Cube_State%3F\">here<\/a>, and only the latter skantly goes into detail how to actually perform the tests. And any information about performing the tests is either a little off or under explained! \u00a0At least, for example, permutation tests only consider one side of a cube and not the WHOLE cube. So thats why I felt it necessary to make this lengthy blog in detail.<\/p>\n<h2>Permutation Test<\/h2>\n<div id=\"attachment_681\" style=\"width: 195px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/Passes_edge_and_corner_test.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-681\" class=\"wp-image-681 size-full\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/Passes_edge_and_corner_test.png\" alt=\"Passes_edge_and_corner_test\" width=\"185\" height=\"186\" srcset=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/Passes_edge_and_corner_test.png 185w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/Passes_edge_and_corner_test-150x150.png 150w\" sizes=\"auto, (max-width: 185px) 100vw, 185px\" \/><\/a><p id=\"caption-attachment-681\" class=\"wp-caption-text\">Fails permutation test, but corner and edge parity tests pass!<\/p><\/div>\n<p>In my opinion, the easiest test to implement.<br \/>\nSimply consider each unqiue Edge and Corner Cubie as an arbitrary unique number. Seperately for Edge and Corner, pick a fixed cubie to start from and consider what # is actually in that position and repeat for all Edges or Corners. Then if the total number of inversions to make both\u00a0lists (edges and corners) ordered is\u00a0<em>even<\/em>, you have a valid permutation.<\/p>\n<p>Rewind.<br \/>\nLets start with edges, we have 12 unqiue cubies for them.<br \/>\n<strong>RW &#8211; RG &#8211; RB &#8211; RY &#8211; GW &#8211; GY &#8211; GO &#8211; YB &#8211; YO &#8211; BW &#8211; BO &#8211; OW<br \/>\n<\/strong><strong>0 \u00a0 \u00a0 &#8211; \u00a01 \u00a0 &#8211; \u00a02 \u00a0 &#8211; \u00a03 \u00a0 &#8211; \u00a0 4 \u00a0 &#8211; \u00a05 \u00a0 &#8211; \u00a0 6 \u00a0 &#8211; \u00a07 \u00a0&#8211; \u00a08 \u00a0 &#8211; \u00a0 9 \u00a0 &#8211; \u00a010 \u00a0&#8211; \u00a0 11<\/strong><\/p>\n<p>This is the order I went with. I number each of these cubies 0 to 11. Basically, if I look at\u00a0<em>any<\/em> edge on the cubie in my program (or physically in real life), you can tell that if the edge cubie is R &amp; Y or Y &amp; R, then its\u00a0<em>value<\/em> is\u00a0<strong>3.<\/strong> R &amp; W or W &amp; R is <b>0.<\/b>\u00a0And so on.<\/p>\n<p>To make things easier, its also nice to look at the\u00a0<strong>positions<em>\u00a0<\/em><\/strong>in the same way. So if I say &#8220;go to position 0 for edges&#8221;, you&#8217;d look at where\u00a0<strong>RW<\/strong> is\u00a0<em>supposed to be (its home position).<\/em> Sometimes this is hard for newbies to Rubiks Cubes when someone says go look at a position. Its where the Red and White cubie would be if you would look at a solved cube. That never changes! What&#8217;s\u00a0<em>in that position<\/em> changes.<\/p>\n<p>So consider the list <b>G =\u00a0<\/b>{\u00a00, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}<br \/>\nWe&#8217;d agree with the explanation above that is &#8220;solved&#8221;. It doesn&#8217;t mean the cube itself is actually solved, but that order is how we\u00a0<em>expect<\/em> the cubes to be in when we solve a cube.<\/p>\n<p>If we have the list\u00a0\u00a0<strong>A<\/strong><strong>\u00a0=\u00a0<\/strong>{7, 6, 4, 0, 11, 10, 5, 1, 9, 8, 2, 3}<br \/>\nThat means YB is where RW should be, GO is where RG should be, and so on.<br \/>\nFrom this list, find the number of\u00a0<em>inversions<\/em> to get from\u00a0<strong>A\u00a0<\/strong>to\u00a0<strong>G.\u00a0<\/strong>Inversions are simply the number of times each number has to be swapped to get into sorted order. Read it from left to right to understance easier.<\/p>\n<p>Very simple inversion code:<\/p>\n<p><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/inversion.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-671 size-full\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/inversion.png\" alt=\"inversion\" width=\"523\" height=\"193\" srcset=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/inversion.png 523w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/inversion-300x110.png 300w\" sizes=\"auto, (max-width: 523px) 100vw, 523px\" \/><\/a><\/p>\n<p>Perhaps <strong>A<\/strong> is a bit of a\u00a0complex example, but it would take\u00a038 inversions to get to list <strong>G<\/strong>\u00a0from it.<\/p>\n<p>Take the results from doing this with corners, handled the exact same way (but from 0 to 7 instead), and <i>add the results together<\/i>.<\/p>\n<p>If the result of cornerInversions + edgeInversions is <strong>even<\/strong> then a whopping\u00a0<strong>1\/2<\/strong> of invalid possibilities are rejected! Its an easy and effective test to do!<\/p>\n<p>If its odd, then two cubies or more are out of parity. They&#8217;ve been swapped, possibly from deconstructing and reconstructing the cube. (eg, you switched BO and OW or something)<\/p>\n<p>The reason for this test is because each inversion is a &#8220;swap&#8221;, and there can never be a total number of odd swaps. In other words, no matter how many times you turn a Rubiks cube, if they&#8217;re legal (valid) twists of the cube &#8211; they always result in even swaps in total.<\/p>\n<h2>\u00a0Corner Parity Test<\/h2>\n<div id=\"attachment_679\" style=\"width: 199px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/Fail_corner.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-679\" class=\"wp-image-679 size-full\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/Fail_corner.png\" alt=\"Fail_corner\" width=\"189\" height=\"191\" \/><\/a><p id=\"caption-attachment-679\" class=\"wp-caption-text\">Invalid Corner orientation, but the permutation and edge are not!<\/p><\/div>\n<p>A bit tougher. Look at a face of your cube straight on. Never change the orientation of the cube from here on out. Always look at that face and always make sure the top and bottom colors never change.<\/p>\n<p>For example. if I look at the Orange face on a classic Rubiks Cube and Yellow is the top face, then White is\u00a0<em>garunteed<\/em> to be my bottom face.\u00a0Blue\u00a0is my right face. Green is my left face. And Red is my back face. Choose however you want to look at it, but just make sure you never change it in the middle of Corner and Edge Parity tests.<\/p>\n<p>We&#8217;re going to do something similar to the permutations in regards to positions. So from 0 to 7, we&#8217;re going to look at these positions the same all the time. Its contents can be different, but the positions are where we expect the cubes in their home positions.<\/p>\n<p>For example,<br \/>\n<strong>RGW &#8211; RBW &#8211; RGY &#8211; RBY &#8211; GOW &#8211; GOY &#8211; YOB &#8211; BOW<br \/>\n0 \u00a0 \u00a0 &#8211; \u00a0 \u00a01 \u00a0 \u00a0 &#8211; \u00a0 2 \u00a0 &#8211; \u00a0 \u00a03 \u00a0 \u00a0&#8211; \u00a0 \u00a0 4 \u00a0 \u00a0 &#8211; \u00a0 \u00a05 \u00a0 \u00a0 &#8211; \u00a0 6 \u00a0 \u00a0&#8211; \u00a0 7<\/strong><\/p>\n<p>When I look at position 2, it could have any corner cubie in any orientation in it, but its where\u00a0RGY should be if its a solved cube.<\/p>\n<p>Starting from 0, look at every position to 7 and consider the\u00a0<em>orientation<\/em> of the cubie. What do I mean by that?\u00a0Again, in my example picture, the corner cubies have been twisted. We&#8217;re testing for this!<\/p>\n<p>How its going to work is we treat the top and bottom colors as the\u00a0<em>same<\/em>. In other words, forget the sides of the corner cubies that are Yellow and White in my example. Treat Yellow and White as if they were exactly the same color. Its kind of weird, but bear with me.<\/p>\n<p>If the\u00a0<strong>White or Yellow<\/strong>\u00a0part of a corner cubie is touching\u00a0<strong>White or Yellow<\/strong> center, then we know that our cubie is\u00a0<em>correctly orientated.\u00a0<\/em>If the top\/bottom color is not touching the center of their friend, then we know that the cubie is\u00a0<em>not correctly orientated<\/em>. The issue is the cubie can be two kinds of not correct &#8211; clockwise or counter clockwise.<\/p>\n<p>The way to tell which kind of incorrect orientation is by imaginging you&#8217;re twisting the corner cubie yourself. You&#8217;re pulling out that corner cubie from your Rubiks Cube and physically rotating it in your mind. How many clockwise turns does it take to get that top\/bottom color to touch ? One or two turns?<br \/>\nAn important thing to remember is that using your left or right hand matters here. A clockwise turn with your left hand is not the &#8220;same&#8221; turn with your right hand.<\/p>\n<p>Its tough to explain in words &#8211; here might be a few pictures to help:<\/p>\n<div id=\"attachment_674\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222143.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-674\" class=\"wp-image-674 size-medium\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222143-300x168.jpg\" alt=\"20141104_222143\" width=\"300\" height=\"168\" srcset=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222143-300x168.jpg 300w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222143-1024x576.jpg 1024w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222143-624x351.jpg 624w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-674\" class=\"wp-caption-text\">Value = 2<\/p><\/div>\n<div id=\"attachment_675\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222456_4_bestshot.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-675\" class=\"wp-image-675 size-medium\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222456_4_bestshot-300x168.jpg\" alt=\"20141104_222456_4_bestshot\" width=\"300\" height=\"168\" srcset=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222456_4_bestshot-300x168.jpg 300w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222456_4_bestshot-1024x576.jpg 1024w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222456_4_bestshot-624x351.jpg 624w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-675\" class=\"wp-caption-text\">Twist the corner piece<\/p><\/div>\n<div id=\"attachment_676\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222032.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-676\" class=\"wp-image-676 size-medium\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222032-300x168.jpg\" alt=\"20141104_222032\" width=\"300\" height=\"168\" srcset=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222032-300x168.jpg 300w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222032-1024x576.jpg 1024w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_222032-624x351.jpg 624w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-676\" class=\"wp-caption-text\">Value = 1 but if you rotate it again the value will be 0<\/p><\/div>\n<p>This is where corner positions play an important role. For each of the corner cubie positions we discussed before from 0 to 7, you have to play with your corners to figure out which corners orientations take 2 rotations and which corners only take 1. You can determine this and kind of hard code it into your program by considering which side White or Yellow is on (or whatever your top color is) and simply loop through your structure of 3 colors (corner cubie). If the White or Yellow cubie is in corner X (0-7) and the position inside your corner cubie is Y (0-2), then its either correctly, clockwise, or counterclockwise orientated.<\/p>\n<p>Those three results should be numbered. 0 for correct, 1 for clockwise, 2 for counterclockwise.<br \/>\nFor each of your 8 corner cubies, add those numbers together.\u00a0<strong>If the total number is divisible by 3<\/strong>, then your corner cubies have a valid parity. Thats\u00a0<strong>1\/3<\/strong> invalid possibilities rejected for your Cube!<\/p>\n<h2>\u00a0Edge Parity Test<\/h2>\n<div id=\"attachment_680\" style=\"width: 194px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/Fail_edge.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-680\" class=\"wp-image-680 size-full\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/Fail_edge.png\" alt=\"Fail_edge\" width=\"184\" height=\"189\" \/><\/a><p id=\"caption-attachment-680\" class=\"wp-caption-text\">Edge orientation is invalid, but corner and permutation are not!<\/p><\/div>\n<p>The hardest test to\u00a0program out. I personally went through and found every possibility for this on my Rubiks Cube and hard coded this test pretty throughoughly at first. But, there is an easier way to figure this out on the fly. It has to do with opposing faces, much similar to the Top\/Bottom (White\/Yellow) in the Corner Parity Test.<\/p>\n<p>Again, make sure you look at the same face as you did before with the same orientation in the Corner Parity Test too. (Mine was looking at orange, Yellow on Top, White on the bottom)<\/p>\n<p>White and Yellow are opposing faces for me. Blue and Green are also opposing. And so is Red and Orange.\u00a0Think of the opposing colors as the same colors, again similar to White\/Yellow. If the opposing color is correctly touching the center opposing color correctly, then it is correctly orientated.<\/p>\n<div id=\"attachment_677\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221034.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-677\" class=\"wp-image-677 size-medium\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221034-300x168.jpg\" alt=\"20141104_221034\" width=\"300\" height=\"168\" srcset=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221034-300x168.jpg 300w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221034-1024x576.jpg 1024w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221034-624x351.jpg 624w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-677\" class=\"wp-caption-text\">Red-Blue is incorrectly orientated! Notice how the back face is rotated.<\/p><\/div>\n<p>For example, Orange and Red are again opposing colors. If you have Red\/White edge in the position where Orange\/Yellow should be, and Red is touching Orange center and White is touching Yellow, your cube is <em>not correctly<\/em><strong>\u00a0<\/strong>orientated!<\/p>\n<p>For every edge cubie, go through each position (0 to 11) and perform this test. If its\u00a0<em>not correctly orientated,\u00a0<\/em>increment a counter. If that counter is divisible by 2 after testing every edge cubie, then you&#8217;ve just rejected another\u00a0<strong>1\/2 <\/strong>of invalid configurations!<\/p>\n<div id=\"attachment_678\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221007.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-678\" class=\"wp-image-678 size-medium\" src=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221007-300x168.jpg\" alt=\"20141104_221007\" width=\"300\" height=\"168\" srcset=\"http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221007-300x168.jpg 300w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221007-1024x576.jpg 1024w, http:\/\/anthonybarranco.com\/blog\/wp-content\/uploads\/2014\/11\/20141104_221007-624x351.jpg 624w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-678\" class=\"wp-caption-text\">Blue-Red is correctly orientated! Notice how only the right and top faces needed to be rotated. NOT the front or back.<\/p><\/div>\n<p>But first, why does this work? If you read Arjun&#8217;s page earlier, it has to do with using the front and back faces to flip edges. If you&#8217;re looking at a cube at the orange face, then in order to get an incorrectly orientated edge into position, you need to use either the back or front faces to turn. For correctly orientated edges, you don&#8217;t need to do this! You can use the Top, Bottom, Left, or Right faces to get that cubie into home position with the right orientation.<\/p>\n<p>Here&#8217;s a good video about edges as well:<br \/>\n<iframe loading=\"lazy\" src=\"\/\/www.youtube.com\/embed\/7SzFNhs_ZRE\" width=\"420\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>Results<\/h2>\n<p>And that&#8217;s it. If you cube goes through all 3 of these, and return true, you have a valid Rubiks Cube that can be solved! If even one fails, you have an invalid cube that cannot be solved.<\/p>\n<p>This <a href=\"https:\/\/github.com\/AnthonyB28\/RubiksAI\/tree\/Submission\">branch<\/a>\u00a0on Github has only the code pertaining to Rubiks Cube parity\u00a0tests done in C++. I hard coded EdgeParity, but you can do\u00a0it\u00a0using the method with opposing colors too.<\/p>\n<p>This is just part one of several. I&#8217;ll cover how I designed and implemented my Rubiks Cube representation next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rubiks Cubes! I cant solve them to completetion for the life of me. But now I can just solve them using an AI. But before jumping into heuristics, A* algorithms, and all kinds of solving. First, let us consider a random Rubiks Cube itself. Is the cube actually\u00a0solveable\u00a0in the first place? Can we go from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":687,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,69],"tags":[77,78,42,46,75,70,32,37,74,76],"class_list":["post-665","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-portfolio","category-programming-gems","tag-ai","tag-algorithm","tag-c","tag-cpp","tag-cube","tag-gems","tag-portfolio-2","tag-programming","tag-rubiks","tag-rubiks-cube"],"_links":{"self":[{"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/posts\/665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/comments?post=665"}],"version-history":[{"count":14,"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/posts\/665\/revisions"}],"predecessor-version":[{"id":693,"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/posts\/665\/revisions\/693"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/media\/687"}],"wp:attachment":[{"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/media?parent=665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/categories?post=665"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/anthonybarranco.com\/blog\/wp-json\/wp\/v2\/tags?post=665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}