changeset 353:6c03c2c80429

fixed counting travel time
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 15 Feb 2009 14:20:25 +0800
parents 1105914c1b74
children 72df6f5bd05d
files enemy.pl
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/enemy.pl	Sun Feb 15 02:10:11 2009 +0800
+++ b/enemy.pl	Sun Feb 15 14:20:25 2009 +0800
@@ -13,8 +13,12 @@
 
 sub travelTime {
     my ($x1, $y1, $x2, $y2, $speed) = @_;
-    $speed = 20 unless(defined($speed));
-    return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed));
+    $speed = 60 unless(defined($speed));
+    if($x1 == $x2 && $y1 == $y2) {
+        return 600/$speed;
+    } else {
+        return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed));
+    }
 }
 
 sub travelMatrix {
@@ -68,7 +72,7 @@
         my @cities = ();
         foreach (glob("city-*-dump.yaml")) {
             my $city = LoadFile($_);
-            $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 20);
+            $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 60);
             push (@cities, $city);
         }
         @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities);
@@ -77,10 +81,10 @@
         for my $x (0..$n) {
             printf("%s (%d)\t- ", $cities[$x]->{name}, $cities[$x]->{id});
             printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", 
-                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y),
-                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 8),
-                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 6),
-                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 10),
+                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 60),
+                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 33),
+                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 26),
+                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 40),
                   );
         }
     }