コード例 #1
0
 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)
     });
コード例 #2
0
        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));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Mayweather50/HelloWorld
        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();
        }
コード例 #4
0
        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));
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: Aza000/Sharp
        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();
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        public void HumanMakesMove_TurnOfMachine_Throws()
        {
            var sut = new SticksGame(10, Player.Machine);

            Assert.Throws <InvalidOperationException>(() => sut.HumaMakesMove(1));
        }
コード例 #9
0
        public void HumanMakesMove_InvalidNumbersOfSticks_Throws(int take)
        {
            var sut = new SticksGame(10, Player.Human);

            Assert.Throws <ArgumentException>(() => sut.HumaMakesMove(take));
        }
コード例 #10
0
 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;
 }