A hunting video game for fish shows how swimming in groups can protect against predators.

Researchers at Princeton University developed a simulation of small prey to observe how group formation and movement alone might reduce the risk of being attacked. Each digital prey was encoded with varying tendencies to swim alone, group together, or follow other prey, so that they would form different types of groups spontaneously in the simulation, a statement from Princeton explained. The virtual prey, which looked like reddish dots, were then projected onto the tank of a bluegill sunfish.

"Effectively, the bluegills were playing an immersive video game in which they hunted," researcher Iain Couzin, a Princeton evolutionary biologist, said in the statement. And like a video game that adapts to the skill of its players, Couzin explained that the simulation was designed to get harder and harder for the bluegills.

"In a similar way, our prey 'evolved' to the mode of hunting that the bluegills exhibited, adapting better strategies that allowed them to evade hunting more effectively," he said.

The researchers found that prey forming groups "survived" better than the solo swimmers, however it was also imperative for the swarms of fish to balance closeness and coordinated movement. Large groups that didn't move much were more likely to fall victim to attacks in "high-risk" areas of the bluegill tank, but groups that moved with coordination whizzed through these high-risk areas unscathed, the researchers said.

The study's results, which were reported in the journal Science last week, suggest that the specific configuration of animal groups evolved as a defense in its own right, the researchers said.

Follow LiveScience on Twitter @livescience. We're also on Facebook & Google+.