From 9ce71de6e6e9bcff4b2b4916afe3c35a7a2c866f Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 8 Nov 2014 15:29:56 -0500 Subject: [PATCH] clean --- commands.go | 15 +++++++-------- system.go | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/commands.go b/commands.go index 39e0948..df03a52 100644 --- a/commands.go +++ b/commands.go @@ -40,7 +40,7 @@ var nearbyCommand = &Command{ } for _, neighbor := range neighbors { other := index[neighbor.id] - fmt.Fprintf(conn, "%s: %v\n", other.name, neighbor.distance) + fmt.Fprintf(conn, "%-4d %-20s %v\n", other.id, other.name, system.TravelTimeTo(other)) } }, } @@ -120,7 +120,7 @@ var scanCommand = &Command{ if id == system.id { continue } - delay := system.TimeTo(index[id]) + delay := system.LightTimeTo(index[id]) id2 := id After(delay, func() { scanSystem(id2, system.id) @@ -140,7 +140,7 @@ var broadcastCommand = &Command{ if id == system.id { continue } - delay := system.TimeTo(index[id]) + delay := system.LightTimeTo(index[id]) id2 := id After(delay, func() { deliverMessage(id2, system.id, msg) @@ -228,11 +228,11 @@ func move(conn *Connection, to *System) { start := conn.System() start.Leave(conn) - delay := start.TimeTo(to) - delay = time.Duration(int64(float64(delay/time.Nanosecond) * 1.25)) + delay := start.TravelTimeTo(to) + fmt.Fprintf(conn, "moving to %s. ETA: %v\n", to.name, delay) After(delay, func() { to.Arrive(conn) - fmt.Fprintf(conn, "You have arrived at the %s system.\n", to.name) + fmt.Fprintf(conn, "You have arrived at the %s system after a total travel time of %v.\n", to.name, delay) }) } @@ -289,8 +289,7 @@ var mkBombCommand = &Command{ func bomb(conn *Connection, to *System) { conn.bombs -= 1 - delay := conn.System().TimeTo(to) - delay = time.Duration(int64(float64(delay/time.Nanosecond) * 1.1)) + delay := conn.System().BombTimeTo(to) fmt.Fprintf(conn, "sending bomb to %s. ETA: %v\n", to.name, delay) After(delay, func() { to.Bombed(conn) diff --git a/system.go b/system.go index ae808e8..873dbde 100644 --- a/system.go +++ b/system.go @@ -70,10 +70,18 @@ func (s *System) DistanceTo(other *System) float64 { return dist3d(s.x, s.y, s.z, other.x, other.y, other.z) } -func (s *System) TimeTo(other *System) time.Duration { +func (s *System) LightTimeTo(other *System) time.Duration { return time.Duration(int64(s.DistanceTo(other) * 100000000)) } +func (s *System) BombTimeTo(other *System) time.Duration { + return time.Duration(int64(s.DistanceTo(other) * 110000000)) +} + +func (s *System) TravelTimeTo(other *System) time.Duration { + return time.Duration(int64(s.DistanceTo(other) * 125000000)) +} + func (s *System) Bombed(bomber *Connection) { s.EachConn(func(conn *Connection) { conn.Die() @@ -88,7 +96,7 @@ func (s *System) Bombed(bomber *Connection) { if id == s.id { continue } - delay := s.TimeTo(index[id]) + delay := s.BombTimeTo(index[id]) id2 := id After(delay, func() { bombNotice(id2, s.id) @@ -216,7 +224,7 @@ func (r *scanResults) write(w io.Writer) { func scanSystem(id int, reply int) { system := index[id] source := index[reply] - delay := system.TimeTo(source) + delay := system.LightTimeTo(source) log_info("scan hit %s from %s after traveling for %v", system.name, source.name, delay) system.EachConn(func(conn *Connection) { @@ -234,7 +242,7 @@ func scanSystem(id int, reply int) { func deliverReply(id int, echo int, results *scanResults) { system := index[id] source := index[echo] - delay := system.TimeTo(source) + delay := system.LightTimeTo(source) log_info("echo received at %s reflected from %s after traveling for %v", system.name, source.name, delay) system.EachConn(func(conn *Connection) { if results.negative() {