A Rubik's Cube for Android

By Sergei Alekseev(Game Developer) on July 16 2020

Views

10280

#android#gamedev#opengl#showcase

Introduction

I've recently found the sources of Rubik's Cube implementation in my old bitbucket account. It was written in Java at the time when developers used Eclipse to develop for the Android platform. I've migrated sources to my new repository and made it opensource. Compiled it with Android Studio and published to my playmarket account again. Why again? Below is the story of that Rubik's Cube path.

The story

Rubiks Cube Gameplay

Offline version

The passion of solving Rubik's Cube has been following me since my eighth grade(2006). I remember my first experience in trying to solve the puzzle without knowing the correct algorithms. It was given to me by an American guy who came to my native city to do teaching at English summer classes just to try it out. I was rotating the sides all day long trying to get my way getting this thing solved. I reached the moment when only one corner of the cube wasn't in the correct orientation. Image is taken from the Internet:

Rubik's Cube Offline Version

Finally, I gave up and asked the teacher to teach me how to solve it. It happened to be that there was an issue with that cube's corner. After he fixed it he taught me how to solve it. Since that time I remember the basic algorithm of solving it: top side, center side, and the bottom side.

First Version

Later at school, I was getting familiar with programming language Pascal and Delphi and then I've implemented the first version of Rubik's Cube 3x3x3 version written in Delphi. It was 2009. I wish I could have the sources of it right now to see it. The solution was not pretty good: all areas of rotatable cube's sides were hardcoded. And the logic was like: if the left mouse is down and it is moving on some area to specific direction then rotate X side, etc. At the university, I used it as course work.

C++ Epoch

Later in 2012(I believe it was that year) I've rewritten it to pure C++ and made a 4x4x4 version. Then I've found some consistent pattern in my code for extending it to multi-sized and I've developed a multi-sized version also in C++ which was much better than the previous version: There was the ability to observe cube and to swipe any side from any angle. I used the color buffer rendering detection method: Each piece of the cube was rendered twice. The first regular render was with the real color of the cube and the second was color buffer render where each piece of the cube had a unique color. So when the mouse left was down it picked up the color of the second color buffer render under the cursor position and the necessary piece was found by its unique color. Very easy method but very unoptimized.

Android Epoch

In 2013 I was an Android Developer and I've rewritten it for Android. It was a simple copy-paste from C++ to Java. But the main issue was in the detection of a touching piece of the cube. It was too heavy for android to maintain two render buffers and here a challenge has started. I was looking for the methods of mouse touch detection and finally stopped at ray with triangle intersection which was working perfectly when I implemented it. Here is the implementation of it. Then I've published it to the android playmarket. It got about 45k of installs in total. Then I decided to integrate ad there and this is how I was banned because of violations of rubiks.com copyrights.

Current Epoch

I was cleaning my old bitbucket repositories and found the source of the cube then decided to give it one more chance and make it open source. I removed the ad, compiled it with Android Studio, and published it to google play again. Let it be alive!

There is a lot of messy code right now. I did not use any patterns in that past. I will refactor it someday and write documentation. Probably will add more features to it. But for now, it is just an act of memory recovery.

Rubik's Cube Android Version

Conclusion

First, I would like to have a time travel machine to go back and to give myself the advice to save source code somewhere in a cloud. I would like to make a comparison of what I had in Delphi version and with C++ implementation. But I have what I have.

I also used an interesting approach to rendering stuff in there. When I refactor all this shit I will write something like "Writing Rubik's Cube in pure OpenGL and Java".

Under construction

Usually a blogger puts here some relative articles. I'm working on creating more interesting content. As soon as I have some related content I will implement some logic here. Below you may find some comments. If there is no any, it is your chance to leave the first comment:) PS.I'm glad you are here and reading this^^

Sergei Alekseev

Game Developer

Discussion