Yup. It's the most complicated part of coding the game.
Yeah it's very difficult. I tried to randomly generate my game but, quickly gave up. I don't have a good grasp on how to accomplish it yet haha. It's cool you managed to pull it off!