Skip to content

Instantly share code, notes, and snippets.

@NoCtrlZ1110
Created October 3, 2020 04:21
Show Gist options
  • Save NoCtrlZ1110/c62f7b6f655e80738096eba2120ee9bf to your computer and use it in GitHub Desktop.
Save NoCtrlZ1110/c62f7b6f655e80738096eba2120ee9bf to your computer and use it in GitHub Desktop.
def findClosestPoint(location, goalArray):
closest = 0
closestCost = util.manhattanDistance( location, goalArray[0] )
for j in range(len(goalArray)):
cornerLocation = goalArray[j]
lengthToCorner = util.manhattanDistance( location, cornerLocation )
if lengthToCorner < closestCost:
closest = j
closestCost = lengthToCorner
return (closest, closestCost)
def findFarthestPoint(location, goalArray):
farthest = 0
farthestCost = util.manhattanDistance( location, goalArray[0] )
for j in range(len(goalArray)):
cornerLocation = goalArray[j]
lengthToCorner = util.manhattanDistance( location, cornerLocation )
if lengthToCorner > farthestCost:
farthest = j
farthestCost = lengthToCorner
return (farthest, farthestCost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment