Fifteen

This file is part of Synchro-Sette January 1984. Download the collection to get this file.
Developer(s): Gene G. Buza
Date: 1984
Type: Program
Platform(s): TS 1000
Tags: Game

The sliding fifteen puzzle, using the inverse letters A to O as tiles on a 4×4 grid drawn with block graphics. A menu offers three starting arrangements: straight, reversed or shuffled. The empty square is moved with the cursor keys 5–8, and the aim is to put the tiles in order from A to O with the gap in the bottom right corner. The program counts moves, announces a win, and keeps the lowest move count as the best score for the session.

Line 0 carries the credit “Written by Gene Buza” in inverse characters.


Program Analysis

Program Structure

  1. Setup (lines 10–150): A$ holds the tiles in order. YY is set to the display file address and XX to the display-file byte of the empty square, then the menu is shown.
  2. Layouts (lines 200–490): straight copies A$, reverse fills B$ backwards, and random draws letters from a working copy until it is all spaces.
  3. Drawing (subroutines 1000 and 2000): the grid lines are drawn with full blocks, then the fifteen tiles are printed at fixed positions with the gap in the top left cell.
  4. Play loop (lines 500–930): checks for a solved grid, waits for a key, rejects moves off the edge, then slides one tile into the gap.

Notable Techniques

  • Tiles are moved by copying display-file bytes. Moving the gap left, for example, is LET XX=XX-4 followed by POKE (XX+4),PEEK XX. Offsets of ±4 move one cell across and ±132 (four rows of 33 bytes) move one cell down or up.
  • The win check at line 500 compares fifteen display-file bytes with the inverse letter codes 166–180.
  • The cursor routine at line 3000 prints a full block, a grey block and then a space at the gap, making it flicker while it waits for a key. Pressing Q (code 54) returns to the menu.

Potential Issues

  • The “straight” layout cannot be solved. It starts with the tiles in order and the gap in the top left, and the goal has the same order with the gap in the bottom right. On a 4×4 board that change moves the gap an odd number of rows without changing the order of the tiles, which is impossible to achieve with legal slides (the same parity rule behind Sam Loyd’s 14–15 puzzle). The reverse layout can be solved, and a shuffled layout can be solved only about half the time.
  • All fifteen PEEK tests at line 500 run before every keypress, which slows the response noticeably.

Appears On

The January 1984 Synchro-Sette subscription cassette: seven programs, including a baccarat game, a fifteen puzzle, an electrical formula calculator and a notes database.

Image Gallery

Source Code

   0 [W][R][I][T][T][E][N]█[B][Y]█[G][E][N][E]█[B][U][Z][A]
  10 LET A$="[A][B][C][D][E][F][G][H][I][J][K][L][M][N][O]"
  20 DIM B$(15)
  30 DIM Z$(15)
  35 LET S=100000
  40 LET YY=PEEK 16396+256*PEEK 16397
  60 LET XX=YY+183
 100 CLS
 105 LET X=5
 106 LET Y=17
 107 LET M=1
 110 SLOW
 120 PRINT AT 1,9;"[F][I][F][T][E][E][N]█[G][A][M][E]";AT 6,0;"STRAIGHT","ENTER <1>";AT 8,0;"REVERSE","ENTER <2>";AT 10,0;"RANDOM","ENTER <3>";AT 21,5;"[E][N][T][E][R]█[O][N][E]█[O][F]█[A][B][O][V][E]"
 130 LET Y$=INKEY$ 
 140 IF CODE Y$<29 OR CODE Y$>31 THEN GOTO 130
 150 GOTO VAL Y$*100+100
 200 LET B$=A$
 210 GOSUB 1000
 220 GOSUB 2000
 299 GOTO 500
 300 FAST
 310 FOR N=1 TO 15
 320 LET B$(16-N)=A$(N)
 330 NEXT N
 340 GOTO 210
 400 FAST
 405 LET C$=A$
 410 FOR N=1 TO 15
 420 IF C$=Z$ THEN GOTO 490
 430 RAND 
 440 LET A=INT (15*RND)+1
 450 IF C$(A)=" " THEN GOTO 440
 460 LET B$(N)=C$(A)
 470 LET C$(A)=" "
 480 NEXT N
 490 GOTO 210
 500 IF PEEK (YY+183)=166 AND PEEK (YY+187)=167 AND PEEK (YY+191)=168 AND PEEK (YY+195)=169 AND PEEK (YY+315)=170 AND PEEK (YY+319)=171 AND PEEK (YY+323)=172 AND PEEK (YY+327)=173 AND PEEK (YY+447)=174 AND PEEK (YY+451)=175 AND PEEK (YY+455)=176 AND PEEK (YY+459)=177 AND PEEK (YY+579)=178 AND PEEK (YY+583)=179 AND PEEK (YY+587)=180 THEN GOTO 3100
 505 GOSUB 3000
 510 IF Y$="5" AND Y=17 THEN GOTO 500
 520 IF Y$="6" AND X=17 THEN GOTO 500
 530 IF Y$="7" AND X=5 THEN GOTO 500
 540 IF Y$="8" AND Y=29 THEN GOTO 500
 542 PRINT AT 2,1;M;" MOVES"
 545 LET M=M+1
 550 IF Y$="5" THEN GOTO 600
 560 IF Y$="6" THEN GOTO 700
 570 IF Y$="7" THEN GOTO 800
 580 IF Y$="8" THEN GOTO 900
 590 GOTO 100
 600 LET XX=XX-4
 610 POKE (XX+4),PEEK XX
 620 LET Y=Y-4
 630 GOTO 500
 700 LET XX=XX+132
 710 POKE (XX-132),PEEK XX
 720 LET X=X+4
 730 GOTO 500
 800 LET XX=XX-132
 810 POKE (XX+132),PEEK XX
 820 LET X=X-4
 830 GOTO 500
 900 LET XX=XX+4
 910 POKE (XX-4),PEEK XX
 920 LET Y=Y+4
 930 GOTO 500
1000 FAST
1010 CLS
1020 FOR N=15 TO 31
1030 PRINT AT 3,N;"█";AT 7,N;"█";AT 11,N;"█";AT 15,N;"█";AT 19,N;"█"
1040 NEXT N
1050 FOR N=4 TO 18
1060 PRINT AT N,15;"█";AT N,19;"█";AT N,23;"█";AT N,27;"█";AT N,31;"█"
1070 NEXT N
1080 SLOW
1090 RETURN
2000 FAST
2010 PRINT AT 5,21;B$(1);AT 5,25;B$(2);AT 5,29;B$(3);AT 9,17;B$(4);AT 9,21;B$(5);AT 9,25;B$(6);AT 9,29;B$(7);AT 13,17;B$(8);AT 13,21;B$(9);AT 13,25;B$(10);AT 13,29;B$(11);AT 17,17;B$(12);AT 17,21;B$(13);AT 17,25;B$(14);AT 17,29;B$(15)
2020 SLOW
2030 RETURN
3000 PRINT AT X,Y;"█";AT X,Y;"[▒]";AT X,Y;" "
3010 LET Y$=INKEY$ 
3020 IF CODE Y$=54 THEN GOTO 40
3030 IF CODE Y$<33 OR CODE Y$>36 THEN GOTO 3000
3040 RETURN
3100 CLS
3110 PRINT ,,"   YOU GOT IT IN ";M;" MOVES."
3120 PAUSE 500
4130 IF M<S THEN LET S=M
4140 PRINT ,,"BEST SCORE IS ";S
4150 GOTO 40
9998 SAVE "FIFTEE[N]"
9999 GOTO 1

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