S
S
synapse_people2016-01-22 13:30:47
Java
synapse_people, 2016-01-22 13:30:47

How to take 2 elements from the queue with a minimum distance between them?

Hello!
There is a PriorityBlockingQueue, it has 40 objects of type Client (essentially a player). Each such object has its position in the world, which is set using Vector3D. To be more precise, then:

org.apache.commons.math3.geometry.euclidean.threed.Vector3D

It is necessary to pull out of the queue at once 2 players with the smallest distance between them.
Help me write the code:
public class TankDistanceComparator implements Comparator<Client> {

  @Override
  public int compare(Client o1, Client o2) {
/*Имплементация getPosition упущена за ненадобностью.*/
    Vector3D o1p = getPosition(o1);
    Vector3D o2p = getPosition(o2);

    double distance = o1p.distance(o2p);
/*Что тут нужно сделать?*/
    return 0;
  }
}

And how then to select 2 or more elements from the queue, for example 10 players?
How to implement, tell me, pliz .. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-01-22
@synapse_people

You need a Comparator, not a Comparator
Right off the bat, except for a complete enumeration of all pairs, I can’t think of it, but for 40 pairs it’s not so scary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question