Beispiel #1
0
        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;
        }
        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++;
        }
Beispiel #3
0
        public bool TriesToStrikeOutBatter(InMatchPositionPlayer _batter)
        {
            int batterKRate = _batter.StrikeOutRate(pitcher.ThrowingHand);
            int pitcherKRate = pitcher.StrikeOutRate(_batter.BatHand());
            int chanceOfStrikeOut = pitcherKRate + batterKRate + STRIKEOUT_MODIFIER_FOR_ORDER_CALCULATIONS;

            chanceOfStrikeOut /= 2;

            return RandomManager.RandomOneToThousand() <= chanceOfStrikeOut;
        }
        private void ApplyWalk(InMatchPositionPlayer _batter, FieldState _fieldState)
        {
            // TODO: reintroduce logging
            // _fieldState.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " walks.");

            _fieldState.PutRunnerOnBaseAdvancingOthers(FieldState.BASE.FIRST, _batter);

            //TODO: walk++ (pitcher)
            //TODO: walk++ (batter)

            //Temp
            StatsCounter.walks++;
        }
        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;
        }
Beispiel #7
0
        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;
            }
        }
Beispiel #8
0
 private void AdvanceRunnerOnThird()
 {
     // TODO: score a run
     runnerOnThird = null;
 }
Beispiel #9
0
        private void AdvanceRunnerOnSecond()
        {
            if (runnerOnThird != null)
                AdvanceRunnerOnSecond();

            runnerOnThird = RunnerOnSecond;
            runnerOnThird = null;
        }
Beispiel #10
0
        private void AdvanceRunnerOnFirst()
        {
            if (runnerOnSecond != null)
                AdvanceRunnerOnSecond();

            runnerOnSecond = runnerOnFirst;
            runnerOnFirst = null;
        }
Beispiel #11
0
 public void ResetFieldState()
 {
     runnerOnFirst = null;
     runnerOnSecond = null;
     runnerOnThird = null;
     outs = 0;
 }
Beispiel #12
0
        public void PutRunnerOnBaseAdvancingOthers(BASE _base, InMatchPositionPlayer _newRunner)
        {
            switch (_base)
            {
                case BASE.FIRST:
                    AdvanceRunnerOnFirst();
                    runnerOnFirst = _newRunner;
                    break;

                case BASE.SECOND:
                    AdvanceRunnerOnSecond();
                    AdvanceRunnerOnFirst();
                    runnerOnSecond = _newRunner;
                    break;

                case BASE.THIRD:
                    AdvanceRunnerOnThird();
                    AdvanceRunnerOnSecond();
                    AdvanceRunnerOnFirst();
                    runnerOnThird = _newRunner;
                    break;

                default:
                    // TODO: throw exception
                    break;
            }
        }
 private bool TryWalk(InMatchPositionPlayer _batter, InMatchPitcher _pitcher)
 {
     return _batter.TriesToWalk(_pitcher);
 }
 private bool TryStrikeOut(InMatchPitcher _pitcher, InMatchPositionPlayer _positionPlayer)
 {
     return _pitcher.TriesToStrikeOutBatter(_positionPlayer);
 }