Friday, March 30, 2012

The Art of Data Modeling in Games

In day-to-day life, we construct mental models. One highly abstract model is the concept of identity. An object or being has an identity, and it can move and change while retaining the same identity - it is the same object. The notion is very useful, but at times becomes less so - for instance, in the George Washington's Axe paradox. (My friend just purchased the very axe with which George Washington chopped down the cherry tree! But in the last 200 years the blade has been replaced twice and the handle three times. Is it still the same axe?) Fortunately, in cases like these, we can flexibly switch to other mental models. We might at one moment think of a river as having a discrete identity that is fixed while the river flows, and the next moment acknowledge that you can't step in the same river twice. Such is the nimbleness of the human mind.

Computers, on the other hand, are inflexible. For a computer to understand anything, any idea, it must somehow be reduced to ones and zeroes. This creates immense challenges for any programmer, but especially a game programmer.

Some video games, like Tetris, are highly abstract. The virtual does not attempt to represent reality in any significant way. An abstract game is easier to create, because the logic of the game world can be made to naturally fit a discrete model. Most games, however, are representational - they attempt to simulate or resemble reality. [1]

So, to create a representational game, the designers and programmers must somehow take some part of reality - unfathomably complex and nuanced - and render it in discrete, finite terms. It's the same modeling problem all of us face every day, except there is no room for flexibility or approximation. When music is stored on a digital medium, no matter what the bitrate, it will always be lossy: such is the nature of rendering sounds into ones and zeroes. Likewise, whenever one renders reality into a video game it must lose detail and complexity.

Such is my biggest hurdle as an aspiring game developer. I want to write elegant, reusable games; but it's extremely difficult designing a system flexible enough to handle all the situations that might arise in the theoretical distant future. Typically I start writing a game, then back up and start writing a game engine, then I realize I need a better language in which to write the engine, and sooner or later I smash against this unchanging limitation: Computers, and their programmers, cannot accurately model reality. Compromises must be made, and thus far I have been too much a perfectionist, insistent on solving huge problems with flawless code, to accept this fact.

The talent of a truly gifted designer-programmer, I believe, is in his exercise of creative moderation. He slices reality into discrete chunks, aiming not for accuracy (never wholly attainable) but for relevance - and fun. He artfully crafts in the medium of abstract models, and works harmoniously with their limitations rather than fighting against them. And he aims not for lofty goals requiring Herculean intellect, but for simple daily ones. Thus the artful designer-programmer follows the Tao:

Act without doing;
work without effort.
Think of the small as large
and the few as many.
Confront the difficult
while it is still easy;
accomplish the great task
by a series of small acts.
The Master never reaches for the great;
thus she achieves greatness.
When she runs into a difficulty,
she stops and gives herself to it.
She doesn't cling to her own comfort;
thus problems are no problem for her.

—The Tao Te Ching, ch. 63

All this serves to reinforce my belief that skill and virtue exist in the same ecology, and that art and work are inherently spiritual endeavors. My own failures in game development are, in essence, spiritual failures. I insisted on building the Tower of Babel, doomed to fall short and fall hard. Perhaps I'll take a stab at test-driven development, a "Keep It Simple, Stupid" style of coding designed to bring lofty programmers back down to earth, solving only today's problems today. People say it's a spiritually healthy way to code - perhaps with a healthier spirit I could finally write the games of which I've always dreamed.

[1]Note that this is a simplification - it would be more accurate to say that games fall on a continuum between abstract and representational. Checkers is more abstract than Chess, which is more abstract than Stratego, which is still way more abstract than Warhammer.