# HG changeset patch # User "Rex Tsai " # Date 1225002658 -28800 # Node ID a8acf50bf7bba10f07025fe350b98f9eae90b0f6 # Parent f25d131535010615e7544c93ebba3925bb700344 implemented a simple MilityExpenditure counting diff -r f25d13153501 -r a8acf50bf7bb Ikariam.pm --- a/Ikariam.pm Sun Oct 26 12:26:43 2008 +0800 +++ b/Ikariam.pm Sun Oct 26 14:30:58 2008 +0800 @@ -692,6 +692,50 @@ return ($self->{cities}->{$cityId}->{citizens}->{total}*4 - $self->{cities}->{$cityId}->{citizens}->{scientists}*8 ); } +sub getMilityExpenditure { + my $self = shift; + my $cityId = shift; + my $cities = $self->{cities}; + my $troops = { + # p 需要人口 + # w 木頭 + # S 硫磺 + # b 製造時間 + # u 維持費用 + # m 最低軍營等級 + # o 最佳軍營等級 + # a 攻擊力 + # d 防守力 + # A + # D + # s 耐力 + # c 種類 + # v speed + # x 加成 Assault, Resistance + Slinger => {n=>"Slinger",p=>1,w=>40,b=>"12m",u=>8,m=>1,o=>4,a=>7,d=>6,A=>2,D=>2,s=>10,c=>"Human",v=>20}, + Swordsman => {n=>"Swordsman",p=>2,w=>47,S=>16,b=>"17m",u=>16,m=>3,o=>5,a=>18,d=>14,A=>4,D=>3,s=>12,c=>"Human",v=>20,x=>"Assault"}, + Phalanx => {n=>"Phalanx",p=>4,w=>104,S=>64,b=>"40m",u=>24,m=>4,o=>7,a=>24,d=>40,A=>6,D=>10,s=>14,c=>"Human",v=>20,x=>"Resistance"}, + Ram => {n=>"Ram",p=>8,w=>198,S=>128,b=>"42m",u=>52,m=>5,o=>8,a=>14,d=>18,A=>3,D=>4,s=>16,c=>"Machina",v=>20,x=>"Ram"}, + Archer => {n=>"Archer",p=>4,w=>172,S=>86,b=>"49m",u=>32,m=>7,o=>10,a=>40,d=>40,A=>10,D=>10,s=>12,c=>"Human",v=>20}, + Catapult => {n=>"Catapult",p=>10,w=>342,S=>232,b=>"49m",u=>72,m=>10,o=>14,a=>36,d=>28,A=>9,D=>7,s=>16,c=>"Machina",v=>20,x=>"Ram"}, + Gunsman => {n=>"Gunsman",i=>"marksman",p=>7,w=>355,S=>154,b=>"1h 23m",u=>58,m=>14,o=>18,a=>80,d=>64,A=>18,D=>14,s=>10,c=>"Human",v=>20}, + Mortar => {n=>"Mortar",p=>12,w=>1325,S=>938,b=>"1h 53m",u=>128,m=>19,o=>21,a=>64,d=>64,A=>15,D=>15,s=>16,c=>"Machina",v=>20,x=>"Ram"}, + SteamGiant => {n=>"SteamGiant",i=>"steamgiant",p=>6,w=>1150,S=>716,b=>"1h 45m",u=>68,m=>16,o=>20,a=>100,d=>140,A=>20,D=>30,s=>14,c=>"Machina",v=>20,x=>"Resistance"}, + Gyrocopter => {n=>"Gyrocopter",p=>8,w=>1250,S=>670,b=>"1h 2m",u=>97,m=>12,o=>16,a=>112,d=>112,A=>25,D=>25,s=>12,c=>"Machina",v=>20}, + Bombardier => {n=>"Bombardier",p=>24,w=>2270,S=>878,b=>"2h 10m",u=>228,m=>22,o=>24,a=>200,d=>165,A=>45,D=>35,s=>14,c=>"Machina",v=>20,x=>"Assault"}, + Doctor => {n=>"Doctor",i=>"medic",p=>6,w=>640,C=>361,b=>"1h 2m",u=>244,m=>11,o=>12,a=>4,d=>28,A=>0,D=>0,s=>14,c=>"Human",v=>20,x=>"Healer"}, + Cook => {n=>"Cook",p=>4,w=>520,W=>103,b=>"38m",u=>138,m=>8,o=>8,a=>6,d=>26,A=>0,D=>0,s=>16,c=>"Human",v=>20,x=>"Regeneration"} + }; + + my $cost = 0; + + foreach(keys(%{$cities->{$cityId}->{army}})) { + # printf("%s %d = %d\n", $_, $cities->{$cityId}->{army}->{$_}, $cities->{$cityId}->{army}->{$_} * $troops->{$_}->{u}); + $cost += $cities->{$cityId}->{army}->{$_} * $troops->{$_}->{u}; + } + return $cost; +} + sub blanceHurmanResource { my $self = shift; my $cityId = shift; @@ -713,7 +757,39 @@ my $freePeople = $self->{cities}->{$cityId}->{citizens}->{total} - ($produceworkers + $self->{cities}->{$cityId}->{scientists}); # XXX - Carp::carp(sprintf("suggested - produce: %s wood %s special %s\n", $produceworkers, int($freePeople*0.3), int($freePeople*0.7))); + # 需計算資源開挖上限, 依照島等級區分 + # 木頭 +# create_slider({ +# dir : 'ltr', +# id : "default", +# maxValue : 367, +# overcharge : 0, +# iniValue : 367, +# bg : "sliderbg", +# thumb : "sliderthumb", +# topConstraint: -10, +# bottomConstraint: 344, +# bg_value : "actualValue", +# bg_overcharge : "overcharge", +# textfield:"inputWorkers" +# }); + +# create_slider({ +# dir : 'ltr', +# id : "default", +# maxValue : 367, +# overcharge : 0, +# iniValue : 367, +# bg : "sliderbg", +# thumb : "sliderthumb", +# topConstraint: -10, +# bottomConstraint: 344, +# bg_value : "actualValue", +# bg_overcharge : "overcharge", +# textfield:"inputWorkers" +# }); + + Carp::carp(sprintf("Suggested HR palnning - produce: %s wood %s special %s\n", $produceworkers, int($freePeople*0.3), int($freePeople*0.7))); } sub logout diff -r f25d13153501 -r a8acf50bf7bb agent.pl --- a/agent.pl Sun Oct 26 12:26:43 2008 +0800 +++ b/agent.pl Sun Oct 26 14:30:58 2008 +0800 @@ -38,6 +38,7 @@ sub is_space_enough { my ($self, $city) = @_; # TODO 應該以消耗率/時間計算 + # $self->{ikariam}->{growth} return ($city->{space}->{total} <= ($city->{space}->{occupied}+6) ? 0 : 1) } @@ -168,6 +169,29 @@ { # TODO } + +sub rule_milityExpenditure +{ + my ($self, $cityId) = @_; + my $workersRatio = { + 'citizens' => 0.4, + 'specialworkers' => 0.3, + 'woodworkers' => 0.7, + }; + + my $currentCost = $self->{'ikariam'}->getMilityExpenditure($cityId); + my $netincome = $self->{'ikariam'}->getNetIncome($cityId); + + # 軍費為 兩成 淨收入 + my $militaryExpenditure = int($netincome * 0.2); + + if($currentCost < $militaryExpenditure) { + printf("Current mility expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure); + } + + # TODO, 海軍 + +} 1; @@ -189,7 +213,6 @@ triggerAction($action, (keys(%$cities))[0]) if(defined($action)); print STDERR Dump($decision) if(defined($verbose)); - # show cities. foreach my $cityId (keys(%$cities)) { printf("%s http://%s/index.php?view=city&id=%d\n", @@ -205,20 +228,19 @@ print("\n"); } print("\n"); + + # maybe this should be moved to Rules. $i->blanceHurmanResource($cityId); + # + $rules->rule_milityExpenditure($cityId); # 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})) - { + while (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { triggerAction($action, $cityId); - if($cities->{$cityId}->{parse_answer} ne "fallback") { - last ; - } else { - # TODO: remove the last rule, if the result is fallback - } + last; } # Debug # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose));