private static int CalcDistance(Planet source, Planet destination) { double dx = source.X() - destination.X(); double dy = source.Y() - destination.Y(); double squared = dx * dx + dy * dy; double rooted = Math.Sqrt(squared); int result = (int) Math.Ceiling(rooted); distances[source.PlanetID(), destination.PlanetID()] = result; distances[destination.PlanetID(), source.PlanetID()] = result; return result; }
//# Generates a string representation of a planet. This is used to send data //# about the planets to the client programs. public static string SerializePlanet(Planet planet) { int owner = planet.Owner(); string message = "P " + string.Format("{0:R}", planet.X()) + " " + string.Format("{0:R}", planet.Y()) + " " + owner + " " + planet.NumShips() + " " + planet.GrowthRate(); return message.Replace(".0 ", " "); }