*Author

davidy22

  • Guest
Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg273840#msg273840
« on: February 19, 2011, 02:09:11 pm »
Hello, I'm new to this forum and really like elements. I also happen to really like programming, and I couldn't help but notice that a little optimization could be made. You know how the deck builder thing gives deck codes like this?

4t5 5f0 5f0 5f0 5f0 5f0 5f2 5f2 5f6 5f6 5f6 5f6 5f9 5f9 5f9 5f9 5f9 5f9 5fa 5fa 5fa 5fa 5fa 5fb 5l9 5l9 5l9 5l9 5l9 5l9

Well, I have a way to shorten that a bit. It's a little mathy, but can reduce the file size of deck codes a a little bit. It's kinda annoying that the deck codes have numbers in them, and an array lookup would be kinda slow, so I'll have to think on how the game is going to do letters. Don't have flash, but I think it has an inbuilt for numbers of a base higher than 10. anyways, on the meat of what I was saying.

Suppose you took a 30-card deck code like this:

4t5 5f0 5f0 5f0 5f0 5f0 5f2 5f2 5f6 5f6 5f6 5f6 5f9 5f9 5f9 5f9 5f9 5f9 5fa 5fa 5fa 5fa 5fa 5fb 5l9 5l9 5l9 5l9 5l9 5l9

That, in programming, would be a string of 120 characters, or 120 bytes. If the player-owned cards database is also managed in the same way, that's 1500 cards times 4, which comes to 6000 bytes. That's 6 kb. 1,000 players means 6mb. 1,000,000 players means 6gb. Doesn't seem like much, but scale up the numbers and the cards and things are going to start adding up. My proposal is a client- side compression, where the codes have the spaces removed and are treated like base-36 integers. They are then converted to base 10 using an inbuilt function in flash, or high-school maths if no inbuilt exists. Those base 10 integers are then stored instead of the long string-based card lists. Thus, a deck code like this:

4t5 5f0 5f0 5f0 5f0 5f0 5f2 5f2 5f6 5f6 5f6 5f6 5f9 5f9 5f9 5f9 5f9 5f9 5fa 5fa 5fa 5fa 5fa 5fb 5l9 5l9 5l9 5l9 5l9 5l9

becomes:

4t55f05f05f05f05f05f25f25f65f65f65f65f95f95f95f95f95f95fa5fa5fa5fa5fa5fb5l95l95l95l95l95l9

Which becomes a really big number that I can't be bothered to work out, but definitly takes up less than 120 bytes of space. Or you could just go halfway and convert each individual card to a number value, to get:

6269 [some long line of four-digit numbers]

While this seems like it would take up even more space, to the computer, it's just a long line of shortints, or whatever you call 16-bit numbers in flash. Decoding is similarly easy, just convert each number back to base 36 to get your original card values. Because flash stores characters as 16-bit characters, you immediately cut out 2/3 of the filesize. If you went all the way and did the conversion of the whole deck code, you may have to store it in multiple longints, butit would take up a small fraction of the space that it would take up now.

What does it mean to players?
Your decks codes will stay the same, but a conversion would be preformed when sending your card info to the server. People with fast internet connections but slow computers will suffer. People with fast computers but slow internet connections will benefit. People who have slow computers and internet connections will see a small performance hike. People with fast computers and fast internet connections should wait for elements 3D.

What does does it mean for Zanzarino?
You can put off upgrading your servers for a little longer by offloading the conversion work to the game clients. Your hard drive gets freed up a little, your bandwidth takes a bit less strain and the CPU has less data to process. Which means you can cut AC costs too and help save the environment.

What can be added because of this?
The max card limit can be ramped up massively, or Zanzarino can implement a “save decks” feature to fill in the space he saved. This will still mean that he has to code the feature, so I wouldn't nag him.


Any thoughts? Is it already done? Any flaws I missed?

Offline Ajit

  • Hero Member
  • *****
  • Posts: 1015
  • Reputation Power: 15
  • Ajit is a Blue Crawler starting to think about his first run.Ajit is a Blue Crawler starting to think about his first run.Ajit is a Blue Crawler starting to think about his first run.
  • Awards: Winner of the Card Border Redesign
Re: Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg274019#msg274019
« Reply #1 on: February 19, 2011, 06:45:22 pm »
I don't know anything about the coding you mentioned (: but looking at the potential outcomes you highlighted, it seems like a great idea!

Just, I wonder, would old codes still work?  I mean by the way you explained it I feel that each card wouldn't have its own unique code?

Offline Tom Bombadil

  • Hero Member
  • *****
  • Posts: 1497
  • Country: it
  • Reputation Power: 16
  • Tom Bombadil is a Blue Crawler starting to think about his first run.Tom Bombadil is a Blue Crawler starting to think about his first run.Tom Bombadil is a Blue Crawler starting to think about his first run.
  • Tryin' to get out of the Pizza topic...
  • Awards: Slice of Elements 5th Birthday Cake
Re: Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg274068#msg274068
« Reply #2 on: February 19, 2011, 07:57:34 pm »
you are talking about treating deckcodes like numbers in base 36.

E.g. 4t55f05f05f05f05f05f25f25f65f65f65f65f95f95f95f95f95f95fa5fa5fa5fa5fa5fb5l95l95l95l95l95l9 ~ 4*3689 ~ 2460 ~ 460 bit ~ 58 byte

now it's 120, you saved about half the space.

But I'd rather choose a 90 36-base-digit sequence in import/export panel, than a 138 10-base-digit sequence, or even a 460 binary digit one.

This idea is good for memory saving (about half the space, or even more, depends on which base would you use for deckcode), but when using Import/Export panel, it's more user friendly to keep the actual code, at least without space.
Wise Man: "If you don’t stand for something, you will fall for anything."
Mankind is divided in 10 types of people: those who understand binary and those who don't.

Offline Ekki

  • Hero Member
  • *****
  • Posts: 1425
  • Country: ar
  • Reputation Power: 0
  • Ekki is a Spark waiting for a buff.
  • Not-so-young Elemental
Re: Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg274145#msg274145
« Reply #3 on: February 19, 2011, 09:50:35 pm »
I think I get the idea, although I know 0 (zero) coding :D but I think that the community in general would be benefited, since Zanz' would have more speed, thus most computers would benefit (IDK up to what point old computers are slowed down by flash games).

Also,
you are talking about treating deckcodes like numbers in base 36.

E.g. 4t55f05f05f05f05f05f25f25f65f65f65f65f95f95f95f95f95f95fa5fa5fa5fa5fa5fb5l95l95l95l95l95l9 ~ 4*3689 ~ 2460 ~ 460 bit ~ 58 byte

now it's 120, you saved about half the space.

But I'd rather choose a 90 36-base-digit sequence in import/export panel, than a 138 10-base-digit sequence, or even a 460 binary digit one.

This idea is good for memory saving (about half the space, or even more, depends on which base would you use for deckcode), but when using Import/Export panel, it's more user friendly to keep the actual code, at least without space.
Maybe with a bit of RAM memory you would be able to make the game/forum do the translation so you would get a shorter code (maybe even shorter than this one), but that's pushing it too much.

IMO, we should think of equality, so IDK up to what point this idea is masses-friendly, although the comunity won't see it.

Offline Stickmasterluke

  • Full Member
  • ***
  • Posts: 255
  • Country: aq
  • Reputation Power: 3
  • Stickmasterluke is a Spark waiting for a buff.
  • :D!
Re: Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg274147#msg274147
« Reply #4 on: February 19, 2011, 09:56:09 pm »
You could hash the codes, but people like them the way they are, nice and easy. And you can make small edits to decks without opening Elements with the current deck code system.

Falcon4415

  • Guest
Re: Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg274164#msg274164
« Reply #5 on: February 19, 2011, 10:13:13 pm »
And you can make small edits to decks without opening Elements with the current deck code system.
If you can keep this, you have my vote. Otherwise, you don't.

Offline Ekki

  • Hero Member
  • *****
  • Posts: 1425
  • Country: ar
  • Reputation Power: 0
  • Ekki is a Spark waiting for a buff.
  • Not-so-young Elemental
Re: Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg274173#msg274173
« Reply #6 on: February 19, 2011, 10:31:09 pm »
And you can make small edits to decks without opening Elements with the current deck code system.
If you can keep this, you have my vote. Otherwise, you don't.
He means that every 3-letter/number code has it's equivalent on a card, so you can add/take out anything you want from it.

davidy22

  • Guest
Re: Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg274268#msg274268
« Reply #7 on: February 20, 2011, 12:29:12 am »
You could hash the codes, but people like them the way they are, nice and easy. And you can make small edits to decks without opening Elements with the current deck code system.
Hashes are lossy processes, and are usually used for integrity checks. If we relied on hashed codes for card storage, people would start losing cards. Maybe if we had a hash alongside the main card list to make sure that there was no data corruption, though I think flash does that for you.

We could have the deck codes translated by the client from the user-friendly version to the integer version for sending off to the server. The server can store that integer value instead of the long strings that we see. Deck codes would stay the same.

davidy22

  • Guest
Re: Backend suggestion https://elementscommunity.org/forum/index.php?topic=21412.msg276135#msg276135
« Reply #8 on: February 22, 2011, 05:58:52 am »
Actually, there is one more limitation to my idea. Because there would be no space separation between cards, the maximum number of cards there can be is 36*36*36, or 46656, unless a painful revamp is done. Given that there are only about two-hundred or so cards right now, and the card creation proccess is slow as mud,  it's going to take a while to hit 46656.

 

blarg: