View Javadoc
1   package org.woehlke.simulation.evolution.model;
2   
3   /**
4    * (C) 2006 - 2008 Thomas Woehlke.
5    * http://thomas-woehlke.de/p/simulated-evolution/
6    * @author Thomas Woehlke
7    * Date: 04.02.2006
8    * Time: 23:12:31
9    */
10  public class LifeCycle {
11  
12      private int fat;
13      private int age;
14      private int hunger;
15      private final int MAX_FAT = 2000;
16      private final int MAX_HUNGER = 1000;
17      private final int FULL_AGE = 200;
18      private final int FAT_MINIMUM_FOR_SEX = 800;
19      private final int FAT_AT_BIRTH = 500;
20      private final int FAT_PER_FOOD = 25;
21      private final int OLD_AGE = 800;
22      private final int MAX_AGE = 1000;
23  
24      public LifeCycle() {
25          hunger = 0;
26          age = 0;
27          fat = FAT_AT_BIRTH;
28      }
29  
30      public LifeCycle(int fatAtBirth) {
31          hunger = 0;
32          age = 0;
33          fat = fatAtBirth;
34      }
35  
36      public boolean move() {
37          age++;
38          if (fat > 0) {
39              fat--;
40              return true;
41          } else {
42              hunger++;
43              return false;
44          }
45      }
46  
47      public void haveSex() {
48          fat /= 2;
49          age = 0;
50      }
51  
52      public boolean isPregnant() {
53          return (age >= FULL_AGE) && (fat >= FAT_MINIMUM_FOR_SEX);
54      }
55  
56      public boolean isDead() {
57          return (hunger >= MAX_HUNGER) || (age >= MAX_AGE);
58      }
59  
60      public void eat(int food) {
61          if (fat + food* FAT_PER_FOOD <= MAX_FAT) {
62              fat += food* FAT_PER_FOOD;
63          }  else {
64              fat = MAX_FAT;
65          }
66      }
67  
68      public int getFat() {
69          return fat;
70      }
71  
72      public LifeCycleStatus getLifeCycleStatus(){
73          if(fat==0 && hunger>=0){
74              return LifeCycleStatus.HUNGRY;
75          }
76          if(age<FULL_AGE){
77              if(fat< FAT_MINIMUM_FOR_SEX){
78                  return LifeCycleStatus.YOUNG;
79              } else {
80                  return LifeCycleStatus.YOUNG_AND_FAT;
81              }
82          } else {
83              if (age<OLD_AGE) {
84                  return LifeCycleStatus.FULL_AGE;
85              } else {
86                  if (age < MAX_AGE) {
87                      return LifeCycleStatus.OLD;
88                  } else {
89                      return LifeCycleStatus.DEAD;
90                  }
91              }
92          }
93      }
94  }