Procedural card generation

In this game, whenever you win a battle - sometimes also when you lose - you will be rewarded with a random selection of new cards. But instead of there being a certain number of hardcoded cards and receiving one of them at random, the game will actually generate that card on the fly according to certain parameters.

The way I achieve this is deceptively simple. Each enemy will have two hidden parameters detailing what kind of cards it is allowed to generate. The first one includes a list of what possible "card models" (i.e. specific card effects and configurations) it can drop on defeat. The second one is as a number I very imaginatively named "card points", which roughly defines how good that card can be.

Each of these possible card models has a specific but simple algorithm that receives the available card points as an input, and outputs a newly generated card. All it does is assign semi-random values to the card without exceeding the allocated card points. Occasionally a card will receive a boost in card points in exchange for a negative effect (added cost, delay, etc.), allowing for a greater effect. For added variety, the points a defeated enemy awards are not set in stone either, but will waver within a certain range.

Here's a sample of 100 randomly generated cards. Some types of cards are more common than others.

This is all nice and fancy, but it leads us to a significant problem. What about card images? Almost every card game will give distinct images to each of its cards for ease of identification. How can we achieve this when our cards are being generated on the fly? Why, by generating the images on the fly too! Once we have the data for the newly generated card, it's just a matter of deciding on a system that can generate a uniquely identifying image from that data.

The easiest way to create a new image might be by combining different small icons representing each of the aspects of the card. A card that grants +5 dice? Just add a dice symbol, a plus sign and a five. It grants health instead? Then change that dice icon for a heart. Maybe it has a cost? We could just tack on a label with the cost in a corner. Of course, the result won't be anything fancy, but it should be enough to identify the card at a glance.

It's actually rather difficult to calculate exactly how many unique cards this generator can produce, but, right now, estimation and testing puts that number somewhere around 2500 different cards (a number that will likely grow in the near future). To be fair, most of those cards are extremely similar to others, but at least they are not simple recolors - we are talking about 2500 functionally different cards. And that only required a few lines of code and high-school math. Not too shabby.

Get Random Number God

Download NowName your own price

Leave a comment

Log in with to leave a comment.