public static IPlayer CreateCompetitor(StrikeInfo strikeModel, Ball ball, Hole hole, User player, ExperimentHistory history, IBallKickPhysics ballKick) { if (history == null) throw new NullReferenceException("history"); IPlayer competitor; var competitorModel = strikeModel.CompetitorModel; if (competitorModel == null) throw new NullReferenceException("Модель соперника не задана"); if (competitorModel is UniformCompetitorModel) { competitor = new UniformCompetitor(ball, hole, strikeModel.CompetitorModel as UniformCompetitorModel, player, ballKick); } else if (competitorModel is NormalAdaptiveCompetitorModel) { var errorGenerator = new NormalAdaptiveCompetitorRandom(strikeModel.CompetitorModel as NormalAdaptiveCompetitorModel, history); competitor = new Competitor(ball.Position.X, hole.Position.X, errorGenerator, ballKick); } else if (competitorModel is UniformAdaptiveCompetitorModel) { var errorGenerator = new UniformAdaptiveCompetitorRandom(strikeModel.CompetitorModel as UniformAdaptiveCompetitorModel, history, strikeModel.Hole.Size, strikeModel.Ball.Size); competitor = new Competitor(ball.Position.X, hole.Position.X, errorGenerator, ballKick); } else { throw new InvalidOperationException($"Модель соперника \"{competitorModel.GetType().Name}\" не поддерживается"); } return competitor; }
public void Sample() { #region Конфигурирование var adaptiveCompetitorModel = new NormalAdaptiveCompetitorModel { ErrorMeanFactor = 1, ErrorStddevFactor = 1, PlayerHistorySamples = new List<PlayerHistorySample> { new PlayerHistorySample { GameTitle = "Game" } } }; var mean = 1; var stddev = 1; var history = CreateHistory(mean, stddev, size: 1000); #endregion var newSamples = new List<double>(); for (var j = 0; j < 1000; j++) { var generator = new NormalAdaptiveCompetitorRandom(adaptiveCompetitorModel, history); newSamples.Add(generator.Sample()); } var newNormal = Normal.Estimate(newSamples); var newMean = newNormal.Mean; var newStddev = newNormal.StdDev; Assert.IsTrue(Math.Abs(newMean - mean) < 0.09); Assert.IsTrue(Math.Abs(newStddev - stddev) < 0.05); }
public void Sample2() { #region Конфигурирование var adaptiveCompetitorModel = new NormalAdaptiveCompetitorModel { ErrorMeanFactor = 0, ErrorStddevFactor = 0, PlayerHistorySamples = new List<PlayerHistorySample> { new PlayerHistorySample { GameTitle = "Game" } } }; var mean = 0; var stddev = 1; var history = CreateHistory(mean, stddev, size: 2); #endregion var newSamples = new List<double>(); var generator = new NormalAdaptiveCompetitorRandom(adaptiveCompetitorModel, history); Assert.AreEqual(generator.Sample(), 0); }