public static IAiStrategy CreateStrategy(AiMode mode, SticksGame game) { return(mode switch { AiMode.Easy => new EasyAiStrategy(game), AiMode.Medium => throw new NotImplementedException(), AiMode.Hard => throw new NotImplementedException(), _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null) });
public void HumanMakesMove_CorrectGameState(int takes, int remains) { var sut = new SticksGame(10, Player.Human); sut = sut.HumaMakesMove(takes); Assert.That(sut.NumberOfSticks, Is.EqualTo(remains)); Assert.That(sut.Turn, Is.EqualTo(Player.Machine)); }
static void HW_SticksGame() { var game = new SticksGame(10, Player.Human); game.MachinePlayed += Game_MachinePlayed; game.HumanTurnToMakeMove += Game_HumanTurnToMakeMove; game.EndOfGame += Game_EndOfGame; game.Start(); }
public void Ctor_ValidParams_GameIsInCorrectState() { int sticks = 10; Player player = Player.Machine; var sut = new SticksGame(sticks, player); Assert.That(sut.NumberOfSticks, Is.EqualTo(sticks)); Assert.That(sut.Turn, Is.EqualTo(player)); }
static void Main(string[] args) { //Первым будет ходить Human var game = new SticksGame(10, Player.Human); // Создаем экземпляр SticksGame game.MashinePlayeed += Game_MashinePlayeed; // Подписываемся и генерируем обработчик game.HumanTurnMakeMove += Game_HumanTurnMakeMove; // Подписываемся и генерируем обработчик game.EndOfGame += Game_EndOfGame; game.Start(); // Вызываем метод Start Console.ReadKey(); }
public async Task DoExercise() { IPlayer player = new Player("Paul", InputCountSticksToTake); var sticksGame = new SticksGame(player); sticksGame.ErrorTakenSticksEventHandler += ErrorTakenSticksEventHandler; sticksGame.PlayerTakenSticksEventHandler += PlayerTakenSticksEventHandler; sticksGame.GameIsEndEventHandler += GameIsEndEventHandler; Console.WriteLine($"Game is start. Total sticks: {sticksGame.TotalSticksNumber}. First turn: {sticksGame.TurnPlayer.Login}."); await sticksGame.StartGameAsync(); }
public void MachineMakesMove_CorrectGameState(int takes, int remains) { var gen = new PredictableGenerator(); gen.SetNumber(takes); int taken = 0; var sut = new SticksGame(10, Player.Machine, gen); sut.MachineMoved += (s, args) => taken = args.Taken; sut = sut.MachineMakesMove(); Assert.That(sut.NumberOfSticks, Is.EqualTo(remains)); Assert.That(takes, Is.EqualTo(taken)); Assert.That(sut.Turn, Is.EqualTo(Player.Human)); }
public void HumanMakesMove_TurnOfMachine_Throws() { var sut = new SticksGame(10, Player.Machine); Assert.Throws <InvalidOperationException>(() => sut.HumaMakesMove(1)); }
public void HumanMakesMove_InvalidNumbersOfSticks_Throws(int take) { var sut = new SticksGame(10, Player.Human); Assert.Throws <ArgumentException>(() => sut.HumaMakesMove(take)); }
public AiPlayer(AiMode aiMode, SticksGame game) { _game = game; _strategy = StrategiesFactory.CreateStrategy(aiMode, _game); Login = $"{aiMode}Robot"; }
public EasyAiStrategy(SticksGame game) { _random = new Random(DateTime.Now.Millisecond); _game = game; }