コード例 #1
0
        private void RunTournamentWithPlayerLeaveAftergFight(int playerCount, int rounds, int leaveAfterMatch, int leaverId)
        {
            List <Player> players = CreatePlayers(playerCount);

            WinsThenScoreMatchManager mgr = new WinsThenScoreMatchManager(players, new Random(), rounds);

            int requiredMatches = GameManager.GetRequiredNumberOfMatches(players.Count, rounds);

            for (int i = 1; i <= requiredMatches; ++i)
            {
                if (i == leaveAfterMatch + 1)
                {
                    mgr.OnPlayerLeave(players[leaverId - 1], true);
                }

                Tuple <Player, Player> selected = mgr.SelectPlayersForNewMatch();

                Assert.IsNotNull(selected.Item1, "selected player can't be null");
                Assert.IsNotNull(selected.Item2, "selected player can't be null");
                Assert.AreNotEqual(selected.Item1, selected.Item2, "selected players can't be the same");

                mgr.OnMatchEnd(selected.Item1, GameEnd.WIN_GAME, 30, null);

                Player winner = mgr.GetTournamentWinner();
                if (winner != null)
                {
                    int maxWins = 0;
                    players.ForEach(d => { if (d.Data.WonMatches > maxWins)
                                           {
                                               maxWins = d.Data.WonMatches;
                                           }
                                    });
                    Assert.IsTrue(maxWins == winner.Data.WonMatches, "winner must the one with most wins");
                    Console.Error.WriteLine("players: " + playerCount + " rounds: " + rounds + " left " + leaverId + " after round " + leaveAfterMatch +
                                            " won: " + winner.GetId() + " with " + winner.Data.WonMatches + " wins");
                    return;
                }
            }
            Assert.Fail("winner must be found at some point.");
        }
コード例 #2
0
        private void RunRegularTournament(int playerCount, int rounds)
        {
            List <Player> players = CreatePlayers(playerCount);

            WinsThenScoreMatchManager mgr = new WinsThenScoreMatchManager(players, new Random(), rounds);

            int requiredMatches = GameManager.GetRequiredNumberOfMatches(players.Count, rounds);

            for (int i = 1; i <= requiredMatches; ++i)
            {
                Tuple <Player, Player> selected = mgr.SelectPlayersForNewMatch();

                Assert.IsNotNull(selected.Item1, "selected player can't be null");
                Assert.IsNotNull(selected.Item2, "selected player can't be null");
                Assert.AreNotEqual(selected.Item1, selected.Item2, "selected players can't be the same");

                mgr.OnMatchEnd(selected.Item1, GameEnd.WIN_GAME, 30, null);

                Player winner = mgr.GetTournamentWinner();
                if (i != requiredMatches)
                {
                    Assert.IsNull(winner, "winner can't be know until last match");
                }
                else
                {
                    Assert.IsNotNull(winner, "winner must be known after last match");
                    int maxWins = 0;
                    players.ForEach(d => { if (d.Data.WonMatches > maxWins)
                                           {
                                               maxWins = d.Data.WonMatches;
                                           }
                                    });
                    Assert.IsTrue(maxWins == winner.Data.WonMatches, "winner must the one with most wins");
                }
            }
        }