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