Forum BigDB Generating Random Booster Pack Serverside?

Discussion and help relating to the PlayerIO database solution, BigDB.

Generating Random Booster Pack Serverside?

Postby sbrodie » August 27th, 2012, 7:11 pm

Hi All,

I'd like to have players be able to buy a booster packs of game items from a list of payVaultItems I've created. I'm having trouble finding an efficient and scalable way to do this. I'd like to hear your suggestions for how to most efficiently support the below scenario:

1) I have all of the items I'd like to select from created as PayVaultItems. Each item has a rarity and edition property. I have an index setup that sorts all items by rarity.
2) I'd like to be able to select a random set of these items based upon some breakdown in rarity (for example, a pack of 8 cards, 4 commons, 3 uncommons, and 1 rare).
3) Award them all to the user's collection once the set is selected.

What I've tried so far:

1) Brute Force: do a load range of my index organized by rarity. Pull down each set of cards by rarity separately. I then select randomly from the arrays that are returned to build my pack. This seems really bad for when I start getting 100's of items in my total collection.

2) I tried to develop a solution that fit what was suggested here (giving each card an id, then loading by that id after a random selection): post5697?hilit=random%20object#p5697 . The difference in my case is that ids for each card will not match their position within the index, because I want to select from only a subset of the collection in most cases. What I'd like to be able to do is: set my total count of known rare cards in some other object, generate a random number between o and that total, and then load an item at that position within the rarity index (ex: select card at index 3 of the returned set of 5 rare cards). I couldn't see a way to load by a particular position in an index, however.

Any suggestions for how to approach this would be appreciated!

-Scott
sbrodie
Paid Member
 
Posts: 3
Joined: March 19th, 2010, 4:37 am

Re: Generating Random Booster Pack Serverside?

Postby RedCorona » August 27th, 2012, 8:11 pm

How about another table with three objects in it, which acts as a cache for rarity->id lookup (i.e. select id from cards group by rarity)? I.e. it would contain

Code: Select all
object rare
rarity => 'rare'
ids => (1, 2, 4, 7, 9, ...)

object uncommon
rarity => 'uncommon'
ids => (3, 6, 8, 12, ...)

object common
rarity => 'common'
ids => (5, 10, 11, 13, 14, 18 ...)


You have to remember to add items to these arrays when you add new cards, of course. But I think you have to cache the information to avoid traversing the whole list. Updating the cache is not difficult, either manually when you push cards into the cards table or automatically if you have some card submission code.

You can then use the arrays as the thing to look up into randomly, which will give you ids that you can use when looking up cards in the cards table.
RedCorona
 
Posts: 1
Joined: August 27th, 2012, 8:09 pm

Re: Generating Random Booster Pack Serverside?

Postby dreamora » August 28th, 2012, 4:22 pm

Instead of additional objects to do that (which is risky due to the 600kb per database object limitation), make the rarity an int or uint on the objects and use an Index that filters by Rarity ascending and you can filter for one of them.

Thats also easier to maintain than an object that needs to be updated on each modification of the card database which can be a major pain
dreamora
 
Posts: 225
Joined: March 2nd, 2012, 9:58 am

Re: Generating Random Booster Pack Serverside?

Postby sbrodie » August 28th, 2012, 6:19 pm

Thanks for the replies! I ended up following the solution RedCorona suggested. At first I was worried about the maintenance of the object, but I created an admin app that lets me poll my card data and regenerate the object for me. I plan to run this object creation operation each time I add cards, right when I launch a new build.

@dreamora I think I might still have the same problem with your index solution? I tried that before (attempt #2 above), but maybe I'm missing a key piece to understand how your solution would work differently? Thanks though!
sbrodie
Paid Member
 
Posts: 3
Joined: March 19th, 2010, 4:37 am

Re: Generating Random Booster Pack Serverside?

Postby dreamora » August 28th, 2012, 7:01 pm

Indexes allow you to specify values, like the rarity of cards that it is meant to return.
You can even make indexes with more than 1 attribute, for example the first attribute could be 'set', while the second is rarity. Cause you will normally want to filter booster for the expansion set to which they belong first while the rarity within that set is the secondary attribute by which you want to filter them


Within these data you will then get, you can then pick 4 or whatever random cards (depending on your request to the index that would be rare, uncommon or common cards) in the array and use them for your booster.
dreamora
 
Posts: 225
Joined: March 2nd, 2012, 9:58 am


Return to BigDB