Posts

Showing posts from 2020

Baseball game dev diary: V1.1.1.202101011620 Adding a diamond

Image
Having overcome the frustration of the last lot of changes, I shifted my focus to improving the interface somewhat. Game log and line score now visible by default. Fixed base buttons getting messed up when simming forward. Was progressing to next batter before checking which base buttons needed disabling, so batter, on deck and in hole were always enabled after simming forward. Line score buttons now clear when rewinding game. Replaced function to generate a rounded up inning number (called 29 times) with an integer variable and add to it when incrementing inning only if int(inning) is not equal to inning number (ie only when progressing to top of an inning). Probably more efficient. Made the start game, sim forward, rewind and sim game menu items not buttons, and the show game log and show line score menu items, not checkboxes. Will remove buttons once I’m satisfied menu items are working correctly. Game log and line score toggles work as required. Moved the call to ButtonsTogg

Baseball game dev diary: V1.1.0.202012302330 Innings buttons on the fly

Image
All innings buttons (regular and extra) are now generated as the game progresses. So innings 2-9 for example do not show until these innings are started. These arrays of objects are quite complicated to set up (especially when replacing existing variables or arrays with new ones) but they make for much more efficient code.  Generating of innings buttons was done incorrectly resulting in innings of 2 or more over the starting game length not being removed correctly. Code seemed to be creating a whole new set of innings buttons with each inning that was added, instead of just the one inning worth.  Hits and runs now update in the line score (as too will errors when they are included). Per-inning runs also update in the line score buttons.  Per innings totals for hits, runs, errors, walks, runners left on (LOBs) stored in two-dimensional arrays (0,1 is team 0 inning 1 etc) with 0,0 and 1,0 being the totals, making use of what would have been an empty array space anyway. These arrays start

Baseball game dev diary: V1.0.2.202012232200 Lineup listboxes put to use and line score

Image
 When selecting a player in the lineup list boxes, that player’s info is shown in the player info box. Switches between the two lineups and base buttons (last player clicks deselects any player selected in the lineup) effectively. Reset game button text changed to ‘rewind game’ to better communicate its purpose (rewind to top of the first, no outs, same lineup).  Fixed bugs when reset game button is clicked, the player info did not clear if showing, and the lineup listboxes did not repopulate after being cleared. Array of buttons created for game log form, for line score. Procedure added to increment it by one, which will be added to extra innings code.  Recreated listboxes for lineups as array of listboxes.  Short demo video showing player info when clicking bases, on deck, in hole and lineups, as well as innings being added to line score (presently a button but will be made automatic when extra innings are required. 

Baseball game dev diary: V1.0.1.202012220933 Addition of on deck / in hole player info

Image
Added buttons for on deck and in hole player info. Runs existing procedure for show player info when clicked. Uses bases array spaces 8 and 9 which were intended for this purpose right from the start. Adjusted code to toggle buttons and on-screen info at various situations such as immediately after simming to last inning or end of game. Removed call to ‘buttons toggle simmed entire’ as it was the same code as ‘buttons toggle game over’ and will probably not differ in the future. Added listboxes showing lineups to make it easier to confirm it is cycling through lineups correctly. Tidied up the end of game and end of inning code so that simmed and manual games used the same code. See below. Well, this was an absolute nightmare of a 'minor' addition. The on deck/in hole stuff was no problem as I had already planned for it with the bases array. The lineup listboxes took literally five minutes. But in amongst all of that I decided to try and refine the end of game code as I realised

Baseball game dev diary game log: 'the one that got away in the bottom of the 9th'

Simulating a few games to test the walk-off code and the following game was generated. The away team was ahead 11-6 going in to the bottom of the 9th: Inning 9, Home Team batting 412 doubles on a 0-1 count.  427 singles on a 0-0 count.  409 doubles on a 1-2 count. 412 scores.  422 strikes out. 1 out. 420 doubles on a 0-0 count. 427 scores. 409 scores.  401 singles on a 1-1 count.  423 singles on a 0-0 count. 420 scores.  417 singles on a 0-2 count.  411 singles on a 1-0 count. 401 scores.  412 strikes out. 2 out. 427 strikes out. 3 out. Inning 10, Away Team batting 312 singles on a 0-0 count.  304 singles on a 0-0 count.  306 strikes out. 1 out. 303 strikes out. 2 out. 323 singles on a 0-2 count.  317 strikes out. 3 out. Inning 10, Home Team batting 409 homers on a 0-1 count.  Final:  Team 0 (away): 11 Team 1 (home): 12 Winner: Team 1 Pure randomness at play right there :)

Baseball game dev diary: V1.0.0.202012171941 Addition of the game log (with video!)

Image
I decided to call this version the first release as it's technically simulating complete games now. This turned out to be a significant update in terms of the amount of work involved to get the game log to a reasonably informative state. Due to the sequence of updates to data and outputting of data, lots of debugging and rearranging of code was required for things to display correct without compromising the integrity of the code (in other words – no band aids allowed!). The whole game can now be traced through the game log, play by play. Functionality will be added later to be able to export as a text file. Each plate appearance is also documented temporarily in the plate appearance log (ie ball 1, ball 2, strike 1, strike 2, strike 3 etc). The result of the plate appearance is output to both the plate appearance log and the game log. The PA log will strictly be for batter stuff only – ie steals, wild pitches etc when they are implemented will go in the game log only.  After clicki

Baseball game dev diary: Short demo video

Image
Recorded in PowerPoint on Windows, edited in iMovie on MacOS, many audio snippets replaced using Voice Memos on iPad. Gotta love technology. Subscribe to my YouTube channel while you're there. If I get over 100 I win a prize, or something like that. While I'm here I'll address the elephant in the room - yes, I'm using Visual Basic. It makes it easy for me, I get valuable feedback from the IDE and the debugging it offers and I get to experiment with using classes and objects in a familiar environment. All of this will end up being converted to some algorithms anyway.

Baseball game dev diary V0.5.3.202012090015 Giving the base buttons meaning

Image
Disabled base buttons at beginning of plate appearance unless occupied. Remove the code to reset bases in StartGame as that procedure called ResetGame procedure, which called ResetBases anyway.  Base buttons now display some player info when clicked, by searching for the playerID within the array of objects.  Added public variable for squadSize instead of hardcoding 28 into several places in code.  All player statuses set to 3 (benched) at start of game. Changed to 1 when put into game. Lineups now populate from squads array of player class objects with random players, not just first nine. Used a while loop to generate a random number up to squadSize and if player status was not 3, repeat random number generation. Ended up spending a lot longer than intended on this one (about 3 hours). Worth the extra time as I now better understand creating instances of classes and am fairly satisfied with the random generation of the lineup (even though that part really only took about 10 minutes).

Baseball game dev diary V0.5.2.202012032305 Prepping for pitchers

Created a player class. No such thing as a record anymore. Chose Class over Structure due to some web page recommendation. Was reminded that when variables within classes are set to private, you can’t change them outside of that class. So created a Property for each variable within the class that uses the Get and Set commands to read and write the values in the instances of a class. The private variable starts with an underscore, the property is the same name without the underscore. This should make coding the main game much easier. Presently, properties are: id, last name, first name, primary position, secondary positions, player type, pitches thrown, energy, stamina and game status. Created 28 instances of players for each team (scaled back from 40 for now). Made the base buttons clickable and each calls a procedure that is designed to show info for the batter/runner, but only when base is occupied. Later on will disable the buttons (including batter) if base is not occupied (or in b

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 as a single for code

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 counts runs scored (play

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 resets o

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.

Baseball game dev diary version 0.2.1.202011192214: rewriting 60 lines of code as 4

Image
 Changed the temporary setLineUp and setSquad procedures to use loops instead of repetitive code. The 300 + (teamtemp*100) + playeridtemp means that for team 0 the squad IDs are set as 300+ and for team 1, set as 400+.  Doing this was a no-brainer, not sure why I previously had 60+ lines in setSquad and 20+ lines in setLineUp. Probably a combination of it being late when I thought of it and figuring it was only temporary anyway so not thinking too much about it. Identifying when to use loops is usually what I'm good at. I'm so embarrassed. You may have worked out by now I'm doing this in Visual Basic. This is simply because it's the language that I can most easily code in off the top of my head, creating a simple user interface is super easy (rather than having to create a web page which is much more time consuming) and I can then turn them into algorithms later which can be converted to whichever language I want (most likely Python or PHP). It was at this point that it

Baseball game dev diary version 0.2.0.202011112223: multiple players

 Added array squad to include all available players for the game, including those in lineup, bench and all pitchers. Should this be an array of records, the one that will include attributes, name, positions etc? It should include a value for whether the player is currently in the game, has been taken out or still yet to play. Because any player could theoretically pinch, will need to identify players further as Position, Starter, Long relief, Middle relief, Setup or Closer. Should add an identifier for an Opener too as it could become more common. Possibly use P, S, O, L, M, U, C. This will be important when selecting players for relief but also making prioritising bullpen when subbing in a pitcher, or bench when pinch hitting. Pinch runner on the other hand is another story (eg Matz).   Added start game button to populate the squads and lineups and reset all game data to starting points.  Added code so that plate appearances cycle through lineups (if last batting player was > #8 th

Baseball game dev diary version 0.1.2.202011102300: Adding lineups

Image
 Changed runs array data type to UShort (previously Integer) as it will never have negative values and goes up to 65000 approx. Added public declarations for lineUp multidimensional array: teams 0-1 and batting order positions 1-9 (position 0 is ignored).  Added (in hindsight, very inefficient) procedure to populate the lineUps. Presently data is fixed for testing purposes. PlayerIDs will be stored in the Lineups, not jersey numbers. The jersey numbers can then be retrieved from database along with name and attributes. Note that PlayerIDs are set as Integer to take into account hundreds of millions of players. Left as signed data type because values could be -1 (eg when there is nobody in the lineup spot or base is empty). Added resetBases procedure to run at end of inning. Hopefully I'll remember its there when I work on the 'moving around the bases' part. Not sure why I did it so early, obviously I was planning ahead, judging from these notes:

Baseball game dev diary version 0.1.1.202011092030: minor edits

Image
 Considered modifying call to checkForWinner function so that it only calls past inning 8 however decided not to because some games may be shorter in future versions. Moved plate appearance result generation into its own function. Reset button now also resets display. Obviously this session was more thinking less doing...

Baseball game dev diary version 0.1.0.202011082350: picking a winner

Added call to checkForWinner function after each play, regardless of when. It checks scores when 3 outs in the top of the 9th, 3 outs in the bottom of the 9th and later, and after each play OR PITCH in the bottom of the 9th and later. If there is a winner (returns 0 or 1) it calls postgame procedure, otherwise (returns -1) adjusts inning if required. Added postgame procedure to output winning team to text box and disable plate appearance button.  Added reset button to reset all progress and start from inning 1 for testing purposes. Can be reset at any time. Improved form to have separate labels for each variable (inning, balls, strikes, outs, runs). Created code to convert inning to ‘top of’ (if a ½ value) or ‘bottom of’ (if whole number) and display inning number with correct suffix st, nd, rd, th etc (unless inning 121 is reached, in which case the inning number suffix won’t be the game’s most obvious problem). Moved output of data to form to its own procedure. Added skip to start of

Baseball game dev diary version 0.0.2.202011012359: counting innings

Added two teams, outs count and runs count; switched between teams when 3 outs using activeTeam variable (0 for away team, 1 for home team). Added innings counter, set to increment by 0.5 every 3 outs. I was really proud of the innings counter idea. Top of the inning (away team) is x.5 (eg 1.5 is the top of the 2nd), bottom of the inning (home team) is x.0 (eg 9.0 is bottom of the 9th). Planned it this way to make use of the integer for home team, non-integer for away team. Man, what is with finishing just before midnight? No wonder I'm so tired all the time.

Baseball game dev diary version 0.0.1.202010242359: random plate appearances

Image
Set up as single plate appearance button with randomised ball and strike counts. Result randomised between 0 and 9: 0: strikeout 1-6: in play, out 7-8: hit, run 9: walk or HBP, run Output result and count to text box. Wish I'd taken a screenshot. Just imagine three numbers in a single textbox and that's all it was. That's pretty much it for the first version. Not my proudest moment in programming, but then again, it was probably about 11.30pm when I sat down to start. But hey, the hardest part is starting. It's all smooth sailing from this point on. Incidentally, because it had been so long since I did any program design that relied on user input to progress through the program, it didn't occur to me that using a loop to cycle through innings would be impractical. Hence I pretty much ignored my scratchings above, and will probably ignore the below too.

Writing a baseball game

Image
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

Baseball, but first... Monopoly.

Image
It's been a good five years since I've done any serious algorithm design; most of the effort since I last taught it has been put into databases and querying. No more perfect an opportunity to blend the two than baseball, the thing that occupies around 75-80% of my brain's attention. But more on that next time. Last time I did something of this calibre was create a 2-6 player Monopoly game back in 2014. That went well. Laid the foundation for a full Monopoly game, following the official rulebook rules. Then I decided to disable the user interface and automatically simulate thousands of turns in a game.  Based on simulating seven games of two to six players, with varying maximums of 6,000 to 12,000 rolls per game (see table below for final tallies), I can confirm that which was already known, which is that the most occupied board location is Jail, with nearly three times as many end-of-turn occupants as its nearest competition: Trafalgar Square (red #3), Vine Street (orange #

MLB (Road to) The Show attribute progression

Image
Two key features of MLB The Show’s career mode have each divided its player base in two; satisfying one group of its users while alienating the other.  This first of two posts focuses on one of those features - the mode’s core feature of attribute progression. The proposed change will keep both groups of users satisfied without compromising the integrity of the mode. RPGs infiltrate the sport genre with career modes First introduced in MLB 07 The Show, Road to the Show (RTTS) is MLB The Show’s role-playing game (RPG) mode, which in sport games is often called career mode. We control a single character, whose existence (behaviours, skills and appearance) in its world is determined by a set of (mostly) numeric attributes. As the puppeteer of that character (and no other in the world) the attribute values are in our hands. It’s a difficult undertaking in sports games to implement a team-based career mode. Maintaining a balance between realism and keeping the player engaged re

MLB The Show needs Online Franchise players to play Custom Leagues

Image
I never played Online Franchise mode in MLB The Show I must preface this post by saying I wasn't fortunate enough to play Online Franchise mode in any of The Shows before 17. The cumbersome and slow interface was a massive turnoff (I did try) but more importantly with my terrible internet connection at the time, I was a liability. So yes, I'm Standing On The Outside looking in. If I were to claim that the former Online Franchise mode was a load of carp, my opinion would be irrelevant and worthless and you would be 100% right in calling me out. Online Franchise players, you need to play Custom Leagues Call me what you will, but this is my rational explanation of why I believe that if you want to play Online Franchise mode in future versions of MLB The Show, you're going to have to play Custom Leagues. I understand the disappointment that Custom Leagues is not OFM. Not yet. It will eventually evolve into something that will be a suitable and superior replacement t

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

Background We now know that (as predicted) MLB The Show 20's rebranding feature will incorporate the Diamond Dynasty team branding features.  Leveraging the DD team branding assets in Franchise mode is a simple first-step solution to a feature long-requested by its player base. It’s also step in the (right) direction of blurring the lines between the game’s two segregated platforms (DD and non-DD). Despite being a mostly Franchise and strictly non-DD player, I’ve never supported the idea of a stadium creator in MLB The Show, or for that matter, the idea of rebranding/relocating a Franchise. I’ve always considered it a lot of effort for not a lot of gain. Personally I would prefer that Franchise resources be allocated to adding depth to some of the content already there to improve the immersion in what’s going on around the league.  However, now that franchise mode has rebranding v1 in The Show 20, my prediction is that rebranding v2 in The Show 21 will see the birth