Example #1
0
        private void ApplyBalk(FieldState _fieldState)
        {
            // TODO: reintroduce logging
            // _fieldState.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _game.GetCurrentPitcher().FirstName + " balks!");
            _fieldState.AdvanceAllRunners();

            //Temp for analysis
            StatsCounter.balks++;
        }
Example #2
0
        // This class will be used to determine whether or not a runner tries/succeeds to advance extra bases
        // as well as manage the result of success or failure.
        public void TryAdvanceRunners(FieldState.BASE _base)
        {
            switch (_base)
            {
                case FieldState.BASE.FIRST:
                    if (runnerOnFirst != null)
                    {
                        advanceRunner(Game.BASE.SECOND, _numberOfBases);
                        switch (_numberOfBases)
                        {
                            case 1:
                                runnerOnSecond = runnerOnFirst;
                                break;
                            case 2:
                                advanceRunner(Game.BASE.THIRD, _numberOfBases);
                                runnerOnThird = runnerOnFirst;
                                break;
                            case 3:
                                advanceRunner(Game.BASE.THIRD, _numberOfBases);

                                ScoreRun();
                                break;
                            default:
                                break;
                        }

                        runnerOnFirst = null;
                    }
                    break;
                case FieldState.BASE.SECOND:
                    if (runnerOnSecond != null)
                    {
                        advanceRunner(Game.BASE.THIRD, _numberOfBases);
                        if (_numberOfBases > 1)
                        {
                            ScoreRun();
                        }
                        else
                        {
                            runnerOnThird = runnerOnSecond;
                        }

                        runnerOnSecond = null;
                    }
                    break;
                case FieldState.BASE.THIRD:
                    if (runnerOnThird != null)
                    {
                        runnerOnThird = null;
                        ScoreRun();
                    }
                    break;
                default:
                    break;
            }
        }
        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++;
        }
Example #4
0
        private void ApplyFaildThirdBaseSteal(FieldState _fieldState)
        {
            // TODO: reintroduce proper logging
            // _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _game.RunnerOnSecond.FirstName + "is caught stealing third!");

            _fieldState.RunnerOnSecond = null;
            _fieldState.IncreaseOuts();

            //Temp
            StatsCounter.caughtStealing++;
        }
        private void ApplyStrikeOut(FieldState _fieldState)
        {
            // TODO: reintroduce logging
            // _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " strikes out!");

            _fieldState.IncreaseOuts();
            // TODO: K++ (batter)
            // TODO: K++ (pitcher)

            //Temp
            StatsCounter.strikeouts++;
        }
        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++;
        }
Example #7
0
        public Game(InMatchTeam _homeTeam, InMatchTeam _awayTeam)
        {
            atBatSimulator = new AtBatSimulator();
            plateAppearanceSimulator = new PlateAppearanceSimulator();
            baseRunningBatSimulator = new BaseRunningSimulator();
            defensivePlaySimulator = new DefensivePlaySimulator();
            baseStealingSimulator = new BaseStealingSimulator();

            home = _homeTeam;
            away = _awayTeam;
            fieldState = new FieldState();
            gameLog = new GameLog();
            gameLog.startInning(currentInning, homeTeamAtBat);
        }
Example #8
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;
        }
        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;
        }
Example #10
0
        private void ApplyPickOff(FieldState _fieldState)
        {
            // TODO: reintroduce logging
            // _fieldState.GetLog().addEvent(_fieldState.CurrentHalfInning, _fieldState.HomeTeamAtBat, _fieldState.RunnerOnFirst.FirstName + " gets picked off first!");

            _fieldState.RunnerOnFirst = null;
            _fieldState.IncreaseOuts();

            //Temp for analysis
            StatsCounter.pickoffs++;
        }
Example #11
0
        private bool TryStealThirdBase(FieldState _fieldState, int _catcherThrowingArm)
        {
            // TODO: test to see if the catcher throws the ball away

            return _fieldState.RunnerOnSecond.TriesToStealThirdInContext(_catcherThrowingArm);
        }
Example #12
0
        private bool TryPickRunnerOff(FieldState _fieldState)
        {
            if (_fieldState.RunnerOnFirst == null) return false;

            if (_fieldState.RunnerOnSecond != null) return false;

            if (RandomManager.RandomOneToThousand() != 1) return false;

            return true;
        }
Example #13
0
        private bool TryBalk(FieldState _fieldState)
        {
            int randomResult = RandomManager.RandomOneToThousand();

            if (randomResult != 1) return false;

            if (_fieldState.RunnerOnFirst == null && _fieldState.RunnerOnSecond == null && _fieldState.RunnerOnThird == null) return false;

            return true;
        }
Example #14
0
        private bool TryAttemptThirdBaseSteal(FieldState _fieldState, int _catcherThrowingArm)
        {
            if (_fieldState.RunnerOnSecond == null) return false;

            if (_fieldState.RunnerOnThird != null) return false;

            return _fieldState.RunnerOnSecond.DoesRunnerTryToStealThirdWithOpportunityInContext(_catcherThrowingArm);
        }
Example #15
0
        private void ApplySuccessfulThirdBaseSteal(FieldState _fieldState)
        {
            // TODO: reintroduce proper logging
            // _fieldState.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _game.RunnerOnSecond.FirstName + " steals third!");

            _fieldState.RunnerOnThird = _fieldState.RunnerOnSecond;
            _fieldState.RunnerOnSecond = null;

            //Temp
            StatsCounter.steals++;
        }
Example #16
0
        private void ApplySuccessfulSecondBaseSteal(FieldState _fieldState)
        {
            // TODO: reintroduce proper logging
            // _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _game.RunnerOnFirst.FirstName + " steals second!");

            _fieldState.AdvanceRunnerOnBase(FieldState.BASE.FIRST);

            //Temp
            StatsCounter.steals++;
        }