Mercurial > eagle-eye
annotate agent.pl @ 79:9d92e8c12f58
rewrited the code in XPath.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 24 Oct 2008 21:46:33 +0800 |
parents | 27b16506231f |
children | 7ab5fc8c847c |
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}; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
7 use YAML qw/LoadFile Dump/; |
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 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
14 my ( $class ) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
15 my $self = {}; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
16 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
|
17 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
18 |
67
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
19 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
|
20 my ($self, $city) = @_; |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
21 # XXX |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
22 return ($city->{wars}->{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
|
23 } |
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 sub is_constructing { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
26 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
27 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
|
28 } |
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 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
|
31 my ($self, $city) = @_; |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
32 # http://ikariam.wikia.com/wiki/Wall_Defense |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
33 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
|
34 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
35 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
36 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
|
37 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
38 # TODO 應該以消耗率/時間計算 |
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
|
39 return ($city->{space}->{total} <= ($city->{space}->{occupied}+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
|
40 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
41 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
42 sub is_corruption { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
43 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
44 return 0; |
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 |
59 | 47 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
|
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 # TODO 以 fuzzy 取出合理 happiness 值 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
50 return ($city->{happiness} >= 2 ? 1 : 0) |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
51 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
52 |
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
|
53 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
|
54 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
55 # TODO 以速率計算容納率 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
56 return 1; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
57 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
58 |
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
|
59 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
|
60 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
61 # TODO 計算可搶劫比例, 城牆防護, 軍事分數 |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
62 # |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
63 # 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
|
64 # 計算軍人消耗 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
65 # |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
66 # 方陣兵, 1.58 軍分, 24 維護費 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
67 # 劍士, 4.64 軍分, 16 維護費 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
68 # 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
|
69 return 0; |
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 |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
72 sub is_gold_enoughforcargo { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
73 my ($self, $city) = @_; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
74 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
|
75 |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
76 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
|
77 return 1; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
78 } else { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
79 return 0; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
80 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
81 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
82 |
55
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
83 sub is_resource_enoghforHall { |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
84 my ($self, $city) = @_; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
85 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
|
86 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
|
87 |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
88 my $level = $city->{buildings}->{townHall}; |
56
6e0d5e781949
fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
55
diff
changeset
|
89 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
|
90 return 1; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
91 } |
56
6e0d5e781949
fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
55
diff
changeset
|
92 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
|
93 return 0; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
94 } |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
95 |
57
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
96 sub is_expansion_researched { |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
97 my ($self, $city) = @_; |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
98 return (defined($city->{research}->{1030}) ? 1 : 0); |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
99 } |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
100 |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
101 sub is_culturalexchange_researched { |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
102 my ($self, $city) = @_; |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
103 return (defined($city->{research}->{1040}) ? 1 : 0); |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
104 } |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
105 |
58
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
106 sub is_wealth_researched { |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
107 my ($self, $city) = @_; |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
108 return (defined($city->{research}->{2030}) ? 1 : 0); |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
109 } |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
110 |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
111 sub is_winepress_researched { |
58
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
112 my ($self, $city) = @_; |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
113 return (defined($city->{research}->{2040}) ? 1 : 0); |
58
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
114 } |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
115 |
59 | 116 sub is_paper_researched { |
58
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
117 my ($self, $city) = @_; |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
118 return (defined($city->{research}->{3020}) ? 1 : 0); |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
119 } |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
120 |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
121 sub is_espionage_researched { |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
122 my ($self, $city) = @_; |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
123 return (defined($city->{research}->{3030}) ? 1 : 0); |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
124 } |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
125 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
126 sub is_invention_researched { |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
127 my ($self, $city) = @_; |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
128 return (defined($city->{research}->{3040}) ? 1 : 0); |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
129 } |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
130 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
131 sub is_professionalarmy_researched { |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
132 my ($self, $city) = @_; |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
133 return (defined($city->{research}->{4030}) ? 1 : 0); |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
134 } |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
135 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
136 sub is_drydock_researched { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
137 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
138 return (defined($city->{research}->{4010}) ? 1 : 0); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
139 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
140 |
67
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
141 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
|
142 my ($self, $city) = @_; |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
143 return 0 if(!defined($city->{buildings}->{barracks})); |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
144 # 方陣兵需要 level 4 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
145 # optimum is 5 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
146 return ($city->{buildings}->{barracks} >= 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
|
147 } |
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
148 |
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
149 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
|
150 my ($self, $city) = @_; |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
151 return 0 if(!defined($city->{buildings}->{shipyard})); |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
152 # optimum is 5 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
153 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
|
154 return 0; |
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
155 } |
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
156 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
157 sub rule_engagement |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
158 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
159 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
160 # XXX |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
161 # 計算距離, 可搶劫比例, 是否有聯盟, 軍事分數 (win rate) |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
162 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
163 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
164 sub rule_resource |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
165 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
166 # XXX |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
167 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
168 1; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
169 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
170 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
171 package main; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
172 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
|
173 $i->login; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
174 my $cities = $i->check; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
175 my $rules = Ikariam::Cities::Rules->new; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
176 my $tree = LoadFile('building.yaml'); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
177 # print Dumper($tree); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
178 # show cities. |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
179 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
|
180 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
|
181 $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
|
182 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
|
183 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
184 # 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
190 print("\n"); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
191 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
192 print("\n"); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
193 # print(Dumper($cities)); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
194 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
195 # make decisions |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
196 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
197 # for the Decision Tree |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
198 $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
|
199 $cities->{$cityId}->{parse_answer} = undef; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
200 while (my $action = ParseTree($tree, $rules, $cities->{$cityId})) |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
201 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
202 # TODO: remove the last rule, if the result is fallback |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
203 triggerAction($action, $cityId); |
55
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
204 if($cities->{$cityId}->{parse_answer} ne "fallback") { |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
205 last ; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
206 } else { |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
207 |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
208 } |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
209 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
210 # Debug |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
211 print(Dumper($cities->{$cityId}->{parse_path})); |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
212 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
213 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
214 $i->logout; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
215 |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
216 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
217 sub triggerAction { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
218 my ($action, $cityId) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
219 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
220 my ($func, $param) = split(/_/,$action); |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
221 printf('$i->%s("%s", %s);'. "\n\n", $func, $param, $cityId); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
222 # eval(sprintf('$i->%s("%s", %s);', $func, $param, $cityId)); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
223 # warn $@ if $@; |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
224 } |