Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
I’d appreciate the input of any programmers out there on the following.
What would be the best way to structure the code for the looping of baseball innings, and why?
So far, I can come up with the following ideas:
I’m thinking #2 simply to avoid repeating code, but it doesn’t take into account the fact that the 9th inning is unique from a winner checking POV so open to better ideas.
Cheers
bool gameEnd = false; int inningCnt = 0;
WHILE (gameEnd == false) { inningCnt++; playRoadTeamBat(); if (inningCnt >= 9 && homeScr > roadScr) { gameEnd = true; break; } if (rain == true && inningCnt > 5 && homeScr > roadScr) { gameEnd = true; break; } playHomeTeamBat(); if (inningCnt >= 9 && homeScr > roadScr) { gameEnd = true; break; } }
@SaveFarris said in Programming baseball innings:
bool gameEnd = false; int inningCnt = 0; WHILE (gameEnd == false) { inningCnt++; playRoadTeamBat(); if (inningCnt >= 9 && homeScr > roadScr) { gameEnd = true; break; } if (rain == true && inningCnt > 5 && homeScr > roadScr) { gameEnd = true; break; } playHomeTeamBat(); if (inningCnt >= 9 && homeScr > roadScr) { gameEnd = true; break; } }
Thanks for the code - wasn't expecting somebody to go to the trouble but that's awesome you took the time to do that.
I'd go so far as to put the rainout check after each pitch rather than in between innings. I'd probably change it to a general 'if rainout then gameEnd' that calls a procedure that goes through the rainout rule decision process (the > or <= 5 inningCnt) separately.
What's making me overthink it is the home 9+ inning and checking for the win during the inning. I reckon I'll try changing the homeScr > roadScr check to a simple winner > 0 (possible values 0, 1, 2 for none, away, home) and have the score check after each pitch also (would do each PA except if a pitch is a balk, wild pitch, passed ball or steal then a plate appearance may not be over) so that it can break to the 'game' while loop if there is a winner.
In a couple more weeks I'll have some time to put together some procedures for a whole game. Might share some here.
Prob would also need a check for roadScr > homeScr somewhere, otherwise the while loop won't exit if the road team is winning.
I never knew I would find a discussion about baseball game development. Pretty cool.
I don't follow any structure so I by no means follow any best practices. I just keep dabbling at the code till it does what I want it do to. Here's something from a game I'm developing:
while($inning < 10 || ($inning > 9 && $homeExtraInningAtBat == false)) {
if($inning >= 9 && $hRuns > $vRuns && $inningHalf == 'bottom'){ print "End game walk off<br>"; $endOfGame = true; ... } if($inning > 8 && $hRuns > $vRuns){ print "End game<br>"; $endOfGame = true; } if($inning > 8 && $vRuns > $hRuns){ print "End game<br>"; $endOfGame = true; $homeExtraInningAtBat = true; } $inningHalf = 'top'; $outs = 0; if($endOfGame == false){ $inning = $inning + 1; }
}
@je8675309 said in Programming baseball innings:
I never knew I would find a discussion about baseball game development. Pretty cool. I don't follow any structure so I by no means follow any best practices. I just keep dabbling at the code till it does what I want it do to. Here's something from a game I'm developing: while($inning < 10 || ($inning > 9 && $homeExtraInningAtBat == false)) { if($inning >= 9 && $hRuns > $vRuns && $inningHalf == 'bottom'){ print "End game walk off<br>"; $endOfGame = true; ... } if($inning > 8 && $hRuns > $vRuns){ print "End game<br>"; $endOfGame = true; } if($inning > 8 && $vRuns > $hRuns){ print "End game<br>"; $endOfGame = true; $homeExtraInningAtBat = true; } $inningHalf = 'top'; $outs = 0; if($endOfGame == false){ $inning = $inning + 1; } }
if($inning >= 9 && $hRuns > $vRuns && $inningHalf == 'bottom'){
print "End game walk off<br>"; $endOfGame = true; ...
if($inning > 8 && $hRuns > $vRuns){
print "End game<br>"; $endOfGame = true;
if($inning > 8 && $vRuns > $hRuns){
print "End game<br>"; $endOfGame = true; $homeExtraInningAtBat = true;
$inningHalf = 'top'; $outs = 0;
if($endOfGame == false){
$inning = $inning + 1;
I like the game log generated as html idea that your code just gave me
I’m all for keeping this discussion going; it’s nice reading in amongst all the complaints. You never know, we could come up with something
I'm not much into programming at all but what would this be for?
@Rabid55Wolverine said in Programming baseball innings:
Just messing around with ideas, keeping the brain active.