Word Find (Puzzle Maker)

Type
Utility
Category
Word-search puzzle generator for the printer
Author
Matthew Ratcliff
Published in
Antic, January 1984 (Vol. 2, No. 10)
Year
1984
Language
Atari BASIC
Requirements
16K RAM, Atari BASIC, printer (40- or 80-column), disk drive or cassette for word lists

About the program

Everyone has seen the "word-find" puzzle books in the supermarket checkout line. Matthew Ratcliff's program prints your own, from any list of words, as many copies as you need. He first wrote it for a friend who wanted puzzles for a sales-promotion party, and suggested it could also be a spelling aid or "a quiet alternative to video games". Ratcliff became a regular Antic contributor, and his Math Wizard and Spell Blaster games also appeared in the magazine.

Typing it in

Only six lines contain inverse-video words ({inv}…{/inv}: press the Atari key before and after). The program is heavily commented, so you can see what each part does. The REMs can be left out to save memory. Before using it, set your printer width in line 60 (PW=72 here). For a 40-column printer the article gives two replacement lines: 1150 C=C+1:IF C=2 THEN C=0:? #3 and 1460 ? #3;PUZZLE$(A,A);. They put two words per line in the word list and print the puzzle single-spaced.

How to use it

  1. Choose a puzzle size from 10 to 30 squares.
  2. Give the file that holds your word list (for example D:WORDS), or type NEW to enter a list and save it to disk (D:name) or cassette (C). Type END to finish the list.
  3. Enter a title, and choose easy (words in a few forward directions) or difficult (any of the eight directions, including backwards).
  4. Choose the number of copies, and whether they should be identical or each hide the words differently.
  5. Ask for a cheat sheet if you like. It prints the grid with only the hidden words, with * in all the other squares.

You can use any printable character except * and ,. A comma splits a phrase into separate words when the list is read back. If you use lower case or other symbols, add them to LTR$ in line 70 so that the random filler letters include them too and don't give the words away.

How it works

  • The grid is one string. PUZZLE$ starts full of asterisks. For each word, the program picks a random direction V and works out the step in each axis with logical expressions (lines 790–800). It then checks that every square on the word's path is either * or already holds the right letter, so words can share letters where they cross.
  • Giving up gracefully. TEST counts how many positions have been tried (lines 650–690). The limit grows as the puzzle fills ((WCNT+1)*5+10). If a word still won't fit, it is dropped and reported as "WONT FIT", and it's left out of the printed word list. Ratcliff's rule of thumb: make the grid at least as wide as the longest word.
  • The finish. At the end, every remaining * is replaced by a random letter from LTR$. The word list holds up to three times the puzzle size, and words can be up to 14 letters (line 1670).

Changes from the published listing

One change, so the program also runs under Altirra BASIC, the free replacement BASIC built into many emulators. Altirra BASIC adds a function called ERR, so it rejected the published lines that use that word as the start of a variable name. The variable is renamed everywhere in the program. The new name is the same length, so the memory layout is unchanged and the program behaves exactly as published on genuine Atari BASIC. If you type it in from the magazine, the original names work fine on a real Atari.

Published Now Lines
ERR ERX 1800, 1810

Listing

10 REM ATARI WORD FIND PUZZLE GENERATOR
11 REM BY MATTHEW RATCLIFF
12 REM ANTIC MAGAZINE
13 REM JANUARY, 1984
20 GRAPHICS 0:? "* WORD FIND BY MAT RAT *":TRAP 1800
30 ? :? "PUZZLE SIZE (10-30) ";:INPUT PSZ
40 IF (PSZ<10 OR PSZ>30) THEN ? PSZ;" SIZE ERROR !":GOTO 30
50 LPZ=PSZ*PSZ:DIM PUZZLE$(LPZ),WORD$(15),LTR$(80),FILE$(15)
60 DIM Q$(5),WSV$(3*PSZ*15),TTL$(50):PW=72:REM PRINTER WIDTH
70 LTR$="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
80 LLTR=LEN(LTR$):REM YOU CAN ADD SPECIAL CHARACTERS TO
90 REM THE RANDOM LETTER FILL ARRAY, LTR$ TO ALLOW FOR
100 REM HYPHENATED WORDS & SHORT PHRASES IN THE LIST. ONLY
110 REM THE '*' & "," ARE NOT ALLOWED IN LTR$
120 WCNT=0:REM MAX WORDS ALLOWED, 3*PSZ
130 REM
140 ? :? "INPUT WORD FILENAME,"
150 ? "(C: FOR CASSETTE), 'NEW' TO CREATE"
160 ? "A NEW WORD FILE ";:INPUT FILE$
170 IF LEN(FILE$)=0 THEN ? :? "NO FILE NAME ?  NO GOOD -":GOTO 140
180 IF FILE$="NEW" THEN GOSUB 1530
190 FLG=1:IF FILE$(1,1)="C" THEN FLG=0:REM CASSETTE FLAG
200 IF FLG THEN 240
210 ? :? "REWIND CASSETTE WITH WORD FILE ON"
220 ? "IT. PRESS {inv}PLAY{/inv} AND PRESS {inv}RETURN{/inv} KEY"
230 ? "WHEN CONSOLE SPEAKER BEEPS ONCE."
240 OPEN #5,4,0,FILE$
250 IF FLG THEN 280
260 FOR I=1 TO 128:GET #5,A:NEXT I
270 REM GET DUMMY RECORD TO STOP CASSETTE
280 ? :? "INPUT TITLE OF PUZZLE ";:INPUT TTL$
290 ? :? "(D)IFFICULT OR (E)ASY PUZZLES ";:INPUT Q$:IF LEN(Q$)=0 THEN 290
300 DIF=2*(Q$(1,1)="D")+(Q$(1,1)="E")
310 IF DIF=0 THEN ? Q$;" * WHAT ? *":GOTO 290
320 ? :? "INPUT NUMBER OF PUZZLE COPIES ";:INPUT NCOP
330 IF NCOP<1 THEN ? "HOW MANY ?":GOTO 320
340 IF NCOP=1 THEN 400
350 ? :? "(I)DENTICAL OR (D)IFFERENT COPIES ";:INPUT Q$
360 TYP=2*(Q$(1,1)="I")+(Q$(1,1)="D")
370 IF TYP=0 THEN ? "'I' OR 'D', NOT ";Q$:GOTO 350
380 REM PRINTER SET-UP CODE.  REPLACE WITH YOUR
390 REM PRINTER'S SPECIFIC REQUIREMENTS.
400 OPEN #3,8,0,"P:"
430 REM * ASK FOR CHEAT SHEETS *
440 ? :? "WOULD YOU LIKE CHEAT SHEETS (EXTRA"
450 ? "PRINTOUT OF PUZZLE BEFORE FILLING"
460 ? "WITH RANDOM LETTERS), Y/N";:INPUT Q$:IF LEN(Q$)=0 THEN 440
470 CHEAT=2*(Q$(1,1)="N")+(Q$(1,1)="Y")
480 IF CHEAT=0 THEN ? "'Y' OR 'N' ?":GOTO 440
490 REM * FILL PUZZLE WITH '*'S FIRST *
500 PUZZLE$(1,1)="*":PUZZLE$(LPZ,LPZ)="*":PUZZLE$(2)=PUZZLE$
510 REM * GET A WORD AND CHECK FOR 'END' *
520 INPUT #5,WORD$:? WORD$
530 IF WORD$="END" THEN GOTO 1010
540 LW=LEN(WORD$)
550 REM *PAD WITH BLANKS TO 15 CHARACTERS *
560 REM * TO FORMAT OUTPUT,& SAVE IN WSV$ *
570 FOR I=LW+1 TO 15:WORD$(I,I)=" ":NEXT I
580 WCNT=WCNT+1:REM WORD COUNT
590 IF WCNT>3*PSZ THEN ? "* ERROR *":? "WORD FILE TOO LONG...":END
600 WSV$(15*(WCNT-1)+1,15*(WCNT-1)+15)=WORD$
610 REM
620 REM * PICK RANDOM COORDINATES AND VECTOR *
630 REM * VECTOR IS 0,+45, OR -45 DEGREES    *
640 REM * FOR EASY PUZZLES                   *
650 TEST=0:REM TEST COUNTER FOR # OF TIMES WE
660 REM TRY TO FIT WORD$ IN PUZZLE$
670 X=INT(PSZ*RND(0))+1:Y=INT(PSZ*RND(0))+1
680 TEST=TEST+1
690 IF TEST<(WCNT+1)*5+10 THEN GOTO 740
700 REM TRY MORE TIMES WHEN PUZZLE IS NEARLY FULL
710 WCNT=WCNT-1:IF WCNT<1 THEN WCNT=1:REM THROW IT OUT
720 ? :? WORD$;" * WONT FIT *"
730 GOTO 520
740 ON DIF GOTO 750,760
750 V=INT(RND(0)*3)+2:GOTO 790
760 V=INT(RND(0)*8)+1
770 REM SET X1,Y1 - X,Y INCREMENTS FOR
780 REM CHOSEN DIRECTION
790 X1=(V=2 OR V=3 OR V=4)-(V=6 OR V=7 OR V=8)
800 Y1=(V=1 OR V=2 OR V=8)-(V=4 OR V=5 OR V=6)
810 REM * SEE IF WORD WILL FIT THERE *
820 FOR I=1 TO LW
830 X2=X+I*X1
840 Y2=Y+I*Y1
850 IF (X2<1 OR Y2<1) THEN GOTO 670
860 IF (X2>PSZ OR Y2>PSZ) THEN GOTO 670
870 A=PSZ*(Y2-1)+X2
880 IF PUZZLE$(A,A)="*" THEN GOTO 910
890 IF PUZZLE$(A,A)=WORD$(I,I) THEN GOTO 910
900 GOTO 670:REM SPACE ALREADY TAKEN, TRY AGAIN
910 NEXT I
920 REM * OK, INSERT WORD HERE *
930 FOR I=1 TO LW
940 X2=X+X1*I:Y2=Y+Y1*I:A=PSZ*(Y2-1)+X2
950 PUZZLE$(A,A)=WORD$(I,I)
960 NEXT I
970 GOTO 520:REM GET NEXT WORD UNTIL 'END'
980 REM
990 REM
1000 REM END OF FILE REACHED
1010 ON CHEAT GOTO 1020,1060
1020 GOSUB 1340:REM PRINT PUZZLE WITHOUT RANDOM LETTER FILL
1030 REM
1040 REM NOW FILL PUZZLE$ WITH RANDOM LETTERS
1050 REM
1060 FOR I=1 TO LPZ
1070 IF PUZZLE$(I,I)<>"*" THEN GOTO 1100
1080 I2=INT(RND(0)*LLTR)+1:REM SELECT A RANDOM CHARACTER
1090 PUZZLE$(I,I)=LTR$(I2,I2):REM FROM LTR$
1100 NEXT I
1110 REM * NOW PRINT OUT PUZZLE AND WORD LIST *
1120 GOSUB 1340:C=0
1130 FOR I=1 TO WCNT
1140 ? #3;WSV$(15*(I-1)+1,15*(I-1)+15);
1150 C=C+1:IF C=4 THEN C=0:? #3
1160 NEXT I:? #3:? #3:? #3:? #3
1170 REM * PRINT MULTIPLE IDENTICAL COPIES ?      *
1180 IF NCOP>1 AND TYP=2 THEN NCOP=NCOP-1:GOTO 1120
1190 REM * PRINT MULTIPLE DIFFERENT COPIES ?             *
1200 IF NCOP>1 AND TYP=1 THEN NCOP=NCOP-1:CLOSE #5:GOTO 1250
1210 CLOSE #3:CLOSE #5
1220 ? :? "PUZZLES COMPLETE."
1230 ? "BYE ......"
1240 END
1250 IF FLG THEN 1290
1260 ? :? "REWIND CASSETTE AGAIN PLEASE"
1270 ? "PRESS {inv}PLAY{/inv} AND THE {inv}RETURN{/inv} KEY"
1280 REM RESTORE CASSETTE WORD FILE
1290 OPEN #5,4,0,FILE$:WCNT=0:WSV$=""
1300 IF FLG THEN 1320
1310 FOR I=1 TO 128:GET #5,A:NEXT I
1320 GOTO 490
1330 REM * PRINT OUT PUZZLE$ *
1340 FOR I=1 TO 10:? #3:NEXT I
1350 REM THIS IS MY FORM FEED FOR A TELETYPE,
1360 REM FOR FANFOLD PRINTER PAPER USE:
1370 REM 1340 ? #3;CHR$(12)
1380 ? #3:? #3:A=INT((PW-10-LEN(TTL$))/2)
1390 REM CENTER TITLE PLUS 'WORD FIND ' ON 72 COL TTY
1400 FOR I=1 TO A:? #3;" ";:NEXT I
1410 ? #3;"WORD FIND ";TTL$:? #3:? #3
1420 FOR Y=1 TO PSZ
1430 FOR I=1 TO INT((PW-2*PSZ)/2):? #3;" ";:NEXT I:REM CENTER PUZZLE
1440 FOR X=1 TO PSZ
1450 A=PSZ*(Y-1)+X
1460 ? #3;PUZZLE$(A,A);" ";
1470 NEXT X
1480 ? #3
1490 NEXT Y
1500 ? #3:? #3
1510 RETURN
1520 REM * CREATE NEW WORD FILE FOR WORD FIND *
1530 ? "FILE NAME TO PUT NEW"
1540 ? "WORD LIST ON ";:INPUT FILE$
1550 IF LEN(FILE$)=0 THEN ? "NO FILE NAME ? NO GOOD -":GOTO 1530
1560 FLG=1:IF FILE$(1,1)="C" THEN FLG=0
1570 IF FLG THEN 1620
1580 ? :? "REWIND BLANK CASSETTE, PRESS"
1590 ? "{inv}PLAY/RECORD{/inv} AND PRESS THE"
1600 ? "{inv}RETURN{/inv} KEY WHEN CONSOLE SPEAKER"
1610 ? "BEEPS TWICE..."
1620 OPEN #2,8,0,FILE$
1630 IF FLG THEN 1650
1640 FOR I=1 TO 128:? #2;"0";:NEXT I
1650 I=1
1660 ? :? I;" WORD = ";:INPUT WORD$
1670 IF LEN(WORD$)>14 THEN ? WORD$;" TOO LONG":GOTO 1660
1680 IF LEN(WORD$)=0 THEN ? "NO WORD?? 'END' IF DONE...":GOTO 1660
1690 ? #2;WORD$
1700 I=I+1:IF I>3*PSZ THEN GOTO 1740
1710 IF WORD$<>"END" THEN 1660
1720 CLOSE #2
1730 RETURN
1740 ? :? "MAXIMUM WORDS ALLOWED REACHED"
1750 ? "FINISHING UP THE FILE..."
1760 ? #2;"END":? "END"
1770 CLOSE #2
1780 ? "CONTINUE..."
1790 RETURN
1800 ERX=PEEK(195):LINE=PEEK(186)+256*PEEK(187)
1810 ? :? "* ERROR # ";ERX;" AT LINE ";LINE;" *"
1820 ? :? :? "CHECK YOUR ERROR CODE AND FIX IT"
1830 END

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: WORDFIND.BAS.

Credits