Mercurial > eagle-eye
comparison sheep.pl @ 324:7077be1a14d5
count travel time
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Wed, 11 Feb 2009 21:04:27 +0800 |
parents | efffa408eec5 |
children | 6296a9cd6878 |
comparison
equal
deleted
inserted
replaced
323:3c6e78faa0d4 | 324:7077be1a14d5 |
---|---|
38 AND user.army_score_main <= $army_score_main | 38 AND user.army_score_main <= $army_score_main |
39 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) | 39 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) |
40 } | 40 } |
41 ); | 41 ); |
42 | 42 |
43 sub travelTime { | |
44 my ($x1, $y1, $x2, $y2, $speed) = @_; | |
45 $speed = 20 unless(defined($speed)); | |
46 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed)); | |
47 } | |
48 | |
43 sub listSheeps | 49 sub listSheeps |
44 { | 50 { |
45 my @sheeps = @_; | 51 my @sheeps = @_; |
46 my %results; | 52 my %results; |
47 | 53 |
75 | 81 |
76 # 測試風險評估 | 82 # 測試風險評估 |
77 # $capture = $capture - ($sheep->army_score_main*100); | 83 # $capture = $capture - ($sheep->army_score_main*100); |
78 | 84 |
79 $line = sprintf("%d %s score %d army %d risk %d %s/%s,", | 85 $line = sprintf("%d %s score %d army %d risk %d %s/%s,", |
80 $capture, | 86 travelTime($::x, $::y, $island->x, $island->y), |
87 # $capture, | |
81 $c->status, $sheep->score, $sheep->army_score_main, $c->risk, $sheep->name, $sheep->ally); | 88 $c->status, $sheep->score, $sheep->army_score_main, $c->risk, $sheep->name, $sheep->ally); |
82 | 89 |
83 $line .= sprintf("\"%s\" %d [%d,%d] %s http://%s/index.php?view=island&id=%d&selectCity=%d\n", | 90 $line .= sprintf("\"%s\" %d [%d,%d] %s http://%s/index.php?view=island&id=%d&selectCity=%d\n", |
84 $c->cityname, $c->citylevel, | 91 $c->cityname, $c->citylevel, |
85 $island->x, $island->y, | 92 $island->x, $island->y, |
95 } | 102 } |
96 | 103 |
97 __MAIN__: | 104 __MAIN__: |
98 | 105 |
99 if($#ARGV != 1) { die("Usage: $0 x y\n"); } | 106 if($#ARGV != 1) { die("Usage: $0 x y\n"); } |
100 my ($x, $y) = @ARGV; | 107 our ($x, $y) = @ARGV; |
101 | 108 |
102 listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6))); | 109 listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
103 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); | 110 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
104 | 111 |