private static bool SearchSlower(Point start, Point goal, bool searchClosest, out PathResult result) { Frontier.Clear(); _nodes ??= new PathNode[World.Size, World.Size]; Array.Clear(_nodes, 0, _nodes.Length); Frontier.Enqueue(start, 0); _nodes[start.X, start.Y] = new PathNode(true, 0, start); int n = 0; var neighbors = new Point[4]; while (Frontier.TryDequeue(out Point current)) { if (searchClosest && current.L1(goal) == 1) { result = BuildResult(current); return(true); } if (current.Equals(goal)) { result = BuildResult(goal); return(true); } neighbors[0] = current.Left; neighbors[1] = current.Right; neighbors[2] = current.Up; neighbors[3] = current.Down; neighbors.Shuffle(); TryVisitPosition(current, neighbors[0], goal); TryVisitPosition(current, neighbors[1], goal); TryVisitPosition(current, neighbors[2], goal); TryVisitPosition(current, neighbors[3], goal); n += 4; if (n >= Limit) { result = BuildResult(current); return(true); } } result = null; return(false); }