public static void ApplyGravity(Moon moon1, Moon moon2) { int aX = GetAccelerationForCoordinate(moon1.Position.X, moon2.Position.X); int aY = GetAccelerationForCoordinate(moon1.Position.Y, moon2.Position.Y); int aZ = GetAccelerationForCoordinate(moon1.Position.Z, moon2.Position.Z); moon1.UpdateVelocity(new Tuple <int, int, int>(aX, aY, aZ)); moon2.UpdateVelocity(new Tuple <int, int, int>(-aX, -aY, -aZ)); }
public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return(false); } else { Moon m = (Moon)obj; return(Position.Equals(m.Position) && Velocity.Equals(m.Velocity)); } }
public static IList <Moon> ProcessMoonScanResults(string[] moonScanResults) { var result = new List <Moon>(); foreach (var moonScanResult in moonScanResults) { var matchResult = Regex.Match(moonScanResult, @"^\<x=(-?\d+),\s*y=(-?\d+),\s*z=(-?\d+)\>$"); if (!matchResult.Success) { throw new Exception($"Invalid moon scan format: {moonScanResult}"); } int x = int.Parse(matchResult.Groups[1].Value); int y = int.Parse(matchResult.Groups[2].Value); int z = int.Parse(matchResult.Groups[3].Value); var moon = new Moon(x, y, z); result.Add(moon); } return(result); }