Page 1 of 1

Semi-randomized tiles

Posted: 21 July 2020, 04:28
by Spaulding
Hey everyone,

I'm just getting started with BGA and am working on implementing Homesteaders - however I'm a bit stuck and overwhelmed trying to just figure out which files to put things in. I did the hearts tutorial and read through a few other game examples, but haven't quite found a good match for Homesteaders.

The current issue I'm having is how to represent the auction tiles - how they work is there are up to 3 piles of 10. The first pile is always in a specific order. The 2nd and 3rd piles are partially randomized based on the phase of the game; tiles 1-4 are randomized, 5-8 are randomized, then 9-10 are randomized.

I'm not sure what the best way to store these (or even entirely what files to use). I'm thinking I would need to create 2-3 database tables for the different tile piles; I was looking into using Deck() but it seems like it would be more difficult than it would be worth. I'm also not sure which files I would specify the definitions of each tiles in, Materials or Game, and where I would do the randomization.

Any advice or direction would be appreciated!

Re: Semi-randomized tiles

Posted: 21 July 2020, 04:53
by paramesis
The Deck is a really flexible component that would be able to do all of this with a single database table.

If it helps, you could look at the setup function in my Off the Rails implementation (see SET UP DEPOSIT DECK around line 228 of game.php). This game has a pretty fiddly setup where decks are split up and shuffled multiple times before combining them to create the deposit deck. The easiest way I found to implement this is to use the php shuffle (ok by the BGA guidelines, but every other random number should use bga_rand) on the sub-decks as they're constructed and shuffled before actually adding them into the php deck.

In this case, it ended up making my database layout and interactions much simpler by storing almost every object in the game in a single deck, which was possible by making use of all of the properties (type, type_arg, location and location_arg).

If elements need to be reshuffled after the game is set up, you can use the deck's shuffle method to shuffle all elements in any given 'location'.

Re: Semi-randomized tiles

Posted: 21 July 2020, 05:17
by Spaulding
Thanks I'll take a look!

Re: Semi-randomized tiles

Posted: 21 July 2020, 10:36
by Tisaac
Whatever you choose (one deck database, or custom database), I strongly encourage you to create a separate Class that will take card of everything you need about this deck so that in the game.php you only make call to methods of this class.
That way, it will make the code easier to read/maintain, and if you change the way of stocking the cards for whatever reasons, you won't have to change all your code but only the corresponding class.