Wednesday 28 August 2024

"Softball" for BASIC 10-Liner Programming Competition (2025)

I decided to try to make another 10-Liner BASIC game for the next BASIC 10Liner Games Contest on Homputerium. It is loosely based on many computer simulation baseball games I've seen over the years, but more specifically, a game video I saw recently for the old 8-bit Japanese home computer the Sharp MZ-700:


I've been thinking for some time that it would be simple to animate a pitcher batter interaction and the plotting of the movement of runners around the 4 bases of a simple diamond.  I wasn't so sure it could all happen on the same screen though, until I say the MZ game.  That old 8-bit machine isn't all that more functional than an MC-10 in its screen resolution. I also really liked the simple dynamic of different zones in the outfield representing different possibilities for number of bases. The original had 1-4, with two zones for out mapped out along the back fence using numbers. I thought I could save some space by using the pixels of them semigraphics-4 mode of the MC-10, which gives me 1-64 units horizontally.  This is a lot better than the 1-40 units of the text "graphics" being used on the MZ game, and more than twice what I would have if I used the 1-32 horizontal text spaces of the regular MC-10 text screen. I just requires using solid colours instead of numbers.

In the end fitting in a diamond and a side bar for the pitcher and batter interaction on the right meant I could only fit in 1,2 and 4 zones for number of bases and two zones for outs. The MZ game also had four positions in the inner outfield for outs. I used Red for the zones causing an out, and a then the colors corresponding to the values 1,2,4 (offset slightly) to save my program doing some conversion between sensing the color the ball is travelling through and the number of bases achieved.

The MZ game doesn't actually recreate a baseball/softball game. There is something else going on about points for hits.  I can't really tell.  My son knows Japanese so maybe I'll try to locate the article for the type-in magazines with the game and see what he can make of it.  But I thought I could recreate the rules of a simple softball match, which I remember from school, including grad school recreational teams I played on. The balls just track within the diamond.  There are no out of bounds.  This would be too complex for a 10-Liner.

The game basically is a reaction game where you try to time your key press to activate the bat at the same time that the ball is crossing directly to the right of the player.  If you make a hit, a random trajectory from a slightly random starting point at the bottom apex of the diamond heads up screen. If the pixel track hits anything besides green, a number of bases are won, or the ball is out if it hits red.  Once I had the graphics for diamond and pitcher and batter printed, and the animation for the pitch and the swing done, then there is just some simple calculations of runs and misses until 3 outs has happened. Then a shift is made to the other team and it is all done again. Repeat until 9 innings are completed, then END with a report of the two scores.

To achieve this in 10 lines requires all the techniques I've developed over the years.  The most important are using ON -(logical test) GOTO line num, line, line num as a kind of 8-bit replacement CASE SELECT IF/ELSE commands.  The other "biggy" is using Boolean logical operators directly in calculation to help omit using IF/THEN statements for conditional calculations.  Then its just the simple techniques-- single letter variables, reusing variables/scratch variables, removing spaces, etc.

The code can be found on my Github here:

https://github.com/jggames/trs80mc10/tree/master/quicktype/Strategy%20%26%20Simulation/Softball

But I'll include the current version here:

0 J=3.5:K=1:B$="*":C$=" ":C=40+RND(10):?"ßßßßßß¿¿¿ÏÏÏ¿¿¿ßßßßßß","ßß߯¯¯¿¿¿ÏÏÏ¿¿¿¯¯¯ßßß","ŸŸŸ¯¯¯¯¯¯ŸŸŸ",

1 ?"ŸŸŸŒŸŸŸ","†Žƒ‰","߆¿¿Ž‡‹¿¿‰ß","ß߆Ž‡‹‰ßß","ßß߆Ž‡‹‰ßßß"

2 ?"ßßß߆Œ‡‹Œ‰ßßßß","ßßßßß‚ßßßßß","ßßßßß߆‰ßßßßßß",:A$(5)="ÿ":A$(6)="€ƒƒ‡":A$(7)="Ž‚":A$(8)="‹‹

3 ?"ßßßßßß߆‰ßßßßßßß ‹ÿ","ßßßßßßß߆‰ßßßßßßßß ‹€","ßßßßßßßß߆‰ßßßßßßßßß ","ßßßßßßßßß߀ßßßßßßßßßß ‡‹"

4 ?@58,"X":FORB=90TO470STEP32:?@B,B$;:FORZ=1TOC:NEXT:?@B,C$;:IFINKEY$<>""THENFORT=5TO8:?@214+T*32,A$(T)" ";:NEXT:IFB=378THEN7

5 NEXT:IFB=474THENS=S+1:SOUND1,2:IFS=3THENS=0:?@277,O+1"OUT":N=N+1:S=0:O=O+1:IFO=3THENO=0:R(W)=R(W)+R:R=0:W=-(W=0):N=0:K=0

6 FORZ=1TO2500:NEXT:N=N*-(N<10):?@480,"R"R"O"O"P"N+1"T"W+1"SC"R(W);:?@0,;:ONKGOTO0:FORT=0TO9:P(T)=0:NEXT:I=I+1:INPUTE:CLS:GOTO0

7 B=500:X=19+RND(3):H=RND(0)*SGN(RND(0)-.5):FORY=25TO0STEP-1:X=X+H:P=POINT(X,Y):RESET(X,Y):IFP=4THENB=442:Y=0:S=2:GOTO9

8 IFP>1ANDP<6THENQ=P-1:?@277,Q"BASES":Y=0:P(N)=.5:FORT=0TO9:P(T)=P(T)+Q*-(P(T)>0):R=R-(P(T)>J):P(T)=P(T)*-(P(T)<=J):NEXT:N=N+1

9 NEXT:?@480,"R"R"O"O"P"N+1"T"W+1"SC"R(W)"I"INT(I/2)+1;:FORZ=1TO2500:NEXT:ON-(E=0)GOTO5:PRINT@0,"T1:"R(0)"T2:"R(1):INPUTE:GOTO5

10 REM                                                                                             1         1         1         1

11 REM   1         2         3         4         5         6         7         8         9         0         1         2         3

12 REM78901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234

Doesn't seem like much, but it plays a whole game of softball. If your reactions are good then you will get more hits and more chances for various runs.  If you miss a lot, then you'll get fewer runs.


It is working but I know as Christmas approaches and I have some more time for programming that I will want to refine it. There are possible bells and whistles I can add to make it a little more fulsome a game, possibly out of bounds hits, and maybe even adjusting the zones to include 3 base runs. I originally had the game limited to 127 characters, which is the max line length of the MC-10, but the contest only has a categories for 80, 120 and 256 line lengths. So I am definitely stuck with the 256 category.  Since there are some ways to trick the MC-10 to accept 256 character lines, I started adding features. But there is still room left.

I'll post addendums here as I go.  If you are interested, you can try playing the current version online at the Internet Archive.  Here is the link:

No comments:

Post a Comment