Nov-02-2018, 04:36 AM
(This post was last modified: Nov-02-2018, 05:56 AM by Gribouillis.)
Hi, new to this thread and programming itself. We've got a software project that asks us to make a game of Boggle/Twisted Word Search, which finds words in a given grid of letters, that has no restrictions, except that the next letter of the word should be adjacent to the previous one. I sort of got the gist but I ended up with a messy nested for loops. My problem is it takes too long to run and it is limited to only five-letter words. My question is how can I make it a recursive function that has a flexible limit, depending on the size of the grid. I've been stuck on this rut for a week now, I'm just really desperate at this point. Thank you! As far as I know, there are no restrictions on this project of ours.
def word_searcher(self,position = (0,0)): row, col = position words = [] curr_word = self.grid[row][col] curr_word_loc = [(row,col)] for a in self.adjacent_finder((row,col)): curr_word += self.return_letter(a) curr_word_loc.append(a) for b in self.adjacent_finder(a): if b not in curr_word_loc: curr_word += self.return_letter(b) if curr_word in dict_offlist: words.append(curr_word) curr_word_loc.append(b) for c in self.adjacent_finder(b): if c not in curr_word_loc: curr_word+=self.return_letter(c) if curr_word in dict_offlist: words.append(curr_word) for d in self.adjacent_finder(c): if d not in curr_word_loc: curr_word+=self.return_letter(d) if curr_word in dict_offlist: words.append(curr_word) for e in self.adjacent_finder(d): if d not in curr_word_loc: curr_word+=self.return_letter(e) if curr_word in dict_offlist: words.append(curr_word) curr_word = self.grid[row][col]+self.return_letter(a)+self.return_letter(b)+self.return_letter(c)+self.return_letter(d) curr_word_loc =[(row,col)] curr_word_loc.append(a) curr_word_loc.append(b) curr_word_loc.append(c) curr_word_loc.append(d) curr_word = self.grid[row][col]+self.return_letter(a)+self.return_letter(b)+self.return_letter(c) curr_word_loc =[(row,col)] curr_word_loc.append(a) curr_word_loc.append(b) curr_word_loc.append(c) curr_word = self.grid[row][col]+self.return_letter(a)+self.return_letter(b) curr_word_loc =[(row,col)] curr_word_loc.append(a) curr_word_loc.append(b) curr_word = self.grid[row][col]+self.return_letter(a) curr_word_loc =[(row,col)] curr_word_loc.append(a) curr_word = self.grid[row][col] curr_word_loc = [(row,col)] return wordsI screwed insertion of the code part lol