don't click here

Blue Sphere Equations...

Discussion in 'General Sonic Discussion' started by Angnix, Jul 13, 2005.

Thread Status:
Not open for further replies.
  1. Angnix


    Pending Member
    Michigan, America's Hand... with no fingers!
    Ummm... random image and FAQs stuff sometimes...
    I was bored... the javascript still confuses me a little, but just looking at the data for the first few levels I tried to figure out some myself... looking at the data from the first 4 levels, the pattern is easy to see... at least between level, stage and the floor plan of the stage. The level determines everything and it is easiest to calculate everything else about it from the level number, the level number directly determines the floor plan which is in 4 sections, and the floor plan then determines the stage number, or at least that is the easiest way to calculate them. These equations are not fun to reverse but possible... anyway my algebra skills are rusty and I am sure there are ways to simplify them...:

    EDIT: Forget the Q formulas till I completely recalculate them.

    s = Stage Number
    Q1 - Q4 = The four floor sections, Q1 is where you start, they are numbered counter-clockwise from there. This number corresponds to floor patterns numbered 0-127.

    s = 2097152(Q1) + 128(Q2) + (Q3) + 16384(Q4)

    Because of the nature of the equation, two levels could in theory have the same stage number, I think, which is why some stage numbers have undefined levels and codes. I have not figured out the codes relationship yet, looks complex in the javascript also, emerald and floor color look simple in the javascript and I just haven't figured them out yet, rings and blue sphere counts is as simple as knowing what they are for each of the 128 sections and what sections are included, difficulty not figured out yet, but as I read on this very forun each section has a difficulty assigned and it's based upon that.

    Sorry if this was pretty obvious, but I was bored, and wanted to show an example of what format I want the equations in. Also wanted to save time because you guys probably have them figured out already and the rest could just be posted.

    I would also sort of like to know how to properly type the floor function symbol :lol:
  2. Shakidna


    Rehash Rampage Member
    Good ta' see you here Agnix. I have no idea what you said though. o.o;

    EDIT: Damn Caps lock >:O
  3. voice


    Make any joke you want, you know I look good. Banned
    45mins west of Chicago
    RSN2.0, PHP:IRC (A attempt at CGI:IRC in PHP)
    Its times like this I knew math...I mean...Im a D student when it comes to math(yet I'm a website programer). But it is refreshing to see some people who can bring in new stuff instead of the same old info prepared 20 diffrent ways.
  4. Angnix


    Pending Member
    Michigan, America's Hand... with no fingers!
    Ummm... random image and FAQs stuff sometimes...
    Okay, the rest is figured out... the lists of values for blue spheres, rings and difficulty for each section is easy to pull out of that code, floor color and emerald color... slightly wierd but it looks simple in the javascript, the cycle is slightly off or something, I'll figure it out... but the codes equation still has me baffled... I'm trying to study the file but I'm confused... yeah, where are the math people here? That's the last equation I really need since I can figure out everything else from what I have. I'll look at it more myself.
  5. LOst


    Tech Member
    Angnix, I think you should be rewarded for what you are trying to do. I mean it isn't an easy task. For math and equations, I wish I undersood it better. I am just a programmer, and the math around programming is the only math I really know. I can make it a try...

    Okay first, you need to know the format of the 4 stage blocks. They are in this format (4 bytes):

    Where 11 is the first block, 22 is the second block mapped horizontally, 33 is the third block mapped vertically, and 44 is the fourth block mapped both horizontally and vertically.

    Now the real formula in C++ would be like this (taken from the S&K source):
    Code (Text):
    1. /* ? ? ? ? ? ? ? ? ? ? ? 11223344 format */
    2. unsigned long BLOCKS = 0x00010203   // This is level 1's stage
    3. unsigned long STAGE_NR = 0x0000000; ?// Not calculated yet
    5. unsigned short CALC_WORD = 0x0000; ?// Just a temp word
    6. unsigned byte BYTE_WORD = 0x00; ?// Just a temp byte
    8. /* First step is to scramble block "33" and "44" */
    10. CALC_BYTE = (BLOCKS & 0xFF) << 1;   // Multiply block "44" with 2
    11. CALC_WORD = (BLOCKS & 0xFF00); ?// Combine block "33" and "44"
    12. CALC_WORD |= CALC_BYTE; ?   //
    13. CALC_WORD <<= 1; ?  // Multiply "33" and "44" with 2
    15. /* "33" and "44" are combined and ready... */
    17. STAGE_NR = CALC_WORD; ? //
    19. /* Second step is to scramble block "11" and "22" */
    21. CALC_BYTE = ((BLOCKS & 0xFF0000) >> 16) << 1;   // Multiply block "22" with 2
    22. CALC_WORD = (BLOCKS & 0xFF000000) >> 16;// Combine block "11" and "22"
    23. CALC_WORD |= CALC_BYTE; ?   //
    24. CALC_WORD >>= 1; ?  // Divide "11" and "22" with 2
    26. /* "11" and "22" are combined and ready...
    27.  ? Time to combine "11" and "22" with "33" and "44" */
    28. STAGE_NR |= (CALC_WORD << 16); ?//
    30. /* Third and last step is to get the stage nr
    31.  ? and make it between 0 and 268435455 */
    32. STAGE_NR /= 4; ? ?// Final divide to get stage nr
    34. STAGE_NR &= 0xFFFFFFF; ?    // Stage nr is now between 0 and
    35.  ? ?    // 268435455
    37. if (STAGE_NR == 16643)
    38.     printf ("Formula worked. Level 1 is STAGE 16643");
    Well, that's the formula for finding the stage number out from the blocks.

    EDIT: Clean version of the code above without comments:
    Code (Text):
    1. /* ? ? ? ? ? ? ? ? ? ? ? 11223344 format */
    2. unsigned long BLOCKS = 0x00010203
    3. unsigned long STAGE_NR = 0x0000000;
    4. unsigned short CALC_WORD = 0x0000;
    5. unsigned byte BYTE_WORD = 0x00;
    8. CALC_BYTE = (BLOCKS & 0xFF) << 1;
    9. CALC_WORD = (BLOCKS & 0xFF00);
    11. CALC_WORD <<= 1;
    16. CALC_BYTE = ((BLOCKS & 0xFF0000) >> 16) << 1;
    17. CALC_WORD = (BLOCKS & 0xFF000000) >> 16;
    19. CALC_WORD >>= 1;
    21. STAGE_NR |= (CALC_WORD << 16);
    23. STAGE_NR /= 4;
    25. STAGE_NR &= 0xFFFFFFF;
    27. if (STAGE_NR == 16643)
    28.  printf ("Formula worked. Level 1 is STAGE 16643");
    So this is the exact thing as your equation in the first post, but all of a sudden it looks more organized. But still confusing because you don't know C++ and binary operations.

    The 0x00 prefix means hexadecimal integer.
    The & sign means logical bitwise AND. Used to mask bits to get the stage number not exceed a special amount.
    The | sign means logical bitwise OR. Used to combine bits.
    The << sign means logical shift left. This is used to shift bits to the left, which is the same as multiplying the shifted number with (pow) 2.
    The >> sign means logical shift right. This is used to shift bits to the right, which is the same as dividing the shifted number with (pow) 2... And the result will be in floor of course because there are no decimal point in integers.
  6. Sakura Courage Solo

    Sakura Courage Solo

    I am a Woodpecker! Except in Dirt! Member
    Lava Reef Zone
    A Sprite-Based Dollmaker and a Card Game
    Oh, Kami-Sama, it looks like Algebra! *Has evil incarnate flashbacks of Algebra in school, and nearly failing said subject* Well... at least someone here can do it... ^^;
  7. Angnix


    Pending Member
    Michigan, America's Hand... with no fingers!
    Ummm... random image and FAQs stuff sometimes...
    It is Algebra... Algebra is easy for me... but Calculus really got me in College, actually I didn't study much... anyway I got the emeralds/floor completely figured out... it's those darn codes, they follow some really awful equation or something... someone knows it, looking at the lists trying to see a pattern is making me go crazy... the javascript I am looking at pretty much just tells me it uses the level number to generate the codes, and the rest is a bunch of stuff I can't make head or tails off...

    And why should I be awarded... someone else obviously figured out these equations... but I just can't figure them out, the javascript code I am looking at uses more complex versions of the formulas I am coming up with for some reason... these formulas work, I've tested them... but arrrgghhh, the codes are generated really weird...

    One thing I didn't understand is why the code generated the emerald color seperate from floor color, there are 15 floor colors and 7 emerald, each of the floor colors is assigned only one emerald color, so you just need to find the floor color and you have to find out one thing... geez...

    Edit: I had the idea to generate a huge list of codes with corresponding level/stage numbers using Dr. Spud's program, put them in Excel and then started sorting and stuff... I see patterns immerging already in the numbers, but I'm tired and well too tired to continue, but I will probably have it worked out tomorrow.
  8. LOst


    Tech Member
    Just a binary mask and/or a table. Remember these things are calculated with binary operators. See my code above!

    People get awarded for taking these stuff up and solving them. Just because two other guys in universe have discovered a way doesn't mean it is public knowledge. What you are trying to do is giving the real format out in Algebra format which can help a few of us. But remember, converting it to Algebra will make it end up in awful equations as you said.
    Don't make Algebra fool you. The code generations were designed in binary, and it is simple as cat pee to understand if you use Windows calculator in hex mode, and use the logical bitwise operations AND, OR, and XOR.

    It's your choice. If you want to make a computer program to generate stage numbers, you use computer language and not algebra. If you want to make a math book for students to read and get bored in, you use algebra. That's how I see it.
  9. Heran Bago

    Heran Bago

    Ah! It's Puyo battle then. Tech Member
    LOst, cat pee's not simple.
    edit: not 'easy', 'simple'.
  10. Aurochs


    Единый, могучий Советский Союз! Tech Member
    Whatever catches my fancy
    But I like algebra... :)
  11. Angnix


    Pending Member
    Michigan, America's Hand... with no fingers!
    Ummm... random image and FAQs stuff sometimes...
    OH CRAP...

    ARRRGHHH... the Q formulas will totally have to be recalculated, it follows a completely different and more complex pattern than previously thought and the earlier formulas break down when you get into higher levels... I should have put the data into Excel in the first place, the formula for stage is correct.
    Excel completely told me something was wrong... so very, very wrong...
  12. Esrael


    Neto Tech Member
    Brazil, São Paulo, Guarulhos
    Neto Assembler Editor / Sonic 2 Delta / Neto MD-DOS
    You Can use this Formula to Calculate Stage
    Sonic Starts in FloorID1 (x=16 and y=3)

    Code (Text):
    1. Level=Level - 1;
    2. FloorID0=(((Level mod 128) * 1) + 0) mod 128;
    3. FloorID1=(((Level mod 127) * 3) + 1) mod 127;
    4. FloorID2=(((Level mod 126) * 5) + 2) mod 126;
    5. FloorID3=(((Level mod 125) * 7) + 3) mod 125;
    7. Stage=(FloorID0 * (128 ^ 3)) +
    8.  ? ? ??(FloorID1 * (128 ^ 2)) +
    9.  ? ? ??(FloorID2 * (128 ^ 1)) +
    10.  ? ? ??(FloorID3 * (128 ^ 0));

    Decompressing Data at Offset 0x1FD5CA In SK Rom you will get the following Data:
    0x0000 to 0x007F => Ring Data
    0x0080 to 0x00FF => Difficulty Data
    0x0100 to 0x80FF => Map Data

    Difficulty is Easy to calculate after you get the block ID.
    Follow the steps below:
    1st - Decompress Data At 0x1FD5CA from SK Rom
    2nd - Get Floor ID using The Formula.
    3rd - Read bytes into Offset 0x80 to 0xFF where 0x80=BlockID 00 and 0xFF=BlockID 7F
    Code (Text):
    1.  ?Difficulty=Offset[FloorID0+0x80]+
    2.  ? ? ? ? ?? ?Offset[FloorID1+0x80]+
    3.  ? ? ? ? ?? ?Offset[FloorID2+0x80]+
    4.  ? ? ? ? ?? ?Offset[FloorID3+0x80]+1;
    6.  ?0x80=Start Offset for difficulty data.
    Ring use the same formula, but Starts in Offset 0x0 of Data:
    Code (Text):
    1.  ?Rings=Offset[FloorID0]+
    2.  ? ? &nbsp;? Offset[FloorID1]+
    3.  ? ? &nbsp;? Offset[FloorID2]+
    4.  ? ? &nbsp;? Offset[FloorID3];
  13. Angnix


    Pending Member
    Michigan, America's Hand... with no fingers!
    Ummm... random image and FAQs stuff sometimes...
    Ehhh... I've given up on the Q algebra problems anyway, it's wierd...

    Q1=(level-1)-(128 l_(level-1)/128_l)

    That is for sure... you would think it would be easy to figure out the rest because the patterns Q2-Q4 follow at least in the beginning are easy, but evey single formula I get for Q2 to start off with will be accurate for many stages but then fall off quickly... I just don't understand it, mostly cause for above Q2 the breakoff points for the cycle are before they should be, for example Level 25's Q2 is 122 so 26 should be 127... but instead it is 1... there is of course a section 127 and it would have been valid, but no, for some reason the cut off is in the wrong place for it to be simple, actually because then the level wouldn't cycle through all the sections... putting in the fudge factor is not working cause I have to know the exact values for a couple of numbers in the equations I can't quite figure out what they are...
  14. LOst


    Tech Member
    Have you ever heard of modulo? It's the rest of the divide, also called "reminder" of the divide. Look at Esrael's code for Q2 (or is it Q1... anyway):

    FloorID1=(((Level mod 127) * 3) + 1) mod 127;

    It uses MOD 127. Here is an example of using MOD:

    128 / 100 = 1.28 (Just a divide)
    128 MOD 100 = 28 (The reminder of the divide above is 28. 100 + 28 = 128)

    Another example:

    128 / 127 = 1,0079 (Just a divide)
    128 MOD 127 = 1 (The reminder of the divide above is 1. 127 + 1 = 128)

    The last examples:

    128 / 129 = 0,9922 (Just a divide)
    128 MOD 129 = 128 ( The reminder of the divide above is 128.)

    128 MOD 130 = 128

    128 MOD 131 = 128

    128 MOD 255 = 128

    128 MOD 2000 = 128

    But now, Esrael's formula uses x MOD 128 and not 128 MOD x, so it will wrap around 128 (127 in this case) which will give that odd effect you are talking about when all of a sudden the the result is 1 when it should have been 127.
  15. LOst


    Tech Member
    Angnix, don't forget you have to use modulo to make the level number and stage number to wrap around their max values:

    level_no MOD 134217728
    stage_no MOD 268435456

    A good example of modulo is to wrap around the level number. You know that after level 134217728 comes level 1 again, fire up the Windows calculator and test yourself:

    134217729 MOD 134217728 = 1

    Pretty much everything you need to know about modulo. Don't tell me you already knew this? x.x
  16. Angnix


    Pending Member
    Michigan, America's Hand... with no fingers!
    Ummm... random image and FAQs stuff sometimes...
    yes, I know of that... I figured that out but... what the heck Arrrgghhh! I've been trying to correct the formula by messing with pretty much everything else but the value 128... ghaw my poor brain for some reason couldn't fathem that...

    This is why I wasn't a math major...
  17. LOst


    Tech Member
    Give us the formula, and tell us exactly where it stops working (using what values will give the error result etc...).
  18. Angnix


    Pending Member
    Michigan, America's Hand... with no fingers!
    Ummm... random image and FAQs stuff sometimes...
    Update (again):

    A power outage has slowed me down, the power is back on... but for how long, lightning still looms in the distance... anyway used the time to find more matematical relationships, but so far have helped me little. The javascript form of these equations instead of making one whole equation has different equations based upon the number range, which ironically make them simpler... anyway first the Q formulas, the question mark shows where a missing part of the equation is, something needs to be added to the general Q equation to be true for all levels. I also made clearer a math relationship in the S equation that is related to level and everything, at least I am pretty sure... anyway:

    L = Level number
    S = Stage
    Q1-Q4 = Floor sections for each level/stage
    X,Y are different for Q1-Q4 as follows:
    Q1: X=1, Y=0 (these values cancel out in the below equation giving the much simpler Q1 equation)
    Q2: X=5, Y=7
    Q3: X=7, Y=3
    Q4: X=3, Y=1
    Q1'-Q4' = used in calculating the Q's if you know the stage number...
    C = FLOOR (128/X) (also varies for each Q of course)

    Q1 = MOD(L-1/128)

    Q2 - Q4 = MOD (X*Q1+Y (?) /128-(Q1/C))

    S = 128^3(Q1)+128^1(Q2)+128^0(Q3)+128^2(Q4)

    (following have to be done in order, of course.)
    Q1' = S/128^3
    Q4' = MOD(Q1')/128^2
    Q2' = MOD(Q4')/128^1

    Q1 = FLOOR(Q1')
    Q2 = FLOOR(Q2')
    Q3 = MOD(Q2')
    Q4 = FLOOR(Q4')

    (If any of the Q values above is greater than 128, stage has an undefined level and code, I think... I at least know alot of stage values show a level map on the viewer but have undefined levels and codes... okay, not really sure why...)

    Since we almost know how to get Q values from levels and for sure can get them from stage numbers, it should be possible to calculate the formulas that relate Stage number to Level number by solving equations... but it's wierd, it relates to the 128 to certain value numbers I think and I tried solving equations if one number = 0 (the equations are L-1 so that is like using a value of 0) but no use, anyway for your info, When S=0, L=101117697 and all of the Q's=0
    When L=1, S=16643 and the Q's are the same as the Y vaules for each Q, Q1=0, Q2=2, Q3=3, Q4=1

    The relationship between L and S is simple probably and should be solvable now, I just haven't done it yet... the Q's bridge the gap between the numbers.

    It took WAY too long to find these equations out... I really shouldn't be the one doing this, THIS IS CONSUMING MY LIFE!!!!!
  19. XFox Prower

    XFox Prower

    x86 Assembly, Tails Search Assistant
    I'm lost here. Is this about pulling Special Stage maps, colors, & difficulty from Sonic 1 & Knuckles Stage numbers? And where is this javascript that is being referenced? Can't be in the rom. Maybe it's some unlinked work in progress javascript page for doing the decodings? I was thinking of making a password generator anyway. Some visual representation would also work wonders for understanding.
Thread Status:
Not open for further replies.