Mercurial > eagle-eye
diff agent.pl @ 187:fa34cdb6879a
merged.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 02 Nov 2008 21:19:07 +0800 |
parents | 2362c8c8909e |
children | d6dc50b64f06 |
line wrap: on
line diff
--- a/agent.pl Sun Nov 02 18:36:28 2008 +0800 +++ b/agent.pl Sun Nov 02 21:19:07 2008 +0800 @@ -77,18 +77,6 @@ return 1; } -sub is_risk { - my ($self, $city) = @_; - # TODO 計算可搶劫比例, 城牆防護, 軍事分數 - # - # my $capture = $city->{buildings}->{townHall} * ($city->{buildings}->{townHall} - 1) * $city->{resource}->gold / 10000; - # 計算軍人消耗 - # 方陣兵, 1.58 軍分, 24 維護費 - # 劍士, 4.64 軍分, 16 維護費 - # army_score_main > (occupied * 0.3) - return 0; -} - sub is_gold_enoughforcargo { my ($self, $city) = @_; my @cargoCost = qw/160 244 396 812 1240 1272 1832 1888 3848 3972 5204 5384 6868 7120 8864 9200 11268 11712 14108 14680 23320 24288 28664 29880 34956 36468 42348 44212 51024 53308 61236 64024 73096 76468 87020 91088 103224 116524 122072 137432 180060 202132 211964 237444 249108 278276 292076 306623 321963 338138 355198 373191 392171 412195 433320 455612 479135 503962 530166 557828 587031 617863 650420 684802 721113 759466 799981 842783 888005 935790 986286 1039654 1096062 1155689 1218724 1285369 1355837 1430353 1509159 1592508 1680670 1773932 1872597 1976989 2087448 2204338 2328045 2458976 2597567 2744276 2899594 3064040 3238163 3422550 3617820 3824635 4043693 4275738 4521561 4782000 5057946 5350345 5660202 5988585 6336630 6705540 7096598 7511164 7950683 8416694 8910828 9434823 9990523 10579889 11205006 11868090 12571498 13317734 14109462 14949514/; @@ -172,17 +160,23 @@ sub is_barracks_level_enough { my ($self, $city) = @_; return 0 if(!defined($city->{buildings}->{barracks})); - # 方陣兵需要 level 4 - # optimum is 5 - return ($city->{buildings}->{barracks} >= 4 ? 1 : 0); + if($city->{buildings}->{townHall} >= 10) { + # optimum is 5 + return ($city->{buildings}->{barracks} >= 5 ? 1 : 0); + } else { + # 方陣兵需要 level 4 + return ($city->{buildings}->{barracks} >= 4 ? 1 : 0); + } } sub is_shipyard_level_enough { my ($self, $city) = @_; return 0 if(!defined($city->{buildings}->{shipyard})); - # optimum is 5 - return ($city->{buildings}->{shipyard} >= 3 ? 1 : 0); - return 0; + if ($self->is_greekfire_researched() eq 1) { + return ($city->{buildings}->{shipyard} >= 5 ? 1 : 0); + } else { + return ($city->{buildings}->{shipyard} >= 3 ? 1 : 0); + } } sub rule_engagement @@ -197,10 +191,63 @@ # TODO } +sub is_shipyard_upgrading { + my ($self, $city) = @_; + return $::i->is_shipyard_upgrading($city->{id}); +} + +sub is_navy_trainning { + my ($self, $city) = @_; + return $::i->is_navy_trainning($city->{id}); +} + +sub train_navy { + my ($self, $city) = @_; + my $cityId = $city->{id}; + # TODO, 依照升級比例算 CP 值最高 + if($self->is_greekfire_researched() eq 1 && $city->{buildings}->{shipyard} >= 5) { + # ok, we can build Flamethrower. + if(($city->{'fleet'}->{BallistaShip} / $city->{'fleet'}->{Flamethrower}) <= (1.5/1)) { + return 213; # 強弩船 + } else { + return 211; # 噴火船 + } + } else { + return 213; # 強弩船 + } +} + +sub is_barracks_upgrading { + my ($self, $city) = @_; + return $::i->is_barracks_upgrading($city->{id}); +} + +sub is_army_trainning { + my ($self, $city) = @_; + return $::i->is_army_trainning($city->{id}); +} + +sub train_army { + my ($self, $city) = @_; + my $cityId = $city->{id}; + + # TODO, 依照升級比例算 CP 值最高 + my $assault = 'Swordsman'; + my $resistance = 'Phalanx'; + + # ok, we can build Flamethrower. + if(($city->{'army'}->{$assault} / $city->{'army'}->{$resistance}) <= (2/1)) { + return 302; # Swordsman + } else { + return 303; # Phalanx + } +} + # navy -sub rule_navyExpenditure +sub is_navyExpenditure_available { my ($self, $cityId) = @_; + # move this to somewhere else. my $workersRatio = { 'citizens' => 0.4, @@ -212,17 +259,19 @@ my $netincome = $self->{'ikariam'}->getNetIncome($cityId); # 軍費為 兩成 淨收入 - # 陸軍佔用 0.8 - # 海軍佔用 0.2 - my $militaryExpenditure = int($netincome * 0.2 * 0.2); + # 陸軍佔用 0.3 + # 海軍佔用 0.7 + my $militaryExpenditure = int($netincome * 0.2 * 0.7); if($currentCost < $militaryExpenditure) { printf("Current navy expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure); + return 1; } + return 0; } # army -sub rule_milityExpenditure +sub is_milityExpenditure_available { my ($self, $cityId) = @_; # move this to somewhere else. @@ -236,13 +285,16 @@ my $netincome = $self->{'ikariam'}->getNetIncome($cityId); # 軍費為 兩成 淨收入 - # 陸軍佔用 0.8 - # 海軍佔用 0.2 - my $militaryExpenditure = int($netincome * 0.2 * 0.8); + # 陸軍佔用 0.3 + # 海軍佔用 0.7 + + my $militaryExpenditure = int($netincome * 0.2 * 0.3); if($currentCost < $militaryExpenditure) { - printf("Current army expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure); + Carp::carp("Current army expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure); + return 1; } + return 0; } 1; @@ -258,9 +310,7 @@ my $rules = Ikariam::Cities::Rules->new($i); # blanace resources, arrange defance my $tree = LoadFile('overall.yaml'); -my $decision; -$decision->{parse_path} = []; -$decision->{parse_answer} = undef; +my $decision; $decision->{parse_path} = []; $decision->{parse_answer} = undef; my $action = ParseTree($tree, $rules, $decision); triggerAction($action, (keys(%$cities))[0]) if(defined($action)); # print STDERR Dump($decision) if(defined($verbose)); @@ -270,8 +320,7 @@ printf("%s http://%s/index.php?view=city&id=%d\n", $cities->{$cityId}->{name}, $::server, $cityId); printf("construction: %s\n", $cities->{$cityId}->{construction}); - - # foreach my $thing (qw/resources space wars buildings citizens army fleet/) { + foreach my $thing (qw/resources space buildings citizens army fleet/) { printf("<%s>\n", uc($thing)); foreach my $i (keys(%{$cities->{$cityId}->{$thing}})) { @@ -283,23 +332,25 @@ # maybe this should be moved to Rules. $i->blanceHurmanResource($cityId); - # milityExpenditure - $rules->rule_milityExpenditure($cityId); - $rules->rule_navyExpenditure($cityId); + + $tree = LoadFile('military.yaml'); + $cities->{$cityId}->{parse_path} = []; + $cities->{$cityId}->{parse_answer} = undef; + if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { + triggerAction($action, $cityId); + } + DumpFile("army-dump.yaml", $cities); + # build and upgrade for cities $tree = LoadFile('city.yaml'); $cities->{$cityId}->{parse_path} = []; $cities->{$cityId}->{parse_answer} = undef; - while (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { + if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { triggerAction($action, $cityId); - last; } - # Debug - # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose)); + DumpFile("cities-dump.yaml", $cities); } -# print(Dump($cities)) if(defined($verbose)); -DumpFile("cities-dump.yaml", $cities); DumpFile("research-dump.yaml", $i->{'research'}); DumpFile("military-dump.yaml", $i->{'military'});