annotate agent.pl @ 84:2c6c219dc3ff

fixed the checkCity function, implemneted a human resources palnning function.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 26 Oct 2008 01:43:40 +0800
parents 82acbba33b97
children a8acf50bf7bb
rev   line source
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
3 use strict;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Ikariam;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5 use Data::Dumper;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 use Decision::ParseTree q{ParseTree};
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
7 use YAML qw/LoadFile Dump DumpFile/;
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 package Ikariam::Cities::Rules;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10 use strict;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 use Data::Dumper;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 sub new {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
14 my ( $class, $i ) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
15 my $self = {
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
16 ikariam => $i,
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
17 };
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 return bless $self, $class;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20
67
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
21 sub is_attacked {
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 my ($self, $city) = @_;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
23 return ($self->{'ikariam'}->{'military'}->{attacks} > 0 ) ? 1 : 0;
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 sub is_constructing {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 return ($city->{construction} > 0 ) ? 1 : 0;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 sub is_wall_enough {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 my ($self, $city) = @_;
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
33 # http://ikariam.wikia.com/wiki/Wall_Defense
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
34 # Basic rule - the wall level must equale or large then townHall level.
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 return ($city->{buildings}->{wall} >= $city->{buildings}->{townHall} ? 1 : 0);
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 sub is_space_enough {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
40 # 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
41 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
42 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 sub is_corruption {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 return 0;
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
59
b40f87f16263 fixed a typo.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 58
diff changeset
49 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
50 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
51 # TODO 以 fuzzy 取出合理 happiness 值
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
52 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
53 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
54
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
55 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
56 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
57 # TODO 以速率計算容納率
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
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
61 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
62 my ($self, $city) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
63 # TODO 計算可搶劫比例, 城牆防護, 軍事分數
74
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 # 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
66 # 計算軍人消耗
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
67 #
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
68 # 方陣兵, 1.58 軍分, 24 維護費
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
69 # 劍士, 4.64 軍分, 16 維護費
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
70 # 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
71 return 0;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
72 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
73
54
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
74 sub is_gold_enoughforcargo {
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
75 my ($self, $city) = @_;
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
76 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
77
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
78 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
79 return 1;
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
80 } else {
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
81 return 0;
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 }
2d3c394b7940 rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 52
diff changeset
84
55
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
85 sub is_resource_enoghforHall {
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
86 my ($self, $city) = @_;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
87 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
88 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
89
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
90 my $level = $city->{buildings}->{townHall};
56
6e0d5e781949 fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 55
diff changeset
91 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
92 return 1;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
93 }
56
6e0d5e781949 fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 55
diff changeset
94 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
95 return 0;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
96 }
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
97
57
9307c559f9bf rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 56
diff changeset
98 sub is_expansion_researched {
9307c559f9bf rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 56
diff changeset
99 my ($self, $city) = @_;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
100 # $self->{'ikariam'}->
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
101 return (defined($self->{'ikariam'}->{research}->{1030}) ? 1 : 0);
57
9307c559f9bf rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 56
diff changeset
102 }
9307c559f9bf rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 56
diff changeset
103
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
104 sub is_culturalexchange_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
105 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
106 return (defined($self->{'ikariam'}->{research}->{1040}) ? 1 : 0);
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
107 }
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
108
58
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
109 sub is_wealth_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
110 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
111 return (defined($self->{'ikariam'}->{research}->{2030}) ? 1 : 0);
58
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
112 }
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
113
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
114 sub is_winepress_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
115 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
116 return (defined($self->{'ikariam'}->{research}->{2040}) ? 1 : 0);
58
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
117 }
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
118
59
b40f87f16263 fixed a typo.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 58
diff changeset
119 sub is_paper_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
120 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
121 return (defined($self->{'ikariam'}->{research}->{3020}) ? 1 : 0);
58
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
122 }
46e60bb040ad list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 57
diff changeset
123
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
124 sub is_espionage_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
125 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
126 return (defined($self->{'ikariam'}->{research}->{3030}) ? 1 : 0);
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
127 }
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 sub is_invention_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
130 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
131 return (defined($self->{'ikariam'}->{research}->{3040}) ? 1 : 0);
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
132 }
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 sub is_professionalarmy_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
135 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
136 return (defined($self->{'ikariam'}->{research}->{4030}) ? 1 : 0);
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
137 }
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
138
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
139 sub is_drydock_researched {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
140 my ($self) = @_;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
141 return (defined($self->{'ikariam'}->{research}->{4010}) ? 1 : 0);
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
142 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
143
67
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
144 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
145 my ($self, $city) = @_;
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
146 return 0 if(!defined($city->{buildings}->{barracks}));
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
147 # 方陣兵需要 level 4
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
148 # optimum is 5
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
149 return ($city->{buildings}->{barracks} >= 4 ? 1 : 0);
67
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
150 }
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
151
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
152 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
153 my ($self, $city) = @_;
74
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
154 return 0 if(!defined($city->{buildings}->{shipyard}));
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
155 # optimum is 5
27b16506231f improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 72
diff changeset
156 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
157 return 0;
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
158 }
6eccb3a95df5 refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 59
diff changeset
159
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
160 sub rule_engagement
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 my ($self, $city) = @_;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
163 # TODO
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
164 # 計算距離, 可搶劫比例, 是否有聯盟, 軍事分數 (win rate)
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
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
167 sub rule_resource
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
168 {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
169 # TODO
52
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 1;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
172
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
173
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
174 package main;
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
175 my $verbose = 1;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
176
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
177 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
178 $i->login;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
179 my $cities = $i->check;
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
180
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
181 # Genereic rules for both overall and city level arranagement.
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
182 my $rules = Ikariam::Cities::Rules->new($i);
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
183 # blanace resources, arrange defance
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
184 my $tree = LoadFile('overall.yaml');
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
185 my $decision;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
186 $decision->{parse_path} = [];
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
187 $decision->{parse_answer} = undef;
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
188 my $action = ParseTree($tree, $rules, $decision);
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
189 triggerAction($action, (keys(%$cities))[0]) if(defined($action));
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
190 print STDERR Dump($decision) if(defined($verbose));
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
191
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
192
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
193 # show cities.
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
194 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
195 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
196 $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
197 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
198
79
9d92e8c12f58 rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 74
diff changeset
199 # 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
200 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
201 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
202 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
203 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
204 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
205 print("\n");
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
206 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
207 print("\n");
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
208 $i->blanceHurmanResource($cityId);
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
209
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
210 # build and upgrade for cities
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
211 $tree = LoadFile('city.yaml');
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
212 $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
213 $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
214 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
215 {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
216 triggerAction($action, $cityId);
55
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
217 if($cities->{$cityId}->{parse_answer} ne "fallback") {
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
218 last ;
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
219 } else {
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
220 # TODO: remove the last rule, if the result is fallback
55
ff00d108e955 check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 54
diff changeset
221 }
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
222 }
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
223 # Debug
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
224 # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose));
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
225 }
84
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
226 # print(Dump($cities)) if(defined($verbose));
2c6c219dc3ff fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 82
diff changeset
227 DumpFile("dump.yaml", $cities);
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
228
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
229 $i->logout;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
230
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
231 sub triggerAction {
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
232 my ($action, $cityId) = @_;
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
233
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
234 my ($func, $param) = split(/_/,$action);
81
d57920014cb4 split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 80
diff changeset
235 printf('$i->%s("%s", %s);'. "\n", $func, $param, $cityId);
79
9d92e8c12f58 rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 74
diff changeset
236 # 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
237 # warn $@ if $@;
52
d2ac1e198ce4 implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
238 }