private void LookForPath() { BaseNode bestLookingNode = null; Quip("Looking..."); // GEt the best looking node bestLookingNode = Memory .OrderBy(x => x.F()) .ThenBy(x => x.RandomValue) .FirstOrDefault(z => z.Status == Status.Open); if (bestLookingNode == null) { return; } Quip("This node looks promising: [" + bestLookingNode.Row + "," + bestLookingNode.Column + "]"); // CLOSE IT bestLookingNode.Status = Status.Closed; if (IsNodeAtEnd(bestLookingNode)) { _preferredPath = new List <BaseNode>(); Quip("Aha! I found me a path!"); var parent = bestLookingNode; while (parent != null) { _preferredPath.Add(parent); parent = parent.Parent; } havePath = true; return; } var neighbours = Memory .Where(x => bestLookingNode.CanWalkTo(x)).ToList(); foreach (var node in neighbours) { if (node.Owner != bestLookingNode.EnemyPlayerNumber()) { if (node.Status == Status.Open) { if (node.G > bestLookingNode.G + (node.Owner == PlayerNumber ? costToMoveToClaimedNode : costToMoveToUnclaimedNode)) { node.Parent = bestLookingNode; node.G = bestLookingNode.G + (node.Owner == PlayerNumber ? costToMoveToClaimedNode : costToMoveToUnclaimedNode);; node.H = (IsHorizontal ? Size - 1 - node.Column : Size - 1 - node.Row) * costPerNodeTillEnd; } } else if (node.Status == Status.Untested) { node.Status = Status.Open; node.Parent = bestLookingNode; node.G = bestLookingNode.G + (node.Owner == PlayerNumber ? costToMoveToClaimedNode : costToMoveToUnclaimedNode); node.H = (IsHorizontal ? Size - 1 - node.Column : Size - 1 - node.Row) * costPerNodeTillEnd; } } } LookForPath(); }