• Welcome to the Speedsolving.com, home of the web's largest puzzle community!
    You are currently viewing our forum as a guest which gives you limited access to join discussions and access our other features.

    Registration is fast, simple and absolutely free so please, join our community of 40,000+ people from around the world today!

    If you are already a member, simply login to hide this message and begin participating in the community!

Cube Computer Programming Help

dbax0999

Member
Joined
Jul 4, 2009
Messages
380
WCA
2009ADAM01
YouTube
Visit Channel
So two of my hobbies are programming and cubing so I wanted to combine them.

The obvious thing to do of course is to make a cube program. I'm just looking for some advice on where to start. (What language to use, any tips on what kind of format to have it in, etc.)

I was thinking of having 4 arrays (Edge Permutation, Edge Orientation, Corner Permutation, Corner Orientation) and using those to store a series of numbers. Then reading those arrays to generate a cube. This method might be able to work but I'm sure there are much better ways out there so if your an experienced programmer or have made a program like this before I would greatly appreciate your shared wisdom.

The language I know best is ActionScript which is probably not the best choice for a program like this. I also know some C++ and Perl, so any help geared towards any of these 3 languages would be the best.

Thanks,
David

P.S. I'm making this program as an exercise for myself. Please don't just give me source code. I'm just looking for some starting tips.
 

qqwref

Member
Joined
Dec 18, 2007
Messages
7,834
Location
a <script> tag near you
WCA
2006GOTT01
YouTube
Visit Channel
I was thinking of having 4 arrays (Edge Permutation, Edge Orientation, Corner Permutation, Corner Orientation) and using those to store a series of numbers. Then reading those arrays to generate a cube.

While that works, I personally prefer just storing the stickers, although whether that's a good idea or not depends on the type of program you're making. For instance, if you're working on some kind of solver program, you'd save time by dealing with the puzzle as a group of pieces which can be moved around into 24 different states, but if you're making some kind of simulator it would be much easier to work with a 6x3x3 (or 6xnxn for an nxn cube) array of stickers.
 

Johannes91

Member
Joined
Mar 28, 2006
Messages
1,341
I was thinking of having 4 arrays (Edge Permutation, Edge Orientation, Corner Permutation, Corner Orientation) and using those to store a series of numbers. This method might be able to work but I'm sure there are much better ways out there so if your an experienced programmer or have made a program like this before I would greatly appreciate your shared wisdom.
That's simple and very good for some things. Verifying the validity (exactly 1 copy of every piece, parity etc.) is easy, for example. Defining moves isn't as nice as for sticker representation, but it's not too bad.

What's the best choice depends on what's "a program like this". For an efficient solver, you can create transition tables and then the state is just a few integers and making moves is O(1). See "The Mathematics behind Cube Explorer" here and Jaap's page here for lots of really useful tips.

The language I know best is ActionScript which is probably not the best choice for a program like this. I also know some C++ and Perl, so any help geared towards any of these 3 languages would be the best.
I don't know much about ActionScript but it certainly doesn't seem like the best language for something like this.

Perl isn't fast or memory-efficient but how much that matters depends again on what exactly you want to do. For a simulator and simple solvers it's fine. For a good solver C++ is clearly the best of those 3.
 
Last edited:

dbax0999

Member
Joined
Jul 4, 2009
Messages
380
WCA
2009ADAM01
YouTube
Visit Channel
I was thinking of having 4 arrays (Edge Permutation, Edge Orientation, Corner Permutation, Corner Orientation) and using those to store a series of numbers. Then reading those arrays to generate a cube.

While that works, I personally prefer just storing the stickers, although whether that's a good idea or not depends on the type of program you're making. For instance, if you're working on some kind of solver program, you'd save time by dealing with the puzzle as a group of pieces which can be moved around into 24 different states, but if you're making some kind of simulator it would be much easier to work with a 6x3x3 (or 6xnxn for an nxn cube) array of stickers.

Alright. Do you have any advice for a faster way to handle the turns. I've decided to do a simulator and currently my method for turning the cube is to manually move the stickers in the arrays in small 4-cycles. This is getting very tedious. Here's an excerpt from the code:

Code:
hold = colors[9];
	colors[10] = colors[19];
	colors[19] = colors[28];
	colors[28] = colors[39];
	colors[39] = hold;
	hold = colors[12];
	colors[12] = colors[21];
	colors[21] = colors[30];
	colors[30] = colors[37];
	colors[37] = hold;
	hold = colors[11];
	colors[11] = colors[20];
	colors[20] = colors[29];
	colors[29] = colors[38];
	colors[38] = hold;
	hold = colors[8];

As you can see its very long and leaves lots of room for error.

After programming U and F moves only I've realized that it doesn't work either. After doing some random U and Fs the cube ends up having multiple yellow stickers on one piece. :(

Any advice would be nice (hey that rhymed)
 

Johannes91

Member
Joined
Mar 28, 2006
Messages
1,341
Should the "colors[10]" on the second line be "colors[9]"? Anyway, yes, coding like that isn't good. Never repeate yourself, use loops and functions.
 

qqwref

Member
Joined
Dec 18, 2007
Messages
7,834
Location
a <script> tag near you
WCA
2006GOTT01
YouTube
Visit Channel
Alright. Do you have any advice for a faster way to handle the turns. I've decided to do a simulator and currently my method for turning the cube is to manually move the stickers in the arrays in small 4-cycles. This is getting very tedious. Here's an excerpt from the code:

As you can see its very long and leaves lots of room for error.
1) Don't use a one-dimensional array... as I said, it's far easier for you if you define six 3x3 arrays for the stickers, rather than one array of size 54. That way - and this works for any size cube - you can do the 4-cycles in two for loops: use one to rotate the stickers on a face (if necessary) and another to rotate the stickers on a slice. So on a U turn the first loop would handle two 4-cycles and the second loop would handle three. (For an M slice or any inner-layer turn on a larger cube, you only need to use the slice one, so it's good to separate the two functions.)
2) Make a function to do a 4-cycle - that is, you should have a function that you can pass four array locations to, and it will cycle them. It saves a lot of time over coding each 4-cycle by hand.
 

jms_gears1

Premium Member
Joined
Jun 10, 2009
Messages
1,303
WCA
2009MAUP01
YouTube
Visit Channel
i found it easy to draw a 3D cube on a paper then supply them with x and y coords (i did a 2D drawing instead of the 3D cube) in a 2D array.

so i drew a 2D cube then assigned coords to them then drew a 3D cube and coppied them down then wrote out what piece moved to where then used that in programming.

i hope that wasnt to vague... but thats what i did and it worked
i also used c# its an easy language with lots of support and if you get xna game studio for it you can create really good 3D Games and appps etc.
 

StachuK1992

statue
Joined
Jul 24, 2008
Messages
3,812
Location
West Chester, PA
WCA
2008KORI02
YouTube
Visit Channel
If I were you, I'd have it so you have an 'edge' class, and a 'corner' class, and create a fictional "core" that these classes revolve around, but then again, I'm not sure how this would work out. :/
 
Last edited:
Top