Ejemplo n.º 1
0
 // Constructor
 public Match(TennisPlayer player1, TennisPlayer player2, Referee Ref)
 {
     Player1  = player1;
     Player2  = player2;
     Sets     = sets;
     this.Ref = Ref;
 }
Ejemplo n.º 2
0
        public void SimulateTournament()
        {
            int matchCounter   = 1;
            int PlayersInRound = PlayersInTournament.Count;

            if (PlayersInTournament.Count == 1) // base case is one player left, i.e. the winner
            {
                Console.WriteLine("The winner is \n" + PlayersInTournament[0]);
            }
            else
            {
                Console.WriteLine("-------------------- ROUND " + roundCounter + " --------------------");

                int currentPlayer = 0;

                while (PlayersInTournament.Count != PlayersInRound / 2)
                {
                    if (roundCounter == Math.Log(NumOfPlayers, 2))
                    {
                        Console.WriteLine("FINAL");
                    }
                    else
                    {
                        Console.WriteLine("Round: " + roundCounter + " Match: " + matchCounter);
                    }

                    Match match = new Match(PlayersInTournament[currentPlayer], PlayersInTournament[currentPlayer + 1], RefereesInTournament[rnd.Next(1, RefereesInTournament.Count)]);

                    Console.WriteLine(match.ToString());

                    TennisPlayer winner = match.SimulateMatch();

                    // remove the loser from the list
                    if (winner != PlayersInTournament[currentPlayer])
                    {
                        RemoveFromTournament(PlayersInTournament[currentPlayer]);
                    }
                    else
                    {
                        RemoveFromTournament(PlayersInTournament[currentPlayer + 1]);
                    }

                    currentPlayer++;
                    matchCounter++;
                }
                Console.WriteLine("---------------- END OF ROUND " + roundCounter + " ----------------- \n");
                roundCounter++;

                SimulateTournament(); // recursive call
            }
        }
Ejemplo n.º 3
0
        public void LoadPlayers(sex gender, int playerCount)
        {
            int             playersAdded = 0;
            TextFieldParser par          = new TextFieldParser(FilePath);

            par.TextFieldType = FieldType.Delimited;
            par.SetDelimiters(Delimiter);

            while (!par.EndOfData && playersAdded < playerCount)
            {
                string[] fields      = par.ReadFields();
                string   firstName   = fields[1];
                string   middleName  = fields[2];
                string   lastName    = fields[3];
                string   birthdate   = fields[4];
                string   nationality = fields[5];
                // create player object
                var player = new TennisPlayer(firstName, middleName, lastName, birthdate, nationality, gender);
                Players.Add(player);
                playersAdded++;
            }
            par.Close();
        }
Ejemplo n.º 4
0
 public void RemoveFromTournament(TennisPlayer player)
 {
     PlayersInTournament.Remove(player);
 }
Ejemplo n.º 5
0
 // overloaded methods to add and remove players/referees
 public void AddToTournament(TennisPlayer player)
 {
     PlayersInTournament.Add(player);
 }