private void doGroundBall(PositionPlayer _batter, Pitcher _pitcher, DefensiveAttributes.POSITION _hitToPosition, Game _game) { if (isAHit(BABIP_ON_GROUND_BALLS, _game.GetDefenderRange(_hitToPosition))) { doSingle(_batter, _pitcher, _hitToPosition, _game); } else { if (!tryField(_hitToPosition, _game)) { doROEError(ERROR_TYPE.SHORT_FIELDING, _game, _batter, _hitToPosition); } else { if (!tryThrow(_hitToPosition, _game)) { doROEError(ERROR_TYPE.SHORT_THROWING, _game, _batter, _hitToPosition); } else { //must revise this part of the logic if (_game.Outs < 2) { if (_game.RunnerOnFirst != null) { if (!(_game.RunnerOnFirst.Speed * 4 <= randomOneToThousand())) { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " grounds to " + POSITION_TEXT[Convert.ToInt32(_hitToPosition)] + " for a double play!"); _game.RunnerOnFirst = null; _game.IncreaseOuts(); if (_game.Outs == 1) { _game.advanceRunner(Game.BASE.THIRD, 1); _game.advanceRunner(Game.BASE.SECOND, 1); } _game.RunnerOnSecond = null; } else { _game.advanceRunner(Game.BASE.THIRD, 1); _game.advanceRunner(Game.BASE.SECOND, 1); _game.RunnerOnFirst = _batter; _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " grounds to " + POSITION_TEXT[Convert.ToInt32(_hitToPosition)] + " for a fielder's choice!"); } } else { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " grounds out to " + POSITION_TEXT[Convert.ToInt32(_hitToPosition)] + "."); _game.advanceRunner(Game.BASE.THIRD, 1); _game.advanceRunner(Game.BASE.SECOND, 1); } } else { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " grounds out to " + POSITION_TEXT[Convert.ToInt32(_hitToPosition)] + "."); } _game.IncreaseOuts(); } } } //Temp counter.groundballs++; }
private void doLineDrive(PositionPlayer _batter, Pitcher _pitcher, DefensiveAttributes.POSITION _hitToPosition, Game _game) { if (isAHit(BABIP_ON_LINE_DRIVES, _game.GetDefenderRange(_hitToPosition))) { switch (determineHitStrenght(_batter, BALL_HEIGHT.LINE_DRIVE, _game.GetDefenderRange(_hitToPosition), _game.GetDefenderThrowing(_hitToPosition))) { case HIT_TYPE.SINGLE: doSingle(_batter, _pitcher, _hitToPosition, _game); break; case HIT_TYPE.DOUBLE: doDouble(_batter, _pitcher, _hitToPosition, _game); break; case HIT_TYPE.TRIPLE: doTriple(_batter, _pitcher, _hitToPosition, _game); break; default: doSingle(_batter, _pitcher, _hitToPosition, _game); break; } } else { if (!tryField(_hitToPosition, _game)) { doROEError(ERROR_TYPE.DEEP_FIELDING, _game, _batter, _hitToPosition); } else { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " lines out to " + POSITION_TEXT[Convert.ToInt32(_hitToPosition)] + "."); _game.IncreaseOuts(); if (_game.Outs != 0 && (_hitToPosition == DefensiveAttributes.POSITION.CENTER_FIELDER || _hitToPosition == DefensiveAttributes.POSITION.LEFT_FIELDER || _hitToPosition == DefensiveAttributes.POSITION.RIGHT_FIELDER)) { tryAdvanceFromThirdBase(_hitToPosition, _game); if (_game.Outs != 0) { tryAdvanceFromSecondBase(_hitToPosition, _game); } } } } //Temp counter.linedrives++; }
//returns whether or not second is open after the play, not whether a runner advanced private bool tryAdvanceFromSecondBase(DefensiveAttributes.POSITION _hitToPosition, Game _game) { if (_game.RunnerOnSecond == null) return true; if (_game.RunnerOnThird != null) return false; if (_game.RunnerOnSecond.Speed >= MINIMUM_SPEED_ADVANCE_FROM_SECOND) { int randomResult = randomOneToThousand(); if (randomResult <= _game.RunnerOnSecond.Speed * 4 - (2 * _game.GetDefenderThrowing(_hitToPosition)) + 100) { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _game.RunnerOnSecond.FirstName + " advances from second!"); _game.advanceRunner(Game.BASE.SECOND, 1); } else if (randomResult <= _game.RunnerOnSecond.Speed * 6 - (2 * _game.GetDefenderThrowing(_hitToPosition)) + 100) { if (!tryField(_hitToPosition, _game)) { doNonROEError(ERROR_TYPE.DEEP_THROWING, _game, _hitToPosition); } else { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _game.RunnerOnSecond.FirstName + " is thrown out trying to advance from second!"); _game.RunnerOnSecond = null; _game.IncreaseOuts(); } } else { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _game.RunnerOnSecond.FirstName + " stays at second!"); return true; } } return false; }