Mercurial > eagle-eye
annotate agent.pl @ 57:9307c559f9bf
rule for research expansion
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Tue, 21 Oct 2008 00:13:52 +0800 |
parents | 6e0d5e781949 |
children | 46e60bb040ad |
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 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
19 sub is_Attacked { |
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) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
31 # TODO 應該以防禦力計算 |
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 應該以消耗率/時間計算 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
38 return ($city->{space}->{total} <= ($city->{space}->{occupied}+6) ? 1 : 0) |
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 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
46 sub is_happiness |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
47 { |
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 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
53 sub is_warehouse_enough |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
54 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
55 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
56 # TODO 以速率計算容納率 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
57 # XXX: not implemented yet. |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
58 return 1; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
59 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
60 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
61 sub is_risk |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
62 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
63 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
64 # TODO 計算可搶劫比例, 城牆防護, 軍事分數 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
65 return 0; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
66 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
67 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
68 sub is_shipyard |
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 return 1; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
71 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
72 |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
73 sub is_gold_enoughforcargo { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
74 my ($self, $city) = @_; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
75 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
|
76 |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
77 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
|
78 return 1; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
79 } else { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
80 return 0; |
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 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
83 |
55
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
84 sub is_resource_enoghforHall { |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
85 my ($self, $city) = @_; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
86 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
|
87 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
|
88 |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
89 my $level = $city->{buildings}->{townHall}; |
56
6e0d5e781949
fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
55
diff
changeset
|
90 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
|
91 return 1; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
92 } |
56
6e0d5e781949
fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
55
diff
changeset
|
93 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
|
94 return 0; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
95 } |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
96 |
57
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
97 sub is_expansion_researched { |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
98 my ($self, $city) = @_; |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
99 return (defined($city->{research}->{1030}) ? 1 : 0); |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
100 } |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
101 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
102 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
|
103 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
104 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
|
105 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
106 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
107 sub is_winepress_researched { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
108 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
109 return (defined($city->{research}->{2040}) ? 1 : 0); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
110 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
111 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
112 sub rule_engagement |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
113 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
114 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
115 # XXX |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
116 # 計算距離, 可搶劫比例, 是否有聯盟, 軍事分數 (win rate) |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
117 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
118 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
119 sub rule_resource |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
120 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
121 # XXX |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
122 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
123 1; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
124 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
125 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
126 package main; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
127 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
|
128 $i->login; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
129 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
|
130 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
131 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
|
132 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
|
133 # print Dumper($tree); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
134 # show cities. |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
135 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
|
136 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
|
137 $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
|
138 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
|
139 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
145 print("\n"); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
146 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
147 print("\n"); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
148 # print(Dumper($cities)); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
149 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
150 # make decisions |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
151 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
152 # 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
|
153 $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
|
154 $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
|
155 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
|
156 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
157 # 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
|
158 triggerAction($action, $cityId); |
55
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
159 if($cities->{$cityId}->{parse_answer} ne "fallback") { |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
160 last ; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
161 } else { |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
162 |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
163 } |
52
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 # Debug |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
166 print(Dumper($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
|
167 } |
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 $i->logout; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
170 |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
171 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
172 sub triggerAction { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
173 my ($action, $cityId) = @_; |
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 ($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
|
176 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
|
177 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
|
178 warn $@ if $@; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
179 } |