Rubiks 2x2

edited February 2018 in Share Your Work

I am relatively new to coding, self taught and only know very basic stuff. I decided to try and make a 2x2 rubiks cube, knowing it wouldn't be the most efficient or simple way, but I would understand it. The code is extremely messy. I enjoyed making this my way without looking at how other rubiks cube simulators are done so if this can be recreated with 2 lines of code I won't be upset. Anyways, any feedback at all would be appreciated.

https://pastebin.com/trgrqijS

PS: The layout of the cube is like this:

     |08 09|16 17
     |10 11|18 19
20 21|00 01|04 05
22 23|02 03|06 07
     |12 13|
     |14 15|

   |Bl|Ye
Or|Wh|Re
   |Gr|
Tagged:

Comments

  • nicely done, Sir!

  • Very nice.

    To improve, I would recommend starting out by eliminating repetition -- Don't Repeat Yourself.

    So for example you have 200+ lines of repeating code that sets the fill for each tile. You could eliminate that repetition by taking the fill control code sequence that starts if (c<=3){, putting all of that in a function, and then calling the function and passing it arguments (i) each time you need it.

  • Nice, thxs for sharing. Thinking in doing the 3x3 version?

    Kf

  • edited February 2018

    Thanks for the feedback Jeremy, that'll be my next step in improving my code :).

  • Thank you Chrisir and kfrajer, yes, but after I refine my method, as 3x3 would have exponentially more code (54 squares, plus 2 more cycles per move due to the edges). Also I am planning to make cubes that would be impossible in real life.

  • If you go 3D, you can use PeasyCam to look at the cube from all sites

Sign In or Register to comment.