Exemple #1
0
        public void TestWhenYouVsOpponent_ThenGameIsPlayed()
        {
            Player you = new Player("Test", new MyBot());
            Player opponent = new Player("Opponent", new MyBot());

            Game game = new Game(GameRules.Default);
            GameResults actual = game.Play(you, opponent);

            Assert.IsNotNull(actual.Winner, "This test expected a winner.");
        }
    public GameResult Play(BotPlayer player1, BotPlayer player2)
    {
      var wrappedPlayer1 = player1.Bot as IRockPaperScissorsBot;
      var wrappedPlayer2 = player2.Bot as IRockPaperScissorsBot;
      if (wrappedPlayer1 == null && wrappedPlayer2 == null) return GameResult.Tie(player1, player2, "Neither player is an IRockPaperScissorsBot");
      if (wrappedPlayer1 == null) return GameResult.WinnerAndLoser(player2, player1, player1.TeamName + " is not an IRockPaperScissorsBot");
      if (wrappedPlayer2 == null) return GameResult.WinnerAndLoser(player1, player2, player1.TeamName + " is not an IRockPaperScissorsBot");

      var rpsPlayer1 = new Player(player1.TeamName, wrappedPlayer1);
      var rpsPlayer2 = new Player(player2.TeamName, wrappedPlayer2);

      var game = new Game(GameRules.Default);
      var gameResults = game.Play(rpsPlayer1, rpsPlayer2);
      return gameResults.ToGameResult((x) => {
        if (x == rpsPlayer1) return player1;
        if (x == rpsPlayer2) return player2;
        throw new InvalidOperationException("You've discovered a bug, you get 50 points.");
      });
    }
Exemple #3
0
        private short PlaySomeOpponentManyTimes(MoveMode mode, short gameCount)
        {
            short wins = 0;
            var results = new List<GameResults>();

            Parallel.For(0, gameCount, i =>
                {
                    Player you = new Player("Test", new MyBot());
                    var accessor = new MyBot_Accessor();
                    accessor.Mode = mode;
                    Player opponent = new Player("Opponent", accessor);

                    Game game = new Game(GameRules.Default);
                    GameResults result = game.Play(you, opponent);

                    if (result.Winner.TeamName.Equals("Test")) wins++;
                    results.Add(result);
                });

            VerifyResults(results, String.Format("against {0}", mode));
            return wins;
        }