During the ship loop, we already track the average amount of resources. (Which we can move, actually, to the loop before that. It's cleaner.)
We can also track the average amount of ship instrument levels. There are 6 monsters levels and 6 instrument levels. As such, monsters will be equal to the average level of instruments, with a random chance of dipping below that, or going above that.
This way, if you encounter a monster, it will be close to your own level and will never be too hard or too easy.
(The same is true for AI ships, although there's a larger spread there, because there are peaceful ships.)
During the ship loop, we already track the average amount of resources. (Which we can move, actually, to the loop before that. It's cleaner.)
We can also track the average amount of ship instrument levels. There are 6 monsters levels and 6 instrument levels. As such, monsters will be equal to the average level of instruments, with a random chance of dipping below that, or going above that.
This way, if you encounter a monster, it will be close to your own level and will never be too hard or too easy.
(The same is true for AI ships, although there's a larger spread there, because there are peaceful ships.)