Posts

Baseball game dev diary V0.5.1.202011302300 cleaning up after pitches

Image
Enabled/disabled buttons according to situation. Not very confident that it’s efficient code, but it works. If already in top of last inning, sim to top of last button is now disabled.  Button also shows which inning is the top of the last on the button text. Changed startgame procedure to call resetgame and resetinterface instead of duplicating that same code. Wondered why extra base hits stopped happening. Discovered that on a hit the checks for a number between 0 and 1 checked correctly for a homer (>0.85) but all others checked integers 80, 50, 10 etc rather than 0.8, 0.5, 0.1 etc. This session was really just about tidying up after adding the individual pitches and the issues that created. Interface evolved a little too (note that Winner at the bottom is a static label, when the game ends the winning team number appears after it):

Baseball game dev diary V0.5.0.202011300120 pitches pitches pitches!

Added a lastInning variable so that end of game check is in the ‘last inning or later’, rather than 9th inning or later. Some games could be 7, or even 3 innings. Inspired by a review of my own dev diary, 0.1.1. Tested 9, 2, 1, and 90 inning games to ensure reliability, by simming to the top of the last inning. (Incidentally, the 90 inning game was a 153-175 scoreline).  At last – pitches! Presently it simply randomises whether it’s a ball or a strike and whether a swing is taken, and whether the swing connects (connection = hit, miss = strike), but it’s a start (all are 50/50). If this seems simple, it’s not. Presently called strike and swinging strike are the same value. This will need to be changed.  Had to move ballCount, strikeCount and resultText scope to global.  Had to implement ball 4 and strike 3 logic. As a result created Strikeout procedure.  Put in basic hit logic so that if connection is made, determine whether single or extra base hits. Presently set a...

Baseball game dev diary version 0.4.2.202011252200: 10,000 games in less than a second

Image
I wonder how accurate it is to timestamp before and after code to determine how much time elapses during. Oh well, that's how I'm going to see how long things take. Changed txtOutput to display who’s up before plate appearance begins, and play result after. Rearranged beginPlateAppearance so check for winner and switching batter is after output of data. Public variables startmilliseconds and finishmilliseconds can be reused anywhere for checking time taken for various loops such as simming game. Sim Entire Game button added to sim everything from setting up teams to final pitch. Added time stamp before and after simming loop. Turns out it takes less than 1 millisecond to sim a game at present. 10,000 games simulated in 0.3 seconds! However, would need to also consider individual pitches, substitutions (presently no subs, no pitcher changes, and pitch counts are randomised). Would probably get away with less than 5 milliseconds per game with these included.  Winner variable move...

Baseball game dev diary version 0.4.1.202011251825: improving output info

Image
Added to end of inning data output procedure to display ‘Middle of’ and ‘End of’ if 3 outs. Added simming Boolean variable so that checks can be made whether to do certain things if simming, such as outputting to the display. Moved inning suffix (st, nd, rd, th) calculation to its own procedure to avoid duplication because of point #1 above. Going to do some testing of how long simming games will take with intention of simming 2500+ games for a season - Majors and Minors. This is going to be very interesting. Mindful of the fact that the times will be faster than expected as there is presently no AI or individual pitches. Here's what it looks like so far - note the runners on 2nd and 3rd after a double and no runner on 1st (-1 indicates base is empty).

Baseball game dev diary version 0.4.0.202011242245: hits, extra base hits, walks and runs

Image
 Moved code for plate appearance and set up batter from within event handlers to their own procedures and had the event handlers call them. This is particularly so that the plate appearances can be simmed without having to call the event handlers which gives errors as parameters  are not specified for parameters for calling object and event arguments. Makes sense to do this anyway – ie have event handlers with minimal code. The idea to move code out of event procedures is probably good practice anyway, and definitely ensures that simming games quickly will now be possible quite easily. Quite proud of this idea. Changed Skip to top of 9th procedure so that it actually sims up to the 9th rather than skipping the innings completely.  Ensured the Next batter button was disabled at end of game by moving button toggles before the check for winner and disabling next batter button in postgame procedure. Added a new procedure to checkBases at the end of each pitch. This count...

Baseball game dev diary version 0.3.0.202011232200: adding the bases

 Added subs for hitSingle, hitDouble, hitTriple and hitHomer. Only hitSingle to be utilised initially. Sidenote: turns out you can’t use single and double as sub names. Added buttons for bases, and code to display playerIDs in button text for batter and last three batters on bases. Added output all data before pitch procedure to Next batter button to have a separation between data shown at end of play and start of next play. Needed to invoke two clicks from user per play – one to prepare for the next plate appearance (nextBatter) and one to execute the next plate appearance (BeginPA). Added a procedure for postPlayDataUpdate for this same reason – end of play display would be lost by the next before pitch display if there isn’t a user interruption between them.  Broke the check end of inning down into two separate procedures instead of being in the begin plate appearance procedure. Checkendofinning() simply calls switchTeams if outs is at 3, and SwitchTeams does the switch and...

Baseball game dev diary: UI preview

Image
 As you can see from the screenshot, my priority is content first, presentation later. So presently it's just a case of get the data onto the screen and make sure it's correct.