1

i want to create a Word Search game using Visual Basic? I've already started it by creating grids (10x10). However, I do not know how to properly insert the words that the user will search for.

Here's a look at what I did as well as the codes.10x10 grid

as you can I see, I created the grid using the Paint Event handler.

I have a text file containing all the words that the user will search. Using VB I open and read all the lines and put the words in an array (not seen in the picture).

I want the words to be inserted in the grid randomly. But I do not know how to?

Any help is much appreciated. Thank you!

Sonson
  • 11
  • 5

1 Answers1

1

The visual grid is a bit of a distraction at this stage. concentrate on getting a list of strings into an nxn two-dimensional string array. I would write a sub which, given a list of words and a dimension, returns a filled-in array (if possible).

A natural choice is a backtracking algorithm, which seeks to randomly place words into a partially filled array. For each new word, generate the collection of all valid locations and then randomly pick one of those locations. If there are no valid locations -- backtrack, removing the most recently placed word and placing it somewhere else. It might help to first sort the list of words to be placed in order of decreasing length, since it will be easier to place smaller words into a partially-filled in array than larger words. Placing the larger words when there are less constraints will thus lessen the amount of back-tracking needed.

When all of the words have been placed, fill in the rest of the array randomly.

John Coleman
  • 51,337
  • 7
  • 54
  • 119