Moving objects on a grid in C++
The first thing to do to clean up the code would be to make a

struct pos {
   int x;
   int y;
};


This will simplify the remaining of the code, making it easier to reason about the logic.

For example, right now it is possible to set the vehicle' velocity (direction) to {1,1}, which your problem statement doesn't allow.

You should then also define an equality comparison for your location. 

Your move function seems to have hard-coded the number of vehicles in play. Instead you should pass it a std::vector&lt;Vehicle&gt; by reference, and use size().

Once you fix these things, the logic of the move function is quite OK. It is quadratic in complexity, but that is OK for few cars. If you ever intend to increase the number of cars by orders of magnitude, there are two ways of improving the code:


Limit the world, and keep a grid where you mark if it is occupied or not.
Store the cars in a std::unordered_map, with their position as key. Then you can look up a position in constant time.




Edit: as suggested in the comment below, using namespace std should not be used. There are several really good reasons for not using it, and the only reason to use it is "I'm lazy". Look around other answers on Code Review for reasoning. This point comes up in about half of the C++ questions.