Like Tree1Likes

Typedef Structs inside Typdef structs

This is a discussion on Typedef Structs inside Typdef structs within the C Programming forums, part of the General Programming Boards category; Originally Posted by CommonTater Seems to me the representation is much simpler than that... You have 6 faces, each a ...

  1. #16
    Registered User
    Join Date
    Dec 2011
    Location
    Barcelos, Braga, Portugal, Portugal
    Posts
    7
    Quote Originally Posted by CommonTater View Post
    Seems to me the representation is much simpler than that...

    You have 6 faces, each a 3x3 matrix...
    Code:
    int rubic[6][3][3];
    The problem is not in how you depict it in data... the real task is how do you rotate the faces when rotating one of the 6 faces also rotates one row of the 4 adjoining faces... Seems to me the real magic is in the code not the picture.
    I understand your point of view, and you are completely right when you say that the problem is rotating it. That is why, the closer I can find how it works in reality, the closer I am so solving the problem "getting a working algorithm".

    That is a much simpler representation, but then again, the problem of rotating it comes in the way. But if i have the [3][3][3] matrix, i can use simple matrix rotations. I've been googling around and found these solutions for the rotation:

    c# - How to Rotate a 2D Array of Integers - Stack Overflow

    java - Rotate array clockwise - Stack Overflow

    I think they would work with the cube.

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    This might help you with the visualization of the issue...

    Rubiks Cube Screen Saver - The Toids World

    The problem with each face being a 3 x 3 x 3 is you don't actually have 27 elements... you have 9.
    Where the logic of this would drive me batty is working out the agacency issues... As you say, rotating one face is actually pretty easy, but rotating one row of each adjacent face ... onto another face ... now that's some true digital legerdemain.

    Although... I shold warn you, I'm probably not the right person to talk to about Rubik's Cube...
    Back when they first came out a friend gave me one, nicely pre-scrambled, for my birthday. Well, I'm a sucker for a good puzzle and ended up spending most of my holiday from work on it, took it to work after, kept twisting away on it, almost all of my spare them, for upwards of 3 months before I solved it... And even then I figure I did it by accident, not skill. So I went down to a local hobby shop and got a trophy base for it, finished it all up real nice in black walnut. Drilled a hole and tapped a spike through the base, glued the cube so it would never move again, heated up the spike and melted one corner of the the cube onto the spike, so it looked like a proper trophy. Then I got out the engraving tools and wrote a suggestion that my friend should perform a sexual impossibility on the little brass plaque... and gave it back to him for Christmas. To this day, he still won't give me birthday gifts...

  3. #18
    Registered User
    Join Date
    Dec 2011
    Location
    Barcelos, Braga, Portugal, Portugal
    Posts
    7
    Quote Originally Posted by CommonTater View Post
    This might help you with the visualization of the issue...

    Rubiks Cube Screen Saver - The Toids World

    The problem with each face being a 3 x 3 x 3 is you don't actually have 27 elements... you have 9.
    Where the logic of this would drive me batty is working out the agacency issues... As you say, rotating one face is actually pretty easy, but rotating one row of each adjacent face ... onto another face ... now that's some true digital legerdemain.

    Although... I shold warn you, I'm probably not the right person to talk to about Rubik's Cube...
    Back when they first came out a friend gave me one, nicely pre-scrambled, for my birthday. Well, I'm a sucker for a good puzzle and ended up spending most of my holiday from work on it, took it to work after, kept twisting away on it, almost all of my spare them, for upwards of 3 months before I solved it... And even then I figure I did it by accident, not skill. So I went down to a local hobby shop and got a trophy base for it, finished it all up real nice in black walnut. Drilled a hole and tapped a spike through the base, glued the cube so it would never move again, heated up the spike and melted one corner of the the cube onto the spike, so it looked like a proper trophy. Then I got out the engraving tools and wrote a suggestion that my friend should perform a sexual impossibility on the little brass plaque... and gave it back to him for Christmas. To this day, he still won't give me birthday gifts...
    Ahahah, funny story

    About the 9 elements, which ones would you suggest? the [6][3][3] array you talked about earlier?

    The problem here would probably be the rotation. Whilst with the [3][3][3] array, I think it's easier to rotate (not sure).

    I really appreciate all this discussion. It's getting very interesting, and I noticed that some people might think the same. I'll be glad to post my full solution once I made it. Thank you.

  4. #19
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    It's not necessarily easier to rotate the 3x3x3 "piece-based" representation since you also have to calculate new orientations for the pieces, whereas with the 6x3x3 "square-based" representation, although the basic rotation is more complicated, the orientation problem goes away. Also, the square-based rep. works well with bare ints, but the other requires a struct with type, orientation, colors....

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by oogabooga View Post
    It's not necessarily easier to rotate the 3x3x3 "piece-based" representation since you also have to calculate new orientations for the pieces, whereas with the 6x3x3 "square-based" representation, although the basic rotation is more complicated, the orientation problem goes away. Also, the square-based rep. works well with bare ints, but the other requires a struct with type, orientation, colors....
    Yep... treat it as a hollow cube. In the multiple piece method you have an additional complexity in that some of your small cubes have 1 side showing, some have 2 and some have 3... but none of them have all 6 so it's just a lot easier to envision as 6 flat surfaces...

    Just give each colour a number... and let the rotation wrangling begin...
    Last edited by CommonTater; 12-30-2011 at 07:25 PM.

  6. #21
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    If it were me then I'd start with the 3x3x3 voxel with a colour for each voxel's face. At least this way I know exactly how to rotate it already.

    Hey CommonTater, if only you had a lot of programming experience back then. You could have written a program to tell you exactly what moves are required to solve it. .
    I read on newscientist that every initial starting point is solvable in twenty moves. Edit: found it, here's the link: 'God couldn't do faster': Rubik's cube mystery solved - physics-math - 11 August 2010 - New Scientist
    Ya know I'm almost tempted to write a rubik solver myself now, a bit like how I wrote a sudoku solver some time ago. Hmm, we could make it into a competition.
    Last edited by iMalc; 12-30-2011 at 07:35 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #22
    Registered User
    Join Date
    May 2009
    Posts
    2,768
    I think, not sure, that you could consider the center square fixed in color and just rotate the edges around it.

    I can not see any easy way to represent the data.

    But, I think I would try 6 faces; I just not what I would use as the face structure/type.

    Edit: Decided that a simple one dim array would be my first try if I tried to solve this problem. I think 0-19 would hold all the pieces locations. 8 top, 8 bottom and 4 sides. (I consider the center positions to never change)
    The logic would not be simple to write; but, I think it would be easier that an 2 or 3 dim array solution.

    Tim S.
    Last edited by stahta01; 12-30-2011 at 08:05 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Typedef, Structs, Reusability without OO
    By tempster09 in forum C Programming
    Replies: 6
    Last Post: 12-05-2009, 03:39 PM
  2. structs inside classes
    By *DEAD* in forum C++ Programming
    Replies: 10
    Last Post: 06-17-2007, 12:54 AM
  3. typedef and structs
    By ^xor in forum C Programming
    Replies: 8
    Last Post: 06-11-2005, 12:46 PM
  4. linked list inside array of structs- Syntax question
    By rasmith1955 in forum C Programming
    Replies: 14
    Last Post: 02-28-2005, 05:16 PM
  5. Help understanding typedef structs
    By difficult.name in forum C Programming
    Replies: 3
    Last Post: 09-22-2004, 01:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21