Ladders

Developer(s): M. Savin
Date: 1982
Type: Program
Platform(s): TS 2068
Tags: Game

A number-ordering game. A ladder of ten coloured rungs, numbered 0 at the bottom to 9 at the top, is drawn down the left of the screen. The computer offers random numbers from 0 to 98 one at a time. Press y to take a number, n to pass it over or s to stop. A number you take goes on the rung you type, and the aim is a ladder that runs from the lowest number at the bottom to the highest at the top. The score counts the numbers you have taken. At the end a score of 8 or more earns “WELL DONE!!!”, and a failed order check brings “TRY AGAIN. I THINK YOU MADE A MISTAKE!!!”.

The title screen reads “© M. Savin 1982”. The instructions say “The ZX Spectrum will choose ten numbers”, and the program is plain Spectrum BASIC that runs unchanged on the TS2068.

Program Analysis

Structure

  • Lines 750–860: the title, a short tune, the instructions, and POKE 23609,255 for a long key click.
  • Lines 20–230: draw the ladder rails with block graphics, the ten coloured rungs and the rung numbers.
  • Lines 250–580: the main loop of ten offers. Each number is stored in b(j), and line 310 polls INKEY$ for y, n or s.
  • Lines 350–560: INPUT LINE a$ for the rung, then a separate IF for each digit that prints the number in that rung’s colour and moves j down by one.
  • Lines 590–670: the end-of-game check. Lines 680–740: the score screen and the play-again prompt.

The End-of-Game Check

Placing a number only prints it on the chosen rung. The program never records which rung was used. The number is kept in b(j), where j counts down from 10 as numbers are accepted, so b(10) holds the first number taken and b(1) the tenth. Lines 590–610 first look for a zero in b(), and if they find one they jump straight to the success tune and the score. Otherwise lines 630–650 compare b(x) with b(x+1) for x = 1, 3, 5, 7 and 9, and call it a mistake if the first is smaller. This compares the first number taken with the second, the third with the fourth, and so on. It reports a mistake only when the later number of a pair is smaller than the earlier one. The NEXT x at line 620 follows a finished loop and does nothing.

Notable Techniques

  • Each rung is printed with its own INK or PAPER colour, and the colour statements are interleaved between the IF lines so that each number takes its rung’s colour.
  • POKE 23609,255 lengthens the keyboard click.

Potential Issues

  • The order check never looks at the ladder. It tests the order in which numbers were accepted, not the rungs they were placed on, so a correctly built ladder can be called a mistake and a wrongly built one can pass.
  • It compares only five pairs of numbers (first with second, third with fourth and so on), not each number with its neighbours.
  • If any number was passed over or the game was stopped early, b() still contains a zero and the check is skipped, so the success tune plays. An offered number of 0 has the same effect.
  • The score counts numbers accepted, not numbers placed correctly. Pressing ENTER without a rung (line 380) adds a point and draws a new number, and a rung outside 0–9 still counts and uses up an offer.
  • Nothing stops a second number going on a rung that is already in use. It simply overprints the first.
  • A failed check plays BEEP 10,-15, a ten-second low tone, and then RUN restarts from the title screen.

This program came from an Oliger (JLO SAFE) disk in the SNUG library set and was converted for tape. It has no disk commands, so no changes were needed. It was tested in ZEsarUX on a stock TS2068 through the instructions, the ladder and the placing of a number.

Image Gallery

Source Code

   10 INK 1: GO TO 750
   20 LET j=10
   30 DIM b(j)
   40 BORDER 7: PAPER 7: CLS 
   50 FOR v=0 TO 19
   60 PRINT TAB 4;" :";TAB 11;": "
   70 NEXT v
   80 LET a=5
   90 PRINT AT 0,a;"  ::::"
  100 FOR n=1 TO 17 STEP 2: PRINT AT n,a;"............": NEXT n
  110 INK 2
  120 PRINT AT 2,a;"  ::::"
  130 INK 3
  140 LET w=9: LET q=0: FOR u=1 TO 10: PRINT AT q,a-3;w;"_": LET q=q+2: LET w=w-1: NEXT u
  150 PRINT AT 4,a;"  ::::"
  160 INK 4
  170 PRINT AT 6,a;"  ::::"
  180 INK 5
  190 PRINT AT 8,a;"  ::::"
  200 INK 6
  210 FOR u=0 TO 4
  220 PRINT AT 10+u*2,a;"  ::::"
  230 INK u: NEXT u
  240 LET y=0
  250 FOR x=0 TO 9
  260 LET b(j)=INT (RND*99)
  270 PRINT AT 0,20; FLASH 1; INK 3;"Score=";y
  280 IF y=10 THEN GO TO 690
  290 LET y=y+1
  300 PRINT AT 20,0," "; INK 0;b(j);"  Y or N?"; INVERSE 0,,,
  310 LET b$=INKEY$: IF b$="n" THEN LET x=x+1: LET y=y-1: GO TO 260
  320 IF b$="y" THEN GO TO 350
  330 IF b$="s" THEN GO TO 690
  340 GO TO 300
  350 INK 0: PRINT AT 20,0;"WHICH BLOCK WOULD YOU LIKE THE    NUMBER ";b(j); INK 0;" TO GO IN (0-9)?"
  360 INK 2
  370 INPUT LINE a$
  380 IF a$="" THEN GO TO 260
  390 IF a$="1" THEN PRINT AT 16,a;"  ";b(j);"": LET j=j-1
  400 INK 1
  410 IF a$="2" THEN PRINT AT 14,a;"  ";b(j);"": LET j=j-1
  420 INK 0
  430 IF a$="3" THEN PRINT AT 12,a;"  ";b(j);"": LET j=j-1
  440 INK 3: IF a$="0" THEN PRINT AT 18,a;"  ";b(j);"": LET j=j-1
  450 INK 6
  460 IF a$="4" THEN PRINT AT 10,a;"  "; INVERSE 0; PAPER 6; INK 0;b(j): LET j=j-1
  470 INK 5
  480 IF a$="5" THEN PRINT AT 8,a;"  "; INK 0; PAPER 5;b(j): LET j=j-1
  490 INK 4
  500 IF a$="6" THEN PRINT AT 6,a;"  "; INK 0; PAPER 4;b(j): LET j=j-1
  510 INK 3
  520 IF a$="7" THEN PRINT AT 4,a;"  ";b(j);"": LET j=j-1
  530 INK 2
  540 IF a$="8" THEN PRINT AT 2,a;"  ";b(j);"": LET j=j-1
  550 INK 1
  560 IF a$="9" THEN PRINT AT 0,a;"  ";b(j);"": LET j=j-1
  570 INVERSE 0
  580 NEXT x
  590 FOR s=1 TO 10
  600 IF b(s)=0 THEN GO TO 680
  610 NEXT s
  620 NEXT x
  630 FOR x=1 TO 9 STEP 2
  640 IF b(x)<b(x+1) THEN GO TO 670
  650 NEXT x
  660 GO TO 680
  670 CLS : PRINT AT 10,0;"TRY AGAIN.  I THINK YOU MADE A  MISTAKE!!!": BEEP 10,-15: RUN 
  680 INK 0: PAPER 4: BORDER 3: CLS : FOR v=1 TO 20: BEEP .1,v: NEXT v
  690 CLS : PRINT FLASH 1;AT 10,8;"Your score was ";y
  700 IF y>=8 THEN PRINT AT 12,10;"WELL DONE!!!": FOR g=1 TO 20: BEEP .05,g: NEXT g
  710 INK 0: PRINT AT 20,0;"Would you like to play again?": IF INKEY$="n" THEN STOP 
  720 PRINT AT 21,0;"Press Y for 'yes'    N for 'no'.": IF INKEY$="n" THEN STOP 
  730 IF INKEY$="y" THEN RUN 20
  740 GO TO 710
  750 PAPER 6: INK 0: BORDER 2: CLS : PRINT TAB 9;"* M. Savin 1982";AT 10,10;"***LADDERS***"
  760 POKE 23609,255
  770 FOR y=1 TO 7
  780 FOR o=1 TO 3
  790 BEEP .1,y: BEEP .1,o
  800 NEXT o: NEXT y
  810 BEEP 2,11: PAPER 7: CLS : INK 2
  820 PRINT AT 0,7;"***INSTRUCTIONS***"
  830 PRINT 
  840 INK 0: PRINT "   The ZX Spectrum will choose  ten numbers which you gave to   place on the ladder in order,   the lowest number should be at  the bottom of the ladder and thehighest at the top.  When you   see the 'L' press a key from    0-9 and then press the key      'ENTER' which is on the right   hand side.  If you get 7 numberson the ladder, you have done    very well!!"
  850 PRINT AT 20,5;"Press any key to start"
  860 PAUSE 0: GO TO 20

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.