Page 1 of 1

How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.05 (00:38)
by TheRealOne
So, about a week ago I asked kryx if it was possible to build a demo from scratch with just the numbers. I wanted to do this because I suck at FBFing and I wanted to create a demo of my map Stupidly Hard: Redux because I thought it would be great for Ska's next Best of N video. KryX told me that it would ridiculously hard because not all of the numbers in each set in the demo data correspond to an action. So I set out to figure out the data to see if it was possible to build/edit a demo from scratch.

So, here is how the demo data work:

We have all seen a string of data that look like this: 21:365733|52346544|3454364|0

The data is read like so:

Code: Select all

The number at the beginning, in this case 21, is the number of total frames in the demo.

Each set of numbers between the lines, such as |34534532|, are the actions taken in a 7 frame section.

The way this number is created by the sum of values given to each action that takes place in these 7 frames.

The values given to each action (jump, left, right and holding a jump for the next frame) were determined by Metanet. They used simple exponential formulas to make them.
Alright now that you have read that I will do an example because it is kind of confusing and I can't say that even I understand it completely.

Let’s say we want n to go 2 frames to the right then jump and keep holding jump and traveling right for 3 more frames then for the last 2 frames we want to let go of jump and pull back left. Here is how that would be done in the demo data.

First you should figure out what buttons are being held in each frame:
(Note: for a hold of a jump, I am going to denote that as "Hold")

Frame 1: Right
Frame 2: Right
Frame 3: Jump, Right
Frame 4: Hold, Right
Frame 5: Hold, Right
Frame 6: Left
Frame 7: Left

Ok, now that we know what is going on in each frame we would look at my handy dandy excel file that is attached with all of the values in it, and find the values for each of these actions.

Frame 1: A right in the first frame has a value of 2
Frame 2: A right in the second frame has a value of 32
Frame 3: Now jumps with holds are a little different, you must figure out what frame you jumped in and how many frames you held for and that is one specific value. A jump in the 3rd frame and 2 more frames of hold has a value of 281600. A right in the 3rd frame has a value of 512.
Frame 4: since we have already accounted for the jump and holds we need only worry about the right, and a right in the 4th frame has a value of 8192.
Frame 5: same as frame 4 but, a right in the 5th frame has a value of 131072.
Frame 6: A left in the 6th frame has a value of 1048576.
Frame 7: A left in the 7th frame has a value of 16777216.

Now that we have the value of each action in each frame we need to sum the values in each frame.

Frame 1 Total: 2
Frame 2 Total: 32
Frame 3 Total: 282112
Frame 4 Total: 8192
Frame 5: Total: 131072
Frame 6: 1048576
Frame 7: 16777216

Now that we have the total of each frame add it all together for the code for these 7 frames.

Total: 18247202

That is now the code for those 7 frames that will have the ninja run 2 frames right then jump to the right for 3 frames and then pull back left for 2 frames. To actually use this you will put it in to this format.

7: 18247202

The only problem with that is usually the ninja is placed a ½ snap from the bottom so it takes a few frames for him to fall to the ground where he can do stuff. So to make this demo work we would need to do nothing for, let’s say 7 frames to make things easy. Now our demo data would look like this.

14:0|18247202

Now that you know how to make a demo here is some information on how all of this data came to be and works.

Once you look at my tables in the excel doc you will see a bunch of jump tables and a theoretical hold value table and this is just to save you time adding up all of those numbers, but technically even though you can just start holding a jump without jumping the hold value for each frame was implemented in the game.

Metanet gave a base value to each of the 4 actions you can do (Jump, right, left, and hold) in the first frame. Jump = 12, right = 2, left = 1, and hold = 4. Then to calculate the value for each action in the next 6 frames the base number was multiplied by 16 for each frame after the first. So a jump in the 3rd frame is 12*16*16 = 3072

*Key for Excel Chat*
0 - no action/buttons pressed
Jump - Jump key pressed in that frame
Hold - Jump key held from a previous jump
Right - Right movement key pressed
Left - Left movement key pressed
Code - The value for a specific action and frame.

*Disclaimer*
1) I know absolutely nothing about programing, I figured out all of this through trial and error, so if something is wrong please don't freak out. Instead feel free to correct me and I will make the necessary changes.

2) I use Excel 2007 version on Windows XP, and when I save it tell me that some of the formatting may not be compatible with old versions, so if it looks all screwed up to you please tell me and I will try to fix it. Although I don't really know how I would.

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.05 (00:59)
by blackbelmoral
pretty good.
4 ninjas
marked

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.05 (01:10)
by LittleViking
The real epiphany hits when you convert those numbers to hexadecimal. I'll leave that to you to experiment with.

Python:

Code: Select all

def demo_to_hex(demo):
    return "".join([("%07X" % (int(fragment)))[::-1] for fragment in demo.split(":")[1].split("|")])[:int(demo.split(":")[0])]

print demo_to_hex("60:35791394|1646|17895697|17895697|17895697|35651585|35791394|139810|0")
>>> 2222222E6600001111111111111111111111000022222222222222000000

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.07 (17:58)
by 999_Springs
Ah, I think I get it!

What you do to create a demo is this:
1) Decide what you want the ninja to do in each frame.
2) Convert that into hexadecimal using this code:
nothing=0
left=1
right=2
left and right=3
hold=4
hold and left=5
hold and right=6
hold and left and right=7
jump=C
jump and left=D
jump and right=E
jump and left and right=F
3) String together all your characters to make one long hexadecimal number.
4) Split this number into groups of 7.
5) Reverse each group.
6) Put the groups back together again, separated by | symbols.
7) Convert the numbers back into base 10.

And there you have it!

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.10 (01:14)
by Superpok
nice, that's pretty cool, i'd try it but i don't have a hex converter

is there a central thread for the no death challenge?

cuz i'm shooting for above 32

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.10 (02:12)
by LittleViking
...How can you possibly be on the internet and claim to not have a hex converter?

http://www.easycalculation.com/decimal-converter.php

Windows calculator also has this functionality. Make sure it's in scientific calculator mode, enter a decimla number, and then hit the Hex radio button near the top left.

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.10 (12:24)
by LittleViking
I think a tool similar to this already exists in another fan program somewhere, but here's a webpage to break down the demo data and visualize it a bit.

http://therealn.com/demo.php
Example

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.10 (18:56)
by TheRealOne
LittleViking wrote:I think a tool similar to this already exists in another fan program somewhere, but here's a webpage to break down the demo data and visualize it a bit.

http://therealn.com/demo.php
Example

Well that is good. But I figured I wasn't the first person to figure this out. It wasn't very hard. But I couldn't find anything like this on these forums so i decided to post it.

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.10 (19:34)
by 999_Springs
Superpok wrote:nice, that's pretty cool, i'd try it but i don't have a hex converter

is there a central thread for the no death challenge?

cuz i'm shooting for above 32
That was part of my ever-changing sig, not my post. The one life challenge thread is here. It is very old. (Yeah, 32-0 is kind of rubbish.)

Google has a base converter. Just type "107374182 in hexadecimal", or "0x22E6445 in decimal" into Google, for example.

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.10 (23:23)
by Superpok
yeah i know it was though, i just thought i'd post there too

thanks for all the hex converters by the way...i feel so ignorant...

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.12 (20:04)
by TheRealOne
If anyone is curious as to what I was able to do with demo data. I was able to create the demo for my map

http://nmaps.net/157307


Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.02.13 (19:40)
by Tunco
Very helpful to me to learn the number at the beginning is the number of the frames.... :]

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.11.15 (18:24)
by Raif
I made an excel worksheet which generates demo data instead of just being a reference sheet.
(It only works in Excel 2007 because Excel 2003 does not support formula nesting. I suppose it could be made to work in Excel 2003 by using the LOOKUP function. But I used the IF function here because it is easier for this purpose; multiplication signs work with in an IF function but not a LOOKUP function)

And if anyone was wondering to what I could do with demo data all of these runs are 100% manually built.

Re: How n's Demo Data Works (let's Build A Demo)

Posted: 2009.11.17 (03:10)
by TheRealOne
mohamedraif wrote:I made an excel worksheet which generates demo data instead of just being a reference sheet.
(It only works in Excel 2007 because Excel 2003 does not support formula nesting. I suppose it could be made to work in Excel 2003 by using the LOOKUP function. But I used the IF function here because it is easier for this purpose; multiplication signs work with in an IF function but not a LOOKUP function)

And if anyone was wondering to what I could do with demo data all of these runs are 100% manually built.
Awesome! I actually tried to make something like this in the excel sheet I made, but I couldn't get the IF statements right. I was using a reference table of all of the values that this if statement referenced. This is great because it is one step closer to actual TASing. Now we just need rerecording and we could find the true max of lvls.