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 KickBall() { var generatorMock = new Moq.Mock<IRandom>(); var strikeModel = new StrikeModel { Delay = 0.1, Velocity = 1 }; generatorMock.Setup(t => t.Sample()).Returns(0.4); var ballPositionX = 0.0d; var holePositionX = 1.0d; var competitor = new Competitor(ballPositionX, holePositionX, generatorMock.Object, new LinearWithTimeDelayBallKickPhysics(strikeModel)); var kick = competitor.KickBall(); Assert.AreEqual(1.4, kick.BallShift.X); Assert.AreEqual(1.3, Math.Round(kick.ElapsedTime, 3)); }