// Gets the best path by back-tracing from the reward to the starting position for each cell public LinkedList <Cell> GetBestPath() { if (currentCell != null) { Cell nextCell = currentCell; while (nextCell.GetRowIndex() != gridWorld.GetAgentStartingPosition()[0] || nextCell.GetColumnIndex() != gridWorld.GetAgentStartingPosition()[1]) { bestPath.AddFirst(nextCell); nextCell = nextCell.GetParent(); if (nextCell == null) { throw new Exception("Unable to find starting cell in best path"); } } // Add the starting cell bestPath.AddFirst(nextCell); return(bestPath); } else { return(null); } }