Celtic Knots
(November 18, 2008) »
Random Number Generators
(September 10, 2008) »
Fence Posts and Pylons
(March 18, 2008) »
My PhD research was in computer science and complexity science, although I also published in web-technologies (and even paleontology!) I have founded, run and sold a high-tech business based on my research and written two technical text-books published by Elsevier.
September 10, 2008
A little hobby project completed this week: creating a set of playing cards that packed in as many random-number-generating devices for board games as is humanly possible.
I think we're on twenty seven different elements, everything from Zener Cards, through Dreidels to British Navy Gambling Games. And a full set of polyhedral gaming dice too.
The final result is quite pleasant, I think, but the only bit of real AI in there is the packing algorithm.
A poker hand of cards, showing many of the elements in place. All of the elements sit on the treasure map, which has a different city marked on each card: the packing algorithm makes sure the X is visible on every card.
The packing algorithm was complicated by two issues: firstly some elements are allowed on top of others. Dice can sit on the Zener (ESP) cards, for example; secondly we have to take height into account, and particularly the angle of the view. So you can put the big d20 right behind the letter tile, for example, but not in front.
The packing plan for the Ace of Spades, shown from above. The lozenge shape is the intersection of the view frustum with the table surface.
So we need a multi-height packing algorithm. Well, actually not. It turns out a very simple tweak to the basic circle packing algorithm works. All I did was allow one element to be made up of many exclusion circles, and made sure that in some cases the extra circles always pointed towards the viewer. This allowed me to 'clear out' the area in front of low lying elements. In addition, I added constraints (the pale blue lines in the picture below) that made sure certain elements appeared in certain places on the card (to avoid the most egregious overlaps), and finally I made some elements fixed (like the purple circles representing the card-denomination boxes at top left and bottom right.
All in all the algorithm is very simple. It is a backtracking depth-first search with local optimisation: namely when a new element is added others can jiggle around to make room. The final result is exactly what I was aiming for though: an image that looks as if the dice have been randomly scattered over the desk.
The rendered Ace of Spades, corresponding to the packing diagram above. This image includes the bleed around the edge of the card, which is trimmed off during production.
I've shown the output from the packing system along with the card that results.
The final pattern is then used to generate the scene using a scripting bridge to the 3D rendering software. All 54 cards (including 2 jokers) can be batch rendered in a couple of hours at 300dpi on a consumer PC. There are various graphic tweaks in there: the dice use a custom shader to make sure that the number that is rolled is brighter than the others, to avoid ambiguity in the rounder dice when they appear near the back; and the lighting is different in every card, indicating a different time of day.
All in all I'm happy with the result: concept to full renders in a three weekends of playing. I'm planning to get some copies of the deck printed. There's more information at dicecards.com.