Semi-randomized tiles

Game development with Board Game Arena Studio
Post Reply
User avatar
Spaulding
Posts: 3
Joined: 10 July 2015, 04:33

Semi-randomized tiles

Post 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!
User avatar
paramesis
Posts: 398
Joined: 28 April 2020, 05:00

Re: Semi-randomized tiles

Post 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'.
User avatar
Spaulding
Posts: 3
Joined: 10 July 2015, 04:33

Re: Semi-randomized tiles

Post by Spaulding »

Thanks I'll take a look!
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Semi-randomized tiles

Post 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.
Post Reply

Return to “Developers”