Randomizing and storing matching tiles

Started by
0 comments, last by Dragoncar 13 years, 8 months ago
Hi,

I'm working on a simple 2d grid-based tile matching game. This is something new for me and I'd love to get some advice on how I would go about creating a random set of matchable tiles (e.g. ensuring that a tile gets added to the board twice, so a match can be made).

* I have a set of 50 tiles to choose from
* The game board would be 6x6
* If Tile1 was randomly selected and added to the board, I'd need to ensure that it was also added elsewhere on the board, thus making a match possible.

I thought about creating an array with 18 random entries, and then using those 18 entries to create another random array with 18 entries, thus netting me 36 tiles. Finally I would combine the arrays and shuffle the entries.

This approach sounds like it would work, but I'm curious if there is a more efficient way to go about doing this? Any advice you could offer would be greatly appreciated.
Advertisement
Have you thought about selecting a card a random and then randomly placing it twice?

Or when you select a card to place on the board, place another of the same card right next to it and then randomise the locations by shuffling?

eg. after first placing the cards, but before shuffling you would have 1 1 2 2 3 3, after shuffling 1 3 2 3 1 2

This topic is closed to new replies.

Advertisement