public PositionPlayer(PersonnalInfo _playerInfo, DefensiveAttributes _defensiveAttributes, BAT_HAND _batHand, THROW_HAND _throwHand, PlateAppearanceRatings _againstLefty, PlateAppearanceRatings _againstRighty, RawPhysicalAttributes _physicalAttributes) : base(_playerInfo, _defensiveAttributes, _throwHand) { againstLefty = _againstLefty; againstRighty = _againstRighty; physicalAttributes = _physicalAttributes; batHand = _batHand; }
public List<PositionPlayer> CreatePlayersPoolForPosition(int _poolSize, DefensiveAttributes.POSITION _position) { List<PositionPlayer> playerPool = new List<PositionPlayer>(); for (int i = 0; i <_poolSize; ++i) { playerPool.Add(CreatePositionPlayer(_position)); } return playerPool; }
//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; }
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 bool tryThrow(DefensiveAttributes.POSITION _pos, Game _game) { int randomResult = randomOneToThousand(); if (randomResult > _game.GetDefenderThrowing(_pos) * 9 + 100) { return false; } return true; }
private void doTriple(PositionPlayer _batter, Pitcher _pitcher, DefensiveAttributes.POSITION _hitToPosition, Game _game) { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " triples to " + POSITION_TEXT[Convert.ToInt32(_hitToPosition)] + "!"); _game.advanceRunner(Game.BASE.THIRD, 3); _game.advanceRunner(Game.BASE.SECOND, 3); _game.advanceRunner(Game.BASE.FIRST, 3); _game.RunnerOnThird = _batter; //TODO: hit++ (batter) _game.GetAHit(); //TODO: hit++ (pitcher) //TODO: Triple++ (batter) if (!tryField(_hitToPosition, _game)) { doNonROEError(ERROR_TYPE.DEEP_BOBBLE, _game, _hitToPosition); } //Temp counter.triples++; }
private void doSingle(PositionPlayer _batter, Pitcher _pitcher, DefensiveAttributes.POSITION _hitToPosition, Game _game) { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " singles to " + POSITION_TEXT[Convert.ToInt32(_hitToPosition)] + "!"); _game.advanceRunner(Game.BASE.THIRD, 1); _game.advanceRunner(Game.BASE.SECOND, 1); //TODO: advance extra base? _game.advanceRunner(Game.BASE.FIRST, 1); //TODO: advance extra base? _game.RunnerOnFirst = _batter; //TODO: hit++ (batter) _game.GetAHit(); //TODO: hit++ (pitcher) tryAdvanceFromThirdBase(_hitToPosition, _game); tryAdvanceFromSecondBase(_hitToPosition, _game); //Temp counter.singles++; }
private void doROEError(ERROR_TYPE _gravity, Game _game, PositionPlayer _batter, DefensiveAttributes.POSITION _posCommitingError) { _game.CommitError(); bool doDeep = false; switch (_gravity) { case ERROR_TYPE.DEEP_FIELDING: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " reaches on an outfield fielding error by " + _game.GetDefenderFirstName(_posCommitingError) + "!"); doDeep = true; break; case ERROR_TYPE.DEEP_THROWING: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " reaches on an outfield throwing error by " + _game.GetDefenderFirstName(_posCommitingError) + "!"); doDeep = true; break; case ERROR_TYPE.SHORT_THROWING: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " reaches on an infield throwing error by " + _game.GetDefenderFirstName(_posCommitingError) + "!"); doDeep = true; break; case ERROR_TYPE.SHORT_FIELDING: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " reaches on an infield fielding error by " + _game.GetDefenderFirstName(_posCommitingError) + "!"); doDeep = false; break; } if (doDeep) { doDeepError(_game); _game.RunnerOnSecond = _batter; } else { doShortError(_game); _game.RunnerOnFirst = _batter; } }
private void doNonROEError(ERROR_TYPE _gravity, Game _game, DefensiveAttributes.POSITION _posCommitingError) { _game.CommitError(); bool doDeep = false; switch (_gravity) { case ERROR_TYPE.DEEP_FIELDING: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, "An outfield fielding error by " + _game.GetDefenderFirstName(_posCommitingError) + " allows the runners to advance!"); doDeep = true; break; case ERROR_TYPE.DEEP_THROWING: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, "An outfield throwing error by " + _game.GetDefenderFirstName(_posCommitingError) + " allows the runners to advance!"); doDeep = true; break; case ERROR_TYPE.SHORT_THROWING: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, "An infield throwing error by " + _game.GetDefenderFirstName(_posCommitingError) + " allows the runners to advance!"); doDeep = true; break; case ERROR_TYPE.SHORT_FIELDING: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, "An infield fielding error by " + _game.GetDefenderFirstName(_posCommitingError) + " allows the runners to advance!"); doDeep = false; break; case ERROR_TYPE.DEEP_BOBBLE: _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, "A bobble by " + _game.GetDefenderFirstName(_posCommitingError) + " allows the runners to advance!"); doDeep = false; break; } if (doDeep) { doDeepError(_game); } else { doShortError(_game); } }
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++; }
private void doHomerun(PositionPlayer _batter, Pitcher _pitcher, DefensiveAttributes.POSITION _hitToPosition, Game _game) { _game.GetLog().addEvent(_game.CurrentHalfInning, _game.HomeTeamAtBat, _batter.FirstName + " homers to " + POSITION_TEXT[Convert.ToInt32(_hitToPosition)] + "!"); _game.advanceRunner(Game.BASE.THIRD, 3); _game.advanceRunner(Game.BASE.SECOND, 3); _game.advanceRunner(Game.BASE.FIRST, 3); _game.ScoreRun(); //TODO: hit++ (batter) _game.GetAHit(); //TODO: hit++ (pitcher) //TODO: HR++ (batter) //TODO: HR++ (game) //TODO: HR++ (pitcher) //Temp for analysis counter.homeRuns++; }
private DefensiveAttributes CreatePlayerDefensiveAttributes(DefensiveAttributes.POSITION _primaryPosition) { // TODO: random attributes (varies from a future skill parameter) return new DefensiveAttributes(50, 50, 50, 50, _primaryPosition); }
public int GetDefenderThrowing(DefensiveAttributes.POSITION _pos) { if (homeTeamAtBat) { return home.GetDefenderThrowing(_pos); } else { return away.GetDefenderThrowing(_pos); } }
public string GetDefenderFirstName(DefensiveAttributes.POSITION _pos) { if (homeTeamAtBat) { return home.GetDefenderFirstName(_pos); } else { return away.GetDefenderFirstName(_pos); } }
private bool IsPositionFilled(DefensiveAttributes.POSITION _positionToCheck) { for (int i = 0; i < 9; ++i) { if (lineup[i] != null) { if (lineup[i].Position == _positionToCheck) { return true; } } else { break; } } return false; }
public Player(PersonnalInfo _playerInfo, DefensiveAttributes _defensiveAttributes, THROW_HAND _throwingHand) { playerInfo = _playerInfo; defensiveAttributes = _defensiveAttributes; throwingHand = _throwingHand; }
private PositionPlayer CreatePositionPlayer(DefensiveAttributes.POSITION _primaryPosition) { // TODO: random attributes (varies from a future player style parameter) return new PositionPlayer(CreatePlayerPersonnalInfo(), CreatePlayerDefensiveAttributes(_primaryPosition), PositionPlayer.BAT_HAND.RIGHT, Player.THROW_HAND.RIGHT, CreatePlateAppearanceRatings(), CreatePlateAppearanceRatings(), CreateRawPhyisicalAttributes()); }