--- title: "Cricket" id: 57526 type: "computer_media" slug: "cricket-2" url: "http://localhost/computer_media/cricket-2/" markdown_url: "http://localhost/computer_media/cricket-2.md" published_at: "2024-10-05T21:28:44+00:00" modified_at: "2026-04-03T07:58:24+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/281_Cric.png" excerpt: "A two-innings text cricket game with difficulty-controlled ball animation, off-side and on-side batting, and fielding outcomes including caught, dropped, and bowled." 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: "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_contents: - id: 56737 title: "Timex Sinclair Public Domain Library Tape 1006" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1006/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/281_Cric.png" media_type_tags: "Game" --- This program implements a two-team text cricket game where players deliver a ball by pressing “7” and attempt to hit it with “5” (off-side) or “8” (on-side). The difficulty level (1–3) controls the speed of the ball’s on-screen animation by varying the loop count in the FOR/NEXT delay at lines 120–122. Dismissal outcomes include being bowled (ball landing on the stumps at column B), caught behind (wrong-side shot), caught (random fielder), or dropped. The scoreboard uses a field diagram drawn with “O” and “A” characters to represent fielders, and the innings subroutine at 8505 also sets key variables M, A, and B used throughout the game. *** ## Program Analysis ### Program Structure The program is divided into several functional blocks: - **Lines 3–27:** Initialisation, key legend display, difficulty selection, and team name input. - **Lines 28–76:** Innings setup — selects which team bats, prints innings header, then jumps into the main input loop. - **Lines 95–1250:** Ball delivery animation loop — moves a `*` up the screen, optionally deflecting it laterally at step 10. - **Lines 1300–1308:** Bowled dismissal handling. - **Lines 2000–2250:** Fielding outcomes — caught or dropped, chosen randomly. - **Lines 3000–3035:** Caught-behind dismissal. - **Lines 4500–5000:** Delivery trigger — waits for key “7” before launching the ball. - **Lines 5005–6095:** Shot trajectory calculation and run scoring. - **Lines 6095–8000:** Scoreboard update and wicket/innings check. - **Lines 8200–8500:** Innings end, next innings, and match end handling. - **Lines 8505–8620:** Field-drawing subroutine and wicket-fall animation. - **Lines 8630–8680:** Match result and winner announcement. - **Lines 8680–8700:**`CLEAR` / `SAVE` / `RUN` block for saving the program. ### Difficulty and Timing Difficulty is selected as 1–3 and mapped to variable `P` at lines 15–17. `P` is used as the upper bound of an inner delay loop at lines 120–122: difficulty 1 gives `P=3` (slow), difficulty 2 gives `P=1` (medium), and difficulty 3 gives `P=-1` (the FOR loop body executes zero times, giving the fastest ball). This is a concise way to scale animation speed without separate code paths. ### Ball Delivery Animation The delivery loop runs from `N=1` to 20 (line 115), printing and erasing `*` at `PRINT AT X,Y`, moving `X` up the screen by one row each iteration. At `N=10` a lateral offset `Q=INT(RND*5-3)` is added to `Y`, simulating swing or spin. At `N=12` the batting window opens: pressing “5” or “8” depending on which side the ball is on routes to line 5001 (shot), while the wrong-side key routes to line 3000 (caught behind). Pressing “0” before step 12 (line 140) advances `N` to 13, acting as a leave/defensive shot. ### Shot and Run Calculation When a shot is played, lines 5005–5007 save the ball’s final position in `C` and `D`, then choose a random trajectory direction `H` (1–4) and a distance variable `S` (0–14). The ball is then animated in one of four diagonal directions across the field. Specific coordinate pairs at lines 6000–6015 represent fielding positions; hitting one triggers the caught/dropped subroutine at line 2000. At the end of the ball’s travel, `S` is mapped to runs by a series of range checks (lines 6061–6078), giving 1, 2, 3, 4, or 6 runs. ### Field Drawing Subroutine The subroutine at line 8505 draws the fielding positions using pairs of “O” (head) and “A” (body) characters at fixed `PRINT AT` coordinates. It also sets three variables critical to the game: `M=17` (bowler column), `A=5` (stumps row), and `B=15` (stumps column). The stumps are drawn at line 8525 as `"II"` at rows `A` and 21. This dual role — rendering and variable initialisation — is a common space-saving idiom. ### Wicket-Fall Animation Lines 8569–8620 handle a wicket animation: the bowler figure is shown with `"O"/"X"` at column `M`, then `M` is decremented 17 times in a loop, walking the figure across the screen. Variables `I` and `U` are assigned inside the loop (lines 8600 and 8607) but never used for any visible effect, suggesting leftover or placeholder code. The routine ends with `STOP` at line 8620, which appears to be a bug — execution should return to the caller after the animation, but instead halts the program. ### Bugs and Anomalies - **Line 85 vs 5001:** Line 140 jumps to `GOTO 85` (no-shot leave), but line 150/155 jump to `GOTO 5001` for a valid shot. Line 5001 does not exist; execution falls through to line 5005. This is intentional fall-through, not a bug. - **Line 85 missing:**`GOTO 85` at line 4510 targets a non-existent line. Execution falls through to line 95, resetting `K=0` — effectively restarting the delivery cycle. This is a deliberate technique. - **Line 860 placement:**`LET TT=2` at line 860 sits inside the delivery animation loop between lines 155–1200 and is reached on every delivery. `TT` is supposed to track the innings number, but it is set to 2 unconditionally here — meaning the second-innings flag is set on the very first delivery, breaking the innings logic at line 31. - **Line 8620 STOP:** The wicket-fall subroutine ends with `STOP` rather than `RETURN`, halting the game after every dismissal. Combined with the missing `GOSUB 8555` targets (line 8555 does not exist), dismissal handling is effectively broken. - **Line 8650 uses `Y(1)`:** The win calculation references `Y(1)`, which is undefined — `T(1)` was clearly intended, giving the wrong result or a variable error. - **Variable `D` reused:**`D` is used both for difficulty (lines 13–17) and for the ball’s column position during shot animation (line 5006 onwards), causing the difficulty value to be overwritten mid-game. ### Variable Summary | Variable | Purpose | | --- | --- | | `D` | Difficulty level (1–3); also reused as ball column in shot animation | | `P` | Delay loop limit (speed control) | | `T(O)` | Score for each team (array of 2) | | `H$(O)` | Team names (2×12 string array) | | `W` | Wickets fallen | | `R` | Runs scored from last shot | | `Z` | Runs since last wicket (partnership) | | `X,Y` | Ball row/column during delivery animation | | `C,D` | Ball row/column during shot animation | | `M` | Bowler/mid-wicket column | | `B` | Stumps column (set by subroutine at 8505) | | `S` | Random shot distance, mapped to runs | | `TT` | Innings counter (1 or 2) | | `O` | Current batting team index (1 or 2) | ## Source Code ``` 3 LET F=1 4 LET Z=0 5 PRINT AT 0,10;"CRICKET";AT 1,10;"~~~~~~~~~~~~~~" 7 PRINT AT 4,0;"7...FOR NEXT DELIVERY" 8 PRINT AT 7,0;"5...TO STRIKE BALL ON OFF-SLIDE" 9 PRINT AT 10,0;"8...TO STRIKE BALL ON ON-SIDE" 12 PRINT AT 16,0;"LEVEL OF DIFFICULTY? (1-3)" 13 INPUT D 14 IF D<1 OR D>3 THEN GOTO 12 15 IF D=1 THEN LET P=3 16 IF D=2 THEN LET P=1 17 IF D=3 THEN LET P=-1 19 DIM T(2) 20 DIM H$(2,12) 21 LET TT=1 22 FOR O=1 TO 2 23 PRINT AT 16,0;" " 25 PRINT AT 16,0;"WHICH TEAMS DO YOU WANT TO PLAY?" 26 INPUT H$(O) 27 NEXT O 28 LET O=1 31 IF TT=2 THEN LET O=2 32 PRINT AT 18,0;"INNINGS OF ";H$(O) 40 PAUSE 25 50 CLS 65 GOSUB 8505 72 LET RR=0 73 LET SS=0 74 LET W=0 75 LET R=0 76 GOTO 4500 95 LET K=0 100 LET X=19 110 LET Y=15 115 FOR N=1 TO 20 117 PRINT AT X,Y;"*" 120 FOR G=1 TO P 122 NEXT G 125 PRINT AT X,Y;" " 127 LET X=X-1 130 IF N=10 THEN LET Q=INT (RND*5-3) 135 IF N=10 THEN LET Y=Y+Q 140 IF N<>12 AND INKEY$="0" THEN LET N=13 145 IF X<=3 THEN LET X=3 150 IF N=12 AND Y<=15 AND INKEY$="5" THEN GOTO 5001 155 IF N=12 AND Y>=16 AND INKEY$="8" THEN GOTO 5001 160 IF Y<=14 AND N=12 AND INKEY$="8" THEN GOTO 3000 170 IF Y>=16 AND N=12 AND INKEY$="5" THEN GOTO 3000 860 LET TT=2 1200 NEXT N 1210 IF Y=B THEN GOTO 1300 1220 IF Y=B+1 THEN GOTO 1300 1250 GOTO 4500 1300 PRINT AT 13,13;"BOWLED" 1303 GOSUB 8555 1305 PRINT AT 13,13;" " 1308 GOTO 6095 2000 LET K=INT (RND*2)+1 2010 IF K=1 THEN GOTO 2200 2020 IF K=2 THEN GOTO 2050 2050 GOSUB 8555 2060 PRINT AT 13,13;"DROPPED" 2070 PAUSE 25 2080 PRINT AT 13,13;" " 2090 GOTO 6095 2200 PRINT AT 13,13;"CAUGHT" 2210 GOSUB 8555 2220 PRINT AT 13,13;" " 2250 GOTO 6095 3000 PRINT AT 3,15;"*";AT 13,0;"CAUGHT BEHIND" 3010 GOSUB 8555 3020 PRINT AT 3,15;" ";AT 13,0;" " 3035 GOTO 6095 4410 GOTO 4500 4500 PRINT AT 10,8;" " 4501 LET C$=INKEY$ 4505 INPUT C$ 4510 IF C$="7" THEN GOTO 85 4520 IF C$<>"7" THEN GOTO 4500 5000 GOTO 4500 5005 LET C=X 5006 LET D=Y 5007 LET S=INT (RND*15) 5008 LET H=INT (RND*4)+1 5015 FOR N=1 TO 9 5020 IF H=1 THEN GOTO 5100 5030 IF H=2 THEN GOTO 5110 5040 IF H=3 THEN GOTO 5120 5050 IF H=4 THEN GOTO 5130 5100 LET D=D-1 5102 LET C=C-1 5105 GOTO 6000 5110 LET D=D-1 5112 LET C=C+1 5115 GOTO 6000 5120 LET D=D+1 5122 LET C=C-1 5125 GOTO 6000 5130 LET D=D+1 5135 LET C=C+1 6000 IF C=2 AND D=9 THEN GOTO 2000 6005 IF C=10 AND D=10 THEN GOTO 2000 6010 IF C=0 AND D=20 THEN GOTO 2000 6015 IF C=15 AND D=22 THEN GOTO 2000 6040 PRINT AT C,D;"*" 6045 FOR Q=1 TO 3 6046 NEXT Q 6047 IF C<=0 THEN LET N=S 6048 IF C>=20 THEN LET N=S 6049 IF D<=0 THEN LET N=S 6050 PRINT AT C,D;" " 6055 GOSUB 8525 6060 NEXT N 6061 IF S>=0 AND S<=3 THEN LET R=1 6062 IF S>=4 AND S<=7 THEN LET R=2 6063 IF S>=8 AND S<=10 THEN LET R=3 6064 IF S>=11 AND S<=13 THEN LET R=4 6078 IF S>=14 THEN LET R=6 6082 PRINT AT 10,B;R 6084 PAUSE 10 6086 LET T(O)=T(O)+R 6087 LET Z=Z+R 6088 LET RR=T(O) 6095 PRINT AT 0,1;H$(O) 6096 PRINT AT 1,2;T(O) 6097 PRINT AT 2,1;"FOR" 6098 PRINT AT 3,2;W 6099 PRINT AT 10,0;"NO.";R;AT 11,3;Z 7000 IF W=10 THEN GOTO 8200 7010 GOSUB 8505 8000 GOTO 4500 8200 CLS 8210 PRINT AT 5,5;"ALL OUT" 8220 PRINT AT 7,5;H$(O);" SCORED ";T(O) 8222 IF O=2 THEN GOTO 8630 8250 PRINT AT 10,0;"PRESS ANY KEY FOR NEXT INNINGS" 8255 INPUT C 8300 CLS 8500 GOTO 28 8505 PRINT AT 1,15;"O";AT 2,15;"A";AT 0,13;"O";AT 1,13;"A" 8510 PRINT AT 4,27;"O";AT 5,27;"A";AT 17,7;"O";AT 18,7;"A" 8515 PRINT AT 5,5;"O";AT 6,5;"A";AT 20,14;"O";AT 21,14;"A" 8520 LET M=17 8521 LET A=5 8522 LET B=15 8525 PRINT AT A,B;"II";AT 21,B;"II" 8530 PRINT AT 7,M;"O";AT 8,M;"7";AT 8,16;"/" 8535 PRINT AT 2,9;"O";AT 3,9;"A";AT 10,10;"O";AT 11,10;"A" 8540 PRINT AT 1,11;"O";AT 2,11;"A" 8545 PRINT AT 0,20;"O";AT 1,20;"A";AT 15,22;"O";AT 16,22;"A" 8550 RETURN 8569 IF K=2 THEN RETURN 8575 LET W=W+1 8576 LET F=F+1 8577 LET Z=0 8578 LET SS=T(O) 8579 PRINT AT 11,3;" " 8580 FOR V=1 TO 17 8585 PRINT AT 7,M;"O";AT 8,M;"X" 8600 LET I=10 8605 PRINT AT 7,M;" ";AT 8,M;" " 8607 LET U=10 8610 LET M=M-1 8615 NEXT V 8620 STOP 8630 PAUSE 20 8635 CLS 8640 IF T(1)>T(2) THEN GOTO 8650 8642 IF T(1)=T(2) THEN GOTO 8672 8645 IF T(1)