A fairly common thing people often forget is the following line:
srand(time(nullptr));
If you notice, the numbers being generated are exactly the same each time you launch the game-chances are that you haven't seeded the random number generator or you haven't provided a proper seed. It's recommended to always use a unix timestamp, as shown.
Tip
The use of this particular random function should be restricted to something that isn't related to security and cryptography. Using it in combination with the modulus operator can produce incredibly non-uniform results due to the introduced bias.
Another fairly common problem is the programmers' choice of the data container to hold their structures. Let's take the following for example:
using SnakeContainer = std::vector<SnakeSegment>;
This defines the type of our SnakeContainer
. If you've compiled the code we've written, you will notice that it runs fairly smoothly. Now consider this next line of code:
Using SnakeContainer = std::deque...