public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenInitialMoneyAreZero()
 {
     Mock<IPlayer> mockedSecondPlayer = new Mock<IPlayer>();
     Mock<IPlayer> mockedFirstPlayer = new Mock<IPlayer>();
     var initialMoney = 0;
     var twoPlayersGame = new TwoPlayersTexasHoldemGame(mockedFirstPlayer.Object, mockedSecondPlayer.Object, initialMoney);
 }
Exemple #2
0
        public static void Main()
        {
            //Console.BackgroundColor = ConsoleColor.Black;
            //Console.ForegroundColor = ConsoleColor.Gray;
            //Console.BufferHeight = Console.WindowHeight = GameHeight;
            //Console.BufferWidth = Console.WindowWidth = GameWidth;

            //ConsoleHelper.WriteOnConsole(GameHeight - 1, GameWidth - ProgramName.Length - 1, ProgramName, ConsoleColor.Green);

            //var consolePlayer1 = new ConsoleUiDecorator(new ElkYPlayer(), 0, GameWidth, 5);
            //var consolePlayer2 = new ConsoleUiDecorator(new SmartPlayer(), 6, GameWidth, 5);

            var player1 = new ElkYPlayer();
            var player2 = new ElkYPlayer();

            for (int j = 0; j < 10; j++)
            {
                for (int i = 0; i < 100; i++)
                {
                    ITexasHoldemGame game = new TwoPlayersTexasHoldemGame(player1, player2);
                    game.Start();
                }

                var playerWins = GamesStatistics.Instance().PlayerWins;
                var allgames = GamesStatistics.Instance().TotalGames;

                Console.WriteLine("Games won: {0}", playerWins);

                GamesStatistics.Instance().PlayerWins = 0;
                GamesStatistics.Instance().PlayerLosses = 0;
                GamesStatistics.Instance().TotalGames = 0;
            }
        }
 public void ConstructorShouldThrowArgumentNullExceptionWhenIncorrectSecondPlayer()
 {
     IPlayer secondPlayer = null;
     Mock<IPlayer> mockedFirstPlayer = new Mock<IPlayer>();
     var initialMoney = 1000;
     var twoPlayersGame = new TwoPlayersTexasHoldemGame(mockedFirstPlayer.Object, secondPlayer, initialMoney);
 }
 public void ConstructorShouldThrowArgumentExceptionWhenTwoPlayersHaveEqualNames()
 {
     Mock<IPlayer> mockedFirstPlayer = new Mock<IPlayer>();
     Mock<IPlayer> mockedSecondPlayer = new Mock<IPlayer>();
     mockedSecondPlayer.SetupGet(x => x.Name).Returns("Player");
     mockedFirstPlayer.SetupGet(x => x.Name).Returns("Player");
     var initialMoney = 1000;
     var twoPlayersGame = new TwoPlayersTexasHoldemGame(mockedFirstPlayer.Object, mockedSecondPlayer.Object, initialMoney);
 }
        public static void Main()
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BufferHeight = Console.WindowHeight = GameHeight;
            Console.BufferWidth = Console.WindowWidth = GameWidth;

            ConsoleHelper.WriteOnConsole(GameHeight - 1, GameWidth - ProgramName.Length - 1, ProgramName, ConsoleColor.Green);

            var consolePlayer1 = new ConsoleUiDecorator(new ConsolePlayer(0), 0, GameWidth, 5);
            var consolePlayer2 = new ConsoleUiDecorator(new IntelligentPlayer(), 6, GameWidth, 5);
            ITexasHoldemGame game = new TwoPlayersTexasHoldemGame(consolePlayer1, consolePlayer2);
            game.Start();
        }
        public LibraryValidatorResult Validate(Assembly assembly)
        {
            var playerClasses =
                assembly.GetTypes()
                    .Where(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(IPlayer).IsAssignableFrom(x)).ToList();
            if (playerClasses.Count > 1)
            {
                return new LibraryValidatorResult("More than one public inheritant of IPlayer found.");
            }

            if (playerClasses.Count == 0)
            {
                return new LibraryValidatorResult("No public types that inherit IPlayer (or BasePlayer) found!");
            }

            var playerClass = playerClasses[0];
            IPlayer firstInstance;
            IPlayer secondInstance;
            try
            {
                // TODO: var sandbox = Sandbox.CreateSandbox();
                // TODO: firstInstance = sandbox.CreateInstanceFromAndUnwrap(playerClass.Assembly.FullName, playerClass.FullName) as IPlayer;
                // TODO: secondInstance = sandbox.CreateInstanceFromAndUnwrap(playerClass.Assembly.FullName, playerClass.FullName) as IPlayer;
                firstInstance = Activator.CreateInstance(playerClass) as IPlayer;
                secondInstance = Activator.CreateInstance(playerClass) as IPlayer;
            }
            catch (Exception ex)
            {
                return new LibraryValidatorResult($"Creating instance of \"{playerClass.Name}\" failed: {ex.Message}");
            }

            if (firstInstance == null || secondInstance == null)
            {
                return new LibraryValidatorResult($"Instance of \"{playerClass.Name}\" is null.");
            }

            try
            {
                var santaseGame = new TwoPlayersTexasHoldemGame(firstInstance, secondInstance);
                santaseGame.Start();
                santaseGame = new TwoPlayersTexasHoldemGame(secondInstance, firstInstance);
                santaseGame.Start();
            }
            catch (Exception ex)
            {
                return new LibraryValidatorResult($"Playing a new game between two instances of your player failed: {ex.Message}");
            }

            return new LibraryValidatorResult();
        }
        public static void Main()
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BufferHeight = Console.WindowHeight = GameHeight;
            Console.BufferWidth = Console.WindowWidth = GameWidth;

            ConsoleHelper.WriteOnConsole(GameHeight - 1, GameWidth - ProgramName.Length - 1, ProgramName, ConsoleColor.Green);

            //TODO our player here
            var raiseTwoSevenTestPlayer = new ConsoleUiDecorator(new RaiseTwoSevenPlayer(), 0, GameWidth, 5);
            var consolePlayer2 = new ConsoleUiDecorator(new SmartPlayer(), 6, GameWidth, 5);
            ITexasHoldemGame game = new TwoPlayersTexasHoldemGame(raiseTwoSevenTestPlayer, consolePlayer2);
            game.Start();
        }
        public static void Main()
        {
            var player1 = new SmartPlayer();
            var player2 = new ForcePlayer();

            int player1WinIndex = 1;
            int player2WinIndex = 1;

            for (int j = 0; j < gamePlaied; j++)
            {
                string winnersName;

                int whoIsWinning = 0;

                for (int i = 0; i < 1000; i++)
                {
                    var game = new TwoPlayersTexasHoldemGame(player1, player2);

                    if (game.Start().Name == player1.Name)
                    {
                        whoIsWinning++;
                    }
                    else
                    {
                        whoIsWinning--;
                    }
                }

                if (whoIsWinning > 0)
                {
                    winnersName = player1.Name;

                    player1WinIndex++;
                }
                else if (whoIsWinning < 0)
                {
                    winnersName = player2.Name;
                    player2WinIndex++;
                }
                else
                {
                    winnersName = "No Winner!";
                }

                if (printing)
                {
                    Console.WriteLine("*");
                    Console.WriteLine("---- Game No {0}", j);
                    Console.WriteLine("Winner is: {0}", winnersName);
                    Console.WriteLine("Game ratio: {0}", whoIsWinning);
                }
                else
                {
                    Console.Write('-');
                }
            }

            Console.WriteLine();
            Console.WriteLine("Players Wining Ratio: {0} / {1}", player2.Name, player1.Name);
            Console.WriteLine(" {0:F2} ",  (float)player2WinIndex / player1WinIndex);
        }