Mercurial > eagle-eye
annotate inference.pl @ 30:de5de6d472f9
added space checking
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 10 Oct 2008 05:24:04 +0800 |
parents | dbec53e754e3 |
children | 91e387b51aa0 |
rev | line source |
---|---|
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1 #!/usr/bin/perl |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
2 use strict; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
3 use Ikariam; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
4 use Data::Dumper; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
5 |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
6 package main; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
7 |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
8 our $cities; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
9 our $server = 's2.ikariam.tw'; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
10 sub Warn |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
11 { |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
12 my ($city, $msg) = @_; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
13 printf("WARNING: http://%s/index.php?view=city&id=%s (%s) %s \n", |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
14 $server, $city, $cities->{$city}->{name}, $msg); |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
15 } |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
16 |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
17 our $i = new Ikariam($server, "chihchun", "c795d57d"); |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
18 $i->login; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
19 $cities = $i->check; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
20 $i->logout; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
21 print(Dumper($cities)); |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
22 |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
23 sub rule_happiness |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
24 { |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
25 my $id = shift; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
26 |
28
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
27 if($cities->{$id}->{happiness} >= 3) { |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
28 Warn($id, sprintf("is not happy (%s)!", $cities->{$id}->{happiness_text})); |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
29 } |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
30 } |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
31 |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
32 sub rule_resource |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
33 { |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
34 my $id = shift; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
35 |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
36 # checking goods |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
37 foreach my $good (qw/wood wine marble crystal/) { |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
38 if($cities->{$id}->{$good} <= 100) { |
28
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
39 Warn($id, sprintf("Running out %s (%d)!", $good, $cities->{$id}->{$good})); |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
40 } |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
41 } |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
42 } |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
43 |
29
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
44 sub rule_building |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
45 { |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
46 my $cityId = shift; |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
47 |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
48 # 城鎮跟圍牆 |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
49 if($cities->{$cityId}->{buildings}->{wall} < $cities->{$cityId}->{buildings}->{townHall}) { |
30
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
50 Warn($cityId, sprintf("Wall level (%d) is lower then town hall (%d)!", |
29
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
51 $cities->{$cityId}->{buildings}->{wall}, |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
52 $cities->{$cityId}->{buildings}->{townHall} |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
53 )); |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
54 } |
30
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
55 } |
29
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
56 |
30
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
57 sub rule_space |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
58 { |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
59 my $cityId = shift; |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
60 |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
61 if($cities->{$cityId}->{space}->{total} == $cities->{$cityId}->{space}->{occupied}) |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
62 { |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
63 Warn($cityId, sprintf("your space is full, upgraded the hall")) if($cities->{$cityId}->{construction} != 1) |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
64 } |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
65 } |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
66 |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
67 sub rule_engagement |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
68 { |
29
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
69 } |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
70 |
28
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
71 # 貪腐 |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
72 sub rule_corruption |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
73 { |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
74 my $id = shift; |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
75 |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
76 if($cities->{$id}->{corruption} > 0) { |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
77 Warn($id, sprintf("corruption is %d", $cities->{$id}->{corruption})); |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
78 } |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
79 } |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
80 |
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
81 # space |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
82 # Checking rules |
30
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
83 foreach my $procedure (qw/rule_happiness rule_corruption rule_building rule_space rule_resource/) { |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
84 foreach my $id (keys(%$cities)) { |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
85 eval(sprintf("%s(%s);", $procedure, $id)); |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
86 } |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
87 } |