private void CalculatePath(ref List <string> Path) { if (IsMazeValid()) { MyStack pathStack = new MyStack(); // 0 Represents the Starting Point pathStack.Push(0); bool isSearching = true; // TODO: Set From Form MazeCell Current = new MazeCell(); int[] Next = new int[2] { 1, 1 }; while (isSearching) { SetNextStep(Current, ref Next, ref pathStack); TakeNextStep(ref Current, Next, ref pathStack); UpdatePathCell(Current.Column, Current.Row); CheckFinished(ref isSearching, Current); } for (int i = pathStack.Length; i > 0; i--) { switch (pathStack.Pop()) { case -1: // Don't write that a decision was made break; case 0: // Starting Location - Not Technically a Move break; case 1: Path.Add("West"); break; case 2: Path.Add("South"); break; case 3: Path.Add("East"); break; case 4: Path.Add("North"); break; default: Path.Add("Error"); break; } } Path.Reverse(); } else { MessageBox.Show("The Maze isn't valid."); } }