boruok it comes out as extremely disrespectful to expect someone to do your job while you don't even put in the effort to type more than one line of text, let alone code
.
if you were to try and convert this yourself, and have a problem with some part, then you could ask about that part and we would probably help.
or if you don't know anything about code, at least tell us WHAT the code is supposed to do, what you need it for, or something.
but this is a tedious work that requires expertise in many languages, which, granted, I have, and some others in the forum too. But the one thing no one wants to do is tedious, because it doesn't just take a long time to do, you don't get any gratification from doing it either.
I'll take a look at it anyway, but just a look.
this looks like the main function, it executes when running the script.
if __name__ == "__main__":
I started with python, but now I f***ng hate this stupid way of defining variables that python has, it's just so confusing.
NATTEMPTS = 100 #this is an INT
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #this is a STRING
nrows, ncols = 7, 7#2 INTs
wordlist = sorted(["uranus","venus","earth","mars","mercury","jupiter","neptune","saturn"], key=lambda w: len(w), reverse=True)#this is a mess. there's a list of string, it is then sorted using a lambda function. I don't care enough to decipher what it does. len(w) gives size of w. read the python docs.
in gdscript you only have arrays, you can sort arrays using the sorting methods or use a custom one. I won't explain.
https://docs.godotengine.org/en/stable/classes/class_array.html#class-array-method-sort
for i in range(NATTEMPTS):#same thing in gdscript
grid = make_wordsearch(nrows, ncols, wordlist)#this is a function
if grid:
print('fitted after {} attempt(s)'.format(i + 1))
show_grid_text(grid)#this is a function
break
first function. too long, there's probably some built in gdscript function that does the same. but what is this supposed to do?
def make_wordsearch(nrows, ncols, wordlist, allow_backwards_words=True):
grid = [['']*ncols for _ in range(nrows)]
def fill_empty_cells(grid):
for irow in range(nrows):
for icol in range(ncols):
if grid[irow][icol] == '':
grid[irow][icol] = random.choice(alphabet)
def is_word_fits(irow, icol, dx, dy, word):
for j in range(len(word)):
if grid[irow][icol] not in ('', word[j]):
return False
irow += dy
icol += dx
return True
def place_word(word):
dxdy_choices = [(0,1), (1,0), (1,1), (1,-1)] # Left, down, and the diagonals.
random.shuffle(dxdy_choices)
for (dx, dy) in dxdy_choices:
if allow_backwards_words and random.choice([True, False]):
word = word[::-1] # If backwards words are allowed, simply reverse word.
# Work out the minimum and maximum column and row indexes, given the word length.
n = len(word)
colmin = 0
colmax = ncols - n if dx else ncols - 1
rowmin = 0 if dy >= 0 else n - 1
rowmax = nrows - n if dy >= 0 else nrows - 1
if colmax - colmin < 0 or rowmax - rowmin < 0:
continue # No possible place for the word in this orientation.
# Build a list of candidate locations for the word.
candidates = []
for irow in range(rowmin, rowmax+1):
for icol in range(colmin, colmax+1):
if is_word_fits(irow, icol, dx, dy, word):
candidates.append((irow, icol))
# If we don't have any candidates, try the next orientation.
if not candidates:
continue
# Pick a random candidate location and place the word in this orientation.
loc = irow, icol = random.choice(candidates)
for j in range(n):
grid[irow][icol] = word[j]
irow += dy
icol += dx
break # We're done: no need to try any more orientations.
else:
return False # If we're here, it's because we tried all orientations but couldn't find anywhere to place the word. Oh dear.
return True
# Iterate over the word list and try to place each word (without spaces).
for word in wordlist:
word = word.replace(' ', '')
if not place_word(word):
return None # We failed to place word, so bail.
fill_empty_cells(grid)
return grid
no it can't and this isn't helpful. but it's kinda deserved for the amount of effort put into the post to get such response.