private string DrawMap() { var map = new string[MaxX, MaxY]; for (var x = 0; x < MaxX; x++) { for (var y = 0; y < MaxY; y++) { var count = Connectors.GetWiresCount(x, y); switch (count) { case 0: map[x, y] = "."; break; case 1: map[x, y] = "-"; break; case 2: map[x, y] = "x"; break; default: map[x, y] = "?"; break; } } } map[Central.X, Central.Y] = "o"; var sb = new StringBuilder(); for (var y = MaxY - 1; y >= 0; y--) { sb.AppendLine(); for (var x = 0; x < MaxX; x++) { sb.Append(map[x, y]); } } return(sb.ToString()); }
private void Connect(Wire wire) { var connector = Connectors.GetConnector(wire.X, wire.Y); if (connector.Wires.ContainsKey(wire)) { return; } connector.Wires[wire] = wire.Steps; if (connector.Wires.Count > 1) { if ((wire.X != Central.X) || (wire.Y != Central.Y)) { Console.WriteLine("Intersection"); var stepsToIntersection = 0; foreach (var tWire in connector.Wires.Keys) { stepsToIntersection += connector.Wires[tWire]; Console.WriteLine($"{tWire.Name} (steps: {connector.Wires[tWire]})"); System.Diagnostics.Debug.WriteLine($"{tWire.Name} (steps: {connector.Wires[tWire]})"); } SetMinimalStepsToIntersection(stepsToIntersection); var distance = ManhattanDistance(Central, wire.LastPoint); if (ClosestIntersectionDistance == 0 || ClosestIntersectionDistance > distance) { ClosestIntersectionDistance = distance; } foreach (var aWire in connector.Wires.Keys) { var steps = connector.Wires[aWire]; if (aWire.SetMinimumStepsToFirstConnector(steps)) { //aWire.ClosestPoint = aWire.LastPoint; aWire.ClosestPoint = new Point(wire.X, wire.Y); } } } } }