/// <summary> /// UnionPossible checks if it is possible to join the roots of two points /// with the disjointedSet. If it is possible, the method returns true, /// otherwise false. /// </summary> /// <param name="randomNumber">the first GridPoint</param> /// <param name="gridPoint">the second GridPoint</param> /// <returns>true if the union was possible, otherwise false</returns> private bool UnionPossible(GridPoint gridPoint, GridPoint newPoint) { int here = GetSquareId(gridPoint); int next = GetSquareId(newPoint); int hereRoot = 0; int nextRoot = 0; //find the root of here try { hereRoot = disjointSet.Find(here); } catch (Exception e) { MessageBox.Show(e.Message); } //find the root of next try { nextRoot = disjointSet.Find(next); } catch (Exception e) { MessageBox.Show(e.Message); } //If they are both top roots, return true if (hereRoot == 0 && nextRoot == 0) { return(true); } //if a value of 0 is returned, it is a top root. Use its square //value instead. if (hereRoot == 0) { hereRoot = here; } if (nextRoot == 0) { nextRoot = next; } //If they do not have the same root, return true if (hereRoot != nextRoot) { return(true); } return(false); }