• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

I need to store 10 different places as a # result

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2010
Messages
950
Can someone help create a way to store 10 different heros with 2 different results but in any combination and have a # represent that combination.

So for example i'll need to assign 1 group of 10 heros, and know what those 10 heros are, and if they are lvl 50 or not.
So hero 1-10 and Is it lvl 50 or not?
Lets say:
Hero1=Pally
Hero2=MK
Hero3=AM
Hero4=BMage
Hero5=Farseer
Hero6=BM
Hero7=TC
Hero8=SH
Hero9=DeathNight
Hero10=DL

example: hero1 >50, hero2 =50, hero3 =50, hero4 =50, hero5 >50, hero6 >50, hero7 =50, hero8 >50, hero9 >50, hero10 =50. So will be from left to right = 0111001001
Now this could be flipped around and turned into binary but then the max # is 1023 for 10bit, is there a way to make the # smaller but still account for all the possible combinations of heros being lvl 50 or not?

Also any help making the system to do this would be helpful. Im new back to editing and a bit rusty :p
So because of that prefer GUI on this.

thanks! :)
 
Level 13
Joined
Mar 24, 2010
Messages
950
Well i'm using it within a save/load system. And i'm trying to conserve on bits used to shorten the code. So basically when a player gets one of their heros to lvl 50 in group 1. I just store it that way rather than saving the lvl 50 per character which would be a huge code.
In other words, i can save all 10 heros or any combo once they hit lvl 50 as 1 10bit # This way that # not only represents the hero being saved but also that its lvl 50. SO it cuts down on the code length BIG TIME.
There is many heros the players can play as and they can keep their past heros once max cap is hit. Also there is a few groups of 10 heros in each group (So a lot of heros). So thats a lot of heros to save.
So this basically allows me to save 10 heros at max lvl with only using 1 bit per hero! Very compressed way of doing this. :)

Thats why i need to set up this system to do this before storing that number to the save code, and then once loaded run it through backwards to get the results of which hero in a given group is maxed lvl. It wont store items or anything just the hero once max cap is hit.

well the smaller the number the better (less bits used) but the more i thought about it there is no better way than binary to account for 10 heroes in any combination. I was thinking there wasn't 1023 possible combinations in 10 digits of yes/no, but wasn't thinking right. I was thinking it could assign smaller placement values to each spot instead of 1,2,4,8,16,32,64,128 etc but you obviously cant and still be able to account for any possible combination. lol
 
Last edited:
Level 9
Joined
Mar 26, 2017
Messages
376
You could add the numbers like;
Hero1: If state 1 then add 1 to number else add 0
Hero2: If state 1 add 2 to number else 0
...
Hero10: If state 1 add 512 else 0
The result number will be anywhere between 0 and 1023.

Then you can find back the appropriate numbers by:
If modulo 512 then Hero10 is state 1 and remove 512 from number, else state 0 and remove 0.
If mod 256 then Hero9 is state 1 and remove 256 else state 0 and remove 0.
etc.


This is max. 4 digits. If you expect some heroes to be very unlikely to reach lvl 50, you can assign those heroes as Hero10, Hero9. So the code will most likely be only 2-3 integers.

And perhaps you can expect it is not possible for a player to have a lot of heroes reach lvl 50?
You might find the shortest code is to append each HeroId above lvl 50 into one number, like:

Hero1 > 50 and Hero 5 > 50
Number is 15.

Code can potentially be 10 digits this way, but if you expect in your map there will never be more than 2 high level heroes, the code will be max 2 digits only.
 
Last edited:
Still not sure how you come to 10 bits limit. Anyways

  • Actions
    • Set VariableSet Code = 0
    • For each (Integer A) from 0 to 9, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Level of Units[(Integer A)]) Greater than or equal to 50
          • Then - Actions
            • Set VariableSet Code = (Code + (Integer((Power(2.00, (Real((Integer A))))))))
          • Else - Actions
This would loop through a units[array] 1 to 10, and add respective value to the integer variable "code", so first bit is "1" if condition for 1st unit is true etc.

binary:
0 or 1 * 2^0 (set first bit)
0 or 1 * 2^1 (set second bit)
...

So in example if 2nd and 4th units match condition it will be:

code = code + 2^1 (2)
and
code = code + 2^3 (8)

code will be 10 which is 00001010 in binary (4th and 2nd bits are set)

Edit:

It will endup actually what @pr114 suggested, he was a bit faster with posting

Edit2: Fixed loop to go 0-9 instead 1-10, to fix binary conversion
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Now this could be flipped around and turned into binary but then the max # is 1023 for 10bit, is there a way to make the # smaller but still account for all the possible combinations of heros being lvl 50 or not?
Yes and no. Data compression theory states there is not as one needs a unique sequence for each unique state that could be represented. However it also allows one to shuffle how data is represented using algorithims like Huffman compression trees so that more likely combinations can use fewer bits than less likely combinations which must use more bits to compensate.

In the end you need to consider if this compression will yield notable space improvements. It takes 1 bit per hero and on top of that for heroes that are not 50 you need to store their values anyway.
 
Status
Not open for further replies.
Top