Sonic and Sega Retro Message Board: Blue Sphere Equations... - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
  • 2 Pages +
  • 1
  • 2
    Locked
    Locked Forum

Blue Sphere Equations... I didn't want to bump topics anymore...

#1 User is offline Angnix 

Posted 13 July 2005 - 05:16 PM

  • Posts: 12
  • Joined: 12-July 05
  • Location:Michigan, America's Hand... with no fingers!
  • Project: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:
This post has been edited by Angnix: 14 July 2005 - 10:24 AM

#2 User is offline Shakidna 

Posted 13 July 2005 - 07:16 PM

  • Rehash Rampage
  • Posts: 550
  • Joined: 02-February 05
  • Gender:Male
  • Location:Philadelphia
  • Wiki edits:1
Good ta' see you here Agnix. I have no idea what you said though. o.o;

EDIT: Damn Caps lock >:O
This post has been edited by Shakidna: 13 July 2005 - 07:18 PM

#3 User is offline voice 

Posted 13 July 2005 - 07:46 PM

  • Make any joke you want, you know I look good.
  • Posts: 3725
  • Joined: 06-June 04
  • Gender:Male
  • Location:45mins west of Chicago
  • Project:RSN2.0, PHP:IRC (A attempt at CGI:IRC in PHP)
  • Wiki edits:65
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 User is offline Angnix 

Posted 13 July 2005 - 08:22 PM

  • Posts: 12
  • Joined: 12-July 05
  • Location:Michigan, America's Hand... with no fingers!
  • Project: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 User is offline LOst 

Posted 13 July 2005 - 09:07 PM

  • Posts: 4886
  • Joined: 10-January 03
  • Gender:Male
  • Wiki edits:2
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):
11223344

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):
/*            11223344 format */
unsigned long BLOCKS = 0x00010203	// This is level 1's stage
unsigned long STAGE_NR = 0x0000000; // Not calculated yet

unsigned short CALC_WORD = 0x0000; // Just a temp word
unsigned byte BYTE_WORD = 0x00; // Just a temp byte

/* First step is to scramble block "33" and "44" */

CALC_BYTE = (BLOCKS & 0xFF) << 1;	// Multiply block "44" with 2
CALC_WORD = (BLOCKS & 0xFF00); // Combine block "33" and "44"
CALC_WORD |= CALC_BYTE; 	//
CALC_WORD <<= 1; 	// Multiply "33" and "44" with 2

/* "33" and "44" are combined and ready... */

STAGE_NR = CALC_WORD; 	//

/* Second step is to scramble block "11" and "22" */

CALC_BYTE = ((BLOCKS & 0xFF0000) >> 16) << 1;	// Multiply block "22" with 2 
CALC_WORD = (BLOCKS & 0xFF000000) >> 16;// Combine block "11" and "22"
CALC_WORD |= CALC_BYTE; 	//
CALC_WORD >>= 1; 	// Divide "11" and "22" with 2

/* "11" and "22" are combined and ready...
  Time to combine "11" and "22" with "33" and "44" */
STAGE_NR |= (CALC_WORD << 16); //

/* Third and last step is to get the stage nr
  and make it between 0 and 268435455 */
STAGE_NR /= 4;  // Final divide to get stage nr

STAGE_NR &= 0xFFFFFFF; 	// Stage nr is now between 0 and
  	// 268435455

if (STAGE_NR == 16643)
	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:
/*            11223344 format */
unsigned long BLOCKS = 0x00010203
unsigned long STAGE_NR = 0x0000000;
unsigned short CALC_WORD = 0x0000;
unsigned byte BYTE_WORD = 0x00;


CALC_BYTE = (BLOCKS & 0xFF) << 1;
CALC_WORD = (BLOCKS & 0xFF00);
CALC_WORD |= CALC_BYTE;
CALC_WORD <<= 1;

STAGE_NR = CALC_WORD;


CALC_BYTE = ((BLOCKS & 0xFF0000) >> 16) << 1;
CALC_WORD = (BLOCKS & 0xFF000000) >> 16;
CALC_WORD |= CALC_BYTE;
CALC_WORD >>= 1;

STAGE_NR |= (CALC_WORD << 16);

STAGE_NR /= 4;

STAGE_NR &= 0xFFFFFFF;

if (STAGE_NR == 16643)
 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.
This post has been edited by LOst: 13 July 2005 - 11:52 PM

#6 User is offline Sakura Courage Solo 

Posted 13 July 2005 - 09:12 PM

  • I am a Woodpecker! Except in Dirt!
  • Posts: 1037
  • Joined: 11-June 05
  • Gender:Female
  • Location:Lava Reef Zone
  • Project: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 User is offline Angnix 

Posted 13 July 2005 - 09:40 PM

  • Posts: 12
  • Joined: 12-July 05
  • Location:Michigan, America's Hand... with no fingers!
  • Project: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.
This post has been edited by Angnix: 13 July 2005 - 10:11 PM

#8 User is offline LOst 

Posted 13 July 2005 - 10:33 PM

  • Posts: 4886
  • Joined: 10-January 03
  • Gender:Male
  • Wiki edits:2

Angnix, on Jul 14 2005, 05:40 AM, said:

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...

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

Quote

And why should I be awarded

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.
This post has been edited by LOst: 13 July 2005 - 10:43 PM

#9 User is offline Heran Bago 

Posted 14 July 2005 - 12:34 AM

  • Ah! It's Puyo battle then.
  • Posts: 2949
  • Joined: 11-May 04
  • Gender:Male
  • Location:Foggy California
  • Project:勉強
  • Wiki edits:4
LOst, cat pee's not simple.
edit: not 'easy', 'simple'.
This post has been edited by Heran_Bago: 14 July 2005 - 12:35 AM

#10 User is offline Aurochs 

Posted 14 July 2005 - 12:52 AM

  • Единый, могучий Советский Союз!
  • Posts: 2343
  • Joined: 09-January 05
  • Gender:Male
  • Project:Whatever catches my fancy
  • Wiki edits:325

LOst, on Jul 13 2005, 10:33 PM, said:

If you want to make a math book for students to read and get bored in, you use algebra.

But I like algebra... :)

#11 User is offline Angnix 

Posted 14 July 2005 - 10:15 AM

  • Posts: 12
  • Joined: 12-July 05
  • Location:Michigan, America's Hand... with no fingers!
  • Project: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...
This post has been edited by Angnix: 14 July 2005 - 10:25 AM

#12 User is offline Esrael 

Posted 14 July 2005 - 12:07 PM

  • Posts: 175
  • Joined: 24-July 03
  • Gender:Male
  • Location:Brazil, São Paulo, Guarulhos
  • Project:Esrael Neto Assembler Editor / Sonic 2 Delta
You Can use this Formula to Calculate Stage
Sonic Starts in FloorID1 (x=16 and y=3)

Level=Level - 1;
FloorID0=(((Level mod 128) * 1) + 0) mod 128;
FloorID1=(((Level mod 127) * 3) + 1) mod 127;
FloorID2=(((Level mod 126) * 5) + 2) mod 126;
FloorID3=(((Level mod 125) * 7) + 3) mod 125;

Stage=(FloorID0 * (128 ^ 3)) + 
   (FloorID1 * (128 ^ 2)) + 
   (FloorID2 * (128 ^ 1)) +
   (FloorID3 * (128 ^ 0));



EDIT:
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
 Difficulty=Offset[FloorID0+0x80]+
      Offset[FloorID1+0x80]+
      Offset[FloorID2+0x80]+
      Offset[FloorID3+0x80]+1;

 0x80=Start Offset for difficulty data.

Ring use the same formula, but Starts in Offset 0x0 of Data:
 Rings=Offset[FloorID0]+
     Offset[FloorID1]+
     Offset[FloorID2]+
     Offset[FloorID3];

This post has been edited by Esrael: 14 July 2005 - 12:45 PM

#13 User is offline Angnix 

Posted 14 July 2005 - 03:46 PM

  • Posts: 12
  • Joined: 12-July 05
  • Location:Michigan, America's Hand... with no fingers!
  • Project: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...
This post has been edited by Angnix: 14 July 2005 - 03:54 PM

#14 User is offline LOst 

Posted 14 July 2005 - 10:00 PM

  • Posts: 4886
  • Joined: 10-January 03
  • Gender:Male
  • Wiki edits:2

Angnix, on Jul 14 2005, 11:46 PM, said:

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

be, for example Level 25's Q2 is 122 so 26 should be 127... but instead it is 1...

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 User is offline LOst 

Posted 14 July 2005 - 10:10 PM

  • Posts: 4886
  • Joined: 10-January 03
  • Gender:Male
  • Wiki edits:2
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
This post has been edited by LOst: 14 July 2005 - 10:11 PM

  • 2 Pages +
  • 1
  • 2
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users