diff 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
line wrap: on
line diff
--- a/inference.pl	Sat Oct 11 05:19:29 2008 +0800
+++ b/inference.pl	Sat Oct 11 05:19:43 2008 +0800
@@ -10,7 +10,7 @@
 sub Warn
 {
     my ($city, $msg) = @_;
-    printf("WARNING: http://%s/index.php?view=city&id=%s (%s) %s \n", 
+    printf("http://%s/index.php?view=city&id=%s (%s) %s \n", 
         $server, $city, $cities->{$city}->{name}, $msg);
 }
 
@@ -18,7 +18,6 @@
 $i->login;
 $cities = $i->check;
 $i->logout;
-print(Dumper($cities));
 
 sub rule_happiness
 {
@@ -35,8 +34,8 @@
 
     # checking goods
     foreach my $good (qw/wood wine marble crystal/) {
-        if($cities->{$id}->{$good} <= 100) {
-            Warn($id, sprintf("Running out %s (%d)!", $good, $cities->{$id}->{$good}));
+        if($cities->{$id}->{resources}->{$good} <= 100) {
+            Warn($id, sprintf("Running out %s (%d)!", $good, $cities->{$id}->{resources}->{$good}));
         }
     }
 }
@@ -50,7 +49,8 @@
         Warn($cityId, sprintf("Wall level (%d) is lower then town hall (%d)!",
                 $cities->{$cityId}->{buildings}->{wall},
                 $cities->{$cityId}->{buildings}->{townHall}
-            ));
+            )) 
+        if($cities->{$cityId}->{construction} != 1);
     }
 }
 
@@ -60,12 +60,27 @@
 
     if($cities->{$cityId}->{space}->{total} == $cities->{$cityId}->{space}->{occupied})
     {
-        Warn($cityId, sprintf("your space is full, upgraded the hall")) if($cities->{$cityId}->{construction} != 1)
+        Warn($cityId, sprintf("your space is full, upgraded the hall")) 
+        if($cities->{$cityId}->{construction} != 1);
+    }
+    return 0;
+}
+
+sub rule_war
+{
+    my $cityId = shift;
+    if($cities->{$cityId}->{force}->{attacks} > 0)
+    {
+        Warn($cityId, sprintf("YOU ARE ATTACKED!!!!")) if($cities->{$cityId}->{construction} != 1)
     }
 }
 
 sub rule_engagement
 {
+    my $cityId = shift;
+    if($cities->{$cityId}->{force}->{wars} == 0) {
+        Warn($cityId, sprintf("Let's Attack someone!"));
+    }
 }
 
 # 貪腐
@@ -78,10 +93,33 @@
     }
 }
 
+print Dumper($cities);
+# show cities.
+foreach my $cityId (keys(%$cities)) {
+    printf("%s http://s2.ikariam.tw/index.php?view=city&id=%d\n", $cities->{$cityId}->{name}, $cityId);
+    printf("construction: %s\n", $cities->{$cityId}->{construction});
+    
+    foreach my $thing (qw/resources space force buildings citizens army fleet/) {
+        printf("%s\n", uc($thing));
+        foreach my $i (keys(%{$cities->{$cityId}->{$thing}})) {
+            printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i});
+        }
+        print("\n");
+    }
+    print("\n");
+}
+
 # space
 # Checking rules
-foreach my $procedure (qw/rule_happiness rule_corruption rule_building rule_space rule_resource/) {
+foreach my $procedure (qw/rule_war rule_happiness rule_corruption rule_building rule_space rule_resource/) {
     foreach my $id (keys(%$cities)) {
         eval(sprintf("%s(%s);", $procedure, $id));
     }
 }
+
+foreach my $procedure (qw/rule_war rule_engagement/) {
+    foreach my $id (keys(%$cities)) {
+        eval(sprintf("%s(%s);", $procedure, $id));
+        last;
+    }
+}