1 REMark England's cricketers can't seem to bat their way out of a paper bag these days, so here's a chance for QL owners to go bat for themselves.
2 REMark One Day Cricket can be played by one or two players. The normal rules of the game are used and a score card is shown at the end of each over. Full prompts are given by the game, so off you go - let's show Gooch and Botham where they're going wrong!
10 REMark * * * ONE DAY CRICKET * * *
11 REMark by Andrew Finch
12 REMark from ZX Computing Jun'86
20 REMark --------------------
30 REMark procedures start at line 5000
40 REMark --------------------
50 set_up_teams
60 toss_coin
70 fielder_positions
80 set_variables
85 flag=0
90 score_sheet
100 get_bowler
120 open_windows
130 play_over
180 GO TO 90
4999 REMark --------------------
5000 DEFine PROCedure set_up_teams
5002 DIM score(2),name$(2,16),wickets$(2,7): score(1)=0: score(2)=0: team_batting=1: no_of_in=0: wickets$(1)='0': wickets$(2)='0'
5005 DIM team$(2,11,10): RESTORE 5015: name$(1)="ENGLAND": name$(2)="AUSTRALIA"
5010 FOR n=1 TO 11: READ team$(1,n): READ team$(2,n)
5015 DATA 'Gooch','Wood',"Rob'son","Hild'ch",'Gower','Wessels','Gatting','Border','Lamb','Boon','Botham','Ritchie','Downton',"Phil'ps",'Emburey',"O'Don'l",'Edmonds','Lawson','Ellison','Thomson','Taylor','Holland'
5020 END DEFine set_up_teams
5025 REMark --------------------
5030 DEFine PROCedure open_windows
5035 MODE 8
5040 OPEN #15,scr_512x256a0x0: PAPER #15,4: CLS #15: BORDER #15,2,5: CLOSE #15
5045 info=6: OPEN #info,scr_400x24a50x10
5050 PAPER #info,2: CLS #info: CSIZE #info,0,0: INK #info,0: BORDER #info,2,7
5060 LINE #info,590,0 TO 590,110
5070 main=7: OPEN #main,scr_420x170a40x40: INK #main,0
5075 PAPER #main,4: CLS #main: BORDER #main,1,7
5080 wicket=8: OPEN #wicket,scr_140x30a175x105
5085 PAPER #wicket,4: CLS #wicket: INK #wicket,0
5090 END DEFine open_windows
5095 REMark --------------------
5100 DEFine PROCedure fielder_positions
5105 DIM fielder_pos_x(11),fielder_pos_y(11): RESTORE 5115
5110 FOR n=1 TO 11: READ fielder_pos_x(n),fielder_pos_y(n)
5115 DATA 20,20,90,15,50,52,25,85,93,67,170,53,173,96,168,3,140,85,3,52,133,52
5120 END DEFine fielder_positions
5125 REMark --------------------
5130 DEFine PROCedure set_variables
5140 wickets_down=0: batsman1=1: batsman2=2: lastbowler=0: next_batsman=3
5145 present_batsman=batsman1: batsman1_pos=1: batsman2_pos=9: overs=0: extras=0
5150 DIM batsman_score(11),how_out$(11,15): FOR n=1 TO 11: batsman_score(n)=0: how_out$(n)=''
5151 how_out$(1)='Not Out': how_out$(2)='Not Out'
5155 DIM bowler_wickets(5),bowler_runs(5),bowler_overs(5): FOR n=1 TO 5: bowler_runs(n)=0: bowler_wickets(n)=0: bowler_overs(n)=0
5156 boundarys=0: last_bowler=0
5160 END DEFine set_variables
5165 REMark --------------------
5170 DEFine PROCedure score_sheet
5171 IF flag=0 THEN flag=1: GO TO 5175
5172 CLOSE #main: CLOSE #info: CLOSE #wicket
5175 MODE 4: OPEN #15,scr_512x256a0x0: PAPER #15,0: CLS #15: CLOSE #15
5180 CSIZE 0,0: BORDER 3,2: PAPER 0: INK 7
5185 FOR ploop=1 TO 11
5186 AT ploop-1,0: PRINT team$(team_batting,ploop)
5190 AT ploop-1,20: PRINT how_out$(ploop)
5200 IF how_out$(ploop)<>'' THEN AT ploop-1,40: PRINT batsman_score(ploop)
5201 END FOR ploop
5205 AT present_batsman-1,10: PRINT "*"
5210 IF team_batting=1 THEN not_batting=2: ELSE not_batting=1: END IF
5212 AT 12,0: PRINT 'Overs - ';overs: AT 12,20: PRINT 'Extras - ';extras: UNDER 1: AT 12,40: PRINT score(team_batting);: IF wickets_down=10 THEN PRINT ' all out': UNDER 0: ELSE PRINT ' / ';wickets_down: UNDER 0: END IF
5215 AT 14,0: FOR n=1 TO 5
5220 PRINT team$(not_batting,6+n),,bowler_overs(n),bowler_runs(n),bowler_wickets(n)
5225 END FOR n: INK #0,0
5230 END DEFine score_sheet
5235 REMark --------------------
5240 DEFine PROCedure get_bowler
5241 overs=overs+1: IF overs=no_of_overs+1 THEN overs=overs-1: end_of_innings
5244 REPeat bloop
5245 INK #0,7: l$='12345': PAPER #0,0: CLS #0: PRINT #0,'What is your choice of bowler. (1-5)? ';:k$=INKEY$(-1): IF NOT k$ INSTR l$ THEN END REPeat bloop
5256 bowler=k$: IF bowler=last_bowler THEN GO TO 5244
5257 last_bowler=bowler: bowler_overs(bowler)=bowler_overs(bowler)+1
5260 PRINT #0;bowler: PAUSE 48: INK #0,0: END DEFine
5265 REMark --------------------
5270 DEFine PROCedure play_over
5271 info_screen: c=1
5275 REPeat naloop
5276 info_screen: AT 0,35: PRINT c
5277 IF no_of_in=1 AND score(team_batting)>score(not_batting) THEN end_of_innings
5280 CLS #main: set_up_players
5295 PAPER #0,4: CLS #0
5300 bowl: IF RND<1E-2 THEN no_ball: c=c-1: GO TO 5330
5301 hit_ball
5302 IF boundarys=1: boundarys=0: GO TO 5330
5303 IF wc=1 AND RND<5E-3 THEN c$="CT": out
5304 IF wc=1 THEN GO TO 5330
5305 find_fielder: IF nearest<3 THEN c$="CT": BEEP 1000,255: FILL #main,0: INK #main,7: LINE #main,70,54 TO ballx,bally: PAUSE 15: INK #main,4: LINE #main,70,54 TO ballx,bally: INK #main,0: POINT #main,ballx,bally: out
5306 IF (present_batsman/5)*RND>1.7 THEN c$="BL": AT #wicket,1,0: PRINT #wicket;'\*       *|': out
5307 IF RND*(present_batsman/6)>1.1 THEN c$="LBW": out
5308 IF RND<2.5E-3 THEN c$="ST": out
5309 BEEP 1000,255: FILL #main,0: INK #main,7: LINE #main,70,54 TO ballx,bally: PAUSE 15: INK #main,4: LINE #main,70,54 TO ballx,bally: INK #main,0: POINT #main,ballx,bally
5310 byes=0: IF RND<5E-2 THEN byes=1: PRINT #0;"BYES": BEEP 5000,100,1,2,0: PAUSE 100: CLS #0
5320 play_ball
5330 c=c+1: IF c<7 THEN END REPeat naloop
5331 IF batsman1=present_batsman THEN present_batsman=batsman2: GO TO 90
5332 present_batsman=batsman1
5335 GO TO 90
5340 END DEFine play_over
5345 REMark --------------------
5400 DEFine PROCedure set_up_players
5403 fielder_pos_x(11)=133
5405 FOR pprint=1 TO 11
5410 FILL #main,1: INK #main,1: CIRCLE #main,fielder_pos_x(pprint),fielder_pos_y(pprint),2
5415 END FOR pprint
5417 INK #wicket,0: AT #wicket,1,0: PRINT #wicket;"|*       *|"
5420 END DEFine set_up_players
5425 REMark --------------------
5430 DEFine PROCedure info_screen
5435 CLS #info: LINE #info,590,0 TO 590,110: CSIZE #info,0,0: AT #info,0,0: PRINT #info;team$(team_batting,batsman1): AT #info,0,7: PRINT #info;": ";: PRINT #info;batsman_score(batsman1)
5440 AT #info,1,0: PRINT #info;team$(team_batting,batsman2): AT #info,1,7: PRINT #info;": ";batsman_score(batsman2)
5445 AT #info,1,14: PRINT #info;score(team_batting);" / ";wickets_down: IF no_of_in=1: AT #info,1,23: PRINT #info,'(';score(not_batting)+1-score(team_batting);')'
5450 AT #info,0,14: PRINT #info;team$(not_batting,bowler+6);" to ";team$(team_batting,present_batsman)
5455 END DEFine
5460 REMark --------------------
5461 DEFine PROCedure bowl
5462 FILL #main,1: INK #main,4: CIRCLE #main,133,52,3
5465 FILL #main,0: INK #main,1: FOR bloop=133 TO 118 STEP -2: CIRCLE #main,bloop,52,2: INK #main,4: CIRCLE #main,bloop,52,2: INK #main,1
5466 FILL #main,1: INK #main,1: CIRCLE #main,bloop,52,2: FILL #main,0
5469 INK #wicket,0: FOR b_path=8 TO 2 STEP -1
5470 AT #wicket,1,b_path: PRINT #wicket;"."
5475 PAUSE 3: AT #wicket,1,b_path
5480 PRINT #wicket,' ': END FOR b_path
5483 fielder_pos_x(11)=bloop
5484 END DEFine
5485 REMark --------------------
5490 DEFine PROCedure hit_ball
5491 wc=0: IF RND<.3 THEN PRINT #0,,"WICKET KEEPER": PAUSE 100: wc=1: CLS #0: END DEFine
5495 ballx=RND(0 TO 186): bally=RND(0 TO 100)
5500 IF ballx<1 OR ballx>180 OR bally<1 OR bally>99 THEN boundary: boundarys=1: END DEFine
5525 END DEFine
5530 REMark --------------------
5535 DEFine PROCedure play_ball
5538 a_r=0: nof=0: at_ball=0: f=0: wic=1
5539 REPeat tloop
5540 INK #0,0: PAPER #0,4: CLS #0: AT #wicket,1,0: PRINT #wicket,'|*       *|': PRINT #0,"Run (y/n)?",,'Runs - ';nof
5544 k$=INKEY$(-1): IF k$<>'y' AND k$<>'n' THEN GO TO 5544
5545 CLS #0: IF "n" INSTR k$ AND a_r=1 THEN c_batsman: RETurn
5546 IF k$="n" THEN RETurn
5547 one_run
5550 b_f=0: r_c=0: a_r=1
5561 r_c=1
5565 IF r_c=1 AND byes=0 THEN score(team_batting)=score(team_batting)+1: batsman_score(present_batsman)=batsman_score(present_batsman)+1: bowler_runs(bowler)=bowler_runs(bowler)+1: a_r=1: nof=nof+1: ELSE nof=nof+1: extras=extras+1: score(team_batting)=score(team_batting)+1: a_r=1: END IF
5566 IF run_out=1 THEN END DEFine
5567 END REPeat tloop
5570 END DEFine
6000 REMark --------------------
6001 DEFine PROCedure find_fielder
6002 fielderx=0: fieldery=0: nearest=1000
6003 FOR as=1 TO 11
6010 diff=ABS(ballx-fielder_pos_x(as))+ABS(bally-fielder_pos_y(as))
6020 IF nearest>diff THEN nearest=diff: fx=fielder_pos_x(as): fy=fielder_pos_y(as)
6030 END FOR as
6040 END DEFine
6045 REMark --------------------
6050 DEFine PROCedure c_batsman
6055 IF nof<>(INT(nof/2)*2) AND batsman1=present_batsman THEN present_batsman=batsman2: RETurn
6060 IF nof<>(INT(nof/2)*2) AND batsman2=present_batsman THEN present_batsman=batsman1
6065 END DEFine
6070 REMark --------------------
6080 DEFine PROCedure out
6085 CLS #0: IF c$<>"LBW": PRINT #0;team$(team_batting,present_batsman)!'has been ';c$: ELSE PRINT #0;team$(team_batting,present_batsman)!'is LBW': END IF
6086 BEEP 20000,1,1,7,2,4,3: PAUSE 100: CLS #0
6090 wickets_down=wickets_down+1
6091 IF c$<>"Run Out" THEN c$=c$&'  '&team$(not_batting,bowler+6)
6092 how_out$(present_batsman)=c$: IF c$<>"Run Out" THEN bowler_wickets(bowler)=bowler_wickets(bowler)+1
6100 IF wickets_down=10 THEN end_of_innings
6101 how_out$(next_batsman)="Not Out"
6110 IF present_batsman=batsman1 THEN
6120 batsman1=next_batsman: present_batsman=batsman1
6130 ELSE
6140 batsman2=next_batsman: present_batsman=batsman2
6150 END IF
6160 next_batsman=next_batsman+1
6180 c=c+1: IF c<7 THEN END REPeat naloop
6190 GO TO 90
6195 END DEFine
6200 REMark --------------------
6210 DEFine PROCedure boundary
6215 no=4: IF RND<.2 THEN no=6
6220 batsman_score(present_batsman)=batsman_score(present_batsman)+no: score(team_batting)=score(team_batting)+no: bowler_runs(bowler)=bowler_runs(bowler)+no
6221 BEEP 1000,255: FILL #main,0: INK #main,7: LINE #main,70,54 TO ballx,bally: PAUSE 15: INK #main,4: LINE #main,70,54 TO ballx,bally: INK #main,0: POINT #main,ballx,bally
6225 CLS #0: PRINT #0;no;" RUNS.": BEEP 20000,255,1,9,1,6,6: PAUSE 50: INK #main,4: POINT ballx,bally
6230 CLS #0: END DEFine
6240 REMark --------------------
6250 DEFine PROCedure end_of_innings
6260 flag=0: score_sheet: PAPER #0,0: INK #0,7: CLS #0: PRINT #0,"PRESS ANY KEY TO CONTINUE": k$=INKEY$(-1): CLS #0
6265 wickets$(team_batting)=wickets_down: IF wickets_down=10 THEN wickets$(team_batting)='All out'
6270 CLS: no_of_in=no_of_in+1: IF no_of_in>1 THEN finish
6280 PRINT name$(team_batting);" scored ";score(team_batting);' runs ';: IF wickets_down=10 THEN
6290 PRINT "all out";
6292 ELSE
6294 PRINT 'for ';wickets_down;' wickets.'
6296 END IF
6300 PRINT \\ name$(not_batting);' need ';score(team_batting)+1;" runs to win."
6310 PRINT \\\ "Press any key to continue": k$=INKEY$(-1)
6312 t=not_batting: not_batting=team_batting: team_batting=t
6313 set_variables
6314 GO TO 85
6320 END DEFine
6330 REMark --------------------
6340 DEFine PROCedure finish
6350 CLS: UNDER 1: PRINT "FINAL RESULT": UNDER 0
6360 PRINT \\ name$(not_batting);' - ';score(not_batting);' runs ';: IF wickets$(not_batting)<>"All out" THEN PRINT 'for ';wickets$(not_batting);' wickets.': ELSE PRINT 'all out.': END IF
6370 PRINT \\ name$(team_batting);' - ';score(team_batting);' runs ';: IF wickets$(team_batting)<>"All out" THEN PRINT 'for ';wickets$(team_batting);' wickets.': ELSE PRINT 'all out.': END IF
6380 IF score(not_batting)>score(team_batting) THEN PRINT \\ name$(not_batting);' have won by ';score(not_batting)-score(team_batting);' runs.'
6395 IF wickets$(1)='All out' THEN wickets$(1)='10'
6396 IF wickets$(2)='All out' THEN wickets$(2)='10'
6397 IF score(team_batting)>score(not_batting) THEN PRINT \\ name$(team_batting);' have won by ';10-wickets$(team_batting);' wickets.'
6400 IF score(2)=score(1) THEN
6420 IF wickets$(1)<wickets$(2): PRINT \\ name$(1);' have won by ';wickets$(2)-wickets$(1);' wickets.'
6440 IF wickets$(2)<wickets$(1): PRINT \\ name$(2);' have won by ';wickets$(1)-wickets$(2);' wickets.'
6460 END IF
6461 IF score(1)=score(2) AND wickets$(1)=wickets$(2) THEN PRINT \\ "The match is drawn."
6465 UNDER 1: PRINT \\\ "PRESS 'n' TO QUIT ANY OTHER KEY TO PLAY.": UNDER 0
6467 k$=INKEY$(-1): IF k$ INSTR 'Nn' THEN STOP
6468 RUN
6470 END DEFine
6480 REMark --------------------
6490 DEFine PROCedure no_ball
6500 CLS #0: IF RND<.5 THEN PRINT #0;'WIDE': ELSE PRINT #0;'No Ball': END IF
6510 extras=extras+1: score(team_batting)=score(team_batting)+1: bowler_runs(bowler)=bowler_runs(bowler)+1: BEEP 5000,0: PAUSE 75
6520 CLS #0
6530 END DEFine
6540 REMark --------------------
6550 DEFine PROCedure toss_coin
6560 MODE 8: OPEN #15,scr_512x256a0x0: PAPER #15,0: CLS #15: CLOSE #15: PAPER 0: INK 7
6565 CLS: INPUT 'How many overs ';no_of_overs$: IF no_of_overs$='' THEN GO TO 6565
6567 no_of_overs=no_of_overs$: CLS
6570 IF RND<.5 THEN team=1: ELSE team=2: END IF
6580 PRINT name$(team);' have won the toss.'
6590 PRINT \\ 'Press 1) To bat first'\'      2) To bowl first.'
6600 k$=INKEY$(-1): IF k$<>'1' AND k$<>'2' THEN GO TO 6600
6700 team_batting=1: not_batting=2
6710 IF (k$='1' AND team=2) OR (k$='2' AND team=1) THEN team_batting=2: not_batting=0
6720 END DEFine
6730 REMark --------------------
6740 DEFine PROCedure one_run
6750 run_out=0
6760 FOR wloop=1 TO 9
6770 AT #wicket,1,wloop: PRINT #wicket,'*': AT #wicket,1,10-wloop: PRINT #wicket,'*'
6780 IF at_ball=0 THEN move_fielder: ELSE throw_ball: END IF
6790 q=RND: IF run_out=1 AND wic=1 AND q<.5: c$='Run Out': AT #wicket,1,0: PRINT #wicket,'\': who: out
6791 IF run_out=1 AND wic=2 AND q<.5: c$="Run Out": AT #wicket,1,10: PRINT #wicket,'/': who: out
6795 IF run_out=1: PRINT #0,'Run Out Missed': BEEP 2000,12: PAUSE 50: CLS #0: END DEFine
6800 END IF: END IF
6810 AT #wicket,1,wloop: PRINT #wicket,' ': AT #wicket,1,10-wloop: PRINT #wicket,' '
6820 END FOR wloop
6830 END DEFine
6840 REMark --------------------
6850 DEFine PROCedure move_fielder
6855 FILL #main,1: INK #main,4: CIRCLE #main,fx,fy,3: FILL #main,0: INK #main,2
6860 IF fx<ballx THEN fx=fx+3: IF fx>ballx THEN fx=ballx
6870 IF fx>ballx: fx=fx-3: IF fx<ballx THEN fx=ballx
6880 IF fy>bally: fy=fy-3: IF fy<bally THEN fy=bally
6890 IF fy<bally: fy=fy+3: IF fy>bally THEN fy=bally
6910 IF ballx=fx AND bally=fy THEN at_ball=1
6915 CIRCLE #main,fx,fy,2
6920 END DEFine
6930 REMark --------------------
6940 DEFine PROCedure throw_ball
6950 IF f=0 THEN
6960 dx=60-fx: dy=54-fy: wic=1
6965 dx2=112-fx: dy2=54-fy: IF ABS(dx2+dy2)<ABS(dx+dy): dx=dx2: dy=dy2: wic=2
6970 te=RND(7 TO 10): stepx=dx/te: stepy=dy/te
6980 END IF
6985 f=1
6990 fx2=fx+stepx: fy2=fy+stepy
7000 INK #main,7: LINE #main,fx,fy TO fx2,fy2
7010 fx=fx2: fy=fy2: IF wic=1 AND fx>59 AND fx<61 AND fy>53 AND fy<55 THEN run_out=1
7011 IF wic=2 AND fx>111 AND fx<113 AND fy>53 AND fy<55 THEN run_out=1
7020 END DEFine
7030 REMark --------------------
7040 DEFine PROCedure who
7050 IF nof=(INT(nof/2)*2) AND present_batsman=batsman1 THEN present_batsman=batsman2: RETurn
7060 IF nof=(INT(nof/2)*2) AND present_batsman=batsman2 THEN present_batsman=batsman1
7070 END DEFine
7080 REMark --------------------
