Inlägg

Food, reproduction, and life counters

Bild
Food After predators were added, we ventured into adding an additional layer to the food chain: fish food. While this change ultimately required relatively few lines of code to implement, there were a lot of small tweaks and bugfixes that needed to be made.  In order to utilize the predator system, food was added as new school of fish. That is to say, every piece of food is actually a boid, with all the abilities and steering forces of any other fish, just with zero movement speed. Apparently there were several parts, both in how the boids spawn and in how they interact, that originally didn't account for having "fishes" that can't move, but once these were hunted down, they were relatively easy to fix. For simplicity's sake, the model for food is just a light green sphere. Reproduction At this point, both fish and food will both be slowly picked off by their respective predators until the only remaining feature in the simulation are the sharks, so the next step i

Space Partitioning

Bild
The primary bottleneck in the boid code from lab 1 was the GetNeighbors method. This method was called by each boid n number of times, where n is the number of boids. This made the combined complexity of the GetNeighbors call O(n 2 ). Naturally this does not scale well when we increase the number of boids. Fortunately it is possible to improve this performance by taking advantage of the fact that all the interactions are limited to only occur within a set radius from any given boids. Any boid outside this radius is guaranteed to not have an impact on the simulation and can thus safely be ignored.  For this approach to work in practice we need a data structure which is able to represent the relative proximity of two boids. In this project we used a grid implemented as a 3D matrix, but there are a number of other possible data structures. The grid works by partitioning the simulation space into a number of cubes. During the simulation each boid is assigned to one of these cubes. The assi

Predators and prey

Bild
  Adding predators involved several steps of modifications to the original simulation, primarily in the Unity settings. First we need a school of fishes using the new predator type which involves making a few prefabs, or prefabrications, of a predator fish that we can use as a template. Doing so was slightly tricky as importing third party models does not seem to be completely standardized and led to some issues in getting the shaders to work. Once this was resolved it was merely a question of adding the scripts to a basic gameobject which added required code for fishes to work, turning each separate fish into a boid. From this point a new school of fishes was required, using the predator prefab as a template to create more fishes. This was easily accomplished by copying the school of fishes and changing the variables to turn it into a school of predators. However, for this to do anything the behavior of fishes had to change based on their type. To do this the Boid class was changed to

Project Specification - Oh-fish-ial business

Bild
  Jakob Arvidsson - jakarv@kth.se Emilia Rosenqvist - emiros@kth.se William Nilsson -  wnil@kth.se Grade Target A-E Background In order to simulate flocking and cohesion behaviors in animal populations, an artificial life program was developed to simulate the behaviors [1]. This program used the notion of each individual in a population having an individual drive based on their own interests and goals based on three fundamental driving forces to simulate the desired behavior. These are the forces of separation, keeping individuals from getting too close, alignment, keeping individuals oriented in the same general direction, and cohesion, keeping individuals within the flock. While the original program was developed specifically for birds, the same algorithm gives good results for flock behavior in other populations as well. One way to expand upon this is by introducing predators and prey which is discussed by [2] and [3].  Implementation The 3D engine Unity will be used to create the s