private void AssignNewAtBatData(AtBat randAtBat) { this.Name = randAtBat.Name; this.BasesValue = randAtBat.BasesValue; this.Probability = randAtBat.Probability; this.IsBattedBall = randAtBat.IsBattedBall; }
public void GenerateRandomPlateAppearance() { var baseballEvent = new AtBat("", 0, 0.0, false); var r = new Random(); //gets a random double var probability = r.NextDouble(); //used to create pseudo weighted probability var cumulative = 0.0; for (var i = 0; i < AtBat.Events.Length; i++) { AtBat.Events.Shuffle(); var item = AtBat.Events[i]; //adds the event probability from the dictionary value cumulative += item.Probability; //establishes if the event probability is above the random number if (!(probability < cumulative)) { continue; } baseballEvent = item; break; } AssignNewAtBatData(baseballEvent); if (this.IsBattedBall) { OnBattedBallEvent(); } else { OnNonBattedBallEvent(); } }