Original Post
Ok heres the background. I have got a wordsearch grid represented as a multi dimensional array in the format Grid[Row][Column]. I have a list of words that i'd like to insert into the grid, in a mixed up fashion (i.e. some horizontal, some vertical and some diagonal). The current method i am using involved the following;(language isn't really important for this) If the above code executes ok then the position is logged and the word is entered into the position. The problem is that with some combination of words and random positions the gird will get stuck, because it keeps finding a position that the words won’t fit in. Currently I have implemented a timer which checks to see if it takes to long, if it does then it starts again. Basically there seems to me that there must be a more efficient way of doing this. Because as long as the number of words is not to high you can always fit the words in, even if its just putting them all horizontal or vertical. Any help on this would be good, particularly any math-like way. I hope I’ve made it clear but if not please ask what you don’t understand.
for each 'word' in 'wordlist' do
{
while(OK)
{
pick a random orientation //(hoz,vert, diagF(\) diagB(/)) pick a starting position for the insert base upon orientation and word lenght
grab whats already in that grid space
compare the two
if each letter in the
for each 'letter' in word do
{
if (grabbedword.letter != empty space)
{
if (grabbedword.letter != word.letter)
{
then OK = false;
}
}
}
}
}