Mercurial > eagle-eye
annotate agent.pl @ 360:26f52b25aa06
disable building warehouse
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Mon, 23 Feb 2009 16:25:02 +0800 |
parents | b74e3a838b58 |
children | 3b2658751efa |
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) = @_; |
144
9fb18f3d6e26
added warning dialog for attacks
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
139
diff
changeset
|
23 |
267 | 24 return ($self->{'ikariam'}->{'military'}->{attack} > 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
|
25 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
26 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
27 sub is_constructing { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
28 my ($self, $city) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
29 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
|
30 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
31 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
32 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
|
33 my ($self, $city) = @_; |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
34 # 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
|
35 # Basic rule - the wall level must equale or large then townHall level. |
319
61dd017416cf
maxium level of wall is 24
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
318
diff
changeset
|
36 return ($city->{buildings}->{wall} >= 24 ? 1 : 0); |
317
2e0e47895148
changed a little bit for 0.0.3
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
311
diff
changeset
|
37 # return ($city->{buildings}->{wall} >= $city->{buildings}->{townHall} ? 1 : 0); |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
38 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
39 |
212
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
40 sub is_academy_enough { |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
41 my ($self, $city) = @_; |
304
cdbb428b464c
new rules for safehouse and academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
289
diff
changeset
|
42 return ($city->{buildings}->{academy} >= 12 ? 1 : 0); |
212
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
43 } |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
44 |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
45 sub is_embassy_enough { |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
46 my ($self, $city) = @_; |
323
3c6e78faa0d4
we don't need embassy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
322
diff
changeset
|
47 return 1; |
311
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
48 return ($city->{buildings}->{embassy} >= 1 ? 1 : 0); |
212
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
49 return ($city->{buildings}->{embassy} >= 6 ? 1 : 0); |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
50 } |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
51 |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
52 sub is_museum_enough { |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
53 my ($self, $city) = @_; |
320
ddfbb413d4dc
maxium level of museum is 8
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
319
diff
changeset
|
54 return 1 if($city->{buildings}->{museum} >= 8); |
308
f6f56a47f383
implemented is_tavern_enough
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
304
diff
changeset
|
55 } |
f6f56a47f383
implemented is_tavern_enough
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
304
diff
changeset
|
56 |
f6f56a47f383
implemented is_tavern_enough
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
304
diff
changeset
|
57 sub is_tavern_enough { |
f6f56a47f383
implemented is_tavern_enough
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
304
diff
changeset
|
58 my ($self, $city) = @_; |
f6f56a47f383
implemented is_tavern_enough
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
304
diff
changeset
|
59 return 0 if(!defined($city->{buildings}->{tavern})); |
318 | 60 return ($city->{buildings}->{tavern} >= 12 ? 1 : 0); |
212
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
61 } |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
62 |
237
a254fb798eb9
rules for branchOffice
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
236
diff
changeset
|
63 sub is_branchOffice_enough { |
a254fb798eb9
rules for branchOffice
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
236
diff
changeset
|
64 my ($self, $city) = @_; |
a254fb798eb9
rules for branchOffice
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
236
diff
changeset
|
65 return ($city->{buildings}->{branchOffice} >= 6 ? 1 : 0); |
a254fb798eb9
rules for branchOffice
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
236
diff
changeset
|
66 } |
a254fb798eb9
rules for branchOffice
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
236
diff
changeset
|
67 |
329
c29c8dad0673
added rules for build ports
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
323
diff
changeset
|
68 sub is_port_enough { |
c29c8dad0673
added rules for build ports
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
323
diff
changeset
|
69 my ($self, $city) = @_; |
c29c8dad0673
added rules for build ports
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
323
diff
changeset
|
70 return ($city->{buildings}->{port} >= 12 ? 1 : 0); |
c29c8dad0673
added rules for build ports
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
323
diff
changeset
|
71 } |
c29c8dad0673
added rules for build ports
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
323
diff
changeset
|
72 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
73 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
|
74 my ($self, $city) = @_; |
137
362184763c04
added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
93
diff
changeset
|
75 # The maximum town hall is level 20, then we build new town |
340
fe740b1c6f94
changed town and warehouse level for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
329
diff
changeset
|
76 return 1 if($city->{buildings}->{townHall} >= 15); |
137
362184763c04
added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
93
diff
changeset
|
77 # TODO 應該以 成長率 * 升級所需時間計算 |
362184763c04
added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
93
diff
changeset
|
78 # 6 hours earlier, we upgrade the twonHall. |
243
dc93eb48a926
we build both museum and tavern at same time.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
237
diff
changeset
|
79 return ($city->{space}->{total} <= ($city->{space}->{occupied} + ($city->{growth}*12)) ? 0 : 1) |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
80 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
81 |
206
b7af307a222d
added build safehouse
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
203
diff
changeset
|
82 sub is_safehouse_enough { |
b7af307a222d
added build safehouse
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
203
diff
changeset
|
83 my ($self, $city) = @_; |
317
2e0e47895148
changed a little bit for 0.0.3
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
311
diff
changeset
|
84 |
2e0e47895148
changed a little bit for 0.0.3
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
311
diff
changeset
|
85 return 1; |
2e0e47895148
changed a little bit for 0.0.3
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
311
diff
changeset
|
86 |
214 | 87 return 0 if(!defined($city->{buildings}->{safehouse})); |
304
cdbb428b464c
new rules for safehouse and academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
289
diff
changeset
|
88 return 1 if(($city->{buildings}->{townHall} - $city->{buildings}->{wall}) > 2); |
275 | 89 return 1 if($city->{buildings}->{townHall} >= 20); |
232
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
90 |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
91 # build the higgest safehouse. |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
92 # maybe we should have more then 4 towns, then we consider that we should upgrade safehouse at level 20. |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
93 # return (($city->{buildings}->{townHall} > $city->{buildings}->{safehouse}) ? 0 : 1) |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
94 # return (($city->{buildings}->{townHall} <= ($city->{buildings}->{safehouse} + 4)) ? 0 : 1); |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
95 |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
96 # Safehouse must be same level as townHall, |
269
c7f4a6f0fbde
added maxium level of buildings
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
267
diff
changeset
|
97 return (($city->{buildings}->{townHall} >= $city->{buildings}->{safehouse}) ? 0 : 1); |
206
b7af307a222d
added build safehouse
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
203
diff
changeset
|
98 } |
b7af307a222d
added build safehouse
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
203
diff
changeset
|
99 |
202
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
100 sub is_warehouse_enough { |
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
101 my ($self, $city) = @_; |
360
26f52b25aa06
disable building warehouse
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
347
diff
changeset
|
102 |
26f52b25aa06
disable building warehouse
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
347
diff
changeset
|
103 return 1; |
233
afd3f5cb8597
refined warehouse levels
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
104 # my @warehouse = (qw/undef undef 0 4 9 16 18 19 20 21 22 23 24 25/); |
278
b2510d9339d8
fixed warehouse level
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
275
diff
changeset
|
105 my @warehouse = (qw/undef undef 0 4 9 15 17 18 19 20 21 22 23 24/); |
202
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
106 my @cities = keys(%{$self->{ikariam}->{cities}}); |
203
60f4ce7e1f63
fixed warehouse level counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
202
diff
changeset
|
107 my $nextCities = ($#cities + 1) + 1; |
202
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
108 |
203
60f4ce7e1f63
fixed warehouse level counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
202
diff
changeset
|
109 Carp::carp(sprintf("Required warehouse level %s for next city (%s), current is %s\n", $warehouse[$nextCities], $nextCities, $city->{buildings}->{warehouse})); |
202
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
110 return 0 if(!defined($city->{buildings}->{warehouse})); |
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
111 return ($city->{buildings}->{warehouse} >= $warehouse[$nextCities]) ? 1 : 0; |
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
112 } |
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
113 |
2c2dcbcc5c4d
upgrade warehouse for next city
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
201
diff
changeset
|
114 |
192
d6dc50b64f06
rules to fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
183
diff
changeset
|
115 sub is_warehouse_enougn_for_governorsresidence { |
d6dc50b64f06
rules to fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
183
diff
changeset
|
116 my ($self, $city) = @_; |
340
fe740b1c6f94
changed town and warehouse level for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
329
diff
changeset
|
117 return (($city->{buildings}->{warehouse} >= 5) ? 0 : 1); |
fe740b1c6f94
changed town and warehouse level for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
329
diff
changeset
|
118 |
197
dbdd7dcc91c6
fixed for friendly troop and corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
193
diff
changeset
|
119 my @warehouse = (qw/undef undef 0 4 9 16 18 19 20 21 22 23 24 25/); |
193
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
120 my @cities = keys(%{$self->{ikariam}->{cities}}); |
203
60f4ce7e1f63
fixed warehouse level counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
202
diff
changeset
|
121 my $citiesNumber = $#cities + 1; |
192
d6dc50b64f06
rules to fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
183
diff
changeset
|
122 |
203
60f4ce7e1f63
fixed warehouse level counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
202
diff
changeset
|
123 Carp::carp(sprintf("Required warehouse level %s for %s cities, current is %s\n", $warehouse[$citiesNumber], $citiesNumber, $city->{buildings}->{warehouse})); |
199
b33c8dbe9b04
fixed is_any_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
198
diff
changeset
|
124 return 0 if(!defined($city->{buildings}->{warehouse})); |
203
60f4ce7e1f63
fixed warehouse level counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
202
diff
changeset
|
125 return ($city->{buildings}->{warehouse} >= $warehouse[$citiesNumber]) ? 1 : 0; |
192
d6dc50b64f06
rules to fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
183
diff
changeset
|
126 } |
d6dc50b64f06
rules to fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
183
diff
changeset
|
127 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
128 sub is_corruption { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
129 my ($self, $city) = @_; |
198
2dfeb4371db7
fixed train_navy counting and corruption counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
197
diff
changeset
|
130 return ($city->{corruption} > 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
|
131 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
132 |
193
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
133 sub is_any_corruption { |
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
134 my ($self, $city) = @_; |
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
135 |
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
136 foreach (keys(%{$self->{ikariam}->{cities}})) { |
199
b33c8dbe9b04
fixed is_any_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
198
diff
changeset
|
137 return 1 if ($self->{ikariam}->{cities}->{$_}->{corruption} > 0); |
193
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
138 } |
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
139 return 0; |
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
140 } |
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
141 |
59 | 142 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
|
143 my ($self, $city) = @_; |
137
362184763c04
added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
93
diff
changeset
|
144 |
139
3bbb1e559e21
we are happy when the city level is more then 20
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
137
diff
changeset
|
145 return ($city->{growth} >= 5 ? 1 : 0) |
262
1b435cd26a7b
change the factor of happiness
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
243
diff
changeset
|
146 if($city->{buildings}->{townHall} <= 10); |
1b435cd26a7b
change the factor of happiness
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
243
diff
changeset
|
147 |
1b435cd26a7b
change the factor of happiness
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
243
diff
changeset
|
148 return ($city->{growth} >= 2 ? 1 : 0) |
1b435cd26a7b
change the factor of happiness
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
243
diff
changeset
|
149 if($city->{buildings}->{townHall} <= 15); |
137
362184763c04
added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
93
diff
changeset
|
150 |
139
3bbb1e559e21
we are happy when the city level is more then 20
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
137
diff
changeset
|
151 return 1 if($city->{buildings}->{townHall} >= 20); |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
152 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
153 |
173
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
152
diff
changeset
|
154 |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
152
diff
changeset
|
155 sub is_bacchanal { |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
152
diff
changeset
|
156 my ($self, $city) = @_; |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
152
diff
changeset
|
157 return ($city->{tavern}->{maxValue} == $city->{tavern}->{iniValue} ? 1 : 0); |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
152
diff
changeset
|
158 } |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
152
diff
changeset
|
159 |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
160 sub is_gold_enoughforcargo { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
161 my ($self, $city) = @_; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
162 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
|
163 |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
164 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
|
165 return 1; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
166 } else { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
167 return 0; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
168 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
169 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
170 |
55
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
171 sub is_resource_enoghforHall { |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
172 my ($self, $city) = @_; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
173 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
|
174 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
|
175 |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
176 my $level = $city->{buildings}->{townHall}; |
56
6e0d5e781949
fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
55
diff
changeset
|
177 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
|
178 return 1; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
179 } |
56
6e0d5e781949
fixed a typo in agent.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
55
diff
changeset
|
180 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
|
181 return 0; |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
182 } |
ff00d108e955
check resources for build_townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
54
diff
changeset
|
183 |
57
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
184 sub is_expansion_researched { |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
185 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
|
186 # $self->{'ikariam'}-> |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
187 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
|
188 } |
9307c559f9bf
rule for research expansion
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
56
diff
changeset
|
189 |
212
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
190 sub is_foreigncultures_researched { |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
191 my ($self) = @_; |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
192 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
|
193 } |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
194 |
151 | 195 sub is_greekfire_researched { |
196 my ($self) = @_; | |
197 return (defined($self->{'ikariam'}->{research}->{1060}) ? 1 : 0); | |
198 } | |
199 | |
311
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
200 sub is_paddlewheelengine_researched { |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
201 my ($self) = @_; |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
202 return (defined($self->{'ikariam'}->{research}->{1100}) ? 1 : 0); |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
203 } |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
204 |
212
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
205 sub is_conservation_researched { |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
206 my ($self) = @_; |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
207 return (defined($self->{'ikariam'}->{research}->{2010}) ? 1 : 0); |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
208 } |
5f94d8d8370a
build embassy, museum, academy
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
208
diff
changeset
|
209 |
58
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
210 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
|
211 my ($self) = @_; |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
212 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
|
213 } |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
214 |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
215 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
|
216 my ($self) = @_; |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
217 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
|
218 } |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
219 |
59 | 220 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
|
221 my ($self) = @_; |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
222 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
|
223 } |
46e60bb040ad
list down the basic research.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
57
diff
changeset
|
224 |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
225 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
|
226 my ($self) = @_; |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
227 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
|
228 } |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
229 |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
230 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
|
231 my ($self) = @_; |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
232 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
|
233 } |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
234 |
152 | 235 sub is_culturalexchange_researched { |
236 my ($self) = @_; | |
237 return (defined($self->{'ikariam'}->{research}->{3060}) ? 1 : 0); | |
238 } | |
239 | |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
240 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
|
241 my ($self) = @_; |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
242 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
|
243 } |
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
244 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
245 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
|
246 my ($self) = @_; |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
247 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
|
248 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
249 |
311
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
250 sub is_robotics_researched { |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
251 my ($self) = @_; |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
252 return (defined($self->{'ikariam'}->{research}->{4110}) ? 1 : 0); |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
253 } |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
254 |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
255 |
67
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
256 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
|
257 my ($self, $city) = @_; |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
258 return 0 if(!defined($city->{buildings}->{barracks})); |
311
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
259 if($self->is_robotics_researched() eq 1) { |
321
d3bcdaa0180c
changed level of barrack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
320
diff
changeset
|
260 return ($city->{buildings}->{barracks} >= 24 ? 1 : 0); |
311
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
261 } |
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
262 |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
263 if($city->{buildings}->{townHall} >= 10) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
264 # optimum is 5 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
265 return ($city->{buildings}->{barracks} >= 5 ? 1 : 0); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
266 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
267 # 方陣兵需要 level 4 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
268 return ($city->{buildings}->{barracks} >= 4 ? 1 : 0); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
269 } |
67
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
270 } |
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
271 |
289
4c1eb583b97c
new function for checking shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
278
diff
changeset
|
272 sub is_shipyard_availble { |
4c1eb583b97c
new function for checking shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
278
diff
changeset
|
273 my ($self, $city) = @_; |
4c1eb583b97c
new function for checking shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
278
diff
changeset
|
274 return 0 if(!defined($city->{buildings}->{shipyard})); |
4c1eb583b97c
new function for checking shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
278
diff
changeset
|
275 return 1; |
4c1eb583b97c
new function for checking shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
278
diff
changeset
|
276 } |
4c1eb583b97c
new function for checking shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
278
diff
changeset
|
277 |
67
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
278 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
|
279 my ($self, $city) = @_; |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
72
diff
changeset
|
280 return 0 if(!defined($city->{buildings}->{shipyard})); |
311
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
281 if ($self->is_paddlewheelengine_researched() eq 1) { |
322
4cf62bfa4cbd
changed the level of shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
321
diff
changeset
|
282 return ($city->{buildings}->{shipyard} >= 16 ? 1 : 0); |
311
6aeedda23e3a
refined the level of barracks and shipyard
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
308
diff
changeset
|
283 } elsif ($self->is_greekfire_researched() eq 1) { |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
284 return ($city->{buildings}->{shipyard} >= 5 ? 1 : 0); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
285 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
286 return ($city->{buildings}->{shipyard} >= 3 ? 1 : 0); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
287 } |
67
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
288 } |
6eccb3a95df5
refiended the research of tech tree, and added many todos
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
59
diff
changeset
|
289 |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
290 sub is_shipyard_upgrading { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
291 my ($self, $city) = @_; |
193
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
292 return $self->{'ikariam'}->is_shipyard_upgrading($city->{id}); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
293 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
294 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
295 sub is_navy_trainning { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
296 my ($self, $city) = @_; |
193
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
297 return $self->{'ikariam'}->is_navy_trainning($city->{id}); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
298 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
299 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
300 sub train_navy { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
301 my ($self, $city) = @_; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
302 my $cityId = $city->{id}; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
303 # TODO, 依照升級比例算 CP 值最高 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
304 if($self->is_greekfire_researched() eq 1 && $city->{buildings}->{shipyard} >= 5) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
305 # ok, we can build Flamethrower. |
198
2dfeb4371db7
fixed train_navy counting and corruption counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
197
diff
changeset
|
306 if(defined($city->{'fleet'}->{Flamethrower}) && ($city->{'fleet'}->{Flamethrower} > 0) |
2dfeb4371db7
fixed train_navy counting and corruption counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
197
diff
changeset
|
307 && ($city->{'fleet'}->{BallistaShip} / $city->{'fleet'}->{Flamethrower}) <= (1.5/1)) { |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
308 return 213; # 強弩船 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
309 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
310 return 211; # 噴火船 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
311 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
312 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
313 return 213; # 強弩船 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
314 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
315 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
316 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
317 sub is_barracks_upgrading { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
318 my ($self, $city) = @_; |
197
dbdd7dcc91c6
fixed for friendly troop and corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
193
diff
changeset
|
319 return $self->{ikariam}->is_barracks_upgrading($city->{id}); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
320 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
321 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
322 sub is_army_trainning { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
323 my ($self, $city) = @_; |
193
a6a4a48d5fda
we don't bulid anything, untill we fix corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
192
diff
changeset
|
324 return $self->{ikariam}->is_army_trainning($city->{id}); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
325 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
326 sub train_army { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
327 my ($self, $city) = @_; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
328 my $cityId = $city->{id}; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
329 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
330 # TODO, 依照升級比例算 CP 值最高 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
331 my $assault = 'Swordsman'; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
332 my $resistance = 'Phalanx'; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
333 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
334 if(($city->{'army'}->{$assault} / $city->{'army'}->{$resistance}) <= (2/1)) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
335 return 302; # Swordsman |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
336 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
337 return 303; # Phalanx |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
338 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
339 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
340 |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
341 # navy |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
342 sub is_navyExpenditure_available |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
343 { |
197
dbdd7dcc91c6
fixed for friendly troop and corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
193
diff
changeset
|
344 my ($self, $city) = @_; |
dbdd7dcc91c6
fixed for friendly troop and corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
193
diff
changeset
|
345 my $cityId = $city->{id}; |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
346 |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
347 # move this to somewhere else. |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
348 my $workersRatio = { |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
349 'citizens' => 0.4, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
350 'specialworkers' => 0.3, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
351 'woodworkers' => 0.7, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
352 }; |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
353 |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
354 my $currentCost = $self->{'ikariam'}->getNavyExpenditure($cityId); |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
355 my $netincome = $self->{'ikariam'}->getNetIncome($cityId); |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
356 |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
357 # 軍費為 兩成 淨收入 |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
358 # 陸軍佔用 0.3 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
359 # 海軍佔用 0.7 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
360 my $militaryExpenditure = int($netincome * 0.2 * 0.7); |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
361 |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
362 if($currentCost < $militaryExpenditure) { |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
363 printf("Current navy expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
364 return 1; |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
365 } |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
366 return 0; |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
367 } |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
368 |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
369 # army |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
370 sub is_milityExpenditure_available |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
371 { |
197
dbdd7dcc91c6
fixed for friendly troop and corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
193
diff
changeset
|
372 my ($self, $city) = @_; |
dbdd7dcc91c6
fixed for friendly troop and corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
193
diff
changeset
|
373 my $cityId = $city->{id}; |
dbdd7dcc91c6
fixed for friendly troop and corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
193
diff
changeset
|
374 |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
375 # move this to somewhere else. |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
376 my $workersRatio = { |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
377 'citizens' => 0.4, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
378 'specialworkers' => 0.3, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
379 'woodworkers' => 0.7, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
380 }; |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
381 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
382 my $currentCost = $self->{'ikariam'}->getMilityExpenditure($cityId); |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
383 my $netincome = $self->{'ikariam'}->getNetIncome($cityId); |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
384 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
385 # 軍費為 兩成 淨收入 |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
386 # 陸軍佔用 0.3 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
387 # 海軍佔用 0.7 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
388 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
389 my $militaryExpenditure = int($netincome * 0.2 * 0.3); |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
390 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
391 if($currentCost < $militaryExpenditure) { |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
392 Carp::carp("Current army expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
393 return 1; |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
394 } |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
395 return 0; |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
396 } |
207
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
397 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
398 1; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
399 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
400 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
401 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
|
402 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
|
403 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
404 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
|
405 $i->login; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
406 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
|
407 |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
408 # 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
|
409 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
|
410 # 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
|
411 my $tree = LoadFile('overall.yaml'); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
412 my $decision; $decision->{parse_path} = []; $decision->{parse_answer} = undef; |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
413 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
|
414 triggerAction($action, (keys(%$cities))[0]) if(defined($action)); |
137
362184763c04
added comments and added new research (greek fire)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
93
diff
changeset
|
415 # 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
|
416 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
417 # show cities. |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
418 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
|
419 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
|
420 $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
|
421 printf("construction: %s\n", $cities->{$cityId}->{construction}); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
422 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 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
|
427 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
428 print("\n"); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
429 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
430 print("\n"); |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
431 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
432 # maybe this should be moved to Rules. |
84
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
82
diff
changeset
|
433 $i->blanceHurmanResource($cityId); |
207
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
434 |
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
435 # build spy |
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
436 $i->buildSpy('spy', $cityId); |
232
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
437 # enlarge the scientist number. |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
438 $i->set("academy", $cityId); |
269
c7f4a6f0fbde
added maxium level of buildings
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
267
diff
changeset
|
439 |
c7f4a6f0fbde
added maxium level of buildings
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
267
diff
changeset
|
440 # Only when you are not happy. |
319
61dd017416cf
maxium level of wall is 24
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
318
diff
changeset
|
441 # $i->set("tavern", $cityId); |
207
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
442 |
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
443 # build military! |
347
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
444 # $tree = LoadFile('military.yaml'); |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
445 # $cities->{$cityId}->{parse_path} = []; |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
446 # $cities->{$cityId}->{parse_answer} = undef; |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
447 # if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
448 # triggerAction($action, $cityId); |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
449 # } |
208
a2bb38589172
refined debug file name
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
207
diff
changeset
|
450 DumpFile("military-$cityId-dump.yaml", $cities->{$cityId}); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
451 |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
452 # 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
|
453 $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
|
454 $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
|
455 $cities->{$cityId}->{parse_answer} = undef; |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
456 if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { |
267 | 457 # printf("%s is suppressed\n", $action); |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
458 triggerAction($action, $cityId); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
459 } |
208
a2bb38589172
refined debug file name
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
207
diff
changeset
|
460 DumpFile("city-$cityId-dump.yaml", $cities->{$cityId}); |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
461 } |
150
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
144
diff
changeset
|
462 DumpFile("research-dump.yaml", $i->{'research'}); |
235 | 463 DumpFile("wars-dump.yaml", $i->{'military'}); |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
464 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
465 $i->logout; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
466 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
467 sub triggerAction { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
468 my ($action, $cityId) = @_; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
469 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
470 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
|
471 printf('$i->%s("%s", %s);'. "\n", $func, $param, $cityId); |
93
73f0a1cafc23
upgrade townHall first, then the wall.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
472 eval(sprintf('$i->%s("%s", %s);', $func, $param, $cityId)); |
73f0a1cafc23
upgrade townHall first, then the wall.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
473 warn $@ if $@; |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
474 } |