Fascinating Word-Search Program

Introduction

The ubiquitous word-search puzzles that are printed in virtually every newspaper and on-line are mostly produced by computer programs. The example discussed in this document was interesting not because of its algorithm but how it shows the computer working out how to fit words into a grid.

This program comes from the site: Programming by Example, a website dedicated to teaching school children coding (see References at end of article). Examples use R.T. Russell's superb BBC BASIC for Windows. The WordSearch Creator program has been modified to work in RISC OS BASIC. Luckily only a few changes were needed.

Program Description

Program creates a 16 x 16 grid. It reads one word at a time from the file, placing it randomly within the grid in a random direction. Words may overlap if they share a common letter. The code ensures that words do not overlap the edge of the grid. When all of the words have been positioned random letters fill the remaining gaps. The completed grid is saved as a datafile named 'wordgrid' in the root directory of the hard-drive.

A word may appear in one of eight directions: horizontally, vertically or diagonally, including in reverse.

The search algorithm, is not the most efficient but remember it was designed as a student tutorial. The resulting animation neatly demonstrates the logic applied. Located words are highlighted for a couple of seconds before the next word is read.

Modifications

Installation

Create Word List

Create a word list (standard textfile - 20 words, maximum of 16 letters), name it WordList and save in the root directory of your hard-drive. Hyphens/spaces in words are ignored but probably best to avoid them. There is an example with this program.

Running The Program

Run WordSearch_Creator. Program will create a datafile called Wordgrid in the root directory. It is quite mesmerising to see how the program attempts to fit all the words into the grid. If you require the program to run at optimum speed then use a search utility to find the two delay statements starting with the keyword... TIME. REM these out and re-run program.

Wordsearch Solver

This is located in the Solver directory. It reads the file generated by the WordSearch Creator program to check that all words can be successfully found. This has also been modified to make it compatible with RISC OS BASIC. It would be nice if all words were highlighted before the program terminates but obviously additional code would be needed - any takers? Ideally programs would be better run in the desktop multi-tasking environment utilising AppBasic or DrWimp but would be quite a big task.

Printing the WordSearch

If you wish to print your creation then open the directory - Hardcopy.

Open the Wordgrid, datafile in the root directory of your hard drive. If you open this file (StrongED recommended) you will see it displays the grid in a rectangular format which if printed doesn't look anything like the familiar word search printed in so many puzzle publications. I have included another small program... Format which does 2 things...

Running the program can be done from a TaskObey file - one is provided called ~Format. Run the TaskObey which opens a window. The Wordgrid is still in a rectangular format but rest assured when printed changes to a square format. Do ensure when printing the document in StrongED that Text mode is selected not Graphics.

Reference

http://freeman69.moonfruit.com/intro/4583376831

Program Downloads

Word Search Programs

Back