Classic Computer Magazine Archive ANTIC VOL. 5, NO. 11 / MARCH 1987

Word Searcher

Atari power finds the winners

By Kevin Peck

With Word Searcher, just type in the letter grid from a word-finding contest grid, give your Atari the list of words to be searched, and the computer will find them in a flash. This BASIC program works on all 8-bit Atari computers of any memory size, with disk or cassette.

A word search contest in my local newspaper inspired me to develop this program. Each week, a few of the names of the contest's 114 sponsors were hidden in a grid of letters. No clues were given about when any sponsor would appear, so it took a lot of trial and error to solve the puzzle. I decided that my Atari should do this dirty work for me.

Word search contests are fairly common newspaper promotions. So if you'd like your 8-bit Atari to put you ahead of the pack next time such a contest appears in your hometown paper, type in Listing 1, WORDFIND.BAS. Check it with TYPO II and SAVE a copy before you RUN it.

I have also provided two puzzles for you to try with the Word Searcher program. Listing 2, PUZZLE2.DAT, contains various Atari computer terms. Listing 3, PUZZLE3.DAT, has a variety of words. These listings are both included on the monthly disk.

Type in Listing 2 or 3 and check it with TYPO II. Then LIST it to disk or cassette. Type NEW to clear memory, LOAD Listing 1 and ENTER Listing 2 (or 3). This creates a ready-to-RUN program. When you are through with the first sample puzzle, repeat this process with the listing for the second sample puzzle. Be sure to save a copy of Listing 1 without any puzzles merged in, so you can use it with any puzzle you want.

You can use Word Searcher with any printed puzzles, or with ones that you create yourself. Deciding if the program can handle the puzzle is simple. A puzzle grid can be no larger than 24 x 24 letters. (This is actually imposed by the screen size of the Atari, not memory space.) The word list can be any size.


The first DATA statement of your Puzzle Program must contain the width and height of the puzzle. In the first sample puzzle, the first DATA statement reads DATA 24,24. The second sample puzzle is eight letters wide and 10 letters tall, so the first DATA statement reads DATA 8,10. The next DATA statements contain the puzzle grid itself. Each statement must have the same number of letters as the width of the puzzle. And the total number of DATA statements must equal the height of the puzzle. Otherwise an error will be generated.

The following DATA statement will tell the program how many words to search for. The DATA statements after this contain the words themselves.

Do not type spaces within words. For example, one of the search words in the first sample puzzle is really two words: DISK DRIVE. But in the DATA statements it appears as DISKDRIVE.

If there are fewer words in the DATA than you have allowed for in the word count, the program will still search for the given number of words and then tell you it has unexpectedly run out of words. This causes no problems, but you should try to avoid it. If you have more words in the DATA than you tell the program, it just won't search for unaccounted-for words.

When you RUN the program, your grid of letters appears on the left side of the screen in a blue box. The right side has the command area. The top box displays the number of words found and missed so far. The next box contains the word being searched for. The third box is the message box, which says when a word is found, not found, too long for the puzzle, etc. The bottom box shows what keys to press when needed.

The cursor moves through the grid looking for the first word in the list, highlighting it in inverse video when found. You then can press either [START] to continue or [OPTION] to quit. You should now circle the word in the puzzle you're working on and then press [START] to continue with Word Searcher.

When the program finishes searching the entire word list, the back ground turns black and the word "Finished" appears in the command box.

If a word isn't found, either you've misspelled the word in the word list or a letter in the puzzle grid DATA is incorrect--or the puzzle you're using has a typo. The program will tell you it can't find a word and the screen will turn red. Exit by pressing [OPTION].


You might wonder how I got two colors on the screen in Graphics 0 and used them all over the screen. You've probably seen it done using display list interupts, but that only works for splitting the screen horizontally. The only way to split it horizontally in some places and vertically in others is to use Player/Missile graphics along with the normal screen display. I only needed three players to achieve the desired effect. And notice how the blue box surrounding the puzzle grid shrinks or expands to cover just the puzzle grid itself.

The smallest area a player needed to cover was an 8 x 8 pixelblock, the size of one Graphics 0 character. I used double resolution players set to quadruple width. When all bits are set on in a player's data stripe, it covers eight characters on the screen--equal to one character width per bit.

(For learning more about Player/Missile graphics, two helpful books would be Ian Chadwick's Mapping The Atari and Lon Poole's Your Atari Computer.--ANTIC ED)

The program scans the puzzle, one letter at a time, starting with the upper left corner. When it finds a letter in the puzzle which matches the first letter of the word being sought, it checks the surrounding letters in the puzzle for a complete match.

Let's look at how the loops within the program perform this task. The I loop starting at line 270 is the main outer loop. It READs a word from the list and makes sure the word isn't too long to fit in the puzzle. Over-long words are printed in the command box.

The X and Y loops move the cursor through the grid, highlighting each letter as it scanned. This is done by using the LOCATE command to get the screen RAM value of the letter, adding 128 to set bit 8 on for inverse video and finally PLOTting the letter back to the screen at the same spot. You usually do not consider using the PLOT, LOCATE and other graphics commands in Mode 0, but they work here just as they do in any other graphics mode. For the commands to work properly, you must turn the cursor off beforehand by POKEing 752,1. Turn it back on with POKE 752,0 before exiting the program.

If the first letter of the search word doesn't match the letter at the current grid position then it skips the next set of loops and moves on to the next letter in the puzzle grid.

If the first letter does match the grid letter, the area around that grid position is searchd to see if the rest of the word is there. Here's where the DX and DY loops come in. These loops give nine possible values, of which eight are valid. The ninth value occurs when DX and DY are both 0, which means we're not going anywhere-- so we skip over the subroutine call to the NEXT line and try the next valid set of values.

For each pass of the DX/DY loop pair we enter the subroutine starting at line 80, which makes sure the word will fit in the puzzle going in the direction indicated by DX and DY. If a 10-letter word is being searched and we're in grid position 18, then the word won't fit going to the right. There's no need to check anything else with this set of directions. We also perform the same check for vertical words.

If the word fits, we must check, character by character, against the grid in the current direction. As we look we will set each character in the grid to inverse video. No match means resetting all matched letters to normal video and exiting the subroutine. We then continue searching in the next direction.

lf the check is successful, the user is informed of the find by a message in the command box and the screen turning green.

Kevin Peck is currently in college studying computer science. He has written various programs for business in Salina, Kansas

Listing1:WORD.BAS Download

Listing2:PUZZLE1.DAT Download

Listing3:PUZZLE2.DAT Download