The mainframe where I work has a Hangman-style number guessing game in its library which has fascinated me. I wrote HANG-MULT to emulate the mainframe’s program on my TS-2068 and thought other SWN readers might enjoy it too.
The program’s title screen includes a PAUSE to prevent the random-number SEED from starting at the same value each time the program is loaded.
After the title screen prompt is answered, the program creates a random 3-digit and 2-digit number which are multiplied and converted to a subscripted string variable. Another string is created and used to display the problem. Unidentified digits are represented as “X”. Previous guesses are listed by column. The program then displays prompts for column, number, and yes or no.
The data-input request prompts may be answered with digits 1 through 5 for “Column =” (5 is the most significant column), 0 through 9 for “Number =”, and “Y”, “y”, or ENTER for an affirmative response to “OK? (Y/N)” (anything else for a negative). These prompts may also be answered with “?” to forfet. The solution will then be displayed and all variables CLEARed. All prompts, except the title page, may be answered with “S” or “s” to SAVE the program to tape. After the SAVE, program execution continues at the point the SAVE occurred. When reloaded, the program retains the problem data existing at the time of the SAVE (I.E. None if SAVEd from the forfet screen).
Guessing all 18 numbers displays the solved problem, a rating, and statistics. A prompt offers “Another game (Y/N)?”. Exiting from this prompt CLEARs the variables. All variables and the UDG are defined in the program, so SAVE “HANG-MULT” LINE 0 is OK, as is RUNning to re-start.
There is an error trap which sents the program to the exit routine and CLEARs everything ON ERRor. This prevents the temptation of BREAKing into the program and changing data.
The only thing in the listing that’s unclear is the GRAPHICS character defined in line 1090 and printed in line 210. It doesn’t matter which character is used providing its the same in both places. I used GRAPHICS “l” (for “l”ine).
10 REM COLD START
20 ON ERR GO TO 1900: GO SUB 300: LET gm=0: LET tm=0: PRINT ''"Press any key to begin": PAUSE 0: GO TO 1000
30 DEF FN r$(x)=STR$ (INT (100*x)/100)+" "
100 REM DATA INPUT
110 BORDER 0: ON ERR GO TO 120
120 IF INKEY$<>"" THEN STOP
130 PAUSE 0: LET I$=INKEY$: IF I$="S" OR I$="s" THEN SAVE "HANG-MULT" LINE l
140 GO SUB 500: ON ERR GO TO 1900: RETURN
200 REM PRINT PROBLEM
210 PRINT AT 0,10;" HANG-MULT "'': FOR x=1 TO 5: PRINT TAB 12;d$(x): IF x=2 OR x=4 THEN PRINT TAB 12;"LLLLL"
220 NEXT x: RETURN
240 NEXT y: NEXT x: PRINT AT 19,0;"Misses = ";m;" ": RETURN
300 REM TITLE
310 GO SUB 400: PRINT AT 6,0;"[illegible]"''"© 1986"''"Kent E. Cook"'"PO Box 1031"'"Terre Haute, Ind."'"47808": RETURN
400 REM [illegible]
410 INK 7: PAPER 0: BORDER 0: CLS : RETURN
500 REM [illegible]
510 PRINT #1;AT 0,0;" ": RETURN
1000 REM [illegible]
1010 LET gm=gm+1: LET hit=0: LET mt=0: DIM c$(5,20): DIM a$(5,5): LET a$(1)=" 000": LET a$(2)=" 00": LET a$(3)=" 0000": LET a$(4)="0000 ": LET a$(5)="00000": DIM d$(5,5): LET d$(1)=" XXX": LET d$(2)=" XX": LET d$(3)=" XXXX": LET d$(4)="XXXX ": LET d$(5)="XXXXX"
1020 RANDOMIZE 0: LET x=INT (1+RND*999): LET a$(1,6-LEN STR$ x TO )=STR$ x
1030 LET x=INT (1+RND*99): LET a$(2,6-LEN STR$ x TO )=STR$ x
1040 LET x=VAL a$(1)*VAL a$(2,5): LET a$(3,6-LEN STR$ x TO )=STR$ x
1050 LET x=VAL a$(1)*VAL a$(2,4): LET a$(4,5-LEN STR$ x TO )=STR$ x: LET a$(4,5)=" "
1060 LET x=VAL a$(1)*VAL a$(2): LET a$(5,6-LEN STR$ x TO )=STR$ x
1070 DIM p$(160): FOR x=0 TO 4: LET p$(32*x+1 TO )="Col "+STR$ (5-x)+":": NEXT x
1080 REM [illegible]
1090 GO SUB 400: FOR x=0 TO 7: POKE USR "L"+x,(255 AND x=4): NEXT x: LET l=1080
1100 REM DISPLAY PROBLEM
1110 GO SUB 200: IF hit=18 THEN GO TO 1500
1120 PRINT AT 10,0;"Previous guesses:"''P$''"Game #";gm,"Misses = ";mt''"Average misses/game = ";FN r$((mt+tm)/gm)
1200 REM INPUT GUESS
1210 PRINT #1;AT 0,0;"Column = ?": GO SUB 100: IF I$="?" THEN GO TO 1400
1215 IF I$<"1" OR I$>"5" THEN GO TO 1210
1220 LET col=VAL I$
1230 PRINT #1;AT 0,0;"Column = ";col,"Number = ?": GO SUB 100: IF I$="?" THEN GO TO 1400
1235 IF I$<"0" OR I$>"9" THEN GO TO 1230
1240 LET n=VAL I$
1250 PRINT #1;AT 0,0;"Column = ";col,"Number = ";n'"OK (Y/N)?": GO SUB 100: GO SUB 500: IF I$="?" THEN GO TO 1400
1255 IF CODE I$<>13 AND I$<>"Y" AND I$<>"y" THEN GO TO 1200
1260 LET col=6-col: FOR x=2 TO 20 STEP 2: IF c$(col,x)<>STR$ n THEN NEXT x: GO TO 1300
1265 PRINT #1;AT 0,0;" You already tried that! ": BEEP .5,1: PAUSE 40: GO SUB 500: GO TO 1200
1300 REM HIT MISS
1310 LET miss=1: FOR x=20 TO 2 STEP -2: IF c$(col,x)=" " THEN NEXT x: LET c$(col,2)=STR$ n: GO TO 1340
1320 FOR x=x TO 2 STEP -2: IF c$(col,x)>STR$ n THEN NEXT x
1330 LET c$(col,x+2 TO )=STR$ n+" "+c$(col,x+2 TO 18)
1340 FOR x=0 TO 4: LET y=32*x+8: LET p$(y TO y+20)=c$(x+1): IF a$(x+1,col)=STR$ n THEN BEEP .1,36: LET hit=hit+1: LET d$(x+1,col)=STR$ n: LET miss=0
1350 NEXT x: LET mt=mt+miss: GO TO 1100
1400 REM FORFET
1410 GO SUB 400: FOR x=1 TO 5: LET d$(x)=a$(x): NEXT x: GO SUB 200: PRINT '''"Previous game records erased!"''"Start over (Y/N)?": LET l=0: GO SUB 100: IF I$<>"N" AND I$<>"n" THEN RUN
1420 GO TO 1900
1500 REM SOLUTION
1510 GO SUB 400: GO SUB 200: LET tm=tm+mt: PRINT ''"You solved it with ";mt;" miss";"es" AND mt<>1;"-"''"An unbeatable performance" AND mt=0;"A world class performance!" AND (mt=1 OR mt=2);"A first class performance" AND (mt=3 OR mt=4);"A good effort!" AND mt=5;"Not bad for a tough problem" AND (mt=6 OR mt=7);"Too bad! This one was tricky" AND (mt=8 OR mt=9);"A poor showing, but keep trying" AND mt>=10 AND mt<=12;"I hope no one is watching!" AND mt>=13
1520 PRINT ''"Average misses/game after"'gm;" game";"s" AND gm<>1;" = ";FN r$(tm/gm)''"Another game (Y/N)?": GO SUB 100: IF I$<>"N" AND I$<>"n" THEN GO TO 1000
1900 REM EXIT
1910 CLEAR : GO SUB 300: ON ERR RESET : STOP
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.