comparison inference.pl @ 34:91e387b51aa0

added more rules checking
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sat, 11 Oct 2008 05:19:43 +0800
parents de5de6d472f9
children 65e847de5187
comparison
equal deleted inserted replaced
33:d183277b4d93 34:91e387b51aa0
8 our $cities; 8 our $cities;
9 our $server = 's2.ikariam.tw'; 9 our $server = 's2.ikariam.tw';
10 sub Warn 10 sub Warn
11 { 11 {
12 my ($city, $msg) = @_; 12 my ($city, $msg) = @_;
13 printf("WARNING: http://%s/index.php?view=city&id=%s (%s) %s \n", 13 printf("http://%s/index.php?view=city&id=%s (%s) %s \n",
14 $server, $city, $cities->{$city}->{name}, $msg); 14 $server, $city, $cities->{$city}->{name}, $msg);
15 } 15 }
16 16
17 our $i = new Ikariam($server, "chihchun", "c795d57d"); 17 our $i = new Ikariam($server, "chihchun", "c795d57d");
18 $i->login; 18 $i->login;
19 $cities = $i->check; 19 $cities = $i->check;
20 $i->logout; 20 $i->logout;
21 print(Dumper($cities));
22 21
23 sub rule_happiness 22 sub rule_happiness
24 { 23 {
25 my $id = shift; 24 my $id = shift;
26 25
33 { 32 {
34 my $id = shift; 33 my $id = shift;
35 34
36 # checking goods 35 # checking goods
37 foreach my $good (qw/wood wine marble crystal/) { 36 foreach my $good (qw/wood wine marble crystal/) {
38 if($cities->{$id}->{$good} <= 100) { 37 if($cities->{$id}->{resources}->{$good} <= 100) {
39 Warn($id, sprintf("Running out %s (%d)!", $good, $cities->{$id}->{$good})); 38 Warn($id, sprintf("Running out %s (%d)!", $good, $cities->{$id}->{resources}->{$good}));
40 } 39 }
41 } 40 }
42 } 41 }
43 42
44 sub rule_building 43 sub rule_building
48 # 城鎮跟圍牆 47 # 城鎮跟圍牆
49 if($cities->{$cityId}->{buildings}->{wall} < $cities->{$cityId}->{buildings}->{townHall}) { 48 if($cities->{$cityId}->{buildings}->{wall} < $cities->{$cityId}->{buildings}->{townHall}) {
50 Warn($cityId, sprintf("Wall level (%d) is lower then town hall (%d)!", 49 Warn($cityId, sprintf("Wall level (%d) is lower then town hall (%d)!",
51 $cities->{$cityId}->{buildings}->{wall}, 50 $cities->{$cityId}->{buildings}->{wall},
52 $cities->{$cityId}->{buildings}->{townHall} 51 $cities->{$cityId}->{buildings}->{townHall}
53 )); 52 ))
53 if($cities->{$cityId}->{construction} != 1);
54 } 54 }
55 } 55 }
56 56
57 sub rule_space 57 sub rule_space
58 { 58 {
59 my $cityId = shift; 59 my $cityId = shift;
60 60
61 if($cities->{$cityId}->{space}->{total} == $cities->{$cityId}->{space}->{occupied}) 61 if($cities->{$cityId}->{space}->{total} == $cities->{$cityId}->{space}->{occupied})
62 { 62 {
63 Warn($cityId, sprintf("your space is full, upgraded the hall")) if($cities->{$cityId}->{construction} != 1) 63 Warn($cityId, sprintf("your space is full, upgraded the hall"))
64 if($cities->{$cityId}->{construction} != 1);
65 }
66 return 0;
67 }
68
69 sub rule_war
70 {
71 my $cityId = shift;
72 if($cities->{$cityId}->{force}->{attacks} > 0)
73 {
74 Warn($cityId, sprintf("YOU ARE ATTACKED!!!!")) if($cities->{$cityId}->{construction} != 1)
64 } 75 }
65 } 76 }
66 77
67 sub rule_engagement 78 sub rule_engagement
68 { 79 {
80 my $cityId = shift;
81 if($cities->{$cityId}->{force}->{wars} == 0) {
82 Warn($cityId, sprintf("Let's Attack someone!"));
83 }
69 } 84 }
70 85
71 # 貪腐 86 # 貪腐
72 sub rule_corruption 87 sub rule_corruption
73 { 88 {
76 if($cities->{$id}->{corruption} > 0) { 91 if($cities->{$id}->{corruption} > 0) {
77 Warn($id, sprintf("corruption is %d", $cities->{$id}->{corruption})); 92 Warn($id, sprintf("corruption is %d", $cities->{$id}->{corruption}));
78 } 93 }
79 } 94 }
80 95
96 print Dumper($cities);
97 # show cities.
98 foreach my $cityId (keys(%$cities)) {
99 printf("%s http://s2.ikariam.tw/index.php?view=city&id=%d\n", $cities->{$cityId}->{name}, $cityId);
100 printf("construction: %s\n", $cities->{$cityId}->{construction});
101
102 foreach my $thing (qw/resources space force buildings citizens army fleet/) {
103 printf("%s\n", uc($thing));
104 foreach my $i (keys(%{$cities->{$cityId}->{$thing}})) {
105 printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i});
106 }
107 print("\n");
108 }
109 print("\n");
110 }
111
81 # space 112 # space
82 # Checking rules 113 # Checking rules
83 foreach my $procedure (qw/rule_happiness rule_corruption rule_building rule_space rule_resource/) { 114 foreach my $procedure (qw/rule_war rule_happiness rule_corruption rule_building rule_space rule_resource/) {
84 foreach my $id (keys(%$cities)) { 115 foreach my $id (keys(%$cities)) {
85 eval(sprintf("%s(%s);", $procedure, $id)); 116 eval(sprintf("%s(%s);", $procedure, $id));
86 } 117 }
87 } 118 }
119
120 foreach my $procedure (qw/rule_war rule_engagement/) {
121 foreach my $id (keys(%$cities)) {
122 eval(sprintf("%s(%s);", $procedure, $id));
123 last;
124 }
125 }