protected override ISantaseGame CreateGame()
 {
     IPlayer firstPlayer = new SmartPlayer();
     IPlayer secondPlayer = new SmartPlayer();
     ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); // new ConsoleLogger("[game] "));
     return game;
 }
コード例 #2
0
 protected override ISantaseGame CreateGame()
 {
     IPlayer firstPlayer = new ELRumDrinkingCapitanPlayer(); // new PlayerWithLoggerDecorator(new SmartPlayer(), new ConsoleLogger("[-]"))
     IPlayer secondPlayer = new DummyPlayer();
     ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); // new ConsoleLogger("[game] "));
     return game;
 }
コード例 #3
0
 public void StartGameShouldReturnOneOfThePlayersAsWinner()
 {
     var firstPlayer = new ValidPlayerWithMethodsCallCounting();
     var secondPlayer = new ValidPlayerWithMethodsCallCounting();
     var game = new SantaseGame(firstPlayer, secondPlayer);
     var winner = game.Start();
     Assert.IsTrue(winner != PlayerPosition.NoOne);
 }
コード例 #4
0
        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: Time limit (if available use decorator from the library)
                // 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 SantaseGame(firstInstance, secondInstance);
                santaseGame.Start();
                santaseGame = new SantaseGame(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();
        }
コード例 #5
0
        public void PlayersMethodsShouldBeCalledCorrectNumberOfTimes()
        {
            const int GamesToPlay = 200;

            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();

            for (var i = 0; i < GamesToPlay; i++)
            {
                var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer;
                var game = new SantaseGame(firstPlayer, secondPlayer);
                game.Start(firstToPlay);
            }

            // StartGame()
            Assert.AreEqual(GamesToPlay, firstPlayer.StartGameCalledCount);
            Assert.AreEqual(GamesToPlay, secondPlayer.StartGameCalledCount);

            // EndGame()
            Assert.AreEqual(GamesToPlay, firstPlayer.EndGameCalledCount);
            Assert.AreEqual(GamesToPlay, secondPlayer.EndGameCalledCount);

            // StartRound()
            Assert.GreaterOrEqual(
                firstPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the first player");
            Assert.GreaterOrEqual(
                secondPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the second player");

            // EndRound()
            Assert.GreaterOrEqual(
                firstPlayer.EndRoundCalledCount,
                GamesToPlay * 4,
                "Not ended at least 4 rounds per game for the first player");
            Assert.GreaterOrEqual(
                secondPlayer.EndRoundCalledCount,
                GamesToPlay * 4,
                "Not ended at least 4 rounds per game for the second player");

            // GetTurn() and EndTurn()
            Assert.IsTrue(firstPlayer.GetTurnWhenFirst > GamesToPlay * 10);
            Assert.IsTrue(firstPlayer.GetTurnWhenSecond > GamesToPlay * 10);
            Assert.IsTrue(firstPlayer.EndTurnCalledCount > GamesToPlay * 10);

            Assert.IsTrue(secondPlayer.GetTurnWhenFirst > GamesToPlay * 10);
            Assert.IsTrue(secondPlayer.GetTurnWhenSecond > GamesToPlay * 10);
            Assert.IsTrue(secondPlayer.EndTurnCalledCount > GamesToPlay * 10);
        }
コード例 #6
0
        public MainPage()
        {
            this.InitializeComponent();

            if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Desktop")
            {
                this.AdRow.Height = new GridLength(90);
                this.AdMediator_2D55AF.Height = 90;
                this.AdMediator_2D55AF.Width = 768;
            }
            else
            {
                this.AdRow.Height = new GridLength(80);
                this.AdMediator_2D55AF.Height = 80;
                this.AdMediator_2D55AF.Width = 480;
            }

            this.playerCardControls = new[]
                                          {
                                              this.PlayerCard1, this.PlayerCard2, this.PlayerCard3,
                                              this.PlayerCard4, this.PlayerCard5, this.PlayerCard6
                                          };

            this.uiPlayer = new UiPlayer();
            this.uiPlayer.RedrawCards += this.UiPlayerRedrawCards;
            this.uiPlayer.RedrawTrumpCard += this.UiPlayerRedrawTrumpCard;
            this.uiPlayer.RedrawNumberOfCardsLeftInDeck += this.UiPlayerOnRedrawNumberOfCardsLeftInDeck;
            this.uiPlayer.RedrawPlayerPlayedCard += this.UiPlayerOnRedrawPlayerPlayedCard;
            this.uiPlayer.RedrawOtherPlayerPlayedCard += this.UiPlayerOnRedrawOtherPlayerPlayedCard;
            this.uiPlayer.RedrawCurrentAndOtherPlayerRoundPoints +=
                this.UiPlayerOnRedrawCurrentAndOtherPlayerRoundPoints;
            this.uiPlayer.RedrawCurrentAndOtherPlayerTotalPoints +=
                this.UiPlayerOnRedrawCurrentAndOtherPlayerTotalPoints;
            this.uiPlayer.RedrawPlayedCards += this.UiPlayerOnRedrawPlayedCards;
            this.uiPlayer.GameClosed += this.UiPlayerOnGameClosed;
            this.uiPlayer.GameEnded += this.UiPlayerOnGameEnded;

            IPlayer smartPlayer = new SmartPlayer();
            this.game = new SantaseGame(this.uiPlayer, smartPlayer);

            this.PlayerCard.Transparent();
            this.OldPlayerCard.Transparent();
            this.OtherPlayerCard.Transparent();
            this.OldOtherPlayerCard.Transparent();

            Task.Run(() => this.game.Start());
        }
コード例 #7
0
        public void StartingGameShouldRestartTheGameToReuseGameInstance()
        {
            const int GamesToPlay = 20;

            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var game = new SantaseGame(firstPlayer, secondPlayer, GameRulesProvider.Santase, new NoLogger());

            for (var i = 0; i < GamesToPlay; i++)
            {
                game.Start(i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer);
            }

            Assert.GreaterOrEqual(
                firstPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the first player");
            Assert.GreaterOrEqual(
                secondPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the second player");
        }
コード例 #8
0
        public void WinnersShouldBeEquallyDistributed()
        {
            const int GamesToPlay = 200;

            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();

            var firstPlayerWinner = 0;
            var secondPlayerWinner = 0;

            for (var i = 0; i < GamesToPlay; i++)
            {
                var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer;
                var game = new SantaseGame(firstPlayer, secondPlayer);
                var winner = game.Start(firstToPlay);
                if (winner == PlayerPosition.FirstPlayer)
                {
                    firstPlayerWinner++;
                }
                else if (winner == PlayerPosition.SecondPlayer)
                {
                    secondPlayerWinner++;
                }
            }

            Assert.AreEqual(GamesToPlay, firstPlayerWinner + secondPlayerWinner);
            Assert.IsTrue(Math.Abs(firstPlayerWinner - secondPlayerWinner) < 150);
        }