--- title: "Backgammon" id: 51705 type: "computer_media" slug: "backgammon" url: "http://localhost/computer_media/backgammon/" markdown_url: "http://localhost/computer_media/backgammon.md" published_at: "2023-08-13T23:14:28+00:00" modified_at: "2026-04-03T07:59:18+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "A full Backgammon implementation with four skill levels, animated dice, a doubling cube, gammon/backgammon scoring, and a machine code AI that evaluates positions before making its moves." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "Timex Computer Corporation" slug: "timex-computer-corporation" taxonomy: "post_tag" url: "http://localhost/tag/timex-computer-corporation/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_type: "Cassette" download_url: "https://archive.org/download/timex-sinclair-software-archive/Backgammon (1981)(Timex)(TS1000)(Cassette).zip" mediadate: "1981" producer_company: - id: 11401 title: "Timex Computer Corporation" type: "company" url: "http://localhost/company/timex-computer-corporation/" related_products: - id: 11859 title: "Backgammon and Dice" type: "product" url: "http://localhost/product/backgammon-and-dice/" media_type_tags: "Game" --- This program implements a full two-player Backgammon game where one player competes against a computer opponent, with four selectable skill levels that scale the computer’s lookahead depth via the variable LMX (10×2^(SKL−1) iterations). The game supports standard Backgammon rules including doubles, the bar, bearing off, gammon, and backgammon scoring, as well as a doubling cube mechanic that triggers a computer evaluation routine before accepting or declining. Dice rolling is animated using POKE instructions to memory addresses 16514 and 16515 combined with USR calls to a machine code routine at 16523, and the board display is rendered entirely in character graphics using block graphic characters for point markers and piece counters. Multiple USR calls throughout the program (at addresses 16639, 16642, 16645, 16648, 17348, 17351, and 17354) delegate move generation, board evaluation, and input handling to embedded machine code routines. The board position is tracked using arrays Z(24) and Y(24) for the computer and player respectively, with centroid variables ZC and YC used as heuristic position scores for the AI evaluation function. *** ## Program Analysis ### Program Structure The program is organized into clearly separated subroutine blocks identified by their line number ranges: | Line Range | Purpose | | --- | --- | | 1 | REM block containing embedded machine code (tokenized data) | | 10–14 | Initialization: GOSUB to setup, DIM arrays P, Q, D | | 150–800 | Main game loop: scoring display, skill/mode selection, doubling | | 900–960 | Key input subroutine using USR and INKEY$ | | 1010–1570 | Game controller: turn sequencing, win detection, gammon/backgammon detection | | 2000–2800 | Human player move processing, legal move validation | | 2800–2990 | Player move candidate finder (used by AI lookahead) | | 3000–3350 | Computer turn: AI move search loop with FAST/SLOW mode switching | | 4000–4900 | Doubling cube offer evaluation and accept/reject logic | | 5000–5350 | Position scoring subroutine, calls machine code evaluator | | 5500–5690 | Pip count calculator for both sides | | 5900–5940 | Utility: assigns minimum of YC/ZC to P | | 6000–6395 | AI move tree traversal / candidate move generator | | 6800–6990 | Machine code interface stubs for board update (make/unmake move) | | 7100–7190 | Bar display renderer | | 7500–7690 | Execute best move found by AI and update board display | | 8000–8090 | Display computer’s chosen moves | | 8200–8250 | Sort dice so larger value is D(1) | | 8300–8340 | Print doubling cube value | | 8500–8595 | Redraw a single board point (column) with piece counts | | 8600–8650 | Draw doubling cube area on screen | | 8700–8790 | Display message strings E$ and F$, clear them after | | 8800–8890 | Animated dice roll with POKE/USR rendering | | 8900–8990 | Set up initial board position and game state variables | | 9000–9390 | Draw static board graphic using a large PRINT statement | | 9710–9790 | Variable and array declarations | ### Machine Code Integration The program makes extensive use of `USR` calls to machine code routines stored in the `REM` statement at line 1. At least seven distinct entry points are used: - `USR 16523` — Renders a die face on screen using values POKEd into 16514/16515 - `USR 16639` — Appears to compute a penalty/noise term subtracted from the score T - `USR 16642` — Updates the internal board representation for a move (make or unmake depending on `BB`) - `USR 16645` — Finds a candidate source point for the computer’s move - `USR 16648` — Evaluates board features for the AI scoring function, populating `T(1)`, `T(2)`, `HI`, `ZO` - `USR 17348` — Formats a move as a string into `P$` - `USR 17354` — Appears to be a general utility, used both to flush display state and as a timing call - `USR 17351` — Reads player piece selection input, writing result into `N` The die animation at lines 8805–8870 is particularly notable: values are POKEd directly into addresses 16514 and 16515 before calling `USR 16523`, iterating 7 times to animate a spinning die effect before settling on the final `RND`-generated values. ### AI Search Algorithm The computer’s move selection (lines 3000–3350 and 6000–6395) implements an iterative deepening-style search. The outer loop at lines 3200–3290 runs up to `LMX` iterations (determined by skill level: 10, 20, 40, or 80), calling `GOSUB 6000` to generate candidate moves and `GOSUB 5000` to score them. The best position found is saved via `GOSUB 3900` into the Q array. The search is accelerated using `FAST` mode at line 3190 when `FST=1`, and `SLOW` is restored at line 3300 before displaying results. The position scoring function at line 5000 calls `USR 16648` to populate feature variables, then computes a weighted sum: `T = 9*T(2) + 36*HI + ZO`, with an optional blot/wastage penalty `XP*T(1) + WB` applied when `BB=1` (indicating a blot was hit). The sign of `T` is compared against `F` (current best) to decide whether to save the candidate. ### Board Representation The 24 points are stored in arrays `Y(24)` (human, moving from point 1 toward 24) and `Z(24)` (computer, moving in the opposite direction). Piece counts on the bar are held in `YB` and `ZB`. The variables `YC` and `ZC` are running centroid accumulators — each piece’s position weighted toward the home board — used as fast proxies for pip count in the heuristic. `YN` and `ZN` count pieces remaining to be borne off (starting at 15); they decrement to 0 (all borne off) or go negative on a win. ### Doubling Cube The doubling cube is tracked by `DD` (current stake, starting at 1) and `DC` (ownership: 0=centered, 1=player owns, -1=computer owns). The computer’s decision to offer a double (lines 4100–4580) evaluates pip difference and a weighted formula involving `P` (the minimum pip count) to determine when to offer. The player may accept (`R$="A"`) or reject (`R$="R"`); rejection sets `ZN=-1`, immediately awarding the game. The player may offer a double during their turn by pressing `D` (lines 2025–2080), which triggers `GOSUB 4000` for the computer’s accept/reject evaluation before proceeding. ### Display Rendering The static board is drawn once at `GOSUB 9000` using a single large `PRINT` statement at line 9050 that fills all 17 screen rows simultaneously with block graphics. Individual point updates are handled by the `GOSUB 8500` subroutine (lines 8500–8595), which calculates the screen column `X` from point number `N` using two different formulas for upper (N≤12) and lower (N>12) halves of the board, then prints stacked piece symbols up to a cap of 7 visible pieces, using `CHR$ (CODE R$-24)` to switch to a compact representation for overflow counts. The bar (middle column) is redrawn by `GOSUB 7100` whenever a piece is hit. ### Key BASIC Idioms - `LET LMX=10*2**(SKL-1)` — Exponential scaling of search depth by skill level using integer exponentiation - `LET DD=1.5*DD` at lines 1452 and 1550 — Backgammon bonus multiplies stake by 1.5 (not always an integer, which could cause non-integer scores) - `CODE R$-28` at line 310 — Converts keypress character code to numeric digit 1–4 using ZX81 character encoding offset - `DIM E$(20)` / `DIM F$(20)` — Fixed-length strings used as message buffers, cleared by reassignment to `""` - `IF INKEY$="" THEN GOTO 920` — Busy-wait loop for keypress in the input subroutine - `LET R=3-R` — Toggles R between 1 and 2 to alternate between the two dice ### Notable Anomalies Line 2550 is referenced by a `GOTO 2550` at line 2500 but the listing shows line 2555 as the nearest line; there is no line 2550, so execution falls through to 2555. This appears to be an intentional fall-through after the off-board bearing-off check at line 2500. Similarly, line 2600 is targeted by `GOTO 2600` at lines 2132 and 2294, but the nearest defined line is 2610 — another deliberate skip to the “YOU CAN NOT MOVE” message at 2610. The variable `Q` is used both as a scalar (board position index, e.g. lines 6020, 6060) and as an array `Q(4,2)` (best move storage). In ZX81 BASIC this is legal since array and scalar namespaces for single-letter variables are distinct, but it is unusual and could cause confusion. At line 2580, `CHR$ (I+37)` converts a point number to a letter character to display in error messages like “WHAT ABOUT F” — the offset 37 maps point 19 to ASCII code 56 (“8”), suggesting the labeling matches the board column letters printed in the static display rather than raw point numbers. ## Source Code ``` 1 REM ▌.7▀#▘#68LN [H]RNDU▄RND:▖ACS #C▝:▗U▙RND NEW▛COS #ACS #4▘WLN [V]RND#X( RAND TAN : ▞▛Y WLN [V]RND#( RAND TAN PRINT - #5▄RND;U▄RND▚#- E£RND;)#▝; LET TAN "£$??)▞▞▌▀▝▀▛(J▝▞ ?▖▖▖▞~~▒▞▖▝▝▝▝▝▝▝▝▝▝▖▌▀▝▝▝#1PI#NOT PI###5 6▙RND6 SLOWRNDY▘M STEP RNDM LPRINT RNDWM LLIST RND5▌▘LN #INKEY$ VAL 5<▘LN #INKEY$ LPRINT ,,#[P]C,,Y▘M▄RNDWM LPRINT RND5£▘LN #INKEY$ #M▙RNDLN [7]INKEY$ GOSUB # SLOWRND▞ 5E▘LN ▄INKEY$ TAN XCOS )▌ ;X4 UNPLOT TAN FAST GOSUB #(RND,,# NEW##: C-7# PLOT █#7#5 ACS 7ACS >ACS +ACS =( PLOT ## LPRINT TAN FASTVAL #[L]C$Y[)]ACS 5ACS (XK RAND ACS SACS ; GOSUB #(RND;#7#7#AT LPRINT TAN 5▞ LN ACS PI4=Y▝M LLIST RND5▜ LN ACS PIC-Y▝M LPRINT RND/?U LPRINT RNDXM SLOWRND$4▒Y▝M LLIST RND#>PIU▙RND[R]Y▝C"5 NEWRND GOSUB # STEP RND- ;##- U LLIST RND#5 ;( CLEAR FAST52▘U LPRINT RNDLN #INKEY$ LN #INKEY$ LPRINT ,,##52▘U LPRINT RNDLN #INKEY$ LN ▄INKEY$ 5 LLIST RNDO5 STEP RNDOY;[Y]TAB [7]INKEY$ TAN Y▘M LPRINT RND5 6 LLIST RND5L▘LN #INKEY$ #M NEWRNDE STEP RND#6 STEP RND5▞ LN ACS PI$4#Y M▙RNDM SLOWRNDU▄RND[R]C>U LPRINT RND RETURN$K"▘PEEK RND#A ,,#M▙RND5 STEP RNDPC9U SLOWRNDWM SLOWRND RETURN$K,5▜ LN ACS PIC SCROLL▘PEEK RNDU SLOWRND#A ,,#5▙RND▚#/STR$ U▙RND[R]C;#U LPRINT RND#Y;[(]#5 - ;( CLEAR GOSUB # LLIST RND;6 LLIST RND5 LPRINT RNDOU NEWRNDW[Y]TAB MPI GOSUB # LLIST RNDTAN FAST5▙RNDACS #C▝ GOSUB #▟# LPRINT TAN U STEP RNDLN #INKEY$ LN #INKEY$ #[L]TAN 5E▘LN #INKEY$ #M▙RND5S▘LN #INKEY$ # RETURN;4(5 RETURN LN #INKEY$ Y COPYLN [X]PILN ▄INKEY$ /)M STEP RND5▞ LN ACS PIY COPYLN [X]PILN ▄INKEY$ 5Z▘LN #INKEY$ #M STEP RND[K]4?5#▘LN #INKEY$ Y▘LN [X]PILN ▄INKEY$ TAN 5▞ LN ACS PIY▘LN [X]PILN ▄INKEY$ 5▜ LN ACS PICOS 5<▘LN #INKEY$ U STEP RNDLN [X]PILN ▄INKEY$ TAN 5#▘LN #INKEY$ GOSUB # STEP RND5E▘LN #INKEY$ GOSUB #▙RND5▞ LN ACS PIC*U▙RND#U STEP RND[(]S6C05▜ LN EXP PI# RETURN▝S~~5 STEP RNDP4<=▘ TAN U STEP RND#▞ TAN Y▞/▀U STEP RND GOSUB # STEP RNDINKEY$ # GOSUB # STEP RND5 STEP RNDO# RETURN;C£5▞ LN ACS PIC LOAD ▘ TAN U LPRINT RND#▞ 5E▘#▄INKEY$ ###LN )#5#▘)#▝LN OR #5#▘)[.]▝ GOSUB #(RND,, FOR GOSUB #£RND,, FAST▞=Q 7( CLS LPRINT FOR FAST▘= ,,[J]▌F▖[Q]C CLS LPRINT FOR # RETURN=SQR ACS S#▞ ,, GOSUB #LEN =#▞ FOR GOSUB [K]TAN E(RND▘[5]▘,,#CHR$ A**W RETURN,SQR RETURN;4▘[J]▞ #5▗▘VAL VAL LN ▄INKEY$ 5S▘AT LN ▄INKEY$ 5[$]▘LN #INKEY$ LPRINT ,,##5Z▘LN ▄INKEY$ LN ## GOSUB #(RND5#▘,, FOR 5[/]▘,,▘▀ GOSUB [K]TAN )[/]▘E(RND; FOR 5S▘LN ##<5Z▘STR$ LN #INKEY$ #[R]C,, RETURN;S▀[J]/▝LEN 9SGN >TAN ▝ REM 10 GOSUB 9700 12 DIM P(4,2) 13 DIM Q(4,2) 14 DIM D(2) 150 LET ZSC=0 155 LET YSC=0 200 CLS 250 RAND 290 LET E$="ZX81 SKILL LEVEL?" 295 LET F$="PRESS 1,2,3 OR 4" 300 GOSUB 900 310 LET SKL=CODE R$-28 320 IF SKL<1 OR SKL>4 THEN GOTO 290 350 LET LMX=10*2**(SKL-1) 360 LET E$="FAST OR SLOW MODE?" 362 LET F$="PRESS F OR S" 370 GOSUB 900 382 LET FST=1 384 IF R$="S" THEN LET FST=0 410 CLS 420 PRINT AT 2,13;"SCORE" 422 PRINT AT 3,13;"~~~~~~~~~~" 430 PRINT AT 6,9;"YOU.......";YSC 440 PRINT AT 9,9;"ZX81......";ZSC 450 PRINT AT 14,0;"ZX81 SKILL LEVEL: ";SKL;TAB 27; 452 IF FST=0 THEN PRINT "SLOW" 454 IF FST=1 THEN PRINT " FAST" 460 LET E$="CHANGE SKILL LEVEL?" 462 LET F$="PRESS Y OR N" 470 GOSUB 900 480 IF R$="Y" THEN GOTO 200 500 GOSUB 1000 800 GOTO 400 900 LET T=USR 17354 920 IF INKEY$ ="" THEN GOTO 920 930 LET R$=INKEY$ 940 IF R$=" " THEN GOTO 920 950 LET E$="" 952 LET F$="" 960 RETURN 1010 GOSUB 9000 1220 GOSUB 8800 1223 GOSUB 8900 1225 IF M=2 THEN GOTO 1300 1230 LET DD=2 1240 PRINT AT 8,15;"02" 1250 GOSUB 8800 1260 IF M=4 THEN GOTO 1250 1300 IF D(1)>D(2) THEN GOTO 1305 1301 GOSUB 2125 1302 GOTO 1340 1305 GOSUB 3030 1310 GOSUB 2000 1320 IF YN<1 THEN GOTO 1410 1340 GOSUB 3000 1350 IF ZN<1 THEN GOTO 1510 1400 GOTO 1310 1410 LET F$="" 1415 LET S$="YOU WIN" 1420 IF YN<0 OR ZN<15 THEN GOTO 1460 1425 LET F$="GAMMON" 1430 LET DD=2*DD 1435 IF ZB>0 THEN GOTO 1450 1440 FOR I=18 TO 24 1441 IF Z(I)>0 THEN GOTO 1447 1442 NEXT I 1445 GOTO 1460 1450 LET F$="BACKGAMMON" 1452 LET DD=1.5*DD 1460 LET YSC=YSC+DD 1470 LET S$=S$+" "+STR$ DD+" POINT" 1475 IF DD>1 THEN LET S$=S$+"S" 1476 LET E$=S$ 1480 GOSUB 8700 1482 PAUSE 999 1490 RETURN 1510 LET F$="" 1515 LET S$="I WIN" 1520 IF ZN<0 OR YN<15 THEN GOTO 1560 1530 LET DD=2*DD 1532 LET F$="GAMMON" 1535 IF YB>0 THEN GOTO 1550 1540 FOR I=1 TO 6 1541 IF Y(I)>0 THEN GOTO 1550 1542 NEXT I 1545 GOTO 1560 1550 LET DD=1.5*DD 1552 LET F$="BACKGAMMON" 1560 LET ZSC=ZSC+DD 1570 GOTO 1470 2010 LET E$="PRESS A KEY" 2015 GOSUB 900 2017 LET U=USR 17354 2020 RAND 2025 IF R$<>"D" OR DC=1 THEN GOTO 2120 2030 LET E$="I WILL CONSIDER" 2032 LET F$="YOUR OFFER" 2035 GOSUB 8700 2050 GOSUB 4000 2060 IF YN<0 THEN RETURN 2065 LET E$="I ACCEPT" 2067 GOSUB 8700 2070 LET DC=1 2075 LET DD=2*DD 2080 GOSUB 8600 2090 PRINT AT 2,15; 2095 GOSUB 8300 2120 GOSUB 8800 2125 LET M1=M 2126 LET G=1 2127 LET R=1 2128 LET F=0 2129 GOSUB 8200 2130 GOSUB 2800 2132 IF J<0 THEN GOTO 2600 2145 LET P=D(R) 2147 LET E$="YOUR MOVE WITH THE "+STR$ P 2157 GOSUB 900 2160 LET N=-1 2161 LET U=USR 17351 2164 IF N<0 THEN GOTO 2190 2165 LET E$="PRESS NEW LINE" 2170 GOSUB 900 2171 IF CODE (R$)<>118 THEN GOTO 2160 2172 LET E$="" 2173 LET F$=P$ 2174 GOSUB 8700 2175 IF N>0 THEN GOTO 2200 2178 IF YB=0 THEN GOTO 2212 2180 IF Z(P)>1 THEN GOTO 2232 2181 LET YC=YC-25 2182 LET YB=YB-1 2184 GOSUB 7100 2186 LET N=P 2188 GOTO 2260 2190 IF R$<>"Z" THEN GOTO 2147 2192 IF F=0 THEN LET R=3-R 2197 GOTO 2145 2200 IF YB=0 THEN GOTO 2210 2202 LET F$="YOU ARE ON THE BAR" 2203 GOSUB 8700 2204 GOTO 2145 2210 IF Y(N)>0 THEN GOTO 2220 2212 LET F$="NOTHING THERE" 2214 GOTO 2203 2220 IF N+P<25 THEN GOTO 2230 2221 IF LP>18 THEN GOTO 2500 2222 GOSUB 2740 2223 IF LP>18 THEN GOTO 2500 2224 LET F$="OFF THE BOARD" 2226 GOTO 2203 2230 IF Z(N+P)<2 THEN GOTO 2240 2232 LET F$="BLOCKED" 2234 GOTO 2203 2250 LET Y(N)=Y(N)-1 2251 LET YC=YC-25+N 2252 GOSUB 8500 2255 LET N=N+P 2257 LET FLG=0 2260 IF Z(N)<>1 THEN GOTO 2280 2264 LET Z(N)=0 2267 LET ZC=ZC+25-N 2268 LET ZB=ZB+1 2269 LET FLG=1 2280 LET Y(N)=Y(N)+1 2281 LET YC=YC+25-N 2282 GOSUB 8500 2283 IF FLG=1 THEN GOSUB 7100 2285 LET G=G+1 2290 LET R=3-R 2291 LET F=1 2292 IF YN=0 THEN RETURN 2293 IF G>M THEN RETURN 2294 IF G>M1 THEN GOTO 2600 2295 GOTO 2130 2500 IF N+P>25 THEN GOTO 2550 2510 LET YN=YN-1 2520 LET Y(N)=Y(N)-1 2530 LET YC=YC-25+N 2540 GOTO 2282 2555 FOR I=19 TO N-1 2560 IF Y(I)>0 THEN GOTO 2580 2569 NEXT I 2570 GOTO 2510 2580 LET F$="WHAT ABOUT "+CHR$ (I+37) 2590 GOTO 2203 2610 LET E$="YOU CAN NOT MOVE" 2620 GOTO 8700 2700 LET J=-2 2710 IF YB=0 THEN GOTO 2735 2715 IF Z(P)>1 THEN RETURN 2720 LET J=0 2725 RETURN 2735 IF LP>0 THEN GOTO 2747 2740 FOR I=1 TO 24 2742 IF Y(I)=0 THEN GOTO 2746 2744 LET LP=I 2745 GOTO 2747 2746 NEXT I 2747 IF LP<25-P THEN GOTO 2750 2748 LET J=LP 2749 RETURN 2750 FOR I=LP TO 24-P 2752 IF Y(I)=0 THEN GOTO 2759 2754 IF Z(I+P)>1 THEN GOTO 2759 2756 LET J=I 2758 RETURN 2759 NEXT I 2770 FOR I=LP TO 24-P 2772 IF Y(I)>0 THEN RETURN 2774 NEXT I 2780 LET J=25-P 2790 RETURN 2805 IF G=1 THEN LET LP=0 2810 IF M=2 THEN GOTO 2820 2811 LET P=D(1) 2815 GOTO 2700 2820 IF G=2 THEN RETURN 2825 FOR S=1 TO 2 2827 LET T(S)=0 2830 LET P=D(S) 2831 GOSUB 2700 2835 LET N=J 2836 LET Q=N+P 2838 IF N<0 THEN GOTO 2860 2840 LET T=1 2842 GOSUB 2950 2844 LET T(S)=1 2845 LET P=D(3-S) 2846 GOSUB 2700 2848 IF J<0 THEN GOTO 2855 2850 LET T(S)=2 2855 IF N<0 THEN GOTO 2860 2856 LET T=-1 2858 GOSUB 2950 2860 NEXT S 2862 IF T(1)=0 AND T(2)=0 THEN RETURN 2865 IF T(1)=2 AND T(2)=2 THEN RETURN 2867 LET F=1 2868 LET J=1 2870 IF T(1)=2 OR T(2)=2 THEN GOTO 2890 2871 LET M1=1 2872 IF T(1)=0 THEN LET R=2 2880 RETURN 2891 IF T(2)=2 THEN LET R=2 2895 RETURN 2955 IF N=0 THEN LET YB=YB-T 2960 IF N>0 THEN LET Y(N)=Y(N)-T 2965 IF Q<25 THEN LET Y(Q)=Y(Q)+T 2990 RETURN 3000 GOSUB 4100 3001 IF ZN<0 THEN RETURN 3005 LET E$="MY THROW" 3010 GOSUB 8700 3020 GOSUB 8800 3025 GOSUB 8200 3030 LET G=0 3031 LET M1=1 3032 LET F=-9999 3034 LET HI=0 3035 LET WB=0 3036 LET ZO=0 3040 FOR I=1 TO 4 3042 LET Q(I,1)=0 3044 LET Q(I,2)=0 3045 NEXT I 3055 LET WW=1 3057 LET LP=18 3060 LET XP=3 3062 LET WB=0 3065 LET SM=D(1)+D(2) 3070 IF D(1)=D(2) THEN LET SM=2*SM 3075 LET SM=SM+YC-ZC 3080 IF SM<(3*ZC+380)/40 THEN GOTO 3100 3085 LET WB=-999 3087 LET LP=15 3090 LET WW=0 3095 LET XP=9 3100 GOSUB 8750 3105 GOSUB 8700 3120 GOSUB 6000 3125 IF G=0 THEN GOTO 3300 3130 GOSUB 5000 3135 GOSUB 3900 3140 LET LM=2 3190 IF FST=1 THEN FAST 3200 GOSUB 6000 3210 IF GF OR G>M1 THEN GOSUB 3900 3280 LET LM=LM+1 3290 IF LM<=LMX THEN GOTO 3200 3300 SLOW 3310 GOSUB 8000 3330 GOSUB 7500 3350 RETURN 3910 LET F=T 3915 LET M1=G 3920 FOR I=1 TO M 3925 LET Q(I,1)=P(I,1) 3930 LET Q(I,2)=P(I,2) 3935 NEXT I 3990 RETURN 4010 GOSUB 5900 4020 IF P<55 THEN GOTO 4050 4030 IF ZC-YC>(3*P+220)/40 THEN LET YN=-1 4040 RETURN 4050 GOSUB 5500 4060 IF N-M>1+INT (M/6) THEN LET YN=-1 4090 RETURN 4140 IF DC=-1 THEN RETURN 4150 IF ZC>YC THEN RETURN 4160 GOSUB 5900 4165 IF P>110 THEN RETURN 4175 IF P<55 THEN GOTO 4250 4180 LET N=YC-ZC 4190 IF N<(3*P+100+100*DC)/40 THEN RETURN 4200 IF YN=15 AND N>35 THEN RETURN 4210 GOTO 4300 4250 GOSUB 5900 4260 LET N=M-N 4270 IF N<2 THEN RETURN 4280 IF YN=15 AND N>12 THEN RETURN 4310 FOR I=24 TO 18 STEP -1 4320 IF Z(I)>0 THEN GOTO 4350 4325 NEXT I 4330 GOTO 4500 4350 LET N=0 4360 FOR J=12 TO I 4365 IF Y(J)>1 THEN LET N=N+1 4370 NEXT J 4380 IF N>3 THEN RETURN 4510 LET E$="DOUBLE? ENTER A OR R" 4512 LET F$="TO ACCEPT OR REJECT" 4515 GOSUB 8700 4520 INPUT R$ 4525 IF R$<>"R" THEN GOTO 4550 4530 LET ZN=-1 4540 RETURN 4550 LET DD=2*DD 4560 LET DC=-1 4570 GOSUB 8600 4574 PRINT AT 11,0 4580 GOSUB 8300 4900 RETURN 5015 LET BB=0 5025 LET T(1)=0 5030 LET T(2)=0 5100 LET U=USR 16648 5260 LET T=9*T(2)+36*HI+ZO 5270 IF BB=1 THEN LET T=T+XP*T(1)+WB 5290 IF T<=F THEN RETURN 5300 LET U=USR 16639 5310 LET T=T-U 5350 RETURN 5560 LET M=0 5570 LET N=0 5600 FOR I=1 TO 24 5605 LET J=INT ((I-1)/4+1) 5610 LET N=N+Z(I)*J 5620 LET M=M+Y(I)*J 5630 NEXT I 5650 LET N=N+ZB*7 5660 LET M=M+YB*7 5690 RETURN 5910 LET P=YC 5920 IF ZC>P THEN RETURN 5930 LET P=ZC 5940 RETURN 6010 IF G>0 THEN GOTO 6250 6015 LET R=1 6016 LET G=1 6020 LET Q=24 6030 LET JL=Q 6032 LET P=D(R) 6034 IF G<>1 THEN LET P=D(3-R) 6040 IF ZB=0 THEN GOTO 6050 6042 LET S=25-P 6043 IF Y(S)>1 THEN GOTO 6225 6044 LET P(G,1)=25 6045 LET P(G,2)=S 6049 GOTO 6200 6050 LET BB=P 6060 LET Q=USR 16645 6070 IF Q=0 THEN GOTO 6225 6080 LET S=Q-BB 6100 LET P(G,1)=Q 6112 LET P(G,2)=S 6210 GOSUB 6800 6215 IF G=M THEN RETURN 6220 LET G=G+1 6222 GOTO 6030 6225 IF G>M1 THEN GOTO 6380 6230 IF G=1 THEN GOTO 6350 6236 LET G=G-1 6250 GOSUB 6900 6251 IF P(G,1)=25 THEN GOTO 6350 6252 IF P(G,2)=0 THEN GOTO 6230 6255 LET JL=P(G,1)-1 6260 IF JL<1 THEN GOTO 6230 6270 LET P=D(R) 6275 IF G<>1 THEN LET P=D(3-R) 6290 GOTO 6050 6350 IF M=4 OR R=2 THEN GOTO 6365 6355 LET R=2 6360 IF G=1 THEN GOTO 6020 6362 GOSUB 6900 6363 LET G=G-1 6364 GOTO 6360 6370 IF G=1 THEN GOTO 6380 6371 GOSUB 6900 6372 LET G=G-1 6375 GOTO 6365 6380 FOR I=G TO M 6385 LET P(I,1)=0 6386 LET P(I,2)=0 6390 NEXT I 6393 LET G=G-1 6395 RETURN 6810 LET P1=P(G,1) 6811 LET P2=P(G,2) 6820 LET BB=0 6830 LET BB=USR 16642 6890 RETURN 6910 LET P1=P(G,1) 6911 LET P2=P(G,2) 6920 LET BB=1 6930 LET BB=USR 16642 6990 RETURN 7115 PRINT AT 8,1;"[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]";TAB 18;"[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]" 7120 IF ZB=0 THEN GOTO 7150 7125 PRINT AT 8,14-ZB; 7130 FOR I=1 TO ZB 7135 PRINT "[O]"; 7140 NEXT I 7150 IF YB=0 THEN RETURN 7155 PRINT AT 8,18; 7160 FOR I=1 TO YB 7165 PRINT "O"; 7170 NEXT I 7190 RETURN 7520 IF G=0 THEN GOTO 7550 7525 GOSUB 6900 7530 LET G=G-1 7535 GOTO 7520 7550 FOR Q=1 TO M 7555 LET P1=Q(Q,1) 7560 LET P2=Q(Q,2) 7562 IF P1=P2 THEN GOTO 7655 7565 GOSUB 6820 7568 LET ZC=ZC+P2-P1 7570 LET N=P1 7575 IF N<25 THEN GOTO 7595 7580 GOSUB 7100 7590 GOTO 7600 7595 GOSUB 8500 7600 LET N=P2 7605 IF N>0 THEN GOTO 7610 7606 LET ZN=ZN-1 7607 GOTO 7650 7610 LET FLG=0 7615 IF Y(N)=0 THEN GOTO 7630 7620 LET Y(N)=0 7621 LET YC=YC+N 7623 LET YB=YB+1 7625 LET FLG=1 7630 GOSUB 8500 7635 IF FLG=1 THEN GOSUB 7100 7650 NEXT Q 7690 RETURN 8000 LET E$="MY MOVES ARE" 8010 LET F$="" 8025 IF Q(1,1)=Q(1,2) THEN LET F$="I CAN NOT MOVE" 8030 FOR I=1 TO M 8035 LET P1=Q(I,1) 8036 LET P2=Q(I,2) 8037 IF P1=P2 THEN RETURN 8038 LET U=USR 17348 8039 LET F$(4*I-3 TO 4*I)=P$ 8040 NEXT I 8045 LET U=USR 17354 8090 RETURN 8210 IF D(1)>D(2) THEN RETURN 8220 LET BB=D(1) 8230 LET D(1)=D(2) 8240 LET D(2)=BB 8250 RETURN 8310 LET P$=STR$ (100+DD) 8330 PRINT TAB 15;"▀▀" 8332 PRINT TAB 15;P$(2 TO 3) 8334 PRINT TAB 15;"▄▄" 8340 RETURN 8501 LET JL=Y(N)+Z(N) 8502 LET BB=JL 8503 IF JL>7 THEN LET JL=7 8507 LET R$="O" 8508 IF Z(N)>0 THEN LET R$="[O]" 8510 IF N>12 THEN GOTO 8550 8511 LET X=31-2*N-5*INT (N/7) 8512 IF JL=0 THEN GOTO 8530 8515 FOR J=1 TO JL 8516 PRINT AT J,X;R$ 8517 NEXT J 8520 IF JL=BB THEN GOTO 8530 8521 LET S=BB-JL 8522 LET R$=CHR$ (CODE R$-24) 8525 FOR J=1 TO S 8526 PRINT AT J,X;R$ 8527 NEXT J 8529 RETURN 8530 LET S=JL+1 8531 IF S>7 THEN RETURN 8532 FOR J=S TO 7 8534 PRINT AT J,X;"[▒]" 8535 NEXT J 8545 RETURN 8550 LET X=2*(N-12)+5*INT (N/19) 8551 IF JL=0 THEN GOTO 8570 8555 FOR J=1 TO JL 8556 PRINT AT 16-J,X;R$ 8557 NEXT J 8560 IF JL=BB THEN GOTO 8570 8561 LET S=BB-JL 8562 LET R$=CHR$ (CODE R$-24) 8565 FOR J=1 TO S 8566 PRINT AT 16-J,X;R$ 8567 NEXT J 8569 RETURN 8570 LET S=JL+1 8572 IF S>7 THEN RETURN 8575 FOR J=S TO 7 8576 PRINT AT 16-J,X;"[▒]" 8577 NEXT J 8595 RETURN 8610 PRINT AT 0,0; 8620 FOR I=1 TO 15 8630 PRINT TAB 15;"██" 8640 NEXT I 8650 RETURN 8710 LET U=USR 17354 8755 LET E$="" 8760 LET F$="" 8790 RETURN 8805 FOR I=1 TO 7 8810 LET D(1)=INT (RND*6+1) 8820 LET D(2)=INT (RND*6+1) 8825 FOR J=0 TO 1 8830 POKE 16514,J*D(1) 8832 POKE 16515,0 8834 LET P=USR 16523 8840 POKE 16514,J*D(2) 8842 POKE 16515,27 8844 LET P=USR 16523 8850 NEXT J 8870 NEXT I 8880 LET M=2 8882 IF D(1)=D(2) THEN LET M=4 8890 RETURN 8910 FOR I=1 TO 24 8920 LET Z(I)=0 8925 LET Y(I)=0 8930 NEXT I 8940 LET Y(1)=2 8942 LET Z(6)=5 8944 LET Z(8)=3 8946 LET Y(12)=5 8948 LET Z(13)=5 8950 LET Y(17)=3 8952 LET Y(19)=5 8954 LET Z(24)=2 8960 LET ZN=15 8962 LET YN=15 8963 LET ZC=167 8964 LET YC=167 8965 LET ZB=0 8966 LET YB=0 8967 LET DD=1 8968 LET DC=0 8990 RETURN 9000 CLS 9050 PRINT "██[L]█[K]█[J]█[I]█[H]█[G]██████[F]█[E]█[D]█[C]█[B]█[A]███[▒]O[▒][▒][▒][▒][▒][▒][▒][O][▒][▒][▒]████[▒][O][▒][▒][▒][▒][▒][▒][▒][▒][▒]O[▒]██[▒]O[▒][▒][▒][▒][▒][▒][▒][O][▒][▒][▒]████[▒][O][▒][▒][▒][▒][▒][▒][▒][▒][▒]O[▒]██[▒]O[▒][▒][▒][▒][▒][▒][▒][O][▒][▒][▒]████[▒][O][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒]O[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]████[▒][O][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒]O[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]████[▒][O][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]████[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]█▀▀█[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]█64█[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]█▄▄█[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]████[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][O][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]████[▒]O[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][O][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]████[▒]O[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][O][▒][▒][▒][▒][▒][▒][▒]O[▒][▒][▒]████[▒]O[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]██[▒][O][▒][▒][▒][▒][▒][▒][▒]O[▒][▒][▒]████[▒]O[▒][▒][▒][▒][▒][▒][▒][▒][▒][O][▒]██[▒][O][▒][▒][▒][▒][▒][▒][▒]O[▒][▒][▒]████[▒]O[▒][▒][▒][▒][▒][▒][▒][▒][▒][O][▒]███[M]█[N]█[O]█[P]█[Q]█[R]██████[S]█[T]█[U]█[V]█[W]█[X]██" 9075 PRINT "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌ ████[P][S][I][O][N]█[B][A][C][K][G][A][M][M][O][N]████ ▐▌ ██ <- ZX81 YOU -> ██ ▐▌ ██ ██ ▐▙▄▄▄████████████████████████▄▄▄▟" 9390 RETURN 9710 DIM Z(24) 9711 DIM Y(24) 9712 LET ZB=0 9713 LET YB=0 9714 LET WW=0 9715 LET HI=0 9716 DIM T(2) 9717 LET BB=0 9718 LET LP=0 9719 LET P1=0 9720 LET P2=0 9721 LET ZO=0 9722 LET JL=0 9723 DIM E$(20) 9724 DIM F$(20) 9725 LET N=0 9726 LET P=0 9727 DIM P$(3) 9728 DIM R$(1) 9790 RETURN ```