This file is part of Synchro-Sette May 1984. Download the collection to get this file.
A two-player game against the computer, played with the sixteen hexadecimal digits 0–F. The digits are shuffled into a row beneath a row of position labels, and the players take turns swapping any two of them by typing the two positions. A point is scored for each digit a swap puts into its proper position, and the game ends when the row is back in order, with the higher score winning.
Program Analysis
Program Structure
- Shuffle (lines 10–96): the sixteen inverse digits in
A$are placed at random positions inB$, retrying any slot that is already filled, while a counter shows progress on an “Initializing” screen. - Player move (lines 2000–2190): two keypresses with character codes 28–43 (
0–9,A–F) select the positions. The digits are swapped, and the score goes up by one for each digit that lands on its own inverse code. - Computer move (lines 3000–3300): finds the first digit out of place, then looks for a pair of digits that are in each other’s positions. If there is one it swaps them for 2 points, and if not it fetches the digit that belongs in the first wrong position for 1 point.
- End (lines 5000–5060): the scores are compared and the program offers another game.
Notable Techniques
- Each board digit is stored as its inverse character, so checking whether it is in place is just a comparison with
CHR$ (CODE E$+128), the inverse form of the position key. - Position keys are converted directly to indexes with
CODE E$-27.
Potential Issues
- The computer always scores at least one point per move and takes two-point swaps whenever they exist. A human can make a swap that scores nothing, or even move a correct digit out of place, without penalty, so the contest favours the computer.
Source Code
10 LET A$="[0][1][2][3][4][5][6][7][8][9][A][B][C][D][E][F]"
15 PRINT AT 10,8;"█[I][N][I][T][I][A][L][I][Z][I][N][G]█"
20 DIM B$(16)
30 FOR N=1 TO 16
40 LET A=INT (RND*16)+1
45 PRINT AT 12,14;N
50 IF B$(A)<>" " THEN GOTO 40
60 LET B$(A)=A$(N)
70 NEXT N
80 LET C$="0123456789ABCDEF"
90 LET S$=B$
95 LET HS=0
96 LET CS=0
100 DIM T$(30)
105 CLS
110 PRINT ,,,,"DO YOU WANT TO GO FIRST?"
120 LET Y$=INKEY$
130 IF Y$="" THEN GOTO 120
140 CLS
150 IF Y$<>"Y" THEN GOTO 2200
1000 CLS
1010 PRINT AT 1,0;"HUMAN - ";HS;AT 2,0;"COMPUTER - ";CS
1020 FOR N=1 TO 16
1030 PRINT AT 10,2*N-1;B$(N);AT 8,2*N-1;C$(N)
1040 NEXT N
2000 PRINT AT 19,0;"YOUR MOVE";AT 20,0;"FROM : ";
2010 LET D$=INKEY$
2020 IF CODE D$<28 OR CODE D$>43 THEN GOTO 2010
2030 PRINT D$,
2100 PRINT "TO : ";
2110 LET E$=INKEY$
2120 IF CODE E$<28 OR CODE E$>43 THEN GOTO 2110
2130 IF D$=E$ THEN GOTO 2110
2140 PRINT E$
2150 LET F$=B$(CODE E$-27)
2160 LET B$(CODE E$-27)=B$(CODE D$-27)
2170 LET B$(CODE D$-27)=F$
2180 IF CHR$ (CODE E$+128)=B$(CODE E$-27) THEN LET HS=HS+1
2190 IF CHR$ (CODE D$+128)=B$(CODE D$-27) THEN LET HS=HS+1
2200 PRINT AT 1,0;"HUMAN - ";HS;AT 2,0;"COMPUTER - ";CS
2210 FOR N=1 TO 16
2220 PRINT AT 10,2*N-1;B$(N);AT 8,2*N-1;C$(N)
2230 NEXT N
2240 IF B$=A$ THEN GOTO 5000
3000 FOR N=1 TO 16
3010 IF B$(N)<>A$(N) THEN GOTO 3100
3020 NEXT N
3100 FOR I=1 TO 16
3105 FOR J=I+1 TO 16
3110 IF B$(I)=CHR$ (155+J) AND B$(J)=CHR$ (155+I) THEN GOTO 3140
3115 NEXT J
3120 NEXT I
3130 GOTO 3150
3140 LET CS=CS+2
3142 LET N=J
3145 GOTO 3200
3150 LET CS=CS+1
3155 FOR I=1 TO 16
3160 IF B$(I)=CHR$ (155+N) THEN GOTO 3200
3170 NEXT I
3200 LET F$=B$(N)
3210 LET B$(N)=B$(I)
3220 LET B$(I)=F$
3230 PRINT AT 19,0;"I MOVE ";AT 20,0;"FROM : ";CHR$ (I+27),"TO : ";CHR$ (N+27)
3235 PRINT AT 1,0;"HUMAN - ";HS;AT 2,0;"COMPUTER - ";CS
3240 FOR N=1 TO 16
3250 PRINT AT 10,2*N-1;B$(N);AT 8,2*N-1;C$(N)
3260 NEXT N
3270 PAUSE 200
3280 IF B$=A$ THEN GOTO 5000
3290 PRINT AT 19,0;T$;AT 20,0;T$
3300 GOTO 1010
5000 PRINT AT 19,0;T$;AT 20,0;T$;AT 21,0;T$
5005 IF HS>CS THEN PRINT AT 20,0;"YOU WIN :::"
5010 IF CS>HS THEN PRINT AT 20,0;"I WIN :::"
5020 IF CS=HS THEN PRINT AT 20,0;"TIE SCORE :::"
5030 PRINT AT 21,0;"PRESS ENTER FOR ANOTHER GAME ::"
5040 PAUSE 40000
5050 CLS
5060 RUN
9998 SAVE "HEXE[R]"
9999 RUNNote: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
