chiark / gitweb /
Fix output formatting a little.
[rocl] / elite-tantalus
CommitLineData
74bdd262 1#! /usr/bin/tclsh
2#
3# $Id$
4
5package require "elite" "1.0.1"
6package require "vector" "1.0.0"
7package require "graph" "1.0.0"
8
9set gg {1 2 3 4 5 6 7 8}
9590c915 10set maxdist 100
74bdd262 11set minratio 10
12
13for {set i 0} {$i < [llength $argv]} {incr i} {
14 set a [lindex $argv $i]
15 switch -glob -- $a {
16 "-maxdist" {
17 incr i
18 set maxdist [expr {int([lindex $argv $i] * 10)}]
19 }
20 "-minratio" {
21 incr i
22 set minratio [lindex $argv $i]
23 }
24 "--" {
25 incr i
26 break
27 }
28 "-*" {
29 puts stderr "usage: $argv0 \[-maxdist DIST\] \[-minratio RATIO\] \[GALAXY\] ..."
30 exit 1
31 }
32 default {
33 break
34 }
35 }
36}
37
38if {[llength $argv] > $i} {
39 set gg [lrange $argv $i end]
40}
41
42foreach g $gg {
43 destructure {. gs} [parse-galaxy-spec $g]
44 set l [elite-galaxylist $gs]
45 set i 0
46 foreach {w x y} $l {
47 set index($w) $i
48 incr i
49 }
50 elite-adjacency a $l
51 set v [vector {256 256} -1]
52 foreach {w x y} $l {
53 set i $index($w)
54 foreach {ww xx yy} $a($w) {
55 set j $index($ww)
56 $v set $i $j [elite-distance $x $y $xx $yy]
57 }
58 $v set $i $i 0
59 }
60 destructure {lv pv} [graph-shortest-path $v]
61
62 elite-adjacency b $l $maxdist
63 foreach {w x y} $l {
64 set i $index($w)
65 foreach {ww xx yy} $b($w) {
66 set d [elite-distance $x $y $xx $yy]
67 if {$d <= 70 || [string compare $w $ww] > 0} { continue }
68 set j $index($ww)
69 set dd [$lv get $i $j]
70 set r [expr {$dd/"$d.0"}]
71 if {$r >= $minratio} {
9590c915 72 puts [format "%14s %-8s -> %-8s %5.1f %5.1f (%5.1f)" \
73 $g [worldname $w] [worldname $ww] \
74 [expr {$d/10.0}] [expr {$dd/10.0}] $r]
74bdd262 75 }
76 }
77 }
78 $v destroy
79 $lv destroy
80 $pv destroy
81}
82