comparison agent.pl @ 86:a8acf50bf7bb

implemented a simple MilityExpenditure counting
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 26 Oct 2008 14:30:58 +0800
parents 2c6c219dc3ff
children 4c82cf844aa8
comparison
equal deleted inserted replaced
85:f25d13153501 86:a8acf50bf7bb
36 } 36 }
37 37
38 sub is_space_enough { 38 sub is_space_enough {
39 my ($self, $city) = @_; 39 my ($self, $city) = @_;
40 # TODO 應該以消耗率/時間計算 40 # TODO 應該以消耗率/時間計算
41 # $self->{ikariam}->{growth}
41 return ($city->{space}->{total} <= ($city->{space}->{occupied}+6) ? 0 : 1) 42 return ($city->{space}->{total} <= ($city->{space}->{occupied}+6) ? 0 : 1)
42 } 43 }
43 44
44 sub is_corruption { 45 sub is_corruption {
45 my ($self, $city) = @_; 46 my ($self, $city) = @_;
165 } 166 }
166 167
167 sub rule_resource 168 sub rule_resource
168 { 169 {
169 # TODO 170 # TODO
171 }
172
173 sub rule_milityExpenditure
174 {
175 my ($self, $cityId) = @_;
176 my $workersRatio = {
177 'citizens' => 0.4,
178 'specialworkers' => 0.3,
179 'woodworkers' => 0.7,
180 };
181
182 my $currentCost = $self->{'ikariam'}->getMilityExpenditure($cityId);
183 my $netincome = $self->{'ikariam'}->getNetIncome($cityId);
184
185 # 軍費為 兩成 淨收入
186 my $militaryExpenditure = int($netincome * 0.2);
187
188 if($currentCost < $militaryExpenditure) {
189 printf("Current mility expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure);
190 }
191
192 # TODO, 海軍
193
170 } 194 }
171 1; 195 1;
172 196
173 197
174 package main; 198 package main;
186 $decision->{parse_path} = []; 210 $decision->{parse_path} = [];
187 $decision->{parse_answer} = undef; 211 $decision->{parse_answer} = undef;
188 my $action = ParseTree($tree, $rules, $decision); 212 my $action = ParseTree($tree, $rules, $decision);
189 triggerAction($action, (keys(%$cities))[0]) if(defined($action)); 213 triggerAction($action, (keys(%$cities))[0]) if(defined($action));
190 print STDERR Dump($decision) if(defined($verbose)); 214 print STDERR Dump($decision) if(defined($verbose));
191
192 215
193 # show cities. 216 # show cities.
194 foreach my $cityId (keys(%$cities)) { 217 foreach my $cityId (keys(%$cities)) {
195 printf("%s http://%s/index.php?view=city&id=%d\n", 218 printf("%s http://%s/index.php?view=city&id=%d\n",
196 $cities->{$cityId}->{name}, $::server, $cityId); 219 $cities->{$cityId}->{name}, $::server, $cityId);
203 printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i}); 226 printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i});
204 } 227 }
205 print("\n"); 228 print("\n");
206 } 229 }
207 print("\n"); 230 print("\n");
231
232 # maybe this should be moved to Rules.
208 $i->blanceHurmanResource($cityId); 233 $i->blanceHurmanResource($cityId);
234 #
235 $rules->rule_milityExpenditure($cityId);
209 236
210 # build and upgrade for cities 237 # build and upgrade for cities
211 $tree = LoadFile('city.yaml'); 238 $tree = LoadFile('city.yaml');
212 $cities->{$cityId}->{parse_path} = []; 239 $cities->{$cityId}->{parse_path} = [];
213 $cities->{$cityId}->{parse_answer} = undef; 240 $cities->{$cityId}->{parse_answer} = undef;
214 while (my $action = ParseTree($tree, $rules, $cities->{$cityId})) 241 while (my $action = ParseTree($tree, $rules, $cities->{$cityId})) {
215 {
216 triggerAction($action, $cityId); 242 triggerAction($action, $cityId);
217 if($cities->{$cityId}->{parse_answer} ne "fallback") { 243 last;
218 last ;
219 } else {
220 # TODO: remove the last rule, if the result is fallback
221 }
222 } 244 }
223 # Debug 245 # Debug
224 # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose)); 246 # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose));
225 } 247 }
226 # print(Dump($cities)) if(defined($verbose)); 248 # print(Dump($cities)) if(defined($verbose));