public int BinarySearchWithRadius(GeoPoint searchElement) { int low = 0; // 0 is always going to be the first element int high = list_from_the_database.Count - 1; // Find highest element int middle = (low + high + 1) / 2; // Find middle element int location = -1; // Return value -1 if not found do // Search for element { // if an element is found within the range of the players coordinates it returns that position // a check will be done after to check around the found position for more enemies if (WithinRanage(searchElement, list_from_the_database[middle].GeoPoint, 1f)) { return(middle); } // if element is found at middle if (searchElement.IsEqual(list_from_the_database[middle].GeoPoint)) { location = middle; // location is current middle } // middle element is too high else if (searchElement.CoordinateMagnitude() < list_from_the_database[middle].GeoPoint.CoordinateMagnitude()) { high = middle - 1; // eliminate lower half } else // middle element is too low { low = middle + 1; // eleminate lower half } middle = (low + high + 1) / 2; // recalculate the middle } while ((low <= high) && (location == -1)); return(location); // return location of search key }