Sunday, June 21, 2015

An Eco-Fantasy Game

This month I've been so intensely into my computer sandbox/simulation game project that I haven't thought much about my next blog post. So let's talk about the game I'm working on.



The game I'm working on, tentatively titled "The Eldar and the Fallen."
I don't know, I might make the characters less cartoony than the one you see here.

The project is actually years old. It's hard to say when it started. When I was six we got a Nintendo and I remember asking Uncle John, a computer programmer, how video games were made so that you could do so many different things in them. At the age of seven my brother and I started a video game design notebook with drawings of enemies, controller layouts, and level designs. We continued to "design" games pretty much until I went to college, though by that time a lot of our creative energy went into board games and role-playing games like D&D, since we could actually playtest what we designed.

I didn't learn any actual programming until my junior year at Caltech. When I did it was a revelation. There was this adjunct lecturer from JPL who was into "artificial life," that is, designing computer programs capable of evolution. He held a bunch of popular undergraduate courses where you could do experiments with his "domesticated computer viruses."

Designing computer programs that evolve is actually laughably easy. In terms of programming all you need is a program that copies itself with random mutations. At first they tried compiling their evolutionary programs in "machine code," that is, the basic hardware language that all computers use. But when they ran the code it evolved out of control.

A mutation is nothing but a copy mistake. When your DNA replicates, sometimes there are errors, and when these are passed on to your children it might give them new traits that were never seen before. Because mutations are random, most are harmful. But some are beneficial, and these provide raw material for evolution by natural selection.

In the first artificial life experiments they ran, most of these mutations would corrupt the code and the program would be unable to replicate, and some other program would overwrite it with its own offspring. But other mutations were very beneficial. For example, they might introduce a shortcut so that a program could self-replicate a little faster. Or they might introduce some trick for getting more attention from the CPU. And this is exactly what happened. The programs got really really short and fast, and found more and more tricks for exploiting the hardware. Eventually they got so good at self-replicating they broke free and corrupted the system's registers, and the hardware was ruined.

Desert, plains and forest. Still needs trees and more natural, curved boundaries.
After that their experiments with artificial life were more careful. They gave their living programs a "virtual CPU" to fight over. You might Google 'Tierra' and 'Avida' if you're more curious about how these programs work. Tierra was especially interesting because it managed to evolve its own ecology, complete with producers and consumers, and a balance between the two. As I got deeper into the theory of evolution, it turned out that computer simulations were indispensable for doing certain evolutionary and ecological experiments. Over the past ten years I've written several of my own simulations for exploring the nature of Group Selection, which I've discussed in previous posts. Basically, Group Selection is what allows traits like "kindness," "charity," and "self-sacrifice" to evolve. Many biologists have argued that it must be rare because evolution appears to be "selfish." But to the question of how rare group selection might be in nature, my simulations have given me the answer "not rare at all." The conditions for it, I've learned, are extremely general.

Biologists like to say that kindness evolves from "kin selection" -- that is, we are kind to our family because they are carrying our genes and thus we are really "selfishly" promoting our own genetic material. But if you think more carefully about this reasoning you can see it doesn't make sense. To see this logically let's take a silly fictional example. Say there was a gene for kindness that you transplanted from humans to frogs and it still worked. Might seem impossible, but let's assume it for the sake of argument. By the theory of "kin selection" we would then care as much for these frogs as for our own relatives.

"But wait," you say, "our own relatives would still carry many more of the same genes, so shouldn't we still be nicer to them?" Maybe, but that's irrelevant to how evolution actually works. Our hypothetical gene for kindness would spread by promoting itself wherever it might be found. It doesn't matter if you help a frog or a human, if they have the gene for kindness they too will go on helping other frogs and humans.

Humans and frogs share most of the same DNA anyway, so the entire discussion is absurd. What really matters is helpfulness itself. You should help all organism no matter how closely related they are to you, and this behavior is supported by group evolution. To prove this to myself I wrote a simulation where organisms were split into a number of different "species." I divided each species into "nice," "species-centric," and "mean." Nice organisms would help each other reproduce when they were next to each other--whatever the species. Species-centric organisms would only help their own species. Mean organisms were competitive and would harm everyone.

Eventually what happened was that the "nice" organisms banded together against the "species-centric" and "mean" organisms. The coalitions of several species working together did the best.  It was after running these simulations that I became fully convinced that ecological-level natural selection is the most powerful.

***



This rocky cliffs along this randomly-generated coastline turned out rather nice.


Evolutionary programming is seductive because it seems like you can get creativity for free. Since learning about artificial life in college I have spent countless hours daydreaming about designing my own form of artificial life that could evolve with endless creativity, so you could watch diverse new species and ecosystems emerge. About a year ago I had an idea for doing something kind of like this. 

The first thing you realize is that you have to simplify. Even the simplest bacteria is too complicated to be simulated completely on a computer, let alone an entire ecosystem. The idea is imitate nature, to represent it artistically, not to rival it. So the question was: what is essential to ecological evolution?

I wanted it to be open, free to evolve in any direction. So I began to design a kind of language, similar to DNA and to the self-replicating code of Avida and Tierra.  The language would include things like, "compare this gene to that gene" or "move this gene from position X to position Y." Just as you can build complex computer programs out of simply instructions, I hoped my organisms could evolve complex, interesting behavior over time.

I never did finish writing this program. I think it became too abstract. Even if my organisms did become complex, it would be in a way that I could hardly appreciate. Avida and Tierra tend to evolve very dense, efficient, hard-to-read code, code that a human programmer would never write and would hate to maintain. Human DNA is the same -- most of it is still to tangled up for researchers to grasp. Evolution works this way too -- it doesn't have an audience in mind. It's like when you enter a "disorganized" mechanic's shop. The mechanic knows exactly where everything is and thus his mess is extremely efficient. But it would be a waste of time to try to learn his system because it evolved for this particular man and how he thinks. It would be more efficient to simply develop your own system.

Some more pretty cliffs on the coast.


So I returned to fiction writing and blog-post writing. I wondered if truly interesting artificial evolution was a pipe dream. Even if you got it to work it wouldn't really be interesting, just an evolving mess with its own set of problems that have nothing to do with yours. Sort of made me think of pessimistic extra-terrestrial contact movies like Solaris or Contact. Even if we did meet a totally different life-form out there, maybe it would be too different to be really interesting or relatable.

But over the past couple of months this train of thought collided violently with another.

For years I've been trying to write "ecological" science fiction. I wanted to write something where the future wasn't some endless progress toward a more and more trivial way of life. Nor an endless war between empires over power and money. Rather, I wanted to re-envision history as a evolutionary story about ecological balance. Every empire collapses. Every trivial way of life self-destructs. Maybe we could build Utopia but it would never last. Why?  It is in the nature of evolution, ecology, and life itself. Progress is an illusion. The only things that last are value, virtue, truth, and beauty.

I want to teach people to think ecologically with my stories. I want them to understand that life is a balance of suffering and joy, creation and destruction. I want to express the importance of what is real, genuine, and creative over what is superficial, entertaining, and complacent.

Even my best stories are still failing to do that. If I write a story with a lot of ecology and not enough character development people lose interest. If a I write a story with a lot of ecology and fantastic character development people praise it up and down for the characters but never notice the ecology.

The problem is, a story is just a representation. You can write a super complex series of novels about how this empire collapses and out of the chaos a new sense of duty and virtue evolves, but something similar has already been done so many times that your readers and critics will only notice the cliches. They will probably miss the subtle, essential things that it is really about.

Ecology is about consequences, as the author of Dune, Frank Herbert, was fond of pointing out. So maybe the medium I'm looking is one where the reader is forced to make decisions and face the consequences.

Eventually all this dark green area will be forest. I'm going for a lush, pixellated look. Still working on getting it right.


There is a medium like this out there. It's one of the newest and most successful media there are. It's the only art form I spent more time with as a kid than novels or movies.

Fortunately for me, I've been a professional computer programmer now for over two years. In about a month I've written a program capable of:

1) Animating a little cartoon-elf who can walk north, east, south, west, and diagonally, and bump into objects.

2) Generating a world map with mountains, seas, plains, forests, and deserts. I've successfully generated a map large enough that it would take you over 2 hours to walk from one side to the other, and several hundred hours to explore the whole thing.

3) Generating some detail in the local terrain. My strategy is to provide each local map with a random seed that will psuedo-randomly generate a unique local terrain. This way I've succeeding in having a world with over a billion shrubs, and over a million unique local landscapes that will be the same when you come back, without storing more than few megabytes of data total. This is currently in progress.  You'll notice in the screenshots a lot of straight lines and flat areas. I'm going to be making the boundaries between terrains look more curved, blotchy, and natural, and adding trees, hills, etc.
A randomly-generated world map. Black is water.

My goals for the program in the coming months/years are:

* Have populations of herbivores in place that will live in ecological balance with the vegetation.
* Have populations of predators to eat the herbivores
* Have populations of elves that can fall in love, marry, have children, garden, forage, and hunt
* Have in place a few rare "magical" plant species and animals (like unicorns & fairies) that are also part of the ecology.
* Give some elves the capability of exploiting the land by mining or tilling, and give them the capability of banding together into empires that conquer land and throw it out of ecological balance
* Set this all up in such way that you have an entertaining game somewhere between a sim (like Sim City or the Sims), a sandbox (like Minecraft), and an real-time-strategy game (like Age of Empires) where the challenge is to preserve your tribe of nature-loving elves against the onslaught of an expanding empire. Maybe you could call it "eco-fantasy." I want there to be enough freedom that you could join the empire if you wanted, or try out some of its magic and technology, or become an independent raider or conqueror -- and see where it lands you.  I'd like there to be real danger of permanent death for characters (it's just a game anyway!) where the challenge is to stay alive and save others' lives.  Where it's also possible to befriend the enemy, or to run away and start again in the hills during the dark times. I'd like the game to function as a sort of story-engine, where there can be romance, mulit-generational conflict, and tensions between the goals of individual characters and the tribal or imperial society. 

I have ideas for implementing all of the things I just described, but the nature of the beast is to run into unexpected complications along the way. I'll be forced to simplify, abandon certain objectives, and maybe introduce new sub-objectives. But enough progress has already been made in modern computer games that I am optimistic, and extremely excited.  It's pretty much all I think about these days ...

More updates to come. And hopefully a continuation of some of the philosophical trains of thoughts in my last post, if and when I can ever pull myself away from this game project for a bit.

No comments:

Post a Comment