WELLINGTON, New Zealand – In a sparse, sunlit loft, programmer Stephen Regelous quietly works alone every day to the hum of his laptop. But what he's really doing is leading the masses.

Regelous created Massive, the special-effects program behind the colossal battles in The Lord of the Rings film trilogy. Using Massive, the Oscar-winning Weta Digital team pulled off anticipated scenes for the latest installment, The Two Towers – such as the battle at Helm's Deep – by digitally generating smart crowds to supplement the live action.

The computer-generated characters, called agents, have minds of their own.

"Every agent has its own choices and a complete brain," Regelous said. "The most important thing about making realistic crowds is making realistic individuals."

To bring J.R.R. Tolkien's books to life, gathering 70,000 or so tall, broad-shouldered extras, dressing them in elaborate armor and choreographing them slaughtering each other was out of the question. And that was just one scene from the prologue to The Fellowship of the Ring.

So in 1996, director Peter Jackson asked Regelous, who had worked on Jackson's film The Frighteners, to come up with a program that could handle the task.

In Massive, agents' brains – which look like intricate flow charts – define how they see and hear, how fast they run and how slowly they die. For the films, stunt actors' movements were recorded in the studio to enable the agents to wield weapons realistically, duck to avoid a sword, charge an enemy and fall off tower walls flailing.

Like real people, agents' body types, clothing and the weather influence their capabilities. Agents aren't robots, though. Each makes subtle responses to its surroundings with fuzzy logic rather than yes-no, on-off decisions. And every agent has thousands of brain nodes, such as their combat node, which has rules for their level of aggression.

When an animator places agents into a simulation, they're released to do what they will. It's not crowd control but anarchy. That's because each agent makes decisions from its point of view. Still, when properly genetically engineered, the right character will always win the fight.

"It's possible to rig fights, but it hasn't been done," Regelous said. "In the first test fight we had 1,000 silver guys and 1,000 golden guys. We set off the simulation, and in the distance you could see several guys running for the hills."

For inspiration, Regelous didn't watch war movies as you might expect. Instead he experimented with artificial intelligence by growing digital plants, and studied how people avoided each other on crowded streets.

Massive is not just for making war. It was also used to generate doubles of the film's stars and to create flocks of birds.

"I wanted to take the processes of nature and apply them to generate computer imagery," Regelous said.

As a result, when the dark wizard Saruman leads his Uruk-hai warriors to Helm's Deep to crush the human alliance in The Two Towers, the army isn't made up of the same character copied and pasted 50,000 times, marching symmetrically like a chain of paper dolls.

"Every soldier is drawing from their own repertoire of military moves and determining how they will fight the fight," explained Richard Taylor, director of Weta Workshop, on New Line Cinema's site. "Some of the scenes that we'll see in Helm's Deep will defy belief."

Regelous plans to sell Massive for $40,000 per single floating license. Even if he doesn't win over the market, some say he's made great advances. Seth Lippman, a 3-D sequence lead for the first two Rings films, said Massive surpasses techniques used for other Oscar-winning films he's worked on.

"In What Dreams May Come, the crowd characters were like 2-D billboards in space – filler. They couldn't become main parts of the action," Lippman said. "The illusion created by using the 2-D billboards would be exposed when employing the radical 3-D moves Peter Jackson is famous for. With the Massive approach, he could fly cameras right through the middle of the battle."

For his part, Regelous is satisfied that Massive's agents are covert enough to win over fans of the classic trilogy.

"I can't tell what's Massive and what's not anymore."