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