Number Encoding (Put lots of numbers into 1)
Vmlweb
Member Posts: 427
Hey,
I've just finished making a maths formula that might be useful for a lot of you.
Basically it lets you store multiple numbers in 1 integer.
This encoded number will have a specified number of positions, each of these positions would contain a number as well.
All you do with these formulas is fill in the letters with the number to fit:
============================== Formulas =========================================
Adding To The Positions=
x + z * ( y ^ n )
x = Encoded Number To Add To
z = Amount To Add To The Position
y = Max Size Of The Position Numbers (eg. for a max of 10 in a position y would be 11)
n = Position To Add To
Extracting A Position=
floor ( x / y ^ n) % y
x = Encoded Number To Extract From
y = Max Size Of The Position Numbers (eg. for a max of 10 in a position y would be 11)
n = Position To Extract
================================= FAQ ===========================================
Where would I use this?
If you have high-scores for instance instead of having a separate integers for every single high score this could hold all of them.
Is there a limit to the positions?
Yes, there is a limit to how many positions you can have which is limited by y which is the max size you can have.
If y is 3 which means each position would be 1 or 2, then you would be able to fit much more positions in than if y was equal to 20
What happens if a position value is bigger than the max size I put?
It will extract as 0
=================================================================================
Hope this helps you,
If you have any questions please ask.
Thanks,
Vmlweb
I've just finished making a maths formula that might be useful for a lot of you.
Basically it lets you store multiple numbers in 1 integer.
This encoded number will have a specified number of positions, each of these positions would contain a number as well.
All you do with these formulas is fill in the letters with the number to fit:
============================== Formulas =========================================
Adding To The Positions=
x + z * ( y ^ n )
x = Encoded Number To Add To
z = Amount To Add To The Position
y = Max Size Of The Position Numbers (eg. for a max of 10 in a position y would be 11)
n = Position To Add To
Extracting A Position=
floor ( x / y ^ n) % y
x = Encoded Number To Extract From
y = Max Size Of The Position Numbers (eg. for a max of 10 in a position y would be 11)
n = Position To Extract
================================= FAQ ===========================================
Where would I use this?
If you have high-scores for instance instead of having a separate integers for every single high score this could hold all of them.
Is there a limit to the positions?
Yes, there is a limit to how many positions you can have which is limited by y which is the max size you can have.
If y is 3 which means each position would be 1 or 2, then you would be able to fit much more positions in than if y was equal to 20
What happens if a position value is bigger than the max size I put?
It will extract as 0
=================================================================================
Hope this helps you,
If you have any questions please ask.
Thanks,
Vmlweb
Comments
I don't really see this working without further constraints for the high score values and/or I'm just misinterpreting your descriptions of your variables above.
When you say "position" above, I intepret it as a position on the high score leaderboard but further down in your FAQ, it almost reads as if position a high score value.
Confused. :-|
| Position0 | Position1 | Position2 | Position3 |
Those positions can be changed individually.
Say if I use the Add To Position formula and replace n=2 and z=4
That would change to
| Position0 | Position1 | 4 | Position3 |
I haven't wrote this down properly it's just to show you cause If you haven't added anything to a position it's value is 0.
Really the above would be
| 0 | 0 | 4 | 0
If your still struggling I'll make an example for you
However, maybe when you say "If you have high-scores for instance..." you mean a high score per level as opposed to a high score list for a single level!?
So in your second post, you give the starting "state" of your high score integer as:
`| P0 | P1 | P2 | P3 |`
which you say really looks like:
`| 0 | 0 | 0 | 0 |`
Then you add:
"Say if I use the Add To Position formula and replace n=2 and z=4"
To me, that sounds like you want to place the high score value of "4" in the third high score slot, i.e.:
`
High Score 1 - 0
High Score 2 - 0
High Score 3 - 4
High Score 4 - 0
`
which you represent as:
`| 0 | 0 | 4 | 0 |`
(and technically, doesn't make sense, since the high score should go in the first slot if the first slot is still zero but let's ignore that since you are just demonstrating)
So if your current "state" is now:
`| 0 | 0 | 4 | 0 |`
And you want to add high score "3" to the 4th high score position so it looks like:
`| 0 | 0 | 4 | 3 |`
I assume X would equal "4" in your equation as you proceed to add the "3" into it.
Maybe your equations work for these small number examples but what if you have this leaderboard you want to store (with a max high score of say "9999"):
`
High Score Position Score
1 4,321
2 3,222
3 2,999
4 1,000
5 1,000
6 570
7 0
8 0
9 0
10 0
`
I see your formulas fall apart if my math was sound.
So either there are limits to the value stored in each position or my interpretation of your system is incorrect.
Not trying to be difficult or a nay-sayer. Just want to understand its usage and limitations as it sounds like a neat system to employ in a game!
So
| P0 | P1 | P2 | P3 | P4 |
to add to the first position you need n=0
for the last position it's n=4
I'll start making an example and upload it
If you can, show it encoding:
`
High Score Position Score
1 4,321
2 3,222
3 2,999
4 1,000
5 1,000
6 570
7 0
8 0
9 0
10 0
`
I'll repost a new topic in a minute with the example.
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io