Generate the Board
One of the primary motivations for positioning pawns at runtime is to vary gameplay on each playthrough.
If pawns are placed within the editor and not moved each playthrough, once you play a single round, you will know exactly where those pawns are placed each time. If instead, you randomly place pawns each time, there are multiple starting configurations.
To put this into perspective, if you have a board that is 5 x 5 tiles and five pawns, there are (25 choose 5) 53,130 distinct configurations. If you increase the board by just 1 more space in each dimension to 6 x 6 and keep five pawns, that number goes up to (36 choose 5) 11,686,752.
Randomization can be a powerful tool to create varied gameplay.
Generate a Random Tile Coordinate
To randomly place a pawn, you need to generate a random tile coordinate within the bounds of a board. There are many different ways to randomly generate a coordinate in two-dimensional space. The most common is uniform distribution, which is what you will use for this example. A uniform distribution places an equal likelihood for a pawn to be put on any tile on the board. For more information, see https://en.wikipedia.org/wiki/Discrete_uniform_distribution . To this end, construct a utility function named GenerateUniformRandomTileCoordinatethat takes in a bounds object to know what domain to generate the coordinate within.
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.