Sharp PC-1500 : Blackjack

"Blackjack" for Sharp PC-1500.
Author: Antony F. P. Vickery.

Download zipped file (2.84MB).

Attached is a zipped file containing (1) a BASIC blackjack program I wrote in 1984 for my Sharp PC-1500; (2) a wave file containing the program suitable for loading into the computer. The program follows the rules of blackjack as they were in Atlantic City in New Jersey in 1984 (I actually made a trip to Atlantic City to pick up a copy of the rules). The only function that isn't implemented in Insurance, which is always a bad bet.

As you will see from the source code, lines 60 to 110 actually implement an algorithm to renumber the line numbers of the program in memory. You enter the starting line number (I use 50) and the increment interval (I use 10) and the renumbering takes place automatically. To run the renumberer you enter "run 60." Entering just "run" executes the blackjack program. Of course, if you've used absolute line number references in your program you won't want to run the renumbering program.
Lines 130 to 210 implement an "inverse video" routine for the display.
During initialization certain questions are asked of the user. Defaults are displayed thus: .
"Win limit" defaults to two times initial funds. The games will stop automatically if the win limit is reached.
The program implements a basic card counting strategy which can be displayed at will (see below).

Valid commands are during the game are:
C = Turns card counting on or off
D = Double down
E = End game
F = Displays available funds
G = Displays game statistics (number of wins, number of losses, etc.)
H = Hit
S or Enter = Stick
T = Displays total value of bets
X = Split
* = Displays this command list

Hope you enjoy it.
Antony F. P. Vickery
Lansdale, Pennsylvania, USA


BASIC program.

50 ARUN :LOCK :GOTO "B-J"
60 A=(STATUS 2)-1:B=14533:INPUT "START LINE NO.? ";C
70 INPUT "INTERVAL? ";D:WAIT 0:C=C-D:USING "######"
80 CLS :CURSOR 0:PRINT "LINE ":CURSOR 12:PRINT "RENUMBERED":CURSOR 5:BEEP 1
90 "1":C=C+D:E=INT (C/256):POKE B,E:POKE B+1,C-(E*256):PRINT C:CURSOR
5:B=B+(PEEK (B+2))+3
100 IF A<>BTHEN "1"
110 BEEP 1:END
120 "B-J":CLEAR :WAIT 0
130 A=STATUS 2:A=(INT (A/8)*8)+9
140 POKE A,72,118,74,0,5,189,255,65,78,78,153,8,76,119,139,6,72,119,74,0
150 POKE A+20,158,18,154:T=A
160 PRINT " BLACKJACK - AFPV 1984"
170 FOR C=1TO 11
180 FOR D=1TO 20
190 NEXT D
200 CALL T
210 NEXT C
220 DIM A(13):DIM C$(2)*30:DIM C(2):DIM T(2):DIM S(2)
230 DIM F(2):DIM K(2):DIM M(2):DIM LW(1):DIM LL(1):ZZ=0:Z=10:GOSUB "D":R=ND*52:DIM B$(R)*1
240 DIM J$(13)*1:J$(1)="A":J$(10)="T":J$(11)="J":J$(12)="Q":J$(13)="K"
250 FOR J=2TO 9:J$(J)=STR$ J:NEXT J
260 "G":GOSUB "A":WAIT
270 REM B$(2)="2":B$(3)="2":B$(4)="T":B$(5)="2"
280 REM B$(6)="3":B$(7)="4":B$(8)="3":B$(9)="Q":B$(10)="Q":B$(11)="J":B$(12)="8"
290 "N":I=1:K=1:L=0:F(1)=0:F(2)=0:G=0:B=B+1:MC=INT (R*.85)
300 IF B>MCTHEN CLS :PRINT "NEW DECK REQUIRED":GOTO "G"
310 IF MC-B<16THEN BEEP 1,25,1200
320 C$(I)=B$(B)+",":H$=B$(B):GOSUB "H":T(I)=H:IF H=1THEN LET F(I)=1
330 B=B+1:C$(I)=C$(I)+B$(B):H$=B$(B):GOSUB "H":T(I)=T(I)+H:IF H=1THEN LET F(I)=1
340 B=B+1:E$=B$(B):H$=B$(B):GOSUB "H":U=H:IF H=1THEN LET G=1
350 J=0:IF H=1OR H=10THEN LET J=1
360 B=B+1:F$=B$(B):H$=B$(B):GOSUB "H":U=U+H:IF H=1THEN LET G=1
370 GOSUB "J"
380 IF K=0THEN GOSUB "F":GOTO "N"
390 "NN":O=0:Z1=0
400 IF T(I)=20OR T(I)+(F(I)*10)=20THEN LET O=83:GOTO "P"
410 H$=B$(B-2):XB=XX:GOSUB "H":XX=XB
420 IF T(I)<10AND F(I)=0AND T(I)<>H*2THEN LET O=72:GOTO "P"
430 "O":D$=INKEY$ :IF D$=""THEN GOTO "O"
440 O=ASC D$
450 IF O=72OR O=13OR O=83OR O=68OR O=88OR O=69OR O=70OR O=71OR O=84OR O=67OR O=42THEN GOTO "P"
460 WAIT 75:BEEP 1,100,50:PRINT "C,D,E,F,G,H,S,T,X,* ONLY":GOSUB "I1":GOTO "O"
470 "P":IF O=72THEN GOSUB "Q"
480 IF O=88AND L<>0THEN WAIT :PRINT "SPLIT NOT ALLOWED - X":GOTO "P1"
490 IF K=0THEN GOSUB "F":GOTO "N"
500 IF T(I)=20OR T(I)+(F(I)*10)=20THEN LET O=83
510 IF T(I)=21OR T(I)+(F(I)*10)=21THEN LET O=83
520 IF T(I)<10AND F(I)=0AND T(I)<>H*2THEN LET O=72
530 IF O=72THEN GOTO "NN"
540 IF O=13OR O=83THEN GOSUB "T":GOSUB "F":GOTO "N"
550 IF O=68THEN GOSUB "DD":IF O=68THEN LET Z=Z-Z1:GOSUB "F":GOTO "N"
560 IF O=88THEN GOSUB "SX":IF O=88THEN GOSUB "F":GOTO "N"
570 IF O=70THEN GOSUB "CA"
580 IF O=84THEN WAIT 75:PRINT "TOTAL BETS=$";STR$ ZZ
590 IF O=71THEN GOSUB "GA"
600 IF O=67THEN GOSUB "CC"
610 IF O=69THEN LET W=W+Z:N=N-1:GOTO "END"
620 IF O=42THEN GOSUB "HE"
630 "P1":D$="":GOSUB "I1":GOTO "O"
640 "A":RANDOM :WAIT 0:CLS :PRINT "SHUFFLING"
650 FOR B=1TO 13:A(B)=ND*4:NEXT B
660 FOR C=RTO 1STEP -1:D=RND C:J=0
670 FOR H=1TO 13:J=J+A(H):IF J 680 A(H)=A(H)-1:B$(C)=J$(H):CURSOR 9:PRINT C;" ":H=13:NEXT H:NEXT C
690 CLS :WAIT 0
700 FOR J=24TO 0STEP -1:BEEP 1,J:NEXT J
710 B=1:XX=0:H$=B$(B):GOSUB "H":RETURN
720 "D":ND=4:X=200:W=X:D1=W:D2=W:WW=W:W1=400:L$="N":BEEP OFF :S(0)=0:S(1)=0:S(2)=0
730 Y=5:V=500:WAIT 75:SG$="Y":INPUT "STANDARD GAME? /N ";SG$
740 IF SG$="Y"THEN GOTO "SGE"
750 INPUT "HOW MANY DECKS? <4> ";ND:IF ND<1OR ND>4THEN LET ND=4
760 INPUT "CASH ON HAND? <200> $";X
770 W=X:D1=W:D2=W:WW=W
780 "D1":W1=X*2:INPUT "WIN LIMIT? $";W1
790 IF W1<=XTHEN PRINT "WIN LIMIT NOT > CASH":GOTO "D1"
800 INPUT "DISPLAY COUNT? Y/ ";L$
810 INPUT "BEEP ON? Y/ ";BP$
820 IF BP$="Y"THEN BEEP ON
830 "E":INPUT "MINIMUM BET? <5> $";Y:IF Y<1THEN PRINT "MIN. BET < 1":GOTO "E"
840 "E1":INPUT "MAXIMUM BET? <500> $";V:IF V 850 "F":IF W>WWTHEN LET LW(0)=LW(0)+1:LL(0)=0
860 IF LW(0)>LW(1)THEN LET LW(1)=LW(0)
870 IF W 880 IF LL(0)>LL(1)THEN LET LL(1)=LL(0)
890 WW=W
900 IF W 910 IF W>D2THEN LET D2=W
920 IF Y>WTHEN WAIT :PRINT "GAME OVER - FUNDS < MIN.":GOTO "END"
930 IF W>=W1THEN WAIT :PRINT "GAME OVER - WIN LIMIT HIT":GOTO "END"
940 "F1":IF L$<>"Y"THEN INPUT "BET? $";Z
950 IF L$="Y"THEN WAIT 0:PRINT "C= ";STR$ XX;",";STR$ (MC-B):WAIT 75:CURSOR 12:INPUT " BET? $";Z
960 IF Z 970 IF Z>VTHEN CLS :PRINT "MAXIMUM BET IS $";STR$ V:GOTO "F1"
980 IF Z>WTHEN CLS :PRINT "$";STR$ Z;" BET > $";STR$ W;" CASH":GOTO "F1"
990 "SGE":W=W-Z:ZZ=ZZ+Z:RETURN
1000 "H":H=VAL H$
1010 IF H$="T"OR H$="J"OR H$="Q"OR H$="K"THEN LET H=10:XX=XX-1
1020 IF H$="A"THEN LET H=1:XX=XX-1
1030 IF H>1AND H<7THEN LET XX=XX+1
1040 RETURN
1050 "I":CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR (26-LEN E$):WAIT :PRINT E$:RETURN
1060 "I1":CLS :WAIT 0:CURSOR 0:PRINT C$(I)+" ?":CURSOR (26-LEN E$):WAIT 0:PRINT E$:RETURN
1070 "J":N=N+1:IF T(I)=20OR T(I)+(F(I)*10)=20THEN RETURN
1080 IF T(I)<>11THEN GOSUB "I1":RETURN
1090 IF F(I)<>1THEN GOSUB "I1":RETURN
1100 T(I)=21:K=0:IF J<>1THEN GOSUB "L":RETURN
1110 E$=E$+","+F$:IF U<>11THEN GOSUB "L":RETURN
1120 IF G=0THEN RETURN
1130 U=21:K=0:GOSUB "M":RETURN
1140 "L":S(0)=S(0)+1:W=W+Z+((Z/2)*3):C$(I)=C$(I)+" <":M=M+1
1150 CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR (26-LEN E$):PRINT E$
1160 FOR C=1TO 6:BEEP 1
1170 FOR D=1TO 20
1180 NEXT D
1190 CALL T
1200 NEXT C
1210 WAIT 75:CLS :PRINT "CASH=$";STR$ W;" (";STR$ (W-X);")":RETURN
1220 "M":S(2)=S(2)+1:W=W+Z:C$(I)=C$(I)+" "+"<":E$="> "+E$:GOSUB "I"
1230 WAIT 25:PRINT "CASH=$";STR$ W;" (";STR$ (W-X);")":RETURN
1240 "Q":B=B+1:C$(I)=C$(I)+","+B$(B):H$=B$(B):GOSUB "H"
1250 T(I)=T(I)+H:IF H=1THEN LET F(I)=1
1260 IF T(I)>21THEN GOSUB "S":RETURN
1270 IF Z1=0AND T(I)<>21AND T(I)+(F(I)*10)<>21AND T(I)<>20AND T(I)+(F(I)*10)<>20THEN GOSUB "I1"
1280 RETURN
1290 "S":S(1)=S(1)+1:E$="> "+E$:BEEP 1,100,50:GOSUB "I"
1300 K=0:WAIT 25:PRINT "CASH=$";STR$ W;" (";STR$ (W-X);")":RETURN
1310 "T":IF U+(G*10)=21THEN LET E$=E$+","+F$:W=W+Z1:GOSUB "S":RETURN
1320 U1=U:IF U+(G*10)>16THEN LET E$=E$+","+F$:U=U+(G*10)
1330 IF U1+(G*10)>16THEN GOSUB "U":RETURN
1340 U1=U:IF U+(G*10)>16THEN LET U=U+10
1350 IF U1+(G*10)>16THEN GOSUB "U":RETURN
1360 E$=E$+","+F$:GOSUB "Z"
1370 "T1":B=B+1:E$=E$+","+B$(B):H$=B$(B):GOSUB "H":U=U+H:IF H=1THEN LET G=1
1380 IF G=0THEN GOTO "T2"
1390 U1=U:IF U+10<17THEN GOSUB "Z":GOTO "T1"
1400 IF U+10<22THEN LET U=U+10
1410 IF U1+10<22THEN GOSUB "U":RETURN
1420 IF U>16THEN GOSUB "U":RETURN
1430 GOSUB "Z":GOTO "T1"
1440 "T2":IF U>16THEN GOSUB "U":RETURN
1450 GOSUB "Z":GOTO "T1"
1460 "DD":WAIT 75:IF LEN C$(I)=3THEN GOTO "DD1"
1470 BEEP 1,100,50:PRINT "DD NOT ALLOWED":O=0:RETURN
1480 "DD1":IF W=0THEN BEEP 1,100,50:PRINT "NO FUNDS FOR A DD BET":O=0:RETURN
1490 IF W>=ZTHEN LET Z1=Z:GOTO "DD2"
1500 Z1=W
1510 "DD2":W=W-Z1:Z=Z+Z1:ZZ=ZZ+Z1:GOSUB "Q":IF K=1THEN GOSUB "T"
1520 RETURN
1530 "CC":IF L$="Y"THEN LET L$="N":GOTO "CCX"
1540 IF L$="N"THEN LET L$="Y"
1550 "CCX":RETURN
1560 "Z":CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR (26-LEN E$):WAIT 1:PRINT E$:RETURN
1570 "U":IF U>21THEN GOSUB "W":RETURN
1580 IF T(I)+(F(I)*10)>21THEN LET F(I)=0
1590 T(I)=T(I)+(F(I)*10):IF T(I)+U=42THEN GOSUB "V":RETURN
1600 IF T(I)>UTHEN GOSUB "W":RETURN
1610 IF T(I) 1620 GOSUB "M":RETURN
1630 "V":IF LEN E$=3THEN GOSUB "S":RETURN
1640 GOSUB "M":RETURN
1650 "W":S(0)=S(0)+1:W=W+(Z*2):C$(I)=C$(I)+" "+"<":BEEP 1:GOSUB "I"
1660 K=0:WAIT 25:PRINT "CASH=$";STR$ W;" (";STR$ (W-X);")":RETURN
1670 "SX":WAIT 75:H$=B$(B-2):XB=XX:GOSUB "H":XX=XB:IF T(I)<>H*2THEN BEEP 1,100,50
1680 IF T(I)<>H*2THEN PRINT "SPLIT NOT ALLOWED":O=0:RETURN
1690 IF W 1700 W=W-Z:ZZ=ZZ+Z:L=1:K(1)=2:K(2)=2:M(1)=0:M(2)=0:Q=0
1710 C$(2)="X2 "+LEFT$ (C$(1),1):C$(1)="X1 "+LEFT$ (C$(1),1):T(1)=H
1720 T(2)=H:F(2)=F(1)
1730 IF T(1)=1THEN LET Q=1:I=1:GOSUB "SH":K(1)=0:I=2:GOSUB "SH":K(2)=0:GOTO "SE"
1740 C$(1)=C$(1)+","
1750 B=B+1:C$(1)=C$(1)+B$(B):H$=B$(B):GOSUB "H":T(1)=T(1)+H:IF H=1THEN LET F(1)=1
1760 IF T(1)+(F(1)*10)<20THEN GOTO "SB"
1770 GOSUB "SHY":I=2:K(1)=0:B=B+1:C$(2)=C$(2)+","+B$(B):H$=B$(B):GOSUB "H"
1780 T(2)=T(2)+H:IF H=1THEN LET F(2)=1
1790 IF T(2)+(F(2)*10)>19THEN LET K(2)=0
1800 IF K(1)+K(2)<1THEN GOTO "SE"
1810 "SB":GOSUB "I1":O=0
1820 "SQ":D$=INKEY$ :IF D$=""THEN GOTO "SQ"
1830 O=ASC D$:IF O=72OR O=13OR O=83OR O=68OR O=70OR O=71OR O=84THEN "SA"
1840 WAIT 75:BEEP 1,100,50:PRINT "C,F,D,G,H,S,T ONLY":GOSUB "I1":GOTO "SQ"
1850 "SA":IF O=13OR O=83THEN LET K(I)=0
1860 IF O=68THEN GOSUB "SD"
1870 IF O=72THEN GOSUB "SH"
1880 IF O=70THEN GOSUB "CA"
1890 IF O=84THEN WAIT 75:PRINT "TOTAL BETS=$";STR$ ZZ
1900 IF O=71THEN GOSUB "GA"
1910 IF I=1AND K(1)<1THEN LET I=2:GOSUB "SH"
1920 IF K(1)+K(2)<1THEN LET O=88:GOTO "SE"
1930 D$="":GOSUB "I1":GOTO "SQ"
1940 "SH":B=B+1:C$(I)=C$(I)+","+B$(B):H$=B$(B):GOSUB "H"
1950 T(I)=T(I)+H:IF H=1THEN LET F(I)=1
1960 IF T(I)<22THEN "SHX"
1970 K(I)=-1:BEEP 1,100,50:S(1)=S(1)+1
1980 CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR 23:WAIT :PRINT "> "+E$:RETURN
1990 "SHX":IF T(I)=20OR T(I)=21OR T(I)+(F(I)*10)=20OR T(I)+(F(I)*10)=21THEN "SHY"
2000 RETURN
2010 "SHY":CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR 25:WAIT 50:PRINT E$:K(I)=0:RETURN
2020 "SD":WAIT 75:IF LEN C$(I)<>6THEN BEEP 1,100,50:PRINT "DD NOT ALLOWED":RETURN
2030 IF W=0THEN BEEP 1,100,50:PRINT "NO FUNDS FOR A DD BET":RETURN
2040 IF W>=ZTHEN LET M(I)=Z:GOTO "SD2"
2050 M(I)=W
2060 "SD2":W=W-M(I):ZZ=ZZ+M(I):B=B+1:C$(I)=C$(I)+","+B$(B):H$=B$(B):GOSUB "H"
2070 T(I)=T(I)+H:IF H=1THEN LET F(I)=1
2080 IF T(I)<22THEN CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR 25:WAIT 50:PRINT E$:K(I)=0:RETURN
2090 K(I)=-1:BEEP 1,100,50:S(1)=S(1)+1
2100 CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR 23:WAIT :PRINT "> "+E$:RETURN
2110 "SE":P=0
2120 FOR C1=1TO 2
2130 I=C1:IF K(C1)<0THEN "SE10"
2140 IF P=0THEN LET E$=E$+","+F$
2150 IF U=11AND G=1THEN LET K$="DB":GOTO "SE9"
2160 IF P=1OR U+(G*10)>16THEN GOTO "SE1"
2170 CLS :CURSOR 23:WAIT 1:PRINT E$
2180 "SEC":P=1:B=B+1:E$=E$+","+B$(B):H$=B$(B):GOSUB "H":U=U+H
2190 IF H=1THEN LET G=1
2200 IF G=0AND U>16THEN GOTO "SE1"
2210 IF G=0AND U<17THEN CLS :CURSOR (26-LEN E$):WAIT 1:PRINT E$:GOTO "SEC"
2220 IF U+10<17THEN CLS :CURSOR (26-LEN E$):WAIT 1:PRINT E$:GOTO "SEC"
2230 IF U+10<22THEN LET U=U+10:GOTO "SE1"
2240 IF U>16THEN GOTO "SE1"
2250 CLS :CURSOR (26-LEN E$):WAIT 1:PRINT E$:GOTO "SEC"
2260 "SE1":P=1
2270 IF U>21THEN LET U=0:G=0
2280 IF T(I)+(F(I)*10)>21THEN LET F(I)=0
2290 T(I)=T(I)+(F(I)*10):IF U+(G*10)>21THEN LET G=0
2300 U=U+(G*10):IF T(I)>UTHEN LET K$="PW":GOTO "SE9"
2310 IF T(I) 2320 K$="SO"
2330 "SE9"
2340 IF K$="PB"THEN LET S(0)=S(0)+1:W=W+(Z*2):C$(I)=C$(I)+" <":BEEP 1:GOSUB "I":GOTO "SE10"
2350 IF K$="PW"THEN LET S(0)=S(0)+1:W=W+((Z+M(I))*2):C$(I)=C$(I)+" <":BEEP 1:GOSUB "I"
2360 IF K$="PW"THEN "SE10"
2370 IF K$="DB"THEN LET S(1)=S(1)+1:W=W+M(I):BEEP 1,100,50
2380 IF K$="DB"AND Q=1THEN LET W=W+(Z/2)
2390 IF K$="DB"THEN CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR 21:WAIT :PRINT "> "+E$:GOTO "SE10"
2400 IF K$="SO"THEN LET S(2)=S(2)+1:W=W+Z+M(I)
2410 IF K$="SO"THEN CLS :WAIT 0:CURSOR 0:PRINT C$(I)+" <":CURSOR (24-LEN E$):WAIT :PRINT "> "+E$:GOTO "SE10"
2420 S(1)=S(1)+1:BEEP 1,100,50
2430 CLS :WAIT 0:CURSOR 0:PRINT C$(I):CURSOR (24-LEN E$):WAIT :PRINT "> "+E$
2440 "SE10":K(I)=-1:NEXT C1
2450 WAIT 25:PRINT "CASH=$";STR$ W;" (";STR$ (W-X);")":RETURN
2460 "GA":WAIT 150:IF EN=1THEN WAIT
2470 PRINT "P-HANDS=";STR$ N;",";"B-JACKS=";STR$ M
2480 PRINT "HANDS W=";STR$ S(0);",";"L=";STR$ S(1);",";"D=";STR$ S(2)
2490 PRINT "MIN=$";STR$ D1;",MAX=$";STR$ D2
2500 PRINT "LONG WINS=";STR$ LW(1);",LOSSES=";STR$ LL(1):RETURN
2510 "HE":WAIT 150:PRINT "C = COUNT ON/OFF TOGGLE":PRINT "D = DOUBLE DOWN"
2520 PRINT "E = END GAME":PRINT "F = FUNDS DISPLAY":PRINT "G = GAME STATISTICS"
2530 PRINT "H = HIT":PRINT "S OR ENTER = STICK":PRINT "T = TOTAL BETS"
2540 PRINT "X = SPLIT":PRINT "* = COMMAND LIST":RETURN
2550 "CA":WAIT 75:IF EN=1THEN WAIT
2560 PRINT "CASH=$";STR$ W;" (";STR$ (W-X);")":RETURN
2570 "END":EN=1:GOSUB "CA":GOSUB "GA"
2580 PRINT "TOTAL BETS=$";STR$ ZZ
2590 USING "+####.##":PRINT "AVG. WIN/LOSS=";((W-X)/(S(0)+S(1)+S(2))):END


Return to the main page