Thread: Typedef Structs inside Typdef structs

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2011
    Location
    Barcelos, Braga, Portugal, Portugal
    Posts
    7
    Quote Originally Posted by iMalc View Post
    Straight after answering this I went to another forum and look what I found: Rubik Cube C - GameDev.net
    Well yes, I did post it in two forums, this and that one. I don't think it's a bad idea. But definitely, I've been getting a better study of my problem here, and I am thankful for that.

    If it is a problem, just let me know...

  2. #2
    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. #3
    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. #4
    - - - - - - - - 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. #5
    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. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    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. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    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.

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-16-2007, 11:54 PM
  3. typedef and structs
    By ^xor in forum C Programming
    Replies: 8
    Last Post: 06-11-2005, 11:46 AM
  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, 12:43 AM