Introducing Rubikraze, my current project
This is the first post I'm making in a while. I, of course, have not stopped learning and coding for the past year.
I won a national competition in programming, graduated high school, and developed a really useful Chrome extension called Convertool, which I'll be talking about soon in another post.
I have taken a break from blogging, not from programming :).
I'll talk about Convertool and the National Olympiad in Informatics in other posts so nothing gets mixed. In this post I'll write about the project I'm currently working on, Rubikraze (Oh and by the way, from now on, my posts will have a different font, Consolas, because I think it represents better my blog's theme, and is kind of more comfortable to read).
I've always liked Rubik cubes since I was around 14 years old, I used to dedicate them hours on end. I've got a small collection, but of course I have picked other interests since then.
Now that I've gotten a lot into competitive programming and computer science, I'm more and more fascinated by the hidden mathematics behind the classic Rubik's cube. And since I'm practicing my C++ problem solving abilities (which involve a lot of math), I thought about doing some experiments here and there relating to the Rubik's cube. If something cool comes out of this, I'll probably expand it into a website, where I can demonstrate a lot of frontend, backend, and problem solving abilities. But for the moment, I think C++ is a good choice for this.
The first thing I wanted to do is simulate a Rubik's cube with all its possible movements. For this, I'm creating a three dimensional array called cube that contains 6 arrays that represent the faces of the cube. Inside each of these six faces, there are three arrays with three objects each, reflecting the 3x3 configuration of the Rubik's cube faces. This structure simplifies coding the movement functions. Instead of changing values at positions 0, 3, and 6 (as I would with a single 9-element array), I can change the first value of each of the three subarrays.
For explanation purposes, let's use the following terminology:
- The entire cube array is the "superarray" (representing the whole cube).
- Each of the six arrays inside it is a "bigarray" (example in red).
- Each array inside a bigarray is a "subarray" (example in green).
- Each subarray contains characters representing colors (example in blue).
So we end up with something that looks like this (note: C++ uses {} for arrays, but I'll use [] for clarity):
cube = [[[W, W, W], [W, W, W], [W, W, W]],
[[Y, Y, Y], [Y, Y, Y], [Y, Y, Y]],
[[R, R, R], [R, R, R], [R, R, R]],
[[O, O, O], [O, O, O], [O, O, O]],
[[B, B, B], [B, B, B], [B, B, B]],
[[G, G, G], [G, G, G], [G, G, G]]]
After this, I create a class called Face, and declare the 6 faces of the Rubik's cube taking the center color as reference (the center colors inside the faces of the Rubik's cube never move because they are the "core" of the cube).
Each Face object references each of the 6 bigarrays inside the cube, and it also declares which faces are above, below, right to, and left to it (we need this information because when we move a face in the Rubik's cube, other faces are also affected).
This is all I'm going to talk about for today's post. Of course this is just the beginning, I still need to implement the movements functions. But I will not get into that just yet.
You see, if the colors of a Rubik's cube are assigned arbitrarily, odds are, that Rubik's cube will not be possible to solve. Just like when you rotate a corner in the Rubik's cube, it becomes unsolvable. This is a very important thing to take into account, but I want to get deeper into it, and see if I can write a program that can immediately know if a Rubik's cube configuration is unsolvable. This is a work in progress, and maybe it is just impossible to know if a Rubik's cube is solvable by using simple addition, but I still want to write about it. More of that in the next post.
As always, thanks for reading.
Comments
Post a Comment