/// <summary> /// Returns a random position not in touch with another element /// </summary> /// <param name="pos"></param> /// <returns></returns> private ElementPosition randomPositionNotInTouchWith(ElementPosition pos) { ElementPosition outputPosition = new ElementPosition(); ushort randomPositionIndex = (ushort)(rnd.Next(1, Width * Height - neighborsCount(ref pos))); bool flag = false; ushort stepCounter = 0; for (byte i = 0; i < Height; i++) { outputPosition.Row = i; for (byte j = 0; j < Width; j++) { outputPosition.Col = j; if (!outputPosition.IsNextTo(pos)) { stepCounter++; if (stepCounter == randomPositionIndex) { flag = true; break; } } } if (flag) { break; } } return(outputPosition); }