10 REM ENTER AND CALCULATE WEEKLY BOWLING SCORES   (SCORES)
12 REM Developed by William W. Klaproth,  Moraga Ca.  94556    September 1982
20 REM MASTER FILE DESCRIPTIONS FOR ALL BOWLING PROGRAMS
30 OPEN "B:TEAMS.HDR" AS #1 LEN = 64
40 FIELD #1, 2 AS TM$, 30 AS NAM$, 2 AS RCNT$, 2 AS GAM$, 4 AS PINS$, 2 AS AVG$, 2 AS HIG$, 2 AS HIS$, 4 AS PTSW$, 4 AS PTSL$, 2 AS B1ID$, 2 AS B2ID$, 2 AS B3ID$, 2 AS B4ID$, 2 AS B5ID$
50 FIELD #1, 2 AS HDRID$, 30 AS LEAGUE$, 2 AS WEEKS$, 2 AS TEAMS$, 4 AS FILLER$, 2 AS BWLPERTM$, 2 AS NXTID$, 2 AS HCPBASE$, 4 AS HCPPCNT$
60 OPEN "B:BOWLERS.HDR" AS #2 LEN = 64
70 FIELD #2, 2 AS BBO$, 30 AS BNAM$, 2 AS BRCNT$, 2 AS BGAM$, 4 AS BPINS$, 2 AS BAVG$, 2 AS BHIG$, 2 AS BHIS$, 2 AS BHCP$, 2 AS BHIGH$, 2 AS BHISH$, 2 AS BTM$,2 AS GAM2$, 2 AS SER5$, 2 AS SER6$,2 AS CURSER$,2 AS AVGLSTYR$
80 OPEN "B:TEAM.DET" AS #3 LEN = 16
90 FIELD #3,2 AS DTM$, 2 AS TMO$, 2 AS TDAY$, 2 AS TG1$, 2 AS TG2$, 2 AS TG3$, 2 AS TSER$, 2 AS DPTSW$
100 OPEN "B:BOWLER.DET" AS #4 LEN = 16
110 FIELD #4,2 AS DBO$, 2 AS BMO$, 2 AS BDAY$, 2 AS BG1$, 2 AS BG2$, 2 AS BG3$, 2 AS BSER$
120 OPEN "B:HISCORES.DET" AS #5 LEN = 16
130 FIELD #5, 2 AS HBNO$, 2 AS HG1$, 2 AS HG2$, 2 AS HG3$, 2 AS HSER$, 1 AS HFLG1$, 1 AS HFLG2$, 1 AS HFLG3$, 1 AS HFLGS$, 2 AS HCNT$
140 HILTECNT% = 1  'SET START OF HILITE RECORDS IN FILE 5
150 DIM BNUM%(5)
160 CLS:KEY OFF
170 INPUT "ENTER BOWLING MONTH AND DAY SEPARATED BY A COMMA (MM,DD):",MON%,DAY%
180 GET #1,1
190 TM%=CVI(TEAMS$)
200 BO%=CVI(BWLPERTM$)
210 LEAGUENAM$ = LEAGUE$
220 FBOT% = CVI(NXTID$) - 1
230 BASE% = CVI(HCPBASE$)
240 HPCNT = (CVS(HCPPCNT$) / 100)
250 FOR T% = 1 TO FBOT%        'RESET CURRENT SERIES FIELDS OF SUBS
260 GET #2,T%
270 IF CVI(BTM$) > 0 GOTO 300
280 RSET CURSER$ = MKI$(0)
290 PUT #2,T%
300 NEXT T%
310 FOR T%=1 TO TM%
320 CLS: LOCATE 25,1: PRINT "WEEKLY SCORE PROCESSING   ";
330 PRINT LEAGUENAM$,DATE$
340 LOCATE 1,1: PRINT "NOTE: Enter 0 for all games not bowled - 999 in Game1 to indicate substitute"
350 GET #1,(T% + 1)
360 BNUM%(1) = CVI(B1ID$)
370 BNUM%(2) = CVI(B2ID$)
380 BNUM%(3) = CVI(B3ID$)
390 BNUM%(4) = CVI(B4ID$)
400 BNUM%(5) = CVI(B5ID$)
410 PRINT " "
420 PRINT "ENTER SCORES FOR TEAM:";NAM$
430 PRINT " "
440 PRINT "NO BOWLER NAME                 GM1  GM2  GM3  SER  GAM TOT-PN AVG"
450 PRINT "-- --------------------        ---  ---  ---  ---"
460 TG1%=0:TG2%=0:TG3%=0:TSER%=0
470 FOR B%=1 TO BO%
480 TREC% = BNUM%(B%)
490 GET #2,TREC%
500 REC% = CVI(BRCNT$) + 1
510 GAM% = CVI(BGAM$)
520 PINS = CVS(BPINS$)
530 AVERAGE% = CVI(BAVG$)
540 AVG = AVERAGE%
550 LOCATE ,52:PRINT USING "###";GAM%;
560 PRINT USING " ######";PINS;
570 PRINT USING " ###";AVERAGE%;
580 PRINT "              ";
590 LOCATE ,1
600 PRINT USING "## ";TREC%;
610 PRINT LEFT$(BNAM$,20);
620 PRINT SPC(26);
630 G1%=0:G2%=0:G3%=0:SER%=0
640 BL1%=0:BL2%=0:BL3%=0:BLSER%=0
650 IF LEFT$(BNAM$,8) = "*VACANCY" GOTO 860
660 LOCATE ,32,1:INPUT; "",G1%
670 IF G1% = 999 GOTO 810
680 LOCATE ,37,1:INPUT; "",G2%
690 LOCATE ,42,1:INPUT; "",G3%
700 LOCATE ,47,1:INPUT; "",SER%
710 IF G1% = 0 GOTO 860
720 IF G2% = 0 GOTO 860
730 IF G3% = 0 GOTO 860
740 SERIES% = G1% + G2% + G3%
750 BLSERIES% = BL1% + BL2% + BL3%
760 IF (SERIES% + BLSERIES%) = (SER% + BLSER%) GOTO 940
770 BEEP
780 LOCATE ,52:PRINT "ERROR-SERIES SHOULD BE:";
790 PRINT USING "####";(SERIES% + BLSERIES%);
800 GOTO 590
810 SER% = 0  'SET REG BOWLER SERIES TO 0
820 GOSUB 2580   'WRITE HEADER FOR REGULAR BOWLER
830 LOCATE ,52,1:INPUT; " ENTER SUB NO:";ISUB%
840 TREC% = ISUB%
850 GOTO 490
860 PRINT " "
870 PRINT "    ENTER BLIND SCORES:";
880 LOCATE ,32,1:INPUT; "",BL1%
890 IF BL1% = 999 GOTO 810
900 LOCATE ,37,1:INPUT; "",BL2%
910 LOCATE ,42,1:INPUT; "",BL3%
920 LOCATE ,47,1:INPUT; "",BLSER%
930 GOTO 740
940 TG1% = TG1% + G1% + BL1%
950 TG2% = TG2% + G2% + BL2%
960 TG3% = TG3% + G3% + BL3%
970 TSER% = TSER% + SER% +BLSER%
980 IF SER% = 0 GOTO 1850
990 GAM2X% = CVI(GAM2$)
1000 SER5% = CVI(SER5$)
1010 SER6% = CVI(SER6$)
1020 HILTE% = 0:FLAG1$=" ":FLAG2$=" ":FLAG3$=" ":FLAGS$=" "
1030 IF G1% < 200 GOTO 1050
1040 GAM2X%=GAM2X% + 1:HILTE%=HILTE% + 1:FLAG1$="1"
1050 IF G2% < 200 GOTO 1070
1060 GAM2X%=GAM2X% + 1:HILTE%=HILTE% + 1:FLAG2$="1"
1070 IF G3% < 200 GOTO 1090
1080 GAM2X%=GAM2X% + 1:HILTE%=HILTE% + 1:FLAG3$="1"
1090 IF SER% < 500 GOTO 1130
1100 IF SER% < 600 THEN SER5% = SER5% + 1
1110 IF SER% > 599 THEN SER6% = SER6% + 1
1120 HILTE%=HILTE% + 1:FLAGS$="1"
1130 IF AVERAGE% = 0 GOTO 1200
1140 IF G1% < (AVERAGE%+50) GOTO 1160
1150 HILTE%=HILTE% + 1:FLAG1$="1"
1160 IF G2% < (AVERAGE%+50) GOTO 1180
1170 HILTE%=HILTE% + 1:FLAG2$="1"
1180 IF G3% < (AVERAGE%+50) GOTO 1200
1190 HILTE%=HILTE% + 1:FLAG3$="1"
1200 RSET GAM2$ = MKI$(GAM2X%)
1210 RSET SER5$ = MKI$(SER5%)
1220 RSET SER6$ = MKI$(SER6%)
1230 RSET CURSER$ = MKI$(SER%)
1240 HIGAM% = G1%
1250 IF G2% > HIGAM% THEN HIGAM% = G2%
1260 IF G3% > HIGAM% THEN HIGAM% = G3%
1270 REM FORMAT AND WRITE HILITE RECORD
1280 RSET HBNO$ = MKI$(TREC%)
1290 RSET HFLG1$ = FLAG1$
1300 RSET HFLG2$ = FLAG2$
1310 RSET HFLG3$ = FLAG3$
1320 RSET HFLGS$ = FLAGS$
1330 RSET HG1$ = MKI$(G1%)
1340 RSET HG2$ = MKI$(G2%)
1350 RSET HG3$ = MKI$(G3%)
1360 RSET HSER$ = MKI$(SER%)
1370 RSET HCNT$ = MKI$(HILTE%)
1380 PUT #5,HILTECNT%
1390 HILTECNT% = HILTECNT% + 1
1400 RSET DBO$ = MKI$(TREC%)
1410 LSET BMO$ = MKI$(MON%)
1420 LSET BDAY$ = MKI$(DAY%)
1430 RSET BG1$ = MKI$(G1%)
1440 RSET BG2$ = MKI$(G2%)
1450 RSET BG3$ = MKI$(G3%)
1460 RSET BSER$ = MKI$(SER%)
1470 REM RANDOMIZING ROUTINE FOR BOWLER DETAIL ADDRESSES
1480 X = TREC% / 2: X% = CINT(X): Y% = X% * 2
1490 WREC% = REC%
1500 IF Y% = TREC% THEN WREC% = REC% + 50
1510 BDET% = X% * 100 + WREC% - 100
1520 REM END OF RANDOMIZING ROUTINE
1530 PUT #4,BDET%
1540 RSET BRCNT$ = MKI$(REC%)
1550 G% = 3   'CALCULATE NUMBER OF GAMES BOWLED
1560 IF G1% = 0 THEN G% = G% -1
1570 IF G2% = 0 THEN G% = G% -1
1580 IF G3% = 0 THEN G% = G% -1
1590 GAM% = GAM% + G%
1600 PINS = PINS + SER%
1610 AVG = PINS / GAM%
1620 AVG% = INT(AVG)
1630 IF CVI(AVGLSTYR$) = 0 THEN IF GAM% >= 21 THEN RSET AVGLSTYR$ = MKI$(AVG%)
1640 RSET BGAM$ = MKI$(GAM%)
1650 RSET BPINS$ = MKS$(PINS)
1660 RSET BAVG$ = MKI$(AVG%)
1670 IF SER% > CVI(BHIS$) THEN RSET BHIS$ = MKI$(SER%)
1680 IF HIGAM% > CVI(BHIG$) THEN RSET BHIG$ = MKI$(HIGAM%)
1690 BHCP% = CVI(BHCP$)       'Get handicap from record
1700 IF BHCP% <> 0 GOTO 1750  'If handicap established, go to process it
1710 IF GAM% < 21 GOTO 1910   'If no handicap and less than 21 games, bypass
1720 BHCP = (BASE% - AVG%) * HPCNT  'Compute handicap   first time only
1730 IF BHCP < 0 THEN BHCP = 0
1740 BHCP% = INT(BHCP)
1750 HIGAMH% = HIGAM% + BHCP%
1760 IF HIGAMH% > CVI(BHIGH$) THEN RSET BHIGH$ = MKI$(HIGAMH%)
1770 HISERH% = SER% + BHCP% * 3
1780 IF HISERH% > CVI(BHISH$) THEN RSET BHISH$ = MKI$(HISERH%)
1790 BHCP = (BASE% - AVG%) * HPCNT  'Update handicap
1800 IF BHCP < 0 THEN BHCP = 0
1810 BHCP% = INT(BHCP)
1820 RSET BHCP$ = MKI$(BHCP%)
1830 GOTO 1910
1840 REM CALCULATE CONSECUTIVE ABSENCES
1850 CURSER% = CVI(CURSER$)
1860 IF CURSER% < 50 GOTO 1880
1870 CURSER% = 0
1880 CURSER% = CURSER% + 1
1890 RSET CURSER$ = MKI$(CURSER%)
1900 AVG% = AVERAGE%   'INSERT PROPER AVERAGE WHEN BOWLER WAS ABSENT
1910 PUT #2,TREC%
1920 LOCATE ,52:PRINT USING "###";GAM%;
1930 PRINT USING " ######";PINS;
1940 PRINT USING " ###";AVG%;
1950 PRINT "              "
1960 PRINT " "
1970 NEXT B%
1980 PRINT "                              ---- ---- ---- ----"
1990 PRINT "TEAM TOTALS";
2000 LOCATE ,31
2010 PRINT USING "#### ";TG1%,TG2%,TG3%,TSER%
2020 INPUT; "ENTER TEAM H'CAP PER GAME:",IHCP%
2030 LOCATE ,31
2040 PRINT USING "#### ";IHCP%,IHCP%,IHCP%,IHCP%*3
2050 TG1H% = TG1% + IHCP%
2060 TG2H% = TG2% + IHCP%
2070 TG3H% = TG3% + IHCP%
2080 TSERH% = TG1H% + TG2H% + TG3H%
2090 PRINT "                              ---- ---- ---- ----"
2100 LOCATE ,31
2110 PRINT USING "#### ";TG1H%,TG2H%,TG3H%,TSERH%
2120 INPUT "VERIFY TEAM TOTALS, ENTER Y IF CORRECT:",TTRESP$
2130 IF TTRESP$ = "Y" OR TTRESP$ = "y" GOTO 2140 ELSE GOTO 1990
2140 GET #1,(T% + 1)
2150 TREC% = CVI(RCNT$) + 1
2160 RSET RCNT$ = MKI$(TREC%)
2170 TGAM% = CVI(GAM$) + 3
2180 TPINS = CVS(PINS$) + TSERH%
2190 TAVG = TPINS / TGAM%
2200 TAVG% = INT(TAVG)
2210 IF TSERH% > CVI(HIS$) THEN RSET HIS$ =MKI$(TSERH%)
2220 HITGAM% = TG1H%
2230 IF TG2H% > HITGAM% THEN HITGAM% = TG2H%
2240 IF TG3H% > HITGAM% THEN HITGAM% = TG3H%
2250 IF HITGAM% > CVI(HIG$) THEN RSET HIG$ = MKI$(HITGAM%)
2260 RSET GAM$ = MKI$(TGAM%)
2270 RSET PINS$ = MKS$(TPINS)
2280 RSET AVG$ = MKI$(TAVG%)
2290 INPUT "ENTER POINTS WON:",IW
2300 IL = (4! - IW)
2310 PRINT "GAMES WON:";IW," LOST:";IL
2320 INPUT "VERIFY TEAM POINTS AND ENTER Y TO CONTINUE:",PRESP$
2330 IF PRESP$ = "Y" OR PRESP$ = "y" GOTO 2340 ELSE GOTO 2290
2340 RSET PTSW$ = MKS$((CVS(PTSW$) + IW))
2350 RSET PTSL$ = MKS$((CVS(PTSL$) + IL))
2360 PUT #1,(T% + 1)
2370 RSET DTM$ = MKI$(T%)
2380 LSET TMO$ = MKI$(MON%)
2390 LSET TDAY$ = MKI$(DAY%)
2400 RSET TG1$ = MKI$(TG1H%)
2410 RSET TG2$ = MKI$(TG2H%)
2420 RSET TG3$ = MKI$(TG3H%)
2430 RSET TSER$ = MKI$(TSERH%)
2440 RSET DPTSW$ = MKI$(IW * 10)
2450 REM RANDOMIZING ROUTINE FOR TEAM DETAIL ADDRESSES
2460 X = T% / 2: X% = CINT(X): Y% = X% * 2
2470 TWREC% = TREC%
2480 IF Y% = T% THEN TWREC% = TREC% + 50
2490 TDET% = X% * 100 + TWREC% - 100
2500 REM END OF RANDOMIZING ROUTINE
2510 PUT #3,TDET%
2520 NEXT T%
2530 RSET HG1$ = MKI$(9999)  'SET EOF IN HILITE FILE
2540 PUT #5,HILTECNT%
2550 PRINT "Score Processing Completed - Returning to MENU"
2560 CLOSE
2570 RUN "A:MENU"
2580 REM THIS ROUTINE IS ENTERED WHEN A SUBSTITUTE IS INDICATED -
2590 REM    IT CALCULATES ABSENCES AND WRITES THE HEADER FOR THE REGULAR BOWLER
2600 CURSER% = CVI(CURSER$)
2610 IF CURSER% < 50 GOTO 2630
2620 CURSER% = 0
2630 CURSER% = CURSER% + 1
2640 RSET CURSER$ = MKI$(CURSER%)
2650 PUT #2,TREC%
2660 RETURN