public bool SimulateAtBat(InMatchPositionPlayer _currentBatter, InMatchPitcher _currentPitcher, InMatchTeam _team, Game _game) { DefensiveAttributes.POSITION hitToPosition; switch (getBallHeight(_batter, _pitcher)) { case BALL_HEIGHT.FLY_BALL: hitToPosition = getPositionFlyBallHitTo(_batter); if (tryHomeRun(_batter.Power)) { doHomerun(_batter, _pitcher, hitToPosition, _game); } doFlyBall(_batter, _pitcher, hitToPosition, _game); break; case BALL_HEIGHT.LINE_DRIVE: hitToPosition = getPositionLineDriveHitTo(_batter); doLineDrive(_batter, _pitcher, hitToPosition, _game); break; case BALL_HEIGHT.GROUND_BALL: hitToPosition = getPositionGroundBallHitTo(_batter); doGroundBall(_batter, _pitcher, hitToPosition, _game); break; } return true; }
public bool TriesToWalk(InMatchPitcher _pitcher) { int batterWalkRate = positionPlayer.WalkRate(_pitcher.GetThrowHand()); int pitcherWalkRate = _pitcher.GetWalkRate(positionPlayer.BatHand); int chanceOfWalk = batterWalkRate + pitcherWalkRate + WALK_MODIFIER_FOR_ORDER_CALCULATIONS; chanceOfWalk /= 2; return RandomManager.RandomOneToThousand() <= chanceOfWalk / 2; }
private void ApplyHitBatter(FieldState _fieldState, InMatchPositionPlayer _batter, InMatchPitcher _pitcher) { // TODO: reintroduce logging // _fieldState.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _pitcher.FirstName + " hits " + _batter.FirstName + "!"); _fieldState.PutRunnerOnBaseAdvancingOthers(FieldState.BASE.FIRST, _batter); //Temp StatsCounter.hitBatters++; }
public bool SimulateBaseStealing(InMatchPositionPlayer _batter, InMatchPitcher _pitcher, InMatchTeam _defense, FieldState _fieldState) { if (TryPickRunnerOff(_fieldState)) { ApplyPickOff(_fieldState); return true; } if (TryBalk(_fieldState)) { ApplyBalk(_fieldState); return true; } // TODO: passed ball/wild pitches int catcherThrowingArm = _defense.GetDefenderThrowing(DefensiveAttributes.POSITION.CATCHER); if (TryAttemptSecondBaseSteal(_fieldState, catcherThrowingArm)) { if (TryStealSecondBase(_fieldState, catcherThrowingArm)) { ApplySuccessfulSecondBaseSteal(_fieldState); } else { ApplyFaildSecondBaseSteal(_fieldState); } return true; } if (TryAttemptThirdBaseSteal(_fieldState, catcherThrowingArm)) { if (TryStealThirdBase(_fieldState, catcherThrowingArm)) { ApplySuccessfulThirdBaseSteal(_fieldState); } else { ApplyFaildThirdBaseSteal(_fieldState); } return true; } return false; }
public bool SimulatePlateAppearance(InMatchPositionPlayer _batter, InMatchPitcher _pitcher, FieldState _fieldState) { if (TryHitBatter(_pitcher)) { ApplyHitBatter(_fieldState, _batter, _pitcher); return true; } if (TryWalk(_batter, _pitcher)) { ApplyWalk(_batter, _fieldState); return true; } // this is technically an at-bat but it does not put the ball in play so it will be resolved here if (TryStrikeOut(_pitcher, _batter)) { ApplyStrikeOut(_fieldState); return true; } return false; }
private BALL_HEIGHT GetBallHeight(InMatchPositionPlayer _batter, InMatchPitcher _pitcher) { int randomResult = RandomManager.RandomOneToThousand(); int flyBallMaxValue = (_batter.FlyBallRate(_pitcher.ThrowingHand) + _pitcher.AllowedFlyBallRate(_batter.BatHand))/2; int lineDriveMaxValue = (_batter.LineDriveRate(_pitcher.ThrowingHand) + _pitcher.AllowedLineDriveRate(_batter.BatHand))/2 + flyBallMaxValue; if (randomResult <= flyBallMaxValue) { return BALL_HEIGHT.FLY_BALL; } else if (randomResult <= lineDriveMaxValue) { return BALL_HEIGHT.LINE_DRIVE; } else { return BALL_HEIGHT.GROUND_BALL; } }
private bool TryWalk(InMatchPositionPlayer _batter, InMatchPitcher _pitcher) { return _batter.TriesToWalk(_pitcher); }
private bool TryStrikeOut(InMatchPitcher _pitcher, InMatchPositionPlayer _positionPlayer) { return _pitcher.TriesToStrikeOutBatter(_positionPlayer); }
private bool TryHitBatter(InMatchPitcher _pitcher) { return _pitcher.TriesToHitBatter(); }