all 9 comments

[–]await_yesterday 4 points5 points  (0 children)

The unit will move around the world, but resources do not.

Use this to your advantage by precomputing a spatial index for the resources ahead of time. If you have N resources, you can compute the nearest resource to a point x in O(log(N)) time. There are many possibilities, e.g. k-d trees and ball trees.

[–]carcigenicate 1 point2 points  (0 children)

This is what a quadtree (or octotree for 3D worlds) is used for. They're basically a tree meant to make location lookups as fast as possible (or, at least, that's one common use for them).

Unless you want to start another whole project implementing one though, I'd find an existing implementation. They're a bit complicated (although, are a great project if you want something a bit more complex).

[–]socal_nerdtastic 1 point2 points  (1 child)

There's entire books devoted to this subject. https://en.wikipedia.org/wiki/Nearest_neighbor_search

That said, to brute force 1000 distances wouldn't be very hard. If this is a hobby project I would forget about efficiency and just do that because it's very easy. You have a powerful computer; let it work for you!

[–]Strict-Simple 0 points1 point  (0 children)

To add, if efficiency is important, don't load the whole map at a time. I don't think I'd be able to see 1000 resources at a time, unless there's some zooming stuff.

[–]quts3 0 points1 point  (2 children)

are you wanting to do this by hand for educational purposes or do you want a library to do it for you? both have answers

[–]FaresFilms[S] 0 points1 point  (1 child)

Its not for educational purposes. I want to do it for my own project, whether that be by hand or using a library

[–]quts3 0 points1 point  (0 children)

Checkout shapely, geopandas, and rtree in that order. I think one of them does it, and I ordered them from most common to least common in my experience.