// Return path public static List <Vector3> ComputePath(ReducedVisibility singleton, Vector2 start, Vector2 end) { Global.pathPlanned++; Stopwatch sw = Stopwatch.StartNew(); Vector2 dir = end - start; Vector3 pos = new Vector3(start.x, start.y, Global.obstacleZ); List <Vector3> path; // if you can reach it directly if (!Physics.BoxCast(pos, Agent.halfExtents, dir, Quaternion.identity, dir.magnitude)) { Vector3 vDest = new Vector3(end.x, end.y, Global.agentZ); pos.z = Global.agentZ; path = new List <Vector3>() { vDest, pos }; } else { var g = new Graph(singleton, start, end); path = g.AStarSearch(); } sw.Stop(); Global.total += sw.Elapsed; return(path); }
public override void PartTwo(IInput input, IOutput output) { var map = input.ParseFullMap(); var area2d = Area2d.Create(map.Keys); var graph = new Graph(map); var path = graph.AStarSearch( area2d.TopLeft, area2d.BottomRight, static (a, b) => PointHelpers.ManhattanDistance(a, b)); var totalCost = path.Skip(1) .Sum(point => map[point]); output.WriteProperty("Total Cost", totalCost); }