Writing a baseball game

Baseball is the perfect sport for which to create a simulator. Every season, every game, every play, every pitch, every player is comprised of a set of numbers. The choice of pitch, the target pitch location, how many outs, the batter's count, who's on base and where... and that's only part of what's going through the pitcher's head even before a pitch is thrown. Then there's the batter, the baserunners, the fielders, the Manager, the General Manager... It's no wonder those who don't follow the game have trouble getting their heads around how it all works. Who would be crazy enough to try and recreate that in simulation form, AI logic and all?

Well, this guy, as it turns out (in addition to a few awesome development studios who have had many years head start). 

Yes, I finally pulled my finger out and started the 'baseball simulator' project that has been traversing my thoughts for the last year. The few scribbles I jotted down pre-COVID either on paper or using the old Apple Pencil have been dusted off, ready to put to use. 

Where to start?

My thoughts immediately turned to the core of baseball gameplay - the at-bat (more accurately, the plate appearance since walks, hit-by-pitches, sac flies and some other obscure events don't count as at-bats). Each plate appearance, depending on the situation, can have wildly different outcomes and events may occur during plate appearances that may not even end the plate appearance (such as steals, injuries, errors, pick-offs...). It quickly occurred to me that even a single pitch, a routine event in most situations, is not so simple some of the time, and requires consideration of many possible happenings taking place. It is a simulation I'm going for, after all. So I decided to try and map out exactly what could happen. Presenting: anatomy of a pitch (incomplete, by the way):

First thoughts on paper

It was at this point I decided that I rather than killing my motivation by trying to create the perfect ballpark one roll of turf at a time (it could take years until a game could actually be played), I'd instead lay some dodgy Astroturf straight away to get a game going and then replace it one roll at a time with real turf when I have enough time to plan, code and test each blade of grass... er... line of code.

If you're not following me, ballpark = the whole program I'm writing; roll of turf = a single procedure that carries out a particular task (eg a steal, a foul ball, a substitution); blade of grass = line of code.

I've decided to document my journey in this blog, in amongst the other ramblings I come up with about video games, for no other reason than I couldn't be bothered managing a second blog.

So here we go. Feel free to play along at home and make your own baseball simulator.

Note: Version numbering will follow the Semantic versioning (SemVer) format x.y.z, where x is a major revision, y is a minor revison and z is a patch. I also chuck the date and 24hr time in yyyymmddhhmm format (year month date hour minute) on the end to represent when I saved that version to disk. So 202011032215 is 3/11/2020 at 10.15pm. Time included because some days (eg holidays) I could do multiple additions in several jam sessions.

Also some of the diary notes were made a few weeks before they were put into the blog, hence the discrepancy in dates.

Comments

Popular posts from this blog

MLB (Road to) The Show attribute progression

MLB The Show 21: create a stadium prediction & using created stadiums in online games

V1.1.4.202103032300 Basic player creator, line score tidy up and additional play results, including errors