Mercurial > eagle-eye
annotate agent.pl @ 375:0ec57ac68a4c
one more parameter for ship speed.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Tue, 14 Apr 2009 17:01:49 +0800 |
parents | 0522468991c1 |
children |
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; |
371
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
5 use Ikariam::CitiesRules; |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
6 use Data::Dumper; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
7 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
|
8 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
|
9 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
10 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
|
11 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
|
12 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
13 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
|
14 $i->login; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
15 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
|
16 |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
17 # Genereic rules for both overall and city level arranagement. |
371
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
18 my $rules = Ikariam::CitiesRules->new($i); |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
19 # 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
|
20 my $tree = LoadFile('overall.yaml'); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 # 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
|
25 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
26 # show cities. |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
27 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
|
28 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
|
29 $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
|
30 printf("construction: %s\n", $cities->{$cityId}->{construction}); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
31 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
32 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
|
33 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
|
34 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
|
35 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
|
36 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
37 print("\n"); |
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 print("\n"); |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
40 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
41 # 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
|
42 $i->blanceHurmanResource($cityId); |
207
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
43 |
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
44 # build spy |
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
45 $i->buildSpy('spy', $cityId); |
232
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
46 # enlarge the scientist number. |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
214
diff
changeset
|
47 $i->set("academy", $cityId); |
269
c7f4a6f0fbde
added maxium level of buildings
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
267
diff
changeset
|
48 |
c7f4a6f0fbde
added maxium level of buildings
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
267
diff
changeset
|
49 # 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
|
50 # $i->set("tavern", $cityId); |
207
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
51 |
48ea8222782a
automatic build spys
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
52 # build military! |
347
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
53 # $tree = LoadFile('military.yaml'); |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
54 # $cities->{$cityId}->{parse_path} = []; |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
55 # $cities->{$cityId}->{parse_answer} = undef; |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
56 # if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
57 # triggerAction($action, $cityId); |
b74e3a838b58
do not build military
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
344
diff
changeset
|
58 # } |
208
a2bb38589172
refined debug file name
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
207
diff
changeset
|
59 DumpFile("military-$cityId-dump.yaml", $cities->{$cityId}); |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
173
diff
changeset
|
60 |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
61 # build and upgrade for cities |
371
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
62 # $tree = LoadFile('city.yaml'); |
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
63 # $cities->{$cityId}->{parse_path} = []; |
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
64 # $cities->{$cityId}->{parse_answer} = undef; |
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
65 # if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { |
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
66 # # printf("%s is suppressed\n", $action); |
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
67 # triggerAction($action, $cityId); |
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
68 # } |
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
69 |
0522468991c1
added flash attacking script.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
363
diff
changeset
|
70 |
208
a2bb38589172
refined debug file name
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
207
diff
changeset
|
71 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
|
72 } |
150
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
144
diff
changeset
|
73 DumpFile("research-dump.yaml", $i->{'research'}); |
235 | 74 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
|
75 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
76 $i->logout; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
77 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
78 sub triggerAction { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
79 my ($action, $cityId) = @_; |
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 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
|
82 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
|
83 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
|
84 warn $@ if $@; |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
85 } |