コード例 #1
0
ファイル: AtBatSimulator.cs プロジェクト: sathalom/BBSim
        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;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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++;
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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;
        }
コード例 #6
0
ファイル: AtBatSimulator.cs プロジェクト: sathalom/BBSim
        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;
            }
        }
コード例 #7
0
 private bool TryWalk(InMatchPositionPlayer _batter, InMatchPitcher _pitcher)
 {
     return _batter.TriesToWalk(_pitcher);
 }
コード例 #8
0
 private bool TryStrikeOut(InMatchPitcher _pitcher, InMatchPositionPlayer _positionPlayer)
 {
     return _pitcher.TriesToStrikeOutBatter(_positionPlayer);
 }
コード例 #9
0
 private bool TryHitBatter(InMatchPitcher _pitcher)
 {
     return _pitcher.TriesToHitBatter();
 }