View Javadoc
1   package org.woehlke.simulation.evolution.model;
2   
3   /**
4    * State of the Cell which monitors age and getting enough food.
5    * After an minimum age and at a minimum af eaten food,
6    * the cell becomes able to reproduce by cell division.
7    * If there is not enough food, the cell will not move and later it will die.
8    *
9    * Simulated Evolution.
10   * Artificial Life Simulation of Bacteria Motion depending on DNA.
11   *
12   * © 2006 - 2008 Thomas Woehlke.
13   * http://thomas-woehlke.de/p/simulated-evolution/
14   * @author Thomas Woehlke
15   * Date: 04.02.2006
16   * Time: 23:12:31
17   */
18  public class LifeCycle {
19  
20      /**
21       * Status of the LifeCycle is fat, age and hunger.
22       */
23      private int fat;
24  
25      /**
26       * Status of the LifeCycle is fat, age and hunger.
27       */
28      private int age;
29  
30      /**
31       * Status of the LifeCycle is fat, age and hunger.
32       */
33      private int hunger;
34  
35  
36      /**
37       * LifeCycle Threshold Parameter
38       */
39      private final static int MAX_FAT = 2000;
40  
41      /**
42       * LifeCycle Threshold Parameter
43       */
44      private final static int MAX_HUNGER = 1000;
45  
46      /**
47       * LifeCycle Threshold Parameter
48       */
49      private final static int FULL_AGE = 200;
50  
51      /**
52       * LifeCycle Threshold Parameter
53       */
54      private final static int FAT_MINIMUM_FOR_SEX = 800;
55  
56      /**
57       * LifeCycle Threshold Parameter
58       */
59      private final static int FAT_AT_BIRTH = 500;
60  
61      /**
62       * LifeCycle Threshold Parameter
63       */
64      private final static int FAT_PER_FOOD = 25;
65  
66      /**
67       * LifeCycle Threshold Parameter
68       */
69      private final static int OLD_AGE = 800;
70  
71      /** LifeCycle Threshold Parameter */
72      private final static int MAX_AGE = 1000;
73  
74      public LifeCycle() {
75          hunger = 0;
76          age = 0;
77          fat = FAT_AT_BIRTH;
78      }
79  
80      public LifeCycle(int fatAtBirth) {
81          hunger = 0;
82          age = 0;
83          fat = fatAtBirth;
84      }
85  
86      /**
87       * moving consumes food energy
88       * @return true, if cell has enough energy to move.
89       */
90      public boolean move() {
91          age++;
92          if (fat > 0) {
93              fat--;
94              return true;
95          } else {
96              hunger++;
97              return false;
98          }
99      }
100 
101     /**
102      * having sex by cell division changes age and fat.
103      */
104     public void haveSex() {
105         fat /= 2;
106         age = 0;
107     }
108 
109     /**
110      * @return has enough age and fat for having sex.
111      */
112     public boolean isPregnant() {
113         return (age >= FULL_AGE) && (fat >= FAT_MINIMUM_FOR_SEX);
114     }
115 
116     /**
117      * @return died by hunger. found and eaten too few food and so too few fat.
118      */
119     public boolean isDead() {
120         return (hunger >= MAX_HUNGER) || (age >= MAX_AGE);
121     }
122 
123     /**
124      * @param food eat the found food and add the energy to the cells fat.
125      */
126     public void eat(int food) {
127         if (fat + food* FAT_PER_FOOD <= MAX_FAT) {
128             fat += food* FAT_PER_FOOD;
129         }  else {
130             fat = MAX_FAT;
131         }
132     }
133 
134     public int getFat() {
135         return fat;
136     }
137 
138     public LifeCycleStatus getLifeCycleStatus(){
139         if(fat==0 && hunger>=0){
140             return LifeCycleStatus.HUNGRY;
141         }
142         if(age<FULL_AGE){
143             if(fat< FAT_MINIMUM_FOR_SEX){
144                 return LifeCycleStatus.YOUNG;
145             } else {
146                 return LifeCycleStatus.YOUNG_AND_FAT;
147             }
148         } else {
149             if (age<OLD_AGE) {
150                 return LifeCycleStatus.FULL_AGE;
151             } else {
152                 if (age < MAX_AGE) {
153                     return LifeCycleStatus.OLD;
154                 } else {
155                     return LifeCycleStatus.DEAD;
156                 }
157             }
158         }
159     }
160 }