annotate agent.pl @ 139:3bbb1e559e21

we are happy when the city level is more then 20
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 10:11:00 +0800
parents 362184763c04
children 9fb18f3d6e26
rev   line source
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
3 use strict;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Ikariam;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5 use Data::Dumper;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 use Decision::ParseTree q{ParseTree};
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
7 use YAML qw/LoadFile Dump DumpFile/;
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 package Ikariam::Cities::Rules;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10 use strict;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 use Data::Dumper;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 sub new {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
14 my ( $class, $i ) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
15 my $self = {
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
16 ikariam => $i,
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
17 };
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 return bless $self, $class;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20
67
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
21 sub is_attacked {
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 my ($self, $city) = @_;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
23 return ($self->{'ikariam'}->{'military'}->{attacks} > 0 ) ? 1 : 0;
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 sub is_constructing {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 return ($city->{construction} > 0 ) ? 1 : 0;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 sub is_wall_enough {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 my ($self, $city) = @_;
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
33 # http://ikariam.wikia.com/wiki/Wall_Defense
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
34 # Basic rule - the wall level must equale or large then townHall level.
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 return ($city->{buildings}->{wall} >= $city->{buildings}->{townHall} ? 1 : 0);
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 sub is_space_enough {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 my ($self, $city) = @_;
137
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
40 # The maximum town hall is level 20, then we build new town
89
86402d28544f stop upgrade townHall after the level is 20.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 87
diff changeset
41 return 1 if($city->{buildings}->{townHall} >= 20);
137
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
42 # TODO 應該以 成長率 * 升級所需時間計算
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
43 # 6 hours earlier, we upgrade the twonHall.
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
44 return ($city->{space}->{total} <= ($city->{space}->{occupied} + ($city->{growth}*6)) ? 0 : 1)
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 sub is_corruption {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 return 0;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
51
59
b40f87f16263 fixed a typo.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 58
diff changeset
52 sub is_happiness {
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
53 my ($self, $city) = @_;
139
3bbb1e559e21 we are happy when the city level is more then 20
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 137
diff changeset
54 # FIXME.
3bbb1e559e21 we are happy when the city level is more then 20
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 137
diff changeset
55 # we should update the tavern setting.
137
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
56
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
57 # we should update the travl
139
3bbb1e559e21 we are happy when the city level is more then 20
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 137
diff changeset
58 return ($city->{growth} >= 5 ? 1 : 0)
3bbb1e559e21 we are happy when the city level is more then 20
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 137
diff changeset
59 if($city->{buildings}->{townHall} <= 10);
137
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
60
139
3bbb1e559e21 we are happy when the city level is more then 20
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 137
diff changeset
61 return 1 if($city->{buildings}->{townHall} >= 20);
137
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
62
139
3bbb1e559e21 we are happy when the city level is more then 20
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 137
diff changeset
63 return ($city->{happiness} >= 2 ? 1 : 0);
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
64 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
65
72
2af91e80353e fixed a typo in is_space_enough, and fixed the rules format.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 67
diff changeset
66 sub is_warehouse_enough {
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
67 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
68 # TODO 以速率計算容納率
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
69 return 1;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
70 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
71
72
2af91e80353e fixed a typo in is_space_enough, and fixed the rules format.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 67
diff changeset
72 sub is_risk {
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
73 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
74 # TODO 計算可搶劫比例, 城牆防護, 軍事分數
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
75 #
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
76 # my $capture = $city->{buildings}->{townHall} * ($city->{buildings}->{townHall} - 1) * $city->{resource}->gold / 10000;
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
77 # 計算軍人消耗
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
78 # 方陣兵, 1.58 軍分, 24 維護費
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
79 # 劍士, 4.64 軍分, 16 維護費
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
80 # army_score_main > (occupied * 0.3)
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
81 return 0;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
82 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
83
54
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
84 sub is_gold_enoughforcargo {
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
85 my ($self, $city) = @_;
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
86 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/;
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
87
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
88 if($city->{resources}->{gold} >= ($cargoCost[$city->{transporters}->{sum}]*5)) {
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
89 return 1;
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
90 } else {
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
91 return 0;
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
92 }
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
93 }
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
94
55
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
95 sub is_resource_enoghforHall {
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
96 my ($self, $city) = @_;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
97 my @wood = qw/udnef 0 70 98 65 129 236 402 594 849 1176 1586 2101 3208 4937 7171 10139 14537 18420 22896 28047 33934 40623 48017 56511 226044 452088 904176 1808352 3616704 7233408 14466816 28933632/;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
98 my @marble = qw/undef 0 0 17 28 66 95 156 243 406 579 799 1348 2124 2951 4409 6461 8187 10176 12466 15082 18055 21381 25116 100464 200928 401856 803712 1607424 3214848 6429696 12859392/;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
99
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
100 my $level = $city->{buildings}->{townHall};
56
6e0d5e781949 fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 55
diff changeset
101 if($city->{resources}->{wood} >= $wood[$level] && $city->{resources}->{marble} >= $marble[$level] ) {
55
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
102 return 1;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
103 }
56
6e0d5e781949 fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 55
diff changeset
104 warn(sprintf("Resource is short for build city hall. wood [%d] marble [%d] ", $wood[$level], $marble[$level]));
55
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
105 return 0;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
106 }
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
107
57
9307c559f9bf rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 56
diff changeset
108 sub is_expansion_researched {
9307c559f9bf rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 56
diff changeset
109 my ($self, $city) = @_;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
110 # $self->{'ikariam'}->
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
111 return (defined($self->{'ikariam'}->{research}->{1030}) ? 1 : 0);
57
9307c559f9bf rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 56
diff changeset
112 }
9307c559f9bf rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 56
diff changeset
113
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
114 sub is_culturalexchange_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
115 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
116 return (defined($self->{'ikariam'}->{research}->{1040}) ? 1 : 0);
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
117 }
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
118
58
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
119 sub is_wealth_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
120 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
121 return (defined($self->{'ikariam'}->{research}->{2030}) ? 1 : 0);
58
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
122 }
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
123
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
124 sub is_winepress_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
125 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
126 return (defined($self->{'ikariam'}->{research}->{2040}) ? 1 : 0);
58
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
127 }
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
128
59
b40f87f16263 fixed a typo.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 58
diff changeset
129 sub is_paper_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
130 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
131 return (defined($self->{'ikariam'}->{research}->{3020}) ? 1 : 0);
58
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
132 }
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
133
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
134 sub is_espionage_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
135 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
136 return (defined($self->{'ikariam'}->{research}->{3030}) ? 1 : 0);
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
137 }
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
138
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
139 sub is_invention_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
140 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
141 return (defined($self->{'ikariam'}->{research}->{3040}) ? 1 : 0);
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
142 }
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
143
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
144 sub is_professionalarmy_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
145 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
146 return (defined($self->{'ikariam'}->{research}->{4030}) ? 1 : 0);
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
147 }
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
148
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
149 sub is_drydock_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
150 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
151 return (defined($self->{'ikariam'}->{research}->{4010}) ? 1 : 0);
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
152 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
153
137
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
154 sub is_greekfire_researched {
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
155 my ($self) = @_;
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
156 return (defined($self->{'ikariam'}->{research}->{6077}) ? 1 : 0);
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
157 }
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
158
67
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
159 sub is_barracks_level_enough {
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
160 my ($self, $city) = @_;
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
161 return 0 if(!defined($city->{buildings}->{barracks}));
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
162 # 方陣兵需要 level 4
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
163 # optimum is 5
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
164 return ($city->{buildings}->{barracks} >= 4 ? 1 : 0);
67
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
165 }
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
166
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
167 sub is_shipyard_level_enough {
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
168 my ($self, $city) = @_;
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
169 return 0 if(!defined($city->{buildings}->{shipyard}));
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
170 # optimum is 5
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
171 return ($city->{buildings}->{shipyard} >= 3 ? 1 : 0);
67
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
172 return 0;
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
173 }
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
174
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
175 sub rule_engagement
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
176 {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
177 my ($self, $city) = @_;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
178 # TODO
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
179 # 計算距離, 可搶劫比例, 是否有聯盟, 軍事分數 (win rate)
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
180 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
181
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
182 sub rule_resource
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
183 {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
184 # TODO
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
185 }
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
186
87
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
187 # navy
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
188 sub rule_navyExpenditure
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
189 {
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
190 my ($self, $cityId) = @_;
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
191 # move this to somewhere else.
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
192 my $workersRatio = {
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
193 'citizens' => 0.4,
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
194 'specialworkers' => 0.3,
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
195 'woodworkers' => 0.7,
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
196 };
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
197
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
198 my $currentCost = $self->{'ikariam'}->getNavyExpenditure($cityId);
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
199 my $netincome = $self->{'ikariam'}->getNetIncome($cityId);
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
200
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
201 # 軍費為 兩成 淨收入
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
202 # 陸軍佔用 0.8
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
203 # 海軍佔用 0.2
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
204 my $militaryExpenditure = int($netincome * 0.2 * 0.2);
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
205
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
206 if($currentCost < $militaryExpenditure) {
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
207 printf("Current navy expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure);
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
208 }
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
209 }
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
210
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
211 # army
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
212 sub rule_milityExpenditure
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
213 {
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
214 my ($self, $cityId) = @_;
87
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
215 # move this to somewhere else.
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
216 my $workersRatio = {
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
217 'citizens' => 0.4,
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
218 'specialworkers' => 0.3,
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
219 'woodworkers' => 0.7,
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
220 };
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
221
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
222 my $currentCost = $self->{'ikariam'}->getMilityExpenditure($cityId);
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
223 my $netincome = $self->{'ikariam'}->getNetIncome($cityId);
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
224
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
225 # 軍費為 兩成 淨收入
87
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
226 # 陸軍佔用 0.8
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
227 # 海軍佔用 0.2
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
228 my $militaryExpenditure = int($netincome * 0.2 * 0.8);
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
229
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
230 if($currentCost < $militaryExpenditure) {
87
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
231 printf("Current army expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure);
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
232 }
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
233 }
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
234 1;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
235
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
236
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
237 package main;
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
238 my $verbose = 1;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
239
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
240 our $i = new Ikariam($::server, $::user, $::pass);
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
241 $i->login;
137
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
242 $i->checkMilitaryAdvisorCombatReports();
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
243 my $cities = $i->check;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
244
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
245 # Genereic rules for both overall and city level arranagement.
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
246 my $rules = Ikariam::Cities::Rules->new($i);
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
247 # blanace resources, arrange defance
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
248 my $tree = LoadFile('overall.yaml');
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
249 my $decision;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
250 $decision->{parse_path} = [];
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
251 $decision->{parse_answer} = undef;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
252 my $action = ParseTree($tree, $rules, $decision);
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
253 triggerAction($action, (keys(%$cities))[0]) if(defined($action));
137
362184763c04 added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 93
diff changeset
254 # print STDERR Dump($decision) if(defined($verbose));
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
255
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
256 # show cities.
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
257 foreach my $cityId (keys(%$cities)) {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
258 printf("%s http://%s/index.php?view=city&id=%d\n",
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
259 $cities->{$cityId}->{name}, $::server, $cityId);
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
260 printf("construction: %s\n", $cities->{$cityId}->{construction});
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
261
79
9d92e8c12f58 rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 74
diff changeset
262 # foreach my $thing (qw/resources space wars buildings citizens army fleet/) {
9d92e8c12f58 rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 74
diff changeset
263 foreach my $thing (qw/resources space buildings citizens army fleet/) {
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
264 printf("<%s>\n", uc($thing));
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
265 foreach my $i (keys(%{$cities->{$cityId}->{$thing}})) {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
266 printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i});
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
267 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
268 print("\n");
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
269 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
270 print("\n");
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
271
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
272 # maybe this should be moved to Rules.
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
273 $i->blanceHurmanResource($cityId);
87
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
274 # milityExpenditure
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
275 $rules->rule_milityExpenditure($cityId);
87
4c82cf844aa8 counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 86
diff changeset
276 $rules->rule_navyExpenditure($cityId);
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
277
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
278 # build and upgrade for cities
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
279 $tree = LoadFile('city.yaml');
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
280 $cities->{$cityId}->{parse_path} = [];
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
281 $cities->{$cityId}->{parse_answer} = undef;
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
282 while (my $action = ParseTree($tree, $rules, $cities->{$cityId})) {
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
283 triggerAction($action, $cityId);
86
a8acf50bf7bb implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 84
diff changeset
284 last;
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
285 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
286 # Debug
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
287 # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose));
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
288 }
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
289 # print(Dump($cities)) if(defined($verbose));
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
290 DumpFile("dump.yaml", $cities);
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
291
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
292 $i->logout;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
293
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
294 sub triggerAction {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
295 my ($action, $cityId) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
296
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
297 my ($func, $param) = split(/_/,$action);
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
298 printf('$i->%s("%s", %s);'. "\n", $func, $param, $cityId);
93
73f0a1cafc23 upgrade townHall first, then the wall.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
299 eval(sprintf('$i->%s("%s", %s);', $func, $param, $cityId));
73f0a1cafc23 upgrade townHall first, then the wall.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
300 warn $@ if $@;
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
301 }