Hello everyone! I am a first year student studying computer science and I am having a little trouble figuring out how to implement this part of a program.
I am writing a word search puzzle generator that takes in a list of words and dimensions (such as "cat", "animal", "fish", etc...) and then populates the board in random directions with the words on the list, such as up, down, left, right, diagonal up, diagonal left, etc.
One of the things I'm having trouble with is having words that are too long to fit in the random spot they are assigned to. For example, if I had a 5x5 and had the word 'bear' and wanted to fit it as such below and wanted the word to wrap around the board, how would I calculate the way to do so?
A x x x x
x R x x x
x x x x x
x x x B x
x x x x E
I can't think of a way to do it accurately without having a switch statement that repeats tons of code over and over. I've heard a good way to do it would be to mod the value to wrap it around, but I am not too sure how to do this correctly. >_<
Could anyone please give me some insight as to a useful algorithm I could use to do this properly? The rest of my program works just fine; just the wrapping is giving me headaches.
Mucho thanks. ^^