• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Word Puzzle algorithm : How to ?

Mert

Member
I have a list of words that I'd like to put on a grid. Players will need to find words inside of it.

An example:



How should I do it best ? Do you have any experience on this ?
 
P

ph101

Guest
Here's how I would do it.

-make a ds_grid
-make an array or list with required hidden words in
-have a loop where you pick a "word_hide_type"
eg.
type 1: horizontal forward
type 2: horizontal backward
type 3: diagonal forwards down
type 4: diagonal backwards down
etc.
-have a loop which runs the number of words you want
-pick a random number for word_hide_type
-use a switch statement for each type
-pick random x,y pos in grid to start
-within that case, find the number of letters for word number n, loop that number of times. check if there is space. Each word type will move the current position by x,y plus +1,0 (for example horizontal forward), +1,+1 for example diagonal forward down per loop. check if there is space for word (dont hit grid boundary, if not then use this position otherwise repeat until you find one (use do/until remembering to have a failsafe count so you cant have infinite loop)
-repeat past step adding the nth letter of the chosen word int the grid.
-repeat the larger loop per number of words needed to be hidden
-loop through whole grid using 2 nested for loops for x and y pos, check contents of grid and if empty add a random letter.
-Done!

There is sure to be a more efficient way than my random iteration of finding positions, but this is a quick and fairly simple way.
 
Top