Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - George McGinn

Pages: 1 ... 12 13 [14]
196
InForm-based programs / Re: Distributing your InForm-based programs
« on: March 19, 2021, 04:52:12 pm »
Question - If I am distributing a binary executable do I need the same files? If not, what files do I need to include when providing an executable?

197
Programs / Re: Blackjack
« on: July 09, 2020, 11:52:08 am »
That makes sense. I do not think macOS can handle CHR$(0) at end–of–line. Internally only requires a linefeed character which I believe is CHR$(13).

Later on today I’m gonna fire up my Linux machine and give it a try on that (I have Linux Mint LMDE4 version installed, with version 1.4 of QB64)

Also there is another area that may not be related to this and I like someone else to check it Because I’m now cross side trying to count all the open and closing brackets, but this error that happened I believe is a separate bug in QB64 in that there is not enough closing brackets in the statement generated below:

./../temp/main.txt:304:70: error: arithmetic on a pointer to void
qbs_set(*((qbs**)((__UDT_DEALER)+(8))),qbs_add(*((qbs**)(__UDT_DEALER+(8))),((qbs*)(((uint64*)(__ARRAY_STRING_DECK[0]))[array_check((*__INTEGER_DECKINDEX)-__ARRAY_STRING_DECK[4],__ARRAY_STRING_DECK[5])]))));
                                                         ~~~~~~~~~~~~^
George

Hey it's not one of those CHR$(0) at the end of the string things is it?

198
Programs / Re: Blackjack
« on: July 09, 2020, 11:41:05 am »
Are there any specific coding for windows?

Since I have been coded in windows since the mid-1990s, plus one project I did in 2000–2001, I very rarely use windows because it always bothered to down my computer where macOS and Linux does not.

In macOS and Linux I very rarely get errors, unless there’s code for a specific operation system.


@George McGinn

Copy Paste test of code from forum to double check in my Windows 10 laptop, works fine!

Looks like macOS doesn't like QB64 so much?

199
Programs / Re: Blackjack
« on: July 08, 2020, 09:46:08 pm »
WOW!

Who Knew? I sure didn't. I just thought it was the most expedient way to do a random sort without having a SWAP statement.

I tested it with 8 decks (without all the print statements) and it still finished in hundreds or milliseconds.

I guess you should add my name to the WIKI, as I just co-invented it!!!

George

Hi @George McGinn

I see you come from Steve McNeil's camp of swapping each card with any of the other 52 cards.

There is a math proof that this is not ideal and leaves slightly less than perfect random distribution (given perfect random generator but who has that?)

"https://en.wikipedia.org/wiki/Fisher–Yates_shuffle"  <<copy/paste between quotes this in browser because underline link usually fails.

Look under Naive Shuffle:
 
Naive shuffle.PNG


200
Programs / Re: Blackjack
« on: July 08, 2020, 09:32:57 pm »
@bplus - I might take you up on creating a playing AI.

Give me about a month. I'm waiting to hear if I have been approved to buy a house, and may have to move quickly, by July 31. This means I'll be spending my time packing most of July.

201
Programs / Re: Blackjack
« on: July 08, 2020, 09:28:07 pm »
When I run the BJ Dealer Test program on macOS, I get the following errors (I'm running v1.4 of QB64:



In file included from qbx.cpp:2226:
./../temp/main.txt:100:33: error: arithmetic on a pointer to void
qbs_set(*((qbs**)((__UDT_DEALER)+(8))),qbs_new_txt_len("",0));
                  ~~~~~~~~~~~~~~^
./../temp/main.txt:135:46: error: arithmetic on a pointer to void
qbs_set(tqbs,qbs_right(*((qbs**)(__UDT_DEALER+(8))), 1 ));
                                 ~~~~~~~~~~~~^
./../temp/main.txt:304:33: error: arithmetic on a pointer to void
qbs_set(*((qbs**)((__UDT_DEALER)+(8))),qbs_add(*((qbs**)(__UDT_DEALER+(8))),((qbs*)(((uint64*)(__ARRAY_STRING_DECK[0]))[array_check((*__INTEGER_DECKINDEX)-__ARRAY_STRING_DECK[4],__ARRAY_STRING_DECK[5])]))));
                  ~~~~~~~~~~~~~~^
./../temp/main.txt:304:70: error: arithmetic on a pointer to void
qbs_set(*((qbs**)((__UDT_DEALER)+(8))),qbs_add(*((qbs**)(__UDT_DEALER+(8))),((qbs*)(((uint64*)(__ARRAY_STRING_DECK[0]))[array_check((*__INTEGER_DECKINDEX)-__ARRAY_STRING_DECK[4],__ARRAY_STRING_DECK[5])]))));
                                                         ~~~~~~~~~~~~^
./../temp/main.txt:337:116: error: arithmetic on a pointer to void
if ((qbs_cleanup(qbs_tmp_base,-(func_instr(NULL,qbs_new_txt_len("A23456789XJQK",13),func_mid(*((qbs**)(__UDT_DEALER+(8))),*_SUB_PLAYERADDCARD_INTEGER_I, 1 ,1),0)> 10 )))||new_error){
                                                                                                       ~~~~~~~~~~~~^
./../temp/main.txt:344:115: error: arithmetic on a pointer to void
*_SUB_PLAYERADDCARD_INTEGER_CV=func_instr(NULL,qbs_new_txt_len("A23456789XJQK",13),func_mid(*((qbs**)(__UDT_DEALER+(8))),*_SUB_PLAYERADDCARD_INTEGER_I, 1 ,1),0);
                                                                                                      ~~~~~~~~~~~~^
6 errors generated.

202
Programs / Re: Blackjack
« on: July 08, 2020, 07:50:13 pm »
Bbplus,

Here is the code that I have on techBASIC on my iPad. I basically do a manual swap.

The print statements are there so that when I tested it I could see what it was doing and making sure that it was not duplicating any numbers.

Near the technique is just about the same, but what I do is I first preload an array And then swap the numbers around.

The following code is NOT QB64, but it is simple enough that it it will probably run in QB64:

Code: Text: [Select]
  1.  
  2. ! Shuffle a deck of cards, represented by an array contiaining the
  3. ! ordinal number of each card.
  4.  
  5. DIM cards(52) AS INTEGER
  6.  
  7. FOR i = 1 TO 52
  8.     cards(i) = i
  9. NEXT
  10.  
  11. j=0
  12.  
  13. FOR i = 1 to 52
  14.     PRINT "i: ";i
  15.     j = INT(1 + Math.rand*52) ! This generates the random number to swap from
  16.     PRINT "j: ";j
  17.     temp = cards(i)                  ! Saves the card number currently at i
  18.     PRINT "temp=cards(i): ";temp
  19.     cards(i) = cards(j)              ! This swaps position j into i
  20.     PRINT "cards(i)=cards(j): ";cards(i)
  21.     cards(j) = temp                  ! This moves the value that was in i into j
  22.     PRINT "cards(j)=temp: ";cards(j)
  23.     PRINT
  24. NEXT
  25.  
  26. ! Print out the new deck just shuffled
  27. FOR i = 1 TO 52
  28.     PRINT cards(i)
  29. NEXT
  30.  

203
Programs / Re: Blackjack
« on: July 08, 2020, 07:35:08 pm »
Thank you.

The one I have a little bit longer, but it’s written for the techBASIC on iPad which does not have a SWAP statement.

However, I have noticed playing your blackjack game that it doesn’t quite follow basic play. I’ve noticed where the dealer has a 10 value showing, Everybody’s up to 16 should be hitting, yeah I’ve seen players stand on 13. I never a few other little things but I do understand what you’re trying to do with the AI. And it’s working pretty well so far.

I would however, chance a bust with a dealer showing a 10 value card as an up card, as I do in real life at casinos and do pretty well playing the basic strategy with some of my personal modifications.

Otherwise, you have done a great job on the coding.


Can shuffle be simpler than this from my last code post, from all my code that needs shuffle)?
Code: QB64: [Select]
  1.     FOR i = 52 TO 2 STEP -1 'shuffle
  2.         SWAP deck$(INT(RND * i) + 1), deck$(i)
  3.     NEXT
  4.  

Welcome aboard George!

204
Programs / Re: BASEBALL - TEXT VERSION
« on: July 08, 2020, 07:26:25 pm »
Thanks SierraKen,


I’m glad that you enjoyed the game, I do too.


I usually Forget to do that whenever I convert an old program to QB64, as most of the time I convert the program to my iPad using techBASIC and then once I get it working there I bring it over to QB64 where I generally have to make minor changes but I do forget to put the _LIMIT in it.

TechBASIC is based on the Apple IIgs GSoft BASIC.

205
Programs / Re: Blackjack
« on: July 07, 2020, 11:15:45 am »
Over on my iPad, I have a deck shuffling program which is very simple. I create a random array with numbers from 1 to 52, and these numbers serve as an index to another table that holds the card number and suit. I use graphics (UNICODE or the iPad's expanded ASCII Code) and the suit is the same size as the number.

I can bring it over to QB64 and get it to work if you are interested in it. I can even create options where you can create a shuffled array with 4 to 8 decks if you can use it.

206
Programs / Microsoft RemLine - Line Number Removal Utility
« on: July 07, 2020, 11:05:03 am »

This program will go through any QB64 that has line numbers, remove the ones that do not have a reference to it.

According to the comments:
    REMLINE.BAS is a program to remove line numbers from Microsoft Basic Programs. It removes only those line numbers that       
    are not the object of one of the following statements: GOSUB, RETURN, GOTO, THEN, ELSE, RESUME, RESTORE, or RUN.

    When REMLINE is run, it will ask for the name of the file to be processed and the name of the file or device to receive the
    reformatted output. If no extension is given, .BAS is assumed (except for output devices). If filenames are not given,
    REMLINE prompts for file names. If both filenames are the same, REMLINE saves the original file with the extension .BAK.

This is a handy utility if you are like me and love structured code. I have already converted and tested it on 50 Vintage BASIC programs and they ran with no issues with bad/missing line numbers (I did have to change some of the statements as different dialects have different ways of doing things not compatible with QB64). I use this program a lot because I will be publishing a blog on Vintage BASIC programs, and show how to convert them to run on QB64, which will be in all my posts.

I hope you find this program useful.

BTW: This program does not display a finish message, so if you need one, you should be able to put it just infront of the END statement.


Code: QB64: [Select]
  1. '
  2. '   Microsoft RemLine - Line Number Removal Utility
  3. '   Copyright (C) Microsoft Corporation 1985-1990
  4. '
  5. '   REMLINE.BAS is a program to remove line numbers from Microsoft Basic
  6. '   Programs. It removes only those line numbers that are not the object
  7. '   of one of the following statements: GOSUB, RETURN, GOTO, THEN, ELSE,
  8. '   RESUME, RESTORE, or RUN.
  9. '
  10. '   When REMLINE is run, it will ask for the name of the file to be
  11. '   processed and the name of the file or device to receive the
  12. '   reformatted output. If no extension is given, .BAS is assumed (except
  13. '   for output devices). If filenames are not given, REMLINE prompts for
  14. '   file names. If both filenames are the same, REMLINE saves the original
  15. '   file with the extension .BAK.
  16. '
  17. '   REMLINE makes several assumptions about the program:
  18. '
  19. '     1. It must be correct syntactically, and must run in BASICA or
  20. '        GW-BASIC interpreter.
  21. '     2. There is a 400 line limit. To process larger files, change
  22. '        MaxLines constant.
  23. '     3. The first number encountered on a line is considered a line
  24. '        number; thus some continuation lines (in a compiler-specific
  25. '        construction) may not be handled correctly.
  26. '     4. REMLINE can handle simple statements that test the ERL function
  27. '        using  relational operators such as =, <, and >. For example,
  28. '        the following statement is handled correctly:
  29. '
  30. '             IF ERL = 100 THEN END
  31. '
  32. '        Line 100 is not removed from the source code. However, more
  33. '        complex expressions that contain the +, -, AND, OR, XOR, EQV,
  34. '        MOD, or IMP operators may not be handled correctly. For example,
  35. '        in the following statement REMLINE does not recognize line 105
  36. '        as a referenced line number and removes it from the source code:
  37. '
  38. '             IF ERL + 5 = 105 THEN END
  39. '
  40. '   If you do not like the way REMLINE formats its output, you can modify
  41. '   the output lines in SUB GenOutFile. An example is shown in comments.
  42.  
  43. DEFINT A-Z
  44.  
  45. REM *** Increased size of input/display screen and change the font and its size (George McGinn)
  46. REM *** Setup Screen, Font Type,  and Size
  47. SCREEN _NEWIMAGE(800, 600, 32)
  48.  
  49. REM *** NOTE: I like Veranda, but you can remove it or replace it with your favorite font.
  50. fontpath$ = "Veranda.tff"
  51. font& = _LOADFONT(fontpath$, 16, "")
  52.  
  53.  
  54. ' Function and Subprocedure declarations
  55. DECLARE FUNCTION GetToken$ (Search$, Delim$)
  56. DECLARE FUNCTION StrSpn% (InString$, Separator$)
  57. DECLARE FUNCTION StrBrk% (InString$, Separator$)
  58. DECLARE FUNCTION IsDigit% (Char$)
  59. DECLARE SUB GetFileNames ()
  60. DECLARE SUB BuildTable ()
  61. DECLARE SUB GenOutFile ()
  62. DECLARE SUB InitKeyTable ()
  63.  
  64. ' Global and constant data
  65. CONST TRUE = -1
  66. CONST false = 0
  67. CONST MaxLines = 9999999
  68.  
  69. DIM SHARED LineTable!(MaxLines)
  70. DIM SHARED LineCount
  71. DIM SHARED Seps$, InputFile$, OutputFile$, TmpFile$
  72.  
  73. ' Keyword search data
  74. CONST KeyWordCount = 9
  75. DIM SHARED KeyWordTable$(KeyWordCount)
  76.  
  77. KeyData:
  78.  
  79. ' Start of module-level program code
  80. Seps$ = " ,:=<>()" + CHR$(9)
  81. InitKeyTable
  82. GetFileNames
  83. ON ERROR GOTO FileErr1
  84. OPEN InputFile$ FOR INPUT AS 1
  85. COLOR 7: PRINT "Working";: COLOR 23: PRINT " . . .": COLOR 7: PRINT
  86. BuildTable
  87. OPEN InputFile$ FOR INPUT AS 1
  88. ON ERROR GOTO FileErr2
  89. OPEN OutputFile$ FOR OUTPUT AS 2
  90. GenOutFile
  91. CLOSE #1, #2
  92. IF OutputFile$ <> "CON" THEN CLS
  93.  
  94.  
  95. FileErr1:
  96. PRINT "      Invalid file name": PRINT
  97. INPUT "      New input file name (ENTER to terminate): ", InputFile$
  98. IF InputFile$ = "" THEN END
  99. FileErr2:
  100. INPUT "      Output file name (ENTER to print to screen) :", OutputFile$
  101. IF (OutputFile$ = "") THEN OutputFile$ = "CON"
  102. IF TmpFile$ = "" THEN
  103.     RESUME
  104.     TmpFile$ = ""
  105.     RESUME NEXT
  106.  
  107. '
  108. ' BuildTable:
  109. '   Examines the entire text file looking for line numbers that are
  110. '   the object of GOTO, GOSUB, etc. As each is found, it is entered
  111. '   into a table of line numbers. The table is used during a second
  112. '   pass (see GenOutFile), when all line numbers not in the list
  113. '   are removed.
  114. ' Input:
  115. '   Uses globals KeyWordTable$, KeyWordCount, and Seps$
  116. ' Output:
  117. '   Modifies LineTable! and LineCount
  118. '
  119. SUB BuildTable STATIC
  120.  
  121.     DO WHILE NOT EOF(1)
  122.         ' Get line and first token
  123.         LINE INPUT #1, InLin$
  124.         Token$ = GetToken$(InLin$, Seps$)
  125.         DO WHILE (Token$ <> "")
  126.             FOR KeyIndex = 1 TO KeyWordCount
  127.                 ' See if token is keyword
  128.                 IF (KeyWordTable$(KeyIndex) = UCASE$(Token$)) THEN
  129.                     ' Get possible line number after keyword
  130.                     Token$ = GetToken$("", Seps$)
  131.                     ' Check each token to see if it is a line number
  132.                     ' (the LOOP is necessary for the multiple numbers
  133.                     ' of ON GOSUB or ON GOTO). A non-numeric token will
  134.                     ' terminate search.
  135.                     DO WHILE (IsDigit(LEFT$(Token$, 1)))
  136.                         LineCount = LineCount + 1
  137.                         LineTable!(LineCount) = VAL(Token$)
  138.                         Token$ = GetToken$("", Seps$)
  139.                         IF Token$ <> "" THEN KeyIndex = 0
  140.                     LOOP
  141.                 END IF
  142.             NEXT KeyIndex
  143.             ' Get next token
  144.             Token$ = GetToken$("", Seps$)
  145.         LOOP
  146.     LOOP
  147.  
  148.  
  149. '
  150. ' GenOutFile:
  151. '  Generates an output file with unreferenced line numbers removed.
  152. ' Input:
  153. '  Uses globals LineTable!, LineCount, and Seps$
  154. ' Output:
  155. '  Processed file
  156. '
  157. SUB GenOutFile STATIC
  158.  
  159.     ' Speed up by eliminating comma and colon (can't separate first token)
  160.     Sep$ = " " + CHR$(9)
  161.     DO WHILE NOT EOF(1)
  162.         LINE INPUT #1, InLin$
  163.         IF (InLin$ <> "") THEN
  164.             ' Get first token and process if it is a line number
  165.             Token$ = GetToken$(InLin$, Sep$)
  166.             IF IsDigit(LEFT$(Token$, 1)) THEN
  167.                 LineNumber! = VAL(Token$)
  168.                 FoundNumber = false
  169.                 ' See if line number is in table of referenced line numbers
  170.                 FOR index = 1 TO LineCount
  171.                     IF (LineNumber! = LineTable!(index)) THEN
  172.                         FoundNumber = TRUE
  173.                     END IF
  174.                 NEXT index
  175.                 ' Modify line strings
  176.                 IF (NOT FoundNumber) THEN
  177.                     Token$ = SPACE$(LEN(Token$))
  178.                     MID$(InLin$, StrSpn(InLin$, Sep$), LEN(Token$)) = Token$
  179.                 END IF
  180.  
  181.                 ' You can replace the previous lines with your own
  182.                 ' code to reformat output. For example, try these lines:
  183.  
  184.                 'TmpPos1 = StrSpn(InLin$, Sep$) + LEN(Token$)
  185.                 'TmpPos2 = TmpPos1 + StrSpn(MID$(InLin$, TmpPos1), Sep$)
  186.                 '
  187.                 'IF FoundNumber THEN
  188.                 '   InLin$ = LEFT$(InLin$, TmpPos1 - 1) + CHR$(9) + MID$(InLin$, TmpPos2)
  189.                 'ELSE
  190.                 '   InLin$ = CHR$(9) + MID$(InLin$, TmpPos2)
  191.                 'END IF
  192.  
  193.             END IF
  194.         END IF
  195.         ' Print line to file or console (PRINT is faster than console device)
  196.         IF OutputFile$ = "CON" THEN
  197.             PRINT InLin$
  198.         ELSE
  199.             PRINT #2, InLin$
  200.         END IF
  201.     LOOP
  202.  
  203.  
  204. '
  205. ' GetFileNames:
  206. '  Gets a file name by prompting the user.
  207. ' Input:
  208. '  User input
  209. ' Output:
  210. '  Defines InputFiles$ and OutputFiles$
  211. '
  212. SUB GetFileNames STATIC
  213.  
  214.     CLS
  215.     PRINT " Microsoft RemLine: Line Number Removal Utility"
  216.     PRINT "       (.BAS assumed if no extension given)"
  217.     PRINT
  218.     INPUT "      Input file name (ENTER to terminate): ", InputFile$
  219.     IF InputFile$ = "" THEN END
  220.     INPUT "      Output file name (ENTER to print to screen): ", OutputFile$
  221.     PRINT
  222.     IF (OutputFile$ = "") THEN OutputFile$ = "CON"
  223.  
  224.     IF INSTR(InputFile$, ".") = 0 THEN
  225.         InputFile$ = InputFile$ + ".BAS"
  226.     END IF
  227.  
  228.     IF INSTR(OutputFile$, ".") = 0 THEN
  229.         SELECT CASE OutputFile$
  230.             CASE "CON", "SCRN", "PRN", "COM1", "COM2", "LPT1", "LPT2", "LPT3"
  231.                 EXIT SUB
  232.             CASE ELSE
  233.                 OutputFile$ = OutputFile$ + ".BAS"
  234.         END SELECT
  235.     END IF
  236.  
  237.     DO WHILE InputFile$ = OutputFile$
  238.         TmpFile$ = LEFT$(InputFile$, INSTR(InputFile$, ".")) + "BAK"
  239.         ON ERROR GOTO FileErr1
  240.         NAME InputFile$ AS TmpFile$
  241.         ON ERROR GOTO 0
  242.         IF TmpFile$ <> "" THEN InputFile$ = TmpFile$
  243.     LOOP
  244.  
  245.  
  246. '
  247. ' GetToken$:
  248. '  Extracts tokens from a string. A token is a word that is surrounded
  249. '  by separators, such as spaces or commas. Tokens are extracted and
  250. '  analyzed when parsing sentences or commands. To use the GetToken$
  251. '  function, pass the string to be parsed on the first call, then pass
  252. '  a null string on subsequent calls until the function returns a null
  253. '  to indicate that the entire string has been parsed.
  254. ' Input:
  255. '  Search$ = string to search
  256. '  Delim$  = String of separators
  257. ' Output:
  258. '  GetToken$ = next token
  259. '
  260. FUNCTION GetToken$ (Search$, Delim$) STATIC
  261.  
  262.     ' Note that SaveStr$ and BegPos must be static from call to call
  263.     ' (other variables are only static for efficiency).
  264.     ' If first call, make a copy of the string
  265.     IF (Search$ <> "") THEN
  266.         BegPos = 1
  267.         SaveStr$ = Search$
  268.     END IF
  269.  
  270.     ' Find the start of the next token
  271.     NewPos = StrSpn(MID$(SaveStr$, BegPos, LEN(SaveStr$)), Delim$)
  272.     IF NewPos THEN
  273.         ' Set position to start of token
  274.         BegPos = NewPos + BegPos - 1
  275.     ELSE
  276.         ' If no new token, quit and return null
  277.         GetToken$ = ""
  278.         EXIT FUNCTION
  279.     END IF
  280.  
  281.     ' Find end of token
  282.     NewPos = StrBrk(MID$(SaveStr$, BegPos, LEN(SaveStr$)), Delim$)
  283.     IF NewPos THEN
  284.         ' Set position to end of token
  285.         NewPos = BegPos + NewPos - 1
  286.     ELSE
  287.         ' If no end of token, return set to end a value
  288.         NewPos = LEN(SaveStr$) + 1
  289.     END IF
  290.     ' Cut token out of search string
  291.     GetToken$ = MID$(SaveStr$, BegPos, NewPos - BegPos)
  292.     ' Set new starting position
  293.     BegPos = NewPos
  294.  
  295.  
  296. '
  297. ' InitKeyTable:
  298. '  Initializes a keyword table. Keywords must be recognized so that
  299. '  line numbers can be distinguished from numeric constants.
  300. ' Input:
  301. '  Uses KeyData
  302. ' Output:
  303. '  Modifies global array KeyWordTable$
  304. '
  305. SUB InitKeyTable STATIC
  306.  
  307.     RESTORE KeyData
  308.     FOR Count = 1 TO KeyWordCount
  309.         READ KeyWord$
  310.         KeyWordTable$(Count) = KeyWord$
  311.     NEXT
  312.  
  313.  
  314. '
  315. ' IsDigit:
  316. '  Returns true if character passed is a decimal digit. Since any
  317. '  Basic token starting with a digit is a number, the function only
  318. '  needs to check the first digit. Doesn't check for negative numbers,
  319. '  but that's not needed here.
  320. ' Input:
  321. '  Char$ - initial character of string to check
  322. ' Output:
  323. '  IsDigit - true if within 0 - 9
  324. '
  325. FUNCTION IsDigit (Char$) STATIC
  326.  
  327.     IF (Char$ = "") THEN
  328.         IsDigit = false
  329.     ELSE
  330.         CharAsc = ASC(Char$)
  331.         IsDigit = (CharAsc >= ASC("0")) AND (CharAsc <= ASC("9"))
  332.     END IF
  333.  
  334.  
  335. '
  336. ' StrBrk:
  337. '  Searches InString$ to find the first character from among those in
  338. '  Separator$. Returns the index of that character. This function can
  339. '  be used to find the end of a token.
  340. ' Input:
  341. '  InString$ = string to search
  342. '  Separator$ = characters to search for
  343. ' Output:
  344. '  StrBrk = index to first match in InString$ or 0 if none match
  345. '
  346. FUNCTION StrBrk (InString$, Separator$) STATIC
  347.  
  348.     Ln = LEN(InString$)
  349.     BegPos = 1
  350.     ' Look for end of token (first character that is a delimiter).
  351.     DO WHILE INSTR(Separator$, MID$(InString$, BegPos, 1)) = 0
  352.         IF BegPos > Ln THEN
  353.             StrBrk = 0
  354.             EXIT FUNCTION
  355.         ELSE
  356.             BegPos = BegPos + 1
  357.         END IF
  358.     LOOP
  359.     StrBrk = BegPos
  360.  
  361.  
  362. '
  363. ' StrSpn:
  364. '  Searches InString$ to find the first character that is not one of
  365. '  those in Separator$. Returns the index of that character. This
  366. '  function can be used to find the start of a token.
  367. ' Input:
  368. '  InString$ = string to search
  369. '  Separator$ = characters to search for
  370. ' Output:
  371. '  StrSpn = index to first nonmatch in InString$ or 0 if all match
  372. '
  373. FUNCTION StrSpn% (InString$, Separator$) STATIC
  374.  
  375.     Ln = LEN(InString$)
  376.     BegPos = 1
  377.     ' Look for start of a token (character that isn't a delimiter).
  378.     DO WHILE INSTR(Separator$, MID$(InString$, BegPos, 1))
  379.         IF BegPos > Ln THEN
  380.             StrSpn = 0
  381.             EXIT FUNCTION
  382.         ELSE
  383.             BegPos = BegPos + 1
  384.         END IF
  385.     LOOP
  386.     StrSpn = BegPos
  387.  
  388.  

207
Programs / BASEBALL - TEXT VERSION
« on: July 07, 2020, 10:46:44 am »
This program came with the Altair 8800, 8K BASIC.

I remember this game because as a graduation present, my parents bought me an Altair 8800. I loved working with that computer, and it helped me to understand how to code in machine code, which came in handy when I was a systems programmer and had to solve problems on an IBM 360/67 mainframe. The lights and switches worked just like the ones on the Altair 8800, but 360 showed a lot more registers. memory, and instruction sets.

So I have gone back and got a Altair Clone, so you will see some oldies but goodies here.

I plan to add graphics to this game once I unspaghettify the code (I also have a QB64 version of Microsoft's Remove Line Numbers program, which I will also post here.

I first got this code to run on my iPad using TechBASIC (a modified version GSoft BASIC, but designed to work with sensors and Arduino and PI boards), that made the conversion to QB64 easier, as GSoft BASIC ran on the Apple IIgs.

Also, in modifying the code for QB64, I am also attaching to this post the Veranda ttf Font File, as I use it in the code. You can look at the Screen section and replace that with any font you like.

Here is the program.

Code: QB64: [Select]
  1. _TITLE "BASEBALL (TEXT VERSION)"
  2.  
  3. REM "BASEBALL SIMULATION PROGRAM (TEXT MODE)
  4. REM "A VERSION OF THIS PROGRAM RAN ON THE ALTAIR 8800 8K BASIC (1977)
  5. REM "WRITTEN BY JOEL LIND & KEN BIRKMAN - NYU - JULY 1973
  6. REM "STOLEN AND ENHANCED DECEMBER 1973 BY R. D. KURLAND - NYU
  7. REM "RESTOLEN AND CONVERTED TO RUN IN TECHBASIC (JULY 7, 2020) BY GEORGE MCGINN
  8. REM "CONVERTED FROM TECHBASIC TO QB64 (JULY 7, 2020) BY GEORGE MCGINN
  9.  
  10. '***************************************************
  11. ' SETUP SCREEN FORMAT & SIZE, FONT TYPE & SIZE
  12. '***************************************************
  13.  
  14. '*** Setup Screen Format and Size
  15. SCREEN _NEWIMAGE(800, 700, 32)
  16.  
  17. '*** Setup and load Font Type, Format and Size
  18. fontpath$ = "Veranda.tff"
  19. font& = _LOADFONT(fontpath$, 16, "")
  20.  
  21.  
  22. 130 DIM B(7), P$(9), W$(7), J$(8), K$(4)
  23. 140 FOR I = 1 TO 7: B(I) = 0: NEXT
  24. 150 BA = 0: T9 = 0: R9 = 0: S = 0: O = 0: B1 = 0: B2 = 0: T = 0
  25. 160 Z1 = 1: Z2 = 1
  26. 170 PRINT "WELCOME TO EBBETT'S FIELD"
  27. 180 PRINT "WHAT DO YOU WANT TO CALL YOUR TEAM ";
  28. 190 INPUT A$
  29. 200 FOR I = 1 TO 7: READ W$(I): NEXT
  30. 210 FOR I = 1 TO 9: READ P$(I): NEXT
  31. 220 FOR I = 1 TO 4: READ K$(I): NEXT
  32. 230 FOR I = 1 TO 8: READ J$(I): NEXT
  33. 240 PRINT "FINE. THE "; A$; " NEED A MANAGER. WHAT'S YOUR NAME ";
  34. 250 INPUT B$
  35. 260 PRINT "WHAT DO YOU WANT TO CALL MY TEAM, "; B$;
  36. 270 INPUT C$
  37. 280 PRINT
  38. 290 PRINT "OPENING DAY, THE "; A$; " VERSUS THE "; C$
  39. 300 PRINT
  40. 310 PRINT "LET'S FLIP A COIN. THE WINNER IS THE HOME TEAM."
  41. 320 PRINT "HEADS OR TAILS ";
  42. 330 INPUT D$: D$ = UCASE$(D$)
  43. 340 IF D$ <> "HEADS" AND D$ <> "TAILS" THEN GOTO 320
  44. 350 FOR I = 1 TO TYM
  45. 360 Y = RND(1)
  46. 370 NEXT I
  47. 380 H = 1
  48. 390 Y = RND(1)
  49. 400 Y$ = "HEADS"
  50. 410 IF Y > .5 THEN Y$ = "TAILS"
  51. 420 IF D$ = Y$ THEN 490
  52. 430 H = 0
  53. 440 PRINT "YOU LOST THE TOSS. THE "; A$; " ARE UP FIRST."
  54. 450 PRINT
  55. 460 PRINT
  56. 470 A = 0
  57. 480 GOTO 610
  58. 490 PRINT "YOU WIN THE TOSS. "; A$; " TAKE THE FIELD, AND ";
  59. 500 PRINT C$; " ARE AT BAT."
  60. 510 A = 1
  61. 520 R9 = 0
  62. 530 T = T + 1
  63. 540 IF T < 18 THEN GOSUB 5140
  64. 550 IF T < 18 THEN 710
  65. 560 IF T > 18 THEN 590
  66. 570 GOSUB 3500
  67. 580 GOTO 710
  68. 590 GOSUB 3290
  69. 600 GOTO 710
  70. 610 REM START AN INNING - WE ARE OUT ON THE FIELD
  71. 620 T = T + 1
  72. 630 R9 = 0
  73. 640 IF T < 18 THEN 690
  74. 650 IF T > 18 THEN 680
  75. 660 GOSUB 3500
  76. 670 GOTO 690
  77. 680 GOSUB 3290
  78. 690 REM IF T>2 THEN 710
  79. 700 GOSUB 5070
  80. 710 S = 0: BA = 0
  81. 720 PRINT
  82. 730 IF O = 0 THEN PRINT "NO OUTS"
  83. 740 IF O = 1 THEN PRINT "THERE IS 1 OUT"
  84. 750 IF O > 1 THEN PRINT "THERE ARE "; O; " OUTS"
  85. 760 P = B(1) + B(2) + B(3)
  86. 770 IF P <> 3 THEN 800
  87. 780 PRINT "BASES LOADED"
  88. 790 GOTO 900
  89. 800 IF P = 0 THEN 900
  90. 810 Y$ = "RUNNER ON "
  91. 820 IF P > 1 THEN Y$ = "RUNNERS ON "
  92. 830 PRINT Y$;
  93. 840 IF B(1) = 0 THEN 870
  94. 850 PRINT "FIRST";
  95. 860 IF P > 1 THEN PRINT " AND ";
  96. 870 IF B(2) = 1 THEN PRINT "SECOND";
  97. 880 IF P > 1 AND B(1) = 0 THEN PRINT " AND ";
  98. 890 IF B(3) = 1 THEN
  99.     PRINT "THIRD"
  100.     PRINT " "
  101. 900 IF A = 0 THEN 920
  102. 910 GOTO 3030
  103. 920 PRINT "BATTER UP"
  104. 930 IF BA <> 3 OR S <> 2 THEN 960
  105. 940 PRINT "FULL COUNT"
  106. 950 GOTO 970
  107. 960 IF BA > 0 OR S > 0 THEN PRINT "THE COUNT IS "; BA; " AND "; S
  108. 970 PRINT
  109. 980 IF A = 1 THEN 3030
  110. 990 PRINT "WHAT WILL YOUR BATTER DO, "; B$;
  111. 1000 INPUT C
  112. 1010 IF C > 0 AND C < 5 THEN GOTO 1050
  113. 1020 PRINT "HUH?  ";
  114. 1030 GOSUB 5070
  115. 1040 GOTO 990
  116. 1050 Y2 = RND(1)
  117. 1060 IF Y2 < .56 OR Y2 > .5625 THEN GOTO 1120
  118. 1070 PRINT "WILD PITCH!"
  119. 1080 N = 1
  120. 1090 GOSUB 3540
  121. 1100 B(1) = 0
  122. 1110 GOTO 1210
  123. 1120 IF Y2 > .772 AND Y2 < .775 THEN 4880
  124. 1130 ON C GOTO 1140, 1450, 2600, 4450, 5500
  125. 1140 C = 1
  126. 1150 GOSUB 5240
  127. 1160 IF A = 0 THEN Z1 = Z1 + 1
  128. 1170 Y = RND(1)
  129. 1180 IF BA <> 3 OR S <> 0 THEN 1200
  130. 1190 IF Y < .7 THEN GOTO 1310 ELSE GOTO 1210
  131. 1200 IF Y < .5 THEN 1310
  132. 1210 BA = BA + 1
  133. 1220 Y = INT(RND(1) * 8 + 1)
  134. 1230 IF Y = 9 THEN 1220
  135. 1240 PRINT J$(Y); " - BALL "; BA
  136. 1250 IF BA <> 4 THEN 930
  137. 1260 PRINT "WALK"
  138. 1270 GOSUB 4950
  139. 1280 Y = RND(1)
  140. 1290 GOTO 710
  141. 1300 PRINT "HIGH POP - FOUL DOWN THE "; Y$; " FIELD LINE"
  142. 1310 S = S + 1
  143. 1320 IF C = 2 OR C = 5 THEN GOTO 1370
  144. 1330 Y = INT(RND(1) * 4 + 1)
  145. 1340 IF Y = 5 THEN 1330
  146. 1350 PRINT K$(Y); ", CALLED STRIKE "; S
  147. 1360 GOTO 1380
  148. 1370 PRINT "SWINGING STRIKE "; S
  149. 1380 IF C = 5 AND S <> 3 THEN 4450
  150. 1390 IF S <> 3 THEN 930
  151. 1400 PRINT "STRUCK OUT"
  152. 1410 O = O + 1
  153. 1420 IF O = 3 THEN 2850
  154. 1430 IF C = 5 THEN 4450
  155. 1440 GOTO 710
  156. 1450 C = 2
  157. 1460 Y = INT(RND(1) * 10 + 1)
  158. 1470 IF Y = 10 THEN 1450
  159. 1480 IF A = 0 THEN Z2 = Z2 + 1
  160. 1490 IF C <> 5 THEN GOSUB 5240
  161. 1500 IF S <> 2 AND Z2 / Z1 > 7 AND A = 0 THEN 1520
  162. 1510 IF S <> 2 OR Z2 / Z1 < 25 THEN 1590
  163. 1520 Y = INT(RND(1) * 20 + 1)
  164. 1530 IF Y > 7 THEN 1550
  165. 1540 ON Y GOTO 1610, 1310, 1310, 1310, 1310, 1680, 1610
  166. 1550 IF Y > 13 THEN 1570
  167. 1560 ON Y - 7 GOTO 1680, 1310, 1740, 1850, 1740, 1850
  168. 1570 IF Y > 18 THEN 1600
  169. 1580 ON Y - 13 GOTO 1980, 1980, 2040, 2570, 1640, 2570
  170. 1590 IF Y < 3 THEN 1310
  171. 1600 ON Y - 2 GOTO 1610, 1680, 1740, 1850, 1980, 2040, 2570
  172. 1610 PRINT "FOULED INTO THE STANDS-OUT OF PLAY"
  173. 1620 IF S <> 2 THEN S = S + 1
  174. 1630 GOTO 930
  175. 1640 Y = RND(1)
  176. 1650 Y$ = "RIGHT"
  177. 1660 IF Y < .5 THEN Y$ = "LEFT"
  178. 1670 GOTO 1620
  179. 1680 Y = INT(RND(1) * 20 + 1)
  180. 1690 IF Y > 18 THEN 1720
  181. 1700 PRINT "FOULED BACK INTO THE STANDS"
  182. 1710 GOTO 1620
  183. 1720 PRINT "POPPED IT UP - CAUGHT BY CATCHER"
  184. 1730 GOTO 1410
  185. 1740 PRINT "INFIELD GROUNDER"
  186. 1750 E2 = RND(1)
  187. 1760 IF E2 < .37 OR E2 > .41 THEN 1820
  188. 1770 PRINT "1 BASE ERROR!!"
  189. 1780 N = 1
  190. 1790 C = 4
  191. 1800 GOSUB 3540
  192. 1810 GOTO 710
  193. 1820 GOSUB 4100
  194. 1830 IF O = 3 THEN 2850
  195. 1840 GOTO 710
  196. 1850 PRINT "GROUNDER - COULD BE TROUBLE - "
  197. 1860 Y = RND(1)
  198. 1870 IF Y > .75 THEN 1950
  199. 1880 Y$ = "UP THE MIDDLE"
  200. 1890 IF Y < .5 THEN Y$ = "THROUGH THE HOLE INTO RIGHT FIELD"
  201. 1900 IF Y < .25 THEN Y$ = "THROUGH THE HOLE INTO LEFT FIELD"
  202. 1910 PRINT "A SINGLE "; Y$; "!"
  203. 1920 N = 1
  204. 1930 GOSUB 3540
  205. 1940 GOTO 710
  206. 1950 PRINT "INFIELDER UP WITH IT!"
  207. 1960 GOSUB 4800
  208. 1970 IF O = 3 THEN GOTO 2850 ELSE GOTO 710
  209. 1980 Y = RND(1)
  210. 1990 Y$ = "LEFT"
  211. 2000 IF Y < .6 THEN Y$ = "CENTER"
  212. 2010 IF Y < .3 THEN Y$ = "RIGHT"
  213. 2020 PRINT "FLY-OUT TO "; Y$; " FIELD"
  214. 2030 GOTO 1410
  215. 2040 Z = RND(1)
  216. 2050 Y$ = "CENTER"
  217. 2060 IF Z < .6 THEN Y$ = "RIGHT"
  218. 2070 IF Z < .3 THEN Y$ = "LEFT"
  219. 2080 PRINT "LONG FLY TO DEEP "; Y$; " FIELD - LOOKS GOOD! "
  220. 2090 Z = RND(1)
  221. 2100 IF Z < .9 THEN 2130
  222. 2110 PRINT Y$; "FIELDER CAUGHT IT AT THE WALL!"
  223. 2120 GOTO 2180
  224. 2130 IF Z < .8 THEN 2160
  225. 2140 PRINT "A DIVING CATCH!"
  226. 2150 GOTO 2180
  227. 2160 IF Z < .7 THEN 2290
  228. 2170 PRINT Y$; "FIELDER CAUGHT IT ON THE WARNING TRACK!"
  229. 2180 O = O + 1
  230. 2190 IF O = 3 THEN 2850
  231. 2200 FOR I = 3 TO 1 STEP -1
  232. 2210 IF B(I) = 1 THEN 2240
  233. 2220 NEXT I
  234. 2230 GOTO 710
  235. 2240 B(I + 1) = B(I)
  236. 2250 B(I) = 0
  237. 2260 PRINT "LEAD RUNNER TAGS UP - AND ADVANCES 1 BASE!"
  238. 2270 GOSUB 3830
  239. 2280 GOTO 710
  240. 2290 IF Z < .5 THEN 2360
  241. 2300 PRINT "BATTER HOLDS WITH A SINGLE."
  242. 2310 N = 2
  243. 2320 GOSUB 3540
  244. 2330 B(2) = 0
  245. 2340 B(1) = 1
  246. 2350 GOTO 710
  247. 2360 IF Z < .15 THEN 2480
  248. 2370 PRINT "DOUBLE!"
  249. 2380 Y = RND(1)
  250. 2390 IF Y > .5 THEN 2430
  251. 2400 N = 2
  252. 2410 GOSUB 3540
  253. 2420 GOTO 710
  254. 2430 N = 3
  255. 2440 GOSUB 3540
  256. 2450 B(3) = 0
  257. 2460 B(2) = 1
  258. 2470 GOTO 710
  259. 2480 IF Z < .1 THEN 2530
  260. 2490 PRINT "TRIPLE!"
  261. 2500 N = 3
  262. 2510 GOSUB 3540
  263. 2520 GOTO 710
  264. 2530 PRINT "IT'S OVER THE WALL -- A H*O*M*E R*U*N!!!"
  265. 2540 N = 4
  266. 2550 GOSUB 3540
  267. 2560 GOTO 710
  268. 2570 Y = INT(RND(1) * 7 + 1)
  269. 2580 PRINT "LINED OUT TO "; P$(Y)
  270. 2590 GOTO 1410
  271. 2600 GOSUB 5240
  272. 2610 PRINT "BATTER BUNTS... "
  273. 2620 Y = RND(1)
  274. 2630 IF Y < .6 THEN 2750
  275. 2640 IF B(3) = 0 THEN 2660
  276. 2650 IF Y < .8 THEN 2830
  277. 2660 PRINT "THROWN OUT AT FIRST."
  278. 2670 O = O + 1
  279. 2680 IF O = 3 THEN 2850
  280. 2690 IF B(1) + B(2) + B(3) = 0 THEN 710
  281. 2700 PRINT "SACRIFICE - ";
  282. 2710 N = 1
  283. 2720 GOSUB 3540
  284. 2730 B(1) = 0
  285. 2740 GOTO 710
  286. 2750 IF Y < .2 THEN 2830
  287. 2760 IF Y < .4 THEN 2790
  288. 2770 PRINT "BATTER MISSES PITCH"
  289. 2780 GOTO 1310
  290. 2790 PRINT "BEATS IT OUT! SINGLE!"
  291. 2800 N = 1
  292. 2810 GOSUB 3540
  293. 2820 GOTO 710
  294. 2830 GOSUB 4100
  295. 2840 IF O <> 3 THEN 710
  296. 2850 PRINT "3 OUTS. THE SIDE IS RETIRED";
  297. 2860 I = B(1) + B(2) + B(3)
  298. 2870 IF I = 0 THEN PRINT "."
  299. 2880 IF I = 1 THEN PRINT ", LEAVING 1 MAN ON BASE"
  300. 2890 IF I > 1 THEN PRINT ", LEAVING "; I; " MEN ON BASE"
  301. 2900 PRINT
  302. 2910 PRINT
  303. 2920 PRINT "*************"
  304. 2930 D = T / 2 - INT(T / 2)
  305. 2940 PRINT "AFTER ";
  306. 2950 IF T > 1 THEN PRINT INT(T / 2); " ";
  307. 2960 IF D > .3 THEN PRINT "1/2 ";
  308. 2970 Y$ = "INNINGS"
  309. 2980 IF T < 3 THEN Y$ = "INNING"
  310. 2990 PRINT Y$; " OF PLAY, THE SCORE IS"
  311. 3000 GOSUB 3960
  312. 3010 O = 0: B(1) = 0: B(2) = 0: B(3) = 0
  313. 3020 IF A = 0 THEN GOTO 510 ELSE GOTO 470
  314. 3030 REM MY TEAM IS AT BAT
  315. 3040 Y = RND(1)
  316. 3050 IF B(1) + B(2) + B(3) = 0 THEN 3140
  317. 3060 REM IF O=2 AND S=2 AND B=3 THEN 4850
  318. 3070 IF B(3) = 1 THEN 3110
  319. 3080 IF B(2) = 0 THEN 3100
  320. 3090 IF .45 < Y AND .46 > Y THEN 4450
  321. 3100 IF .45 < Y AND .47 > Y THEN 4450
  322. 3110 IF O = 2 THEN 3140
  323. 3120 IF O < 2 AND Y < .333 AND B(3) = 1 THEN 2600
  324. 3130 IF .45 < Y AND .55 > Y THEN 2600
  325. 3140 IF S = 0 THEN 3240
  326. 3150 IF BA <> 3 THEN GOTO 3180
  327. 3160 IF Y < .6 THEN GOTO 1450
  328. 3170 GOTO 1140
  329. 3180 IF Y > .3 THEN GOTO 1450
  330. 3190 IF S <> 2 THEN GOTO 1140
  331. 3200 IF BA = 0 AND Y < .1 THEN GOTO 1140
  332. 3210 IF BA = 0 THEN GOTO 1450
  333. 3220 IF Y < .2 THEN GOTO 1140
  334. 3230 GOTO 1450
  335. 3240 IF BA = 3 THEN GOTO 3270
  336. 3250 IF Y < .6 THEN GOTO 1140
  337. 3260 GOTO 1450
  338. 3270 IF Y < .9 THEN GOTO 1140
  339. 3280 GOTO 1450
  340. 3290 IF T <> 19 THEN GOTO 3330
  341. 3300 IF R1 <> R2 THEN GOTO 3340
  342. 3310 PRINT
  343. 3320 PRINT "*** GOING INTO EXTRA INNINGS ***"
  344. 3330 IF R1 = R2 THEN RETURN
  345. 3340 IF (T - 1) / 2 <> INT(T - 1) / 2 THEN RETURN
  346. 3350 PRINT "THE BALLGAME IS OVER."
  347. 3360 PRINT "*************"
  348. 3370 PRINT "FINAL SCORE:"
  349. 3380 T9 = 1
  350. 3390 GOSUB 3960
  351. 3400 IF R1 > R2 THEN 3470
  352. 3410 PRINT "NICE TRY, "; B$
  353. 3420 PRINT "YOU SHOULD KNOW BETTER THAN TO TRY TO"
  354. 3430 PRINT "OUT-MANAGE A COMPUTER.  MAYBE BASEBALL"
  355. 3440 PRINT "JUST ISN'T YOUR SPORT...WHY DON'T YOU TRY GOLF?"
  356. 3450 REM CHAIN GOLF
  357. 3460 STOP
  358. 3470 PRINT "CONGRATULATIONS, "; B$
  359. 3480 PRINT "YOU'VE BEATEN ME, BUT I WILL HAVE MY REVENGE."
  360. 3490 STOP
  361. 3500 REM 9TH INNING
  362. 3510 IF A = 0 THEN 3530
  363. 3520 IF R2 > R1 THEN GOTO 3350 ELSE RETURN
  364. 3530 IF R1 > R2 THEN GOTO 3350 ELSE RETURN
  365. 3540 REM ADVANCE N BASES (SET N BEFORE GOSUB)
  366. 3550 N2 = B(1) + B(2) + B(3)
  367. 3560 IF C = 5 THEN N = N + 1
  368. 3570 N3 = N
  369. 3580 IF N2 = 0 THEN 3650
  370. 3590 REM FIND LAST RUNNER: MAKE SURE HE ISN‘T TRYING TO ADVANCE
  371. 3600 REM PAST HOME PLATE.
  372. 3610 FOR I = 1 TO 3
  373. 3620 IF B(I) = 1 THEN 3640
  374. 3630 NEXT I
  375. 3640 IF 4 - I < N THEN N3 = 4 - I
  376. 3650 FOR I = 3 + N TO N + 1 STEP -1
  377. 3660 B(I) = B(I - N)
  378. 3670 NEXT I
  379. 3680 B(N) = 1
  380. 3690 IF N = 1 THEN 3740
  381. 3700 FOR P = 1 TO 3
  382. 3710 IF (N - P) > 1 THEN B(N - P) = 0
  383. 3720 IF (N - P) <= 1 THEN B(1) = 0
  384. 3730 NEXT P
  385. 3740 FOR P = 1 TO 7
  386. 3750 IF P = N THEN 3780
  387. 3760 NEXT P
  388. 3770 GOTO 3830
  389. 3780 IF C = 4 OR N2 = 0 THEN 3830
  390. 3790 Y$ = "RUNNERS ADVANCE "
  391. 3800 IF N2 = 1 THEN Y$ = "RUNNER ADVANCES "
  392. 3810 PRINT Y$; N3;
  393. 3820 IF N3 = 1 THEN
  394.     PRINT " BASE"
  395.     PRINT " BASES"
  396. 3830 IF B(4) + B(5) + B(6) + B(7) = 0 THEN RETURN
  397. 3840 REM AT LEAST 1 RUN HAS SCORED.
  398. 3850 N2 = B(4) + B(5) + B(6) + B(7)
  399. 3860 IF A = 0 THEN 3890
  400. 3870 R2 = R2 + N2
  401. 3880 GOTO 3900
  402. 3890 R1 = R1 + N2
  403. 3900 B(4) = 0: B(5) = 0: B(6) = 0: B(7) = 0
  404. 3910 IF N2 = 1 THEN PRINT "** 1 RUN SCORED"
  405. 3920 IF N2 > 1 THEN PRINT "** "; N2; " RUNS SCORED"
  406. 3930 PRINT
  407. 3940 PRINT
  408. 3950 PRINT "******** NEW SCORE:"
  409. 3960 IF H = 1 THEN 4000
  410. 3970 IF LEN(A$) > LEN(C$) THEN PRINT A$; TAB(LEN(A$) + 3); R1
  411. 3980 IF LEN(A$) <= LEN(C$) THEN PRINT A$; TAB(LEN(C$) + 3); R1
  412. 3990 IF H = 1 THEN 4030
  413. 4000 IF LEN(A$) > LEN(C$) THEN PRINT C$; TAB(LEN(A$) + 3); R2
  414. 4010 IF LEN(A$) <= LEN(C$) THEN PRINT C$; TAB(LEN(C$) + 3); R2
  415. 4020 IF H = 1 THEN 3970
  416. 4030 PRINT "*************"
  417. 4040 PRINT
  418. 4050 PRINT
  419. 4060 IF T9 = 1 THEN 4090
  420. 4070 IF A = 1 AND T > 17 AND INT(T / 2) = T / 2 AND R2 > R1 THEN 3350
  421. 4080 IF A = 0 AND T > 17 AND INT(T / 2) = T / 2 AND R1 > R2 THEN 3350
  422. 4090 RETURN
  423. 4100 REM LEAD RUNNER OUT (FIELDER‘S CHOICE THEN ONE BASE ADVANCE)
  424. 4110 N = 1
  425. 4120 I = 4
  426. 4130 IF B(4) = 0 AND B(3) = 1 AND B(2) = 1 AND B(1) = 1 THEN 4220
  427. 4140 I = 3
  428. 4150 IF B(3) = 0 AND B(2) = 1 AND B(1) = 1 THEN 4220
  429. 4160 I = 2
  430. 4170 IF B(2) = 0 AND B(1) = 1 THEN 4220
  431. 4180 REM NO ONE FORCED
  432. 4190 O = O + 1
  433. 4200 PRINT "BATTER THROWN OUT"
  434. 4210 RETURN
  435. 4220 B(I - 1) = 0
  436. 4230 F = RND(1)
  437. 4240 IF O = 2 OR F > .3 THEN 4290
  438. 4250 O = O + 2
  439. 4260 PRINT "DOUBLE PLAY!"
  440. 4270 IF O = 3 THEN RETURN
  441. 4280 GOTO 4910
  442. 4290 O = O + 1
  443. 4300 PRINT "RUNNER ON BASE "; I - 1; " IS OUT ON FIELDER'S CHOICE"
  444. 4310 IF O = 3 THEN RETURN
  445. 4320 GOSUB 3540
  446. 4330 RETURN
  447. 4340 REM FORCED RUNNERS ADVANCE 1 BASE, OTHERS HOLD
  448. 4350 FOR I = 1 TO 3
  449. 4360 IF B(I) = 0 THEN 4400
  450. 4370 NEXT I
  451. 4380 N = 1
  452. 4390 GOTO 3540
  453. 4400 REM NO ONE ON BASE I
  454. 4410 FOR I2 = I TO 1 STEP -1
  455. 4420 B(I2) = 1
  456. 4430 NEXT I2
  457. 4440 RETURN
  458. 4450 REM LEAD RUNNER STEALS
  459. 4460 FOR I = 3 TO 1 STEP -1
  460. 4470 IF B(I) = 1 THEN 4510
  461. 4480 NEXT I
  462. 4490 PRINT "NO ONE ON BASE, DUMMY!"
  463. 4500 GOTO 990
  464. 4510 REM I IS LEAD RUNNER‘S BASE
  465. 4520 IF C <> 5 THEN GOSUB 5240
  466. 4530 IF RND(1) / I < .3 THEN 4680
  467. 4540 IF B(1) + B(2) + B(3) > 1 THEN 4570
  468. 4550 PRINT "RUNNER STEALS A BASE"
  469. 4560 GOTO 4580
  470. 4570 PRINT "RUNNERS STEAL A BASE"
  471. 4580 N = 1
  472. 4590 C2 = C
  473. 4600 C = 4
  474. 4610 GOSUB 3540
  475. 4620 C = C2
  476. 4630 B(1) = 0
  477. 4640 IF C = 5 AND S <> 3 THEN 930
  478. 4650 IF C = 5 THEN 710
  479. 4660 Y = RND(1)
  480. 4670 IF Y > .5 THEN GOTO 1210 ELSE GOTO 1310
  481. 4680 PRINT "RUNNER THROWN OUT STEALING"
  482. 4690 O = O + 1
  483. 4700 B(I) = 0
  484. 4710 IF O = 3 THEN GOTO 2850
  485. 4720 N = 1
  486. 4730 GOSUB 3540
  487. 4740 B(1) = 0
  488. 4750 IF C = 5 AND S <> 3 THEN GOTO 930
  489. 4760 IF C = 5 THEN GOTO 710
  490. 4770 Y = RND(1)
  491. 4780 IF BA = 3 THEN GOTO 1310
  492. 4790 IF Y > .5 THEN GOTO 1210 ELSE GOTO 1310
  493. 4800 REM RUNNERS ADVANCE ONE BASE, BATTER THROWN OUT
  494. 4810 N = 1
  495. 4820 IF O = 2 THEN 4850
  496. 4830 GOSUB 3540
  497. 4840 B(1) = 0
  498. 4850 O = O + 1
  499. 4860 PRINT "BATTER THROWN OUT"
  500. 4870 RETURN
  501. 4880 PRINT "HIT BATSMAN (OUCH!)"
  502. 4890 GOSUB 4950
  503. 4900 GOTO 710
  504. 4910 N = 1
  505. 4920 GOSUB 3540
  506. 4930 B(1) = 0
  507. 4940 RETURN
  508. 4950 REM BATTER WALKED
  509. 4960 FOR I = 1 TO 3
  510. 4970 IF B(I) = 0 THEN 5010
  511. 4980 NEXT I
  512. 4990 N = 1
  513. 5000 GOTO 3540
  514. 5010 IF I = 1 THEN 5050
  515. 5020 FOR I0 = I TO 2 STEP -1
  516. 5030 B(I0) = B(I0 - 1)
  517. 5040 NEXT I0
  518. 5050 B(1) = 1
  519. 5060 RETURN
  520. 5070 PRINT "WHEN YOUR'RE UP:"
  521. 5080 PRINT "1-BATTER TAKES PITCH"
  522. 5090 PRINT "2-BATTER SWINGS AWAY"
  523. 5100 PRINT "3-BATTER BUNTS"
  524. 5110 PRINT "4-LEAD RUNNER STEALS"
  525. 5120 REM PRINT "5-HIT AND RUN"
  526. 5130 RETURN
  527. 5140 REM PITCHING ROUTINE
  528. 5150 PRINT "YOUR PITCHER MAY THROW:"
  529. 5160 PRINT "1-FAST BALL"
  530. 5170 PRINT "2-CURVE"
  531. 5180 PRINT "3-SLIDER"
  532. 5190 PRINT "4-SINKER"
  533. 5200 PRINT "5-CHANGE-UP"
  534. 5210 PRINT "6-KNUCKLEBALL"
  535. 5220 PRINT "7-SCREWBALL"
  536. 5230 RETURN
  537. 5240 IF A = 0 THEN 5370
  538. 5250 IF R9 = 1 THEN 5300
  539. 5260 PRINT "WHAT WILL YOUR PITCHER THROW? ";
  540. 5270 INPUT W
  541. 5280 IF W < 0 THEN R9 = 1
  542. 5290 IF R9 = 0 THEN GOTO 5320 ELSE PRINT "RANDOM PITCHES FOR REST OF INNING"
  543. 5300 W = INT(RND(1) * 8 + 1)
  544. 5310 IF W = 8 THEN 5300
  545. 5320 IF W > 0 AND W < 8 THEN 5470
  546. 5330 PRINT "UH-UH, "; B$; ".  ";
  547. 5340 GOSUB 5150
  548. 5350 PRINT
  549. 5360 GOTO 5260
  550. 5370 REM I MUST SELECT A PITCH
  551. 5380 W1 = RND(1)
  552. 5390 W = 1
  553. 5400 IF W1 < .75 THEN W = 2
  554. 5410 IF W1 < .55 THEN W = 3
  555. 5420 IF W1 < .45 THEN W = 4
  556. 5430 IF W1 < .35 THEN W = 5
  557. 5440 IF W1 < .15 THEN W = 6
  558. 5450 IF W1 < .08 THEN W = 7
  559. 5460 GOTO 5470
  560. 5470 PRINT W$(W);
  561. 5480 PRINT "...";
  562. 5490 RETURN
  563. 5500 REM HIT-AND-RUN
  564. 5510 IF B(1) + B(2) + B(3) = 0 THEN 4490
  565. 5520 GOSUB 5240
  566. 5530 PRINT "HIT AND RUN!"
  567. 5540 C = 5
  568. 5550 GOTO 1460
  569. 5560 DATA FAST BALL,CURVE BALL,SLIDER,SINKER,CHANGE-UP,KNUCKLEBALL
  570. 5570 DATA SCREWBALL
  571. 5580 DATA RIGHT,LEFT,CENTER,FIRST,SECOND,THIRD,SHORTSTOP,PITCHER,CATCHER
  572. 5590 DATA RIGHT OVER THE PLATE,CAUGHT THE OUTSIDE CORNER
  573. 5600 DATA OVER THE INSIDE CORNER,OVER AT THE KNEES
  574. 5610 DATA HIGH,LOW,INSIDE,OUTSIDE,HIGH AND TIGHT,LOW AND OUTSIDE
  575. 5620 DATA LOW AND INSIDE,HIGH AND OUTSIDE
  576. 5630 END
  577.  

Pages: 1 ... 12 13 [14]