comparison agent.pl @ 137:362184763c04

added comments and added new research (greek fire)
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 02:21:05 +0800
parents 73f0a1cafc23
children 3bbb1e559e21
comparison
equal deleted inserted replaced
125:4374173bab47 137:362184763c04
35 return ($city->{buildings}->{wall} >= $city->{buildings}->{townHall} ? 1 : 0); 35 return ($city->{buildings}->{wall} >= $city->{buildings}->{townHall} ? 1 : 0);
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 # The maximum town hall is level 20, then we build new town
41 # $self->{ikariam}->{growth}
42 return 1 if($city->{buildings}->{townHall} >= 20); 41 return 1 if($city->{buildings}->{townHall} >= 20);
43 return ($city->{space}->{total} <= ($city->{space}->{occupied}+6) ? 0 : 1) 42 # TODO 應該以 成長率 * 升級所需時間計算
43 # 6 hours earlier, we upgrade the twonHall.
44 return ($city->{space}->{total} <= ($city->{space}->{occupied} + ($city->{growth}*6)) ? 0 : 1)
44 } 45 }
45 46
46 sub is_corruption { 47 sub is_corruption {
47 my ($self, $city) = @_; 48 my ($self, $city) = @_;
48 return 0; 49 return 0;
49 } 50 }
50 51
51 sub is_happiness { 52 sub is_happiness {
52 my ($self, $city) = @_; 53 my ($self, $city) = @_;
53 # TODO 以 fuzzy 取出合理 happiness 值 54 # TODO 以 fuzzy 取出合理 happiness 值
54 return ($city->{happiness} >= 2 ? 1 : 0) 55
56 # we should update the travl
57 # return ($city->{growth} >= 5 ? 1 : 0)
58 # if($city->{buildings}->{townHall} <= 10);
59
60 return 0;
61
62 # FIXME.
63 # we should update the tavern setting.
64 # return ($city->{happiness} >= 2 ? 1 : 0);
55 } 65 }
56 66
57 sub is_warehouse_enough { 67 sub is_warehouse_enough {
58 my ($self, $city) = @_; 68 my ($self, $city) = @_;
59 # TODO 以速率計算容納率 69 # TODO 以速率計算容納率
64 my ($self, $city) = @_; 74 my ($self, $city) = @_;
65 # TODO 計算可搶劫比例, 城牆防護, 軍事分數 75 # TODO 計算可搶劫比例, 城牆防護, 軍事分數
66 # 76 #
67 # my $capture = $city->{buildings}->{townHall} * ($city->{buildings}->{townHall} - 1) * $city->{resource}->gold / 10000; 77 # my $capture = $city->{buildings}->{townHall} * ($city->{buildings}->{townHall} - 1) * $city->{resource}->gold / 10000;
68 # 計算軍人消耗 78 # 計算軍人消耗
69 #
70 # 方陣兵, 1.58 軍分, 24 維護費 79 # 方陣兵, 1.58 軍分, 24 維護費
71 # 劍士, 4.64 軍分, 16 維護費 80 # 劍士, 4.64 軍分, 16 維護費
72 # army_score_main > (occupied * 0.3) 81 # army_score_main > (occupied * 0.3)
73 return 0; 82 return 0;
74 } 83 }
139 } 148 }
140 149
141 sub is_drydock_researched { 150 sub is_drydock_researched {
142 my ($self) = @_; 151 my ($self) = @_;
143 return (defined($self->{'ikariam'}->{research}->{4010}) ? 1 : 0); 152 return (defined($self->{'ikariam'}->{research}->{4010}) ? 1 : 0);
153 }
154
155 sub is_greekfire_researched {
156 my ($self) = @_;
157 return (defined($self->{'ikariam'}->{research}->{6077}) ? 1 : 0);
144 } 158 }
145 159
146 sub is_barracks_level_enough { 160 sub is_barracks_level_enough {
147 my ($self, $city) = @_; 161 my ($self, $city) = @_;
148 return 0 if(!defined($city->{buildings}->{barracks})); 162 return 0 if(!defined($city->{buildings}->{barracks}));
224 package main; 238 package main;
225 my $verbose = 1; 239 my $verbose = 1;
226 240
227 our $i = new Ikariam($::server, $::user, $::pass); 241 our $i = new Ikariam($::server, $::user, $::pass);
228 $i->login; 242 $i->login;
243 $i->checkMilitaryAdvisorCombatReports();
229 my $cities = $i->check; 244 my $cities = $i->check;
230 245
231 # Genereic rules for both overall and city level arranagement. 246 # Genereic rules for both overall and city level arranagement.
232 my $rules = Ikariam::Cities::Rules->new($i); 247 my $rules = Ikariam::Cities::Rules->new($i);
233 # blanace resources, arrange defance 248 # blanace resources, arrange defance
235 my $decision; 250 my $decision;
236 $decision->{parse_path} = []; 251 $decision->{parse_path} = [];
237 $decision->{parse_answer} = undef; 252 $decision->{parse_answer} = undef;
238 my $action = ParseTree($tree, $rules, $decision); 253 my $action = ParseTree($tree, $rules, $decision);
239 triggerAction($action, (keys(%$cities))[0]) if(defined($action)); 254 triggerAction($action, (keys(%$cities))[0]) if(defined($action));
240 print STDERR Dump($decision) if(defined($verbose)); 255 # print STDERR Dump($decision) if(defined($verbose));
241 256
242 # show cities. 257 # show cities.
243 foreach my $cityId (keys(%$cities)) { 258 foreach my $cityId (keys(%$cities)) {
244 printf("%s http://%s/index.php?view=city&id=%d\n", 259 printf("%s http://%s/index.php?view=city&id=%d\n",
245 $cities->{$cityId}->{name}, $::server, $cityId); 260 $cities->{$cityId}->{name}, $::server, $cityId);