I am making a wordsearch type game in which you have a grid and manipulate it in order to create words. I have most of the code working however currently it is only working for words that are the size of the grid. I need it to look for words up to the grid size. eg. if the grid is something like
‘|D|A|D|E|
|E|F|T|S|
|A|I|O|D|
|D|B|O|C|’
I need the code to find dad, fib and cob but also dead. with my current program it can only find dead.
score = 0
finding_THREE = ['FAB',"AGO", "AIM", "AND", "ARE", "ARM", "ART", "BAT", "BED", "BED", "BEE", 'BID', "BIG", "BOX",
"BOY", "BUD", "BUS", "BUT", "BUY", "CAB", "CAN", "CAR", "CAT", "COB", "CUP", "DAD",
"DAY", "DID", "DIG", "DIG", "DIM", "DOG", "DRY", "DUE", "EAR", "EGG", "EGG", "ELM",
"END", "EVE", "FAN", "FAR", "FAT"]
finding_FOUR = ["HOPE","LOVE","BEAR","TREE","TALL","WIND","RAIN","FIRE","DARK","JUMP",
"DUST","STAR","MOON","SOON","COLD","WARM","GOLD","BLUE","ROSE","SONG"]
word_arrays = {
3: finding_THREE,
4: finding_FOUR,
}
new = ''
found = ''
check = []
found_words = []
def check_left(grid_size, score):
global found_words
finding_a = word_arrays.get(grid_size, [])
check = []
for i in range(grid_size):
new = ''
for j in range(grid_size-1, -1, -1):
new = new + myarray[i][j]
check.append(new)
print(check)
for i in range(grid_size):
found = ''
if check[i] in finding_a and check[i] not in found_words:
found = check[i]
score = score + 1
found_words.append(found)
else:
None
return score
this is my current code, i also have functions for checking up down and right which follow a very similar pattern to the 'check left()'
New contributor