Eric Turner Period 3 Comp. Res. September 26, 2006 Evolution Simulator The evolution of various organisms is in fact just a simple process taking place in fairly intricate environments that would support any multitude of applications. The EvolutionSimulator contains a Set of Environments, which can interact with each other. ****Environment: Everything in the simulation takes place in the Environment, which is essentially a coordinate system. An environment is a two-dimensional grid that contains a Set of Items. Every Object in the EvolutionSimulator is-an Item. Items have several characteristics, including position, size, and which Environment they are in. Items have various characteristics, one of which is position, represented by a Vector. The Environment provides an origin for all the position Vectors, which allows them to relate to each other (position A is to the left of position B, etc.). This allows the Environment and the Items to detect and prevent collisions, which is critical for most simulations. Using only a Set of all Items in an Environment, collision detection would have an efficiency of O(n^2) (every Item iterates through every other Item to check if they are overlapping). Since the Environments usually need to be fairly big, this would make the program's run-time far too slow. So, every Environment, along with a list of all Items, has a matrix of Sectors. A Sector is a set of Items, usually representing an area on the terrain of an Environment. A sector can either be composed of water, or non-water (land). A sector can also be active or inactive. If a sector is inactive, then Items cannot enter it, so it acts as if the environment does not exist in that particular area. This allows Environments to have shapes that are more than rectangles. If given a position, an Environment can return which Sector contains that position. This allows Items to know what is immediately around them, and provides O(n) efficient collision-detections. Usually, a grid of 9 Sectors are checked, just in case an Item lies on the edge of a Sector. Environments have several other physical properties in addition to content, size, and shape. One of these temperature. Temperature is measured in Fahrenheit, though conversion to Centigrade is built-in. While the temperature does not affect the Environment itself, it can affect Items within the Environment. An Environment also has a timer, which can show an age, or a time of day (day-length is also a property of Environments). Because of this, an Environment has two states: day-time and night-time. Temperature within an Environment varies by a specified amount during each day, reaching a maximum temperature in the middle of the day, and a minimum temperature in the middle of the night. The temperature change follows a sinosoidal curve. The Environment has properties for the average temperature, and the temperature range. Every Environment also has an Atmosphere, which is prodominantly used for the breathing of plants and animals. An Atmosphere contains Oxygen and Carbon Dioxide, the amounts of which are proportional to the size of the Environment. Although an Environment is displayed as a 2-D grid, it is in fact a Torrous. In other words, when an Item moves out-of-bounds on the a side, they reappear on the opposite side. This is a quality that can be toggled within all Environments. Since the Items of the Environment are continuously being iterated through, there is a special method for the adding and removing of Items from Environments. Each Environment has two public Sets: itemsToBeAdded and itemsToBeRemoved. If through the course of an iteration it is decided for an Item to be added or removed, then they are added to the respective set. This provides more centralized control of the contents of the Environment. Finally, Environments have a set of characteristics that are purely aestetic. These are a name, background color, and background image, as well if the background image is tiled or untiled. ****Types of Items: There are three direct subclasses of Item: Food, MovingItem, and Transporter. A Transporter is connected to another Transporter at a distant location (including a separate Environment entirely), and transports any Item that collides to a location in proximity to the partner Transporter. This is a mechanism for Items to move to different Environments, but is not really important to the simulation, other than organisms naturally moving to foreign Environments. Food is an object continuously accumulates energy. Food is used by Herbivores, which will be discussed later. It is currently the only edible object in the Simulation. Food accumulates energy twice as fast when in water. It also intakes Carbon Dioxide, and releases Oxygen. MovingItems are, simply, any Item that moves. These Items contain the collision detection code. The only MovingItems currently in the simulation are Organisms, though there is unused code for others. Every Item has a specific function. This function can be accessed by Orgnanisms when they are in certain states, such as curious. Most objects do not perform a function, but tools such as Transporters are used through this method. I hope to incorporate smart enough AI to record the function of discovered Items, and possibly use that to their advantage. ****Organisms: While Organisms are just one type of Item in the environment, they contain the code that this simulation is most dependant on. While every item has a quality isAlive(), which returns a boolean, Organism and its subclassses are the only ones to return true. An Organism is considered alive, because if certain conditions are not met, it dies (is removed from the environment). If an Organism's health is 0 or its oxygenStored is 0, it dies. Otherwise, a probability is checked at every timestep to see if it will die randomly: if(!canBreedAndDie) return false; if(health() <= 0 || oxygenStored() <= 0) return true; return Math.random() < probOfDying()*age()/health()/radiusOfContact()*temperatureDiscomfort(); In other words, the probability that an organism will die at any given time is directly related to its genetic trait probOfDying (which can evolve), its age, and how uncomfortable it is with its Environment's current temperature. It is inversely related to its health, and its size. The key property of Organisms for this simulator is that they can evolve. This is currently done by manipulating variables representing traits, but I hope to incorporate a method that allows for the unexpected. Organisms have genetic traits, and non-genetic traits. Their non-genetic traits are: color current status* number of children current target* gender current strength energy health oxygen stored age size *deals with AI Genetic traits are those that are passed onto offspring, and have a probability of mutating, allowing for natural selection. The current genetic traits of an Organism are: child color adult color senior color pregancy period speed turning speed strength factor default health breath amount oxygen used out of breath at lung capacity metabolism probability of dying disease resistance radius of sight night vision factor fertility energy percentage given to offspring hunger factor age of maturity age of impotence size of maturity preferred temperature temperature comfort factor probability of a mutuation These are the variables that determine how evolved a specific Organism is. Traits such as strength factor, and probability of dying, are included in a varying trait of an Organism. Organisms also have a genetic image that evolves, allowing Organisms of close relations to have similar patturns and freckles. ****Types of Organisms: Currently there are two subclasses of Organism: Herbivore and Predator. A member of the Herbivore class gets nutrients by 'eating' Food items, and a member of the Predator class gets nutrients by 'eating' Herbivores. In both cases the aggressor is removing nutrients, but not killing. If the Herbviore's current energy is not enough to satisfy the Predator, it also takes energy from the prey's health. Since a Food item continuously resupplies itself, it eventually grows back. However, since the death probability of an Organism depends on its health, a Herbivore is more likely to die after a severe attack. The strength of both predator and prey is a determining factor to how much nutrience the Predator is able to acquire. Sine both Herbivores and Predators can evolve, the hope is the predator-prey relationship will be an incentive for both parties to evolve faster. Since it is much more difficult for a Predator to catch and eat its prey than a Herbivore, The initial values of eyesight radius, strength, and speed are twice the values of Herbivores, and their metabolism is half the value. I am still perfecting these default values to produce a stable Herbivore-Predator ratio. I hope to introduce more Organisms into the environment, including Omnivores, and ones that reproduce asexually. ****AI for Organisms: The AI is an aspect that I hope to improve on greatly, since I am currently taking the course AI. The current AI has an Organism select a target, based on its current status, or 'Mood', which determines what it currently needs. It then finds the target and uses it. The moods are: Hungary In Heat Afraid Curious Out of Breath The code segment to determine the current status is: public int currentStatus() { if(oxygenStored() <= outOfBreathAt() || (previousStatus == OUT_OF_BREATH && oxygenStored() < lungCapacity())) return OUT_OF_BREATH; if(energy() < DEFAULT_HEALTH()*hungerFactor()) return HUNGRY; if(age() > matureAge() && age() < ageOfImpotence()) return IN_HEAT; return CURIOUS; } In other words, if the organism is currently out of breath, or was previously out of breath and hasn't recovered, then the status is OUT_OF_BREATH and it goes to air. If its current energy supply is less than the point it feels hunger, then the status is HUNGARY and it goes to Food. If the Organism is in a lifestage when it can reproduce, then the status is IN_HEAT and it finds a mate. Otherwise it is curious, and investigates Items that it has not encountered yet. I hope to implement the AFRAID status, but have yet to do so successfully. Whenever an Organism comes in contact with an object, it logs that object in a Set itemsEncountered. If it every is in need of something, say Food, and it cannot find a target in its current area, it will go to a Food item in its memory and choose that as its target. Organisms also log the last location that they were able to breath, in order to use if they are OUT_OF_BREATH underwater. This gives Organisms a basic memory, which I again hope to improve on.