How to Connect a raspberry Pi3 with nearest Raspberry Pi3 both associated with same ad-hoc network

I have setup ad-hoc network via Wi-Fi on Three Raspberry Pi3 and it is working fine. I call them Node1, Node2, and Node3. Node3 is mobile node(a moving node) which will connect to nearest Node. Now I want my mobile node to connect to nearest Node which is in the range of Wi-Fi signal and if both are in range then connect to Node which has the strong signal strength. I also need to get the node name when connecting to it. I'll be very thankful in advance.