I have a course object, which is an ArrayList that accepts Horse objects. I chose ArrayList because it is easy to implement. However, the disadvantage of using ArrayList is that I cannot easily track the positions of each horse without spending an expensive iteration through the collection. For example, if I want to find 2 horses that are within X distance of each other, I will have to go through n^2 times.
Is there a better strategy for this?
EDIT: A lot of requests for a specific model of my race, so I'll tell you here.
The model is updated at each iteration. Thus, each horse has its own speed, acceleration, distance, etc., And each iteration through the collection updates these values. There is a requirement that the horse be next to another, it will slow down, which I plan to do by comparing their "distance traveled".
source share